<!--quick contact validation script starts here-->	
	$(document).ready(function() {	
							   
			$("#name").focus(function() {
		   		$("#name").val('');	 });			
			$("#name").blur(function() {
		   		if($("#name").val()=='') $("#name").val('Name'); });	
				
			$("#email").focus(function() {
		   		$("#email").val(''); });			
			$("#email").blur(function() {
		   		if($("#email").val()=='') $("#email").val('Email'); });
				
			$("#phone").focus(function() {
		   		$("#phone").val(''); });			
			$("#phone").blur(function() {
		   		if($("#phone").val()=='') $("#phone").val('Phone No.');
				
			});			
			
		
			$("#description").focus(function() {
		   		$("#description").val(''); });			
			$("#description").blur(function() {
		   		if($("#description").val()=='') $("#description").val('Description'); });						
		});	
<!--quick contact validation script ends here-->

	function submit_contact()
	{
		var name   			=	trim($('#name').attr('value'));
		var email   			=	trim($('#email').attr('value'));
		var phone   			=	trim($('#phone').attr('value'));
		var description  		=	trim($('#description').attr('value'));
		var security_text  		=	trim($('#security_text').attr('value'));				
		
		document.getElementById("name").value			=	name;
		document.getElementById("email").value			=	email;
		document.getElementById("phone").value			=	phone;
		document.getElementById("description").value	=	description;
		document.getElementById("security_text").value	=	security_text;
		
		//Validation
		if( name == "" || name == "Name" )
		{
			alert("Please enter your name.");
			document.getElementById("name").focus();
			return false;
		}
		if( email == "" || email == "Email" )
		{
			alert("Please enter your email.");
			document.getElementById("email").focus();
			return false;
		}
		if(email != "" && !isEmail(email))
		{
			alert("Please enter a valid email.");
			document.getElementById("email").value	=	'';
			document.getElementById("email").focus();
			return false;
		}
		if( phone == "" || phone == "Phone No." )
		{
			alert("Please enter your phone.");
			document.getElementById("phone").focus();
			return false;
		}
		
		var rege = /^([0-9-+\ ])+$/;
		var ph = $("#phone").val();
		if(!(rege.test(ph))){ 
			alert("Enter a valid phone number"); $("#phone").focus();
			return false; }
				
		if( description == "" || description == "Description" )
		{
			alert("Please enter description.");
			document.getElementById("description").focus();
			return false;
		}
		if( security_text == "" )
		{
			alert("Please enter the security text.");
			document.getElementById("security_text").focus();
			return false;
		}
		
		
		/*var ajax_load 		= 	"<img class='loading' src='images/load.gif' alt='loading...' />";*/
		var ajax_load 		= 	"Loading...";
		var data     			=  "name="+ name + "&email="+ email + "&phone="+ phone + "&description="+ description + "&security_text="+ security_text;
		var ajax_url		 	= 	"submit_contact_ajax.php";
		
		document.getElementById("message_row").innerHTML = ajax_load;

			$.ajax({
			type: "POST",
			url: ajax_url,
			data: data,
			success: function(msg){
				document.getElementById("message_row").style.display = '';
				if(msg == 1)
				{
					document.getElementById("message_row").innerHTML = "Your contact details submitted successfullly";
					$("#name").val('Name');
					$("#email").val('Email');
					$("#phone").val('Phone No.');
					$("#description").val('Description');				
					thesrc = document.getElementById("CaptchaSecurityImages01").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("CaptchaSecurityImages01").src = thesrc+"?sessId=01&"+Math.round(Math.random()*100000);
		
				}
				else
				{
					document.getElementById("message_row").innerHTML = "Invalid captcha entered.";
					thesrc = document.getElementById("CaptchaSecurityImages01").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("CaptchaSecurityImages01").src = thesrc+"?sessId=01&"+Math.round(Math.random()*100000);
		
					
				}
			}
		});
		/*$('#cfmain').load('../quick_contact.php');*/
		 		return false;
		
	}
	
	function submit_contact_small()
	{
		var email   			=	trim($('#email').attr('value'));
		
		var description  		=	trim($('#description').attr('value'));
		var security_text  		=	trim($('#security_text').attr('value'));				
		
		document.getElementById("email").value			=	email;
		
		document.getElementById("description").value	=	description;
		document.getElementById("security_text").value	=	security_text;
		
		//Validation
		if( email == "" || email == "Email" )
		{
			alert("Please enter your email.");
			document.getElementById("email").focus();
			return false;
		}
		if(email != "" && !isEmail(email))
		{
			alert("Please enter a valid email.");
			document.getElementById("email").value	=	'';
			document.getElementById("email").focus();
			return false;
		}
		
			
		if( description == "" || description == "Description" )
		{
			alert("Please enter description.");
			document.getElementById("description").focus();
			return false;
		}
		if( security_text == "" )
		{
			alert("Please enter the security text.");
			document.getElementById("security_text").focus();
			return false;
		}
		
		
		/*var ajax_load 		= 	"<img class='loading' src='images/load.gif' alt='loading...' />";*/
		var ajax_load 		= 	"Loading...";
		var data     			=  "email="+ email + "&description="+ description + "&security_text="+ security_text;
		var ajax_url		 	= 	"../submit_contact_small_ajax.php";
		
		document.getElementById("message_row").innerHTML = ajax_load;

			$.ajax({
			type: "POST",
			url: ajax_url,
			data: data,
			success: function(msg){
				document.getElementById("message_row").style.display = '';
				if(msg == 1)
				{
					document.getElementById("message_row").innerHTML = "Your contact details submitted successfullly";
					$("#email").val('Email');
					$("#description").val('Description');		
					thesrc = document.getElementById("CaptchaSecurityImages01").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("CaptchaSecurityImages01").src = thesrc+"?sessId=01&"+Math.round(Math.random()*100000);
				}
				else
				{
					document.getElementById("message_row").innerHTML = "Invalid captcha entered.";
					thesrc = document.getElementById("CaptchaSecurityImages01").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("CaptchaSecurityImages01").src = thesrc+"?sessId=01&"+Math.round(Math.random()*100000);
					
				}
			}
		});
		/*$('#cfmain').load('../quick_contact.php');*/
		 
		
		return false;
	}
	
	function trim(str)
	{
		return str.replace(/^\s+|\s+$/g,'');
	}
	
	function isEmail(str)
	{
		var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
		return regex.test(str);
	}
	
	function new_freecap()
	{
		// loads new freeCap image
		if(document.getElementById)
		{
			// extract image name from image source (i.e. cut off ?randomness)
			thesrc = document.getElementById("CaptchaSecurityImages").src;
			thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
			// add ?(random) to prevent browser/isp caching
			document.getElementById("CaptchaSecurityImages").src = thesrc+"?"+Math.round(Math.random()*100000);
		} else {
			alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
		}
	}
	
	function new_freecap01()
	{
		// loads new freeCap image
		if(document.getElementById)
		{
			// extract image name from image source (i.e. cut off ?randomness)
			thesrc = document.getElementById("CaptchaSecurityImages01").src;
			thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
			// add ?(random) to prevent browser/isp caching
			document.getElementById("CaptchaSecurityImages01").src = thesrc+"?sessId=01"+Math.round(Math.random()*100000);
		} else {
			alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
		}
	}
