//trim lefthand spaces
function LTrim (s){	
	while(''+s.charAt(0)==' '){
		s = s.substring(1,s.length);
	}
	return s;
}

//trim righthand spaces
function RTrim (s){
	if (s.length>1){
		while(''+s.charAt(s.length-1)==' '){
			s= s.substring(0,s.length-1);
		}
	
	}
		return s;
}

//clear the field if undefined
function clear(item){
	if (item.value=="undefined"){
		item.value="";
	}
	return item;
}

//trim the field
function trim (s){
	s.value=LTrim(s.value);	
	s.value=RTrim(s.value);
	s=clear(s);
	return s;
}

//function to check mail format	
function checkEmail(s){
	var i;
	var found1 = false;
	var found2 = false;
	var count1 = 0;	

	for (i = 0; i < s.value.length; i++){   
      	  // Check that current character isn't whitespace.
	      if(s.value.charAt(i)== ' ') {found1=true;found2=true;count1=2;}
		  if(s.value.charAt(i)== '@') {found1=true;count1++;}
      	  if(s.value.charAt(i)== '.'){ found2=true; }
	   }
	if(found1==true && found2==true){	
		if(count1 > 1)
			return false;
		else			
		    return true;
	}else{
		return false;
	}
	return true;
}

//checks for mandatory condition
function isMandatory(field, message){
	if(trim(field).value==""){			
		alert("Please Enter "+message);
		field.value="";
		field.focus();
		return true;		
	}	
	return false;
}


//used to move the cursor between the 3 phone fields, and to allow ONLY mumeric values
function checkPhone(field, altField, lastField){
	if((window.event.keyCode > 57) || (window.event.keyCode < 48)){
		return false;
	}	
	if(!lastField && field.value.length==3){
		altField.focus();
	}
}

function validatecomments(){		

	if(isMandatory(document.frmPartners.txtFName, "Your First Name!")){
		return false;
	}
	
	else if(isMandatory(document.frmPartners.txtLName, "Your Last Name!")){
		return false;
	}
	
	else if(isMandatory(document.frmPartners.txtEmail, "Your Email Address!")){
		return false;
	}

	else if(!checkEmail(trim(document.frmPartners.txtEmail))){
		alert("Please Enter a Valid Email Address");
		document.frmPartners.txtEmail.focus();
		return false;
	}

	else if(isMandatory(document.frmPartners.txtJobTitle, "Your Job Title!")){
		return false;
	}

	else if(isMandatory(document.frmPartners.txtCName, "Your Company Name!")){
		return false;
	}

	else if(isMandatory(document.frmPartners.txtAdd1, "Your Address!")){
		return false;
	}
	else if(isMandatory(document.frmPartners.txtAdd2, "Your Address 2!")){
		return false;
	}
	else if(isMandatory(document.frmPartners.txtCity, "Your City!")){
		return false;
	}
	
	else if(isMandatory(document.frmPartners.txtState, "Your State")){
		return false;
	}
	
	else if(isMandatory(document.frmPartners.txtZip, "Your Area ZipCode")){
		return false;
	}	
	else if(isNaN(document.frmPartners.txtZip.value)){
		alert("Please Enter a Numeric Value in the Zip Field!");
		document.frmEmployment.txtZip.focus();
		return false();
	}
		
	else if(isMandatory(document.frmPartners.txtCountry, "Your Country")){
		return false;
	}

	else if(isMandatory(document.frmPartners.txtCPhone, "Your Company Phone!")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtFax, "Your Fax Number")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtWebsite, "Your Website")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtYearsBus, "Number of Employees in Business")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtNoEmployees, "Number of Employees")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtNoEmpSales, "Number of Employees in Sales")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtAnnualRev, "Annyal Revenues")){
		return false;
	}	
	else if(isMandatory(document.frmPartners.txtCustomerSize, "Typical Customer Size")){
		return false;
	}	

	else
	{
	document.frmPartners.submit();
	}

}