function AJAXConn(sDestino, sCargando)
{
    var xmlhttp, bCompleto = false;

    try { 
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    }
    catch (excepcion) { 
        try { 
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
        }
        catch (excepcion) { 
            try { 
                xmlhttp = new XMLHttpRequest(); 
            }
            catch (excepcion) { 
                xmlhttp = false; 
            }
        }
    }
    if (!xmlhttp) return null;

    this.connect = function(sURL, sMetodo, sVars,bscripts)    {
        if (!xmlhttp) return false;
        bCompleto = false;
        sMetodo = sMetodo.toUpperCase();

        try {
              if (sMetodo == "GET") {
                xmlhttp.open(sMetodo, sURL+"?"+sVars, true);
                sVars = "";
              }
              else {
                xmlhttp.open(sMetodo, sURL, true);
                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
              }
              
              xmlhttp.onreadystatechange = function(){
                //    Estado del Objeto:    //
                ST_UNINITIALIZED     = 0;
                ST_LOADING            = 1;
                ST_LOADED            = 2;
                ST_INTERACTIVE        = 3;
                ST_COMPLETE            = 4;

/*                if (xmlhttp.readyState == ST_LOADING) {
                    document.getElementById(sDestino).innerHTML = sCargando;
                } */

                if (xmlhttp.readyState == ST_COMPLETE && !bCompleto) {
                    bCompleto = true;
                   /* var str = xmlhttp.responseText;
                    document.getElementById(sDestino).innerHTML = str; */
                    
/* version1                      
                    document.getElementById(sDestino).innerHTML =  xmlhttp.responseText.tratarResponseText();
*/                    
/* version 2 */                    
if(bscripts)
{
var scs=xmlhttp.responseText.extractScript();    //capturamos los scripts
document.getElementById(sDestino).innerHTML=xmlhttp.responseText.stripScript();    //eliminamos los scripts... ya son innecesarios
scs.evalScript();       //ahora si, comenzamos a interpretar todo
/* version 3
ejecutar archivos leidos tipo: <script type='text/javascript' src="algo.js"></script>
var scs=myAjax.responseText.extractScript();    //capturamos los scripts
        myDivUoTroLugar.innerHTML=myAjax.responseText
        scs.evalScript();       //ahora si, comenzamos a interpretar todo  
*/                      
}
else
{
 document.getElementById(sDestino).innerHTML=xmlhttp.responseText;  
}                    
                    
                     /* document.getElementById(sDestino).innerHTML = str.substr(0,18); */
                    /* document.getElementById(sDestino).innerHTML = xmlhttp.responseText;  */
                }
            };
            xmlhttp.send(sVars);
        }   
        catch(excepcion) { 
            return false; 
        }
        return true;
    };
  return this;
}

 var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
        /**
        * Eval script fragment
        * @return String
        */
        String.prototype.evalScript = function()
        {
                return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
        };
        /**
        * strip script fragment
        * @return String
        */
        String.prototype.stripScript = function()
        {
                return this.replace(new RegExp(tagScript, 'img'), '');
        };
        /**
        * extract script fragment
        * @return String
        */
        String.prototype.extractScript = function()
        {
                var matchAll = new RegExp(tagScript, 'img');
                return (this.match(matchAll) || []);
        };
        /**
        * Eval scripts
        * @return String
        */
        Array.prototype.evalScript = function(extracted)
        {
                var s=this.map(function(sr){
                         var sc=(sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
                         if(window.execScript){
                              window.execScript(sc);
                         }
                        else
                       {
                           window.setTimeout(sc,0);
                        }
                });
                return true;
        };
        /**
        * Map array elements
        * @param {Function} fun
        * @return Function
        */
        Array.prototype.map = function(fun)
        {
                if(typeof fun!=="function"){return false;}
                var i = 0, l = this.length;
                for(i=0;i<l;i++)
                {
                        fun(this[i]);
                }
                return true;
        };
        
function getWindowHeight()
{
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth()
{
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}        
             
