﻿// JScript File


//To display the full tree: use openItem="0"
//To display none: use openItem=""

function displayMenu(openItem)
{
    var menu = document.getElementById("sidemenu");
    menu.innerHTML = "";
    var strMenu = "";
    try{
        xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp = false;
            }
        }
    }

    xmlhttp.open("GET", "SideMenu.aspx",true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            //building the menu
            strMenu = xmlhttp.responseText.toString();
            menu.innerHTML = strMenu;

            //Show only the selected tree
            if (openItem != "" && openItem != "0") {
                var menuItems = menu.getElementsByTagName("div");
                for (i = 0; i < menuItems.length; i++) {
                    openMenu(openItem)
                }
            }
            if (openItem == "") {
                var menuItems = menu.getElementsByTagName("div");
                for (i = 0; i < menuItems.length; i++) {
                    menuItems[i].style.display = "none";
                }
            }

        }
    }
    xmlhttp.send(null) 
}

function openMenu(openItem)
{
    var menu = document.getElementById("sidemenu");
    menu.style.display = "block";
    
    var menuItems = menu.getElementsByTagName("div");
    selectedItem = document.getElementById(openItem);
    
    if(selectedItem!=null)
    {
        //Third level element
        if(selectedItem.getAttribute("parentid") != "0" &&  selectedItem.getAttribute("parentofparentid") != "0")
        {
            
	    for (i=0;i<menuItems.length;i++)
            {
                menuItems[i].style.display = "none";
                //if(menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("parentid") || menuItems[i].getAttribute("id")==selectedItem.getAttribute("parentid") || menuItems[i].getAttribute("id")==selectedItem.getAttribute("parentofparentid") || menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("parentofparentid"))
                if(menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("parentid") || menuItems[i].getAttribute("id")==selectedItem.getAttribute("parentid")  || menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("parentofparentid"))
                {
                    menuItems[i].style.display = "block";
                }
            }
        }
        //Second level element
        if(selectedItem.getAttribute("parentid") != "0" &&  selectedItem.getAttribute("parentofparentid") == "0")
        {
            for (i=0;i<menuItems.length;i++)
            {
                menuItems[i].style.display = "none";
                //if(menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("parentid") || menuItems[i].getAttribute("id")==selectedItem.getAttribute("parentid") || menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("id"))
                if(menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("parentid") || menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("id"))
                {
                    menuItems[i].style.display = "block";
                }
            }
        }
        //First level element
        else if(selectedItem.getAttribute("parentid") == "0" &&  selectedItem.getAttribute("parentofparentid") == "0")
        {
            for (i=0;i<menuItems.length;i++)
            {
                menuItems[i].style.display = "none";
                //if(menuItems[i].getAttribute("id") == selectedItem.getAttribute("id") || menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("id"))
                if(menuItems[i].getAttribute("parentid")==selectedItem.getAttribute("id"))
                {
                    menuItems[i].style.display = "block";
                }
            }
        }
    }else
    {
        // PARA RECURSOS HUMANOS - DETALHES DA BOLSA DE OPORTUNIDADES - NÃO OCULTAR O MENU
        if ( openItem != 387 && openItem != 388 ) {
            for (i=0;i<menuItems.length;i++)
            {
                menuItems[i].style.display = "none";
            }
        }
    }
    
    
}

