var ARR_DATES = new Array();
$(function() {

	var calendar_image = '/templates/cubicle_fly/images/calendar.gif';
	$('#fromDatePicker_charter').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_charter').val(first_key(ARR_DATES[$("#searchCityFrom").val()][value.substring(8,10)+value.substring(3,5)+value.substring(0,2)])); if ($.browser.msie) { $('#toDatePicker_charter').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_charter').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_charter').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_charter').val()); calInfo(); departure=$('#fromDatePicker_charter').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_nofshons').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_nofshons').val(first_key(ARR_DATES[$("#searchCityFrom").val()][value.substring(8,10)+value.substring(3,5)+value.substring(0,2)])); if ($.browser.msie) { $('#toDatePicker_nofshons').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_nofshons').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_nofshons').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_nofshons').val()); calInfo(); departure=$('#fromDatePicker_nofshons').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_tours').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_tours').val(addDays(date,1)); if ($.browser.msie) { $('#toDatePicker_tours').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_tours').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_tours').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_tours').val()); calInfo(); departure=$('#fromDatePicker_tours').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_hotel').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_hotel').val(addDays(date,1)); if ($.browser.msie) { $('#toDatePicker_hotel').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_hotel').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_hotel').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_hotel').val()); calInfo(); departure=$('#fromDatePicker_hotel').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_domflights').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_domflights').val(addDays(date,1)); if ($.browser.msie) { $('#toDatePicker_domflights').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_domflights').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_domflights').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_domflights').val()); calInfo(); departure=$('#fromDatePicker_domflights').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_domhotels').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_domhotels').val(addDays(date,1)); if ($.browser.msie) { $('#toDatePicker_domhotels').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_domhotels').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_domhotels').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_domhotels').val()); calInfo(); departure=$('#fromDatePicker_domhotels').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_dompackages').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_dompackages').val(addDays(date,1)); if ($.browser.msie) { $('#toDatePicker_dompackages').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_dompackages').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_dompackages').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_dompackages').val()); calInfo(); departure=$('#fromDatePicker_dompackages').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_schedule').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_schedule').val(addDays(date,1)); if (0&&$.browser.msie) { $('#toDatePicker_schedule').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_schedule').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_schedule').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_schedule').val()); calInfo(); departure=$('#fromDatePicker_schedule').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_schedule2').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_schedule').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_schedule').val()); calInfo(); departure=$('#fromDatePicker_schedule').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_schedule3').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_schedule').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#toDatePicker_schedule2').val()); calInfo(); departure=$('#fromDatePicker_schedule').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#fromDatePicker_rentcar').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', minDate: days_in_calendar, altField: '#date1', onSelect: function(value,date) { $('#toDatePicker_rentcar').val(addDays(date,1)); if ($.browser.msie) { $('#toDatePicker_rentcar').datepick('show'); } }, beforeShow: function() { calInfo(); departure=''; }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });
	$('#toDatePicker_rentcar').datepick({showOn: 'both', buttonImageOnly: true, buttonImage: calendar_image, dateFormat: 'dd/mm/yy', altField: '#date2', minDate: $('#fromDatePicker_rentcar').val(), beforeShow: function() { $(this).datepick('option', 'minDate', $('#fromDatePicker_rentcar').val()); calInfo(); departure=$('#fromDatePicker_rentcar').val(); }, beforeShowDay: inactiveDates, showAnim: 'fadeIn', closeAtTop: false, mandatory: true });

	$("#searchCity_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#searchCity_value").val(item[2]); $("#searchCity_schedule").css('direction', 'rtl'); })
	$("#searchCityFrom_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#searchCityFrom_value").val(item[2]); $("#searchCityFrom_schedule").css('direction', 'rtl'); })
	$("#from2_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#from2_value").val(item[2]); $("#from2_schedule").css('direction', 'rtl'); })
	$("#to2_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#to2_value").val(item[2]); $("#to2_schedule").css('direction', 'rtl'); })
	$("#from3_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#from3_value").val(item[2]); $("#from3_schedule").css('direction', 'rtl'); })
	$("#to3_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#to3_value").val(item[2]); $("#to3_schedule").css('direction', 'rtl'); })

	$("#searchCity_schedule").change(function() { $("#searchCity_value").val($(this).val()); })
	$("#searchCityFrom_schedule").change(function() { $("#searchCityFrom_value").val($(this).val()); })
	$("#from2_schedule").change(function() { $("#from2_value").val($(this).val()); })
	$("#to2_schedule").change(function() { $("#to2_value").val($(this).val()); })
	$("#from3_schedule").change(function() { $("#from3_value").val($(this).val()); })
	$("#to3_schedule").change(function() { $("#to3_value").val($(this).val()); })

	$("#sByPrice li a").click(function() {
		$("#frm input[name=dealtype]").val($(this).attr("rel"));
		$("#frm input[name=searchCityFrom]").val($("#"+$(this).attr("rel")+"CityFrom").val());
		$(".inner_searchPrice").hide();
		$("#show"+$(this).attr("rel")).show();
		$("#sByPrice li a").removeClass("activ")
		$(this).addClass("activ");
		return false;
	})
	$("#NOFSHONCityFrom, #CHARTERCityFrom").change(function(){ $("#frm input[name=searchCityFrom]").val($(this).val()); });

