var sito_title = 'Sorgeaqua - Servizio idrico integrato'
var sito_url = 'http://www.sorgeaqua.it'
var sito_dominio = 'sorgeaqua'

// antispam (almeno ci proviamo!)
function scrivi(nome) {
    	document.location = "mailto:" + nome + "@" + sito_dominio;
}

// defult status
defaultStatus = sito_title

// variabile random
var numero_random = (Math.random()*1000);

// tira fuori dal frameset
if (window != top) top.location = location;

// javascript:PopUPThis('imm/1.jpg');
function PopUPThis(img) {
	var fpop = window.open("","nome","width=100,height=100,menubar=no,toolbar=no,resizable=no,scrollbars=no");
	fpop.document.write('<html>\n');
	fpop.document.write('<head>\n');
	fpop.document.write('<title>' + sito_title + '</title>\n');  
	fpop.document.write('</head>\n');
	fpop.document.write('<script language=\'JavaScript\' type="text/javascript">\n');  
	fpop.document.write('function fitPic() {\n');  
	fpop.document.write('	var NS = (navigator.appName=="Netscape")?true:false;\n');
	fpop.document.write('	iWidth  = (NS)?window.innerWidth:document.body.clientWidth;\n');
	fpop.document.write('	iHeight = (NS)?window.innerHeight:document.body.clientHeight;\n');  
	fpop.document.write('\n');
	fpop.document.write('	var l = Math.floor((screen.availWidth  - document.images[0].width)/2);\n');
	fpop.document.write('	var a = Math.floor((screen.availHeight - document.images[0].height)/2);\n');
	fpop.document.write('\n');
	fpop.document.write('	iWidth  = document.images[0].width  - iWidth;\n');
	fpop.document.write('	iHeight = document.images[0].height - iHeight;\n');
	fpop.document.write('	window.resizeBy(iWidth, iHeight-1);\n');
	fpop.document.write('\n');
	fpop.document.write('	window.moveTo(l, a);\n');
	fpop.document.write('\n');
	fpop.document.write('	self.focus();\n');
	fpop.document.write('}\n');	
	fpop.document.write('</script>\n');
	fpop.document.write('<body style="margin:0px;" onLoad="fitPic();">\n');  
	fpop.document.write('<a href="javascript:self.close()"><img src="' + img + '" border="0" galleryimg="no" alt="Close"></a>\n');  
	fpop.document.write('</body>\n');
	fpop.document.write('</html>\n');
	fpop.document.close();
}

// pop up NO SCROLL
function winnoscroll(pag,w,h,nome) {
  var l = Math.floor((screen.availWidth-w)/2); 
  var a = Math.floor((screen.availHeight-h)/2);
  fin = window.open(pag,nome,"width="+w+",height="+h+",menubar=no,toolbar=no,resizable=no,scrollbars=no,left=" + l + ",top=" + a);
}

// pop up CON SCROLL
function winscroll(pag,w,h,nome) {
  var l = Math.floor((screen.availWidth-w)/2); 
  var a = Math.floor((screen.availHeight-h)/2);
  fin = window.open(pag,nome,"width="+w+",height="+h+",menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=" + l + ",top=" + a);
}

// funzione per scopri copri pezzi di codice
function scopri(a) {
	if(document.getElementById(a).style.display != 'block') {
		document.getElementById(a).style.display = 'block';
	} else {
		document.getElementById(a).style.display = 'none';
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

//Bookmark Page

//
isIE = isIE4 = isIE5 = isIE6 = isIE7 = isNS = isNS4 = isNS6 = isNS7 = isNS8 = isFlash5 = isFlashMX = false;

// Browser Detection
if(navigator.appName.indexOf('Netscape') == 0) isNS = true;
if(navigator.appName.indexOf('Microsoft') == 0) isIE = true;
isUNIX = (window.navigator.appVersion.indexOf("X11") != -1) ||
         (window.navigator.appVersion.indexOf("Linux") != -1) ||
         (window.navigator.appVersion.indexOf("SunOS") != -1) ||
         (window.navigator.appVersion.indexOf("IRIX") != -1) ||
         (window.navigator.appVersion.indexOf("HP-UX") != -1);
isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
isWindows = navigator.userAgent.indexOf("Windows 95") != -1 ||
            navigator.userAgent.indexOf("Windows 98") != -1 ||
            navigator.userAgent.indexOf("Windows NT") != -1;
isMacIE = (isMac && isIE);

// Netscape Version
if(isNS) {
  v = parseInt(navigator.appVersion);
  if(v == 4) {
    isNS4 = true;
  } else if(v == 5) {
    p = navigator.userAgent.lastIndexOf('/');
    v = parseInt(navigator.userAgent.substr(p+1));
    eval("isNS" + v + " = true");
  }
}

// Internet Explorer Version
if(isIE) {
  v = parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+5));
  eval("isIE" + v + " = true");
}


