﻿
////////////////////////////////////////////// INIZIO RICAVA COORDINATE DEL MOUSE
var IE = document.all?true:false;
// if (!IE) document.captureEvents(Event.MOUSEMOVE)
if (!IE) document.addEventListener('mousemove', getMouseXY, true);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	// document.Show.MouseX.value = tempX;
	// document.Show.MouseY.value = tempY;
	return true;
}
////////////////////////////////////////////// FINE RICAVA COORDINATE DEL MOUSE

/////////////// FUNZIONE PER RIMUOVERE ELEMENTI DA UN ARRAY
Array.remove = function(array, from, to) {
  var rest = array.slice((to || from) + 1 || array.length);
  array.length = from < 0 ? array.length + from : from;
  return array.push.apply(array, rest);
};

/////////////// FUNZIONE PER CAPITALIZE
String.prototype.capitalize = function(){ //v1.0
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};

//////////////////////////////// STAMPA DI UN BLOCCO DI UNA PAGINA
function stampa(idBlock) {
	var testo = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
	testo += "<link href=\"css/stili.css\" rel=\"stylesheet\" type=\"text/css\" />"; 
	testo += "</head><body><div style=\"height:10px;\"></div><div id=\"coldx\" class=\"floatLeft\" style=\"width:745px;\">";
	testo += document.getElementById(idBlock).innerHTML;
	testo += "</div></body></html>";
	var ident_finestra = window.open("","finestra_stampa","height=700,width=800,top=5,left=5,scrollbars=yes");
	ident_finestra.document.open();
	ident_finestra.document.write(testo);
	ident_finestra.print();
	ident_finestra.document.close();
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function linkblank(src){
	MM_openBrWindow(src,'','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/* INIZIO SCRIPT PER MAPPE GOOGLE ----------------------------------------------------------- */

//<![CDATA[

var map = null;
var geocoder = null;

var coordinate = "";

/*cerca un indirizzo*/
function showAddress(address,titolo) {

	// document.getElementById('daddr').value=address;

  if (GBrowserIsCompatible()) {
	geocoder = new GClientGeocoder();
  }

  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  // alert(address + " non trovato");
		} else {
		/*zoom*/

			coordinate = point;

			map = new GMap2(document.getElementById("map"));
			
			/*mappa - satellite - ibrida */
			map.addControl(new GMapTypeControl());
			
			/*controller con barra vert*/
			// map.addControl(new GSmallMapControl());
			map.addControl(new GLargeMapControl());
			
			/*zoom box, in basso a dx*/
			map.addControl(new GOverviewMapControl(),
			
			new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(9, 9)));
			
			/*COORDINATE DI PARTENZA DELLA MAPPA*/
			map.setCenter(point, 15);
			// map.setCenter(point, 12);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			if(titolo){
				marker.openInfoWindowHtml(titolo+"&nbsp;&nbsp;&nbsp;&nbsp;");
			} else {
				marker.openInfoWindowHtml(address+"&nbsp;&nbsp;&nbsp;&nbsp;");
			}
		}
	  }
	);
  }
}

//]]>

/* FINE SCRIPT PER MAPPE GOOGLE ----------------------------------------------------------- */

/* -------------- INIZIO FUNZIONE PER GESTIRE POST E GET IN AJAX --------------------------------------------- */

