/*** COPYRIGHT 2009  BY FDM4 INTERNATIONAL INC. - ALL RIGHTS RESERVED ********/
/*** global.js -- Global JavaScript                                        ***/ 
/*****************************************************************************/
/* 070012 05/19/11 JB - Moved enableElements, pairs with disableElements.    */
/* 070011 04/18/11 JB - Use cart status to condition shopping cart page link.*/
/* 070010 01/18/11 JB - Removed top references.                              */
/* 070009 12/01/10 JD2- Added validation for floatingAdded.                  */
/* 070008 08/23/10 JB - Added getNoCacheParam,appended to cartRequest.w call.*/
/* 070007 03/10/10 APY- Remove Alert when adding to cart.                    */
/* 070006 02/24/10 APY- Update CartHover logic to split cart / added display.*/
/* 070005 02/23/10 JD2- Only hide the processing display if it exists.       */
/*                      Issue on pages not running through site.w.           */
/* 070004 02/16/10 JD2- Moved ajax functions to site.js. Issues on checkout. */
/*                    - Added getParam function get retrieving query param.  */
/* 070003 02/03/10 APY- Add getHash, showMore and hideMore functions.        */
/* 070002 01/19/10 JD2- Removed 10dev reference.                             */
/*                    - Added clearField and setField functions.             */
/* 070001 01/06/10 JB - Added ajax functions - deprecate ajax-js.i.          */
/* 070000 12/19/09 JB - Added and removed functions/vars for P9134.          */
/*                      Full content of CartHover.js is now contained here.  */
/* 060000 12/11/09 APY- Add setColorCookie function.                         */
/* 050000 04/03/09 JB - Update global.js from the web server.                */
/* 040000 04/23/02 JZ - Added missing image functionality.                   */
/*****************************************************************************/
/* 030100 10/15/01 JZ - Fix enlarge function for Mac IE 5.                   */
/* 030000 09/20/01 JZ - Added enlarge view functionality.                    */
/*****************************************************************************/
/* 020000 08/23/01 JZ - Wip'd to correct version problem.                    */
/*                    - Added blank function.                                */
/* 010102 12/12/00 IAB- Added functions for On Hold Alert                    */
/* 010100 08/22/00 JZ - Added a progress bar function with no time out.      */
/*****************************************************************************/
/* 070000 12/19/09 JB - Added and removed functions/vars for P9134.          */
/* 060000 12/11/09 APY- Add setColorCookie function.                         */
/* 050000 04/03/09 JB - Update global.js from the web server.                */
/* 040000 04/23/02 JZ - Added missing image functionality.                   */
/*****************************************************************************/
/* 030100 10/15/01 JZ - Fix enlarge function for Mac IE 5.                   */
/* 030000 09/20/01 JZ - Added enlarge view functionality.                    */
/*****************************************************************************/
/*** CartHover.js -- Renders order info and provides add-to-cart           ***/ 
/* 020000 08/23/01 JZ - Wip'd to correct version problem.                    */
/*                    - Added blank function.                                */
/* 010102 12/12/00 IAB- Added functions for On Hold Alert                    */
/* 010100 08/22/00 JZ - Added a progress bar function with no time out.      */
/*****************************************************************************/
// This is a .js file that contains several commonly used javascript functions
var img        = new Image();                                      /* 030000 */
var maxWidth   = 0;                                                /* 030000 */
var maxHeight  = 0;                                                /* 030000 */
var imagePath  = "";                                               /* 030000 */
var cartLink=(siteContent.cartStatus=="e")?"olc/olc-cart-fm.w":"b2c/retail-shop-list.w";  /* 070011 */
/********************^ 050000 ^********************/
// xp_progressbar
// Copyright 2004 Brian Gosselin of ScriptAsylum.com
//
// v1.0 - Initial release
// v1.1 - Added ability to pause the scrolling action (requires you to assign
//        the bar to a unique arbitrary variable).
//      - Added ability to specify an action to perform after a x amount of
//      - bar scrolls. This requires two added arguments.
// v1.2 - Added ability to hide/show each bar (requires you to assign the bar
//        to a unique arbitrary variable).
// var xyz = createBar(
// total_width,
// total_height,
// background_color,
// border_width,
// border_color,
// block_color,
// scroll_speed,
// block_count,
// scroll_count,
// action_to_perform_after_scrolled_n_times
// )
var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;
function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
if(ie||w3c){
var t='<div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
for(i=0;i<blocks;i++){
t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
t+='"></span>';
}
t+='</span></div>';

document.getElementById("procDiv").innerHTML = t; 
var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
bA.blocks=blocks;
bA.N=N;
bA.w=w;
bA.h=h;
bA.speed=speed;
bA.ctr=0;
bA.count=count;
bA.action=action;
bA.togglePause=togglePause;
bA.showBar=function(){
this.bar.style.visibility="visible";
}
bA.hideBar=function(){
this.bar.style.visibility="hidden";
}
bA.tid=setInterval('startBar('+N+')',speed);
return bA;
}}

