function submitt() {
var str = false; 
getReferrerURL();
str = salesvalidation();
if (str) {
 document.forms['sales'].submit(); }
}

function getReferrerURL() {


var sitepathURL = self.document.forms['sales'].referrer.value;

var count = sitepathURL.indexOf("?");
var filepathURL;

if (count > 0)  {
	filepathURL = sitepathURL.substring(0,count);  }
else  {
	filepathURL = sitepathURL;  }
var countURL = filepathURL.indexOf("/servlet/wtb_search");

if (countURL != -1) {
 self.document.forms['sales'].referrer.value = "/industrialsystems/wheretobuy.shtml";  }

}

function salesvalidation(){
	//Validations for Most Common field for all the Forms Start Here
	
	//Validations for First Name start here 
	
	/*  Steps and Content of what has been validated
	1.) The value is being trimmed so that it does not contain any blank spaces.
	2.) It is being validated for null value as it is a compusary field
	3.) Then it is Being checked that the length is greater than one 
	4.) It is Being validated for blank spaces if it contains total blank spaces.
	5.) Next it is being validated for character so that it contaians only alphabetic character.
	6.) The first Character Is being Converted to Upper Case
	*/

	// step 1 as described above	
	if (textvalidation(document.forms['sales'].first_name,"Please enter a valid First Name")==false) 
	{
	document.forms['sales'].first_name.focus();
	return false;
	}
	
	// step 2 as described above
	if(document.forms['sales'].first_name.value != "")
	document.forms['sales'].first_name.value = trimStr(document.forms['sales'].first_name); 

	// step 3 as Described above
	var tempfname = document.forms['sales'].first_name.value
	
	if(tempfname.length < 2)
	{
	alert("Please Enter a Proper First Name");
	document.forms['sales'].first_name.focus();
	document.forms['sales'].first_name.select();
	return false;
	}
	//Step 4 as Described above
	if(blankvalidation(document.forms['sales'].first_name,"Please enter a valid First Name")==false)
	{
	document.forms['sales'].first_name.focus();
	document.forms['sales'].first_name.select();
	return false;
	};
	//Step 5 as described above
	if(charvalidation(document.forms['sales'].first_name.value,"Please enter a valid First Name")==false){
	document.forms['sales'].first_name.focus();
	document.forms['sales'].first_name.select();
	return false;
	};
	//Step 6 as Described above
	var con = document.forms['sales'].first_name.value;
	document.forms['sales'].first_name.value = (con.charAt(0)).toUpperCase()+ con.substring(1,con.length);
	/* validations of First name end in above line */

	//Validations for Last Name Begin here
	
	/*  Steps and Content of what has been validated
	1.) The value is being trimmed so that it does not contain any blank spaces.
	2.) It is being validated for null value as it is a compusary field
	3.) Then it is Being checked that the length is greater than one 
	4.) It is Being validated for blank spaces if it contains total blank spaces.
	5.) Next it is being validated for character so that it contaians only alphabetic character.
	6.) The first Character Is being Converted to Upper Case
	*/
	
	// Step 1 as Described above
	document.forms['sales'].last_name.value = trimStr(document.forms['sales'].last_name);
	// Step 2 as Described above
	if (textvalidation(document.forms['sales'].last_name,"Please enter a valid Last Name")==false)
	{
	document.forms['sales'].last_name.focus();	
	return false;
	};
	// Step 3 as Described above
	var templname = document.forms['sales'].last_name.value;
	if(templname.length < 2)
	{
	alert("Please Enter a Proper Last Name");
	document.forms['sales'].last_name.focus();
	document.forms['sales'].last_name.select();
	return false;
	}
	//Step 4 as Described above
	if(blankvalidation(document.forms['sales'].last_name,"Please enter a valid Last Name")==false)
	{
	document.forms['sales'].last_name.focus();
	document.forms['sales'].last_name.select();
	return false;
	};
	//Step 5 as Described above
	if(charvalidation(document.forms['sales'].last_name.value,"Please enter a valid Last Name")==false){
	document.forms['sales'].last_name.focus();
	document.forms['sales'].last_name.select();
	return false;
	};
	//Step 6 as Described above
	var con = document.forms['sales'].last_name.value;
	document.forms['sales'].last_name.value = (con.charAt(0)).toUpperCase()+ con.substring(1,con.length);
	
	/* Validations for Last Name End in above line */

	//Validations For Middle Name Start Here
	
	/*  Steps and Content of what has been validated
	1.) The value is being trimmed so that it does not contain any blank spaces.
	2.) It is Being validated for blank spaces if it contains total blank spaces.
	3.) Next it is being validated for character so that it contaians only alphabetic character.
	4.) All Characters are Converted to Upper Case
	*/

	if(document.forms['sales'].middle_name.value!="")
	{
	//Step 1 as described above
	document.forms['sales'].middle_name.value = trimStr(document.forms['sales'].middle_name);
	//Step 2 as described above
	if(blankvalidation(document.forms['sales'].middle_name,"Please enter a valid Middle Name")==false)
	{
	document.forms['sales'].middle_name.focus();
	document.forms['sales'].middle_name.select();
	return false;
	};
	//step 3 as described above
	if(charvalidation(document.forms['sales'].middle_name.value,"Please enter a valid Middle Name")==false){
	document.forms['sales'].middle_name.focus();
	document.forms['sales'].middle_name.select();
	return false;
	};
	//Step 4 as Described above
	var con = document.forms['sales'].middle_name.value;
	document.forms['sales'].middle_name.value = con.toUpperCase(); 
	}
	
	/* Validations For Middle Name End here */
	
	//Validations For E-mail Start Here
	
	/*  Steps and Content of what has been validated
	if Communication Mode Is selected as email then this becomes a compulsary field otherwise Phone Number becomes compulsary field 
	1.) It is Being Validated for not null
	2.) It is Being checked whether the address contains one '@' Symbol and atleast one '.'.
	3.) Next it is checking whether after the dot there are either two or three characters only. 
	4.) all spaces enetered by user are being truncated.
	*/
	//Step 1 As Described Above
	
	
	//Step 4 as Dscribed Above
	document.forms['sales'].email.value = trimStr(document.forms['sales'].email);
	//Steps 2 and 3 as Described Above
	if (emailvalidation(document.forms['sales'].email,"Please Enter a valid E-mail Address")==false){
	document.forms['sales'].email.focus();
	document.forms['sales'].email.select();
	return false;
	};
	
	
	/* Validations For E-mail end here */
	
	//Validations For Phone Number Start Here

	/*  Steps and Content of what has been validated
	if Communication Mode Is selected as phone then this becomes a compulsary field otherwise email becomes compulsary field 
	1.) It is Being Validated for not null
	2.) It is Also Being checked so that user cannot enter only blank spaces
	3.) It Is being Checked to Accept Only numerals and some special Characters Such as '(',')','-' 
	4.) All spaces enetered by user are being truncated.
	*/
	
	//Step 1 Starts Here
	if(document.forms['sales'].contact[1].checked || document.forms['sales'].phone.value!="")
	{
	//Step 4 as desscribed above
	document.forms['sales'].phone.value = trimStr1(document.forms['sales'].phone);
	//Step 2 as Described Above
	if(blankvalidation(document.forms['sales'].phone,"Please Enter a valid Contact Number")==false)
	{
	document.forms['sales'].phone.focus();
	document.forms['sales'].phone.select();
	return false;
	};
	//Step 3 as described above
	if (phonenumbervalidation(document.forms['sales'].phone,"Please Enter a Valid Contact Number")==false)
	{
	document.forms['sales'].phone.focus();
	document.forms['sales'].phone.select();
	return false;
	}
	}
	
	/* Validations for phoneNumber End Here */
	
	//Company Validation Start Here
	
	/*  Steps and Content of what has been validated
	1.) It is Being Validated for not null as it is a compulsary field
	2.) It is Also Being checked so that user cannot enter only blank spaces
	3.) All unnecessary spaces entered by user are being truncated and replaced by a single space.
	*/
	
	if (textvalidation(document.forms['sales'].company,"Please enter a company Name")==false)
	{
	document.forms['sales'].company.focus();
	return false;
	};
	document.forms['sales'].company.value = trimStr1(document.forms['sales'].company);
	if(blankvalidation(document.forms['sales'].company,"Please enter a company Name")==false)
	{
	document.forms['sales'].company.focus();
	document.forms['sales'].company.select();
	return false;
	};

	/* Company Validation ends here */
	
	//Address1 Validation Start Here
	
	/*  Steps and Content of what has been validated
	1.) It is Being Validated for not null as it is a compulsary field
	2.) It is Also Being checked so that user cannot enter only blank spaces
	3.) All unnecessary spaces entered by user are being truncated and replaced by a single space.
	*/

	if (textvalidation(document.forms['sales'].address1,"Please enter the Address")==false)
	{
	document.forms['sales'].address1.focus();
	return false;
	};
	document.forms['sales'].address1.value = trimStr1(document.forms['sales'].address1);
	if(blankvalidation(document.forms['sales'].address1,"Please enter the Address")==false)
	{
	document.forms['sales'].address1.focus();
	document.forms['sales'].address1.select();
	return false;
	};
	var tempAddress1 = document.forms['sales'].address1.value;
	if(tempAddress1.length < 2)
	{
	alert("Please Enter a proper Address");
	document.forms['sales'].address1.focus();
	document.forms['sales'].address1.select();
	return false;
	}
	
	/* Address1 Validation ends here */

	//Address2 Validation Start Here
	
	/*  Steps and Content of what has been validated
	1.) It is Being checked so that user cannot enter only blank spaces
	2.) All unnecessary spaces entered by user are being truncated and replaced by a single space.
	*/

	if(document.forms['sales'].address2.value!="")
	{
	if (textvalidation(document.forms['sales'].address2,"please enter the Address")==false)
	{
	document.forms['sales'].address2.focus();
	return false;
	};
	if(blankvalidation(document.forms['sales'].address2,"please enter the Address")==false)
	{
	document.forms['sales'].address2.focus();
	document.forms['sales'].address2.select();
	return false;
	};
	document.forms['sales'].address2.value = trimStr1(document.forms['sales'].address2);
	}
	
	/* Address 2 Validation ends Here */

	//City validation starts here
	
	/*  Steps and Content of what has been validated
	1.) It is being validated for null value as it is a compusary field
	2.) The value is being trimmed so that it does not contain any extra blank spaces.
	3.) Then it is Being checked that the length is greater than two 
	4.) It is Being validated for blank spaces if it contains total blank spaces.
	5.) Next it is being validated for character so that it contains only alphabetic character and single spaces are allowed.
	6.) The first Character Is being Converted to Upper Case
	*/
	
	//Step 1 as Described Above
	if (textvalidation(document.forms['sales'].city,"Please enter a valid City Name")==false)
	{
	document.forms['sales'].city.focus();
	return false;
	};
	// Step 2 as Described Above
	document.forms['sales'].city.value = trimStr1(document.forms['sales'].city);
	//Step 3 as Described Above
	var tempCity = document.forms['sales'].city.value;
	if( tempCity.length < 2)
	{
	alert("Please Enter a Valid City Name");
	document.forms['sales'].city.focus();
	document.forms['sales'].city.select();
	return false;
	} 
	//Step 4 as described above
	if(blankvalidation(document.forms['sales'].city,"Please enter a valid City Name")==false)
	{
	document.forms['sales'].city.focus();
	document.forms['sales'].city.select();
	return false;
	};
	//Step 5 as described above
	if(charspacevalidation(document.forms['sales'].city.value,"Please enter a valid City Name")==false){
	document.forms['sales'].city.focus();
	document.forms['sales'].city.select();
	return false;
	};//Step 6 as Described Above
	var con = document.forms['sales'].city.value;
	document.forms['sales'].city.value = (con.charAt(0)).toUpperCase()+ con.substring(1,con.length);

	/* Validation of City Field Ends Here */
	
	//State Field validation starts here
	
	/*  Steps and Content of what has been validated
	1.) It is being validated for null value as it is a compusary field
	2.) The value is being trimmed so that it does not contain any extra blank spaces.
	3.) Then it is Being checked that the length is greater than one 
	4.) It is Being validated for blank spaces if it contains total blank spaces.
	5.) Next it is being validated for character so that it contains only alphabetic character and single spaces are allowed.
	6.) The first Character Is being Converted to Upper Case
	*/

	//Step 1 as Described above
	if (textvalidation(document.forms['sales'].state,"Please enter a valid State Name")==false)
	{
	document.forms['sales'].state.focus();
	return false;
	};
	//Step 2 as Described above
	document.forms['sales'].state.value = trimStr1(document.forms['sales'].state);
	//Step 3 as Described Above
	var tempState = document.forms['sales'].state.value;
	if( tempState.length < 2)
	{
	alert("Please Enter a Valid State Name");
	document.forms['sales'].state.focus();
	document.forms['sales'].state.select();
	return false;
	}
	//Step 4 as Described Above
	if(blankvalidation(document.forms['sales'].state,"Please enter a valid State Name")==false)
	{
	document.forms['sales'].state.focus();
	document.forms['sales'].state.select();
	return false;
	};
	//Step 5 as Described Above
	if(charspacevalidation(document.forms['sales'].state.value,"Please enter a valid State Name")==false)
	{
	document.forms['sales'].state.focus();
	document.forms['sales'].state.select();
	return false;
	};
	//Step 6 as described above
	var con = document.forms['sales'].state.value;
	document.forms['sales'].state.value = (con.charAt(0)).toUpperCase()+ con.substring(1,con.length);

	/* State Field Validation Ends Here */

	//Country Field validation starts here
	
	/*  Steps and Content of what has been validated
	1.) It is being validated for null value as it is a compusary field
	2.) The value is being trimmed so that it does not contain any extra blank spaces.
	3.) Then it is Being checked that the length is greater than one 
	4.) It is Being validated for blank spaces if it contains total blank spaces.
	5.) Next it is being validated for character so that it contains only alphabetic character and single spaces are allowed.
	6.) The first Character Is being Converted to Upper Case
	*/

	//Step 1 as Described above
	if (textvalidation(document.forms['sales'].country,"Please enter a valid Country Name")==false)
	{
	document.forms['sales'].country.focus();
	return false;
	};
	//Step 2 as Described above
	document.forms['sales'].country.value = trimStr1(document.forms['sales'].country);
	//Step 3 as Described Above
	var tempCountry = document.forms['sales'].country.value;
	if( tempCountry.length < 2)
	{
	alert("Please Enter a Valid Country Name");
	document.forms['sales'].country.focus();
	document.forms['sales'].country.select();
	return false;
	}
	//Step 4 as Described above
	if(blankvalidation(document.forms['sales'].country,"Please enter a valid Country Name")==false)
	{
	document.forms['sales'].country.focus();
	document.forms['sales'].country.select();
	return false;
	};
	//Step 5 as Described above
	if(charspacevalidation(document.forms['sales'].country.value,"Please enter a valid Country Name")==false)
	{
	document.forms['sales'].country.focus();
	document.forms['sales'].country.select();
	return false;
	};
	//Step 6 as Described above
	var con = document.forms['sales'].country.value;
	document.forms['sales'].country.value = (con.charAt(0)).toUpperCase()+ con.substring(1,con.length);

	/* Validation for Country Ends Here */
	
	//Zip code field validation starts here
	
	/*  Steps and Content of what has been validated
	1.) It is being validated for null value as it is a compusary field
	2.) It is Being validated for blank spaces if it contains total blank spaces.
	3.) Next it is being validated for numbers and spaces 
	*/
	
	//Step 1 as described above
	if (textvalidation(document.forms['sales'].zip_code,"Please enter a valid Zip Code")==false)
	{
	document.forms['sales'].zip_code.focus();
	return false;
	};
	//Step 2 as described above
	if(blankvalidation(document.forms['sales'].zip_code,"Please enter a valid Zip Code")==false)
	{
	document.forms['sales'].zip_code.focus();
	document.forms['sales'].zip_code.select();
	return false;
	};
	//Step 3 as described above
	if (zipcodevalidation(document.forms['sales'].zip_code,"Please enter a valid Zip Code")==false)
	{
	document.forms['sales'].zip_code.focus();
	document.forms['sales'].zip_code.select();
	return false;
	};
	
	/* zip code Validation Ends Here */
	
	/* The above Field are Common for Most OF the Forms */		
	
	//validations for Fields, Which are Specific to this form
	
	//validations for comments Start Here
	
	/*  Steps and Content of what has been validated
	1.) It is Being Checked as this Field Is a Compulsary one
	2.) All the Extra White Spaces Are Being Removed.
	3.) Max length of the field is also being checked
	4.) It is Being checked that entered fields are not in blank spaces
	*/

	//Step 1 as Described above
	if (textvalidation(document.forms['sales'].comments,"Please Enter your Comments")==false)
	{
	document.forms['sales'].comments.focus();
	return false;
	};
	//Step 2 as Described above
	document.forms['sales'].comments.value = trimStr1(document.forms['sales'].comments);
	//Step 3 as Described Above
	var tempComments = document.forms['sales'].comments.value;
	if( tempComments.length > 2039)
	{
	alert("Entered text exceeds the limit");
	document.forms['sales'].comments.focus();
	document.forms['sales'].comments.select();
	return false;
	}
	//Step 4 As Described Above
	if(blankvalidation(document.forms['sales'].comments,"Please Enter your Comments")==false)
	{
	document.forms['sales'].comments.focus();
	document.forms['sales'].comments.select();
	return false;
	};
	
	/* Validations For Comments Are Over */	
return true;
}
// function for trimming values
function trimStr(txtbox) {
var txtVal = txtbox.value;
var outstr = "";
	for( i=0;i<txtVal.length;i++) {
		if(txtVal.charAt(i) == ' ')
			continue;
		else{
			outstr +=txtVal.charAt(i);
		}
	}

	return outstr;
}
//end of triming function

