/****************************************************************************************
*** CALENDARIO v1.6 - 30-06-2009													  ***
****************************************************************************************/
lingua="IT";

GiornoDellaSettimana = new Array("Dom","Lun","Mar","Mer","Gio","Ven","Sab");
NomeDelMese = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");

GiornoDellaSettimanaEN = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
NomeDelMeseEN = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//--------------------------------------------------------------------------------------------
function FixYear(anno){
	if(anno<200)return anno+1900;
	else return anno;
}
//--------------------------------------------------------------------------------------------
function WeekDay(anno, mese, giorno){
	var data1=new Date(anno,mese,giorno);
	if(lingua=="IT") return GiornoDellaSettimana[data1.getDay()];
	else return GiornoDellaSettimanaEN[data1.getDay()];
}
//--------------------------------------------------------------------------------------------
function nomeMese(mese){
	if(lingua=="IT") return NomeDelMese[mese];
	else return NomeDelMeseEN[mese];
}
//--------------------------------------------------------------------------------------------

function DaysInMonth(WhichMonth, WhichYear)
{
	var DaysInMonth = 31;
	if (WhichMonth == 3 || WhichMonth == 5 || WhichMonth == 8 || WhichMonth == 10) DaysInMonth = 30;
	if (WhichMonth == 1)  {
  		if ((WhichYear % 4 == 0 && WhichYear % 100 != 0) || WhichYear % 400 == 0 || WhichYear == 0) DaysInMonth = 29;
		else DaysInMonth = 28;
	}
	return DaysInMonth;
}
//--------------------------------------------------------------------------------------------
function numMese(NomeMese)
{
		 if (NomeMese=="Gennaio") return 0;
	else if (NomeMese=="Febbraio") return 1;
	else if (NomeMese=="Marzo") return 2;
	else if (NomeMese=="Aprile") return 3;
	else if (NomeMese=="Maggio") return 4;
	else if (NomeMese=="Giugno") return 5;
	else if (NomeMese=="Luglio") return 6;
	else if (NomeMese=="Agosto") return 7;
	else if (NomeMese=="Settembre") return 8;
	else if (NomeMese=="Ottobre") return 9;
	else if (NomeMese=="Novembre") return 10;
	else if (NomeMese=="Dicembre") return 11;
	else if (NomeMese=="January") return 0;
	else if (NomeMese=="February") return 1;
	else if (NomeMese=="March") return 2;
	else if (NomeMese=="April") return 3;
	else if (NomeMese=="May") return 4;
	else if (NomeMese=="June") return 5;
	else if (NomeMese=="July") return 6;
	else if (NomeMese=="August") return 7;
	else if (NomeMese=="September") return 8;
	else if (NomeMese=="October") return 9;
	else if (NomeMese=="November") return 10;
	else if (NomeMese=="December") return 11;
}
//--------------------------------------------------------------------------------------------

