function MM_preloadImages() {
	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 Chk_Form_Info() {
var i, f, err = 0;
	n = document.mod_info;
	if (n.nome_cogn.value == "") {err = 1;}
	if (n.email.value == "") {err = 1;}
	if (n.probl.value == "") {err = 1;}
	
	if (err > 0) {
		alert("ATTENZIONE\n\nI campi contrassegnati con * sono richiesti.");
		return false;
	} else if (document.mod_info.inf_priv.checked == false) {
		alert("ATTENZIONE\n\nE\' necessario accettare l\'informativa sulla privacy.");
		return false;
	} else {
		document.mod_info.submit();
	}
}

function Chk_Form_Newsl() {
	if (document.newsl.email.value == "" || document.newsl.email.value == "indirizzo email") {
		return false;
	} else if (document.newsl.newsl_rb[0].checked == true) {
		if (confirm("INFORMATIVA PRIVACY\nGentile Signore/a,\nai sensi del D.lgs. n. 196/2003 (Codice in materia di protezione dei dati personali), che ha sostituito la legge n. 675/1996, il trattamento delle informazioni che La riguardano sara' improntato ai principi di correttezza, liceita' e trasparenza e di tutela della Sua riservatezza e dei Suoi diritti.")) {
			document.newsl.action= "./mlist.php?b=go";
		}
	} else if (document.newsl.newsl_rb[1].checked == true) {
		document.newsl.action= "./mlist.php?b=go";
	}
}

var http_request = false;

function makeRequest(url,method,datas) {
	http_request = false;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    }   else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }   catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('This browser does not support http_request, sorry.');
        return false;
    }
	http_request.open(method, url, true);
	if (datas == "a=0") {
		http_request.onreadystatechange = clearCache;
	} else {
		http_request.onreadystatechange = alertContents;
	}
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(datas);
}

function alertContents() {
	if (http_request.readyState == 1) {
		document.getElementById('rcam').src = './img/loading2.gif';
	}
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//document.getElementById('loading').style.visibility = "hidden";
			var xmldoc    = http_request.responseXML;
			var root_node = xmldoc.getElementsByTagName("root");
			var error  = root_node.item(0).getAttribute("error");
			var to   = root_node.item(0).getAttribute("to");
			var big_img = xmldoc.getElementsByTagName("bigimg");
			var testo = big_img.item(0).firstChild.data;
			if (error == 'OK') {
				document.getElementById('rcam').src = to;
				document.getElementById('a_webc').setAttribute('href',testo);
				document.getElementById('rcam').style.width = '100px';
				document.getElementById('rcam').style.height = '81px';				
			}
		} else {
			alert('There was a problem with the request.\n'+http_request.status);
		}
	}
}
function clearCache() {
	if (http_request.readyState == 1) {
	
	}
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc    = http_request.responseXML;
			var root_node = xmldoc.getElementsByTagName("root");
			var error  = root_node.item(0).getAttribute("error");
		} else {
			alert('There was a problem with the request.\n'+http_request.status);
		}
	}
}

function unloadPage() {
	makeRequest('ccache.php','POST','a=0');
}

function GetACam(num) {
	var quale = new String(num);
	makeRequest('loadcam.php','POST','load='+quale);
}
function RedirectWin(page) {
	self.location.href=page;
}
function ChangeCat(categoria,lingua) {
	var numrnd= (Math.random() * Date.parse(new Date()));
	self.location.href= './?p=foto_'+lingua+'&c='+categoria.toString().toLowerCase()+'&nrnd='+numrnd;
}

function showType(num) {
	switch (num) {
		case 1:
			document.getElementById('nomi_corsi').style.display = 'none';
			document.getElementById('privati').style.display = 'block';
		break;
		case 0:
			document.getElementById('nomi_corsi').style.display = 'none';
			document.getElementById('privati').style.display = 'none';
		break;
	}
}

function Chk_Form_Pren() {
	var i, n, err = 0;
	n = document.mod_pren.elements;
	for (i=0;i<n.length;i++) {
		var valore = new String();
		valore = n[i].value;
		if (valore == "") {
				err = 1;
		}
	}
	if (err == 1) {
		alert("ATTENZIONE\n\nRiempire tutti i campi.");
		return false;
	} else if (document.mod_info.inf_priv.checked == false) {
		alert("ATTENZIONE\n\nE\' necessario accettare l\'informativa sulla privacy.");
		return false;
	} else {
		document.mod_pren.submit();
	}
}