/*   ////////////////////////////////////////////
	JavaScript Document :: voipcheck1.js
	version 1.0 28.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.Voip1.orgname.value == '') { 
alert('Please fill in the field:\n\nName of Organisation'); 
// the double "\n\n" creates two new lines (like a paragraph break) in the alert box 
document.Voip1.orgname.focus(); 
return false; 
}

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

/* 		NEW EMAIL PROCEDURE - 28.6.03 - STARTS HERE 	*/

// offer the person the option of leaving the two email fields blank if they are both blank
if((document.Voip1.contemail1a.value == '') && (document.Voip1.contemail1b.value == '')) { 
if(!confirm("Are you sure you want to leave the two 'Office Bearer Email Address' fields blank?\n\nPlease click on 'OK' to confirm, or click on 'Cancel' to go back and enter your email address.")) { 
document.Voip1.contemail1a.focus(); 
return false; 
}
}
// check both email fields to make sure just the first isn't blank 
if((document.Voip1.contemail1b.value != '') && (document.Voip1.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.Voip1.contemail1a.focus(); 
return false; 
}
// check both email fields to make sure just the second isn't blank 
if((document.Voip1.contemail1a.value != '') && (document.Voip1.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.Voip1.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.Voip1.contemail1a.value != '') && (document.Voip1.contemail1b.value != '')) { 
// check if email address entered has got valid syntax 
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.Voip1.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.Voip1.contemail1a.focus(); 
return false; 
}  //end the first if within if
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.Voip1.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.Voip1.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.Voip1.contemail1a.value.toLowerCase() != document.Voip1.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.Voip1.contemail1a.focus(); 
return false; 
} //end if 

/* 		NEW EMAIL PROCEDURE ENDS HERE 	*/





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

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

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

//check a field to make sure it's not blank 
if(document.Voip1.org_established.value == '') { 
alert('Please fill in the field:\n\nHow long has your organisation been established?'); 
document.Voip1.org_established.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.full_desc_activities.value == '') { 
alert('Please fill in the field:\n\nFull description of activities'); 
document.Voip1.full_desc_activities.focus(); 
return false; 
}

// three value radio group
// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.fax_or_post_copies); 
//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: \n\n'copies of all relevant documents are being faxed/posted separately' \n\nOR \n\n'copies of some documents are being faxed/posted separately'\n\nOR \n\n'no documents are being faxed/posted separately'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.fax_or_post_copies[0].focus(); // and focus on the first option
return false; 
}



//check a field to make sure it's not blank 
if(document.Voip1.period_of_insurance.value == '') { 
alert('Please fill in the field:\n\nPeriod of Insurance\n\ne.g. \'one year\' or \'2 yrs\''); 
document.Voip1.period_of_insurance.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.period_from.value == '') { 
alert('Please fill in the field:\n\nPeriod of Insurance\n\nFrom'); 
document.Voip1.period_from.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.period_to.value == '') { 
alert('Please fill in the field:\n\nPeriod of Insurance\n\nTo'); 
document.Voip1.period_to.focus(); 
return false; 
}

// FIRST SECTION ENDS



// PROPERTY SECTION STARTS

