// ---------------------------------- STAZIONE EDITORIALE E ARTICOLI ---------------------------------------------

function openWin(url, name, scrollbar, w, h) {

       popupWin = window.open(url, name, 'resizable=1,scrollbars=' + scrollbar + ',width=' + w + ',height=' + h + '');
       // focus window (only for Navigator >= 3.0)

    if ( (navigator.appName != "Microsoft Internet Explorer") && (navigator.appVersion.substring(0,1) == "3") )

    popupWin.focus();

}


// Aggiunge la pagina ai preferiti
function addbookmark(pagina,titolo){

		window.external.AddFavorite(pagina,titolo);

}

// Fa del sito la home page di default
function principale(modulo) {

	if (isIE4){
		modulo.style.behavior='url(#default#homepage)';
		modulo.setHomePage("http://www.inauto.com/");
	}

}

// stampa...
function stampa() {
            self.print();
}

// per photogallery
function doLoadSecNextPage(s, max) {

				       // the timeout value should be the same as in the "refresh" meta-tag

     					// max is the number of pages

     					var tempo;

     					tempo = 1000 * s;

     					//setTimeout("refresh(" + max + ")", tempo);

     					setTimeout("refreshNextPage(" + max + ")", tempo);

}

// refresh automatico per gallery
function refreshNextPage(max) {

        				var count = 0;
        				var base = "";
        				var temp = window.location.href;
        				var u = temp.lastIndexOf('pg');
        				var a = temp.lastIndexOf('/');

        				if (u < a) {

               				 //sono alla prima pagina
                				base = temp + '/pg';
                				count = 2;

        				}

        				else {
                				//sono in pagina successiva
                				base = temp.substring(0, u + 2);
                				count = eval(temp.substring(u+2,temp.length)) + 1;
                			}

        				if (max >= count) {
                				temp = base + count;
                			}

        				else {
                				//ho superato il contatore
                				temp = base + 1;
                			}

                			window.location.href = temp;

}





// ----------------------- UPLOAD FILE ----------------------------------------- //

function apriPopupUpload(theURL) {
self.name="chiamante";
var winOpts = 'resizable=no,scrollbars=yes,width=550,height=600';
  window.open(theURL,'',winOpts);
}

function verificaCompleto() {
	var inString = "";
	var completo = 1;
	var estensioneCorretta = 1;

	inString = "" + document.invia_dati.name.value;
	if (inString.length < 1) {
		completo = 0;
	}
	inString = "" + document.invia_dati.surname.value;
	if (inString.length < 1) {
		completo = 0;
	}
	inString = "" + document.invia_dati.subject.value;
	if (inString.length < 1) {
		completo = 0;
	}
	inString = "" + document.invia_dati.email.value;
	if (!validateEmail(inString)) {
		completo = 0;
		document.invia_dati.email.select();
	}

	if(completo==0){
		alert("Completa tutti i campi, per favore");
		return false;
	} else {
		return true;
   	}
}


// Javascript per la verifica dell'indirizzo email //

function validateEmail(inString) {
	var alfaNum;
	var startPos;
	var ch;
	var ch;
	var up;
	var pp;
	var dom;

	ch = inString.lastIndexOf('@');
	dom = inString.substring(ch+1);
	pp = dom.indexOf('.');
	up = dom.lastIndexOf('.');

	//!*|,;:"<>()[]{}@&$#%
	if (inString.length < 6) { //indirizzo troppo corto
		return false;
	}
	if (ch < 1) { //@ troppo indierto
		return false;
	}
	if (pp < 1) {  //@ troppo vicina al primo .
		return false;
	}
	if (up > dom.length - 3) { //ultimo . troppo avanti
		return false;
	}
	if (up < dom.length - 7) {  //ultimo . troppo indietro
		return false;
	}

	startPos = 0;
	alfaNum = "!*|,;:<>()[]{}@&$#%?"; //!*|,;:<>()[]{}@&$#% caratteri vietati nel dominio
	while (startPos < dom.length) {
		ch = dom.charAt(startPos);
		if (alfaNum.indexOf(ch) >= 0) {
			return false;
		}
		startPos++;
	}

	return true;
}