function startBar(bn){
var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
t.style.left=-(t.h*2+1)+'px';
t.ctr++;
if(t.ctr>=t.count){
eval(t.action);
t.ctr=0;
}}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}
/********************^ 050000 ^********************/
/********************^ 040000 ^********************/
function centreMe(jwindow, height, width) 
{ 
   var screenHeight = screen.height; 
   var screenWidth  = screen.width; 
   var topLeftx     = Math.round( (screenWidth - width)/2 ); 
   var topLefty     = Math.round( (screenHeight - height)/2 ); 
   jwindow.moveTo(topLeftx, topLefty); 
} 

function status_write(msg) 
{
   window.status = msg;
   return true;
}
/********************v 020000 v********************/
function blank() { return "<html></html>";}
/********************^ 020000 ^********************/
var clickFlag = false;
var onhold = false;                                               /* 010102 */
var OnHoldWindow = null;                                          /* 010102 */

function getClickFlag()
{
   return clickFlag;
}

function checkClickFlag(vWindow)
{
   var isWindow = vWindow;
   if ( (!getClickFlag()) && (!onhold) )
   {
      clickFlag = true;
      brokenHref();
      if ( isWindow != "YES" )
      {
         runProgressBar();
      }
      return true;
   }
   else
   {
     if (OnHoldWindow != null)                                     /* 010102 */
         OnHoldWindow.focus();                                     /* 010102 */
      return false;
   }
}
/**************** 010100 ******************/
function checkClickFlagNoTimeout(vWindow)
{
   var isWindow = vWindow;
   if ( !getClickFlag() )
   {
      clickFlag = true;
      /* removed call to brokenHref() */
      if ( isWindow != "YES" )
      {
         runProgressBar();
      }
      return true;
   }
   else
   {
      return false;
   }
}
/****************^ 010100 ^******************/
var errorFlag;
function brokenHref()
{
   errorFlag = setTimeout("clickFlag = false;",10000);
}

// progress bar stuff below 

var i = 0;
var progressBar;
var goForward = true;

function runProgressBar() 
{
   i         = 0;
   goForward = true;

   if ( navigator.appName != "Netscape" )
   {
      for (var j=1; j<=50; j++)
      {
         eval("menu.document.all.cell_" + j + ".style.background=\"white\"");
      }
      eval("menu.document.all.progress.style.visibility=\"visible\"");
   
      progressBar = setInterval("if ( getClickFlag() ) {changeColor();} else {clearInterval(progressBar); eval(  \"menu.document.all.progress.style.visibility='hidden'\"  );}",5);
   }
}

function changeColor() 
{
   if ( goForward )
   {
      i++;
      if ( i > 50 )
      {
         i = 50;
         goForward = false;
         for (var j=1; j<=50; j++)
         {
            eval("menu.document.all.cell_" + j + ".style.background=\"white\"");
         }
      }
   }
   else
   {
      i--;
      if ( i < 1 )
      {
         i = 1;
         goForward = true;
         for (var j=1; j<=50; j++)
         {
            eval("menu.document.all.cell_" + j + ".style.background=\"white\"");
         }
      }

   }   
   eval("menu.document.all.cell_" + i + ".style.background=\"#cccc99\"");
}
/********************v 030000 v********************/
function enlarge(defWidth, defHeight, largeImage) 
{ 
   imagePath = largeImage;
   maxWidth  = defWidth;
   maxHeight = defHeight;
   img.src   = largeImage;

   if ( !( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1) ) ) 
   {
      imageWidth = setInterval("setWidth();", 100);
      stopWidth  = setTimeout("clearInterval(imageWidth); clearTimeout(stopWidth); ", 1000);
   }
   else
      openImage();
} 

function setWidth()
{
   if ( img.width != 0 )
   {
      clearInterval(imageWidth);
      clearTimeout(stopWidth);
      openImage();
   }

   if ( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1)) 
      openImage();
}

