// JavaScript Document
// browser
var ie= (navigator.appVersion).indexOf('MSIE') >= 0 ? 1 : 0;
var iever= parseInt(navigator.appVersion);
var campoMancante='Compilare il campo';
var xb='';
  function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 
  } 
  function formatDate(vDate, vFormat){ 
    var vDay                      = addZero(vDate.getDate()); 
    var vMonth            = addZero(vDate.getMonth()+1); 
    var vYearLong         = addZero(vDate.getFullYear()); 
    var vYearShort        = addZero(vDate.getFullYear().toString().substring(3,4)); 
    var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
    var vHour             = addZero(vDate.getHours()); 
    var vMinute           = addZero(vDate.getMinutes()); 
    var vSecond           = addZero(vDate.getSeconds()); 
    var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
    vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
    return vDateString 
  } 
 function setSelection(theField,b){
	 
	for ( i = 0; i < theField.options.length; i++ ) {
 	 		if (theField.options[i].value==b)  theField.options[i].selected =true
 	 	} 
	  }
	   function setSelection12(theField,b){

	for ( i = 0; i < theField.options.length; i++ ) {

 	 		if (theField.options[i].text==b)  theField.options[i].selected =true
 	 	} 
	  }
function urlencode(strText) {                             
   return strText;
            var isObj;

            var trimReg;

            if( typeof(strText) == "string" ) {

                        if( strText != null ) {

                                    trimReg = /(^\s+)|(\s+$)/g;

                                    strText = strText.replace( trimReg, '');

                                    for(i=32;i<256;i++) {               

                                                strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));                                                                 

                                    }

                        }

            }          

            return strText;

}


 

var highcolor= "#feb259";
var unhighcolor= "#BDCFDF";

function hidePros(num){
	var y=0;
	for(i=0;i<document.links.length;i++)
	if(document.links[i].href.indexOf('#')!=-1)
	y=y+1;
	
if(y<30){
document.getElementById('divpros').innerHTML="";
document.getElementById('divpros1').innerHTML="";
}
}
function replaceSubstring(inputString, fromString, toString) {
// Goes through the inputString and replaces every occurrence of fromString with toString
var temp = inputString;
if (fromString == "") {
return inputString;
}
if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
while (temp.indexOf(fromString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(fromString));
var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
temp = toTheLeft + toString + toTheRight;
}
} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
var midStrings = new Array("~", "`", "_", "^", "#");
var midStringLen = 1;
var midString = "";
// Find a string that doesn't exist in the inputString to be used
// as an "inbetween" string
while (midString == "") {
for (var i=0; i < midStrings.length; i++) {
var tempMidString = "";
for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
if (fromString.indexOf(tempMidString) == -1) {
midString = tempMidString;
i = midStrings.length + 1;
}
}
} // Keep on going until we build an "inbetween" string that doesn't exist
// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
while (temp.indexOf(fromString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(fromString));
var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
temp = toTheLeft + midString + toTheRight;
}
// Next, replace the "inbetween" string with the "toString"
while (temp.indexOf(midString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(midString));
var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
temp = toTheLeft + toString + toTheRight;
}
} // Ends the check to see if the string being replaced is part of the replacement string or not
return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function



function getFieldValueex( theField, vType ) {
	//this function will return the field value (or value list) based on the element type
	
	
	theValue = ""; 
	sep = ""; 
	hits = 0;

	// testo
	if (  vType == "text" || vType == "textarea" ) return ( theField.value ); 
	
	// select
	if ( vType == "select" ) { 
 		for ( i = 0; i < theField.options.length; i++ ) {

 	 		if ( theField.options[i].selected ) theValue += theField.options[i].value 
 	 	} 
 	 	return ( theValue );
	}	
		if ( vType == "select1" ) { 
 		for ( i = 0; i < theField.options.length; i++ ) {

 	 		if ( theField.options[i].selected ) theValue += theField.options[i].text 
 	 	} 
 	 	return ( theValue );
	}	
	//checkboxes & radio buttons
	if ( vType == "checkbox"){
			if( theField.checked ) return("OK");
		 	else
		 	return("");
		 }
if( vType == "radio" ) { 
		if ( theField.value == null ) {
			//if we're here, we are validating a radio button or a nn multi-element checkbox
			for ( i = 0; i < theField.length; i++ ) { 
				if ( theField[i].checked ) { 
					hits++; 
					if ( hits > 1 ) {
						sep = "; ";
					} 
					theValue += sep + theField[i].value;  
				} 
			}
		} 
		return ( theValue );
 
	} else {
  		//if we are here, must be an ie checkbox, or nn with a one-element checkbox")
  	  	if ( navigator.appName == "Microsoft Internet Explorer" ) { 
	 		//ie. return some data so we can validate on the server; 
	 		return ("can't validate on client")
	 	}
		//nn one-element checkbox, see if its checked ...
		if (theField.checked ) { 
			return ( theField.value ); 
		} else {
			return ( "" ); 
		} 
	} 

}

function Get_Cookie(name) {
  var start = document.cookie.indexOf(name + '=');
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0,name.length)))
    return null;
  if (start == -1)
    return null;
  var end = document.cookie.indexOf(';',len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
var a;
 a=    name + '=' + escape(value) +
    ( (expires) ? ';expires=' + expires.toGMTString() : '') +
    ( (path) ? ';path=' + path : '') + 
    ( (domain) ? ';domain=' + domain : '') +
    ( (secure) ? ';secure' : '');
	  document.cookie = a;
	 var b= Get_Cookie('lurl');
	 Delete_Cookie('lurl','/');
	 if(b!=null) location=b;
		else
		location='/webapp/clienti.nsf/cli_ragsoc?OpenView&count=30';
}

