
function validatecampo(campo){      // return true if all is well
	var valor = 0 ;
	var retorna = 0;

	var v = campo.validator;       // get validator, if any
	if(v) 
	{                 // no validator property, skip
		if (v == "fechaPat"){
			var thePat = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/;
			// matches fecha en formato dd/mm/aaaa y dd/mm/aa
		}else if(v == "urlPat"){
			var thePat = /(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;  
		}else
			var thePat = PatternsDict[v];     // select the validating regular expr
	
		valor = campo.value;
		var gotIt = thePat.test(valor);   // run it on value of elArr[i]
		var nomstr = campo.nombre;
		if(!nomstr) str = "";
		if(!gotIt && !(valor == "" || valor == null)){
			var str = campo.alerta;
			if(!str) str = "Revise los contenidos de los campos";
			
			// alert("Error en el valor del Parámetro : " + nomstr + ". Fallo de concordancia de la regla " + v + " con el valor :" + campo.value); return false;}
			alert("VALOR =" + valor + " , CAMPO : " + nomstr + ". AVISO : " + str ); 
			campo.value = "";
			return false;
		}
		
	}
  	var sigue = campo.obl;
  		
  	// return false;
  	if(sigue == "TRUE" && (valor == "" || valor == null)){
  		alert("El campo " + nomstr + " es obligatorio")
  		return false;
	}

	return true;
}


function validateForm(theForm){      // return true if all is well
 var elArr = theForm.elements;       // get all elements of the form into array
 var valor = 0 ;
 var retorna = 0;
 for(var i = 0; i < elArr.length; i++)
  with(elArr[i]){                    // for each element of the form...
   	var v = elArr[i].validator;       // get validator, if any
   	if(!v) continue;                  // no validator property, skip
	if (v == "fechaPat"){
		var thePat = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/;
		// matches fecha en formato dd/mm/aaaa y dd/mm/aa
	}else if(v == "urlPat"){
		var thePat = /(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;  
	}else
		var thePat = PatternsDict[v];     // select the validating regular expr
	
   valor = elArr[i].value;
   var gotIt = thePat.exec(valor);   // run it on value of elArr[i]
   var nomstr = elArr[i].nombre;
   if(!nomstr) str = "";
   if(!gotIt  && !(valor == "" || valor == null)){
		var str = elArr[i].alerta;
		if(!str) str = "Revise los contenidos de los campos";
		
		// alert("Error en el valor del Parámetro : " + nomstr + ". Fallo de concordancia de la regla " + v + " con el valor :" + value); return false;}
		alert("VALOR =" + valor + " , CAMPO : " + nomstr + ". AVISO : " + str ); 
		elArr[i].value = "";
   }
   var sigue = elArr[i].obl;
  
  // return false;
   if(sigue == "TRUE" && (valor == "" || valor == null)){
  		alert("El campo " + nomstr + " es obligatorio")
   		retorna = 1;
   	}
  } 
  if(retorna == 1)
  	return false;
  	
  return true;
}



var PatternsDict = new Object();

PatternsDict.zipPat = /^\d{5}(-\d{4})?$/;
  // matches zip codes

PatternsDict.eurosPat = /^\d{1,3}(\.\d{3})*(\,\d{2})?$/;
  // matches 14.281.545,45 or ...
  
PatternsDict.pesetasPat = /^\d{1,3}(\.\d{3})*$/;
  // matches 14.281.545 or ...

PatternsDict.timePat = /^\d{2}:\d{2}$/;
  // matches 12:34 but also 75:83

PatternsDict.timePat2=/^([0-1][0-9]|[2][0-3]):([0-5][0-9])$/;
  // matches 5:04 or 12:34 but not 75:83
  
PatternsDict.textoPat = /\w*([-,. ])?/;
  // matches texto en general y algunos simbolos
  
PatternsDict.texto1Pat = /^\w+/;
  // matches texto en general y el simbolo -
  
PatternsDict.texto2Pat = /^(\w)([a-zA-Z0-9\-\_\ \,\.\á\é\í\ó\ú\ñ\Ñ\@\Ø]*)/;
  
PatternsDict.texto3Pat = /(^\w+)/;
  // matches empieza con texto y - no inserta caract especiales
 
PatternsDict.numeroenteroPat = /^[-+]?\d*$/;
  // matches digitos

PatternsDict.emailPat = /^.+\@.+\..+$/;
  // matches email permisivo

PatternsDict.email1Pat = /^([\w-_]+\.)*[\w-_]+\@ ([\w-_]+\.)+[a-zA-Z] {2,3}$/;
  // matches email mas restrictivo
  
PatternsDict.email2Pat =  /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 

PatternsDict.telefPat = /^(\w)([0-9\-\ \,\.\(\)])+/;



PatternsDict.passwordPat = /^[a-zA-Z]\w{3,14}$/;

