/************************************************************************************************************
http://www.cristalab.com/tutoriales/enviar-datos-por-post-y-get-en-ajax-en-una-funcion-c237l/

como enlace
<a href="javascript:ajax_PostContent('http://www.misitio.com/mipagina.php','variableenviada=enviaste get,'','micapa')">Mi Enlace GET</a>

como boton
<form name="Miformulario" onSubmit="return false">

<input name="Submit" type="submit" value="Enviar" 
onClick="recibeid('http://www.misitio.com/mipagina.php',
'variablegetenviada=enviaste get','variablepostenviada1='+
Miformulario.campoparalavariablepostenviada1.value+'
&variablepostenviada2='+Miformulario.campoparalavariablepostenviada2.value+
'','micapa')" >

</form>

Modificado por jorge mario saldarriaga

************************************************************************************************************/
function objetus(file) {
    xmlhttp=false;

    this.AjaxFailedAlert = "Su navegador no soporta las funciónalidades de este sitio y podria experimentarlo de forma diferente a la que fue pensada.  Por favor habilite javascript en su navegador para verlo normalmente.\n";
    this.requestFile = file;
    this.encodeURIString = true;
    this.execute = false;
    if (window.XMLHttpRequest) { 
        this.xmlhttp = new XMLHttpRequest();
        if (this.xmlhttp.overrideMimeType) {
            this.xmlhttp.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                this.xmlhttp = null;
            }
        }
        if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
            this.xmlhttp = new XMLHttpRequest();
            if (!this.xmlhttp){
                this.failed = true; 
            }
        } 
    }
    return this.xmlhttp ;
}



//function recibeid(_pagina,valorget,valorpost,capa){
	function ajax_PostContent(preloader,capa,_pagina,valorpost,valorget){
    //alert('estoy aqui '+_pagina);
	ajax=objetus(_pagina);
    if(valorpost!=""){
        ajax.open("POST", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);
    } else {
        ajax.open("GET", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);
    }
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1){
            //document.getElementById(capa).innerHTML = "<img src='loadingcircle.gif' align='center'> Aguarde por favor...";
				document.getElementById(preloader).innerHTML = '<div align="center"><img src="graficas/gifs/pixel_transparente.gif" width="20"  /></div>';
        }
        if (ajax.readyState==4) {
			document.getElementById(preloader).innerHTML = '';
            if(ajax.status==200)
            {document.getElementById(capa).innerHTML = ajax.responseText;}
            else if(ajax.status==404)
            {
                capa.innerHTML = "La direccion no existe";
            }
            else
            {
                capa.innerHTML = "Error: ".ajax.status;
            }
        }
    }
    if(valorpost!=""){
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
        ajax.send(valorpost);
	
    } else {
        ajax.send(null);
    }
} 




