var menu = new Array();
var leftmenu = new Object();
var leftmenu_flag = 0;
var menuPath = 0;

function addMenuItem(id, parent, link, caption, targetNew) {    

    if (menu['m'+id]) {
        id = id+'_1';
        if (menu['m'+id]) {
          id = id+'_1';
        } 
    } 
    menu['m'+id] = new Array(parent?'m'+parent:parent, link, caption, targetNew);    
}

function addLeftMenuItem(id, parent, link, caption, targetNew) {    

	leftmenu['m'+id] = new Array(parent?'m'+parent:0, link, caption, targetNew);
	leftmenu_flag = 1;
}

function generateMenu(activeItem, openOnClick) {	
    activeItem = 'm'+activeItem;
    menuPath = getPath(activeItem); 

    m1  = '<div id="menuLevel1"><div>\n';            // level 1
    first = true;
    for (var j in menu) {
        if (menu[j][0] == 0) {  
            if (openOnClick) {
                m1 += '<a '+(first?'style="padding: 0px 9px 0px 9px;"':'')+' id="m_'+j+'" href="javascript: showMenuLevel2(\''+j+'\')">'+menu[j][2]+'</a>\n';
            } else {
		if (menu[j][2] == 'Servis') // dalibor 20110214
                {
                        m1 += '<a '+(first?'style="padding: 0px 9px 0px 9px;"':'')+' id="m_'+j+'" '+(menu[j][3]?'target="_blank"':'')+' onmouseover="showMenuLevel2(\''+j+'\')" onmouseout="hideMenuLevel2(\''+j+'\');" showSearchField();" href="http://www.allianzsp.sk/likvidacia_poistnych_udalosti">'+menu[j][2]+'</a>\n';
                }
		else
		{
		        m1 += '<a '+(first?'style="padding: 0px 9px 0px 9px;"':'')+' id="m_'+j+'" '+(menu[j][3]?'target="_blank"':'')+' onmouseover="showMenuLevel2(\''+j+'\')" onmouseout="hideMenuLevel2(\''+j+'\');" showSearchField();" href="javascript: void(0);">'+menu[j][2]+'</a>\n';
		}
            }
            first = false;
        }
    }
    m1 += '</div></div>\n\n';
    
    m2  = '<div id="menuLevel2" style="display: none;">\n';    // level 2
    for (var j in menu) {
        if (menu[j][0] == 0) {  
            first = true;
            m2tmp = '<div id="m2_'+j+'" style="display: none">\n';
            subexists = false;
            for (var k in menu) {
                if (menu[k][0] == j) {
                    m2sub = '';
                    for (var l in menu) {
                        if (menu[l][0] == k) {
                            m2sub += '<a  style="background: none;" '+(menu[l][3]?('onclick="return showMore(\''+menu[l][1]+'\', 860, 630, true)"'):'')+' href="'+menu[l][1]+'">'+menu[l][2]+'</a>';
                        }
                    }          
                    if (m2sub != '') {
                        m2tmp += '<div style="position: relative; float: left;">';
			if (menu[k][2] == 'Poistenie online') // dalibor 20110214
                        {
                                m2tmp += '<a '+(first?'style="padding: 0px 11px 0px 11px;"':'')+' id="m_'+k+'" '+(menu[k][3]?('onclick="return showMore(\''+menu[k][1]+'\', 860, 630, true)"'):'')+' onmouseover="showMenuLevel3(\''+k+'\')" onmouseout="hideMenuLevel2(\''+k+'\'); hideMenuLevel3(\''+k+'\');" href="https://online.allianzsp.sk/">'+(menu[k][2].replace(/\s/gi,'&nbsp;'))+'</a>\n';
                        }
			else if ( (menu[k][2] == 'Info pre klientov') || (menu[k][2] == 'EU Brokers') ) // milan 20110223
			{
				m2tmp += '<a rel="nofollow" '+(first?'style="padding: 0px 11px 0px 11px;"':'')+' id="m_'+k+'" '+(menu[k][3]?('onclick="return showMore(\''+menu[k][1]+'\', 860, 630, true)"'):'')+' onmouseover="showMenuLevel3(\''+k+'\')" onmouseout="hideMenuLevel2(\''+k+'\'); hideMenuLevel3(\''+k+'\');" href="'+menu[k][1]+'">'+(menu[k][2].replace(/\s/gi,'&nbsp;'))+'</a>\n';
			}
			else
			{
                        	m2tmp += '<a '+(first?'style="padding: 0px 11px 0px 11px;"':'')+' id="m_'+k+'" '+(menu[k][3]?('onclick="return showMore(\''+menu[k][1]+'\', 860, 630, true)"'):'')+' onmouseover="showMenuLevel3(\''+k+'\')" onmouseout="hideMenuLevel2(\''+k+'\'); hideMenuLevel3(\''+k+'\');" href="'+menu[k][1]+'">'+(menu[k][2].replace(/\s/gi,'&nbsp;'))+'</a>\n';
			}
                        m2tmp += '<div class="subMenuLevel3" id="subMenuLevel3_'+k+'" onmouseover="showMenuLevel3(\''+k+'\')" onmouseout="hideMenuLevel2(\''+k+'\'); hideMenuLevel3(\''+k+'\');" >';
                        m2tmp += m2sub;
                        m2tmp += '</div>';
                        m2tmp += '</div>';
                    } else {
                        m2tmp += '<a '+(first?'style="padding: 0px 11px 0px 11px;"':'')+' id="m_'+k+'" onmouseout="hideMenuLevel2(\''+k+'\');" onmouseover="showMenuLevel3(\''+k+'\')" '+(menu[k][3]?('onclick="return showMore(\''+menu[k][1]+'\', 860, 630, true)"'):'')+' href="'+menu[k][1]+'">'+(menu[k][2].replace(/\s/gi,'&nbsp;'))+'</a>\n';
                    }
                    subexists = true;                    
                }
            }
            m2tmp += '</div>\n'
            if (subexists)  
                m2 += m2tmp;
        }
    }        
    m2 += '</div>\n\n';
 
    
    m3 = '';        // level 3
    if (menuPath.length>2) activeItem = menuPath[2];
    
    if (menu[activeItem]) 
    if (menu[activeItem][0])  
        if (menu[menu[activeItem][0]]) {
            var j_first = 1;
            for (var j in menu) {
                if (menu[menu[activeItem][0]][0]) {
                    if (menu[activeItem][0] == menu[j][0]) {
                      /*if ( j_first == 0)
                        m3 += '<div class="dottedSpacer" style="margin: 0px;"><!-- --></div>';
                      */
                        
                        if (j==activeItem) {
                            
                            if (!j_first) m3 += '<div class="dottedSpacer_dark" style="margin: 0px; background-color: #ffffff;"><!-- --></div>';
                            // level 4 a 5
                            m45 = "";
                            for (var k in menu) {
                                if (menu[k][0] == activeItem) {
                                    m45 += '<a id="m_'+k+'" '+(menu[k][3]?'target="_blank"':'')+' href="'+menu[k][1]+'">'+menu[k][2]+'</a>\n';
                                    for (var l in menu) {
                                        if (menu[l][0] == k) {
                                            m45 += '<a id="m_'+l+'" '+(menu[l][3]?'target="_blank"':'')+' href="'+menu[l][1]+'">-&nbsp;'+menu[l][2]+'</a>\n';
                                        }
                                    }
                                }
                            }
                            if (m45!="") {
                                m3 += '<div class="menuLevel4main">';
                                m3 += '<a id="m_'+j+'" '+(menu[j][3]?'target="_blank"':'')+' href="'+menu[j][1]+'">'+menu[j][2]+'</a>\n';
                                m3 += '</div>';
                                m3 += '<div class="menuLevel4">';
                                m3 += m45;
                                m3 += '</div>';
                            } else {
                                m3 += '<a id="m_'+j+'" '+(menu[j][3]?'target="_blank"':'')+' href="'+menu[j][1]+'">'+menu[j][2]+'</a>\n';
                            }                            

                        } else {                                                                                    
                            if (!j_first) m3 += '<div class="dottedSpacer_dark" style="margin: 0px; background-color: #ffffff;"><!-- --></div>';
                            m3 += '<a id="m_'+j+'" '+(menu[j][3]?'target="_blank"':'')+' href="'+menu[j][1]+'">'+menu[j][2]+'</a>\n';                                                        
                        }           
                        j_first = 0;               
                        
                    }
                } else {
                    if (activeItem == menu[j][0]) {
                        m3 += '<a  id="m_'+j+'" '+(menu[j][3]?'target="_blank"':'')+' href="'+menu[j][1]+'">'+menu[j][2]+'</a>\n';
                        m3 += '<div class="dottedSpacer_dark" style="margin: 0px; background-color: #ffffff;"><!-- --></div>';
                        j_first = 0;
                    }
                        
                }                                
            }        
            if (m3 != '') m3 += '<div class="dottedSpacer_dark" style="margin: 7px 7px;"><!-- --></div>';
        }
        
        
    document.getElementById('menuContainer').innerHTML = 
      '<div style="position: absolute; top: 0px; height:24px; width: 996px;"></div>' +
      '<div id="fixDiv2" style="position: absolute; top: 26px; height:22px; width: 996px;"></div>' + m1 + m2;
      
      
    // left menu
    if ( document.getElementById( 'menuLevel3'))
    {
	    if ( leftmenu_flag)
	    {
		    var pom = '';
		    for (var j in leftmenu) 
		    {
			if (pom != '') pom += '<div class="dottedSpacer_dark" style="margin: 0px; background-color: #ffffff;"><!-- --></div>';    
			pom += '<a id="m_'+j+'" '+(leftmenu[j][3]?'target="_blank"':'')+' href="'+leftmenu[j][1]+'">'+leftmenu[j][2]+'</a>\n';
		    }
		    if (pom != '') pom += '<div class="dottedSpacer_dark" style="margin: 7px 7px;"><!-- --></div>';
		    document.getElementById( 'menuLevel3').innerHTML = pom;
	    }
	    else if (m3 != '') 
	    {
		document.getElementById('menuLevel3').innerHTML = m3;
	    }
    }

/*
for (i=0;i<menuPath.length;i++)
{
    alert(menu[menuPath[i]][1]+':'+menu[menuPath[i]][2]);
}
*/
    activateMenu(menuPath);
}

