
/***************************************
 * MENU
 ***************************************/

   var menu = [
     {
        link: "skatingrho-c.html",
        titolo: "Home",
        nome: "Home",
        cnt: 0,
	bgImg: 'home.gif'
     },
     {
        link: "chiSiamo-c.html",
        titolo:"Chi siamo",
        nome: "chiSiamo",
        cnt: 1,
	bgImg: 'chiSiamo.jpg'
     },
     {
        link:"comeTrovarci-c.html",
        titolo: "Come trovarci",
        nome: "comeTrovarci",
        cnt: 1,
	bgImg: 'comeTrovarci.jpg'
     },
     {
        link: "Corsi-c.html",
        titolo: "Corsi",
        nome: "Corsi",
        cnt: 7,
	bgImg: 'corsi.jpg'
     },
     {
        link: "pensieri/indexj.html",
        titolo: "Pensieri",
        nome: "Pensieri",
        cnt: 3,
	bgImg: 'pensieri.jpg'
     },
     {
        link: "diconoDiNoi-c.html",
        titolo: "Dicono di noi",
        nome: "DDN",
        cnt: 16,
	bgImg: 'diconoDiNoi.gif'
     },
     {
        link: "calendari-c.html",
        titolo: "Calendario 2012",
        nome: "Cal",
        cnt: 9,
	bgImg: 'calendario.jpg'
     },
     {
        link: "eventi-c.html",
        titolo: "Eventi/Foto",
        nome: "Eventi",
        cnt: 27,
	bgImg: 'eventi.jpg'
     },
     {
        link: "video-c.html",
        titolo: "Video",
        nome: "Video",
        cnt: 13,
	bgImg: 'video.jpg'
     },
     {
        link: "atleti/2012/index-c.html",
        titolo: "Gli atleti 2012",
        nome: "Atleti",
        cnt: 5,
	bgImg: 'atleti.jpg'
     }
   ];

function creaMenu(m){
   var md=document.createElement("div");
   md.id="menuDIV";
   var mul=document.createElement("ul");
   mul.id="menuList";

   
   var newMenu=document.createElement('div');
   //newMenu.setAttribute("class","newMenu");
   newMenu.id="newMenu";
   var newMenut=document.createTextNode("New");
   newMenu.appendChild(newMenut);

   for(el in menu){

     var mli=document.createElement("li");
     mli.setAttribute("class","mLA"+menu[el].nome);  
     mli.setAttribute("nome",menu[el].nome);

     var url = " "+document.location;
     if(location.hash=="#"+menu[el].nome){
       mli.id="menuListActive";
     }//else{mli.id="menuListItem";}
     var mlia=document.createElement('a');
     mlia.href=menu[el].link;
     mlia.setAttribute("title",menu[el].nome);
     var mlian=document.createTextNode(menu[el].titolo)
     mlia.appendChild(mlian);

     var cntckname="ck_"+menu[el].nome;
     var cntcookie=readCookie(cntckname);
/*
     if(cntcookie<menu[el].cnt){
        mlia.appendChild(newMenu.cloneNode(true));
        if(mli.id=="menuListActive"){createCookie(cntckname,menu[el].cnt,1000);}
     }
*/
     mli.appendChild(mlia);

     if(cntcookie<menu[el].cnt){
        var nm=mli.appendChild(newMenu.cloneNode(true));
        if(mli.id=="menuListActive"){createCookie(cntckname,menu[el].cnt,1000);}
     }

     mul.appendChild(mli);
   }

   md.appendChild(mul);
   m.appendChild(md);

  $('#menuList a').hover(
     function () {
        $(this).addClass("menu-hover");
     },
     function () {
        $(this).removeClass("menu-hover");
     }
  );
}

function togliNew(li){

  var menuI;
  for(i=0;i<menu.length; i++){
    if(menu[i].nome==li.attr("nome")){menuI=menu[i];break;}
  }/*
  li.children(".newMenu").each(function(n){
    $(this).remove();
  });*/
  li.parent().children().each(function(n){
    $(this).css('background-image','');
  });
  li.css('background-image','url("'+prefisso+'files/'+menuI.bgImg+'")');
  li.children().each(function(n){
    if(n==1){$(this).remove();}
  });
  createCookie("ck_"+menuI.nome,menuI.cnt,1000);
}

/***************************************
 * FOOTER
 ***************************************/