function Delete_Cookie(name,path,domain) {
  if (Get_Cookie(name))
    document.cookie =
      name + '=' +
      ( (path) ? ';path=' + path : '') +
      ( (domain) ? ';domain=' + domain : '') +
      ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
function formatEuro(strVal)
{
	
	a=strVal.indexOf(".",0);
	
	if(a==-1) return strVal +",00"
	if(a==strVal.length-2)return strVal + "0"
	return strVal.substring(0,a+3);
	
}

//Costruisce un vettore di stringhe spaccando la stringa passata in base al carattere passato
function jSEplode(strVal,strChar)
{
	var a,b,c;
	c=0;
	CharArray=new Array();
	b=0;
	a=strVal.indexOf(strChar,b);
	if(a==-1)
	{ 
		CharArray[0]=strVal;
		return (CharArray);
	}
	while(a!=-1)
	{  	

	  	CharArray[c]=strVal.substring(b,a);
		b=a+1;
		a=strVal.indexOf(strChar,b);  
		c=c+1;
	}
  
	if(strVal.substring(b,strVal.length)!="")
	  	CharArray[c]=strVal.substring(b,strVal.length);
 	return CharArray;			
}






function colora(id,color) {
	if (document.all) {

    		//window.document.all[id].style.background =color;
    	}
}


// *************************************************************************
// prende il valore da un campo specifico
// *************************************************************************
function getFieldValue( theField, vType ) {
	//this function will return the field value (or value list) based on the element type
	
	
	theValue = ""; 
	sep = ""; 
	hits = 0;

	// testo
	if (  vType == "text" || vType == "textarea" ) return ( theField.value ); 
	
	// select
	if ( vType == "select" ) { 
 		for ( i = 0; i < theField.options.length; i++ ) {
 	 		if ( theField.options[i].selected ) theValue += theField.options[i].value 
 	 	} 
 	 	return ( theValue );
	}	
	
	//checkboxes & radio buttons
	if ( vType == "checkbox"){
			if( theField.checked ) return("OK");
		 	else
		 	return("");
		 }
if( vType == "radio" ) { 
		if ( theField.value == null ) {
			//if we're here, we are validating a radio button or a nn multi-element checkbox
			for ( i = 0; i < theField.length; i++ ) { 
				if ( theField[i].checked ) { 
					hits++; 
					if ( hits > 1 ) {
						sep = "; ";
					} 
					theValue += sep + theField[i].value;  
				} 
			}
		} 
		return ( theValue );
 
	} else {
  		//if we are here, must be an ie checkbox, or nn with a one-element checkbox")
  	  	if ( navigator.appName == "Microsoft Internet Explorer" ) { 
	 		//ie. return some data so we can validate on the server; 
	 		return ("can't validate on client")
	 	}
		//nn one-element checkbox, see if its checked ...
		if (theField.checked ) { 
			return ( theField.value ); 
		} else {
			return ( "" ); 
		} 
	} 

}



// *************************************************************************
// convalida dei campi
// *************************************************************************
function convalida()  {


var f= document.forms[0];
var valore;
var campo;
var tipo;

for ( j=0; j<campi.length; j++ ) {

	campo= f.elements[campi[j]]; 
	tipo= 	campitipi[j];

	valore= getFieldValue ( campo , tipo );
		if (!(tipo=="radio"  )) 
		colora(campo.name,unhighcolor) ;
		else 
		colora('id_'+ campo[0].name,unhighcolor) ;
	
		if ( valore== '' ||  valore== '-1') { 
	
		if ( tipo=="radio" || tipo=="checkbox" )  { // radio o checkbox
			campo.focus();
			colora('id_'+campo.name,highcolor);
			alert(campoMancante);
		return false;
		}
		else { 
			campo.focus();	
			colora(campo.name,highcolor);
			alert(campoMancante);
		return false;
	
}}
} // ciclo

// invia
f.submit();

}

function exconvalida1(f)  {



var valore;
var campo;
var tipo;

for ( j=0; j<campi.length; j++ ) {

	campo= f.elements[campi[j]]; 

tipo= 	campitipi[j];

	valore= getFieldValueex ( campo , tipo );

		if (!(tipo=="radio"  )) 
		colora(campo.name,unhighcolor) ;
		else 
		colora('id_'+ campo[0].name,unhighcolor) ;
	
		if ( valore== '' || valore== 'Seleziona' || valore== '-- Seleziona --') { 
	
		if ( tipo=="radio" || tipo=="checkbox" )  { // radio o checkbox
			campo.focus();
			colora('id_'+campo.name,highcolor);
			alert(campoMancante);
		return false;
		}
		else { 
			campo.focus();	
			colora(campo.name,highcolor);
			alert(campoMancante);
		return false;
	
}}
} // ciclo

// invia
f.submit();

}
function exconvalida(f)  {



var valore;
var campo;
var tipo;

for ( j=0; j<campi.length; j++ ) {

	campo= f.elements[campi[j]]; 
	tipo= 	campitipi[j];

	valore= getFieldValue ( campo , tipo );
		if (!(tipo=="radio"  )) 
		colora(campo.name,unhighcolor) ;
		else 
		colora('id_'+ campo[0].name,unhighcolor) ;
	
		if ( valore== '') { 
	
		if ( tipo=="radio" || tipo=="checkbox" )  { // radio o checkbox
			campo.focus();
			colora('id_'+campo.name,highcolor);
			alert(campoMancante);
		return false;
		}
		else { 
			campo.focus();	
			colora(campo.name,highcolor);
			alert(campoMancante);
		return false;
	
}}
} // ciclo

// invia
f.submit();

}
// *************************************************************************
// convalida dei campi
// *************************************************************************
function convalidaRichInfos()  {


var f= document.forms[0];
var valore;
var campo;
var tipo;

for ( j=0; j<campi.length; j++ ) {

	campo= f.elements[campi[j]]; 
	tipo= 	campitipi[j];
	
	valore= getFieldValue ( campo , tipo );
		if (!(tipo=="radio"  )) 
		colora(campo.name,unhighcolor) ;
		else 
		colora('id_'+ campo[0].name,unhighcolor) ;
	
		if ( valore== '') { 
	
		if ( tipo=="radio" || tipo=="checkbox" )  { // radio o checkbox
			campo.focus();
			colora('id_'+campo.name,highcolor);
			alert('Compilare il campo: '+campi[j]);
			
		


		return false;
		}
		else { 
			campo.focus();	
			colora(campo.name,highcolor);
		
		
	alert('Compilare il campo: '+campi[j]);
		return false;
	
}}
} // ciclo



// e-mail corretta?
if ( ! isEmail(f.email.value) ) { 
			alert('Il campo Email non sembra corretto ');			
		colora("email",highcolor);
		f.email.select();
		return false;
}


// invia
f.submit();

}
function IsNumeric(sText)
{
	
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


// verifica indirizzo di e-mail
// JavaScript1.2
function isEmail(string) {

	if(string.length>0)
	if(IsNumeric(string.substring(0,1)))
	return false;
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}

function set_layercontent(layerno,vall){

if(document.layers){
 //thisbrowser="NN4";
fredlayer = document.layers[layerno];
fredlayer.document.open();
fredlayer.document.write(vall);
fredlayer.document.close();
                     }
 if(document.all){
//thisbrowser="ie"
fredlayer = document.all[layerno];
fredlayer.innerHTML=vall;
                      }
if(!document.all && document.getElementById){
//thisbrowser="NN6";
fredlayer = document.getElementById(layerno);
fredlayer.innerHTML =vall;
 }
}
function get_layercontent(layerno){
var appo;
appo='';
if(document.layers){
 //thisbrowser="NN4";
fredlayer = document.layers[layerno];
fredlayer.document.open();
appo=fredlayer.document.read();
fredlayer.document.close();

                     }
 if(document.all){
//thisbrowser="ie"
fredlayer = document.all[layerno];
appo=fredlayer.innerHTML;
                      }
if(!document.all && document.getElementById){
//thisbrowser="NN6";
fredlayer = document.getElementById(layerno);
appo=fredlayer.innerHTML ;
 }

 return appo;
}


// da hostelsclub

// JavaScript Document
var langvis = false;

function ApriPopup(URL,nome,proprieta) {
  finestra = window.open(URL,nome,proprieta);
  finestra.focus();
  return false;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function lightit (obj, layr) {
	obj.style.borderBottom='1px solid #f7d6b5'; 
	obj.style.backgroundColor='#f7d6b5';
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="block";
}
function darkenit (obj, layr) {
	obj.style.borderBottom='1px solid #de2219'; 
	obj.style.backgroundColor='#f79b52';
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="none";
}
function light (obj, layr) {
	mytd = MM_findObj(obj);
	mytd.style.backgroundColor='#f7d6b5';
	mytd.style.borderBottom='1px solid #f7d6b5'; 
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="block";
}

function dark (obj, layr) {
	mytd = MM_findObj(obj);
	mytd.style.backgroundColor='#f79b52';
	mytd.style.borderBottom='1px solid #de2219'; 
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="none";
}


function show_facility (hostel, facility, total){
	for(i=0; i<total; i++) {
		layername  = "h"+hostel+"f"+i;
		mylayer = MM_findObj(layername);
		if(i== facility) {
			mylayer.style.display="block";
		} else {
			mylayer.style.display="none";
		}
	}
	return false;
}
function hide_facility (hostel, facility, total){
	mylayer = MM_findObj("h"+hostel+"f"+facility);
	mylayer.style.display="none";
	mylayer = MM_findObj("h"+hostel+"f0");
	mylayer.style.display="block";
	return false;
}

function showLayer(layer) {
	mylayer = MM_findObj(layer);
	mylayer.style.display="block";
}
function hideLayer(layer) {
	mylayer = MM_findObj(layer);
	mylayer.style.display="none";
}




function validateSearch(f, lingua,lingua1) {
	if(f.country.value == "0" || f.city.value == "0") {
			alert(lingua);
		return false;
	} else {
		return validateDate(f, lingua1);
	}
}
function validateDate (f, lingua) {
	miogiorno = f.giorno.selectedIndex;
	miomese = f.mese.selectedIndex;
	mioanno = f.anno.selectedIndex;
	mienotti = f.notti.selectedIndex;
	miecurr = f.currency.selectedIndex;
	giornocheck = parseInt(f.giorno.options[f.giorno.selectedIndex].value) ;
	mesecheck =    parseInt(f.mese.options[f.mese.selectedIndex].value) - 1;
	annocheck = parseInt( f.anno.options[f.anno.selectedIndex].value) ;
	giornimesi = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	leapyear = 2008;
	error = false;
	if(mesecheck == 2 && annocheck == leapyear) {
		if(giornocheck>29) {error =true;}
	} else {
		if(giornocheck>giornimesi[mesecheck]) {error = true;}
	}
	if(error == false) {
		date = new Date(); 
		annoadesso = date.getFullYear();
		if(annoadesso > annocheck) {
			error = true;
		} else if (annoadesso == annocheck) {
			meseadesso = date.getMonth();
			giornoadesso = date.getDate();
			if (mesecheck < meseadesso) {
				error = true;
			} else if((mesecheck == meseadesso) && (giornocheck< (giornoadesso + 1))) {
				error = true;
			}
		}
		
	}
	
	
	if(error == true) {
		alert(lingua);
		
		return false;
	} else {
		setCalCookie(miogiorno, miomese, mioanno, mienotti, miecurr);
		return true;
	}
}
function setDataCookie(f, lingua) {
	miogiorno = f.giorno.selectedIndex;
	miomese = f.mese.selectedIndex;
	mioanno = f.anno.selectedIndex;
	mienotti = f.notti.selectedIndex;
	miecurr = f.currency.selectedIndex;
	setCalCookie(miogiorno, miomese, mioanno, mienotti, miecurr);
	return true;
}
function showhide(id) {
	var a = MM_findObj(id) ;
	if(a.style.display == "none") {
		a.style.display = "block";
	} else {
		a.style.display = "none";
	}
	return false;
}
 function addToFavorites(lingua)
 {
  if (window.external)
  {
   window.external.AddFavorite(urlAddress,pageName);
  }
  else
  { 
   alert(lingua);
  }
 }

// JavaScript Document
miaData = new Date();
var anni = new Array;
for (i=0; i<3; i++) {
		anni[i] = miaData.getFullYear()+i;
}
var giorni = new Array;
function populateYears(modulo) {
	var pm_2 = document.forms[modulo];
	for (i=0; i<3; i++) {
		var cald = new Option (anni[i],anni[i]+"",false, false); 
		pm_2.anno.options[pm_2.anno.options.length] = cald;
	}
}

function populateDays(modulo) {
	var pm_2 = document.forms[modulo];
	for (i=1; i<32; i++) {
		giorni[i] = i;
		var calc = new Option (giorni[i],giorni[i]+"",false, false); 
		pm_2.giorno.options[pm_2.giorno.options.length] = calc;
	}
}


var anno = miaData.getFullYear();
var mioAnno;
for (var i=0; i< anni.length; i++) {
	if(anni[i] == anno) {
		//alert (anno + " "  + anni[i]);
		mioAnno = i;
	}
}

var giorniMesi = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var mese = miaData.getMonth();
var giorno = miaData.getDate() + 2;
if (giorno > giorniMesi[mese]) {
	giorno -= giorniMesi[mese];
	mese++;
	if (mese >11) {
		mese = 0;
		mioAnno++;
	}
}

function setData (modulo) {
	data = readCalCookie();
	if(data != false) {
		var miogiorno = data[0];
		var miomese = data[1];
		var anno = data[2];
		var notti = data[3];
		var currency = data[4];
	} else {
		var anno = mioAnno;
		var miogiorno = giorno - 1; 
		var miomese = mese;
		var notti = 2;
		var currency = 0;
	}
	var pm_2 = document.forms[modulo];
	pm_2.mese.selectedIndex = miomese;
	pm_2.giorno.selectedIndex = miogiorno;
	pm_2.anno.selectedIndex = anno;
	pm_2.notti.selectedIndex = notti;
	pm_2.currency.selectedIndex = currency;
}

function setDataCalendario (anno, mese, giorno, modulo) {
	var pm_2 = document.forms[modulo];
	pm_2.mese.selectedIndex = mese;
	pm_2.giorno.selectedIndex = giorno;
	notti = pm_2.notti.selectedIndex;
	var annoCalendario;
	for (var i=0; i< anni.length; i++) {
		if(anni[i] == anno) {
			annoCalendario = i;
		}
	}
	setCalCookie(giorno, mese, annoCalendario, notti);
	pm_2.anno.selectedIndex = annoCalendario;
}

function populateCountries() {
	
	var pm_2 = document.forms["searchleft"];
	
	if (selectedcountry!= "") {
			pm_2.country.options.length=0;
			for (var i=0; i<selection.length ; i+=3) {
				alert(selection[i])
				if (selection[i] == selectedcountry) {
					
					var cala = new Option (selection[i+1],i+2); 
					pm_2.country.options[pm_2.country.options.length] = cala;
					populateCities (i+2);
					var cala = new Option ("--- ", "0");
					pm_2.country.options[pm_2.country.options.length] = cala;
				}
			}
			if(pm_2.country.options.length==0) {
				var cala = new Option ("select a country", "0");
				pm_2.country.options[pm_2.country.options.length] = cala;
			}
			
	}
	for (i=0; i<selection.length ; i+=3) {
	
		var cale = new Option (selection[i+1],i+2); 
		pm_2.country.options[pm_2.country.options.length] = cale;
	
	} 
}
function setLoc(a,b,c) {
var f=document.forms[0];
	for (i=0; i<f.country.options.length ; i++)
	if(f.country.options[i].text==c) {
			
	location='searchhostels?city='+a+'&country='+f.country.options[i].value+'&lng='+b;
	
	}
}
function doSerchBanner(a,b)
	{
	
	for (i=0; i<selection.length ; i+=3){
		
	for (y=0; y<selection[i+2].length ; y+=3)
	if(a==selection[i+2][y]){

	setLoc(a,b,selection[i+1]);
	return;
	  
	  }
	
	 }
	
	}
	
	function AdjustCountry(cx)
	{
		
	var f=document.forms[0];
	for (i=0; i<selection.length ; i+=3){
	for (y=0; y<selection[i+2].length ; y+=3)
	if(cx==selection[i+2][y]){
		for (v=0; v<f.country.options.length ; v++)
	if(f.country.options[v].text==selection[i+1]){
	
	return f.country.options[v].value;
	  }
	  }
	 }
	}
	
	function getSelIndex(cx)
	{

	var f=document.forms[0];
	for (i=0; i<selection.length ; i+=3){
	for (y=0; y<selection[i+2].length ; y+=3){
		
	if(cx==selection[i+2][y]){
		
		for (v=0; v<f.country.options.length ; v++)
	if(f.country.options[v].text==selection[i+1]){
		
	return v;
	  }
	  }
	 }
	}
	}
	
	
function bookTo(j) {
location='selectrooms?str='+j;
}
function populateCities(j) {
	var pm_2 = document.forms["searchleft"];
	
	if (j!="0") {
		
		pm_2.city.options.length = 0;
		/*if (selectedcity != "") {
			var calf = new Option (city_name, selectedcity);
			pm_2.city.options[pm_2.city.options.length] = calf;
			var calg = new Option ("--- ", "0");
			pm_2.city.options[pm_2.city.options.length] = calg;
			selectedcity="";
		}*/
		for (var k = 0; k<selection[j].length; k+=3) {
			
			var calh = new Option (selection[j][k+1],selection[j][k+0]);
			pm_2.city.options[pm_2.city.options.length] = calh;
			
		}
	}
	
}

function setCalCookie(giorno, mese, anno, notti, currency) {
	mycookie = giorno+"|"+mese+"|"+anno+"|"+notti+"|"+currency;
	document.cookie="dataCal="+mycookie;
	
}
function readCalCookie() {
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("dataCal");
	if(pos!= -1) {
		var start = pos +8;
		var end = allcookies.indexOf(";", start);
		if(end == -1) end = allcookies.length;
		var value = allcookies.substring(start,end);
		var data = value.split('|');
		return data;
	} else {
		return false;
	}
}
function upDateField() {
	var f=document.forms[0];
	day=f.giorno.selectedIndex +1;
	mon=f.mese.selectedIndex +1;
	if(f.anno.selectedIndex ==0) year='2005';
	if(f.anno.selectedIndex ==1)year = '2006';
	if(f.anno.selectedIndex ==2)year = '2007';
	document.forms[0].f_date_c.value=day+"-"+mon+"-"+year;
	}
	function setlng(a){
		var p= location.href;
		if(p.indexOf('lng')==-1){
		if(p.indexOf('?')!=-1)location=location.href+"&lng="+a
		else
		location=location.href+"?lng="+a
		}
		else{
		location=p.substring(0,p.indexOf('lng')+4)+a+p.substring(p.indexOf('lng')+6,p.length)
		}}
		
		function checkFields(){
if(document.forms['login'].username.value==''){
alert('Campo email necessario');
document.forms['login'].username.focus();
return false;
 }
 if(document.forms['login'].password.value==''){
alert('Campo password necessario');
document.forms['login'].password.focus();
return false; 
 }
 //document.forms[0].submit();
 }
				function checkFields1(a){
					
if(document.forms[a].username.value==''){
alert('Campo email necessario');
document.forms[a].username.focus();
return false;
 }
 if(document.forms[a].password.value==''){
alert('Campo password necessario');
document.forms[a].password.focus();
return false; 
 }
 //document.forms[0].submit();
 }
 		
function showEvent(a){
	location='showevent.do?ide='+a
	}
function showEvent1(a){
	location='schedaintermedia.do?type=1&ide='+a
	}
	function cancelRichInfo(a){
	location='showevent?ide='+a
	}
	function RInfo(a){
	location='richinfo?ide='+a
	}
	function gotocat(a){
		location='searchevent.do?cat='+a
	}
	function aziendaIscrizione(){
		location='iscrizioneazienda'
	}
	     function okGetEmail(){
	  campi= new Array(    'email');
     campitipi= new Array( 'text');
	exconvalida(document.forms['sendmail']);

 }
 
 
  function  okAzienda_cc(){
			
	  campi= new Array(  'nome', 'indirizzo','citta','cap', 'stato',              'settore');
    campitipi= new Array( 'text', 'text',   'text' , 'text', 'select1',	 'select1',  	 'select1',  	 'select1');
	

	 if(getFieldValue(document.forms['addazienda'].stato,'select')=='Italia' ){
document.forms['addazienda'].regione.value=    getFieldValueex(document.forms['addazienda'].id_regione,'select1')
document.forms['addazienda'].provincia.value=    getFieldValueex(document.forms['addazienda'].id_provincia,'select1')

 }

exconvalida1(document.forms['addazienda']);

 }
 
 
 
 
	     function  okAzienda(){
			
	  campi= new Array(  'email', 'password','connome','concognome' , 'nome','settore','contel','indirizzo','citta','cap', 'stato',          'conruolo','cono');
    campitipi= new Array( 'text', 'text',      'text' ,   'text',     'text', 'select1',   'text ','text' ,'text','text' ,
	'select1'       ,'select1'   ,'select1'     ,'select1','select1');

	if(getFieldValue(document.forms['addazienda'].a1,'radio')=='' || getFieldValue(document.forms['addazienda'].a2,'radio')=='' ){
alert('Per poter procedere è necessario accettare  le clausole');
return;
}

if(getFieldValue(document.forms['addazienda'].a1,'radio')=='0' || getFieldValue(document.forms['addazienda'].a2,'radio')=='0'){
alert('Per poter procedere è necessario accettare  le clausole');
return;
 }

 if(getFieldValue(document.forms['addazienda'].stato,'select')=='Italia' && getFieldValueex(document.forms['addazienda'].id_regione,'select1')=='Seleziona'){
alert('Campo regione obbligatorio');
document.forms['addazienda'].id_regione.focus();
return;
 }

if(getFieldValue(document.forms['addazienda'].stato,'select')=='Italia' && getFieldValueex(document.forms['addazienda'].id_provincia,'select1')=='Seleziona'){
alert('Campo provincia obbligatorio');
document.forms['addazienda'].id_provincia.focus();
return;
 }

	 if(getFieldValue(document.forms['addazienda'].stato,'select')=='Italia' ){
document.forms['addazienda'].regione.value=    getFieldValueex(document.forms['addazienda'].id_regione,'select1')
document.forms['addazienda'].provincia.value=    getFieldValueex(document.forms['addazienda'].id_provincia,'select1')

 }

exconvalida1(document.forms['addazienda']);

 }
	function gotocat1(a){
		location='searchevent.do?cat1='+a
	}
	function setdivvis(a){

		if(getFieldValue(document.forms['addrel'].elements['a'+a],'select')=='20')
document.getElementById('dalt'+a).style.display="block";
else
		document.getElementById('dalt'+a).style.display="none";
	}
	function setdivvis1(a){

		if(getFieldValue(document.forms['addrel'].elements['at'+a],'select')=='20')
document.getElementById('daltt'+a).style.display="block";
else
		document.getElementById('daltt'+a).style.display="none";
	}

	function gotocat2(a){
		location='searchevent.do?cat2='+a
	}
	function gotocat3(a){
		location='searchevent.do?cat3='+a
	}
	    function  okRichiesta(){
	  campi= new Array(     'email'  );
     campitipi= new Array( 'text'    );
	 convalida();

 }
   function  okUser(){
	  campi= new Array(     'email','password','nome','cognome','provincia', 'comune', 'cap', 'cono' );
     campitipi= new Array( 'text', 'text'   , 'text'    ,  'text' ,'select'   ,  'text'    ,   'text' ,  'select'   );
  
     if(!checkMail(document.forms['adduser'].email) ){

return;
}
if(getFieldValue(document.forms['adduser'].f1,'radio')=='' ){
alert('Per poter procedere è necessario selezionare un area di interesse');
return;
}
if(getFieldValue(document.forms['adduser'].a1,'radio')=='' || getFieldValue(document.forms['adduser'].a2,'radio')==''){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
}
if(getFieldValue(document.forms['adduser'].a1,'radio')=='0' || getFieldValue(document.forms['adduser'].a2,'radio')=='0'){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
 }
	exconvalida1(document.forms['adduser']);

 }


   function  okUser_mod(){
	  campi= new Array(     'email','password','nome','cognome', 'cono' );
     campitipi= new Array( 'text', 'text'   ,    'text'    ,   'text' ,  'select'   );


	exconvalida1(document.forms['adduser']);

 }
function  cancelUser_mod(a)
 {
	location='searchevent.do?cat='+a;
 }

 function  cancelUser()
 {
	location='showmacro.do?macro=hs_homeusers';
 }
 function  cancelAzienda()
 {
	location='index';
 }
 function  cancelEnte()
 {
	location='index';
 }
 function  cancelRel()
 {
	location='index';
 }
 function  cancelOspita()
 {
	location='index';
 }
     function   doAdvSearch(){
		if(getFieldValueex(document.forms[1].id_regione,'select')=='-1'
		&& getFieldValueex(document.forms[1].id_provincia,'select')=='-1'
		&& getFieldValueex(document.forms[1].categoria,'select')=='-1')return alert('E\' necessario selezionare almeno un campo di ricerca');
	else
	document.forms[1].submit();
	

 }
     function  okRel(){
if(!isInteger(document.forms['addrel'].anno.value)){
alert('Anno non valido');
document.forms['addrel'].anno.focus();
return;
 }
if(!isInteger(document.forms['addrel'].cap.value)){
alert('CAP non valido');
document.forms['addrel'].cap.focus();
return;
 }
if(getFieldValueex(document.forms['addrel'].ne,'checkbox')=='' && 
getFieldValueex(document.forms['addrel'].no,'checkbox')=='' && 
getFieldValueex(document.forms['addrel'].c,'checkbox')=='' && 
getFieldValueex(document.forms['addrel'].s,'checkbox')=='' && 
getFieldValueex(document.forms['addrel'].i,'checkbox')=='' ){
alert('Selezionare una disponibilità a movimenti');
document.forms['addrel'].no.focus();
return;
 }
  campi= new Array(       'nome',  'cognome','password','email','indirizzo',   'comune',    'cap',   'provincia',     'telefono', 'giorni' , 'mesi'    ,'anno' , 'provincianascita','comunenascita', 'statonascita' ,'titolostudio',   'cono');
     campitipi= new Array( 'text','text',    'text',    'text'   , 'text',     'text',    'text',     'select',        'text',    'select',  'select', 'text',    'select1' ,       'text',             'select1' ,     'select1',       'select1' );

var T=''
for(i=1;i<14;i++){
T=T+getFieldValueex(document.forms['addrel'].elements['f'+i],'checkbox')
}
if(T==''){
alert('Inserire almeno un area tematica di interesse')
document.forms['addrel'].f1.focus()
return
}

exconvalida1(document.forms['addrel']);
 }

	 
	 function okOspita(){
	  campi= new Array(   'email', 'password','connome','concognome' , 'nome',    'contel','indirizzo','citta','cap'  ,    'stato');
    campitipi= new Array( 'text', 'text',      'text' ,   'text',     'text' ,   'text ','text' ,    'text','text'   ,    'select1'  );
	
	    if(!checkMail(document.forms['addospita'].email) ){

return;
}
	
	if(getFieldValue(document.forms['addospita'].a1,'radio')=='' || getFieldValue(document.forms['addospita'].a2,'radio')=='' ){
alert('Per poter procedere è necessario accettare  le clausole');
return;
}
if(getFieldValue(document.forms['addospita'].a1,'radio')=='0' || getFieldValue(document.forms['addospita'].a2,'radio')=='0'){
alert('Per poter procedere è necessario accettare  le clausole');
return;
 }

	 if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia' ){
document.forms['addospita'].regione.value=    getFieldValueex(document.forms['addospita'].id_regione,'select1')
document.forms['addospita'].provincia.value=    getFieldValueex(document.forms['addospita'].id_provincia,'select1')
 }
 if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia' && getFieldValueex(document.forms['addospita'].id_regione,'select1')=='Seleziona'){
alert('Campo regione obbligatorio');
document.forms['addospita'].id_regione.focus();
return;
 }

if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia' && getFieldValueex(document.forms['addospita'].id_provincia,'select1')=='Seleziona'){
alert('Campo provincia obbligatorio');
document.forms['addospita'].id_provincia.focus();
return;
 }
	 exconvalida1(document.forms['addospita']);
 }
	 
	 
	 
	  
	 function okOspita_scheda(){
	  campi= new Array(   'email', 'password','connome','concognome' ,    'contel');
    campitipi= new Array( 'text', 'text',      'text' ,   'text',       'text ' );
	
		    if(!checkMail(document.forms['addospita'].email) ){

return;
}

	 exconvalida1(document.forms['addospita']);
 }
	 
	 
	 
	  function okOspita_cc(){
	  campi= new Array(   'nome', 'indirizzo','citta','cap' , 'stato',      'id_regione','nsale','captot','capsalap' );
    campitipi= new Array( 'text', 'text',      'text' , 'text',     'select' ,   'select ','select' ,    'select','select' );
document.forms['addospita'].regione.value=    getFieldValueex(document.forms['addospita'].id_regione,'select1')
document.forms['addospita'].provincia.value=    getFieldValueex(document.forms['addospita'].id_provincia,'select1')
	 exconvalida1(document.forms['addospita']);
 }
	 
	 
  function okOspita_cc1(){
	  campi= new Array(   'email', 'password','connome','concognome' , 'nome',    'contel','indirizzo','citta','cap'  ,    'stato');
    campitipi= new Array( 'text', 'text',      'text' ,   'text',     'text' ,   'text ','text' ,    'text','text'   ,    'select1'  );
	
	    if(!checkMail(document.forms['addospita'].email) ){

return;
}
	

	 if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia' ){
document.forms['addospita'].regione.value=    getFieldValueex(document.forms['addospita'].id_regione,'select1')
document.forms['addospita'].provincia.value=    getFieldValueex(document.forms['addospita'].id_provincia,'select1')
 }
 if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia' && getFieldValueex(document.forms['addospita'].id_regione,'select1')=='Seleziona'){
