var preUrl = '';
/* Date de creation: 09/04/2008 */
//|----
var isOverElm = null;
var TimeoutID = null;
var isIE        = ((window.ActiveXObject)? true : false);//
/*
function showRegInfo(oThis){
    isOverElm=1;
    document.getElementById("myspacetext").style.display = 'block';
    oThis.onmouseout = function () {
        isOverElm=null;
        TimeoutID = setTimeout("displayNone('myspacetext')", 750);
    }
}

function getFocus(oThis) {
    isOverElm=1;
    oThis.onmouseout = function () {
        isOverElm = null;
        TimeoutID = setTimeout("displayNone('myspacetext')", 750);
    }
}

function displayNone(id){
    if (isOverElm==null) {
        isOverElm = null;
        document.getElementById("myspacetext").style.display = 'none';
    }
}
*/


function qsearch(oThis){
//  var savedvalue = oThis.value;
    if (oThis.value==oThis.title) oThis.value = "";
    oThis.onblur = function (){
        if (this.value=='')
            this.value = this.title;
    }
}


// popin + alpha background
function showAlphaPopin(){
    var comefromForm = (typeof thisIsAnAjaxForm!='undefined')? true : false;
    if (document.getElementById("mediacontent")) {
        document.getElementById("mediacontent").style.visibility = 'hidden';
    }
    var oTell = document.getElementById(alphapopin);
    var state = ((isIE)? oTell.currentStyle.display : getComputedStyle(oTell, null).display);
    if (state=='none') {
        oTell.style.display ="block";
    } else {
        oTell.style.display ="none";
        if (comefromForm) getAjaxAnswer.resetForm();
    }
}



function displayBg() {
   var myImgs = document.getElementsByTagName('img');
   for (img in myImgs) {
     if(myImgs[img].className == 'CS_productBG') {
       myImgs[img].parentNode.style.backgroundImage ='url('+myImgs[img].src+')';
       myImgs[img].parentNode.style.backgroundPosition = 'center center';
       myImgs[img].parentNode.style.backgroundPositionX = 'center';
       myImgs[img].parentNode.style.backgroundPositionY = 'center';
       myImgs[img].parentNode.style.backgroundRepeat    = 'no-repeat';
     }
   }
}




function initVisuals() {
  var myhrefList = getElementsByClassName("hoverMeForVisual");
  for(a in myhrefList) {
    img = myhrefList[a].getElementsByTagName('img');
    if(img.length) {
      myhrefList[a].onmouseover = function() {
        imgSrc = this.getElementsByTagName('img')[0].src;
        $("#visuelPubContainer").stop(true, true);
        document.getElementById("visuelPub").src = imgSrc;
        $("#visuelPubContainer").fadeIn("normal");

      }
      myhrefList[a].onmouseout = function() {
        $("#visuelPubContainer").fadeOut("normal");
      }
    }
  }
/*
  try {
      var mesBoites = getElementsByClassName("hoverMenu");
      var opacity = 50;
      for (a in mesBoites) {
          try {
              var tmpBoite = mesBoites[a];
              tmpBoite.style.backgroundColor = '#000';
              //jQuery(mesBoites[a]).opacity(0.5);
              tmpBoite.style.opacity = (opacity / 100);
              tmpBoite.style.MozOpacity = (opacity / 100);
              tmpBoite.style.KhtmlOpacity = (opacity / 100);
              tmpBoite.style.filter = "alpha(opacity=" + opacity + ")";
              //alert(mesBoites[a].style.filter);
          } catch (e) {
            //alert(e);
          }
      }
  } catch(e) {
    //
    //alert(e);
  }
  */
}




