// JScript File


//FUNCOES JeA

//MENU ESQ

function menuOver(menu)
{

 document.all[menu].className = "menuPrincipalSelect";

 switch (menu)
 {
    case "empresa": {
                      document.all["set1"].style.display = 'block';
                      document.all["set2"].style.display = 'none';
                      document.all["set3"].style.display = 'none';
                      document.all["set4"].style.display = 'none';
                      document.all["set5"].style.display = 'none';
                      break;
                    }
    case "qualidade": {
                      document.all["set1"].style.display = 'none';
                      document.all["set2"].style.display = 'block';
                      document.all["set3"].style.display = 'none';
                      document.all["set4"].style.display = 'none';
                      document.all["set5"].style.display = 'none';
                      break;
                    }
    case "prod": {
                      document.all["set1"].style.display = 'none';
                      document.all["set2"].style.display = 'none';
                      document.all["set3"].style.display = 'block';
                      document.all["set4"].style.display = 'none';
                      document.all["set5"].style.display = 'none';
                      break;
                    }
    case "parc": {
                      document.all["set1"].style.display = 'none';
                      document.all["set2"].style.display = 'none';
                      document.all["set3"].style.display = 'none';
                      document.all["set4"].style.display = 'block';
                      document.all["set5"].style.display = 'none';
                      break;
                    }
    case "cont": {
                      document.all["set1"].style.display = 'none';
                      document.all["set2"].style.display = 'none';
                      document.all["set3"].style.display = 'none';
                      document.all["set4"].style.display = 'none';
                      document.all["set5"].style.display = 'block';
                      break;
                    }
    
 }
}
function menuOut(menu)
{
 document.all[menu].className =  "menuPrincipal";
 document.all["set1"].style.display = 'none';
 document.all["set2"].style.display = 'none';
 document.all["set3"].style.display = 'none';
 document.all["set4"].style.display = 'none';
 document.all["set5"].style.display = 'none';
}

function actualizaContent(menu)
{
 if (menu == 0)
  document.location.href='Default.aspx';
 else
  document.location.href='Conteudos.aspx?id='+menu;
}

function pressBotao(btn)
    {
    // alert(document.all[btn].style.backgroundColor);
     document.all[btn].style.backgroundColor = "#e0e0e0";
     document.all[btn].style.Color = "#ffffff";
    }
function UnPressBotao(btn)
    {
    //alert(btn);
     document.all[btn].style.backgroundColor = "#ececec";
     document.all[btn].Color = "#565656";
    }
function terminaSessao()
{
    top.location.href='../site/default.aspx';
}  
         
function verificaValidFicha()
{
    if(document.all["tbVendTelef"].value == "" && document.all["tbVendTelem"].value == "")
    {
        document.all["erroTelef"].style.display = 'block';
        document.all["erroTelem"].style.display = 'block';
        return false;
    }
    else
    {
        if(document.all["tbVeicMat1"].value == "" || document.all["tbVeicMat2"].value == "" || document.all["tbVeicMat3"].value == "")
        {
            document.all["erroMat"].style.display = 'block';
            return false;
        }
        document.all["erroMat"].style.display = 'none';
        document.all["erroTelef"].style.display = 'none';
        document.all["erroTelem"].style.display = 'none';
        return true;    
    }
}

//muda selectores da ficha de introdução do Veiculo

function paginaGuia(param)
{
  //  alert (document.all["pnGuia"].style.display);
   
    
    if (document.all["dpMarcas"].value != "0")
    {
      document.all["pnGuia"].style.display = 'block';
      document.all["iGuia"].src = "http://www.guiadoautomovel.pt/novos.aspx?ma="+document.all["dpMarcas"].value;
    }else
    {
      document.all["pnGuia"].style.display = 'none';
    }
    
}


