

/*** Checkout variable ***/

var dl = 0;

/*** ICOMMERCE ***/

function init(page)
{
	setHeight(document.getElementById('bodyBlock'));

	switch (page)
	{
		case	"emailReminder":
		{
			occasionDate();
			sendReminderOn();
			changeSRDay(document.emailReminder);
			getVerificationImage('');
			break;
		}
		case	"iContact":
		case	"memberCheck":
		case	"checkout":
		{
			getVerificationImage('');
			break;
		}
	}
	/*
	
	if (document.getElementById("leftNavBar"))
	{
		var menu1 = document.getElementById("search1");
		clearMenu("search1");
		writeMenu(menu1,Array0);
		menu1.blur();
	}
	*/
}


/*** COLUMN HEIGHTS ***/

function getHeight(theEl)
{
	return (theEl.currentStyle) ? theEl.offsetHeight : stripPX(document.defaultView.getComputedStyle(theEl,'').height);
}
function stripPX(theValue)
{
	return (theValue.substring(0, theValue.length - 2) - 0);
}
function setHeight(element)
{
	var leftSide		= document.getElementById("leftNavBar");
	var theMiddle    	= document.getElementById("bodyContent");
	var rightSide   	= document.getElementById("rightNavBar");
	
	leftSideHeight  	= (leftSide)		? Math.ceil(parseInt(getHeight(leftSide)))  		: 0;
	theMiddleHeight 	= (theMiddle)   	? Math.ceil(parseInt(getHeight(theMiddle))) 		: 0;
	rightSideHeight 	= (rightSide)   	? Math.ceil(parseInt(getHeight(rightSide))) 		: 0;

	tallestColumn   	= (leftSideHeight > rightSideHeight)	? leftSideHeight	: rightSideHeight;
	tallestColumn   	= (tallestColumn > theMiddleHeight) 	? tallestColumn 	: theMiddleHeight;

	if (element.style.minHeight)
	{
		if (leftSide)   	leftSide.style.minHeight		= tallestColumn+"px";
		if (theMiddle)  	theMiddle.style.minHeight   	= tallestColumn+"px";
	}
	else
	{
		if (leftSide)   	leftSide.style.height   		= tallestColumn+"px";
		if (theMiddle)  	theMiddle.style.height  		= tallestColumn+"px";
	}

	if (theMiddle)  	theMiddle.style.zIndex  		= "1";

}

function verticalAlign() {
	var thePage = document.getElementById("page");
	var theBody = document.body;
	var whiteSpace = getHeight(theBody)-getHeight(thePage);
	if (whiteSpace>0) {
		whiteSpace = Math.floor(whiteSpace/2);
		thePage.style.marginTop=whiteSpace+"px";
	}
}

/*** ICOMMERCE ***/

function verifyQuantity(theField,min) {
	if (isNaN(min)) min=1;
	var theValue=theField.value;
	if (theValue.length<1) theField.value="1";
	if (isNaN(theValue)) theField.value="1";
	theValue=theValue-0;
	if (theValue<min)  theField.value=min;
}

/*** GENERAL FORM CHECKING TOOLS ***/

