function valid_required(field)
{
		 var pattern = /[\S]/;
		 var match = field.match(pattern);
		 
         if(field=="" || match == null){
         return false;
         }
         
    return true;
}

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					
	}
	
	function focus_message(){
		if(document.myform.message.value=="Message"){
			document.myform.message.value='';
			document.myform.message.focus();
			return;
		}
		
	}

	function valForm1()
{

        if(!valid_required(document.myform.first_name.value) || document.myform.first_name.value=="Name")
        {
			alert("First Name is a required field!")
			document.myform.first_name.focus();
			return false;
        }
        if(!valid_required(document.myform.last_name.value) || document.myform.last_name.value=="Name")
        {
			alert("Last Name is a required field!")
			document.myform.last_name.focus();
			return false;
        }
		
		if(!valid_required(document.myform.phone.value) || document.myform.phone.value=="Phone")
        {
			alert("Phone is a required field!")
			document.myform.phone.focus();
			return false;
        }		
			
		if(!echeck(document.myform.email.value))
		{
			document.myform.email.focus();
			return false;
			
		}
		
        if(!valid_required(document.myform.elements[8].value)) //This is referring to the Services field. Can't use the field name because it starts w/ numeric. This is an auto-generated field by Salesforce, so we can't change the name.
        {
			alert("Services is a required field!")
			document.myform.elements[8].focus();
			return false;
        }
        
	document.myform.retURL.value="http://www.cdgnow.com/include/form.asp?fname="+document.myform.first_name.value+"&lname="+document.myform.last_name.value+"&email="+document.myform.email.value+"&phone="+document.myform.phone.value+"&company="+document.myform.company.value+"&source="+document.myform.lead_source.value+"&spam_checker="+document.myform.spam_checker.value;
	//document.myform.retURL.value="http://www.cdgnow.com/services/engineeringservices/form.asp?fname="+document.myform.first_name.value+"&lname="+document.myform.last_name.value+"&email="+document.myform.email.value+"&phone="+document.myform.phone.value+"&company="+document.myform.company.value+"&source="+document.myform.lead_source.value+"&spam_checker="+document.myform.spam_checker.value;
		
    return true;
}

function valForm2()
{
        if(!valid_required(document.myform2.name.value) || document.myform2.name.value=="Name")
        {
			alert("Name is a required field!")
			document.myform2.name.focus();
			return false;
        }
		
		if(!valid_required(document.myform2.company.value) || document.myform2.company.value=="Name")
        {
			alert("Company Name is a required field!")
			document.myform2.company.focus();
			return false;
        }
		
		if(!valid_required(document.myform2.address.value) || document.myform2.address.value=="Name")
        {
			alert("Address is a required field!")
			document.myform2.address.focus();
			return false;
        }
		
		if(!valid_required(document.myform2.phone.value) || document.myform2.phone.value=="Phone")
        {
			alert("Phone is a required field!")
			document.myform2.phone.focus();
			return false;
        }	
		
		if(!echeck(document.myform2.email.value))
		{
			document.myform2.email.focus();
			return false;
			
		}
					
    return true;
}