function fichaVeiculo(id)
{

 
 if (id == 1)
 {
    document.all["proprietario"].style.display = 'block';
    document.all["equipamento"].style.display = 'none';
    document.all["veiculo"].style.display = 'none';
    document.all["historico"].style.display = 'none';
    document.all["valores"].style.display = 'none';
    
 }
 if (id == 2)
 {
    document.all["proprietario"].style.display = 'none';
    document.all["equipamento"].style.display = 'block';
    document.all["veiculo"].style.display = 'none';
    document.all["historico"].style.display = 'none';
    document.all["valores"].style.display = 'none';
 }
 if (id == 3)
 {
    document.all["proprietario"].style.display = 'none';
    document.all["equipamento"].style.display = 'none';
    document.all["veiculo"].style.display = 'block';
    document.all["historico"].style.display = 'none';
    document.all["valores"].style.display = 'none';
 }
 if (id == 4)
 {
    document.all["proprietario"].style.display = 'none';
    document.all["equipamento"].style.display = 'none';
    document.all["veiculo"].style.display = 'none';
    document.all["historico"].style.display = 'block';
    document.all["valores"].style.display = 'none';
    
 }
 if (id == 5)
 {
    document.all["proprietario"].style.display = 'none';
    document.all["equipamento"].style.display = 'none';
    document.all["veiculo"].style.display = 'none';
    document.all["historico"].style.display = 'block';
    document.all["valores"].style.display = 'none';
 }
}

function inicializaFichaVeiculo()
{

 document.all["proprietario"].style.display = 'block';
 document.all["equipamento"].style.display = 'none';
 document.all["veiculo"].style.display = 'none';
 document.all["historico"].style.display = 'none';
 document.all["valores"].style.display = 'none';
 
}

function consultingPrice()
{
  var ano = document.getElementById('hidano').value;
  var marca = document.getElementById('hidMarca').value;
  var portas = document.getElementById('hidPortas').value;
   
  window.open('ConsultingPrice.aspx?ano='+ano+'&marca='+marca+'&portas='+portas,'Consult','height=200,width=480');
}
function actualizaHiddenPrice(id)
{
 if (id == 1)
  {
   document.getElementById('hidano').value = document.getElementById('tbVeicAnoFabrico').value;
   document.getElementById('hidMarca').value = document.getElementById('dpMarca').value;
   document.getElementById('hidPortas').value = document.getElementById('dpVeicPortas').value;
   
  }
}

function vCheckNC(Contribuinte)
{
            var sNumber = Contribuinte.toString().substr(0,8);
            var iResul = 0, iResto, iCheck, sCheck;
            var i, fx =new Array(7,6,5,4,3,2,9,8,7,6,5,4,3,2);
            sNumber = "000000" + sNumber;
            for(i = 0; i < (sNumber.length); i++){iResul += parseInt(sNumber.charAt(i)) * fx[i];}
            iResto = iResul % 11;
            iCheck = 11 - iResto;
            if (iCheck == 11 || iCheck == 10)
            {
                sCheck = "0";
            }
            else
            {
                sCheck = iCheck.toString();
            }
            if (!sCheck == Contribuinte.toString().substr(8,1))
            {
                
                alert("Numero de Contribuinte Inválido");    
                document.all["tbVendNif"].focus();
            }
            return (sCheck == Contribuinte.toString().substr(8,1))
}   



function muda_foto(foto)
 {
    var max=200;
	obj=document.getElementById('imgPreview');
	obj.src = foto.value;
	obj.style.width = 270;
 }
 
   	
function entidadeExiste() 
{
    alert ('Entidade já existe!!!');
}


function editaVeiculoCliente()
{
alert("sss");
}

//SITE
function actualizaClick(banner)
{
 window.open("banner.aspx?id="+banner,"banner");
}
//Funções para mudar igagens de butões menu horizontal
function muda(imagem)
{
  //alert (imagem);
  var foto = document.all[imagem].src;
  
  document.all[imagem].src = foto.substring(0,foto.length-4) + "_PRESS.jpg";
}
function UnMuda(imagem)
{
  //alert (imagem);
  var foto = document.all[imagem].src;
  document.all[imagem].src = foto.substring(0,foto.length-10) + ".jpg";
}

function esqueceuPass()
 {
 window.open('esqueceuPass.aspx','name','height=300,width=445');
 }
 
 function novoRegisto()
 {
 document.location.href='registo.aspx';
 //window.open('esqueceuPass.aspx','name','height=300,width=445');
 }

 function simulador()
 {
    document.location.href='simuladorCred.aspx';
 }
 
 function venderUsado()
 {
    document.location.href='DivulgaViatura.aspx';
 }


function maisExtras(div)
{
   if (document.all[div].style.display == "none")
    document.all[div].style.display = 'block';
   else
    document.all[div].style.display = 'none';
}

function automoveisNovos()
{
 window.open('http://www.guiadoautomovel.pt/Comprar_Novo/cnovo.htm','automoveisNovos');
}

function imprimirFicha()
 {
 window.open('FichaVeiculoImprime.aspx','nome');
 }

