/* probooker.js (c) 2009 - 2010 Sancar Saran last update 23.03.2010 */

var my_book_id     = '';
var current_merken = '';
var curr           = '';
var curr_cover     = '';
var dest           = '';
var dest_href      = '';
var rentacar       = '';
var travel_cost    = 0;
var railway_price  = 0;
var railway_class  = 0;
var insurance_cost = 0;
var rentacar_cost  = 0;
var grand_total    = 0;
var sGTotal        = 0;
var cur_spp_region = 'B';
var cc_from_tit    = 'no';
var ibe_climate_data = [];

//--- Document Ready's
$(document).ready(function() {
	/* Put Bookmark Data */
	put_bookmark();
	tit_init_searchform();
});

function put_bookmark() {
	if(bookmark_data != undefined && bookmark_data != '&nbsp;') {
		bdata = bookmark_data.replace('</div>','');
		$('#merken_cover').html("<h1>IHR MERKZETTEL</h1><div class='box_lr_body'>"+bdata+"</div><div class='box_lr_bottom'>&nbsp;</div>");
		$('#merken_cover').css('display','block');
	}
}

function set_bookmark(bdata) {
	bdata = bdata.replace('</div>', '');
	$('#merken_cover').html("<h1>IHR MERKZETTEL</h1><div class='box_lr_body'>"+bdata+"</div><div class='box_lr_bottom'>&nbsp;</div>");
	if($('#merken_cover').css('display') != 'block') {
		$('#merken_cover').css('display','block');
	}
}

function update_sm_dates_sommer() {
	my_tage = $('#bundesland').val();
	if(my_tage != undefined && my_tage != '') {
		tages = my_tage.split('/');
		$('#outbound_date').val(tages[0]);
		$('#inbound_date').val(tages[1]);
	}
}

function update_sm_dates_bruckentage() {
	my_tage = $('#holidays').val();
	if(my_tage != undefined && my_tage != '') {
		tages = my_tage.split('/');
		$('#outbound_date').val(tages[0]);
		$('#inbound_date').val(tages[1]);
	}
}

function gup( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
		return "";
	} else {
		return results[1];
	}
}
/*
function get_content(tdata,rtype,state) {
	nurl = ibe_ajax+'#'+state;

	$.ajax({
		type: rtype,
		url: nurl,
		data: tdata,
		success: function(ajaxCevap) {
			$('#centcol').html(ajaxCevap);
			titstate = $('#tit-state').attr('title')
			switch (titstate) {
				case 'region':   get_region();   break;
				case 'offers':   get_offers();   break;
				case 'schedule': get_schedule(); break;
			}
		}
	});
	return false;
}*/

// get_region#
function get_region() {
	$('.ibe-region-highlight').hover(function(){
		$(this).addClass('ibe-hover');
	},function(){
		$(this).removeClass('ibe-hover');
	});

	hide_regions();
	unhide = gup('unhide');
	if(unhide != undefined) {
		if(unhide == '' || unhide == undefined) { unhide = 'B'; }
		probooker_unhide = 'region-'+unhide;
	}

	$('.'+probooker_unhide).css('display','block');

	$('.ibe-region-click').click(function(){
		$(this).next().slideToggle('fast');
	});

}

function hide_regions() {
	for ( var i in probooker_unhide ) {
		dest = "."+probooker_unhide[i];
		$(dest).slideToggle('fast');
	}
}

function click_region_row(rurl) {
	window.location = proto+'://'+SERVER_NAME+'/'+rurl;
}

