////////Stop editting////////////////
TZRTABS = new Object();
TZRTABS.initialtab=[1, "sc1"]

function _cascadedstyle(el, cssproperty, csspropertyNS){
if (el.currentStyle)
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(csspropertyNS)
}
}
TZRTABS.enablepersistence=true;
TZRTABS.previoustab="";
TZRTABS.initTabColor="";
TZRTABS.initTabpostcolor="";
TZRTABS.optimalWidth = "";
TZRTABS.expandcontent = function (cid,aobject) {
  /* rr IE => save du general, qui est ok */
  if (TZRTABS.previoustab == "sc1" && TZRTABS.optimalWidth == ""){
    TZRTABS.optimalWidth = document.getElementById('tzr-tabcontentcontainer').offsetWidth;
  }/* fin */

  if (document.getElementById){
    TZRTABS.highlighttab(aobject)
    TZRTABS.detectSourceindex(aobject)
    if (TZRTABS.previoustab!="")
    document.getElementById(TZRTABS.previoustab).style.display="none"
    document.getElementById(cid).style.display="block"
    /* rr IE => force width */
    if (TZRTABS.optimalWidth && TZRTABS.optimalWidth != ""){
      document.getElementById(cid).style.width=TZRTABS.optimalWidth;
    }/* fin */
    
    TZRTABS.previoustab=cid
    if (aobject.blur){
      aobject.blur()
    }
    if (TZRTABS.enablepersistence){
      TZRTABS.setCookieTab(cid);
    }
    return false
  } else {
    return true;
  }
}
TZRTABS.collecttablinks = function (){
var tabobj=document.getElementById("tzr-tablist")
if (tabobj)
tabobjlinks=tabobj.getElementsByTagName("A")
else
tabobjlinks = new Array()
}

TZRTABS.highlighttab = function (aobject) {
if (typeof tabobjlinks=="undefined")
TZRTABS.collecttablinks()
for (i=0; i<tabobjlinks.length; i++){
tabobjlinks[i].style.backgroundColor=TZRTABS.initTabColor
//tabobjlinks[i].style.backgroundColor='red';
}
var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : TZRTABS.initTabpostcolor
//aobject.style.backgroundColor=document.getElementById("tzr-tabcontentcontainer").style.backgroundColor=themecolor
aobject.style.backgroundColor=themecolor
}

TZRTABS.detectSourceindex = function (aobject) {
for (i=0; i<tabobjlinks.length; i++){
if (aobject==tabobjlinks[i]){
tabsourceindex=i //source index of tab bar relative to other tabs
break
}
}
}
TZRTABS.init = function (){
  var cookiename=TZRTABS.cookieName();
  TZRTABS.collecttablinks()
  if (tabobjlinks.length > 0){// some page do not have tab
    TZRTABS.initTabpostcolor=_cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
    if(tabobjlinks[1]) {
      TZRTABS.initTabColor=_cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
    } else {
      TZRTABS.initTabColor=TZRTABS.initTabpostcolor;
    }
    var tabcontentid=TZRTABS.getCookieTab(cookiename);
    if (typeof TZRTABS.enablepersistence!="undefined" && TZRTABS.enablepersistence && tabcontentid != ''){
      var tab = document.getElementById('tab'+tabcontentid);
      if (tab != null){
	TZRTABS.expandcontent(tabcontentid, tab);
      }else {
	TZRTABS.expandcontent(TZRTABS.initialtab[1], tabobjlinks[TZRTABS.initialtab[0]-1]);
      }
    }else{
      TZRTABS.expandcontent(TZRTABS.initialtab[1], tabobjlinks[TZRTABS.initialtab[0]-1]);
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", TZRTABS.init, false)
else if (window.attachEvent)
window.attachEvent("onload", TZRTABS.init)
else if (document.getElementById)
window.onload=TZRTABS.init;
     
TZRTABS.cookieName = function(){
return  'tzrtab'+TZRTABS.moid;
}
TZRTABS.setCookieTab = function(cid){
  if (typeof TZRTABS.moid != 'undefined' && TZRTABS.moid != ''){
    document.cookie = TZRTABS.cookieName() + '=' + cid; //+';expires='+fin;
  }
}
TZRTABS.getCookieTab = function(){
  var cookie_name = TZRTABS.cookieName();
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results )
    return ( unescape ( results[1] ) );
  else
    return '';
}
TZRTABS.resetCookieTab = function(moid){
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = 'tzrtab' + moid + "=; expires=" + cookie_date.toGMTString();
}
TZRTABS.ajaxPopulate = function(cid,url){
  ret=TZR.file_get_contents(url);
  Element.update(document.getElementById(cid),ret);
}
