
function _geb(id){
	var ret = document.getElementById(id);
	if(typeof ret == 'undefined')
		return false;
	else
		return ret;
}

var otwartyTab_lewo_dol = '0l';
var otwartyTab_lewo_gora = '0';
var otwartyTab_prawo_gora = '0r';
var otwartyTab_prawo_dol = '0rd';
var rodzaj = '';

function show_tab(self, html)
{	        
    advAJAX.get({
        url : domain + '/_stuff/' + html,
        onSuccess : function(obj)
                    {
    var line1 = '';
    var line2 = '';
    
    if (html.indexOf('zakladki_lewo_dol') != -1)
    {  
        rodzaj = 'lewo_dol';
    }
    else if (html.indexOf('zakladki_lewo_gora') != -1)
    {
        rodzaj = 'lewo_gora';            
    }               		        
    
    if (rodzaj == 'lewo_dol')
    {
        var outputDivId = 'panel0l_content';                
        
        // zamyka poprzednia zakladke
    	var open = _geb('tab' + otwartyTab_lewo_dol + '_on');		
	    open.style.marginTop = '3px';	
	    open.id = 'tab'+otwartyTab_lewo_dol;		            

    	open = _geb('tab'+otwartyTab_lewo_dol+'_content');
	    open.style.border = '1px solid #eeeded';
    	open.style.borderTop = 'none';
	    open.style.borderBottom = 'none';
    	open.style.color = '#576169';	
	    open.style.padding = '2px 0px';
    	open.style.height = '12px'; 	    

    	var open = _geb('tab'+otwartyTab_lewo_dol+'_top');
    	open.style.background = 'url(http://dev.gery.pl/img/bg/tab_off_top.gif) no-repeat 0 0';	        

        // otwiera nowa zakladke
    	otwartyTab_lewo_dol = self.id.substring(3);        
    	self.id += '_on';
	    self.style.marginTop = '0px';

    	var open = _geb('tab'+otwartyTab_lewo_dol+'_top');    	
	    open.style.backgroundImage = 'url(http://dev.gery.pl/img/bg/tab0ld_on_top.gif)';
    	open.style.backgroundRepeat = 'no-repeat';
	    open = _geb('tab'+otwartyTab_lewo_dol+'_content');
    	open.style.border = '1px solid #D5D4D4';
    	open.style.borderTop = 'none';
    	open.style.borderBottom = 'none';
    	open.style.color = '#576169';	
    	open.style.height = '16px'; 	

    	// ustala linie
        if (otwartyTab_lewo_dol == '0l')
        {
            line1 = 'panel0_line';
        }
        else if (otwartyTab_lewo_dol == '6l')
        {        
            line1 = 'panel6_line';
        }
        else
        {
            var strLength = otwartyTab_lewo_dol.length;
            line1 = 'panel' + otwartyTab_lewo_dol.substring(0, strLength-1) + '_line1';
            line2 = 'panel' + otwartyTab_lewo_dol.substring(0, strLength-1) + '_line2';
        }    	
    }
    else if (rodzaj == 'lewo_gora')
    {  
        var outputDivId = 'panel0_content';               
        
        // zamyka poprzednia zakladke
    	var open = _geb('tab' + otwartyTab_lewo_gora + '_on');		
	    open.style.marginTop = '3px';	
	    open.id = 'tab'+otwartyTab_lewo_gora;		            

    	open = _geb('tab'+otwartyTab_lewo_gora+'_content');
	    open.style.border = '1px solid #eeeded';
    	open.style.borderTop = 'none';
	    open.style.borderBottom = 'none';
    	open.style.color = '#576169';	
	    open.style.padding = '2px 0px';
    	open.style.height = '12px'; 	    

    	var open = _geb('tab'+otwartyTab_lewo_gora+'_top');
    	open.style.background = 'url(http://dev.gery.pl/img/bg/tab_off_top.gif) no-repeat 0 0';	        

        // otwiera nowa zakladke
    	otwartyTab_lewo_gora = self.id.substring(3);        
    	self.id += '_on';
	    self.style.marginTop = '0px';

    	var open = _geb('tab'+otwartyTab_lewo_gora+'_top');
	    open.style.backgroundImage = 'url(http://dev.gery.pl/img/bg/tab0_on_top.gif)';
    	open.style.backgroundRepeat = 'no-repeat';
	    open = _geb('tab'+otwartyTab_lewo_gora+'_content');
    	open.style.border = '1px solid #D5D4D4';
    	open.style.borderTop = 'none';
    	open.style.borderBottom = 'none';
    	open.style.color = '#576169';	
    	open.style.height = '16px'; 	

    	// ustala linie
        if (otwartyTab_lewo_gora == '0')
        {
            line1 = 'panel0_line';
        }
        else if (otwartyTab_lewo_gora == '6') 
        {        
            line1 = 'panel6_line';
        }
        else
        {
            line1 = 'panel' + otwartyTab_lewo_gora + '_line1';
            line2 = 'panel' + otwartyTab_lewo_gora + '_line2';
        }    
    }
    var outputDiv = _geb(outputDivId);            

    if (!line2)
    {
        line2 = rodzaj + 'qqq';
    }
    var lines = '<div class="panel_line" id="' + line1 + '"></div>' +
		        '<div class="panel_line" id="' + line2 + '"></div>';		        
	var linesDiv = _geb('lines_' + rodzaj);	  

                        outputDiv.innerHTML = obj.responseText;
                        linesDiv.innerHTML = lines;
                        
                        if (saveTabs)
                        {
                            zapiszCiastko();
                        }
                    },
        onError   : function(obj)
                    {
                        if (debug)
                        {
                            alert("Error: " + obj.status);
                        }
                    },
        timeout   : 10000,
        onTimeout : function()
                    {
                        if (debug)
                        {
                            alert("Connection timed out.");
                        }
                    },
        mimeType: 'text/plain'
    });	
}

