function showDetalhes(h) {
	if((document.getElementById(h).style.display == 'none')||(document.getElementById(h).style.display == '')){
		document.getElementById(h).style.display = 'block';
		document.getElementById(h*100).style.backgroundImage = 'url(images/apolices/icon_menos.gif)';
		document.getElementById(h*10).style.display = 'none';
	}
	else { 
		document.getElementById(h).style.display = 'none';
		document.getElementById(h*10).style.display = 'inline';
		document.getElementById(h*100).style.backgroundImage = 'url(images/apolices/icon_mais.gif)';
	}
}

function toggleDiv(divid){
	if((document.getElementById(divid).style.display == 'none')||(document.getElementById(divid).style.display == '')){
		document.getElementById(divid).style.display = 'block';
	}else{
		document.getElementById(divid).style.display = 'none';
	}
}

function showQuemSomos(h) {
    for(i = 1; i < 6; i++) {
        if(i == h) { 
            document.getElementById(i).style.display = 'block';
			document.getElementById(i*10).style.fontWeight = 'bold';
        }
        else { 
            document.getElementById(i).style.display = 'none';
			document.getElementById(i*10).style.fontWeight = 'normal';
        }
    }
}

function showTabela() {
	document.getElementById('tabelaP').style.display = 'block';
	document.getElementById('paraVer').style.display = 'none';
}

function hideTabela() {
	document.getElementById('paraVer').style.display = 'block';
	document.getElementById('tabelaP').style.display = 'none';
}

function mostraAmigo() {
	document.getElementById('labelAmigo').className = 'active';
	document.getElementById('labelAmigo').innerHTML = '<a onclick="javascript: mostraAmigo();" title="Enviar a um amigo"><img src="images/simulacao/icon_enviar.gif" width="12" height="17" alt="Enviar a amigo" /></a><a onclick="javascript: mostraAmigo();" title="Enviar a um amigo">Enviar a amigo</a><span>&nbsp;</span>';
	document.getElementById('formAmigo').style.display = 'block';
	document.getElementById('labelContacto').className = 'inactive';
	document.getElementById('formContacto').style.display = 'none';
	document.getElementById('labelContacto').innerHTML = '<a onclick="javascript: mostraContacto();" title="Contactem-me"><img src="images/simulacao/icon_contacto.gif" width="14" height="17" alt="Contactem-me" /></a><a  onclick="javascript: mostraContacto();" title="Contactem-me">Contactem-me &raquo;</a><span>&nbsp;</span>';
	document.getElementById('opcoes').style.borderBottom = 'none';
	
}

function mostraContacto() {
	document.getElementById('labelAmigo').className = 'inactive';
	document.getElementById('formAmigo').style.display = 'none';
	document.getElementById('labelAmigo').innerHTML = '<a onclick="javascript: mostraAmigo();" title="Enviar a um amigo"><img src="images/simulacao/icon_enviar.gif" width="12" height="17" alt="Enviar a amigo" /></a><a onclick="javascript: mostraAmigo();" title="Enviar a um amigo">Enviar a amigo &raquo;</a><span>&nbsp;</span>';
	document.getElementById('labelContacto').className = 'active';
	document.getElementById('labelContacto').innerHTML = '<a onclick="javascript: mostraContacto();" title="Contactem-me"><img src="images/simulacao/icon_contacto.gif" width="14" height="17" alt="Contactem-me" /></a><a  onclick="javascript: mostraContacto();" title="Contactem-me">Contactem-me</a><span>&nbsp;</span>';
	document.getElementById('formContacto').style.display = 'block';
	document.getElementById('opcoes').style.borderBottom = 'none';
}

function mostraAmigoHab() {
	document.getElementById('labelAmigo').className = 'active';
	document.getElementById('labelAmigo').innerHTML = '<a onclick="javascript: mostraAmigo();" title="Enviar a um amigo"><img src="images/habitacao/icon_enviar.gif" width="12" height="17" alt="Enviar a amigo" /></a><a onclick="javascript: mostraAmigoHab();" title="Enviar a um amigo">Enviar a amigo</a><span>&nbsp;</span>';
	document.getElementById('formAmigo').style.display = 'block';
	document.getElementById('labelContacto').className = 'inactive';
	document.getElementById('formContacto').style.display = 'none';
	document.getElementById('labelContacto').innerHTML = '<a onclick="javascript: mostraContacto();" title="Contactem-me"><img src="images/habitacao/icon_contacto.gif" width="14" height="17" alt="Contactem-me" /></a><a  onclick="javascript: mostraContactoHab();" title="Contactem-me">Contactem-me &raquo;</a><span>&nbsp;</span>';
	document.getElementById('opcoes').style.borderBottom = 'none';
	
}

