/*** COPYRIGHT 2009  BY FDM4 INTERNATIONAL INC. - ALL RIGHTS RESERVED ********/
/*** site.js -- Site JavaScript Include for the <head> section             ***/ 
/*****************************************************************************/
/* 010107 01/18/11 JB - Removed top references.                              */
/* 010106 11/15/10 MS - Merged T010101 from TRI99w (IE cookie fix).          */
/*****************************************************************************/
/*T010101 11/10/10 MS - Removed cookie retrieval for fdmLoggedIn value, now  */
/*                    - is set from Users table inside inc/web_scripts.i     */
/*****************************************************************************/
/* 010105 11/06/10 JD2- Removed JS alert when XML tag not found from         */
/*                      getNodeValue.                                        */
/* 010104 08/05/10 JB - Added centreMe function.                             */
/* 010103 02/24/10 APY- MoveDialog Fixes.                                    */
/* 010102 02/16/10 JD2- Moved in ajax functions from global.js.              */
/* 010101 02/08/10 JD2 - getCookie: Always return "" when cookie is blank.   */
/* 010100 01/13/10 PMS - Added language variable                             */
/* 010000 12/19/09 JB - Reworked global.js and removed site.w scripting.     */
/*****************************************************************************/
var vOrderLine = new Array();
var vOrderHeader = null;
var vCustomerInfo = null;
var vUnappliedCheck = false;
var vClickProtected = false;
var hostDomain="";
var shostDomain="";
var appPath="";
var webPath="";
var imgPath="";
var fdmCookie="";
var sitePath="";
var fdmLoggedIn=null;
var clientLang="en-US";
var fdmSponsor="";
var siteImg="";
var siteBanner="";
var siteHome="";
var siteDesc="";
var siteEmail="";
var GaID=null;
var securePages="";
vColor=new Array();
/********************v 040000 v********************/

var missingImgSmall = new Image();      
var missingImgThumb = new Image();      
var missingImgBig   = new Image();       
var missingImgSwatch  = new Image();                               /* 050000 */

/********************v 050000 v********************/

missingImgSmall.src="/missing_small.gif"; 
missingImgThumb.src="/missing_thumb.gif"; 
missingImgBig.src="/missing_large.gif";    
missingImgSwatch.src="/missing_swatch.gif";                        /* 050000 */

/********************v 010104 v********************/
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); 
} 
/********************^ 010104 ^********************/
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 getCookie( label ) 
{ 
   var labelLen = label.length; 
   var cLen = document.cookie.length; 
   var i = 0; 
   var cEnd;
   var cVal = "";  /* 010101 */ 
   while ( i < cLen ) 
   { 
      var j = i + labelLen; 
      if ( document.cookie.substring(i,j) == label ) 
      { 
         cEnd = document.cookie.indexOf(";", j); 
         if ( cEnd == -1 ) 
         { 
            cEnd = document.cookie.length; 
         }
         cVal = unescape(document.cookie.substring(j + 1,cEnd)); /* 010101 */
         if (cVal == ";") cVal = "";                             /* 010101 */
         return cVal;                                            /* 010101 */ 
      } 
      i++; 
   } 
   return ""; 
} 

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";
   }
}
siteContent = function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)           /* T010101 */ 
{
 var useVars=true; // this is to include use of the variables for compatibility purposes

 this.hostDomain=a;
 this.shostDomain=b;
 this.appPath=c;
 this.webPath=d;
 this.imgPath=e;
 this.fdmCookie=f;
 this.sitePath="/site.w?location=";
 this.fdmLoggedIn=p;                                              /* T010101 */
 this.clientLang=getCookie("clientLang"+this.fdmCookie);
 this.fdmSponsor=g;
 this.siteImg=h;
 this.siteBanner=i;
 this.siteHome=j;
 this.siteDesc=k;
 this.siteEmail=l;
 this.GaID=m;
 this.securePages=n;
 this.showProcessing=o;

 if (useVars)
 {
  hostDomain=a;
  shostDomain=b;
  appPath=c;
  webPath=d;
  imgPath=e;
  fdmCookie=f;
  sitePath="/site.w?location=";
  fdmLoggedIn=p;                                                  /* T010101 */
  clientLang=getCookie("clientLang" + fdmCookie);
  fdmSponsor=g;
  siteImg=h;
  siteBanner=i;
  siteHome=j;
  siteDesc=k;
  siteEmail=l;
  GaID=m;
  securePages=n;
 }
}

