function changeCaptcha(){
	ran = Math.floor(Math.random()*10000);
	document.getElementById('captcha').src = 'CaptchaSecurityImages.php?width=60&height=22&characters=5&rand='+ran;
}

function sendForm(){
		var URL = 'send_mail.php';
		var aj = new Ajax.Request(URL,{method: 'POST',
			parameters: Form.serialize($('form1')),
			onComplete: getResponse
 		});
	}
function getResponse(oReq) {  
	if(oReq.responseText == 'wrong'){
		var strError1 = "<b>Please correct the following errors .</b><br>";
		Modalbox.show('<span class="error">'+strError1+'Please enter valid security code</span>', {title: 'Status', width: 400});
		return false;
	}else{
		clearForm();
		changeCaptcha();
		Modalbox.show('<span class="style1">Thanks for contact. <br/>We will contact you shortly to plan our visit.</span>', {title: 'Status', width: 400});
		return true
	}
}  

function validate_contact(){
	var f				= $('form1');	
	var name			= f.name;
	var email			= f.email;
	var phone			= f.phone;
	var cname			= f.cname;
	var message			= f.message;
	var security_code	= f.security_code;
	var strError		= "";		 

	if(name.value == null || name.value == ""){
		strError += "Please enter your name.<br/>";
	}
	
	if(email.value == null || email.value == ""){
		strError += "Please enter email.<br/>";
	}
	else if(!_email(email.value)){
		strError += "Please enter valid email.<br/>";
	}
	if(phone.value == null || phone.value == ""){
		strError += "Please enter phone number.<br/>";
	}
	if(cname.value == null || cname.value == ""){
		strError += "Please enter your company name.<br/>";
	}
	if(message.value == null || message.value == ""){
		strError += "Please enter your message.<br/>";
	}
	if(security_code.value == null || security_code.value == ""){
		strError += "Please enter security code.";
	}
	if(strError != ""){
		var strError1 = "<b>Please correct the following errors</b><br>";
		Modalbox.show('<span class="error">'+strError1+strError+'</span>', {title: 'Status', width: 400});
		return false;
	}
	else{

		return true;
	}
}

function clearForm(){
	/*var f				= $('form1');	
	var name			= f.name;
	var email			= f.email;
	var phone			= f.phone;
	var cname			= f.cname;
	var website			= f.website;
	var message			= f.message;
	var security_code	= f.security_code;
	name.value			= "";
	cname.value			= "";
	email.value			= "";
	website.value		= "";
	phone.value			= "";
	message.value		= "";
	security_code.value = "";*/
}

function _email(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
		   	return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		}
		if (str.indexOf(dot,(lat+2))==-1){
		    return false;
	 	}
		if (str.indexOf(" ")!=-1){
		    return false;
		}

 		return true;
}