function display(obj)
{
//this function is called from the site map when a user clicks on a category
	var num=obj.id;
	var menu=document.getElementById("Menu"+num);

	var display = menu.style.display;
	menu.style.display = (display == "block") ? "none" : "block";
}

function rechts(k) 
 { if ( navigator.appName.indexOf("Netscape") > -1 && 
      ( k.which == 3 || k.which == 2 ) ) 
      { alert ('OOPS !!!');
        return false; }
   else 
        if ( navigator.appName.indexOf("Explorer") > -1 && 
           ( event.button == 2 || event.button == 3 ) )
           { alert ('OOPS !!!');
             return false; }
  return true;
}

function ContactForm_Validator(frm)
{
//this function is called from the contact form
missinginfo="";

if(frm.elements["name"].value=="") {
missinginfo += "\n Name";
}

if(frm.elements["phone"].value == "" && frm.elements["email"].value=="") { missinginfo += "\n Phone Number or Email"}

if (frm.elements["email"].value!="")
{missinginfo += CheckEmail(frm.elements["email"].value)};

if (missinginfo != "") {
missinginfo ="Please fill in the following required fields:\n" +
"_____________________________\n" +
missinginfo + "\n_____________________________" +
"\n";
alert(missinginfo);
return false;
}
else{
frm.elements["realname"].value=frm.elements["name"].value;
return true;}

}

function CheckEmail(email)
{
	if(email=="") {
	return "\n Email address";
	}
	else
	{
  	tmp=email;

   		if(tmp.indexOf("@")==-1 ||
tmp.indexOf(".") ==-1){
		return "\n Valid Email address";
		}
		else
		{
			return "";
		}
	}
}

//document.onmousedown=rechts;
//if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//window.onmousedown=rechts;

function openBgImg(img)
{
popwin=window.open("prodbig.htm?" + img, "prodBig", "width=550, height=600, left=0, top=0, menubar=no, status=yes, location=yes, toolbar=no, scrollbars=yes, resizable=yes")
popwin.focus();
}

function openBgImg2(frm)
{
	alert(frm.elements[0].src);
}
function openCatImg(img)
{
popwin=window.open("prodcat.htm?" + img, "prodCat", "width=700, height=600, left=0, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes");
popwin.focus();
}

function showImg()
{
//this function is called from the prodbg.htm onload event
var tmp=window.location.href;
if(tmp.indexOf("?")>0)
{var imgname=tmp.substring(tmp.indexOf("?")+1,tmp.length);
document.images.img.src="images/Products/" + imgname + "_big.jpg"}
else{}
}

function showCat()
{
//this function is called from the prodcat.htm onload event
var tmp=window.location.href;
if(tmp.indexOf("?")>0)
{var imgname=tmp.substring(tmp.indexOf("?")+1,tmp.length);
document.images.cat.src="images/products/cat/" + imgname + ".jpg"}
else{}
}

function Validate()
{
//The statements below only allow numbers (keyCode 48-57);
//this is called from the keypress event of all the itemquantity fields;
if (window.event.keyCode < 48 || window.event.keyCode > 57) window.event.returnValue=false
}


function AddtoQuote(thisForm)
{
	iNumberOrdered=0;
	iNumberOrdered=GetCookie("NumberOrdered");
	
	prodname=thisForm.elements[0].value;
	sku=thisForm.elements[1].value;
	desc=thisForm.elements[2].value;
	color=thisForm.elements[3].value;
	
	fullprodname=prodname + " - " + desc + " (" + color + ")"

	tmp=sku + "|" + fullprodname;
	
	var flag=0;  //this will keep track of whether a new item should be added to the shopping cart;
	var i=0;

	if(iNumberOrdered==null) {flag=0}
	else
	{
		while(i<iNumberOrdered && flag==0)
		{
			i++;
			NewOrder = "Order." + i;
		   	tmp1 = "";
     	      		tmp1 = GetCookie(NewOrder);
			
		//tmp1 is in the format of --sku|fullprodname--;

			Token0=tmp1.indexOf("|", 0);
			tmpsku=tmp1.substring(0,Token0);
			
			if (tmpsku==sku) 
			{
				alert("This item has already been added to the list");
				return false;
			}
		}
	}

	
	iNumberOrdered++;
	strNewOrder="Order." + iNumberOrdered;
	SetCookie(strNewOrder, tmp, null, "/");
	SetCookie("NumberOrdered", iNumberOrdered, null, "/");
	notice = fullprodname + " has been added to the list.";
	alert(notice);
	return false;
	

}


function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}


function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();
   date.setTime (date.getTime() - skew);
}

function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }
   return(null);
}

function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


function CheckValue(field)
//This function returns 0 if the field is true for the listed conditions, if 
//not then it converts the passed variable to a format that can be used in calculations
	{
		return field==null ? 0 : isNaN(parseFloat(field)) ? 0 : parseFloat(field);
	}

function RemoveFromCart(RemOrder) {
   if ( confirm("Click 'Ok' to remove this product from your shopping cart.") ) {
      NumberOrdered = GetCookie("NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "Order." + (i+1);
         NewOrder2 = "Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, null, "/");
      }
      NewOrder = "Order." + NumberOrdered;
      SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
      DeleteCookie(NewOrder, "/");
      location.href=location.href;   }}


function GetFromCart() {
    WriteToForm( true, 0 );
}