function openImage()
{
   if ( imagePath != "" ) 
   { 
      if ( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1)) 
         var large = window.open("", "Enlarge", "width=" + maxWidth + ",height=" + maxHeight + ",resizable=yes");  
      else 
         var large = window.open("", "Enlarge", "width=" + img.width + ",height=" + img.height + ",resizable=yes");  

      if ( large != null )    
      { 
         large.document.open();
         large.document.writeln('<html>'); 
         large.document.writeln('<head>'); 
         large.document.writeln('<title>Enlarged View</title>'); 
         large.document.writeln('</head>'); 
         large.document.writeln('<BODY bgcolor="#FFFFFF" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bottommargin="0">'); 
         large.document.write('<img src="" name="largepic" border="0"'); 
                              
         if ( img.width != 0 && img.width != 1 && img.width != null ) /* 030100 */
            large.document.write(' width="' + img.width + '"');

         if ( img.height != 0 && img.height != 1 && img.height != null) /* 030100 */
            large.document.write(' height="' + img.height + '"');
         
         large.document.write('>');
         large.document.writeln('</body>'); 
         large.document.writeln('</html>');           
         large.document.close();
         large.document.largepic.src = imagePath;
         large.focus();  
      } 
   } 
}
/********************^ 030000 ^********************/
/** APY 4/23/07 - update header shopping bag **/
function set_cart_qty(vNumItems) {
  var strQyt;
  strQyt = vNumItems;
  if(vNumItems == 1) {
    strQyt = strQyt + " item";
  } else {
    strQyt = strQyt + " items";
  }
  if (document.getElementById("cartItems"))                        /* 070010 */
  {
    document.getElementById("cartItems").innerHTML = strQyt;       /* 070010 */
  }
}
/** end APY **/

/********************v JJS v********************/
function ltrim (s) {
  return s.replace( /^\s*/, "" );
}

function rtrim (s) {
   return s.replace( /\s*$/, "" );
}

function trim(s) {
   var temp = s;
   return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}

function echeck(str) {
  var emailRegxp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(str.match(emailRegxp)){
  return true;
}else{
  return false;
}
}

function isNumeric(inNum) {	
//CHECK FOR NUMBERS
//ALLOWS -s
var x=inNum
var anum=/(\-)|(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true;
else{
testresult=false;
}
return (testresult);
}
/********************^ JJS ^********************/
/******v APY 01/03/08 v*****/
function getCurrency(vAmt,vCurrency)
{
  var vSymbol = "";
  var vReturnAmt = vAmt.toFixed(2);
  var vReturn = "";

  switch(vCurrency)
  {
    case "CAD":
       vSymbol = "$";
       break;
    case "CA":
       vSymbol = "$";
       break;
    case "USD":
       vSymbol = "$";
       break;
    case "US":
       vSymbol = "$";
       break;
    case "USD":
       vSymbol = "$";
       break;
    case "EUR":
       vSymbol = "&euro;";
       break;
    case "GBP":
       vSymbol = "&pound;";
       break;
  }
  if(vSymbol == "")
    vReturn = vReturnAmt + " " + vCurrency.toUpperCase();
  else
    vReturn = vSymbol + vReturnAmt;
   return vReturn;
} 
/******^ APY 01/03/08 ^*****/

/* vv 050000 jb vv */
function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
alert("Please enter date as either mm/dd/yyyy or use the calendar.");
return false;
}

month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}

if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
/* ^^ 050000 ^^ */

function findPosX(obj)
 {
  var curleft = 0;
  if(obj.offsetParent)
  while(1)
  {
   curleft += obj.offsetLeft;
  if(!obj.offsetParent)
    break;
  obj = obj.offsetParent;
  }
 else if(obj.x)
  curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
 var curtop = 0;
 if(obj.offsetParent)
 while(1)
 {
  curtop += obj.offsetTop;
  if(!obj.offsetParent)
    break;
  obj = obj.offsetParent;
  }
  else if(obj.y)
    curtop += obj.y;
  return curtop;
}

