/* Protravel protravel.js (c) 2009 Sancar Saran last update 17.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';

//--- Document Ready's
$(document).ready(function() {
	/* Put Bookmark Data */
	put_bookmark();
	tit_init_searchform();
	$('#outbound_destination').change(function() {
		$('#hotel_name').val('');
	});
	$(".jqfancybox").fancybox({ "hideOnContentClick": 0, "zoomSpeedIn":500,"zoomSpeedOut":500,"overlayShow":1, "overlayOpacity":0.9});

});

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;
}

function get_region() {
	$(".rregion-region-tr").hover(function(){
		$(this).addClass("ui-state-hover");
		$(this).addClass("cuPointer");
	},function(){
		$(this).removeClass("ui-state-hover");
		$(this).removeClass("cuPointer");
	});

	$(".rregion-area-tr").hover(function(){
		$(this).addClass("ui-state-hover");
		$(this).addClass("cuPointer");
	},function(){
		$(this).removeClass("ui-state-hover");
		$(this).removeClass("cuPointer");
	});

	hide_regions();
	unhide = gup("unhide");
	if(unhide != undefined) {
		if(unhide == '') { unhide = 'B'; }
		protravel_unhide = 'region-'+unhide;
	}

	$('.'+protravel_unhide).css("display","block");
	if(undefined === window.tit_collect['data_type']){

	} else {
		if(tit_collect['data_type'] == 'epackage') {
			var epk_cookie = $.cookie("epackage");
			if(epk_cookie == null || epk_cookie == false || epk_cookie == ''){
				$("#epackage_popup").dialog({
					bgiframe: true, height:150 ,width: 350,modal: false,draggable:false,resizable:false,title:'Hinweis !',
					close: function(ev, ui) { $("#epackage_popup").html(""); $(this).dialog('destroy');  }
				});

				$("#epackage_popup").html("Bitte beachten Sie, dass die hier voreingestellten Altersangaben der Kinder für 5 Jahre betragen.<br />Passen Sie bitte in der Suchmaske die Altersangaben Ihrer Kinder entsprechend an!");
				$.cookie("epackage","SET");
			} else {

			}
		}
	}

}

function hide_regions() {
	for ( var i in protravel_unhide ) {
		dest = "."+protravel_unhide[i];
		$(dest).slideToggle("fast");
	}

	$(".rregion-region-tr").click(function(){
		$(this).parent().parent().next().slideToggle("fast");
	});
}

function click_region_row(rurl) {
	window.location = proto+'://'+SERVER_NAME+'/'+rurl;
}

function get_offers() {
	$(".roffer-detail-tr").hover(function(){
		$(this).addClass("ui-state-hover");
	},function(){
		$(this).removeClass("ui-state-hover");
	});

	$("#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+'&place='+c_place;
	});

	$('#place_sort').change(function() {
		sortOption = $("#place_sort").val();
		location.href = pos_url+'&place='+sortOption+'&sort='+c_sort;
	});

	$(".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;
	});


	$('.roffer-detail-table tr:even').addClass("row-even");
	$('.roffer-detail-table tr:odd').addClass("row-odd");

	$("#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#mainContent',
		cssStyles: {color: '#003399', fontSize: '10px',background:'#fff'},
		width: 595,
		fill: '#fff',
		strokeStyle: '#fff',
		padding: 0,
		cornerRadius: 0,
		animate: true,
		spikeLength: 15,
		spikeGirth: 0,
		positions: ['right', 'bottom']
	});

	$(".bt-kombi").bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/infos/slr_kombi.html div#mainContent',
		cssStyles: {color: '#003399',fontSize: '10px', width: '595px',background:'#fff'},
		width: 595,
		fill: '#fff',
		strokeStyle: '#fff',
		padding: 0,
		cornerRadius: 0,
		animate: true,
		spikeLength: 15,
		spikeGirth: 0,
		positions: ['right', 'bottom']
	});

	$(".bt-rentacar").bt({
		ajaxPath: '/fileadmin/Redaktion_SLR/service/mietwagenbed/mw.html div#content',
		cssStyles: {color: '#003399',fontSize: '10px',background:'#fff'},
		fill: '#fff',
		strokeStyle: '#fff',
		padding: 0,
		cornerRadius: 0,
		animate: true,
		spikeLength: 15,
		spikeGirth: 0,
		positions: ['right', 'bottom']
	});

}

