function GetHttpRequest(){
     var thePage = false
    if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
    thePage = new XMLHttpRequest()
        } else if (window.ActiveXObject){ // pero si es IE
        try {
    thePage = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e){ // en caso que sea una versión antigua
        try{
        thePage = new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch (e){}
        }
        }
        else
        return false
        return thePage;
    }
 


 
function makePOSTRequest(parameters, containerId,rp){
     var rand   = Math.random(9999);         
    var url = rp+parameters;
    var thePage = GetHttpRequest();
    if(thePage=== false)
        return;
    	document.getElementById(containerId).innerHTML="<p align='center'>Enviando datos<br/><img src='%RootPath%/Templates/_css/_img/preloader.gif'></p>";
        thePage.onreadystatechange=function(){ // función de respuesta
        	LoadPostView(thePage, containerId)
    	}
        
        
      thePage.open('GET', url, true);
      /*thePage.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      thePage.setRequestHeader("Content-length", parameters.length);
      thePage.setRequestHeader("Connection", "close");*/
      thePage.send(null);
      //alert(url);
		//document.write(url);     
		
		
		   
     }

    // todo es correcto y ha llegado el momento de poner la información requerida
    // en su sitio en la pagina xhtml
    function LoadPostView(thePage, containerId){
		if (thePage.readyState == 4 && (thePage.status==200 || window.location.href.indexOf("http")==-1))
			document.getElementById(containerId).innerHTML=thePage.responseText
		
     }
     
     
    function getRec(obj, getstr){
 
         for(i=0; i<obj.length; i++){
        
         if (obj[i].tagName == "INPUT") {
            if (obj[i].type == "text" || obj[i].type == "hidden") {
               getstr += obj[i].name + "=" + encodeURI( obj[i].value ) + "&";
            }
            if (obj[i].type == "checkbox") {
               if (obj[i].checked) {
                  getstr += obj[i].name + "=" + encodeURI( obj[i].value ) + "&";
               } else {
                  getstr += obj[i].name + "=&";
               }
            }
            if (obj[i].type == "radio") {
               if (obj[i].checked) {
                  getstr += obj[i].name + "=" + encodeURI( obj[i].value ) + "&";
               }
            }
         }   
         else
         if (obj[i].tagName == "SELECT") {
            var sel = obj[i];
            getstr += sel.name + "=" + encodeURI(sel.options[sel.selectedIndex].value) + "&";
         }else
         if (obj[i].tagName == "TEXTAREA") {
            
            getstr += obj[i].name + "=" +  encodeURI( obj[i].value )+ "&";
         }
         
         /*else{
         if(obj[i].childNodes && obj[i].childNodes.length>0)
            getstr = getRec(obj[i],getstr);
         }*/
         
      }
      return getstr;
    }


 function get(obj,containerId,rp) {
      var getstr = "?";
     getstr = getRec(obj,getstr);
     
      makePOSTRequest( getstr,containerId, rp);
   }


 
