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 showprod(id)
{
	window.location="http://diviniti.ca/catalog/product_info.php?products_id=" + id;
}

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 "";
		}
	}
}


function EnquiryForm_Validator(frm) {
//this function is called from the onSubmit event of the mailing list 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 = "";

 if(frm.elements["name"].value=="") {
 missinginfo += "\n Full Name";
}
 
   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 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 GetValue(tmp) {
	index=tmp.selectedIndex;
	return tmp.options(index).text;
}

function CustomizedForm_Validator(frm)
{
//this function is called from the form on the customized pages
missinginfo="";

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

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

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


if (GetValue(frm.elements["timeframe"])=="") {
	missinginfo += "\n When do you want these gifts";
}

if (GetValue(frm.elements["budget"])=="") {
	missinginfo += "\n Budget";
}

if (GetValue(frm.elements["numberofgifts"])=="") {
	missinginfo += "\n Number of Gifts";
}

if (GetValue(frm.elements["purpose"])=="") {
	missinginfo += "\n Purpose / Occasion";
}

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 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;
}
//document.onmousedown=rechts;
//if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//window.onmousedown=rechts;

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

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 + ".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");
	
	itemname=thisForm.elements[0].value;
	itemcode=thisForm.elements[1].value;
	//unitprice=thisForm.elements[2].value;
	qty=thisForm.elements[2];
	
	if (itemcode=="")
	{ alert("Invalid Item Code"); return false;}

	//if(unitprice=="")
	//{ unitprice="0.00";}

	if(qty.value=="")
	{ alert("No Quantity entered"); return false;}

	tmp=itemcode + "|" + qty.value + "|" + itemname;
	//tmp=itemcode + "|" + qty.value;
	
	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 --itemcode|qty|itemname--;

			Token0=tmp1.indexOf("|", 0);
			Token1=tmp1.indexOf("|", Token0+1);
			tcode=tmp1.substring(0,Token0);
			tqty=tmp1.substring(Token0+1,Token1);

			if (tcode==itemcode) 
			{
				var agree=confirm("You have already added this item (" + tcode +") to your Quote.\nDo you want to overwrite the previous quantity -- " + tqty + " -- with the new quantity -- " + qty.value);
				if(agree){flag=i;}
				else {flag=-1;qty.value="";}
			}
		}
	}

	if(flag==0)
	{
		iNumberOrdered++;
		strNewOrder="Order." + iNumberOrdered;
		SetCookie(strNewOrder, tmp, null, "/");
		SetCookie("NumberOrdered", iNumberOrdered, null, "/");
		notice = qty.value + " " + itemname + " added to your Quote.";
		alert(notice);
		qty.value="";
		return false;
	}
	else
	if(flag>0)
	{
		strNewOrder="Order." + flag;
		SetCookie(strNewOrder, tmp, null, "/");
		notice = qty.value + " " + itemname + " added to your Quote.";
		alert(notice);
		qty.value="";
		return false;	
	}

}

