function Validate(theForm)
{
	var errMesg = "";
	var diplayMesg = ""
	var Q = ""; // this block determines lifespan of Q
	if (isWhitespace(theForm.email.value))
	{
		Q += "  Email Address\n";
	}
	else if(echeck(theForm.email.value))
	{
	   errMesg += "Invalid Email Address.\n";
	}
	/*
	else if(!isCharsInBag(theForm.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
	{
	  errMesg += "Email Address contains Invalid Characters.\n";
	}
	*/
	//Check for password
	if (isWhitespace(theForm.password.value))
	{
		Q += "  Password\n";
	}
	else if ((theForm.password.value.length < 6) ||  (theForm.password.value.length > 12))
	{
		errMesg += "Password should be 6-12 chars.\n";
	}
	else if ( theForm.password.value != theForm.cpassword.value)
	{
		errMesg += "Your passwords do not match. Please retype and try again.\n" ;
	}

	// Check all the Required Information fields.
	{
	
	if (isWhitespace(theForm.firstname.value))
	{
		Q += "  First Name\n";
	}
	if (isWhitespace(theForm.lastname.value))
	{
		Q += "  Last Name\n";
	}
	/*
	if (isWhitespace(theForm.company.value))
	{
		Q += "  Company Name\n";
	}
	*/
	if (isWhitespace(theForm.address.value))
	{
		Q += "  Street Address\n";
	}	
	else if(theForm.address.value.length>500)
	{
		errMesg += "Address should not be greater than 500 characters\n";
	}
	if (isWhitespace(theForm.city.value))
	{
		Q += "  City\n";
	}
	if (theForm.country.value==0)
	{
		Q += "  Country\n";
	}


	/*if (theForm.country.value!=0)
	{
		if (theForm.country.value!=1 && theForm.region.value=="")
		{	
			Q += "  Region\n";
		}

		if (theForm.country.value==1 && theForm.state.value=="")
		{
			Q += "  State\n";
		}
	}*/
	if (isWhitespace(theForm.zipcode.value))
	{
		Q += "  Zip Code\n";
	}

	if (isWhitespace(theForm.phone.value))
	{
		Q += "  Day Phone\n";
	}
	/*
	else if(!isCharsInBag(theForm.phone.value,"0123456789- "))
	{
	  errMesg += "Phone contains Invalid Characters.\n";
	}
	*/
	if(!isWhitespace(theForm.companyemail.value))
	{
		if(echeck(theForm.companyemail.value))
		{
		   errMesg += "Invalid Company Email Address.\n";
		}
		/*
		else if(!isCharsInBag(theForm.companyemail.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
		{
		  errMesg += "Company Email Address contains Invalid Characters.\n";
		}
		*/
	}
	/*
	if (!isWhitespace(theForm.website.value))
	{
		var website=theForm.website.value;
		//webRE=/^[wW]{3}\.[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
		webRE=/^[wW]{3}\.[a-zA-Z0-9._-]+\.[a-zA-Z/]/;
		if(!website.match(webRE))
		{
			errMesg +="Please check the website address\nEx:www.test.com\n";
		}
	}
	*/

	if(theForm.distributor_info.value != '')
	{
		var char_count = theForm.distributor_info.value.length;
		var fullStr = theForm.distributor_info.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		//var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var non_alphanumerics_rExp = rExp = /\s+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		if (fullStr.length <2) {
		word_count = 0;
		}

		if (word_count > 75) {
			errMesg += "Distributors/Wholesalers Should be 75 Words.\n";
		}
	}

	if(theForm.mis_info.value != '')
	{
		var char_count = theForm.mis_info.value.length;
		var fullStr = theForm.mis_info.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		//var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var non_alphanumerics_rExp = rExp = /\s+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		if (fullStr.length <2) {
		word_count = 0;
		}

		if (word_count > 75) {
			errMesg += "Miscellaneous Order Information Should be 75 Words.\n";
		}
	}


//Add   validation 
			/*
			if (isWhitespace(theForm.billing_company.value))
			{
				Q += "  Catalog Company Name\n";
			}
			*/
			if (isWhitespace(theForm.billing_city.value))
			{
				Q += "  Catalog City\n";
			}
			
			/*if (theForm.billing_state.value=="")			
			{
					Q += "  Catalog State\n";
			}*/
			if (theForm.billing_country.value==0)
			{
				Q += "  Catalog Country\n";
			}
		
			/*if (theForm.billing_country.value!=0)
			{
				if (theForm.billing_country.value!=1 && theForm.billing_region.value=="")
				{	
					Q += "  Catalog Region\n";
				}
				
				if (theForm.billing_country.value==1 && theForm.billing_state.value=="")			
				{
					Q += "  Catalog State\n";
				}
			}*/
			if (isWhitespace(theForm.billing_zipcode.value))
			{
				Q += "  Catalog Zip Code\n";
			}
		
			if(!isWhitespace(theForm.billing_companyemail.value))
			{
				if(echeck(theForm.billing_companyemail.value))
				{
				   errMesg += "Invalid Company Email Address.\n";
				}
				/*
				else if(!isCharsInBag(theForm.billing_companyemail.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
				{
				  errMesg += "Company Email Address contains Invalid Characters.\n";
				}
				*/
			}