alert('Campo regione obbligatorio');
document.forms['addospita'].id_regione.focus();
return;
 }

if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia' && getFieldValueex(document.forms['addospita'].id_provincia,'select1')=='Seleziona'){
alert('Campo provincia obbligatorio');
document.forms['addospita'].id_provincia.focus();
return;
 }
	 exconvalida1(document.forms['addospita']);
 }
	 
  function  addEvent(a){
		location='addevent.do?type='+a;
 }

function convalidaevents(f)  {


var valore;
var campo;
var tipo;

for ( j=0; j<campi.length; j++ ) {

	campo= f.elements[campi[j]]; 
	tipo= 	campitipi[j];

	valore= getFieldValue ( campo , tipo );
		if (!(tipo=="radio"  )) 
		colora(campo.name,unhighcolor) ;
		else 
		colora('id_'+ campo[0].name,unhighcolor) ;
	
		if ( valore== '' ||  valore== '-1') { 
	
		if ( tipo=="radio" || tipo=="checkbox" )  { // radio o checkbox
			campo.focus();
			colora('id_'+campo.name,highcolor);
			alert(campoMancante);
		return false;
		}
		else { 
			campo.focus();	
			colora(campo.name,highcolor);
			alert(campoMancante);
		return false;
	
}}
} // ciclo

  if(f.type.value=='2'){

if(getFieldValue(f.stage,'select')!=-1)
	if(getFieldValue(f.stage,'select')==0){
			f.durata_stage.value='';
		 } else{
			if(f.durata_stage.value==''){
	alert('Inserire la durata dello stage')
f.durata_stage.focus();
return false;
 }
}} 
// invia
f.submit();

}

   function  okEventi(){
	  var f =document.forms['addeventi'];
	  	  if(f.type.value=='1'){
	 campi= new Array(    'titolo','finalita','id_regione','id_provincia','categoria','tev','data_inizio' );
     campitipi= new Array( 'text',  'text',     'select',    'select',      'select', 'select',   'text' );
	 }
	  if(f.type.value=='2'){
	 campi= new Array(    'titolo','finalita','id_regione','id_provincia','categoria','tev','data_inizio','data_fine' );
     campitipi= new Array( 'text',   'text' ,   'select',    'select',      'select',  'select',  'text',     'text'  );
	 }

	 convalidaevents(document.forms['addeventi']);

 }


  function  okSegnala(){
if(checkMail(document.forms['sendamico'].email))
	if(checkMail(document.forms['sendamico'].a_email))
if(getFieldValue(document.forms['sendamico'].acc,'radio')==1){
	  campi= new Array(    'nome','email','a_nome','a_email');
     campitipi= new Array( 'text','text', 'text'   , 'text');
      exconvalida1(document.forms['sendamico']);
	 }else
alert('Per utilizzare il servizio di segnalazione è necessario dare il consenso per il trattamento dei dati personali')
 }
       function  setdivrg(){

if(getFieldValue(document.forms['addente'].stato,'select')=='Italia'){
document.getElementById('div_pr').style.display ='block';
document.getElementById('div_rg').style.display ='block';
document.getElementById('div_pr1').style.display ='block';
document.getElementById('div_rg1').style.display ='block';
 }
else {
document.getElementById('div_pr').style.display ='none';
document.getElementById('div_rg').style.display ='none';
document.getElementById('div_pr1').style.display ='none';
document.getElementById('div_rg1').style.display ='none';
 }
 }
            function  setdivrg1(){

if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia'){
document.getElementById('div_pr').style.display ='block';
document.getElementById('div_rg').style.display ='block';
document.getElementById('div_pr1').style.display ='block';
document.getElementById('div_rg1').style.display ='block';
 }