// function for trimming blanks in between
function trimStr1(txtbox) {
var txtVal = txtbox.value;
var outstr = "";
var outstr1 = "";	
	for( i=0;i<txtVal.length;i++) {
		if((txtVal.charAt(i) == ' ' && txtVal.charAt(i+1) == ' ' ))
			continue;
		else{
			outstr +=txtVal.charAt(i);
		}
	}
	templen=outstr.length;
	if(outstr.charAt(0) == ' ')
	outstr1 = outstr.slice(1,templen)
	else
	{
	if(outstr.charAt(templen-1) == ' ')
	outstr1 = outstr.slice(0,templen-1);
	else
	outstr1 = outstr;
	}
	return outstr1;
}
//end of triming function

//text validation starts here
function textvalidation(entered,alertbox)
{
	with (entered)
	{
		if (entered.value==null || entered.value==""){
			if (alertbox!=""){
			alert(alertbox);}
		entered.focus();
		return false;
		}
		else
		{ return true; }
}
}//text validation ends here

//digit validation starts here
function digitvalidation(entered, min, max, alertbox, datatype)
{
	with (entered)
	{
	checkvalue=parseFloat(value);
		if (datatype){
		smalldatatype=datatype.toLowerCase();
			if (smalldatatype.charAt(0)=="i"){
			checkvalue=parseInt(value);
				if (value.indexOf(".")!=-1){
				checkvalue=checkvalue+1
				}
			};
		}
		if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue || checkvalue == 0){
			if (alertbox!=""){
			alert(alertbox);
			}
		entered.focus();
		entered.select();
		return false;
		}
		else
		{return true;}
	}
}//digit validation ends here

