/* (c) 2005 Thermotron Industries, Author: MOWEN
Purpose: Immediate response on omissions.
Idea from http://www.peterbailey.net/fValidate/
v1.8, 10/28/05 */
//error responses
var p='&bull; Please '; var b=p+'enter your '; var q=p+'enter the '; var c1='#fff'; var c2='#ffc'; var cR=0;//count Rows
//check for empty values in required fields, incl. select boxes
function validate(fN){//fN=Form Name
	EA=new Array();//EA=Error Array
	var NE=fN.length;//NE=Number Elements
	for (i=0;i<NE-2;i++){//subtract two for submit/reset
	  fN.elements[i].style.backgroundColor=c1;}
	if(fN.Agree){//look for field
		a=document.getElementById('agree');	a.style.backgroundColor='#f5f5f5';}
	if(fN.Description){fN.Description.style.backgroundColor=c1;}
	if(fN.Stock_Number){fN.Stock_Number.style.backgroundColor=c1;}
	if(fN.Model_Number){fN.Model_Number.style.backgroundColor=c1;}
	if(fN.Equipment_Type){fN.Equipment_Type.style.backgroundColor=c1;}
	if(fN.Serial_Number){fN.Serial_Number.style.backgroundColor=c1;}
	if(fN.Price){fN.Price.style.backgroundColor=c1;}
	//any fields empty
	for(i=0;i<NE-2;i++){
		el=fN.elements[i];//content of field, el=element
		eN=el.name;//eN=element/field name
		if(el.value==''||el.value=='00'||el.value=='$'){ //if no entry...
			EA[i]=eN;}}//...add field name to array	
	AL=EA.length;//AL=Array length
	d=document.getElementById('errorLog');//error table, d=data
	for(i=cR;i>0;i--){//if any rows...
		d.deleteRow(i);//...delete 'em.
		cR--;}
	//output of errors
	for(i=1;i<AL;i++){
		if(EA[i]=='First_Name'){
			cR++;//for row placement and count
			d.insertRow(cR).insertCell(0).innerHTML=b+'first name.';//insert row for error message
			fN.First_Name.style.backgroundColor=c2;//color the field
		}else if(EA[i]=='Last_Name'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'last name.';fN.Last_Name.style.backgroundColor=c2;
		}else if(EA[i]=='Company'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'company name.';fN.Company.style.backgroundColor=c2;
		}else if(EA[i]=='Street_Address_1'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'street address.';fN.Street_Address_1.style.backgroundColor=c2;
		}else if(EA[i]=='City'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'city.';fN.City.style.backgroundColor=c2;
		}else if(EA[i]=='State'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'state.';fN.State.style.backgroundColor=c2;
		}else if(EA[i]=='Zip'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'zip/postal code.';fN.Zip.style.backgroundColor=c2;
		}else if(EA[i]=='country'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'country.';fN.country.style.backgroundColor=c2;
		}else if(EA[i]=='Telephone_Number'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'telephone number.';fN.Telephone_Number.style.backgroundColor=c2;
		}else if(EA[i]=='Email'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=b+'email address.';fN.Email.style.backgroundColor=c2;
		}else if(EA[i]=='Description'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=p+'describe what you are testing.';fN.Description.style.backgroundColor=c2;
		}else if(EA[i]=='Stock_Number'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=q+'stock number.';fN.Stock_Number.style.backgroundColor=c2;
		}else if(EA[i]=='Model_Number'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=q+'model number.';fN.Model_Number.style.backgroundColor=c2;
		}else if(EA[i]=='Equipment_Type'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=q+'equipment type.';fN.Equipment_Type.style.backgroundColor=c2;
		}else if(EA[i]=='Serial_Number'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=q+'serial number.';fN.Serial_Number.style.backgroundColor=c2;
		}else if(EA[i]=='Price'){
			cR++;d.insertRow(cR).insertCell(0).innerHTML=q+'price.';fN.Price.style.backgroundColor=c2;}}
	if(fN.Agree&&!fN.Agree.checked){//agree checkbox error
		cR++;d.insertRow(cR).insertCell(0).innerHTML='&bull; You must agree to the terms and conditions to continue.';
		a.style.backgroundColor=c2;}
  setCookie(fN);
	if(cR>0){
		return false;//stop submit
	}else {return true;} //send submit
}
