﻿function NumberOnly(evt) 
{
   var charCode = (evt.which) ? evt.which : window.event.keyCode;
   var keyChar = String.fromCharCode(charCode);
   var re = /[0-9]/
   return re.test(keyChar);
}

function PhoneNumber(evt)
{
   	var charCode = (evt.which) ? evt.which : window.event.keyCode;
	var keyChar = String.fromCharCode(charCode);
	var re = /[\s\+0-9-]/
	return re.test(keyChar);
}

function AlphaSpace(evt)
{
   	var charCode = (evt.which) ? evt.which : window.event.keyCode;
	var keyChar = String.fromCharCode(charCode);
	var re = /[\s\a-zA-Z0-9ãõÃÕêÊáéíóúÁÉÍÓÚçÇ]/
	return re.test(keyChar);
}

function AlphaNumeric(evt)
{	
	var charCode = (evt.which) ? evt.which : window.event.keyCode;
	var keyChar = String.fromCharCode(charCode);
	var re = /[\s\?\*\@\#\(\)\$\%\&\!a-zA-Z0-9_-ãõÃÕêÊáéíóúÁÉÍÓÚçÇ]/
	return re.test(keyChar);
}

function CompareDates(sender, args)
{

  var mesInicio = document.getElementById('drpMesInicio');
  var anoInicio = document.getElementById('drpAnoInicio');
  
  var mesFim = document.getElementById('drpMesFim');
  var anoFim = document.getElementById('drpAnoFim');
  
  objDataInicio = new Date(parseInt(anoInicio.options[anoInicio.selectedIndex].value),parseInt(mesInicio.options[mesInicio.selectedIndex].value)-1,1);
  objDataFim = new Date(parseInt(anoFim.options[anoFim.selectedIndex].value),parseInt(mesFim.options[mesFim.selectedIndex].value)-1,1);
  
  if(objDataInicio > objDataFim)
  {
    
    args.IsValid = false;
    return;
  }
  
  args.IsValid = true;
}

function NavegarPagina(pagina)
{
     var blnSubmit = true;
	 frm.hdnNavegar.value = pagina;
	 frm.hdnAcao.value = "";
	if( frm.hdnClicouPaginar)
	{
		 frm.hdnClicouPaginar.value = "S";
	}

	if (blnSubmit) {
	    frm.submit();
    }
}

function fcnAtualizar(objTr, pValorBotao)
{
	var i = 0;
	var j = 0;
	var x = 0;
	var arrValores = "";
	var strIDCampo = "";
	var strValorCampo = "";
	var blnDesabilitaCampo;
	var objCampo;
	
	for (i=0;i<objTr.cells.length;i++)
	{
		if ((objTr.cells[i].getAttribute("id").length > 0) && (objTr.cells[i].getAttribute("id").search("_td") > -1))
		{
			strIDCampo = objTr.cells[i].getAttribute("id").search("_td"); // Pega posicao onde comeca o ID do TD
			strIDCampo = objTr.cells[i].getAttribute("id").substr(parseInt(strIDCampo+3)); // Recorta parte do ID do td que eh gerado pelo .NET
			strValorCampo = objTr.cells[i].getAttribute("innerText"); // Le o conteudo do TD
			objCampo = document.getElementById(strIDCampo);
			
			// Se for option, pega o option especifico
			if (strIDCampo.substr(0,3) == "opt")
				objCampo = document.getElementById("opt" + strValorCampo);

            
			// Verifica se o campo deve ser desabilitado
			blnDesabilitaCampo = false
			if (objTr.cells[i].getAttribute("desabilitar") != null)
			{
				if (objTr.cells[i].getAttribute("desabilitar").toLowerCase() == "true")
					blnDesabilitaCampo = true;
				else
					blnDesabilitaCampo = false;
			}
			
			// Verifica o tipo do campo
			if (objCampo != null)
			{
			    
				switch (objCampo.type)
				{
				    
					case "text":
					case "textarea":
						objCampo.value = strValorCampo;
						objCampo.disabled = blnDesabilitaCampo;
						if (blnDesabilitaCampo)
							objCampo.className = "desabilitado";
						break;
						
					/*case "textarea":
					    objCampo.innerText = document.getElementById(objTr.cells[i].getAttribute("id").substring(0,objTr.cells[i].getAttribute("id").search("_td")) + "_auxtd" + strIDCampo).value; // IE
						objCampo.value = document.getElementById(objTr.cells[i].getAttribute("id").substring(0,objTr.cells[i].getAttribute("id").search("_td")) + "_auxtd" + strIDCampo).value; // Opera
						objCampo.disabled = blnDesabilitaCampo;
						if (blnDesabilitaCampo)
							objCampo.className = "desabilitado";
						break;*/
					case "hidden":
						objCampo.value = strValorCampo;
						break;
					case "select-one":
						objCampo.value = strValorCampo;
						objCampo.disabled = blnDesabilitaCampo;
						if (blnDesabilitaCampo)
							objCampo.className = "desabilitado";
						if (objCampo.onchange != null) // Se tiver funcao no onchange, forca evento.
							objCampo.onchange();
						break;
					case "select-multiple":
						x=0;
						arrValores = strValorCampo.split(",");
						objCampo.selectedIndex = -1;
						for(x=0;x<objCampo.length;x++)
						{
							j = 0;
							for(j=0;j<arrValores.length;j++)
							{
								if (objCampo[x].value == arrValores[j])
								{
									objCampo[x].selected = true;
									break;
								}
							}
						}
						objCampo.disabled = blnDesabilitaCampo;
						break;
					case "checkbox":
						if ((strValorCampo.toLowerCase() == "true" ) || (strValorCampo.toLowerCase() == "s"))
							objCampo.checked = true;
						else
							objCampo.checked = false;
							
						objCampo.disabled = blnDesabilitaCampo;
						break;
					case "radio":
						if (blnDesabilitaCampo) // Desabilita todos os radios da colecao.
							eval("x=0; for (x=0;x<document.getElementById('frm')." + strIDCampo + ".length;x++) document.getElementById('frm')." + strIDCampo + "[x].disabled = true;")
							eval("x=0; for (x=0;x<document.getElementById('frm')." + strIDCampo + ".length;x++){ if(document.getElementById('frm')." 
							+ strIDCampo + "[x].value == '"+strValorCampo +"'){ document.getElementById('frm')." + strIDCampo + "[x].checked = true;}}")
						break;
					default:
						alert('default');
				}
			}
		}
	}
	
	frm.hdnAcao.value = "Alterar";
	frm.setAttribute("value",pValorBotao);
}


function ShowDiv()
{
    document.getElementById('divDados').style["display"] = 'block';
    document.getElementById('txTitulo').disabled = true;
    document.getElementById('txTitulo').className = "desabilitado";
    
    if(document.getElementById('txCodMensagem') != null)
        frm.hdnCodigo.value = document.getElementById('txCodMensagem').value;
}

function ShowDivUsuario()
{
    document.getElementById('divDados').style["display"] = 'block';
    document.getElementById('btnExcluir').style["visibility"] = "visible";
    frm.hdnEmail.value = document.getElementById('txEmail').value;
   
    EnableValidatorAlt();
    document.getElementById('txUsuario').disabled = false;
    document.getElementById('txUsuario').className = "textbox";
    
    document.getElementById('divPesquisa').style["display"] = 'none';
    
    return false;
}


function ShowDivNovoUsuario()
{
   frm.hdnEmail.value = '';
   document.getElementById('divDados').style["display"] = 'block';
   
   document.getElementById('txEmail').disabled = false;
   document.getElementById('txEmail').value = '';
   document.getElementById('txEmail').className = 'textbox';
   
   document.getElementById('txUsuario').disabled = true; 
   document.getElementById('txUsuario').value = ''; 
   document.getElementById('txUsuario').className = "desabilitado"; 
   
   EnableValidatorInc();
   
   document.getElementById('btnExcluir').style["visibility"] = "hidden";
   
   document.getElementById('divPesquisa').style["display"] = 'none';
   
   return false;
}

function EnableValidatorInc()
{
   ValidatorEnable(document.getElementById('reqtdtxUsuario'),false);
   document.getElementById('vsAtualizar').style['visibility'] = 'hidden';
   document.getElementById('vsAtualizar').style['display'] = 'none';
   document.getElementById('btnAtualizar').style['display'] = 'none';
   
   ValidatorEnable(document.getElementById('reqTxtEmail'),true);
   document.getElementById('vsIncluir').style['visibility'] = 'visible';
   document.getElementById('vsIncluir').style['display'] = 'block';
   document.getElementById('btnIncluir').style['display'] = 'block';
}

function EnableValidatorAlt()
{
   ValidatorEnable(document.getElementById('reqtdtxUsuario'),true);
   document.getElementById('vsAtualizar').style['visibility'] = 'visible';
   document.getElementById('vsAtualizar').style['display'] = 'block';
   document.getElementById('btnAtualizar').style['display'] = 'block';
   
   ValidatorEnable(document.getElementById('reqTxtEmail'),false);
   document.getElementById('vsIncluir').style['visibility'] = 'hidden';
   document.getElementById('vsIncluir').style['display'] = 'none';
   document.getElementById('btnIncluir').style['display'] = 'none';
}

function HideDiv()
{
   document.getElementById('divDados').style["display"] = 'none';
}

function HideDivUsuario()
{
   document.getElementById('divDados').style["display"] = 'none';
   document.getElementById('divPesquisa').style["display"] = 'block';
}

function LimitTextAreaSize(control)
{
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
     if(maxLength && value.length > maxLength-1)
     {
          event.returnValue = false;
          maxLength = parseInt(maxLength);
     }
}

function CheckPasteText(control)
{
    maxLength = control.attributes["maxLength"].value;
     if(maxLength)
     {
          event.returnValue = false;
     }
}

function AvoidPaste(control)
{
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
     if(maxLength)
     {
          event.returnValue = false;
          maxLength = parseInt(maxLength);
          var oTR = control.document.selection.createRange();
          var iInsertLength = maxLength - value.length + oTR.text.length;
          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
          oTR.text = sData;
     }
}

function ConfirmaExcluir()
{
    if(confirm('Deseja realmente excluir este usuário?'))
    {
        frm.hdnExcluir.value = true;
        LimparOrdenacao();
        frm.submit();
    }
}

function LimparOrdenacao()
{
  frm.hdnAscDesc.value = '';
  frm.hdnOrderBy.value = '';
  frm.hdnPaginaAtual.value = '1';
}

function LimparPesquisaUsuario()
{
    document.getElementById('txtNmUsuario').value = '';
    document.getElementById('txtEmailusuario').value = '';
}

function LimparPesquisaRespostas()
{
  var id = "";
  for(i=0;i<5;i++)
  {
    id = "ckl_TPAS_TipoAssunto_"+i;
    document.getElementById(id).checked = false;
  }
  
  for(i=0;i<7;i++)
  {
    id = "ckl_MSGC_Competencias_Organizacionais_"+i;
    document.getElementById(id).checked = false;
  }
  
  for(i=0;i<4;i++)
  {
    id = "ckl_MSGC_Cargos_Lideranca_"+i;
    document.getElementById(id).checked = false;
  }
  
  for(i=0;i<1;i++)
  {
    id = "ckl_MSGC_Cargos_Tecnicos_"+i;
    document.getElementById(id).checked = false;
  }
  
    for(i=0;i<3;i++)
  {
    id = "ckl_MSGC_Areas_Vendas_"+i;
    document.getElementById(id).checked = false;
  }
  
  var mes = new Date();
  var anoInicial = 2009;
  
  document.getElementById('txtCodigoMsg').value = '';
  document.getElementById('drpMesInicio').selectedIndex = mes.getMonth();
  document.getElementById('drpAnoInicio').selectedIndex = mes.getFullYear - anoInicial;
  document.getElementById('drpMesFim').selectedIndex = mes.getMonth();
  document.getElementById('drpAnoFim').selectedIndex = mes.getFullYear - anoInicial;
  
  if(document.getElementById('drpPublicadas') != null)
  {
    document.getElementById('drpPublicadas').selectedIndex = 0;
  }
  
}

function MostrarOrganizacionais()
{
    window.open("Competencias/Organizacionais.htm","","menubar=0,toolbar=0,location=0,scrollbars=1");
}

function MostrarLideranca()
{
    window.open("Competencias/Lideranca.htm","","menubar=0,toolbar=0,location=0,scrollbars=1");
}

function MostrarTecnicos()
{
    window.open("Competencias/Tecnicos.htm","","menubar=0,toolbar=0,location=0,scrollbars=1");
}


function MostrarVendas()
{
    window.open("Competencias/Vendas.htm","","menubar=0,toolbar=0,location=0,scrollbars=1");
}