function show_tab_pg(self, nazwa)
{	     
    advAJAX.get({
        url : domain + '/_stuff/zakladki_prawo_gora/' + nazwa + '_1.htm',
        onSuccess : function(obj)
                    {
    var line1 = '';
    var line2 = '';
    
    rodzaj = 'prawo_gora';                  		                      
        
    // zamyka poprzednia zakladke
	var open = _geb('tab' + otwartyTab_prawo_gora + '_on');		
    open.style.marginTop = '3px';	
	open.id = 'tab'+otwartyTab_prawo_gora;		            

    open = _geb('tab'+otwartyTab_prawo_gora+'_content');
    open.style.background = '#ffffff';
    open.style.border = '1px solid #eeeded';
   	open.style.borderTop = 'none';
    open.style.borderBottom = 'none';
   	open.style.color = '#576169';	
    open.style.padding = '2px 0px';
   	open.style.height = '12px';
   	if(otwartyTab_prawo_gora == '2r'){    
    	open.innerHTML = 'Firmy';
    }

   	var open = _geb('tab'+otwartyTab_prawo_gora+'_top');
   	open.style.background = 'url(http://dev.gery.pl/img/bg/tab_off_top.gif) no-repeat 0 0';	        

    // otwiera nowa zakladke
   	otwartyTab_prawo_gora = self.id.substring(3);        
  	self.id += '_on';
    self.style.marginTop = '0px';

   	var open = _geb('tab'+otwartyTab_prawo_gora+'_top');
    open.style.backgroundImage =  'url(http://dev.gery.pl/img/bg/tab' + otwartyTab_prawo_gora + '_on_top.gif)';
    open.style.backgroundRepeat = 'no-repeat';
    open = _geb('tab'+otwartyTab_prawo_gora+'_content');

    var outputDiv_1 = _geb('panel0r_content_1');            
    var outputDiv_2 = _geb('panel0r_content_2'); 
    
    
    var lineColor = '';    
    switch (otwartyTab_prawo_gora)
    {
        case '0r':
            lineColor = '#C9DF88';
            bColor = '#E4FAA4';
            break;
        case '1r':
            lineColor = '#D9B105';
            bColor = '#fff085';
            break;
        case '2r':
            lineColor = '#02558a';
            bColor = '#0374bd';            
            break;
        case '3r':
            lineColor = '#bfa78c';
            bColor = '#FFDFBB';
            break;
        case '4r':
            lineColor = '#bfb68e';
            bColor = '#e1d6a7';
            break;
    }
    open.style.border = '1px solid ' + lineColor;
    
    temp = _geb('tab'+otwartyTab_prawo_gora+'_content');
    
    temp.style.backgroundColor = bColor;                
    
    if(otwartyTab_prawo_gora == '2r'){
    	temp.style.background = '#0374bd url(img/bg/tab2r_on_content.gif) 50% 2px';
    	temp.style.backgroundRepeat = 'no-repeat';
    	temp.innerHTML = '';
    }
   	open.style.borderTop = 'none';
   	open.style.borderBottom = 'none';
   	open.style.color = '#576169';	
   	open.style.height = '16px'; 	

   	// ustala linie
    if (otwartyTab_prawo_gora == '0r')
    {
        line1 = 'panel0r_line';
    }
    else if (otwartyTab_prawo_gora == '4r')
    {        
        line1 = 'panel4r_line';
    }
    else
    {
        line1 = 'panel' + otwartyTab_prawo_gora + '_line1';
        line2 = 'panel' + otwartyTab_prawo_gora + '_line2';
    }    	
     
               
    if (!line2)
    {
        line2 = rodzaj + 'qqq';
    }
    
    var lines = '<div class="panel_line" id="' + line1 + '"></div>' +
		        '<div class="panel_line" id="' + line2 + '"></div>';		        
		
	var linesDiv = _geb('lines_' + rodzaj);
                        outputDiv_1.style.backgroundColor = bColor;
                        outputDiv_1.innerHTML = obj.responseText;                        
                        linesDiv.innerHTML = lines;
                        var line1obj = _geb(line1);
                        if (line1obj)
                        {
                            line1obj.style.borderTopColor = lineColor;
                        }
                        var line2obj = _geb(line2);
                        if (line2obj)
                        {
                            line2obj.style.borderTopColor = lineColor;
                        }                        
                        var panelobj = _geb("panel0r");
                        panelobj.style.borderColor = lineColor;
                        
                        getStyleClass('banner_maly').style.borderTopColor = lineColor;
                        getStyleClass('banner_maly').style.borderBottomColor = lineColor;                        

                        if (saveTabs)
                        {
                            zapiszCiastko();
                        }                        
                    },
        onError   : function(obj)
                    {
                        if (debug)
                        {                    
                            alert("Error: " + obj.status);
                        }
                    },
        timeout   : 10000,
        onTimeout : function()
                    {
                        if (debug)
                        {                    
                            alert("Connection timed out.");
                        }
                    },
        mimeType: 'text/plain'
    });	
    advAJAX.get({
        url : domain + '/_stuff/zakladki_prawo_gora/' + nazwa + '_2.htm',
        onSuccess : function(obj)
                    {
                        var outputDiv_2 = _geb('panel0r_content_2');
                        outputDiv_2.innerHTML = obj.responseText;
                    },
        onError   : function(obj)
                    {
                        if (debug)
                        {                        
                            alert("Error: " + obj.status);
                        }
                    },
        timeout   : 3000,
        onTimeout : function()
                    {
                        if (debug)
                        {                    
                            alert("Connection timed out.");
                        }
                    },
        mimeType: 'text/plain'
    });    
}


