var defaultEmptyOK = false;
var decimalPointDelimiter = ",";	

function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    if(i==radio.length)
		return null;
	else
		return radio[i].value;
}

function textCounter(field, maxlimit) {
	if (field.value.length >= maxlimit){
		event.keyCode=0;
		field.value = field.value.substring(0, maxlimit);	
	}
}
		
/*Funções básicas********************************************************************/
function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s,10);
    return ((num >= a) && (num <= b));
}

//******************************************************************
function FU_Modulo11 ( Arg_Val , Arg_Fator , Arg_Resto0 ) 
//******************************************************************
{
   var VL_Total=0;
   var VL_Fator=0;
   var VL_Numero=0;
   var VL_Tamanho=0;
   var VL_Resto=0;
   var VL_Digito=0;
   
   VL_Fator = 2;
   VL_Total = 0;
   for ( VL_Tamanho = Arg_Val.length; VL_Tamanho > 0; VL_Tamanho-- )
   {
      VL_Numero = Arg_Val.substring ( VL_Tamanho , VL_Tamanho - 1 );
      VL_Numero *= VL_Fator;
      VL_Total += VL_Numero;
      if ( VL_Fator == Arg_Fator )
         VL_Fator = 2;
      else
         ++VL_Fator;
   }
   VL_Resto = VL_Total % 11;
   if ( VL_Resto == 0 )
      VL_Digito = Arg_Resto0;
   else
      {
       if ( VL_Resto == 1 )
          VL_Digito = 0;
       else
          VL_Digito = 11 - VL_Resto;
       }
   return VL_Digito;  
}

//******************************************************************
function FU_CGC(Arg_Cgc)
//******************************************************************
{
    var VL_Digit1 ;
    var VL_Digit2 ;
	var X=0;
    if (Arg_Cgc.length == 14)
    {

       VL_Digit1 = " ";
       VL_Digit2 = " ";
       VL_Digit1 = FU_Modulo11(Arg_Cgc.substring ( 12 , 0 ), 9, 0);
       VL_Digit2 = FU_Modulo11(Arg_Cgc.substring ( 13 , 0 ), 9, 0);
       if ( VL_Digit1 == Arg_Cgc.substring ( 13 , 12 ) ) 
         if ( VL_Digit2 == Arg_Cgc.substring ( 14 , 13 ) )
          {
              // alert ("OK" , "CNPJ" ) ; // ( true ) ;
              return true;
          }
     }
     //alert ( "O número do CNPJ informado é inválido !"  , "CNPJ" ) ;
	 
     return false;//(X) ; // ( false );
}

function CPFValido(s)
{
	if (s.length < 11)
		return false;
	else
	{
		var varFirstChr = s.charAt(0);
		var vaCharCPF = false;
		for ( var i=0; i<=10; i++ ) 
		{ 
			var c = s.charAt(i);
            if( ! (c>="0")&&(c<="9") ) 
				return false;
            if( c!=varFirstChr ) 
				vaCharCPF = true; 
		} 

        if( ! vaCharCPF ) 
			return false;
        
		soma=0;
		for ( i=0; i<9; i++ ) 
		{ 
			soma += (10-i) * ( eval(s.charAt(i)) );	
		} 
		digito_verificador = 11-(soma % 11);
		if ( (soma % 11) < 2 )
			digito_verificador = 0;
		if ( eval(s.charAt(9)) != digito_verificador ) 
			return false;
		soma=0;
		for ( i=0; i<9; i++ ) 
		{
			soma += (11-i) * ( eval(s.charAt(i)) ); 
		}
		soma += 2 * ( eval(s.charAt(9)) );
		digito_verificador = 11-(soma % 11);
		if ( (soma % 11) < 2 )
			digito_verificador = 0;
		if ( eval(s.charAt(10)) != digito_verificador ) 
			return false; 
		return true;
	}
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
	//Conta os @
	var j = 0;
	var k = 0;
	while (j < sLength)
    {
		if(s.charAt(j) == "@")
			k++;
		j++;
    }
	if (k > 1)
		return false;
	
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isMultipleEmails(strText)
{
	
	if(strText.indexOf(";") > 0)
	{
		arrTemp = strText.split(";");
		for(var i=0; i<arrTemp.length; i++)
		{
			if(!isEmail(arrTemp[i]))
			{
				return false;
			}
		}
		return true;
	}
	else
	{
		return isEmail(strText);
	}
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s, 10) > 0) ) );
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isWhitespace (s)

