// Form Validation script
// by Alex Kim - 2006
// ===========================================

function checkWholeForm(wholeform) {
    var why = "";
    why += checkCompany(wholeform.company.value);
    why += checkContact(wholeform.contact.value);
    why += checkStreet(wholeform.street.value);
    why += checkCity(wholeform.city.value);
    why += checkState(wholeform.state.value);
    why += checkZip(wholeform.zip.value);
    why += checkPhone(wholeform.phone.value);
    why += checkFax(wholeform.fax.value);
    why += checkEmail(wholeform.email.value);
    why += checkWeb(wholeform.web.value);
    why += checkPtype(wholeform.ptype.value);
    why += checkFclass(wholeform.fclass.value);
    why += checkHazdesc(wholeform.hazdesc.value, wholeform.hazmats[0].checked, wholeform.hazmats[1].checked);
    why += checkSkuquant(wholeform.skuquant.value);
    why += checkPsize(wholeform.psl.value, wholeform.psw.value, wholeform.psh.value);
    why += checkCasecount(wholeform.casecount.value);
    why += checkItemcount(wholeform.itemcount.value);
    why += checkInnerpacks(wholeform.innerpacks[0].checked, wholeform.innerpacks[1].checked);
    why += checkCube(wholeform.cube.value);
    why += checkWeight(wholeform.weight.value);
    why += checkLotserial(wholeform.lotserial[0].checked, wholeform.lotserial[1].checked);
    why += checkRetail(wholeform.retaild.value, wholeform.retailc.value);
    why += checkPstorage(wholeform.pstorage.value);
    why += checkStartup(wholeform.startup.value);
    why += checkMstorage(wholeform.mstorage.value);
    why += checkOrder(wholeform.order[0].checked, wholeform.order[1].checked, wholeform.order[2].checked);
    why += checkIturns(wholeform.iturns.value);
    why += checkMdate(wholeform.movemm.value, wholeform.movedd.value, wholeform.moveyyyy.value);
    why += checkInterest(wholeform.interest[0].checked, wholeform.interest[1].checked, wholeform.interest[2].checked);
    why += checkTmode(wholeform.tmode.value);
    why += checkInloads(wholeform.inloads.value);
    why += checkCaseload(wholeform.caseload.value);
    why += checkLoadpallets(wholeform.loadpallets[0].checked, wholeform.loadpallets[1].checked, wholeform.caseload2.value);
    why += checkOPM(wholeform.orderltl.value, wholeform.ordersp.value, wholeform.ordertl.value);
    why += checkCPO(wholeform.casesltl.value, wholeform.casessp.value, wholeform.casestl.value);
    why += checkSPO(wholeform.skultl.value, wholeform.skusp.value, wholeform.skutl.value);
    why += checkWillcalls(wholeform.willcalls[0].checked, wholeform.willcalls[1].checked, wholeform.wcpercent.value);
    why += checkRepack(wholeform.repack[0].checked, wholeform.repack[1].checked, wholeform.rppercent.value);
    why += checkKitting(wholeform.kitting[0].checked, wholeform.kitting[1].checked, wholeform.ktpercent.value);
//    why += isEmpty(wholeform.notempty.value);
//    why += isDifferent(wholeform.different.value);
//    for (i=0, n=wholeform.radios.length; i<n; i++) {
//        if (wholeform.radios[i].checked) {
//            var checkvalue = wholeform.radios[i].value;
//            break;
//        } 
//    }
//    why += checkRadio(checkvalue);
//    why += checkDropdown(wholeform.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkFirstForm(wholeform) {
    var why = "";
    why += checkCompany(wholeform.company.value);
    why += checkContact(wholeform.contact.value);
    why += checkStreet(wholeform.street.value);
    why += checkCity(wholeform.city.value);
    why += checkState(wholeform.state.value);
    why += checkZip(wholeform.zip.value);
    why += checkPhone(wholeform.phone.value);
    why += checkFax(wholeform.fax.value);
    why += checkEmail(wholeform.email.value);
    why += checkWeb(wholeform.web.value);
    why += checkPtype(wholeform.ptype.value);
    why += checkFclass(wholeform.fclass.value);
    why += checkHazdesc(wholeform.hazdesc.value, wholeform.hazmats[0].checked, wholeform.hazmats[1].checked);
    why += checkSkuquant(wholeform.skuquant.value);
    why += checkPsize(wholeform.psl.value, wholeform.psw.value, wholeform.psh.value);
    why += checkCasecount(wholeform.casecount.value);
    why += checkItemcount(wholeform.itemcount.value);
    why += checkInnerpacks(wholeform.innerpacks[0].checked, wholeform.innerpacks[1].checked);
    why += checkCube(wholeform.cube.value);
    why += checkWeight(wholeform.weight.value);
    why += checkLotserial(wholeform.lotserial[0].checked, wholeform.lotserial[1].checked);
    why += checkRetail(wholeform.retaild.value, wholeform.retailc.value);
    why += checkPstorage(wholeform.pstorage.value);
    why += checkStartup(wholeform.startup.value);
    why += checkMstorage(wholeform.mstorage.value);
    why += checkOrder(wholeform.order[0].checked, wholeform.order[1].checked, wholeform.order[2].checked);
    why += checkIturns(wholeform.iturns.value);
    why += checkMdate(wholeform.movemm.value, wholeform.movedd.value, wholeform.moveyyyy.value);
    why += checkInterest(wholeform.interest[0].checked, wholeform.interest[1].checked, wholeform.interest[2].checked);
//    why += checkTmode(wholeform.tmode.value);
//    why += checkInloads(wholeform.inloads.value);
//    why += checkCaseload(wholeform.caseload.value);
//    why += checkLoadpallets(wholeform.loadpallets[0].checked, wholeform.loadpallets[1].checked, wholeform.caseload2.value);
//    why += checkOPM(wholeform.orderltl.value, wholeform.ordersp.value, wholeform.ordertl.value);
//    why += checkCPO(wholeform.casesltl.value, wholeform.casessp.value, wholeform.casestl.value);
//    why += checkSPO(wholeform.skultl.value, wholeform.skusp.value, wholeform.skutl.value);
//    why += checkWillcalls(wholeform.willcalls[0].checked, wholeform.willcalls[1].checked, wholeform.wcpercent.value);
//    why += checkRepack(wholeform.repack[0].checked, wholeform.repack[1].checked, wholeform.rppercent.value);
//    why += checkKitting(wholeform.kitting[0].checked, wholeform.kitting[1].checked, wholeform.ktpercent.value);
//    why += isEmpty(wholeform.notempty.value);
//    why += isDifferent(wholeform.different.value);
//    for (i=0, n=wholeform.radios.length; i<n; i++) {
//        if (wholeform.radios[i].checked) {
//            var checkvalue = wholeform.radios[i].value;
//            break;
//        } 
//    }
//    why += checkRadio(checkvalue);
//    why += checkDropdown(wholeform.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkSecondForm(wholeform) {
    var why = "";
//    why += checkCompany(wholeform.company.value);
//    why += checkContact(wholeform.contact.value);
//    why += checkStreet(wholeform.street.value);
//    why += checkCity(wholeform.city.value);
//    why += checkState(wholeform.state.value);
//    why += checkZip(wholeform.zip.value);
//    why += checkPhone(wholeform.phone.value);
//    why += checkFax(wholeform.fax.value);
//    why += checkEmail(wholeform.email.value);
//    why += checkWeb(wholeform.web.value);
//    why += checkPtype(wholeform.ptype.value);
//    why += checkFclass(wholeform.fclass.value);
//    why += checkHazdesc(wholeform.hazdesc.value, wholeform.hazmats[0].checked, wholeform.hazmats[1].checked);
//    why += checkSkuquant(wholeform.skuquant.value);
//    why += checkPsize(wholeform.psl.value, wholeform.psw.value, wholeform.psh.value);
//    why += checkCasecount(wholeform.casecount.value);
//    why += checkItemcount(wholeform.itemcount.value);
//    why += checkInnerpacks(wholeform.innerpacks[0].checked, wholeform.innerpacks[1].checked);
//    why += checkCube(wholeform.cube.value);
//    why += checkWeight(wholeform.weight.value);
//    why += checkLotserial(wholeform.lotserial[0].checked, wholeform.lotserial[1].checked);
//    why += checkRetail(wholeform.retaild.value, wholeform.retailc.value);
//    why += checkPstorage(wholeform.pstorage.value);
//    why += checkStartup(wholeform.startup.value);
//    why += checkMstorage(wholeform.mstorage.value);
//    why += checkOrder(wholeform.order[0].checked, wholeform.order[1].checked, wholeform.order[2].checked);
//    why += checkIturns(wholeform.iturns.value);
//    why += checkMdate(wholeform.movemm.value, wholeform.movedd.value, wholeform.moveyyyy.value);
//    why += checkInterest(wholeform.interest[0].checked, wholeform.interest[1].checked, wholeform.interest[2].checked);
    why += checkTmode(wholeform.tmode.value);
    why += checkInloads(wholeform.inloads.value);
    why += checkCaseload(wholeform.caseload.value);
    why += checkLoadpallets(wholeform.loadpallets[0].checked, wholeform.loadpallets[1].checked, wholeform.caseload2.value);
    why += checkOPM(wholeform.orderltl.value, wholeform.ordersp.value, wholeform.ordertl.value);
    why += checkCPO(wholeform.casesltl.value, wholeform.casessp.value, wholeform.casestl.value);
    why += checkSPO(wholeform.skultl.value, wholeform.skusp.value, wholeform.skutl.value);
    why += checkWillcalls(wholeform.willcalls[0].checked, wholeform.willcalls[1].checked, wholeform.wcpercent.value);
    why += checkRepack(wholeform.repack[0].checked, wholeform.repack[1].checked, wholeform.rppercent.value);
    why += checkKitting(wholeform.kitting[0].checked, wholeform.kitting[1].checked, wholeform.ktpercent.value);
//    why += isEmpty(wholeform.notempty.value);
//    why += isDifferent(wholeform.different.value);
//    for (i=0, n=wholeform.radios.length; i<n; i++) {
//        if (wholeform.radios[i].checked) {
//            var checkvalue = wholeform.radios[i].value;
//            break;
//        } 
//    }
//    why += checkRadio(checkvalue);
//    why += checkDropdown(wholeform.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// =========== Contact Info functions =================

function checkCompany (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter your company name.\n";
 }
 return error;
}