//	$("#schedule_multidest").click(function(){ $("#searchengine .box").css("height", "513px"); });

	$(".flightstab,.tab").hide();
	$("div#israel").show();
	$('div#israel div:first').show();
	$("#flights-table-nav label").click(function(){
		$(".flightstab").slideUp();
		$("#flights-table-nav label").removeClass("selected");
		$(this).addClass("selected");
		$('#'+$(this).attr("for").substring(4)).slideDown();
	});

	function formatItem(row) {
		return '<table border="0" width="300" cellpadding="0" cellspacing="0"><tr><td width="130">' + row[0] + '</td><td width="130" align="left">' + row[1] + '</td><td width="40" align="left">' + row[2] + '</td></tr></table>';
	}

	function first_key(x) {
		var result = '';
		for (key in x)
			for (p in x[key]) {
				if (!result || p<result) result = p; }
		return result.substring(4,6)+'/'+result.substring(2,4)+'/20'+result.substring(0,2);
	}

	$("#schedule_roundtrip").addClass("active");
	$("#triptype").val($("#schedule_roundtrip").attr("rel"));
	$("#schedule_form .sched_type span").click(function(){
		$("#schedule_form .sched_type span").removeClass("active");
		$(this).addClass("active");
		$("#triptype").val($(this).attr("rel"));
	});
	$("#flight_roundtrip").addClass("active");
	$("#flight_type").val($("#flight_roundtrip").attr("rel"));
	$("#flight_form .dom_type span").click(function(){
		$("#flight_form .dom_type span").removeClass("active");
		$(this).addClass("active");
		$("#flight_type").val($(this).attr("rel"));
	});

$("#searchCityFrom_schedule, #from2_schedule, #to2_schedule, #from3_schedule, #to3_schedule").css("color", "silver");
$("#searchCityFrom_schedule, #from2_schedule, #to2_schedule, #from3_schedule, #to3_schedule").focus(function() { if ($(this).val()=='שדה תעופה או עיר (בעברית)') $(this).val("").css("color", "black"); });
$("#searchCityFrom_schedule, #from2_schedule, #to2_schedule, #from3_schedule, #to3_schedule").blur(function() { if ($(this).val()=='') $(this).val("שדה תעופה או עיר (בעברית)").css("color", "silver"); });
	//$("#searchCity_schedule, #from2_schedule, #from3_schedule, #searchCity_value, #from2_value, #from3_value").val('TLV');
	//$("#searchCityFrom_schedule, #to2_schedule, #to3_schedule, #searchCityFrom_value, #to2_value, #to3_value").val('IST');

	$(".maintabs li a:first").addClass('active');
	$(".flights li a[href=#schedule], .domestic li a[href=#domflights]").addClass('active');
	$("#searchCityFrom_charter, #searchCityFrom_nofshons, #searchCityFrom_tours, #searchCityFrom_domflight, #searchCityFrom_domhotel, #searchCityFrom_dompackage, #searchCityFrom_hotel, #searchCityFrom_rentcar").change(function(){ $("#searchCityFrom").val(this.value); });
