

/*** Checkout variable ***/

var dl = 0;

/*** ICOMMERCE ***/

function init(page)
{
	$("ul#topMenu").superfish({hoverClass:'topMenuHover',speed:'fast',delay:200});
	// limit width to between 779 and 1003
	if (document.all) {
		var thePage = document.getElementById('page');
		var theWidth = getWidth(thePage);
		if (theWidth>1003) thePage.style.width = "1003px";
		if (theWidth<779)  thePage.style.width = "779px";
	}
	setHeight(document.getElementById('bodyBlock'));
}






// ** Show currency converter for Value 'thePrice' **
function cConvert(thePrice)
{
//	var theURL = "http://www.xe.net/pca/input.cgi?amount=" + thePrice + "&From=AUD";

	CurrencyWindow = window.open ("http://www.xe.net/pca/input.cgi?Amount=" + thePrice + "&From=AUD", 
									'CurrencyWindow', 
									'toolbar=0,location=0,directories=0=0,menubar=0,scrollbars=0,resizable=1,height=170,width=600');
	CurrencyWindow.focus();
}

function verifyQuantity(theField)
{
	var theValue				= theField.value;

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

	if (theValue.length < 1)	theField.value  = "0.00";
	if (isNaN(theValue))		theField.value  = "0.00";
	theValue					= theValue - 0;
	if (theValue < 1) 			theField.value	= "0.00";
}

/*** COLUMN HEIGHTS ***/

function getWidth(theEl)
{
	return (theEl.currentStyle) ? theEl.offsetWidth : stripPX(document.defaultView.getComputedStyle(theEl,'').width);
}
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("leftColumn");
	var theMiddle    	= document.getElementById("contentColumn");
	var theMiddleWide  	= document.getElementById("contentColumnWide");
	var rightSide   	= document.getElementById("rightColumn");
	
	leftSideHeight  	= (leftSide)		? Math.ceil(parseInt(getHeight(leftSide)))  		: 0;
	theMiddleHeight 	= (theMiddle)   	? Math.ceil(parseInt(getHeight(theMiddle))) 		: 0;
	theMiddleWideHeight = (theMiddleWide)   ? Math.ceil(parseInt(getHeight(theMiddleWide))) 	: 0;
	rightSideHeight 	= (rightSide)   	? Math.ceil(parseInt(getHeight(rightSide))) 		: 0;
	
	if (theMiddleWideHeight > theMiddleHeight) theMiddleHeight = theMiddleWideHeight;

	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";
		if (theMiddleWide)  theMiddleWide.style.minHeight   = tallestColumn+"px";
		if (rightSide)  	rightSide.style.minHeight   	= tallestColumn+"px";
	}
	else
	{
		if (leftSide)   	leftSide.style.height   		= tallestColumn+"px";
		if (theMiddle)  	theMiddle.style.height  		= tallestColumn+"px";
		if (theMiddleWide)  theMiddleWide.style.height  	= tallestColumn+"px";
		if (rightSide)  	rightSide.style.height  		= tallestColumn+"px";
	}

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


}

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

function isFieldEmpty(theField)
{
	return (theField.value.length < 1) ? true : false;
}
function isFieldBadEmail(theField)
{
	theEmail = theField.value;
	if (theEmail.indexOf('@')==-1 || theEmail.indexOf('.')==-1 || theEmail.length<6) return true;
	return false;
}
function clearQuotes(theForm)
{
	for (i = 0; i < theForm.elements.length; i++)
	{
		if (theForm.elements[i].value) theForm.elements[i].value = theForm.elements[i].value.replace(/'/gi,"`");
	}
}
function showPicture(theImage,width,height)
{
	if (width > 800)	width = 800;
	if (height > 600)   height = 600;
	
	pathname = self.location.pathname.substr(0, self.location.pathname.lastIndexOf("/") + 1);
	if (pathname.indexOf("gallery/") != -1) pathname = pathname.substr(0, pathname.indexOf("gallery/"));
	url = "http://"+self.location.host+pathname+"story/showPicture.php?id=" + theImage;
	showPictureWindow = window.open (url, 'showPicture', 'toolbar=0,location=0,directories=0=0,menubar=0,scrollbars=1,resizable=1,height='+height+',width='+width);
	showPictureWindow.focus();
}

function addBookmarkForBrowser() {
  if (document.all)
  {
    window.external.AddFavorite(document.location.href, document.title);
  } 
}


function checkSideQuoteFormHeyaDude() {
	var theForm = document.getElementById('uQuoteForm');
	if (theForm.firstname.value.length<1) {alert("Please enter your given name.");return false;}
	if (theForm.lastname.value.length<1) {alert("Please enter your family name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	var checksum = 0;
	if (theForm.email.value.indexOf('.')==-1) checksum++;
	if (theForm.email.value.indexOf('@')==-1) checksum++;
	if (theForm.email.value.length<6) checksum++;
	if (checksum>0) {alert("The email address you have entered does not appear to be valid. Please check it.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}
	if (theForm.street1.value.length<1) {alert("Please enter your street address.");return false;}
	if (theForm.suburb.value.length<1) {alert("Please enter your town or suburb.");return false;}
	if (theForm.postcode.value.length<1) {alert("Please enter your postcode.");return false;}
	checksum = 0;
	if (theForm.postcode.value.length!=4) checksum++;
	if (isNaN(theForm.postcode.value-0)/2) checksum++;
	if ((theForm.postcode.value-0)<6000) checksum++;
	if ((theForm.postcode.value-0)>6999) checksum++;
	if (checksum>0) {alert("The postcode you have entered does not appear to be a valid Western Australian postcode. Please check it.");return false;}
	return true;
}