//FIM FUNCOES C2C
function centeredWindow(theURL,winName,features,width,height) { 
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" 
	    && parseInt(navigator.appVersion)==3
	    && navigator.javaEnabled()
	   ) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}
	
	var pos_x = (screenW/2) - (width/2);
	var pos_y = (screenH/2) - (height/2);
	
	window.open(theURL,winName,features+",width="+width+",height="+height+",left="+pos_x+",top="+pos_y);
}

function MovetoWindow(theURL, wnd, winName, width, height) {
	wnd.close();
	OpenDialogWindow(theURL, winName, width, height);
} 

function OpenDialogWindow(theURL, WIdent, width, height) {
	centeredWindow(theURL, WIdent, 'toolbar=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no',width,height);
}

function OpenResizeWindow(theURL, WIdent, width, height) {
	centeredWindow(theURL, WIdent, 'toolbar=no,directories=no,status=no,scrollbars=no,resizable=yes,menubar=no',width,height);
}

var lastClick = ""
var ctrlImagem = ""
var openImg = new Image();
openImg.src = "../images/open.jpg";
var closedImg = new Image();
closedImg.src = "../images/closed.jpg";


function over(obj)
{
    obj.style.background = '#D4A679';//'#F4BBBB';
    obj.style.color = '#485259';
}
function out(obj,cor)
{
obj.style.background = cor;
//obj.style.color = '#485259';

}
function geturl(url)
{

top.frames[2].location=url;
} 
//-->

function showBranch(branch,imagem){
	swapFolder(imagem)	
	var objBranch = document.getElementById(branch).style;	
	if(objBranch.display=="block")
		objBranch.display="none";
	else
		objBranch.display="block";		
	lastClick=branch;
}
function swapFolder(img)
{
objImg = document.getElementById(img);

if(objImg.src.indexOf('closed.jpg')>-1)
objImg.src = openImg.src;
else
    objImg.src = closedImg.src;	
}
//=================================================================
//============= COMPARAR DATAS
//=================================================================

