jQuery.fn.slideFadeToggle = function(easing, speed, callback) {
	return this.toggle('blind', {}, 500, callback);
};

$(window).load(function(){
	if ($.browser.safari == true){
//		$('.richiesta_non_impegnativa').css('float','right');
//		$('.richiesta_non_impegnativa').css('float','left');
	}
});
$(window).ready(function(){
	if ($('.iframe').length != 0){
		$('.iframe').fancybox({
			'frameWidth': 950,
			'frameHeight':550
		});
	}
	
	if ($('.iframe_offer').length != 0){
		$('.iframe_offer').fancybox({
			'frameWidth':502,
			'frameHeight':450
		});
	}

	if ($('.iframe_generic').length != 0){
		$('.iframe_generic').fancybox({
			'frameWidth':502,
			'frameHeight':370
		});
	}
});

function showSearchOptions1(){
	if ($('#otherOptions').attr('class') != "searchOptions"){
		$('#otherOptions').attr('class', 'searchOptions');
		$('#otherOptions a').css('color','#000');
		$('#searchOptions').show();
	}
	else{
		$('#otherOptions').attr('class','');
		$('#otherOptions a').css('color','');
		$('#searchOptions').hide();
	}
}

function showSearchOptions(){
	$('#searchOptions').slideFadeToggle();
}

function popTheWin(url)
{
	window.open(url);
}

function makeChildren(){
	totale = $('#bambini')[0].value;
	if (totale != 0 && totale != '20+')
	{
		var theOptions = '';
		for (y=1;y<=12;y++)
		{
			if (y == 1)
			{scrivi = '0-1';}
			else
			{scrivi = y;}
			theOptions+='<option value="'+scrivi+'">'+scrivi+'</option>';}
		var toWrite = '';
		for (x=1;x<=totale;x++)
		{
			toWrite+='<tr><td style="text-align:right;width:25px;">'+x+'.</td><td><select name="bambini_'+x+'">'+theOptions+'</select></td></tr>';
		}
		$('#children').html('<br>Et&agrave; <table cellpadding=0 cellspacing=0 border=0>'+toWrite+'</table>');
	}
	else
	{$('#children').html('');}
}

function doSearch(){
	array_options = Array();
	$('#searchOptions input:checked').each(function(){
		array_options.push(this.value);
	});
	$('#options_json')[0].value = $.toJSON(array_options);
	$('#searchForm')[0].submit();
}

function showOfferRequest(){
	$('#offerRequest').slideFadeToggle();
}

function loadPlus(plusID){
	$('.plusDetails').each(function(){
		if($(this).css('display') == 'block'){
			$(this).slideFadeToggle();
		}
	});
	$('#plus_'+plusID).slideFadeToggle();
}

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){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }

		 return true;					
}


function checkNLForm(){
	form_errors = '';
	if($('#nome')[0].value == ''){
		form_errors += 'Nome inserito non valido\n';
	}
	
	if($('#cognome')[0].value == ''){
		form_errors += 'Cognome inserito non valido\n';
	}
	
	if(!echeck($('#email')[0].value)){
		form_errors += 'Email inserita non valida\n';
	}
	
	if($('#privacy')[0].checked == false){
		form_errors += 'Bisogna accettare l\'informativa sulla privacy per procedere';
	}
	
	if (form_errors != ''){
		alert('Impossibile inviare la richiesta, correggere gli errori riportati e riprovare:\n\n'+form_errors);
		return false;
	}
	else{
		return true;
	}
}