var Ajax = new Object();

Ajax.Request = function(url,id, callbackMethod,temp,tempa)
{
/*
	if ( id == 0 )
	{
		return;
	}*/


		Ajax.request = Ajax.createRequestObject();
	//	alert( Ajax.request.status);
	//	alert(Ajax.request.readyState)
		if(Ajax.request.readyState == 0)
		{
			if(Ajax.temp!="pusto")
				Ajax.temp=temp;
	
				Ajax.tempa=tempa;	

			
				Ajax.request.onreadystatechange = callbackMethod;			
				Ajax.request.open("POST", url+id, true);
				Ajax.request.send(url);			
		}
/*	alert(url+id);*/
}

Ajax.Responseb = function ()
{
	if(Ajax.CheckReadyState(Ajax.request) == true )
	{		
//	alert("fb" + Ajax.CheckReadyState(Ajax.request))
		document.getElementById('select_produkt').length = 0;
		//document.getElementById('selSubCat').options[0] = new Option("----","0");
			
			
		var	response = Ajax.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('kategoria');	
		if(_data.length == 0)
		{			
			document.getElementById('select_produkt').length = 0;
		//	document.getElementById('select_produkt').options[0] = new Option(" brak produktow",'0');		
					
		}
		var i;
		if(_data.length != 0)
			document.getElementById('select_produkt').options[0] = new Option(" model",'-1');			
		for ( i = 0 ; i < _data.length ; i ++ )
		{
			document.getElementById('select_produkt').options[i+1] = new Option(" " + response.getElementsByTagName('nazwa')[i].firstChild.data,response.getElementsByTagName('id_kategoria')[i].firstChild.data);	
			if(Ajax.tempa!=0 && Ajax.tempa==response.getElementsByTagName('id_kategoria')[i].firstChild.data)
			{
			//	alert("zaznacz" + Ajax.tempa);				
				document.getElementById('select_produkt').selectedIndex=i;
				
			}
		}
		getElement("szukaj_expl").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl").onclick="";		
			
	}
}


Ajax.Responseb1 = function ()
{
	if(Ajax.CheckReadyState1(Ajax.request) == true )
	{		
//	alert("fb" + Ajax.CheckReadyState(Ajax.request))
		document.getElementById('select_produkt1').length = 0;
		//document.getElementById('selSubCat').options[0] = new Option("----","0");

		var	response = Ajax.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('kategoria');	
		if(_data.length == 0)
		{			
			document.getElementById('select_produkt1').length = 0;
		//	document.getElementById('select_produkt').options[0] = new Option(" brak produktow",'0');		
					
		}
		var i;
		if(_data.length != 0)
			document.getElementById('select_produkt1').options[0] = new Option(" model",'-1');			
		for ( i = 0 ; i < _data.length ; i ++ )
		{
			document.getElementById('select_produkt1').options[i+1] = new Option(" " + response.getElementsByTagName('nazwa')[i].firstChild.data,response.getElementsByTagName('id_kategoria')[i].firstChild.data);	
			if(Ajax.tempa!=0 && Ajax.tempa==response.getElementsByTagName('id_kategoria')[i].firstChild.data)
			{
			//	alert("zaznacz" + Ajax.tempa);				
				document.getElementById('select_produkt1').selectedIndex=i;
				
			}
		}
		getElement("szukaj_expl1").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl1").onclick="";			
	}
}

Ajax.Responsec = function (value,link)
{
	if(value!=-1 && value!=0)
	{
		getElement("szukaj_expl").src="/_gfx/szukaj_eksploatacja.png";	
	//	getElement("szukaj_expl").onclick=new Function('getElement("wyszukiwarka_materialow").action="' + link + "/" + value + '.cd?materialy";getElement("wyszukiwarka_materialow").submit();');		
		getElement("szukaj_expl").onmouseover=new Function('on(this)');	
		getElement("szukaj_expl").onmouseout=new Function('off(this)');		
		getElement("szukaj_expl").style.cursor="pointer";	
		getElement("wyszukiwarka_materialow").action=link + "/" + value + ".cd?materialy";
		getElement("wyszukiwarka_materialow").submit();		
	}	
	else
	{
		getElement("szukaj_expl").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl").onclick="";	
		getElement("szukaj_expl").onmouseover="";	
		getElement("szukaj_expl").onmouseout="";
		getElement("szukaj_expl").style.cursor="";	
	}			
}

