function utenticonnessi(){
var randomnumber=(Math.floor(Math.random()*21))+50
return randomnumber;
}
function annooggi(){
var data=new Date();
return data.getFullYear();
}
function oggi(){
var Giorni=new Array(7); 
Giorni[0]='Dom';
Giorni[1]='Lun';
Giorni[2]='Mar';
Giorni[3]='Mer';
Giorni[4]='Gio';
Giorni[5]='Ven';
Giorni[6]='Sab';
var Mesi=new Array(11); 
Mesi[0]='Gen';
Mesi[1]='Feb';
Mesi[2]='Mar';
Mesi[3]='Apr';
Mesi[4]='Mag';
Mesi[5]='Giu';
Mesi[6]='Lug';
Mesi[7]='Ago';
Mesi[8]='Set';
Mesi[9]='Ott';
Mesi[10]='Nov';
Mesi[11]='Dic';
var data=new Date();
return Giorni[data.getDay()]+", "+data.getDate()+" "+Mesi[data.getMonth()]+ " " + data.getFullYear();
}
function oggiEsteso(){
var Giorni=new Array(7); 
Giorni[0]='Dom';
Giorni[1]='Lun';
Giorni[2]='Mar';
Giorni[3]='Mer';
Giorni[4]='Gio';
Giorni[5]='Ven';
Giorni[6]='Sab';
var Mesi=new Array(11); 
Mesi[0]='Gennaio';
Mesi[1]='Febbraio';
Mesi[2]='Marzo';
Mesi[3]='Aprile';
Mesi[4]='Maggio';
Mesi[5]='Giugno';
Mesi[6]='Luglio';
Mesi[7]='Agosto';
Mesi[8]='Settembre';
Mesi[9]='Ottobre';
Mesi[10]='Novembre';
Mesi[11]='Dicembre';
var data=new Date();
//return Giorni[data.getDay()]+", "+data.getDate()+" "+Mesi[data.getMonth()]+ " " + data.getFullYear();
//return Giorni[data.getDay()]+", "+data.getDate()+" "+Mesi[data.getMonth()]+ " '" + data.getFullYear().toString().substr(2,2);
//return Giorni[data.getDay()]+" "+data.getDate()+" "+Mesi[data.getMonth()]+ " " + data.getFullYear().toString() + " " + data.getHours() + ":" + data.getMinutes();
return Giorni[data.getDay()]+" "+data.getDate()+" "+Mesi[data.getMonth()]+ " " + data.getFullYear().toString();
}

