﻿function imgOn(imgId)
{
	document.getElementById(imgId).src = "gui/" + imgId + "_over.gif";
}


function imgOff(imgId)
{
	document.getElementById(imgId).src ="gui/" + imgId + ".gif";
}

function imgOnGif(imgId)
{
	document.getElementById(imgId).src = "gui/" + imgId + "_over.gif";
}


function imgOffGif(imgId)
{
	document.getElementById(imgId).src ="gui/" + imgId + ".gif";
}

function imgOnAdmin(imgId)
{
	document.getElementById(imgId).src = "../gui/" + imgId + "_over.gif";
}


function imgOffAdmin(imgId)
{
	document.getElementById(imgId).src = "../gui/" + imgId + ".gif";
}


function imgDown (imgId)
{
	document.getElementById(imgId).src ="gui/" + imgId + "_active.gif";
}

//only for maintenance menu "save" and "delete" buttons
function imgOnM(img, ID, bEdit)
{
	var sPrefix = "";
	if (bEdit)
	{
		sPrefix = "../";
	}
	document.getElementById(img + ID).src = sPrefix + "gui/" + img + "_i.gif";
}


function imgOffM(img, ID, bEdit)
{
	var sPrefix = "";
	if (bEdit)
	{
		sPrefix = "../";
	}
	document.getElementById(img + ID).src = sPrefix + "gui/" + img + "_o.gif";
}

// Cross-browser function to add a function to the onload event.
function AddOnload(myfunc)
{

	if(window.addEventListener)	// FireFox
	{
		window.addEventListener('load', myfunc, false);
	}
	else if(window.attachEvent)	// IE
	{
		window.attachEvent('onload', myfunc);
	}
	else if (window.onload)
	{
		var func = window.onload; 
		window.onload = function()
		{
			func();
			myfunc();
		}
	}
	else
	{
		window.onload = myfunc();
	}
}


// The hover function:
//  If there is a child sub-menu, show it on mouseover, hide it on mouseout!
var sfHover = function()
{
	var menu = document.getElementById("menu");
	if (!menu)
	{
		return;
	}
	var listItems = menu.getElementsByTagName("LI");
	for (var i = 0; i < listItems.length; i++)
	{
		listItems[i].onmouseover = function()
		{
			if (this.getElementsByTagName("UL").length > 0)
			{
				// Show the sub-menu
				this.getElementsByTagName("UL").item(0).style.display = "block";
			}
		}
		listItems[i].onmouseout = function()
		{
			if (this.getElementsByTagName("UL").length > 0)
			{
				// Hide the sub-menu
				this.getElementsByTagName("UL").item(0).style.display = "none";
			}
		}
	}
}

AddOnload(sfHover); // Activate the menus when the page loads...

function NotAvailable() 
{
}


function target(url, bType)
{
	window.open(url, bType);
	return false;	
}



//Check if the cart is Empty, if it is empty then customer cann't fill the finalise form
//And Check if total price of the order is less than minimum purchase.
function CheckCart(MinimumOrderAmount)
{
	var NumOfTotalItems, TotalAmountWithGST;

	NumOfTotalItems = readCookie("NumOfTotalItems");
	TotalAmountWithGST = readCookie("TotalAmountWithGST");

	if (NumOfTotalItems == null || parseFloat(NumOfTotalItems) == 0) 
	{
		alert('Your shopping cart is empty.\r\nPlease place an order first.');
		return false;
	}
	
	if (parseFloat(TotalAmountWithGST) < parseFloat(MinimumOrderAmount))
	{
		alert('Minimum order is ' + formatCurrency(MinimumOrderAmount));
		return false;
	}
	
	return true;
}


// Produce a "summary" of the cart in a single line...
function DoCartLine()
{
	var sCartMem = readCookie("Cart");
	if (!sCartMem)
	{
		document.write ("Your cart is empty.");
		return;
	}

	var b64 = Base64.decodeToArray(sCartMem);

	if (b64.length < 20)
	{
		document.write ("Your cart is empty.");
		return;
	}

	var nCartItems = b64[18] + 256 * b64[19]

	if (nCartItems <= 0) 
	{
		document.write ("Your cart is empty.");
	}
	else
	{
		document.write ("Items in cart: " + nCartItems);
	}
}

// This is called from the Cart.
function doCheckout()
{
	var oFrm = document.getElementById("frmCart");
	oFrm.action = "Checkout.asp";
	oFrm.submit();
}