function ChangeCheckinMese(){

	var now=new Date();
	if ($$('sm').options.length<5){

		$$("sm").options.length=0;
		nUltimoMese=12;
		nUltimoAnno=FixYear(now.getYear())+1;
	
		fine=nUltimoAnno*100+nUltimoMese;
		$$("em").options.length=0;
		nMese=now.getMonth();
		Anno=FixYear(now.getYear());
		
		//Fix ultimo del mese (successivo alla modifica per prenotazioni sucecssive ad aggi) del #30 giugno 2009#
		if(DaysInMonth(nMese,FixYear(now.getYear()))<(now.getDate()+1)){
			nMese++;
			if (nMese==12){
				nMese=0;
				Anno++;
			}
		}
		//----------------------------------------------------------------------------------------------------

		i=Anno*100+nMese;
		while (i<fine){
			var anOption = document.createElement("option");
			anOption.value=(nMese+1)+"."+Anno;
			anOption.text = nomeMese(nMese)+" '"+Anno.toString().substring(2);
			$$("sm").options.add(anOption);
			nMese++;
	
			if (nMese==12){
				nMese=0;
				Anno++;
			}
			
			i=Anno*100+nMese;
		}
	}

	if(!$$('sd'))return false;
	
	//Se è selezionato un giorno lo segna
	if ($$('sd').options.length>0){
		GiornoSel=$$('sd').options[$$('sd').selectedIndex].text;
		nGiornoSel=parseInt(GiornoSel.substring(GiornoSel.length-2));
	} else nGiornoSel=1;
	$$('sd').options.length=0;


	//Trova il mese e l'anno selezionato
	NomeMese=$$('sm').options[$$('sm').selectedIndex].text;
	Anno=2000+parseInt(NomeMese.substring(NomeMese.length-2,NomeMese.length),10);
	nMese=numMese(NomeMese.substring(0,NomeMese.length-4));

	//Individua il primo giorno disponibile

	dagiorno=1;
	//Se è selezionato il mese corrente setta oggi come primo gg disp
	if (parseInt(now.getMonth())==parseInt(nMese) && parseInt(FixYear(now.getYear()))==parseInt(Anno))dagiorno=now.getDate()+1;
	if(DaysInMonth(nMese,Anno)<dagiorno){
		dagiorno=1;
		nMese++;
		if (nMese==12){
			nMese=0;
			Anno++;
		}
	}
	
	if(nGiornoSel==31 && Anno==FixYear(now.getYear())+1) nGiornoSel=30;
	
	//Crea tutti i giorni

	for (i=dagiorno; i<=DaysInMonth(nMese,Anno); i++)
	{
 	    var anOption = document.createElement("option");
		anOption.value = i;
		anOption.text = WeekDay(Anno,nMese,i) +" "+i;
		if (i==nGiornoSel) {
				anOption.selected=true;
				anOption.defaultSelected=true;
		}
		$$("sd").options.add(anOption);
	}

	CaricaCheckout();
}

//--------------------------------------------------------------------------------------------

function ChangeCheckinGiorno(){

	SelNomeMese=$$('sm').options[$$('sm').selectedIndex].text;

	var now=new Date();
	if (
		$$('sd').selectedIndex==$$('sd').length-1 &&
		$$('sm').selectedIndex==$$('sm').length-1)
	{
		$$('sd').selectedIndex=$$('sd').selectedIndex-1;
	}

	//Trova checkin
	checkin=new Date(
		parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
		parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
		parseInt($$('sd').options[$$('sd').selectedIndex].value)
	);

	
	//Trova checkout
	checkout=new Date(
		parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
		parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
		parseInt($$('sd').options[$$('sd').selectedIndex].value)+1
	);

	//Carica i mesi nel checkout dal checkout alla fine
		nUltimoMese=12;
		nUltimoAnno=FixYear(now.getYear())+1;
		fine=nUltimoAnno*100+nUltimoMese;


		nMese=checkout.getMonth();
		Anno=FixYear(checkout.getYear());
		i=Anno*100+nMese;

	
		$$("em").options.length=0;
		while (i<fine){
			var anOption = document.createElement("option");
			anOption.value=(nMese+1)+"."+Anno;
			anOption.text = nomeMese(nMese)+" '"+Anno.toString().substring(2);
			$$("em").options.add(anOption);
			nMese++;
	
			if (nMese==12){
				nMese=0;
				Anno++;
			}
			
			i=Anno*100+nMese;
		}
	//Carica i giorni nel checkout dal checkout alla fine
	CaricaCheckout();
}
function ChangeCheckoutMese(){
	now=new Date();
	//Carica i giorni nel checkout dal checkout alla fine

	SelNomeMese=$$('sm').options[$$('sm').selectedIndex].text;
	checkin=new Date(
		parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
		parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
		parseInt($$('sd').options[$$('sd').selectedIndex].value)
	);
	SelNomeMese=$$('em').options[$$('em').selectedIndex].text;	
	checkout=new Date(
		parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
		parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
		parseInt($$('ed').options[$$('ed').selectedIndex].value)
	);

	//Se esiste il giorno del mese selezionato (es. 30/02 dà errore)
	if(checkout.getMonth()!==parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4)))){
		checkout=new Date(
			parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
			parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
			1
		);
	}
	nMese=checkout.getMonth();
	Anno=FixYear(checkout.getYear());
	$$("ed").options.length=0;
	inizio=1;
	if(checkout.getMonth()==checkin.getMonth())inizio=checkin.getDate()+1;
	for (i=inizio; i<=DaysInMonth(checkout.getMonth(),FixYear(checkout.getYear())); i++)
	{
 	    var anOption = document.createElement("option");
		anOption.value = i;
		anOption.text = WeekDay(Anno,nMese,i) +" "+i;
		if (i==checkout.getDate()) {
				anOption.selected=true;
				anOption.defaultSelected=true;
		}
		$$("ed").options.add(anOption);
	}
};
//---------------------------------------------------------------------------------------
function CaricaCheckout(){
	SelNomeMese=$$('sm').options[$$('sm').selectedIndex].text;

	var now=new Date();
	if (
		$$('sd').selectedIndex==$$('sd').length-1 &&
		$$('sm').selectedIndex==$$('sm').length-1)
	{
		$$('sd').selectedIndex=$$('sd').selectedIndex-1;
	}

	//Trova checkin
	checkin=new Date(
		parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
		parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
		parseInt($$('sd').options[$$('sd').selectedIndex].value)
	);


	
	//Trova prossimo checkout
	checkout=new Date(
		parseInt(SelNomeMese.substring(SelNomeMese.length-2),10)+2000,
		parseInt(numMese(SelNomeMese.substring(0,SelNomeMese.length-4))),
		parseInt($$('sd').options[$$('sd').selectedIndex].value)+1
	);

	//Carica i mesi nel checkout dal checkout alla fine
	
		nUltimoMese=12;
		nUltimoAnno=FixYear(now.getYear())+1;
		fine=nUltimoAnno*100+nUltimoMese;
		$$("em").options.length=0;
		nMese=checkout.getMonth();
		Anno=FixYear(checkout.getYear());
		i=Anno*100+nMese;
		while (i<fine){
			var anOption = document.createElement("option");
			anOption.value=(nMese+1)+"."+Anno;
			anOption.text = nomeMese(nMese)+" '"+Anno.toString().substring(2);
			$$("em").options.add(anOption);
			nMese++;
	
			if (nMese==12){
				nMese=0;
				Anno++;
			}
			
			i=Anno*100+nMese;
		}
		
	//Carica i giorni nel checkout dal checkout alla fine
	Anno=FixYear(checkout.getYear());
	nMese=checkout.getMonth();
	$$("ed").options.length=0;
	for (i=checkout.getDate(); i<=DaysInMonth(checkout.getMonth(),FixYear(checkout.getYear())); i++)
	{
 	    var anOption = document.createElement("option");
		anOption.value = i;
		anOption.text = WeekDay(Anno,nMese,i) +" "+i;
		if (i==checkout.getDate()) {
				anOption.selected=true;
				anOption.defaultSelected=true;
		}
		$$("ed").options.add(anOption);

	}
}
//################################################################################################################

