//form validation Philippa Bull Oct 2007 -----------------------------------------------

// checking required fields
// form name is "subform"

function requiredFields() {
var errormessage = new String();
// Put field checks below this point
if(withoutContent(document.subform.wedding_date.value))
	{ errormessage += "\n\nPlease enter a wedding date"; }
if(withoutContent(document.subform.wedding_time.value))
	{ errormessage += "\n\nPlease enter a wedding time"; }
if(withoutContent(document.subform.contact_name.value))
	{ errormessage += "\n\nPlease enter your name"; }
if(withoutContent(document.subform.contact_email.value))
	{ errormessage += "\n\nPlease enter your email address"; }
if(withoutContent(document.subform.tel.value) && withoutContent(document.subform.mob.value))
	{ errormessage += "\n\nPlease enter a telephone number (home or mobile)"; }	

// Put field checks above this point.
if(errormessage.length > 2) {
	alert('NOTE:' + errormessage);
	return false;
	}
return true;
} // end of function requiredFields()

function withoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}
//end of required fields script

//counting checkboxes:

// ceremony - either minister or registrar
function countChecksCeremony(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.minister.checked == true) { count++; }
if(document.subform.registrar_mon.checked == true
|| document.subform.registrar_sat.checked == true
|| document.subform.registrar_sun.checked == true
) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only one of either Minister or Registrar may be selected.');
	}
}

// registrar - only one out of three
function countChecksRegistrar(which) {
var maxchecked = 1;
var count = 0;
if (document.subform.registrar_mon.checked == true) { count++; }
if (document.subform.registrar_sat.checked == true) { count++; }
if (document.subform.registrar_sun.checked == true) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only one Registrar choice may be selected.');
	}

}

function countChecksAccom(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.accom_bridal.checked == true) { count++; }
if(document.subform.accom_b_and_b.checked == true) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only ' + maxchecked + ' accommodation choice may be selected.');
	}
}

function countChecksTrans(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.trans_rolls.checked == true) { count++; }
if(document.subform.trans_vintage.checked == true) { count++; }
if(document.subform.trans_horse.checked == true) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only ' + maxchecked + ' of the three transport choices may be selected');
	}
}

//allowing only one photography type to be selected
function countChecksPhoto(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.photo_budget_12.checked == true
|| document.subform.photo_budget_16.checked == true
) { count++; }
if(document.subform.photo_basic_12.checked == true
|| document.subform.photo_basic_16.checked == true
) { count++; }
if(document.subform.photo_deluxe_16.checked == true
|| document.subform.photo_deluxe_20.checked == true
)
 { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only one type of Photography choice may be selected.');
	}
}

//allowing only one Budget choice
function countChecksPhotoBudget(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.photo_budget_12.checked == true) { count++; }
if(document.subform.photo_budget_16.checked == true) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only one Bronze choice may be selected.');
	}
}

//allowing only one Basic choice
function countChecksPhotoBasic(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.photo_basic_12.checked == true) { count++; }
if(document.subform.photo_basic_16.checked == true) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only one Silver choice may be selected.');
	}
}

//allowing only one Deluxe choice
function countChecksPhotoDeluxe(which) {
var maxchecked = 1;
var count = 0;
if(document.subform.photo_deluxe_16.checked == true) { count++; }
if(document.subform.photo_deluxe_20.checked == true) { count++; }
if(count > maxchecked) {
	eval('document.subform.' + which + '.checked = false');
	alert('Sorry, only one Gold choice may be selected.');
	}
}

//if minister or registrar checked, check wedding venue
function checkVenue() {
if (document.subform.minister.checked == true 
|| document.subform.registrar_mon.checked == true
|| document.subform.registrar_sat.checked == true
|| document.subform.registrar_sun.checked == true
) {
document.subform.wedding_venue.checked = true;
}
}

//if wedding venue unchecked when has already been checked, uncheck minister or registrar
function uncheckCeremony() {
if (document.subform.wedding_venue.checked == false) {
document.subform.minister.checked = false;
document.subform.registrar_mon.checked = false;
document.subform.registrar_sat.checked = false;
document.subform.registrar_sun.checked = false;
}
}

// total the checked values whenever a checkbox is clicked on:
function totalCheckedValues() {
var total = 0;
if(document.subform.wedding_venue.checked == true) { total += parseFloat(document.subform.wedding_venue.value); }
if(document.subform.minister.checked == true) { total += parseFloat(document.subform.minister.value); }
if(document.subform.registrar_mon.checked == true) { total += parseFloat(document.subform.registrar_mon.value); }
if(document.subform.registrar_sat.checked == true) { total += parseFloat(document.subform.registrar_sat.value); }
if(document.subform.registrar_sun.checked == true) { total += parseFloat(document.subform.registrar_sun.value); }
if(document.subform.accom_bridal.checked == true) { total += parseFloat(document.subform.accom_bridal.value); }
if(document.subform.accom_b_and_b.checked == true) { total += parseFloat(document.subform.accom_b_and_b.value); }
if(document.subform.trans_rolls.checked == true) { total += parseFloat(document.subform.trans_rolls.value); }
if(document.subform.trans_vintage.checked == true) { total += parseFloat(document.subform.trans_vintage.value); }
if(document.subform.trans_horse.checked == true) { total += parseFloat(document.subform.trans_horse.value); }
if(document.subform.trans_extra.checked == true) { total += parseFloat(document.subform.trans_extra.value); }
if(document.subform.photo_budget_12.checked == true) { total += parseFloat(document.subform.photo_budget_12.value); }
if(document.subform.photo_budget_16.checked == true) { total += parseFloat(document.subform.photo_budget_16.value); }
if(document.subform.photo_basic_12.checked == true) { total += parseFloat(document.subform.photo_basic_12.value); }
if(document.subform.photo_basic_16.checked == true) { total += parseFloat(document.subform.photo_basic_16.value); }
if(document.subform.photo_deluxe_16.checked == true) { total += parseFloat(document.subform.photo_deluxe_16.value); }
if(document.subform.photo_deluxe_20.checked == true) { total += parseFloat(document.subform.photo_deluxe_20.value); }
if(document.subform.piper.checked == true) { total += parseFloat(document.subform.piper.value); }
if(document.subform.video.checked == true) { total += parseFloat(document.subform.video.value); }
if(document.subform.button_hole.checked == true) { total += parseFloat(document.subform.button_hole.value); }
if(document.subform.insurance.checked == true) { total += parseFloat(document.subform.insurance.value); }
var ts = new String(total);
if(ts.indexOf('.') < 0) { ts += '.00'; } // dealing with decimals
if(ts.indexOf('.') == (ts.length - 2)) { ts += '0'; }
document.subform.formTotal.value = ts;
}

// end of form validation -----------------------------------------------