function creaFooter(f){

   var fd=document.createElement("div");
   fd.id='footerDIV';
   var ful=document.createElement("ul");
   ful.id='footerList';

   var footerEls = [
     {
        nome: "Archema",
	img : "files/logo-arkema.gif",
        link: "http://www.arkemagroup.com/"
     },
     {
        nome: "Comune di Rho",
	img : "files/logo-comune-rho.gif",
        link: "http://www.comune.rho.mi.it/"
     },
     {
        nome: "FIHP",
	img : "files/logo-fihp.jpg",
        link: "http://www.fihp.org/"
     },
     {
        nome: "CONI",
	img : "files/logo-coni.gif",
        link: "http://www.coni.it/"
     },
     {
        nome: "Circuito Nord Ovest",
	img : "files/logo-cno.png",
        link: "http://www.circuitonordovest.org/"
     },
     {
        nome: "TC Gru",
	img : "files/logo1-tcgru.jpg",
        link: "http://www.tcgru.com/"
     },/*
     {
        nome: "Sprintauto",
	img : "files/logo-Sprintauto-Alliance.gif",
        link: "http://www.sprintauto.com/"
     },*/
     {
        nome: "Centro Dentale Crodent<br>Chirurgia orale e maxillo facciale<br>Odontoiatria generale - implantologia<br>ortodonzia - protesi dentarie<br>Dir. San. Dott. Cugliandro Sergio<br><br><b>RHO</b><br>Via Buozzi 6 Passirana di Rho (MI)<br>+39 02 93502782<br><br><b>CRODO</b><br>Via Pellanda 23 Crodo (VB)<br>+39 0324 618857",
	img : "files/logo-CentroDentaleCrodent.gif"
     },
     {
        nome: "Gymnasion Parabiago",
	img : "files/LogoGym.png",
	 	  link: "http://www.gymnasionparabiago.it"
     }
   ];

   for(el in footerEls){
     var fli=document.createElement("li");
     var flia=document.createElement('a');
     var img=document.createElement('img');
     img.src=prefisso+footerEls[el].img;
     img.title=footerEls[el].nome;
     img.alt=footerEls[el].nome;
     img.setAttribute("class", "tooltipSR");
     if(footerEls[el].link){flia.href=footerEls[el].link};
     //var flian=document.createTextNode(footerEls[el].nome)
     //flia.appendChild(flian);
     flia.appendChild(img);
     fli.appendChild(flia);
     ful.appendChild(fli);
   }

   fd.appendChild(ful);
   f.appendChild(fd);

   fd=document.createElement("div");
   fd.id="footerSR";
   flia=document.createElement('a');
   flia.href="mailto:info@skatingrho.it";
   flian=document.createTextNode("info@skatingrho.it")
   flia.appendChild(flian);
   fd.appendChild(flia);
   f.appendChild(fd);
}

/***************************************
 * SetDefaultPage
 ***************************************/
function SetDefaultPage() {
   var i = document.getElementById("intestazione");
   var m = document.getElementById("menu");
   var f = document.getElementById("footer");

   // INTESTAZIONE
   var a = document.createElement("a");
   a.href=prefisso+"index.html";
   var ii = document.createElement("img");
   ii.src = prefisso+"files/bg-2011.jpg";
   ii.alt = "Skating Rho";
   a.appendChild(ii);
   i.appendChild(a);

   // MENU
   creaMenu(m);

   // FOOTER
   creaFooter(f);
}

/***************************************
 * SetNoMenuPage
 ***************************************/
function SetNoMenuPage() {
   var i = document.getElementById("intestazione");
   var f = document.getElementById("footer");

   // INTESTAZIONE
   var a = document.createElement("a");
   a.href=prefisso+"index.html";
   var ii = document.createElement("img");
   ii.src = prefisso+"img/bg6.jpg";
   ii.alt = "Skating Rho";
   a.appendChild(ii);
   i.appendChild(a);

   // FOOTER
   creaFooter(f);
}


function write_smail() {
 at="onio@";

 document.write('<form action="/cgi-bin/FormMail.pl" method="POST"> <input type=hidden name="recipient" value="ant');
 document.write(at);
 document.write('skatingrho.it"> <input type=hidden name="subject" value="Richiesta Info"> <table border="0" cellspacing="0" cellpadding="5" align="center"> <tr> <td align="right"><b> Nome e Cognome:</b></td> <td align="left"><input type=text name="realname" size="30"></td> </tr> <tr> <td align="right"><b>Indirizzo e-mail:</b></td> <td align="left"><input type=text name="email" size="30"></td> </tr> <tr> <td colspan="2"><b>Messaggio:</b></td> </tr> <tr> <td colspan="2" align="center"><textarea name="messaggio" cols="60" rows="5"></textarea></td> </tr> <tr> <td colspan="2" align="center"><input type="Submit" value="Invia"></td> </tr> </table> <input type=hidden name="required" value="email,realname,messaggio"> </form> ');
}


  function numMese(mese){
    var m=mese.substr(0,3).toLowerCase();
    if(m=='gen'){return '00';}
    if(m=='feb'){return '01';}
    if(m=='mar'){return '02';}
    if(m=='apr'){return '03';}
    if(m=='mag'){return '04';}
    if(m=='giu'){return '05';}
    if(m=='lug'){return '06';}
    if(m=='ago'){return '07';}
    if(m=='set'){return '08';}
    if(m=='ott'){return '09';}
    if(m=='nov'){return '10';}
    if(m=='dic'){return '11';}
    return '00';
  }

  function getDataEvento(d) {
       var data1 = d, datav=data1.split(" ");
       var aaaa=2010,mm,dd="04";
       if(datav.length>2){
         aaaa=datav[2];
       }
       if (datav.length>1){
         dd=datav[0];
         mm=numMese(datav[1]);
       }
       if(datav.length==1){
         mm=numMese(datav[0]);
       }
       var datad = new Date()
       datad.setDate(dd);
       datad.setMonth(mm);
       datad.setFullYear(aaaa);
       return datad;
  }

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 var 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 "";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