function orderHeader(vOrderId,vAffiliation,vTotal,vTax,vShipping,vCity,vState,vCountry) {
   this.orderId = vOrderId;
   this.affiliation = vAffiliation;
   this.total = vTotal;
   this.tax = vTax;
   this.shipping = vShipping;
   this.city = vCity;
   this.state = vState;
   this.country = vCountry;
}
function orderLine(vOrderId,vSku,vProductName,vCategory,vPrice,vQuantity) {
   this.orderId = vOrderId;
   this.sku = vSku;
   this.productName = vProductName;
   this.category = vCategory;
   this.price = vPrice;
   this.quantity = vQuantity;
}

function customerInfo(vUserEmail,vCustAddress,vCustCity,vCustProv,vCustPcode,vCustCountry,vCustPhone,vUserFirstName,vUserLastName) {
   this.userEmail = vUserEmail;
   this.custAddress = vCustAddress;
   this.custCity = vCustCity;
   this.custProv = vCustProv;
   this.custPcode = vCustPcode;
   this.custCountry = vCustCountry;
   this.custPhone = vCustPhone;
   this.userFirstName = vUserFirstName;
   this.userLastName = vUserLastName;
}

function ImageError(imgObj,size)
{
 if (size == "small")
    imgObj.src = missingImgSmall.src;
 else
 if (size == "thumb")
    imgObj.src = missingImgThumb.src;
 else
 if (size == "large")
    imgObj.src = missingImgBig.src;
 else
 if (size == "swatch")
    imgObj.src = missingImgSwatch.src;                             /* 050000 */
}

/***vv 010103 vv***/
moveDialog = function(vElementID){
 vElementID = "#" + vElementID;
 $Elem = $(vElementID);
 if($Elem.length){
 $Elem.css("top", ($(window).height() - $Elem.outerHeight() ) / 2 + $(document).scrollTop() )
      .css("left", ($(window).width() - $Elem.outerWidth() ) / 2 + $(document).scrollLeft() );
 }
} 
/***^^ 010103 ^^***/

 disableElements = function(vElement){
   if( document.body.scrollHeight > document.body.offsetHeight ) // IE
   {
      document.getElementById('overlay').style.width = document.body.scrollWidth;
      document.getElementById('overlay').style.height = document.body.scrollHeight;
   }
   else // IE 6 Strict, Mozilla and Safari
   { document.getElementById('overlay').style.width = document.body.offsetWidth + document.body.offsetLeft; 
      document.getElementById('overlay').style.height = document.body.offsetHeight + document.body.offsetTop; 
   }
   document.getElementById('overlay').style.top        = 0;
   document.getElementById('overlay').style.left       = 0;
   document.getElementById('overlay').style.display    = "block";
   document.getElementById('overlay').style.visibility = "visible";
   keepDisabled="^";
       for(f=0;f<document.forms.length;f++){
        for(i=0;i<document.forms[f].elements.length;i++){
      if (document.forms[f].elements[i].disabled==true)
      { keepDisabled+=document.forms[f].name + document.forms[f].elements[i].name + "^";}
    document.forms[f].elements[i].disabled=true;
      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 = "hidden";
      }
   }
   }
  }

 showProcessing = function()
{
   var processDiv = document.getElementById('siteProcess');
   processDiv.className = "siteProcessDiv";
  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 = "hidden";
     }
   }
  }
   moveDialog("siteProcess");
 }
