function inviaData(data)      
{
  document.form_data_bacheca.dtCald_giorno.value = data;
  document.form_data_bacheca.submit();
}
function inviaDataGiorno(data)      
{
  document.formStrisciaGiorno.dtCald_giorno.value = data;
  document.formStrisciaGiorno.submit();
}
function inviaDataMese(data)      
{
  document.formStrisciaMese.dtCald_anno.value = data;
  document.formStrisciaMese.submit();
}
function cerca(azione)      
{
  document.formCerca.action.value = azione;
  document.formCerca.submit();
}


function ControllaUserPwd(u, p) 
{
    if ((u == '' || u.length <= 3) || (p == '' || p.length <= 3)) 
        return false; 
    else 
        return true; 
}
function inviaRicorda(azione, log)      
{
  document.getElementById('areaRiserv').action.value = azione;
  document.getElementById('areaRiserv').submit();
}

function invia(azione, log, pwd)      
{
  if (ControllaUserPwd(log, pwd))
  {
	document.getElementById('areaRiserv').action.value = azione;
    document.getElementById('areaRiserv').submit();
  }
  else
  {
    alert("Scrivere più di tre caratteri nei campi user e/o password!");
  }
}

function ControllaMail(EmailAddr)
{
  Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(EmailAddr))
    return true;
  else
    return false;
}
function invia_mail(indirizzo)
{
  if (ControllaMail(indirizzo))
  {
    document.location = "mailto: " + indirizzo + "?subject=http://www.unita.it/";
  }
  else
  {
    alert("Per favore inserisci un indirizzo e-mail valido!");
    document.form2.email.focus();
  }
}
function invia_dr(nome, email, azione)
{
  if (document.getElementById('formDR').privacy.checked)
  {
  if (nome != ''){
	  if (email != ''){
          if (ControllaMail(email)){
              trovato = false;
			  a = document.getElementById('formDR');
              for (i = 0; i < a.length; i++)
              {
                if (a.elements[i].type == "textarea" && a.elements[i].value != "")
			      trovato = true;
              }
			  if (trovato)
			  {
    	        document.getElementById('formDR').action.value = azione;
                document.getElementById('formDR').submit();
			  }
			  else
			  	alert("Devi rispondere ad almeno una domanda!");
          }
          else{
              alert("Per favore inserisci un indirizzo e-mail valido!");
    	      document.formDR.email.focus();
          }
      }
      else{
            trovato = false;
			a = document.getElementById('formDR');
            for (i = 0; i < a.length; i++)
            {
              if (a.elements[i].type == "textarea" && a.elements[i].value != "")
			    trovato = true;
            }
			if (trovato)
			{
              document.getElementById('formDR').action.value = azione;
              document.getElementById('formDR').submit();
			}
			else
			  alert("Devi rispondere ad almeno una domanda!");
      }
  }
  else{
      alert("Il campo Nome e Cognome è obbligatorio!");
      document.formDR.nome.focus();
  }
  }
  else
    alert("E\' necessario approvare la normativa sulla privacy!");
}

function votazione(IDcontent, votare)
{
  scelta = "";
  if (votare)
  {
    a = document.sondaggio.vota;
    for (i = 0; i < a.length; i++)
    {
      if (a[i].checked == true)
      {
        scelta = a[i].value;
        break;
      }
    }
  }
  if ((votare && scelta != "") || !votare)
      window.open('sondaggio/vota.asp?vota=' + scelta + '&IDcontent=' + IDcontent, 'sondaggio','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=110,left=0,width=577,height=280');
  else if (votare && scelta == "")
      alert("Per poter votare devi prima selezionare un'opzione!");
}
function apriPopup(ID, IDcanale)
{
  var win = open('view/view.asp?ID='+ID+'&IDcanale='+IDcanale, 'preview','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=20,left=20,width=520,height=600');
  win.window.focus();
}
function openImgBig(url_root, ID, IDcanale, templateImageW, templateImageH) 
{
  var win = open(url_root+'view/view_imgBig.asp?ID='+ID+'&IDcanale='+IDcanale,"Preview","resizable=no,scrollbars=yes,menubar=no,width="+templateImageW+",height="+templateImageH+",top=0,left=0")
  win.window.focus();
}
function newBachUten(nick, lingua, ges)
{
  var win = open('ges_bacheca.asp?nick='+nick+'&lingua='+lingua+'&ges='+ges, 'preview','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=0,left=0,width=550,height=640');
  win.window.focus();
}
function openStampa(namePag, lingua, ID ,IDcontent, IDcanale, tema, tema2, tema3, tema4, pagLista, pagNews, pagBandi, pagEventi, pagCaleven, pagRastamp, pagLinks, pagDocum, pagVideo, pagGalfot, pagGalvid, pagCerca, action, testo, pagImg, pagVid)
{
  var win = open(namePag+'?stp=stp&lingua='+lingua+'&ID='+ID+'&IDcontent='+IDcontent+'&IDcanale='+IDcanale+'&tema='+tema+'&tema2='+tema2+'&tema3='+tema3+'&tema4='+tema4+'&pagLista='+pagLista+'&pagNews='+pagNews+'&pagBandi='+pagBandi+'&pagEventi='+pagEventi+'&pagCaleven='+pagCaleven+'&pagRastamp='+pagRastamp+'&pagLinks='+pagLinks+'&pagDocum='+pagDocum+'&pagVideo='+pagVideo+'&pagGalfot='+pagGalfot+'&pagGalvid='+pagGalvid+'&pagCerca='+pagCerca+'&action='+action+'&testo='+testo+'&pagImg='+pagImg+'&pagVid='+pagVid, 'preview','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=20,left=20,width=558,height=600');
  win.window.focus();
}
function newsletterIscr(IDcontent, IDcanale, tema, tema2, tema3, tema4, lingua)
{
  var win = open('newsletterIscr.asp?IDcontent='+IDcontent+'&IDcanale='+IDcanale+'&tema='+tema+'&tema2='+tema2+'&tema3='+tema3+'&tema4='+tema4+'&lingua='+lingua, 'preview','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=0,left=0,width=650,height=600');
  win.window.focus();
}
function lingua(namePag, IDcanale, tema, tema2, tema3, tema4, lingua)
{
  location.href(namePag+'?IDcanale='+IDcanale+'&tema='+tema+'&tema2='+tema2+'&tema3='+tema3+'&tema4='+tema4+'&lingua='+lingua);
}