function mostraContactoHab() {
	document.getElementById('labelAmigo').className = 'inactive';
	document.getElementById('formAmigo').style.display = 'none';
	document.getElementById('labelAmigo').innerHTML = '<a onclick="javascript: mostraAmigo();" title="Enviar a um amigo"><img src="images/habitacao/icon_enviar.gif" width="12" height="17" alt="Enviar a amigo" /></a><a onclick="javascript: mostraAmigoHab();" title="Enviar a um amigo">Enviar a amigo &raquo;</a><span>&nbsp;</span>';
	document.getElementById('labelContacto').className = 'active';
	document.getElementById('labelContacto').innerHTML = '<a onclick="javascript: mostraContacto();" title="Contactem-me"><img src="images/habitacao/icon_contacto.gif" width="14" height="17" alt="Contactem-me" /></a><a  onclick="javascript: mostraContactoHab();" title="Contactem-me">Contactem-me</a><span>&nbsp;</span>';
	document.getElementById('formContacto').style.display = 'block';
	document.getElementById('opcoes').style.borderBottom = 'none';
}

function showFaq(h) {

    if (document.lastFaq)
    {    
        document.getElementById(document.lastFaq).style.display = 'none';
		document.getElementById(document.lastFaq + '00').style.display = 'none';
    }

    document.getElementById(h).style.display = 'block';
	document.getElementById(h + '00').style.display = 'block';    

    document.lastFaq = h;
}

function hideFaq(h) {
    document.getElementById(h).style.display = 'none';
    document.getElementById(h + '00').style.display = 'none';	
    
    document.lastFaq = null;
}

function chargeLocalVideo (swf)
{
    var videoDiv = document.getElementById('videoLeft');
    videoDiv.innerHTML= '<embed width="183" height="345" align="middle" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" flashvars="" name="Files/Flash/' + swf + '" bgcolor="#FFFFFF" quality="high" src="Files/Flash/' + swf + '.swf"/>';
    
}

function chargeRemoteVideo (swf)
{
    var videoDiv = document.getElementById('videoLeft');
    videoDiv.innerHTML= '<embed width="183" height="345" align="middle" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" flashvars="" name="http://video.segurodirecto.pt/' + swf + '" bgcolor="#FFFFFF" quality="high" src="http://video.segurodirecto.pt/' + swf + '.swf"/>';    
    //videoDiv.innerHTML= '<embed width="183" height="345" align="middle" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" flashvars="" name="http://video.segurodirecto.pt/' + swf + '" bgcolor="#FFFFFF" quality="high" src="' + (("https:" == document.location.protocol) ? "https://operations.ptempresas.pt/ssl/23/video.segurodirecto.pt/" : "http://video.segurodirecto.pt/") + swf + '.swf"/>';    
}

function ShowBySideLayor()
{
    setTimeout("popUp('https://webcare.byside.com/agent/survey.php?wid=N0JCRDE3RTY1QkA2MTM1QDYwMTNASUBAQFNANzE2OUBAYjYxMzVA&lang=pt', 400, 365);bysideWebcare_onwindowclose_allow=false;", 15000 );
}

function popUp(url, width, height) {
        window.open(url, '', 'width='+width+',height='+height);
}

function checkmod(num)
{
    val=0;
    for (pos=0; pos<num.length-1; ++pos) {
    val += (1 * num.charAt(pos)) * (9 - pos);
    }
    ctl = val % 11 ? (11 - val % 11) % 10 : 0;

    return ctl == (1 * num.charAt(pos));
}
    
function ValidateNIF(num, args)
{
    var c;
    args.Value = args.Value.replace(" ", "");
    c = args.Value.charAt(0);
    if(args.Value.length != 9 || eval(args.Value) < 99999999 || (c=='0') || (c=='3') || (c=='4') || (c=='5') || (c=='7') || (c=='8'))
    { args.IsValid = false; return; }
    args.IsValid = checkmod(args.Value);
}

function ValidateNIF_Register(num, args)
{
    var c;
    args.Value = args.Value.replace(" ", "");
    c = args.Value.charAt(0);
    if(args.Value.length != 9 || eval(args.Value) < 99999999 || (c=='0') || (c=='3') || (c=='4') || (c=='7') || (c=='8'))
    { args.IsValid = false; return; }
    args.IsValid = checkmod(args.Value);
}

function CheckBI(nbi, lastDigit)
{
    var BIformated;
    // verifica tamanhos
    if((nbi.length < 7) || (nbi.length > 8))
        return false;
    if(lastDigit.length != 1)
        return false;

    // prepara o numero de BI formatado
    if(nbi.length == 8)
    {
        BIformated = nbi + lastDigit;
    }
    else
    {
        BIformated = '0' + nbi + lastDigit;
    }

    // algoritmo de validação
    return checkmod(BIformated);
}