Ajax.Responseh = function (value,link)
{
	/*
	if(value!=-1 && value!=0)
	{
		getElement("szukaj_expl").src="/_gfx/szukaj_eksploatacja.png";	
	//	getElement("szukaj_expl").onclick=new Function('getElement("wyszukiwarka_materialow").action="' + link + "/" + value + '.cd?materialy";getElement("wyszukiwarka_materialow").submit();');		
		getElement("szukaj_expl").onmouseover=new Function('on(this)');	
		getElement("szukaj_expl").onmouseout=new Function('off(this)');		
		getElement("szukaj_expl").style.cursor="pointer";	

	}	
	else
	{
		getElement("szukaj_expl").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl").onclick="";	
		getElement("szukaj_expl").onmouseover="";	
		getElement("szukaj_expl").onmouseout="";
		getElement("szukaj_expl").style.cursor="";	
	}		
	*/
	getElement("wyszukiwarka_hp").action="aaaaaa";
		getElement("wyszukiwarka_hp").action=link + value;
		getElement("wyszukiwarka_hp").submit();		
		
}

Ajax.Responsec1 = function (value,link)
{
	if(value!=-1 && value!=0)
	{
		getElement("szukaj_expl1").src="/_gfx/szukaj_eksploatacja.png";	
		//getElement("szukaj_expl1").onclick=new Function('getElement("firma").action="' + link + "/" + value + '.cd?materialy";getElement("firma").submit();');		
		getElement("szukaj_expl1").onmouseover=new Function('on(this)');	
		getElement("szukaj_expl1").onmouseout=new Function('off(this)');		
		getElement("szukaj_expl1").style.cursor="pointer";	
		getElement("firma").action=link + "/" + value + ".cd?materialy";
		getElement("firma").submit();
	}	
	else
	{
		getElement("szukaj_expl1").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl1").onclick="";	
		getElement("szukaj_expl1").onmouseover="";	
		getElement("szukaj_expl1").onmouseout="";
		getElement("szukaj_expl1").style.cursor="";	
	}			
}
//								cells[j].childNodes[ii].onclick = ;

Ajax.Responsea = function ()
{
	if(Ajax.CheckReadyState(Ajax.request) == true)
	{		
		getElement("szukaj_expl").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl").onclick="";	
//		alert("fa" + Ajax.CheckReadyState(Ajax.request))
		document.getElementById('selSubCat').length = 0;
		document.getElementById('select_produkt').length = 0;
		//document.getElementById('selSubCat').options[0] = new Option("----","0");
		
		var	response = Ajax.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('kategoria');	
		if(_data.length == 0)
		{			
		//	document.getElementById('selSubCat').options[0] = new Option("brak serii",'0');	

		//	Ajax.Request('/get_data_w.php?method=getXMLb&param=',-1, Ajax.Responseb,0);

//			this.Request(/get_data_w.php?method=getXMLb&param=',0, this.Responseb);					
		}
		var i;

		if(_data.length != 0)
			document.getElementById('selSubCat').options[0] = new Option("seria",'-1');	
		for ( i = 0 ; i < _data.length ; i ++ )
		{
			document.getElementById('selSubCat').options[i+1] = new Option(" " + response.getElementsByTagName('nazwa')[i].firstChild.data,response.getElementsByTagName('id_kategoria')[i].firstChild.data);	
			if(Ajax.temp!=0 && Ajax.temp==response.getElementsByTagName('id_kategoria')[i].firstChild.data)
			{
			//	alert("zaznacz" + Ajax.temp);
				document.getElementById('selSubCat').selectedIndex=i+1;	
			}		
		}
		
		
		var _data = response.getElementsByTagName('produkt');	
	//	alert(_data.length )	;
		if(_data.length != 0)
			document.getElementById('select_produkt').options[0] = new Option("model",'-1');	
		for ( i = 0 ; i < _data.length ; i ++ )
		{
			document.getElementById('select_produkt').options[i+1] = new Option(" " + response.getElementsByTagName('nazwap')[i].firstChild.data,response.getElementsByTagName('klucz')[i].firstChild.data);	
			if(Ajax.temp!=0 && Ajax.temp==response.getElementsByTagName('klucz')[i].firstChild.data)
			{
			//	alert("zaznacz" + Ajax.temp);
				document.getElementById('select_produkt').selectedIndex=i+1;	
			}		
		}
		
		
		
		
		
		
		
		
		
		

		Ajax.temp="pusto";
	}
}