else {
document.getElementById('div_pr').style.display ='none';
document.getElementById('div_rg').style.display ='none';
document.getElementById('div_pr1').style.display ='none';
document.getElementById('div_rg1').style.display ='none';
 }
 }
      function  setdivrg1(){

if(getFieldValue(document.forms['addospita'].stato,'select')=='Italia'){
document.getElementById('div_pr').style.display ='block';
document.getElementById('div_rg').style.display ='block';
document.getElementById('div_pr1').style.display ='block';
document.getElementById('div_rg1').style.display ='block';
 }
else {
document.getElementById('div_pr').style.display ='none';
document.getElementById('div_rg').style.display ='none';
document.getElementById('div_pr1').style.display ='none';
document.getElementById('div_rg1').style.display ='none';
 }
 }
    function  setdivrg2(){

if(getFieldValue(document.forms['addazienda'].stato,'select')=='Italia'){
document.getElementById('div_pr').style.display ='block';
document.getElementById('div_rg').style.display ='block';
document.getElementById('div_pr1').style.display ='block';
document.getElementById('div_rg1').style.display ='block';
 }
else {
document.getElementById('div_pr').style.display ='none';
document.getElementById('div_rg').style.display ='none';
document.getElementById('div_pr1').style.display ='none';
document.getElementById('div_rg1').style.display ='none';
 }
 }
 
             function  setdivrex(a){

if(getFieldValue(document.forms[a].stato,'select')=='Italia'){
document.getElementById('div_pr').style.display ='block';
document.getElementById('div_rg').style.display ='block';
document.getElementById('div_pr1').style.display ='block';
document.getElementById('div_rg1').style.display ='block';
 }
else {
document.getElementById('div_pr').style.display ='none';
document.getElementById('div_rg').style.display ='none';
document.getElementById('div_pr1').style.display ='none';
document.getElementById('div_rg1').style.display ='none';
 }
 }
     
     
      function  okEnte(){
	  campi= new Array     ( 'email','password','connome','concognome','nome',   'contel','indirizzo',   'citta',    'cap',   'stato',       'cono');
     campitipi= new Array( 'text',  'text',    'text'    ,'text'   , 'text',     'text',   'text',    'text',       'text',    'select',          'select1' );

var T=''
for(i=1;i<15;i++){

T=T+getFieldValueex(document.forms['addente'].elements['f'+i],'checkbox')
}
     if(!checkMail(document.forms['addente'].email) ){

return;
}
if(T==''){
alert('Inserire almeno un area tematica di interesse')
document.forms['addente'].f1.focus()
return
}
if(getFieldValue(document.forms['addente'].a1,'radio')=='' || getFieldValue(document.forms['addente'].a2,'radio')==''){
alert('Per poter procedere è necessario accettare  le clausole');
return;
}
if(getFieldValue(document.forms['addente'].a1,'radio')=='0' || getFieldValue(document.forms['addente'].a2,'radio')=='0'){
alert('Per poter procedere è necessario accettare  le clausole');
return;
 }
 if(getFieldValue(document.forms['addente'].stato,'select')=='Italia' ){
document.forms['addente'].regione.value=    getFieldValueex(document.forms['addente'].id_regione,'select1')
document.forms['addente'].provincia.value=    getFieldValueex(document.forms['addente'].id_provincia,'select1')
 }
 if(getFieldValue(document.forms['addente'].stato,'select')=='Italia' && getFieldValueex(document.forms['addente'].id_regione,'select1')=='Seleziona'){
alert('Campo regione obbligatorio');
document.forms['addente'].id_regione.focus();
return;
 }

if(getFieldValue(document.forms['addente'].stato,'select')=='Italia' && getFieldValueex(document.forms['addente'].id_provincia,'select1')=='Seleziona'){
alert('Campo provincia obbligatorio');
document.forms['addente'].id_provincia.focus();
return;
 }
exconvalida1(document.forms['addente']);


 }
     function  okEnte_cc(){
	  campi= new Array(    'nome',  'indirizzo',   'citta',    'cap');
     campitipi= new Array(    'text',      'text',    'text',       'text'  );
 if(getFieldValue(document.forms['addente'].stato,'select')=='Italia' ){
document.forms['addente'].regione.value=    getFieldValueex(document.forms['addente'].id_regione,'select1')
document.forms['addente'].provincia.value=    getFieldValueex(document.forms['addente'].id_provincia,'select1')
 }
 document.forms['addente'].light.value='1'

exconvalida1(document.forms['addente']);


 }
      function  okEnte_ccxx(){
	  campi= new Array(    'nome',  'indirizzo',   'citta',    'cap');
     campitipi= new Array(    'text',      'text',    'text',       'text'  );
 if(getFieldValue(document.forms['addente'].stato,'select')=='Italia' ){
document.forms['addente'].regione.value=    getFieldValueex(document.forms['addente'].id_regione,'select1')
document.forms['addente'].provincia.value=    getFieldValueex(document.forms['addente'].id_provincia,'select1')
 }
 document.forms['addente'].light.value='0'

exconvalida1(document.forms['addente']);


 }
   function  okEnte_cc1(){
	  campi= new Array(    'email','password','connome','concognome',   'contel','confax',   'conemail');
     campitipi= new Array( 'text',  'text',    'text'    ,'text'   ,     'text',   'text',    'text'  );

exconvalida1(document.forms['addente']);


 }
