﻿// Visualiza newsletter
function VisualizaNews(id)
{
    var news = window.open('#ROOT_DIR#newsletter/?txtCod='+id, 'Newsletter' , 'scrollbars=yes,left=100,top=10,width=550,height=450');
    news.focus();
}

//envia newsletter
function EnviaNews(id)
{
    var x = x = screen.width;
	x = x - 300;
	
    var news = window.open('envia.aspx?txtCod='+id, 'Enviar' , 'scrollbars=no,left='+x+',top=5,width=250,height=200'); //300 x 250
    news.focus();
}

//servicos
function PopServicos(url)
{
    var news = window.open(url, 'Servicos' , 'scrollbars=yes,left=0,top=0,width=778,height=550');
    news.focus();
}

//servicos
function PopServicosNet(url)
{
    var news = window.open(url, 'ServicosAGV' , 'width=830, height=630, left=0, top=0, status=no, resizable=yes, scrollbars=no, toolbar=no, location=no, menubar=no, directories=no, titlebar=no, padding=0px 0px 0px 0px');
    news.focus();
}

function PopUpRedirectServicos(url, usuario, senha, numPN, canal){
  var mywindow;
  var html;
//  mywindow = window.open('', 'servicos','location=no,toolbar=yes,menubar=no,scrollbars=yes,resizable=yes'); 
//  mywindow.document.writeln('<html><body>');
//  mywindow.document.writeln('<form name="srvForm" target="_blank" method="post" action="'+url'">');
//  mywindow.document.writeln('<input type="hidden" name="usuario"   value="'+usuario+'">');
//  mywindow.document.writeln('<input type="hidden" name="senha"     value="'+senha  +'">');
//  mywindow.document.writeln('<input type="hidden" name="ParceiroDeNegocio"  value="'+numPN+'">');
//  mywindow.document.writeln('<input type="hidden" name="CodCanal"  value="'+canal  +'">');
//  mywindow.document.writeln("</form>");
//  mywindow.document.writeln("<script>document.srvForm.submit();</script>");
//  mywindow.document.writeln("</body></html>");
//  mywindow.focus();
  //mywindow.close();
}


//cria campos de resposta da enquete
var arrInput = new Array(0);
var arrInputValue = new Array(0);

function AdicionaImput() {
   
    if(arrInput.length > 10){
        alert('A Enquete deve conter no máximo 10 respostas!');
    }
    else
    {
        arrInput.push(arrInput.length);
        //arrInputValue.push(arrInputValue.length);
        arrInputValue.push("");
        document.getElementById('hndTotal').value = (parseInt(document.getElementById('hndTotal').value)+1);
        display();
    }
}

function AdicionaImputServidor() {

        arrInput.push(arrInput.length);
        //arrInputValue.push(arrInputValue.length);
        arrInputValue.push("");
        document.getElementById('hndTotal').value = (parseInt(document.getElementById('hndTotal').value)+1);
        display();
}

function display() {
  document.getElementById('txtResposta').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('txtResposta').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);  
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
 
  return "<input type='text' size='50' maxlength='255' name='txtResposta"+id+"'  id='txtResposta"+(parseInt(id))+"' onChange='javascript:saveValue("+id+",this.value)' value='"+ value +"'><br>";
  
}

function DeletaImput(){
  
  if (arrInput.length > 2) { 
     if (arrInput.length > 0){ 
         arrInput.pop(); 
         arrInputValue.pop();
    }
  
  document.getElementById('hndTotal').value = (parseInt(document.getElementById('hndTotal').value)-1);
  display();  
  
  }
  else{
    alert('A Enquete deve conter pelo menos 2 respostas!');
  }
  
}

function DeletaImputServidor(){
  
  if (arrInput.length > 1) { 
     if (arrInput.length > 0){ 
         arrInput.pop(); 
         arrInputValue.pop();
    }
  
  document.getElementById('hndTotal').value = (parseInt(document.getElementById('hndTotal').value)-1);
  display();  
  
  }
  else{
    alert('Deve conter pelo menos 1 servidor!');
  }
  
}

//valida enquete
function ValidaEnquete(){

        var msg = "<ul>";
        var erro = 0;
        
        if(document.getElementById("ctl00_cttConteudo_txtPergunta").value == ""){
           msg += "<li>Preencha o campo Pergunta</li>";
           erro = 1;
       } 
       
       
       if(document.getElementById("ctl00_cttConteudo_rblStatus_0").checked == false && document.getElementById("ctl00_cttConteudo_rblStatus_1").checked == false){
           msg += "<li>Marque o Status da Enquete.</li>";
           erro = 1;
       } 
       
       
        
       if(document.getElementById("txtResposta0").value == ""){
           msg += "<li>Preencha o campo da 1ª resposta</li>";
           erro = 1;
       }
       
       if(document.getElementById("txtResposta1").value == ""){
           msg += "<li>Preencha o campo da 2ª resposta</li>";
           erro =1;
       }
       
        msg += "</ul>";
        
       if(erro == 1){
            document.getElementById("spnEnquete").innerHTML = msg;
            return false;
       }
       
        
}


function Validaservidor(){

        var msg = "<ul>";
        var erro = 0;
        
       if(document.getElementById("txtResposta0").value == ""){
           msg += "<li>Preencha no mínimo 1 servidor</li>";
           erro = 1;
       }
       
        msg += "</ul>";
        
       if(erro == 1){
            document.getElementById("spnEnquete").innerHTML = msg;
            return false;
       }
       
        
}


//tamanho da font
function FontSize(text_size) {
    //var oLnk = document.getElementById("ctl00_cssSize");    
    var oLnk = document.getElementById("cssSize");    
    var s = "#ROOT_DIR#css/" + text_size+ ".css"; 
    oLnk.href = s;
    var datDate = new Date(); var datNextYear = datDate
    datNextYear.setTime(datDate.getTime()+31536000000)
    document.cookie = "txtSize="+text_size+"; expires="+datNextYear.toGMTString()+"; path=/"
}

//verifica se já existe o cookie 
function get_cookie ( cookie_name )
{
    var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
    if (results){ 
        return (unescape(results[1]));
    }
    else
    {
        return null;
    }
}


function ValidaBusca(){

    if (document.getElementById("ctl00_txtBusca").value == "")
    {
        document.getElementById("spnBusca").innerHTML = "Digite uma plavra chave para efetuar a busca.";
        return false;
    }

    if (document.getElementById("ctl00_txtBusca").value.length < 3)
    {
        document.getElementById("spnBusca").innerHTML = "A palavra chave deve ter mais de 3 caracteres.";
        return false;
    }

}

function tecla(){
 
    if (event.keyCode==13){
       event.keyCode.disabled = true;
       return false;
    }
//document.onkeydown = tecla;
}

window.status = "Agência Virtual";
//setInterval("window.status='Agência Virtual';",10);