function checkBlank(vField)
{
     vField.value = rtrim(vField.value);
     vField.value = ltrim(vField.value);
 if (vField.value.length <= 0) return true;
 else return false;
}
/***vv 070000 vv***/
function setColorCookie(vStyleCode,vColorCode){
   setCookie("prodColor",vStyleCode + "," + vColorCode,null,"/",null,null);   /* 070010 */
}
/***^^ 070000 ^^***/
 addToCart = function(vProduct,vColor,vSize,vQty,vType) 
{
 document.location.href=siteContent.appPath+"/site.w?sponsor="+siteContent.fdmSponsor+"&frames=no&target=main&location=b2c/product.w&addtocart=yes&product=" + vProduct + "&color" + vProduct + "=" + vColor + "&size" + vProduct + "=" + vSize + "&qty=" + vQty + "&price=" + vSelectedPrice+"&type="+vType;
}

 validateSearchString = function()
{
   var flgStringValid = true;
   var strSearchString = new String(document.wordsearch.textsearch.value);
   if(strSearchString=="")
   {
      alert("Please enter a word or phrase to search for.");
      document.wordsearch.textsearch.focus();
      return false;
   }
   var index;
   var strErrorMsg, strErrorMsgInvalidChars;
   var strArrayOfInvalidChars = 
    new Array("\?", "\/","\\","\@","\(","\)","$","%","!","#");
   index = 0;
   while (flgStringValid == true && index < strArrayOfInvalidChars.length)
   {
      if (strSearchString.indexOf(strArrayOfInvalidChars[index]) != -1)
      {
         strErrorMsg = "Were sorry, your search phrase cannot contain the following characters: ";
         strErrorMsgInvalidChars = "";
         for (index = 0; index < strArrayOfInvalidChars.length; index++)
         {
            strErrorMsgInvalidChars = strErrorMsgInvalidChars + "'" + strArrayOfInvalidChars[index] + "'";
            if (index + 1 < strArrayOfInvalidChars.length)
            {
               strErrorMsgInvalidChars = strErrorMsgInvalidChars + ", ";
            }
         }
         alert(strErrorMsg + strErrorMsgInvalidChars);
         flgStringValid = false;
      }
      index++;
   }
   return flgStringValid;
}

 goSearch = function()
{
  if(validateSearchString()) 
 {
   goReplace(siteContent.appPath + '/olc/word-search.w?search=yes&textsearch=' + document.wordsearch.textsearch.value,'main');  /* 070002 */
  }
  return false;
 } 
 vOnLoad = "" ; 
 /* 070012 enableElements now in site.js */
 hideProcessing = function()
{
   var processDiv = document.getElementById('siteProcess');
   if (!processDiv) return;                                        /* 070005 */
   processDiv.className = "siteProcessNone";
  for(f=0;f<document.forms.length;f++){
   for(i=0;i<document.forms[f].elements.length;i++){
     if (navigator.appName=="Microsoft Internet Explorer" && parseFloat(navigator.appVersion)<=4 && navigator.appVersion.indexOf("MSIE 6") != -1 && (document.forms[f].elements[i].type=="select-one" || document.forms[f].elements[i].type=="select-multiple" || document.forms[f].elements[i].type=="select"))
     {
      document.forms[f].elements[i].style.visibility = "visible";
     }
   }
  }
 }
 showLoginPopup = function()
{
 disableElements("loginPopup");
 if (document.getElementById("loginMsg").offsetWidth > document.getElementById("loginPopup").offsetWidth)
 {
   document.getElementById("loginPopup").style.width  = document.getElementById("loginMsg").offsetWidth  + 50 + "px";
   document.getElementById("loginPopup").style.height = document.getElementById("loginMsg").offsetHeight + 50 + "px";
 }
 else
 {
   document.getElementById("loginPopup").style.width  = document.getElementById("loginMsg").offsetWidth  + 40 + "px";
   document.getElementById("loginPopup").style.height = document.getElementById("loginMsg").offsetHeight + 40 + "px";
 }
 vOnLoad = "moveDialog('loginPopup')";
 moveDialog('loginPopup');
 window.onscroll = function() {eval(vOnLoad);};
}

 hideLoginPopup = function()
{
   document.getElementById("loginPopup").style.display = "none";
   window.onscroll = "";
   document.getElementById('overlay').style.display = "none";
   document.getElementById('overlay').style.visibility = "hidden";
   enableElements();
}

/* vv Old CartHover.js vv */
/******vv 070006 vv******/
var vParams2 = "?frames=no&target=main&sponsor="+fdmSponsor;
var xmlUrl = appPath + "/xml/cartRequest.w" + vParams2; /* 010005 */
var myCart = new Cart("0");
var CartShown = false;
var cartTimer, addedTimer;
var vAddedDispTime = 4000; 
var boundFloatingAdd = false; 
var orderType = "";  /* 010000 */
var vLeft=0;
var vTop=0;
/***vv 010000 vv***/
var vStartLoad = false;
var currTime = new Date();
var currSecs  = (((currTime.getHours() * 60) + currTime.getMinutes()) * 60) + currTime.getSeconds();
var nocache = "&nocache=" + currSecs;
var vProductMode="";
var vCartLabel="";
var vCartMsgSelector=""; /* 010002 */
var vTopScroll=false;    /* 010002 */
/* 070008 - removed nocache var */
/***^^ 010000 ^^***/