//Bookmark Page

function addbookmark() { 
  var bookmarktitle = sito_title;
  var bookmarkurl = sito_url;
  var netscape
  var macintosh
  netscape="Attenzione! Per aggiungere questa pagina ai Preferiti premere CTRL+D.\n\nPer aggiungere questa pagina alla Sidebar di Netscape, premi OK alla schermata successiva.\n\nAttention! To Bookmark this page please click the page you would like to bookmark and press CTRL+D. If you would like to add this page to your Netscape Sidebar, please click OK on the next window which appears.";
  macintosh="Attenzione! Per aggiungere ai Preferiti questa pagina premere CTRL+D.\n\nAttention! To Bookmark this page please click the page you would like to bookmark and press CTRL+D.";

  if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
    window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
  } else if (isMac) {
    alert(macintosh);
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  }
}

aa_gg = new Array('Domenica','Lunedì','Martedì','Mercoledì','Giovedì','Venerdì','Sabato');
aa_ms = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');
function vis_dataora() {
	var ora = new Date();
	var aa = ora.getDate();
	var mm = ora.getMonth();
	var yy = ora.getFullYear();
	var oo = ora.getHours();
	var mn = ora.getMinutes();
	var sec = ora.getSeconds();
	var dd = ora.getDay();
	var aa2  = ((aa < 10) ? "0" : "");
	var oo2  = ((oo < 10) ? "0" : "");
	var mn2  = ((mn < 10) ? ".0" : ".");
	var sec2  = ((sec < 10) ? ".0" : ".");
	// var Data = aa2 + aa +" "+ aa_ms[mm]  + " " + yy;
	var Data = aa +" "+ aa_ms[mm]  + " " + yy;
	//var hh = oo2 + oo + mn2 + mn + sec2 + sec;
	var hh = oo + mn2 + mn + sec2 + sec;
	
	//if(document.all){
	//	document.all.dataora.innerHTML = "Con Ms Ie: " + aa_gg[dd] + " - " + Data + " - " + hh;
	//}
	//else if(document.getElementById){
	//	document.getElementById('dataora').innerHTML  = aa_gg[dd] + " - " + Data + " - " + hh;		
	//} 
	document.getElementById('dataora').innerHTML  = Data + " ore " + hh;
	window.setTimeout("vis_dataora()",1000);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////

// AC Run Active Content
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////

// cambia lingua
// le cartelle devono essere di 2 lettere 
// si passa il nome della cartella (es: it, en, es, fr, de, ecc)
function cl(quale){
	var lunghezza = sito_url.length 
	var tuttoUrl = String ( document.location ) 
	var lingua = "/" + tuttoUrl.slice ( lunghezza + 1, lunghezza + 3 ) + "/"
	var nuovoUrl = tuttoUrl.replace( lingua , "/" + quale + "/" ) 
	document.location = nuovoUrl;
}


function swimgph(q,d) {
	document.getElementById('iph'+q+'s').src = '/immagini/ph_'+q+'_s_'+d+'.gif';	
}

//o

function openD(theURL) {
  var l = Math.floor((screen.availWidth-580)/2); 
  var a = Math.floor((screen.availHeight-400)/2);
  window.open(theURL,'cv_news',"width=580,height=400,menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=" + l + ",top=" + a);
}

function openNI(dd) {
  var l = Math.floor((screen.availWidth-580)/2); 
  var a = Math.floor((screen.availHeight-400)/2);
  window.open('/dd_ni.htm?ID='+dd,'cv_news_i',"width=580,height=400,menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=" + l + ",top=" + a);
}

function PopupPic(sPicURL) { 
  /*window.open("/popup.htm?"+sPicURL, "", "resizable=0,HEIGHT=10,WIDTH=10");*/
  PopUPThis(sPicURL);  
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve contenere un numero tra '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è un campo obbligatorio.\n'; }
  } if (errors) alert('ATTENZIONE!\nSi sono verificati i seguenti errori:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}



function validEmail(email){
	invalidChars = "/:,;";
	if (email == ""){ return false;}
	for (i=1; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) != -1){ return false;}
		}
	atPos = email.indexOf("@",1)
	if (atPos == -1) return false;
	if (email.indexOf("@",atPos+1) != -1) return false;
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) return false;
	if (periodPos+3 >  email.length) return false;
	return true;
}
function validPhone(phone){
	invalidChars = "abcdfghijklmnopqrsuvwyzABCDFGHIJKLMNOPQRSUVWYZ!@$%&*?"
	if (phone == ""){ return false;}
	for (i=1; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (phone.indexOf(badChar,0) != -1){ return false; }
	}
	return true;
}
function autolettura(form){			
	if (form.cod_utenza.value == "") {
		alert("Occorre inserire i 13 campi del codice utenza");
		form.cod_utenza.focus();
		form.cod_utenza.select();
		return false;
	}
	if (form.mat_contatore.value == "") {
		alert("Occorre inserire la matricola del contatore");
		form.mat_contatore.focus();
		form.mat_contatore.select();
		return false;
	}
	if (form.int_fornitura.value == "") {
		alert("Occorre inserire l'intestatario della fornitura");
		form.int_fornitura.focus();
		form.int_fornitura.select();
		return false;
	}
	if (form.lett_rilevata.value == "") {
		alert("Occorre inserire la lettura rilevata");
		form.lett_rilevata.focus();
		form.lett_rilevata.select();
		return false;
	}
	if (form.data_rilevazione.value == "") {
		alert("Occorre inserire la data di rilevazione");
		form.data_rilevazione.focus();
		form.data_rilevazione.select();
		return false;
	}	
	if ((form.telefono.value == "") || ((form.telefono.value!="") && (!validPhone(form.telefono.value)))) {
		alert("Occorre inserire un numero di telefono corretto nel caso sia necessario ricontattarvi");
		form.telefono.focus();
		form.telefono.select();
		return false;
	}	
	return true;
}

