$(document).ready(function(){
	
	// Start News Ticker
	$("#NewsFeed").marquee({showSpeed: 1, pauseSpeed: 3000, scrollSpeed: 40}); 
	
	$("#MainNav li").hover(
		function(){
			$(this).addClass('Hover');
		},
		function(){
			$(this).removeClass('Hover');
		}
	);
	
	$("#txtSearch").focus(function(){
		if ($(this).val() == 'Search...')
		{
			$(this).val('');
		}
	});
	
	$("#txtSearch").blur(function(){
		if ($(this).val() == '')
		{
			$(this).val('Search...');
		}
	});


	if($.cookie("css")) {
		$("link").attr("href",$.cookie("css"));
		$('#TextOnly').html('Graphical');
	}
	
	$("#TextOnly").click(function() { 
	if($.cookie("css")) {
		$.cookie("css",null, {expires: 365, path: '/'});
		$('#TextOnly').html('text only');
		$("link").attr("href","/styles/cscs-v4.css");
	}else{
		$("link").attr("href",$(this).attr('rel'));
		$.cookie("css",$(this).attr('rel'), {expires: 365, path: '/'});
		$('#TextOnly').html('Graphical');
		return false;
	}
	
});




	var $z = "0";
	
		function validfield($id){
			
			$($id).removeClass("red");
		
			if($($id).val() == ''){
				//alert($id);
				$($id).addClass("redb");
				$($id).focus();
				$z = "1";
				/*return false;*/
			}
		}	


	$('#conform').submit(function() {
		$z = "0";
			
		validfield('#xPostcode');
		validfield('#xDoB');
		validfield('#xTelephone');
		validfield('#xEmail');
		validfield('#xName');
		
			if($z == "1"){
				return false;
			}
	});
	

	$("#xMessage").click(function(){
			$(this).val("");
			$(this).addClass("cblack");
	});





var surcook = get_cookie ( "sur" );
if(surcook == "x")
	{
		$("#popupContact").hide();
		$("#backgroundPopup").hide();	
	}


$("#popupContactClose").click(function () {
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setDate ( cookie_date.getDate() + 1 );
		document.cookie = "sur=x; expires=" + cookie_date.toGMTString();
    });


	$('#eventbook').submit(function() {					
									
			if($('#n').val() == ''){
				$("#frmmsg").html('<p>Please enter ensure you enter a name</p>');
				return false; 
			};

			if($('#t').val() == ''){
				$("#frmmsg").html('<p>Please ensure you enter a telephone number</p>');
				return false; 
			};
			
			if(isNaN($('input[name=eventloc]:checked').val())){
				$("#frmmsg").html('<p>Please ensure you select a date</p>');
				return false; 
			};
			
			if(isValidEmailAddress($('#e').val())){
				// do nothing
			} else {
				$("#frmmsg").html('<p>Please ensure you select a valid email address</p>');
				return false; 
			}
			
			
	});


});




function get_cookie(cookie_name)
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}


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);

}

//alert(surcook);

