﻿/************************************************************
//
//
//              ROTINAS GLOBAIS DE JAVASCRIPT
//
//
/*************************************************************/

/************************************************************
//funcionalidades
/*************************************************************/
//=================================================================

function setTrataTela()
{
   var strPrefixo = document.getElementById('WUCHeader1_1$cboTipoArea')? 'WUCHeader1_1$':'ctl00_WUCHeader11_';
   
   switch (document.getElementById(strPrefixo+'cboTipoArea').value.toLowerCase()) {
     	
	   case "associado":    
         document.getElementById('lbl_login').innerHTML ="Inscrição:";   
         document.getElementById(strPrefixo+'str_inscricao').style.width = 62; //só no IE
         document.getElementById(strPrefixo+'str_inscricao').maxchars = 8;
	   break;	
	   case "corretor":
	   	   
	      document.getElementById('lbl_login').innerHTML ="Usuário:";   
         document.getElementById(strPrefixo+'str_inscricao').style.width = 116; //só no IE
	      document.getElementById(strPrefixo+'str_inscricao').maxchars = 35; 
   	   
	   break;
	   case "parceiro":
	     
   	   
	   break;

   }
}



//=================================================================
//faz o encaminhamento de aordo com a opção escolhida na tela
function getLoginArea()
{    

var strPrefixo = document.getElementById('WUCHeader1_1$cboTipoArea')? 'WUCHeader1_1$':'ctl00_WUCHeader11_';
var strPrefixo2 = document.getElementById('WUCHeader1_1$cboTipoArea')? '':'ctl00_';

var objForm = document.forms[0];

    document.getElementById(strPrefixo2 +'str_inscricao').value = document.getElementById(strPrefixo+'str_inscricao').value;
    document.getElementById(strPrefixo2 +'str_senha').value = document.getElementById(strPrefixo+'str_senha').value;
  
//alert(document.getElementById('WUCHeader1_1$cboTipoArea').value.toLowerCase());
switch (document.getElementById(strPrefixo+'cboTipoArea').value.toLowerCase()) {
	
	case "associado":    
      objForm.action='http://www.aplubnet.com.br/areadoassoc/areadoassoc.asp'; 
      
	break;	
	case "corretor":
	   //alert('http://localhost/sga/Forms/wfrmLogin.aspx?urlPedindoAutenticacao=http://localhost/PortalWeb/Corretores/Produtos.aspx?idaba=6');
	  // objForm.action='http://localhost/sga/Forms/wfrmLogin.aspx?urlPedindoAutenticacao=http://localhost/PortalWeb/Corretores/Produtos.aspx?idaba=6';
	    login();
	   
	break;
	case "parceiro":
	   objForm.action='http://www.aplubnet.com.br/areadoassoc/areadoassoc.asp';
	   
	break;

}
objForm.submit();

}
//=================================================================
//submete um form para o SGA com as informações do usuario
function login()
{
var strPrefixo = document.getElementById('WUCHeader1_1$cboTipoArea')? 'WUCHeader1_1$':'ctl00_WUCHeader11_';
var strHtml  = "";
//var strAction=  "http://localhost/sga/forms/wfrmlogin.aspx?urlPedindoAutenticacao=http://localhost/PortalWeb/Corretores/Produtos.aspx?idaba=6";
//sga quente

window.location.host
  strAction='http://sga.aplub.com.br/sga/Forms/wfrmLogin.aspx?urlPedindoAutenticacao=http://' + window.location.hostname +'/PortalWeb/Corretores/Produtos.aspx?idaba=6';
      //Monta o Form
      strHtml += "<Form Method='Post' id='frm' Action='" + strAction + "' >";
      //Monta o Hidden, com o login
      strHtml += "<input type='hidden' name='usuario' value='" + document.getElementById(strPrefixo+'str_inscricao').value + "' />";
      strHtml += "<input type='hidden' name='senha' value='" + document.getElementById(strPrefixo+'str_senha').value + "' />";
      strHtml += "</Form>";
//alert(strHtml);
      //Monta javascript para submeter o form
      strHtml += "<script language='javascript'>";
      strHtml += "document.getElementById('frm').submit();";
      strHtml += "<"+"/script>";

//alert(strHtml);
     document.write(strHtml);
      Response.End();
}

//=============================================================================

//function getLoginAreaOLD()
//{

//var objForm = document.getElementById('form1');

