var hayerrores=false;
var semaforo=false;
var mirocaptcha=false;

//VERIFICAR EL FORMULARIO ENTERO
function verificaform(){
	hayerrores=false;
	semaforo=false;
	document.form1.captcha.focus();
	document.form1.captcha.blur();
	setTimeout("errorono();", 500);
	return false;
}

function errorono(){
	if ((semaforo==false) && (hayerrores==true)){
			alert("Revise los campos marcados en rojo.");
			return false;
	}else{
		if (semaforo){
			if (hayerrores){
				alert("Revise los campos marcados en rojo.");
				return false;
			}else{
				document.form1.submit();
				return true;
			}
		}else{
			setTimeout("errorono();", 500);
		}
	}
}
 
function vcaptcha(esto,divi,div){
	if (mirocaptcha ==false){
		mirocaptcha=true;
		var ajax = new ajaxFunction();
		
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4) {
				if(ajax.responseText=='ok'){
					esto.style.borderColor="#7f9db9";
					WriteLayer(divi,null,'<img src="/imagenes/register-success.gif" style="vertical-align: middle;">');
					WriteLayer(div,null,'<br>');
				}else{
					if(ajax.responseText=='NoSession'){
						esto.style.borderColor="#FF0000";
						WriteLayer(divi,null,'<img src="/imagenes/register-error.gif" style="vertical-align: middle;">');
						WriteLayer(div,null,'Debe bajar la seguridad de su navegador.');
						hayerrores=true;
						alert("Debe bajar la seguridad de su navegador.");
					}else{
						esto.style.borderColor="#FF0000";
						WriteLayer(divi,null,'<img src="/imagenes/register-error.gif" style="vertical-align: middle;">');
						WriteLayer(div,null,'No es el texto de la imagen');
						hayerrores=true;
					}
				}
				mirocaptcha=false;
				semaforo=true;
			}
		}
		
		ajax.open("GET","/usuarios/includes/validarcaptchau.php?captcha="+esto.value+"&tipo="+tipocaptcha,true);
		ajax.send(null);
	}
}
 
function ajaxFunction()
  { var xmlHttp;
  try { xmlHttp=new XMLHttpRequest();return xmlHttp; }
  catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");return xmlHttp; }
  catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");return xmlHttp; }
  catch (e) { alert("Your browser does not support AJAX!");return false; }
}}}

function WriteLayer(ID,parentID,sText) {
 if (document.layers) {
   var oLayer;
   if(parentID){
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
   }else{
     oLayer = document.layers[ID].document;
   }
   oLayer.open();
   oLayer.write(sText);
   oLayer.close();
 }
 else if (parseInt(navigator.appVersion)>=5&&navigator.
appName=="Netscape") {
   document.getElementById(ID).innerHTML = sText;
 }
 else if (document.all) document.all[ID].innerHTML = sText
}

function escribircaptcha(){
	dv=new Date();
	document.write('<img src="captchau.php?text='+dv.getTime()+'&tipo='+tipocaptcha+'" alt="captcha" width="100" height="30" style="margin-bottom:3px;vertical-align:text-bottom;" /><br />');
}

//precarga de imagenes
imagenok = new Image(); imagenok.src = "/imagenes/register-error.gif";
imagenfail = new Image(); imagenfail.src = "/imagenes/register-success.gif";