$("#flight_oneway").click(function() { $("#domtodate").slideUp(400); });
	$("#flight_roundtrip").click(function() { $("#domtodate").slideDown(400); });

	$("#schedule_oneway").click(function() {
		$("#sched_cities").slideUp(400);
		$("#schedtodate").slideUp(400,function(){$(this).hide()});
		$("#wrapper-inner").css("height", "auto");
		$("#wrapper-inner").css("min-height", "276px");
	});
	$("#schedule_roundtrip").click(function() {
		$("#sched_cities").slideUp(400);
		$("#schedtodate").slideDown(400);
		$("#wrapper-inner").css("height", "auto");
		$("#wrapper-inner").css("min-height", "276px");
	});
	$("#schedule_multidest").click(function() { 
		$("#sched_cities").slideDown(400);
		$("#schedtodate").slideUp(400,function(){$(this).hide()});
		$("#wrapper-inner").css("height", "auto");
	});
	
	$("ul.maintabs li a").click(function(){
		$("#wrapper-inner").css("min-height", "380px");
	});
		
	$(".search_button").click(function(){

		if ($(this).attr('rel')=='search') {
			$("#Pform").append('<input type="hidden" name="range" id="range" value="0" />');
			$("#Pform").append('<input type="hidden" name="ndbl" id="ndbl" value="1" />');
			$("#Pform").append('<input type="hidden" name="top" id="top" value="50" />');
			}
		if ($(this).attr('rel')=='charter') {
			$("#searchCityFrom").val($("#searchCityFrom_charter").val());
			if ($("#charterairline").val()) $("#Pform").append('<input type="hidden" name="airline" value="'+$("#charterairline").val()+'" />');
			}
		if ($(this).attr('rel')=='nofshons') {
			if ($("#packagegrade").val()) $("#Pform").append('<input type="hidden" name="rate" value="'+$("#packagegrade").val()+'" />');
			if ($("#packagebasis").val()) $("#Pform").append('<input type="hidden" name="bb" value="'+$("#packagebasis").val()+'" />');
			if ($("#club").is(':checked')) $("#Pform").append('<input type="hidden" name="club" value="'+$("#club").val()+'" />');
			}
		if ($(this).attr('rel')=='hotel') {
			if ($("#hotelgrade").val()) $("#Pform").append('<input type="hidden" name="rate" value="'+$("#hotelgrade").val()+'" />');
			if ($("#hotelbasis").val()) $("#Pform").append('<input type="hidden" name="bb" value="'+$("#hotelbasis").val()+'" />');
			}
		if ($(this).attr('rel')=='schedule') {
			//childs and inf cant flight alone
			checkPeople();
			if (checkMe == false) {
				return checkMe;
			}
			if ($("#searchCityFrom_value").val() == 'שדה תעופה או עיר (בעברית)' || !$("#searchCityFrom_value").val().match(/^[a-zA-Z]{3}$/)) { alert('יש לבחור יעד הטיסה / נחיתה'); return false; }
			if ($("#adults").val()+$("#childs").val()+$("#infants").val()+$("#seniors").val()+$("#youths").val()+$("#students").val()==0) { alert('יש לבחור לפחות נוסע אחד'); return false; }
			$("#mode").val("searchit");
			$("#searchCityFrom").val($("#searchCityFrom_value").val());
			if ($("#airline").attr('checked')) $("#Pform").append('<input type="hidden" name="airline" value="LY" />');
			$("#Pform").append('<input type="hidden" name="triptype" value="'+$("#triptype").val()+'" />');
			$("#Pform").append('<input type="hidden" name="searchCity" value="'+$("#searchCity_value").val()+'" />');
			$("#Pform").append('<input type="hidden" name="classService" value="Y" />');
			$("#Pform").append('<input type="hidden" name="destination_name" value="'+hebencode($("#searchCityFrom_schedule").val())+'" />');
				if ( $('#searchCityFrom_value').val() == "" ) {
					return false;
				}			
			if ($("#triptype").val()==2) {
				$("#Pform").append('<input type="hidden" name="from1" value="'+$("#searchCity_value").val()+'" />');
				$("#Pform").append('<input type="hidden" name="to1" value="'+$("#searchCityFrom_value").val()+'" />');
				$("#Pform").append('<input type="hidden" name="from2" value="'+$("#from2_value").val()+'" />');
				$("#Pform").append('<input type="hidden" name="to2" value="'+$("#to2_value").val()+'" />');
				$("#Pform").append('<input type="hidden" name="from3" value="'+$("#from3_value").val()+'" />');
				$("#Pform").append('<input type="hidden" name="to3" value="'+$("#to3_value").val()+'" />');
				$("#date2").val($("#toDatePicker_schedule2").val());
				$("#Pform").append('<input type="hidden" name="date3" value="'+$("#toDatePicker_schedule3").val()+'" />');
			}
			if ($("#scheduleairline").val()) $("#Pform").append('<input type="hidden" name="airline" value="'+$("#scheduleairline").val()+'" />');
			$("#Pform").append('<input type="hidden" name="adults" value="'+$("#adults").val()+'" />');
			$("#Pform").append('<input type="hidden" name="childs" value="'+$("#childs").val()+'" />');
			$("#Pform").append('<input type="hidden" name="infants" value="'+$("#infants").val()+'" />');
			$("#Pform").append('<input type="hidden" name="seniors" value="'+$("#seniors").val()+'" />');
			$("#Pform").append('<input type="hidden" name="students" value="'+$("#students").val()+'" />');
			$("#Pform").append('<input type="hidden" name="youths" value="'+$("#youths").val()+'" />');
			}
		if ($(this).attr('rel')=='domflights') {
			$("#Pform").append('<input type="hidden" name="deal_type" id="deal_type" value="flight" />');
			$("#Pform").append('<input type="hidden" name="flight_type" value="'+$("#flight_type").val()+'" />');
			$("#Pform").append('<input type="hidden" name="searchCity" value="'+$("#searchCity_domflight").val()+'" />');
			$("#Pform").append('<input type="hidden" name="adults" value="'+$("#domadults").val()+'" />');
			$("#Pform").append('<input type="hidden" name="childs" value="'+$("#domchilds").val()+'" />');
			$("#Pform").append('<input type="hidden" name="infants" value="'+$("#dominfants").val()+'" />');
			}
		if ($(this).attr('rel')=='domhotels') {
			$("#Pform").append('<input type="hidden" name="deal_type" id="deal_type" value="hotel" />');
			$("#Pform").append('<input type="hidden" name="complect" value="'+$("#complect_domhotels").val()+'" />');
			}
		if ($(this).attr('rel')=='dompackages') {
			$("#Pform").append('<input type="hidden" name="deal_type" id="deal_type" value="package" />');
			$("#Pform").append('<input type="hidden" name="complect" value="'+$("#complect_dompackages").val()+'" />');
			}
		$("#wrap").hide();
		$("#loadingDiv").show();
		$("#Pform").submit();
	});
	$(".maintabs li a").click(function(){
		$(".tab").hide();
		$(this.hash).show();
		$("#search_title").html('חפש'+($(this).html().replace(/<\/?[^>]+>/gi,''))+' באיזיגו');
		$(".maintabs li a").removeClass('active blank');
		$(this).addClass('active');
		$(this).parent().closest('li').prev('li').children().addClass('blank')
		if ($(this).attr("rel")) {
			$("#dealtype").val($(this).attr("rel"));
			$("#searchCityFrom").val($("#searchCityFrom_"+this.hash.substring(1)).val())
			$("#date1").val($("#fromDatePicker_"+this.hash.substring(1)).val())
			$("#date2").val($("#toDatePicker_"+this.hash.substring(1)).val())
			}
		else {
			switch (this.hash) {
				case '#flights':
					$('#schedule').show();
					if ($("#flights a[href=#charters]").hasClass('active')) {
						$("#dealtype").val($("#flights a[href=#charters]").attr("rel"));
						$("#searchCityFrom").val($("#searchCityFrom_charter").val())
						$("#date1").val($("#fromDatePicker_charter").val())
						$("#date2").val($("#toDatePicker_charter").val())
						}
					if ($("#flights a[href=#schedule]").hasClass('active')) {
						$("#dealtype").val($("#flights a[href=#schedule]").attr("rel"));
						$("#searchCityFrom").val($("#searchCityFrom_schedule").val())
						$("#date1").val($("#fromDatePicker_schedule").val())
						$("#date2").val($("#toDatePicker_schedule").val())
						}
					break;
				case '#israel':
					if ($("#israel a[href=#domflights]").hasClass('active')) {
						$("#dealtype").val($("#israel a[href=#domflights]").attr("rel"));
						$("#searchCityFrom").val($("#searchCityFrom_domflight").val())
						$("#date1").val($("#fromDatePicker_domflights").val())
						$("#date2").val($("#toDatePicker_domflights").val())
						}
					if ($("#israel a[href=#domhotels]").hasClass('active')) {
						$("#dealtype").val($("#israel a[href=#domhotels]").attr("rel"));
						$("#searchCityFrom").val($("#searchCityFrom_domhotels").val())
						$("#date1").val($("#fromDatePicker_domhotels").val())
						$("#date2").val($("#toDatePicker_domhotels").val())
						}
					if ($("#israel a[href=#dompackages]").hasClass('active')) {
						$("#dealtype").val($("#israel a[href=#dompackages]").attr("rel"));
						$("#searchCityFrom").val($("#searchCityFrom_dompackages").val())
						$("#date1").val($("#fromDatePicker_dompackages").val())
						$("#date2").val($("#toDatePicker_dompackages").val())
						}
					break;
				}
			}
		return false;
	});
	$(".flights li a").click(function(){
		$("#flights .subtab").hide();
		$(this.hash).show();
		$(".flights li a").removeClass('active');
		$(this).addClass('active');
		if ($(this).attr("rel")) { $("#dealtype").val($(this).attr("rel")); }
		if ($(this).attr("rel") == "CHARTER") { $("#searchCityFrom").val($("#searchCityFrom_charter").val()) }
		return false;
	})
	$("#israel li a").click(function(){
		$("#israel .subtab").hide();
		$(this.hash).show();
		$(".domestic li a").removeClass('active');
		$(this).addClass('active');
		if ($(this).attr("rel")) { $("#dealtype").val($(this).attr("rel")); }
		return false;
	})
});

