// JavaScript Document
/* 
	What this is: general form validation.
	Author: Jason Yeung
	First Created: Mar. 12, 2001
	
	Modifications:
	
	Mar. 20, 2001 (Jason)	- Created for the create user form in the nca directory (form_user.cfm)
	Dec. 05, 2001 (Jason)	- Modified for use in Newsletter Factory
*/

// General function that returns a string with its spaces removed.
function ignoreSpaces(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++) {
		temp += splitstring[i];
	}
	return temp;
}

// General function that returns false if "fieldname" is empty.
function checkfield(fieldname) {
	var strStripped = ignoreSpaces(fieldname.value);
	var fieldval = (fieldname.value.length == 0) ? false: true;
	return fieldval;
}


// General function that returns the value of a field.
function getfieldvalue(fieldname) {
	var fieldval = ignoreSpaces(fieldname.value);
	return fieldval;
}




// General function that returns false if "fieldname" is empty.
function checkbox(fieldname) {
	var fieldval = (fieldname.checked) ? true: false;
	return fieldval;
}

// General function that returns false if "fieldname" is not a number.
function checknumber(fieldname) {
	var strStripped = ignoreSpaces(fieldname.value);
	var numPattern = /\d/;
	var nonNumPattern = /\D/;

	var isNumber = ( strStripped.match(numPattern) == null )? false : true;
	var isNonNumber = ( strStripped.match(nonNumPattern) == null )? false : true;

	var fieldval = ( isNumber && !isNonNumber ) ? true : false;
	return fieldval;
}

// General function that returns false if "fieldname" is not a floating point number.
function checkfloat(fieldname) {
	var strStripped = ignoreSpaces(fieldname.value);
	var floatPattern = /^(\d+\.?\d*|\.\d+)$/;
	var isFloat = ( strStripped.match(floatPattern) == null )? false : true;
	return isFloat;
}

// 
function checkoption(fieldname) {
	if ( (! fieldname.options[fieldname.selectedIndex].value)
	  || (fieldname.options[fieldname.selectedIndex].value.toString().length < 1)
	  || (fieldname.options[fieldname.selectedIndex].value == 0)
	){
		return false;
	} else {
		return true;
	}
}

// 
function checkoptionvalue(fieldname) {
	fieldvalue = fieldname.options[fieldname.selectedIndex].value;
	return fieldvalue;
}



// check equipment & accessories - default val = 0.00
function checkequipment(fieldname) {
	if ( (! fieldname.options[fieldname.selectedIndex].value)
	  || (fieldname.options[fieldname.selectedIndex].value.toString().length < 1)
	  || (fieldname.options[fieldname.selectedIndex].value == 0)
	){
		return false;
	} else {
		return true;
	}
}
// check birth day
function checkdate(fieldname) {
	if (fieldname.options[fieldname.selectedIndex].value == "0"){
	return false;
	} else {
		return true;
	}
}

// General function that checks for valid E-mail. Returns false if not valid.
/* function checkemail(fieldname) {

	if (!checkfield(fieldname)) {
		return false;
	}

	invalidchars = " /:,;"
	for (count = 0; count < invalidchars.length; count++) {
		badchar = invalidchars.charAt(count);
		if (fieldname.value.indexOf(badchar,0) > -1) {
			return false;
		}
	}

	atpos = fieldname.value.indexOf("@", 1);
	if (atpos == -1) {
		return false;
	}
	if (fieldname.value.indexOf("@", atpos + 1) > -1) {
		return false;
	}

	periodpos = fieldname.value.indexOf(".", atpos);
	if (periodpos == -1) {
		return false;
	}
	if (periodpos + 3 > fieldname.value.length) {
		return false;
	}
	return true;
} */

/* 
bug: does not allow hyphenated domain names - i.e. winfall-lottery.com
function checkemail(fieldname) {
	var strStripped = ignoreSpaces(fieldname.value);
	// 	var emailPattern = /\w{1,}@\w{1,}\.\w{1,}/;			// Pattern is "j@g.f"
	//	var emailPattern = /\S+@\S+\.\S+/;					// Pattern is "j@g.f"
	var emailPattern = /\w+@\w.+\w+/;	
	var isEmail = ( strStripped.match(emailPattern) == null )? false : true;
	return isEmail;
}
*/

// validate email
function checkemail(fieldname) {
	var emailPattern = (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
	var isEmail = emailPattern.test(fieldname.value);
	return isEmail;
	}

// General function that returns false a radio button is not checked
function checkradio(fieldname) {
	var numradio = fieldname.length;
	var onechecked = false;
	for (counter = 0; counter < numradio; counter++) {
		if ( fieldname[counter].checked ) {
			onechecked = true;
		}
	}
	return onechecked;
}

function checkradiovalue(fieldname) {
	var numradio = fieldname.length;
	var rad_val = "";
	for (var i=0; i < numradio; i++)
	   {
	   if (fieldname[i].checked)
	      {
	       rad_val = fieldname[i].value;
	      }
	   }
	   return rad_val;
}




/* 
	What this is: general form validation.
	Author: Jason Yeung
	First Created: Mar. 12, 2001
	
	Modifications:
	
	Mar. 20, 2001 (Jason)	- Created for the create user form in the nca directory (form_user.cfm)
	Dec. 07, 2001 (Jason)	- Modified for use in Newsletter Factory 
								(make sure that in the HTML file, the file formvalidation.js is included before this. The
								functions in that file are used in this one).
*/



function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
 
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
 
    var newstr = string.substring(0,i) + by;
 
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
 
    return newstr;
}