// get_offers#
function get_offers() {

	$('.ibe-offer-hotel-dcover:even').addClass('ibe-row-even');
	$('.ibe-offer-hotel-dcover:odd').addClass('ibe-row-odd');

	$('.ibe-offer-hotel-dcover').hover(function(){
		if ($(this).is(".ibe-row-even")) {
			$(this).removeClass('ibe-row-even');
		} else {
			$(this).removeClass('ibe-row-odd');
		}
		$(this).addClass('ibe-hover');
	},function(){
		$(this).removeClass('ibe-hover');
		$('.ibe-offer-hotel-dcover:even').addClass('ibe-row-even');
		$('.ibe-offer-hotel-dcover:odd').addClass('ibe-row-odd');

	});
	/*
	$('.ibe-offer-pop-icon').each(function() {
		my_height = 120 - parseInt($(this).css('height'));
		$(this).css('top',my_height+'px');
	});
	*/
	$('#offers_pos').change(function() {
		window.location.href = pos_url+"&pos="+this.value;
	});

	$('#offers_limit').change(function() {
		window.location.href = pos_url+"&pos=0&offers_limit="+this.value;
	});

	$('#offers_sort').change(function() {
		sortOption = $('#offers_sort').val();
		if(window.c_place) {
			location.href = pos_url+'&sort='+sortOption+'&place='+c_place;
		} else {
			location.href = pos_url+'&sort='+sortOption;
		}
	});

	$('#place_sort').change(function() {
		sortOption = $('#place_sort').val();
		if(window.c_sort) {
			location.href = pos_url+'&place='+sortOption+'&sort='+c_sort;
		} else {
			location.href = pos_url+'&place='+sortOption;
		}
	});

	$('.roffer-clear-ort').click(function() {
		pos_arr = pos_url.split('&');
		for ( var i in pos_arr ) {
			if(pos_arr[i].match('place')) {
				pos_arr[i] = '';
			}
		}
		back_url = pos_arr.join('&');
		location.href = back_url;
	});

	$('#sort_price').click(function() {
		window.location = base_url+'&sort=0';
	});

	$('#sort_price_href').click(function() {
		window.location = base_url+'&sort=0';
	});

	$('#sort_hotel').click(function() {
		window.location = base_url+'&sort=1';
	});

	$('#sort_hotel_href').click(function() {
		window.location = base_url+'&sort=1';
	});

	$('#sort_place').click(function() {
		window.location = base_url+'&sort=2';
	});

	$('#sort_place_href').click(function() {
		window.location = base_url+'&sort=2';
	});

	$('#sort_operator').click(function() {
		window.location = base_url+'&sort=4';
	});

	$('#sort_operator_href').click(function() {
		window.location = base_url+'&sort=4';
	});
	/*
	$('.bt-classic').bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/infos/slr_classic.html div#content',
		width: 600,
		fill: 'transparent',
		cssStyles: {color: '#003399', fontSize: '10px', width: '600'},
		strokeStyle: 'transparent',
		padding: 10,
		cornerRadius: 10,
		animate: true,
		spikeLength: 15,
		spikeGirth: 5,
		positions: ['right', 'bottom']
	});

	$('.bt-kombi').bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/infos/slr_kombi.html div#content',
		width: 600,
		fill: 'transparent',
		cssStyles: {color: '#003399',fontSize: '10px', width: '600'},
		strokeStyle: 'transparent',
		padding: 10,
		cornerRadius: 10,
		animate: true,
		spikeLength: 15,
		spikeGirth: 5,
		positions: ['right', 'bottom']
	});

	$('.bt-rentacar').bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/mietwagenbed/mw.html div#content',
		width: 600,
		fill: 'transparent',
		cssStyles: {color: '#003399',fontSize: '10px', width: '600'},
		strokeStyle: 'transparent',
		padding: 10,
		cornerRadius: 10,
		animate: true,
		spikeLength: 15,
		spikeGirth: 5,
		positions: ['right', 'bottom']
	});*/
}



function ibe_offers_slide(rownum){
	my_id = '#ibe_offer_'+rownum;
	my_height = parseInt($(my_id).css('height'));

	if ($(my_id).is(":hidden")) {
		$(my_id).slideDown("slow");
	} else {
		$(my_id).slideUp();
	}
}

function open_extra_offers() {
	$('.extra_eof_cover').slideToggle('fast');
}

/* get_schedule#
 *
 *
*/
function get_schedule() {
	$('.ibe-sch-verify-cover').css('height','1px');
	$('.ibe-sch-verify-row').hide();
	$('.ibe-sch-ba-cover').hide();

	$('.ibe-sch-row:even').addClass('ibe-row-even');
	$('.ibe-sch-row:odd').addClass('ibe-row-odd');

	$('.ibe-sch-row').hover(function(){
		if ($(this).is(".ibe-row-even")) {
			$(this).removeClass('ibe-row-even');
		} else {
			$(this).removeClass('ibe-row-odd');
		}
		$(this).addClass('ibe-hover');
	},function(){
		$(this).removeClass('ibe-hover');
		$('.ibe-sch-row:even').addClass('ibe-row-even');
		$('.ibe-sch-row:odd').addClass('ibe-row-odd');
	});

	$('#schedule_pos').change(function() {
		window.location.href = pos_url+"&tpos="+this.value;
	});

	$('#schedule_limit').change(function() {
		window.location.href = pos_url+"&tpos=0&schedule_limit="+this.value;
	});

	$('.ibe-sch-sort').click(function() {
		switch (this.lang) {
			case 'departure': window.location = pos_url+'&tsort=1';   break;
			case 'departure_date':  window.location = pos_url+'&tsort=2';   break;
			case 'duration': window.location = pos_url+'&tsort=3'; break;
			case 'price': window.location = pos_url+'&tsort=0'; break;
		}
	});

	$('#ibe-sch-sort').change(function() {
		switch ($('#schedule_sort').val()) {
			case '1': window.location = pos_url+'&tsort=1';   break;
			case '2':  window.location = pos_url+'&tsort=2';   break;
			case '3': window.location = pos_url+'&tsort=3'; break;
			case '0': window.location = pos_url+'&tsort=0'; break;
		}
	});

	$('#ibe_sch_giata_tabs').tabs();
	//$('#ibe_pikame').PikaChoose({show_captions:false, slide_enabled:false,auto_play:true,show_prev_next:false});
	$('.ui-tabs-panel').css('padding','1px');
	$('.ui-tabs').css('padding','0');
	//--- Panorama navigator
	$('#ibe_giata_panorama_ifrm').attr('src',$('#ibe_giata_panorama_select').val());
	$('#ibe_giata_panorama_select').change(function() {
		$('#ibe_giata_panorama_ifrm').attr('src',$('#ibe_giata_panorama_select').val());
	});
}