function isInteger(value) {

  return (parseInt(value) == value);
}
function checkInt(a) {

 if(!isInteger(a.value) && a.value!="")  {
 alert( 'Inserire un valore numerico');
 a.value=xb;
 }else  xb=a.value;

}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function setSH(){
var a=getFieldValue(document.forms['addeventi'].fcosto,'radio');
if(a==1)
document.getElementById('div_costo').style.display ='none';
else 
document.getElementById('div_costo').style.display ='block';
}
function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}
function ricercaOspita(){
var a=getFieldValue(document.forms['so'].provincia,'select');
var b=getFieldValue(document.forms['so'].captot,'select');
if(a=='Seleziona' && b=='Seleziona'){alert('Selezionare un parametro'); return}
document.forms['so'].submit()
}

function checkMail(a){
if ( ! isEmail(a.value) ) { 
			alert('L\'Email non sembra valida ');	
a.focus();		
		return false;
}
return true;
}
function ricercaEnti(){

document.forms['so'].submit()



return true;
}


function okConf(){
if(getFieldValue(document.forms['acceptform'].email,'text')=='' || getFieldValue(document.forms['acceptform'].password,'text')==''){
alert('Inserire email e password');
return;
}
if(getFieldValue(document.forms['acceptform'].a1,'radio')=='' || getFieldValue(document.forms['acceptform'].a2,'radio')==''){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
}
if(getFieldValue(document.forms['acceptform'].a1,'radio')=='0' || getFieldValue(document.forms['acceptform'].a2,'radio')=='0'){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
}
document.forms['acceptform'].submit()
}

	function setdivvisCat(){
theField=document.forms['addeventi'].elements['categoria'];
theValue='';
 		for ( i = 0; i < theField.options.length; i++ ) {
 	 		if ( theField.options[i].selected ) theValue += theField.options[i].text 
 	 	} 

		if(theValue=='Altro')
document.getElementById('altrocat').style.display="block";
else
		document.getElementById('altrocat').style.display="none";
	}

	function setdivvisEvent(a){
theField=document.forms[a].elements['f1'];
theValue=getFieldValue(theField,'radio');

		if(theValue=='20')
document.getElementById('altrocat').style.display="block";
else
		document.getElementById('altrocat').style.display="none";
	}