function checkContact (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter a contact name.\n";
 }
 return error;
}

function checkStreet (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter your street address.\n";
 }
 return error;
}

function checkCity (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter your city name.\n";
 }
 return error;
}

function checkState(choice) {
 var error = "";
 if (choice == 0) {
    error = "Please select your state from the drop-down list.\n";
 }    
 return error;
}

function checkZip (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (!(stripped.length == 5)) {
    error = "The zip code must be five digits only.\n";
 }
 if (isNaN(parseInt(stripped))) {
    error = "The zip code contains illegal characters.\n";
 }
 if (strng == "") {
    error = "Please enter your zip code.\n";
 }
 return error;
}

function checkPhone (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (!(stripped.length == 10)) {
    error = "The phone number including area code should be ten digits only.\n";
 }
 if (isNaN(parseInt(stripped))) {
    error = "The phone number contains illegal characters.\n";
 }
 if (strng == "") {
    error = "Please enter your phone number.\n";
 }
 return error;
}

function checkFax (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (strng.length > 0) {
	 if (!(stripped.length == 10)) {
	    error = "The fax number including area code should be ten digits only.\n";
	 }
	 if (isNaN(parseInt(stripped))) {
	    error = "The fax number contains illegal characters.\n";
	 }
 }
 return error;
}
    