//New email validation starts here
function emailvalidation(entered,alertbox)
{
	tempEmail = entered.value;
	var lenEmail = tempEmail.length;
	var countEmail = 0;
	var tempFlag = 0;
	for(i=0;i<lenEmail;i++)
	{
		chrEmail = tempEmail.charAt(i);
		if(chrEmail == '@'){
		countEmail++;
		}
		if((chrEmail >= 'a' && chrEmail <= 'z')||(chrEmail >= 'A' && chrEmail <= 'Z') || chrEmail == '.' || chrEmail == '@'){
		tempFlag = 1;
		}
	}
	apos=tempEmail.indexOf("@");
	for(j=0;j<lenEmail;j++)
	 {
	 if(tempEmail.charAt(j) == '.')
	  {
		if(tempEmail.charAt(j+1) == '.')
		{
		alert(alertbox);
	 	return false;
		}
	   }
	 }
	dotpos=tempEmail.lastIndexOf(".");
	lastpos=tempEmail.length-1;
	if (apos < 1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || countEmail > 1 || tempFlag == 0){
		if (alertbox)
		{alert(alertbox);} 
		return false;
		entered.focus();
		entered.select();
		}
		else 
		{return true;}
}//New email validations ends here

//Blanks Validation Starts here
function blankvalidation(entered,alertbox)
{
	var found=1;
	str1=entered.value;
	for(var i=0;i<str1.length;i++)
	{
		if(str1.charAt(i) != " ")
		{
		found=0;
		break;
		}
	}
	if(found)
	{
		
		alert(alertbox);
		return false;
	}
	else
	return true; 
}//end of blankvalidation

