/*
created by ilya lebedev (ilya@lebedev.net)
Modified by Victor Fokin (vfokin@voltweb.com)

!!! requires DOMextensions.js !!!
*/
window.onerror = null;
var active_reports="";

function tab_menu(block_pfx, img_pfx, c_name)
{
	this.block_pfx=block_pfx;
	this.img_pfx=img_pfx;
	this.c_name=c_name;
}

tab_menu.prototype.block_pfx    = "div_";   // tab block prefix, suffix will be set equal to corresponding image sfx
tab_menu.prototype.blocks       = {};          // blocks collection
tab_menu.prototype.img_pfx      = "tab_";   // image associated with block prefix
tab_menu.prototype.last         = "";             // link to the last shown page
tab_menu.prototype.last_src     = ""; 		   // last tab defult image src
tab_menu.prototype.last_rollsrc = "";		   // last tab rollover image src
tab_menu.prototype.cookie       = "";
tab_menu.prototype.c_name       = "tabmenu";
  
tab_menu.prototype.c=function (e) 
{
    var el = window.event ? window.event.srcElement : e.currentTarget;
	if (this.last == el.id) return;
	last = document.getElementById(this.last);
    last.stopOut = false;
	last.defsrc=this.last_src;
	last.rollsrc=this.last_rollsrc;
    last.fireEvent('onmouseout');
    el.stopOut = true;
	this.last_src=el.defsrc;
	this.last_rollsrc=el.rollsrc; 
	el.src=el.actsrc;
	el.defsrc=el.actsrc;
	el.rollsrc=el.actsrc;
    this.blocks[this.last].style.display = 'none';
    this.blocks[el.id].style.display = 'block';
    this.last = el.id;
	
    this.cookie.set(this.c_name,this.last);
  }
  
tab_menu.prototype.init=function (listener)
	{
    var last = new Cookie();
    this.cookie = last;
    var last = this.cookie.get(this.c_name);
    var re = new RegExp(this.img_pfx + "(.*)","");
    for (var i = 0; (img_item = document.getElementsByTagName("img").item(i)); i++){
		
      var r = img_item.id.match(re);
      if (!r) continue; // !!!
      var blk = document.getElementById(this.block_pfx + r[1]);
      if (!blk) continue; // !!!
	  obj=this;
	  //listener=function(e) {reports_menu.c(e);};
	  img_item.attachEvent("onclick", listener);
      this.blocks[r[0]] = blk;
      if (blk.style.display != 'none') {
		this.last = r[0];
		//alert(this.last);
		
		
		this.last_src=img_item.defsrc;
		this.last_rollsrc=img_item.rollsrc;
		
		
        img_item.stopOut = true;
	
	
		img_item.src=img_item.actsrc;
		img_item.rollsrc=img_item.actsrc;
		
		
        //img_item.fireEvent('onmouseover');
      }
    }
    //alert(last+":"+this.last)
    /*var alstr="";
    if (is_all_reports)  alstr+="is_all_reports";
    if (is_proc_reports) alstr+=" is_proc_reports";
      alert(alstr);*/
    if (active_reports) {
        var l = document.getElementById(active_reports);
        l.fireEvent('onclick');
        l.fireEvent('onmouseover');
    }else{
      if (last && this.last != last) {
        var l = document.getElementById(last);
        l.fireEvent('onclick');
        l.fireEvent('onmouseover');
      }
    }
  }  
  
/*

tab_menu = {
  block_pfx    : "div_",      // tab block prefix, suffix will be set equal to corresponding image sfx
  blocks       : {},          // blocks collection
  img_pfx      : "tab_",      // image associated with block prefix
  last         : "",          // link to the last shown page
  last_src     : "", 			// last tab defult image src
  last_rollsrc : "",			// last tab rollover image src
  cookie       : "",
  c_name       : "tabmenu",

  c : function (e) {
    var el = window.event ? window.event.srcElement : e.currentTarget;
    if (this.last == el.id) return;
    last = document.getElementById(this.last);
    last.stopOut = false;
	last.defsrc=this.last_src;
	last.rollsrc=this.last_rollsrc;
    last.fireEvent('onmouseout');
    el.stopOut = true;
	this.last_src=el.defsrc;
	this.last_rollsrc=el.rollsrc; 
	el.src=el.actsrc;
	el.defsrc=el.actsrc;
	el.rollsrc=el.actsrc;
    this.blocks[tab_menu.last].style.display = 'none';
    this.blocks[el.id].style.display = 'block';
    this.last = el.id;
	
    this.cookie.set(this.c_name,this.last);
  },
  init : function (){
    var last = new Cookie();
    tab_menu.cookie = last;
    var last = tab_menu.cookie.get(tab_menu.c_name);
    var re = new RegExp(tab_menu.img_pfx + "(.*)","");
    for (var i = 0; (img_item = document.getElementsByTagName("img").item(i)); i++){
		
      var r = img_item.id.match(re);
      if (!r) continue; // !!!
      var blk = document.getElementById(tab_menu.block_pfx + r[1]);
      if (!blk) continue; // !!!
	  img_item.attachEvent("onclick",tab_menu.c);
      tab_menu.blocks[r[0]] = blk;
      if (blk.style.display != 'none') {
		tab_menu.last = r[0];
		tab_menu.last_src=img_item.defsrc;
		tab_menu.last_rollsrc=img_item.rollsrc; 
        img_item.stopOut = true;
		img_item.src=img_item.actsrc;
		img_item.rollsrc=img_item.actsrc;
        //img_item.fireEvent('onmouseover');
      }
    }
    if (last && tab_menu.last != last) {
		
      var l = document.getElementById(last);
      l.fireEvent('onclick');
      l.fireEvent('onmouseover');
    }
  }
} 
*/

// Commented by Vic. Now init launches from rollmenu.js init, as explorer and Mozilla are processing onload events in different order
//if (window.attachEvent) window.attachEvent("onload",tab_menu.init);
//else document.attachEvent("onload",tab_menu.init)

/**
* Setting tabs properties
*/

