
function limitarCaracteres(field, count, max) {
if (field.value.length > max)
field.value = field.value.substring(0, max);
else
document.getElementById(count).innerHTML = max - field.value.length;
}

function ventana(URL,nombre,ancho,alto) 
	{
		x = (screen.width - ancho)/2
		y = (screen.height - alto)/2
		eval("page = window.open(URL, nombre, 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=1,width="+ancho+",height="+alto+",left=" + x + ",top = " + y + "');");
		
	}

function NuevoAjax(){
        var xmlhttp=false;
        try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                        xmlhttp = false;
                }
        }

        if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}

function getAjax (url, div){
        var contenedor = document.getElementById(div);
        ajax=NuevoAjax(); 
        //peticionamos los datos, le damos la url enviada desde el link
        ajax.open("GET", url, true); 
        ajax.onreadystatechange=function(){
                if(ajax.readyState==1){

            contenedor.innerHTML = "<div align='center'style='float: right; width: 225px; margin: 60px 0;'><img src='images/loading.gif' width='30' height='30' /><br />Cargando...</div>";

            }else if(ajax.readyState==4){
                        if(ajax.status==200){
                                //mostramos los datos dentro del contenedor
                                contenedor.innerHTML = ajax.responseText
                        }else if(ajax.status==404){
                                contenedor.innerHTML = "La página no existe";
                        }else{
                                //mostramos el posible error
                                contenedor.innerHTML = "Error:"+ajax.status; 
                        }
                }
        }
        ajax.send(null);
}

function urlDecode(str){
  	str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
