// JavaScript Document
//RodRoy Registration registration.js
//deadline year must be changed lines 94-95 +-
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
	function codeDetails(){

		window.open("code_details.htm", "details_win", "width=200, height=400");

	}

function cost() {
	subtotal = 0;
	theSkiPatrol = 0;
	theUSMed = 0;
	if (document.rodroy.programCode.value == "A"){
		subtotal = 259;}
	if (document.rodroy.programCode.value == "S2") {
		subtotal = 572;}
	if (document.rodroy.programCode.value == "J2") {
		subtotal = 572;}
	if (document.rodroy.programCode.value == "B2") {
		subtotal = 572;}
	if (document.rodroy.programCode.value == "K2") {
		subtotal = 572;}
	if (document.rodroy.programCode.value == "S4") {
		subtotal = 637;}
	if (document.rodroy.programCode.value == "J4") {
		subtotal = 637;}
	if (document.rodroy.programCode.value == "B4") {
		subtotal = 637;}
	if (document.rodroy.programCode.value == "K4") {
		subtotal = 637;}
	if (document.rodroy.programCode.value == "SF") {
		subtotal = 677;}
	if (document.rodroy.programCode.value == "JF") {
		subtotal = 677;}
	if (document.rodroy.programCode.value == "BF") {
		subtotal = 677;}
	if (document.rodroy.programCode.value == "KF") {
		subtotal = 677;}
	if (document.rodroy.programCode.value == "S2Uam") {
		subtotal = 355;}
	if (document.rodroy.programCode.value == "J2Uam") {
		subtotal = 355;}
	if (document.rodroy.programCode.value == "S2Upm") {
		subtotal = 328;}
	if (document.rodroy.programCode.value == "J2Upm") {
		subtotal = 328;}
	if (document.rodroy.programCode.value == "B2Uam") {
		subtotal = 355;}
	if (document.rodroy.programCode.value == "D") {
		subtotal = 554;}
	if (document.rodroy.programCode.value == "D1") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "D2") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "D3") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "D4") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "D5") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "D6") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "D6G") {
		subtotal = 609;}
	if (document.rodroy.programCode.value == "E") {
		subtotal = 540;}
	if (document.rodroy.programCode.value == "E1") {
		subtotal = 593; }
	if (document.rodroy.programCode.value == "E2"){
		subtotal = 593;}
	if (document.rodroy.programCode.value == "F") {
		subtotal = 559;}
	if (document.rodroy.programCode.value == "F1") {
		subtotal = 588;}
	if (document.rodroy.programCode.value == "F2") {
		subtotal = 588;}
	if (document.rodroy.programCode.value == "K2Uam") {
		subtotal = 355;}
	if (document.rodroy.programCode.value == "B2Upm") {
		subtotal = 328;}
	if (document.rodroy.programCode.value == "K2Upm") {
		subtotal = 328;}
	if (document.rodroy.programCode.value == "S4U") {
		subtotal = 389;}
	if (document.rodroy.programCode.value == "J4U") {
		subtotal = 389;}
	if (document.rodroy.programCode.value == "B4U") {
		subtotal = 389;}
	if (document.rodroy.programCode.value == "K4U") {
		subtotal = 389;}
	if (document.rodroy.programCode.value == "A2") {
		subtotal = 399;}
	if (document.rodroy.programCode.value == "L2") {
		subtotal = 399;}
	if (document.rodroy.programCode.value == "L") {
		subtotal = 259;}
	if (document.rodroy.programCode.value == "J8") {
		subtotal = 311;}
	if (document.rodroy.programCode.value == "H"){
		subtotal = 556;}
	if (document.rodroy.programCode.value == "H1") {
		subtotal = 526;}
	if (document.rodroy.programCode.value == "SC1"){
		subtotal = 259;}
	if (document.rodroy.programCode.value == "SC2"){
		subtotal = 320;}
	if (document.rodroy.programCode.value == "SC3"){
		subtotal = 340;}
	if (document.rodroy.programCode.value == "SC4"){
		subtotal = 325;}
	if (document.rodroy.programCode.value == "SC5"){
		subtotal = 51.79;}
	if (document.rodroy.programCode.value == "SC5A"){
		subtotal = 67.59;}
	if (document.rodroy.programCode.value == "SC6"){
		subtotal = 55.81;}
	if (document.rodroy.programCode.value == "SC6A"){
		subtotal = 60.24;}
	if (document.rodroy.programCode.value == "SC7"){
		subtotal = 55.81;}
	if (document.rodroy.programCode.value == "SC7A"){
		subtotal = 60.24;}
	if (document.rodroy.programCode.value == "SC8"){
		subtotal = 65.83;}
	if (document.rodroy.programCode.value == "SC8A"){
		subtotal = 69.34;}
	if (document.rodroy.programCode.value == "SC9"){
		subtotal = 65.83;}
	if (document.rodroy.programCode.value == "SC9A"){
		subtotal = 69.34;}
	if (document.rodroy.programCode.value == "SC10"){
		subtotal = 52.00;}
	if (document.rodroy.programCode.value == "SC10A"){
		subtotal = 65.83;}
	if (document.rodroy.programCode.value == "SC11"){
		subtotal = 61.13;}
	if (document.rodroy.programCode.value == "SC11A"){
		subtotal = 64.67;}
	if (document.rodroy.programCode.value == "SC12"){
		subtotal = 52.27;}
	if (document.rodroy.programCode.value == "SC12A"){
		subtotal = 68.22;}
	if (document.rodroy.programCode.value == "M2"){
		subtotal = 262.24;}
	if (document.rodroy.programCode.value == "M3"){
		subtotal = 225.91;}
	if (document.rodroy.programCode.value == "M4"){
		subtotal = 208.20;}
			document.rodroy.subText.value = formatCurrency(subtotal);
			document.rodroy.gst.value = formatCurrency((subtotal * 0.05));
			document.rodroy.pst.value = formatCurrency((subtotal * 1.05 * 0.095));
			document.rodroy.subTax.value = formatCurrency((subtotal * 1.05 * 1.095));

	//function for calculating early registration discount
	//must change deadline years every year!!

		today = new Date();
		discount35 = new Date (2011,09,28);//deadline year must be changed Jan = 00, Feb = 01, Oct =09, Dec = 11;
		discount15 = new Date (2011,11,2);//deadline year must be changed
		theMonth = today.getMonth();
		theDay = today.getDate();

		if (today > discount15){
			theDiscount = 0;
		}
		if (today <= discount15){
			theDiscount = 20;
		}
		if (today <= discount35){
			theDiscount = 40;

		}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "A")){
			theDiscount = 15;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC1")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC1")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC1")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC2")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC2")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC2")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC3")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC3")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC3")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC4")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC4")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC4")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC5")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC5")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC5")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC5A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC5A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC5A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC6")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC6")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC6")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC6A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC6A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC6A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC7")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC7")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC7")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC7A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC7A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC7A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC8")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC8")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC8")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC8A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC8A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC8A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC9")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC9")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC9")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC9A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC9A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC9A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC10")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC10")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC10")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC10A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC10A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC10A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC11")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC11")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC11")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC11A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC11A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC11A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC12")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC12")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC12")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "SC12A")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "SC12A")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "SC12A")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "M2")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "M2")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "M2")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "M3")){
			theDiscount = 0;
			}
	if ((theDiscount == 40) && (document.rodroy.programCode.value == "M3")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "M3")){
			theDiscount = 0;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "M4")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "M4")){
			theDiscount = 0;
			}
		if ((theDiscount == 20) && (document.rodroy.programCode.value == "M4")){
			theDiscount = 0;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "S2Uam")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "S2Uam")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "J2Uam")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "J2Uam")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "S2Upm")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "S2Upm")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "J2Upm")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "J2Upm")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "B2Uam")){
			theDiscount = 25;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "K2Uam")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "K2Uam")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "B2Upm")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "B2Upm")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "K2Upm")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "K2Upm")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "S4U")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "S4U")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "J4U")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "J4U")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "B4U")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "B4U")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "K4U")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "K4U")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "A2")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "A2")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "L2")){
			theDiscount = 25;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "L2")){
			theDiscount = 30;
			}
		if ((theDiscount == 40) && (document.rodroy.programCode.value == "L")){
			theDiscount = 15;
			}
		if ((theDiscount == 50) && (document.rodroy.programCode.value == "L")){
			theDiscount = 15;
			}
		document.rodroy.discount.value = formatCurrency(theDiscount);

		//end of early registration calculations

		// Age discount added 16-sep-2006
                age = 2013 - Right(document.rodroy.DateofBirth.value, 4)
                if (age > 1000) {
                  age = 1;
  		  }
                if ((age >= 65 ) && (document.rodroy.programCode.value == "H")) {
                   theDiscount += 30;
                   }
                if ((age >= 65 ) && (document.rodroy.programCode.value == "H1")) {
                   theDiscount += 30;
                   }
		document.rodroy.discount.value = formatCurrency(theDiscount);
                //alert(age) ;

	        //end Age discount

		//start of US Medical calculations

		if(document.rodroy.usMed[0].checked) {theUSMed =20};
		if(document.rodroy.usMed[1].checked) {theUSMed =0};
		//adjustment for SC5, SC7, SC8 and SC9
		                if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC5"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC5A"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC6"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC6A"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC7"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC7A"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC8"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SCA8A"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC9"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC9A"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC10"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC10A"){
		theUSMed =15};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC11"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC11A"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC12"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "SC12A"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "M2"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "M3"){
		theUSMed =0};
		if(document.rodroy.usMed[0].checked && document.rodroy.programCode.value == "M4"){
		theUSMed =0};
		document.rodroy.Medical.value = formatCurrency(theUSMed);
		//document.rodroy.usvalue.value = theUSMed;

		//end of US Medical
		//start of Ski Patrol calculations
		theSkiPatrol = document.rodroy.skiPatrol.value;
		//end of Ski Patrol



		//Final Calculations
		var theAdjustments = (parseFloat(theUSMed)  + parseFloat(theSkiPatrol) - parseFloat(theDiscount) );

	var theGrandTotal =  theAdjustments + (subtotal * 1.05 * 1.095);
	if (theGrandTotal <= 0){
		theGrandTotal = 0
		};
	document.rodroy.grandTotal.value = formatCurrency(theGrandTotal);

		//addition for postdated cheques
                document.rodroy.postdatedAmount.value = ""
		var postdated = ((theGrandTotal + 5) / 4);
		if (document.rodroy.paymentMethod.value == "Postdated Cheques"){
			var theGrandTotal = theGrandTotal + 5;
			document.rodroy.grandTotal.value = formatCurrency(theGrandTotal);
			document.rodroy.postdatedAmount.value = formatCurrency(postdated);
		}

	//miraPay
	mpGrandTotal = Math.round(theGrandTotal *100);
	mpGrandTotal = mpGrandTotal.toString().replace(/\$|\,/g,'');
	mpGrandTotal = mpGrandTotal.substring(0,mpGrandTotal.length-2)+"."+mpGrandTotal.substring(mpGrandTotal.length-2,mpGrandTotal.length);

        var cdate = new Date(); // 10sep2006
        mtid_num = cdate.getTime() - 1100000000000; // 10sep2006

	//mtid_num =  Math.round(Math.random()*10000000); // commented 10sep2006

	//document.forms[0].elements[38].value = MKEYun;
	//document.forms[0].elements[39].value = MKEY;
	document.rodroy.Amount1.value = mpGrandTotal;//[39] aug2004[38] for index_choice, [40] for mira_index
	document.rodroy.MTID.value = mtid_num;//[38] aug 2004

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