// This checks the form submission when submitting an order. This uses array indices, so order of the form fields ARE important.
function checkform(f) {
	
	//var out = document.getElementById('txtFirstname');
	//out.value = "";
	
	var firstnameval = checkfield(f.firstname);		// Name field
	var lastnameval = checkfield(f.lastname);	// Name field
	var genderval = checkoption(f.gender);	// Gender field
	var heightval = checkfield(f.height);	
	var weightval = checkfield(f.weight);	
	var shoesizeval = checkfield(f.shoesize);	
	var footlengthval = checkfield(f.footlength);	
	var addressval = checkfield(f.address);	
	var cityval = checkfield(f.city);	
	var provval = checkfield(f.prov);	
	var postalval = checkfield(f.postal);
	
	var phone_areaval = checkfield(f.phone_area);
	var phone_oneval = checkfield(f.phone_one);
	var phone_twoval = checkfield(f.phone_two);
	var ccnumval = checkfield(f.ccnum);		
	var ccnameval = checkfield(f.ccname);	
	var ccexpiryval = checkfield(f.ccexpiry);	
	
	var emailval = checkemail(f.email);
	/*
	var alt_areaval = checkfield(f.alt_area);
	var alt_oneval = checkfield(f.alt_one);
	var alt_twoval = checkfield(f.alt_two);
	*/
	
	var insuranceval = checkradio(f.insurance);
	var depositval = checkbox(f.deposit);
	
	var sbtypeval = checkequipment(f.sbtype);
	var sbsizeval = checkoption(f.sbsize);
	
	var hpsbtypeval = checkequipment(f.hpsbtype);
	var hpsbsizeval = checkoption(f.hpsbsize);
	
	var skitypeval = checkequipment(f.skitype);
	var skisizeval = checkoption(f.skisize);
	
	var hpskitypeval = checkequipment(f.hpskitype);
	var hpskisizeval = checkoption(f.hpskisize);
	
	var helmettypeval = checkequipment(f.helmettype);
	var helmetsizeval = checkoption(f.helmetsize);
	
	/*var gogglestypeval = checkequipment(f.gogglestype);
	var gogglessizeval = checkoption(f.gogglessize);
	
	var glovestypeval = checkequipment(f.glovestype);
	var glovessizeval = checkoption(f.glovessize);*/
	
	var jacketpanttypeval = checkequipment(f.jacketpanttype);
	var jacketpantsizeval = checkoption(f.jacketpantsize);
	
	var birth_yearval = checkdate(f.birth_year);
	var birth_monthval = checkdate(f.birth_month);
	var birth_dayval = checkdate(f.birth_day);
	
	var rentaldayval = checkdate(f.rentalday);
	var rentalmonthval = checkdate(f.rentalmonth);
	var rentalyearval = checkdate(f.rentalyear);
	
//out.value += "a";
    
	var snowboarderval = checkradio(f.snowboardertype);
//out.value += "A";
	
	var howval = checkfield(f.how);
//out.value += "B";
	
	
	//get the value of each field
	var confirmnovalue = getfieldvalue(f.confirmno);
//out.value += "C";
	// 1. personal info
	var firstnamevalue = getfieldvalue(f.firstname); // Name field
//out.value += "D";
	var lastnamevalue = getfieldvalue(f.lastname);	// Name field
//out.value += "b";
	var addressvalue = getfieldvalue(f.address);	
	var phone_areavalue = getfieldvalue(f.phone_area);
	var phone_onevalue = getfieldvalue(f.phone_one);
	var phone_twovalue = getfieldvalue(f.phone_two);
	var emailvalue = getfieldvalue(f.email);
	var heightvalue = getfieldvalue(f.height);	
	var weightvalue = getfieldvalue(f.weight);	
	var footlengthvalue = getfieldvalue(f.footlength);
	var foottypevalue = checkoptionvalue(f.foot_type);
//	alert (phone_onevalue);
//	alert (phone_twovalue);
//	alert (foottypevalue);
	
	
	//var birth_yearvalue = checkoptionvalue(f.birth_year);
	var birth_yearvalue = document.equipmentrental.birth_year.options[document.equipmentrental.birth_year.selectedIndex].text;
	var birth_monthvalue = checkoptionvalue(f.birth_month);
	var birth_dayvalue = document.equipmentrental.birth_day.options[document.equipmentrental.birth_day.selectedIndex].text;
	var agevalue = getfieldvalue(f.age);
	var gendervalue = checkoptionvalue(f.gender);	
	
	
	
	
	
	// Gender field
	//var shoesizevalue = getfieldvalue(f.shoesize);	
	//var cityvalue = getfieldvalue(f.city);	
	//var provvalue = getfieldvalue(f.prov);
	
	
	// 2. rental date and time
	var rentaldayvalue = checkoptionvalue(f.rentalday);
	var rentalmonthvalue = checkoptionvalue(f.rentalmonth);
	var rentalyearvalue = checkoptionvalue(f.rentalyear);
	
		var rentalday = f.rentalday.value;
	var now = new Date();
    var thisDay = now.getDate(), thisMonth = now.getMonth()+1, thisYear = now.getYear(), thisHours = now.getHours();
   var yearsDifference = rentalyearvalue - thisYear, monthsDifference = rentalmonthvalue - thisMonth;
    var daysDifference = rentaldayvalue - thisDay;
	
	//alert(yearsDifference);
	//alert(monthsDifference);
	//alert(daysDifference);
	//alert(thisHours);
	//return false;
	// 3. equipment info
	// snowboard 
	var sbtypevalue = checkoptionvalue(f.sbtype);  // 0.00
	var sbsizevalue = checkoptionvalue(f.sbsize);
	var hpsbtypevalue = checkoptionvalue(f.hpsbtype);
	var hpsbsizevalue = checkoptionvalue(f.hpsbsize);
	//ski
	var skitypevalue = checkoptionvalue(f.skitype); // 0.00
	var skisizevalue = checkoptionvalue(f.skisize);
	var hpskitypevalue = checkoptionvalue(f.hpskitype); // 0.00
	var hpskisizevalue = checkoptionvalue(f.hpskisize);
	// accessories
	var helmettypevalue = checkoptionvalue(f.helmettype); // 0.00
	var helmetsizevalue = checkoptionvalue(f.helmetsize);
	/*var gogglestypevalue = checkoptionvalue(f.gogglestype); // 0.00
	var gogglessizevalue = checkoptionvalue(f.gogglessize);
	var glovestypevalue = checkoptionvalue(f.glovestype); // 0.00
	var glovessizevalue = checkoptionvalue(f.glovessize);*/
	var jacketpanttypevalue = checkoptionvalue(f.jacketpanttype); // 0.00
	var jacketpantsizevalue = checkoptionvalue(f.jacketpantsize);
	

	
	//4. coast info
	
	var totalvalue = getfieldvalue(f.total);
	var ccnumvalue = getfieldvalue(f.ccnum);
	var ccnamevalue = getfieldvalue(f.ccname);
	var ccexpiryvalue = getfieldvalue(f.ccexpiry);
	//var depositval = checkbox(f.deposit); yes
	var deposittypevalue = checkoptionvalue(f.deposittype);
	var insurancevalue = checkradiovalue(f.insurance);  //0.00
	var agreementval = checkbox(f.agreement);
	
	//alert (f.insurance);
	//alert (firstnamevalue);
	//alert (gendervalue);
	//alert (insurancevalue);
	//return false;
	
	
	var formvalid = true;
	var focusfield = "";
	var errormsg = "The following errors were found when attempting to submit the form:\n\n";
    
    do {
	if (!firstnameval) {
		formvalid = false;
		errormsg = errormsg + '  - First name is missing.\n';
		focusfield = f.firstname;
		break;
	}
	
	if (!lastnameval) {
		formvalid = false;
		errormsg = errormsg + '  - Last name is missing.\n';
		focusfield = f.lastname;
		break;
	}
	if (!birth_yearval || !birth_monthval || !birth_dayval) {
		formvalid = false;
		errormsg = errormsg + '  - Birth day is missing.\n';
		focusfield = f.birth_year;
		break;
	}
	if (!genderval) {
		formvalid = false;
		errormsg = errormsg + '  - Gender is missing.\n';
		focusfield = f.gender;
		break;
	}
	if (!heightval) {
		formvalid = false;
		errormsg = errormsg + '  - Height is missing.\n';
		focusfield = f.height;
		break;
	}
	if (!weightval) {
		formvalid = false;
		errormsg = errormsg + '  - Weight is missing.\n';
		focusfield = f.weight;
		break;
	}
	if (!shoesizeval) {
		formvalid = false;
		errormsg = errormsg + '  - Shoe size is missing.\n';
		focusfield = f.shoesize;
		break;
	}
	if (!footlengthval) {
		formvalid = false;
		errormsg = errormsg + '  - Foot length is missing.\n';
		focusfield = f.footlength;
		break;
	}
	if (!addressval) {
		formvalid = false;
		errormsg = errormsg + '  - Address is missing.\n';
		focusfield = f.address;
		break;
	}
	if (!cityval) {
		formvalid = false;
		errormsg = errormsg + '  - City is missing.\n';
		focusfield = f.city;
		break;
	}
	if (!provval) {
		formvalid = false;
		errormsg = errormsg + '  - Province is missing.\n';
		focusfield = f.prov;
		break;
	}
	if (!postalval) {
		formvalid = false;
		errormsg = errormsg + '  - Postal/zip is missing.\n';
		focusfield = f.postal;
		break;
	}
	if (!phone_areaval || !phone_oneval || !phone_twoval) {
		formvalid = false;
		errormsg = errormsg + '  - Phone is missing.\n';
		focusfield = f.phone_area;
		break;
	}
	
	if (!emailval) {
		formvalid = false;
		errormsg = errormsg + '  - Email is missing or format is not correct.\n';
		focusfield = f.email;
		break;
	}
	if (!rentaldayval || !rentalmonthval || !rentalyearval) {
		formvalid = false;
		errormsg = errormsg + '  - Rental date is missing.\n';
		focusfield = f.rentalyear;
		break;
	}
	//*start to Snowboard Equipment
	if ( (sbsizeval) && !sbtypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Snowboarder type missing.\n';
		focusfield = f.sbtype;
		break;
	}
	if ( (sbtypeval) && !sbsizeval ) {
		formvalid = false;
		errormsg = errormsg + '  - Snowboard size missing.\n' + '"' + sbtypeval + '" "' + sbsizeval + '"';
		focusfield = f.sbsize;
		break;
	}
	if ( (hpsbsizeval) && !hpsbtypeval ) {
			formvalid = false;
			errormsg = errormsg + '  - High-Performance Snowboarder type is missing.\n';
			focusfield = f.hpsbtype;
		break;
	}
	if ( (hpsbtypeval) && !hpsbsizeval  ) {
			formvalid = false;
			errormsg = errormsg + '  - High-Performance Snowboard size is missing.\n';
			focusfield = f.hpsbsize;
		break;
	}
	if ( (skisizeval) && !skitypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Ski type missing.\n';
		focusfield = f.skitype;
		break;
	}
	if ( (skitypeval) && !skisizeval ) {
		formvalid = false;
		errormsg = errormsg + '  - Ski size missing.\n';
		focusfield = f.skisize;
		break;
	}
	if ( (hpskisizeval) && !hpskitypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Hi Performance Ski type missing.\n';
		focusfield = f.hpskitype;
		break;
	}
	if ( (hpskitypeval) && !hpskisizeval) {
		formvalid = false;
		errormsg = errormsg + '  - Hi Performance Ski size missing.\n';
		focusfield = f.hpskisize;
		break;
	}
	if ( (helmetsizeval) && !helmettypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Helmet type missing.\n';
		focusfield = f.helmettype;
		break;
	}
	if ( (helmettypeval) && !helmetsizeval) {
		formvalid = false;
		errormsg = errormsg + '  - Helmet size missing.\n';
		focusfield = f.helmetsize;
		break;
	}
	/*if ( !gogglestypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Goggles type missing.\n';
		focusfield = f.gogglestype;
		break;
	}
	if ( !gogglessizeval) {
		formvalid = false;
		errormsg = errormsg + '  - Goggles size missing.\n';
		focusfield = f.gogglessize;
		break;
	}
	if ( !glovestypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Gloves type missing.\n';
		focusfield = f.glovestype;
		break;
	}
		if (!glovessizeval) {
		formvalid = false;
		errormsg = errormsg + '  - Gloves size missing.\n';
		focusfield = f.glovessize;
		break;
	}*/
	if ( (jacketpantsizeval) && !jacketpanttypeval) {
		formvalid = false;
		errormsg = errormsg + '  - Jacket and Pants type missing.\n';
		focusfield = f.jacketpanttype;
		break;
	}
	if ( (jacketpanttypeval) && !jacketpantsizeval) {
		formvalid = false;
		errormsg = errormsg + '  - Jacket and Pants size missing.\n';
		focusfield = f.jacketpantsize;
		break;
	}
	
	/*
	if (!alt_areaval || !alt_oneval || !alt_twoval) {
		formvalid = false;
		errormsg = errormsg + '  - Alt phone is missing.\n';
		focusfield = f.alt_area;
	}
	*/
	if (!insuranceval) {
		formvalid = false;
		errormsg = errormsg + '  - Insurance is missing.\n';
		focusfield = f.insurancecost;
		break;
	}
	
	if (!ccnumval) {
		formvalid = false;
		errormsg = errormsg + '  - Credit Cart Number is missing.\n';
		focusfield = f.ccnum;
		break;
	}
	
	if (!ccnameval) {
		formvalid = false;
		errormsg = errormsg + '  - Cardholder Name is missing.\n';
		focusfield = f.ccname;
		break;
	}
	
	if (!ccexpiryval) {
		formvalid = false;
		errormsg = errormsg + '  - Expiry Date is missing.\n';
		focusfield = f.ccexpiry;
		break;
	}
	if (!depositval) {
		formvalid = false;
		errormsg = errormsg + '  - Deposit is missing.\n';
		focusfield = f.deposit;
		break;
	}
	if (!howval) {
		formvalid = false;
		errormsg = errormsg + '  - How did you hear about online rentals is missing.\n';
		focusfield = f.how;
		break;
	} 
	if (!agreementval) {
		formvalid = false;
		errormsg = errormsg + '  - You must agree to the Rental Waiver.\n';
		focusfield = f.agreement;
		break;
	}
	
	
	
	 
	
	//var yearsDifference = rentalyearval - thisYear, monthsDifference = rentalmonthval - thisMonth;
	//if (daysDifference <= 0 ||(daysDifference ==1 &&thisHours >=21) ) {
     //   formvalid = false;
		//errormsg = errormsg + '  - Online rental reservations must be made by 9 pm the night before your selected rental date.\n';
	//	focusfield = f.rentalday;
	// }
	 
	 
	// if (!(jacketpantsizevalue == "0.00"))
	 
	 if ((yearsDifference >= 1)|| ((yearsDifference ==0)&&(monthsDifference >=1)) || ((yearsDifference == 0) && (monthsDifference == 0) && (daysDifference >=2)) || ((yearsDifference == 0) && (monthsDifference == 0) && (daysDifference==1) &&(thisHours<21)))      
    { 
	  }
	 else{
        formvalid = false;
		errormsg = errormsg + '  - Online rental reservations must be made by 9 pm the night before your selected rental date.\n';
	focusfield = f.rentalday;
	break;
	 }
	 
	
  } while (false);	
	
	 
	 
	// (yearsDifference > =1) 
	 

	 
	

	
	
	
	/*
	else {
		var rentalDate = checkRentalDate();
		if (!rentalDate){
		formvalid = false;
		errormsg = errormsg + '  - Rental date requires 2 days advance notice.\n';
		focusfield = f.rentalyear;
		}
	}*/
	
  

	
	if ( formvalid ) {
	
	   // var warning = 'Please click "OK" if following is all accurate information \n\n';
	   
	    var warning = '\n';
	
		warning = warning + 'Your Personal Information: \n';
		warning = warning + ' - Name: '+ firstnamevalue +' '+lastnamevalue+'\n';
		warning = warning + ' - Birth Date: '+ birth_monthvalue +'/'+ birth_dayvalue +'/' + birth_yearvalue + '\n';
        warning = warning + ' - Age: '+ agevalue +'\n';
		warning = warning + ' - Gender: '+ gendervalue +'\n';
		warning = warning + ' - Address: '+ addressvalue +'\n';
		warning = warning + ' - Phone: ('+ phone_areavalue +') '+ phone_onevalue + phone_twovalue + '\n';
		warning = warning + ' - Email: '+emailvalue +'\n';
		warning = warning + ' - Height: '+heightvalue +'\n';
		warning = warning + ' - Weight: '+weightvalue +'\n';
		warning = warning + ' - Foot size: '+footlengthvalue +' '+foottypevalue+'\n\n';
		
		warning = warning + 'Your Equipment Infomation: \n';
		// snowboard 
		
		if (!(sbtypevalue == "0")){
		 warning = warning + '   Snowboard Package \n';
		 warning = warning + ' - Type: '+sbtypevalue +'\n';
		 warning = warning + ' - Size: '+sbsizevalue +'\n';
	     }
		 
		 if (!(hpsbtypevalue == "0")){
		 warning = warning + '   High Performance Snowboard Package \n';
		 warning = warning + ' - Type: '+hpsbtypevalue +'_adult \n';
		 warning = warning + ' - Size: '+hpsbsizevalue +'\n';
	     }
		 
		  if (!(skitypevalue == "0")){
		 warning = warning + '   Ski Package  \n';
		 warning = warning + ' - Type: '+skitypevalue +'\n';
		 warning = warning + ' - Size: '+skisizevalue +'\n';
	     }
		 
		 if (!(hpskitypevalue == "0")){
		 warning = warning + '   High Performance Ski Package  \n';
		 warning = warning + ' - Type: '+hpskitypevalue +'_adult \n';
		 warning = warning + ' - Size: '+hpskisizevalue +'\n';
	     }
		 
		 if (!(helmettypevalue == "0")){
		 warning = warning + '   Helmet  \n';
		 warning = warning + ' - Type: '+helmettypevalue +'\n';
		 warning = warning + ' - Size: '+helmetsizevalue +'\n';
	     }
	
	     /*if (!(gogglestypevalue == "0")){
		 warning = warning + '   Goggles  \n';
		 warning = warning + ' - Type: '+gogglestypevalue +'\n';
		 warning = warning + ' - Size: '+gogglessizevalue +'\n';
	     }
		 
		 if (!(glovestypevalue == "0")){
		 warning = warning + '   Gloves \n';
		 warning = warning + ' - Type: '+glovestypevalue +'\n';
		 warning = warning + ' - Size: '+glovessizevalue +'\n';
	     }*/
		 
		 if (!(jacketpanttypevalue == "0")){
		 warning = warning + '   Snow Jacket & Pants  \n';
		 warning = warning + ' - Type: '+jacketpanttypevalue +'\n';
		 warning = warning + ' - Size: '+jacketpantsizevalue +'\n';
	     }
	
		 warning = warning + '\n';
	

		
		warning = warning + 'Your Total Cost and Payment Method Infomation: \n';
		warning = warning + ' - Total Cost: '+totalvalue +'\n';
		warning = warning + ' - Deposit Type: '+deposittypevalue +'\n';
		warning = warning + ' - Insurance Cost: '+insurancevalue +'\n';
		warning = warning + ' - Credit Card Number: '+ccnumvalue +'\n';
		warning = warning + ' - Card Holder Name: '+ccnamevalue +'\n';
		warning = warning + ' - Expiry Date: '+ccexpiryvalue +'\n\n';
		
		
		warning = warning + 'Your Rental Date and Time: \n';
		warning = warning + ' - Date: '+ rentalmonthvalue +'/'+rentaldayvalue+'/'+rentalyearvalue+'\n';
        warning = warning + ' - Time: 9am \n';
		warningfinal = 'Please click "OK" if the following information is accurate \n' + warning;

		var confirmationview = 'The following is your confirmation info. Please print this form as you will be required to give the confirmation number at the time of pick-up in order to receive your equipment. For your records, an email confirmation will be sent to the address you provided. \n\n';
		  confirmationview = confirmationview + 'Your confirmation Number: '+confirmnovalue + '\n';
		  confirmationview = confirmationview + warning;
		  var confirmation = replace(confirmationview,"\n","<br>");
		
		var confirminfo = confirm(warningfinal);
		if (confirminfo) {
			//var agree =  confirm('You might want to print this confirmtion info.\n\n Ok to Print?\n\n' + confirmationview);
       		//if (agree) {
			//	printVersion(confirmation)
			//}
			return true;
		} else {
			return false;
		}
		
		//return true
		
		
		
		
		//return confirm(warning);
		return true;
	} else {
		alert(errormsg);
		if (focusfield != ""){
		focusfield.focus();
		}
		return false;
	}
}