var min_val = 0;
var max_val = 99999999;
function schedule_filters() {
	if ($("#price_slider").slider("values",0)!=undefined) min_val = $("#price_slider").slider("values",0);
	if ($("#price_slider").slider("values",1)!=undefined) max_val = $("#price_slider").slider("values",1);
	$("#loading_message").show();
	$("#searchResults li").hide();
	if ($("#direct_flights").is(':checked')) { $("#searchResults [rel*=flights_2]").show(); } else { $("#searchResults li").show(); };
	for (var i=0; i<$(".ui-dropdownchecklist-dropcontainer input[type=checkbox]").size(); i++)
      if (!$(".ui-dropdownchecklist-dropcontainer input[type=checkbox]")[i].checked) $("#searchResults [rel*=airline_"+$(".ui-dropdownchecklist-dropcontainer input[type=checkbox]")[i].value+"]").hide();
//	for (var i=0; i<$("#searchResults li").size(); i++) {
//	  if (i<5) ($("#searchResults li")[i].attr("rel"));
//	  }
	$("#searchResults li").each(function(i) {
		var rels = $(this).attr("rel").split(' ');
		for (var i=0; i<rels.length; i++) if (rels[i].substring(0,6)=='price_')
		  if (min_val>parseInt(rels[i].substring(6))||max_val<parseInt(rels[i].substring(6))) $(this).hide();
	});
	$("#loading_message").hide();
	}