function displayContentWithSideMenu(channelid, contentid) {

    if (contentid.toString() != "0") {

        openMenu(channelid);
        displayMenu(channelid);

        document.getElementById("scrollerBase").style.display = "block";
        document.getElementById("scrollerBase").style.visibility = "visible";

        document.getElementById("mainContentContainer").style.width = "550";

        if (parseInt(navigator.appVersion) > 3) {
            if (navigator.appName == "Netscape") {
                winW = window.innerWidth;
                document.getElementById("mainContentContainer").style.left = (winW / 2) - 180;
                document.getElementById("scrollerBase").style.left = (winW / 2) + 370;
            }
            if (navigator.appName.indexOf("Microsoft") != -1) {
                winW = document.body.offsetWidth;
                document.getElementById("mainContentContainer").style.left = (winW / 2) - 190;
                document.getElementById("scrollerBase").style.left = (winW / 2) + 360;
            }
        }
        /*
        document.getElementById("mainContent").style.top = "0";
        document.getElementById("scrollerBar").style.top = "0";

        document.getElementById("mainContent").style.left = "0";
        */
        var content = document.getElementById("content");
        content.innerHTML = loadingMsg;
        var strContent = "";
        try {
            xmlhttp1 = new XMLHttpRequest();
        } catch (ee) {
            try {
                xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    xmlhttp1 = false;
                }
            }
        }

        xmlhttp1.open("GET", "Content.aspx?contentid=" + contentid, true);
        xmlhttp1.onreadystatechange = function () {
            if (xmlhttp1.readyState == 4) {
                //building the content
                strContent = xmlhttp1.responseText.toString();
                content.innerHTML = strContent;
                window.document.title = 'Grupo Visabeira';
                resetTitle();
            }
        }
        xmlhttp1.send(null)
    }
    else {
        var content = document.getElementById("content");
        content.innerHTML = "";
        resetTitle();
    }

}

function displayContent(contentid)
{
    if(contentid.toString()!="0")
    {
        // displayPath(contentid);
        var content = document.getElementById("content");
        content.innerHTML = loadingMsg;
        var strContent = "";
        try{
            xmlhttp1 = new XMLHttpRequest();
        }catch(ee){
            try{
                xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{
                    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                    xmlhttp1 = false;
                }
            }
        }

        xmlhttp1.open("GET", "Content.aspx?contentid="+contentid,true);
        xmlhttp1.onreadystatechange = function () {
            if (xmlhttp1.readyState == 4) {
                //building the content
                strContent = xmlhttp1.responseText.toString();
                content.innerHTML = strContent;

                //show scrollbar when needed
               scroller.init();
                document.getElementById("mainContent").style.left = "0";
                document.getElementById("mainContent").style.top = "0";
                document.getElementById("scrollerBar").style.top = "0";
                //alert("altura do conteudo:"+ document.getElementById("mainContent").offsetHeight);
                window.document.title = 'Grupo Visabeira';
                resetTitle();

            }
        }
        xmlhttp1.send(null)
    }
    else
    {
        var content = document.getElementById("content");
        content.innerHTML = "";
        resetTitle();
    }
      
}


//This function is used to display content and open the side menu in once
function openMenuAndDisplayContent(channelid,contentid)
{
    // alert("channelid:"+channelid+",contentid:"+contentid);
    if(contentid.toString() != "0") {

        openMenu(channelid);

        if (channelid.toString() != "223" && channelid.toString() != "213" && channelid.toString() != "197" && channelid.toString() != "388" && channelid.toString() != "387") {
            displayMenu(channelid);
            document.getElementById("scrollerBase").style.display = "block";
            document.getElementById("scrollerBase").style.visibility = "visible";
        }
        else {
		if (channelid.toString() == "388" || channelid.toString() == "387")
		{
	            document.getElementById("scrollerBase").style.display = "block";
	            document.getElementById("scrollerBase").style.visibility = "visible";
		}
		else
		{
	            document.getElementById("scrollerBase").style.display = "none";
	            document.getElementById("scrollerBase").style.visibility = "hidden";
	        }
        }

        displayContent(contentid);
        // openMenuFlash(channelid);
        
        //check if the sidemenu and page title needs to be hidden---------------
        var menu = document.getElementById("sidemenu");
        document.getElementById("mainContentContainer").style.width = "550";
        //align content
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
                document.getElementById("mainContentContainer").style.left = (winW/2)-180;
                document.getElementById("scrollerBase").style.left = (winW/2)+370;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
                document.getElementById("mainContentContainer").style.left = (winW/2)-190;
                document.getElementById("scrollerBase").style.left = (winW/2)+360;
            }
        }
        
        for (j=0;j<arrayOfIdsToHideMenu.length;j++)
        {
            if(arrayOfIdsToHideMenu[j].toString()==channelid.toString())
            {
                menu.style.display = "none";
                document.getElementById("mainContentContainer").style.width = "760";
                posLayers();
            }
        }
        
        document.getElementById("mainContentContainer").style.height = defaultHeight;
        document.getElementById("lineContent").style.height = defaultHeight;
        for (j=0;j<arrayOfIdsToResizeContent.length;j++)
        {
            if(arrayOfIdsToResizeContent[j].toString()==channelid.toString()) {
                document.getElementById("mainContentContainer").style.height = exceptionHeight;
                document.getElementById("lineContent").style.height = exceptionHeight;
            }
        }
        if (channelid.toString() == homePageId)
        {
            document.getElementById("mainContentContainer").style.height = homeHeight;
            document.getElementById("lineContent").style.height = homeHeight;
        }
        else if (channelid.toString() == WorldWideId)
        {
            document.getElementById("mainContentContainer").style.height = 520;
            document.getElementById("lineContent").style.height = 505;
        }


