// Code from Simmental Java Script
var authVal1=0;
var authVal2=0;
var authVal3=0;
var numParticipants=1;

function updateAuth(newVal, group){
	var currVal;
	
	currVal = document.frmForm.txt_final_total.value;
	
	if (currVal=='') currVal = 0;
	if (currVal=="0.00") currVal = 0;

	switch(group) {
		case 1:
			if(numParticipants==0)							// if not a group
				{	
					numParticipants=1;
					currVal = currVal - authVal1;		// subtract the old authVal
					authVal1 = parseInt(newVal);		// Make the new authVal an integer version of newVal
					currVal = parseInt(currVal) + parseInt(newVal);
				}
			else																// If a group
				{
					authVal1 = parseInt(newVal);
					currVal = currVal - authVal3;		// delete the old amount from the old group
					authVal3 = numParticipants * authVal1; 	// recalculate the group using the new value (due to clicking other radio button
					currVal = parseInt(currVal) + parseInt(authVal3); 	// add new authVal3 to current value
				}
			break;
		case 2:
			currVal = currVal - authVal2;
			authVal2 = parseInt(newVal);
			currVal = parseInt(currVal) + parseInt(newVal);
			break;
		case 3:
			numParticipants = parseInt(newVal);								// record the number of participants in the group
			currVal = currVal - authVal3;											// subtract any old value for the group
				
			if(newVal!=0)
				authVal3 = numParticipants * parseInt(authVal1);// i.e. $300 x 10 guests = $3000
			else
			{
				authVal3 = 0;
				numParticipants=1;
			}
			
			currVal = parseInt(currVal) + parseInt(authVal3);
			break;
	}	
	
	// Put the computed value in the text field
	document.frmForm.txt_final_total.value = currVal + ".00";
}
// End Code from Simmental Java Script
// ------------------------------------------------------------------

	function turnOn(imgName) {
		if (document.images) {
			document[imgName].src = eval(imgName + 'on.src');
		}
	}
	
	function turnOff(imgName) {
		if (document.images) {
			document[imgName].src = eval(imgName + 'off.src');
		}
	}
	
	function cms_popup(theURL,winName,width,height) {
		var myWin = window.open(theURL,winName,'width=' + width + ',height=' + height + ',top=' + (screen.height-height)/2 + ',left=' + (screen.width-width)/2 + ',scrollbars=yes');
	}

	function MM_findObj(n, d) { //v4.01
	 var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	 if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_showHideLayers() { //v3.0 (id, null, 'show/hide')
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	    obj.visibility=v; }
	}
	
// ------------------------------------------------------------------


	function enlargeRuler() {
		minPageHeight = 287;
		minRulerHeight = 0;
		if (document.layers) {
			if (window.innerHeight > minPageHeight) document.images['ruler'].height = (window.innerHeight - minPageHeight) + minRulerHeight;
		}
		else if (document.documentElement.clientHeight > 0) {
			if (document.documentElement.clientHeight > minPageHeight) document.images['ruler'].height = (document.documentElement.clientHeight - minPageHeight) + minRulerHeight;
		}
		else {
			if (document.body.clientHeight > minRulerHeight) document.images['ruler'].height = (document.body.clientHeight - minPageHeight) + minRulerHeight;
		}
	}
	
	function myRuler() {
		minPageHeight = 287;
		minRulerHeight = 0;
		if (document.layers) document.write ('<img src=\"' + rootURL + 'pub/images/dot.gif\" width=\"1\" height=\"'+((window.innerHeight > minPageHeight) ? (window.innerHeight - (minPageHeight + 10)) + minRulerHeight : 1)+'\" name=\"ruler\">');
			else document.write ('<img src=\"' + rootURL + 'pub/images/dot.gif\" width=\"1\" height=\"1\" name=\"ruler\">');
	}
	
	rootURL = "http://www.rfa-dmcservices.com/";



// --------------------------------------------------------------------

function showSection()
	{
		var oForm = document.frmForm;

		if( oForm.sel_payment.value == "Credit Card") {
			document.getElementById('bycheque').style.display = "none";
			document.getElementById('bycredit').style.display = "block";
		}
		else if( oForm.sel_payment.value == "Cheque") {
			document.getElementById('bycredit').style.display = "none";
			document.getElementById('bycheque').style.display = "block";
		}
		else
		{
			document.getElementById('bycredit').style.display = "none";
			document.getElementById('bycheque').style.display = "none";
			}

	}

	
/* For page id 21, to keep runing total of the inventory */

function addRunningTotal() {
	var costs = new Array(50.00,45.00,40.00,17.00,50.00,46.00,42.00,86.50,27.50,0.0);
	var field_names = new Array('','','','','','','','','','');
	
	field_names[0] = 'sel_th_adult';
	field_names[1] = 'sel_th_youth';
	field_names[2] = 'sel_th_child';
	
	field_names[3] = 'sel_fr_yoga';
	
	field_names[4] = 'sel_fr_casa';
	field_names[5] = 'sel_fr_casa_y';
	field_names[6] = 'sel_fr_casa_c';
	
	field_names[7] = 'sel_fr_hock';
	field_names[8] = 'sel_fr_hock_y';
	field_names[9] = 'sel_fr_hock_c';
	
	var sub_total = 0;
	var tax_percent = 0.03;
	var total = 0;
	var total_tax = 0;
	
	for (i = 0; i < 10; i++) {
		if (document.getElementById(field_names[i]).value != '') {
			sub_total = sub_total + (costs[i] * Number(document.getElementById(field_names[i]).value));
		}
	}
	
	total_tax = (Math.round(((tax_percent * sub_total) * 100)) / 100);
	total = sub_total + total_tax;
	document.getElementById('txt_subtotal').value = convertToCurrency(sub_total);
	document.getElementById('txt_service').value = convertToCurrency(total_tax);
	document.getElementById('txt_total').value = convertToCurrency(total);
}

function convertToCurrency(money_val) {
	var round_amt = (Math.round(((money_val) * 100)) / 100);
	var txt_amt = String(round_amt);
	if (txt_amt.indexOf('.') == -1) 
		return txt_amt+'.00';
	var dot_pos = txt_amt.length - txt_amt.indexOf('.');
	if (dot_pos == 3) {
		return txt_amt;
	}
	else if (dot_pos == 2) {
		return (txt_amt+'0');
	}
	else 
		return (txt_amt+'.00');
	
}