function show_trd() {
	if (document.body.innerHTML.indexOf("trdb")>=0){
		var htmlTrdb = document.getElementById('trdb').document.body.innerHTML;
			htmlTrdb = htmlTrdb.replace(/>/,">");
			htmlTrdb = htmlTrdb.replace(/</,"<");
			//document.getElementById('myFrame').document.body.innerHTML= myHTML;
			alert(htmlTrdb);
	}//else{
	//	alert("no");
	//}
}
function show_calendar(str_target, str_datetime) {
	var arr_months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",
		"Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];
	var week_days = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"];
	var n_weekstart = 1; // day week starts from (normally 0 or 1)

	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n"+
		"</head>\n"+
		"<body bgcolor=\"White\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#4682B4\">\n"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"#4682B4\"><a href=\"javascript:window.opener.show_calendar('"+
		str_target+"', '"+ dt2dtstr(dt_prev_month)+"'+document.cal.time.value);\">"+
		//str_target+"', '"+ dt2dtstr(dt_prev_month)+"');\">"+
		"<img src=\"calendarioprev.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"previous month\"></a></td>\n"+
		"	<td bgcolor=\"#4682B4\" colspan=\"5\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"
		+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
		"	<td bgcolor=\"#4682B4\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('"
		+str_target+"', '"+dt2dtstr(dt_next_month)+"'+document.cal.time.value);\">"+
		//+str_target+"', '"+dt2dtstr(dt_next_month)+"');\">"+
		"<img src=\"calendarionext.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"next month\"></a></td>\n</tr>\n"
	);

	var dt_current_day = new Date(dt_firstday);
	// print weekdays titles
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#87CEFA\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		week_days[(n_weekstart+n)%7]+"</font></td>\n";
	// print calendar table
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getDate() == dt_datetime.getDate() &&
					dt_current_day.getMonth() == dt_datetime.getMonth())
					// print current date
					str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#DBEAF5\" align=\"right\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					//".value='"+dt2dtstr(dt_current_day)+"'+document.cal.time.value; window.close();\">"+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					//".value='"+dt2dtstr(dt_current_day)+"'+document.cal.time.value; window.close();\">"+
					".value='"+dt2dtstr(dt_current_day)+"; window.close();\">"+
					"<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}
	// print calendar footer
	
	
	str_buffer +=
		"<form name=\"cal\">\n<tr><td colspan=\"7\" bgcolor=\"#87CEFA\">"+
		"<font color=\"White\" face=\"tahoma, verdana\" size=\"2\">"+
		//"Time: <input type=\"text\" name=\"time\" value=\""+dt2tmstr(dt_datetime)+
		"<input type=\"hidden\" name=\"time\" value=\""+dt2tmstr(dt_datetime)+
		"\" size=\"8\" maxlength=\"8\"></font></td></tr>\n</form>\n" +
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";
	

	var vWinCal = window.open("", "Calendar", 
		"width=200,height=250,status=no,resizable=yes,top=200,left=200");
	vWinCal.opener = self;
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (str_datetime) {
	//var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	var re_date = /^(\d+)\/(\d+)\/(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	if (!re_date.exec(str_datetime))
		return alert("Invalid Datetime format: "+ str_datetime);
	return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));
}
function dt2dtstr (dt_datetime) {
	return (new String (
			//dt_datetime.getDate()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getFullYear()+" "));
			dt_datetime.getDate()+"/"+(dt_datetime.getMonth()+1)+"/"+dt_datetime.getFullYear()+" "));
}
function dt2tmstr (dt_datetime) {
	return (new String (
			dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));
}

function isDate(str) { // anno a 4 cifre !!!
	spz = str.split("/"); 
	dat = new Date(spz[2], spz[1]-1, spz[0]); 
	if	( 
		dat.getFullYear() == parseFloat(spz[2]) &&
		dat.getMonth() == (parseFloat(spz[1])-1) &&
		dat.getDate() == parseFloat(spz[0]) 
		) {
			return dat;
	}
	return false;
}

function ctrlDataIniFin(dataIni,dataFine) { // anno a 4 cifre !!!
	var data_inizio = isDate(dataIni);
	var data_fine = isDate(dataFine);

	if ((data_fine)<(data_inizio)) {
		alert("Non è possibile selezionare la data finale antecedente la data iniziale!\n(inserire la stessa data equivale a considerare il giorno specifico)");
		return false;
	}
	return true;
}

function ctrlFrmSelReport(){
	if (document.frmSelReport.periodo.value==0){
		if ((document.frmSelReport.data1.value!="")&&(document.frmSelReport.data2.value!="")){
			return ctrlDataIniFin(document.frmSelReport.data1.value,document.frmSelReport.data2.value)
		}else{
			alert("Bisogna specificare entrambe le date di Inizio e Fine intervallo!");
			return false
		}
	}
	//if (!confirm('La richiesta sarà inviata.\nConfermi i dati inseriti?')) return false;
	return true;
}


function onLoadBody(){
	document.getElementById('meteo').style.display='none';
	loadXMLDoc('http://www.ilmeteo.it/meteo.php?citta_input=caserta');
	//getGBnn(document.body.innerHTML);
}


