/*   ////////////////////////////////////////////
	JavaScript Document :: engineeringcheck1.js
	version 1.1 24.6.03
	copyright (c) 2003, Chris Whincop, neurvana.com
	email: chrisATneurvanaDOTcom
	tel: +44 (0)1896 820161
	adapted from various Open Source scripts and
	released under the GPL, see:
	http://www.gnu.org/copyleft/gpl.html
 	No warranty, freely distributable and reusable.
	If you make improvements, please let me know.
	Thanks! 
///////////////////////////////////////// */

function validate() { 


//check a field to make sure it's not blank 
if(document.Engineering1.orgname.value == '') { 
alert('Please fill in the field: \n\nName of Organisation'); 
document.Engineering1.orgname.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Correspondence_Address.value == '') { 
alert('Please fill in the field: \n\nCorrespondence Address'); 
document.Engineering1.Correspondence_Address.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Plant_Address.value == '') { 
alert('Please fill in the field: \n\nPlant Address'); 
document.Engineering1.Plant_Address.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.contname.value == '') { 
alert('Please fill in the field: \n\nContact Name'); 
document.Engineering1.contname.focus(); 
return false; 
}




/* 		NEW EMAIL PROCEDURE - 27.6.03 STARTS HERE 	*/

// offer the person the option of leaving the two email fields blank if they are both blank
if((document.Engineering1.contemail1a.value == '') && (document.Engineering1.contemail1b.value == '')) { 
if(!confirm("Are you sure you want to leave the two 'Contact Email Address' fields blank?\n\nPlease click on 'OK' to confirm, or click on 'Cancel' to go back and enter your email address.")) { 
document.Engineering1.contemail1a.focus(); 
return false; 
}
}
// check both email fields to make sure just the first isn't blank 
if((document.Engineering1.contemail1b.value != '') && (document.Engineering1.contemail1a.value == '')){ 
alert("It looks like you have filled in the second email field, but not the first.\n\nPlease EITHER:\n\n1. fill in the first email field: \n\n'Contact Email Address' \n\nOR:\n\n2. make sure the second email field is also empty"); 
document.Engineering1.contemail1a.focus(); 
return false; 
}
// check both email fields to make sure just the second isn't blank 
if((document.Engineering1.contemail1a.value != '') && (document.Engineering1.contemail1b.value == '')){ 
alert("It looks like you have filled in the first email field, but not the second.\n\nPlease EITHER:\n\n1. fill in the second email field: \n\n'Please retype the Contact Email Address...'\n\nOR:\n\n2. make sure the first email field is also empty"); 
document.Engineering1.contemail1b.focus(); 
return false; 
}

// check both email fields again, and this time, if neither is blank, proceed to check each of them for valid syntax
// if both are blank, do nothing
if((document.Engineering1.contemail1a.value != '') && (document.Engineering1.contemail1b.value != '')) { 
// check if email address entered has got valid syntax 
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.Engineering1.contemail1a.value))) { 
alert("What you\'ve entered in the first email field is not a valid email address!\n\nPlease check it for spaces and other typos."); 
document.Engineering1.contemail1a.focus(); 
return false; 
}  //end the first if within if
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.Engineering1.contemail1b.value))) { 
alert("What you\'ve entered in the second email field is not a valid email address!\n\nPlease check it for spaces and other typos."); 
document.Engineering1.contemail1b.focus(); 
return false; 
}  //end the second if within if
} //end the main if

// Now make sure that the two email addresses entered match
  if (document.Engineering1.contemail1a.value.toLowerCase() != document.Engineering1.contemail1b.value.toLowerCase()) {
alert("The two email addresses you\'ve just entered must match each other exactly!\n\nPlease check them both for spaces and other typos."); 
document.Engineering1.contemail1a.focus(); 
return false; 
} //end if 

/* 		NEW EMAIL PROCEDURE - 24.6.03 ENDS HERE 	*/





