getSection();

function getUrlVars(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
}
function getUrlVar(name){
    return getUrlVars()[name];
}

function creaSottoMenu(sottoMenu){
	document.getElementById('menuL2').innerHTML=sottoMenu;
}
function creaMenu(menu){
	if(menu!=null && menu!=''){
		document.getElementById('menuPrincipale').innerHTML=menu;
		document.getElementById('menuPrincipale').style.display='';
	}
	paintMenu();
} 

jQuery.noConflict();

jQuery(document).ready(function() {
	loadMenu();
});

function getSection(){
	function initFromSection(section){
		if(section == null || section == '')
			_section=getParam("sezione");
		else
			_section=section;
		if(_section == null || _section == '')
			_section='pub';
		loadAllcss();
	}
	if(window.authenticationProxy != null){
		authenticationProxy.getUserSection(initFromSection);
	}else{
		_section=getParam("sezione");
	}
}

function loadMenu(){
	if(_section!='' && _section!='pub' && document.getElementById('menuPrincipale')){
		document.getElementById('menuPrincipale').style.display='none';
		var sottosezione = unescape(getUrlVar('sottosezione'));
		var nome_sottosezione = unescape(getUrlVar('nome_sottosezione'));
		dwr.engine.beginBatch();
			menuProxy.getSottoMenu(sottosezione,creaSottoMenu);
			menuProxy.getMenu(sottosezione,nome_sottosezione,creaMenu);
		dwr.engine.endBatch();	
	}
	if(_section == 'pub'){
		paintMenu();
	}
	if(_section == null || _section == ''){
		window.setTimeout("loadMenu()", 1000);
	}else{
		loadHeaderFooterLink();
	}
}

function loadHeaderFooterLink(){
	if(_section=='club' || _section=='ricevitori')
		document.getElementById('Homepage').href='/arearicevitori/privato/index.html?sottosezione=home';
	else if(_section=='pub'||_section=='')
		document.getElementById('Homepage').href='/arearicevitori/pub/index.html';
	for(i=1;i<5;i++){
		document.getElementById('testata'+i).href=document.getElementById('testata'+i).href.replace('@sezione@' , _section)+'?sezione='+_section;
	}
	for(i=1;i<3;i++){
		document.getElementById('footer'+i).href=document.getElementById('footer'+i).href.replace('@sezione@',_section)+'?sezione='+_section;
	}
}