var xmlhttp;
function loadXMLDoc(url){
	xmlhttp=null;
	if (navigator.userAgent.indexOf("Firefox")!=-1){
		try {
	        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	        if (window.XMLHttpRequest){
	 				 xmlhttp=new XMLHttpRequest(); // code for all new browsers
					}else if (window.ActiveXObject){
	  				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE5 and IE6
					}
	    } catch (e) {
	        //alert("Permission UniversalBrowserRead denied.");
	    }
	}else{
		if (window.XMLHttpRequest){
		  xmlhttp=new XMLHttpRequest(); // code for all new browsers
		}else if (window.ActiveXObject){
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE5 and IE6
		}
	}
	if (xmlhttp!=null){
	  xmlhttp.onreadystatechange=state_Change;
	  //Async=true
	  //the script continues to run after the send() method, without waiting for a response from the server
	  //The onreadystatechange event complicates the code. But it is the safest way if you want to prevent the code from stopping if you don't get a response from the server
		//By setting the parameter to "false", your can avoid the extra onreadystatechange code. Use this if it's not important to execute the rest of the code if the request fails
	  xmlhttp.open("GET",url,true);
	  xmlhttp.send(null);
	}else{
	  //alert("Your browser does not support XMLHTTP.");
		//document.getElementById('meteo').style.display='none';
		document.getElementById('meteo').innerHTML="";
  }
}
function state_Change(){
	if (xmlhttp.readyState==4){
		// 4 = "loaded"
  	if (xmlhttp.status==200){
  		// 200 = OK
    	// ...our code here...
    		//document.getElementById('A1').innerHTML=xmlhttp.status;
	    	//document.getElementById('A2').innerHTML=xmlhttp.statusText;
	    	//alert(xmlhttp.status + "-" + xmlhttp.statusText);
	    	//alert(xmlhttp.responseText);
  	  //document.getElementById('A3').innerHTML=xmlhttp.responseText;
  	  var pagina = xmlhttp.responseText;
  	  
  	  getData(pagina);

			/*
  	  var posIni=pagina.search('<!-- day:begin -->');
  	  alert(pagina.substr(posIni,3000))
  	  var posIniLinkImage=pagina.search('<img src="');
				//pagina1=pagina.substr(posIniLinkImage+10,1000);
				pagina1=pagina.substr(posIniLinkImage,1000);
			alert(pagina1);
			//var posFinLinkImage=pagina1.search('"');
			var posFinLinkImage=pagina1.search('/>');
			alert(pagina1.substr(0,posFinLinkImage));
			//document.getElementById('meteoOggiImg').innerHTML='<img src="'+pagina1.substr(0,posFinLinkImage)+'" border="0" align="left" width="19" height="19">';
			document.getElementById('meteoOggiImg').innerHTML=pagina1.substr(0,posFinLinkImage+2);
  	  var posIniTmin=pagina1.search('#0000F0">');
			pagina1=pagina1.substr(posIniTmin+9,500);
			alert(pagina1);
			var posFinTmin=pagina1.search('<');
			alert(pagina1.substr(0,posFinTmin));
			document.getElementById('meteoOggiTmpMin').innerHTML=pagina1.substr(0,posFinTmin);
			*/
    }else{
			//alert("Problem retrieving XML data:" + xmlhttp.statusText);
			document.getElementById('meteo').innerHTML="";
			
    }
  }
}

function getArray(newHtmlSrc){
	//alert(newHtmlSrc);
	tot = new Array();
	
	srcImgIni=   newHtmlSrc.search('<img src="');
	newHtmlSrc=  newHtmlSrc.substr(srcImgIni+10,1000);
	srcImgFin=   newHtmlSrc.search('"');
	tot[tot.length]=newHtmlSrc.substr(0,srcImgFin);
	newHtmlSrc=  newHtmlSrc.substr(srcImgFin,1000);
	
	
	
	srcAltIni=   newHtmlSrc.search('alt="');
	newHtmlSrc=  newHtmlSrc.substr(srcAltIni+5,1000);
	srcAltFin=   newHtmlSrc.search('"');
	tot[tot.length]=newHtmlSrc.substr(0,srcAltFin);
	newHtmlSrc=  newHtmlSrc.substr(srcAltFin,1000);

	tMinIni=   newHtmlSrc.search('#0000F0">');
	newHtmlSrc=  newHtmlSrc.substr(tMinIni+9,1000);
	tMinFin=   newHtmlSrc.search('<');
	tot[tot.length]=newHtmlSrc.substr(0,tMinFin);
	newHtmlSrc=  newHtmlSrc.substr(tMinFin,1000);


	tMaxIni=   newHtmlSrc.search('#C00000">');
	newHtmlSrc=  newHtmlSrc.substr(tMaxIni+9,1000);
	tMaxFin=   newHtmlSrc.search('<');
	tot[tot.length]=newHtmlSrc.substr(0,tMaxFin);
	newHtmlSrc=  newHtmlSrc.substr(tMaxFin,1000);
	
return tot;

}

