
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// fr2009.js
// Javascript functions for Farylrobin website 2009
//
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//============================================================================//
//                             Slideshow                                      //
//============================================================================//
var delayBg = 10000;
var timeoutBg;
var preLoad = new Array();

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function initSlideShowBg
// Object : Preload images for background slideshow and start slideshow
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initSlideShowBg(arrBg) {
  if (arrBg.length>0) {
    for(var i=0; i<arrBg.length; i++) {
      preLoad[i] = new Image();
      preLoad[i].src = arrBg[i];
    }
    runSlideShowBg(arrBg.length-1,-1);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function runSlideShowBg
// Object : Process slideshow
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function runSlideShowBg(nbImg,cId){
  var id;
  var cpt=0;
  var idOK=0;
  while((cpt<=10)&&(idOK==0)) {
    cpt++;
    id = Math.round(nbImg*Math.random());
    if (id!=cId) idOK=1;
  }
  if (idOK==1 && document.getElementById("bgimg")) document.getElementById("bgimg").src = preLoad[id].src;
  timeoutBg = setTimeout('runSlideShowBg('+nbImg+','+id+')',delayBg);
}

//============================================================================//
//                             Inactivity                                     //
//============================================================================//
var idContentUserActive=-1;
var timeoutUserActive;
var userActive = 1;
var delayUserActive = 45000;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setUserActive
// Object : User is active
//          - initialyse timer
//          - restore context if needed
//          - start timer for setUserInactive()

// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setUserActive(lcode) {
  clearTimeout(timeoutUserActive);
  if (userActive==0) {
    userActive = 1;
    if (menuVisible==1) {
      clearTimeout(timeoutMenu);
      clearTimeout(timeoutContent);
      showMenu(idContentUserActive,lcode);
    }
  }
  timeoutUserActive = setTimeout('setUserInactive(\''+lcode+'\')',delayUserActive);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setUserActive
// Object : User is inactive, if needed :
//          - save context
//          - close Menu & content
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setUserInactive(lcode) {
  if (userActive==1) {
    userActive = 0;
    idContentUserActive = idContent;
    clearTimeout(timeoutMenu);
    clearTimeout(timeoutContent);
    hideMenu(lcode);
  }
}

//============================================================================//
//                             Layout                                         //
//============================================================================//
var w,h,y;
var imgRatio = 0.75;

var buttonWidth = 40;
var buttonHeight = 40;
var logoWidth = 125;
var marginMenu = 5;
var contentWidth = 800;
var contentTopHeight = 160;
var contentBottomHeight = 320;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setLayout
// Object : Set layout, compute divs size & position
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setLayout() {

  if (self.innerHeight) { // all except Explorer
    w = self.innerWidth;
    h = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  }
  else if (document.body) { // other Explorers
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }

  if (w>0 && h>0) {
    cRatio = h/w;

    if (cRatio>=imgRatio) {
      imgHeight = h;
      if (h<contentTopHeight+contentBottomHeight+buttonHeight+(marginMenu*2)) imgHeight = contentTopHeight+contentBottomHeight+buttonHeight+(marginMenu*2);
      imgWidth = Math.round(imgHeight/imgRatio);
    }
    else {
      imgWidth = w;
      if (imgWidth<contentWidth+buttonWidth) imgWidth = contentWidth+buttonWidth;
      imgHeight = Math.round(imgRatio*imgWidth);
    }

    x=0;
    if (w<(contentWidth+buttonWidth)) {
        w = contentWidth+buttonWidth;
        x=0
    }

    if (h<=(contentTopHeight+contentBottomHeight+buttonHeight+(marginMenu*2))) {
        h = contentTopHeight+contentBottomHeight+buttonHeight+(marginMenu*2);
        y = 0;
    }
    else
        y = Math.round((h-(contentTopHeight+contentBottomHeight+buttonHeight+(marginMenu*2)))/2);

    document.getElementById('main').style.top = '0px';
    document.getElementById('main').style.left = '0px';
    document.getElementById('main').style.width = w+'px';
    document.getElementById('main').style.height = h+'px';
    if (document.getElementById('imagec')) {
      document.getElementById('imagec').style.top = '0px';
      document.getElementById('imagec').style.left = '0px';
      document.getElementById('imagec').style.width = w+'px';
      document.getElementById('imagec').style.height = h+'px';
    }

    if (document.getElementById('content')) {
      document.getElementById('content').style.top = y+'px';
      document.getElementById('content').style.left = x+'px';
    }

    if (document.getElementById('menubutton'))
      document.getElementById('menubutton').style.top = (contentTopHeight+marginMenu+y)+'px';

    if (document.getElementById('menu')) {
      document.getElementById('menu').style.top = (contentTopHeight+marginMenu+y)+'px';
      if (menuVisible==1) {
        document.getElementById('menu').style.width = (w-buttonWidth)+'px';
        document.getElementById('menutail').style.left = (w-buttonWidth-logoWidth)+'px';
        document.getElementById('menucontent').style.width = (w-buttonWidth-logoWidth)+'px';
      }
    }

    if (document.getElementById('bgimg')) {
      document.getElementById('bgimg').width = imgWidth;
      document.getElementById('bgimg').height = imgHeight;
    }

    if (document.getElementById('image')) {
      //if (imgWidth==w && imgHeight>h) {
      if (imgWidth==w) {
        document.getElementById('image').style.left = '0px';
        document.getElementById('image').style.top = -Math.abs(Math.round((h-imgHeight)/2))+'px';
      }
      //else if (imgWidth>w && imgHeight==h) {
      else if (imgHeight==h) {
        document.getElementById('image').style.top = '0px';
        document.getElementById('image').style.left = -Math.abs(Math.round((w-imgWidth)/2))+'px';
      }
    }

    document.getElementById('footer').style.top = (h-document.getElementById('footer').offsetHeight)+'px';
    document.getElementById('footer').style.left = '0px';
    document.getElementById('footer').style.width = w+'px';
    document.getElementById('footer').style.visibility = 'visible';
  }
}

//============================================================================//
//                             On load                                        //
//============================================================================//
var delayMenuOnLoad = 3000;
var delayMenuContentOnLoad = 1000;
var setScroll = 0;

function frOnLoad(id,lcode) {
  idContent = id;

  var arrBg = new Array();
  for(var i=2; i<arguments.length; i++) {
    arrBg[i-2] = arguments[i];
  }
  initSlideShowBg(arrBg);

  if (document.getElementById('content')) {
    document.getElementById('content').style.width = (buttonWidth+contentWidth)+'px';
    document.getElementById('content').style.height = (buttonHeight+(contentTopHeight+contentBottomHeight)+(marginMenu*2))+'px';

//    document.getElementById('topcontentc').style.left = buttonWidth+'px';
//    document.getElementById('topcontentc').style.width = contentWidth+'px';
    document.getElementById('topcontentc').style.height = contentTopHeight+'px';

    document.getElementById('topcontent').style.top = contentTopHeight+'px';
//    document.getElementById('topcontent').style.width = contentWidth+'px';

//    document.getElementById('bottomcontentc').style.left = buttonWidth+'px';
    document.getElementById('bottomcontentc').style.top = (contentTopHeight+buttonHeight+(marginMenu*2)) +'px';
//    document.getElementById('bottomcontentc').style.width = contentWidth+'px';
    document.getElementById('bottomcontentc').style.height = contentBottomHeight+'px';

//    document.getElementById('bottomcontent').style.width = contentWidth+'px';

    document.getElementById('menubutton').style.width = buttonWidth+'px';
    document.getElementById('menubutton').style.height = buttonHeight+'px';

    document.getElementById('menu').style.left = buttonWidth+'px';
    document.getElementById('menu').style.height = buttonHeight+'px';

    document.getElementById('menucontent').style.height = buttonHeight+'px';

    document.getElementById('menutail').style.width = logoWidth+'px';
    document.getElementById('menutail').style.height = buttonHeight+'px';
  }

  setLayout();

  if (id>=0)
    timeoutMenu = setTimeout('showMenuOnLoad('+id+',\''+lcode+'\')',delayMenuContentOnLoad);
  else
    timeoutMenu = setTimeout('showMenuOnLoad('+id+',\''+lcode+'\')',delayMenuOnLoad);
}

//============================================================================//
//                             Menu                                           //
//============================================================================//
var menuVisible = 0;
var timeoutMenu;
var delayMenu = 5;
var stepMenu = 10;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function showMenuOnLoad
// Object : Show menu
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showMenuOnLoad(id,lcode) {
  if (menuVisible==0) {
    menuVisible = 1;
    showMenu(id,lcode);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setMenu
// Object : Initialyse timer, show/hide menu
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setMenu(id,lcode) {
  clearTimeout(timeoutMenu);
  if (menuVisible==1) {
    idContent = -1;
    contentVisible = 0;
    menuVisible = 0;
    hideMenu(lcode);
  }
  else {
    menuVisible = 1;
    showMenu(id,lcode);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function showMenu
// Object : Compute and show all menu divs : tail & content
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showMenu(id,lcode) {
  if (document.getElementById('menu')) {
    cWidth = document.getElementById('menu').offsetWidth;
    newWidth = cWidth+stepMenu;

    if (newWidth>=w-40) {
      document.getElementById('menu').style.width = (w-40)+'px';
      document.getElementById('menutail').style.left = (w-40-125)+'px';
      document.getElementById('menucontent').style.width = (w-40-125)+'px';
      if (id>=0) showContent(id,lcode);
    }
    else {
      document.getElementById('menu').style.width = newWidth+'px';
      if (newWidth-125<0)
        document.getElementById('menucontent').style.width = '0px';
      else
        document.getElementById('menucontent').style.width = (newWidth-125)+'px';
      document.getElementById('menutail').style.left = (newWidth-125)+'px';
      timeoutMenu = setTimeout('showMenu('+id+',\''+lcode+'\')',delayMenu);
    }
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function hideMenu
// Object : Hide Content & menu
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function hideMenu(lcode) {
  clearTimeout(timeoutContent);
  hideContent(-1,lcode);
  hideMenuSlide(lcode);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function hideMenuSlide
// Object : Compute and hide all menu divs : tail & content
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function hideMenuSlide(lcode) {
  if (document.getElementById('menu')) {
    cWidth = document.getElementById('menu').offsetWidth;
    newWidth = cWidth-stepMenu;

    if (newWidth<0) {
      newWidth=0;
      document.getElementById('menu').style.width = newWidth+'px';
      document.getElementById('menutail').style.left = (newWidth-125)+'px';
      document.getElementById('menucontent').style.width = '0px';
    }
    else {
      document.getElementById('menu').style.width = newWidth+'px';
      document.getElementById('menutail').style.left = (newWidth-125)+'px';
      if (newWidth-125<0)
        document.getElementById('menucontent').style.width = '0px';
      else
        document.getElementById('menucontent').style.width = (newWidth-125)+'px';
      timeoutMenu = setTimeout('hideMenuSlide(\''+lcode+'\')',delayMenu);
    }
  }
}

//============================================================================//
//                            content                                         //
//============================================================================//
var idContent = -1 ;
var contentVisible = 0;
var contentOpening = 0;
var contentClosing = 0;
var timeoutContent;
var delayContent = 15;
var stepContent = 10;
var pauseContent = 300;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setContent
// Object : Initialyse timer, show/hide content
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setContent(id,lcode) {
  clearTimeout(timeoutContent);
  setScroll=1;
  if (contentVisible==1 || contentOpening==1) {
    if (id!=idContent) {
      // content visible or being opened -> closing content, and re-opening with new content (id)
      hideContent(id,lcode);
    }
    else
      hideContent(0,lcode);
  }
  else {
    // content hidden, showing required content (id)
    showContent(id,lcode);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function showContent
// Object : Update content & display by calling showContentSlide
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showContent(id,lcode) {
  clearTimeout(timeoutContent);
  contentClosing = 0;
  contentOpening = 1;
  contentVisible = 0;

  if (id!=idContent) {
    idContent = id;
    if (id>0) {
      // update content
      fbGetUrlDiv('themenu','default.php?fct=mc&p='+id,'');
      fbGetUrlDiv('bottomcontent','default.php?fct=bc&p='+id,'');
      fbGetUrlDiv('topcontent','default.php?fct=tc&p='+id,'');
    }
    else
      showContentSlide();
  }
  else
    showContentSlide();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function showContentSlide
// Object : Slide top & bottom content divs
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showContentSlide() {
  if (document.getElementById('bottomcontent') && document.getElementById('topcontent')) {
    cTopStr = document.getElementById('topcontent').style.top;
    var reg = new RegExp("(px)", "g");
    cTop = parseInt(cTopStr.replace(reg,""));
    newTop = cTop-stepContent;
    cHeight = document.getElementById('bottomcontent').offsetHeight;
    newHeight = cHeight+(stepContent*2);

    if (newTop<0) newTop = 0;
    if (newHeight>contentBottomHeight) newHeight = contentBottomHeight;

    document.getElementById('topcontent').style.height = (contentTopHeight-newTop)+'px';
    document.getElementById('topcontent').style.top = newTop+'px';
    document.getElementById('bottomcontent').style.height = newHeight+'px';

    if (newTop>0 || newHeight<contentBottomHeight)
      timeoutContent = setTimeout('showContentSlide()',delayContent);
    else {
      contentOpening = 0;
      contentVisible = 1;

      if (setScroll==1) {
        if (document.getElementById('cb')) Scroller.reset('cb');
        if (document.getElementById('cbl')) Scroller.reset('cbl');
        if (document.getElementById('cbr')) Scroller.reset('cbr');
        if (document.getElementById('ct')) Scroller.reset('ct');
        if (document.getElementById('ctl')) Scroller.reset('ctl');
        if (document.getElementById('ctr')) Scroller.reset('ctr');
        if (document.getElementById('storeonline')) Scroller.reset('storeonline');
        if (document.getElementById('storeinstoreslist')) Scroller.reset('storeinstoreslist');
        if (document.getElementById('pressnavigation')) Scroller.reset('pressnavigation');
        if (document.getElementById('nesttext')) Scroller.reset('nesttext');
      }
      else
        setScroll=1;
    }
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function hideContent
// Object : Update content & hidding content divs by calling hideContentSlide
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function hideContent(id,lcode) {
  clearTimeout(timeoutContent);
  idContent = -1;
  contentClosing = 1;
  contentOpening = 0;
  contentVisible = 0;
  // update content
  //document.getElementById('topcontent').innerHTML = '';
  //document.getElementById('bottomcontent').innerHTML = '';
  hideContentSlide(id,lcode);
  fbGetUrlDiv('themenu','default.php?fct=mc','');
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function hideContentSlide
// Object : Slide/hide content divs to. If needed : start timer to display new content
// FASTBOIL                     1.0         12/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function hideContentSlide(id,lcode) {
  if (document.getElementById('bottomcontent') && document.getElementById('topcontent')) {
    cTopStr = document.getElementById('topcontent').style.top;
    var reg = new RegExp("(px)", "g");
    cTop = parseInt(cTopStr.replace(reg,""));
    newTop = cTop+stepContent;
    cHeight = document.getElementById('bottomcontent').offsetHeight;

    newHeight = cHeight-(stepContent*2);
    // To be modified.....

    if (newTop>contentTopHeight) newTop = contentTopHeight;
    if (newHeight<0) newHeight = 0;

    document.getElementById('topcontent').style.top = newTop+'px';
    document.getElementById('topcontent').style.height = (contentTopHeight-newTop)+'px';
    document.getElementById('bottomcontent').style.height = newHeight+'px';

    if (newTop<contentTopHeight || newHeight>0)
      timeoutContent = setTimeout('hideContentSlide('+id+',\''+lcode+'\')',delayContent);
    else {
      contentClosing = 0;
      contentVisible = 0;
      if (id>0) timeoutContent = setTimeout('showContent('+id+',\''+lcode+'\')', pauseContent);
    }
  }
}

//============================================================================//
//                            Ajax                                            //
//============================================================================//
function fbGetUrlDiv(id,url,innerhtml) {
  if (document.getElementById(id)) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById(id);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDiv(xRequest,anId) {
    if (xRequest.readyState==4) {
        document.getElementById(anId).innerHTML=xRequest.responseText;
        if (anId=='admcontent') {
          setTimeout('Scroller.reset(\''+anId+'\')',300);
        }
        else if (anId=='topcontent') {
          showContentSlide();
        }
        else if (anId=='storeinstoreslist') {
          Scroller.reset('storeinstoreslist');
        }
    }
}

function fbShowWaiting(obj,innerhtml) {
    obj.innerHTML=innerhtml;
}

function getXmlHttpRequest() {
    if (window.XMLHttpRequest) // Firefox
    {
       return(new XMLHttpRequest());
    }
    else if (window.ActiveXObject) // Internet Explorer
    {
        try
        {
            return(new ActiveXObject("Msxml2.XMLHTTP"));
        } 
        catch (e)
        {
            try
            {
                return(new ActiveXObject("Microsoft.XMLHTTP"));
            }
            catch (e)
            {
                alert("Your browser does not support XMLHTTPRequest...");
            }
        }
    }
    else
    { // XMLHttpRequest non supporté par le navigateur
       alert("Your browser does not support XMLHTTPRequest...");
    }
}

function fbSendAjaxFormTargetDiv(idForm,baseurl,targetId,innerhtml) {
    var xReq=getXmlHttpRequest();
    var i;
    var url="";
    var myForm=document.getElementById(idForm);

    if (myForm) {
        var first=true;
        for(i=0;i<myForm.elements.length;i++) {
            var elmt=myForm.elements[i];
            var type=elmt.nodeName.toLowerCase();
            var ok=true;

            if (type=="input") {
                switch (elmt.type.toLowerCase()) {
                case "radio":
                case "checkbox":
                    if (!elmt.checked) ok=false;
                    break;

                case "submit":
                    break;
                case "image":
                    ok=false;
                    break;
                }
            }
            else if ((type!="select") && (type!="textarea")) ok=false;
            if (ok) {
                if (first) first=false;
                else url+="&";
                url+=elmt.name+"="+elmt.value.replace(/%/g,"%25").replace(/&/g,"%26").replace(/=/g,"%3D").replace(/ /g,"%20");
            }
        }
    }

    var obj=document.getElementById(targetId);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);

    xReq.open("POST",baseurl,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,targetId);};
    xReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
    xReq.send(url);
}

function fbSendAjaxFormAdmin(idForm,baseurl,targetId,innerhtml,menuurl) {
    var xReq=getXmlHttpRequest();
    var i;
    var url="";
    var myForm=document.getElementById(idForm);

    if (myForm) {
        var first=true;
        for(i=0;i<myForm.elements.length;i++) {
            var elmt=myForm.elements[i];
            var type=elmt.nodeName.toLowerCase();
            var ok=true;

            if (type=="input") {
                switch (elmt.type.toLowerCase()) {
                case "radio":
                case "checkbox":
                    if (!elmt.checked) ok=false;
                    break;

                case "submit":
                    break;
                case "image":
                    ok=false;
                    break;
                }
            }
            else if ((type!="select") && (type!="textarea")) ok=false;
            if (ok) {
                if (first) first=false;
                else url+="&";
                url+=elmt.name+"="+elmt.value.replace(/%/g,"%25").replace(/&/g,"%26").replace(/=/g,"%3D").replace(/ /g,"%20");
            }
        }
    }

    var obj=document.getElementById(targetId);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);

    xReq.open("POST",baseurl,true);
    xReq.onreadystatechange=function(){fbEventGetFormAdmin(xReq,targetId,menuurl);};
    xReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
    xReq.send(url);
}

function fbEventGetFormAdmin(xRequest,anId,menuurl) {
    if (xRequest.readyState==4) {
        document.getElementById(anId).innerHTML=xRequest.responseText;
        fbGetUrlDiv('admsubmenu',menuurl,'')
    }
}






function frLogin(checkurl,redirecturl,innerhtml) {
    var xReq=getXmlHttpRequest();
    var i;
    var url="";
    var myForm=document.getElementById("frmLogin");
    if (myForm) {
        var first=true;
        for(i=0;i<myForm.elements.length;i++) {
            var elmt=myForm.elements[i];
            if (first) first=false; else url+="&";
            url+=elmt.name+"="+elmt.value.replace(/%/g,"%25").replace(/&/g,"%26").replace(/=/g,"%3D").replace(/ /g,"%20");
        }
    }
    var obj=document.getElementById('cbr');
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("POST",checkurl,true);
    xReq.onreadystatechange=function(){frLoginEvent(xReq,redirecturl);};
    xReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
    xReq.send(url);
}

function frLoginEvent(xRequest,redirecturl) {
    if (xRequest.readyState==4) {
        if (xRequest.responseText=="ok")
          fbGetUrlDiv('main',redirecturl,'');
        else
          document.getElementById('cbr').innerHTML=xRequest.responseText;
    }
}

function frAdmMenu(contenturl,submenuurl,menuurl) {
  if (arguments.length>0) contenturl = arguments[0]; else contenturl = "";
  if (arguments.length>1) submenuurl = arguments[1]; else submenuurl = "";
  if (arguments.length>2) menuurl = arguments[2]; else menuurl = "";
  if (menuurl!="") fbGetUrlDiv('admmenu',menuurl,'');
  if (submenuurl!="") fbGetUrlDiv('admsubmenu',submenuurl,'');
  if (contenturl!="") fbGetUrlDiv('admcontent',contenturl,'');
}



function startUpload(){
  document.getElementById('loading').style.visibility = 'visible';
  return true;
}

function stopUpload(msgStr,url){
  if (msgStr=='')
     fbGetUrlDiv('admcontent',url,'');
  else
     document.getElementById('result').innerHTML = msgStr;
  document.getElementById('loading').style.visibility = 'hidden';
  return true;   
}

function setSizeRun(myform,lCode) {
//  alert("ok");
//  alert(document.forms[myform].elements['ESR_'+lCode].value);
  document.forms[myform].elements['ST_SIZE_RUN_'+lCode].value = document.forms[myform].elements['ESR_'+lCode].value
}

function numbersonly(e) {
  var unicode=e.charCode? e.charCode : e.keyCode;
  if (unicode!=8 && unicode!=46){ //if the key isn’t the backspace key (which we should allow)
    if (unicode<48||unicode>57) { //if not a number
      return false //disable key press
    }
  }
}

function hidediv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
      if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layer[myId].visibility = 'hidden';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'hidden';
        }
    }
}

function showdiv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layers[myId].visibility = 'visible';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'visible';
        }
    }
}

function showStyle(url) {
  if (document.getElementById('collectionstyle')) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('collectionstyle');
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){eventShowStyle(xReq);};
    xReq.send(null);
  }
}

function eventShowStyle(xRequest) {
    if (xRequest.readyState==4) {
        if (xRequest.responseText!='') {
            hidediv('collectionresume');
            document.getElementById('collectionstyle').innerHTML=xRequest.responseText;
            showdiv('collectionstyle');
            clearTimeout(timeoutSlideImage);
            timeoutSlideImage = setTimeout('eventShowStyleSlideImage()',100);
        }
    }
}

var delaySlideImage = 10;
var stepSlideImage = 10;
var timeoutSlideImage;
function eventShowStyleSlideImage() {
  if (document.getElementById('collectionstyleimage')) {
    cWidth = document.getElementById('collectionstyleimage').offsetWidth;
    newWidth = cWidth+stepSlideImage;

    if (newWidth>280) {
      newWidth=280;
      document.getElementById('collectionstyleimage').style.width = newWidth+'px';
      document.getElementById('collectionstyleimage').style.height = newWidth+'px';
      document.getElementById('collectionstyleimage').style.left = '-1px';
      document.getElementById('collectionstyleimage').style.top = '-1px';
      document.getElementById('collectionstyleimagecontent').style.top = '0px';
      document.getElementById('collectionstyleimagecontent').style.left = '0px';
    }
    else {
      document.getElementById('collectionstyleimage').style.width = newWidth+'px';
      document.getElementById('collectionstyleimage').style.height = newWidth+'px';
      document.getElementById('collectionstyleimage').style.left = (Math.round((280-newWidth)/2)-1)+'px';
      document.getElementById('collectionstyleimage').style.top = (Math.round((280-newWidth)/2)-1)+'px';
      document.getElementById('collectionstyleimagecontent').style.top = '-'+Math.round((280-newWidth)/2)+'px';
      document.getElementById('collectionstyleimagecontent').style.left = '-'+Math.round((280-newWidth)/2)+'px';
      timeoutSlideImage = setTimeout('eventShowStyleSlideImage()',delaySlideImage);
    }
  }
}

function showPress(url) {
  if (document.getElementById('press')) {
   var xReq=getXmlHttpRequest();
    var obj=document.getElementById('press');
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){eventShowPress(xReq);};
    xReq.send(null);
  }
}

function eventShowPress(xRequest) {
    if (xRequest.readyState==4) {
        if (xRequest.responseText!='') {
            document.getElementById('press').innerHTML=xRequest.responseText;
            clearTimeout(timeoutSlideImage);
            timeoutSlideImage = setTimeout('eventShowPressSlideImage()',100);
        }
    }
}

function eventShowPressSlideImage() {
  if (document.getElementById('pressimage')) {
    cWidth = document.getElementById('pressimage').offsetWidth;
    newWidth = cWidth+stepSlideImage;

    if (newWidth>280) {
      newWidth=280;
      document.getElementById('pressimage').style.width = newWidth+'px';
      document.getElementById('pressimage').style.height = newWidth+'px';
      document.getElementById('pressimage').style.left = '-1px';
      document.getElementById('pressimage').style.top = '-1px';
      document.getElementById('pressimagecontent').style.top = '0px';
      document.getElementById('pressimagecontent').style.left = '0px';
    }
    else {
      document.getElementById('pressimage').style.width = newWidth+'px';
      document.getElementById('pressimage').style.height = newWidth+'px';
      document.getElementById('pressimage').style.left = (Math.round((280-newWidth)/2)-1)+'px';
      document.getElementById('pressimage').style.top = (Math.round((280-newWidth)/2)-1)+'px';
      document.getElementById('pressimagecontent').style.top = '-'+Math.round((280-newWidth)/2)+'px';
      document.getElementById('pressimagecontent').style.left = '-'+Math.round((280-newWidth)/2)+'px';
      timeoutSlideImage = setTimeout('eventShowPressSlideImage()',delaySlideImage);
    }
  }
}

function showStyleResume() {
    hidediv('collectionstyle');
    showdiv('collectionresume');
}

function showColor(urlimg,urlempty,urlstaf) {
  document.getElementById('imgStyle').src = urlempty;
  document.getElementById('collectionstyleimage').style.width = '0px';
  document.getElementById('collectionstyleimage').style.height = '0px';
  document.getElementById('imgStyle').src = urlimg;
  document.getElementById('linkstaf').href = urlstaf;
  eventShowStyleSlideImage();
}

function showSendToAFriend(url) {
  if (document.getElementById('collectionstyle')) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('collectionstyle');
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){eventShowSendToAFriend(xReq);};
    xReq.send(null);
  }
}

var timeoutSlideSTAF;
var stepSlideSTAF = 10;
var delaySlideSTAF = 10;
function eventShowSendToAFriend(xRequest) {
    if (xRequest.readyState==4) {
        if (xRequest.responseText!='') {
            document.getElementById('collectionstyle').style.width = '0px';
            document.getElementById('collectionstyle').innerHTML=xRequest.responseText;
            clearTimeout(timeoutSlideSTAF);
            timeoutSlideSTAF = setTimeout('eventShowSendToAFriendSlide()',delaySlideImage);

        }
    }
}

function eventShowSendToAFriendSlide() {
  if (document.getElementById('collectionstyle')) {
    cWidth = document.getElementById('collectionstyle').offsetWidth;
    newWidth = cWidth+stepSlideImage;

    if (newWidth>620) {
      newWidth=620;
      document.getElementById('collectionstyle').style.width = newWidth+'px';
    }
    else {
      document.getElementById('collectionstyle').style.width = newWidth+'px';
      timeoutSlideSTAF = setTimeout('eventShowSendToAFriendSlide()',delaySlideSTAF);
    }
  }
}

function setStoreList(ids,url) {
  fbGetUrlDiv('storeinstoreslist',url+ids,'');
}

function setDirectory(id) {
  cn = document.getElementById("directory").childNodes;
  for (var i = 0; i < cn.length; i++){
    if (cn[i].nodeName == 'DIV'){
      iddiv = cn[i].id;
      if ((iddiv.substring(0,7)=='dircont') && (iddiv!='dircont'+id)) {
          //alert('hide '+iddiv);
          //cHeight = document.getElementById(iddiv).offsetHeight;
          //if (cHeight> 0)
          hideDirectory(iddiv);
      }
    }
  }
  //alert('show '+'dircont'+id);
  showDirectory('dircont'+id,'dirtext'+id);
}



var timeoutSlideDirectory;
var stepSlideDirectory = 5;
var delaySlideDirectory = 10;

function hideDirectory(iddiv) {
  if (document.getElementById(iddiv)) {
    cHeight = document.getElementById(iddiv).offsetHeight;
    newHeight = cHeight-stepSlideDirectory;

    if (newHeight<0) {
      document.getElementById(iddiv).style.height = '0px';
    }
    else {
      document.getElementById(iddiv).style.height = newHeight+'px';
      timeoutSlideDirectory = setTimeout('hideDirectory(\''+iddiv+'\')',delaySlideDirectory);
    }
  }
}

function showDirectory(iddiv,iddivtext) {
  if (document.getElementById(iddiv) && document.getElementById(iddivtext)) {
    cHeight = document.getElementById(iddiv).offsetHeight;
    newHeight = cHeight+stepSlideDirectory;

    if (newHeight>document.getElementById(iddivtext).offsetHeight) {
      document.getElementById(iddiv).style.height = document.getElementById(iddivtext).offsetHeight+'px';
    }
    else {
      document.getElementById(iddiv).style.height = newHeight+'px';
      timeoutSlideDirectory = setTimeout('showDirectory(\''+iddiv+'\',\''+iddivtext+'\')',delaySlideDirectory);
    }
  }
}

function showNest(url) {
  if (document.getElementById('nestcontent')) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('nestcontent');
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){eventShowNest(xReq);};
    xReq.send(null);
  }
}