// chiusura finestra //

function chiudi(){
    window.close() ;
}

// Javascript per la verifica di form //

function verifica(form) {
  if (form.globale.value == "") {
    alert("scrivi una marca o un modello");
    return false;
  }
}

// Javascript per ora internet //

function orainternet(BrowserTime) {
var thisT;
var thisM;
var thisS;
var iT;
     thisT = BrowserTime.getHours();
	 thisM = BrowserTime.getMinutes();
	 thisS = BrowserTime.getSeconds();
	 iT = (thisT*3600 + thisM*60 +thisS)*10/864;
     //return '<a href="javascript:;" onClick="popUpInternetTime()">' + iT + '</a>';
     return iT;
}

//**************************  FORUM   ***********************************//


function apriPopup(theURL) {
self.name="chiamante";
var winOpts = 'resizable=no,scrollbars=yes,width=750,height=600';
  window.open(theURL,'',winOpts);
}

function closeRemote() {
  timer = setTimeout('window.close();', 10);
}

function trimString(inString) {
  var startPos;
  var endPos;
  var ch;

  // where do we start?
  startPos = 0;
  ch = inString.charAt(startPos);
  while ((ch == " ") || (ch == "\b") || (ch == "\f") || (ch == "\n") || (ch == "\r") || (ch == "\n")) {
    startPos++;
    ch = inString.charAt(startPos);
  }

  // where do we end?
  endPos = inString.length - 1;
  ch = inString.charAt(endPos);
  while ((ch == " ") || (ch == "\b") || (ch == "\f") || (ch == "\n") || (ch == "\r") || (ch == "\n")) {
    endPos--;
    ch = inString.charAt(endPos);
  }
  return inString.substring(startPos, endPos + 1);
}

function validateEmail(inString) {
  var alfaNum;
  var startPos;
  var ch;
  var ch;
  var up;
  var pp;
  var dom;

  ch = inString.lastIndexOf('@');
  dom = inString.substring(ch+1);
  pp = dom.indexOf('.');
  up = dom.lastIndexOf('.');

  if ((inString.length < 6) || (ch < 1) || (pp < 1) || (up > dom.length - 3) ||(up < dom.length - 7))
    return false;
  startPos = 0;
  alfaNum = "!*|,;:<>()[]{}@&$#%?"; // caratteri vietati nel dominio
  while (startPos < dom.length) {
    ch = dom.charAt(startPos);
    if (alfaNum.indexOf(ch) >= 0) {
      return false;
    }
    startPos++;
  }
  return true;
}

function cancellaInter(url) {
  var ret = confirm("Sicuro di voler cancellare l'intervento?");
  if(ret==true){
    document.invio.action=url;
    document.invio.submit();
  }
}

function cancellaArgo(url){
  var ret = confirm("Sicuro di voler cancellare l'argomento?");
  if(ret==true){
    document.invio.action=url;
    document.invio.submit();
  }
}

function verificaInter(moderato) {
  if (trimString(document.invio.nick.value).length==0) {
    alert("inserire nickname");
    return false;
  }
  if (trimString(document.invio.titolo.value).length==0) {
    alert("inserire titolo");
    return false;
  }
  if (trimString(document.invio.testo.value).length==0) {
    alert("inserire testo");
    return false;
  }
  if (trimString(document.invio.testo.value).length>3200) {
    alert("il testo è troppo lungo");
    return false;
  }
  document.invio.nick.value = trimString(document.invio.nick.value);
  document.invio.email.value = trimString(document.invio.email.value);
  document.invio.titolo.value = trimString(document.invio.titolo.value);
  document.invio.testo.value = trimString(document.invio.testo.value);
  if (moderato=='0')
    closeRemote();
  return true;
}