//check a field to make sure it's not blank 
if((document.Voip1.rep_cost_furn_fix_fit.value == '') || (document.Voip1.rep_cost_furn_fix_fit.value == '£')) { 
alert('Please fill in the field:\n\nReplacement cost as new of all furniture fixtures and fittings'); 
document.Voip1.rep_cost_furn_fix_fit.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if((document.Voip1.rep_cost_e_equip_on_premises.value == '') || (document.Voip1.rep_cost_e_equip_on_premises.value == '£')){ 
alert('Please fill in the field:\n\nReplacement cost as new of all Electronic Equipment  \n\na) at your premises'); 
document.Voip1.rep_cost_e_equip_on_premises.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if((document.Voip1.rep_cost_e_equip_off_premises.value == '') || (document.Voip1.rep_cost_e_equip_off_premises.value == '£')){ 
alert('Please fill in the field:\n\nReplacement cost as new of all Electronic Equipment  \n\nb) away from your premises'); 
document.Voip1.rep_cost_e_equip_off_premises.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if((document.Voip1.biz_files.value == '') || (document.Voip1.biz_files.value == '£')){ 
alert('Please fill in the field:\n\nBusiness Files'); 
document.Voip1.biz_files.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if((document.Voip1.stock.value == '') || (document.Voip1.stock.value == '£')){ 
alert('Please fill in the field:\n\nStock'); 
document.Voip1.stock.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if((document.Voip1.build_ten_improve.value == '') || (document.Voip1.build_ten_improve.value == '£')){ 
alert('Please fill in the field:\n\nBuildings/Tenants Improvements'); 
document.Voip1.build_ten_improve.focus(); 
return false; 
}


// PROPERTY SECTION ENDS





// LIABILITY SECTION STARTS



//check a field to make sure it's not blank 
if(document.Voip1.cam_no_vol.value == '') { 
alert('Please fill in the field:\n\nNumber of (Clerical & Managerial and non-manual) volunteers'); 
document.Voip1.cam_no_vol.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.cam_no_emp.value == '') { 
alert('Please fill in the field:\n\nNumber of (Clerical & Managerial and non-manual) employees'); 
document.Voip1.cam_no_emp.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.cam_emp_pay.value == '') { 
alert('Please fill in the field:\n\nAnnual Payment to (Clerical & Managerial and non-manual) employees'); 
document.Voip1.cam_emp_pay.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.other_no_vol.value == '') { 
alert('Please fill in the field:\n\nNumber of (All other) volunteers'); 
document.Voip1.other_no_vol.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.other_no_emp.value == '') { 
alert('Please fill in the field:\n\nNumber of (All other) employees'); 
document.Voip1.other_no_emp.focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.other_emp_pay.value == '') { 
alert('Please fill in the field:\n\nAnnual Payment to (All other) employees'); 
document.Voip1.other_emp_pay.focus(); 
return false; 
}



//check a field to make sure it's not blank 
if(document.Voip1.how_split.value == '') { 
alert('Please fill in the field:\n\nPlease list, for \'All other\', all of the job types for volunteers and employees and indicate:\n\n- number of volunteers\n- number of employees\n- annual payment to employees\n\nfor each of these job types.'); 
document.Voip1.how_split.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.Voip1.advice_or_info); 
//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: \n\n'Do you provide advice or information?'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.advice_or_info[0].focus(); // and focus on the first option
return false; 
}
//check a field to make sure it's not blank IFF particular radio selection made
var radioVal = valRadiobutton(document.Voip1.advice_or_info); 
if((radioVal == 'Yes') && (document.Voip1.type_of_info_or_advice.value == '')) { 
alert("As you have answered 'Yes' to the question:\n\n'Do you provide advice or information?', \n\nplease fill in the field:\n\nWhat form does the advice or information take?"); 
document.Voip1.type_of_info_or_advice.focus(); 
return false; 
}

// check to see whether a particular radio button has a particular value, and IFF it does, check that another radio button has been selected 
var radioVal1 = valRadiobutton(document.Voip1.advice_or_info);
var radioVal2 = valRadiobutton(document.Voip1.advice_for_fee);
// Check the value of the FIRST radio button group in question
if((radioVal1 == 'Yes') &&
// Check the value of the SECOND radio button group in question
(radioVal2 == '')) { 
alert("As you have answered 'Yes' to the question:\n\n'Do you provide advice or information?',  \n\nplease answer the question:\n\nIs advice or information provided for a fee?"); 
document.Voip1.advice_for_fee[0].focus(); // and focus on the first option
return false; 
}

// LIABILITY SECTION ENDS




// BUSINESS INTERRUPTION SECTION STARTS

//  nothing is required in this section, as it might be that the proposal is solely for a shop - see instruction on form at beginning of section


// BUSINESS INTERRUPTION SECTION ENDS





// GENERAL QUESTIONS SECTION STARTS

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.prem_good_state); 
//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: \n\n'Are your premises in a good state of repair?'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.prem_good_state[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.non_x_walls_or_roofs); 
//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: \n\n'Do any of the buildings that you occupy have walls that are not made of brick, stone or concrete, or roofs not made of slate, tile, concrete, metal or asbestos?'  \n \nSorry, but you MUST make a selection!"); 
document.Voip1.non_x_walls_or_roofs[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.previous_insurance); 
//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: \n\n'Has your organisation previously held insurance?'  \n \nSorry, but you MUST make a selection!"); 
document.Voip1.previous_insurance[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.previous_refusal); 
//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: \n\n'Has any previous insurer declined a proposal, \nrefused to renew a policy or imposed special terms or conditions?'  \n \nSorry, but you MUST make a selection!"); 
document.Voip1.previous_refusal[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.previous_offence); 
//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: \n\n'Has any Director or Trustee been convicted of,\nor is any prosecution pending for, arson or \nany offence involving dishonesty of any kind, \ne.g. fraud, robbery, theft or handling of stolen goods?'  \n \nSorry, but you MUST make a selection!"); 
document.Voip1.previous_offence[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.declared_bankrupt); 
//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: \n\n'Has any Director, Trustee or Office Bearer ever been \ndeclared bankrupt or insolvent?'  \n \nSorry, but you MUST make a selection!"); 
document.Voip1.declared_bankrupt[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.claims_last5yrs); 
//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: \n\n'Has your organisation incurred any loss, \ndestruction or damage, or made any claims, \nor had any claim made against it \nin the last 5 years?'  \n \nSorry, but you MUST make a selection!"); 
document.Voip1.claims_last5yrs[0].focus(); // and focus on the first option
return false; 
}

// check whether any of a number of radio grops have a 'Yes' response, and iff one or more does, check that a textbox or textarea is not blank
//IFF potential_claim_aware OR potential_losses_aware OR potential_consideration_aware THEN potential_claim_details
var radioVal1 = valRadiobutton(document.Voip1.non_x_walls_or_roofs); 
var radioVal2 = valRadiobutton(document.Voip1.previous_insurance); 
var radioVal3 = valRadiobutton(document.Voip1.previous_refusal);
var radioVal4 = valRadiobutton(document.Voip1.previous_offence); 
var radioVal5 = valRadiobutton(document.Voip1.declared_bankrupt); 
var radioVal6 = valRadiobutton(document.Voip1.claims_last5yrs);  
if(((radioVal1 == 'Yes') || (radioVal2 == 'Yes')  || (radioVal3 == 'Yes')  || (radioVal4 == 'Yes')  || (radioVal5 == 'Yes')  || (radioVal6 == 'Yes')) && (document.Voip1.gen_ques_details.value == '')) { 
alert("As you have answered 'Yes' to AT LEAST ONE of the questions:\n\n'2 - 7 in the section 'General Questions', \n\nplease fill in the field:\n\nIf you have answered yes to questions \n2-7 please provide details"); 
document.Voip1.gen_ques_details.focus(); 
return false; 
}

// GENERAL QUESTIONS SECTION ENDS


// QUOTES FOR OTHERS?		STARTS

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.theft_by_employee); 
//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: \n\n'Do you require quotations for any of the following cover? \n\n     Theft by Employee'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.theft_by_employee[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.personal_accident); 
//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: \n\n'Do you require quotations for any of the following cover? \n\n     Personal Accident'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.personal_accident[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.legal_expenses); 
//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: \n\n'Do you require quotations for any of the following cover? \n\n     Legal Expenses'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.legal_expenses[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.trustee_insurance); 
//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: \n\n'Do you require quotations for any of the following cover? \n\n     Trustee Insurance'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.trustee_insurance[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.counselling_services); 
//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: \n\n'Do you require quotations for any of the following cover? \n\n     Counselling Services'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.counselling_services[0].focus(); // and focus on the first option
return false; 
}

// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.loss_of_no_claims); 
//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: \n\n'Do you require quotations for any of the following cover? \n\n     Loss of No Claim Discount for Volunteers'  \n\nSorry, but you MUST make a selection!"); 
document.Voip1.loss_of_no_claims[0].focus(); // and focus on the first option
return false; 
}

// QUOTES FOR OTHERS?		ENDS





// DISCLOSURE OF MATERIAL INFO STARTS

//check a field to make sure it's not blank 
if(document.Voip1.material_info_disclosure_details.value == '') { 
alert('Please fill in the field:\n\n\'Please disclose here any such material information\neven if you have doubts as to whether it is material or not\'\n\nPlease state \'No material information to disclose\', if appropriate, or provide comments or explanations if unsure about disclosure.'); 
document.Voip1.material_info_disclosure_details.focus(); 
return false; 
}

// DISCLOSURE OF MATERIAL INFO ENDS





// Get the value of the radio button group in question
// valRadioButton is a function we define down below 
var radioVal = valRadiobutton(document.Voip1.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\n'Are you resubmitting...' question. \n\nSorry, but you MUST make a selection!"); 
document.Voip1.resubmitting[1].focus(); 
return false; 
}

//check a field to make sure it's not blank 
if(document.Voip1.Full_Name.value == '') { 
alert('Please fill in the field:\n\nName of Director/Trustee/Office Bearer'); 
document.Voip1.Full_Name.focus(); 
return false; 
}

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

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

return; 

}// end validate function 



/*  this function gets the value of a 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 


//EOF