{   var i;

	// whitespace characters
	var whitespace = " \t\n\r";

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function IsNumeric(Valor)
{
   var i
   
   for (i = 0; i < Valor.length; i++)
   {
	  if (Valor.charAt(i) < "0" || Valor.charAt(i) > "9")
		return false;
   }
   
	return true;
}

function isEmpty(s)
{   if ((s == null) || (s.length == 0))
	{
		return true;
	}
	else
	{
	    for (var i = 0 ; i < s.length ; i++) 
	    {
	        if (s.charAt(i) != ' ') 
		    {
			    return false;
			}
		}
    }
    return true;
}


function isBissexto(iAno)
{
	var bRet
	bRet = false
	if (iAno % 4 == 0 && (iAno % 100 !=0 || iAno % 400 ==0 ))
		bRet = true
	return bRet
}

function isDate(sData)
{
	var bRet
	var i
	bRet = true

	if (sData.length != 10)
	    bRet = false
	
	if (bRet)
	{
		i = 0
		while (i < sData.length && bRet)
		{
			if (i == 2 || i == 5)
			{
				if (sData.charAt(i) != "/")
					bRet = false
			}
			else
			{
				if (!IsNumeric(sData.charAt(i), 0))
					bRet = false
			}
			i++
		}
		}
	if (bRet)
	{
		iDia = parseInt(sData.substring(0, 2), 10)
		iMes = parseInt(sData.substring(3, 5), 10)
		iAno = parseInt(sData.substring(6, 10), 10) 
		
		if (iMes < 1 || iMes > 12)
			bRet = false
		if (iAno < 1)
			bRet = false
	}
	if (bRet)
	{
		if (iMes == 1 || iMes == 3 || iMes == 5 || iMes == 7 || iMes == 8 || iMes == 10 || iMes == 12)
		{
			if (iDia < 1 || iDia > 31)
				bRet = false
		}
		if (iMes == 2)
		{
			if (isBissexto(iAno))
			{
				if (iDia < 1 || iDia > 29)
					bRet = false
			}
			else
			{
				if (iDia < 1 || iDia > 28)
					bRet = false
			}
		}
		if (iMes == 4 || iMes == 6 || iMes == 9 || iMes == 11)
		{
			if (iDia < 1 || iDia > 30)
				bRet = false
		}
	}

	return bRet
}

function isInteger(s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isDigit(c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isNonnegativeInteger (s)
{   var secondArg = false;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s, 10) >= 0) ) );
}

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return false;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = false;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

/*********************************************************************/






/*Funções de Validação********************************************************************/

/*
function fnPermitirFone()
{
	if ((event.keyCode==40) || (event.keyCode==41) || (event.keyCode==45) || (event.keyCode==32))
		event.returnValue = true;
	else
	{
		if((event.keyCode<48)||(event.keyCode>57))
		event.returnValue = false;
	}
}
*/

/*
function fnPermitirCEP()
{
	if ((event.keyCode==40) || (event.keyCode==41) || (event.keyCode==45) || (event.keyCode==32))
		event.returnValue = true;
	else
	{
		if((event.keyCode<48)||(event.keyCode>57))
		event.returnValue = false;
	}
}
*/

function fnPermitirNumeros()
{
	var sTeclasPermitidas = '8,35,36,37,38,39,40,45,46,96,97,98,99,100,101,102,103,104,105';
	
	//alert(sTeclasPermitidas.indexOf(event.keyCode));
	//event.returnValue = true;
	//return;
	
	if(sTeclasPermitidas.indexOf(event.keyCode) > -1)
	{
		event.returnValue = true;
		return;
	}
	
	if(!isNonnegativeInteger(String.fromCharCode(event.keyCode)))
		event.returnValue = false;
}

