﻿function hide_button(){
 document.getElementById('Invia').style.display='none';
}
function agree(){
 var IE=(window.navigator.userAgent.indexOf('MSIE')>-1)?1:0; 
 if (document.getElementById('frm_agree').checked){
  document.getElementById('Invia').style.display=(IE)?'block':'block';
 }else{
  document.getElementById('Invia').style.display='none';
 }
}
function inizio(){
  document.getElementById('frm_agree').checked=false;
 }
 //////////////////////////////////////////////////////////////////
 pagina=null;
function apri (url,w,h,x,y){
if (pagina != null)
	pagina.close();
	pagina=window.open(url,null,"fullscreen=no,status=no,resizable=yes,toolbar=no,scrollbars=yes,width="+w+",height="+h+",top="+x+",left="+y);
}
///////////////////////////////////////////////////////////////////
function printpage() {
	window.print();  
}
///////////////////////////////////////////////////////////////////
function change(img){
	document.images["photo"].src = img;
}
////////////////////////////////////////////////////////////////////

var putItThere = null; 

var chasm = screen.availWidth;
var mount = screen.availHeight;


var w = 0;
var h = 0;


function deadCenter(u,w,h) {
  putItThere = window.open(u,'posB','width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 10) * .5));
}

pagina=null;
function apri (url,w,h,x,y){
if (pagina != null)
	pagina.close();
	pagina=window.open(url,null,"fullscreen=no,status=no,resizable=yes,toolbar=no,scrollbars=yes,width="+w+",height="+h+",top="+x+",left="+y);
}
//////////////////////////////////////////////////////////////////////
(function(){

	/*Use Object Detection to detect IE6*/
	var  m = document.uniqueID /*IE*/
	&& document.compatMode  /*>=IE6*/
	&& !window.XMLHttpRequest /*<=IE6*/
	&& document.execCommand ;
	
	try{
		if(!!m){
			m("BackgroundImageCache", false, true) /* = IE6 only */ 
		}
		
	}catch(oh){};
})();


function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function swap_image(object,src1,src2) {
	if (object.src==src1) {
		object.src=src2;
	} else {
		object.src=src1;
	}
}

function imageChange(imageID,imageName,imageID2,imageName2) {
document.images[imageID].src = eval(imageName + ".src");
document.images[imageID2].src = eval(imageName2 + ".src");
}

var ref;
//function openwin(url,x,y)
// {
// ref=window.open(url,'url','width='+x+',height='+y+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes,screenX=0,screenY=0,top=0,left=0');
// ref.focus();
// }
 
var win = null;
function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,'FOTO',settings);
  win.window.focus();
}

