

var initialtab=[1, '@PAGE_ACTIVE']
var turntosingle=0 //0 for no (default), 1 for yes
var disabletablinks=0 //0 for no (default), 1 for yes

var previoustab=""
if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

var hilight;
function change(id, newClass, oldClass) {
	identity=document.getElementById(id);
	
	if (hilight) {
		oldidentity=document.getElementById(hilight);
		oldidentity.className=oldClass;
	}
	
	identity.className=newClass;
	hilight = id;
}

function expandcontent(cid, class1, class2) {
	change('tab_'+cid, class1, class2)

	// if (disabletablinks==1)
	// aobject.onclick=new Function("return false")
	if (document.getElementById) {
		// highlighttab(aobject)
		if (turntosingle==0){
			if (previoustab!="")
				document.getElementById(previoustab).style.display="none"
			document.getElementById(cid).style.display="block"
			previoustab=cid
		}
	}
}

function collecttablinks(){
	var tabobj=document.getElementById("tablist")
	tabobjlinks=tabobj.getElementsByTagName("A")
}


function popup(url, width,height) { 
	window.open(url, '', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto, resizable=yes,copyhistory=no,width="+width+",height="+height); return false;
}

function pot(pytanie, urla) {
	if (confirm(pytanie)) {
		if (Is.nav) {
			document.location.href=urla;
		} else {
			pk = String(urla);
			pk = pk.replace('?', '');
			aa = pk.split('=');
			document.write("<form name='potform' action=''>");
			document.write("<input type='hidden' name='"+aa[0]+"' value='"+aa[1]+"'>");
			document.write("</form>");
			document.forms.potform.submit();
			// alert("<input type='hidden' name='"+aa[0]+"' value='"+aa[1]+"'>");
		}
	} else
		return false;
}

function pot2(pytanie, urla) {
	if (confirm(pytanie)) {
		if (Is.nav) {
			document.location.href=urla;
		} else {
			pk = String(urla);
			pk = pk.replace('?', '');
			kk = pk.split('&');
			aa = kk[0].split('=');
			bb = kk[1].split('=');
			document.write("<form name='potform' action=''>");
			document.write("<input type='hidden' name='"+aa[0]+"' value='"+aa[1]+"'>");
			document.write("<input type='hidden' name='"+bb[0]+"' value='"+bb[1]+"'>");
			document.write("</form>");
			document.forms.potform.submit();
			// alert("<input type='hidden' name='"+aa[0]+"' value='"+aa[1]+"'>");
		}
	} else
		return false;
}

function zaokr(liczba) {
	liczba = liczba * 100;
	var wynik = Math.round(liczba)/100;
	return wynik;
}

function str_repeat(i, m) {
for (var o = ''; m-- > 0; o += i);
return o;
}

function sprintf () {
var a, f = arguments[0], fi= '', i = 1, m = [''], o = '', p;
while (f = f.substring (m[0].length)) {
m = /^([^\%]*)(?:(\x25)((\x25)|(?:(\d+)\$)?(\+)?(0|'([^$]))?(-|\^)?(\d+)?(?:\.(\d+))?([bcdefosuxX])))?/.exec(f);
if (a = m[12]) {
if (arguments.length < (i = m[5] || i))
throw("sprintf '" + m[0] + "' : No argument " + i);
a = arguments[i++];
s = (/[def]/.test(m[12]) && m[6] && a > 0) ? '+':'';
switch (m[12]) {
case 'b': a = a.toString(2); break;
case 'c': a = String.fromCharCode(a); break;
case 'd': a = parseInt(a); break;
case 'e': a = m[11] ? a.toExponential(m[11]) : a.toExponential(); break;
case 'f': a = m[11] ? parseFloat(a).toFixed(m[11]) : parseFloat(a); break;
case 'o': a = a.toString(8); break;
case 's': a = ((a = String(a)) && m[11] ? a.substring(0, m[11]) : a); break;
case 'u': a = Math.abs(a); break;
case 'x': a = a.toString(16); break;
case 'X': a = a.toString(16).toUpperCase(); break;
}
if (m[10] && (m[10] > a.length)) {
fir=fil=str_repeat(m[7] ? m[8] || '0' : ' ', m[10]-a.length);
if (m[9] == '^') {
fil = fil.substr(0, fil.length / 2);
fir = fir.substr(fil.length);
} else
m[9] == '-' ? (fil = '') : (fir = '');
a = fil + a + fir;
}
}
o += m[1] + ((m[3] ? m[4] || (s + a) : m[2]) || '');
}
return o;
}


function Is ()
	{   
		 var agt=navigator.userAgent.toLowerCase()
	
		 this.major = parseInt(navigator.appVersion)
		 this.minor = parseFloat(navigator.appVersion)
	
		 this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
					 && (agt.indexOf('compatible') == -1)))
		 this.nav2 = (this.nav && (this.major == 2))
		 this.nav3 = (this.nav && (this.major == 3))
		 this.nav4 = (this.nav && (this.major == 4))
	
		 this.ie   = (agt.indexOf("msie") != -1)
		 this.ie3  = (this.ie && (this.major == 2))
		 this.ie4  = (this.ie && (this.major == 4))
	
		 this.opera = (agt.indexOf("opera") != -1)
	
		 this.nav4up = this.nav && (this.major >= 4)
		 this.ie4up  = this.ie  && (this.major >= 4)
	}
	
	Is = new Is();


	
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() 
{
  var xmlHttp;
  try
  {
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
 
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
      "MSXML2.XMLHTTP.5.0",
      "MSXML2.XMLHTTP.4.0",
      "MSXML2.XMLHTTP.3.0",
      "MSXML2.XMLHTTP",
      "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  if (!xmlHttp)
    alert("Błąd podczas tworzenia obiektu XMLHttpRequest.");
  else 
    return xmlHttp;
}

function XMLHtmlGet(url, fnState) {
 if (xmlHttp)
  {
    try
    {
      try
      {
       netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
      }
      catch(e) {} // ignoruje błąd
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange = fnState;
      xmlHttp.send(null);
    }
    catch (e)
    {
      alert("A Nie mogę nawiązać połączenia z sewerem:\n" + e.toString());
    }
  }
}

var actual_id = 0;
var old_content;

function SwitchEdit(id, object) {
	if (id != actual_id && actual_id > 0) {
		// SavePos(actual_id, object);
		mydiv = document.getElementById('pos'+actual_id);
		mydiv.innerHTML = old_content;
	}

	actual_id = id;
	aa = '/?T='+object+'&obj='+object+'&option=2&action=edit&getxml=1&id='+id;
	
	XMLHtmlGet(aa, SwitchEditState);
}

function SwitchEditState() {
  
 mydiv = document.getElementById('pos'+actual_id);
 
  if (xmlHttp.readyState == 1) {
  	old_content = mydiv.innerHTML;
  	mydiv.innerHTML = document.getElementById('loadingindicator').innerHTML;
  }

  if (xmlHttp.readyState == 4) 
  {
 
    if (xmlHttp.status == 200) 
    {
      try
      {

  	xmlResponse = xmlHttp.responseXML;
       if(!xmlResponse || !xmlResponse.documentElement) throw("Invalid XML structure\n\n" + xmlHttp.responseText); // IE, Opera
       var rootNodeName = xmlResponse.documentElement.nodeName;
       if(rootNodeName == "parseerror") throw("Invalid XML structure\n\n" + xmlHttp.responseText); // FireFox
       xmlDocumentElement = xmlResponse.documentElement;
       mydiv.innerHTML = xmlDocumentElement.firstChild.data;
      // alert(mydiv.innerHTML);
      }
      catch(e)
      {
        alert("Wystąpił błąd podczas odczytu odpowiedzi: " + e.toString());
      }
    } 
    else
    {
      alert("Pojawił się problem podczas odbierania danych:\n" + xmlHttp.statusText);
    }
  }
}

function SavePos(id, object) {
	pl = 	[['Ę','%CA'],
		['Ó', '%D3'],
		['Ą','%A5'],
		['Ś','%8C'],
		['Ł','%A3'],
		['Ż','%AF'],
		['Ź','%8F'],
		['Ć','%C6'],
		['Ń','%D1'],
		['ę','%EA'],
		['ó','%F3'],
		['ą','%B9'],
		['ś','%9C'],
		['ł','%B3'],
		['ż','%BF'],
		['ź','%9F'],
		['ć','%E6'],
		['ń','%F1']];

	form = document.forms['form'+id];
	params = new String();
	for(j=0; j< form.elements.length; j++){
		bb = strtr(form.elements[j].value, pl);
		params =  params+form.elements[j].name+'='+bb+'&';
  	}
	aa = '/?T='+object+'&obj='+object+'&option=3&getxml=1&id='+id+'&'+params;
	XMLHtmlGet(aa, SavePosState);
}


function strtr(tekst, tablica, zmienna2)
{
	
	if ((typeof(tablica)=="object") && (tablica.length))
	{
		for (i in tablica)
		{
			tekst = tekst.replace(RegExp(tablica[i][0], "g"), tablica[i][1])
		}
		return tekst
	}
	else
	{
		tablica2 = new Array();
		for(i = 0; i < tablica.length; i++)
			tablica2[i] = [tablica.substr(i,1), zmienna2.substr(i,1)]
		return strtr(tekst, tablica2)
	}
}

function SavePosState() {
  
 mydiv = document.getElementById('pos'+actual_id);
 
  if (xmlHttp.readyState == 1) {
  	mydiv.innerHTML = document.getElementById('loadingindicator').innerHTML;
  }

  if (xmlHttp.readyState == 4) 
  {
 
    if (xmlHttp.status == 200) 
    {
      try
      {

  	xmlResponse = xmlHttp.responseXML;
       if(!xmlResponse || !xmlResponse.documentElement) throw("Invalid XML structure\n\n" + xmlHttp.responseText); // IE, Opera
       var rootNodeName = xmlResponse.documentElement.nodeName;
       if(rootNodeName == "parseerror") throw("Invalid XML structure\n\n" + xmlHttp.responseText); // FireFox
       xmlDocumentElement = xmlResponse.documentElement;
       mydiv.innerHTML = xmlDocumentElement.firstChild.data;
     
      }
      catch(e)
      {
        alert("Wystąpił błąd podczas odczytu odpowiedzi: " + e.toString());
      }
    } 
    else
    {
      alert("Pojawił się problem podczas odbierania danych:\n" + xmlHttp.status + " "+xmlHttp.statusText);
    }
  }
}
