// ** Various Utilities used throughout site **

function init() {
    MM_preloadImages('graphics/menu/about_on.gif','graphics/menu/safety_on.gif','graphics/menu/eyewear_on.gif','graphics/menu/help_on.gif','graphics/menu/security_on.gif','graphics/menu/guarantee_on.gif','graphics/menu/contact_on.gif','graphics/menu/checkout_on.gif','graphics/menu/home_on.gif');
}

// ** 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 (theURL, 'CurrencyWindow', 'toolbar=0,location=0,directories=0=0,menubar=0,scrollbars=0,resizable=1,height=170,width=600');
	CurrencyWindow.focus();
}

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) {
	alert('setheight')
	leftSideHeight  	= getHeight(document.getElementById("leftColumn"));
	contentColumnHeight = getHeight(document.getElementById("contentColumn"));

	tallestColumn   	= (leftSideHeight > contentColumnHeight) ? leftSideHeight 	: contentColumnHeight;

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



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBr1Window(theURL,winName,features) { //v2.0
	var features="scrollbars=yes,resizable=no,height=220,width=500";
  window.open(theURL,winName,features);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	var features="scrollbars=yes,resizable=no,height=350,width=650";
  window.open(theURL,winName,features);
}


function checkQuantity() {
	var theQTY=document.addToBasketForm.QTY0.value;
	if (isNaN(theQTY/2)) {
		alert('Please indicate how many items you wish to order');
		return false;
	}
	if (theQTY==0) {alert('Please indicate how many items you wish to order');return false;}
	return true;
}
function checkMultipleQuantity()
{
	var productcount = document.addToBasketForm.productcount.value;

	for (i = 0, noerror = 0; i < productcount; i++)
	{
		var theQTY = eval('document.addToBasketForm.QTY'+i);
	
		if (theQTY.value > 0) noerror++;
	}
	if (noerror == 0)
	{
		alert('Please indicate how many items you wish to order');
		return false;
	}
	return true;
}

function popTextWindow(theURL) {
	var features="scrollbars=yes,resizable=yes,width=400,height=400,left=100,top=100,screenX=100,screenY=100";
  window.open(theURL,"",features);
}

function setType() {
	var theForm = document.addToBasketForm;
	var singlePrice	= theForm.productPrice1.value;
	var boxPrice	= theForm.productPrice2.value;
	if (theForm.prodList[0].checked==true) {
		theForm.PRICE0.value = singlePrice;
		theForm.NAME0.value = theForm.productName.value;
		theForm.OPT10.value = "Single Pair";
	}
	if (theForm.prodList[1].checked==true) {
		theForm.PRICE0.value = boxPrice;
		theForm.NAME0.value = theForm.productName.value + " Box of 12";
		theForm.OPT10.value = "Box of 12";
	}
}

function NewsLetterFormCheckIt() {
	if (document.NewsLetterForm.email){
		if (AssessAll(document.NewsLetterForm.email,"15","Please enter your email address") == false) return false;
	} else {
		alert('You have not supplied an email input field');
		return false;
	}
	return true;
}

function checkValue(el) {
	theValue=el.value;
	if (isNaN(theValue/2)) theValue=0;
	if (theValue<0) theValue=0;
	el.value = theValue;
}

function price(theValue) {
	theValue = (Math.ceil(theValue*100))/100;
	theValue = theValue+"";
	if (theValue.indexOf(".")==-1) theValue +=".00";
	while ((theValue.length-theValue.indexOf("."))<3) theValue +="0";
	return "$"+theValue;
}

function accCalc() {
	var theForm=document.addToBasketForm;
	var numProds = theForm.productcount.value;
	var grandTotal = 0;
	for (i=1;i<numProds;i++) {
		thisCost = eval("theForm.PRICE"+i+".value")-0;
		thisQty  = eval("theForm.QTY"+i+".value")-0;
		thisValue = thisCost*thisQty;
		document.getElementById("subtotal"+i).innerHTML = price(thisValue);
		grandTotal += thisValue;
	}
	document.getElementById("accTotal").innerHTML = price(grandTotal);
}