var nombreEstablecimiento, direccion;
var regexNombreEstablecimiento, regexDireccion;
var suma = 0;
var errores = new Array();
var campo;
var salida;
function error(n){
	errores.push(n);
	/*
	document.getElementById(campo).style.borderColor = "red";
	document.getElementById(campo).style.borderWidth = 1+"px";
	document.getElementById(campo).style.borderStyle = "solid";
	*/
}
function bien(){
	/*
	document.getElementById(campo).style.borderColor = "#cccc00";
	document.getElementById(campo).style.borderWidth = 1+"px";
	document.getElementById(campo).style.borderStyle = "solid";
	document.getElementById(campo).style.color = "#cccc00";
	*/
	suma ++;	
}
function limpiaErrores(){
	errores = new Array();
}

function validaCliente(){
	suma = 0; 
	/*Validacion, 18 = ok*/
	validaEmail();
	validaCodigo();
	
	if (suma == 2){//Los campos que valida son 16 si no error.
		document.getElementById("salida").style.display = "none";//Oculto la salida
		document.getElementById("form").action = "ingresar2.php";
		document.getElementById("form").submit();	
	}else{
		salida = "<b>Atención debe revisar los siguientes errores:</b><br/>";
		for(var m=0;m<errores.length;m++){
			salida =  salida + (m+1) + ". " + errores[m] + "<br/>";
		}
		limpiaErrores();
		document.getElementById("salida").style.display = "";
		//document.getElementById("salida").firstChild.firstChild.nodeValue = salida;
		document.getElementById("salida").firstChild.innerHTML = salida;
	}
}
/*-----------------------------------------------------------------------------------*/
function validaEmail(){
	campo = 'email';
	email = document.getElementById(campo).value;
	regexEmail = "^([0-9a-zA-Z\xF1\x2D]+(?:[._][0-9a-zA-Z\xF1\x2D]+)*)\@([0-9a-zA-Z\xF1\x2D]+(?:[._-][0-9a-zA-Z\x2D]+)*(?:[.][0-9a-zA-Z]{2,3}))$";
	if (email.match(regexEmail)!=null){
		bien();
	}else{
		error('Debe revisar su E-mail');
	}
}
function validaCodigo(){
	campo = 'codigo';
	direccion = document.getElementById(campo).value;
	regexDireccion = "^[A-Za-z0-9,.\xBA\x20\xE1\xE9\xED\xF3\xFA\xF1]+$";
	if (direccion.match(regexDireccion)!=null){
		bien();
	}else{
		error('Debe revisar su Código de acceso');
	}
}

