// JavaScript Document// General Page scripts for front end.
xMouse=0; 
yMouse=0; 
document.onmousemove=getMouse;
<!--
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

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

var curtop = "";
var curbot = "";

function changebgs(number,url){
	document.getElementById(-1).style.backgroundImage = "";
	document.getElementById(0).style.backgroundImage = "";
	document.getElementById(1).style.backgroundImage = "";
	document.getElementById(2).style.backgroundImage = "";
	document.getElementById(3).style.backgroundImage = "";
	document.getElementById(4).style.backgroundImage = "";
	document.getElementById(5).style.backgroundImage = "";
	document.getElementById(6).style.backgroundImage = "";
	document.getElementById(7).style.backgroundImage = "";
	document.getElementById(8).style.backgroundImage = "";
	document.getElementById(9).style.backgroundImage = "";
	document.getElementById(10).style.backgroundImage = "";
	document.getElementById(11).style.backgroundImage = "";
	document.getElementById(12).style.backgroundImage = "";
	document.getElementById(13).style.backgroundImage = "";
	document.getElementById(14).style.backgroundImage = "";
	document.getElementById(15).style.backgroundImage = "";
	//document.getElementById(16).style.backgroundImage = "";
	document.getElementById(-1).style.paddingTop = "";
	document.getElementById(0).style.paddingTop = "";
	document.getElementById(1).style.paddingTop = "";
	document.getElementById(2).style.paddingTop = "";
	document.getElementById(3).style.paddingTop = "";
	document.getElementById(4).style.paddingTop = "";
	document.getElementById(5).style.paddingTop = "";
	document.getElementById(6).style.paddingTop = "";
	document.getElementById(7).style.paddingTop = "";
	document.getElementById(8).style.paddingTop = "";
	document.getElementById(9).style.paddingTop = "";
	document.getElementById(10).style.paddingTop = "";
	document.getElementById(11).style.paddingTop = "";
	document.getElementById(12).style.paddingTop = "";
	document.getElementById(13).style.paddingTop = "";
	document.getElementById(14).style.paddingTop = "";
	document.getElementById(15).style.paddingTop = "";
	//document.getElementById(16).style.paddingTop = "";
	//alert(url);
	//callajax_wrapper(url);
	
	var top = number-1;
	var bottom = number+1;
		
	document.getElementById(top).style.backgroundImage = "url(assets/images/leftnav/selabove.jpg)";
	document.getElementById(bottom).style.backgroundImage = "url(assets/images/leftnav/selbelow.jpg)";
	document.getElementById(number).style.backgroundImage = "url(assets/images/leftnav/header_selcat.jpg)";
	
	document.getElementById(top).style.height = "25px";
	document.getElementById(bottom).style.height = "20px";
	document.getElementById(bottom).style.paddingTop = "4px";
	
	var browserName=navigator.appName;
	if(browserName=="Microsoft Internet Explorer" && browserVer>=4){
		document.getElementById(number).style.marginTop = "2px";
		document.getElementById(number).style.backgroundRepeat="repeat-y";
	}
}


/*  AJAX back button fix */
function callajax_wrapper(call) {
	// change iframe src to the place you want to go to
	
	window.frames["hiddenIframe"].location.href= "directto.php?hash="+call;
	//alert(call);
}

function callPage(goto,num,height){
	//if range
	if(goto.indexOf('range')==0){
		var rid = goto.substr(5,5);
		window.location = "range.php?rid="+rid+"&box="+num+"&height="+height;
	}
	if(goto.indexOf('category')==0){
		var cid = goto.substr(8,5);
		window.location = "category.php?cID="+cid+"&box="+num+"&height="+height;
	}
	if(goto.indexOf('home')==0){
		window.location = "homepage.php";
	}
	
}
//-->

function confirmDel(name, id, table, cid, uid)  {
	var verify = window.confirm("Are you sure you want to DELETE "+name+"?");
	// Delete upon confirmation
	if (verify) {
		Spry.Utils.updateContent('main', 'assets/includes/delete.php?t='+table+'&r='+id+'&cid='+cid+'&uid='+uid);
	}
}

<!--  CART FUNCTIONS -->
function updatePrice(price, shipping,index) {
	// Update cart price to include shipping
	//alert(document.cartForm.cartID.value);
	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));
	var fPrice = formatAsMoney(oPrice);
	//if(String(fPrice).indexOf('.') == -1) {
		//fPrice = fPrice+".00";	
	//} // Fix for 101.5 etc
	document.cartForm.shipsel.value = index+20;
	document.cartForm.shipping.value = shipping;
	document.cartForm.comTot.value = fPrice;
	priceDiv.innerHTML = "&nbsp;&nbsp;&nbsp;$"+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);
			  
}

function requiredFill(){
	document.cartForm.required.value= document.method.required.value;	
}

function extraFill(){
	document.cartForm.extra.value= document.method.extrainfo.value;	
}

function paymethChan(meth){
	if(meth == 'cred'){
		document.cartForm.payMeth.value="credit";
	}
	if(meth=='cheq'){
		document.cartForm.payMeth.value="cheque";
	}
	if(meth=='dir'){
		document.cartForm.payMeth.value="direct";
	}
	document.cartForm.submit();
}

//large detail page rollover function
function getMouse(e){
	e= e || window.event;
	de = document.documentElement;
	b = document.body;
	xMouse = e.clientX + (de.scrollLeft || b.scrollLeft)-(de.clientLeft||0);
	yMouse = e.clientY + (de.scrollTop || b.scrollTop)-(de.clientTop||0);
	//move popup from right edge
	while(xMouse>780){ xMouse -= 330; }
}

function hideLayer(){
	document.getElementById('largedetail').style.display="none";	
}

function popLayer(a){
	Spry.Utils.updateContent('largedetail','assets/includes/large.php?prod='+a);
	document.getElementById('largedetail').style.left = xMouse - 430 + 'px';
	document.getElementById('largedetail').style.top = yMouse - 270 + 'px';
	document.getElementById('largedetail').style.display = "block";
	
}

function popCatLayer(a){
	Spry.Utils.updateContent('largedetail','assets/includes/catdetail.php?prod='+a);
	document.getElementById('largedetail').style.left = xMouse - 430 + 'px';
	document.getElementById('largedetail').style.top = yMouse - 250 + 'px';
	document.getElementById('largedetail').style.display = "block";
}

var lastClassChange = '';

function changeClass(lin){
	if (lastClassChange == ''){
		document.getElementById(lin).className = "selected";
		lastClassChange = lin;
	}else{
		document.getElementById(lastClassChange).className = "content";
		document.getElementById(lin).className = "selected";
		lastClassChange = lin;
	}
}

function validateThis(form){
	if(form.shipping.value==''){
		alert("Please select your shipping destination");
		return false;
	}else{
		return true;	
	}
}

function validatePay(form){
	if(form.payMeth.value==''){
		alert("Please select your method of payment");
		return false;
	}else{
		return true;	
	}
}

function changePageLoc(page,num){
	if(page=="home"){
		window.location = "index.php";
	}
	if(page=="range"){
		window.location = "range.php?rid="+num;	
	}
	if(page=="category"){
		window.location = "category.php?cID="+num;	
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}



function setPage(num){
	//alert(num);
	document.cookie="pageNum="+num;
}