//End billing conditions




	if(!theForm.terms.checked){
		errMesg +="Please read and understand Terms and Conditions";
	}
	if ( Q.length > 0 )
	{
		diplayMesg = "Please provide Valid values for\n" + Q ;
		//errMesg += "Please provide Valid values for\n" + Q ;
	
	}

	if (errMesg == "" && diplayMesg == "")
	{
		//theForm.submit();
		
	}
	
	else
	{
	
			if(diplayMesg!="")
			{
				alert(diplayMesg);
				return false;			
			}
			else
			{
				alert(errMesg);
				return false;
			}	
	}
   }
   
   if(theForm.billaddress.checked==true)
   {
	   theForm.billing_address.value=1;
   }
   else
   {
	 theForm.billing_address.value=0;
   }
  
}




function delivery()
{ 	
  if (document.form1.billaddress.checked)
  {
       document.form1.billing_firstname.value	=	document.form1.firstname.value;
	   document.form1.billing_lastname.value	=	document.form1.lastname.value;
	   document.form1.billing_email.value		=	document.form1.email.value;	   	   
   	   document.form1.billing_company.value		=	document.form1.company.value;
	   document.form1.billing_address1.value	=	document.form1.address.value;
	   document.form1.billing_city.value		=	document.form1.city.value;
	   document.form1.billing_state.value		=	document.form1.state.value;
	   document.form1.billing_region.value		=	document.form1.region.value;
	   document.form1.billing_zipcode.value		=	document.form1.zipcode.value;
	   document.form1.billing_fax.value			=	document.form1.fax.value;
	   document.form1.billing_country.value		=	document.form1.country.value;
	   document.form1.billing_phone.value		=	document.form1.phone.value;
	   document.form1.billing_companyemail.value=	document.form1.companyemail.value;
	   document.form1.billing_website.value		=	document.form1.website.value;
	   
	   
	   /*document.form1.billing_firstname.readOnly	=	true;
	   document.form1.billing_lastname.readOnly		=	true;
	   document.form1.billing_email.readOnly		=	true;   	   
   	   document.form1.billing_company.readOnly		=	true;
	   document.form1.billing_address1.readOnly		=	true;
	   document.form1.billing_city.readOnly			=	true;
	   document.form1.billing_state.readOnly		=	true;
	   document.form1.billing_region.readOnly		=	true;
	   document.form1.billing_zipcode.readOnly		=	true;
	   document.form1.billing_fax.readOnly			=	true;
	   document.form1.billing_country.readOnly		=	true;
	   document.form1.billing_phone.readOnly		=	true;
	   document.form1.billing_companyemail.readOnly	=	true;
	   document.form1.billing_website.readOnly		=	true;*/

   }
   else
   {
	   /*document.form1.billing_firstname.readOnly	=	false;
	   document.form1.billing_lastname.readOnly		=	false;
	   document.form1.billing_email.readOnly		=	false;   	   
   	   document.form1.billing_company.readOnly		=	false;
	   document.form1.billing_address1.readOnly		=	false;
	   document.form1.billing_city.readOnly			=	false;
	   document.form1.billing_state.readOnly		=	false;
	   document.form1.billing_region.readOnly		=	false;
	   document.form1.billing_zipcode.readOnly		=	false;
	   document.form1.billing_fax.readOnly			=	false;
	   document.form1.billing_country.readOnly		=	false;
	   document.form1.billing_phone.readOnly		=	false;
	   document.form1.billing_companyemail.readOnly	=	false;
	   document.form1.billing_website.readOnly		=	false;*/
        
	   document.form1.billing_firstname.value	=	"";
	   document.form1.billing_lastname.value	=	"";
	   document.form1.billing_email.value		=	"";   	   
   	   document.form1.billing_company.value		=	"";
	   document.form1.billing_address1.value	=	"";
	   document.form1.billing_city.value		=	"";
	   document.form1.billing_state.value		=	"";
	   document.form1.billing_region.value		=	"";
	   document.form1.billing_zipcode.value		=	"";
	   document.form1.billing_fax.value			=	"";
	   document.form1.billing_country.value		=	1;
	   document.form1.billing_phone.value		=	"";
	   document.form1.billing_companyemail.value=	"";
	   document.form1.billing_website.value		=	"";	   
     }
}