function CartLine(style, styleVal, color, colorVal, size, sizeVal, price, qty, tot)
{
	this.Style = style;
	this.StyleVal = styleVal;
	this.Color = color;
	this.ColorVal = colorVal;
	this.Size = size;
	this.SizeVal = sizeVal;
	this.Price = price;
	this.Quantity = qty;
	this.LineTotal = tot;
}
function AddedItem(style, styleVal, color, size, qty, image)
{
	this.Style = style;
	this.StyleVal = styleVal;
	this.Color = color;
	this.Size = size;
	this.Quantity = qty;
	this.ImagePath = image;
}

function Cart(subtotal)
{
	if (subtotal.length < 1)
		subtotal = 0.00;

	this.SubTotal		= subtotal;
	this.CartLines		= new Array();
	this.JustAdded		= new Array();
	this.HiddenPages	= new Array();
	this.IsLoading		= false;
 /******v 010000 v******/
 if (orderType == "Q")
	   this.LoadingMessage = "Loading Wishlist...";
 else
    this.LoadingMessage = "Loading " + vCartLabel + "...";  /* 010000 */
 /******^ 010000 ^******/
	this.ToHtmlStub		= function()
	{
		var ret = "<img src=\""+imgPath+"/1by1pix.gif\" border=\"0\" id=\"floatPosition\"><a class=\"cartStubLink\" href=\"javascript:golink('"+cartLink+"','main');\">";  /* 010001 */  /* 070011 */
		if (this.CartLines.length < 1)
			   ret += "No items in your " + vCartLabel + ".";  /* 010000 */
		else
		{
			var itemTotal = 0;
			for (var i=0; i<this.CartLines.length; i++)
			{
				var tItem = this.CartLines[i];
				if (isNaN(tItem.Quantity))
					itemTotal += 1;
				else
					itemTotal += parseInt(tItem.Quantity);
			}

			ret += "Items: " + itemTotal + ", Subtotal: " + this.SubTotal;
		}
		ret += '</a>';
		return ret;
	}
	this.ToHtml		= function() 
	{
		if (this.CartLines.length < 1)
		{
			return "<table class=\"cartTable\"><tbody><tr>" +
				   "<td class=\"cartCell\" style=\"text-align: center\">No Items.</td>" + 
				   "</tr></table>";
		}

		var msg = "<table class=\"cartTable\"><tbody>";
		var itemTotal = 0;
		for (var i=0; i<this.CartLines.length; i++)
		{
			var tItem = this.CartLines[i];
			msg += "<tr><td class=\"cartCell\" style=\"text-align: left; width: 70%;\">" + 
							"<a href=\"javascript:golink('b2c/product.w?product=" + tItem.StyleVal + "','main');\">" + tItem.Style + "</a>" + 
						"</td>\n" +
					    "<td class=\"cartCell\" style=\"text-align: right; width: 30%;\">" + tItem.Quantity + "@ " + tItem.Price + "</td></tr>\n";
    if(vProductMode=="S")
     msg+="<tr><td class=\"cartSubCell\" style=\"text-align: left;\" colspan=\"2\">" + tItem.Size + ", " + tItem.Color + "</td></tr>\n";

			if (isNaN(tItem.Quantity))
				itemTotal += 1;
			else
				itemTotal += parseInt(tItem.Quantity);
		}
		msg += "<tr><td colspan=\"2\"><hr class=\"cartSep\"></td></tr>\n" +
			   "<tr><td class=\"cartFooter\" style=\"text-align: left;\">" + itemTotal + " Items</td>\n" + 
			   "<td class=\"cartFooter\" style=\"text-align: right; width: 75%;\">Subtotal: " + 
				this.SubTotal + "</td></tr></tbody></table>\n";
		return msg;
	}
	this.ErrorMessage	= function (msg)
	{
		return "<table class=\"cartTable\"><tbody><tr>" +
			   "<td class=\"cartCell\" style=\"text-align: center\">" + msg + "</td>" + 
			   "</tr></table>";
	}
	this.JustAddedHtml	= function ()
	{
		// This shouldn't ever really be called when there are no items, however on the off chance it was...
		if (this.JustAdded.length < 1)
		{
			return "<table class=\"cartTable\"><tbody><tr>" +
				   "<td class=\"cartCell\" style=\"text-align: center\">No items were recently added.</td>" + 
				   "</tr></table>";
		}

		var msg = "<table class=\"cartTable\"><tbody>";
		for (var i = 0; i<this.JustAdded.length; i++)
		{
			var tItem = this.JustAdded[i];
			msg += "<tr><td class=\"cartCell\" style=\"text-align: left;\">" + 
						"<a class=\"cartLink\" href=\"javascript:golink('b2c/product.w?product=" + tItem.StyleVal + "','main');\">" + 
							tItem.ImagePath + "</a></td><td class=\"cartCell\" style=\"text-align: center;\">" +
  						"<span class=\"cartAddedText\">Added ";
			if (tItem.Quantity > 1)
				msg += tItem.Quantity + " of ";
   
   /******v 010000 v******/
   if (orderType == "Q")
   			msg += "<br /><a href=\"javascript:golink('b2c/product.w?product=" + tItem.StyleVal + "','main');\">" + 
   						tItem.Style + "</a><br /> to your wishlist.</span><br /><br />" + 
   				   "<a href=\"javascript:golink('b2c/retail-wishlist.w','main');\">" + 
   				   "<img src=\""+imgPath+"/buttons/View-Wishlist.jpg\" alt=\"View Wishlist\" /></a>" +  /* 010001 */
   				   "</td></tr>";
   else
   			msg += "<br /><a href=\"javascript:golink('b2c/product.w?product=" + tItem.StyleVal + "','main');\">" + 
   						tItem.Style + "</a><br /> to your " + vCartLabel + ".</span><br /><br />" +  /* 010000 */
   				   "<a href=\"javascript:golink('"+cartLink+"','main');\">" +  /* 070011 */
   				   "<img src=\""+imgPath+"/buttons/View-Bag.jpg\" alt=\"View "+vCartLabel+"\" /></a>" +  /* 010000 */  /* 010001 */
   				   "</td></tr>";
   /******^ 010000 ^******/
		}

		return msg;
	}
	this.IsHiddenHere	= function (page)
	{
		// Loop through HiddenPages array and search the page string for it.
		if (this.HiddenPages.length < 1)
			return false;

		if (page == null)
			page = document.location.href;

		for (var i = 0; i<this.HiddenPages.length; i++)
		{
			var tPage = this.HiddenPages[i];
			// If we find it, return true (that it's hidden)
			if (page.toUpperCase().indexOf(tPage.toUpperCase()) >= 0)	
				return true;
		}
		return false;
	}
}