function ControlloForm1(Form){
	nPosti=0;
	errore=false;
	num=0;
	
	for (i=0; i < Form.elements.length; i++) {
		ele = Form.elements[i];
		if(ele.name && ele.name.substr(0,6)=="stanza" && parseInt(ele.value)>0) nPosti+=parseInt(ele.value);
	}

	if (nPosti==0) {
		if (lingua=="IT") alert('Selezionare almeno una camera.');
		else alert('Select a room please.');
		return false;
	}
	else return true;
}

//--------------------------------------------------------------------------------------------
function trim(stringa) 
{
	while (stringa.substring(0,1) == ' ')
	{
		stringa = stringa.substring(1, stringa.length);
	}
	while (stringa.substring(stringa.length-1, stringa.length) == ' ')
	{
		stringa = stringa.substring(0,stringa.length-1);
	}
	if (stringa=="") return "0";
	return stringa;
}
//--------------------------------------------------------------------------------------------
function ControllaFormato(stringa)
{
	errore=false;
	if (stringa.length==0)errore=true;

	for (i=0;i<stringa.length;i++){
		car=stringa.substring(i,i+1);

		if (car!=="0" && car!=="1" && car!=="2" && car!=="3" && car!=="4" && car!=="5" && car!=="6" && car!="7" && car!=="8" && car!=="9"){
			errore=true;
		}
	}	
	return !errore;
}
//--------------------------------------------------------------------------------------------
function Ingrandisci(img){
	$$('ingrandimento').src=img;
	return false;
};
//--------------------------------------------------------------------------------------------
function selIn(giorno){
	var $j=giorno.split("-");

	ob=$$('sm');
	for (i=0; i<ob.length;i++) {
		if(ob.options[i].value==parseInt($j[1])+"."+$j[2]) ob.selectedIndex=i;
	}
	ChangeCheckinMese();
	ob=$$('sd');
	for (i=0; i<ob.length;i++) {
		if(ob.options[i].value==parseInt($j[0])) ob.selectedIndex=i;
	}
	CaricaCheckout();
}
//--------------------------------------------------------------------------------------------
function selOut(giorno){
	var $j=giorno.split("-");

	ob=$$('em');
	for (i=0; i<ob.length;i++) {
		if(ob.options[i].value==parseInt($j[1])+"."+$j[2]) ob.selectedIndex=i;
	}
	ChangeCheckoutMese();
	ob=$$('ed');
	for (i=0; i<ob.length;i++) {
		if(ob.options[i].value==parseInt($j[0])) ob.selectedIndex=i;
	}
}
//--------------------------------------------------------------------------------------------
function controllonum(){
	$v=window.event.keyCode;
	if(!$v || $v==0 || $v==8 || $v==9 || $v==13 || $v==27) return null;
	$k=String.fromCharCode($v);
	$charset="0123456789";
	if (($charset).indexOf($k) > -1) return true; else return false;
}
//--------------------------------------------------------------------------------------------

