/*-------------------------------------*/
//                                    	/
// Controllo Validità CAPTCHA				/
//                                    	/
/*-------------------------------------*/
function check_captcha (captcha,captchb)
	{
		//document.write(captcha+"<br>"); 
		//document.write(captchb+"<br>");
		if (captcha == captchb)  {return true;}
		return false;
	}

	
/*-------------------------------------*/
//                                    	/
// Controllo Validità Email				/
//                                    	/
/*-------------------------------------*/
function check_mail (mail)
	{
		formacorretta = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!formacorretta.test(mail)) {return false;}
		Gettoni = mail.split("@");
		k = Gettoni.length;
		//document.write(k+"<br>");
		if (k < 2) {return false;}
		Dominio = Gettoni[k-1].split(".");
		k = Dominio.length;
		//document.write(k+"<br>");
		if (k < 2) {return false;}
		return true;
	}

/*-------------------------------------*/
//                                    	/
// Visualizzazione data e ora			/
//                                    	/
/*-------------------------------------*/	
function ShowTime1 (d, m)     
	{
		var today = new Date();
		var day = today.getDate();
		var year = today.getYear();
		var giorno = today.getDay();
		var mese = today.getMonth();
		if (year < 2000) 
		year = year + 1900; 
		var hour = today.getHours();
		if (hour < 10) hour = "0"+hour;
		var minute = today.getMinutes();
		if (minute < 10) minute = "0"+minute;
		var second = today.getSeconds();
		if (second < 10) second = "0"+second;
		var currentTimeString = d[giorno]+" "+day+" "+m[mese]+" "+year+" "+hour+":"+minute+":"+second;
		document.getElementById("clock").firstChild.nodeValue = currentTimeString;
	} 
	 
function ShowTime_IT ()     
	{
		var d = new Array("Domenica","Luned́","Martedi","Mercoledi","Giovedi","Venerdi","Sabato");
		var m = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
		ShowTime1(d, m);
	}  
	 
function ShowTime_EN ()     
	{
		var d = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		var m = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		ShowTime1(d, m);
	}

/*-------------------------------------*/
//                                    	/
// Creazione calendario					/
//                                    	/
/*-------------------------------------*/	
function Show_Calend (lingua, mesein, annoin) 
	{

	if (lingua == "IT") 
		{ 	var months=new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
			var days=new Array("D","L","M","Me","G","V","S");
		}
	if (lingua == "EN")  
		{ 	var months=new Array("January","Feburary","March","April","May","June","July","August","September","October","November","December");
			var days=new Array("Su","M","T","W","Th","F","Sa");
		}
		
	var test_it=location.search.substring(1);
	var info = test_it.split(",");
	var data_month=parseInt(info[0],10);
	var data_year=parseInt(info[1],10);
	
	var the_date= new Date();
	var the_month=the_date.getMonth();
	var the_date_number=the_date.getDate();
	var the_year=the_date.getFullYear();
	var the_day=the_date.getDay();
	
	if (mesein == 99 || annoin == 99 ) {;}
		else {
			var the_month=mesein;
			var the_year=annoin;
		} 
	
	var first_day= new Date(the_year,the_month,1);
	var first_day=first_day.getDay();
	var short_year=new String(the_year);
	var short_year=short_year.slice(2,4);
	var day_in_month=31;
	
	if (the_month == 8 || the_month == 3 || the_month == 5 || the_month == 10)
		{ var day_in_month=30;}
	if (the_month==1)
		{var day_in_month=28;}
 	var day_counter=1;
	
	document.write('<table class="Tabella_Calend" >');
	document.write("<tr>");
	document.write('<td class="MeseAnno_Calend"' +  " colspan='7'>" + months[the_month] + " " + the_year + "</td>");
	document.write("</tr><tr>");
	
	for (i=0;i<7;i++) 
		{
			document.write('<td class="GiornoSett_Calend">' +days[i] +"</td>");
		}
	document.write("</tr><tr>");
	
	for (i=0;i<(first_day);i++)
		{
			document.write('<td class="GiornoSett_Calend" >&nbsp</font></td>');
		}
	
	for (i=first_day;i<7;i++)
		{
			var two_digit_year=new String(the_year);
			var two_digit_year=two_digit_year.slice(2,4);
			var the_date_string = new String(the_month+1) + "/" + new String(day_counter) + "/" + two_digit_year ;
			if (day_counter==the_date_number)
				{
					document.write('<td class="Giorno_Calend">' + day_counter + "</td>");
					}
			if (day_counter != the_date_number)
				{
					document.write('<td class="GiornoSett_Calend">' + day_counter + "</td>");
					}		
			var day_counter=day_counter + 1;
		}
	
	document.write("</tr>");
	
	for (a=1;a<6;a++)
		{
			document.write("<tr>");
			for (b=0;b<7;b++)
				{
					if (day_counter >= day_in_month)
						{
						var b=7;
						var a=5;
						}
					if (day_counter==the_date_number)
						{
							document.write('<td class="Giorno_Calend">' + day_counter + "</td>");
						}
					if (day_counter != the_date_number)
						{
							document.write('<td class="GiornoSett_Calend">' + day_counter + "</td>");
						}	
					var day_counter=day_counter + 1;			
				}
			document.write("</tr>");	
		}
	
	document.write("</table>");
	
	}
	
