

function controllo() {
	if (document.getElementById("nome").value == "") {
		alert("Inserire il proprio nome");
		document.getElementById("nome").focus()
		return;
	}	
	if (document.getElementById("email").value == "") {
		alert("Inserire il proprio indirizzo email");
		document.getElementById("email").focus()
		return;
	}	
	dest = "cont";
	document.getElementById("frm_contatti").action = dest + "atti" + ".php";
	document.getElementById("frm_contatti").submit();
}

/**
 * Trova i box con classe "allclick".
 * All'interno cerca dei link, ed estende l'href sul click di tutto il box
 * @return null
 */
function checkAllclick()
{
try
{
	var clickbox = $('.allclick');
	clickbox.each(function()
	{
		var $this = $(this);
		//	ad ogni box allclick assegno il cursore pointer
		$this.css('cursor','pointer');
		//	sul click mando la pagine all'href del link sottostante
		$this.bind('click', function(){window.location.href=$('a',this).attr('href');});
	});
}
catch(e) {toDebug(e.toString());}
}


function slideOfferte()
{
try
// scrollVert,
{		
	$('#offerte-container').cycle({
		fx: 'scrollUp',
		speed: 1000,
		timeout: 6500,
		prev: '#offertaPrev',
		next: '#offertaNext'
	});	
}
catch(e) {toDebug(e.toString());}
}
function slideOfferteCongressi()
{
try
// scrollVert,
{		
	$('#offerte-container-congressi').cycle({
		fx: 'scrollUp',
		speed: 1000,
		timeout: 6500,
		prev: '#offertaPrev_c',
		next: '#offertaNext_c'
	});	
}
catch(e) {toDebug(e.toString());}
}


/**
 * Trova i gli input text con classe "input_form".
 * Quando si clicca all'interno del form la scritta originale scopare e ricompare se non si digita nulla.
 * @return null
*/
function cancellaForm()
{
try
{
	$(".input_form:text").bind('focus blur',function(event)
	{
		var value = $(this).attr("originalValue");
		if (event.type == "focus") {
			if ($(this).val() == "" || $(this).val() == value) {
				$(this).val("");
			}
		}else {
			if ($(this).val() == "") {
				$(this).val(value);
			}
		}
	});	
	$("textarea.input_form").bind('focus blur',function(event)
	{
		var value = $(this).attr("originalValue");
		if (event.type == "focus") {
			if ($(this).text() == "" || $(this).text() == value) {
				$(this).text("");
			}
		}else {
			if ($(this).text() == "") {
				$(this).text(value);
			}
		}
	});
}
catch(e) {toDebug(e.toString());}
}

/*****************************************************************************************/
//	inizio funzioni di debug
debug_msg = false;
function toDebug(string)
{
	if (debug_msg)
	{
		if((typeof window.console=="undefined")) {alert(string);}
		else {
			console.error();
			console.group(string);
			console.trace();
			console.groupEnd();
		}
	}
}
function toConsole(string)
{
	if((typeof window.console=="undefined")) {alert(string);}
	else console.log(string);
}
//fine funzioni di debug

function $j(argument)
{
	var result = jQuery(argument);
	if (result.length == 0) return null;
	else return result;
}

$j(document).ready(function()
{ 

	checkAllclick();
	slideOfferte();
	//cancellaForm();
	
	
	$("#checkin").datepicker({option:'en', dateFormat: 'dd-mm-yy',showOn: 'both', buttonImage: 'images/calendarietto.png', buttonText: '', buttonImageOnly: true, numberOfMonths: 3});
	$("#checkout").datepicker({option:'en', dateFormat: 'dd-mm-yy',showOn: 'both', buttonImage: 'images/calendarietto.png', buttonText: '', buttonImageOnly: true, numberOfMonths: 3});
	
	$("#checkin").change(
		function(){
			date1 = $("#checkin").datepicker( 'getDate' );
			// devo controllare che la data sia valida
			check = false;
			dateCheck = date1;
			date2 = new Date(dateCheck);						
			$("#checkout").datepicker('option', 'minDate',date2);
		}
	);
});

function ctrform(){
	if (document.getElementById("checkin").value==''){
		document.getElementById("checkin").focus();
		alert("Data di Arrivo obbligatoria");
		return false;
	}
	if (document.getElementById("checkout").value=='') {
		document.getElementById("checkout").focus();
		alert("Data di Partenza obbligatoria");
		return false;
	}
	document.getElementById("form_ins").submit();	
}
function cambia_bambini(n) {
	frm = document.getElementById("form_ins");
	camere = parseInt(document.getElementById("numRooms").value);
	if (n>4) n=4;
	if ((n>0)&&(camere==1))
	{
		var contenuto = "";
		var name = "";
		for (i=1; i<=n; i++){
			name="bform[reqRooms][1][childAge]["+i+"]";
			contenuto += "<select name='"+name+"' id='"+name+"'><option value='-1'>-?-</option><option value='0'>&lt;1</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option></select>";
		}
		document.getElementById("bam_div").innerHTML=contenuto+"&nbsp;";
		document.getElementById("bam_div").style.visibility = "visible";
		document.getElementById("bam_div").style.display = "block";
		document.getElementById("bam_div1").style.visibility = "visible";
		document.getElementById("bam_div1").style.display = "block";
	} else {
		document.getElementById("bam_div").style.visibility = "hidden";
		document.getElementById("bam_div").style.display = "none";
		document.getElementById("bam_div1").style.visibility = "hidden";
		document.getElementById("bam_div1").style.display = "none";
	}

}

$j(window).load(function()
{


});

$j(window).resize(function()
{

});

