/* Cookies */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* Busca links externs i els fica a una finestra nova */
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}


/* Modul menu */
var menu = [];
function getElementbyClass(classname){ 
	var inc=0;
	var customcollection = [];
	var alltags=document.all? document.all : document.getElementsByTagName("*"); 
	for (i=0; i<alltags.length; i++){ 
		if (alltags[i].className==classname)
			customcollection[inc++]=alltags[i];
	} 
	return customcollection;
}
function oculta() {
	for(var i=0;i<menu.length;i++) {
		menu[i].style.display = "none";
	}
}
function mostra() {
	for(var i=0;i<menu.length;i++) {
		menu[i].style.display = "block";
	}
}

function canviaMenu(id) {
	oculta();
	document.getElementById(id).style.display = "block";
}


/* FOTO */

function dibuixInicialitza() {
  album = new Array();
  i=0;
  album[i++] = "http://www.nasticdetarragona.com/web/img/esquerra/1.gif";
  album[i++] = "http://www.nasticdetarragona.com/web/img/esquerra/2.gif";
  album[i++] = "http://www.nasticdetarragona.com/web/img/esquerra/3.gif";
  album[i++] = "http://www.nasticdetarragona.com/web/img/esquerra/4.gif";
  album[i++] = "http://www.nasticdetarragona.com/web/img/esquerra/5.gif";
  album[i++] = "http://www.nasticdetarragona.com/web/img/esquerra/6.gif";
  id=Math.floor(Math.random() * album.length);
  document.getElementById("dibuix").src = album[id];
  setTimeout("dibuixInicialitza()",10000);
}

function canviaVisibilitat(id) {
	if(document.getElementById(id).style.display=="none") {
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

function inicialitza () {
	menu = getElementbyClass("zonaBotons");
	//oculta();
	dibuixInicialitza()
	externalLinks;
}


window.onload = inicialitza;



function imgArticle(imatge) {
  widthw = 20;
  heightw = 20;
  estilo = "resizable=1,menubar=0,toolbar=0,location=0,personalbar=0"+
  ",status=0,scrollbar=0,width="+widthw+",height="+heightw+",top="+
  (screen.height-heightw)/4+",left="+(screen.width-widthw)/4;
  window.open("/web/img_article.php?img="+imatge,"imgArticle",estilo);
}
function escoltaRadio(){
  window.open("/radio.html","radioOnline", "toolbar=no,menubar=no,location=no,statusbar=no,scrollbars=no,resizable=yes,width=300,height=50");
}

function finestra(url) {
  widthw = 350;
  heightw = 300;
  estilo = "resizable=yes,menubar=0,toolbar=0,location=0,personalbar=0"+",status=0,scrollbar=0,width="+widthw+",height="+heightw+",top="+(screen.height-heightw)/2+",left="+(screen.width-widthw)/2;
  window.open(url,"finestra",estilo);
}

function gfotos () {
  msg=open("","NewWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=500,height=420");
  msg.location = "./fotos/index.php"
}

function go(url) {
  document.location = url;
  return true;
}