//	alert('WorldWideId : ' + WorldWideId );
//	alert('Channelid : ' + channelid );

        if (channelid.toString() == WorldWideId ) {
//            alert("Wordwide");
            displayBanners(channelid);
        }
        else 
        { 
//            alert("NO Wordwide");        
            displayBanners(0);
        }
        
    }
    
}

function posLayers()
{
    //align content
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
            document.getElementById("mainContentContainer").style.left = (winW/2)-380;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.body.offsetWidth;
            document.getElementById("mainContentContainer").style.left = (winW/2)-390;
        }
    }
}


var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

/*
function openMenuFlash(channelid)
{
    var flashObj = getFlashMovie("menuflash");
    if(navigator.appName.indexOf("Microsoft") > -1)
    {
        flashObj.sendTextToFlash(channelid);
    }
}
*/
function getFlashMovie(movieName) {
    var flashObj = (document[movieName] == null) ? window[movieName] : document[movieName];
    return flashObj;
}

/*
function menuflash_DoFSCommand(command, args) 
{
    var sampleFlaMovieObj = getFlashMovie("menuflash");
    
    if (command == "openMenuAndDisplayContent")
    {
        var args1 = args.split(",");
        openMenuAndDisplayContent(args1[0],args1[1]);
    }
    if (command == "closeDiv")
    {
        closeDiv();
    }
    if (command == "openDiv")
    {
        openDiv();
    }
}



// Hook for Internet Explorer
if (navigator.appName && 
  navigator.appName.indexOf("Microsoft") != -1 &&
  navigator.userAgent.indexOf("Windows") != -1 && 
  navigator.userAgent.indexOf("Windows 3.1") == -1) 
{
  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write(
    'Sub menuflash_FSCommand(ByVal command, ByVal args)\n');
  document.write(
    ' call menuflash_DoFSCommand(command, args)\n');
  document.write('end sub\n');
  document.write('</SCRIPT\> \n');
}

function openDiv()
{
     document.getElementById("menu").style.clip = "rect(auto auto auto auto)"; 
}

function closeDiv()
{
    document.getElementById("menu").style.clip = "rect(auto auto 50 auto)"; 
}

function displayPath(contentid)
{
    //alert(contentid);
    var strPath = "";
    try{
        xmlhttp2 = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp2 = false;
            }
        }
    }

    xmlhttp2.open("GET", "Path.aspx?contentid="+contentid,true);
    xmlhttp2.onreadystatechange=function() {
        if (xmlhttp2.readyState==4){ 
            //building the path
           strPath = xmlhttp2.responseText.toString();
           var path = document.getElementById("path");
           path.innerHTML = strPath;
           //alert(strPath);

           window.document.title = 'Grupo Visabeira';                    
           resetTitle();
           
        }
    }
    xmlhttp2.send(null)
}
*/


//Function used to set the language links style
function markLang(lang)
{
    document.getElementById("but"+lang).className = "selectedLang";
}