//check a field to make sure it's not blank 
if(document.Engineering1.contphone1.value == '') { 
alert('Please fill in the field: \n\nContact Telephone No.'); 
document.Engineering1.contphone1.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Steam_Boilers_Steam_Ovens_Autoclaves.value == '') { 
alert('Please fill in the field: \n\nSteam Boilers, Steam Ovens, Autoclaves \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Steam_Boilers_Steam_Ovens_Autoclaves.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Canteen_Steam_Boiler.value == '') { 
alert('Please fill in the field: \n\nCanteen Steam Boiler \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Canteen_Steam_Boiler.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Hot_Water_Heating_Boilers.value == '') { 
alert('Please fill in the field: \n\nHot Water Heating Boilers \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Hot_Water_Heating_Boilers.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Air_or_Oil_pressure_Vessels.value == '') { 
alert('Please fill in the field: \n\nAir/Oil pressure Vessels \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Air_or_Oil_pressure_Vessels.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Other_Pressure_Systems.value == '') { 
alert('Please fill in the field: \n\nOther Pressure Systems \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Other_Pressure_Systems.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Passenger_or_Goods_Lift.value == '') { 
alert('Please fill in the field: \n\nPassenger/Goods Lift\n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Passenger_or_Goods_Lift.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Stair_Lift.value == '') { 
alert('Please fill in the field: \n\nStair Lift \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Stair_Lift.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Bath_Hoist.value == '') { 
alert('Please fill in the field: \n\nBath Hoist \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Bath_Hoist.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Vehicle_Tailboard_Lift.value == '') { 
alert('Please fill in the field: \n\nVehicle Tailboard Lift \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Vehicle_Tailboard_Lift.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Food_Hoist_or_Dumb_Waiter.value == '') { 
alert('Please fill in the field: \n\nFood Hoist/Dumb Waiter \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Food_Hoist_or_Dumb_Waiter.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Motor_Vehicle_Lifting_Table.value == '') { 
alert('Please fill in the field: \n\nMotor Vehicle Lifting Table \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Motor_Vehicle_Lifting_Table.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Fork_Lift_Truck.value == '') { 
alert('Please fill in the field: \n\nFork Lift Truck \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Fork_Lift_Truck.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Chain_Blocks.value == '') { 
alert('Please fill in the field: \n\nChain Blocks \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Chain_Blocks.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Lifting_Tackle.value == '') { 
alert('Please fill in the field: \n\nLifting Tackle \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Lifting_Tackle.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Window_Cleaning_Apparatus.value == '') { 
alert('Please fill in the field: \n\nWindow Cleaning Apparatus \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Window_Cleaning_Apparatus.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.the_number_of_extraction_units_involved.value == '') { 
alert('Please fill in the field: \n\nthe number of extraction units involved \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.the_number_of_extraction_units_involved.focus(); 
return false; 
}

/* NOT CHECKED FOR:

	the_exhaust_extraction_process_type 

	depends on condition of the_number_of_extraction_units_involved,
	which is really too complex to check for reliably - we could test for the three null conditions,
	but people could vary these in too many ways
	If we did check it, we'd first check for the_number_of_extraction_units_involved's state
	
*/

//check a field to make sure it's not blank 
if(document.Engineering1.Total_square_footage_of_premises.value == '') { 
alert('Please fill in the field: \n\nElectrical Wiring Installation :: Total square footage of premises '); 
document.Engineering1.Total_square_footage_of_premises.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.HP_or_KW_of_each_item.value == '') { 
alert('Please fill in the field: \n\nFixed Electrical Items :: HP/KW of each item\n\nPlease list each Fixed Electrical Item on a new line, along with how many HP/KW it is.\n\n(Please state \'no fixed electrical items on premises\', if appropriate)'); 
document.Engineering1.HP_or_KW_of_each_item.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.PortAppTotal_number_of_items.value == '') { 
alert('Please fill in the field: \n\nPortable Appliances :: Total number of items \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.PortAppTotal_number_of_items.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Microwave_OvensTotal_number_of_items.value == '') { 
alert('Please fill in the field: \n\nMicrowave Ovens :: Total number of items\n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Microwave_OvensTotal_number_of_items.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Engineering1.Emergency_Lighting_Installations_Total_number_of_luminaires.value == '') { 
alert('Please fill in the field: \n\nEmergency Lighting Installations :: Total number of luminaires \n\n(state \'0\', or \'none\'  or \'zero\', if appropriate)'); 
document.Engineering1.Emergency_Lighting_Installations_Total_number_of_luminaires.focus(); 
return false; 
}



// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Engineering1.resubmitting); 
//make sure that the user actually selected one of the radio buttons: 
if (radioVal == '') { 
alert("It looks like you forgot to click on your choice in response to the \n'Are you resubmitting...' question. \n \nSorry, but you MUST make a selection!"); 
document.Engineering1.resubmitting[0].focus(); // and focus on the first option
return false; 
}


//if the checking gets this far, everything checked is OK 

return; 

}// end validate function 



/*  this function checks values returned for any required radio group */
function valRadiobutton(radiobutton) { 
myOption = -1; 
for (i=0; i< radiobutton.length; i++) { 
if (radiobutton[i].checked) { 
myOption = i; 
}
}
if (myOption == -1) { 
return ""; 
} else { 
return radiobutton[myOption].value 
}
}// end function valRadioButton 