function verificaArgo(moderato) {
  if (trimString(document.invio.nick.value).length==0) {
    alert("inserire nickname");
    return false;
  }
  if (trimString(document.invio.titolo.value).length==0) {
    alert("inserire titolo");
    return false;
  }
  if (trimString(document.invio.testo.value).length==0) {
    alert("inserire testo");
    return false;
  }
  if (trimString(document.invio.testo.value).length>4000) {
    alert("il testo è troppo lungo");
    return false;
  }
  if (!validateEmail(trimString(document.invio.email.value))) {
    alert("verificare email");
    return false;
  }
  document.invio.nick.value = trimString(document.invio.nick.value);
  document.invio.email.value = trimString(document.invio.email.value);
  document.invio.titolo.value = trimString(document.invio.titolo.value);
  document.invio.testo.value = trimString(document.invio.testo.value);
  if(moderato=="0")
    closeRemote();
  return true;
}

function verificaInterAmm(moderato) {
  var ret;
  if (trimString(document.invio.nick.value).length==0) {
    alert("inserire nickname");
    return false;
  }
  if (trimString(document.invio.titolo.value).length==0) {
    alert("inserire titolo");
    return false;
  }
  if (trimString(document.invio.testo.value).length==0) {
    alert("inserire testo");
    return false;
  }
  if (trimString(document.invio.testo.value).length>3200) {
    alert("il testo è troppo lungo");
    return false;
  }
  if (!validateEmail(trimString(document.invio.email.value))) {
    alert("verificare email");
    return false;
  }
  document.invio.nick.value = trimString(document.invio.nick.value);
  document.invio.email.value = trimString(document.invio.email.value);
  document.invio.titolo.value = trimString(document.invio.titolo.value);
  document.invio.testo.value = trimString(document.invio.testo.value);
  if (document.invio.cdIntervento.value != "0")
    if (document.invio.nuovo.checked) {
      document.invio.cdIntervento.value = "0";
      ret = true;
    }
    else {
      ret = confirm("Modifcare l'intervento mostrato?");
    }
    else
      ret = true;
    if (ret==true)
      closeRemote();
    return ret;
}

function verificaArgoAmm(moderato) {
  if (trimString(document.invio.nick.value).length==0) {
    alert("inserire nickname");
    return false;
  }
  if (trimString(document.invio.titolo.value).length==0) {
    alert("inserire titolo");
    return false;
  }
  if (trimString(document.invio.testo.value).length==0) {
    alert("inserire testo");
    return false;
  }
  if (trimString(document.invio.testo.value).length>4000) {
    alert("il testo è troppo lungo");
    return false;
  }
  if (!validateEmail(trimString(document.invio.email.value))) {
    alert("verificare email");
    return false;
  }
  document.invio.nick.value = trimString(document.invio.nick.value);
  document.invio.image.value = trimString(document.invio.image.value);
  document.invio.email.value = trimString(document.invio.email.value);
  document.invio.titolo.value = trimString(document.invio.titolo.value);
  document.invio.testo.value = trimString(document.invio.testo.value);
  closeRemote();
  return true;
}

//---------------------------------------SONDAGGI----------------------------------------------------------------

function vota() {
var risp='risp_'+document.sondaggio.domanda.value;
var id='';
var nr=document.sondaggio.numrisp.value;
for(var i=0; i<nr; i++){
	if(document.sondaggio.risp_1[i].checked){
           id= risp+'='+document.sondaggio.risp_1[i].value + '&';
}
}
  openWin('/sondaggi/43?'+ id +'idCategoria='+ document.sondaggio.idCategoria.value +'&idServizio='+ document.sondaggio.idServizio.value +'&idScheda='+ document.sondaggio.idScheda.value,'','yes',720,580);
}


//--------------------------------------GESTIONE UTENTE----------------------------------------------------------


function validaNuovoUtente() {

  var nickname = document.formutente.nickname.value;
  var password = document.formutente.password.value;

  if (nickname == "" || password == "") {
  	alert("I campi username e password sono obbligatori");
  	return false;
  }
  else
  	return true;
}