function printIt(){
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) window.print()
}

function printVersion(confirmation){
	//open the popup window and get a handle 
	msgWindow=window.open(' ','printwindow','status=0,menubar=0,toolbar=0,scrollbars=1,resizable=0,width=550,height=500');

	msgWindow.document.open();

	msgWindow.document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"../styles/grouse_styles.css\">\n<BO");
	msgWindow.document.writeln("DY BGCOLOR='#FFFFFF'>");

	//write the form input to the popup window document
	msgWindow.document.writeln("<P class=\"content\">"+confirmation+"</P>");

	msgWindow.document.writeln("<center><form><input type='button' value='Print' onClick='window.print()'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='Close this window' onClick='window.close()'></form></center></FONT>"); 

}




function  updateBDay()
{

    if (document.equipmentrental.age.value == "")
	{

      birthDay = document.equipmentrental.birth_day.options[document.equipmentrental.birth_day.selectedIndex].value;
	  birthMonth = document.equipmentrental.birth_month.options[document.equipmentrental.birth_month.selectedIndex].value;
      birthYear = document.equipmentrental.birth_year.options[document.equipmentrental.birth_year.selectedIndex].value;



      if (birthYear != "0")
      {
        if (birthMonth != "0")
        {
          if (birthDay != "0")
          {

                birthDay = document.equipmentrental.birth_day.options[document.equipmentrental.birth_day.selectedIndex].text;
                birthYear = document.equipmentrental.birth_year.options[document.equipmentrental.birth_year.selectedIndex].text;


                date = new Date();
                month = date.getMonth() + 1;
                year = date.getYear();
                day = date.getDate();

                if (year < 1000)
                {
                  year = year + 1900;
                }

                age = "error"


                if (month > birthMonth)
                {

                    age = year - birthYear;

                }else if (month < birthMonth)
                {

                    age = year - birthYear - 1;


                }else
                {
//                    alert(day + "--" + birthDay);
                    // By Day of month
                    if (day > birthDay)
                    {

                        age = year - birthYear;

                    }else if(day < birthDay)
                    {
                        age = year - birthYear - 1;

                    }else
                    {
                        // Birthday today, give them the discount, what the heck, happy birthday
                        age = year - birthYear - 1;

                    }


                }
//                alert(age);
                document.equipmentrental.age.value = age;
          }
        }
      }
    }
}