//charcater validation function starts from next line

function charvalidation(name,alertbox)
{
	var temp=0;
	str=name.length;
	for(i=0;i<str;i++) 
	{
	str1=name.charAt(i)
		if( (str1 >= 'a' && str1 <= 'z')||(str1 >= 'A' && str1 <= 'Z') || (str1 == " ")) {
		temp=1;
		}
		else {
		temp=0;
		break;
		}
	}
	if(temp!=0)
	return true;
	else{
	if (alertbox) alert(alertbox);
	return false;
	}
}// end of character validation

// charcater and Space validation it Takes  Characters From a-z and A-Z and Also Spaces
function charspacevalidation(name,alertbox)
{
	var temp=0;
	str=name.length;
	for(i=0;i<str;i++) 
	{
	str1=name.charAt(i)
		if( (str1 >= 'a' && str1 <= 'z')||(str1 >= 'A' && str1 <= 'Z') || (str1 == ' ')) {
		temp=1;
		}
		else {
		temp=0;
		break;
		}
	}
	if(temp!=0)
	return true;
	else{
	alert(alertbox);
	return false;
	}
}// end of character With space validation

//phone number validation starts here
function phonenumbervalidation(entered,alertbox)
{
	var temp1=0;
	var phone=entered.value;
	strlen=phone.length;
	for(i=0;i<=strlen;i++) 
	{
	str1=phone.charAt(i)
		if((str1 == "-" )|| (str1 == "+" ) || (str1 =="(" ) || (str1 == ")" ) || (str1 == " " ) || isFinite(str1)) 
		{
		temp1=1;
		}
		else {
		temp1=0;
		break;
		}
	}
	if(temp1!=0)
	return true;
	else{
	alert(alertbox);
	entered.focus();
	return false;
	}
}//end of phone validation function
//Zip code Validation start
function zipcodevalidation(entered,alertbox)
{
	var temp1=0;
	var phone=entered.value;
	strlen=phone.length;
	if(strlen > 12)
	{
	alert(alertbox);
	return false;
	}
	for(var i=0;i<=strlen;i++) 
	{
	str1=phone.charAt(i)
		if((str1 == "-" )||(str1 == " " )|| isFinite(str1) || charvalidation(str1)) 
		{
		temp1=1;
		}
		else {
		temp1=0;
		break;
		}
	}
	if(temp1!=0)
	return true;
	else{
	alert(alertbox);
	entered.focus();
	return false;
	}
}//end of Zip code validation function



