﻿// 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
    {
    
        for (i=0;i<menuItems.length;i++)
        {
            menuItems[i].style.display = "none";
        }
    }

    
}


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.top = "0";
               document.getElementById("scrollerBar").style.top = "0";
            }
        }
        xmlhttp1.send(null)
    }
    else
    {
        var content = document.getElementById("content");
        content.innerHTML = "";
    }
}


//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);
        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;
        }
    }
}

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();
    }
}

function subitens_DoFSCommand(command, args) 
{
    var sampleFlaMovieObj = getFlashMovie("subitens");
    
    if (command == "openMenuAndDisplayContent")
    {
        var args1 = args.split(",");
        openMenuAndDisplayContent(args1[0],args1[1]);
    }
}

// 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);
        }
    }
    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()
{
    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;
            }
        }
    }

    xmlhttp3.open("GET", "Banners.aspx");
    xmlhttp3.onreadystatechange=function() {
        if (xmlhttp3.readyState==4){ 
            //building the menu
           strBanners = xmlhttp3.responseText.toString();
           var banners = document.getElementById("banners");
           banners.innerHTML = strBanners;
           //alert(strBanners);
        }
    }
    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);
}

function openDetailedAdvert(advertid,channelid,contentid)
{
    openMenuAndDisplayContent(channelid,contentid + "&advertid="+advertid);
}


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); 
}