// calculate cost
function formatAsPrice(price) {
  var cents = Math.round((100*price)%100);
  var dollars = Math.floor(price);
  if (cents == 0)
    cents = "00";
  else if (cents < 10)
    cents = "0" + cents;
  return dollars + "." + cents;
}

function formatValue(controlID)
{

	if ((isNaN(parseInt(controlID.value))) ||
		 (parseInt(controlID.value) < 0))
		{
		controlID.value = 0;
		}

	controlID.value = Math.round(controlID.value);
}

function Total(controlID)

{
	if (controlID)
	{
		formatValue(controlID);
	}
	
	//snowboard packages
	tempStr = document.equipmentrental.sbtype.options[document.equipmentrental.sbtype.selectedIndex].value;
    tempStrPrice = tempStr.substring(0,4);
document.equipmentrental.sbprice.value =formatAsPrice(tempStrPrice);
    
	tempStr= document.equipmentrental.hpsbtype.options[document.equipmentrental.hpsbtype.selectedIndex].value;
    tempStrPrice = tempStr.substring(0,4);
	document.equipmentrental.hpsbprice.value = formatAsPrice(tempStrPrice);
	
	//ski packages
	tempStr = document.equipmentrental.skitype.options[document.equipmentrental.skitype.selectedIndex].value;
     tempStrPrice = tempStr.substring(0,4);
document.equipmentrental.skiprice.value = formatAsPrice(tempStrPrice);
  
	tempStr = document.equipmentrental.hpskitype.options[document.equipmentrental.hpskitype.selectedIndex].value;
    tempStrPrice = tempStr.substring(0,4);
	document.equipmentrental.hpskiprice.value = formatAsPrice(tempStrPrice);
	//accessories
	tempStr = document.equipmentrental.helmettype.options[document.equipmentrental.helmettype.selectedIndex].value; //helmet
	tempStrPrice = tempStr.substring(0,4);
	document.equipmentrental.helmetprice.value = formatAsPrice(tempStrPrice);
	/*tempStr = document.equipmentrental.gogglestype.options[document.equipmentrental.gogglestype.selectedIndex].value; //goggles
	tempStrPrice = tempStr.substring(0,4);
	document.equipmentrental.gogglesprice.value = formatAsPrice(tempStrPrice);
	tempStr = document.equipmentrental.glovestype.options[document.equipmentrental.glovestype.selectedIndex].value; //gloves
	tempStrPrice = tempStr.substring(0,4);
	document.equipmentrental.glovesprice.value = formatAsPrice(tempStrPrice);*/
	document.equipmentrental.jacketpantprice.value = formatAsPrice(document.equipmentrental.jacketpanttype.options[document.equipmentrental.jacketpanttype.selectedIndex].value); //jacket pant
	
	//insurance
	if (document.equipmentrental.insurance[0].checked){
	//alert (document.equipmentrental.insurance[0].value);
	document.equipmentrental.insurancecost.value = formatAsPrice(document.equipmentrental.insurance[0].value);
	} 
	if (document.equipmentrental.insurance[1].checked) {
	document.equipmentrental.insurancecost.value = formatAsPrice(document.equipmentrental.insurance[1].value);
	}
	
	// calculate subtotal
	document.equipmentrental.subtotal.value = 
		formatAsPrice(
		eval(document.equipmentrental.sbprice.value) + 
		eval(document.equipmentrental.hpsbprice.value) +
		eval(document.equipmentrental.skiprice.value) +
		eval(document.equipmentrental.hpskiprice.value) +
		eval(document.equipmentrental.helmetprice.value) +
		/*eval(document.equipmentrental.gogglesprice.value) +
		eval(document.equipmentrental.glovesprice.value) +*/
		eval(document.equipmentrental.jacketpantprice.value) +
		eval(document.equipmentrental.insurancecost.value)
		);
		
	var subtotal = eval(document.equipmentrental.subtotal.value);
		
	var gst = subtotal * 0.06
   	document.equipmentrental.gst.value = formatAsPrice(gst);
	
	var pst = subtotal * 0.07
	//alert(pst);
   	document.equipmentrental.pst.value = formatAsPrice(pst);
	
	var total = subtotal + gst + pst
   	document.equipmentrental.total.value = formatAsPrice(total);
			

}


