﻿// JScript File

<!--


/////////////////////////////////////////////////////////////////////////////////////
// changeLabelCAI                                                                  //
/////////////////////////////////////////////////////////////////////////////////////
function changeLabelTextCAI(labelId, str){    
    document.getElementById(labelId).innerHTML = str;
}

/////////////////////////////////////////////////////////////////////////////////////
// GetObject                                                                       //
/////////////////////////////////////////////////////////////////////////////////////
function funcGetObjectCAI( id )
    {   if ( typeof( window.innerWidth ) == 'number' ) 
            { return(document.getElementById(id)); }
        else
            { if (document.all) { return(document.all(id)); }
                if (document.getElementById) { return(document.getElementById(id)); } } }
                
/////////////////////////////////////////////////////////////////////////////////////
// On Start                                                                        //
/////////////////////////////////////////////////////////////////////////////////////
function funcFocusCAI( id )
    {   
        SetCssClassLeftMenuCAI();
        if ( funcGetObjectCAI( id ) != null )
            {   funcGetObjectCAI( id ).focus() ; } }

/////////////////////////////////////////////////////////////////////////////////////
// Show Menu                                                                       //
/////////////////////////////////////////////////////////////////////////////////////
var strCurrentMenu                                        = "";
var strCurrentMenuClass                                   = "";

function funcShowMenuCAI( id, nMenus, tag )
    {           
       var strCurrentClass                               = tag.className;
       
       var i = 1;        
        for(; i <= nMenus; ++i){
            var idAux = 'Menu'+i;
            if(document.getElementById(idAux) != null)
                funcGetObjectCAI(idAux).style.display = "none";
        }
        
        strCurrentMenu.className                          = strCurrentMenuClass;
        
        funcGetObjectCAI('aBlocker').style.display   = "none";          
        if ( id != "HideAll" ){ 
            strCurrentMenu                            = tag;
            strCurrentMenuClass                       = tag.className;              
            funcGetObjectCAI('aBlocker').style.display   = "block";            
            funcGetObjectCAI( id ).style.display         = "block"; 
            tag.className                             = strCurrentClass + " aOn"; 
        }                             
    }

/////////////////////////////////////////////////////////////////////////////////////
// SetCssClassLeftMenuCAI                                                          //
/////////////////////////////////////////////////////////////////////////////////////
function SetCssClassLeftMenuCAI()
{
    if(funcGetObjectCAI('divContentCAI') != null)
    {
        funcGetObjectCAI('divContentCAI').className = '';
        
        if(funcGetObjectCAI('LeftMenu_divLeftMenu') == null)    
            funcGetObjectCAI('divContentCAI').className = 'sideContent';        
        else
            funcGetObjectCAI('divContentCAI').className = 'sideSubmenu';                         
    }
}

function redirectToHB(hb)
{   
    if(document.Form1.LoginHomeBanking_inputNAdesao.value.length != 8)
    {
        alert("Número de adesão inválido");
		return;
    }    
    
    if(hb == 1)
    {
        document.subformParticulares.ad.value = document.Form1.LoginHomeBanking_inputNAdesao.value;
        document.subformParticulares.submit();			
    }

    if(hb == 2)
    {
        document.subformEmpresas.ad.value = document.Form1.LoginHomeBanking_inputNAdesao.value;
        document.subformEmpresas.submit();
	}
}

function redirectToHB2(inputName, instanceId, locationId)
{   
    
    var input = document.getElementById(inputName);
    
    if (input != null)
    {
        if(input.value.length != 8)
        {
            alert("Número de adesão inválido");
		    return;
        }    
        
        if (locationId != "")
        {
            document.subformParticulares.rd.value = locationId;
        }
        
        if(instanceId == 1)
        {
            document.subformParticulares.ad.value = input.value;
            document.subformParticulares.submit();
        }
        
        if(instanceId == 2)
        {
            document.subformEmpresas.ad.value = input.value;
            document.subformEmpresas.submit();
        }
    }
}