/*----------------------------------------------------*/
//                                                     /
// Ajax XML Ticker (txt file source)				   /
// Author: Dynamic Drive (http://www.dynamicdrive.com) /
//                                    	               /
/*----------------------------------------------------*/	
// -------------------------------------------------------------------
// Ajax XML Ticker (txt file source)
// Author: Dynamic Drive (http://www.dynamicdrive.com)
// -------------------------------------------------------------------

////////////No need to edit beyond here//////////////

function createAjaxObj()
{
	var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest()
			if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
	}
	else if (window.ActiveXObject){ // if IE
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e){}
		}
	}
	return httprequest
}

// -------------------------------------------------------------------
// Main Ajax Ticker Object function
// ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
// -------------------------------------------------------------------

function ajax_ticker(xmlfile, divId, divClass, delay, fadeornot,language)
{
	this.xmlfile=xmlfile //Variable pointing to the local ticker xml file (txt)
	this.tickerid=divId //ID of ticker div to display information
	this.delay=delay //Delay between msg change, in miliseconds.
	this.language=language // 0 per testo in Italiano, 1 inglese
	this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
	this.pointer=0
	this.opacitystring=(typeof fadeornot!="undefined")? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : ""
	if (this.opacitystring!="") this.delay+=1000 //add 1/2 sec to account for fade effect, if enabled
	this.opacitysetting=0.2 //Opacity value when reset. Internal use.
	this.messages=[] //Arrays to hold each message of ticker
	this.ajaxobj=createAjaxObj()
	document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'">Initializing ticker...</div></div>')
	this.getXMLfile()
}

// -------------------------------------------------------------------
// getXMLfile()- Use Ajax to fetch xml file (txt)
// -------------------------------------------------------------------

ajax_ticker.prototype.getXMLfile=function()
{
	if (this.ajaxobj){
		var instanceOfTicker=this
		var url=this.xmlfile+"?bustcache="+new Date().getTime()
		this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
		this.ajaxobj.open('GET', url, true)
		this.ajaxobj.send(null)
	}
}

// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Gets contents of xml file and parse it using JavaScript DOM methods 
// -------------------------------------------------------------------

ajax_ticker.prototype.initialize=function()
{ 
	if (this.ajaxobj.readyState == 4){ //if request of file completed
		if (this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful
			this.contentdiv=document.getElementById(this.tickerid).firstChild //div of inner content that holds the messages
			var xmldata=this.ajaxobj.responseText
			this.contentdiv.style.display="none"
			this.contentdiv.innerHTML=xmldata
			if (this.contentdiv.getElementsByTagName("div").length==0){ //if no messages were found
				this.contentdiv.innerHTML="<b>Error</b> fetching remote ticker file!"
				return
				}
			var instanceOfTicker=this
			document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
			document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
			if (window.attachEvent) //Clean up loose references in IE
			window.attachEvent("onunload", function(){instanceOfTicker.contentdiv=instanceOfTicker.ajaxobj=null})
			//Cycle through XML object and store each message inside array
			for (var i=0; i<this.contentdiv.getElementsByTagName("div").length; i++){
				if (this.contentdiv.getElementsByTagName("div")[i].className==this.language)
				this.messages[this.messages.length]=this.contentdiv.getElementsByTagName("div")[i].innerHTML
				}
			this.contentdiv.innerHTML=""
			this.contentdiv.style.display="block"
			this.rotatemsg()
		}
	}
}

// -------------------------------------------------------------------
// rotatemsg()- Rotate through ticker messages and displays them
// -------------------------------------------------------------------

ajax_ticker.prototype.rotatemsg=function()
{
	var instanceOfTicker=this
	if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
	setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
	else{ //else, construct item, show and rotate it!
		this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
		this.contentdiv.innerHTML=this.messages[this.pointer]
		this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
		this.pointer=(this.pointer<this.messages.length-1)? this.pointer+1 : 0
		setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container periodically
		}
}

// -------------------------------------------------------------------
// fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
// -------------------------------------------------------------------

ajax_ticker.prototype.fadetransition=function(fadetype, timerid)
{
	var contentdiv=this.contentdiv
	if (fadetype=="reset")
	this.opacitysetting=0.2
	if (contentdiv.filters && contentdiv.filters[0]){
		if (typeof contentdiv.filters[0].opacity=="number") //IE6+
		contentdiv.filters[0].opacity=this.opacitysetting*100
		else //IE 5.5
		contentdiv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
		}
	else if (typeof contentdiv.style.MozOpacity!="undefined" && this.opacitystring!=""){
		contentdiv.style.MozOpacity=this.opacitysetting
		}
	else
	this.opacitysetting=1
	if (fadetype=="up")
	this.opacitysetting+=0.1
	if (fadetype=="up" && this.opacitysetting>=1)
	clearInterval(this[timerid])
}
