//email validation
function echeck(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					
	}

function hideEnqResponse(){
	document.getElementById("enqResponse").innerHTML		=	"";
	document.getElementById("enqResponse").style.display	=	"none";
}
function sendEnquiry(frm){
		name		=	frm.cname.value
		address		=	frm.address.value
		city		=	frm.city.value
		country		=	frm.country.value
		mobile		=	frm.mobile.value
		email		=	frm.email.value
		query		=	frm.query.value
		about		=	frm.about.value
		
		errorno		=	1;
		errormsg	=	"Error while submitting enquiry form\n"
		error		=	false
		
		if(name==''){
			errormsg+=" \n\t" + errorno +") Please enter the name";
			error = true
			errorno++;
		}
		if(address==''){
			errormsg+=" \n\t" + errorno +") Please enter the address";
			error = true
			errorno++;
		}
		if(city==''){
			errormsg+=" \n\t" + errorno +") Please enter the city";
			error = true
			errorno++;
		}
		if(country==''){
			errormsg+=" \n\t" + errorno +") Please enter the country";
			error = true
			errorno++;
		}
		if(mobile==''){
			errormsg+=" \n\t" + errorno +") Please enter the phone / mobile number";
			error = true
			errorno++;
		}
		if(email==''){
			errormsg+=" \n\t" + errorno +") Please enter the email address";
			error = true
			errorno++;
		}else{
			if(echeck(email)==false){
				errormsg+=" \n\t" + errorno +") Invalid email address";
				error = true
				errorno++;
			}
		}
		if(query==''){
			errormsg+=" \n\t" + errorno +") Please enter the query";
			error = true
			errorno++;
		}
		
		if(error){
			alert(errormsg);
			return false;
		}else{
				document.getElementById("enqResponse").style.display	=	"block"
				$("#enqResponse").html('<img src="js/loadingAnimation.gif" border="0"/>');
				$.ajax({
					type: "POST",
					url: "sendEnq.php",
					data: 	"Name=" + name + 
							"&Email=" + email +
							"&Phone=" + mobile +
							"&Address=" + address +
							"&City=" + city  +
							"&Country=" + country  +
							"&EnquiryAbout=" + about  +
							"&EnquiryDetails=" + query,
					success: function(html){
						$("#enqResponse").html(html);
						frm.reset();
						setTimeout("hideEnqResponse()",5000)
					}
				});
				}
		}
		
		
		
function sendMiniEnq(frm){
		name		=	frm.cname.value
		email		=	frm.email.value
		phone		=	frm.phone.value
		query		=	frm.query.value
		
		errorno		=	1;
		errormsg	=	"Error while submitting enquiry form\n"
		error		=	false
		
		if(name==''){
			errormsg+=" \n\t" + errorno +") Please enter the name";
			error = true
			errorno++;
		}
		if(email==''){
			errormsg+=" \n\t" + errorno +") Please enter the email address";
			error = true
			errorno++;
		}else{
			if(echeck(email)==false){
				errormsg+=" \n\t" + errorno +") Invalid email address";
				error = true
				errorno++;
			}
		}
		if(query==''){
			errormsg+=" \n\t" + errorno +") Please enter the query";
			error = true
			errorno++;
		}
		
		if(error){
			alert(errormsg);
			return false;
		}else{
				document.getElementById("enqResponseMini").style.display	=	"block"
				//alert("sendEnq.php?Name=" + name + "&Email=" + email + "&EnquiryDetails=" + query)
				//return false;
				$("#enqResponseMini").html('<img src="js/loadingAnimation.gif" border="0"/>');
				$.ajax({
					type: "POST",
					url: "sendEnqMini.php",
					data: 	"Name=" + name + 
							"&Email=" + email +
							"&Phone=" + phone +
							"&EnquiryDetails=" + query,
					success: function(html){
						$("#enqResponseMini").html(html);
						frm.reset();
						setTimeout("hideEnqResponseMini()",5000)
					}
				});
				}
		}
		
function hideEnqResponseMini(){
	document.getElementById("enqResponseMini").innerHTML		=	"";
	document.getElementById("enqResponseMini").style.display	=	"none";
}

