var allFields=true;
var validEmail;
//var allRadio;
//var allChBox;

function validateMail()
{
	var mail = document.forms[0].Email;
	var dot = mail.value.indexOf(".");
	var lastdot = mail.value.lastIndexOf(".");
	var len = mail.value.length;
	var at = mail.value.indexOf("@");
	var at2 = mail.value.lastIndexOf("@");
	
	if (!(len-lastdot>=3 && len-lastdot<=4 && at>0 && lastdot-at>1 && at==at2)||(at == "-1" || dot == "-1")||(mail.value==""))
	{
		alert("Please provide your valid email address!");
		mail.focus();
		allFields=false;
		validEmail=false;
		return false;
	}

allFields=true;
validEmail=true;
Check();
}

/*function CheckRadio()
{
	var elm=document.forms[0].elements;
	for(j=10; j<14; j++) 
	{	
		if(elm[j].type=="radio" && elm[j].checked==true)
		{
			allRadio=true;
			ValidCheckBoxs();
			break;
		}
		else
		{
			allRadio=false;
		}
	}
	if(allRadio==false && allFields==true){
	alert("Please select the type of business.");
	}
}*/

/*function ValidCheckBoxs()
{
	var elm=document.forms[0].elements;
	for(j=11; j<19; j++) 
	{	
		if(elm[j].type=="checkbox" && elm[j].checked==true)
		{
			allChBox=true;
			document.forms[0].submit();
			break;
		}
		else
		{
			allChBox=false;
		}
	}
	if(allChBox==false){
	alert("Please select the type of Operating system.");
	}
}*/

function TestDigit(re,str,fieldName)
{                                 
    // Test string for existence of regular expression.
    if (re.test(str)) 
	{   //Test for existence.
        alert("Please enter only digit, whitespace, parentheses, \"+\" or \"-\" characters in the "+fieldName+" field.");
		return ("");
	}
    else
    {  
    	rExp = /(\-+)/g;
		str1 = str.replace(rExp, "-");
		return(str1);
    }
}

function Check()
{	
	var elm=document.forms[0].elements;
	for(j=0; j<9; j++) 
	{	
		if(elm[j].value=="" && elm[j].name!="State") //State is optional
		{
			elm[j].focus();
			alert("Please enter a value for the "+elm[j].name+" field.");
			allFields=false;
			return false;
		}
		if(elm[j].value!="" && (elm[j].name=="Phone" || elm[j].name=="Fax" || elm[j].name=="Zip"))
		{
			rExp = /[^0-9,\(,\),+," ",-]/g;
			elm[j].value=TestDigit(rExp,elm[j].value,elm[j].name);
			if(elm[j].value==""){
			elm[j].focus();
			return false;
			}
		}
		if(elm[j].value!="" && (elm[j].name=="Email" && validEmail==false) || (elm[j].name=="Email" && validEmail==undefined))
		{
			allFields=false;
			validateMail();
			return false;
		}
	}
	document.forms[0].action="submit_request.asp";
	document.forms[0].submit();
	/*if(validEmail!=false && validEmail!=undefined)
	{
		CheckRadio();
	}*/
}
 
function check_key()
{
	if (event.keyCode==13) 
	{
	  Check();
	}  
}
 
function focus()
{
	if(document.forms[0]!=null) document.forms[0].Company.focus();
}	

