﻿function f_Initialize() {
    dhtmlHistory.initialize();
    dhtmlHistory.addListener(f_HistoryChange);
    //Image Manager
    window.setInterval('f_NewTopImage()', 3000);
    
    var currentLocation = dhtmlHistory.getCurrentLocation();
    if (currentLocation == "") {
        currentLocation = "section:mTM0";
        return;
    }
    
    currentLocation = currentLocation.replace(/section\:/, "");
    f_GotoPage(currentLocation);
    
}
function f_GotoPage(page)
{
    if(page=='mTM1') {
        window.location='mappa.aspx';
        return;
     }
     
    page='section:'+page;
    f_HistoryChange(page,'');
    dhtmlHistory.add(page, '');
}
function f_HistoryChange(newLocation, historyData) {

    if (newLocation.indexOf('section:')==0) newLocation=newLocation.substring(8);
    if(newLocation.indexOf('mMI')==0)
    {
        f_SetSelected2(0);
        f_OpenCloseMenu(newLocation);
    }
    else if(newLocation.indexOf('mTM')==0)
    {
        f_SetSelected('');
        f_SetSelected2(newLocation.substring(3));
    }
    else if(newLocation!='login')
        newLocation="";
    
    f_OpenContents(newLocation);
}
function f_OpenContents(page, objId, type)
{
    document.CurrentSelectedPage=page;
    ob_post.UpdatePanelFromPage('mPostbackPanel', 'mContentPanel', 'Default.aspx?pageId='+page+'&l='+document.getElementById('mLanguage').value);
}
function f_ChangeLanguage(languageselect)
{
    window.location="?l="+languageselect.value +"#section:"+(document.CurrentSelectedPage?document.CurrentSelectedPage:"TM0");
}
function f_SetWait()
{
    cont=document.getElementById("id_cont");
    cont.innerHTML='<table class=\"cT\"><tr><td align=\"center\"><table><tr><td><img src=\"./images/loader.gif\"/></td><td>&nbsp;&nbsp;Loading...</td></tr></table></td></tr></table>';
}
function f_SetContents(r)
{
    cont=document.getElementById("id_cont");
    if(r==null) cont.innerHTML="";
    else cont.innerHTML = r;
}
function f_OpenCloseMenu(objId)
{
    f_SetSelected(objId)

    var child;
    var id=objId.substring(3);
    id=id.substring(0,id.indexOf('_'));
    
    for(izs=0;;izs++)
    {
        if(izs<=id) continue;
        child=document.getElementById('mMI'+izs+'_'+id);
        
        if(child==null) break;
          
        if(child.style.display=='none')
            child.style.display='block';
        else
            child.style.display='none';
    }
}
function f_SetSelected2(objID)
{
    l=document.getElementById('mLanguage').value;
    
    for(i=0;i<5;i++)
        if(i==objID)
        {
            document.getElementById('mTM'+i).src='./udata/raw/Dynamics/m'+i+l+'s.jpg';
            document.getElementById('mTMcX'+i).className='cTopMenuItemS';
            document.getElementById('mTMcL'+i).className='cTopMenuItemLS';
            document.getElementById('mTMcR'+i).className='cTopMenuItemRS';
        }
        else
        {
            document.getElementById('mTMcX'+i).className='cTopMenuItem';
            document.getElementById('mTM'+i).src='./udata/raw/Dynamics/m'+i+l+'.jpg';
            document.getElementById('mTMcL'+i).className='cTopMenuItemL';
            document.getElementById('mTMcR'+i).className='cTopMenuItemR';
        }
    
}
function f_SetSelected(objId)
{
    var el,sel;
    for(izx=1;;izx++)
    {
        el=document.getElementById('mMI'+izx+'_0')
        if (el==null)break;
        
        if(objId==el.id)
            el.className="cCMenuItem0S";
        else
            el.className="cCMenuItem0";

        for(jzx=izx;;)
        {
            izx++;
            sel=document.getElementById('mMI'+izx+'_'+jzx);
            if (sel==null)break;
            if(objId==sel.id){
                sel.className="cCMenuItem1S";
                el.className="cCMenuItem0S";
            }
            else
                sel.className="cCMenuItem1";
        }
        izx--;
    }
    
}