function getPath(id) {
    path = new Array();
    path[0] = id;
    if (menu[path[0]]) {        
        var level = 0;
        var stoplvl = false;
        for (lvl=0;lvl<5;lvl++) {    
        if (!stoplvl) {
            if (menu[path[lvl]][0] != 0)
            for (i in menu) {        
                if (menu[path[lvl]][0] == i) {
                    path[lvl+1] = i;
                    if (menu[path[lvl+1]][0] == 0) stoplvl = true;
                }
            }
            if (!path[lvl+1]) stoplvl=true;
        }
        }
    }
    
    return path.reverse();
}

var myTimeout2=0;
function showMenuLevel2(id) {
    //skova vyhladavacie pole,         
    document.getElementById('searchInput').blur();
    hideMenuLevel3all();
    clearTimeout(myTimeout);
    clearTimeout(myTimeout2);
    
    for (var j in menu) {
        if (menu[j][0] == 0) {
            if (document.getElementById('m2_'+j))
                document.getElementById('m2_'+j).style.display='none';
            document.getElementById('m_'+j).className='';
        }
    }
    
    if (document.getElementById('m2_'+id)) {
        document.getElementById('m2_'+id).style.display='block';
        document.getElementById('menuLevel2').className='active';
        document.getElementById('m_'+id).className='active';
        //document.getElementById('fixDiv2').style.backgroundColor = '#426bb3';
        document.getElementById('menuLevel2').style.display='block';
    } else {
        document.getElementById('menuLevel2').className='';
        document.getElementById('m_'+id).className='active noSub';
        document.getElementById('fixDiv2').style.backgroundColor = '#113388';
        document.getElementById('menuLevel2').style.display='none';
    }

}

