function checkEmail(pCampo,pMsg)
{
	if (!validateEmail(pCampo.value))
	{
		alert(pMsg);
		pCampo.focus();
		return false;
	}
	return true;
}

function Menu(form) {
	if (form.ondeIr.selectedIndex !=0){
		var result = (form.ondeIr.options[form.ondeIr.selectedIndex].value);
		form.action = result;
		form.submit();
	}	
}


function checkSe1Menor2(pCampo1,pCampo2,pMsg)
{
	if (parseInt(pCampo1.value) >= parseInt(pCampo2.value))
	{
		alert(pMsg);
		pCampo1.focus();
		return false
	}
	return true
}

function checkVazio(pCampo,pMsg)
{
	if (pCampo.value == "")
	{
		alert(pMsg);
		pCampo.focus();
		return false
	}
	return true
}

function checkEspaco(pCampo,pMsg)
{
	if (!validateLetra(pCampo.value," "))
	{
		alert(pMsg);
		pCampo.focus();
		return false
	}
	return true
}


function checkDate(pCampo,pMsg)
{
	if (!validateDate(pCampo.value))
	{
		alert(pMsg);
		pCampo.focus();
		return false
	}
	return true
}

function checkValorMinimo(pCampo,pMin,pMsg)
{
	if (!validateValorMinimo(pCampo.value,pMin))
	{
		alert(pMsg);
		pCampo.focus();
		return false;
	}
	return true;
}

function checkNumber(pCampo,pMsg)
{
	if (!validateNumber(pCampo.value))
	{
		alert(pMsg);
		pCampo.focus();
		return false;
	}
	return true;
}

function checkNumberPonto(pCampo,pMsg)
{
	if (!validateNumberPonto(pCampo.value))
	{
		alert(pMsg);
		pCampo.focus();
		return false;
	}
	return true;
}


function checkIguais(pCampo1,pCampo2, pMsg)
{
	if (pCampo1.value != pCampo2.value)
	{
		alert(pMsg);
		pCampo1.focus();
		return false
	}
	return true
}


function ValidaSelect(pCampo,pMsg){

	if (pCampo.selectedIndex == 0)
	{
		alert(pMsg);
		pCampo.focus();
		return false
	}
	return true
}

function ValidaTamanho(pCampo,iTamanho){
if (pCampo.value.length == 0){
	alert("O campo Atividade está vazio.");
	pCampo.focus();
	return false;
}	
else{
	if (pCampo.value.length > iTamanho){
		alert("Seu texto possui " + (pCampo.value.length - iTamanho)  + " caracteres excedentes. Para que seu texto seja inserido, você deverá diminuí-lo.");
		pCampo.focus();
		return false;
	}	
}
return true;	
}	


function validateSignedNumber(s)
{
	var gabarito = "0123456789";
	var temPonto = false;
	var thisChar;

	//Test for a string
	if (s.length <= 0)
	{
		return false;
	}

	thisChar = s.substring(0,1);
	if ( (thisChar == "+") || (thisChar == "-") )
	{
		s = s.substring(1,s.length);
	}
	else
	{
		if  ((thisChar < "0" || thisChar > "9") )
		{
        	     return false ; 
		}
	}


	for (var j=0; j < s.length; j++)  
	{                                      
          thisChar = s.substring(j,j+1);                              
          if (thisChar == "," )
	    {                             
             return false;                                                  
          }    
          if (thisChar == "." )
          {                             
		 temPonto=true;
          }    
	}

	
	//Create an array to split the number into (nn.nn)
	strarr = new Array ()

	//Use own split function as JScript does not include JavaScripts split function
	own_split(strarr, s, ".");

		
	if (strarr.length > 2)
	{
		return false;
	}


	//2 array elements means day, month, and year
	if  (strarr.length == 2) 
	{
		if ( (strarr[0].length == 0) || (strarr[1].length == 0 ) )
		{
			return false;
		}
	}

	//2 array elements means 2 casas decimais.
	if  ((strarr.length == 1) && (temPonto))
	{
		return false;
	}


	//Test the value of each element falls in an acceptable range
	for (var i = 0; i < strarr.length; i++)
	{
		for (var k = 0; k < strarr[i].length; k++)
		{
	          thisChar = strarr[i].substring(k,k+1);                              
		  if (thisChar < "0" || thisChar > "9") 
		  {                             
		             return false ;
		  }
		}
	}

	return true;
}