function openwin(url,x,y)
 {
   var w = x;
   var h = y;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   ref=window.open(url,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes");
 ref.focus();
 }


 //FUNZIONI PER CONTROLLO EMAIL

 var whitespace = " \t\n\r";
function isEmail (s){
	if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")){ 
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

//FUNZIONE PER ACCESSO A MYSOVENICE
function MySoveniceLogin(){
	var campo_username=document.getElementById("username");
	var campo_password=document.getElementById("password");
	if(campo_username.value==''){
		if(lingua=='en')
			alert("Email required!");
		else
			alert("Attenzione è necessario inserire il proprio indirizzo email");
		campo_username.focus();
		return 1;
	}
	if (!isEmail(campo_username.value)){
		if(lingua=='en')
			alert("Wrong email address!");
		else
			alert("Attenzione l'indirizzo email inserito non è corretto");
		campo_username.focus();
		return 1;
	}
	if (campo_password.value==''){
		if(lingua=='en')
			alert("Password required!");
		else
			alert("Attenzione è necessario inserire la propria password");
		campo_password.focus();
		return 1;
	}

	document.frm_login.action.value='#';
	document.frm_login.submit();

}


//FUNZIONE PER ISCRIZIONE A MYSOVENICE
function ConfermaIscrizione(){
	var campo_email=document.getElementById("email");
	var campo_nickname=document.getElementById("username");
	var campo_password=document.getElementById("password");
	var re_campo_password=document.getElementById("re_password");
	var campo_privacy=document.getElementById("privacy");
	if(campo_email.value==''){
		if(lingua=='en')
			alert("Email required!");
		else
			alert("Attenzione è necessario inserire un indirizzo email");
		campo_email.focus();
		return 1;
	}
	if (!isEmail(campo_email.value)){
		if(lingua=='en')
			alert("Wrong email address!");
		else
			alert("Attenzione l'indirizzo email inserito non è corretto");
		campo_email.focus();
		return 1;
	}
	if(campo_nickname.value=='' || campo_nickname.value.length<6){
		if(lingua=='en')
			alert("Nickname must be at leas 6 characters!");
		else
			alert("Attenzione è necessario inserire un nickname di almeno 6 caratteri");
		campo_nickname.focus();
		return 1;
	}
	if (campo_password.value==''){
		if(lingua=='en')
			alert("Password required!");
		else
			alert("Attenzione è necessario inserire una password");
		campo_password.focus();
		return 1;
	}else{
		if(campo_password.value.length<6){
			if(lingua=='en')
				alert("Password must be at least 6 characters!");
			else
				alert("Attenzione è necessario inserire una password di almeno 6 caratteri");
			campo_password.focus();
			return 1;
		}
	}
	if (re_campo_password.value==''){
		if(lingua=='en')
			alert("Confirm password required!");
		else
			alert("Attenzione è necessario confermare la password");
		re_campo_password.focus();
		return 1;
	}
	if (campo_password.value!==re_campo_password.value){
		if(lingua=='en')
			alert("Password and Confirm password do not match!");
		else
			alert("Attenzione la nuova password e quella di conferma non coincidono");
		re_campo_password.value="";
		re_campo_password.focus();
		return 1;
	}
	if (campo_privacy.checked!==true){
		if(lingua=='en')
			alert("You must agree with the personal data processing!");
		else
			alert("Attenzione è necessario acconsentire al trattamento dei dati personali");
		return 1;
	}
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	document.frm_iscrizione.iscrizione.value='Si';
	document.frm_iscrizione.gettone.value=rand_no;
	document.frm_iscrizione.action.value='iscrizione.php';
	document.frm_iscrizione.submit();

}


function RecuperaPassword(){
	var campo_email=document.getElementById("email_forgot_password");
	if(campo_email.value==''){
		if(lingua=='en')
			alert("Email required!");
		else
			alert("Attenzione è necessario inserire un indirizzo email");
		campo_email.focus();
		return 1;
	}
	if (!isEmail(campo_email.value)){
		if(lingua=='en')
			alert("Wrong email address!");
		else
			alert("Attenzione l'indirizzo email inserito non è corretto");
		campo_email.focus();
		return 1;
	}
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	document.frm_recupera.recupera.value='Si';
	document.frm_recupera.gettone.value=rand_no;
	document.frm_recupera.action.value='iscrizione.php';
	document.frm_recupera.submit();
}


//FUNZIONE PER MODIFICA / CANCELLAZIONE DATI PROFILO
function ModificaProfilo(){
	var campo_email=document.getElementById("email");
	var campo_nickname=document.getElementById("username");
	var campo_password=document.getElementById("password");
	var re_campo_password=document.getElementById("re_password");

	var elimina_mysovenice=document.getElementById("elimina_mysovenice");

	if(elimina_mysovenice.checked==true)
	{
		if(document.getElementById("eliminazione_confermata").value=="Si"){
			var rand_no = Math.random();
			rand_no = rand_no * 100;
			document.frm_profilo.modifica_profilo.value='Si';
			document.frm_profilo.gettone.value=rand_no;
			document.frm_profilo.action.value='profilo.php';
			document.frm_profilo.submit();
		}else{
			ApriPopupCentrato("pop_elimina_iscrizione.php","nomePopup","420","270","no");
		}
	}else{
		if(campo_email.value==''){
			if(lingua=='en')
				alert("Email required!");
			else
				alert("Attenzione è necessario inserire un indirizzo email");
			campo_email.focus();
			return 1;
		}
		if (!isEmail(campo_email.value)){
			if(lingua=='en')
				alert("Wrong email address!");
			else
				alert("Attenzione l'indirizzo email inserito non è corretto");
			campo_email.focus();
			return 1;
		}
		if(campo_nickname.value=='' || campo_nickname.value.length<6){
			if(lingua=='en')
				alert("Nickname must be at least 6 characters!");
			else
				alert("Attenzione è necessario inserire un nickname di almeno 6 caratteri");
			campo_nickname.focus();
			return 1;
		}
		if (campo_password.value.length>0){
			if(campo_password.value.length<6){
				if(lingua=='en')
					alert("Password must be at least 6 characters!");
				else
					alert("Attenzione è necessario inserire una password di almeno 6 caratteri");
				campo_password.focus();
				return 1;
			}
		}
		if(campo_password.value.length>0)
		{
			if (re_campo_password.value==''){
				if(lingua=='en')
					alert("Confrim password required!");
				else
					alert("Attenzione è necessario confermare la password");
				re_campo_password.focus();
				return 1;
			}
			if (campo_password.value!==re_campo_password.value){
				if(lingua=='en')
					alert("Password and Confirm password do not match!");
				else
					alert("Attenzione la nuova password e quella di conferma non coincidono");
				re_campo_password.value="";
				re_campo_password.focus();
				return 1;
			}
		}
		var rand_no = Math.random();
		rand_no = rand_no * 100;
		document.frm_profilo.modifica_profilo.value='Si';
		document.frm_profilo.gettone.value=rand_no;
		document.frm_profilo.action.value='profilo.php';
		document.frm_profilo.submit();
	}
}

function SalvaItinerario(){
	var campo_titolo=document.getElementById("nome_itinerario");
	if(campo_titolo.value==""){
		if(lingua=='en')
			alert("Name required!");
		else
			alert("Attenzione è necessario inserire un nome");
		campo_titolo.focus();
		return 1;	
	}
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	document.frm_itinerario.salva_itinerario.value='Si';
	document.frm_itinerario.gettone.value=rand_no;
	document.frm_itinerario.action.value='my_itinerario.php';
	document.frm_itinerario.submit();
}

function AggiornaItinerario(lang,id_percorso){
	if(lang=='')
		lang='it';

	if(id_percorso)
	{
		var campo_titolo=document.getElementById("nome_itinerario");
		if(campo_titolo.value==""){
			if(lingua=='en')
				alert("Name required!");
			else
				alert("Attenzione è necessario inserire un nome");
			campo_titolo.focus();
			return 1;	
		}
		var rand_no = Math.random();
		rand_no = rand_no * 100;
		document.frm_itinerario.gettone.value=rand_no;
		document.frm_itinerario.aggiorna_itinerario.value='Si';
		document.frm_itinerario.action.value='my_itinerario.php?lang='+lang+'&action=edit&id_percorso='+id_percorso;
		document.frm_itinerario.submit();
	}
}
var win = null;
function ApriPopupCentrato(mypage,myname,w,h,resizable){
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable='+resizable;
	win = window.open(mypage,myname,settings);
}

function OrdinaSu(id, posizione_corrente,id_percorso) 
{
	document.frm_ordina.ordina_tappa.value="Si";
	document.frm_ordina.action="scheda.php?object=percorso&id_percorso="+id_percorso;
	document.frm_ordina.sposta.value="SU";
	document.frm_ordina.id_tappa_sposta.value=id;
	document.frm_ordina.posizione_attuale.value=posizione_corrente;
	document.frm_ordina.submit();
}
function OrdinaGiu(id, posizione_corrente,id_percorso) 
{
	document.frm_ordina.ordina_tappa.value="Si";
	document.frm_ordina.action="scheda.php?object=percorso&id_percorso="+id_percorso;
	document.frm_ordina.sposta.value="GIU";
	document.frm_ordina.id_tappa_sposta.value=id;
	document.frm_ordina.posizione_attuale.value=posizione_corrente;
	document.frm_ordina.submit();
}


function CercaMyItinerari(){
	var tags=document.getElementById("tags");
	var nickname=document.getElementById("nickname");
	
	if(tags.value=='' && nickname.value==''){
		if(lingua=='en')
			alert("Fill in at least one of search field!");
		else
			alert("Attenzione è necessario compilare almeno un campo di ricerca");
		tags.focus();
		return 1;
	}
	
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	document.frm_cerca.cerca.value='Si';
	document.frm_cerca.gettone.value=rand_no;
	document.frm_cerca.action.value='itinerari_my_sovenice.php';
	document.frm_cerca.submit();
}

function EliminaMyItinerario(lang,id_percorso){
	if(lang=='')
		lang='it';
	if(lingua=='en')
		var response=confirm("Are you sure you want to procede deleting Route?")
	else
		var response=confirm("Procedere con l'eliminazione dell'itinerario?")
	if(response)
	{
		var rand_no = Math.random();
		rand_no = rand_no * 100;
		document.frm_azioni_utente.azione.value='elimina_itinerario';
		document.frm_azioni_utente.gettone.value=rand_no;
		document.frm_azioni_utente.action.value='scheda.php?lang='+lang+'&object=percorso&id_percorso='+id_percorso;
		document.frm_azioni_utente.submit();
	}
}

function InviaAmico(lang,id_percorso)
{
	if(lang=='')
		lang='it';
	
	ApriPopupCentrato("pop_invia_amico.php?lang="+lang+"&id_percorso="+id_percorso,"nomePopup","420","400","no");
}

function InviaMessaggioAmico(lang,id_percorso){
	if(lang=='')
		lang='it';

	var campo_mittente=document.getElementById("mittente");
	var campo_destinatario=document.getElementById("destinatario");
	var campo_messaggio=document.getElementById("messaggio");

	if(campo_mittente.value==''){
		if(lingua=='en')
			alert("Email required!");
		else
			alert("Attenzione è necessario inserire un indirizzo email");
		campo_mittente.focus();
		return 1;
	}
	if (!isEmail(campo_mittente.value)){
		if(lingua=='en')
			alert("Wrong email address!");
		else
			alert("Attenzione l'indirizzo email inserito non è corretto");
		campo_mittente.focus();
		return 1;
	}

	if(campo_destinatario.value==''){
		if(lingua=='en')
			alert("Email required!");
		else
			alert("Attenzione è necessario inserire un indirizzo email");
		campo_destinatario.focus();
		return 1;
	}
	if (!isEmail(campo_destinatario.value)){
		if(lingua=='en')
			alert("Wrong email address!");
		else
			alert("Attenzione l'indirizzo email inserito non è corretto");
		campo_destinatario.focus();
		return 1;
	}
	if(campo_messaggio.value=='')
	{
		if(lingua=='en')
			alert("Message required!");
		else
			alert("Attenzione è necessario inserire il messaggio");
		campo_messaggio.focus();
		return 1;
	}

	var rand_no = Math.random();
	rand_no = rand_no * 100;
	document.frm_amico.invia.value='Si';
	document.frm_amico.gettone.value=rand_no;
	document.frm_amico.action.value='pop_invia_amico.php?lang='+lang+'&id_percorso='+id_percorso;
	document.frm_amico.submit();
}

function ConfermaEliminazione(){
	var op=window.opener;
	op.document.getElementById('eliminazione_confermata').value='Si';
	op.ModificaProfilo();
	window.close();
}


//FUNZIONE PER ACCESSO A MYSOVENICE
function MySoveniceLoginPopup(){
	var campo_username=document.getElementById("username");
	var campo_password=document.getElementById("password");
	if(campo_username.value==''){
		if(lingua=='en')
			alert("Email required!");
		else
			alert("Attenzione è necessario inserire il proprio indirizzo email");
		campo_username.focus();
		return;
	}
	if (!isEmail(campo_username.value)){
		if(lingua=='en')
			alert("Wrong email address!");
		else
			alert("Attenzione l'indirizzo email inserito non è corretto");
		campo_username.focus();
		return;
	}
	if (campo_password.value==''){
		if(lingua=='en')
			alert("Password required!");
		else
			alert("Attenzione è necessario inserire la propria password");
		campo_password.focus();
		return;
	}

	document.frm_login.action.value='pop_login.php';
	document.frm_login.submit();

}