var isIE = false;
var req;
var curComboObj;// setto  la  variabile  che  mi  crea  la  combo  obj

function loadXMLDoc(Id,elem) {


  document.body.style.cursor="wait";
  var select = document.getElementById(curComboObj);
  var Idsez='';
      if(document.forms[0].Id_sez)Idsez="&Id_sez="+document.forms[0].Id_sez.value
	  Idsub="&Id_sub="+elem.name
      url="dbcms/cmsv2/includes/xmlHTTP.php?Id="+Id+"&IdCombo="+curComboObj+Idsez+Idsub
	
	  clearTopicList();
      appendToSelect(select,'',document.createTextNode("Please Wait"));
   if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
  } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
		    req.onreadystatechange = processReqChange;
            req.open("GET",url, true);
            req.send();
        }
   }
 }


function processReqChange() {

      if (req.readyState == 4) {
         if (req.status == 200) {
            clearTopicList();
            buildTopicList();
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
	
}

function loadDoc(evt,ComboObj) {
    curComboObj=ComboObj

    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
           
                if (elem.selectedIndex > 0) {
                    loadXMLDoc(elem.options[elem.selectedIndex].value,elem);
                }	
           
           
        }
    }
}


function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
         result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;
        }
    } else {
        return "n/a";
    }
}

function clearTopicList() {
    var select = document.getElementById(curComboObj);
    while (select.length > 0) {
        select.remove(0);
    }
	
}


function appendToSelect(select, value, content) {
    var opt;
    opt = document.createElement("option");
    opt.value = value;
    opt.appendChild(content);
    select.appendChild(opt);
}

function buildTopicList() {
    
    var select = document.getElementById(curComboObj);
    var items = req.responseXML.getElementsByTagName("item");
	    appendToSelect(select,'',document.createTextNode("Please Select"));
	    for (var i = 0; i < items.length; i++) {
      ind=getElementTextNS("", "a", items[i], 0)
      valore=document.createTextNode(getElementTextNS("", "b", items[i], 0))
      appendToSelect(select,ind,valore);
		  
	}
	
	
	if(document.getElementById('sub_1'))document.getElementById('sub_1').style.cursor="auto";
	document.body.style.cursor="auto";
}






 
 function loadTxt(Id) {
   url="/crm/report/responseTxt.php?Id="+Id+"&IdCombo="+curComboObj
   if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqTxt;
        req.open("POST", url, true);
        req.send(null);
   } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
		    req.onreadystatechange = processReqTxt;
            req.open("POST",url, true);
            req.send();

        }
   }
  
}



function processReqTxt() {
   if (req.readyState == 4) {
       if (req.status == 200) {verificaObj();}
	   else {
              alert("There was a problem retrieving the TxT data:\n" + req.statusText);
       }
   }
}



 





 

 
 












