function init() {
	if ((document.getElementById) && (document.getElementsByTagName)) {
		if (document.getElementById("llista-menu")!=null) {
			sfHover();
		}
		
		if (document.getElementById("submenu")!=null) {
			getMenu()
		}
		
		var buttons = document.getElementsByTagName("button");
		for ( var button in buttons ) {
		    buttons[button].onclick = function () {
		        this.form.submit();
		    }
		}
		
		if (document.getElementById("presentacioFlash")) {
			d = new Date();
			activarFlash2("flash/"+idiomaSessio+"/header_auditori.swf","presentacioFlash","id"+d.getMilliseconds())
		}
		
		if (document.getElementById("amics-flash")) {
			d = new Date();
			activarFlash("flash/amic_auditori.swf","amics-flash","354","88")
		}
		
		if (document.getElementById("dataText")) {
			var mydate= new Date()
				var theyear=mydate.getFullYear()
				var themonth=mydate.getMonth()+1
				var thetoday=mydate.getDate()
			
			document.getElementById("dataText").appendChild(document.createTextNode(weekday[mydate.getDay()]));
			strong = document.createElement("strong");
			strong.appendChild(document.createTextNode(thetoday+"."+themonth+"."+theyear));
			document.getElementById("dataText").appendChild(strong);
		}
		
	}
	
}
 


//Activació del flash
function activarFlash(adreca,desti,ample,alt) {
	var so = new SWFObject(adreca, "mymovie", ample, alt, "7", "#FFFFFF");
	so.addParam("wmode", "transparent");
    so.write(desti);
}

function activarFlash2(adreca,desti,movieName) {
	var so = new SWFObject(adreca, movieName, "", "", "7", "#FFFFFF");
	so.addParam("wmode", "transparent");
    so.write(desti);
}

				


//Enviar formulari
function sendForm(idFormulari) {
	if (document.getElementById(idFormulari)) {
		var formulari = document.getElementById(idFormulari);
		validateForm( formulari, 0, 1, 0, 0, 2 );
	}
	
}




//Menu principal
function sfHover() {
	var sfEls = document.getElementById("llista-menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			if (this.className == "ultimsfhover")
				Element.toggleClassName(this, 'ultimsfhover');
			else
				Element.toggleClassName(this, 'sfhover');
		}
		sfEls[i].onmouseout=function() {
			if (this.className == "ultimsfhover")
				Element.toggleClassName(this, 'ultimsfhover');
			else
				Element.toggleClassName(this, 'sfhover');
		}
	}
}





//Funció que eleimina els nodes "blnks" al mozilla
	// -- S'utilitza a: getMenu()
	
var notWhitespace = /\S/;

function cleanWhitespace(node) {
	for (var x = 0; x < node.childNodes.length; x++) {
		
		var childNode = node.childNodes[x]
		if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
		// that is, if it's a whitespace text node
		node.removeChild(node.childNodes[x])
		x--
		}
	
	
		if (childNode.nodeType == 1) {
			// elements can have text child nodes of their own
			cleanWhitespace(childNode)
		}
	}
}









//Submenu
var oMenuListItemsActive = new Array();
var activeMenu = ''; 
var activeSubmenu = '';

function getMenu() {
	oMenu = document.getElementById('submenu');
	cleanWhitespace(oMenu)
}

function showMenu(obj) {
	
	if (activeMenu!='') {
		activeMenu.style.display="none";
		activeMenu=''
	}
		
	var oUL = obj.nextSibling;
	
	oUL.style.display="block"
	activeMenu = oUL;
}

function showMenuOferta(obj) {
	
	if (activeSubmenu!='') {
		activeSubmenu.style.display="none";
		activeSubmenu=''
	}
		
	var oUL = obj.nextSibling;
	
	oUL.style.display="block";
	activeSubmenu = oUL;
}



//obrir popup
function openPopup(url) {
	window.open(absHREF(url),'finestra','width=500,height=500,resizable=yes,scrollbars=yes,status=yes');
}

function openPopupH(url, aH ) {
	window.open(absHREF(url),'finestra','width=500,height='+aH+',resizable=yes,scrollbars=yes,status=yes');
}

function openPopupWH (url, aW, aH ) {
	window.open(absHREF(url),'finestra','width='+aW+',height='+aH+',resizable=yes,scrollbars=yes,status=yes');
}

function openLink(url){
	window.open(absHREF(url),'finestra','resizable=yes,scrollbars=yes,status=yes');
}

function linkMain(url) {
	window.opener.location.href = absHREF(url);
	return false;
}



//Canvi d'idioma

function canviIdioma(codi) {
	formulari = document.getElementById('llenguatge');
	idioma = document.getElementById('idioma');
	
	var ubicacio = document.location.href
	
	if (ubicacio.charAt(ubicacio.length-1)=='/') {
		formulari.action = (document.location.href + "index.aspx")
	}
	
	idioma.value=codi;
	formulari.submit();
}

//window.onload=init
Event.observe(window,"load",init);