//---------------------------------------------------------------------||
// FUNCTION:    WriteToForm                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product hidden fields Written to Document              ||
// PURPOSE:     Draws current cart product hidden fields on HTML form  ||
//              if bDisplay == true, shows cart output as HTML table   ||
//---------------------------------------------------------------------||
function WriteToForm( bDisplay, fShipping ) {
   iNumberOrdered = 0;
   fTotal         = 0;
   itotal=0;
   strTotal       = "";
   strShipping    = "";
   strOutput      = "";
   iNumberOrdered = GetCookie("NumberOrdered");
  
  noitemsmsg = "There are currently no items in your List.  Please click on the button below to view our Products<br><br>";
  
  //check to see if the cart is empty
    if (iNumberOrdered==0)
    {
    	strOutput = noitemsmsg;
    	document.write(strOutput);
 	document.close();
 	return false;
   }
   
      strOutput = "<TABLE width=\"100%\" border=\"1\" cellspacing=\"2\" cellpadding=\"8\"><TR>" +
                  "<TD bgcolor=\"#CCCCCC\" width=\"15%\" class=\"txt\"><B>SKU</B></td>" +
                  "<TD bgcolor=\"#CCCCCC\" width=\"65%\" class=\"txt\"><B>Product name with description</B></Td>" +
                  "<TD width=\"14%\" class=\"txt\"><B>&nbsp;</B></Td></TR>";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      tmp = "";
      tmp = GetCookie(NewOrder);
//tmp is in the format of --sku|fullproductname--;

      Token0 = tmp.indexOf("|", 0);
     
      sku = tmp.substring( 0, Token0 );  		//sku
      fullprodname = tmp.substring( Token0+1, tmp.length );  //full product name
    

     
         strOutput += "<TR><TD CLASS=\"txt\">"  + sku + "</TD>";

        strOutput += "<TD CLASS=\"txt\">"  + fullprodname  + "</TD>";

                         
         strOutput += "<TD CLASS=\"txt\"><input type=button value=\"  Remove  \" onClick=\"RemoveFromCart("+i+")\" class=\"Button1\"></TD></TR>";
      
      
      strOutput += "<input type=hidden name=\"BRANDNAME_"       + i + "\" value=\"" + sku + "\">";
      strOutput += "<input type=hidden name=\"ITEMNAME_"     + i + "\" value=\"" + fullprodname + "\">";
      strOutput += "<input type=hidden name=\"End Of Item#" + i + "\" value=\"------------------------------------------\">";
      
   }

 strOutput += "</TABLE>";
 strOutput += "<input type=hidden name=\"--" + "\" value=\"------------------------------------------\">"; 

   document.write(strOutput);
   document.close();
}

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) { //v3.0
  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); 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() { //v3.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; }
}

/* For showing/hiding layers */
/* For setting text/back color on mouse over */
function setMnuMouseOver(txtID){
	txtID.color="#000000";
}

/* For resetting text/back color on mouse out */
function setMnuMouseOut(txtID){
	txtID.color="#FFFFFF";
}
// -->
function MM_showHideLayers() { //v2.0
  var i, visStr, args, theObj;
  args = MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
    visStr   = args[i+2];
	//alert(args[i])
    if (navigator.appName == 'Netscape' && document.layers != null) {
      theObj = eval(args[i]);
	   
      if (theObj) theObj.visibility = visStr;
    } else if (document.all != null) { //IE
    
	  if (visStr == 'show') visStr = 'visible'; //convert vals
      if (visStr == 'hide') visStr = 'hidden';
   
	  theObj = eval(args[i+1]);
      if (theObj) theObj.style.visibility = visStr;
  } }
}

function formatCurrency(num) 
//This function formats the passed variable into currency format ($#.##)
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num) || num=="Infinity")
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}

function checkFields() {
//this function is called from the onSubmit event of the order form to check that all the required fields have been filled in;
//if any required field has not been filled in, then the user will be shown a list of those fields and the form will NOT be submitted;

missinginfo = "";
var frm=document.forms[0];
if(frm.Salutation.selectedIndex==0) {
missinginfo += "\n   - Salutation";
}
if(frm.FirstName.value=="") {
missinginfo += "\n   - First Name";
}
if(frm.LastName.value=="") {
missinginfo += "\n   - Last Name";
}
if(frm.PhoneNo.value=="") {
missinginfo += "\n   - Phone Number";
}
if(frm.email.value=="") {
missinginfo += "\n   - Email";
}
else
{
     tmp=frm.email.value;
     if(tmp.indexOf("@")==-1 || tmp.indexOf(".") ==-1){
	missinginfo += "\n   - Valid Email address";
	}
}
if(frm.Address1.value=="") {
missinginfo += "\n   - Address";
}
if(frm.City.value=="") {
missinginfo += "\n   - City";
}
if(frm.ProvState.value=="") {
missinginfo += "\n   - Province / State";
}
if(frm.PostalCode.value=="") {
missinginfo += "\n   - Postal Code / Zip Code";
}

if (missinginfo != "") {
missinginfo ="Please fill in the following required fields:\n" +
"_____________________________\n" +
missinginfo + "\n_____________________________" +
"\n";
alert(missinginfo);
return false;
}
else{return true;}

}

function PopulateName()
{
//this function is called from the Salutation, first name and last name fields to populate the realname field with the user's full name;
//the reason that the fullname field is called 'realname' is that the cgi script that sends the email uses this field to show the user's name in the email;
var sal="";
var first="";
var last="";
var frm=document.forms[0];
	if(frm.Salutation.selectedIndex !="")
	{
		tmp=frm.Salutation.selectedIndex;
		sal=frm.Salutation.options[tmp].text + " ";
	}

	if(frm.FirstName.value!="")
	{
		first=frm.FirstName.value + " ";
	}
	
	if(frm.LastName.value!="")
	{
		last=frm.LastName.value;
	}
	frm.realname.value=sal+first+last;
}

function checkkey()
//This function allows only numbers to be entered in the quantity field;
//this function is called from the keypress event of all the fields that begin with "Qty_"
{
if (window.event.keyCode < 48 || window.event.keyCode > 57) window.event.returnValue=false
}