function fnPermitirNumeros2(){
/*****************************************************************************
Função:		fnPermitirNumeros
Autor:		
Data:		01/09/2004
Objetivo:	Função que permite somente a entrada de números.
Evento:		onkeypress.

Atualizações
Autor:	-	Walter Campos Gandra de Paula
Data:	-	01/09/2004
Motivo:	-	Ajustes de Padrão.

Parametros	:
	==========================================================================
    Nome				| Descrição
	==========================================================================
	Não possui.			| Não possui.
    ==========================================================================

Retorno		: Char
    ==========================================================================
    Campo/Valor				| Descrição
    ==========================================================================
    - Char					| Permite a entrada do caracter caso ele seja válido.
	==========================================================================
*****************************************************************************/
	if(!isNonnegativeInteger(String.fromCharCode(event.keyCode)))
		event.returnValue = false;
}

function fnPermitirMoney()
{
	if (event.keyCode==44)
		event.returnValue = true;
	else
	{
		if((event.keyCode<48)||(event.keyCode>57))
		event.returnValue = false;
	}
}

function fn_FormatCurrency(oNome){
/*****************************************************************************
Função:		fn_FormatCurrency
Autor:		
Data:		01/09/2004
Objetivo:	Função que formata os valores do campo no formato 9.999.999,99.
Evento:		onkeypress, onblur.

Atualizações
Autor:	-	Walter Campos Gandra de Paula
Data:	-	01/09/2004
Motivo:	-	Ajustes de Padrão.

Parametros	:
	==========================================================================
    Nome				| Descrição
	==========================================================================
	ConteudoCampo		| String com o conteúdo do campo.
    ==========================================================================

Retorno		: Boolean
    ==========================================================================
    Campo/Valor				| Descrição
    ==========================================================================
    - True					| Caracter válido.
    - False					| Caracter inválido.
	==========================================================================
*****************************************************************************/
	if (((event.keyCode) > 47) && ((event.keyCode) < 58))
	{
		var NumDig			=	ConteudoCampo.value;
		var TamDig			=	NumDig.length;
		var oObj			=	document.getElementById(oNome);
		var ConteudoCampo	=	oObj.value;
		var Contador		=	0;

		alert(oNome);

		if (TamDig == ConteudoCampo.maxLength){
			event.keyCode = 0;
	        return false;
	    } 
		if (TamDig > 1){
			numer = "";
			for (i = TamDig; (i >= 0); i--){
				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
					Contador++;
					if ((Contador == 2) && ((TamDig -i) < 4)){
						numer = ","+numer;
						Contador = 0;
					}
					else if (Contador == 3){
						numer = "."+numer;
						Contador = 0;
					}
					numer = NumDig.substr(i, 1)+numer;
				}
			}
			ConteudoCampo.value = numer;
		}
		return(true);
	}
	else
		return(false);
}

