/***********************************************/
/* nzrox.com 2007		                       */
/* General Scripts	                           */
/***********************************************/


/***********************************************/
/* Rollover Function		                   */
/***********************************************/

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_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_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_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];}
}

/***********************************************/
/* Open Browser Window		                   */
/***********************************************/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/***********************************************/
/* Open Picture Window		                   */
/***********************************************/

function openPictureWindow_Fever(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt='+alt+'>'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}


/***********************************************/
/* Swap Content Functions	                   */
/***********************************************/

function swapImage(path) {
	var img = document.getElementById('Middle');
	img.innerHTML = '<img src="'+path+'" />';
}


/***********************************************/
/* Cart Functions			                   */
/***********************************************/

function updateCart(type, id) {
	// Remove item from cart
	if(type == 'del') {
		var delItem = document.getElementById('del');
		if(delItem.value == "N/A") {
			delItem.value = id;
			document.shopForm.submit();
		} else {
			document.shopForm.submit();
		}
	}
	// Update item quantity in cart
	if(type == 'update') {
		var updateItem = document.getElementById('update');
		var quantityItem = document.getElementById('quantity');
		var quantity = document.getElementById(id);
		if(updateItem.value == "N/A") {
			updateItem.value = id;
			quantityItem.value = quantity.value;
			document.shopForm.submit();
		}
	}
	if(type == "submit") {
		// Validation
		// Check Country
		if(document.shopForm.shipping.value == 'N/A') {
			alert("Please select your shipping destination");
			document.shopForm.shipping.focus();
			return false;
		}
		// Submit Form
		document.shopForm.action = "https://www.nzrox.com/shop/checkout.php";
		document.shopForm.submit();
	}
}

function updatePrice(price, shipping,japan) {
	// Update cart price to include shipping
	var priceDiv = document.getElementById('gTotal');
	//alert(price);
	//alert(shipping);
	var oPrice = (parseFloat(price)+parseFloat(shipping));
	
	//var fPrice = parseFloat(Math.round(oPrice*Math.pow(10,2))/Math.pow(10,2));
	var fPrice = formatAsMoney(oPrice);
	//if(String(fPrice).indexOf('.') == -1) {
		//fPrice = fPrice+".00";	
	//} // Fix for 101.5 etc
	document.shopForm.total.value = shipping;
	if(japan=='no'){
	var fPrice = formatAsMoney(oPrice);
	priceDiv.innerHTML = "$"+fPrice+' &nbsp;';
	}else{
	priceDiv.innerHTML = "&yen;"+oPrice+' &nbsp;';	
	}
	/*
	var priceDiv = document.getElementById('gTotal');
	var oPrice = (parseFloat(price)+parseFloat(shipping));
	var fPrice = parseFloat(Math.round(oPrice*Math.pow(10,2))/Math.pow(10,2));
	if(String(fPrice).indexOf('.') == -1) {
		fPrice = String(fPrice+".");	
	} // Fix for 101.5 etc
	fPrice = fPrice + "000";
	fPrice = substring(String(fPrice).indexOf('.')+3);
	document.shopForm.total.value = shipping;
	priceDiv.innerHTML = "$"+fPrice+' &nbsp;';
	*/
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}


/*
if(String(fPrice).indexOf('.') == -1) {
		fPrice = fPrice+".";	

(so you always have a dot)

fPrice = fPrice + '000'
so if its 101.5 its now 101.5000
then substring(String(fPrice).indexOf('.')+2)
where 2 is the dp you want

*/

/***********************************************/
/* Initialise ON LOAD		                   */
/***********************************************/

window.onload = function() {
	MM_preloadImages('assets/images/about-link02.jpg','assets/images/contact-link02.jpg','assets/images/shopping-link02.jpg','assets/images/buy-link02.jpg', 'assets/images/shopping/checkout-continue-link02.gif');
}

/***********************************************/
/* Change range function	                   */
/***********************************************/

function changeRange(what){
	if(what == 'oz'){
		var euge = document.getElementById('euge');
		euge.src = "euge-scroller/indexoz.php";		
		var left = document.getElementById('LeftContent');
		left.innerHTML = '<img src="assets/images/shop-online-oz.jpg" alt="Shop Online" width="265" height="271" />';
		var mid = document.getElementById('Middle');
		mid.innerHTML = '<img src="assets/images/ozrox_main_image.jpg" />';	
		var RightContent = document.getElementById('RightContent');
		RightContent.innerHTML = '<img src="assets/images/touchstone-gallery-ozrox.jpg" width="265" height="212" /><br /><img src="assets/images/to-nzrox-link.jpg" alt="NZROX" width="265" height="59" class="imglink" onclick="changeRange(\'nz\');" />';
	}
	if(what == 'nz'){
		var euge = document.getElementById('euge');
		euge.src = "euge-scroller/index.php";
		var mid = document.getElementById('Middle');
		mid.innerHTML = '<img src="assets/images/nzrox_main_image.jpg" />';		
		var left = document.getElementById('LeftContent');
		left.innerHTML = '<img src="assets/images/shop-online-nz.jpg" alt="Shop Online" width="265" height="271" />';
		var RightContent = document.getElementById('RightContent');
		RightContent.innerHTML = '<img src="assets/images/touchstone-gallery-nzrox.jpg" width="265" height="212" /><br /><img src="assets/images/to-ozrox-link.jpg" alt="OZROX" width="265" height="59" class="imglink" onclick="changeRange(\'oz\');" />';
	}
}

function changingRange(what){
	if(what == 'oz'){
		var euge = document.getElementById('euge');
		euge.src = "euge-scroller/indexoz.php";		
		var left = document.getElementById('LeftContent');
		left.innerHTML = '<img src="assets/images/shop-online-oz.jpg" alt="Shop Online" width="265" height="271" />';
		var RightContent = document.getElementById('made');
		RightContent.innerHTML = '<br /><img id="rangetype" src="assets/images/nzrox-link01.jpg" onmouseover="MM_swapImage(\'rangetype\',\'\',\'assets/images/nzrox-link02.jpg\',1)" onmouseout="MM_swapImgRestore()" onclick="changingRange(\'nz\');" />';
	}
	if(what == 'nz'){
		var euge = document.getElementById('euge');
		euge.src = "euge-scroller/index.php";
		var left = document.getElementById('LeftContent');
		left.innerHTML = '<img src="assets/images/shop-online-nz.jpg" alt="Shop Online" width="265" height="271" />';
		var RightContent = document.getElementById('made');
		RightContent.innerHTML = '<br /><img id="rangetype" src="assets/images/ozrox-link01.jpg" onmouseover="MM_swapImage(\'rangetype\',\'\',\'assets/images/ozrox-link02.jpg\',1)" onmouseout="MM_swapImgRestore()" onclick="changingRange(\'oz\');" />';
	}
}
