var w = 400;
var h = 250;
var l = Math.floor((screen.width-w)/2);
var t = Math.floor((screen.height-h)/2);

function apriCerca() {	
	window.open("http://www.puntolis.it/modulo.asp","Cerca", "menubar=no,width=580,height=250,toolbar=no,scrollbars=yes,left=" + l);
	//window.open("/servizi/ricerca_pdv/ricerca_popup.html","Cerca", "menubar=no,width=840,height=630,toolbar=no,scrollbars=no,");
	//window.open("/servizi/ricerca_pdv/ricerca_popup_temp.html","Cerca", "menubar=no,width=840,height=380,toolbar=no,scrollbars=no,");	
}

function apriFormRivenditore() {
	window.open("/servizi/rivenditori/modello.html","FormRivenditore", "menubar=no,width=425,height=860,toolbar=no,scrollbars=yes,left=" + l);
}


function apriPrivacyCard() {	
	window.open("/servizi/lottomaticard/privacy.html","Privacy", "menubar=no,scrollbars=1,width=700,height=630,toolbar=no");}

//SI Effetua login dalla testata
function loginSubmit() {
	if(checkUsernameTop()) {
		document.hLoginForm.submit();
	}else{
		//document.getElementById("loginForm").action.value = "/smslight/login.do?isError=true";
		//document.getElementById("loginForm").submit();
		// fixed in produzione
		location.href='/smslight/login.do?isError=true';
	}
}
//SI Effetua login dalla pagina login
function loginPageSubmit() {
	if(checkUsername()) {
		if(document.getElementById("loginForm").memorizza.checked) {
			saveCredentials();
		}
		document.getElementById("loginForm").submit();
	}else{
		//document.getElementById("loginForm").action.value = "/smslight/login.do?isError=true";
		//document.getElementById("loginForm").submit();
		// fixed in produzione
		location.href='/smslight/login.do?isError=true';
	}
}
//SI
function saveCredentials() {
	username = document.getElementById("loginForm").gkl.value;
	//password = document.getElementById("loginForm").gkp.value;

	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+6);

	document.cookie = "username=" + username + ";expires=" + expireDate.toGMTString() + ";path=/";
	document.cookie = "password=" + password + ";expires=" + expireDate.toGMTString() + ";path=/";
}

function initCredentials() {
	if (document.hLoginForm && document.cookie != "" ) {
		username = cookieVal("username");
		password = cookieVal("password");
		if(username && username != "") { 
			document.hLoginForm.gkl.value = username;
			//document.hLoginForm.gkp.value = password;
			document.hLoginForm.gkp2.style.display='none';
			document.hLoginForm.gkp.style.display = 'inline'
		}
	}
}

function cookieVal(cookieName) {
	var thisCookie = document.cookie.split("; ");

	for (var i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1];
		}
	}

	return "";
}

// SI Verifica username e valorizza gkat
function checkUsernameTop() {
	
	
	username = document.hLoginForm.gkl.value;
	password = document.hLoginForm.gkp.value;
	if(
		!username || username.length == 0 || username == 'Username'
		||
		!password || password.length == 0 || password == 'Password'
	) {
		//alert("Inserisci codice username e password");
		return false;
	}


	return true;
}

function checkUsername() {
		
	username = document.getElementById("loginForm").gkl.value;
	password = document.getElementById("loginForm").gkp.value;
	if(
		!username || username.length == 0 || username == 'Username'
		||
		!password || password.length == 0 || password == 'Password'
	) {
		//alert("Inserisci codice username e password");
		return false;
	}

	return true;
}

//Effettua logout dalla testata
function logoutSubmit(action) {
	document.hLogoutForm.submit();
}


/**Modifiche introdotte per la RIOGANIZZAZIONE**/

/*Scritto in questo modo perchè explorer non accetta costanti globali*/
function apriPdVDocumento(target) 
{
	var PDV_DOCUMENTO_SINTESI = "/servizi/lottomaticard/documenti/pdv/DocumentoSintesi.pdf";
	var PDV_FOGLIO_INFORMATIVO = "/servizi/lottomaticard/documenti/pdv/FoglioInformativo.pdf";
	var PDV_PRIVACY = "/servizi/lottomaticard/documenti/pdv/InformativaDati.pdf";
	var PDV_RECESSO = "/servizi/lottomaticard/documenti/pdv/DirittoRecesso.pdf";
	
	var selected = "";
	switch (target) 
	{
	  case 0:
		selected=PDV_DOCUMENTO_SINTESI;
	  break;
	  case 1:
		selected=PDV_FOGLIO_INFORMATIVO;
	  break;
	  case 2:
		selected=PDV_PRIVACY;
	  break;
	  case 3:
		selected=PDV_RECESSO;
	  break;
	  default:
	   alert("E' stato richiesto un documento che non esiste");
	  break;
	} 
	window.open(selected,"Documenti","menubar=0,scrollbars=0,toolbar=0");
}

function apriHomeDocumento(target) 
{
	var HOME_DOCUMENTO_SINTESI = "/servizi/lottomaticard/documenti/home/DocumentoSintesi.pdf";
	var HOME_FOGLIO_INFORMATIVO = "/servizi/lottomaticard/documenti/home/FoglioInformativo.pdf";
	var HOME_PRIVACY = "/servizi/lottomaticard/documenti/home/InformativaDati.pdf";
	var HOME_FACSIMILE = "/servizi/lottomaticard/documenti/home/ContrattoFACSIMILE.pdf";
	var HOME_RECESSO = "/servizi/lottomaticard/documenti/home/DirittoRecesso.pdf";
	
	var selected = "";
	switch (target) 
	{
	  case 0:
		selected=HOME_DOCUMENTO_SINTESI;
	  break;
	  case 1:
		selected=HOME_FOGLIO_INFORMATIVO;
	  break;
	  case 2:
		selected=HOME_PRIVACY;
	  break;
	  case 3:
		selected=HOME_FACSIMILE;
	  break;
	  case 4:
		selected=HOME_RECESSO;
	  break;
	  default:
	   alert("E' stato richiesto un documento che non esiste");
	  break;
	} 
	window.open(selected,"Documenti","menubar=0,scrollbars=0,toolbar=0");
}
