function VerifySMS(formObj) {
	var phone = formObj.cellno.value;
	var email = formObj.email.value;

	var rExp = /\D/gi;
	phone = phone.replace(rExp,'');
	formObj.cellno.value = phone;


	if (phone.length == 0 && email.length == 0) {
		alert('Inserisci il numero di cellulare e/o email');
		return false;
	}

//	var rExp = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var rExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

	if (phone.length > 0 && phone.length < 9) {
		alert('Il numero di cellulare inserito è troppo corto');
		return false;
	}
	if (phone.length > 0 &&  !(formObj.addremoveSMS[0].checked || formObj.addremoveSMS[1].checked ))	{
		alert('Seleziona iscriviti o cancellati SMS');
		return false;
	}



	if (email.length > 0) {
		if (!email.match(rExp)){
			alert('Invalid email address');
			return false;
		}
		if (!(formObj.addremoveMail[0].checked || formObj.addremoveMail[1].checked ))	{
		alert('Seleziona iscriviti o cancellati email');
			return false;
		}
	}




	return true;
}


function ButtonHoverOn(Obj,sid) {
	Obj.className = 'divmenuitemHover';
	SpanObj = document.getElementById('dot'+sid);
	SpanObj.style.visibility = 'visible';
}
function ButtonHoverOff(Obj,sid) {
	Obj.className = 'divmenuitem';
	SpanObj = document.getElementById('dot'+sid);
	SpanObj.style.visibility = 'hidden';
}


var tempimg,tempimgSrc;
var LastShowImageCaller;



var Icounter = 1;
var IdiotizerOn = true;
function Idiotize() {
	if (IdiotizerOn == true) {
		divIdiotizer.filters[0].apply();
		var R = Math.floor(Math.random()*255);
		var G = Math.floor(Math.random()*255);
		var B = Math.floor(Math.random()*255);
		var col = 'RGB('+R+','+G+','+B+')';
		var col2 = 'RGB('+Math.floor(255-R)+','+Math.floor(255-G)+','+Math.floor(255-B)+')';
		divIdiotizer.style.backgroundColor = col;
		divIdiotizer.style.color = col2;
		divIdiotizer.innerHTML = Icounter;
		divIdiotizer.filters[0].play();
		Icounter++;
		window.setTimeout('Idiotize()',1000);
	}
}


var IdiotizerHTML = '';
IdiotizerHTML += '<div id=divIdiotizer style="padding: 10px; font: bold 72px verdana; width: 100px; color: black; height: 100px; text-align:center; vertical-align:middle; filter:progid:DXImageTransform.Microsoft.RadialWipe(wipestyle=CLOCK)"></div>';
IdiotizerHTML += '<div id=div2 style="padding: 10px; font: bold 14px verdana; width: 200px;  text-align:center; vertical-align:middle;">Loading...</div>';

function ShowImage(caller,IMG) {
	if (caller == LastShowImageCaller) {
		return;
	}
	tempimgSrc = IMG;
	if (LastShowImageCaller != null) {
		LastShowImageCaller.className = 'thumbcell';
	}
	caller.className = 'Selthumbcell';
	LastShowImageCaller = caller;
	imgcell.innerHTML = '';

	tempimg = new Image();
	tempimg.src = IMG;
	if (tempimg.readyState == 'complete')	{
		SetImage();
	}
	else {
		IdiotizerOn = true;
		window.setTimeout('LaunchIdiotizer()',1000);
		tempimg.onreadystatechange = SetImage;
	}
}

function LaunchIdiotizer() {
	if (IdiotizerOn == true) {
		imgcell.innerHTML = IdiotizerHTML;
		Idiotize();
	}
}