function  checkRentalDate()
{
	
    rentalDay = document.equipmentrental.rentalday.options[document.equipmentrental.rentalday.selectedIndex].value;
	rentalMonth = document.equipmentrental.rentalmonth.options[document.equipmentrental.rentalmonth.selectedIndex].value;
    rentalYear = document.equipmentrental.rentalyear.options[document.equipmentrental.rentalyear.selectedIndex].value;

	//todays date + 1
	date = new Date();
	
    month = date.getMonth();
    year = date.getYear();
    day = date.getDate() + 1;;

	date.setDate(day);
	
	//rental date
	newDate = new Date();
	
	newDate.setMonth(rentalMonth - 1);
	newDate.setYear(rentalYear);
	newDate.setDate(rentalDay);
	
	if ( newDate > date){
		return true;
	}else {
		//alert('Rental date requires 2 days advance notice.');
		return false;
	}
	
        
   
}





function checkcontact(f) {
	var first_nameval = checkfield(f.first_name);
	var last_nameval = checkfield(f.last_name);
	var emailval = checkemail(f.email);
	//var subjectint = checknumber(f.subject);
	
	var formvalid = true;
	var focusfield = "";
	var errormsg = "The following errors were found when attempting to submit the form:\n\n";



	if (!last_nameval) {
		formvalid = false;
		errormsg = errormsg + '  - Last Name is required.\n';
		focusfield = f.last_name;
	}
	
	if (!first_nameval) {
		formvalid = false;
		errormsg = errormsg + '  - First Name is required.\n';
		focusfield = f.first_name;
	}
	if (!emailval) {
		formvalid = false;
		errormsg = errormsg + '  - Email invalid.\n';
		focusfield = f.email;
	}
	if ( formvalid ) {
		return true;
	} else {
		alert(errormsg);
		focusfield.focus();
		return false;
	}
	
		
}