function open_extra_offers() {
	$(".extra_eof_cover").slideToggle("fast");
}

function get_schedule() {
	$(".rschedule-verify-cover").css('height','1px');
	$(".rschedule-verify-row").hide();
	$(".rschedule-ba-cover").hide();

	$(".rschedule-row").hover(function(){
		$(this).addClass("ui-state-hover");
	},function(){
		$(this).removeClass("ui-state-hover");
	});

	$('.rschedule-row:even').addClass("row-even");
	$('.rschedule-row:odd').addClass("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;
	});

	$(".rschedule-ba-row").hide();

	$(".schedule-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;
		}
	});

	$("#schedule_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;
		}
	});
}

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 = $("#rschedule_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;
	burl   = 'https://'+SERVER_NAME+'/'+my_url;
	//burl   = 'http://'+SERVER_NAME+'/'+my_url;
	tdata  = my_url+'&av=true&evoar='+tit_ar;

	if(seperator == '&') {
		raw = tdata.split('&');
		raw.splice(0, 1);
		raw = raw.join('&');
	}
	if(seperator == '?') {
		rraw = tdata.split('?');
		raw = rraw[1];
	}
	
	//popBoxy = '';
	//$("#extra_message_cover").css("color","#033568");
	//$("#extra_message_cover").html('<span class="text1">Uno momento ...</span><br><span class="text2">Wir prüfen diese Reise direkt beim Veranstalter</span>');
	//boxy_content = $("#schedule_popup").html();
	//boxy_title   = '';
	//popBoxy = new Boxy(boxy_content,{ draggable: true ,  closeText: lang_close});
	//popBoxy.resize(300,200);
	$("#schedule_popup").dialog({
		bgiframe: true, height:250 ,width: 350,modal: false,draggable:false,resizable:false,title:'Wir bitten um etwas Geduld...',
		close: function(ev, ui) { $(this).dialog('destroy');  }
	});
	$.ajax({
		type: 'GET',
		url: ibe_ajax,
		data: raw,
		success: function(response) {
			rtemp = response.split("<!-- ##### -->");

			$(".rschedule-ba-cover").html(rtemp[1]);
			titstate   = $("#tit-state").attr("title");
			titrestart = $("#tit-restart").attr("title");
			message    = $("#bresponse-cover").html();
			//titstate = 'weg';
			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='fLeft'>"+lang_this_offer_is_weg+"</div><div class='rschedule-price'>ausgebucht!</div><div class='clLeftNh'>&nbsp;</div>");
					setTimeout('$("#schedule_popup").dialog("destroy"); ', 1000);
					return false;
				break;
				case 'nohit':
					$(curr_cover).html("<div class='fLeft'>"+lang_this_offer_is_nohit+"</div><div class='rschedule-price'>ausgebucht!</div>");
					setTimeout('$("#schedule_popup").dialog("destroy"); ', 1000);
					return false;
				break;
			}
		}
	});
	return false;
}