function checkEmail (strng) {
 var error = "";
 var emailFilter=/^.+@.+\..{2,3}$/;
 if (!(emailFilter.test(strng))) { 
    error = "Please enter a valid email address.\n";
 }    
 var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
 if (strng.match(illegalChars)) {
    error = "The email address contains illegal characters.\n";
 }
 return error;
}
    
function checkWeb (strng) {
 var error = "";
 var webFilter=/^.+\..{2,3}$/;
 if (strng == "") {
    return error;
 }
 if (!(webFilter.test(strng))) { 
    error = "Please enter a valid website address.\n";
 }    
 var illegalChars= /[\(\)\<\>\,\;\"\[\]]/
 if (strng.match(illegalChars)) {
    error = "The website address contains illegal characters.\n";
 }
 return error;
}


// =========== General Info functions =================


function checkPtype (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter a product type.\n";
 }
 return error;
}
    
function checkFclass (strng) {
 var error = "";
 if (strng == "0") {
    error = "Please select an average freight class from the drop down list.\n";
 }
 return error;
}
    
function checkHazdesc (strng1, strng2, strng3) {
 var error = "";
 if (strng3) {
 	if (strng1 == "") {
    		error = "Please describe any hazardous materials.\n";
    	}
 }
 if (!strng2 && !strng3) {
    error = "Please select if you will have any hazardous materials.\n";
 }
 return error;
}