function idJSDOMParser()
{
    var divConstituicaoDP = document.getElementById('divConstituicaoDP');
    
    if ( divConstituicaoDP != null)
    {
        var img; var label; var input; var p;
        
        var divCaixaLogin = document.createElement('div'); 
        divCaixaLogin.className = "caixaloginSpec"; 
        divConstituicaoDP.appendChild(divCaixaLogin);
        
        img = document.createElement('img'); 
        img.setAttribute('src', '/CAI/Images/site/spec_loginBox_top.gif'); 
        img.setAttribute('alt', ''); 
        divCaixaLogin.appendChild(img);
        
        var divLogin = document.createElement('div'); 
        divLogin.className = "login"; 
        divCaixaLogin.appendChild(divLogin);
        
        img = document.createElement('img'); 
        img.setAttribute('src', '/CAI/Images/site/Login_Title_Particulares.png'); 
        img.setAttribute('alt', 'On-Line Particulares'); 
        img.className = "imgTitle"; 
        divLogin.appendChild(img);
        
        label = document.createElement('label');
        label.htmlFor = "inputNAdesao";
        label.innerHTML = 'N.º de Adesão';
        divLogin.appendChild(label);
        
        input = document.createElement('input');
        input.setAttribute('id', 'inputNAdesaoAll');
        input.setAttribute('type', 'text');
        input.setAttribute('maxLength', '8');                
        input.onkeypress = function() { return positiveIntInputOnly(event); };               
        input.onkeydown = function() { if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {redirectToHB2("inputNAdesaoAll", 1, 1); return false;} else return true; };               
        divLogin.appendChild(input);
                
        input = document.createElement('input');
        input.setAttribute('type', 'image');
        input.className = "inputButton";
        input.setAttribute('src', '/CAI/Images/site/spec_loginBox_bot.gif');
        input.onclick = function() { redirectToHB2("inputNAdesaoAll", 1, 1); return false; };
        divLogin.appendChild(input);
        
        var divSideText = document.createElement('div'); 
        divSideText.className = "sideText"; 
        divCaixaLogin.appendChild(divSideText);
        img = document.createElement('img'); 
        img.setAttribute('src', '/CAI/Images/site/spec_loginBox_ttl.gif'); 
        img.setAttribute('alt', 'Aceda aqui ao serviço On-Line Particulares e constitua já este depósito'); 
        img.className = "imgTitle"; 
        divSideText.appendChild(img);
        
        p = document.createElement('p');
        p.innerHTML = 'Se ainda não é Cliente On-Line,<br /> clique <a href="https://caonline.credito-agricola.pt/caonline/AdesaoServico.aspx" target="_blank" >aqui</a> para efectuar a adesão.';
        divSideText.appendChild(p);
        
        img = document.createElement('img'); 
        img.setAttribute('src', '/CAI/Images/site/spec_loginBox_bottom.gif'); 
        img.className = "final";
        img.setAttribute('alt', ''); 
        divCaixaLogin.appendChild(img);
    }
}

function positiveIntInputOnly(e) { // KEYPRESS event 
// returns true if 0-9 or BS hit, or can't get key value; otherwise false 

	var k = -1; 

	if (e && e.which) k = e.which; // NS 
	else if (window.event && window.event.keyCode) k = window.event.keyCode; // IE 

	return (k > -1 ? ((k > 47 && k < 58) || k == 8 || k == 9) : true); 

}

String.prototype.trim = function(){ return this.replace(/^\s*/, '').replace(/\s*$/, ''); }

function CheckSearchWordLength(obj)
{    
    //if(obj.value.trim().length < 2 || obj.value.trim() == "Pesquisa ..."){            
    if(obj.value.trim().length < 2){        
        alert("Por favor, introduza pelo menos 2 caracteres.");
        return false;
    }
    if(obj.value.trim() == "Pesquisa ..."){
        obj.value = '';
        obj.focus();
        return false;
    }
        
    return true;
}
    
function numbersValid(e)
{
	var k = -1; 

	if (e && e.which) k = e.which; // NS 
	else if (window.event && window.event.keyCode) k = window.event.keyCode; // IE 

    if(k == 9) return true;

	return (k > -1 ? ((k > 47 && k < 58) || (k > 95 && k < 106) || k == 8) : true); 
}

function postalCodeValid(e, o) 
{
	var k = -1; 

	if (e && e.which) k = e.which; // NS 
	else if (window.event && window.event.keyCode) k = window.event.keyCode; // IE 

    if(k == 8 || k == 9) return true;    

    if((k == 109 || k == 189) && o.value.length != 4) return false;
        
    if(o.value.length == 4 && k != 109 && k != 189) return false;
    
	return (k > -1 ? ((k > 47 && k < 58) || (k > 95 && k < 106) || k == 109 || k == 189) : true); 
}

function birthDateValid(e, o)
{
	var k = -1; 

	if (e && e.which) k = e.which; // NS 
	else if (window.event && window.event.keyCode) k = window.event.keyCode; // IE 	
	
	if(k == 8 || k == 9) return true;

    if((k == 109 || k == 189) && (o.value.length != 2 && o.value.length != 5)) return false;
    
    if((o.value.length == 2 || o.value.length == 5) && (k != 109 && k != 189)) return false;
    
    return (k > -1 ? ((k > 47 && k < 58) || (k > 95 && k < 106) || k == 109 || k == 189) : true); 
}

function googleAnalytics()
{
    if(typeof window.urchinTracker == 'function')
    {
        _uacct = "UA-2190740-1";
        urchinTracker();
    }
}
    
//-->