function get_flight() {
	$('.rschedule-verify-row').hide();
	$('.rschedule-ba-cover').hide();

	$('.flight-cover').hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});

	$('.flight-cover:even').addClass('row-even');
	$('.flight-cover:odd').addClass('row-odd');

	$('#offers_pos').change(function() {
		window.location.href = pos_url+"&pos="+this.value;
	});

	$('#offers_limit').change(function() {
		window.location.href = pos_url+"&pos=0&offers_limit="+this.value;
	});

	$('#offers_sort').change(function() {
		sortOption = $('#offers_sort').val();
		location.href = pos_url+'&sort='+sortOption
	});
}


function check_booking(my_url,obj,row) {

	curr       = $('#schedule_link_'+row);
	curr_cover = $('#ibe_sch_verify_row_'+row);
	dest       = $('#rs_verify_cover_'+row);
	dest_href  = "#rs_verify_cover_"+row+" > a.schedule-book-link";
	my_book_id = 'book_me_'+row;

	burl   = my_url;
	tdata  = my_url+'&av=true&evoar='+tit_req;
	if(seperator == '&') {
		raw = tdata.split('&');
		raw.splice(0, 1);
		raw = raw.join('&');
	}
	if(seperator == '?') {
		rraw = tdata.split('?');
		raw = rraw[1];
	}

	$("#ibe_sch_popup").dialog({
		bgiframe: true, height:250 ,width: 350,modal: false,draggable:false,resizable:false,title:'Bitten um etwas Geduld...',
		close: function(ev, ui) { $(this).dialog('destroy');  }
	});
	//alert(ajax+' '+raw);
	$.ajax({
		type: 'GET',
		url: ajax,
		data: raw,
		success: function(response) {
			//alert(response);
			rtemp = response.split('<!-- ##### -->');
			$('.ibe-sch-ba-cover').html(rtemp[1]);
			titstate   = $('#tit-state').attr('title');
			titrestart = $('#tit-restart').attr('title');
			message    = $('#bresponse-cover').html();

			switch (titstate) {
				case 'book':
					window.location = burl+'tit_restart=true'
					//$(dest).html(message);
					//$(dest).children().children().children().children().next().next().children().attr('href",burl+'tit_restart=true')
					//$(dest).css('height','40px');
					//$(dest).slideToggle('fast');
					//$(dest).css('display','block');
					return false;
				break;
				case 'weg':
					$(curr_cover).html("<div class='evo-f-left'>"+lang_this_offer_is_weg+"</div><div class='ibe-sch-price'>ausgebucht!</div><div class='evo-c-both-nh'>&nbsp;</div>");
					$("#ibe_sch_popup").dialog('destroy');
					return false;
				break;
				case 'nohit':
					$(curr_cover).html("<div class='evo-f-left'>"+lang_this_offer_is_nohit+"</div><div class='ibe-sch-price'>ausgebucht!</div>");
					$("#ibe_sch_popup").dialog('destroy');
					return false;
				break;
			}
		}
	});
	return false;
}

/* Bookin Form Functions */

