// vars to validate the values

var ALPHABETIC_VALUES ="abcdefghijklmnopqrstuvwxyzáéíóúñüABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ -&',"
var DIGITS = "0123456789";
var ALPHABETIC_DIGITS = "abcdefghijklmnopqrstuvwxyzáéíóúñüABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ0123456789 -&',";
var ADDRESS = "abcdefghijklmnopqrstuvwxyzáéíóúñüABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ0123456789 /ºª-.-&',";



// Basic Functions 

//**
//*  function IsEmpty
//* @ param value , is a String  , for example document.(name_formulary).(name_input).value
//* @ returns true if the object is empty
//*

function IsEmpty (value) {
	if (value.length == 0) return true;
	return false;
}

//**
//*  function VerifyValue 
//* @ param value, is a String, for example document.(name_formulary).(name_input).value
//* @ param text, is a another String to compare with the chars of param value
//* @ returns true if the chars of @value are in @text 
//*   and DIGITS)
//*


function VerifyValue (value,text)
{
	var lengthValue = value.length;
	var lengthAlph  = text.length; 
	
	var i,j=0;
	var processOk = "false";

	for (i=0;i<lengthValue;i++) 
	{
		while (j<lengthAlph){
	     	if (value.charAt(i) == text.charAt(j)) processOk = "true";
			j++;
		}
	
		if (processOk == "false") {
			aux = value.charAt(i);
			return aux,false;
		}	

	processOk="false";j=0;
	}
return true;
}



// Util functions 

//**
//*  function IsMail
//* @ param ismail, is a String, for example document.(name_formulary).(name_input).value
//*
//* @ returns true if the value is a correct email
//*
function IsMail (ismail) {
	if (!IsEmpty(ismail))
	{
		var lengthValue=ismail.length;
		var i=0;
		
		while ((i<lengthValue) && (ismail.charAt(i) !="@"))
		{ i++
		}
			
		if (i >= lengthValue) return false;  //@ is not present or there isn't sufficent chars
		i+=2;
		
		while ((i<lengthValue) && (ismail.charAt(i) !="."))
		{i++
		}
		
		if (i >= lengthValue) return false  //. is not present or there isn't sufficient chars
		i++;
		
		if (i >= lengthValue) return false // There isn't sufficient chars
		
	}
	
return true;				
}


//**
//*  function IsAlphabetic
//* @ param alphabetic, is a String, for example document.(name_formulary).(name_input).value
//*
//* @ returns true if the value is enterely Alphabetic values (see ALPHABETIC_VALUES)
//*

function IsAlphabetic (alphabetic) {

	if (VerifyValue (alphabetic,ALPHABETIC_VALUES)) return true;
	else return false;

}


//**
//*  function IsDigit
//* @ param isdigit, is a String, for example document.(name_formulary).(name_input).value
//*
//* @ returns true if the value is enterely Digits (see DIGITS)
//*

function IsDigit (isdigit) {

	if (VerifyValue (isdigit,DIGITS)) return true;
	else return false;
	
}

//**
//*  function IsAlphanumeric
//* @ param isaplphanumeric, is a String, for example document.(name_formulary).(name_input).value
//*
//* @ returns true if the value is enterely Alphabetic or Digits values (see ALPHABETIC_DIGITS 
//*

function IsAlphanumeric(isalphanumeric) 
{
	if (VerifyValue (isalphanumeric,ALPHABETIC_DIGITS)) return true;
	else return false;
}


//**
//*  function IsAddress
//* @ param isaddress, is a String, for example document.(name_formulary).(name_input).value
//*
//* @ returns true if the value is an Address (see ADDRESS) 
//*

function IsAddress(isaddress) 
{
	if (VerifyValue (isaddress,ADDRESS)) return true;
	else return false;
}