function Moeda(strValor){
    var intTam;
    var intValoresPermitidos="0123456789"
    var strValoresPermitidos="0123456789,."
    var strChar;
    var strProxChar;
    var blnVerificaExistenciaNumeros=false;
    strValor = strValor.replace(" ","")

    //Caso a string esteja vazia retorna false

    if(strValor.length == 0){
                return false;
    }
  
    intTam = strValor.length;
    //Percorre toda a string

    for(intTam = 0; intTam < strValor.length; intTam++)
    {
        //Armazena cada caracter da string, de acordo com a iteração no laço for
        strChar=strValor.substring(intTam, intTam+1);
        
        //Verifica se o primeiro caracter é "." ou ","
        if((intTam==0) && (strChar == "," || strChar == ".")){
			return false;
        }
      
        //Verifica se não é o ultimo caracter. Caso isto não fosse verificado, causaria um erro
        //o armazenamento do strProxChar abaixo
        if(intTam<(strValor.length-1))
        {
            //Armazena o caracter seguinte ao atual
            strProxChar = strValor.substring(intTam+1, intTam+2);           

            //Verifica se existe caracteres "." ou "," juntos
            if((strChar == "," || strChar == ".") && (strProxChar=="." || strProxChar==",")){				                        return false;
            }
        }
        
        //Verifica se o caracter atual é um número, ponto ou vírgula
        if(strValoresPermitidos.indexOf(strChar)<0){
			return false;
        }
        
        //Caso a string contenha número configura blnVerificaExistenciaNumeros=true
        if(intValoresPermitidos.indexOf(strChar)>-1)
        {
            blnVerificaExistenciaNumeros=true;
        }
    }

    //Verifica se a string contém número
    if(blnVerificaExistenciaNumeros){

        //Verifica se o último caracter da string passada é "." ou ","
        if(strChar=="." || strChar==","){
            return false;
        }
        else{
            return true;
        }
    }
    else{
        return false;
    }
}


function fnPermitirNumerosePonto()
{
	if(!(isNonnegativeInteger(String.fromCharCode(event.keyCode))||String.fromCharCode(event.keyCode)=="."))
		event.returnValue = false;
}

function fnPermitirLetrasNumeros(c)
{   return (isLetter(c) || isDigit(c))
}

function fnPermitirData(poCampo)
{
	var separador = '/'; 
	var conjunto1 = 2;
	var conjunto2 = 5;
				
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{
		if (poCampo.value.length == conjunto1)
		{
			poCampo.value = poCampo.value + separador;
		}
		if (poCampo.value.length == conjunto2)
		{
			poCampo.value = poCampo.value + separador;
		}
	}
	else
	{
		window.event.keyCode = 0;
	}
}

function fnPermitirData2(strCampo)
/*****************************************************************************
Função:		fnPermitirData2
Autor:		
Data:		01/09/2005
Objetivo:	Função que permite somente a entrada de data.
Evento:		onkeypress.

Atualizações
Autor:	-	Rodrigo Haneda
Data:	-	01/09/2005
Motivo:	-	Ajustes de Padrão.
******************************************************************************/
{
	var separador = '/'; 
	var conjunto1 = 2;
	var conjunto2 = 5;
	var oCampo	  = document.getElementById(strCampo);
				
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{
		if (oCampo.value.length == conjunto1)
		{
			oCampo.value = oCampo.value + separador;
		}
		if (oCampo.value.length == conjunto2)
		{
			oCampo.value = oCampo.value + separador;
		}
	}
	else
	{
		window.event.keyCode = 0;
	}
}

/*
function fnPermitirCNPJ(poCampo)
{
	var separador1 = '.'; 
	var separador2 = '-'; 
	var conjunto1 = 3;
	var conjunto2 = 7;
	var conjunto3 = 11;
	
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{
		if (poCampo.value.length == conjunto1)
		{
			poCampo.value = poCampo.value + separador1;
		}
		if (poCampo.value.length == conjunto2)
		{
			poCampo.value = poCampo.value + separador1;
		}
		if (poCampo.value.length == conjunto3)
		{
			poCampo.value = poCampo.value + separador2;
		}
	}
	else
	{
		window.event.keyCode = 0;
	}
}
*/

function fnPermitirCPF(poCampo)
{
	var caracteres = '01234567890';
	var separacoes = 3;
	var separacao1 = '.';
	var separacao2 = '-';
	var conjuntos = 4;
	var conjunto1 = 3;
	var conjunto2 = 7;
	var conjunto3 = 11;
	var conjunto4 = 14;
	
	if ((caracteres.search(String.fromCharCode(window.event.keyCode))!=-1) && poCampo.value.length < (conjunto4))
	{
	
		if (poCampo.value.length == conjunto1) 
		{
			poCampo.value = poCampo.value + separacao1;
		}
		
		if (poCampo.value.length == conjunto2) 
		{
			poCampo.value = poCampo.value + separacao1;
		}
	
		if (poCampo.value.length == conjunto3) 
		{
			poCampo.value = poCampo.value + separacao2;
		}
	}
	else 
	{
		event.returnValue = false;
	} 
}

