// JavaScript Document

/*var ALERT_TITLE = "Alerta!";
var ALERT_BUTTON_TEXT = "Aceptar";

window.alert = function(txt) {
		createCustomAlert(txt);
}*/

function llamarasincrono(url, id_contenedor, valor, estado){
    var pagina_requerida = false;
   
    if (window.XMLHttpRequest){
        // Si es Mozilla, Safari etc
        pagina_requerida = new XMLHttpRequest();
		
    } else if(window.ActiveXObject){
        // pero si es IE

        try {
            pagina_requerida = new ActiveXObject ("Msxml2.XMLHTTP");
        }
        catch(e){
            // en caso que sea una versi�n antigua
            try{
                pagina_requerida = new ActiveXObject ("Microsoft.XMLHTTP");
            }
            catch(e){
                if (!xmlhttp && typeof XMLHttpRequest!="undefined") xmlhttp=new XMLHttpRequest();
            }
        }
    } 
    else
        return false;
	
	//pagina_requerida = nuevoAjax();
    pagina_requerida.onreadystatechange = function(){
        // funci�n de respuesta
	cargarpagina(pagina_requerida, id_contenedor);
    }
    
    pagina_requerida.open('POST', url, true); // asignamos los m�todos open y send
	
    pagina_requerida.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    pagina_requerida.send(valor);
}
// todo es correcto y ha llegado el momento de poner la informaci�n requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
    if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == -1)){
	document.getElementById(id_contenedor).innerHTML = pagina_requerida.responseText;
    }
}

function valida_textF(tam_min, tam_max, tipo, elem, nombre){
	
    objeto = document.getElementById("txt_" + elem);
	
    if(tam_min <= 2){
	if(objeto.value.length < tam_min)
            return "El campo " + nombre + " es obligatorio \n";
    }
    else{
	if(objeto.value.length < tam_min)
            return "El campo " + nombre + " es obligatorio \n" + "El campo " + nombre + " debe tener minimo " + tam_min + " caracteres\n";
    }
	
    if(objeto.value.length > tam_max)
	return "El campo " + nombre + " debe contener menos de " + tam_max + " caracteres\n";	
	
    if(objeto.value.length > 0)
	switch(tipo){
            case 'text':
                alpha = /^[\s\ta-z\W.]+(\s+[a-z\W\s\t.]+)*$/i;
		/* /^[\s\ta-z������������.]+(\s+[a-z������������\s\t.]+)*$/i; */
		if(!alpha.test(objeto.value))
                    return "El campo " + nombre + " solo debe contener letras \n";
		else
                    return "";
		break;
									
            case 'alpha_num':
                alpha_num = /^[\s\w\W]+(\s+[\w\W]\s+)*$/i;
		if(!alpha_num.test(objeto.value))
                    return "El campo " + nombre + " no admite signos de puntuacion \n";
		else
                    return "";
		break;
						
            case 'num':
                num = /^[0-9]+$/;
		if(!num.test(objeto.value))
                    return "El campo " + nombre + " solo admite numeros \n";
		else
                    return "";
		break;
					
            case 'phone':
                phone = /^(([\s0-9\s]{5,10}$)|([\s0-9\s]{7,10}$))$/i;
		if(!phone.test(objeto.value))
                    return "El campo " + nombre + " no admite espacios, guiones � caracteres \n";
		else
                    return "";
		break;
						
            case 'mail':
                //mail = /^[a-z]+([\._\-a-z0-9]+)*@[a-z]+(\.[a-z]{2,}){1,3}$/i;
		mail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
						
		if(!mail.test(objeto.value))
                    return "El formato del campo " + nombre + " es incorrecto \n";
		else
                    return "";
		break;
        }
	else
	return "";		
}

//alert modificado

/*function createCustomAlert(txt) {
	// shortcut reference to the document object
	d = document;

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	//mObj.style.height = document.documentElement.scrollHeight + "px";

	// create the DIV that will be the alert 
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
	msg.appendChild(d.createTextNode(txt));

	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { removeCustomAlert();return false; }

	
}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}*/