golink = function(vLink,vTarget)
{
   var vResetFlag;
  if (!vClickProtected){
    vClickProtected = true;
 if (vUnappliedCheck)
 {
     if (isUnapplied() && saveUnappForm())
        return;
 }
 
 if(siteContent.showProcessing=="yes") showProcessing();
  var host     = "";
  var sPages   = siteContent.securePages.split(",");
  var vParams=""; 
  var vStart=vLink.indexOf("?") + 1; 
  var vEnd=vLink.length; 
  if (vStart>0 && vEnd>vStart && vLink.indexOf("?") != -1)
 {
   vParams = vLink.substring(vLink.indexOf("?") + 1,vLink.length); 
   vLink = vLink.substring(0,vLink.indexOf("?")); 
  }
  for (var i=0; i< sPages.length; i++)
  {
     if (vLink.indexOf(sPages[i]) > -1)
     {
        host = siteContent.shostDomain;
        break;
     }
  }
  if (host == "")
     host = siteContent.hostDomain;
  if(vParams.indexOf("=")!=-1)
     vParams = vParams + "&frames=no&target=" + vTarget; 
  else 
     vParams = vParams + "frames=no&target=" + vTarget; 

  vParams = vParams + "&sponsor="+siteContent.fdmSponsor;
  if(vTarget=="top")
  {
    document.location.href = host + siteContent.appPath + "/" + vLink + "?" + vParams; 
  }
  else
  {
   document.location.href=host + siteContent.appPath + "/site.w?location=" + vLink + "&" + vParams;  /* 010107 */
 }
}
else
   vResetFlag = setTimeout("vClickProtected = false;",3000);
 }
 goReplace = function(vLink,vTarget)
{
   var vResetFlag;
  if (!vClickProtected){
    vClickProtected = true;

 if(siteContent.showProcessing=="yes") showProcessing();
  var host     = "";
  var sPages   = siteContent.securePages.split(",");
  var vParams=""; 
  var vStart=vLink.indexOf("?") + 1; 
  var vEnd=vLink.length; 
  if (vStart>0 && vEnd>vStart && vLink.indexOf("?") != -1)
 {
   vParams = vLink.substring(vLink.indexOf("?") + 1,vLink.length); 
   vLink = vLink.substring(0,vLink.indexOf("?")); 
  }
  for (var i=0; i< sPages.length; i++)
  {
     if (vLink.indexOf(sPages[i]) > -1)
     {
        host = siteContent.shostDomain;
        break;
     }
  }
  if (host == "")
     host = siteContent.hostDomain;
  if(vParams.indexOf("=")!=-1)
     vParams = vParams + "&frames=no&target=" + vTarget; 
  else 
     vParams = vParams + "frames=no&target=" + vTarget; 
  vParams = vParams + "&sponsor="+siteContent.fdmSponsor;
  if(vTarget=="top")
  {
    document.location.replace(host + siteContent.appPath + "/" + vLink + "?" + vParams);  
  }
  else
  {
   document.location.replace(host + siteContent.appPath + "/site.w?location=" + vLink + "&" + vParams);  /* 010107 */
 }
}
else
   vResetFlag = setTimeout("vClickProtected = false;",3000);
 }
 golinkhash = function(vLink,vTarget)
{
   var vResetFlag;
  if (!vClickProtected){
    vClickProtected = true;
 if (vUnappliedCheck)
 {
     if (isUnapplied() && saveUnappForm())
        return;
 }
 
 if(siteContent.showProcessing=="yes") showProcessing();
  var host     = "";
  var sPages   = siteContent.securePages.split(",");
  var vParams=""; 
  var vStart=vLink.indexOf("?") + 1; 
  var vEnd=vLink.length; 
  if (vStart>0 && vEnd>vStart && vLink.indexOf("?") != -1)
 {
   vParams = vLink.substring(vLink.indexOf("?") + 1,vLink.length); 
   vLink = vLink.substring(0,vLink.indexOf("?")); 
  }
  for (var i=0; i< sPages.length; i++)
  {
     if (vLink.indexOf(sPages[i]) > -1)
     {
        host = siteContent.shostDomain;
        break;
     }
  }
  if (host == "")
     host = siteContent.hostDomain;
  if(vParams.indexOf("=")!=-1)
     vParams = vParams + "&frames=no&target=" + vTarget; 
  else 
     vParams = vParams + "frames=no&target=" + vTarget; 
  vParams = vParams + "&sponsor="+siteContent.fdmSponsor;
  if(vTarget=="top")
  {
    document.location.href = host + siteContent.siteHome + "#/cgi-bin/10dev/" + vLink + "?" + vParams; 
  }
  else
  {
    document.location.href = host + siteContent.siteHome + "#" + siteContent.appPath + "/site.w" + escape("?location=" + vLink + "&" + vParams);  /* 010107 */
 }
}
else
   vResetFlag = setTimeout("vClickProtected = false;",3000);
 }

 /* 010102 - functions from ajax-js.i - prototype.js compatibility */