function check_fbooking(my_url,obj,row) {

	var curr       = $("#schedule_link_"+row);
	var curr_cover = $("#rschedule_verify_row_"+row);
	var dest       = $("#rs_verify_cover_"+row);
	var dest_href  = "#rs_verify_cover_"+row+" > a.schedule-book-link";
	my_book_id     = 'book_me_'+row;

	burl   = 'https://'+SERVER_NAME+'/'+my_url;
	tdata  = my_url+'&av=true&evoar='+tit_ar;

	if(seperator == '&') {
		raw = tdata.split('&');
		raw.splice(0, 1);
		raw = raw.join('&');
	}
	if(seperator == '?') {
		rraw = tdata.split('?');
		raw = rraw[1];
	}

	$.ajax({
		type: 'GET',
		url: ibe_ajax,
		data: raw,
		success: function(response) {
			rtemp = response.split("<!-- ##### -->");

			$(".rschedule-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'
					return false;
				break;
				case 'weg':
					$(curr_cover).html("<div class='fLeft'>"+lang_this_offer_is_weg+"</div><div class='rschedule-price'>ausgebucht!</div><div class='clLeftNh'>&nbsp;</div>");
					return false;
				break;
				case 'nohit':
					$(curr_cover).html("<div class='fLeft'>"+lang_this_offer_is_nohit+"</div><div class='rschedule-price'>ausgebucht!</div>");
					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;


	$('#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 = proto+'://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 = proto+'://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 = proto+'://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();

	$("#rf_tooltip").bt({
		ajaxPath: proto+'://'+SERVER_NAME+'/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: proto+'://'+SERVER_NAME+'/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']
	});

	$('#customer_note').keyup(function(){
		limitChars('customer_note', 40, 'charleft');
	});

	$('.ibe-tage-C').datepick({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/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').datepick({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/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').datepick({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/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').datepick({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/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").datepick('show');
	});

	$("#p2_age_show").click(function() { // Call your event 
		$("#p2_age").datepick('show');
	});

	$("#p3_age_show").click(function() { // Call your event 
		$("#p3_age").datepick('show');
	});

	$("#p4_age_show").click(function() { // Call your event 
		$("#p4_age").datepick('show');
	});

	$("#p5_age_show").click(function() { // Call your event 
		$("#p5_age").datepick('show');
	});
}

function updateMyField(myId) {
	$('#'+myId+'_show').html($('#'+myId).val());
}


function limitChars(textid, limit, infodiv) {
	var my_text = $('#'+textid).val(); 
	var textlength = my_text.length;
	if(textlength > limit) {
		//$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(my_text.substr(0,limit));
		return false;
	} else {
		//$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		//$('#' + infodiv).html((limit - textlength));
		return true;
	}
 }

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;
		$('#insurance_cost').val(cIPrice);
		ilabel = 'RRV';
		if(type2 == 'none') { 
			type2 = ''; 
			ilabel = '';
		}
		if(type2 == 'no') { 
			ilabel = '';
		}
		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('Nein');
		}
		if(type2 == 'first') {
			$('#railway_cost').val(railway_travellers*price);
			railway_price = price;
			railway_class = 1;
			$('#railway_cls').val('1.Klasse');
		}
		if(type2 == 'second') {
			$('#railway_cost').val(railway_travellers*price);
			railway_price = price;
			railway_class = 2;
			$('#railway_cls').val('2.Klasse');
		}
	}

	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 "by_phone":
		form_data+= '';
		$('#direct_payment').val('0');
		$('#hamili').val('0');
		$('#payment_mode').val('3');
		break;

		case "by_bank":
		form_data+= $('#ibe_bank_transfer_cover').html();
		$('#direct_payment').val('1');
		$('#hamili').val('0');
		$('#payment_mode').val('2');
		break;

		case "by_cc":
		form_data+= $('#ibe_cc_cover').html();
		$('#direct_payment').val('1');
		$('#hamili').val('1');
		$('#payment_mode').val('1');
		break;

		case "by_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"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"><link href="fileadmin/Site_SLR/css/slr.css" rel="stylesheet" type="text/css" \/><!--[if lte IE 7]><link href="fileadmin/Site_SLR/css/patches/patch_slr.css" rel="stylesheet" type="text/css" \/><![endif]--><link rel="stylesheet" type="text/css" href="/fileadmin/Site_SLR/css/screen/pratik.css" \/><link rel="stylesheet" type="text/css" href="/fileadmin/Site_SLR/css/screen/jquery-ui/jquery-ui.css" \/><link rel="stylesheet" type="text/css" href="/fileadmin/Site_SLR/css/screen/ibe.css" \/><link rel="stylesheet" type="text/css" href="/fileadmin/Site_SLR/css/screen/site.css" \/><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <\/head><body style="width:590px;text-align:left;font-family:arial">');
				write('<img src="/fileadmin/Redaktion_SLR/images/slr-logo-welle_590.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()
		}
	}
}

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;
}


//--- Bookmark a termin function
function add_bookmark(bdata) {
	$.post(ajax,{
		av: "true",
		evoar: book_ar,
		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_ar+'&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_ar,
		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_ar+'&data='+bdata+'&action=list';
				$.ajax({type: 'POST',url: ajax,data: tdata,success: function(list_html) {
						rtemp = list_html.split("<!-- ##### -->");
						boxy_content = "<div id='bookmark-list-cover'>"+rtemp[1]+"<\/div>";
						boxy_title   = lang_bookmark_list;
						blist = new Boxy(boxy_content,{ title: boxy_title , draggable: true , unloadOnHide: true, closeText: lang_close});
					}
				});
			} else {
				if(baction == 'list' || baction == 'print') {
					boxy_content = "<div id='bookmark-list-cover'>"+html+"<\/div>";
					boxy_title   = lang_bookmark_list;

					blist = new Boxy(boxy_content,{ title: boxy_title , draggable: true , unloadOnHide: true, closeText: lang_close});
					if(baction == 'print') {
 						jsPrintOut("PWindow","print_div","merken");
						blist.hide();
					}
				}
				if(baction == 'email') {
					boxy_content = "<div id='bookmark-mail-cover'>"+html+"<\/div>";
					boxy_title   = lang_bookmark_list;

					blist = new Boxy(boxy_content,{ title: boxy_title , draggable: true , unloadOnHide: true, closeText: lang_close});

					$(".bmark-mail-back").click(function(){
						if(blist != undefined) {
							blist.unload();
						}
					});

					$('#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_ar);
							$.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(){
										if(blist != undefined) {
											blist.unload();
										}
									});
								}
							});
						}
						return false;
					});
				}
			}

		}
	);
}

