
//functions.js

//Create a boolean variable to check for a valid IE instance.
var xmlhttp = false;

//Check if we are using IE.
try {
	//If the javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	//If not, then use the older active x object.
	try {
		//If we are using IE.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		//Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}

//If we are using a non-IE browser, create a JavaScript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

//A variable used to distinguish whether to open or close the calendar.
var showCalendar = true;

function showHideCalendar() {
	
	//The location we are loading the page into.
	var objID = "calendar";
	
	//Change the current image of the minus or plus.
	if ( showCalendar == true ) {
		//Show the calendar.
		document.getElementById("opencloseimg").src = "images/mins.gif";
		//The page we are loading.
		var serverPage = "calendar.php?count=5";
		//Set the open close tracker variable.
		showCalendar = false;
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	} else {
		//Hide the calendar.
		document.getElementById("opencloseimg").src = "images/plus.gif";
		showCalendar = true;
		
		document.getElementById(objID).innerHTML = "";
	}
	
	
}

function captureDate( year, month, day ) {

	var obj;
	
	obj = document.getElementById("event_year");
	obj.value = year;
	obj = document.getElementById("event_month");
	obj.value = month;
	obj = document.getElementById("event_day");
	obj.value = day;
	
}

// Implement sum function to allow capturing total price for selected product checkboxes
function sumRadio( buttonObj ) {
//	alert( "In sumRadio, buttonObj name is " + buttonObj.name + ", buttonObj value is " + buttonObj.value );
	if ( ( "No" == buttonObj.value ) && ( true == electricity ) ) {
		electricity = false;
		total += 45;
	} else
	if ( ( "Yes" == buttonObj.value ) && ( false == electricity ) ) {
		electricity = true;
		total -= 45;
	}

	updatePrice();
}

function sumChkBox( chkBoxObj ) {
//	if ( chkBoxObj.checked ) setting = ""; else setting = "un";
//	alert( "In sum, chkBoxObj name is " + chkBoxObj.name + ", chkBoxObj value is " + chkBoxObj.value + ", chkBoxObj is " + setting + "checked" );
	if ( chkBoxObj.checked ) {
		total += parseInt( chkBoxObj.value );
	} else {
		total -= parseInt( chkBoxObj.value );
	}

	updatePrice();
}

function sumSelect( selectObj ) {
//	alert( "In sumSelect, selectObj name is " + selectObj.name + ", selectObj value is " + selectObj.value );
	var price = 0;
	switch ( selectObj.name ) {
		case "ProductsSmall":
			price = 89;
			if ( ( 0 != selectObj.value ) && ( false == ps ) ) {
				total += price;
				ps = true;
			} else
			if ( ( 0 == selectObj.value ) && ( true == ps ) ) {
				total -= price;
				ps = false;
			}
			break;
		case "ProductsMedium":
			price = 99;
			if ( ( 0 != selectObj.value ) && ( false == pm ) ) {
				total += price;
				pm = true;
			} else
			if ( ( 0 == selectObj.value ) && ( true == pm ) ) {
				total -= price;
				pm = false;
			}
			break;
		case "ProductsLarge":
			price = 175;
			if ( ( 0 != selectObj.value ) && ( false == pl ) ) {
				total += price;
				pl = true;
			} else
			if ( ( 0 == selectObj.value ) && ( true == pl ) ) {
				total -= price;
				pl = false;
			}
			break;
		case "ProductsHuge":
			price = 265;
			if ( ( 0 != selectObj.value ) && ( false == ph ) ) {
				total += price;
				ph = true;
			} else
			if ( ( 0 == selectObj.value ) && ( true == ph ) ) {
				total -= price;
				ph = false;
			}
			break;
	}

	updatePrice();
}

function updatePrice() {

	var priceDisplayObj = document.getElementById( 'totalPrice' );
	if ( priceDisplayObj )
		priceDisplayObj.innerHTML = total;
}


var total = 0;

var electricity = true;

var ps = false, pm = false, pl = false, ph = false;