function getData(htmlSrc){
	tot = new Array();
	srcImg = new Array();
	altImg = new Array();
	tMin = new Array ();
	tMax = new Array ();
	
	startPos = htmlSrc.search('<!-- day:begin -->');
	htmlSrc = htmlSrc.substr(startPos,3500);


	startPos = htmlSrc.search('<!-- day:begin -->');
	finPos = htmlSrc.search('<!-- day:end -->');
	newHtmlSrc = htmlSrc.substr(startPos,finPos+16);
	htmlSrc = htmlSrc.substr(finPos+16,2500);
	tot = getArray(newHtmlSrc);
	srcImg[srcImg.length] = tot[0];
	altImg[altImg.length] = tot[1];
	tMin[tMin.length] = tot[2];
	tMax[tMax.length]=tot[3];

	startPos = htmlSrc.search('<!-- day:begin -->');
	finPos = htmlSrc.search('<!-- day:end -->');
	newHtmlSrc = htmlSrc.substr(startPos,finPos+16);
	htmlSrc = htmlSrc.substr(finPos+16,2500);
	tot = getArray(newHtmlSrc);
	srcImg[srcImg.length] = tot[0];
	altImg[altImg.length] = tot[1];
	tMin[tMin.length] = tot[2];
	tMax[tMax.length]=tot[3];
	
	startPos = htmlSrc.search('<!-- day:begin -->');
	finPos = htmlSrc.search('<!-- day:end -->');
	newHtmlSrc = htmlSrc.substr(startPos,finPos+16);
	htmlSrc = htmlSrc.substr(finPos+16,2500);
	tot = getArray(newHtmlSrc);
	srcImg[srcImg.length] = tot[0];
	altImg[altImg.length] = tot[1];
	tMin[tMin.length] = tot[2];
	tMax[tMax.length]=tot[3];


	/*
	alert (srcImg.length);
	for(i=0;i<srcImg.length;i++){
		alert (i);
		alert(srcImg[i]);
		alert(altImg[i]);
		alert(tMin[i]);
		alert(tMax[i]);
	};
	*/
	document.getElementById('meteo').style.display='block';
	document.getElementById('meteoOggiImg').innerHTML='<img src="'+srcImg[0]+'" alt="'+altImg[0]+'" border="0" align="left" width="22" height="22">';
	document.getElementById('meteoOggiTmpMin').innerHTML=tMin[0];
	document.getElementById('meteoOggiTmpMax').innerHTML=tMax[0];

	document.getElementById('meteoDomaniImg').innerHTML='<img src="'+srcImg[1]+'" alt="'+altImg[1]+'" border="0" align="left" width="22" height="22">';
	document.getElementById('meteoDomaniTmpMin').innerHTML=tMin[1];
	document.getElementById('meteoDomaniTmpMax').innerHTML=tMax[1];

	document.getElementById('meteoDDomaniImg').innerHTML='<img src="'+srcImg[2]+'" alt="'+altImg[2]+'" border="0" align="left" width="22" height="22">';
	document.getElementById('meteoDDomaniTmpMin').innerHTML=tMin[2];
	document.getElementById('meteoDDomaniTmpMax').innerHTML=tMax[2];
}