function checkquestion(f) {
	var emailval = checkemail(f.email);
	var questionval = checkfield(f.question);
	//var subjectint = checknumber(f.subject);
	
	var formvalid = true;
	var focusfield = "";
	var errormsg = "The following errors were found when attempting to submit the form:\n\n";



	if (!emailval) {
		formvalid = false;
		errormsg = errormsg + '  - Email invalid.\n';
		focusfield = f.email;
	}
	

	if (!questionval) {
		formvalid = false;
		errormsg = errormsg + '  - You have not filled in a Question.\n';
		focusfield = f.question;
	}
	

	if ( formvalid ) {
		return true;
	} else {
		alert(errormsg);
		focusfield.focus();
		return false;
	}
	
		
}

function checkprform(f) {
	var emailval = checkemail(f.email);
	var questionval = checkfield(f.question);
	//var subjectint = checknumber(f.subject);
	
	var formvalid = true;
	var focusfield = "";
	var errormsg = "The following errors were found when attempting to submit the form:\n\n";



	if (!emailval) {
		formvalid = false;
		errormsg = errormsg + '  - Email invalid.\n';
		focusfield = f.email;
	}
	

	if (!questionval) {
		formvalid = false;
		errormsg = errormsg + '  - You have not filled in a Request.\n';
		focusfield = f.question;
	}
	

	if ( formvalid ) {
		return true;
	} else {
		alert(errormsg);
		focusfield.focus();
		return false;
	}
	
		
}