function delete_bookmark(bid) {
	/*
	tdata  = '&av=true&evoar='+book_ar+'&bid='+bid+'&action=delete';
	//alert(ajax+''+tdata);
	$.ajax({
		type: 'GET',
		url: ajax,
		data: tdata,
		cache: false,
		success: function(html){
			$('#bookmark-list-cover').html(html);
		}
	});
	*/
	$.post(ajax,{
		evoar: book_ar,
		bid: bid,
		action: "delete",
		av: 'true'
		}, function(response) {
			rtemp = response.split("<!-- ##### -->");
			$('#bookmark-list-cover').html(rtemp[1]);
		}
	);
}

function get_giata_data(evoar,giata_id,vc) {
	$.post(ajax,{
		evoar: evoar,
		giataid: giata_id,
		vc: vc,
		av: 'true'
		}, function(response) {
			boxy_content = "<div id='roffer-hotel-ext-nfo'>"+response+"<\/div>";
			boxy_title = "&nbsp;";
			new Boxy(boxy_content,{ title: boxy_title , modal: true , unloadOnHide: true, y:50, closeText: lang_close });

		/*
		winId = window.open('',giata_id,'width=660,left=5,top=5, scrollbars=no');
		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("\n");
			write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">');
			write("\n");
			write('<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
			write("\n");
			write('<link href="/fileadmin/yaml/print/print_100_draft.css" rel="stylesheet" type="text/css"/>');
			write("\n");
			write('<link href="/fileadmin/css/screen/ibe.css" rel="stylesheet" type="text/css"/>');
			write("\n");
			write('<\/head>');
			write("\n");
			write('<body style="width:640px;">'+boxy_content+'<\/body>');
			write('<\/html>');
			close();
		}
		*/
			$("#giata-nfo-cover").tabs();
			$("#pics").before('<div id="giata-pics-nav">').cycle({ fx: 'scrollRight', speed: 'slow', timeout: 7000, pager:  '#giata-pics-nav' });

		}
	);
}

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_NDetail(ziel,code) {
	DetailUrl =  'http://www.hotel-beschreibung.de/'+ziel+'/'+code+'.htm?TIT';
	tit_Open_Window(DetailUrl, 'DETAIL', 'scrollbars=yes,resizable=yes',800,600)
}

