function Validateform()
{

		if (document.form1.namefield.value=='' || document.form1.namefield.value.length < 2)
		{
				alert("Please enter a valid name.");
				document.form1.namefield.focus();
				return false;
		}

 		if (document.form1.email.value=='')
		{
			alert("Please enter a valid email.");
			document.form1.email.focus();
			return false;
		}
		if (!isEmailAddr(document.form1.email.value))
		  {
			alert("Please enter a complete valid email address in the format: yourname@yourdomain.com");
			document.form1.email.focus();
			return (false);
		  }

		if (document.form1.phonefield.value=='')
		{
			alert("Please enter Phone Number.");
			document.form1.phonefield.focus();
			return false;
		}

		var phonerrormsg = validatePhone(document.form1.phonefield);

		if (phonerrormsg.length > 0 )
		{
			alert(phonerrormsg);
			document.form1.phonefield.focus();
			return false;
		}


 

 

		//document.form1.submit.disabled=true;
//alert('b4');
		document.form1.action="http://www.rugwashinc.com/thankspage.asp";
					return true;
}



function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Please enter a valid phone number with area code.\n";
        //fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "Please enter a valid phone number with area code.\n";
        //fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "Please enter a valid phone number with area code.\n";
        //fld.style.background = 'Yellow';
    }
    return error;
}

function check_usphone(phonenumber,useareacode)
{
	if(!useareacode)useareacode=1;
	if((phonenumber.match(/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null) && ((useareacode!=1) && (phonenumber.match(/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null))) 
	{
		alert("false");
		return false;
	}
	
	return true;
} 

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
