// Funzioni per il controllo dei caratteri rimanenti

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if 
(e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder);
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(theform,thelimit){
var limit_text='<strong><span id="'+theform.toString()+'">'+thelimit+'</span></strong> caratteri rimanenti'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function()
{ return restrictinput(thelimit,event,theform)} 
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { 
restrictinput(thelimit,event,theform) }, true); document.body.addEventListener('keyup', function(event) { 
countlimit(thelimit,event,theform) }, true); }
}



// Funzioni per il Fade
function high(which2) 
{
  theobject = which2
  highlighting = setInterval("highlightit(theobject)", 50)
}

function low(which2) 
{
  clearInterval(highlighting)
  which2.filters.alpha.opacity = 60
}

function highlightit(cur2) 
{
  if (cur2.filters.alpha.opacity < 100)
    cur2.filters.alpha.opacity += 5
  else if (window.highlighting)
    clearInterval(highlighting)
}



// News
function moduloNotizie(modulo) 
{
	with(modulo)
	
	if
	( 
		(valoreNonSelezionato(idNewsCategoria,"Categoria"))||
		(valoreNonSelezionato(data,"Data"))||
		(testoVuoto(titolo,"Titolo"))||
		(testoVuoto(sottotitolo,"Sottotitolo"))||
		(testoVuoto(descrizione,"Descrizione")) ||
		(valoreNonSelezionato(idFonte,"Fonte"))||
		(testoVuoto(autore,"Autore"))
		
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function eliminaNotizie(id)
{

	var conferma = window.confirm("Fare clic su OK per cancellare il progetto. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="notizie-salva.asp?azione=cancellazione&id=" + id 
	}
}

// News
function moduloRubriche(modulo) 
{
	with(modulo)
	
	if
	( 
		(testoVuoto(categoria,"Categoria"))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function eliminaRubriche(id)
{

	var conferma = window.confirm("Fare clic su OK per cancellare la rubrica. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="rubriche-salva.asp?azione=cancellazione&idNewsCategoria=" + id 
	}
}





function news(id) {
		var w,h,l,t;
		w=520;
		h=450;
		l=screen.width;
		l=(l - w) / 2;
		t=screen.height;
		t=(t - h) / 3;
		window.open('newsView.asp?id=' + id + '','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width='+w+',height='+h+',left='+l+',top='+t+'');
}

function barzellettaPop(id)
{	
	w=400;
	h=400;
	l=screen.width;
	l=(l - w) / 2;
	t=screen.height;
	t=(t - h) / 3;
	window.open('barzellettePopView.asp?id=' + id + '','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width='+w+',height='+h+',left='+l+',top='+t+'');
	
}

function homePage()
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://www.sezzeweb.it/');
}


function inserisciSpot() 
{
  var w=screen.width; 
  var x=(w - 400) / 2;
  var h=screen.height;
  var y=(h - 400) / 3;
  //popupImage = window.open('','_blank','toolbar=0,left=' + x + ',top=' + y + ',location=0,directories=0,menuBar=0,scrollbars=0,align=center,resizable=0');
  window.open("SpotIns.asp","componi","width=400,height=280,left=" + x + ",top=" + y + ",scrollbars=0");
}

function ControlloNewsletter()
{

email = document.newsletter.txtEmail.value;
if ((email == "") || (email.indexOf ('@') == -1) || (email.indexOf ('.') == -1)) 
{
	alert("Indirizzo email inserito non valido");
	return false; 
}
{
	document.newsletter.submit();
}
}


function moduloAppuntamenti(modulo) 
{
	with(modulo)

		
	if
	( 
		(valoreNonSelezionato(categoria,"Categoria")) ||		
		(testoVuoto(data,"Data")) ||
		(testoVuoto(citta,"Cittā")) ||
		(testoVuoto(luogo,"Luogo")) ||
		(testoVuoto(orario,"Orario")) ||
		(testoVuoto(appuntamento,"Appuntamento")) ||
		(testoVuoto(descrizione,"Descrizione"))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function moduloGuest(modulo) 
{
	with(modulo)

		
	if
	( 
		(testoVuoto(nominativo,"Nominativo")) ||
		(testoVuoto(descrizione,"Descrizione"))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function moduloCommentoImmagini(modulo) 
{
	with(modulo)

		
	if
	( 
		(testoVuoto(nominativo,"Nominativo")) ||
		(testoVuoto(commento,"Commento"))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function moduloImmagini(modulo) 
{
	with(modulo)

		
	if
	( 
		(valoreNonSelezionato(galleria,"Galleria")) ||		
		(testoVuoto(nome,"Nome")) ||
		(testoVuoto(anno,"Anno")) ||
		(testoVuoto(autore,"autore")) ||
		(testoVuoto(descrizione,"Descrizione"))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}


function moduloGallerie(modulo) 
{
	with(modulo)

		
	if
	( 
		(valoreNonSelezionato(categoria,"Categoria")) ||		
		(testoVuoto(titolo,"Titolo")) ||
		(testoVuoto(sottotitolo,"Sottotitolo")) ||
		(testoVuoto(descrizione,"Descrizione"))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}


function eliminaAppuntamento(id)
{
	
	var conferma = window.confirm("Fare clic su OK per cancellare l'appuntamento. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="appuntamenti-salva.asp?azione=cancellazione&id=" + id 
	}
}

function eliminaImmagine(id)
{
	
	var conferma = window.confirm("Fare clic su OK per cancellare l'immagine. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="gallerie-salva-immagine.asp?azione=cancellazione&id=" + id 
	}
}


function eliminaGalleria(id)
{
	
	var conferma = window.confirm("Fare clic su OK per cancellare la galleria. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="gallerie-salva.asp?azione=cancellazione&id=" + id 
	}
}


function moduloNegozi(form) 
{
	with(form)
	
	if
	( 
		(valoreNonSelezionato(idAttivitaCategoria,"Categoria"))||		
		(testoVuoto(ragioneSociale,"Ragione Sociale"))||
		(testoVuoto(attivitaSvolta,"Attivitā svolta"))||		
		(testoVuoto(citta,"Cittā"))||
		(testoVuoto(indirizzo,"Indirizzo"))||		
		(testoVuoto(descrizione,"Descrizione"))||
		(ErrorEmail(email))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function eliminaNegozio(id)
{
	
	var conferma = window.confirm("Fare clic su OK per cancellare l'annuncio. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="negozi-salva.asp?azione=cancellazione&id=" + id 
	}
}


function moduloAnnunci(form) 
{

	with(form)
	
	if
	( 
		(valoreNonSelezionato(categoria,"Categoria"))||		
		(testoVuoto(oggetto,"Oggetto"))||
		(testoVuoto(descrizione,"Descrizione"))||
		(testoVuoto(zona,"Zona"))||		
		(testoVuoto(nominativo,"nominativo"))||		
		(CampiVuoti(email,"email", telefono,"telefono")) ||
		(ErrorEmail(email))
	)
	{
		return false;
	}
	else
	{ 
		return true;
	}
}

function eliminaAnnuncio(id)
{
	
	var conferma = window.confirm("Fare clic su OK per cancellare l'annuncio. Fare clic su Annulla per interrompere l'operazione.");
	if (conferma) {
	location.href="annunci-salva.asp?azione=cancellazione&id=" + id 
	}
}

// Controlla se un valore in una cambo box č stato selezionato
function valoreNonSelezionato(campo,nome) {
	
	if (campo.value == "") {
        alert("Il campo '"+nome+"' non e' stato selezionato");
		campo.focus();
		return true;
	}
	return false 
	
}



// Questa funzione verifica se il campo č valorizzato
function testoVuoto(campo,nome) 
{
	if (campo.value=="")
	{  
          alert("Il campo '"+nome+"' e' obbligatorio");
          campo.focus();
          return true;   
	} 
return false;
}

// Questa funzione verifica se almeno uno dei campi e riempito
function CampiVuoti(campo,nome,campo1,nome1)
{ if ((campo.value=="")&&(campo1.value==""))
        { 
          alert("Almeno uno dei campi tra '"+nome+"' o '"+nome1+"' deve essere riempito");
          campo.focus();
          return true;
        }
  return false;
}

// Questa funzione controlla l'email
function ErrorEmail(campo)
{
  var st=campo.value;
  if (st !="")
  {
        if ( 	(st.indexOf("@")==-1)  || (st.indexOf(".")==-1)|| (st.length < 8) ||
				(st.indexOf("@-")!=-1) || 
				(st.indexOf("-.")!=-1) ||
				(st.indexOf("@.")!=-1) ||
                (st.indexOf("@@")!=-1)
           )
                { 
                alert("Indirizzo di Email non valido");
                campo.focus();
//              campo.value="";
                return true;
                }

        for(var i=0;i<st.length;i++)
                {
                car=st.charAt(i);
                if (car==" ")
                        {
                        alert("Non e' possibile inserire spazi nell'indirizzo di Email");
                        campo.focus();
                        return true;
                        }
                if (car=="@")
                        {
                        for(var k=i+1;k<st.length;k++)
                                {
                                car1=st.charAt(k);
                                if (
                                        ((car1<'a') || (car1>'z')) &&
                                        ((car1<'A') || (car1>'Z')) &&
                                        ((car1<'-') || (car1>'-')) &&
                                        ((car1<'0') || (car1>'9')) &&
                                        ((car1<'.') || (car1>'.'))
                                   )
                                        {
                                        alert("Indirizzo di Email non valido");
                                        campo.focus();
                                        return true;
                                        }
                                }
                        }
                }

  }
  return false;
}

// Questa funzione controlla il numero telefonico
function ErrorTel(campo,nomeCampo)
{var st=campo.value;
 var car;
  if (st !="")
  {
        for (var k=0;k<st.length;k++)
        { car=st.charAt(k);
          if (
              ((car<'0') || (car>'9'))
              &&
 	           ((car != '+') && (car !='/') && (car !='-')) 
             )
           { alert("Il campo "+nomeCampo+" puo'  contenere solo caratteri numerici");
             campo.focus();
//	     campo.value="";
             return true;
           }
        }
}

return false;

}  









