// JavaScript Document
// Area pubblica


function apriCentra(larghezza, altezza, URL, proprieta) {
	xx = (screen.width - larghezza) / 2;
	yy = (screen.height - altezza) / 2;
	win = window.open (URL,'','width='+ larghezza + ',height=' + altezza + ',left=' + xx + ',top=' + yy +',' + proprieta);
	
	if (win==null || typeof(win)=="undefined") {
		alert ('Apertura della finestra popup fallita. n\ E\' necessario disattivare tutti i programmi di blocco dei pop-up.');
		return false;
	} 
};
	
function login() {
	sUrl = 'chkLogin.asp';
	var status = AjaxRequest.submit(
	document.frmInvio_dati,
	{
		'url':sUrl,
		'onLoading': function() {},
		'onError': function(req) {alert(req.responseText)},
		'onSuccess': function(req){
			sRisposta = req.responseText;

			if (sRisposta == ''){
				document.location.href= 'homepage.asp'
			}else if (sRisposta == 'NEW'){
				apriCentra(450,480,'cambiaPassword.asp','');
			}else{
				document.getElementById("error").style.display = "block";
				document.getElementById("error").innerHTML =  '<p><b>' + sRisposta + '</b></p>';
			};
		}
	}
	);
};

function getCookie(){
//Memorizzo user e psw in un cookie
var user = document.frmInvio_dati.txtUsername.value;
var psw = document.frmInvio_dati.txtPassword.value;
//var chk = document.frmInvio_dati.memorizza.checked;

	//if (document.frmLogin.memorizza.checked == true ){
		document.cookie = "log" + "=" + user + ";expires=Fri, 31 Dec 2099 23:59:59 GMT;";
		document.cookie = "psw" + "=" + psw + ";expires=Fri, 31 Dec 2099 23:59:59 GMT;"; 
		//document.cookie = "chk" + "=" + chk + ";expires=Fri, 31 Dec 2099 23:59:59 GMT;";
	/*}
	else{
		document.cookie = "log" + "=" ;
		document.cookie = "psw" + "=" ;
		document.cookie = "chk" + "=" ;
	};*/
}