function get_book() {
	var d = new Date();
	var curr_year = d.getFullYear();
	var min_year  = curr_year - min_adult_age;
	var max_year  = curr_year - max_adult_age;
	var kmin_year  = curr_year - min_child_age;
	var kmax_year  = curr_year - max_child_age;
	var bmin_year  = curr_year;
	var bmax_year  = curr_year - max_baby_age;

	$('.ibe-price-row:even').addClass('ibe-row-even');
	$('.ibe-price-row:odd').addClass('ibe-row-odd');

	$('#customer_name').keyup(function() {
		$('input#p1_name').val(this.value);
	});

	$('#customer_surname').keyup(function() {
		$('input#p1_surname').val(this.value);
	});


	$('.cResponseCarInfo').click(function() {
		var url = 'http://www.sunnycars.com/b2c.docs/deu.l/single_vehicledetails.html?';
		var indexStore = 0;
		if($('#car_list').attr('selectedIndex') == -1) {
			indexStore = $('#car_list').attr('selectedIndex');
			$('#car_list').attr({ 'selectedIndex': 0 });
		}
		var rentacar = $('#car_list :selected').attr('id');
		aRentacar = rentacar.split('-');
		url = url+'ilvid='+aRentacar[1]+'&&ilssid='+aRentacar[2];
		if(indexStore != 0) {
			indexStore = 0;
			$('#car_list').attr({ 'selectedIndex': -1 });
		}
		window.open(url,'carInfo','width=720,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=no');
		return false;
	});
	$('#travel_operator_info_link').click(function() {
		code = this.rel;
		url = 'http://www.lmweb.net/lmi/agb/agb_' + code + '.htm';
		window.open(url,'hotelInfo','width=720,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
		return false;
	});
	$('#travel_packer_info_link').click(function() {
		code = this.rel;
		url = 'http://www.lmweb.net/lmi/agb/agb_' + code + '.htm';
		window.open(url,'hotelInfo','width=720,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
		return false;
	});
	$('#site_owner_info_link').click(function() {
		window.open(site_owner_url,'hotelInfo','width=720,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
		return false;
	});

	if($('#bookmarkPanelCoverDIV').html() != '&nbsp;') {
		$('#bookmarkPanelCoverDIV').css('visibility',('visible'));
	}
	$('#tit_booking').validate();

	//$('.ibe-book-trav-age').mask('99.99.9999');

	/*
	$('#rf_tooltip').bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/zugzumflug/zugzumflug.html div#content',
		width: 600,
		fill: '#003399',
		cssStyles: {color: 'white', fontSize: '10px', width: 'auto'},
		strokeStyle: '#003399',
		padding: 10,
		cornerRadius: 10,
		animate: true,
		spikeLength: 15,
		spikeGirth: 5,
		positions: ['left', 'right', 'bottom']
	});

	$('#mw_tooltip').bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/mietwagenbed/mw_info.html div#content',
		width: 600,
		fill: '#003399',
		cssStyles: {color: 'white', fontSize: '10px', width: 'auto'},
		strokeStyle: '#003399',
		padding: 10,
		cornerRadius: 10,
		animate: true,
		spikeLength: 15,
		spikeGirth: 5,
		positions: ['left', 'right', 'bottom']
	});*/

	$('.ibe-tage-C').datepicker({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/fileadmin/evo_live/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Angabe des Geburtsdatums',
		dateFormat: 'dd.mm.yy',
		yearRange: max_year+':'+min_year,
		changeMonth: true,
		changeYear: true,
		onSelect: function() {
			updateMyField(this.id);
			return {};
		}
	});

	$('.ibe-tage-A').datepicker({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/fileadmin/evo_live/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Angabe des Geburtsdatums',
		dateFormat: 'dd.mm.yy',
		yearRange: max_year+':'+(kmax_year-1),
		changeMonth: true,
		changeYear: true,
		onSelect: function() {
			updateMyField(this.id);
			return {};
		}
	});

	$('.ibe-tage-K').datepicker({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/fileadmin/evo_live/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Angabe des Geburtsdatums',
		dateFormat: 'dd.mm.yy',
		yearRange: kmax_year+':'+kmin_year,
		changeMonth: true,
		changeYear: true,
		onSelect: function() {
			updateMyField(this.id);
			return {};
		}
	});

	$('.ibe-tage-B').datepicker({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/fileadmin/evo_live/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Angabe des Geburtsdatums',
		dateFormat: 'dd.mm.yy',
		yearRange: bmax_year+':'+bmin_year,
		changeMonth: true,
		changeYear: true,
		onSelect: function() {
			updateMyField(this.id);
			return {};
		}
	});

	$("#p1_age_show").click(function() { // Call your event
		$("#p1_age").datepicker('show');
	});

	$("#p2_age_show").click(function() { // Call your event
		$("#p2_age").datepicker('show');
	});

	$("#p3_age_show").click(function() { // Call your event
		$("#p3_age").datepicker('show');
	});

	$("#p4_age_show").click(function() { // Call your event
		$("#p4_age").datepicker('show');
	});

	$("#p5_age_show").click(function() { // Call your event
		$("#p5_age").datepicker('show');
	});

}

function updateMyField(myId) {
	$('#'+myId+'_show').html($('#'+myId).val());
}

function toggle_carrental(stat) {
	if(stat == 'disabled') {
		$('#rent_a_car').val('');
		$('#car_list').attr({ 'selectedIndex': -1 });
		$('#car_list').attr({ 'disabled': true });
		updatePrice('rentacar','type2',0);
	}
	if(stat == 'enabled') {
		$('#car_list').removeAttr('disabled');
	}
}

function updatePrice(part,type2,price) {

	if(part == 'insurance') {
		cIPrice = price * adult_amount;
		$('#insurance_cost').val(cIPrice);
		ilabel = 'RRV';
		if(type2 == 'none') {
			type2 = '';
			ilabel = 'None';
		}
		if(type2 == 'no') {
			ilabel = 'None';
		}
		if(type2 == 'VSP') {
			ilabel = 'Paket';
		}
		$('#travel_insurance').val('Vers.-Total-'+ilabel+':'+cIPrice);
	}

	if(part == 'railway') {
		if(type2 == 'no') {
			$('#railway_cost').val(0);
			railway_price = 0;
			railway_class = 0;
			$('#railway_cls').val('no');
		}
		if(type2 == 'first') {
			$('#railway_cost').val(railway_travellers*price);
			railway_price = price;
			railway_class = 1;
			$('#railway_cls').val('first_class');
		}
		if(type2 == 'second') {
			$('#railway_cost').val(railway_travellers*price);
			railway_price = price;
			railway_class = 2;
			$('#railway_cls').val('second_class');
		}
	}

	rentacar = $('#car_list').val();
	if(rentacar != null) {
		aRentacar = rentacar.split(':');
		$('#rentacar_cost').val(aRentacar[1]);
		$('#rent_a_car').val(rentacar);
	} else {
		$('#rentacar_cost').val(0);
		$('#rent_a_car').val('');
	}

	travel_cost    =  parseInt($('#travel_cost').val());
	insurance_cost =  parseInt($('#insurance_cost').val());
	rentacar_cost  =  parseInt($('#rentacar_cost').val());
	railway_cost   =  parseInt($('#railway_cost').val());

	if(insurance_cost == 0 || isNaN(insurance_cost)) { insurance_cost = 0; }
	if(rentacar_cost == 0 || isNaN(rentacar_cost)) { rentacar_cost = 0; }

	grand_total   = travel_cost + insurance_cost + rentacar_cost + railway_cost;

	$('#insurance_price').html(insurance_cost+'');
	$('#rentacar_price').html(rentacar_cost+'');
	$('#railway_price').html(railway_cost+'');

	sGTotal = grand_total+'';

	if(sGTotal.length > 3) {
		if(sGTotal.length > 6) {
			alert('value too high');
		} else {
			var limit    = sGTotal.length - 3;
			var hundrets = sGTotal.substring(limit);
			var tousants = sGTotal.substring(0,limit);
			grand_total = tousants+'.'+hundrets;
		}
	}

	$('#total_cost').val(sGTotal);
	grand_total = grand_total;
	$('#grand_total').html(grand_total);
}

function getPaymentForm(mode) {
	var form_data = '';

	switch (mode) {
		case "direct":
		form_data+= "&nbsp;";
		$('#direct_payment').val('0');
		$('#hamili').val('0');
		$('#payment_mode').val('3');
		break;

		case "bank":
		form_data+= $('#ibe_bank_transfer_cover').html();
		$('#direct_payment').val('1');
		$('#hamili').val('0');
		$('#payment_mode').val('2');
		break;

		case "ccard":
		form_data+= $('#ibe_cc_cover').html();
		$('#direct_payment').val('1');
		$('#hamili').val('1');
		$('#payment_mode').val('1');
		break;

		case "transfer":
		form_data+= $('#ibe_transfer_payment_cover').html();
		$('#direct_payment').val('1');
		$('#hamili').val('1');
		$('#payment_mode').val('4');
		break;
	}
	$('#reponse_payement_method').html(form_data);
}


function jsPrintOut(strWinId,objectId,pType) {
	if (window.print) {
		text  = document.getElementById(objectId).innerHTML;
		winId = window.open('about:blank',strWinId);
		if(winId) {
			with (winId.document) {
				write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
				write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">');
				write('<link href="/fileadmin/css/main.css" rel="stylesheet" type="text/css" \/>');
				write('<!--[if lte IE 7]><link href="/fileadmin/css/patches/patch_main.css" rel="stylesheet" type="text/css" \/><![endif]-->');
				write('<link rel="stylesheet" type="text/css" href="/fileadmin/evo_live/site/css/evo_live.css" \/>');
				write('<link rel="stylesheet" type="text/css" href="/fileadmin/evo_live/site/css/site.css" \/>');
				write('<link rel="stylesheet" type="text/css" href="/fileadmin/evo_live/site/css/jquery-ui/jquery-ui.css" \/>');
				write('<link rel="stylesheet" type="text/css" href="/fileadmin/evo_live/modules/probooker/templates/css/probooker.css" \/>');
				write('<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <\/head>')
				write('<body style="width:590px;text-align:left;font-family:arial">');
				write('<img src="/fileadmin/images/logo_pring.jpg" alt="logo"\/><br \/><br \/>'+text+'<\/body><\/html>');
				winId.focus();
				winId.print();
			}
		} else {
			alert("Wir haben festgestellt, dass Sie in Ihrem Browser Popup-Blocker verwenden. \n Bitte schalten Sie den Popup-Blocker in Ihrem Browser aus, um Druck-Funktion nutzen zu können. \n");
			winId.close()
		}
	}
}

//--- Bookmark a termin function
function add_bookmark(bdata) {
	alert(book_req);
	$.post(ajax,{
		av: "true",
		evoar: book_req,
		data: bdata,
		action: "add"
		}, function(response) {
			rtemp = response.split('<!-- ##### -->');
			bookmark_data = rtemp[1];
			set_bookmark(rtemp[1]);
			display_bookmark_info();
			tdata  = '&av=true&evoar='+book_req+'&data='+bdata+'&action=list';
		}
	);
	return false;
}

//--- Bookmark a termin function
function display_bookmark_info() {
	$(dest).children().next().html(bookmark_data);
	$(dest).children().next().css('display','block');
	$(dest).css('height','60px');
}

function erase_bookmark_info() {

}

//--- Bookmark a termin function
function fetch_bookmark(bookmark_id,c_merken) {
	current_merken = c_merken;
	if(cbookmarks != undefined) {
		if(cbookmarks[bookmark_id] != undefined) {
			add_bookmark(cbookmarks[bookmark_id]);
		}
	}
	return false;
}

function bookmarkIt(baction,bdata,tid,elm) {
	$.post(ajax,{
		evoar: book_req,
		data: bdata,
		action: baction,
		av: 'true'
		}, function(html) {
			rtemp = html.split('<!-- ##### -->');
			html = rtemp[1];
			if(baction == 'delete_all') {
				bookmark_data = '&nbsp;';
				$('#merken_cover').html('&nbsp;');
				$('#merken_cover').css('display','none');
				$('#bookmark-list-cover').html(html);
				$('.merken-cover-td').html('&nbsp;');
				$('.merken-cover-td').css('display','none');
			} else if(baction == 'add') {
				bookmark_data = html;
				put_bookmark();
				display_bookmark_info();

				tdata  = '&av=true&evoar='+book_req+'&data='+bdata+'&action=list';
				$.ajax({type: 'POST',url: ajax,data: tdata,success: function(list_html) {
						rtemp = list_html.split('<!-- ##### -->');
						$("#ibe_storage").html('');
						$("#ibe_storage").dialog({
							bgiframe: true, height:450 ,width: 550,modal: false,draggable:false,resizable:false,title:lang_bookmark_list,
							close: function(ev, ui) { $("#ibe_storage").html(''); $(this).dialog('destroy');  }
						});
						$("#ibe_storage").html("<div id='bookmark-list-cover'>"+rtemp[1]+"<\/div>");
					}
				});
			} else {
				if(baction == 'list' || baction == 'print') {
					$("#ibe_storage").html('');
					$("#ibe_storage").dialog({
						bgiframe: true, height:450 ,width: 550,modal: false,draggable:false,resizable:false,title:lang_bookmark_list,
						close: function(ev, ui) { $("#ibe_storage").html(''); $(this).dialog('destroy');  }
					});
					$("#ibe_storage").html("<div id='bookmark-list-cover'>"+html+"<\/div>");
					if(baction == 'print') {
 						jsPrintOut('PWindow','print_div','merken');
						$("#ibe_storage").html('');
						$("#ibe_storage").dialog('destroy');
					}
				}
				if(baction == 'email') {
					$("#ibe_storage").html('');
					$("#ibe_storage").dialog({
						bgiframe: true, height:450 ,width: 550,modal: false,draggable:false,resizable:false,title:lang_bookmark_list,
						close: function(ev, ui) { $("#ibe_storage").html(''); $(this).dialog('destroy');  }
					});
					$("#ibe_storage").html("<div id='bookmark-list-cover'>"+html+"<\/div>");

					$('.bmark-mail-back').click(function(){
						$("#ibe_storage").html('');
						$("#ibe_storage").dialog('destroy');
					});

					$('#bookmark_post').validate();
					$('#bookmark_post').submit(function() {
						if($('#bookmark_post').valid() != false) {
							$('#form_submit_td').html("<img src='/fileadmin/images/loading_2.gif' alt='' />");
							$('#evoar').val(book_req);
							$.ajax({type: 'POST',url: ajax,data: $('#bookmark_post').serialize(),success: function(eformc) {
									rtemp = eformc.split('<!-- ##### -->');
									$('#bookmark-mail-cover').html(rtemp[1]);
									$('.bmark-mail-back').click(function(){
										$("#ibe_storage").html('');
										$("#ibe_storage").dialog('destroy');
									});
								}
							});
						}
						return false;
					});
				}
			}

		}
	);
}

function delete_bookmark(bid) {
	$.post(ajax,{
		evoar: book_req,
		bid: bid,
		action: "delete",
		av: 'true'
		}, function(response) {
			rtemp = response.split('<!-- ##### -->');
			$('#bookmark-list-cover').html(rtemp[1]);
		}
	);
}

function get_own_data(info_url) {
	window.open(info_url,'own_info','width=800,left=5,top=10, scrollbars=yes');
}

function wrap_form_values(form) {
	form = "#" + form + " :input";
	form = $(form).serializeArray();
	var data_aray = new Object();

	for( index in form) {
		if(form[index].value)   {
			data_aray[form[index].name] = form[index].value;
		}
	}
	return data_aray;
}

function tit_Detail(Rec,titq) {
	if(titq == undefined || titq == '' || titq == false || titq == 'false') {
		titq = tit_query;
	}
	DetailUrl =  tit_server+titq+'&DETAILS=1&REC='+Rec;
	tit_Open_Window(DetailUrl, 'DETAIL', 'scrollbars=yes,resizable=yes',800,600)
}

function tit_RDetail(Rec) {
	DetailUrl =  'http://www.zielgebietsinfo.de/'+Rec+'.html';
	tit_Open_Window(DetailUrl, 'DETAIL', 'scrollbars=yes,resizable=yes',800,600)
}
/**
 * tit_GDetail
 *
 * Hotel information detail from GIATA hotel info db
 *
 * @author Sancar Saran <sancar.saran@evodot.com>
 * @version 1.0
**/
function tit_GDetail(hname,place,giata_id,veranst,cache_crc) {

	$.ajax({
		type: 'GET',
		url: ajax,
		data: '&evoar='+giata_req+'&place='+place+'&name='+hname+'&giata_id='+giata_id+'&operator='+veranst+'&crc='+cache_crc,
		success: function(response) {
			//alert(response);
			rtemp = response.split('<!-- ##### -->');
			html = rtemp[1];
			$('#ibe_storage').html(html);
			$('#ibe_giata_info_tabs').tabs();
			$('#ibe_giata_info_cover').dialog({
				bgiframe: true, height:whpercent_50 ,width: wwpercent_80,modal: true,draggable:false,resizable:false,title:'hotel info',
				close: function(ev, ui) {
					$('#ibe_giata_info_tabs').tabs('destroy');
					//$('#ibe_storage').html('&nbsp;');
					$(this).dialog('destroy');
				}
			});
			/*
			$('#ibe_pikame').PikaChoose({show_captions:false, slide_enabled:false,auto_play:true,show_prev_next:false});
			bar_height = parseInt($('#ibe_pikame').css('height'));
			my_height = parseInt($('#ibe_giata_info_pics').css('height'));
			new_height = bar_height+my_height;
			$('#ibe_giata_info_pics').css('height',new_height+'px');
			*/
			//--- Panorama navigator
			$('#ibe_giata_panorama_ifrm').attr('src',$('#ibe_giata_panorama_select').val());
			$('#ibe_giata_panorama_select').change(function() {
				$('#ibe_giata_panorama_ifrm').attr('src',$('#ibe_giata_panorama_select').val());
			});
		}
	});
}

/**
 * hdb_info#
 *
 * Hotel information detail from evodot hdb system
 *
 * @author Sancar Saran <sancar.saran@evodot.com>
 * @version 1.0
**/
function hdb_info(gid,vc,iff,perf,acc,tinfo) {
	pdata = '&evoar='+giata_req+'&gid='+gid+'&vc='+vc+'&iff='+iff+'&perf='+perf+'&acc='+acc+'&tinfo='+tinfo;
	$.ajax({
		type: 'GET',
		url: ajax,
		data: pdata,
		success: function(response) {
			//alert(response);
			$('#ibe_storage').html('&nbsp;');
			rtemp = response.split('<!-- ##### -->');
			html = rtemp[1];
			$('#ibe_storage').html(html);
			$('#ibe_giata_info_tabs').tabs();
			$('#ibe_storage').dialog({
				bgiframe: true, height:whpercent_70 ,width: wwpercent_80,modal: true,draggable:false,resizable:false,title:'hotel info',
				close: function(ev, ui) {
					$('#ibe_storage').html('&nbsp;');
					$('#ibe_storage').dialog('destroy');
				}
			});
			//--- Panorama navigator
			$('#ibe_giata_panorama_ifrm').attr('src',$('#ibe_giata_panorama_select').val());
			$('#ibe_giata_panorama_select').change(function() {
				$('#ibe_giata_panorama_ifrm').attr('src',$('#ibe_giata_panorama_select').val());
			});
		}
	});
}

function tit_Open_Window(Url,WindowName,Options,ww,wh) {
	WindowParam = Options + ',left='+(screen.width-ww)/2 + ',top='+(screen.height-wh)/2+',width='+ww+',height='+wh
	NewWindow=window.open(Url, WindowName, WindowParam);
	return NewWindow
}



/**
* tit_init_searchform#
* inits travel it search form events
*
* @author Sancar Saran <sancar.saran@evodot.com>
* @version 1.0
*/
function tit_init_searchform() {
	if(datepicker_months == undefined) {
		var datepicker_months = 2;
	}
	//--- Load Destination hotel names for hotel name auto show
	$('#outbound_destination').change(function() {
		prep_hotel_name();
	});

	//--- Hotel Name Field
	$('#hotel_name').click(function(){
		prep_hotel_name();
	});

	//--- Search form submit event
	$('#probooker_search').submit(function(){
		//--- Clear Hotel name default value
		if(hotel_name_label == $('#hotel_name').val()) {
			$('#hotel_name').val('');
		}
		checkRange();
	});

	//--- jQuery Datepicker plugin with custom range check init
	init_mask_date(datepicker_months);

	//--- Multi Departure
	$('#outbound_departure1').change(function() {
		generate_departure();
	});

	$('#outbound_departure2').change(function() {
		generate_departure();
	});

	$('#outbound_departure3').change(function() {
		generate_departure();
	});

	$('#outbound_departure4').change(function() {
		generate_departure();
	});
}


/**
 * prep_hotel_name#
 *
 * Prepares hotel_name field for searchmasks
 *
 * @author Sancar Saran <sancar.saran@evodot.com>
 * @version 1.0
**/
function prep_hotel_name() {
	$('#hotel_name').val('');
	get_hotel_names();
}

/**
 * get_hotel_names
 *
 * loads external hotel names related to destination (or main)
 *
 * @author Sancar Saran <sancar.saran@evodot.com>
 * @version 1.0
**/
function get_hotel_names(){
		dest = $('#outbound_destination').val();
		if(dest.length == 3) {
			load_ext_hotel_names(dest);
		} else {
			load_ext_hotel_names('main');
		}
}

/**
 * load_ext_hotel_names#
 * loads destination spesific hotel names in js array
 *
 * @author Sancar Saran <sancar.saran@evodot.com>
 * @version 1.0
**/
function load_ext_hotel_names(dest){
	hname = auto_complete_data_path+'hotels_'+dest+'.php';
	$.ajax({
		type: 'GET',
		url: hname,
		success: function(ajaxCevap) {
		var hotel_names = ajaxCevap.split('|');
		$('#hotel_name').flushCache();
		$('#hotel_name').autocomplete(hotel_names);
		}
	});
}


/**
* checkRange
* checks two dates
*
* @author Sancar Saran <sancar.saran@evodot.com>
* @version 1.0
*/
function checkRange(input) {
	outbound_date = humanToTime($('#outbound_date').val());
	inbound_date  = humanToTime($('#inbound_date').val());
	if(outbound_date >= inbound_date) {
		inbound_date = outbound_date + (86400 * 21);
		$('#inbound_date').val(timeToHuman(inbound_date));
	}
}

function putDate(btime,range,direction) {

	if(btime == 'today') {
		myDate     = new Date();
		curr_date  = myDate.getDate();
		curr_month = myDate.getMonth();
		curr_month = curr_month + 1;
		curr_year  = myDate.getFullYear();
		btime      = curr_date + '.'+ curr_month + '.'+ curr_year;
	}

	time = humanToTime(btime);
	diff = (86400 * range);
	if(direction == 'b') {
		new_time = time - diff;
	} else {
		new_time = time + diff;
	}

	new_time = timeToHuman(new_time);
	return new_time;
}

function humanToTime(date) {
	aDate = date.split('.');
	Day   = sLZero(aDate[0]);
	Month = sLZero(aDate[1]);
	Year  = aDate[2];
	//hDate = new Date(Year,Month-1,Day,0,0,0);
	hDate = parseInt(new Date(Year,Month-1,Day,0,0,0).getTime().toString().substring(0, 10));
	return hDate;
}

function humanToJsDate(date) {
	aDate = date.split('.');
	var jsDate = new Date(aDate[2],(sLZero(aDate[1])-1),sLZero(aDate[0]),0,0,0);
	return jsDate;
}

function timeToHuman(time) {
	theDate = new Date(time * 1000);
	day     = theDate.getDate();
	month   = theDate.getMonth()+1;
	year    = theDate.getFullYear();
	if(day < 10) { day = '0'+day+''; }
	if(month < 10) { month = '0'+month+''; }
	sDate  = day+'.'+month+'.'+year+'';
	return sDate;
}

function dayName(time) {
	theDay  = new Date(time * 1000);
	dName   = day_names[theDay.getDay()]
	return dName.substr(0,2);
}

function sLZero(input) {
	if(isNaN(input)) { return false; }
	if((input.length > 1) && (input.substr(0,1) == '0')) {
		val = input.substr(1);
	} else {
		val = input;
	}
	val =  parseInt(val);
	return val;
}

/**
* init_mask_date#
* init search form date
*
* @author Sancar Saran <sancar.saran@evodot.com>_
* @version 1.0
*
*		beforeShow: function() {
*			checkRange();
*			return {};
*		},
*
*
*		afterShow: function() {
*			checkRange();
*			return {};
*		},

*		onSelect: function(date) {
*			checkRange();
*		},
*
*/
function init_mask_date(no_of_months) {
	if(no_of_months == undefined || no_of_months == 0) { no_of_months = 1;}

	$('#outbound_date').datepicker({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/fileadmin/evo_live/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Früheste Hinreise',
		minDate: '1d',
		dateFormat: 'dd.mm.yy',
		numberOfMonths: parseInt(no_of_months),
		showButtonPanel: true,
		yearRange: '-0:2+',
		defaultDate: +1,
		onSelect: function() {
			updateOutField();
			return {};
		}
	});

	$('#inbound_date').datepicker({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/fileadmin/evo_live/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Späteste Rückreise',
		minDate: '3d',
		dateFormat: 'dd.mm.yy',
		numberOfMonths: parseInt(no_of_months),
		showButtonPanel: true,
		yearRange: '-0:2+',
		defaultDate: +21,
		onSelect: function() {
			updateInField();
			return {};
		}
	});
}

function updateOutField() {
	$('#ibe_outbound_date_show').html($('#outbound_date').val());
}

function updateInField() {
	$('#ibe_inbound_date_show').html($('#inbound_date').val());
}


/**
* generate_departure
* generate multi departure string for tit
*
* @author Sancar Saran <sancar.saran@evodot.com>
* @version 1.0
*/
function generate_departure() {
	dest1 = $('#outbound_departure1').val();
	dest2 = $('#outbound_departure2').val();
	dest3 = $('#outbound_departure3').val();
	dest4 = $('#outbound_departure4').val();

	departure = '';

	if(dest1 != '') {
		departure = dest1;
	}

	if(dest2 != '') {
		if(departure != '') {
			departure = departure+'x'+dest2;
		} else {
			departure = dest2;
		}
	}

	if(dest3 != '') {
		if(departure != '') {
			departure = departure+'x'+dest3;
		} else {
			departure = dest3;
		}
	}

	if(dest4 != '') {
		if(departure != '') {
			departure = departure+'x'+dest4;
		} else {
			departure = dest4;
		}
	}

	$('#outbound_departure').val(departure);
}

/**
* prepost_age_check
* age check for booking form
*
* @author Sancar Saran <sancar.saran@evodot.com>
* @version 1.0
*/
function prepost_age_check() {
	my_r = true;
	my_a = false;
	$('.trv-age').each(function() {

		if($(this).val() == 'TT.MM.JJJJ') {
			my_r = false;
			my_a = 'Bitte vergessen Sie nicht, das Geburtsdatum einzutragen!';
		}
	});
	if(my_a != false) {
		alert(my_a);
	}
	return my_r;
}