function validateNumber(s)
{
	var gabarito = "0123456789";
	var temPonto = false;
	var thisChar;

	//Test for a string
	if (s.length <= 0)
	{
		return false;
	}

	for (var j=0; j < s.length; j++)  
	{                                      
          thisChar = s.substring(j,j+1);                              
          if (thisChar == "," )
	    {                             
             return false ;                                                  
          }    
          
	    if (thisChar == "." )
	    {                             
	       temPonto = true;
          }    
	}

	
	//Cria varios Arrays em funcao do pos pontos que possam ser encontrados.
	strarr = new Array ()

	//Use own split function as JScript does not include JavaScripts split function
	own_split(strarr, s, ".");


			
	if (strarr.length > 2)
	{//O numero possui mais de um ponto.
		return false;
	}


	//O numero esta coerente em relacao ao ponto.
	if  (strarr.length == 2) 
	{
		if ( (strarr[0].length == 0) || (strarr[1].length == 0 ) )
		{
			return false;
		}
	}

	//Numero sem casa decimal
	if  ((strarr.length == 1) && (temPonto))
	{
		return false;
	}



	//Test the value of each element falls in an acceptable range
	for (var i = 0; i < strarr.length; i++)
	{
		for (var k = 0; k < strarr[i].length; k++)
		{
	          thisChar = strarr[i].substring(k,k+1);                              
		  if (thisChar < "0" || thisChar > "9") 
		  {                             
		      return false ;
		  }
		}
	}

	return true;
}


function validateNumberPonto(s)
{
	var gabarito = "0123456789";
	var temPonto = false;
	var thisChar;

	//Test for a string
	if (s.length <= 0)
	{
		return false;
	}

	for (var j=0; j < s.length; j++)  
	{                                      
          thisChar = s.substring(j,j+1);                              
          if (thisChar == "." )
	    {                             
             return false ;                                                  
          }    
          
	    if (thisChar == "," )
	    {                             
	       temPonto = true;
          }    
	}

	
	//Cria varios Arrays em funcao do pos pontos que possam ser encontrados.
	strarr = new Array ()

	//Use own split function as JScript does not include JavaScripts split function
	own_split(strarr, s, ",");


			
	if (strarr.length > 2)
	{//O numero possui mais de um ponto.
		return false;
	}


	//O numero esta coerente em relacao ao ponto.
	if  (strarr.length == 2) 
	{
		if ( (strarr[0].length == 0) || (strarr[1].length == 0 ) || (strarr[1].length == 1 ) || (strarr[1].length > 2 ) )
		{
			return false;
		}
	}

	//Numero sem casa decimal
	if  ((strarr.length == 1) && (temPonto))
	{
		return false;
	}



	//Test the value of each element falls in an acceptable range
	for (var i = 0; i < strarr.length; i++)
	{
		for (var k = 0; k < strarr[i].length; k++)
		{
	          thisChar = strarr[i].substring(k,k+1);                              
		  if (thisChar < "0" || thisChar > "9") 
		  {                             
		      return false ;
		  }
		}
	}

	return true;
}

function ConvertStrToNumber(s)
{
var numOrg
	
	numOrg = s;
//	alert ("s=" + s);
	s = s.replace(",",".");	
//	alert ("s2=" + s);
//	if (validateNumberv2(s))
//	{
//		return s
//	}
//	else
//	{
//		s.replace(',','.')
//		return s
//	}
	return s
}
	
