// trim function for check space
function trim(myString){
 
   return myString.replace( /^\s+/g,'').replace(/\s+$/g,'');
   
}
/// function for check 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){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
///end here email check validation

//////// function for newsletter form////
function check(){
	x = document.frm_newsletter;
	//email validation
	var emailID=x.email;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID!")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}//end of mail validation
	
	
	return true;
}


//////// function for enquiry page///////////
function checkEnquiry(){
	x = document.enquiry;
	
	var emailID=x.email;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID!")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}//end of mail validation
	
	str = trim(x.home_tel.value);
	if(str == ""){
		alert("Please enter Home Telephone");
		x.home_tel.value = "";
		x.home_tel.focus();
		return false;
	}
	
	str = trim(x.mob_tel.value);
	if(str == ""){
		alert("Please enter Mobile Number");
		x.mob_tel.value = "";
		x.mob_tel.focus();
		return false;
	}
	
	str = trim(x.address.value);
	if(str == ""){
		alert("Please enter Address");
		x.address.value = "";
		x.address.focus();
		return false;
	}
	
	str = trim(x.pcode.value);
	if(str == ""){
		alert("Please enter Postal Code");
		x.pcode.value = "";
		x.pcode.focus();
		return false;
	}
}


//////// function for contact us page///////////
function checkContactUs(){
	x = document.contactus;
	
	str = trim(x.name.value);
	if(str == ""){
		alert("Please enter Name");
		x.name.value = "";
		x.name.focus();
		return false;
	}

	var emailID=x.email;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID!")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}//end of mail validation
	
	str = trim(x.home_tel.value);
	if(str == ""){
		alert("Please enter Home Telephone");
		x.home_tel.value = "";
		x.home_tel.focus();
		return false;
	}
	
	str = trim(x.mob_tel.value);
	if(str == ""){
		alert("Please enter Mobile Number");
		x.mob_tel.value = "";
		x.mob_tel.focus();
		return false;
	}
	
	str = trim(x.frequest.value);
	if(str == ""){
		alert("Please enter Request");
		x.frequest.value = "";
		x.frequest.focus();
		return false;
	}
	
	str = trim(x.address.value);
	if(str == ""){
		alert("Please enter Address");
		x.address.value = "";
		x.address.focus();
		return false;
	}
}



//////// function for contact us page///////////
function checkAdvertisementForm(){
	x = document.adverstisement;

	str = trim(x.name.value);
	if(str == ""){	
		alert("Please Enter Name");
		x.name.value = "";
		x.name.focus();
		return false;
	}
	
	var emailID=x.email;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID!")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}//end of mail validation
	
	str = trim(x.phonenumber.value);
	if(str == ""){	
		alert("Please Enter Phone Number");
		x.phonenumber.value = "";
		x.phonenumber.focus();
		return false;
	}
	str = trim(x.address.value);
	if(str == ""){	
		alert("Please Enter Address");
		x.address.value = "";
		x.address.focus();
		return false;
	}
	str = trim(x.category.value);
	if(str == "0"){	
		alert("Please Select Category");
		x.category.focus();
		return false;
	}
	
	
	
	str = trim(x.pname.value);
	if(str == ""){	
		alert("Please Enter Product Name");
		x.pname.value = "";
		x.pname.focus();
		return false;
	}


	str = trim(x.pcode.value);
	if(str == ""){
		alert("Please Enter Product Code");
		x.pcode.value = "";
		x.pcode.focus();
		return false;
	}
	
	str = trim(x.description.value);
	if(str == ""){
		alert("Please Enter Description");
		x.description.value = "";
		x.description.focus();
		return false;
	}
	
	str = trim(x.dimensions.value);
	if(str == ""){
		alert("Please Enter Dimensions");
		x.dimensions.value = "";
		x.dimensions.focus();
		return false;
	}
}