var timeoutSlideNest;
var stepSlideNest = 10;
var delaySlideNest = 10;
function eventShowNest(xRequest) {
    if (xRequest.readyState==4) {
        if (xRequest.responseText!='') {
            document.getElementById('nestcontent').style.width = '0px';
            document.getElementById('nestcontent').innerHTML=xRequest.responseText;
            if (document.getElementById('nesttext')) Scroller.reset('nesttext');
            clearTimeout(timeoutSlideNest);
            timeoutSlideNest = setTimeout('eventShowNestSlide()',100);
        }
    }
}

function eventShowNestSlide() {
  if (document.getElementById('nestcontent')) {
    cWidth = document.getElementById('nestcontent').offsetWidth;
    newWidth = cWidth+stepSlideImage;

    if (newWidth>470) {
      newWidth=470;
      document.getElementById('nestcontent').style.width = newWidth+'px';
    }
    else {
      document.getElementById('nestcontent').style.width = newWidth+'px';
      timeoutSlideNest = setTimeout('eventShowNestSlide()',delaySlideNest);
    }
  }
}

function doMySpace(T, C, U, L) {
var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&'+'t='+encodeURIComponent(T)+'&c='+encodeURIComponent(C)+'&u='+encodeURIComponent(U)+'&l='+L;
window.open(targetUrl);
}

