// JavaScript Document

function chex()
{
	
	if(document.form1.name.value == "")	
	{
	document.form1.name.focus();
	alert("Please enter your name.");
	document.form1.name.style.backgroundColor="#FF9900";
	return false;
	}
	
	if(document.form1.phone.value == "")	
	{
	document.form1.phone.focus();
	alert("Please enter your phone number.");
	document.form1.phone.style.backgroundColor="#FF9900";
	return false;
	}

if (document.form1.email.value=='')
	{
	alert('You must enter a valid email address to proceed');
	document.form1.email.focus();
	document.form1.email.style.backgroundColor="#FF9900";
	return false;
	}
	
	if (echeck(document.form1.email.value)==false){
		document.form1.email.value=""
		document.form1.email.focus()
  		document.form1.email.style.backgroundColor="#FF9900";
		return false
	}
		if(document.form1.description.value == "")	
	{
	document.form1.description.focus();
	alert("Please describe your jewelry.");
	document.form1.description.style.backgroundColor="#FF9900";
	return false;
	}
		if(document.form1.security_code.value == "")	
	{
	document.form1.security_code.focus();
	alert("Please enter security code as showing.");
	document.form1.security_code.style.backgroundColor="#FF9900";
	return false;
	}
}	
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 Address \r Please enter a valid email address \re.g. you@domain.com")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address \r Please enter a valid email address \re.g. you@domain.com")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		     alert("Invalid E-mail Address \r Please enter a valid email address \re.g. you@domain.com")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		     alert("Invalid E-mail Address \r Please enter a valid email address \re.g. you@domain.com")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			 alert("Invalid E-mail Address \r Please enter a valid email address \re.g. you@domain.com")		
			 return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
 			alert("Invalid E-mail Address \r Please enter a valid email address \re.g. you@domain.com")
			return false
		 }
		 
		
		 if (str.indexOf(" ")!=-1){
		 alert("Invalid E-mail Address \r Please enter a valid email address \re.g. you@domain.com")		
		 return false
		 }

 		 return true					
	}