function SetImage() {
	if (tempimg.readyState == 'complete')	{
		IdiotizerOn = false;
		Icounter = 1;
		imgcell.filters[0].apply();
		var W = tempimg.width;
		var H = tempimg.height;
		var imgW = tempimg.width;
		var imgH = tempimg.height;
		var cellW = imgcell.clientWidth - 25;
		var cellH = imgcell.clientHeight - 25;
		
		var WiRatio = imgW / cellW;
		var HiRatio = imgH / cellH;
		
		var MaxRatio = Math.max(WiRatio,HiRatio);

		if (MaxRatio > 1) {
			imgW = Math.floor(imgW / MaxRatio);
			imgH = Math.floor(imgH / MaxRatio);
		}
		imgcell.innerHTML = '<img id="bigimg" src="'+tempimgSrc+'" style="width:'+imgW+'px;height:'+imgH+'px;">';
		imgcell.innerHTML += '<br><a href="#" onclick="SatWindow(\''+tempimgSrc+'\','+W+','+H+')">Show full size ('+W+'x'+H+')</a>';
		imgcell.filters[0].play();
	}
	else {
	}
}

function SatWindow(URL,W,H) {
	var Wi = W+25;
	var He = H+66;
	if (URL != '') {
		SatWin = window.open('','SatWin','width='+Wi+',height='+He+',left=50,top=50,resizable=1,scrollbars=no,menubar=no,status=no');

		SatWin.document.open();
		SatWin.document.write('<head><title>On Stage</title><style>body{margin:0px; background:#000000} img{margin:3px;}</style></head>\n');
		SatWin.document.write('<body><center>\n');
		SatWin.document.write('<img src="'+URL+'">\n');
		SatWin.document.write('<div style="border:1px solid gray; padding:2px; width:'+W+'px;background:#FCBC84;	font: normal 12px verdana;">\n');

		rExp = /^.*\//gi;
		URL = URL.replace(rExp,'');

		SatWin.document.write('Filename: '+URL+'\n');
		SatWin.document.write('</div>\n');
		SatWin.document.write('</center></body>\n');
		SatWin.document.close();

		
		SatWin.resizeTo(Wi,He);
		SatWin.focus();
	}
}




function ChangeStyle(S) {
	document.styleSheets(3).href = '/styles/s'+S+'/colorstyle.css';
	document.cookie = 'thundercookie=' + escape('style='+S) + '; expires=Fri, 31 Dec 2010 23:59:59 GMT;';
}




var LastTransition;


//============== Page Transitions (banner) ======

var BannerIndex = 0;
var BannerDivIndex = 1;
function RotateRightBanner() {
	if (typeof(divbanner1) == 'undefined')	{
		return;
	}
	if (divbanner1.style.visibility == 'visible')	{
		if (DivRightHTML.length > 0) {
			var TargetBannerDiv = divbanner1;
			
			TargetBannerDiv.filters[0].apply();
			TargetBannerDiv.innerHTML = DivRightHTML[BannerIndex];
			if (BannerIndex < DivRightHTML.length-1) {
				BannerIndex++;
			}
			else {
				BannerIndex = 0;
			}
			TargetBannerDiv.filters[0].play();

			if (typeof(divbanner2) != 'undefined')	{
				BannerDivIndex = BannerDivIndex == 1 ? 2 : 1;
			}
		}
	}
	window.setTimeout("RotateRightBanner()", 10000);
}
//============== Page Transitions ===============

function FirstLoad() {
	divloading.style.display = 'none';
	RotateRightBanner();
	MenuTransition(null,0);
	IdiotizerOn == false;
}


function LaunchIdiotizerA() {
	return;
	if (IdiotizerOn == true) {
		divloading.innerHTML = IdiotizerHTML;
		Idiotize();
	}
}



