var err, errmsg, email;
var bool;

function init(){
	err = 0;
	email = "";
	errmsg = "Please properly complete the following fields\n";
	errmsg += "-----------------------------------------------------\n\n";
}

function verify(f){
	init()
	for(var i=0; i < f.length; i++){
		var e = f.elements[i];
		if((e.type == "text") && (e.value == "")){
			switch(e.name){
				case "txt_fname":err++;errmsg+="\tFirst Name\n";break;
				case "txt_lname":err++;errmsg+="\tLast Name\n";break;
				case "txt_companyname":err++;errmsg+="\tCompany Name\n";break;
				//case "txt_business_type":err++;errmsg+="\tBusiness Type\n";break;
				case "txt_address1":err++;errmsg+="\tAddress\n";break;
				case "txt_city":err++;errmsg+="\tCity\n";break;
				case "txt_zip":err++;errmsg+="\tZip Code\n";break;
				case "txt_country":err++;errmsg+="\tCountry\n";break;
				case "txt_phone":err++;errmsg+="\tPhone Number\n";break;
				case "txt_email":err++;errmsg+="\tEmail Address\n";break;
				
			}
		}
		if((e.name=="sel_business_type") && (e.selectedIndex==0)){
			err++;
			errmsg+="\tBusiness Type\n";
		}
		
		if((e.name == "sel_state") && (e.selectedIndex == 0)){	//e.name.substr(0,3) --  use for multiple sel
			err++;
			//switch(e.name.substr(4)){
				errmsg+="\tState\n";
			//}
		}
		if (e.name == "txt_email") {
			email=e.value;
		}
	}

	var notchecked=0;
	for(var k=0; k < document.trade_info.check_product_types.length; k++){
		if (!document.trade_info.check_product_types[k].checked) {
			notchecked++;
			//alert(notchecked);
		}
	}
	if (notchecked==7){
		err++;errmsg+="\tChoose at least one Product Type\n";
	}
	
	if(err > 0){
		alert(errmsg);
		return false;
	}else{
		if (emailCheck(email)) {
			//alert("true");
			return true;
		}else{
			//alert ("false");
			return false;
		}
		//return false;
	}
}

function fix_phone(obj){
	var ph=obj.value;
	var areacode,exch,fone,rem;
	if(obj.value== null || obj.value==""){
		return;
	}else{
		if (ph.charAt(0)!='('){
			if (ph.length==7){
				exch=ph.substr(0,3);
				rem=ph.substr(3);
				fone=exch+"-"+rem;
				obj.value=fone;
				return obj.value;
			}else{
				if (ph.length==8){
					exch=ph.substr(0,3);
					rem=ph.substr(4);
					fone=exch+"-"+rem;
					obj.value=fone;
					return obj.value;
				}else{
					if (ph.length==10){
						areacode=ph.substr(0,3);
						exch=ph.substr(3,3);	
						rem=ph.substr(6);	
						fone="("+areacode+")"+exch+"-"+rem;
						obj.value=fone;
						return obj.value;
					}else{
						if (ph.length>=12){
							areacode=ph.substr(0,3);	
							exch=ph.substr(4,3);
							rem=ph.substr(8);
							fone="("+areacode+")"+exch+"-"+rem;
							obj.value=fone;
							return obj.value;
						}else{
							alert("\nPlease enter a valid phone number\nwith area code first.");
							obj.focus();
							obj.select();
							return obj.value;
						}//end fourth else.
					}//close third else
				}//close second else
			}//close first else
		}//end first if
	}
}