var defaultEmptyOK = false;
var decimalPointDelimiter = ",";	

function fnDisableList(objCheck){
	var objNews = document.getElementById("cuAtributo208Valor_0");
	var objData = document.getElementById("cuAtributo19Valor");
	var intIndice = 0;
	
	if(objNews == null){
		objNews = document.getElementById(objCheck.name.substring(0, objCheck.name.indexOf(":")) + "_cuAtributo208Valor_0");
		intIndice = objCheck.name.indexOf(":") + 1;
	}
		
	if(objData == null){
		objData = document.getElementById(objCheck.name.substring(0, objCheck.name.indexOf(":")) + "cuAtributo19Valor");
	}

	for (var i = 0; i < document.forms[0].length; i++){
		//alert(document.forms(0).item(0).name)
		//alert(document.forms(0).item(i).name.substring(intIndice, 10 + intIndice).toUpperCase() + "\n\n" + document.forms(0).item(i).name.substring(0,11).toUpperCase())
		
		if (document.forms[0].elements[i].name.substring(intIndice, 10 + intIndice).toUpperCase() == 'CUATRIBUTO' || document.forms[0].elements[i].name.substring(intIndice, 11 + intIndice).toUpperCase() == 'CONFIRMACAO') {
			//alert(document.forms(0).item(0).name.substring(0,13).toUpperCase())
			if ((document.forms[0].elements[i].type.toUpperCase() == 'CHECKBOX' && document.forms[0].elements[i].name.substring(intIndice, 12 + intIndice).toUpperCase() == 'CUATRIBUTO21') || document.forms[0].elements[i].name.substring(intIndice, 13 + intIndice).toUpperCase() == 'CUATRIBUTO207' || document.forms[0].elements[i].name.substring(intIndice, 13 + intIndice).toUpperCase() == 'CUATRIBUTO208'){
				document.forms[0].elements[i].disabled = !(objNews.checked && objCheck.checked);
			}
			else {
				document.forms[0].elements[i].disabled = !objCheck.checked;
			}
		}
	}
	fnValidarIdade(objData);	
	objCheck.disabled = false;
}

function fnEstudante(objEst){	
	
	var strPrefixo = objEst.substring(0, objEst.indexOf("cuAtributo"));
	
	var objEstudante= document.getElementById(objEst);
	var objTpReg	= document.getElementById(strPrefixo + "cuAtributo261Valor");
	var objTxNoReg	= document.getElementById(strPrefixo + "cuAtributo259Valor");
	var objUfReg	= document.getElementById(strPrefixo + "cuAtributo262Valor");
	var objEsp		= document.getElementById(strPrefixo + "cuAtributo260Valor");
	
	if(objEstudante.selectedIndex != 2)
	{
		objTpReg.disabled = true;
		objTxNoReg.disabled = true;
		objUfReg.disabled = true;
		objEsp.disabled = true;	
		
		objTpReg.selectedIndex = 0;
		objTxNoReg.value = "";
		objUfReg.selectedIndex = 0;
		objEsp.selectedIndex = 0;	
	}
	else
	{		
		objTpReg.disabled = false;
		objTxNoReg.disabled = false;
		objUfReg.disabled = false;
		objEsp.disabled = false;
	}	
	return true;		
}

function fnValidarEstudante(objEst){	
	
	var strPrefixo = objEst.substring(0, objEst.indexOf("cuAtributo"));
	
	var objEstudante= document.getElementById(objEst);
	var objTpReg	= document.getElementById(strPrefixo + "cuAtributo261Valor");
	var objTxNoReg	= document.getElementById(strPrefixo + "cuAtributo259Valor");
	var objUfReg	= document.getElementById(strPrefixo + "cuAtributo262Valor");
	var objEsp		= document.getElementById(strPrefixo + "cuAtributo260Valor");
	
	if(objEstudante.selectedIndex == 2)
	{
		if(objTpReg.selectedIndex == 0)
		{
			alert('Por favor preencha o campo Tipo de Registro');
			objTpReg.focus();
			return false;
		}
		if(isEmpty(objTxNoReg.value))
		{
			alert('Por favor preencha o campo Número de Registro');
			objTxNoReg.focus();
			return false;
		}
		if(objUfReg.selectedIndex == 0)
		{
			alert('Por favor preencha o campo UF Registro');
			objUfReg.focus();
			return false;
		}
		if(objEsp.selectedIndex == 0)
		{
			alert('Por favor preencha o campo Especialidade');
			objEsp.focus();
			return false;
		}
	}	
	return true;		
}