/*****************************************************************************************/


  function inviamail(){
    document.fmail.submit();
  }
  function validateformesperto(){
    //alert();
		referente = document.generale.referente.value;
		if ((referente == "") || (referente == "undefined")) {
			alert('Il referente inserito non è valido');
		   document.generale.referente.focus();
			return false;
		}
		telefono = document.generale.telefono.value;
		if ((telefono == "") || (telefono == "undefined")) {
			alert('Il telefono inserito non è valido');
		   document.generale.telefono.focus();
			return false;
		}
		email = document.generale.email.value;
		if ((email == "") || (email == "undefined")) {
			alert('L'+chr(44)+'email inserita non è valida');
		   document.generale.email.focus();
			return false;
		}
		messaggio = document.generale.messaggio.value;
		if ((messaggio == "") || (messaggio == "undefined")) {
			alert('Il messaggio inserito non è valido');
		   document.generale.messaggio.focus();
			return false;
		}
		document.generale.action = document.getElementById("pagina").value;
    	document.generale.submit();
  }
  
  function TGetCookie( 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_land_ref(){
							
							var ref = '';
							var uid = '';
							var uidc = '';
							var land = '';
							var referer = '';
							var landing = '';
							var testcoockie = '';
							testcoockie = TGetCookie('TCookiesTest');
							if(testcoockie){
								referer = TGetCookie('Provenienza');
								landing = TGetCookie('Landing');
								uidc = TGetCookie('uid');
								if(uidc==null){
									uid = '';
								}else{
									if(document.frm_contatti.uid) document.frm_contatti.uid.value = uidc;
								}
								if(referer==null){
									ref = '';
								}else{
									if(document.frm_contatti.provenienza) document.frm_contatti.provenienza.value = referer;
								}
								if(landing==null){
									land = '';
								}else{
									if(document.frm_contatti.landing) document.frm_contatti.landing.value = landing;
								}
							}else{
								if(document.frm_contatti.provenienza) document.frm_contatti.provenienza.value = 'Non rilevabile';
							}
								
						}
						
						function send_data_form(form,url){
								
								
							
								var myValidator = validate_frm_contatti;
								var check = myValidator(document.frm_contatti);
								
								if(check)
								{
									if(document.getElementById('note_e_richieste'))
									{
										var textarea = document.getElementById('note_e_richieste');
										if(textarea.className.indexOf('default') != -1)
										{
											textarea.innerHTML = '';
										}
									}
									
									var land = '';
									var referer = '';
									var landing = '';
									var testcoockie = '';
									var uidc = '';
                                    var uid = '';
									
									testcoockie = TGetCookie('TCookiesTest');
									if(testcoockie){
										referer = TGetCookie('Provenienza');
										landing = TGetCookie('Landing');
										uidc = TGetCookie('uid');
										if(uidc==null){
											var uid = '';
										}else{
											var uid = '&uid=' + encodeURIComponent(uidc);
										}
										if(referer==null){
											var ref = '';
										}else{
											var ref = '&provenienza=' + encodeURIComponent(referer);
										}
										if(landing==null){
											land = '';
										}else{
											land = '&landing=' + encodeURIComponent(landing);
										}
									}else{
										var ref = '&provenienza=Non rilevabile';
									}
									
									
									var qstring = setquerystring(form);
									var jsel = document.createElement('SCRIPT');
									jsel.type = 'text/javascript';
									jsel.src = url + '?' + qstring + ref + land + uid;     
									window.document.body.appendChild (jsel); 
									
								}else{
									
									
									
								}
						}
						
						function setquerystring(form) {
							   
						   var querystring = '';
						   var numberElement = form.elements.length; 
						
							for(var i=0; i<numberElement; i++)
							{
								if((form.elements[i].name == 'copia_su_richiesta') && (form.elements[i].checked == false))
								{
									continue;
								}
								if(i<numberElement-1)
								{ 
								   querystring+= form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
								}
								else
								{
									querystring+= form.elements[i].name+"="+encodeURIComponent(form.elements[i].value);
								}
							}
							
							return querystring;
						   
						}
						
						function enable_lista(oggetto,id_lista){
							if(oggetto.value=='no'){
								oggetto.value = '1';

							}else{
								oggetto.value = 'no'; 
							}
							
							
							
						}
						function showhide_elem(chkbx,name) {   	 
							
							if(chkbx.value=='0'){
								chkbx.value = '1';
								document.getElementById(name).style.display = 'block';  
							}else{
								chkbx.value = '0';  
								document.getElementById(name).style.display = 'none';    
							}

						} 
						
  
  function validate_frm_contatti(frm) {
  var value = '';
  var errFlag = new Array();
  var _qfGroups = {};
  _qfMsg = '';

  value = frm.elements['nome'].value;
  if (value == '' && !errFlag['nome']) {
    errFlag['nome'] = true;
    _qfMsg = _qfMsg + '\n -  Nome e Cognome';
  }

  value = frm.elements['email'].value;
  var regex = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;
  if (value != '' && !regex.test(value) && !errFlag['email']) {
    errFlag['email'] = true;
    _qfMsg = _qfMsg + '\n -  E-mail error';
  }

  value = frm.elements['email'].value;
  if (value == '' && !errFlag['email']) {
    errFlag['email'] = true;
    _qfMsg = _qfMsg + '\n -  E-mail';
  }

  if (_qfMsg != '') {
    _qfMsg = 'Alcuni campi obbligatori non sono stati compilati.' + _qfMsg;
    _qfMsg = _qfMsg + '\n';
    alert(_qfMsg);
    return false;
  }
  return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