function hideMenuLevel2(id) {        
    showSearchField();
    //myTimeout2 = setTimeout('hideMenuLevel2now(\''+id+'\')', 1000);
    myTimeout2 = setTimeout('hideMenuLevel2all()', 1000);
}

function hideMenuLevel2all() {
    for (i in menu) {
        if (menu[i][0]) {
            if (menu[menu[i][0]][0] == 0) {                                
                document.getElementById('m2_'+menu[i][0]).style.display='none';
                document.getElementById('m_'+menu[i][0]).className='';
            }
        }
    }
    document.getElementById('menuLevel2').className='';
    document.getElementById('menuLevel2').style.display='none';
}


var myTimeout=0;
function showMenuLevel3(id) {    
    showMenuLevel2(menu[id][0])
    clearTimeout(myTimeout);
    clearTimeout(myTimeout2);
    
    if (document.getElementById('subMenuLevel3_'+id)) {
        showMenuLevel2(menu[id][0]);
        document.getElementById('subMenuLevel3_'+id).style.display='block';
        document.getElementById('m_'+id).className='active';
    }
}

function hideMenuLevel3now(id,resetL2) {    
    if (document.getElementById('subMenuLevel3_'+id)) {
        document.getElementById('subMenuLevel3_'+id).style.display='none';
        document.getElementById('m_'+id).style.width = 'auto';
        if (menuPath.length>1) {
            if (id != menuPath[1])
                document.getElementById('m_'+id).className='';
        } else 
            document.getElementById('m_'+id).className='';
        if (resetL2) {
            showMenuLevel2(menu[id][0]);
        }
    }
}