var http_request = false;
var mimeType     = "";
var parseMode    = "";
var errorStatus  = "";
var errorMessage = "";
var textResponse = null;
var xmlResponse  = null;
function makeRequest(url,vMethod,vMimeType,vMode,vSendFields) {
    if (url.indexOf("nocache") < 0)
    {
       var currTime = new Date();
       var currSecs  = (((currTime.getHours() * 60) + currTime.getMinutes()) * 60) + currTime.getSeconds();
       var nocache = "nocache=" + currSecs;
       if (url.indexOf("?") != -1)
       {
          url = url + "&" + nocache;
       }
       else
       {
          url = url + "?" + nocache;
       }
    }
    http_request = false;
    mimeType = vMimeType;
    parseMode = vMode;
    var sendFields = "";
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType(vMimeType);
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        return false;
    }
    http_request.onreadystatechange = getRequest;
    if (vMethod == "POST" && (vSendFields == "" || vSendFields == null))
        sendFields = getSendFields();
    if (vSendFields != "" && vSendFields != null)
       sendFields = vSendFields;
    http_request.open(vMethod, url, true);
    if (vMethod == "POST")
    {
       http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       http_request.send(sendFields);
    }
    else
       http_request.send(null);
}
function getRequest() {
   var vDoc = null;
   if (http_request.readyState == 4) {
       if (http_request.status == 200) {
           if (mimeType == "text/xml")
              vDoc = http_request.responseXML;
           else
              vDoc = http_request.responseText;
          processRequest(vDoc);
       }
       else
          return false;
   }
}
function processRequest(vDoc) {
   if(mimeType == "text/xml")
   {
               xmlResponse      = vDoc.documentElement;
               var topNode      = vDoc.getElementsByTagName('ajaxml').item(0);
               errorStatus  = topNode.getAttribute('status');
               errorMessage = "";
               if (errorStatus == "error")
                  errorMessage = xmlResponse.getElementsByTagName("error")[0].firstChild.data;
      parseXML();
   }
   else if (parseMode == "market")
   {
      textResponse = vDoc;
      parseMarket();
   }
   else
  {
      textResponse = vDoc;
      parseText();
  }
}
function getNodeValue(tagName) {
   if (xmlResponse.getElementsByTagName(tagName))
   {
     if (xmlResponse.getElementsByTagName(tagName)[0])
     {
        if (xmlResponse.getElementsByTagName(tagName)[0].firstChild) return xmlResponse.getElementsByTagName(tagName)[0].firstChild.data;
        else return "";
     }                                                             /* 010105 */
  }
}
function getSendFields() {
        var submitForm = null;
        var vFormValue = "";
        var sendFields = "";
        var fields = new Array();
        submitForm = eval("document." + formName);
        if (submitForm)
        {
            for (var x = 0; x < eval("document." + formName + ".elements.length"); x++)
            {
               vFormValue = submitForm.elements[x].value;
               if (submitForm.elements[x].type == "checkbox")
                 vFormValue = submitForm.elements[x].checked;
               else if (submitForm.elements[x].type == "radio") 
                 vFormValue = (submitForm.elements[x].checked)?submitForm.elements[x].value : "";
               fields.push(submitForm.elements[x].name + "=" + escape(vFormValue));
            }
            sendFields = fields.join("&");
        }
    return sendFields;
}
/* end of ajax functions 010102 */


