

function clearHTMLForm() {

	if (confirm('Are you sure you wish to clear the form?\n\nAll entered data will be lost.')) {
		window.location.href='getaprice.asp';
	}
	
}


function doSubmitGetAPrice() {
	
	fm = document.quoteForm;
	msg="";
	newclass="";		
	sDIV="";
	
	if  (fm['strFirstName'].value=='') {
		msg += sDIV + "First Name";
		sDIV=", ";
		newclass="INPUTrequired";
	} 
	
	fm['strFirstName'].className = newclass;
	
	newclass="";
	
	if  (fm['strLastName'].value=='') {
		msg += sDIV + "Last Name";
		sDIV=", ";
		newclass="INPUTrequired";
	}
	
	fm['strLastName'].className = newclass;
	
	newclass="";		
	
	if  (fm['strStreetAddress'].value=='') {
		msg += sDIV + "Street Address";
		sDIV=", ";
		newclass="INPUTrequired";
	}
	
	fm['strStreetAddress'].className = newclass;
	newclass="";		
	
	if  (fm['strSuburb'].value=='') {
		msg+= sDIV + "Suburb";
		sDIV=", ";
		newclass="INPUTrequired";
	}
	
	fm['strSuburb'].className = newclass;
	newclass="";			
	
	if  (fm['strState'][fm['strState'].selectedIndex].value =='') {
		msg+= sDIV + "State";
		sDIV=", ";
		newclass="INPUTrequired";		
	}
	
	if (document.getElementById) {
		document.getElementById('spanState').className = newclass;
	}
	
	newclass="";			
	
	if  (fm['strPostcode'].value=='') {
		msg+= sDIV + "Postcode";
		sDIV=", ";

		newclass="INPUTrequired";
	}
	
	fm['strPostcode'].className = newclass;
	newclass="";				
	
	if  (fm['strPhone'].value=='') {
		msg+= sDIV + "Phone Number";
		sDIV=", ";
		newclass="INPUTrequired";
	}
	
	fm['strPhone'].className = newclass;
	newclass="";			
	
	if (  !(fm['chkSupply'][0].checked || fm['chkSupply'][1].checked)) {
		msg+= sDIV + "Quotation Type";
		sDIV =", ";
		newclass="INPUTrequired";
	}
	
	fm['chkSupply'][0].className = newclass;
	fm['chkSupply'][1].className = newclass;
	
	
	if (fm['strDescription'].value=='') {
		msg+= sDIV + "Quotation Description";
		sDIV =", ";
		newclass="INPUTrequired";		
	}
	
	fm['strDescription'].className = newclass;
	newclass="";
	
	if (fm['strEmailAddr'].value=='') {
		msg+= sDIV + "Email Address";
		sDIV =", ";
		newclass="INPUTrequired";		
	}
	
	fm['strEmailAddr'].className = newclass;
	
	if (msg=='') {
		
		if (fm['chkProductsProductsOther'].checked && fm['strProductsOther'].value=="") {
			
			alert("Please specify the product requested.");
			fm['strProductsOther'].focus();
			
		} else if (validateEmailContents(fm)) {
			
			var sDIV="";
			var sVal="";
			
			for (var iCheck=1; iCheck <= 14; iCheck++) {
				if (fm['chkProducts' + iCheck].checked) {
					sVal += sDIV;
					sVal += fm['chkProducts' + iCheck].value;
					sDIV = ", ";
				}
			}
			
			fm['productsSelected'].value = sVal;
			fm.submit();
			
		}
			
	} else {
		
		if (msg.split(",").length==1) {
			alert('The Price Request cannot be submitted.\n\n' + msg + " is a required field. \n\n This field has been highlighted with a red border.");
		} else {
			alert('The Price Request cannot be submitted.\n\n' + msg + " are all required fields. \n\n These fields have been highlighted with a red border.");
		}
		
	}

	
}

function validateEmailContents(fm) {
	
	var bOK = true;
	
	var sEmail = fm['strEmailAddr'].value;
	
	if (sEmail.indexOf("@")==-1) {
		bOK = false;
	} else {
		var aParts = sEmail.split("@");
		if (aParts.length!=2) {
			bOK = false;
		} else {
			if ((aParts[0]=="")||(aParts[1]=="")) {
				bOK = false;
			} else if (aParts[1].indexOf(".")==-1) {
				bOK = false;
			}
		}
		
	}
	
	if (!bOK) {
		
		fm['strEmailAddr'].className = "INPUTrequired";
		alert("Email address must be of the form username@domainName.\n\nPlease recheck the entry and try again.");
		
	} else {
		
		fm['strEmailAddr'].className = "";
		
	}
	
	return bOK;
	
	
}


function doChooseOther(bClicked) {
	
	document.getElementById('otherInputCellContainer').style.display = (bClicked ? '' : 'none');
	
	if (bClicked) {
		document['quoteForm']['strProductsOther'].focus();
	} else {
		document['quoteForm']['strProductsOther'].value = "";
	}
	
}