function compareDates (DataInicio, DataFim) {
   var DiaInicio, DiaFim;
   var MesInicio, MesFim;
   var AnoInicio, AnoFim;
   DiaInicio = DataInicio.substring (0, DataInicio.indexOf ("-"));
   MesInicio = DataInicio.substring (DataInicio.indexOf ("-")+1, DataInicio.lastIndexOf ("-"));
   AnoInicio = DataInicio.substring (DataInicio.lastIndexOf ("-")+1, DataInicio.length);
   DiaFim = DataFim.substring (0, DataFim.indexOf ("-"));
   MesFim = DataFim.substring (DataFim.indexOf ("-")+1, DataFim.lastIndexOf ("-"));
   AnoFim = DataFim.substring (DataFim.lastIndexOf ("-")+1, DataFim.length); 
   if (AnoFim > AnoInicio) return 1;
   else if (AnoFim < AnoInicio) return -1;
   else if (MesFim > MesInicio) return 1;
   else if (MesFim < MesInicio) return -1;
   else if (DiaFim > DiaInicio) return 1;
   else if (DiaFim < DiaInicio) return -1;
   else return 0;
}
//=================================================================
//=================================================================
//=================================================================
// Passagem de ListBox
function CopiaValor(iValor,sTexto,sLista)
{
    sListaDestino =  document.getElementById(sLista);
    var iTamanho = sListaDestino.length;    
    sListaDestino.options[iTamanho] = new Option(sTexto,iValor);
    InsereColaborador(iValor,sTexto,sLista) 
}
function CopiaValorDatas(dDataInicio,dDataFim,sLista)
{
    sListaDestino = document.getElementById(sLista);
    var iTamanho = sListaDestino.length;
    var DiaInicio = dDataInicio.substring (0, dDataInicio.indexOf ("-"));
    var MesInicio = dDataInicio.substring (dDataInicio.indexOf ("-")+1, dDataInicio.lastIndexOf ("-"));
    var AnoInicio = dDataInicio.substring (dDataInicio.lastIndexOf ("-")+1, dDataInicio.length);
    var DiaFim = dDataFim.substring (0, dDataFim.indexOf ("-"));
    var MesFim = dDataFim.substring (dDataFim.indexOf ("-")+1, dDataFim.lastIndexOf ("-"));
    var AnoFim = dDataFim.substring (dDataFim.lastIndexOf ("-")+1, dDataFim.length); 
    var auxiliar = 0
    
    
    if(MesInicio.length!=2)
    {
        if(DiaInicio.length!=2)
        {
            DiaInicio='0' + DiaInicio;
        }
        dDataInicio=DiaInicio + '-0' + MesInicio + '-' + AnoInicio;
    }
    else if(MesInicio.length=2)
    {
        if(DiaInicio.length!=2)
        {
            DiaInicio='0' + DiaInicio;
        }
        dDataInicio=DiaInicio+ '-' + MesInicio + '-' + AnoInicio;
    }
    
    if(MesFim.length!=2)
    {
        if(DiaFim.length!=2)
        {
            DiaFim='0' + DiaFim;
        }
        dDataFim=DiaFim + '-0' + MesFim + '-' + AnoFim;
    }
    else if(MesFim.length=2)
    {
        if(DiaFim.length!=2)
        {
            DiaFim='0' + DiaFim;
        }
        dDataFim=DiaFim + '-' + MesFim + '-' + AnoFim;
    }
    
    if(compareDates(dDataInicio,dDataFim)!=-1)
    {
       if(iTamanho!=0)
       {       
           for(var i = (iTamanho-1); i >= 0; i--) 
            {
                if((sListaDestino.options[i].value)==(dDataInicio + '|' + dDataFim))
                {
                    auxiliar = auxiliar + 1
                }
            }
            if(auxiliar>0)
            {
                alert("O periodo que escolheu já se encontra atribuido a esta frota.");
                return;
            }
            else
            {
                sListaDestino.options[iTamanho] = new Option('SOLDOUT de ' + dDataInicio + ' a ' + dDataFim,dDataInicio + '|' + dDataFim);
                InsereColaborador(dDataInicio,dDataFim,"SOLDOUT");
                return; 
            }
        }
        else
        {
           sListaDestino.options[iTamanho] = new Option('SOLDOUT de ' + dDataInicio + ' a ' + dDataFim,dDataInicio + '|' + dDataFim);
           InsereColaborador(dDataInicio,dDataFim,"SOLDOUT"); 
           return;
        }  
     }
     else
     {
        alert("Verifique as datas que escolheu.");
        return;
     }  
}
function LimpaDatas(sLista) {
//alert(document.getElementById(sLista).value);
    sListaDestino =  document.getElementById(sLista);
    var datas = document.getElementById(sLista).value;
    var len = sListaDestino.options.length;
    for(var i = (len-1); i >= 0; i--) 
        {
            if ((sListaDestino.options[i] != null) && (sListaDestino.options[i].selected == true)) 
            {
                sListaDestino.options[i] = null;
            }
        }
    CallServer(datas+"|"+"DSOLDOUT","");
}
function Limpa(sLista) {
    sListaDestino =  document.getElementById(sLista);
    var len = sListaDestino.options.length;
    for(var i = (len-1); i >= 0; i--) 
        {
            if ((sListaDestino.options[i] != null) && (sListaDestino.options[i].selected == true)) 
            {
                sListaDestino.options[i] = null;
            }
        }
}
function InsereColaborador(idRegisto,sNome,sTipo)    
{
    //alert(sTipo);
    CallServer(idRegisto+"|"+sNome+"|"+sTipo, "");
}

function DeleteColaborador(iColaborador,sNome)    
{
    CallServer("D"+iColaborador+"|"+sNome, "");
}

function EscondeResultsHolder()
{
    ResultsHolder.style.display="none";
}

function ReceiveServerData(rValue)
{
    if (rValue != "")
    {    
        //ResultsHolder.style.display="block";
        //Results.innerText = rValue;            
        //Limpa();
        //setTimeout('EscondeResultsHolder()', 5000) ;
    } 
    
}

// Fim Passagem de ListBox

/***********************************************************************/
/*                  Separador                                          */
/***********************************************************************/
function AccionaTab(myButtons, button, tab, tipo, onclass, offclass, lang) {
	var a = tabcontrol.all.tags('div');
	var b = myButtons.parentElement.all.tags('td');
	
	if (a!=null) {
	    for (i=0; i<a.length; i++) {
			if (a[i].tab == tipo) {
				if (a[i].id == tab) a[i].style.display ='block'
				else a[i].style.display ='none';
			}
		}
	}
	if (b!=null) {
	    for (i=0; i<b.length; i++) {
			if (b[i].tab == "") {
				if (b[i].id == button) b[i].className = onclass
				else b[i].className = offclass;
			}
		}
	};
	
	document.getElementById('topTable').className="tabTable"+lang;	
}
/***********************************************************************/
/*                   Fim Separador                                     */
/***********************************************************************/


  