function show_tab_pd(self, nazwa)
{	     
    advAJAX.get({
        url : domain + '/_stuff/zakladki_prawo_dol/' + nazwa + '.htm',
        onSuccess : function(obj)
                    {
    var line1 = '';
    var line2 = '';
    
    rodzaj = 'prawo_dol';                  		                      
        
    // zamyka poprzednia zakladke
	var open = _geb('tab' + otwartyTab_prawo_dol + '_on');		
    open.style.marginTop = '3px';	
	open.id = 'tab'+otwartyTab_prawo_dol;		            

    open = _geb('tab'+otwartyTab_prawo_dol+'_content');
    open.style.backgroundColor = 'white';
    open.style.border = '1px solid #eeeded';
   	open.style.borderTop = 'none';
    open.style.borderBottom = 'none';
   	open.style.color = '#576169';	
    open.style.padding = '2px 0px';
   	open.style.height = '12px'; 	    

   	var open = _geb('tab'+otwartyTab_prawo_dol+'_top');
   	open.style.background = 'url(http://dev.gery.pl/img/bg/tab_off_top.gif) no-repeat 0 0';	        

    // otwiera nowa zakladke
   	otwartyTab_prawo_dol = self.id.substring(3);        
  	self.id += '_on';
    self.style.marginTop = '0px';

   	var open = _geb('tab'+otwartyTab_prawo_dol+'_top');
    open.style.backgroundImage =  'url(http://dev.gery.pl/img/bg/tab' + otwartyTab_prawo_dol + '_on_top.gif)';
    open.style.backgroundRepeat = 'no-repeat';
    open = _geb('tab'+otwartyTab_prawo_dol+'_content');

    var outputDiv_1 = _geb('panel0rd_content');            
    
    var lineColor = '';
    switch (otwartyTab_prawo_dol)
    {
        case '0rd':
            lineColor = '#758bab';
            bColor = '#cbd3df';
            break;
        case '1rd':
            lineColor = '#bfad78';
            bColor = '#ffe7a0';
            break;
        case '2rd':
            lineColor = '#bda6ad';
            bColor = '#f8dae3';
            break;
        case '3rd':
            lineColor = '#78c4b8';
            bColor = '#ade8df';
            break;
        case '4rd':
            lineColor = '#95b5a4';
            bColor = '#c1ebd5';
            break;
    }
    open.style.border = '1px solid ' + lineColor;

    temp = _geb('tab'+otwartyTab_prawo_dol+'_content');
    temp.style.backgroundColor = bColor;
    
   	open.style.borderTop = 'none';
   	open.style.borderBottom = 'none';
   	open.style.color = '#576169';	
   	open.style.height = '16px'; 	

   	// ustala linie
    if (otwartyTab_prawo_dol == '0rd')
    {
        line1 = 'panel0rd_line';
    }
    else if (otwartyTab_prawo_dol == '4rd')
    {        
        line1 = 'panel4rd_line';
    }
    else
    {
        var strLength = otwartyTab_prawo_dol.length;
        line1 = 'panel' + otwartyTab_prawo_dol + '_line1';
        line2 = 'panel' + otwartyTab_prawo_dol + '_line2';

    }    	
               
    if (!line2)
    {
        line2 = rodzaj + 'qqq';
    }
    var lines = '<div class="panel_line" id="' + line1 + '"></div>' +
		        '<div class="panel_line" id="' + line2 + '"></div>';		        
	var linesDiv = _geb('lines_' + rodzaj);	   	 

                        outputDiv_1.style.backgroundColor = bColor;
                        outputDiv_1.innerHTML = obj.responseText;                        
                        linesDiv.innerHTML = lines;

                        var line1obj = _geb(line1);
                        if (line1obj)
                        {
                            line1obj.style.borderTopColor = lineColor;
                        }
                        var line2obj = _geb(line2);
                        if (line2obj)
                        {
                            line2obj.style.borderTopColor = lineColor;
                        }                        
                        var panelobj = _geb("panel0rd");
                        panelobj.style.borderColor = lineColor;
                        
                        getStyleClass('banner_maly').style.borderTopColor = lineColor;
                        getStyleClass('banner_maly').style.borderBottomColor = lineColor;                        
                        
                        if (saveTabs)
                        {
                            zapiszCiastko();
                        }                        
                    },
        onError   : function(obj)
                    {
                        if (debug)
                        {                    
                            alert("Error: " + obj.status);
                        }
                    },
        timeout   : 10000,
        onTimeout : function()
                    {
                        if (debug)
                        {                    
                            alert("Connection timed out.");
                        }
                    },
        mimeType: 'text/plain'
    });	      
}