function validateValorMinimo(s,intMinimo)
{
var intNumber		
	s = ConvertStrToNumber(s);
	intNumber = parseInt(s);
	
	if (s < intMinimo)
		return false
	else
		return true
}


function validateNumberv2(s)
{
	intNumber = parseInt(s)
	//alert ("intbumber:" + intNumber);
	if (isNaN(intNumber))
		return false
	else
		return true
}

function validateNumberv3(s)
{
var thisChar;
	
	for (var k = 0; k < s.length; k++)
	{
		thisChar = s.substring(k,k+1); 
		
		if (thisChar < "0" || thisChar > "9") 
		{                             
			return false ;
		}
	}
	return true;
}

function validateLetra(s,letra)
{

	var thisChar;

	for (var j=0; j < s.length; j++)  
	{                                      
          thisChar = s.substring(j,j+1);                              
          if (thisChar == letra )
	    {                             
             return false ;                                                  
          }              
	}

	return true;
}


//Date validation function
function validateDate(s)
{
	//Test for a string
	if (s.length > 0)
	{
		//Create an array to split the date into (dd/mm/yyyy)
		strarr = new Array ()

		//Use own split function as JScript does not include JavaScripts split function
		own_split(strarr, s, "/");
		
		//3 array elements means day, month, and year
		if (strarr.length == 3)
		{
			//Test the value of each element falls in an acceptable range
			for (var i = 0; i < strarr.length; i++)
			{
				if ((strarr[0] < 0) || (strarr[0] >31)){
					return false;
				}
				if ((strarr[1] < 0) || (strarr[1] >12)){
					return false;
				}
				if (strarr[2].length != 4 ){
					return false;
				//Verifica se aos mes de fevereiro foi atribuido mais de 29 dias
				if((strarr[1] == 2) && (strarr[0]>29))
					return false;
				//Verifica se aos mes de abril foi atribuido mais de 30 dias
				if((strarr[1] == 4) && (strarr[0]>30))
					return false;
				//Verifica se aos mes de junho foi atribuido mais de 30 dias
				if((strarr[1] == 6) && (strarr[0]>30))
					return false;
				//Verifica se aos mes de setembro foi atribuido mais de 30 dias
				if((strarr[1] == 9) && (strarr[0]>30))
					return false;
				//Verifica se aos mes de novembro foi atribuido mais de 30 dias
				if((strarr[1] == 11) && (strarr[0]>30))
					return false;

				}
			}
			return true;
		}
		return false;
	}
	return false;
}

function validateEmail(Expression)
{

	if (Expression == null)
		return (false);

	var supported = 0;
	Expression = Trim(Expression);
	if(Expression.indexOf(" ")>-1)
	{
		return false;
	}
		
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(Expression) && r2.test(Expression));
}


function Str2Date(s)
{


	// Converte uma string para um objeto do tipo Data.
	// Espera uma string correta,  que deve ser tratada pela funcao validateDate antes.

	//Create an array to split the date into (dd/mm/yyyy)
	strarr = new Array ()

	//Use own split function as JScript does not include JavaScripts split function
	own_split(strarr, s, "/");
	
	// alert(strarr);
	dia = strarr[0];
	mes = strarr[1] - 1; //mes 0 -11
	ano = strarr[2];

	// alert (dia);
	// alert (mes);
	// alert (ano);
	 
var objData = new Date(ano , mes, dia);	 
	
	//objData.setUTCFullYear(ano,mes,dia);
	
	return objData;
}


//String split function to accomodate JScripts lack of JavaScripts split function
function own_split(arr, str, delim)
{
	//Initialise local variables
	var pos = 0;
	var num = 0;
	var start = 0;
	
	//Loop while there are characters in the string
	while (pos < str.length)
	{
		//Loop while there are delimiters in the string
		while((str.substring (pos, pos+1) != delim) && (pos < str.length))
		{
		pos++;
		}
		//Add the new characters to the output array
		arr[num] = str.substring(start,pos);
		num++;
		start = pos+1;
		pos++;
	}
}