/*#####################################################################################
## STRINGHE																			 ##
#####################################################################################*/
function ContaChar(variabile,char){
	variabile=variabile.match('/['+char+']/g');
	if(!variabile) return 0; else return variabile.length;
}
function substr_count(haystack, needle) {
    var pos = 0, cnt = 0, offset = 0, length = 0; offset--;
    while ((offset = haystack.indexOf(needle, offset+1)) != -1) cnt++; 
    return cnt;
}
//-------------------------------------------------------------------------------------
function ContaNumeri(variabile){
	variabile=variabile.match(/[0-9]/g);
	if(!variabile) return 0; else return variabile.length;
}
//-------------------------------------------------------------------------------------
function ContaMinuscole(variabile){
	variabile=variabile.match(/[a-z]/g);
	if(!variabile) return 0; else return variabile.length;
}
//-------------------------------------------------------------------------------------
function ContaMaiuscole(variabile){
	variabile=variabile.match(/[A-Z]/g);
	if(!variabile) return 0; else return variabile.length;
}
//-------------------------------------------------------------------------------------
function trim(stringa){
	while (stringa.substring(0,1) == ' ') stringa = stringa.substring(1, stringa.length);
	while (stringa.substring(stringa.length-1, stringa.length) == ' ') stringa = stringa.substring(0,stringa.length-1);
	return stringa;
}

