$(document).ready(function(){ 
	$(".floating-box").click(function(){
		$(".error-list").fadeOut();
	});
	
	$(".error-list").click(function(){
		$(".error-list").fadeOut();
	});
});
function validate_contact(){
	
	var ctName	  	= $('#ctName').val();
	var ctBusiness	= $('#ctBusiness').val();
	var ctEmail  		= $('#ctEmail').val();
	var ctTelephone	= $('#ctTelephone').val();
	var ctEnquiry     	= $('#ctEnquiry').val();
	var code      		= $('#code').val();
	var returnVal 		= false;
	
	// Verify Name
		if (ctName == '' || ctName.length < 2 ) { inlineMsg('ctName','Please specify your Name!',3); return false; }
	
	// Verify Business
		if (ctBusiness == '' || ctBusiness.length < 2 ) { inlineMsg('ctBusiness','Please specify your Business!',3); return false; }
	
	// Verify Email
		if (ctEmail == '' || ctEmail.length < 2 ) { inlineMsg('ctEmail','Please specify your Email!',3); return false; }
		
		if (validateEmail(ctEmail) ) { inlineMsg('ctEmail','Invalid email address!',3); return false; }
	
	// Verify Bought
		if (ctTelephone == '' || ctTelephone.length < 2 ) { inlineMsg('ctTelephone','Please specify your Telephone number!',3); return false; } 
	
	// Verify content
		if (ctEnquiry == '' || ctEnquiry.length < 2 ) { inlineMsg('ctEnquiry',"You have nothing to tell us?",3); return false; } 
	
	// Verify Security Code
		if (code == '' || code.length < 2 ) { inlineMsg('code','Please specify exactly the Security Code shown in the image!',3); return false; }
	
	// Verify captcha
	$.ajax
	({
		type: "POST",
		url: "ajax/ajax_send_enquiry.php",
		data: "code="+escape(code)+"&rand="+Math.random(),
		async: false,
		success: function(msg)
		{		
			if ( msg == '1' )	
				returnVal = true;				
			else 
			{					
				inlineMsg('code','<b>Invalid code!</b> <br> Please specify exactly the Security Code shown in the image.',3);
			}
		},
		error: function(msg) 
		{
		        alert("Invalid request!\n"+msg);
		}
	});
	
	if(returnVal)
	{
		//ascund butonul
		$(".loading-ajax").show();
		$("#submit").hide();
	}
	return returnVal;
}

function validateEmail(emailad) {
		
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,4}$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return true;
	}
	else {
		return false;
	}
}