function AddtoQuote1(thisForm)
{
	//this function will be called from items that have a drop-down list
	iNumberOrdered=0;
	iNumberOrdered=GetCookie("NumberOrdered");
	
	itemname=thisForm.elements[0].value;
	itemcode=thisForm.elements[1].value;
	color=thisForm.elements[2].value;
	
	qty=thisForm.elements[3];
	
	if (itemcode=="")
	{ alert("Invalid Item Code"); return false;}

	if(color=="")
	{ alert("Please select a color"); return false;}

	if(qty.value=="")
	{ alert("No Quantity entered"); return false;}

	tmp=itemcode + "|" + qty.value + "|" + itemname + "~" + color;
	
	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 itemcode|qty|itemname~color;

			Token0=tmp1.indexOf("|", 0);
			Token1=tmp1.indexOf("|", Token0+1);
			tcode=tmp1.substring(0,Token0);
			tqty=tmp1.substring(Token0+1,Token1);
			tmpitemcode=itemcode;
			if(tmp1.indexOf("~")>0)
			{
			token2=tmp1.indexOf("~");
			color1=tmp1.substring(token2+1,tmp1.length);
			tcode=tcode+"-"+color1;
			tmpitemcode=tmpitemcode+"-" +color;}

			if (tcode==tmpitemcode) 
			{
				var agree=confirm("You have already added this item (" + tcode + ") to your Quote.\nDo you want to overwrite the previous quantity -- " + tqty + " -- with the new quantity -- " + qty.value);
				if(agree){flag=i;}
				else {flag=-1;qty.value="";}
			}
		}
	}

	if(flag==0)
	{
		iNumberOrdered++;
		strNewOrder="Order." + iNumberOrdered;
		SetCookie(strNewOrder, tmp, null, "/");
		SetCookie("NumberOrdered", iNumberOrdered, null, "/");
		notice = qty.value + " " + itemname + " added to your Quote.";
		alert(notice);
		qty.value="";
		return false;
	}
	else
	if(flag>0)
	{
		strNewOrder="Order." + flag;
		SetCookie(strNewOrder, tmp, null, "/");
		notice = qty.value + " " + itemname + " added to your Quote.";
		alert(notice);
		qty.value="";
		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 Quote.  Please click on the button below to view our Products";
  
   //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=\"#FEFAD7\" width=\"20%\" class=\"txt\"><B>Item Code</B></td>" +
                  "<TD bgcolor=\"#FEFAD7\" width=\"40%\" class=\"txt\"><B>Product Name</B></Td>" +
                  "<TD bgcolor=\"#FEFAD7\" width=\"10%\" class=\"txt\"><div align=\"center\"><B>Qty</B></div></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 --itemcode|qty|item name--;

      Token0 = tmp.indexOf("|", 0);
      Token1 = tmp.indexOf("|", Token0+1);
//      Token2 = tmp.indexOf("|", Token1+1);


      itemcode = tmp.substring( 0, Token0 );  		//item code
      qty = tmp.substring( Token0+1, Token1 );  	//qty
      itemname = tmp.substring( Token1+1, tmp.length );  //itemname
      if(itemname.indexOf("~")>0)
      {
      	tindex=itemname.indexOf("~");
      	itemname=itemname.substring(0,tindex) + " (" + itemname.substring(tindex+1,itemname.length) + ")";
      }
//      itemname = tmp.substring( Token2+1, tmp.length );  //item name

//      itotal = CheckValue(qty) * CheckValue(unitprice);
//      fTotal     += itotal;
//      strTotal    = formatCurrency(fTotal);

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

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

        strOutput += "<TD CLASS=\"txt\"><div align=\"center\">"  + qty + "</div></TD>" ;
                      
         strOutput += "<TD CLASS=\"txt\"><input type=button value=\"  Remove  \" onClick=\"RemoveFromCart("+i+")\" class=\"Button\"></TD></TR>";
      
      
      strOutput += "<input type=hidden name=\"ITEMCODE_"       + i + "\" value=\"" + itemcode + "\">";
      strOutput += "<input type=hidden name=\"QUANTITY_" + i + "\" value=\"" + qty + "\">";
      strOutput += "<input type=hidden name=\"ITEMNAME_"     + i + "\" value=\"" + itemname + "\">";
      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 QuoteForm_Validator(frm) {
//this function is called from the onSubmit event of the quote 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 = "";

if(frm.elements["Salutation"].selectedIndex==0) {
missinginfo += "\n   - Salutation";
}
if(frm.elements["FirstName"].value=="") {
missinginfo += "\n   - First Name";
}
if(frm.elements["LastName"].value=="") {
missinginfo += "\n   - Last Name";
}
if(frm.elements["PhoneNo"].value=="") {
missinginfo += "\n   - Phone Number";
}
if(frm.elements["email"].value=="") {
missinginfo += "\n   - Email";
}
else
{
     tmp=frm.elements["email"].value;
     if(tmp.indexOf("@")==-1 || tmp.indexOf(".") ==-1){
	missinginfo += "\n   - Valid Email address";
	}
}
if(frm.elements["Address1"].value=="") {
missinginfo += "\n   - Address";
}
if(frm.elements["City"].value=="") {
missinginfo += "\n   - City";
}
if(frm.elements["ProvState"].value=="") {
missinginfo += "\n   - Province / State";
}
if(frm.elements["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(frm)
{
//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="";

	if(frm.elements["Salutation"].selectedIndex !="")
	{
		tmp=frm.Salutation.selectedIndex;
		sal=frm.Salutation.options[tmp].text + " ";
	}

	if(frm.elements["FirstName"].value!="")
	{
		first=frm.FirstName.value + " ";
	}
	
	if(frm.elements["LastName"].value!="")
	{
		last=frm.LastName.value;
	}
	frm.elements["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
}