function comunica_con_noi(form){			
	if (form.nominativo.value == "") {
		alert("Occorre inserire il proprio nome e cognome");
		form.nominativo.focus();
		form.nominativo.select();
		return false;
	}
	if ((form.telefono.value == "") || ((form.telefono.value!="") && (!validPhone(form.telefono.value)))) {
		alert("Occorre inserire un numero di telefono corretto nel caso sia necessario ricontattarvi");
		form.telefono.focus();
		form.telefono.select();
		return false;
	}	
	if ((form.email.value == "") || ((form.email.value!="") && (!validEmail(form.email.value)))) {
		alert("Occorre inserire un numero di e-mail corretto nel caso sia necessario ricontattarvi");
		form.email.focus();
		form.email.select();
		return false;
	}	
	if (form.messaggio.value == "") {
		alert("Occorre inserire il testo del messaggio");
		form.messaggio.focus();
		form.messaggio.select();
		return false;
	}
	return true;
}

/*---*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


/*---here---*/



var images = new Array( '/immagini/top.jpg', '/immagini/top1.jpg', '/immagini/top2.jpg', '/immagini/top3.jpg', '/immagini/top4.jpg', '/immagini/top5.jpg', '/immagini/top6.jpg');

var nextImage = 1;
var imageWidth = 904;
var imageHeight = 79;
var imageTimeout = 3000;


function setOpacity(el, opacity) {

	//  Which opacity method does this browser support?

	opacity /= 100;

	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";

}

function fadeImage(el, currentOpacity) {

	currentOpacity += 5;

	if (currentOpacity > 100) {
		setOpacity(el, 100);
		var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
		prevEl.style.visibility = 'hidden';
		el.style.zIndex = 1;
		window.setTimeout(startFading, imageTimeout);
	}
	else {
		setOpacity(el, currentOpacity);
		window.setTimeout(function() { fadeImage(el, currentOpacity); }, 50);
	}

}


function startFading() {

	var el = document.getElementById('image-container').childNodes[nextImage];

	el.style.visibility = 'visible';
	el.style.zIndex = 2;
	setOpacity(el, 0);
	fadeImage(el,0);

	nextImage = (nextImage < images.length-1) ? nextImage + 1 : 0;

}


function pageLoad() {

	var el = document.getElementById('image-container');

	while (el.firstChild) { el.removeChild(el.firstChild); }

	el.style.width = imageWidth + 'px';
	el.style.height = imageHeight + 'px';

	for(var i=0; i<images.length; i++) {

		var t = document.createElement('IMG');
		t.setAttribute('src',images[i]);
		t.setAttribute('width',imageWidth);
		t.setAttribute('height',imageHeight);
		t.style.position = 'absolute';
		t.style.visibility = 'hidden';
		el.appendChild(t);

	}

	el.firstChild.style.visibility = 'visible';

	window.setTimeout(startFading, imageTimeout);

}


addLoadEvent( pageLoad );

