/*function click(e) {
	if (document.all) {
		if (event.button == 2) {
			alert(message);
			return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
			alert(message);
			return false;
		}
	}
}
if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;*/


function open360(url) {
	window.open("/products/"+url, "threesixty", "width=680,height=372");
}

function preload(imgObj,imgSrc) {
  if (document.images) {
     eval(imgObj+' = new Image()')
     eval(imgObj+'.src = "'+imgSrc+'"')
   }
}

function changeImage(imgName, imgObj) {
  if (document.layers)
    eval('document.images["'+imgName+'"].src = '+imgObj+'.src');
  else document.images[imgName].src = eval(imgObj+".src");
}

preload('addtocarton','/images/addtocartrol.gif');
preload('addtocartoff','/images/addtocart.gif');

// addtocart(productid,itemid,voptions,required)
function addtocart(productid,itemid,voptions,required,theReturn)
{
	if (isRequired(required))
	{
		// The path to the add to cart page
		thelink = "/index.php/fuseaction/shopping.addtocart/productid/"+productid;
		// Add the itemid
		if (itemid != "" && itemid != 0)
		{
			thelink = thelink + "/itemid/"+itemid;
		}
		if (addtocart.arguments.length > 5)
		{
			thelink = thelink + "/qty/"+addtocart.arguments[5];
		}
		
		// Add the options
		if (voptions != "" && voptions != 0)
		{
			thelink = thelink + "/voptions/";
			// Loop over the options and add them to the list
			// split the string
			theoptions = voptions.split(";");
			arrnumrows = theoptions.length;
			
			for (i=0; i < arrnumrows; i++)
			{
				theo = theoptions[i];
				theval = theo.split("~");
				theselectid = theval[1];
				thefield = eval("thecart."+theval[0]);
				
				vfieldname = theval[1];
				thenumber = vfieldname.lastIndexOf("_");
				vfieldname = vfieldname.substr(0, thenumber);
				
				if(thefield.options[thefield.selectedIndex].text != "")
				{
					thisoption = thefield.options[thefield.selectedIndex].text;
					thisoptionvalue = thefield.options[thefield.selectedIndex].value;
				}
				else
				{
					thisoption = 0;
				}
				
				if (i > 0)
				{
					thelink = thelink + "|";
				}
				thelink = thelink + theselectid + "^" + thisoptionvalue + "^" + thisoption;
			}
		}
		
		// Add the Return
		thelink = thelink + "/theReturn/"+theReturn;
		//alert("Shopping cart is under construction."+"\n\n"+thelink);
		top.location=thelink;
	}
}

function isRequired(required)
{
	// check for required options
	if (required != "" && required != 0)
	{
		// split the string
		requiredfields = required.split(";");
		arrnumrows = requiredfields.length;
		
		for (i=0; i < arrnumrows; i++)
		{
			thefield = eval("thecart."+requiredfields[i]);
			if(thefield.options[thefield.selectedIndex].value == "")
			{
				vfieldname = requiredfields[i];
				thenumber = vfieldname.lastIndexOf("_");
				vfieldname = vfieldname.substr(0, thenumber);
				thisexp = /_/g
				thealert = vfieldname.replace(thisexp, " ");
				alert(thealert + " is a required field.");
				return false;
			}
		}
	}
	return true;
}

function openwin(url,attr)
{
	window.open(url, "popup", attr);
}

function openWindow(content) 
{
	var w = window.open(content,'demarcation','width=569,height=425,scrollbars=no');
	w.focus();
}

function PopupPic(sPicURL) {
     window.open( "/popup.htm?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
} 

function getRefToDivMod( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivNest(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }
	return document[divID];
}

function openPerfectPopup(oW,oTitle,oContent) {
	var x = window.open('','windowName','width=500,height=400,resizable=1');
	if( !x ) { return true; }
	x.document.open();
	x.document.write('<html><head><title>'+oTitle+'<\/title><link rel=stylesheet type="text/css" href="/stylesheets/ie.css"><\/head><body>'+
	  (document.layers?('<layer left="5" top="5" width="'+oW+'" id="myID">')
	    :('<div style="position:absolute;left:5px;top:5px;display:table;width:'+oW+'px;" '+
	    'id="myID">'))+'<img src=/images/logo_new.jpg><br><hr>'+oContent+'<br><br><center><a href=javascript:self.close()>Close Window</a></center>'+
	  (document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	x.document.close();
	var oH = getRefToDivMod( 'myID', x.document ); if( !oH ) { return false; }
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
	x.resizeTo( oW + 400, oH + 400 );
	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	if( window.opera && !document.childNodes ) { myW += 16; }
	x.resizeTo( oW + ( ( oW + 400 ) - myW ) + 5, oH + ( (oH + 400 ) - myH ) + 5 );
	if( x.focus ) { x.focus(); }
	return false;
}

function expand(s)
{
  var td = s;
  var d = td.getElementsByTagName("div").item(0);

  td.className = "menuHover";
  d.className = "menuHover";
}

function collapse(s)
{
  var td = s;
  var d = td.getElementsByTagName("div").item(0);

  td.className = "menuNormal";
  d.className = "menuNormal";
}