$.ajaxSetup ({ cache: false });
function addDays(date,days) {
	this.AddZero = function(val) { return !val || val > 9 ? val : '0'+val }
	var check = ''+this.AddZero(date.getYear()>1900?date.getYear()-2000:date.getYear()-100)+this.AddZero(date.getMonth()+1)+this.AddZero(date.getDate());
	date.setDate(date.getDate()+days);
	if (ARR_DATES[$("#searchCityFrom").val()]) {
		var firstRet = ''+this.AddZero(date.getDate())+'/'+this.AddZero(date.getMonth()+1)+'/'+this.AddZero(date.getYear()>1900?date.getYear():date.getYear()+1900);
		for (p=0; p<ARR_DATES[$("#searchCityFrom").val()][check].length; p++) {
			for (x in ARR_DATES[$("#searchCityFrom").val()][check][p]) {
				temp_date1 = x.substring(0,2)+x.substring(2,4)+x.substring(4,6);
				temp_date2 = firstRet.substring(8,10)+firstRet.substring(3,5)+firstRet.substring(0,2);
				if (temp_date1<temp_date2 || temp_date2==check) firstRet = x.substring(4,6)+'/'+x.substring(2,4)+'/20'+x.substring(0,2);
				}
			}
		}
	return firstRet;
  }