Ajax.Responsea1 = function ()
{
	if(Ajax.CheckReadyState1(Ajax.request) == true)
	{		
		getElement("szukaj_expl1").src="/_gfx/szukaj_eksploatacja_off.png";	
		getElement("szukaj_expl1").onclick="";	
//		alert("fa" + Ajax.CheckReadyState(Ajax.request))
		document.getElementById('selSubCat1').length = 0;
		document.getElementById('select_produkt1').length = 0;
		//document.getElementById('selSubCat').options[0] = new Option("----","0");
		
		var	response = Ajax.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('kategoria');	
		if(_data.length == 0)
		{			
		//	document.getElementById('selSubCat').options[0] = new Option("brak serii",'0');	

		//	Ajax.Request('/get_data_w.php?method=getXMLb&param=',-1, Ajax.Responseb,0);

//			this.Request(/get_data_w.php?method=getXMLb&param=',0, this.Responseb);					
		}
		var i;

		if(_data.length != 0)
			document.getElementById('selSubCat1').options[0] = new Option("seria",'-1');	
		for ( i = 0 ; i < _data.length ; i ++ )
		{
			document.getElementById('selSubCat1').options[i+1] = new Option(" " + response.getElementsByTagName('nazwa')[i].firstChild.data,response.getElementsByTagName('id_kategoria')[i].firstChild.data);	
			if(Ajax.temp!=0 && Ajax.temp==response.getElementsByTagName('id_kategoria')[i].firstChild.data)
			{
			//	alert("zaznacz" + Ajax.temp);
				document.getElementById('selSubCat1').selectedIndex=i+1;	
			}		
		}
		
		
		
		var _data = response.getElementsByTagName('produkt');		
		if(_data.length != 0)
			document.getElementById('select_produkt1').options[0] = new Option("model",'-1');	
		for ( i = 0 ; i < _data.length ; i ++ )
		{
			document.getElementById('select_produkt1').options[i+1] = new Option(" " + response.getElementsByTagName('nazwap')[i].firstChild.data,response.getElementsByTagName('klucz')[i].firstChild.data);	
			if(Ajax.temp!=0 && Ajax.temp==response.getElementsByTagName('klucz')[i].firstChild.data)
			{
			//	alert("zaznacz" + Ajax.temp);
				document.getElementById('select_produkt1').selectedIndex=i+1;	
			}		
		}
		
		
		
		

		Ajax.temp="pusto";
	}
}


Ajax.createRequestObject = function(temp)
{
	var obj;
	if(window.XMLHttpRequest)
	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}

Ajax.CheckReadyState = function(obj)
{
//	alert(obj.readyState);
	if(obj.readyState < 4) {		
		
		//document.getElementById('loading').style.top = (Page.top + Page.height/2)-100;
		//document.getElementById('loading').style.left = Page.width/2-75;
		//document.getElementById('loading').style.position = "absolute";
		document.getElementById('loading').style.visibility="visible";
		
		return false;
	}
	//if(obj.readyState == 1) { document.getElementById('loading').innerHTML = "Loading..."; }
	//if(obj.readyState == 2) { document.getElementById('loading').innerHTML = "Loading..."; }
	//if(obj.readyState == 3) { document.getElementById('loading').innerHTML = "Loading..."; }	
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			document.getElementById('loading').style.visibility="hidden";
		//	setTimeout('Page.loadOut()',1000);
		
			return true;
		}
		else
		{
		//	document.getElementById('loading').innerHTML = "HTTP " + obj.status;
		}
	}
}
Ajax.CheckReadyState1 = function(obj)
{
//	alert(obj.readyState);
	if(obj.readyState < 4) {		
		
		//document.getElementById('loading').style.top = (Page.top + Page.height/2)-100;
		//document.getElementById('loading').style.left = Page.width/2-75;
		//document.getElementById('loading').style.position = "absolute";
		document.getElementById('loading1').style.visibility="visible";
		
		return false;
	}
	//if(obj.readyState == 1) { document.getElementById('loading').innerHTML = "Loading..."; }
	//if(obj.readyState == 2) { document.getElementById('loading').innerHTML = "Loading..."; }
	//if(obj.readyState == 3) { document.getElementById('loading').innerHTML = "Loading..."; }	
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			document.getElementById('loading1').style.visibility="hidden";
		//	setTimeout('Page.loadOut()',1000);
		
			return true;
		}
		else
		{
		//	document.getElementById('loading').innerHTML = "HTTP " + obj.status;
		}
	}
}

