var semafor = false;
var example = false;



function Search(slowo)
{
	search_word = document.getElementById(slowo).value;
	if (search_word !='')		
		window.location='/wyszukaj,'+search_word;
}


function removeOldSchool(theSel)
{   
    for(i=theSel.length-1; i>=0; i--)
    {    
        theSel.options[i] = null;    
    } 
  
}


function Sleep(numberMillis) {
	  var now = new Date();
	  var exitTime = now.getTime() + numberMillis;
	  while (true) {
	    now = new Date();
	    if (now.getTime() > exitTime)
	   return;
	  }
	}

	
 function send(form) {	
    var boundary = form.generateBoundary();
    var xhr = new XMLHttpRequest;

    xhr.open("POST", form.action, false);

    var contentType = "multipart/form-data; boundary=" + boundary;
    xhr.setRequestHeader("Content-Type", contentType);

    for (var header in form.headers) {
        xhr.setRequestHeader(header, headers[header]);
    }

    // here's our data variable that we talked about earlier
    var data = form.buildMessage(form.elements, boundary);

    // finally send the request as binary data
    xhr.sendAsBinary(data);
    
    alert(xhr.responseText);
}




function updatepage(str, wybrany){
	
  
  //alert(str);
	var col_array=str.split("|");
	var part_num=0;
	while (part_num < col_array.length-1)
	{
		//alert(col_array[part_num]);
		
		var col = col_array[part_num].split("^");
		
		wybrany.options[wybrany.length] = new Option(col[0], col[1]);
		part_num+=1;		
	}
}






function Load(wybrany, gdzie) {
    var xmlHttpReq = false;
    var self = this;
   
    removeOldSchool(gdzie);
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('GET', "/inc/get_sub_cat.php?id_rodzic="+escape(wybrany.value), false);
    
    self.xmlHttpReq.send(null);
    
    if (! isStatusGood(self.xmlHttpReq.status)) {
	    throw "Failed to get " + url + ", status: " + self.xmlHttpReq.status;
	}
    
    //alert(self.xmlHttpReq.responseText);
    
    updatepage(self.xmlHttpReq.responseText, gdzie);  
}


function updatepage2(str, wybrany){
	
    
 //alert(str);
	var col_array=str.split("|");
	var part_num=0;
	while (part_num < col_array.length-1)
	{
		//alert(col_array[part_num]);
		
		var col = col_array[part_num].split("^");
		var obj =new Option(col[0], col[1]);
		obj.setAttribute('id','fields');
		
		wybrany.options[wybrany.length] =obj; 
		
		part_num+=1;		
	}
}



function Load2(wybrany, gdzie) {
    var xmlHttpReq = false;
    var self = this;
   
    removeOldSchool(gdzie);
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('GET', "/inc/get_sub_cat2.php?id_rodzic="+escape(wybrany.value), false);
    
    self.xmlHttpReq.send(null);
    
    if (! isStatusGood(self.xmlHttpReq.status)) {
	    throw "Failed to get " + url + ", status: " + self.xmlHttpReq.status;
	}        
    updatepage2(self.xmlHttpReq.responseText, gdzie);    
}




function isStatusGood(status) {
    // OK, or not-modified. When using Ajax, IE 6.0 fakes 200 when 304
    // is the actual status. Opera 8.0 returns 304 as is. Firefox
    // 1.5 doesn't even go back to server when requested URL is
    // cached. You should stop browser caching if content requested through
    // Ajax is dynamic.
    return (status == 200) || (status == 304 || (status == 0));
}

function SelectCategory(form)
{	
	//Load2(form.kategoria, form.podkategoria);		
}

function SelectGroup(form)
{	
	Load2(form.grupa, form.kategoria);	
	SelectCategory(form);	
}








