$(document).ready(function(){ 
	$(".trLink td[class!=nolink]").click(function(){
		goto = $(this).parent('tr').attr('url');
		location.href=goto;
	});	
	$(".divInformation").css({opacity:0});
	$("p.error").fadeIn();
	$("p.success").fadeIn();
	$(".error-messages").slideDown();
	$(".liMain").hoverIntent({
	   sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
	   interval: 50, // number = milliseconds for onMouseOver polling interval
	   over: submenuSlidedown, // function = onMouseOver callback (required)
	   timeout: 300, // number = milliseconds delay before onMouseOut
	   out: submenuSlideup // function = onMouseOut callback (required)
	});	
	$(".trRegular").hover(function(){		
		$(this).find('td').addClass('tdMO'); 
	},function(){   		
		$(this).find('td').removeClass('tdMO'); 
	});
	$(".spanInformation").hover(function(){		
		$(this).next('.divInformation').css('z-index', 1000).animate({opacity:1}); 
	},function(){   		
		$(this).next('.divInformation').animate({opacity:0}).css('z-index', 0); 
	});	
	$("*[enabled=true]").removeAttr('disabled');
	/*********** Trick to remove all REQUIRED="NO" attributes, that are blocking Firefox ********************/
	$('*[required="no"]').removeAttr('required');
});
function submenuSlidedown(){
	$(".liMain").removeClass('liActive');
	$('.ulSubmenubuttons').slideUp(300);
	$(this).addClass('liActive');	
	$(this).children('.ulSubmenubuttons').slideDown(300);
}
function submenuSlideup(){
	$(this).children('.ulSubmenubuttons').slideUp(300);
	$(this).removeClass('liActive');		
}
function checkRequired(){
	var noError = true;
	jQuery.each($("*[required]"), function() {
		if($(this).attr('required')=='yes'&&
			$(this).attr('disabled')==false &&
			$(this).attr('value')==''){
			$(this).addClass('inputError');		
			$('#divError').show();
			noError = false;
		}else{
			$(this).removeClass('inputError');		
		}	
		if($(this).attr('required')=='yes'&&
			$(this).attr('disabled')==false&&
			$(this).attr('validateemail')=='yes'){
			var validEmail = isValidEmailAddress($(this).attr('value'));
			if(!validEmail){
				$(this).addClass('inputError');		
				$('#divError').show();				
				noError=false;	
			}else{
				$(this).removeClass('inputError');		
			}
		}		
	});
	if(noError==true){
		document.myForm.submit();
		return true;
	}
		return false;
}
function isValidEmailAddress(emailAddress) { 
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); 
	return pattern.test(emailAddress); 
}
function checkSingleParent(fieldname,isSingleparent){
	$("*[id*="+fieldname+"]").attr("disabled",isSingleparent);
	if(isSingleparent==true){
	$("*[id*="+fieldname+"]").val("");	
	}
}
function checkBorn(fieldname,isBorn){
	if(isBorn==true){
		/*$("#divDOB").hide();
		$("#divRREG").show();
		$("*[id*=child-DOB]").attr("disabled",true);	*/
		$("*[id*="+fieldname+"][id!=child-lastname][id!=child-parent2id]").attr("disabled",false);	
		$("#divFNAME").show();
		$("#child-firstname").attr({'required':'yes'});
		$("#DOB_LABEL").html(DOBNormalText);
		
	}else{
		/*
		$("#divDOB").show();
		$("*[id*="+fieldname+"][id!=child-lastname][id!=child-parent2id][id!=child-DOB-day][id!=child-DOB-month][id!=child-DOB-year]").val("");
		$("*[id*="+fieldname+"][id!=child-lastname][id!=child-parent2id]").attr("disabled",true);
		$("#child-born").attr("disabled",false);
		$("*[id*=child-DOB]").attr("disabled",false);*/
		$("#divFNAME").hide();
		$("#child-firstname").removeAttr('required');
		$("#divRREG").hide();
		$("#DOB_LABEL").html(DOBExpectText);
		
	}
}
function showID(selectBox,checkValue,showObject,requiredObject){
	selectedValue = $('#'+selectBox).val();
	if(selectedValue == checkValue){
		$('#'+showObject).show();	
		$('#'+requiredObject).attr('required','yes');
	}else{
		$('#'+showObject).hide();	
		$('#'+requiredObject).attr('required','no');
	}
}
function checkAll(objectChecked){
	$('*[name=status]').attr('checked',objectChecked);
}
function showField(fieldID,gid){
	try{
		$('#container'+gid+' > *[id*=fld]').hide();
		$('#container'+gid+' > *[id*=inp]').attr('required','no');
		$('#fld'+fieldID+gid).show();
		$('#inp'+fieldID+gid).attr('required','yes');
	}catch(e){}
}
/************************ jQuery tooltip *****************************/
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = -305;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
// starting the script on page load
$(document).ready(function(){
	tooltip();	
});
function copyAddress(from,to){
	$('#'+to+'-street').val($('#'+from+'-street').val());	
	$('#'+to+'-streetnumber').val($('#'+from+'-streetnumber').val());	
	$('#'+to+'-postcode').val($('#'+from+'-postcode').val());	
	$('#'+to+'-city').val($('#'+from+'-city').val());	
}
function loadAddPopup(){ 
	$(document).ready(function(){
		$.colorbox({href:"/group/finished", width:400, height:235,  initialWidth:400, initialHeight:235,scrolling:false, opacity:0.7});
	});
}
