var key = "BAD4@.56CEGFHIJKLVWdfTUhijXYZbacemngMNOPQRSopqrstuvz018923klwxy7";
var base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@.0123456789";

// per inserire un indirizzo email vedi http://www.dynamicobjects.com/d2r/archives/js-encrypt.html
function generateMailLink(encoded, linkText)
{
  document.write("<a hr"+"ef=\"ma"+"ilto"+":"+decode(encoded)+"\">"
+linkText+"</"+"a>");
}

function decode(str)
{
  return codec(key, base, str);
}

function codec(from, to, str)
{
  var codedResult = "";
  for (i = 0; i < str.length; i++) {
    current = str.charAt(i);
    idx = from.indexOf(current);
    nextVal = (idx == -1) ? current : to.charAt(idx);
    codedResult += nextVal;
  }
  return codedResult;
}

function clickFintPwd()
{
  document.getElementById('fintapwd').style.display='none'; 
  document.getElementById('password').style.display=''; 
  document.getElementById('password').focus();
}

function focusFintPwd()
{
 document.getElementById('fintapwd').style.display='none';
 document.getElementById('password').style.display='';
 document.getElementById('password').focus();
}

function visualizza(id){
  if (document.getElementById){
    if(document.getElementById(id).style.display == 'none'){
 //     document.getElementById(id).style.visibility = 'visible';
      document.getElementById(id).style.display = 'block';
    }else{
//      document.getElementById(id).style.visibility = 'hidden';
      document.getElementById(id).style.display = 'none';
    }
  }
}

function chekka(id)
{
	if (document.getElementById(id).checked==0)
		document.getElementById(id).checked=1;
	else		
		document.getElementById(id).checked=0;
}

function visualizzaTesto(testo)
	{
		window.status = testo;
	}
	
function openA2Usite()
	{
	   open("http://www.a2u.onlyhype.com","_blank");
	}
	
// funzione status bar scorrevole

   //messaggio Status Bar inserito nella pagina x es: 
    var scrtxt="SABATO 18 ...è gradito indossare il  N E R O !!!";
	var lentxt=scrtxt.length;
	var width=200;
	var pos=1-width;
function scrollStatusBar() 
	{
		pos++;
		var scroller="";
		if (pos==lentxt) {
		  pos=1-width;
		}
		if (pos<0) 
		{
		  for (var i=1; i<=Math.abs(pos); i++) {
		    scroller=scroller+" ";}
		  scroller=scroller+scrtxt.substring(0,width-i+1);
		}
		else {
		  scroller=scroller+scrtxt.substring(pos,width+pos);
		}
		window.status = scroller;
		setTimeout("scrollStatusBar()",60);
	}

//funzione alternatica x la scrollBar  e dichiarare nella pagina la variabile msg="testo messaggio" e 
                                     //  onload ="JSCTimeOutID = window.setTimeout('scrollStatusBar2(msg)',500)"
	var str=""
	function scrollStatusBar2(msg)
	{
	  if (str == "")
	  {
	     for (var ii = 0; ii < 900; ii += 50) 
	     {
	        str = str + "    "
	     }
	     str = str + msg
	  }
	  else
	  {
	     str = str.substring(2, str.length)
	  }
	  window.status = str
	  JSCTimeOutID = window.setTimeout('scrollStatusBar2(msg)',100)
	}



	function openWindow() 
	{
	    document.getElementById("Layer1").style.visibility = 'visible';
	    //document.getElementById("Layer2").style.visibility = 'visible';
	}

	function closeWindow() 
	{
	    document.getElementById("Layer1").style.visibility = 'hidden';
	    //document.getElementById("Layer2").style.visibility = 'hidden';
	}
	
	function GoPage(page) 
	{
	  document.location.href = page
	}
	
	function submitLogin()
	{
		if (document.Login.login.value == "")
		{
			alert("Specificare l'e-mail");
			document.Login.login.focus();
			return false;
		}

		if (document.Login.password.value == "")
		{
			alert("Specificare la password");
			document.Login.password.focus();
			return false;
		}

		document.Login.submit();
	}

function invia(tipo, titolo){
	var domaininvia='www.vivicrema.com';
	var urlinvia=document.location.href;
	var subjPrefix= tipo + " da "+domaininvia+": ";
	var bodyPrefix="Puoi trovare questo articolo all'indirizzo:\n\n";
	var bodyFooter="\n\n----------\n http://"+domaininvia+"/ : l'unico portale che offre informazioni sempre aggiornate sui locali di Crema e dintorni";
	var subj=escape(subjPrefix+titolo);
	var body=escape(bodyPrefix+urlinvia+bodyFooter);
	var popup=window.open("mailto:?subject="+subj+"&body="+body,"mail");
} 

function Reset_fields(nome_form){
	nome_form = "document."+nome_form;		
	// alert("nome_form.length:"+eval(nome_form+".length"));	
	for (i=0;i< eval(nome_form+".length");i++){
		var fild_name=eval(nome_form).elements[i].name;		
		var field_type=eval(nome_form).elements[i].type;
		//alert("Campo:"+nome_form);
		//alert("nome_form:"+fild_name+"\nTipo-->"+field_type);
		/* --- TEXT FIELD --- */
		if (field_type=="text"){
			var campo=eval(nome_form).elements[i].name;
			eval(nome_form+"."+campo+".value=\"\"");
			eval(nome_form+"."+campo+".style.backgroundColor=\"#EBEBEB\"");
		}
		if (field_type=="password"){
			var campo=eval(nome_form).elements[i].name;
			eval(nome_form+"."+campo+".value=\"\"");
			eval(nome_form+"."+campo+".style.backgroundColor=\"#EBEBEB\"");
		}
		/* --- SELECT --- */
		if (field_type=="select-one"){
			var campo=eval(nome_form).elements[i].name;
			eval(nome_form+"."+campo+".selectedIndex=0");
		}		
		/* --- CHECKBOX --- */
		if (field_type=="checkbox"){
			var campo=eval(nome_form).elements[i].name;
			eval(nome_form+"."+campo+".checked=0");
		}
		/* --- RADIO FIELD --- */
		if (field_type=="radio"){ 
			var campo=eval(nome_form).elements[i].name;
			campo_radio_lung = nome_form + "." + campo + ".length";
			
			/* -------------------------------------------------------------
			   Verifico se il campo radio button è composto da un solo campo 
			   oppure da diversi radio (con lo stesso nome)
			   ------------------------------------------------------------- */ 
			if (eval(campo_radio_lung) > 1) {
				for (j=0;j< eval(campo_radio_lung);j++){
					eval(nome_form + "." + campo + "[j].checked=0");
				}	
			} else {
				eval(nome_form + "." + campo + ".checked=0");
			}
		}
		/* --- TEXTAREA --- */
		if (field_type =="textarea"){
			var campo=eval(nome_form).elements[i].name;
			eval(nome_form+"."+campo+".value=\"\"");
			eval(nome_form+"."+campo+".style.backgroundColor=\"#EBEBEB\"");
		}
	}

	
}
