// 

$(document).ready(function() {
	$("form").submit(function(){
        
		//validation
		
		var errors = [];
		
		if ($('#forename').val() == '')
		{
			errors.push("Please type your 'Name' in the space provided.");
		}
		if ($('#surname').val() == '')
		{
			errors.push("Please type your 'Surname' in the space provided.");
		}
		if ($('#email').val() == '')
		{
			
			errors.push("Please type a valid 'Email Address' in the space provided.");
			
		}
		else
		{
			
			if (!isValidEmail($('#email').val()))
			{
				errors.push("Please type a valid 'Email Address' in the space provided.");
			}
		}
		
		if ($('#tel').val() == '')
		{
			errors.push("Please type your 'Telephone Number' in the space provided.");
			
		}
		
		if ($('#friendName').val() == '')
		{
			errors.push("Please type your 'Friend's Name' in the space provided.");
			
		}
		
		if ($('#femail').val() == '')
		{
			errors.push("Please type a valid 'Friend's Email Address' in the space provided.");
		}
		else
		{
			if($('#femail').length > 0 )
			{
				if (!isValidEmail($('#femail').val()))
				{
					errors.push("Please type a valid 'Friend's Email Address' in the space provided.");
				}	
			}
		}
		
		
		//notification
		
		if(errors.length != 0)
		{
			var errorCode = '<h2>Form Submission Errors</h2><ul id="errorList">';
			for(i=0; i<errors.length;i++)
			{
					errorCode = errorCode + '<li>'+ errors[i] +'</li>'	;
			}
			
			errorCode = errorCode + '</ul>';
			
			$('#formErrors').html(errorCode);
			$('form').css('margin-top','20px');
			
			if(typeof sIFR == "function"){sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"jubilat.swf", sColor:"#415a68", sLinkColor:"#415a68", sWmode:"transparent", sHoverColor:"#415a68", sFlashVars:"height:26px;"}));
			};
			
			return false;
		}
		else
		{
				
		}
    });
	
	
	
	function isValidEmail(str) {
   		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 	}

	
});