function fieldEmpty(theField) {
	if (theField.value.length<1) return true;
	return false;
}
function fieldEmail(theField) {
	theEmail = theField.value;
	if (theEmail.indexOf('@')==-1 || theEmail.indexOf('.')==-1 || theEmail.length<6) return true;
	return false;
}
function cleanForm(theForm) {
	for (i=0;i<theForm.elements.length;i++) {
		if (theForm.elements[i].value) theForm.elements[i].value = theForm.elements[i].value.replace(/'/gi,"`");
	}
}

/*** SPECIFIC FORMS ***/

function editMembershipFormCheck()
{
	theForm = document.editMembershipForm;
	cleanForm(theForm);
	if (fieldEmpty(theForm.fname)) {alert("Please enter your first name");theForm.fname.focus();return false;}
	if (fieldEmpty(theForm.lname)) {alert("Please enter your last name");theForm.lname.focus();return false;}
	if (fieldEmpty(theForm.phone1)) {alert("Please enter your phone number");theForm.phone1.focus();return false;}
	if (fieldEmpty(theForm.email)) {alert("Please enter your email address");theForm.email.focus();return false;}
	if (fieldEmail(theForm.email)) {alert("Your email address does not seem to be valid. Please check it.");theForm.email.focus();return false;}

	var thePassword = theForm.phone1.value;
	thePassword = thePassword.replace(/[^0-9]*/gi,"");
	theForm.password.value = thePassword;

	return true;
}


/*** SEARCH MENU ***/

// Dropdown menu code

var Array0 = ["Home","Office","Restaurant/Cafe"];

var Array1 = ["Manual","Automatic"];
var Array2 = ["0-10 Staff","10-50 Staff","Over 50 Staff"];
var Array3 = ["Manual","Automatic"];

var Array11 = ["All","Up to $500","$500 to $1000","$1000 to $3000","Over $3000","Ex Demo Machines"];
var Array12 = Array11;

var Array21 = ["All","Up to $1500","$1500 to $3000","Over $3000","Free Machines"];
var Array22 = Array21;
var Array23 = Array21;

var Array31 = ["All","Up to $3000","Over $3000","Ex Demo Machines","Free Machines"];
var Array32 = Array31;

function clearMenu(targetMenu) {
	targetMenu = document.getElementById(targetMenu);
	targetMenu.options.length=0;
	targetMenu.options[targetMenu.options.length] = new Option("Select...");
}

function writeMenu(targetMenu,sourceArray) {
	for (i=0;i<sourceArray.length;i++) {
		targetMenu.options[targetMenu.options.length] = new Option(sourceArray[i]);
	}
	targetMenu.focus();
}

 function loadMenu(sourceMenu) {
	var theSelected = sourceMenu.selectedIndex;
	if (theSelected==0) return; // do nothing

	var selected1 = document.getElementById("search1").selectedIndex;
	var selected2 = document.getElementById("search2").selectedIndex;
	var sourceArray = "Array"+selected1;

	var targetNum=0;
	if (sourceMenu.id=="search1") { targetNum="2"; clearMenu("search2"); clearMenu("search3")}
	if (sourceMenu.id=="search2") { targetNum="3"; clearMenu("search3"); sourceArray+=selected2;}
	if (sourceMenu.id=="search3") return; // do nothing
	sourceArray = eval(sourceArray);

	var targetMenu = document.getElementById("search"+targetNum);

	writeMenu(targetMenu,sourceArray);
} 

function searchMachines() {
	var searchString="";
	var theForm = document.sideSearch;

	var term1 = theForm.search1.options[theForm.search1.selectedIndex].text; if (term1=="Select...") return false;
	var term2 = theForm.search2.options[theForm.search2.selectedIndex].text; if (term2=="Select...") return false;
	var term3 = theForm.search3.options[theForm.search3.selectedIndex].text; if (term3=="Select...") return false;

	return true;
}
function popuplogin(theURL) {
	var theParams = "width=550,height=360,left=100,top=100,scrollbars=no,resizable=yes,status=no";
	var loginWin = window.open(theURL,"",theParams);
	loginWin.focus();
}

/* **** BOOKING FORM CODE ***** */
// Completely stupid way to do this - but apparently we can't possibly go to a page
// saying 'Please Login' and then automatically popup the login form (when people 
// aren't logged in), no matter how robust that solution is. Instead we have to mess
// around with a whole load of dodgy javascript so the login form pops up *without
// going anywhere first* or the world will end.

function bookingForm() {
	// figure out if person is logged in in a really dodgy way
	var loggedIn = document.getElementById("hLoginForm");
	// If logged in, go to form, if not, popup login, and may God have mercy on our souls
	if (loggedIn) {
		popuplogin('http://www.espressoitalia.com.au/popupLogin/bookService');
	} else {
		self.location.href = "http://www.espressoitalia.com.au/serviceBooking";
	}
}