function in_array (needle, haystack) {
	for (x in haystack) if (needle==haystack[x]) return true;
	return false;
  }

function calInfo() {
	if (!in_array($("#dealtype").val(),['CHARTER','NOFSHON']) || !$("#dealtype").val() || !$("#searchCityFrom").val()) {
		ARR_DATES = new Array();
		return false;
	}
	var xml = '<request><function>get_array</function><value>'+$("#searchCityFrom").val()+'</value><argument>'+$("#dealtype").val()+'</argument></request>';
	$.ajax({
	  async: false,
	  type: "POST",
	  url: '/midoffice/checkval.php',
	  processData: false,
	  contentType: "text/xml",
	  dataType: "application/text-xml",
 	  data: xml,
 	  success: function(result) { eval(result); }
	});
  }
function inactiveDates(date) {
	if (!in_array($("#dealtype").val(),['CHARTER','NOFSHON']) || !$("#dealtype").val() || !$("#searchCityFrom").val()) return [true,''];
	if (!ARR_DATES[$("#searchCityFrom").val()]) return [false,''];
	depDate = departure ? departure.substring(8,10)+departure.substring(3,5)+departure.substring(0,2) : '';
	this.AddZero = function(val) { return !val || val > 9 ? val : '0'+val }
	this.retDate = function(date,check) { for (x in check) if (check[x][date]!=undefined) return true; return false; }
	var check = ''+this.AddZero(date.getYear()>1900?date.getYear()-2000:date.getYear()-100)+this.AddZero(date.getMonth()+1)+this.AddZero(date.getDate());
	return [depDate ? this.retDate(check,ARR_DATES[$("#searchCityFrom").val()][depDate]) : ARR_DATES[$("#searchCityFrom").val()][check]!=undefined,''];
	}
jQuery.extend({ getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;
	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});
