// JavaScript Document
function showArea(id) {
	var element=document.getElementById(id);
	if(element.style.display=="block") {
		element.style.display="none";
	} else {
		element.style.display="block";
	}
}

function show(id) {
	var element=document.getElementById(id);
	if(element.style.display=="block") {
		element.style.display="none";
	} else {
		element.style.display="block";
	}
}

function display(id) {
	var element=document.getElementById(id);
	element.style.display="block";
}


function nascondi(id) {
	var element=document.getElementById(id);
	element.style.display="none";
}

function autogrow_textarea(id) {
	// Opera isn't just broken. It's really twisted.
	ta = document.getElementById(id);
	ta.style.overflow = "hidden";
	if (ta.scrollHeight > ta.clientHeight && !window.opera) {
		ta.rows += 1;
	}
}

function normalize(str) {
	str=str.toLowerCase();
	str=str.replace(/[ "'°]/gi, "_");
	str=str.replace(/à/gi, "a");
	str=str.replace(/è/gi, "e");
	str=str.replace(/ì/gi, "i");
	str=str.replace(/ò/gi, "o");
	str=str.replace(/ù/gi, "u");
	str=str.replace(/&/gi, "");
	//alert(str);
	return str;
}

// Utilizzata in add_podcast.php
function codicePaese(paese) {
	area=document.getElementById("area_codice");
	nomeFile=normalize(paese);
	codice='<p><img src="img/step2.gif" alt="Step 2" /> Ascolta il podcast di <strong class="viola">'+paese+'</strong> attraverso il player oppure vai direttamente al passo successivo</p>';
	codice+='<style type="text/css">@import "http://www.belsalento.it/inc/podcast.css";</style>';
	codice+='<center><div id="podcastOnSiteByBelsalento">';
	codice+='<h1>'+paese+'</h1>';
	codice+='<object type="application/x-shockwave-flash" data="http://www.belsalento.it/podcast/streaming.swf?mp3file=http://www.belsalento.it/podcast/mp3/'+nomeFile+'.mp3" width="90" height="25">';
	codice+='<param name="movie" value="http://www.belsalento.it/podcast/streaming.swf?mp3file=http://www.belsalento.it/podcast/mp3/'+nomeFile+'.mp3" />';
	codice+='<param name="bgcolor" value="#FFFFFF" />\n<param name="quality" value="high" />';
	codice+='<param name="menu" value="false" />';
	codice+='</object>';
	codice+='<a href="http://www.belsalento.it/" title="Vieni a scoprire il Bel Salento">BelSalento.it</a>';
	codice+='</div></center>';
	codice+='<p><img src="img/step3.gif" alt="Step 3" /> <strong class="viola">Copia il codice</strong> contenuto nell\'area che segue nella tua pagina web:</p>';
	codice+='<textarea cols="30" rows="5" readonly="readonly" onclick="this.select();">';
	codice+='<div id="podcastOnSiteByBelsalento"><a href="http://www.belsalento.it/" title="Vieni a scoprire il Bel Salento">BelSalento.it</a></div>\n';
	codice+='<script type="text/javascript" src="http://www.belsalento.net/podcastonsite.php?paese=\''+paese+'\'"></script>';
	codice+='</textarea>';
	area.innerHTML=codice;
}
function chk_cellulare(numero)
{
	re = /^\d{9,12}$/;
	return numero.search(re) != -1;
}

function verificaNumStrutture(limite_selezione)
{
	var max =  limite_selezione; // numero massimo strutture contattabili contemporaneamente
	fmobj = document.getElementById('frm');
	contatto_alert=document.getElementById('check_selection');
	var cnt = 0;
	var arr_strutture = "";
  for (var i=0;i<fmobj.elements.length;i++)
  {
    var e = fmobj.elements[i];
    if ( (e.type=='checkbox') && (e.checked) )
    {
      cnt++;
      arr_strutture += e.value +",";
    }
  }

  if (cnt == 0)
  {
	contatto_alert.innerHTML='<div class="attenzione"><p>Seleziona almeno una struttura.</p></div>';
  	return false;
  }
  if (cnt > max)
  {
	contatto_alert.innerHTML='<div class="attenzione"><p>Non puoi contattare pi&ugrave; di '+max+' strutture.</p></div>';
  	fmobj.arr_strutture.value = '';
  	return false;
  }
  else
  {
  	contatto_alert.innerHTML='';
  	fmobj.arr_strutture.value = arr_strutture.substr(0, arr_strutture.length-1);
  	return true;
  }
}

function verificaSel()
{
	fmobj = document.getElementById('frm_contatta');
	contatto_alert=document.getElementById('check_selection');
	var cnt = 0;
	var arr_strutture = "";
  for (var i=0;i<fmobj.elements.length;i++)
  {
    var e = fmobj.elements[i];
    if ( (e.type=='checkbox') && (e.checked) )
    {
      cnt++;
      arr_strutture += e.value +",";
    }
  }

  if (cnt == 0)
  {
	contatto_alert.innerHTML="<div class=\"attenzione\"><p>Seleziona almeno una struttura.</p></div>";
  	return false;
  }
  else
  {
  	contatto_alert.innerHTML='';
  	return true;
  }
}
