
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
* Versao: 2.1 - 04/09/2007
* Autor: Micox - Náiron José C. Guimaraes - 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.toLowerCase().indexOf("<option")<0){//se nao é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().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
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}
// inizializzo le funzioni basilari di AJAX

var myRequest = null;

function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
  } catch(e) {
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}

function myHandler() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
        e = document.getElementById("provincia");
		select_innerHTML(e,myRequest.responseText);
       
    }
}

function show_provincia (regione){
     var e = document.getElementById("provincia");
    myRequest = CreateXmlHttpReq(myHandler);
    myRequest.open("GET","provincia.php?regione="+escape(regione));
    myRequest.send(null);
    
}



function myHandler_comune() {
    if (myRequest_comune.readyState == 4 && myRequest_comune.status == 200) {
        e_comune = document.getElementById("comune");
		select_innerHTML(e_comune,myRequest_comune.responseText);
       
    }
}

function show_comune (comune){
     var e_comune = document.getElementById("comune");
    myRequest_comune = CreateXmlHttpReq(myHandler_comune);
    myRequest_comune.open("GET","comune.php?provincia="+escape(comune));
    myRequest_comune.send(null);
    
}







function myHandler_SEARCH() {
    if (myRequest_SEARCH.readyState == 4 && myRequest_SEARCH.status == 200) {
        e_SEARCH = document.getElementById("provincia_SEARCH");
		select_innerHTML(e_SEARCH,myRequest_SEARCH.responseText);
       
    }
}

function show_provincia_SEARCH (regione){
     var e_SEARCH = document.getElementById("provincia_SEARCH");
    myRequest_SEARCH = CreateXmlHttpReq(myHandler_SEARCH);
    myRequest_SEARCH.open("GET","provincia.php?regione="+escape(regione));
    myRequest_SEARCH.send(null);
    
}


function check_num(val,tex){
if (isNaN(parseInt(val))) {
   document.getElementById(tex).value="";
   }}
 
function show_riga(campo){
if(document.getElementById(campo).checked){
document.getElementById(campo+"_RIGA").style.display="";
}else document.getElementById(campo+"_RIGA").style.display="none";
}
function show_zf (toshow,tohide){
document.getElementById("riga-"+toshow).style.display="";
document.getElementById("riga-"+tohide).style.display="none";    
}