function fnPermitirCEP(poCampo)
{
	separador = '-'; 
	conjunto1 = 5;
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{
		if (poCampo.value.length == conjunto1)
		{
			poCampo.value = poCampo.value + separador;
		}
	}
	else
	{
		window.event.keyCode = 0;
	}
}

function Mascara(pControl, pMask)
{

	var valorAtual = pControl.value;
	var valorNumerico = '';
	var nIndexMask = 0;
	var nIndexString = 0;
	var valorFinal = '';
	var adicionarValor = true;


	// limpa a string valor atual para verificar
	// se todos os caracteres são números
	for (i=0;i<pMask.length;i++)
	{
		if (pMask.substr(i,1) != '#')
		{
			valorAtual = valorAtual.replace(pMask.substr(i,1),'');
		}
	}

	// verifica se todos os caracteres são números
	for (i=0;i<valorAtual.length;i++)
	{
		if (!isNaN(parseFloat(valorAtual.substr(i,1))))
		{
			valorNumerico = valorNumerico + valorAtual.substr(i,1);
		}
	}

	// aplica a máscara ao campo informado usando
	// o pMask de máscara informado no script
	for (i=0;i<pMask.length;i++)
	{

		if (pMask.substr(i,1) == '#')
		{
			if (valorNumerico.substr(nIndexMask,1) != '')
			{
				valorFinal = valorFinal + valorNumerico.substr(nIndexMask,1);
				nIndexMask++;nIndexString++;
			}
			else 
			{
				adicionarValor = false;
			}
		}
		else 
		{
			if (adicionarValor && valorNumerico.substr(nIndexMask,1) != '')
			{
				valorFinal = valorFinal + pMask.substr(nIndexString,1);
				nIndexString++;
			}
		}
	}
	
	pControl.value = valorFinal
}


/********************************************************************/


/*Funções Validação de Client ********************************************************************/

function VerifyTextNull(psMessage, poText)
{	
	if(isEmpty(poText))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}	
}

function VerifySpaces(psMessage, poText)
{
	if(isWhitespace(poText))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}


}