function getStyleClass(className)
{
    for (var s = 0; s < document.styleSheets.length; s++)
    {
        if (document.styleSheets[s].rules)
        {
            for (var r = 0; r < document.styleSheets[s].rules.length; r++)
            {
                if (document.styleSheets[s].rules[r].selectorText == '.' + className)
                {
                    return document.styleSheets[s].rules[r];
                }
            }
        }
        else if (document.styleSheets[s].cssRules)
        {
            for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
            {
                if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
                {
                    return document.styleSheets[s].cssRules[r];
                }
            }
        }
    }
	
    return null;
}

	function setCookie (name, value)
    {
        document.cookie = name + '=' + escape (value) + '; expires=Wed, 1 Jan 2020 00:00:00 GMT;';
    }
    
    function getCookie(name) {
	  var dc = document.cookie;
	  var prefix = name + "=";
	  var begin = dc.indexOf("; " + prefix);
	  if (begin == -1) {
	    begin = dc.indexOf(prefix);
	    if (begin != 0) return null;
	  } else
	    begin += 2;
	  var end = document.cookie.indexOf(";", begin);
	  if (end == -1)
	    end = dc.length;
	  return unescape(dc.substring(begin + prefix.length, end));
	}
	
  function moveAd(from,to)
  {
	try
	{
		var to_obj = document.getElementById(to);
		var from_obj = document.getElementById(from);
		to_obj.innerHTML = from_obj.innerHTML;
		from_obj.parentNode.removeChild(from_obj);
	}
	catch(e){}
  }
  
  //zamienia dzieci elementu o podanym ,,id'' na tekst ,,na''
  function podmien(id,na)
  {
    t = document.getElementById(id);
	while(t.childNodes.length)
  	  t.removeChild(t.childNodes[0])
	t.appendChild(document.createTextNode(na));
  }