function tit_RDetail(Rec) {
	DetailUrl =  proto+'://www.zielgebietsinfo.de/'+Rec+'.html';
	tit_Open_Window(DetailUrl, 'DETAIL', 'scrollbars=yes,resizable=yes',800,600)
}

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() {
	var my_ibe_dp_click = jQuery.Event("click"); 

	$("#outbound_date_show").click(function() { // Call your event 
		$("#outbound_date").datepick('show');
	});

	$("#inbound_date_show").click(function() { // Call your event 
		$("#inbound_date").datepick('show');
	});

	if(datepicker_months == undefined) {
		var datepicker_months = 2;
	}
	//--- Load Destination hotel names for hotel name auto show
	$("#outbound_destination").change(function() {
		dest = $("#outbound_destination").val();
		if(dest.length == 3) {
			get_ext_array(dest);
		} else {
			get_ext_array('main');
		}
	});

	//--- Search form submit event
	$("#protravel_search").submit(function(){
		//--- Clear Hotel name default value
		if(hotel_name_label == $("#hotel_name").val()) {
			$("#hotel_name").val('');
		}
		checkRange();
	});
	
	if(window.hotel_names) {
		//--- jQuery autocomplete plugin for hotel names
		$("#hotel_name").autocomplete(hotel_names);
	}

	if(jQuery.datepick) {
		//--- jQuery Datepicker plugin with custom range check init
		init_mask_date(datepicker_months);
	}
}

/**
* 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;}
	no_of_months = 3;

	$('#outbound_date').datepick({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Früheste Hinreise',
		dateFormat: 'dd.mm.yy',
		numberOfMonths: parseInt(no_of_months),
		showButtonPanel: true,
		yearRange: '-0:2+',
		defaultDate: +1,
		onSelect: function() {
			updateOutField();
			return {};
		}
	});

	$('#inbound_date').datepick({
		showAnim: false,
		showOn: 'both',
		buttonImage: '/site/images/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Späteste Rückreise',
		dateFormat: 'dd.mm.yy',
		numberOfMonths: parseInt(no_of_months),
		showButtonPanel: true,
		yearRange: '-0:2+',
		defaultDate: +21,
		onSelect: function() {
			updateInField();
			return {};
		}
	});
}

function updateOutField() {
	checkRange();
	$('#outbound_date_show').html($('#outbound_date').val());
	
}

function updateInField() {
	checkRange();
	$('#inbound_date_show').html($('#inbound_date').val());
}


/**
* get_ext_array#
* loads destination spesific hotel names in js array
*
* @author Sancar Saran <sancar.saran@evodot.com>
* @version 1.0
*/
function get_ext_array(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);
		}
	});
}

/**
* generate_departure
* generate multi departure string for tit
*
* @author Sancar Saran <sancar.saran@evodot.com>
* @version 1.0
*/
function generate_departure() {
	destR = $("#outbound_departureR").val();
	dest1 = $("#outbound_departure1").val();
	dest2 = $("#outbound_departure2").val();
	dest3 = $("#outbound_departure3").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(destR != '') {
		if(departure != '') {
			departure = departure+'x'+destR;
		} else {
			departure = destR;
		}
	}

	$("#outbound_departure").val(departure);
}

function isset(varname)  {
	if(typeof( window[ varname ] ) != "undefined") return true;
	else return false;
}