/*
 (C) 2005, Thermotron Industries
 Version 2.5, optimized, Oct 26, 05
*/
var c1='#fff';
var c2='#ffc';
var P='Please enter ';
var O=P+'only the ';
var SN=' S/N.';
var C=' Chamber';
var T=' ThermoTrak II';
//Validate form entries
function validate(fN) {//fN=fN name
validatef(fN);
if (error){return false;}
//set input text boxes to white background
fN.Chamber_SN.style.backgroundColor = c1;
fN.ThermoTrakII_SN.style.backgroundColor = c1;
fN.Email.style.backgroundColor = c1;
fN.Confirm_Email.style.backgroundColor = c1;
//check emails
if (fN.Email.value != fN.Confirm_Email.value){
	alert('Your email addresses do not match. Please verify and enter them again.');
	fN.Email.style.backgroundColor = c2; //change this text box background color
	fN.Confirm_Email.style.backgroundColor = c2; //change this text box background color
	return false; //stop submit
	}
rS=false;//rS=radio select
//go through every radio button 0-7 (8 total) to see if checked
for (cnt=0;cnt<8;cnt++) {
if (fN.InstApp[cnt].checked && fN.Chamber_SN.value == '' && fN.ThermoTrakII_SN.value == '') {
	//if ThermoTrak II not chosen (any of the other radio buttons) and Chamber SN blank
	if (!fN.InstApp[7].checked && fN.Chamber_SN.value == ''){
		rS=true;
		alert(P+'the'+C+SN);
		fN.Chamber_SN.focus(); //set focus to this input, and so on...
		fN.Chamber_SN.style.backgroundColor = c2;
		return false;
		}
		//if ThermoTrak II chosen and ThermoTrak II SN blank
		  else if (fN.InstApp[7].checked && fN.ThermoTrakII_SN.value == ''){
			rS=true;
			alert(P+'the'+T+SN);
			fN.ThermoTrakII_SN.focus();
			fN.ThermoTrakII_SN.style.backgroundColor = c2;
			return false;
			}
		}
		//if ThermoTrak II chosen and SN left blank, but Chamber SN entered
			else if (fN.InstApp[7].checked && fN.ThermoTrakII_SN.value == '' && fN.Chamber_SN.value != ''){
				rS=true;
				alert(O+T+SN);
				fN.ThermoTrakII_SN.focus();
				fN.ThermoTrakII_SN.style.backgroundColor = c2;
				fN.Chamber_SN.style.backgroundColor = c2;
				return false;
			}
			//if Chamber controller chosen and SN left blank, but ThermoTrak II SN entered
			else if (!fN.InstApp[7].checked && fN.ThermoTrakII_SN.value != '' && fN.Chamber_SN.value == ''){
				rS=true;
				alert(O+C+SN);
				fN.ThermoTrakII_SN.focus();
				fN.ThermoTrakII_SN.style.backgroundColor = c2;
				fN.Chamber_SN.style.backgroundColor = c2;
				return false;
			}
		//if both Chamber SN and ThermoTRak II SN filled in
		 else if (fN.InstApp[cnt].checked && fN.Chamber_SN.value != '' && fN.ThermoTrakII_SN.value != ''){
				alert(O+'respective'+C+' or'+T+SN);
				fN.ThermoTrakII_SN.style.backgroundColor = c2;
				fN.Chamber_SN.style.backgroundColor = c2;
				return false;
			}
		//if everything seems ok
		 else if (fN.InstApp[cnt].checked && (fN.Chamber_SN.value != '' || fN.ThermoTrakII_SN.value != '')){
        rS = true;
				return true;
			}
}

//no radio button chosen
if (!rS) {
	alert('Please choose Instrument/Application type.');
	return false;
	}
}

//error responses
var b='&bull; Please enter your ';
var cR=0;//count Rows
//check for empty values in required fields, incl. select boxes
function validatef(fN){//fN=Form Name
	EA=new Array();//EA=Error Array
	for (i=0;i<8;i++){//subtract two for submit/reset
	  fN.elements[i].style.backgroundColor=c1; //background of each form field to white
	}
	//any fields empty
	for(i=0;i<8;i++){
		el=fN.elements[i];//content of field, el=element
		eN=el.name;//eN=element/field name
		if(el.value==''){ //if no entry...
			EA[i]=eN;//...add field name to array
		}
	}
	AL=EA.length;//AL=Array length
	d=document.getElementById('errorLog');//area for errors, d=data
	for(i=cR;i>0;i--){//if there are 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]=='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]=='Confirm_Email'){
			cR++;
			d.insertRow(cR).insertCell(0).innerHTML=b+'confirmation email address.';
			fN.Confirm_Email.style.backgroundColor=c2;
		}
	}
	if(cR>0){
		error = true;
	}else error = false;
}
function ShowHelp(){
	document.getElementById('showhelp').style.display='block';
}
function HideHelp(){
	document.getElementById('showhelp').style.display='none';
}