isRTL = function(str){
  rtlDir = new RegExp('^[^A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF]*[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]');
  return rtlDir.test(str);
  }
  
  
 $(document).ready(function() {
	$_GET = {};
	document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
	function decode(s) {
	    return decodeURIComponent(unescape(s).split("+").join(" "));
	}
	$_GET[decode(arguments[1])] = decode(arguments[2]);
	});
	function select_city(tab, value) {
		$(tab).find('select[name="searchCityFrom"]:eq(0)').val(value);
	}	
	function select_tab() {
		var mode = $_GET["mode"];
		var city = $_GET["searchCityFrom"];
		var destination_name = $_GET["destination_name"];
		$("#searchCityFrom_charter, #searchCityFrom_nofshons, #searchCityFrom_hotel, #searchCityFrom_rentcar , #searchCityFrom_domflight , #searchCityFrom_domhotel , #searchCityFrom_domflight , #searchCityFrom_dompackage").val(city);
		
		if (mode == "searchit") {
			$('#searchCityFrom_schedule').val(city);
			$('#searchCityFrom_value').val(city);
			$('#searchCityFrom_schedule').val(destination_name);
		}
		
		if (mode == "newsearch") {
			$('ul.maintabs li a').removeClass('active');
			$('#wrapper-inner div.tab').hide();
			var dealtype = $_GET["dealtype"];
			if (dealtype == "TOURS") {
				$('ul.maintabs li a:eq(4)').addClass('active');			    
				$("#tours").show();
				$('#searchCityFrom_tours').val(city);
			}
			if (dealtype == "NOFSHON") {
				$('ul.maintabs li a:eq(1)').addClass('active');
				$("#nofshons").show();
				$('#searchCityFrom_nofshons').val(city);
			}
			if (dealtype == "HOTEL") {
				$('ul.maintabs li a:eq(2)').addClass('active');
				$("#hotel").show();
				$('#searchCityFrom_hotel').val(city);
			}
			if (dealtype == "RENTACAR") {
				$('ul.maintabs li a:eq(3)').addClass('active');
				$("#rentcar").show();
				$('#searchCityFrom_rentcar').val(city);
			}
			if (dealtype == "DOMESTIC") {
				$('ul.maintabs li a:eq(5)').addClass('active');
				$("#israel").show();
			}			
			if (dealtype == "CHARTER") {
				$('ul.maintabs li a:eq(0)').addClass('active');
				$("#flights").show().children('div.subtab').hide();
				$('#flights ul.flights li').children('a').removeClass('active');
				$('#flights ul.flights li:eq(1)').children('a').addClass('active');
				$("#flights").children('#charters').show();
				$('#searchCityFrom_charter').val(city);
			}
		}
		
		var slg = $_GET["slg"];
		if (mode == "package" && (slg=="nofshon" || slg=="tour" || slg=="charter" || slg=="family")) {
			$('ul.maintabs li a').removeClass('active');
			$('#wrapper-inner div.tab').hide();
			
			if (slg == "nofshon" || slg=="family") {
			    $('ul.maintabs li a:eq(1)').addClass('active');
			    $("#nofshons").show();
			    $('#dealtype').val('NOFSHON');
			    $('#searchCityFrom').val($('#searchCityFrom_nofshons').val());
			}
			if (slg == "tour") {
			    $('ul.maintabs li a:eq(4)').addClass('active');			    
			    $("#tours").show();
			    $('#dealtype').val('TOURS');
			    $('#searchCityFrom').val($('#searchCityFrom_tours').val());
			}
			if (slg == "charter") {
			    	$('ul.maintabs li a:eq(0)').addClass('active');
				$("#flights").show().children('div.subtab').hide();
				$('#flights ul.flights li').children('a').removeClass('active');
				$('#flights ul.flights li:eq(1)').children('a').addClass('active');
				$('#dealtype').val('CHARTER');
				$("#flights").children('#charters').show();
			}				
		}		
		
		if (mode == "hotelscategories") {
			$('ul.maintabs li a').removeClass('active');
			$('#wrapper-inner div.tab').hide();		    
			$('ul.maintabs li a:eq(2)').addClass('active');
			$("#hotel").show();
			$('#dealtype').val('HOTEL');
			$('#searchCityFrom').val($('#searchCityFrom_hotel').val());
		}		

	}
	select_tab();
	if ( $('#searchCityFrom_value').val() == "" ) {
		$('#searchCityFrom_schedule').css('color','silver');
	}
	else {
		$('#searchCityFrom_schedule').css('color','#363636');
	}	
 });
 
 function hebencode(string) {
	try { return encodeURIComponent(string); }
    catch(err) {
      try { return encodeURI(string); }
      catch(err) { return (string); }
    }
}
