var preUrl = '';
/* Date de création: 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';
    }
}
//|---------------------------| operations sur page, navmenu selection
var axeMenuOn = null;
var opWork = {

    free :function(){
        document.getElementById("innercontainer").style.visibility = 'visible';
        document.getElementById('subnavmenu').style.visibility = "visible";
    },
    select : function(num){
        try {
            var groupNav = document.getElementById("navmenu").getElementsByTagName("a");
            var reg = new RegExp(" on", "g");

            for(var i=0; i<groupNav.length; i++){
                var oldClassName  = groupNav[i].className;
                groupNav[i].className = oldClassName.replace(reg,"");
            }
            var oldClassName  = groupNav[num-1].className;
            groupNav[num-1].className = oldClassName+" on";
        } catch(e) {
          //
        }
    },
    show : function(who){
        axeMenuOn = who;
        document.getElementById(who).style.top = "0px";
    }
}

//|---------------------------| topmenu slider
function topMenuSlide(idDiv){
    var set = new Array;
    var topElements= document.getElementById(idDiv).getElementsByTagName('a');
    var subnavmenu  = document.getElementById("subnavmenu");
    var traildiv    = document.getElementById("trail");
    var trailDisplay = ((isIE)? traildiv.currentStyle.display : getComputedStyle(traildiv, null).display);
    var selectTags  = document.getElementsByTagName("select");

    //subnavmenu.style.zIndex="0";

    this.menu = function (i){
        this.timer = null;
        this.cleanOne = null;
        this.mouseOnIt = null;
        var subElmt = document.getElementById("submenuaxe"+(i+1));
        if (subElmt!=undefined) {
            var savedPos = parseFloat((isIE)? subElmt.currentStyle.top : getComputedStyle(subElmt, null).top);
            topElements[i].parentNode.onmouseover = function(){
                if (isIE) hideSelect();
                traildiv.style.display = 'none';
                subnavmenu.style.zIndex="1500";

                clearOthers(i,0);

                /*----------------DEROULEMENT DU MENU -------------------*/
                if (axeMenuOn!="submenuaxe"+(i+1)) {
                    set[i].mouseOnIt = 1;
                    getDown();
                    if (subElmt.id!=axeMenuOn){
                        subElmt.onmouseover = function(){
                            clearTimeout(set[i].cleanOne);
                            set[i].mouseOnIt = 1;
                        }
                        subElmt.onmouseout = function(){
                            set[i].mouseOnIt = null;
                            clearOne(i);
                        }
                    }
                }
                /*-------------------------------------------------------*/


            }
            topElements[i].parentNode.onmouseout = function(){
                set[i].mouseOnIt = null;
                clearOne(i);
            }
        }
        function clearOne(){
            clearTimeout(set[i].cleanOne);
            set[i].cleanOne  = setTimeout("clean("+i+")", 750);
            this.clean = function () {
                if (set[i].mouseOnIt==null) {
                    var subElmt2 = document.getElementById("submenuaxe"+(i+1));
                    getUp();
                }
            }
        }
        function clearOthers(a,call){
            for(var z=0;z<topElements.length;z++){
                if ((z!=a) && axeMenuOn!="submenuaxe"+(z+1)) {
                    var subElmt2 = document.getElementById("submenuaxe"+(z+1));
                    if (subElmt2!=undefined) {
                        clearInterval(set[z].timer);
                        subElmt2.style.top = "-409px";
                    }
                }
            }
        }
        function getDown(){
            clearInterval(set[i].timer);
            set[i].timer = setInterval( 'goindown()', 30);
            subElmt.style.zIndex = "1000";
            this.goindown = function(){
                var actualTop = parseFloat((isIE)? subElmt.currentStyle.top : getComputedStyle(subElmt, null).top);
                var dx =  (0 - actualTop);
                var doMath = Math.ceil(actualTop+(0.2*dx));
                if (actualTop<0) {
                    subElmt.style.top = doMath+"px";
                } else {
                    clearInterval(set[i].timer);
                    subElmt.style.zIndex = "1000";
                    subnavmenu.style.zIndex="105";
                }
            }
        }
        function getUp(){
            clearInterval(set[i].timer);
            set[i].timer = setInterval( 'goinUp()', 30);
            this.goinUp = function(){
                var actualTop = parseFloat((isIE)? subElmt.currentStyle.top : getComputedStyle(subElmt, null).top);
                var dx =  (savedPos - actualTop);
                var doMath = Math.floor(actualTop+(0.2*dx));
                if (actualTop>savedPos) {
                    subElmt.style.top = doMath+"px";
                } else {
                    checkForOpenMenu();
                    clearInterval(set[i].timer);
                }
            }
        }
        function hideSelect() {
        for (var i=0; i< selectTags.length; i++) {
                selectTags[i].style.visibility = 'hidden';
            }
        }
        function showSelect(){
            for (var i=0; i< selectTags.length; i++) {
                selectTags[i].style.visibility = '';
            }
        }

        function checkForOpenMenu(){
            var noZindexRetrun=0;
            for(var z=0;z<topElements.length;z++){
                var subElmt2 = document.getElementById("submenuaxe"+(z+1));
                if (subElmt2!=undefined) {
                    if ( (parseFloat(subElmt2.style.top)==0) || (set[z].mouseOnIt==1)) {
                        noZindexRetrun++;
                    }
                }
            }
            if ((noZindexRetrun==0)) {
                subnavmenu.style.zIndex="0";
                    traildiv.style.display = trailDisplay;
                    if (isIE) showSelect()
            }
        }
    }

    for (var i=0;i<topElements.length;i++) {
        set[i] = new this.menu(i);
    }

}