function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
indirizzo = "";
for(var j=0; j < this.keyValuePairs.length; j++)
{
  if(this.keyValuePairs[j].split("=")[0] != "style")
  {
    if (indirizzo == "")
      indirizzo = "?" + this.keyValuePairs[j].split("=")[0] + "=" + this.keyValuePairs[j].split("=")[1];
    else
      indirizzo = indirizzo + "&" + this.keyValuePairs[j].split("=")[0] + "=" + this.keyValuePairs[j].split("=")[1];
  }
}
if (indirizzo == "")
  indirizzo = "?" + "style=" + s;
else
  indirizzo = indirizzo + "&" + "style=" + s;
indirizzo = location.href.replace(location.search, "") + indirizzo;
location.href = indirizzo;
return false;
}
this.getLength = function() { return this.keyValuePairs.length; }
}
function queryString(key){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));
}

function rossa(theURL,winName,features) { //v2.0
  var w;
  var h;
  var str;
  var inizio;
  var str;
  inizio = features.indexOf("width=") + 6;
  fine = features.indexOf(",",inizio);
  if (fine != -1) {
     str = features.substring(inizio,fine);
    } else {
     str = features.substring(inizio);
     }
  w = parseFloat(str)
  inizio = features.indexOf("height=") + 7;
  fine = features.indexOf(",",inizio);
  if (fine != -1) {
     str = features.substring(inizio,fine);
    } else {
     str = features.substring(inizio);
     }
  h = parseFloat(str)

  PosX = (screen.width - w) / 2;
  PosY = (screen.height - h) / 2;

  window.open(theURL,winName,features + ",left=" + PosX + ",top=" +
PosY+",screenX=" + PosX +",screenY=" + PosY);
}

var fin;
function apri(theURL,winName,features){
  if (fin != null){
	if (!fin.closed){
      fin.close();
	  fin=null;
	  fin=window.open(theURL,winName,features);
	  fin.focus();
	}
	else{
	  fin=window.open(theURL,winName,features);
	  fin.focus();
	}
  }
  else{
	fin=window.open(theURL,winName,features);
	fin.focus();
  }
}

function popupStampa(url, dimX, dimY){
  if (screen){
    y = (screen.availHeight - dimY)/2;
    x = (screen.availWidth - dimX)/2;
  }
  var oWin = window.open(url,'Stampa_articolo','width='+dimX+',height='+dimY+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',toolbar=0, location=0, status=0, menubar=0, scrollbars=1, resizable=1');
  if (oWin==null || typeof(oWin)=="undefined"){ 
    alert('Il tuo browser non consente l\'apertura di finestre di Popup.\nPer visualizzare la versione stampabile è necessario abilitarlo per questo sito.'); 
  }
}

function popupOpen(url, dimX, dimY){
  if (screen){
    y = (screen.availHeight - dimY)/2;
    x = (screen.availWidth - dimX)/2;
  }
  var oWin = window.open(url,'Popup','width='+dimX+',height='+dimY+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',toolbar=0, location=0, status=0, menubar=0, scrollbars=0, resizable=0');
  if (oWin==null || typeof(oWin)=="undefined"){
    alert('Il tuo browser non consente l\'apertura di finestre di Popup.\nPer visualizzare il popup è necessario abilitarlo per questo sito.'); 
  }
}

function openLogin(){
  window.open('login.asp','','width=400,height=350,menubar=no,toolbar=no,statusbar=no,titlebar=no');
}

function MM_openBrWindow(theURL,winName,features){
  window.open(theURL,winName,features);
}

function conta_battute(id, max, lung){
  lung = lung.length;
  campo_conteggio = eval("document.formDR.conta_" + id);
  campo_conteggio.value = lung;
  campo_conteggio.style.background = "white";
  campo_conteggio.style.color = "black";
  if (lung > max)
  {
	campo_conteggio.style.background = "red";
    campo_conteggio.style.color = "white";
	alert("Hai superato la lunghezza massima dei caratteri: " + lung  + " / " + max + "\nSe viene superata la lunghezza massima il testo sarà tagliato");
  }
}