function checkSkuquant (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The number of products should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the number of products to be warehoused.\n";
 }
 return error;
}
    
function checkPsize (strng1, strng2, strng3) {
 var error = "";
 var stripped = (strng1 + strng2 + strng3).replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The pallet dimensions should be numeric values only.\n";
 }
 if (strng1 == "" || strng2 == "" || strng3 == "" ) {
    error = "Please enter proper pallet dimensions in inches.\n";
 }
 return error;
}
    
function checkCasecount (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The case count per pallet should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the average case count per pallet.\n";
 }
 return error;
}
    
function checkItemcount (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The item count per case should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the average items per case.\n";
 }
 return error;
}
    
function checkInnerpacks (strng1, strng2) {
 var error = "";
 if (!strng1 && !strng2) {
    error = "Please select if you need cases inventoried in inner packs.\n";
 }
 return error;
}

function checkCube (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The average cube per case should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the average cube per case figure.\n";
 }
 return error;
}
    
function checkWeight (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The average weight per case should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the average weight per case in pounds.\n";
 }
 return error;
}
    
function checkLotserial (strng1, strng2) {
 var error = "";
 if (!strng1 && !strng2) {
    error = "Please select whether or not your product is lotted or serialized.\n";
 }
 return error;
}

function checkRetail (strng1, strng2) {
 var error = "";
 var stripped = (strng1 + strng2).replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The average retail value per case should be a numeric value only.\n";
 }
 if (strng1 == "" || strng2 == "") {
    error = "Please enter the average retail value per case.\n";
 }
 return error;
}

function checkPstorage (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The intended pallet storage figure should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the intended pallet storage figure.\n";
 }
 return error;
}
    
function checkStartup (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The initial storage figure should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the initial storage amount.\n";
 }
 return error;
}

function checkMstorage (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The average monthly storage figure should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the average monthly storage amount.\n";
 }
 return error;
}
    
function checkOrder (strng1, strng2, strng3) {
 var error = "";
 if (!strng1 && !strng2 && !strng3) {
    error = "Please select at least one method by which you will send us orders.\n";
 }
 return error;
}

function checkIturns (strng) {
 var error = "";
 if (strng == "0") {
    error = "Please select your projected inventory turns per year from the drop down list.\n";
 }
 return error;
}
    
function checkMdate (strng1, strng2, strng3) {
 var error = "";
 var stripped = (strng1 + strng2 + strng3).replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The projected move-in date should be numeric values only.\n";
 }
 if (strng1 == "" || strng2 == "" || strng3 == "" || strng3.length != 4) {
    error = "Please enter a valid move-in date.\n";
 }
 return error;
}
    
function checkInterest (strng1, strng2, strng3) {
 var error = "";
 if (!strng1 && !strng2 && !strng3) {
    error = "Please select at least one type of warehousing service you will require.\n";
 }
 return error;
}


// =========== Inbound Info functions =================