function hideMenuLevel3(id) {    
    showSearchField();
    myTimeout = setTimeout('hideMenuLevel3now(\''+id+'\')', 1000);
}

function hideMenuLevel3all() {
    for (i in menu) {
        if (menu[i][0]) {
            if (menu[menu[i][0]]) {
                if (menu[menu[i][0]][0] == 0) {
                    hideMenuLevel3now(i);
                }
            }
        }
    }
}

function activateMenu(path) {
    id = path[path.length-1];
    if (document.getElementById('m_'+id)) {
        
        document.getElementById('m_'+id).className='active';        
        //showMenuLevel2(path[0]);

        if (path.length>1) {
            document.getElementById('m_'+path[1]).className='active';
        }

    }
}

function showSearchField()
{
//  document.getElementById('header_search').style.display="block";
}


/* START: google analytics */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20303642-1']);
_gaq.push(['_setDomainName', '.allianzsp.sk']);
_gaq.push(['_trackPageview']);

/* END: google analytics */

/* START: custom tracking */

/**
* tracking function called from within campaign hub flash
* you may use a different name for this function.
* To do this enter the name of the function
* into following node of your campaign hub configuration
*     <trackingFunction>...</trackingFunction>
* the configuration xml is assigned to the xmlPath in your flashvars
* 
*/

function serviceTracker(trackStr)
{
	/**
	* tracking string contains following parameters
	*     area (e.g. Filter, Scroll, AdditionalInfo, Follow, Print, Open, DetailView, UGC)
	*     element (e.g. Search, Category, UGCText, PlayVideo ...)
	*     detail (e.g. search terms, selected values ...)
	*     advice (= ID of advice)
	*     isPageView (= 'true' or 'false')
	*
	* example: area=...&element=...&detail=...&advice=...&isPageView=...
	*
	*	parameters names may also be custimized to match your needs
	* by entering the names into your configuration xml:
	*				<params>
	*					<area>area</area>
	*					<element>element</element>
	*					<detail>detail</detail>
	*					<advice>advice</advice>
	*					<isPageView>isPageView</isPageView>
	*				</params>
	*
	*/

	// build params object from tracking string
	var paramArr = trackStr.split('&');
	var params = {};
	for(var i = 0, len = paramArr.length; i < len; i++){
		var _param = paramArr[i].split('=');
		params[_param[0]] = _param[1];
	}
	
	// do pageview oder event tracking
	if(params.isPageView == 'true'){
		/**
		* submit ['_trackPageview' , url] to google analytics queue
		* build the url from tracking string according to your tracking requirements
		*
		* example: area/element/detail/advice
		* 
		* for more information:
		* http://code.google.com/intl/en/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview
		*/
		
		var ga_url = params.area + '/' + params.element;
		if(typeof params.detail != 'undefined' && params.detail !== '' && params.detail !== null){
			ga_url += '/' + params.detail
		}
		if(typeof params.advice != 'undefined' && params.advice !== '' && params.advice !== null){
			ga_url += '/' + params.advice
		}
		
		_gaq.push(['_trackPageview',ga_url]); // track pageview
		
	}else{
		
		/**
		* submit ['_trackEvent' , category, action, opt_label, opt_value] to google analytics queue
		* assign the params from tracking string according to your tracking requirements
		*
		* example:
		*     category = area (e.g. Filter, Scroll, AdditionalInfo, Follow, Print, Open, DetailView, UGC)
		*     action = element (e.g. Search, Category, UGCText, PlayVideo ...)
		*     opt_label = detail#advice
		* 
		*     opt_value = [optional, not used in this example]
		* 
		* Please note: "opt_value" differs from the others in that it is of type integer rather than string.
		* It is used to assign a numerical value to a tracked page object.
		* The value is interpreted as a number and the report adds the total values based on each event count.
		* The report also determines the average value for the category.
		* 
		* for more information: 
		* http://code.google.com/intl/en/apis/analytics/docs/tracking/eventTrackerOverview.html
		*/
		
		var ga_category = params.area,
				ga_action = params.element || params.area,
				ga_opt_label = params.advice;
		if(typeof params.detail != 'undefined' && params.detail!==null){
			if(typeof ga_opt_label == 'undefined' || ga_opt_label===null){
				ga_opt_label = params.detail;
			}else{
				ga_opt_label += '#' + params.detail;
			}
		}
		if(typeof ga_opt_label == 'undefined'){
			ga_opt_label =  null;
		}
		
		_gaq.push(['_trackEvent', ga_category, ga_action, ga_opt_label]); // track event
		
	}
}

/* END: custom tracking */

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