//Function that calls and display the html of the banners at the bottom of the page
function displayBanners(channelid)
{
    var strBanners = "";
    try{
        xmlhttp3 = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp3 = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp3 = false;
            }
        }
    }

    if (channelid.toString() != "0")
    {
        // alert('ChannelID: 1');
        xmlhttp3.open("GET", "Banners.aspx?channelid="+channelid);
    }
    else {
        // alert('ChannelID: 0');
        xmlhttp3.open("GET", "Banners.aspx?channelid=0");    
    }

    xmlhttp3.onreadystatechange=function() {
        if (xmlhttp3.readyState==4){ 
            //building the menu
           strBanners = xmlhttp3.responseText.toString();

           var banners = document.getElementById("banners");
           banners.innerHTML = strBanners;
//           alert(strBanners);
           window.document.title = 'Grupo Visabeira';                    
           resetTitle();

        }
    }
    xmlhttp3.send(null) 
    
         
}


//This function is called when the user clicks on a questions at the FAQ's page
function openFaqQuestion(idQuestion,totalQuestions){
	for (i=0;i<totalQuestions;i++)
	{
	    document.getElementById("question"+i).style.display = 'none';
	}
	document.getElementById("question"+idQuestion).style.display = 'block';
}


function openSearch(searchStr,channelid,contentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&searchStr="+searchStr)
    fillTxtSearch();
}

function changeSearchImg()
{
    document.getElementById("imgSearch").src = "imgs/arrow_search_hover.gif";
}

function resetSearchImg()
{
    document.getElementById("imgSearch").src = "imgs/arrow_search.gif";
}
function fillTxtSearch()
{
    document.getElementById("txtSearch").value = searchMsg;
    //align the search button in firefox
    if(navigator.appName.indexOf("Microsoft") == -1)
    {
        document.getElementById("imgSearch").style.paddingBottom="2";
    }
    
}
function resetTxtSearch()
{
    document.getElementById("txtSearch").value = "";
}

function applyForSelectedJob(advertid,channelid,contentid) {
    openMenuAndDisplayContent(channelid, contentid + "&advertid=" + advertid + "&rh=" + channelid);
}

function applyForSelectedSite(siteid,advertid, channelid, contentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&advertid="+advertid+"&SiteID="+siteid);
}

function openDetailedSiteWithAdverts(siteid,channelid, contentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&SiteID="+siteid);
}

function openDetailedAdvert(urlAdvert)
{
    window.open(urlAdvert,'','');
}

function openBoxWorld(numberWorld) {

    // window.location.hash = 'TopMap';    
    closeBoxAllWorld();
    switch (numberWorld) {
        case '1':
            document.getElementById("dvPortugal").style.visibility = 'visible';
            document.getElementById("dvPortugal").style.display = 'block';
            break;            
        
        case '2':
            document.getElementById("dvEspanha").style.visibility = 'visible';
            document.getElementById("dvEspanha").style.display = 'block';
            break;            

        case '3':
            document.getElementById("dvFranca").style.visibility = 'visible';
            document.getElementById("dvFranca").style.display = 'block';
            break;            

        case '4':
            document.getElementById("dvBelgica").style.visibility = 'visible';
            document.getElementById("dvBelgica").style.display = 'block';
            break;            

        case '5':
            document.getElementById("dvRomenia").style.visibility = 'visible';
            document.getElementById("dvRomenia").style.display = 'block';
            break;            

        case '6':
            document.getElementById("dvMarrocos").style.visibility = 'visible';
            document.getElementById("dvMarrocos").style.display = 'block';
            break;            

        case '7':
            document.getElementById("dvArgelia").style.visibility = 'visible';
            document.getElementById("dvArgelia").style.display = 'block';
            break;            

        case '8':
            document.getElementById("dvAngola").style.visibility = 'visible';
            document.getElementById("dvAngola").style.display = 'block';
            document.getElementById("dvVisabeiraAngola").style.visibility = 'visible';
            document.getElementById("dvVisabeiraAngola").style.display = 'block';
            break;            

        case '9':
            document.getElementById("dvMocambique").style.visibility = 'visible';
            document.getElementById("dvMocambique").style.display = 'block';
            document.getElementById("dvVisabeiraMocambique").style.visibility = 'visible';
            document.getElementById("dvVisabeiraMocambique").style.display = 'block';
            break;            

        case '10':
            document.getElementById("dvEmiratosArabesUnidos").style.visibility = 'visible';
            document.getElementById("dvEmiratosArabesUnidos").style.display = 'block';
            break;            

        case '11':
            document.getElementById("dvAfricaDoSul").style.visibility = 'visible';
            document.getElementById("dvAfricaDoSul").style.display = 'block';
            break;  
            
        case '12':
            document.getElementById("dvCaraibas").style.visibility = 'visible';
            document.getElementById("dvCaraibas").style.display = 'block';
            break;  
            
        case '13':
            document.getElementById("dvBulgaria").style.visibility = 'visible';
            document.getElementById("dvBulgaria").style.display = 'block';
            break;            

        case '14':
            document.getElementById("dvTimor").style.visibility = 'visible';
            document.getElementById("dvTimor").style.display = 'block';
            break;            
            
        default:
            closeBoxAllWorld();
            break;       
    }
    window.scrollTo(0,500);
    window.document.title = 'Grupo Visabeira';                    
    resetTitle();
    
}