function ValidateNIB(nib1,nib2,nib3,nib4)
{
    var i = 0;
    var imult = 0;
    var result = "";
    var nib =  nib1 + nib2 + nib3 + nib4;
    if(nib.length != 21)
    {
        return false;
    }
    else
    {
        var dcontrol = nib4;
        nib = nib1 + nib2 + nib3;
    	
        for(i = 0; i<19; i++)
        {
	        imult = ((imult + parseInt(nib.substr(i,1),10))*10)%97;
        }

        imult = 98 - ((imult*10)%97);
        result = imult.toString();
    	
        if(imult<10)
        {
	        result = "0" + imult.toString()
        }
    	
        if(dcontrol == result)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

function ValidateTandCs(source, args)
{
    args.IsValid = document.getElementById('<%= CheckBoxTos.ClientID %>').checked;
} 
   
function On_KeyPress()
{
    var strValidKeys = '-0123456789';
    var strKeyPressed = String.fromCharCode(window.event.keyCode)
    
    if (strValidKeys.indexOf(strKeyPressed)==-1)
    {
	    window.event.returnValue=false;
    }
    else
    {
	    window.event.returnValue=true;
    }
}

function On_KeyPress(CanBeNegative)
{
        
    if (CanBeNegative)
    {
	    var strValidKeys = '-0123456789'
    }
    else
    {
	    var strValidKeys = '0123456789'
    }
    
    var strKeyPressed = String.fromCharCode(window.event.keyCode)
    if (strValidKeys.indexOf(strKeyPressed)==-1)
    {
	    window.event.returnValue=false;
    }
    else
    {
	    window.event.returnValue=true;
    }
}

function showTable(h) {
	var flag;
    for(i = 1; i <= 10; i++) {
        if(i == h)
		{
			if(document.getElementById('hidden'+i).style.display == 'block')
				flag = true;
			document.getElementById('hidden'+i).style.display = 'block';
			document.getElementById('table'+i).style.backgroundImage = 'url(images/habitacao/table_menos.gif)';
			
		}	else	{ 
			document.getElementById('hidden'+i).style.display = 'none';
			document.getElementById('table'+i).style.backgroundImage = 'url(images/habitacao/table_mais.gif)';
		}
	}
	if(flag)
	{
		document.getElementById('hidden'+h).style.display = 'none';
		document.getElementById('table'+h).style.backgroundImage = 'url(images/habitacao/table_mais.gif)';
	}		
}

function onkeyValidaFormatoData(p_event,p_obj,p_formato)
{
    /*  Obs. (XXABR2006_AXA)
     * Recebe um evento (p_event), objecto (p_obj) onde este ocorre e o formato de data pretendido...
     * (p_formato), que pode ser [DD-MM-AAAA|AAAA-MM-DD]. Todos os parametros são obrigatorios. Esta...
     * funcao, coloca automaticamente os "-" quando na introducao dos digitos. Podera mais tarde ser incluido..
     * um novo parametro (p_separador), que nao será obrigatorio mas que quando preenchido sera o separador da data.
     * Esta funcao deve ser usada, preferencialmente, no evento onkeydown. [onkeydown="onkeyValidaFormatoData(event, this,'dd-mm-aaaa')]
     */

    if (p_event.keyCode == 9 || p_event.keyCode == 8 || p_event.keyCode == 35 || p_event.keyCode == 36 || p_event.keyCode == 37 || p_event.keyCode == 39 || p_event.keyCode == 46 ) return false; //BackSpace

    if ((p_event.keyCode < 48 || p_event.keyCode > 57) && (p_event.keyCode < 96 || p_event.keyCode > 105)) p_event.returnValue = false //Só aceita numeros

    if (p_obj.value=="") return false;

    var loc_tamanho = p_obj.value.length;

    /* JR(22/07/09) - Comentei para não obrigar a apagar e deixar escrever nos casos em que se selecciona texto.
    if (loc_tamanho == "10")
    {
        p_event.returnValue = false;
        return false;
    }
    */

    var loc_strAux = new String();

    loc_strAux = p_formato;

    switch (loc_strAux.toUpperCase())
    {
        case "DD-MM-AAAA":   if (loc_tamanho == 2 || loc_tamanho == 5)
            {
                p_obj.value = p_obj.value + "-";
            }
            break;

        case "AAAA-MM-DD":   if (loc_tamanho == 4 || loc_tamanho == 7)
            {
                p_obj.value = p_obj.value + "-";
            }
            break;                                                                                  
    }//fim do switch

}//Fim onkeyValidaFormatoData

// JR[01/04/09] - Verificar o limite de caracteres numa text box devido ao multiline * * * * * * *

function checkTextAreaMaxLength(textBox,e, length)
{
        var mLen = textBox["MaxLength"];
        if(null==mLen)
            mLen=length;
        
        var maxLength = parseInt(mLen);
        if(!checkSpecialKeys(e))
        {
         if(textBox.value.length > maxLength-1)
         {
            if(window.event)//IE
              e.returnValue = false;
            else//Firefox
                e.preventDefault();
         }
    }   
}

function checkSpecialKeys(e)
{
    if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
        return false;
    else
        return true;
}  

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
