
function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Versão: 2.1 - 04/09/2007
* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML


    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];

        if(spantemp.tagName){
            opt = document.createElement("OPTION")

   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }

   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   /*if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }*/
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML.replace(/&amp;/,"&");
   //IE
   opt.selected = spantemp.getAttribute('selected');
   //opt.className = spantemp.className;
  }
 }
 document.body.removeChild(selTemp)
 selTemp = null
}

function ajaxRequestSelect(obj,url,parameters,method,mime,oload) {
  this.req=false;
  this.url=url;
  this.parameters=parameters;
  this.method=method;
  this.oload=oload;
  this.obj=obj;

  this.sendRequest=function(){
    this.req=false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
       this.req=new XMLHttpRequest();
       if (this.req.overrideMimeType) {
          this.req.overrideMimeType(mime);
       }
    } else if (window.ActiveXObject) { // IE
       try {
          this.req=new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             this.req=new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
       }
    }
    if (!this.req) {
      alert('Cannot create XMLHTTP instance');
      return false;
    }

    if (this.obj) {
        this.obj.className+=" loading";
    }

    var self=this;

    if (this.method=='post'){
      this.req.open(this.method,this.url,true);
      this.req.onreadystatechange=function(){self.handleResponse(self);}
      this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      this.req.setRequestHeader("Content-length", this.parameters.length);
      this.req.setRequestHeader("Accept-Charset","UTF-8");
      this.req.setRequestHeader("Connection", "close");
      this.req.send(this.parameters);
    }
    else{
      this.parameters="?"+this.parameters;
      if (this.parameters.length>1) this.parameters+='&';
      this.parameters+='r='+Math.floor(Math.random()*10000);
//alert(this.url+this.parameters);
//alert(document.location.href);
	if(document.location.href.indexOf("http://www") == -1)
	      this.req.open(this.method,"http://nyitvatartas.hu/"+this.url+this.parameters,true);
	else
	      this.req.open(this.method,"http://www.nyitvatartas.hu/"+this.url+this.parameters,true);
	    this.req.onreadystatechange=function(){self.handleResponse(self);}
      this.req.send(null);
    }
  }

  this.handleResponse = function(t){
    if (t.req.readyState == 4) {
        if (t.req.status == 200) {
            //this.obj.style.backgroundColor=this.prevbg;
            if (t.obj) {
                t.obj.className=t.obj.className.replace('loading','');
            }
          ctype=t.req.getResponseHeader("Content-Type").split(";")[0];
          if (ctype=='application/xml') {
            //XML parser
          }
          else if (ctype=='text/plain' || ctype=='text/html') {
            if (t.obj!=null){
				select_innerHTML(t.obj,t.req.responseText.replace(/&/,"&"));
				//t.obj.innerHTML=t.obj.innerHTML.replace(/&amp;/,"&");
			}
            else alert(t.req.responseText);
          }
          else if (ctype=='text/javascript') {
            eval(t.req.responseText);
            //alert(t.req.responseText);
          } else {
            alert("Unknown content type!");
          }
          if (this.oload) eval(this.oload);
        } else {
            //alert("There was a problem retrieving data:\n" + t.req.statusText);
        }
      }
  }
  this.sendRequest();
}

function ajaxRequest(obj,url,parameters,method,mime,oload) {
  this.req=false;
  this.url=url;
  this.parameters=parameters;
  this.method=method;
  this.oload=oload;
  this.obj=obj;

  this.sendRequest=function(){
    this.req=false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
       this.req=new XMLHttpRequest();
       if (this.req.overrideMimeType) {
          this.req.overrideMimeType(mime);
       }
    } else if (window.ActiveXObject) { // IE
       try {
          this.req=new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             this.req=new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
       }
    }
    if (!this.req) {
      alert('Cannot create XMLHTTP instance');
      return false;
    }

    if (this.obj) {
        this.obj.className+=" loading";
    }

    var self=this;

    if (this.method=='post'){
      this.req.open(this.method,this.url,true);
      this.req.onreadystatechange=function(){self.handleResponse(self);}
      this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      this.req.setRequestHeader("Content-length", this.parameters.length);
      this.req.setRequestHeader("Accept-Charset","UTF-8");
      this.req.setRequestHeader("Connection", "close");
      this.req.send(this.parameters);
    }
    else{
      this.parameters="?"+this.parameters;
      if (this.parameters.length>1) this.parameters+='&';
      this.parameters+='r='+Math.floor(Math.random()*10000);
      this.req.open(this.method,this.url+this.parameters,true);
	    this.req.onreadystatechange=function(){self.handleResponse(self);}
      this.req.send(null);
    }
  }

  this.handleResponse = function(t){
    if (t.req.readyState == 4) {
        if (t.req.status == 200) {
            //this.obj.style.backgroundColor=this.prevbg;
            if (t.obj) {
                t.obj.className=t.obj.className.replace('loading','');
            }
          ctype=t.req.getResponseHeader("Content-Type").split(";")[0];
          if (ctype=='application/xml') {
            //XML parser
          }
          else if (ctype=='text/plain' || ctype=='text/html') {
            if (t.obj!=null) t.obj.innerHTML=t.req.responseText
            else alert(t.req.responseText);
          }
          else if (ctype=='text/javascript') {
            eval(t.req.responseText);
            //alert(t.req.responseText);
          } else {
            alert("Unknown content type!");
          }
          if (this.oload) eval(this.oload);
        } else {
            alert("There was a problem retrieving data:\n" + t.req.statusText);
        }
      }
  }
  this.sendRequest();
}

//####################################### URL encode / decode ############################

function urlencode(str){
  var ret = str;
  ret = ret.toString();
  ret = encodeURIComponent(ret);
  ret = ret.replace(/%20/g, '+');
  return ret;
}

function urldecode(str){
  var ret=str;
  if (ret){
    ret=ret.replace(/\+/g, '%20');
    ret=decodeURIComponent(ret);
    ret=ret.toString();
    return ret;
  }
  else return "";
}
