<!--

/*

************************************************************
***         ANUNZIA SOLUCIONS TECNOLÒGIQUES, S.L.        ***
***                                                      ***
*** /e. anunzia@anunzia.com          /w. www.anunzia.com ***
************************************************************

1er Dígito: TIPO DE INPUT

T: Text, Password, TextArea
S: Select
C: Checkbox
R: RadioButon
H: Hidden
B: Button
X: Archivo

NOTA: Los tipo hidden y los button solo necesitan este prefijo.

2o Dígito: NECESIDAD DE INPUT

Y: Si es un campo imprescindible.
N: Si es un campo opcional o innecesario.

3er Dígito: COMPROVACIÓN U OPERACIÓN A APLICAR EN UN INPUT

I: Es entero?
F: Es un float?
A: Es un alphanumeric?
D: Es una fecha?
H: Es una hora?
E: Es un e-email?
W: Es una URL?
D: Es un Documento de texto (.doc,.txt,.htm,.html)?
I: Es un Documento de imagen (.gif,.jpeg,.jpg)?
S: Es un Documento de sonido (.wav,.mid,.mod,.mp3,.ra)?
V: Es un Documento de video (.avi,.mov,.mpg,.mpeg,.ram,.rm)?
C: Custom por el programador, la operación se deberá llamar filterNOMBRECAMPO.
   A esta se le pasara el campo del form en cuestión, no el value, todo.
   Solo es valida para campos de texto.
N: Ninguna operación.

4o Dígito: MENSAJE DE ERROR

Y: Utiliza un msj de error genérico.
C: Utiliza un texto propio que deberá llamarse tipo_error NOMBRECAMPO + LETRAIDIOMA.
   Los tipos de error son:
   notext: No se ha introducido un texto necesario.
		noint: El texto ha de ser un entero.
		nofloat: El texto ha de ser un decimal.
   nosel: Es necesario seleccionar un elemento de un select.
N: No utiliza mensajes.

*/

// MENSAJES DE ERROR GENERICOS.

notext = "It is necessary to introduce a value in this field.";
noint = "This field must be a integer number.";
nofloat = "This field must be a decimal number.";
noalpha = "This field must be alphanumeric.\nForbbiden Characters: ,\", \'";
nodate = "This field must be a date. (dd/mm/[yy]yy)";
nohour = "This field must be a hour. (hh:mm)";
noemail = "This field must be a e-mail.";
noweb = "This field must be a Web location.";
noradio = "It must choose one of the options of between different radio buttons.";
nocheck = "It is necessary to mark this checkbox.";
nosel = "It is necessary to select an element of the list.";
nofile = "The selected file is not of the required type.";
nullfile = "It is necessary to select a file."

// FUNCIÓN PRINCIPAL DE COMPROBACIONES DE UN FORMULARIO