function checkPr(a,b,c){
 st=getFieldValue(a,'select')

 theField=document.forms[c].elements[b]
if(st!='Italia')
for ( i = 0; i < theField.options.length; i++ ) {
 	 		 if('ee' == theField.options[i].value ) theField.options[i].selected =true

 	 	} 
}



function buyEvent() {
location='buyevent'
}
function buyEventO() {
location='buyevento'
}


  function  updateTotal(num,b){
	tot=0
	var ck=0;
	var i=0

for(i=0 ;i<num;i++){

	if(getFieldValue(document.forms['pack'].elements['checkbox'],'radio')==""+i)
	tot+=parseFloat(getFieldValue(document.forms['pack'].elements['pf_'+i],'text'))
}
	document.getElementById('total').innerHTML=formatEuro(""+tot)+" €";
	
 }

  function  okOrder(num){
var i=0

ap=''
for(i=0 ;i<num;i++)
if(getFieldValue(document.forms['pack'].elements['checkbox'],'radio')==""+i){
if(ap!='')ap+='_'
ap+=i
 }
if(ap==''){
alert('Selezionare l\'offerta')
return
 }
document.forms['pack'].elemensel.value=ap
document.forms['pack'].submit()
 }
 function  okOrder2(){

if(getFieldValue(document.forms['pack'].ac1,'radio')=='' || getFieldValue(document.forms['pack'].ac1,'radio')=='0'){
alert('Per poter procedere è necessario accettare tutte le clausole');
return;
}
if(getFieldValue(document.forms['pack'].ac2,'radio')=='' || getFieldValue(document.forms['pack'].ac2,'radio')=='0'){
alert('Per poter procedere è necessario accettare tutte le clausole');
return;
}
if(getFieldValue(document.forms['pack'].ac3,'radio')=='' || getFieldValue(document.forms['pack'].ac3,'radio')=='0'){
alert('Per poter procedere è necessario accettare tutte le clausole');
return;
}


	  campi= new Array( 'rag_soc',   'codicefiscale','partitaiva','a_cap','a_indirizzo','a_citta','a_provincia','statoamm','a_telefono','a_fax');
     campitipi= new Array('text',       'text',          'text', 'text'     , 'text'      , 'text'   , 'select'     , 'select'    , 'text'      , 'text' );
      exconvalida1(document.forms['pack']);


 }
 
 function  okOrder2s(){

if(getFieldValue(document.forms['pack'].ac1,'radio')=='' || getFieldValue(document.forms['pack'].ac1,'radio')=='0'){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
}
if(getFieldValue(document.forms['pack'].ac2,'radio')=='' || getFieldValue(document.forms['pack'].ac2,'radio')=='0'){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
}
if(getFieldValue(document.forms['pack'].ac3,'radio')=='' || getFieldValue(document.forms['pack'].ac3,'radio')=='0'){
alert('Per poter procedere è necessario accettare entrambe le clausole');
return;
}


	  campi= new Array( 'rag_soc',   'codicefiscale','partitaiva','a_cap','a_indirizzo','a_citta','a_provincia','statoamm','a_telefono','a_fax');
     campitipi= new Array('text',       'text',          'text', 'text'     , 'text'      , 'text'   , 'select'     , 'select'    , 'text'      , 'text' );
      exconvalida1(document.forms['pack']);


 }
 
 
 
  function  okContatti(){
 
	if(checkMail(document.forms['sendamico'].u_email))
if(getFieldValue(document.forms['sendamico'].acc,'radio')==1){
	  campi= new Array( 'mail',   'nome','cognome','richiesta');
     campitipi= new Array('select', 'text','text', 'text'  );
      exconvalida1(document.forms['sendamico']);
	 }else
alert('Per utilizzare il servizio di segnalazione è necessario dare il consenso per il trattamento dei dati personali')
 }