/* Events */
function cartInitialize()
{
 if(vStartLoad==false)
 loadMyCart();
}

/* Methods */
function loadMyCart(mode,style,color,size,qty,vOrderType) /* 010000 */
{
	myCart.IsLoading = true;
 vStartLoad = true;
 orderType = vOrderType;                                  /* 010000 */
	var realUrl = xmlUrl;

	if (mode == "add") // Add something to cart mode.
	{
		realUrl +=  "&cartMode=add&product=" + style;
  if(color!=null) realUrl += "&color=" + color; 
  if(size!=null) realUrl += "&size=" + size;
  realUrl+="&qty=" + qty + "&ordertype=" + vOrderType; /* 010000 */
	}

 $.ajax({
   type: "GET",
   url: realUrl+getNoCacheParam(),                                 /* 070008 */
   dataType: "xml",
   complete: function(data) {
       myCart.IsLoading = false;

       //XML Error Checking
       if (data.responseXML == null) return;
       var cart = data.responseXML.documentElement;		
       if (! cart) return; // we got an invalid value back
       vError = cart.attributes.getNamedItem("error").value;
       if(vError.length>0) { alert(vError); return;}

       myCart = new Cart(cart.attributes.getNamedItem("total").value);
       vProductMode = cart.attributes.getNamedItem("productMode").value;
       vCartLabel = cart.attributes.getNamedItem("cartLabel").value;

       //Set Pages that should not display cartHover
       var hiddenPages = cart.attributes.getNamedItem("hideOnPages");
       if (hiddenPages != null){
        var tArr = hiddenPages.value.split(",");
        for (var i = 0; i< tArr.length; i++){
         myCart.HiddenPages.push(tArr[i]);
        }
       }
       
       hideCartNow();
       clearTimeout(cartTimer);
       clearTimeout(addedTimer);       

       /* <cartLine> */
       var cartLines = cart.getElementsByTagName("cartLine");

       for (var i = 0; i<cartLines.length; i++)
       {
        var line = cartLines[i];

        /* <style /> Style */
        var styleEle = line.getElementsByTagName("style")[0];
        var style = styleEle.attributes.getNamedItem("desc").value;
        if(vProductMode=="S"&&styleEle.childNodes[0]!=null)  /* 010000 */
        {
         var styleVal = styleEle.childNodes[0].nodeValue; 
         /* <color /> Color */
         var colorEle = line.getElementsByTagName("color")[0];
         var color = colorEle.attributes.getNamedItem("desc").value;
         var colorVal=null;
         var sizeVal=null;
         var size="";
         if(colorEle.childNodes[0]!=null) colorVal=colorEle.childNodes[0].nodeValue;
        /* <size /> Size */
         var sizeEle = line.getElementsByTagName("size")[0];	
         if(sizeEle.attributes.getNamedItem("desc")!=null) size = sizeEle.attributes.getNamedItem("desc").value;
         if(sizeEle.childNodes[0]!=null) sizeVal = sizeEle.childNodes[0].nodeValue;
        }
        else if (styleEle.childNodes[0]!=null) {   // 010004
          var styleVal = styleEle.childNodes[0].nodeValue; // 010004 
        }
        /* <price /> Item Price */
        var price = line.getElementsByTagName("price")[0].childNodes[0].nodeValue;
        /* <qty /> Quantity */
        var quantity = line.getElementsByTagName("qty")[0].childNodes[0].nodeValue;
        /* <total /> Line Total */
        var lineTotal = line.attributes.getNamedItem("total").value;

        myCart.CartLines.push(new CartLine(style, styleVal, color, colorVal, size, sizeVal, price, quantity, lineTotal));
       }
       /* </cartLine> */
       if (orderType != "Q")                                   /* 010000 */
       document.getElementById("shopStub").innerHTML = myCart.ToHtmlStub();

       /* <added> */
       var added = cart.getElementsByTagName("added");
       myCart.JustAdded = new Array();
       if (added.length > 0)
       {
        for (var i = 0; i<added.length; i++)
        {
         var addItem = added[i];
         /* <style /> Style */
         var styleEle = addItem.getElementsByTagName("style")[0];
         var style = styleEle.attributes.getNamedItem("desc").value;
         
         if(vProductMode=="S"&&styleEle.childNodes[0]!=null)  /* 010000 */
         {
           var styleVal = styleEle.childNodes[0].nodeValue;  
           /* <color /> Color -- Unused atm. */	
           var color = addItem.getElementsByTagName("color")[0].childNodes[0].nodeValue;
           /* <size /> Size */
           var size = addItem.getElementsByTagName("size")[0].childNodes[0].nodeValue;
         }
         else if (styleEle.childNodes[0]!=null) {   // 010004
           var styleVal = styleEle.childNodes[0].nodeValue; // 010004 
         }
         /* <qty /> Quantity */
         var qty = addItem.getElementsByTagName("qty")[0].childNodes[0].nodeValue;
         /* <image /> Image */
         var imageEle = addItem.getElementsByTagName("image")[0];
         var image = null;
         if (imageEle.childNodes.length > 0)
          image = imageEle.childNodes[0].nodeValue;
         
         myCart.JustAdded.push(new AddedItem(style, styleVal, color, size, qty, image));
        }
        // Show the cart display with a message in it.
        displayAddedToCart(myCart.JustAddedHtml());
	      }
       /* </added> */

       /***vv 010002 vv***/   
       //scroll to top is set
       if (vTopScroll&&$(document).scrollTop() > $("#shopStub").offset().top)
       { $(document).scrollTop($("#shopStub").offset().top); }
       // Show msg in selector element if set
       if (vCartMsgSelector != "") 
       {	$(vCartMsgSelector).html(qty + " " + style + " added to shopping cart."); }
       /***^^ 010002 ^^***/

   }
 });
}
function floatingAddToCart(style,color,size,qty,vOrderType,vJQSelector) /* 010000 */ /* 010002 */
{
 /******vv 010002 vv******/
 if(vJQSelector){
   $(vCartMsgSelector).html(); 
   vCartMsgSelector = vJQSelector; 
 }
 /******^^ 010002 ^^******/
 loadMyCart("add",style,color,size,qty,vOrderType); /* 010000 */
}
function updateShopStub(){
	// Update the non-cart values now that the cart is built.
	if (myCart.IsLoading)
 		document.getElementById("shopStub").innerHTML = myCart.LoadingMessage;
	else
		 document.getElementById("floatingCart").innerHTML = myCart.ToHtml();
}