function checkTmode(choice) {
 var error = "";
 if (choice == 0) {
    error = "Please select the mode of transport for your inbound stock replenishments.\n";
 }    
 return error;
}

function checkInloads(choice) {
 var error = "";
 if (choice == 0) {
    error = "Please select your projected number of inbound loads per month.\n";
 }    
 return error;
}

function checkCaseload (strng) {
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The projected number of cases per inbound load should be a numeric value only.\n";
 }
 if (strng == "") {
    error = "Please enter the projected number of cases per inbound load.\n";
 }
 return error;
}
    
function checkLoadpallets (strng1, strng2, strng3) {
 var error = "";
 var stripped = strng3.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (strng2) {
 	if (strng3 == "" || parseInt(stripped) < 1) {
    		error = "The number of pallets per inbound load is invalid.\n";
    	}
 }
 if (!strng1 && !strng2) {
    error = "Please choose if cases will be loaded onto pallets.\n";
 }
 return error;
}
    

// =========== Projected Shipments functions =================


function checkOPM (strng1, strng2, strng3) {
 var error = "";
 var stripped = (strng1 + strng2 + strng3).replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The number of orders per month should be a numeric value.\n";
 }
 if (strng1 == "" && strng2 == "" && strng3 == "") {
    error = "Please enter a projected number of orders per month.\n";
 }
 return error;
}
    
function checkCPO (strng1, strng2, strng3) {
 var error = "";
 var stripped = (strng1 + strng2 + strng3).replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The number of cases per order should be a numeric value.\n";
 }
 if (strng1 == "" && strng2 == "" && strng3 == "") {
    error = "Please enter a projected number of cases per order.\n";
 }
 return error;
}
    
function checkSPO (strng1, strng2, strng3) {
 var error = "";
 var stripped = (strng1 + strng2 + strng3).replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped))) {
    error = "The number of SKUs per order should be a numeric value.\n";
 }
 if (strng1 == "" && strng2 == "" && strng3 == "") {
    error = "Please enter a projected number of SKUs per order.\n";
 }
 return error;
}
    
function checkWillcalls (strng1, strng2, strng3) {
 var error = "";
 var stripped = strng3.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (strng2) {
 	if (strng3 == "" || parseInt(stripped) < 1) {
    		error = "The will call percentage of monthly orders is invalid.\n";
    	}
 }
 if (!strng1 && !strng2) {
    error = "Please choose whether you will need customer will calls.\n";
 }
 return error;
}
    
function checkRepack (strng1, strng2, strng3) {
 var error = "";
 var stripped = strng3.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (strng2) {
 	if (strng3 == "" || parseInt(stripped) < 1) {
    		error = "The repackaging service percentage of monthly orders is invalid.\n";
    	}
 }
 if (!strng1 && !strng2) {
    error = "Please choose whether you will need repackaging services.\n";
 }
 return error;
}
    
function checkKitting (strng1, strng2, strng3) {
 var error = "";
 var stripped = strng3.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (strng2) {
 	if (strng3 == "" || parseInt(stripped) < 1) {
    		error = "The kitting service percentage of monthly orders is invalid.\n";
    	}
 }
 if (!strng1 && !strng2) {
    error = "Please choose whether you will need kitting services.\n";
 }
 return error;
}
    












function checkUsername (strng) {
 var error = "";
 if (strng == "") {
    error = "Please enter a username.\n";
 }
 if ((strng.length < 4) || (strng.length > 10)) {
    error = "The username is the wrong length.\n";
 }
 var illegalChars = /\W/;
// allow only letters, numbers, and underscores
 if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
 } 
 return error;
}

function checkPassword (strng) {
 var error = "";
 if (strng == "") {
    error = "You didn't enter a password.\n";
 }
 var illegalChars = /[\W_]/; // allow only letters and numbers
 if ((strng.length < 6) || (strng.length > 8)) {
    error = "The password is the wrong length.\n";
 }
 else if (illegalChars.test(strng)) {
    error = "The password contains illegal characters.\n";
 }
 return error;
}

    
    
    
    
    
    


//end