function formsubmit(form)
{
	error = "";
	i = 0;

	// Recorremos todos los elementos del formulario.

	while(i<form.elements.length)
	{
		switch(form.elements[i].name.substr(0,1))
		{
			case "T":

			// Es un campo de texto, comprovamos si es campo requerido.

            if(form.elements[i].name.substr(1,1)=='Y')
            {
				if((form.elements[i].value.length==0)&&(form.elements[i].value==""))
				{
					error = "notext";
				}
            }
            if(error=="")
            {
				// Realizamos las comprobaciones que se nos indique.

				switch(form.elements[i].name.substr(2,1))
				{
					case "I":	// Comprobamos si el dato introducido es un entero.

                       if(!isInt(form.elements[i].value)&&(form.elements[i].value!=""))
                       {
							error = "noint";
							form.elements[i].select();
                       }
                       break;

					case "F":	// Comprovamos si el número introducido es un decimal.

                       form.elements[i].value = form.elements[i].value.replace(".",",");
                       if(!isFloat(form.elements[i].value)&&(form.elements[i].value!=""))
                       {
							error = "nofloat";
							form.elements[i].select();
                       }
                       break;

					case "A":	// Comprovamos si el texto es un alphanumerico.

                       if(!isAlpha(form.elements[i].value)&&(form.elements[i].value!=""))
                       {
							error = "noalpha";
							form.elements[i].select();
                       }
                       break;

					case "D":	// Comprovamos si el texto es una fecha correcta.

                       form.elements[i].value = form.elements[i].value.replace(/-/g,"/");
                       if(!isDate(form.elements[i].value)&&(form.elements[i].value!=""))
                       {
							error = "nodate";
							form.elements[i].select();
                       }
                       break;

					case "H":	// Comprovamos si el texto es una hora correcta.

						if(!isHour(form.elements[i].value)&&(form.elements[i].value!=""))
						{
							error = "nohour";
							form.elements[i].select();
						}
						break;

					case "E":	// Comprovamos si el texto es una cuenta email correcta.

						if(!isEmail(form.elements[i].value)&&(form.elements[i].value!=""))
						{
							error = "noemail";
							form.elements[i].select();
						}
						break;

					case "W":	// Comprovamos si el texto es una url correcta.

                       form.elements[i].value = form.elements[i].value.replace(/http:\/\//g,"");
                       if(!isWeb(form.elements[i].value)&&(form.elements[i].value!=""))
                       {
							error = "noweb";
							form.elements[i].select();
                       }
                       break;

					case "C":	// Ejecutamos operaciones definidas por el programador.

                       if(form.elements[i].name.substr(2,1)=='C')
                       {
							if(eval("filter"+form.elements[i].name+"(form.elements[i])")==false)
							{
								form.elements[i].select();
								form.elements[i].focus();
								return false;
							}
                       }
                       break;
				}
			}
            break;

			case "S":	// Es un select, comprovamos si es campo requerido.

            if(form.elements[i].name.substr(1,1)=='Y')
            {
				if((form.elements[i].options[form.elements[i].options.selectedIndex].value=="0")) error = "nosel"
            }
            break;

			case "R":	// Es un radio button, comprovamos si es campo requerido.

            if(form.elements[i].name.substr(1,1)=='Y')
            {
				// Recorremos todos los radio butons que tengan ese nombre.

				radiotake = false;
				for(j=0;j<form.elements.length;j++)
				{
					if(form.elements[j].name==form.elements[i].name)
					{
						if(form.elements[j].checked==true) radiotake = true;
					}
				}
				if(!radiotake) error = "noradio"
            }
            break;

			case "X":	// Es un archivo realizamos la comprovacion de si es necesario.

            if(form.elements[i].name.substr(1,1)=="Y")
            {
				if((form.elements[i].value.length==0)&&(form.elements[i].value=="")) error = "nullfile"
            }
            if(error=="")
            {
				// Comprovamos si la extensión es correcta previamente sustituimos una serie de caracteres de escape.

				stri = form.elements[i].value.replace(/\\/g,"/").replace(/\./g,":")
				if(form.elements[i].name.substr(2,1)=="D")
				{
					if((stri.search(":doc")==-1)&&(stri.search(":txt")==-1)&&(stri.search(":htm")==-1)&&(stri.search(":html")==-1)) error = "nofile";
				}
				else if(form.elements[i].name.substr(2,1)=="I")
				{
					if((stri.search(":GIF")==-1)&&(stri.search(":gif")==-1)&&(stri.search(":JPG")==-1)&&(stri.search(":jpg")==-1)&&(stri.search(":JPEG")==-1)&&(stri.search(":jpeg")==-1)) error = "nofile";
				}
				else if(form.elements[i].name.substr(2,1)=="S")
				{
					if((stri.search(":mid")==-1)&&(stri.search(":mod")==-1)&&(stri.search(":wav")==-1)&&(stri.search(":ra")==-1)&&(stri.search(":mp3")==-1)) error = "nofile";
				}
				else if(form.elements[i].name.substr(2,1)=="V")
				{
					if((stri.search(":avi")==-1)&&(stri.search(":mov")==-1)&&(stri.search(":mpg")==-1)&&(stri.search(":mpeg")==-1)&&(stri.search(":ram")==-1)&&(stri.search(":rm")==-1)) error = "nofile";
				}
            }
            break;

			case "C":	// Es un checkbox, comprovamos si es campo requerido.

			if(form.elements[i].name.substr(1,1)=='Y')
			{
				if(form.elements[i].checked==false) error = "nocheck"
            }
            break;

			case "H":	// Es un campo oculto no se realizan comprobaciones.
            break;

			case "B":	// Es un boton no se realizan comprobaciones.
            break;

			default:	// Si no es un tipo definido por nosotros, lo obviamos y hacemos submit.
			break;
		}

		// Comprovamos si ha existido error.

		if((error.length!=0)&&(error!=""))
		{
			if(form.elements[i].name.substr(3,1)=="Y") alert(eval(error));
			form.elements[i].focus();
			return false;
		}

		// Si no ha habido error continuamos con el siguiente campo.

		i++;
	}

	// Si los datos son correctos hacemos el submit.

	form.submit();
	return true;
}

// FUNCIÓN PARA SABER SI UN NÚMERO ES UN ENTERO.

function isInt(InString)
{
	var desde = 0;

	// Quitamos esto porque los ints de esta página no admiten negativos.

	// if(InString.substr(0,1)=="-") desde = 1; else desde = 0;

	RefString = "1234567890";
	for(Count=desde; Count < InString.length; Count++)
	{
		TempChar = InString.substring(Count, Count+1);
		if(RefString.indexOf(TempChar,0)==-1) return false;
	}
	if(isNaN(InString)) return false;
	return true;
}

// FUNCIÓN PARA COMPROBAR SI UN CAMPO ES UN NÚMERO CON DECIMALES.

function isFloat(InString)
{
	var desde;
	if(InString.substr(0,1)=="-") desde = 1; else desde = 0;
	RefString = "1234567890,";
	dot = false;
	for(Count=desde; Count < InString.length; Count++)
	{
		TempChar = InString.substring(Count, Count+1);
		if(RefString.indexOf(TempChar, 0)==-1) return false;
		if(TempChar==",")
		if(dot==true) return false;
		else dot = true;
	}
	aux = InString.replace(",",".");
	if(isNaN(aux)) return false;
	return true;
}

// FUNCIÓN PARA COMPROBAR SI UN CAMPO ES ALPHANUMERICO.

function isAlpha(InString)
{
	//letras = "0123456789ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz"
	//acentos = "ÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåèéêëìíîïðòóôõöùúûüýÿ"
	//simbolos = "!¡¿?\ ()[]{}/\\&%~$£#@|¬*-+÷_¼½¾,.·:;=<>^`´¨*«»ºª¹º²³±©®¤¥¦§µ¶¢×øØÞþßæ"
	//RefString = letras+acentos+simbolos+String.fromCharCode(10, 13)
	//for(Count=0; Count < InString.length; Count++)
	//{
	//	TempChar = InString.substring(Count, Count+1);
	//	if(RefString.indexOf(TempChar, 0)==-1) return false;
	//}
	return true;
}

// FUNCIÓN PARA SABER SI ES UNA FECHA CORRECTA.

function isDate(InString)
{
	var dia,mes,any;
	if(InString.substr(1,1)=="/")
	{
		dia = InString.substr(0,1);
		if(InString.substr(3,1)=="/")
		{
			mes = InString.substr(2,1);
			any = InString.substr(4);
		}
		else if(InString.substr(4,1)=="/")
		{
			mes = InString.substr(2,2);
			any = InString.substr(5);
		}
		else return false;
	}
	else if(InString.substr(2,1)=="/")
	{
		dia = InString.substr(0,2);
		if(InString.substr(4,1)=="/")
		{
			mes = InString.substr(3,1);
			any = InString.substr(5);
		}
		else if(InString.substr(5,1)=="/")
		{
			mes = InString.substr(3,2);
			any = InString.substr(6);
		}
		else return false;
	}
	else return false;
	if((!isInt(dia))||(!isInt(mes))||(!isInt(any))) return false;
	if((parseInt(mes,10)<1)||(parseInt(mes,10)>12)) return false;
	if((parseInt(any,10)<0)||((any.length!=4)&&(any.length!=2))) return false;
	if(any.length==2) if(parseInt(any,10)>=70) any="19" + any; else any="20" + any;
	if(parseInt(mes,10)==2)
	{
		if((parseInt(any,10)%4==0)&&((!(parseInt(any,10)%100==0))||(parseInt(any,10)%400==0)))
		{
			if((parseInt(dia,10)>29)||(parseInt(dia,10)<1)) return false;
		}
		else if((parseInt(dia,10)>28)||(parseInt(dia,10)<1)) return false;
	}
	else if((parseInt(mes,10)==4)||(parseInt(mes,10)==6)||(parseInt(mes,10)==9)||(parseInt(mes,10)==11))
	{
		if((parseInt(dia,10)>30)||(parseInt(dia,10)<1)) return false;
	}
	else if((parseInt(dia,10)>31)||(parseInt(dia,10)<1)) return false;
	return true;
}

// FUNCIÓN PARA SABER SI ES UNA HORA CORRECTA.

function isHour(InString)
{
	var hora,min;
	if(InString.substr(1,1)==":")
	{
		hora = InString.substr(0,1);
		min = InString.substr(2);
	}
	else if(InString.substr(2,1)==":")
	{
		hora = InString.substr(0,2);
		min = InString.substr(3);
	}
	else return false;
	if(isInt(hora))
	{
		if((parseInt(hora,10)<0)||(parseInt(hora,10)>23)) return false;
	else
	{
		if(isInt(min))
		{
			if((parseInt(min,10)<0)||(parseInt(min,10)>59)) return false;
		}
        else return false;
		}
	}
	else return false;
	return true;
}

// FUNCIÓN PARA SABER SI UNA DIRECCIÓN DE CORREO ES CORRECTA.

function isEmail(InString)
{
	RefString = "0123456789ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz.-_/@"
	arroba = false;
	for(Count=0; Count < InString.length; Count++)
	{
		TempChar = InString.substring(Count, Count+1);
		if(RefString.indexOf(TempChar, 0)==-1) return false;
		if(TempChar=="@") if(arroba==true) return false;
		else arroba = true;
	}
	if(arroba==false) return false;
	return true;
}

// FUNCIÓN PARA SABER SI UNA DIRECCIÓN URL ES CORRECTA.

function isWeb(InString)
{
	RefString = "0123456789ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz.-_/@~"
	for(Count=0; Count < InString.length; Count++)
	{
		TempChar = InString.substring(Count, Count+1);
		if(RefString.indexOf(TempChar, 0)==-1) return false;
	}
	return true;
}

// FUNCIÓN PARA TRATAMIENTO DE RADIOS.

function formreset(form)
{
	// Recorremos todos los elementos "reseteables" del formulario.

	i = 0;
	while(i<form.elements.length)
	{
		switch(form.elements[i].type)
		{
			case "text":			// Es un campo de texto.

               form.elements[i].value = "";
               break;

			case "password":		// Es un campo de password.

				form.elements[i].value = "";
				break;

			case "textarea":		// Es un textarea.

				form.elements[i].value = "";
				break;

			case "checkbox":		// Es un checkbox.

				form.elements[i].checked = false;
				break;

			case "radio":			// Es un radio button.

				form.elements[i].checked = false;
				break;

			case "select-one":		// Es un select.

				form.elements[i].options.selectedIndex = 0;
				break;

			case "select-multiple":	//Es un select.

				form.elements[i].options.selectedIndex = 0;
				break;
		}
		i++;
	}
	return true;
}

-->