function displayAddedToCart(val){
  clearTimeout(addedTimer);
  var $floatingAdded = $("#floatingAddedToCart");
  if ($floatingAdded.length){
     if(boundFloatingAdd==false){    
       if ($floatingAdded.mouseenter != undefined) { /* 070009 */ 
       $floatingAdded.mouseenter(function(){ 
           clearTimeout(addedTimer); 
       });
       } /* 070009 */
       if ($floatingAdded.mouseleave != undefined) { /* 070009 */
        $floatingAdded.mouseleave(function(){ 
          addedTimer = setTimeout(function() {  $("#floatingAddedToCart").hide(); }, vAddedDispTime); 
       });
       } /* 070009 */ 
       boundFloatingAdd = true;
     }
    $floatingAdded.html(val).show();
    addedTimer = setTimeout(function() {  $("#floatingAddedToCart").hide(); }, vAddedDispTime);

  }else{
   displayCart(val);
  }

}
function displayCart(val){
 //Return if empty or in hidden list
	if (myCart.IsHiddenHere() || myCart.CartLines.length < 1) return;
 //Clear hide delay timer
	clearTimeout(cartTimer);

	if (! CartShown && myCart.IsLoading == false)
	{
		if (val == null) val = myCart.ToHtml();

		var $floatingCart = $("#floatingCart");
  var $vFloat=$("#floatPosition");
  var $shopStub = $("#shopStub");

  $floatingCart.html(val);

  vFloatPos=$shopStub.position();
  vFloatPos.top += $shopStub.outerHeight();
  vFloatPos.left += $shopStub.outerWidth();
  //Display offscreen to get width/height
  $floatingCart.css("left","-99999px")
               .css("top","-99999px")
               .show();
  vFloatPos.left -= $floatingCart.outerWidth();
  $floatingCart.css("top",vFloatPos.top)
               .css("left",vFloatPos.left);
		CartShown = true;
	}
}