function VerifyEmailResp(psMessage, poText){
	var objData = document.getElementById("_ctl2_cuAtributo19Valor");
	var age = fnReturnAge(objData.value);
	if (age < 12){
		if (!isEmailExpReg(poText)) {
			alert(psMessage);
			return false;
		}
		else {
			return true;
		}		
	}
	else {
		return true;
	}
}
function VerifyRespName (psMessage, poText){
	var objData = document.getElementById("_ctl2_cuAtributo19Valor");
	var age = fnReturnAge(objData.value);
	if (age < 12){
		if (isEmpty(poText)) {
			alert(psMessage);
			return false;
		}		
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function fnValidarIdade(poCampo){
	if(poCampo != null){
		var objTr = document.getElementById("trResp128")
		if (objTr != null) {
			var age = fnReturnAge(poCampo.value);
			
			if (age < 12){
				trResp128.style.display = '';
				trResp129.style.display = '';
			}
			else {
				trResp128.style.display = 'none';
				trResp129.style.display = 'none';
			}
		}
	}
}

function fnReturnAge(poCampo){
	dd = parseInt(poCampo.substring(0,2));
	mm = parseInt(poCampo.substring(3,5));
	yy = parseInt(poCampo.substring(6,10));
	
	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear = days.getFullYear();

	if (gyear < 2000) {
		gyear += 1900;
	}

	age = gyear - yy;

	if ((mm == (gmonth + 1)) && (dd <= parseInt(gdate)))  {
		age = age; 
	} 
	else {
		if (mm <= (gmonth))  {
			age = age;
		} 
		else  { 
			age = age - 1; 
		}
	}
	return age;
}

function VerifyNewsLetter(){
	var blnCheck = false;
	var objNews = document.getElementById("_ctl2_cuAtributo208Valor_0");
	var objTipo = document.getElementById("_ctl2_cuAtributo207Valor")
	
	if (objNews.checked){
		for (var i = 0; i < document.forms[0].length; i++){
			if (document.forms[0].elements[i].type.toUpperCase() == 'CHECKBOX' && document.forms[0].elements[i].name.substring(6,18).toUpperCase() == 'CUATRIBUTO21') {
				if (document.forms[0].elements[i].disabled) {
					blnCheck = false;
					break;
				}
				else if (document.forms[0].elements[i].checked){
					blnCheck = true;
					break;	
				}
			}
		}
		if (!blnCheck){
			alert("Selecione ao menos um assunto de seu interesse para receber nossa Newsletter");
			return false;
		}
		//else if (!(document.all["_ctl2_cuAtributo207Valor_0"].checked || document.all["_ctl2_cuAtributo207Valor_1"].checked)){
		else if (!(document.getElementById("_ctl2_cuAtributo207Valor").selectedIndex > 0)){
			alert("Selecione o formato no qual deseja receber nossas Newsletter");
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function fnNewsLetters(strCheck){
	var objNews = document.getElementById("cuAtributo208Valor_0");
	//alert(strCheck)
	for (var i = 0; i < document.forms[0].length; i++){
		
		try{
			indice = document.forms[0].elements[i].name.indexOf(":");
		}
		catch(e){
			indice = -1;
		}
		
		if(indice > -1){
			if (document.forms[0].elements[i].type.toUpperCase() == 'CHECKBOX' && document.forms[0].elements[i].name.substring(indice + 1, 13 + indice).toUpperCase() == 'CUATRIBUTO21') {
				if(objNews == null){
					objNews = document.getElementById(document.forms[0].elements[i].name.substring(0, document.forms[0].elements[i].name.indexOf(":")) + "_cuAtributo208Valor_0");
				}
				
				if (!objNews.checked) {
					document.forms[0].elements[i].checked = false;
				}
				document.forms[0].elements[i].disabled = !objNews.checked;
			}
			if (document.forms[0].elements[i].name.substring(indice + 1, 14 + indice).toUpperCase() == 'CUATRIBUTO207'){
				document.forms[0].elements[i].selectedIndex = 0;
				document.forms[0].elements[i].disabled = !objNews.checked;
			}		
		}
		else{
			if (document.forms[0].elements[i].type.toUpperCase() == 'CHECKBOX' && document.forms[0].elements[i].name.substring(0,12).toUpperCase() == 'CUATRIBUTO21') {
				if(objNews == null){
					objNews = document.getElementById(obkCheck.name.substring(0, obkCheck.name.indexOf(":")) + "_cuAtributo208Valor_0");
				}
				
				if (!objNews.checked) {
					document.forms[0].elements[i].checked = false;
				}
				document.forms[0].elements[i].disabled = !objNews.checked;
			}
			if (document.forms[0].elements[i].name.substring(0,13).toUpperCase() == 'CUATRIBUTO207'){
				document.forms[0].elements[i].selectedIndex = 0;
				document.forms[0].elements[i].disabled = !objNews.checked;
			}
		}
	}
}

function VerifyTerm(psMessage, pChecked) {
	if(!pChecked.checked){
		alert(psMessage);
		return false;
	}
	else {
		return true;
	}
}

function VerifyURL(psMessage, poText){
	if(isEmpty(poText)){
		return true;
	}
	else if(poText.substring(0,7) != "http://"){
		alert(psMessage);
		return false;
	}
	else {
		return true;
	}
}


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);	
	}
}

function fnTermoAceite(obkCheck, objForm){
	var objNews = document.getElementById("cuAtributo208Valor_0");
	var objEstudante = document.getElementById("cuAtributo273Valor");
	var indice;
	
	for (var i = 0; i < objForm.length; i++){

		indice = objForm.elements[i].name.indexOf(":");
		
		if(indice > -1){
			if (objForm.elements[i].name.substring(indice + 1 ,11 + indice).toUpperCase() == 'CUATRIBUTO' || objForm.elements[i].name.substring(indice + 1, 12 + indice).toUpperCase() == 'CONFIRMACAO') {
				if ((objForm.elements[i].type.toUpperCase() == 'CHECKBOX' && objForm.elements[i].name.substring(indice + 1, 13 + indice).toUpperCase() == 'CUATRIBUTO21') || objForm.elements[i].name.substring(indice + 1, 14 + indice).toUpperCase() == 'CUATRIBUTO207') {
					if(objNews == null){
						objNews = document.getElementById(obkCheck.name.substring(0, obkCheck.name.indexOf(":")) + "_cuAtributo208Valor_0");
					}
					
					if(objNews != null){
						objForm.elements[i].disabled = !(objNews.checked && obkCheck.checked);
					}
				}
				else {
					objForm.elements[i].disabled = !obkCheck.checked;
				}
			}
		}
		else{
			if (objForm.elements[i].name.substring(0,10).toUpperCase() == 'CUATRIBUTO' || objForm.elements[i].name.substring(0,11).toUpperCase() == 'CONFIRMACAO') {
				if ((objForm.elements[i].type.toUpperCase() == 'CHECKBOX' && objForm.elements[i].name.substring(0,12).toUpperCase() == 'CUATRIBUTO21') || objForm.elements[i].name.substring(0,13).toUpperCase() == 'CUATRIBUTO207') {
					objForm.elements[i].disabled = !(objNews.checked && obkCheck.checked);
				}
				else {
					objForm.elements[i].disabled = !obkCheck.checked;
				}
			}
		}
	}
	//O cd_atributo do campo é diferente de Aceite e Desenvolvimento
	//Por este motivo os campo não estão desabilitados em desenvolvimento
	if(objEstudante == null){		
		objEstudante = document.getElementById(obkCheck.name.substring(0, obkCheck.name.indexOf(":")) + "_cuAtributo273Valor");		
	}
	if(objEstudante != null){
		
		fnEstudante(objEstudante.id);
	}
}

		
/*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;
	
	while(Arg_Cgc.indexOf(".")>-1 || Arg_Cgc.indexOf("-")>-1 || Arg_Cgc.indexOf("/")>-1){
		Arg_Cgc = Arg_Cgc.replace(".", "");
		Arg_Cgc = Arg_Cgc.replace("-", "");
		Arg_Cgc = Arg_Cgc.replace("/", "");
	}
	
    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)
{
	while(s.indexOf(".")>-1 || s.indexOf("-")>-1){
		s = s.replace(".", "");
		s = s.replace("-", "");
	}
	
	if(isEmpty(s)){
		return true;
	}
	else 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 isEmailExpReg (s) {   

	var regExp = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	return (regExp.test(s) && s.toUpperCase().indexOf("WWW") == -1 && s.toUpperCase().indexOf("HTTP") == -1);

}

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()
{
	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 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 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 fnVerMascara (pControl, blnBlur){

	if (blnBlur) {
		if (pControl.value.length == 13){
			Mascara(pControl, '(##) ###-####')
		}
	}
	else {
		if (event.keyCode < 37 || event.keyCode > 40){
			if (pControl.value.length <= 12){
				Mascara(pControl, '(##) ###-####')
			}
			else {
				Mascara(pControl, '(##) ####-####')
			}
		}
	}
}

function VerifyValidCep(psMessage, poText){
	var rExp;
	rExp = /^\d{5}\-\d{3}$/;
	
	if (isEmpty(poText)) {
		return true;
	}
	else {
		if(!rExp.test(poText)) {
			alert(psMessage);
			return false;
		}
		else {
			return true;
		}
	}
}
function VerifyValidFone(psMessage, poText){
	var rExp;
	rExp = /^\(\d{2}\) \d{3,4}\-\d{4}$/;
	
	if (isEmpty(poText)) {
		return true;
	}
	else {
		if(!rExp.test(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)))
	{
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsValidDate(psMessage, pValue)
{
	if(!(isDate(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		var objTr = document.getElementById("trResp128")
		if (objTr != null) {
			if (trResp128.style.display == '') {
				return true;
			}
			else {
				var age = fnReturnAge(pValue);
				if (age < 12){
					trResp128.style.display = '';
					trResp129.style.display = '';
					return false;
				}
				else {
					trResp128.style.display = 'none';
					trResp129.style.display = 'none';
					return true;
				}
			}
		}
		else {
			return true;
		}
	}

}

//Data maior que a atual
function VerifyIsGreaterToday(psMessage, pValue){
	var dia, mes, ano;
	var date = new Date();
	var data;
	
	if(VerifyIsValidDate(psMessage, pValue)){
		dia = "0".toString() + date.getDate();
		mes = "0".toString() + date.getMonth();
		ano = date.getFullYear();
		
		data = dia.substring(dia.length-2, dia.length) + "/" + mes.substring(mes.length-2, mes.length) + "/" + ano
		if(CompareDates(pValue, data) != 4){
			alert(psMessage);
			return false;
		}
		else{
			return true;
		}
	
	}
	else{
		return false;
	}
}

//Data menor que a atual
function VerifyIsMinorToday(psMessage, pValue){
	var dia, mes, ano;
	var date = new Date();
	var data;
	
	if(VerifyIsValidDate(psMessage, pValue)){
		dia = "0".toString() + date.getDate();
		mes = "0".toString() + date.getMonth();
		ano = date.getFullYear();
		
		data = dia.substring(dia.length-2, dia.length) + "/" + mes.substring(mes.length-2, mes.length) + "/" + ano
		if(CompareDates(pValue, data) != 3){
			alert(psMessage);
			return false;
		}
		else{
			return true;
		}
	
	}
	else{
		return false;
	}
}


function VerifyValidCPF(psMessage, pValue)
{
	if(!(CPFValido(pValue)))
	{
		alert(psMessage);
		return false;
	}
	else
	{
		return true;
	}

}

function VerifyIsMail(psMessage, pValue)
{
	if(pValue == '')
	{
		return true;
	}

	if(!(isEmailExpReg(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)
{
	alert(psMensagem)
	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 = window.document.all.item(poRadioButtonListName);
	
	for(var i=0;i<chkTable.length; i++)
	{
		var _chk = chkTable[i] ;
		if(!(_chk.tagName ==  'TABLE'))
		{
			if(_chk.checked)
			{
				return true;
			}
		}
	}
 	alert(psMensagem);
	return false;
}

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 devem ser iguais!')
		return false;
	}
	return true;
}

function ValidarEmaileConfirmacaoEmail(poControleEmail, poControleConfEmail)
{
	
	poControleEmail = document.all.item(poControleEmail);
	poControleConfEmail = document.all.item(poControleConfEmail);
	
	//Executa a validação
	if(!(poControleEmail.value == poControleConfEmail.value))
	{
		alert('O campo email e confirmar email devem ser iguais')
		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 fnExibePower(strId){
	var prefixo="";
	
	if((document.getElementById(strId + "_5"))==undefined){
		for(var i=0; i<document.forms[0].length; i++){
			if(document.forms[0].elements[i].type == "checkbox"){
				if(document.forms[0].elements[i].name.indexOf('cuAtributo208Valor')>-1){
					prefixo = document.forms[0].elements[i].name.substring(0, document.forms[0].elements[i].name.indexOf(":")) + "_"
					i = document.forms[0].length;
				}
			}
		}
	}
	
	if(document.getElementById(prefixo + strId + "_5").checked){
		document.getElementById("trPower").style.display="";
	}
	else{
		document.getElementById("trPower").style.display="none";
	}
}



/*********************************************************************/		


