

var jq = jQuery.noConflict();


function pickUpForm(str_form_name){
	var data ={};
	    jq(str_form_name + ' input[type="check"],' + str_form_name + ' select,' + str_form_name + ' textarea').each(function(){
	        var input_node = jq(this);
	        data[input_node.attr('name')] = input_node.val();
	    });
	    return data;
}

jq(function(){
		jq('select').each(function(){
				this.onchange=function(){
					jq(this).removeClass('err');
					jq(this).parent().removeClass('err');
				}
		});
		jq('input').each(function(){
			if(this.alt){
				this.onfocus=function(){
					if(this.value==this.alt) this.value='';
					jq(this).removeClass('err');
				};
				this.onblur=function(){
					if(this.value=='') this.value=this.alt;
				};
				if(this.value=='') this.value=this.alt;
			}
		});
		jq('textarea').each(function(){
			if(this.title){
				this.onfocus=function(){
					if(this.value==this.title) this.value='';
					jq(this).removeClass('err');
				};
				this.onblur=function(){
					if(this.value=='') this.value=this.title;
				};
				if(this.value=='') this.value=this.title;
			}
			//alert(this.value);
		});
		

		
});


function filter(form){
		jq(form+' input').each(function(){
			if(this.value==this.alt) this.value='';
		});
		jq(form+' textarea').each(function(){
			if(this.value==this.alt) this.value='';
		});
}

function filler(form){
		jq(form+' input').each(function(){
			if(this.value=='') this.value=this.alt;
		});
		jq(form+' textarea').each(function(){
			if(this.value=='') this.value=this.alt;
		});
}


///////////////////////////////////////////////////////////////






function js_register(){
	/*if(!jq('#reg input[name="frangipani"]').val()){
		alert('Please select an answer')
		return false; 
	}*/
	var rad = jq('#reg input[name="frangipani"]');
	
	if(!isRadioChecked(rad)) {
		alert('Please select an answer');
		return false; 
	}
	
	filter('#reg');
	iPost(jq('#reg')[0],after_reg);

}

function after_reg(msg){
	filler('#reg');	
	var s = msg.split(':');
	if(s[0] =='ok'){
		js_referrer();
		return;
	}else{
		var err = s[1].split(',');
		for(var i in err){
			jq('.i_'+err[i]).addClass('err') 
		}
	}

}

function js_refsend(){
	filter('#ref');
	iPost(jq('#ref')[0],after_ref);
}

function after_ref(msg){
	filler('#ref');	
	var s = msg.split(':');

	if(s[0] =='ok'){
		js_thankyou();
		return;
	}else{
		var err = s[1].split(',');
		for(var i in err){
			jq('.i_'+err[i]).addClass('err') 
		}
	}

}


///////////////////////////////////



function js_gettingthere(){

	if(jq('.gettingthere').css('display') == 'none'){
		jq('.open').slideUp("slow").removeClass('open');
		jq('.home').slideUp("slow");
		jq('.enter_bar').slideDown("slow");
		jq('.gettingthere').slideDown("slow").addClass('open')
	}	
	

}

function js_event(){

	if(jq('.event').css('display') == 'none'){
		jq('.open').slideUp("slow").removeClass('open');
		jq('.home').slideUp("slow");
		jq('.enter_bar').slideDown("slow");
		jq('.event').slideDown("slow").addClass('open')
	}	
	

}


function js_romance(){

	if(jq('.romance').css('display') == 'none'){
		jq('.open').slideUp("slow").removeClass('open');
		jq('.home').slideUp("slow");
		jq('.enter_bar').slideDown("slow");
		jq('.romance').slideDown("slow").addClass('open')
	}	
	

}


function js_family(){

	if(jq('.family').css('display') == 'none'){
		jq('.open').slideUp("slow").removeClass('open');
		jq('.home').slideUp("slow");
		jq('.enter_bar').slideDown("slow");
		jq('.family').slideDown("slow").addClass('open')
	}	
	

}


function js_thankyou(){
		jq('.thankyou').slideDown("slow").addClass('open')	
		jq('.referrer').slideUp("slow").addClass('open')	
}

function js_referrer(){
		jq('.referrer').slideDown("slow").addClass('open')	
		jq('.registration').slideUp("slow").addClass('open')	
}


function js_enter(){

	if(jq('.registration').css('display') == 'none'){
		jq('.open').slideUp("slow").removeClass('open');
		jq('.home').slideUp("slow");
		jq('.enter_bar').slideDown("slow");
		jq('.registration').slideDown("slow").addClass('open')
	}	
}



function js_home(){
	
	if(jq('.home').css('display') == 'none'){
		
		jq('.open').slideUp("slow").removeClass('open');
		jq('.enter_bar').slideUp("slow");
		jq('.home').slideDown("slow");
	}	
}


///////////////////////////////////////////////


function passFunction(func, arg) { 
		return function() { 
			func(arg?arg:null) 
		}; 
}	

function iframeDocument(iframe_element){
	if(typeof(iframe_element) == 'string') iframe_element = document.getElementById(iframe_element);
      	var doc = iframe_element.contentDocument;
    		if (doc == undefined || doc == null)
        		doc = iframe_element.contentWindow.document;
    return doc;	
}


function createDiv(id_name)	{
		var div= document.createElement('div');
		div.setAttribute('id',id_name);	
		div.innerHTML = ' ';
		div.style.visibility ='hidden';
		document.body.appendChild(div);
		return $(id_name);
	}


function iPost(form,callback ){
	var iFrame = document.getElementById('xpPost_div')
	iFrame.flag = 0;
   	iFrame.load=function(){
   		if(!iFrame.flag){
   			iFrame.flag = 1
   			 form.submit(); 
    		return
    	}
    	var con = iframeDocument('xpPost_frame').body.innerHTML   
		setTimeout(passFunction(callback,con),1);

    }
    form.target = 'xpPost_name';
   	iFrame.innerHTML = '<iframe lang="utf-8" style="visibility:hidden;height:1px;width:1px; z-index:500000"  id="xpPost_frame"  name="xpPost_name" onload="document.getElementById(\'xpPost_div\').load()"></frame>' 
} 

function isRadioChecked(obj) {
   ischecked = false;
   
   for (i=0;i<obj.length;i++)
   {
				  if (obj[i].checked)
								 ischecked = true;
   }

   return ischecked;
}