function VerifyIsValidIntegerRange(psMessage, psValue, piStart, piEnd)
{
	if(!(isIntegerInRange(psValue, piStart, piEnd)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}
	
}

function VerifyIsNumber(psMessage, pValue)
{	
	
	if(!(IsNumeric(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsPositiveNumber(psMessage, pValue)
{	
	
	if(!(isPositiveInteger(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsFloat(psMessage, pValue)
{	
	if(!(isFloat(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsValidDate(psMessage, pValue)
{
	
	if(!(isDate(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyValidCPF(psMessage, pValue)
{
	if(!(CPFValido(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsMail(psMessage, pValue)
{
	if(pValue == '')
	{
		return true;
	}

	if(!(isEmail(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsValidCNPJ(psMessage, pValue)
{
	if(!(FU_CGC(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

/* 0 - A primeira data é inválida
 1 - A segunda data é inválida
 2 - As duas datas são iguais
 3 - A 1ª data é a mais recente
 4 - A 2ª data é a mais recente */
function VerifyCompareDates(psMessage, psNoPrimeiraData, psNoSegundaData, pData1, pData2, piCondicaoMensagem)
{
	var iRetorno = CompareDates(pData1, pData2);
	
	if(iRetorno == 0)
	{
		alert('O campo ' + psNoPrimeiraData + ' inválido!')
		return false;
	}
	
	if(iRetorno == 1)
	{
		alert('O campo ' + psNoSegundaData + ' inválido!')
		return false;
	}
	
	if(iRetorno == piCondicaoMensagem)
	{
		alert(psMessage);
		return false;
	}
	
	return true;
}


/* Compara datas no formato dd/mm/aaaa
 0 - A primeira data é inválida
 1 - A segunda data é inválida
 2 - As duas datas são iguais
 3 - A 1ª data é a mais recente
 4 - A 2ª data é a mais recente */
function CompareDates(sData1, sData2)
{
	if (!isDate(sData1))
		return (0);
		
	if (!isDate(sData2))
		return (1);
		
	if (sData1 == sData2)
		return (2);
	else
	{
		var lData1 = parseFloat(sData1.substring(6, 10) + sData1.substring(3, 5) + sData1.substring(0, 2))
		var lData2 = parseFloat(sData2.substring(6, 10) + sData2.substring(3, 5) + sData2.substring(0, 2))
		if (lData1<lData2)
			return(3);
		else
			return(4);
	}
}

function VerifyDropDownList(psCombo, psMensagem, psFormName)
{
	psCombo = eval('document.' + psFormName + '.' + psCombo);
	if(psCombo.options[psCombo.selectedIndex].value == '')
	{
		alert(psMensagem);
		psCombo.focus();
		return false;
	} 
	return true;	
}

function VerifyValidCompleteHour(psMensagem, psValor)
{
	//Pega o valor corrente
	psValor = psValor.replace(':', '').replace(':', '');
	
	//O formato esta correto
	if(!(psValor.length == 6))
	{
		alert(psMensagem);
		return false;
	}

	//Separa em hora minuto e segundo
	var iHora	=	psValor.substring(0,2);
	var iMinuto =	psValor.substring(4,2);
	var iSegundo =	psValor.substring(4);
	
	//Compara a hora
	if(iHora > 23)
	{
		alert('Hora do campo ' + psMensagem + ' invalida');
		return false;
	}
	
	//Compara o minuto
	if(iMinuto > 59)
	{
		alert('Minuto do campo ' + psMensagem + ' invalido');
		return false;
	}
	
	//Compara o segundo
	if(iSegundo > 59)
	{
		alert('Segundo do campo ' + psMensagem + ' invalido');
		return false;
	}
	
	return true;
}

/*function VerifyRadioButtonList(psMensagem, poRadioButtonListName)
{

	var chkTable = eval(poRadioButtonListName);
	
	for(var i=0;i<chkTable.rows.length-1; i++)
	{
		var _chk = chkTable.rows[i] ;
		if(!(_chk.tagName ==  'TABLE'))
		{
			if(_chk.checked)
			{
				return true;
			}
		}
	}
 
	alert(psMensagem);
	return false;
}
*/
function VerifyRadioButtonList(psMensagem, poRadioButtonListName)
{
	var _isValid = false;
    var chkTable = window.document.all.item(poRadioButtonListName);
    
    for(var i = 0; i < chkTable.rows.length; i++)
	{
		var _chk = chkTable.rows(i).cells(0).children(0);
		if(_chk.checked)
		{
			_isValid = true;
            break;
        }

    }

    if(! _isValid)
    {
		alert(psMensagem);
        return false;
    }
	else
	{
		return true;
	}
}

function GetListTextsFromRadioButtonList(poRadioButtonListName)
{
	var _isValid = false;
    var chkTable = window.document.all.item(poRadioButtonListName);
    var sValores = '';
    for(var i = 0; i < chkTable.rows.length; i++)
	{
		var _chk = chkTable.rows(i).cells(0).children(0);
		if(_chk.checked)
		{
			sValores += _chk.parentElement.innerText + ';';
        }
    }
    return sValores.substring(0, sValores.length-1);
}

function ValidarSenhaeConfirmacaoSenha(poControleSenha, poControleConfSenha)
{
	poControleSenha = document.all.item(poControleSenha);
	poControleConfSenha = document.all.item(poControleConfSenha);
	
	
	//Executa a validação
	if(!(poControleSenha.value == poControleConfSenha.value))
	{
		alert('O campo senha e confirmar senha são diferentes')
		return false;
	}
	return true;
}

function VerifyCheckButtonList(psMensagem, poCheckButtonListName)
{
	var chkTable = window.document.all.item(poCheckButtonListName);
	
	for(var i=0;i<chkTable.rows.length; i++)
	{
		var _chk = chkTable.rows(i).cells(0).children(0);
		if(_chk.checked)
		{
			return true;
		}
	}

	alert(psMensagem);
	return false;
}


/********************************************************************/

/*Funções de Utilização Run Time ********************************************************************/

function SendPoupUp(strTarget, numAltura, numLargura, ynScroll)
{
	xposition=0; yposition=0; 
    if ((parseInt(navigator.appVersion,10) >= 4 ))
    { 
        xposition = (screen.width - numLargura) / 2; 
        yposition = (screen.height - numAltura) / 2; 
    } 
    args = "width=" + numLargura + "," 
    + "height=" + numAltura + "," 
    + "location=0," 
    + "menubar=0," 
    + "resizable=0," 
    + "scrollbars="+ynScroll+"," 
    + "status=0," 
    + "titlebar=0," 
    + "toolbar=0," 
    + "hotkeys=0," 
    + "directories=0,"
    + "copyhistory=0,"
    + "screenx=" + xposition + ","  //NN Only 
    + "screeny=" + yposition + ","  //NN Only 
    + "left=" + xposition + ","     //IE Only 
    + "top=" + yposition;           //IE Only 
    window.open( 'WindowOpened' , strTarget , args );
}

function OpenWindow(psNomePagina, psNomePopUp, psParametros)
{
	window.open(psNomePagina, psNomePopUp, psParametros);
}

function OpenPageRAD(psNomePagina)
{
	document.frmNextel.action = 'Default.aspx?Page=' + psNomePagina;
	document.frmNextel.method = 'post';
	document.frmNextel.submit();
}

function AbrirJanelaEnviarParaUmigo(psUrl) 	
{
	window.open ('Controles/wfIndiqueParaUmAmigo.aspx?_urlCorrente=' + psUrl, 'EnviarParaUmAmigo', 'width=350, height=190, Top=100, Left=300, menubar=no, toolbar=no, scrollbars=no, status=no');
	return false;
}

function EnterSubmit(NomeDoBotao){
	if (event.keyCode == 13){
		document.getElementById(NomeDoBotao).click();
		return false;
	}
}

function popup(vPagina, vNome, vHeight, vWidth, vTop, vLeft, vScrollbar, vToolbar, vLocation, vMenubar, vResizable)
{   
	var janela;
	var screenHeight;
	var screenWidth;
	screenHeight = screen.availheight;
	screenWidth  = screen.availwidth;

    if (typeof(screenHeight) == 'undefined')
		screenHeight = screen.height - 28

    if (typeof(screenWidth) == 'undefined')
        screenWidth = screen.width
            
    if (vHeight == 0)
        vHeight = screenHeight

    if (vWidth == 0)
        vWidth = screenWidth

    if (vHeight > screenHeight)
        vHeight = screenHeight;

    if (vWidth > screenWidth)
        vWidth = screenWidth;

    if (vTop == 0)
        vTop = ((screenHeight - vHeight) / 2);

    if (vLeft == 0)
        vLeft = ((screenWidth - vWidth) / 2);

    if (vHeight > (screenHeight - 30))
        vHeight = vHeight - 30;

    if (vWidth > (vWidth - 12))
        vWidth = vWidth - 12;

    if (vHeight + vTop * 2 >= screenHeight)
    {
        vHeight = vHeight - 2;
        vTop = vTop - 2;
	}

    janela = window.open(vPagina, vNome,'width=' + vWidth + ',height=' + vHeight + ',top=' + vTop+' , left=' + vLeft + ',scrollbars=' + vScrollbar + ',toolbar=' + vToolbar + ',location=' + vLocation + ',menubar=' + vMenubar + ',resizable=' + vResizable);
    janela.focus();
}

/*********************************************************************/		