function hoverMenuOver(srcObj) {
    hoverMenuClear(srcObj);
    //alert(srcObj.id);
    var tarNum = srcObj.id.replace('submenuaxe', '');
    tarObj = '#smenu_' + tarNum;
    srcObj.style.color='#F5D479';
/*
    if(!isIE) { // FIREFOX, MOZ
      // auto positioning
      $(tarObj).css('top', (srcObj.parentNode.lastChild.offsetHeight));
      $(tarObj).slideDown('slow');

    } else { // MSIE
      // auto positioning
      subCont = document.getElementById('subnavmenuX');
      offsetTop = subCont.offsetTop + subCont.offsetHeight - 5; //); //+ (subCont.style.paddingTop*2);

      $(tarObj).css('left', subCont.offsetLeft + 'px');
      $(tarObj).css('top', offsetTop + 'px');
*/
      $(tarObj).fadeIn('fast');
/*
    }
*/
/*
      var w = $(tarObj)[0].offsetWidth;
      var h = $(tarObj)[0].offsetHeight;
      var myElem = $(tarObj)[0].childNodes[0];
      var opacity = 50;
      $(myElem).css({
         position       : 'absolute',
         background     : '#000',
         height         : h + 'px',
         width          : w + 'px',
         border         : '1px solid blue',
         opacity        : 0.5,
         top            : '0px', // $(tarObj)[0].offsetTop + 'px',
         left           : '0px', //$(tarObj)[0].offsetLeft + 'px'
         zIndex         : 1
      });
*/

}
function hoverMenuOut(srcObj, tarObj) {
    $(srcObj).css("color", '#fff');
    //$(tarObj).fadeOut('fast');
    //hoverMenuClear(srcObj);
    //$(tarObj).css("display", "none");
}
function hoverMenuClear(srcObj) {
    if(!isIE) {
      subElems = srcObj.parentNode.parentNode.getElementsByClassName("hoverMenu");
      for(elem in subElems) {
        if(subElems[elem].id!=undefined) {
          if(subElems[elem].style.display!='none') {
            //$(subElems[elem]).css("display", "none");
            $(subElems[elem]).fadeOut('fast');
            //$(subElems[elem]).slideUp('fast');
          }
        }
      }

    } else {
      $(".hoverMenu").css("display", "none");
    }
}


/*********************/
/* Alex's modifications */

function zoomin(url,titre) {
    //w = window.open(url,titre,'width=650,height=650,align=center,toolbar=no,scrollbars=no,resizable=yes');
    var hauteur=650;
    var largeur=650;
    var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;

    zoomed = open("",titre,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+",toolbar=no,scrollbars=no,resizable=no,location=no");
    zoomed.document.write("<script type='text/javascript' src=\"design/js/main.js\"></script>");
    zoomed.document.write("<TITLE>" + titre +"</TITLE><BODY>");
    zoomed.document.write("<a onclick=\"javascript:window.close()\" title=\"Close\" >" + "<IMG src=" + url +"  /></a></BODY>");
    zoomed.document.close();
    zoomed.focus();
}

var quantity = 0;

function getQuantity(obj)   {
  if (!isNaN(obj.value))  {
    quantity = obj.value;
  }
  else  {
    obj.value = 0;
  }
}

function buildingUrl(url, var_gencode, retailer_ref, var_quantity, var_product, back) {
  var destination = url + '?' + var_gencode + '=' + retailer_ref + '&' + var_quantity + '=' + quantity + '&' + var_product + '=' + back;
  if(quantity>5) {
    alert('You can`t order more than 5 products');
    //return false;
    }
  else if(quantity<1)  {
         alert('You can`t order less than 1 product');
         }
       else {
         document.location = destination;
            }
 }

var id_teint = 'null';

function getTeint(obj)  {
    if(obj.id != 'ml_') {
      document.getElementsByName("teint_0")[0].className = "woborder";
      if(id_teint != 'null')  {
        document.getElementById(id_teint).className = "woborder";
        document.getElementById(id_teint.substring(3,id_teint.length)).style.display="none";
      }
      else {
        document.getElementsByClassName('underlinksbuyoptionsline1')[0].style.display="none";
      }

      id_teint = obj.id;
      document.getElementById(id_teint).className = "wborder";
      document.getElementById(id_teint.substring(3,id_teint.length)).style.display="block";
      document.getElementById(id_teint.substring(3,id_teint.length)).className="underlinksbuyoptionsline1";
    }
}



function tellFriend(titre, ref, gencode)  {
  var hauteur=280;
  var largeur=420;
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;

  var tellafriend = window.open("../YSL Corner Project/tellafriend.php?url="+window.location.href, titre,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+",toolbar=no,scrollbars=no,resizable=no,location=no");
  tellafriend.document.close();
  tellafriend.focus();
}

/*
function expand(obj) {
  obj.a.img.className = 'imgover';
}

function reduce(obj) {
  obj.className = 'teinticon';
}
*/



function getOffsetTop (el) {
      var ot = el.offsetTop;
      while((el = el.offsetParent) != null)
          ot += el.offsetTop;
      return ot;
}




