function jsHcSendForm(URL,form,onRequest,Method){
    var json = new Object();
    for(var i=0;i<form.length;i++){       
        if(form[i].type)
            switch( form[i].type ){
                case 'checkbox':
                    if(form[i].checked==false)
                        break;
                default:
                    json[form[i].name]=form[i].value;
            }
    }
   var jshc = new jsHttpConexion(URL,((Method!=undefined)?json:{}),((Method==undefined)?json:{}),onRequest);
   jshc.form=form;
   jshc.send();
}

function jsHttpConexion(URL,GetVars,PostVars,onRequest){ 
	this.httpC=httpRequest();
    this.PostVars=(PostVars!=undefined)?PostVars:"";
    this.GetVars=(GetVars!=undefined)?GetVars:"";
    this.URL=URL;
    this.getHttpCon=function(){
        return this.httpC;
    }
    this.getUrl=function(){    
        return this.URL+(
            (this.URL.indexOf("?")==-1)?"?":""
            )+this.jSon2UrlEncode(this.GetVars);
           
    }
    this.getVarsPost = function(){
        return this.jSon2UrlEncode(this.PostVars);
    }
    this.jSon2UrlEncode=function(jSon,prefijo){
        var url="";
        for(i in jSon){
            if((typeof jSon[i])=='object'){
                if(isArray(jSon[i]))
                    url+= ((prefijo)?prefijo:"") + this.jSon2UrlEncode(jSon[i],i+"[]")+"&";
                else
                    ;//pediente soporte para JSON hijos y Arreglos Bidimencionales
            }else
                url+=((prefijo)?prefijo:escape(i))+'='+escape(jSon[i])+"&";
        }        
        return url.substr(0,url.length-1);
    }
    this.onRequest=onRequest;
    this.onError=function(){
        //jsHC.status
        alert("Error:"+this.httpC.status);
    }
    this.send=function(){
        var evitaCache=Math.floor(Math.random() * (100000000000000));
        var url = this.getUrl()+((this.getUrl().indexOf('?')==-1)?"?":"&")+evitaCache;
        if(this.getVarsPost()){
            this.httpC.open("POST",url,true);
            this.httpC.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); //cabeceras del post
            this.httpC.send(this.getVarsPost());
        }else{
            this.httpC.open("GET",url,true);
            this.httpC.send();
        }
        //xml.send(variables_aEnviar); //enviar variables
        var jsHttpConexion=this;
        var httpC=this.httpC;
        this.httpC.onreadystatechange=function(){
          //  var onError=this.onError;        
            if (httpC.readyState==4){                
                if(httpC.status==200){                    
                    jsHttpConexion.onRequest(jsHttpConexion);
                }else{                    
                    jsHttpConexion.onError();
                }
            }
    }

    this.getRT = function(){
        return this.httpC.responseText;
    }
   
	//xml.send(variables_aEnviar); //enviar variables
	//xml.onreadystatechange=function() {
	//
	//	}
	}
	return;
}

/*******************************************************/
function httpRequest(){
    try {
	    objXML = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
	    try {
		    objXML = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (E) {
		    objXML = false;
	    }
    }
    if (!objXML && typeof XMLHttpRequest!='undefined') {
	    objXML = new XMLHttpRequest();
    }
    return objXML;
}
/*****************************************************/
function isArray(testObject) {
    return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

/*
function respuesta(jsHC){
 //   alert(jsHC.getRT());
    eval(jsHC.getRT());
    alert(ar.nombre);
}

new jsHttpConexion(
    "proceso.php",
    {'action':"contacto",'do':"send"},
    {nombre:'pako',email:'wario&diaz@gmail.com','id':new Array(1,6)},
    respuesta
).send();
*/

//alert(httpc.getUrl());
//alert(httpc.getVarsPost();
//alert(httpc.getHttpCon());