/*#####################################################################################
## CONTROLLI																		 ##
#####################################################################################*/
function check($nomecampo){
	var $msg="";
	for ($nomeform in forms){
		if(forms[$nomeform][$nomecampo]){
			if(forms[$nomeform][$nomecampo]["etichetta"]) $etichetta=forms[$nomeform][$nomecampo]["etichetta"]; else $etichetta="";
			if(forms[$nomeform][$nomecampo]["opzioni"]  ) $opz      =forms[$nomeform][$nomecampo]["opzioni"];   else $opz="";
			if(forms[$nomeform][$nomecampo]["min_len"]  ) $min      =parseInt(forms[$nomeform][$nomecampo]["min_len"]);   else $min=0;
			if(forms[$nomeform][$nomecampo]["max_len"]  ) $max      =parseInt(forms[$nomeform][$nomecampo]["max_len"]);   else $max=0;
			if(forms[$nomeform][$nomecampo]["charset"]  ) $charset  =forms[$nomeform][$nomecampo]["charset"];   else $charset="";

			$$($nomecampo).value=trim($$($nomecampo).value);
			if($opz=="lower") $$($nomecampo).value=$$($nomecampo).value.toLowerCase();
			if($opz=="upper") $$($nomecampo).value=$$($nomecampo).value.toUpperCase();

			$valore=$$($nomecampo).value;
			
			if(!$msg && $min>0 && $min==$max && $valore.length!==$min) $msg="Il campo "+$etichetta+" deve contenere "+$min+" caratteri."
			if(!$msg && $min>0 && $valore.length<$min) $msg="Il campo "+$etichetta+" deve contenere almeno "+$min+" caratteri.";
			if(!$msg && $max>0 && $valore.length>$max) $msg="Il campo "+$etichetta+" puo' contenere al massimo "+$max+" caratteri.";

			if(!$msg && $charset){
				$charset=$charset.replace("09","0123456789");
				$charset=$charset.replace("az","abcdefghijklmnopqrstuvwxyz");
				$charset=$charset.replace("AZ","ABCDEFGHIJKLMNOPQRSTUVWXYZ");

				for(i=0;i<$valore.length;i++){
					$k=$valore.charAt(i);
					if (($charset).indexOf($k) < 0) $msg="Il campo "+$etichetta+" contiene caratteri non consentiti. [ => "+$k+"]";
				}
			}
		}
	}
	return $msg;
};
function check_en($nomecampo){
	var $msg="";
	for ($nomeform in forms){
		if(forms[$nomeform][$nomecampo]){
			if(forms[$nomeform][$nomecampo]["etichetta"]) $etichetta=forms[$nomeform][$nomecampo]["etichetta"]; else $etichetta="";
			if(forms[$nomeform][$nomecampo]["opzioni"]  ) $opz      =forms[$nomeform][$nomecampo]["opzioni"];   else $opz="";
			if(forms[$nomeform][$nomecampo]["min_len"]  ) $min      =parseInt(forms[$nomeform][$nomecampo]["min_len"]);   else $min=0;
			if(forms[$nomeform][$nomecampo]["max_len"]  ) $max      =parseInt(forms[$nomeform][$nomecampo]["max_len"]);   else $max=0;
			if(forms[$nomeform][$nomecampo]["charset"]  ) $charset  =forms[$nomeform][$nomecampo]["charset"];   else $charset="";

			$$($nomecampo).value=trim($$($nomecampo).value);
			if($opz=="lower") $$($nomecampo).value=$$($nomecampo).value.toLowerCase();
			if($opz=="upper") $$($nomecampo).value=$$($nomecampo).value.toUpperCase();

			$valore=$$($nomecampo).value;
			
			if(!$msg && $min>0 && $min==$max && $valore.length!==$min) $msg="Field "+$etichetta+" must contain "+$min+" characters."
			if(!$msg && $min>0 && $valore.length<$min) $msg="Field "+$etichetta+" must contain at least "+$min+" characters.";
			if(!$msg && $max>0 && $valore.length>$max) $msg="Field "+$etichetta+" can contain at most "+$max+" characters.";

			if(!$msg && $charset){
				$charset=$charset.replace("09","0123456789");
				$charset=$charset.replace("az","abcdefghijklmnopqrstuvwxyz");
				$charset=$charset.replace("AZ","ABCDEFGHIJKLMNOPQRSTUVWXYZ");

				for(i=0;i<$valore.length;i++){
					$k=$valore.charAt(i);
					if (($charset).indexOf($k) < 0) $msg="Field "+$etichetta+" contains invalid characters. [ => "+$k+"]";
				}
			}
		}
	}
	return $msg;
};
//-------------------------------------------------------------------------------------
function addControlliKeys($nomeform){
	for ($input in forms[$nomeform]){
		if($$($input))$$($input).onkeypress=function(){return controllokey(this);}
		if($$($input))$$($input).onchange = function(){return controllochange(this);}
		if(forms[$nomeform][$input]['max_len'] && $$($input)) $$($input).setAttribute('maxLength', parseInt(forms[$nomeform][$input]['max_len']));
	};
};
//-------------------------------------------------------------------------------------
function controllochange($obj){
	for ($nomeform in forms){
		for ($input in forms[$nomeform]){
			if($input==$obj.name){
				if(forms[$nomeform][$input]['opzioni'])$opz=forms[$nomeform][$input]['opzioni']; else $opz="";
				if($opz=="lower") $$($input).value=$$($input).value.toLowerCase();
				if($opz=="upper") $$($input).value=$$($input).value.toUpperCase();
			}
		}
	}
}
//-------------------------------------------------------------------------------------
function controllokey($obj){
	for ($nomeform in forms){
		for ($input in forms[$nomeform]){
			if($input==$obj.name){
				if(forms[$nomeform][$input]['opzioni'])$opz=forms[$nomeform][$input]['opzioni']; else $opz="";
				if(forms[$nomeform][$input]['charset'])$charset=forms[$nomeform][$input]['charset']; else $charset="";
			}
		}
	}
	$v=window.event.keyCode;
	if(!$v || $v==0 || $v==8 || $v==9 || $v==13 || $v==27) return null;
	if($opz=="upper"){
		if ($v>=97 && $v<=122) {window.event.keyCode=$v-32; $v-=32;}
	}
	if($opz=="lower"){
		if ($v>=65 && $v<=90) {window.event.keyCode=$v+32; $v+=32;}
	}
	if(!$charset) return true;
	$k=String.fromCharCode($v);
	$charset=$charset.replace("09","0123456789");
	$charset=$charset.replace("az","abcdefghijklmnopqrstuvwxyz");
	$charset=$charset.replace("AZ","ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	if (($charset).indexOf($k) > -1) return true; else return false;
}
//-------------------------------------------------------------------------------------
function check_charset($valore,$charset){
	$charset=$charset.replace("09","0123456789");
	$charset=$charset.replace("az","abcdefghijklmnopqrstuvwxyz");
	$charset=$charset.replace("AZ","ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	for(i=0;i<$valore.length;i++){
		$k=$valore.charAt(i);
		if (($charset).indexOf($k) < 0) return false;
	}
	return true;
}
function controlla_form($nomeform){
	$errore=false;
	for ($input in forms[$nomeform]){
		if(!$errore){
			$errore=check($input);
			if($errore) $input_focus=$input;
		}
	}
	return $errore;
}
function controlla_form_en($nomeform){
	$errore=false;
	for ($input in forms[$nomeform]){
		if(!$errore){
			$errore=check_en($input);
			if($errore) $input_focus=$input;
		}
	}
	return $errore;
}
function controlla_mail(mail){
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if (!espressione.test(mail)) return false; else return true;
}
//-------------------------------------------------------------------------------------
function assegnaXMLHttpRequest() {
	var XHR = null,
	browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
	XHR = new XMLHttpRequest();
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
		if(browserUtente.indexOf("MSIE 5") < 0) XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XHR;
}
function getLocalita($prov){
	var ajax = assegnaXMLHttpRequest();
	if(ajax) {
		$$('localita').options.length=1;
		ajax.close;
		ajax.open("post", "http://www.bedandbreakfastmania.com/library/ajax.php?cmd=getlocalita&id="+$prov, true);
		ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("connection", "close");
		dati='';
		ajax.send(dati);
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4){

				var res=ajax.responseText;
				var localita=res.split("|");

				for (i in localita) {
					localitaB=localita[i].split("_");
					if(localitaB!=""){
						var newoption = document.createElement('option'); 
						newoption.innerHTML=localitaB[0];
						newoption.setAttribute("value", localitaB[1]); 
						$$('localita').appendChild(newoption); 
					}
				}
			};
		};
	};
	return false;
}
function $$(id){return document.getElementById(id);}
//-------------------------------------------------------------------------------------
function bbcode_check_error($txt){
	$bb_b1=substr_count($txt,"[b]");
	$bb_b2=substr_count($txt,"[/b]");
	$bb_i1=substr_count($txt,"[i]");
	$bb_i2=substr_count($txt,"[/i]");
	$bb_u1=substr_count($txt,"[u]");
	$bb_u2=substr_count($txt,"[/u]");
	$bb_l1=substr_count($txt,"[url");
	$bb_l2=substr_count($txt,"[/url]");
	
	if($no_a && $bb_l1>0) return "Non e' consentito inserire link.";
	
		 if($bb_b1!==$bb_b2) return "Le aperture e chiusure dei grassetti non corrispondono.";
	else if($bb_i1!==$bb_i2) return "Le aperture e chiusure dei corsivi non corrispondono.";
	else if($bb_u1!==$bb_u2) return "Le aperture e chiusure delle sottolineature non corrispondono.";
	else if($bb_l1!==$bb_l2) return "Le aperture e chiusure dei link non corrispondono.";
	else return "";
}
function euro($a){
	$a=""+$a;
	if ($a=="") return "0,00";

	$a=$a.replace(".",",");
	$PosVirgola=$a.indexOf(",");
	if ($PosVirgola>-1) $CifreDopoVirgola=$a.length-$PosVirgola;
	else $CifreDopoVirgola=0;

	if ($CifreDopoVirgola==0) $a = "" + $a + ",00";
	if ($CifreDopoVirgola==1) $a = "" + $a + "00";
	if ($CifreDopoVirgola==2) $a = "" + $a + "0";

	if($CifreDopoVirgola>3)	$a=$a.substring(0,$PosVirgola+3);
	
	return $a;
};

forms=new Array();
$input_focus=null;