function checkcontus(f) {
	var ContactEmailval = checkemail(f.ContactEmail);
	var CharityNameval = checkfield(f.CharityName);
	var ContactNameval = checkfield(f.ContactName);
	var ContactTelephoneval = checkfield(f.ContactTelephone);
	
	//var messageval = checkfield(f.message);
	//var subjectint = checknumber(f.subject);
	
	var formvalid = true;
	var focusfield = "";
	var errormsg = "The following errors were found when attempting to submit the form:\n\n";

	if (!ContactEmailval) {
		formvalid = false;
		errormsg = errormsg + '  - Email invalid.\n';
		focusfield = f.ContactEmail;
	}
	
	if (!CharityNameval) {
		formvalid = false;
		errormsg = errormsg + '  - Please include a Charity Name.\n';
		focusfield = f.CharityName;
	}
	
	if (!ContactNameval) {
		formvalid = false;
		errormsg = errormsg + '  - Please include a Contact Name.\n';
		focusfield = f.ContactName;
	}
	
	if (!ContactTelephoneval) {
		formvalid = false;
		errormsg = errormsg + '  - Please include a Telephone Number.\n';
		focusfield = f.ContactTelephone;
	}
	
	

	if ( formvalid ) {
		return true;
	} else {
		alert(errormsg);
		focusfield.focus();
		return false;
	}
	
		
}