function xmlhttpPost(strURL, idBlock, idFormPost, asinc) {
	loading(1, idBlock);

	/*
	asynchronous true Type of request 
	evalScripts false When set as “true”, scripts in requested url are evaluated 
	method ‘post’ Lets you decide whether to use Get or Post for the request to the server 
	contentType ‘application/x-www-form-urlencoded’ Allows you to set the content-type sent to the server 
	encoding ‘UTF-8’ Allows you to determine the encoding type information given to the server 
	parameters ’’ Allows you to attach parameters to your AJAX request. Most common: parameters:Form.serialize(this) 
	postBody ’’ Specify data to post. Something like: postBody:’thisvar=true&thatvar=Howdy’ How does this differ from parameters? 
	username ’’ 
	password ’’ 
	requestHeaders ’’ 
	onComplete ’’ Function to call on completion of request 
	onSuccess ’’ Function to call on successful completion of request 
	onFailure ’’ Function to call on failed request 
	onException ’’ Function to call on failed request (e.g. attempted cross-site request) 
	on + Status Code ’’ on404 etc. raise an event when given status code is encountered. 
	insertion None Instead of inserting the response in the existing content (possibly overwriting it) you can pass a valid Insertion object, such as Insertion.Top, Insertion.Bottom, Insertion.Before or Insertion.After. 
	*/	
	// if (idFormPost && idFormPost!="") alert (getquerystring(idFormPost));
	if(idFormPost && idFormPost!=""){
		var opt = {
			asynchronous:(asinc==0)?false:true,
			// Use POST
			method:'post',
			// Send this lovely data
			parameters:Form.serialize(idFormPost),
			// Handle successful response
			onSuccess: function(t) {
				response=t.responseText;
				loading(0);
			},
			// Handle 404
			on404: function(t) {
				alert('Error 404: location "' + t.statusText + '" was not found.');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
	} else {
		var opt = {
			asynchronous:(asinc==0)?false:true,
			// Use POST
			method:'get',
			// Send this lovely data
			postBody: getquerystring(idFormPost),
			// Handle successful response
			onSuccess: function(t) {
				response=t.responseText;
				loading(0);
			},
			// Handle 404
			on404: function(t) {
				alert('Error 404: location "' + t.statusText + '" was not found.');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
	}

	if(idBlock==""){
		var apri=new Ajax.Request(strURL, opt);
		return(response);
	} else {
		var apri=new Ajax.Updater(idBlock, strURL, opt);
		return(response);
	}

}

function getquerystring(idFormPost) {
	var qstr = "";
	var form = prendiElementoDaId(idFormPost);
	for (keyVar in form) {
		if(form[keyVar] && form[keyVar].value!=undefined){
			qstr = qstr + keyVar + '=' + escape(form[keyVar].value) + "&";  // NOTE: no '?' before querystring
		}
	}
    return qstr;
}


function confirmPost(messaggio, strURL, idBlock, idFormPost, asinc) {
	if(confirm(messaggio)){
		xmlhttpPost(strURL, idBlock, idFormPost, asinc);
	}
}

/* -------------- FINE FUNZIONE PER GESTIRE POST E GET IN AJAX --------------------------------------------- */


preUrl = "";
preBlock = "";
preFormPost = "";

var chiudiMS;

function setOpacity(idDiv,value){
	if(prendiElementoDaId(idDiv)){
		oggetto=prendiElementoDaId(idDiv);
		oggetto.style.opacity = value/10;
		oggetto.style.filter = 'alpha(opacity=' + value*10 + ')';
	}
}

function setlivelli(nomediv,stato){
	if(prendiElementoDaId(nomediv)){
		oggetto=prendiElementoDaId(nomediv);
		var statoOra = 0;
		if(oggetto.style.visibility=='visible'){
			statoOra = 1;
		}
		if(stato==1){ // && statoOra==0
			oggetto.style.visibility='visible';
		}
		if(stato==0){ // && statoOra==1
			oggetto.style.visibility='hidden';
		}
	}
}

function valId(id){
	if(prendiElementoDaId(id)){
		oggetto=prendiElementoDaId(id);
		return oggetto.value;
	} else {
		return ("err");	
	}
}


function strpos(haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
	if(!offset){
		offset=0;
	}
    var i = haystack.indexOf(needle, offset); // returns -1
    return i >= 0 ? i : false;
}

function swappaVis(idBlock, classOn, classOff){
	oggetto=prendiElementoDaId('expl_'+idBlock);
	if(oggetto){
		if(oggetto.style.display=="block"){
			oggetto.style.display = "none";
			oggetto=prendiElementoDaId('tit_'+idBlock);
			oggetto.className = 'blocco '+classOff+'';
		} else {
			oggetto.style.display = "block";
			oggetto=prendiElementoDaId('tit_'+idBlock);
			oggetto.className = 'blocco '+classOn+'';
		}
	}
}

/* ---------------------------------------------------------------------------- */
/* ---------------- INIZIO SCRIPT PER IL SITO --------------------------------- */
/* ---------------------------------------------------------------------------- */


function loading(act, idBlock){
	if(act && act==1){
		if(idBlock && idBlock!=""){
			oggetto=prendiElementoDaId(idBlock);
			if(oggetto){
				oggetto.innerHTML = '<table border="0" height="100%" cellspacing="0" cellpadding="0" style="width:100%; height:100%;"><tr><td valign="middle"><div class="alignCenter centrato"><img src="img/loading.gif" alt="LOADING" width="47" height="50" /></div></td></tr></table>';
			}
		} else {
			setlivelli("loading",1);
		}
	} else {
		setlivelli("loading",0);
	}
}

var periodicalUpd = function (id,url,sec){
	new Ajax.PeriodicalUpdater(id, url,   
		{
			method: 'get',
			frequency: sec,
			asynchronous: true,
			decay: 1
		}
	);
}

function inviaForm(idForm,url,idDest){
	oggetto=prendiElementoDaId(idDest);
	if(oggetto){
		oggetto.innerHTML=xmlhttpPost(url, '', idForm, 0);
	}
}

function posizionaDiv(idDiv,cooX,cooY){
	oggetto=prendiElementoDaId(idDiv);
	oggetto.style.marginLeft=cooX+"px";
	oggetto.style.marginTop=cooY+"px";
}

function closeTxtPop(idDiv,closeTimeOut){
	if(!(undefined===window.chiudiMS)){
		clearTimeout(chiudiMS);
	}
	chiudiMS = setTimeout("setlivelli('"+idDiv+"',0)",closeTimeOut);
}

var arrMenus=new Array();

function swappaDiv(livOn,livOff){
	setlivelli(livOn,1);
	setlivelli(livOff,0);
	if(livOff.substring(5,8)=="Off"){
		arrMenus[livOn]=setTimeout("swappaDiv('"+livOff+"','"+livOn+"');",5000);
	}
}

function modform(idCampo,valore){
	oggetto=prendiElementoDaId(idCampo);
	oggetto.value=valore;
}


function ajaxWin(strURL, idBlock, idFormPost){
	preUrl = strURL;
	preBlock = idBlock;
	preFormPost = idFormPost;
	if(idBlock!="" && prendiElementoDaId(idBlock)){
		xmlhttpPost(strURL,idBlock, idFormPost);
	} else {
		location.href=strURL;
	}
}

function promptQuest(domanda, tipo, url, target){ // tipo=aj(ajax), ht(html)
	if(confirm(domanda)){
		if(tipo=="aj"){
			ajaxWin(url,target);
		}
		if(tipo=="ht"){
			window.location.href=y;
		}
	}
}


function is_email(valore){
	indirizzo = valore;
	if (window.RegExp) {
		var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		var regnv = new RegExp(nonvalido);
		var regv = new RegExp(valido);
		if (!regnv.test(indirizzo) && regv.test(indirizzo)){
			return false;
		}
		return true;
	} else {
		if(indirizzo.indexOf("@") >= 0){
			return false;
		}
		return true;
	}
}

function randNum(){
	var data = new Date();
	data=data.getYear()+data.getMonth()+data.getDate()+data.getHours()+data.getMinutes()+data.getSeconds()+data.getMilliseconds();
	return(data);
}

function stessa_altezza(className) {
    cols = getElementsByClassName(className);
    var max = 0;
    for(var i=0; i<cols.length; i++) {
        if(cols[i].clientHeight > max) max = cols[i].clientHeight;
    }
    for(i=0; i<cols.length; i++) {
        cols[i].style.height = max + "px";
    }
    for(i=0; i<cols.length; i++) {
        if(cols[i].clientHeight > max) {
            offset = cols[i].clientHeight - max;
            cols[i].style.height = (parseInt(cols[i].style.height)) - offset + "px";
        }
    }
}

/* ---------------------------------------------------------------------------- */
/* ---------------- FINE SCRIPT PER IL SITO ----------------------------------- */
/* ---------------------------------------------------------------------------- */


/* ---------------------------------------------------------------------------- */
/* ---------------- INIZIO SCRIPT PER I FORM ---------------------------------- */
/* ---------------------------------------------------------------------------- */




/* ---------------------------------------------------------------------------- */
/* ---------------- FINE SCRIPT PER I FORM ------------------------------------ */
/* ---------------------------------------------------------------------------- */

