// Scrive data in italiano
function write_data(lingua){
	var time = new Date();
	var giorno = time.getDate();
	var mese = time.getMonth()+1;
	var anno = time.getYear();
	
	var giorni = new Array('Domenica','Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato');
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var nome_giorno = giorni[time.getDay()];
	var days_name = days[time.getDay()];
	
	var mesi = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var nome_mese = mesi[time.getMonth()];
	var month_name = months[time.getMonth()];
	
	if (navigator.appName == "Netscape")
		anno = 1900 + anno;
	
	if (lingua=="ita")
		document.write(nome_giorno + " " + giorno + " " + nome_mese + " " + anno);
	else
		document.write(days_name + " " + giorno + " " + month_name + " " + anno);
}

// Apre il sito in un'altra finestra
function show_site (site_url){
	recordURL = escape (site_url);
	siteURL = window.open(site_url,'win' + Math.floor(1000*Math.random()),'menubar,toolbar,location,status,scrollbars,resizable');
}

// Apri finestra popup
function new_window(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
	if(win.window.focus){win.window.focus();}
}

// Check o uncheck di tutte le checkbox di un form
function check_all(form_name,obj_check_all) {
	my_form = eval('document.'+form_name);
	for (i=0;i<my_form.length;i++) {
		my_form.elements[i].checked = obj_check_all.checked;
	}
}

// True se nel form esiste almeno una checkbox checked
function check_is_selected(form_name) {
	my_form = eval('document.'+form_name);
	for (i=0;i<my_form.length;i++) {
		if (my_form.elements[i].checked==1)
			return true;
	}
	return false;
}

// Oscura un div
function nascondi_obj(obj_id){	
	obj=document.getElementById(obj_id);
	if (obj != null)
		obj.style.display = 'none';
}

// Visualizza un div
function visualizza_obj(obj_id){
	obj=document.getElementById(obj_id);
	if (obj != null)
		obj.style.display = 'block';
}

// Setta il bgcolor di tutte le td di un tr
function set_bg_tr(my_row, bg_color){
	
    var my_cells = null;

    // bg_color is disabled or the browser can't get the row -> exits
    if ((bg_color == '') || typeof(my_row.style) == 'undefined') {
        return false;
    }

    // Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        my_cells = my_row.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        my_cells = my_row.cells;
    }
    else {
        return false;
    }
	
	// with DOM compatible browsers except Opera that does not return valid values with "getAttribute"
	var c = null;
	var rowCellsCnt = my_cells.length;
    if (typeof(window.opera) == 'undefined' && typeof(my_cells[0].getAttribute) != 'undefined') {
        for (c = 0; c < rowCellsCnt; c++) {
			my_cells[c].setAttribute('bgcolor', bg_color, 0);
		}
    }else {
        for (c = 0; c < rowCellsCnt; c++) {
			my_cells[c].style.backgroundColor = bg_color;
		}
    }
}




// Macromedia javascript Luke
<!--
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];}
}
function validazione() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=validazione.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+='- il campo '+nm.substring(3).toUpperCase()+' deve contenere un indirizzo e-mail valido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- il campo '+nm.substring(3).toUpperCase()+' 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+='- il campo '+nm.substring(3).toUpperCase()+' deve contenere un numero tra '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- il campo '+nm.substring(3).toUpperCase()+' è obbligatorio.\n'; }
  } if (errors) alert('Sono stati individuati i seguenti errori:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function chklogin() {
	var login = document.getElementById('cl_username').value;
	var email = document.getElementById('cl_email').value;
	window.open('check_login.php?login='+login+'&email='+email,'chklogin','scrollbars=yes,width=400,height=300');
}

function cngstyle() {
	var chkusername = document.getElementById('cl_username');
	if (chkusername.value == '') { document.getElementById('cl_username').className = ''; }
	else { document.getElementById('cl_username').className = 'notchecked'; }
	var chkemail = document.getElementById('cl_email');
	if (chkemail.value == '') { document.getElementById('cl_email').className = ''; }
	else { document.getElementById('cl_email').className = 'notchecked'; }
	// legenda
	if (chkusername.value == '' && chkemail.value == '') { document.getElementById('legenda').style.display = 'none'; }
	else { document.getElementById('legenda').style.display = ''; }
}

function emuclick() {
	if (document.getElementById('cl_okprivacy').checked == false) { document.getElementById('cl_okprivacy').checked = true; }
	else { document.getElementById('cl_okprivacy').checked = false; }
	disable_submit();
}

function disable_submit() {
	if (document.getElementById('cl_okprivacy').checked == false) { document.getElementById('butsubmit').disabled = true; }
	else { document.getElementById('butsubmit').disabled = false; }
}
//-->