//|---------------------------| quick search
function qsearch(oThis){
//  var savedvalue = oThis.value;
    if (oThis.value==oThis.title) oThis.value = "";
    oThis.onblur = function (){
        if (this.value=='')
            this.value = this.title;
    }
}
//|---------------------------| menu slide
function menuSlide(idDiv){

    var subPanier = new Array();
    var panierHeight = new Array();
    var divPush = new Array();
    var divPushOffset = new Array();
    var saveOriginalPos;

    this.iObj = function (oThis, num){

        this.timer = null;
        function getPadding(elm){
            var padTop = parseFloat((isIE)? elm.currentStyle.paddingTop : getComputedStyle(elm, null).paddingTop);
            var padBot = parseFloat((isIE)? elm.currentStyle.paddingBottom : getComputedStyle(elm, null).paddingBottom);
            return(padTop+padBot);
        }
        this.glob =  oThis;
        this.obj = oThis.frm[num];
        this.subLevelA  = this.obj.getElementsByTagName("a");
        var subLevelALength = this.subLevelA.length;

        if (this.subLevelA.length > 1) {

            this.subLevelA[0].onclick = function(){

                this.removeAttribute('href');// suppression du href des <A>
                var classNameState = oThis.frm[num].className;

                if (classNameState == "on") {
//                  closeAllBlocs();
                } else {
                    var t=1;
                    closeAllBlocs();
                    openOneBlock( num);
                }
            }
        }
    }

    /******/
    function openOneBlock(num){
        var timeoutVarOpen;
        var sObj = subPanier[num].obj;
        sObj.className = "on";

        var thisClsName = sObj.className;
        var goingToHeight = panierHeight[num];

        sObj.style.overflow = "hidden";
        var actualPadding = parseFloat((isIE)? sObj.currentStyle.paddingTop : getComputedStyle(sObj, null).paddingTop);
        var actualBorder = parseFloat((isIE)? sObj.currentStyle.borderTopWidth : getComputedStyle(sObj, null).borderTopWidth);

        var pushDiv = subPanier[num].pushDiv;
        var oOffsetTop = parseFloat(sObj.offsetTop);

/*      var c = parseFloat(pushDiv.offsetTop);
        var b = goingToHeight;
        if (pushDiv.style.position != 'absolute'){//first shot
            pushDiv.style.position = 'absolute';
            saveOriginalPos = c;
        }
        pushDiv.style.top = saveOriginalPos + goingToHeight  +"px";*/

        sObj.parentNode.style.height ="100%";
        subPanier[num].timer = setInterval( 'slowOpen()', 30);

        this.slowOpen = function(){
            var actualHeight = parseFloat((isIE)? sObj.currentStyle.height : getComputedStyle(sObj, null).height);
            actualHeight = actualHeight+actualPadding+actualBorder;

            var dx =  (goingToHeight - actualHeight);
            var doMath = Math.ceil(actualHeight+(0.2*dx));
            if (actualHeight<goingToHeight) {
                sObj.style.height = doMath+"px";
            } else {
                clearInterval(subPanier[num].timer);
//              sObj.style.height = goingToHeight+"px";
                sObj.style.overflow = "";
                sObj.parentNode.style.height ="auto";
            }
        }
        slowOpen();
    }

    function closeAllBlocs(){

        for(var k=0;k<subPanier.length;k++) {

            var timeoutVarClose;
            var fb1 = subPanier[k].obj;

            if (fb1.className =='on'){

                var fixedVarK = k;
                var workon = fb1;
                workon.style.overflow = "hidden";
                workon.className = '';

                subPanier[fixedVarK].timer = setInterval( 'slowClose('+fixedVarK+')', 30);//slowClose(fixedVarK)
            }
        }

         this.slowClose = function(fxVarK) {
            var workon = subPanier[fxVarK].obj;
            var actualPadding = parseFloat((isIE)? workon.currentStyle.paddingTop : getComputedStyle(workon, null).paddingTop);
            var actualBorder = parseFloat((isIE)? 0 : getComputedStyle(workon, null).borderTopWidth);//pas de bordure pour IE

            var actualHeight = parseFloat((isIE)? workon.currentStyle.height : getComputedStyle(workon, null).height);
            var dx =  (minHeight - actualHeight);
            var doMath = Math.floor(actualHeight+(0.2*dx))-(actualPadding+actualBorder);

            if (actualHeight>minHeight) {

                workon.style.height = doMath+"px";
            } else {
                clearInterval(subPanier[fxVarK].timer);
            }
        }
    }
    /******/

    this.frm = document.getElementById(idDiv);

//  this.divs = this.frm.getElementsByTagName("div"); // recuperation des <div> push

    this.frm = this.frm.getElementsByTagName("li");

    this.NbLi = this.frm.length;// nombre de LI
    var minHeight = parseFloat((isIE)? this.frm[0].currentStyle.minHeight : getComputedStyle(this.frm[0], null).minHeight);

/*  for (var d=0;d<this.divs.length;d++) {//div push + offset top
        if (this.divs[d].className=='push'){
            divPush[this.divs[d].parentNode.id] = this.divs[d];
        }
    }*/

    for(var i=0; i<this.NbLi; i++) { // affectation des proprietes de l'objet aux LI
        subPanier[i] = new this.iObj(this, i);
        panierHeight[i] = this.frm[i].offsetHeight;//save each height

        // on ferme tout le monde// sauf ceux qu'on veut ouvert
        if (this.frm[i].className.indexOf("on")<0) {
            this.frm[i].className = "";
            this.frm[i].style.height = minHeight+"px";
        } else {
            this.frm[i].style.height = panierHeight[i]+"px";
        }
    }
}

// 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;
        document.getElementById("visuelPubContainer").style.display = 'block';
        document.getElementById("visuelPub").src = imgSrc;
      }
      myhrefList[a].onmouseout = function() {
        document.getElementById("visuelPubContainer").style.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';
}
*/