function OpenWindow( url, width, height, options, name )
{
    if ( ! width ) width = 325;
    if ( ! height ) height = 450;
    if ( ! options ) options = "scrollbars=no,menubar=no,toolbar=no,location=no,status=yes,resizable=no,x=0,y=0";
    if ( ! name ) name = "outsideSiteWindow";

    var newWin = window.open( url, name, "width=" + width + ",height=" + height + "," + options );
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function _CF_onError(form_object, input_object, object_value, error_message)
    {
	alert(error_message);
       	return false;	
    }



function _CF_hasValue(obj, obj_type)
    {
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    	}
    else if (obj_type == "SELECT")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj.options[i].selected && (obj.options[i].value.toString().length > 0))
			return true;
		}

       	return false;	
	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
	{

		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{

        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}

       	return false;	
	}
	}


function  _CF_checkCFForm_1(_CF_this)

    {

    if  (!_CF_hasValue(_CF_this.name, "TEXT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.name, _CF_this.name.value, "Please enter your Name"))

            {

            return false; 

            }

        }


    if  (!_CF_hasValue(_CF_this.day_phone, "TEXT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.day_phone, _CF_this.day_phone.value, "Please enter your Daytime Phone Number"))

            {

            return false; 

            }

        }


    if  (!_CF_hasValue(_CF_this.email, "TEXT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.email, _CF_this.email.value, "Please enter your Email Address"))

            {

            return false; 

            }

        }


    if  (!_CF_hasValue(_CF_this.meals, "SELECT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.meals, _CF_this.meals.value, "Please select a meal"))

            {

            return false; 

            }

        }

    if  (!_CF_hasValue(_CF_this.howdidyouhear, "SELECT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.howdidyouhear, _CF_this.howdidyouhear.value, "Please tell us how you heard of us"))

            {

            return false; 

            }

        }


    return true;

    }