// ---------------------------------------------------------------------------------------------

function popWindowAdv(url,width,height,style) {

   var top=0;
   var left=0;

   if (style == "center") {
      top = (screen.height - height)/2;
      left = (screen.width - width)/2;
      var reWin = window.open(url,'popAdvice','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height+',top='+top+',left='+left)
   }
   if (style == "hidden") {
      top = (screen.height + 100);
      left = (screen.width + 100);
      width = 50;
      height = 10;
      var reWin = window.open(url,'popAdvice','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height+',top='+top+',left='+left)
      this.focus();
   }
}

// ---------------------------------------------------------------------------------------------

function popWindow(url,width,height,name){
   var objWin;
   var param;

   url = (new String(url) == "undefined")? "" : url;     //verification de l'url
   name = (new String(name) == "undefined")? "" : name; // verification du nom de fenetre

   // toolbar
   param = (arguments[4]+"" == "undefined" || arguments[4]+"" == "") ? "" : "toolbar,";
   // location
   param += (arguments[5]+"" == "undefined" || arguments[5]+"" == "") ? "" : "location,";
   // statusbar
   param += (arguments[6]+"" == "undefined" || arguments[6]+"" == "") ? "" : "status,";
   // menubar
   param += (arguments[7]+"" == "undefined" || arguments[7]+"" == "") ? "" : "menubar,";
   //scrollbar
   param += (arguments[8]+"" == "undefined" || arguments[8]+"" == "") ? "" : "scrollbars,";
   //resizable
   param += (arguments[9]+"" == "undefined" || arguments[9]+"" == "") ? "" : "resizable,";
   // directory
   param += (arguments[10]+"" == "undefined" || arguments[10]+"" == "") ? "" : "directory,";
   // copyhistory
   param += (arguments[11]+"" == "undefined" || arguments[11]+"" == "") ? "" : "copyhistory,";

   param += (new String(height) == "" || new String(height) == "undefined" || isNaN(height))? "height=," : "height=" + height +",";
   param += (new String(width) == "" || new String(width) == "undefined" || isNaN(width))? "width=" : "width=" + width +"";


   objWin = window.open(url,name,param);

   return objWin;

}

// ---------------------------------------------------------------------------------------------
   
   function mvmOver(pImg, pSrcOver, pSrcOut) {
       if(!pSrcOver) pSrcOver = pImg.src.replace("_off","_over"); // We set a default "over" if none is defined
       if(!pSrcOut) pSrcOut = pImg.src; // We set the "out" src to the current one if none is passed as param
       pImg.src = pSrcOver;
       pImg.onmouseout = function(){this.src = pSrcOut; this.onmouseout = null;}
       pImg = null;
   }

// ---------------------------------------------------------------------------------------------

   var BUTTON_STATE_OFF       = "off";
   var BUTTON_STATE_ON        = "on";
   var BUTTON_STATE_DISABLED  = "dis";
   var BUTTON_STATE_INVISIBLE = "inv";

   function layoutButtonObject( pName )
   {
      this.name         = pName;
      this.state        = BUTTON_STATE_OFF;
      this.hoverActive  = "true";
      this.link         = "javascript:;";
      this.image        = "spacer.gif";
      this.message      = "";

      this.getCode      = _layoutButtonObject_getCode;
      this.display      = _layoutButtonObject_display;
      this.changeLink   = _layoutButtonObject_changeLink;
      this.changeImage  = _layoutButtonObject_changeImage;
      this.changeState  = _layoutButtonObject_changeState;
   }

   function _layoutButtonObject_getCode()
   {
      var content = "";

      if (this.state != BUTTON_STATE_INVISIBLE)
      {

         content += "<a id='" + this.name + "_linktag' href='" + (this.state != BUTTON_STATE_DISABLED ? this.link : "javascript:;" ) + "' onclick='window.status=\"Processing...Please wait\"; return true' onMouseOver='window.status=\"" + this.message + "\" ; return true' onMouseOut='window.status=\"\"' >" +
                    "<img id='" + this.name + "_imagetag' src='/" + retailerCode + "/images/"+ populationDomain + "/" + this.image + "_" + this.state + ".gif' border='0' alt='" + this.message + "' ";

         if (this.hoverActive=="true")
         {
            content += "onmouseover='mvmOver(this)'";
         }

         content += "></a>";

      }
      return content;
   }

   function _layoutButtonObject_display()
   {
      document.write(this.getCode());
   }

   function _layoutButtonObject_changeLink( pNewLink )
   {
      if ( document.all && document.anchors(this.name + "_linktag") )
      {
         document.anchors(this.name + "_linktag").href = pNewLink;
      }
      else if ( document.layers )
      {
         //eval(this.name + "_linktag").href = pNewLink;
      }
      else if ( document.getElementById && document.getElementById(this.name + "_linktag") )
      {
         document.getElementById(this.name + "_linktag").href = pNewLink;
      }
   }

   function _layoutButtonObject_changeImage( pNewImage )
   {
      if ( document.all && document.images(this.name + "_imagetag") )
      {
         document.images(this.name + "_imagetag").src = pNewImage;
      }
      else if ( document.layers )
      {
         //findImage(this.name + "_imagetag",document).src = pNewImage;
      }
      else if ( document.getElementById && document.getElementById(this.name + "_imagetag") )
      {
         document.getElementById(this.name + "_imagetag").src = pNewImage;
      }
   }

   function _layoutButtonObject_changeState( pNewState )
   {
      if ( this.state != pNewState )
      {
         this.state = pNewState;

         if ( this.state == BUTTON_STATE_OFF )
         {
            this.changeImage("/" + retailerCode + "/images/"+ populationDomain + "/" + this.image + "_" + this.state + ".gif");
            this.changeLink(this.link);
         }
         else if ( this.state == BUTTON_STATE_ON )
         {
            this.changeImage("/" + retailerCode + "/images/"+ populationDomain + "/" + this.image + "_" + this.state + ".gif");
            this.changeLink(this.link);
         }
         else if ( this.state == BUTTON_STATE_DISABLED )
         {
            this.changeImage("/" + retailerCode + "/images/"+ populationDomain + "/" + this.image + "_" + this.state + ".gif");
            this.changeLink("javascript:;");
         }
         else if ( this.state == BUTTON_STATE_INVISIBLE )
         {
            this.changeImage("/" + retailerCode + "/images/"+ populationDomain + "/spacer.gif");
            this.changeLink("javascript:;");
         }
      }
   }


   function autoResizeWindow(pWidth,pHeight)
   {
      if ( window.opener )
      {
         if (document.all)
         {
            if ( navigator.appVersion.toLowerCase().indexOf("mac") != -1 )
            {
               window.resizeTo(pWidth-10,pHeight-33);
            }
            else
            {
               window.resizeTo(pWidth,pHeight);
            }
         }
         else if ( document.getElementById )
         {
            window.resizeTo(pWidth-5,pHeight-5);
         }
         else if ( window.resizeTo )
         {
            window.resizeTo(pWidth,pHeight);
         }
      }
   }




   function loadImages()
   {
      loadAllImages(document);
   }

   function loadAllImages(doc)
   {
      var i, img;
      if ( doc.images )
      {
         for (i = 0; i < doc.images.length; i++)
            if (doc.images[i].postLoadSrc)
               doc.images[i].src = doc.images[i].postLoadSrc;
      }
      if ( doc.layers )
      {
         for (i = 0; i < doc.layers.length; i++)
            if ((img = loadAllImages(name, doc.layers[i].document)) != null) {
               img.container = doc.layers[i];
               return img;
            }
      }
      return null;
   }


   function formatPrice( pPrice )
   {
      if ( pPrice.indexOf(".") > 0 )
      {
         var priceComponents = pPrice.split(".");
         if ( priceComponents[1].length == 1 )
         {
            pPrice += "0";
         }
      }
      else
      {
         pPrice += ".00";
      }

      return pPrice
   }
   
   
  var ERROR_MSG_PREFIX = "<img src='/images/pointer.gif'> ";