//    document.getElementById('str_inscricao').value = document.getElementById('WUCHeader1_1_str_inscricao').value;
//    document.getElementById('str_senha').value = document.getElementById('WUCHeader1_1_str_senha').value;
////alert(document.getElementById('WUCHeader1_1$cboTipoArea').value.toLowerCase());
//switch (document.getElementById('WUCHeader1_1$cboTipoArea').value.toLowerCase()) {
//	
//	case "associado":    
//      objForm.action='http://www.aplubnet.com.br/areadoassoc/areadoassoc.asp';
//      
//     
//	break;	
//	case "corretor":
//	//alert('http://localhost/sga/Forms/wfrmLogin.aspx?urlPedindoAutenticacao=""http://localhost/PortalWeb/Corretores/Produtos.aspx?idaba=6""');
//   // objForm.action='http://localhost/sga/Forms/wfrmLogin.aspx?urlPedindoAutenticacao=http://localhost/PortalWeb/Corretores/Produtos.aspx?idaba=6';
// 
//   //SGA - quente
//   objForm.action='http://201.70.85.196/sga/Forms/wfrmLogin.aspx?urlPedindoAutenticacao=http://localhost/PortalWeb/Corretores/Produtos.aspx?idaba=6';
//	  
//	break;
//	case "parceiro":
//	   objForm.action='http://www.aplubnet.com.br/areadoassoc/areadoassoc.asp';
//	  
//	break;

//}
//objForm.submit();

//return true;
//}

//===============================================================

//Função que faz o login na área de associado
function getAreaAssociado()
{
    /*
    alert(document.getElementById('WUCHeader1_1_str_inscricao').value);
    alert(document.getElementById('WUCHeader1_1$cboTipoArea').value);
    */
    
    //se opção for diferente de associado selecionada então
    if (document.getElementById('WUCHeader1_1$cboTipoArea').value.toLowerCase() != 'associado') 
    {        
        alert('Os Campos [Inscrição] e [Senha] são para a área restrita de Associado.\nPor favor, selecione a área correta.');
        document.getElementById('str_senha').value = '';
        document.getElementById('WUCHeader1_1_str_senha').value = '';
        return false;
    }
        
    var objForm = document.getElementById('form1');

    document.getElementById('str_inscricao').value = document.getElementById('WUCHeader1_1_str_inscricao').value;
    document.getElementById('str_senha').value = document.getElementById('WUCHeader1_1_str_senha').value;
    //objForm.action='http://aplubnet.des02/areadoassoc/areadoassoc.asp';
    //objForm.action='https://www.aplubnet.com.br/areadoassoc/areadoassoc.asp';
    objForm.action='http://www.aplubnet.com.br/areadoassoc/areadoassoc.asp';
    objForm.submit();
    return true;
}

//======================================================

//Redireciona o usuário de acordo com opção selecinada na Cotação Online
function getRedirectPage(objSelect)
{
    //alert(objSelect.options[objSelect.selectedIndex].value);
    var url = (objSelect.options[objSelect.selectedIndex].value);
    if((url != '') &&
       (url != '#'))
    {
        window.location = url;
    }
    
}

//======================================================

//Redireciona o usuário para área de parceiros
function getAreaParceiro(objSelect)
{    
    
    //alert(objSelect.options[objSelect.selectedIndex].value);
    var strValue = (objSelect.options[objSelect.selectedIndex].value);    
    if(strValue == 'parceiro') 
    {
        window.location = 'http://www.aplub.com.br/parceria/login.asp';
    }
    
}

//======================================================

//Função que faz envia os dados para a rotina de BUSCA do site da APLUB (www.aplub.com.br)
function getBuscaSiteAplub()
{

    var objForm = document.getElementById('form1');

    var search = document.getElementById('search').value;
    objForm.action='http://www.aplub.com.br/site_search.asp?search='+ search +'&mode=anywords&enviar.x=12&enviar.y=11';
    
    objForm.submit();
    return true;
}


/************************************************************
//    Tratamentos de tela
/*************************************************************/

/* Atributo maxChars personalizado.
utilizar no evento keypress e obrigatorio setar valor para maxchars
ex: onkeypress="return limitText(event,this)"
*/
function limitText(evt,field) {
if (evt.which && evt.which == 8) return true; // allow Netscape backspace
else return (field.value.length<field.maxchars);
}



/************************************************************
//    Tratamentos de tela
/*************************************************************/
/*
abre uma url no centro da tela!!
*/
function launchCenter(url, name, height, width ) {

  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;

  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
   
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str += ",scroll=yes";
      str += ",resizable=yes";
	//Se for 640, habilita o Scroll da página
/*	if (aw < 740) {
		str += ",scroll=yes";
	}*/
  }

  return window.open(url, name, str); 

}