//Hide Cart Functions, 1/4 second delay
function hideCart(){
	cartTimer = setTimeout(function() { hideCartNow() }, 250);
}
function hideCartNow(){
	if (CartShown){   
		$("#floatingCart").hide();
		CartShown = false;
	}
}

function setTopScroll(vSetting){
 if (vSetting==false||vSetting==true)
   vTopScroll = vSetting;
} /* 010002 */
/******^^ 070006 ^^******/
$(document).ready(function() { 
  if(document.getElementById("shopStub")!=null)
     addToCart=floatingAddToCart;
});

/* 070004 - moved ajax functions */

 hideProcessing();

/******v 070002 v******/

function clearField(vField,vText) {
  if (vText != "" && vField.value == vText) 
     vField.value = "";
}

function setField(vField,vText) {
  if (vText != "" && vField.value == "") 
     vField.value = vText;
}

/******^ 070002 ^******/
/******v 070003 v******/
function getHash(){
  var hashObj = new Array();
  var urlHash = window.location.hash;
  urlHash = urlHash.substring(1,urlHash.length)
  urlHash = urlHash.split("&");
  $(urlHash).each(function(i){
    var nameValue = this.split("=");
    if (nameValue.length == 2)
      hashObj[i] = {"name":nameValue[0],"value":nameValue[1]};
    if (nameValue.length == 1)
      hashObj[i] = {"name":nameValue[0]};
  });
  return hashObj;
}

function showMore(){
  $('#topCopyLower').slideDown();
  $('#topCopyShow').hide();
}
function hideMore(){
  $('#topCopyLower').slideUp();
  $('#topCopyShow').show();
}
/******^ 070003 ^******/
/******v 070004 v******/
function getParam(name) {
  var start=location.search.indexOf("?"+name+"=");
  if (start<0) start=location.search.indexOf("&"+name+"=");
  if (start<0) return '';
  start += name.length+2;
  var end=location.search.indexOf("&",start)-1;
  if (end<0) end=location.search.length;
  var result='';
  for(var i=start;i<=end;i++) {
    var c=location.search.charAt(i);
    result=result+(c=='+'?' ':c);
  }
  return unescape(result);
}

/******^ 070004 ^******/
/********************v 070008 v********************/
function getNoCacheParam() {
  var vCurrTime = new Date();
  var vCurrSecs  = (((vCurrTime.getHours() * 60) + vCurrTime.getMinutes()) * 60) + vCurrTime.getSeconds();
  var vNoCache = "&nocache=" + vCurrSecs;
  return vNoCache;
}
/********************^ 070008 ^********************/

