String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function VerificaEmail(obj) 
{
	var validChars, err01,err02, err03, err04, fieldValue, fieldLength;
	var cont = 0, cont2 = 0;
	var Limpar = false;
	
	validChars  = "abcdefghijklmnopqrstuvwxyz"; 
	validChars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	validChars += "0123456789.@_-";
	fieldValue  = obj.value; 
	fieldLength = obj.value.length; 
	minLength   = 8; 
	maxLength   = 255; 

	err01   = "Foi encontrado um caracter inválido."; 
	err02   = "Por favor introduza pelo menos " + minLength + " caracteres."; 
	err03   = "Por favor introduza menos que " + maxLength + " caracteres."; 
 
	if ( fieldLength > 0)
	{
		if ( fieldLength < minLength ) 
		{ 
			alert( err02 ); 
			Limpar = true;
		}
		else if (( fieldLength > maxLength ) && ( maxLength > 0 )) 
		{ 
			alert( err03 ); 
			Limpar = true;
		}
		else if (( fieldValue.charAt( 0 ) == "@" ) || ( fieldValue.charAt( fieldLength - 1 ) == "@" )) 
		{
			alert("O Email não é válido !!!"); 
			Limpar = true;
		}
		else 
		{ 
			for( var i=0; i< fieldLength; i++ ) 
			{ 
				if ( validChars.indexOf( fieldValue.charAt( i )) == -1 ) 
				{ 
				    alert( err01 ); 
				    Limpar = true;
				    break; 
				}
				if (fieldValue.charAt( i ) == "@")
					cont++;
				if (fieldValue.charAt( i ) == ".")
					cont2++;
		    } 
			    
		    if (cont2 == 0 )
			{
				alert("O Email não é válido !!!"); 
				Limpar = true;
			}
			else if ( (cont == 0) || (cont > 1) )
		    {
				alert("O Email não é válido !!!"); 
				Limpar = true;		
			}
		} 
    } 
    if(Limpar) obj.focus(); 
}


function VerificaEmailUK(obj) 
{
	var validChars, err01,err02, err03, err04, fieldValue, fieldLength;
	var cont = 0, cont2 = 0;
	var Limpar = false;
	
	validChars  = "abcdefghijklmnopqrstuvwxyz"; 
	validChars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	validChars += "0123456789.@_-";
	fieldValue  = obj.value; 
	fieldLength = obj.value.length; 
	minLength   = 8; 
	maxLength   = 255; 

	err01   = "One invalid caracter was found."; 
	err02   = "Please introduce at least " + minLength + " caracters."; 
	err03   = "Please introduce less than " + maxLength + " caracters."; 
 
	if ( fieldLength > 0)
	{
		if ( fieldLength < minLength ) 
		{ 
			alert( err02 ); 
			Limpar = true;
		}
		else if (( fieldLength > maxLength ) && ( maxLength > 0 )) 
		{ 
			alert( err03 ); 
			Limpar = true;
		}
		else if (( fieldValue.charAt( 0 ) == "@" ) || ( fieldValue.charAt( fieldLength - 1 ) == "@" )) 
		{
			alert("The Email is not valid !!!"); 
			Limpar = true;
		}
		else 
		{ 
			for( var i=0; i< fieldLength; i++ ) 
			{ 
				if ( validChars.indexOf( fieldValue.charAt( i )) == -1 ) 
				{ 
				    alert( err01 ); 
				    Limpar = true;
				    break; 
				}
				if (fieldValue.charAt( i ) == "@")
					cont++;
				if (fieldValue.charAt( i ) == ".")
					cont2++;
		    } 
			    
		    if (cont2 == 0 )
			{
				alert("The Email is not valid !!!"); 
				Limpar = true;
			}
			else if ( (cont == 0) || (cont > 1) )
		    {
				alert("The Email is not valid !!!"); 
				Limpar = true;		
			}
		} 
    } 
    if(Limpar) obj.focus(); 
}

function Mostrar(i)
{
	var l;
	if(document.all("modalidade").style.visibility == "visible")
	{
		document.all("modalidade").style.visibility = "hidden";
		
	}	
	else
	{
		document.all("modalidade").style.visibility = "visible";
		document.all("contexto").innerHTML = i;
	}	
}


function Esconder(i)
{
	var l;
	if(document.all("modalidade").style.visibility == "visible")
	{
		document.all("modalidade").style.visibility = "hidden";
		
	}	
	else
	{
		document.all("modalidade").style.visibility = "v";
	}	
}


function Verifica_Hora(hora, obrigatorio)
{
 //Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
 	//var hora = document.getElementById(hora);
 	if((obrigatorio == 1) || (obrigatorio == 0 && hora.value != "")){
 		if(hora.value.length < 5)
 		{
 			alert("Formato da hora inválido. Por favor, informe a hora no formato correto: hh:mm");
 			hora.focus();
 			return false
 		}
 		if(hora.value.substr(0,2) > 23 || isNaN(hora.value.substr(0,2)))
 		{
 			alert("Formato da hora inválido.");
 			hora.focus();
 			return false
 		}
 		if(hora.value.substr(3,2) > 59 || isNaN(hora.value.substr(3,2)))
 		{
 			alert("Formato do minuto inválido.");
 			hora.focus();
 			return false
 		}
 	}
 }
 
 
 function Verifica_HoraUK(hora, obrigatorio)
{
 //Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
 	//var hora = document.getElementById(hora);
 	if((obrigatorio == 1) || (obrigatorio == 0 && hora.value != "")){
 		if(hora.value.length < 5)
 		{
 			alert("Invalid Format. Please, introduce the hour in the correct format: hh:mm");
 			hora.focus();
 			return false
 		}
 		if(hora.value.substr(0,2) > 23 || isNaN(hora.value.substr(0,2)))
 		{
 			alert("Invalid Format of Hour.");
 			hora.focus();
 			return false
 		}
 		if(hora.value.substr(3,2) > 59 || isNaN(hora.value.substr(3,2)))
 		{
 			alert("Invalid Format of Minute.");
 			hora.focus();
 			return false
 		}
 	}
 }