function closeBoxAllWorld() {
    
    document.getElementById("dvOcult").style.visibility = 'visible';
    document.getElementById("dvOcult").style.display = 'block';
    document.getElementById("dvPortugal").style.visibility = 'hidden';
    document.getElementById("dvPortugal").style.display = 'none';
    document.getElementById("dvEspanha").style.visibility = 'hidden';
    document.getElementById("dvEspanha").style.display = 'none';
    document.getElementById("dvFranca").style.visibility = 'hidden';
    document.getElementById("dvFranca").style.display = 'none';
    document.getElementById("dvBelgica").style.visibility = 'hidden';
    document.getElementById("dvBelgica").style.display = 'none';
    document.getElementById("dvRomenia").style.visibility = 'hidden';
    document.getElementById("dvRomenia").style.display = 'none';   
    document.getElementById("dvBulgaria").style.visibility = 'hidden';
    document.getElementById("dvBulgaria").style.display = 'none';
    document.getElementById("dvMarrocos").style.visibility = 'hidden';
    document.getElementById("dvMarrocos").style.display = 'none';
    document.getElementById("dvArgelia").style.visibility = 'hidden';
    document.getElementById("dvArgelia").style.display = 'none';
    document.getElementById("dvAngola").style.visibility = 'hidden';
    document.getElementById("dvAngola").style.display = 'none';
    document.getElementById("dvVisabeiraAngola").style.visibility = 'hidden';
    document.getElementById("dvVisabeiraAngola").style.display = 'none';
    document.getElementById("dvMocambique").style.visibility = 'hidden';
    document.getElementById("dvMocambique").style.display = 'none';
    document.getElementById("dvVisabeiraMocambique").style.visibility = 'hidden';
    document.getElementById("dvVisabeiraMocambique").style.display = 'none';
    document.getElementById("dvEmiratosArabesUnidos").style.visibility = 'hidden';
    document.getElementById("dvEmiratosArabesUnidos").style.display = 'none';
    document.getElementById("dvAfricaDoSul").style.visibility = 'hidden';
    document.getElementById("dvAfricaDoSul").style.display = 'none';
    document.getElementById("dvCaraibas").style.visibility = 'hidden';
    document.getElementById("dvCaraibas").style.display = 'none';
    document.getElementById("dvTimor").style.visibility = 'hidden';
    document.getElementById("dvTimor").style.display = 'none';
}

function resetTitle()
{
    var txtTitle = window.document.title;
    var txtUrl = window.location.href;
    
    if ( txtUrl.indexOf("#TopMap") > 0 ) {
        window.document.title = 'Grupo Visabeira';
    }
}

function fileCheck(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img); 
    }
    else 
    {
        funzione="fileCheck('"+img+"')"; 
        intervallo=setTimeout(funzione,50); 
    }
}

function makeWindow(img)
{ 	
    ht = picfile.height + 20;
    wd = picfile.width + 20; 

    var args= "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
    // return window.open(img, 'Imagem', args); 
    
	var popurl="SpecialPages/image.aspx?image=" + img
	winpops = window.open(popurl,"Imagem",args)
    
} 

function openPopUp(strPath) {

    picfile = new Image(); 
    picfile.src =(strPath); 
    fileCheck(strPath); 
}
