var url_img_contraida = "/img/arrow_right.png";
var url_img_expandida = "/img/arrow_down.png";
var img_title_contraida = "Mostrar";
var img_title_expandida = "Ocultar";
//Función para procesar una petición XMLHttpRequest
function validate_AJAX(serverPage, str, obj){
	//Obtener el objeto XMLHttpRequest a utilizar
	xmlhttp = getxmlhttp();
	var icono = document.getElementById(obj + "Icono");
	xmlhttp.open("POST", serverPage, true);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == READY_STATE_LOADING) {
		}
		else
		if (xmlhttp.readyState == READY_STATE_COMPLETE) {
			if (xmlhttp.status == READY_STATE_LOADED) {
				if (xmlhttp.responseText !== "") {
					//alert(xmlhttp.responseText);
					if (xmlhttp.responseText != 1) {
						icono.className = "iconovalidar iconoerroneo";
					}
					else {
						icono.className = "iconovalidar iconovalido";
					}
				}
			}
		}
	};
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	xmlhttp.send(str);
}

function showEMsg(thename){
	document.getElementById(thename + "Icono").className = "iconovalidar iconoerroneo";
}

function clearEMsg(thename){
	if(thename == "chkMReadTerms"){
		document.getElementById(thename).className = "campo";
	}
	document.getElementById(thename + "Icono").className = "iconovalidar iconovalido";
}

function verify_input(objID, objName, objValue){
	var inputID = document.getElementById(objID);
	var serverPage = "lib/form/process.php";
	var checks = document.getElementsByTagName("input");
	//alert(checks.length);
	if(objID== "chkMReadTerms"){
		checks[17].checked = inputID.checked ? true : false;
		objValue = checks[17].checked;
	}	
	var str = "verify=1&" + objName + "=" + objValue;
	//alert(checks[17].checked);
	if (objValue === null || objValue.length === 0 || (/^\s+$/.test(objValue))) {
		showEMsg(objName);
	}
	else {
		clearEMsg(objName);
		validate_AJAX(serverPage, str, objID);
	}
}
function desplegarContraer(img_src, obj){
	var img = document.getElementById(img_src);
	var elElemento = document.getElementById(obj);
	if (elElemento.className == 'eltovisbe') {
		elElemento.className = 'eltoculto';
		img.setAttribute("src", url_img_contraida);
		img.setAttribute("title", img_title_contraida);
	}
	else {
		elElemento.className = 'eltovisbe';
		img.setAttribute("src", url_img_expandida);
		img.setAttribute("title", img_title_expandida);
	}
}
