/*	
*	Version:	1.0.2		Modificado: 19/5/2002		Cimfo
*
* 	Verifica el formulario de alta clientes	
*	Los nombres de los elementos deben de llevar:
*		1ª letra: O=opcional		N=Necesario
*		2ª letra: N=numerico	T=Texto		M=mail O=Opcional(no se verifica)
*				  L=telefono/fax
*/
function AllTrim(pCadena)
{
	var _StrAux="";
	var ArEs=pCadena.split(" ");
	for(cont=0;cont<ArEs.length;++cont)
		_StrAux+=ArEs[cont];
	return _StrAux;
}

function VerifyValues(pElement)
{
	var text=unescape(String(pElement.value)).toUpperCase();
	if (text.indexOf("STRING")<0&&text.indexOf("'")<0&&text.indexOf("<")<0&&text.indexOf("\"")<0)
			return true; // Ok
	return false; // error
}

function VerifySpaces(pElement)
{
		var _Aux=new String(pElement.name);
		if (_Aux.charAt(0)=='N')
			if(pElement.value=="")			
				return false;//Error 
			else
				return true;// Ok	
	return true;
}	

function IsNumeric(vText)
{
	var puntos=0;
	var signos=0;
	var Continua=true;
	for(i=0;i<vText.length&&Continua;++i)
		if(vText.charAt(i)<'0'||vText.charAt(i)>'9')
				Continua=false;
		/*else
			if (vText.charAt(i)=='-')
				++signos;
			else
				if (vText.charAt(i)=='.')
					++puntos;*/

	if (!Continua||puntos>1||signos>1)
		return false;//No es un nº			
	return true;// Si es un Nº
}
function VerifyMail(vText)
{
	if ((arroba=vText.indexOf("@"))>0)
		if ((punto=vText.lastIndexOf("."))>(arroba+1))
			return (true);
	return (false);
}
function VerifyTLF(vText)
{
	return IsNumeric(AllTrim(vText));
}
function VerifyAll(pForm)
{
	var cont,Continua;
	for(cont=0;(cont<pForm.elements.length)&&VerifySpaces(pForm.elements[cont]);++cont);
	if (cont<pForm.elements.length)
	{
		alert("Error: Debe rellenar todos las casillas");
		return 0; // error
	}
	
	for(cont=0;(cont<pForm.elements.length)&&VerifyValues(pForm.elements[cont]);++cont);
	if (cont<pForm.elements.length)
	{
		alert("Error: Ha introducido caracteres que se están interpretando como potencialmente peligrosos");
		return 0; // error
	}	

	Continua=true;	
	for(cont=0;(cont<pForm.elements.length)&&Continua;++cont)
	{
		switch((pForm.elements[cont].name.charAt(1)))
		{
			case 'N':(Continua=IsNumeric(pForm.elements[cont].value))?"":alert("Error: El campo "+pForm.elements[cont].name.substring(3,pForm.elements[cont].name.length)+" debe ser numérico");
					break;
			case 'M':(Continua=VerifyMail(pForm.elements[cont].value))?"":alert("Error: El campo "+pForm.elements[cont].name.substring(3,pForm.elements[cont].name.length)+" no tiene el formato adecuado");
					break;
			case 'L':(Continua=VerifyTLF(pForm.elements[cont].value))?"":alert("Error: El campo "+pForm.elements[cont].name.substring(3,pForm.elements[cont].name.length)+" debe ser numérico");
					break;
		}
	}
			
	if (!Continua)
		return 0; // error
	
	return 1; // OK
}
