// JavaScript Document
var peticion = false; 
if (window.XMLHttpRequest) {
      peticion = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
peticion = new ActiveXObject("Microsoft.XMLHTTP");
peticion.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}

function ObtenerDatos(datos,divID) { 
if(peticion) {
     var obj = document.getElementById(divID); 
     peticion.open("POST", (datos));

     peticion.onreadystatechange = function()  { 
          if (peticion.readyState == 4) { 
			
			obj.innerHTML = (peticion.responseText); 

		   if (Left(datos,14) == "agregar_grupos" || Left(datos,64) == "elimino_registro.asp?id=id_mm_gdp_personas&tabla=mm_gdp_personas" )
		   {
			ObtenerDatos('listar.asp','div_lista');   
		
		    }
			if (Left(datos,23) == "agregar_comments_cursos" )
		   {
			document.getElementById('comentario').value='';
			ObtenerDatos('comentarios_cursos.asp','div_comentarios');   
		
		    }
			if (Left(datos,10) == "pendientes" )
		   {
			ObtenerDatos('enviados.asp','div_enviados');  
		
		    }
			
			if (Left(datos,12) == "agregar_news" )
		   {
			document.getElementById('asunto').value = '';
			document.getElementById('titulo').value = '';
			ObtenerDatos('pendientes.asp','div_pendientes');
		
		    }
 			if (Left(datos,42) == "elimino_registro.asp?id=id_news&tabla=news" )
		   {
			ObtenerDatos('pendientes.asp','div_pendientes');  
		
		    }
			if (Left(datos,58) == "elimino_registro.asp?id=id_content_news&tabla=content_news" )
		   {
		    var idx = querySt("id");
		   
			ObtenerDatos('lista_contenido_news.asp?id='+idx,'div_pendientes');  
		
		    }
			
			
          } 
     }
peticion.send(datos); 
}
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