function getGBnn(htmlSrc){
	startPos = htmlSrc.search('<!--bnnG160x600Ini-->');
	finPos = htmlSrc.search('<!--bnnG160x600Fin-->');
	htmlSrc = htmlSrc.substr(startPos,finPos-startPos);
	startPos = htmlSrc.search('<IFRAME');
	finPos = htmlSrc.search('</IFRAME>');
	htmlSrc = htmlSrc.substr(startPos,finPos-startPos); //IFRAME
	alert(htmlSrc);
	startPos = htmlSrc.search('src="');
	startPos= startPos+5
	strLen=htmlSrc.length-startPos
	htmlSrc = htmlSrc.substr(startPos,strLen); 
	finPos = htmlSrc.search('"');
	htmlSrc = htmlSrc.substr(0,finPos);//src IFRAME
	alert(htmlSrc);
	loadXMLDoc2(htmlSrc.replace(/&amp;/g,"&"));
}
var xmlhttp2;
function loadXMLDoc2(url){
	xmlhttp2=null;
	if (window.XMLHttpRequest){
	  xmlhttp2=new XMLHttpRequest(); // code for all new browsers
	}else if (window.ActiveXObject){
	  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE5 and IE6
	}
	if (xmlhttp2!=null){
	  xmlhttp2.onreadystatechange=state_Change2;
	  xmlhttp2.open("GET",url,true);
	  xmlhttp2.send(null);
	}else{
	  alert("Your browser does not support XMLHTTP.");
  }
}
function state_Change2(){
	if (xmlhttp2.readyState==4){
		// 4 = "loaded"
  	if (xmlhttp2.status==200){
  		// 200 = OK
  	  var htmlSrc = xmlhttp2.responseText;

  	 alert(htmlSrc);

			startPos = htmlSrc.search('href="');
			startPos= startPos+6
			strLen=htmlSrc.length-startPos
			htmlSrc = htmlSrc.substr(startPos,strLen); 
			finPos = htmlSrc.search('"');
			htmlSrc = htmlSrc.substr(0,finPos);//link
			alert(htmlSrc);
			clickLink="http://googleads.g.doubleclick.net"+htmlSrc
			alert(clickLink);
			window.open (clickLink,"advertisement"); 

    }else{
			alert("Problem retrieving XML data:" + xmlhttp2.statusText);
    }
  }
}

function addbookmark(){
if (document.all)
window.external.AddFavorite("http://www.casertanews.it","Caserta News - Il Portale di Caserta e Provincia")
}

function doHomePage(obj){
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage('http://www.casertanews.it');
}
function GestTabs(obj,active){
    this.active = (active) ? active : 1,
    this.timeout = null,
    this.tabclass = 'tab',
    this.activeclass = 'active',
    this.getTabs = function(){
 
        var retnode = [];
        var elem = document.getElementById(obj).childNodes;     //modified for IE 5.x support
        for (var i = 0; i < elem.length; i++) {
        if (elem[i].className==this.tabclass) retnode[retnode.length]=elem[i];
        }
        return retnode;
    },
    this.links = document.getElementById(obj+'-nav').getElementsByTagName('a'),
    this.tabs = this.getTabs();
    this.show = function(number){
        for (var i = 0; i < this.tabs.length; i++) {
        this.tabs[i].style.display = ((i+1)==number) ? 'block' : 'none';
        this.links[i].className = ((i+1)==number) ? this.activeclass : '';
        }
    },
    this.rotate = function(interval){
        this.show(this.active);
        this.active++;
        if(this.active > this.tabs.length) this.active = 1;
        var self = this;
        this.timeout = setTimeout(function(){self.rotate(interval);}, interval*1000);
    },
    this.init = function(interval){
        this.show(this.active);
        var self = this; 
        for (var i = 0; i < this.links.length; i++) {
        this.links[i].customindex = i+1;
        this.links[i].onclick = function(){ if (self.timeout) clearTimeout(self.timeout); self.show(this.customindex); return false; };
        } 
        if (interval) this.rotate(interval);
    };
};