function MenuTransition(MenuObj,ix) {
	LastTransition = ix;
	var S = new String(ix);
	var ixArray = S.split('.');
	var TargetDiv,index;

	
	if (ixArray.length > 1 || ixArray[0] == 5)	{
		TargetDiv = divmid2;
//		TargetDiv.innerHTML = '';
		divmid2.style.visibility = 'visible';
		if (typeof(divbanner1) != 'undefined')	{
			divbanner1.style.visibility = 'hidden';
		}
		if (typeof(divbanner2) != 'undefined')	{
			divbanner2.style.visibility = 'hidden';
		}
		divtop.style.visibility = 'hidden';
		divblog.style.visibility = 'hidden';
		divmid.style.visibility = 'hidden';
		index = ix;
	}
	else {
		TargetDiv = divmid;
//		TargetDiv.innerHTML = '';
		divmid2.style.visibility = 'hidden';
		if (typeof(divbanner1) != 'undefined')	{
			divbanner1.style.visibility = 'visible';
		}
		if (typeof(divbanner2) != 'undefined')	{
			divbanner2.style.visibility = 'visible';
		}
		divtop.style.visibility = 'visible';
		divblog.style.visibility = 'visible';
		divmid.style.visibility = 'visible';
		index = ixArray[0];
	}

//alert(index+' - '+typeof(Content[index]));
		if (typeof(Content) == 'undefined') {
//			alert('The site is not fully loaded yet. Please wait...');
			alert('Si prega attendere il completo caricamento del sito. Grazie.');
		}
		else {
			TargetDiv.scrollTop = 0;
			TargetDiv.filters[0].apply();
			TargetDiv.innerHTML = Content[index];
			TargetDiv.filters[0].play();
		}

}






//============== Map ===============

function HighlightOn() {
	var Caller = event.srcElement;
	var Arr = Caller.coords.split(',');


	divMapHighlight.style.left = eval(Arr[0]) + M1.offsetLeft;
	divMapHighlight.style.top = eval(Arr[1]) + M1.offsetTop;
	divMapHighlight.style.width = Arr[2]-Arr[0];
	divMapHighlight.style.height = Arr[3]-Arr[1];

//	divMapHighlight.style.border = '2px solid #F8C94A';
	divMapHighlight.style.visibility = 'visible';
//	richToolTip();
}
function HighlightOff() {
	divMapHighlight.style.visibility = 'hidden';
//	oPopup.hide();
}


//============== Tool tip ===============

function richToolTip()
{
    var lefter = event.offsetY+0;
    var topper = event.offsetX+15;
    oPopup.document.body.innerHTML = oToolTip.innerHTML; 
    oPopup.show(topper, lefter, 170, 50, M1);
}


//============== Lights ===============

var AmbientIterations = 0;
var SpotsCount = 0;

function setlights(){
	divcontainer.filters[0].clear();
	divcontainer.filters[0].addAmbient(50, 50, 50, 100)
//	setambient();
	setspotlights();
}

function setambient(){
	AmbientIterations++;
	if (AmbientIterations < 20) {
		var n = AmbientIterations * 10;
		divcontainer.filters[0].changeColor(0, n, n, n, true);

		var x = setTimeout("setambient()",0);
	}
	else {
		divcontainer.filters[0].changeColor(0, 255, 255, 255, true);
//	    var z = setTimeout("setspotlights()",1000);
	}
}


function setspotlights() {
	SpotsCount++;

	//	                           fx   fy   h    tx   ty   R    G    B    st   sp  
	//-----------------------------------------------------------------------------
	if (SpotsCount < 2) {
		divcontainer.filters[0].addcone(550, 612,  5,  650,  80, 100, 100, 100,  60,   5);
	    var spots = setTimeout("setspotlights()",1000);
	}
	else if (SpotsCount < 3) {
		divcontainer.filters[0].addcone(  0, 612,  5,   80,  20, 255, 255,   0,  20,   5);
	    var spots = setTimeout("setspotlights()",500);
	}
	else if (SpotsCount < 4) {
		divcontainer.filters[0].addcone(760, 612,  5,   80,  20, 255,   0,   0,  60,   5);
		var x = setTimeout("setambient()",0);
	}

	

}












//-------------	cycle from 0 to 3 for number of lights 
function keyhandler(){
	g_numlights = (g_numlights += 1)%4;
	setlights();
}

//-----------		move the impact points of all current cones to the mouse x,y (less the 80pixel offset for the table
function mousehandler(){
	var g_numlights = 4;
	x = (window.event.x);
	y = (window.event.y);

	divcontainer.filters[0].movelight(0,x,y,5,1);
	if( g_numlights > 0 ){
		divcontainer.filters[0].movelight(1,x,y,5,1);
		if( g_numlights > 1 ){
			divcontainer.filters[0].movelight(2,x,y,5,1);
			if( g_numlights > 2 ){
				divcontainer.filters[0].movelight(3,x,y,5,1);
			}
		}
	}
}
