//<![CDATA[

	var lang = 'it';
	var cont_check = 0;//numero camere step2
	var num_room = new Array();

	/*scompare loading.gif*/
	function finish(){
		document.getElementById("loading").style.visibility = "hidden";
	}
	/*salvataggio servizi*/
	function save_service(){
		
	}
	/*Aggiorna numero camere inserite*/
	function cont_room(id,prec){
		tag = 'room_'+id;
		var num_r = document.getElementById(tag).value;
		
		var prec_n = parseInt(num_room[id]);
		if(num_r!='') num_r = parseInt(num_r);
		else num_r = 0;
		//alert('prec: '+num_room[id]);
		num_room[id] = num_r;
		
		//alert('attuale: '+num_r);
		if(num_r>0){
			cont_check=cont_check+num_r;
		}
		else if(num_r==0){
			cont_check=cont_check-prec_n;
		}
		//alert('tot: '+cont_check);
	}
	/*controlla se almeno una camera inserita*/
	function check_room(){
		if(cont_check==0){
			alert('Per poter proseguire bisogna inserire il numero delle camere');
			return false;
		}
		return true;
	}
	function makeRequest(id,script,get){
		var p=script+'?w='+get;
		var myAjax = new Ajax.Updater( id, p, { method: 'get'});
	}
	function setLang(tg,ln,str,sc,id_l){
		var default_lang = 'Italiano';
		if(ln=='en') default_lang = 'Inglese';
		else if(ln=='fr') default_lang = 'Francese';
		else if(ln=='ge') default_lang = 'Tedesco';
		else if(ln=='sp') default_lang = 'Spagnolo';
		document.getElementById(id_l).innerHTML = 'Lingua selezionata: '+default_lang;
		lang = ln;
		var tag = tg;
		var script = sc;
		var par = script+'&ln='+lang+'&id_st='+str;
		
		//document.getElementById(tag).removeChild(document.getElementById('desc_struttura'));
		makeRequest(tag,'res.php',par);
		//var txt = tinyMCE.getInstanceById('desc_struttura');
	}

	function insertDesc(str){
		var val = tinyMCE.getInstanceById('desc_struttura').getHTML();
		val = escape(val);
		var tag = 'desc_struttura';
		var par = 'desc&id_st='+str+'&ln='+lang+'&value='+val;
		makeRequest(tag,'res.php',par);
		alert('Descrizione inserita con successo.\nClicca su una bandierina se disponi di un\' altra descrizione in lingua.');
	}
	function insertDescatb(str){
		var val_auto = document.getElementById('desc_arriv_a').value;
		var val_train = document.getElementById('desc_arriv_t').value;
		var val_bus = document.getElementById('desc_arriv_b').value;
		val_auto = escape(val_auto);
		val_train = escape(val_train);
		val_bus = escape(val_bus);
		var tag = 'auto_multi';
		var par = 'desciatb&id_st='+str+'&ln='+lang+'&vala='+val_auto+'&valt='+val_train+'&valb='+val_bus;
		makeRequest(tag,'res.php',par);
		alert('Descrizioni inserite con successo\nClicca su una bandierina se disponi di altre descrizioni in lingua.');
	}
	flag_a = new Array();
	flag_p = new Array();
	function approved(id){
		
		var tag = 'str_appr_'+id;
		if(flag_a[id] == 0){ 
			if(!confirm('Sei sicuro di voler approvare questa struttura?')) return;
			makeRequest(tag,'res.php','appredon&id='+id);
			//var myAjax = new Ajax.Request( url, { method: 'post', parameters: pars });
			//var myAjax = new Ajax.Updater( 'str_appr', 'res.php?g='+id, { method: 'get'});
			flag_a[id] = 1;
			document.getElementById(tag).setAttribute('class','cellma');
		}
		else if(flag_a[id] == 1){
			if(!confirm('Sei sicuro di disabilitare questa struttura?')) return;
			makeRequest(tag,'res.php','appredoff&id='+id);
			flag_a[id] = 0;
			document.getElementById(tag).setAttribute('class','cellm');
		}

	}
	function published(id){
		
		var tag = 'str_pubb_'+id;
		if(flag_a[id]==1){
			if(flag_p[id] == 0){ 
				if(!confirm('Sei sicuro di voler pubblicare questa struttura?')) return;
				makeRequest(tag,'res.php','publidon&id='+id);
				flag_p[id] = 1;
				document.getElementById(tag).setAttribute('class','cellma');
			}
			else if(flag_p[id] == 1){
				if(!confirm('Sei sicuro di non voler pubblicare questa struttura?')) return;
				makeRequest(tag,'res.php','publidoff&id='+id);
				flag_p[id] = 0;		
				document.getElementById(tag).setAttribute('class','cellm');	
			}
		}
		else alert('Struttura non ancora approvata');

	}
	function photo_upload(upload_field)
	{
		var filename = upload_field.value;		
		upload_field.form.submit();
		sendUpload();
		//sendpUpload();		
	}
	function sendUpload(){
		var url = 'res.php';
		var pars = 'w=upload';
		makeRequest('descrizione','res.php','upload&g=provoletta');
	}
	function sendpUpload(){
		var url = 'res.php';
		var pars = 'w=upload&g=provola';
		
		//var pars = 'empID=' + empID + '&year=' + y;		
		//var myAjax = new Ajax.Request( url, { method: 'post', parameters: pars, onComplete: showResponse });
		var myAjax = new Ajax.Request( url, { method: 'post', parameters: pars });
		//makeRequest('descrizione','res.php','upload');
	}
	
	function photo_change(input){
		//makeRequest('descrizione','res.php','upload&g=provoletta');		
		var prev = document.getElementById('preview');
		prev.innerHTML = '<img src="'+input+'" width="260" height="280">'
	
	}
	function showResponse(originalRequest)
	{
		//put returned XML in the textarea
		//$('result').value = originalRequest.responseText;
		$('descrizione').value = originalRequest.responseText;
	}
	function upload_disabled(input){
		var ds = document.getElementById(input);
		ds.disabled = true;
	}
	function validateForm(form){
		var check = true;
		if(form=='form1'){
			if(document.getElementById('desc_struttura').value==''){
				alert('Inserire una descrizione per la struttura');
				document.getElementById('desc_struttura').focus();
				check = false;
			}
		}
		return check;
	}
	function validateNumericCB(id,id2){
		
		document.getElementById(id).value = document.getElementById(id).value.replace(/,/,".");
		if((isNaN(document.getElementById(id).value)) || (document.getElementById(id).value == "undefined") || (document.getElementById(id).value == " ")){
			alert('Inserire solo input numerici');
			document.getElementById(id).focus();
			document.getElementById(id).value = '';
			document.getElementById(id2).checked = false;
		}
		else document.getElementById(id2).checked = true;
		
		
	}
	/*
	function step2(){
		document.getElementById('nav').innerHTML = '<input type="hidden" name="step1" value="1">';
		//prev.innerHTML = '<img src="'+input+'" width="260" height="280">';
		document.form_s.submit();
	
	}
	function step1(){
		
		document.getElementById('nav').innerHTML = '<input value="&#060;&#060; Step 1" name="return_struttura" class="button" type="submit">';
		//prev.innerHTML = '<img src="'+input+'" width="260" height="280">';
		document.form_s.submit();
	}
	function step3(){
		
		document.getElementById('nav').innerHTML = '<input type="hidden" value="1" name="step1" /><input type="hidden" value="1" name="step2" />';
		//document.getElementById('nav').innerHTML = '';
		//document.getElementById('nav').innerHTML = '<input type="hidden" value="1" name="step_r1" />';
		//prev.innerHTML = '<img src="'+input+'" width="260" height="280">';
		document.form_s.submit();
		
	}
	*/
	permissible = new Array();

	function emptyValidate(id){
		if(document.getElementById(id).value == ''){
			document.getElementById(id).focus();
			document.getElementById(id).select();
			return;
		}
	}
	function upper(id){
		document.getElementById(id).value = document.getElementById(id).value.toUpperCase();
	}
	/*
	function trovatastiera()
	{
		if (navigator.appName == "Netscape")browser="ns";
		if (navigator.appName == "Microsoft Internet Explorer") browser="ie";
	}
	*/
	function filter(id){
		document.getElementById(id).value = trim(document.getElementById(id).value);
		upper(id);
		bcolor = '#FFD700';
		color = 'white';
		var tag = document.getElementById(id).value;
		tag = tag.toUpperCase();
		flag = false;
		for(j=0;j<permissible.length;j++){	
			if(tag.indexOf(permissible[j]) != -1){
				flag = true;
			}			
		}	
		if(!flag){
			//alert("Tariffa non presente");
			document.getElementById(id).value = '';
			document.getElementById(id).focus();
			document.getElementById(id).select();
			return;
		}
		if(tag=='A') {bcolor = '#FFD700'; color = 'black';}
		else if(tag=='B') bcolor = 'red';
		else if(tag=='C') bcolor = 'green';
		else if(tag=='D') bcolor = 'blue';
		else if(tag=='E') bcolor = '#DA70D6';
		document.getElementById(id).style.backgroundColor = bcolor;
		document.getElementById(id).style.color = color;
	} 
	function checkA(mese,giorni){
		for(i=1;i<=giorni;i++){
			var id = mese+'_'+i;
			document.getElementById(id).value = 'A';
			document.getElementById(id).style.backgroundColor='#FFD700';
			document.getElementById(id).style.color='black';
		}
	}
	function checkB(mese,giorni){
		for(i=1;i<=giorni;i++){
			var id = mese+'_'+i;
			document.getElementById(id).value = 'B';
			document.getElementById(id).style.backgroundColor='red';
			document.getElementById(id).style.color='white';
		}
	}
	function checkC(mese,giorni){
		for(i=1;i<=giorni;i++){
			var id = mese+'_'+i;
			document.getElementById(id).value = 'C';
			document.getElementById(id).style.backgroundColor='green';
			document.getElementById(id).style.color='white';
			
		}
	}
	function checkD(mese,giorni){
		for(i=1;i<=giorni;i++){
			var id = mese+'_'+i;
			document.getElementById(id).value = 'D';
			document.getElementById(id).style.backgroundColor='blue';
			document.getElementById(id).style.color='white';

		}
	}
	function checkE(mese,giorni){
		for(i=1;i<=giorni;i++){
			var id = mese+'_'+i;
			document.getElementById(id).value = 'E';
			document.getElementById(id).style.backgroundColor='#DA70D6';
			document.getElementById(id).style.color='white';

		}
	}
	// Removes leading whitespaces
	function LTrim( value ) {
		
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
		
	}
	
	// Removes ending whitespaces
	function RTrim( value ) {
		
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
		
	}
	
	// Removes leading and ending whitespaces
	function trim( value ) {
		
		return LTrim(RTrim(value));
		
	}

	function validateNumeric(id){
		document.getElementById(id).value = trim(document.getElementById(id).value);
		if((isNaN(document.getElementById(id).value)) || (document.getElementById(id).value == "undefined") || (document.getElementById(id).value == " ")){
			alert('Inserire solo input numerici');
			document.getElementById(id).focus();
			document.getElementById(id).value = '';			
		}
	}
	function validateNumericWC(id){
		if((isNaN(document.getElementById(id).value)) || (document.getElementById(id).value == "undefined") || (document.getElementById(id).value == " ")){
			alert('Inserire solo input numerici');
			document.getElementById(id).focus();
			document.getElementById(id).value = '#';			
		}
	}
	room_array = new Array();
	period_array = new Array();
	var j = 0;
	var z = 0;
	function validateForm(){
		//arrayd = new Array();
		//var arrayd = document.getElementById('table_room').childNodes;
		//alert(room_array[0]);
		flag = true;
		
		/*for(i=0;i<room_array.length;i++){
			//flag = document.getElementById(room_array[i]).value!=''&&flag;
			//flag = document.getElementById(room_array[i]).value!=' '&&flag;
			
		}*/
		for(i=0;i<period_array.length;i++){
			flag = document.getElementById(period_array[i]).value!=''&&flag;
			flag = document.getElementById(period_array[i]).value!=' '&&flag;
			
		}
		if(!flag){
			alert('Controlla i dati immessi, informazioni mancanti');
		}
		return flag;
	}
	function redirect(msg){
		alert(msg);
		location.href = "login.php";
	}

	function createOverLayer(tag){
		
		if(tag=="guide_descr" && document.getElementById('figlio')==null){
			var txt ='<div class="overlayer1" id="figlio">';
			txt+='<a style="cursor: pointer;" onclick=\'dropOverLayer("guide_descr","figlio")\' title="chiudi" id="chiudi">';
			txt+='<strong style="text-align: right;">[X] Chiudi</strong>';
			txt+='</a>';
			txt+='<h3>Guida&nbsp;alla&nbsp;registrazione</h3>';
			txt+='<p class="testo"><ul>Passi&nbsp;da&nbsp;seguire:&nbsp;';
			txt+='<li>Seleziona&nbsp;una&nbsp;lingua</li>';
			txt+='<li>Inserisci&nbsp;la&nbsp;descrizione&nbsp;in&nbsp;lingua</li>';
			txt+='<li>Premi&nbsp;il&nbsp;tasto inserisci</li>';
			txt+='<li>Ricevuta la conferma di inserimento clicca su un\'altra bandierina per inserire la descrizione in altre lingue.</li>';
			txt+='</ul>PS: Se non hai le descrizioni tradotte in qualche lingua ci penseranno i nostri traduttori.</p>';
			txt+='<a style="text-decoration: none; color: rgb(80, 80, 80);" href="#top_descr">Torna alla registrazione</a>';
			txt+='</div>';
			
			document.getElementById(tag).innerHTML = txt;
			/*
			var new_div = document.createElement('div');
			var id_child = 'figlio';
			new_div.setAttribute('id',id_child);
			new_div.setAttribute('class','overlayer');
			var new_href = document.createElement('a');
			new_href.setAttribute('id','chiudi');
			new_href.setAttribute('title','chiudi');
			new_href.setAttribute('onclick','dropOverLayer("guide_descr","figlio")');
			new_href.setAttribute('style','cursor:pointer');
		
			
			var new_x = document.createElement('strong');
			new_x.setAttribute('style','text-align: right;');
			//var n_t = document.createElement("Chiudi");
			var n_x = document.createTextNode("Chiudi X");
			new_x.appendChild(n_x);
			new_href.appendChild(new_x);
			new_div.appendChild(new_href);
                        
			var new_p = document.createElement('p');
			new_p.setAttribute('class','testo');
			
			new_p.innerHTML = "<h3>Guida&nbsp;alla&nbsp;registrazione</h3>"+
                        "<p><ul>Passi&nbsp;da&nbsp;seguire:&nbsp;"+
                        "<li>Seleziona&nbsp;una&nbsp;lingua</li><li>Inserisci&nbsp;la&nbsp;descrizione&nbsp;in&nbsp;lingua</li><li>Premi&nbsp;il&nbsp;tasto inserisci</li><li>Ricevuta la conferma di inserimento clicca su un'altra bandierina per inserire la descrizione in altre lingue.</li>"+
                        "</ul>PS: Se non hai le descrizioni tradotte in qualche lingua ci penseranno i nostri traduttori.</p>"+
                        "<br /><a style=\"position:absolute; left:790px; text-decoration:none;color:rgb(80,80,80);\" href=\"#top_descr\">Torna alla registrazione</a>"
			
			new_div.appendChild(new_p);
			document.getElementById(tag).appendChild(new_div);*/
		}	
		if(tag=="guide_serv" && document.getElementById('child_serv')==null ){
			var txt ='<div class="overlayer" id="child_serv">';
			txt+='<a style="cursor: pointer;" onclick=\'dropOverLayer("guide_serv","child_serv")\' title="chiudi" id="chiudi">';
			txt+='<strong style="text-align: right;">[X] Chiudi</strong>';
			txt+='</a>';
			txt+='<h3>Guida&nbsp;alla&nbsp;registrazione</h3>';
			txt+='<p class="testo"><ul>Passi&nbsp;da&nbsp;seguire:&nbsp;';
			txt+='<li>Clicca sui servizi&nbsp;della&nbsp;tua&nbsp;struttura</li>';
			txt+='<li>Se non hai qualche servizio lascia lo spazio bianco</li>';
			txt+='<li>Specifica eventualmente un prezzo per i servizi a pagamento</li>';
			txt+='</ul></p>';
			txt+='<a style="text-decoration: none; color: rgb(80, 80, 80);" href="#top_serv">Torna alla registrazione</a>';
			txt+='</div>';
			
			document.getElementById(tag).innerHTML = txt;			
		}
		
		
		if(tag=="guide_arrive" && document.getElementById('child_arrive')==null){
			var txt ='<div class="overlayer1" id="child_arrive">';
			txt+='<a style="cursor: pointer;" onclick=\'dropOverLayer("guide_arrive","child_arrive")\' title="chiudi" id="chiudi">';
			txt+='<strong style="text-align: right;">[X] Chiudi</strong>';
			txt+='</a>';
			txt+='<h3>Guida&nbsp;alla&nbsp;registrazione</h3>';
			txt+='<p class="testo"><ul>Passi&nbsp;da&nbsp;seguire:&nbsp;';
			txt+='<li>Clicca su una bandierina</li>';
			txt+='<li>Indica come raggiungere la tua struttura in auto</li>';
			txt+='<li>Indica come raggiungere la tua struttura in treno</li>';
			txt+='<li>Indica come raggiungere la tua struttura in autobus</li>';
			txt+='<li>Seleziona un\'altra lingua e ripeti il procedimento</li>';
			txt+='</ul><br>PS: Non e\' obbligatorio inserire le descrizioni in tutte le lingue';
			txt+='</p><a style="text-decoration: none; color: rgb(80, 80, 80);" href="#top_arrive">Torna alla registrazione</a>';
			txt+='</div>';
			
			document.getElementById(tag).innerHTML = txt;
		}
			
		if(tag=="guide_photo" && document.getElementById('child_photo')==null){
			var txt ='<div class="overlayer" id="child_photo">';
			txt+='<a style="cursor: pointer;" onclick=\'dropOverLayer("guide_photo","child_photo")\' title="chiudi" id="chiudi">';
			txt+='<strong style="text-align: right;">[X] Chiudi</strong>';
			txt+='</a>';
			txt+='<h3>Guida&nbsp;alla&nbsp;registrazione</h3>';
                        txt+='<p><ul>Si possono inserire fino ad un massimo di 8 foto,';
                        txt+='per tale ti consigliamo di inserire foto della tua struttura nel seguente ordine: ';
                        txt+='<li>Foto veduta generale</li>';
                        txt+='<li>Foto delle camere</li>';
                        txt+='<li>Servizi (bagni, sala d\'aspetto, sala conferenza, piscina, ecc..)</li>';
                        txt+='</ul>';
                        txt+='<ul>I passi da seguire per l\'inserimento delle foto sono: ';
                        txt+='<li>Inserire il titolo della foto che si vuole inserire</li>';
                        txt+='<li>Clicca il pulsante e seleziona la foto dal tuo computer</li>';
			txt+='<li>Il sistema in automatico salver&#224; la foto</li>';
                        txt+='<li>Ripeti il procedimento per le altre foto</li></ul>';
                        txt+='<p>PS: Ti consigliamo di inserire foto in cui sono presenti persone</p></p>';

			txt+='<a style="text-decoration: none; color: rgb(80, 80, 80);" href="#top_photo">Torna alla registrazione</a>';
			txt+='</div>';
			
			document.getElementById(tag).innerHTML = txt;		
		}
			
		if(tag=="guide_room" && document.getElementById('child_room')==null){
			var txt ='<div class="overlayer" id="child_room">';
			txt+='<a style="cursor: pointer;" onclick=\'dropOverLayer("guide_room","child_room")\' title="chiudi" id="chiudi">';
			txt+='<strong style="text-align: right;">[X] Chiudi</strong>';
			txt+='</a>';
			txt+='<h3>Guida&nbsp;alla&nbsp;registrazione</h3>';
			txt+='<p><ul>Passi&nbsp;da&nbsp;seguire:&nbsp;<li>Inserisci il numero di camere della tua struttura</li><li>Se non si dispone di una determinata tipologia di camera lascia lo spazio vuoto</li><li>Indica le differenti tariffe che applichi specificando un nome (esempio: bassa stagione, alta stagione, ecc..)</li></ul><p>PS: Puoi inserire massimo 5 possibili tariffe.</p>';
			txt+='<a style="text-decoration: none; color: rgb(80, 80, 80);" href="#top_room">Torna alla registrazione</a></p>';
			txt+='</div>';
			
			document.getElementById(tag).innerHTML = txt;
		}
		if(tag=="guide_calendar" && document.getElementById('child_calendar')==null){
			var txt ='<div class="overlayer" id="child_calendar">';
			txt+='<a style="cursor: pointer;" onclick=\'dropOverLayer("guide_calendar","child_calendar")\' title="chiudi" id="chiudi">';
			txt+='<strong style="text-align: right;">[X] Chiudi</strong>';
			txt+='</a>';
			txt+='<h3>Guida&nbsp;alla&nbsp;registrazione</h3>';
 			txt+='<p><ul>Adesso devi inserire i prezzi relativi ai tuoi servizi:<li>In alto trovi una tabella che ti permettera\' di inserire i prezzi relativi alle camere in base alla stagione</li><li>Es: se una doppia in mezza pensione nel periodo di alta stagione &#233; 50 euro a persona per notte dovrai inserire "50" nella casella corrispondente alla riga(1,2,..ecc) relativa alla tipologia di camera</li><li>Nel calendario in basso dovrai inserire i giorni dell\'anno indicando i periodi di alta o bassa stagione es: se tutto il mese di febbraio &#232; in alta stagione clicca la lettera "A" per selezionare tutto il mese</li><li>Il prezzo inserito non deve essere superiore alla tariffe presenti nel tuo sito web</li><li>Se in un mese hai due tipologie di tariffe, puoi modificarle cancellando il contenuto delle caselle e inserendo la lettera della tariffa corrispondente</li><li>Ti ricordo che i prezzi sono espressi a persona per notte eccetto la colonna "Per una settimana"</li></ul></p>';

			txt+='<a style="text-decoration: none; color: rgb(80, 80, 80);" href="#top_calendar">Torna alla registrazione</a>';
			txt+='</div>';
			
			document.getElementById(tag).innerHTML = txt;
		}	
		
	}
	function dropOverLayer(tag,tagChild){
		var child = document.getElementById(tagChild);
		document.getElementById(tag).removeChild(child);
	}
//]]>