var dive = false;
var tour = false;
var toff = null;
var doff = null;
var dofr = null;
var dcancel = null;
var dkeep = null;
var dopen = null;
var ddiscard = null;
var second_switch = null;
var landingpage_deeplink = null;

$(document).ready(function() {

	doff = $('#diveoffers');
	dofr = $('#diverentals');
    toff = $('#touroffers');
	dcancel = $(".diveswitch.cancel");
	dkeep = $(".diveswitch.keep");
	dopen = $(".diveswitch.open");
	ddiscard = $(".diveswitch.discard");
	second_switch = $(".second-choice");

	if(ibestep == 3 || (ibestep == 4 && ibetyp == 1)) {
		$(".pager .angebnavi").bind("click",function(e){
			LINK("POS",$(this).attr("id").split("_")[1]);
		});
	}
	
	if(ibestep == 4) {
		$(".pager .hotelnavi").bind("click",function(e){
			LINK("TPOS",$(this).attr("id").split("_")[1]);
		});
	}

	$(".wiki").bind("click",function(e) {
		e.stopPropagation();
        var name = $(this).attr("title").split("|")[1];
        var url = 'http://'+lang+'.wikipedia.org/wiki/'+name;
        if($(this).attr("href") == url) { return; }
		$(this).attr("href",url).click();
	});

    $(".info-icon").bind("mouseover",function(e){
        //$(this).find(".infobox").show();
        e.stopPropagation();
		tooltip($(this),"over");
    }).bind("mouseout",function(e){
        //$(this).find(".infobox").hide();
        e.stopPropagation();
		tooltip($(this),"out");
    });
    $(".diveicon").bind("mouseover",function(e){
        e.stopPropagation();
		tooltip($(this),"over");
		return;
    }).bind("mouseout",function(e){
        e.stopPropagation();
		tooltip($(this),"out");
    });

    $("#switch-dive").bind("click", function(e) {
        var elem = $(this);
        if(elem.hasClass("opened")) {
            elem.removeClass("opened").html(messages.tauchinfos);
            $(".dive-cnt").hide();
        }
        else {
            elem.addClass("opened").html(messages.tauchinfos_close);
            $(".dive-cnt").show();
        }
    });
});

function tooltip(obj, action) {
	if(action == "out") {
		$("#tooltip").hide();
		return;
	}
	if($("#tooltip").length == 0) {
		$("body").append('<div id="tooltip"></tooltip>');
	}
	var o = obj.offset();
	$("#tooltip").text(obj.attr("title")).css({top: o.top+"px", left: (o.left + 25)+"px"}).show();
}

function showWiki(name) {
    var url = 'http://'+lang+'.wikipedia.org/wiki/'+name;
    showit('','',url+name,700);
}
function diveSwitch(what) {
    doff.find("input").attr("readonly",true);
    dofr.find("input").attr("readonly",true);
	switch(what) {
		case "open":
			if(dive) {
                doff.find("input").attr("readonly",false);
                dofr.find("input").attr("readonly",false);
				doff.show();
				dofr.show();
				second_switch.show();
				updatePrice("show",0);
			}
			else {
				second_switch.show();
				getDiveOfferBook(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]);
			}
			switchDiveButtons(0,1,0,1);
		break;
		case "keep":
            var divecheck = true;
            var fromgroup = '';
            var togroup = '';
            var checkvalue = 0;
            $(".tboffers").each(function(i){
                if($(this).val() != '' && isNaN(parseInt($(this).val()))) {
                    divecheck = false;
                }
                if(isNaN(parseInt($(this).val())) && $(this).val() != '') {
                    $(this).val('');
                    $(this).css('background-color','#F5F4EE');
                } else {
                    if($(this).attr("title").length > 0) {
                        fromgroup = $(this).attr("title").split("-")[0];
                        togroup   = $(this).attr("title").split("-")[1];
                        checkvalue = parseInt($(this).val());
                        if((fromgroup > checkvalue || checkvalue > togroup) && $(this).val() != '') {
                            divecheck = false;
                            $(this).val('');
                            $(this).css('background-color','#F5F4EE');
                        } else $(this).css('background-color','#FFFFFF');
                    } else $(this).css('background-color','#FFFFFF');
                }
            });
            if(divecheck) {
			doff.show();            
			//second_switch.hide();
			window.location.href="#diving";            
			updatePrice("keep",0);
            if(document.F.DEPREIS.value == 0) dofr.hide();
			else dofr.show();
			if(document.F.DDPREIS.value == 0) {
                alert(messages.no_tboffers_selected);
                /*if(lang == 'de') alert("Es sind keine Tauchangebote ausgewählt worden.");
                if(lang == 'en') alert("There are no dive offers choosen..");*/
				updatePrice("show",0);
			}
			else {
                // availabfrage und markieren                
				switchDiveButtons(1,0,0,1);
                if(checkVakanzTB() == false) {
                    /*var weg = "Leider ausgebucht!";
                    if(lang == 'en') weg = "Sorry, offer is sold out.!";*/
                    var weg = messages.sold_out;
                    alert(weg);
                    updatePrice("keep",0);
                    diveSwitch("open");
                }
			}
         } else {
             /*var checkinfo = 'Fehlerhafte Eingabe.';
             if(lang == 'en' ) checkinfo = 'Please check your entry.';*/
             alert(messages.wrong_entry);
         }
		break;
		case "cancel":
			if(document.F.DGPREIS.value != 0 && document.F.RGPREIS.value != 0 && $(".diveswitch.open").css("display") != "none") {
				doff.hide();
				dofr.hide();
				//second_switch.hide();
				window.location.href="#diving";
				updatePrice("cancel",0);
				switchDiveButtons(1,0,0,0);
			}
			else {
				updatePrice("keep",0);
				switchDiveButtons(1,0,0,1);
			}
		break;
		case "discard":
			updatePrice("discard",0);
			doff.hide();
			dofr.hide();
			second_switch.hide();
			window.location.href="#diving";
			switchDiveButtons(1,0,0,0);
		break;
	}
}

function switchDiveButtons(open,keep,cancel,discard) {
	open ? dopen.show() : dopen.hide();
	keep ? dkeep.show() : dkeep.hide();
	cancel ? dcancel.show() : dcancel.hide();
	discard ? ddiscard.show() : ddiscard.hide();
}

function DelHttpParam(Param, Url) {
	uarr = Url.split("?");
	parr = uarr[1].split("&");
	var paramstr = "?";
	$.each(parr,function(){
		var elem = this.split("=");
		if(elem[0] != Param){
			paramstr += paramstr == "?" ? elem[0] + "=" + elem[1] : "&" + elem[0] + "=" + elem[1];
		}
	});
	var NewUrl = uarr[0] + paramstr;
	return NewUrl;
}

function LINK(param, ref) {
	var href = param == "ZIEL" ? DelHttpParam("ORT", window.location.href) : window.location.href;
	href = param == "ZIEL" ? DelHttpParam("match",href) : href;
	href = param == "ZIEL" ? DelHttpParam("SORT",href) : href;
	href = param == "ORT" || param == "ZIEL" ? DelHttpParam("POS",href) : href;
	href = DelHttpParam(param, href);
	href = href.replace(/#diving/,"");
	href = checkAddrDate(href);
    window.scrollTo(0,0);
    if($.browser.msie) {
        href = href.replace(/&/g,"&amp;");
    }
    
	window.location.href = ref != '' ? href+"&"+param+"="+ref : href;
}
function TOURLINK(param, ref,city,tcity) {
	var href = param == "ZIEL" ? DelHttpParam("ORT", window.location.href) : window.location.href;
	href = param == "ZIEL" ? DelHttpParam("match",href) : href;
	href = param == "ZIEL" ? DelHttpParam("SORT",href) : href;
	href = param == "ORT" || param == "ZIEL" ? DelHttpParam("POS",href) : href;
	href = DelHttpParam(param, href);
	href = href.replace(/#diving/,"");
	href = checkAddrDate(href);
    if($.browser.msie) {
        href = href.replace(/&/g,"&amp;");
    }
	window.location.href = ref != '' ? href+"&"+param+"="+ref+"&"+city+"="+tcity : href;
}
function checkAddrDate(href) {
	if(von_selected != "") {
		href = DelHttpParam("von", href);
		href += "&von="+von_selected;
	}
	if(bis_selected != "") {
		href = DelHttpParam("bis", href);
		href += "&bis="+bis_selected;
	}
	return href;
}

// make step in the IBE, instead of "back" and "new search" links
function makeStep(step) {
	//if(step == "1") {LINK("reg","");}
	if(step == "1") {ZM();}
	if(step == "2") {ZR();}
	if(step == "3") {ZA();}
	if(step == "4") {ZH();}
}

// back to searchform (step 1)
function ZM() {
	var hin = DelHttpParam("ORT", window.location.href);
	hin = DelHttpParam("BOOK", hin);
	hin = DelHttpParam("SORT", hin);
	hin = DelHttpParam("POS", hin);
	hin = DelHttpParam("match", hin);
	hin = DelHttpParam("REC", hin);
	hin = DelHttpParam("DCENTER", hin);
	hin = DelHttpParam("CID", hin);
	hin = DelHttpParam("reg", hin);
    hin = DelHttpParam("TOURS", hin);
    hin = DelHttpParam("checked", hin);
	hin = hin.replace(/#diving/,"");
	hin = checkAddrDate(hin);
    window.scrollTo(0,0);
    
	window.location.href = hin;
}

// back to regions list (step 2)
function ZR() {
	var hin = DelHttpParam("ZIEL", window.location.href);
	hin = DelHttpParam("ORT", hin);
	hin = DelHttpParam("BOOK", hin);
	hin = DelHttpParam("SORT", hin);
	hin = DelHttpParam("POS", hin);
	hin = DelHttpParam("match", hin);
	hin = DelHttpParam("REC", hin);
    hin = DelHttpParam("TOURS", hin);
    hin = DelHttpParam("checked", hin);
	hin = hin.replace(/#diving/,"");
	hin = checkAddrDate(hin);
    window.scrollTo(0,0);
    if($.browser.msie) {
        hin = hin.replace(/&/g,"&amp;");
    }
	window.location.href = hin;
}

// back to offers (step 3)
function ZA() {
      //if(!isParam("REC",window.location.href)) var hin = DelHttpParam("ZIEL", window.location.href);
      //else
	var hin = DelHttpParam("REC", window.location.href);
	hin = DelHttpParam("BOOK", hin);
	hin = DelHttpParam("TPOS", hin);
	hin = DelHttpParam("TSORT", hin);
	hin = DelHttpParam("POS", hin);
	hin = DelHttpParam("match", hin);
	hin = DelHttpParam("DCENTER", hin);
    hin = DelHttpParam("TOURS", hin);
    hin = DelHttpParam("checked", hin);
	hin = hin.replace(/#diving/,"");
	hin = checkAddrDate(hin);
    if($.browser.msie) {
        hin = hin.replace(/&/g,"&amp;");
    }
    window.scrollTo(0,0);
	window.location.href = hin;
}

// back to hotel (step 4)
function ZH() {
	var hin = DelHttpParam("BOOK", window.location.href);
	hin = DelHttpParam("TPOS", hin);
	hin = DelHttpParam("TSORT", hin);
    hin = DelHttpParam("TOURS", hin);
    hin = DelHttpParam("checked", hin);
	hin = hin.replace(/#diving/,"");
	hin = checkAddrDate(hin);
    window.scrollTo(0,0);
    if($.browser.msie) {
        hin = hin.replace(/&/g,"&amp;");
    }
    
	window.location.href = hin;

}
function getXmlHttpObject() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        try {
            // Microsoft Internet Explorer
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {

            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {

                return null;
            }
        }
    }
    return xmlHttp;
}
function showEvent(code,von,bis,k1,k2,k3,p) {

    var width = 700;
    var ie = $.browser.msie ? true : false;
        var pop = false;
        if(ie) {
            var bver = $.browser.version;
            if(parseInt(bver.substr(0,1)) < 7) { pop = true; }
        }
        if(iframecontent == 1 || Number(ibestep) > 4){ pop = true; }
        if(pop) {
            url = baseUrl+"detailTour.php?tcode="+code+'&von='+von+'&bis='+bis+'&k1='+k1+'&k2='+k2+'&k3='+k3+'&p='+p+'&aff='+affid;
            window.open(url,"infopopup","width=700,height=700,top=100,left=100");
        } else {
            var hoffest = 75;
            var wh = $(window).height();
            $("#overlay")
                .appendTo("body")
                .height(wh + 10)
                .show()
                .click(function(e){
                    hideit();
                })
                .css({
                    top: "0px",
                    left: "0px"
                });
            if(width != "") {
                $("#popUpDiv").width(width);
            }
            $("#popUpDiv")
                .appendTo("body")
                .height((wh - hoffest * 2))
                .css({
                    top: Number(hoffest)+"px",
                    left: Number(($(window).width()-$("#popUpDiv").outerWidth())/2)+"px"
                })
                .show();
			//console.debug($("#popUpDiv").parent());
            $("#infoframe")
                .height($("#popUpDiv")
                .height()-$("#hideit")
                .outerHeight()-10);
            $("#infoframe")
                .attr("src",baseUrl+"detailTour.php?tcode="+code+'&von='+von+'&bis='+bis+'&k1='+k1+'&k2='+k2+'&k3='+k3+'&p='+p+'&aff='+affid);
        }

}
function cleanTours(id){
    $(".diyowo_"+id).each(function(i){
                 $(this).attr("checked",false);
            });
}
function getSelectedTours(id){
    var seltours = new Array();
    if($(".diyowo_"+id+":checked").length > 0) {
        $(".diyowo_"+id).each(function(i){
                 if($(this).attr("checked")) seltours += $(this).val()+']';
            });
       seltours = seltours.substr(0,seltours.length-1);
    }
    return seltours;
}
function tourSwitch(what,id) {
    var toffbook  = $('#touroffers_'+id);
    var topenbook = $('.open_'+id);
    var topensel  = $('.second-choice_'+id);
    var tkeep     = $('.keep_'+id);
    var tdiscard  = $('.discard_'+id);
    switch(what) {
        case "show":
            updatePrice("show",id);
            toffbook.show();
            topenbook.hide();
            topensel.show();
            tdiscard.show();
            tkeep.show();
		break;
		case "keep":
            updatePrice("keep",id);
            if(document.F.TOURPREIS.value == 0) {
                alert(messages.no_touroffers_selected);
				updatePrice("show",id);
                toffbook.show();
                topenbook.hide();
                topensel.show();
                tdiscard.show();
                tkeep.show();
			} else {
                toffbook.show();
                topenbook.show();
                topensel.show();
                tdiscard.show();
                tkeep.hide();
            }
		break;		
		case "discard":
            updatePrice("discard",id);
            toffbook.hide();
            topenbook.show();
            topensel.hide();
            tdiscard.hide();
            tkeep.hide();
		break;
        case "close":
            toffbook.hide();
            topenbook.show();
            topensel.hide();
		break;
	}
}
function getTourOfferBook(id,start,end,aff,p,k1,k2,k3,iteration) {
    var toffbook  = $('#touroffers_'+iteration);
    var topenbook = $('.open_'+iteration);
    var topensel  = $('.second-choice_'+iteration);
	var check = messages.load_tours;
	var nocheck = messages.no_tours;
	if(toffbook.html() == '') {
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "?gdo=2&typ=2&test="+test+'&id='+id+'&p='+p+'&k1='+k1+'&k2='+k2+'&k3='+k3+'&von='+start+'&bis='+end+'&lg='+lang+'&aff='+aff+'&iteration='+iteration+'&proof=3&tpl='+tpl,
			beforeSend: function(){
				toffbook.html('<div class="proof">'+check+' <img src="images/ajax-loader.gif" /></div>').show();
			},
			success: function(resp, stat){
				toffbook.html(resp.content);
				tourSwitch("show",iteration);
			}
		});
	}
	else {
        tourSwitch("show",iteration);
	}
}
function getTourOffer(id,start,end,aff,p,k1,k2,k3,iteration) {
    var toffhotel = $('#touroffers_'+iteration);
    var toffloader = $('.touroffers_'+iteration);
    var topenhotel = $('.touropen_'+iteration);
	var check = messages.load_tours;
	var nocheck = messages.no_tours;
	if(toffhotel.html() == '') {
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "?gdo=2&typ=2&proof=3&test="+test+'&oid='+id+'&p='+p+'&k1='+k1+'&k2='+k2+'&k3='+k3+'&von='+start+'&bis='+end+'&lg='+lang+'&aff='+aff+'&iteration='+iteration+"&tpl="+tpl,
			beforeSend: function(){
				if(toffloader.length > 0)
					toffloader.html('<div class="proof">'+check+' <img src="images/ajax-loader.gif" /></div>').show();
				else
					toffhotel.html('<div class="proof">'+check+' <img src="images/ajax-loader.gif" /></div>');
				toffhotel.show();
				topenhotel.html(messages.discard_tours);
			},
			success: function(resp, stat){
				toffhotel.html(resp.content);
				toffloader.hide();
				tour = true;
				var p = toffhotel.parent();
				if(p.hasClass("tours-container")) { p.show(); }
			}
		});
	}
	else {
		if(toffhotel.css("display") == 'block') {
			toffhotel.css("display",'none');
            topenhotel.html(messages.show_tours);
            cleanTours(iteration);
		} else {
			toffhotel.css("display",'block');
            topenhotel.html(messages.discard_tours);
		}
	}
}
function getDiveOffer(id,start,end,aff) {
	var opener = $('#diveopen');
    var par = opener.parent();
    if(!dive) {
		try {
            var check = messages.check_availability;
            var nocheck = messages.check_avail_failed;
			doff.html('<div class="proof">'+check+' <img src="images/ajax-loader.gif" /></div>');
			doff.css("display",'block');
            //$('#diveopen').html(messages.hide_diving);
            opener.html(messages.hide_diving);
            if(par.hasClass("switch-dive")) { par.addClass("opened"); }
			var xmlHttp = getXmlHttpObject();
			var html = '';
			xmlHttp.open("GET","?gdo=1&test="+test+'&centerid='+id+'&start='+start+'&end='+end+'&lg='+lang+'&type=offer&aff='+aff+'&tpl='+tpl,true);
			xmlHttp.setRequestHeader("If-Modified-Since", new Date(0));
			xmlHttp.send(null);
			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					var html = xmlHttp.responseText;
					dive = true;
					doff.html(html);
				}
			}
		} catch(err) {
			doff.html('<div class="proof">'+nocheck+'</div>');
		}
	}
	else {
		if(doff.css("display") == 'block') {
			doff.css("display",'none');
            //$('#diveopen').html(messages.show_diving);
            opener.html(messages.show_diving);
            if(par.hasClass("switch-dive")) { par.removeClass("opened"); }
		} else {
			doff.css("display",'block');
            //$('#diveopen').html(messages.hide_diving);
            opener.html(messages.hide_diving);
            if(par.hasClass("switch-dive")) { par.addClass("opened"); }
		}
	}
}

var DiveOfferPrice  = new Array();
var DiveRentalPrice = new Array();
//var travelprice     = 0;
function isNumeric(strString) {
    var strValidChars = "123456789";
    var strChar;
    var blnResult = true;
    if (strString.length == 0) return false;
    for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function getDiveOfferBook(id,start,end,gpreis,aff) {
    try {
        var check = messages.check_availability;
        var nocheck = messages.check_avail_failed;
        $('#diveoffers').html('<div class="proof">'+check+' <img src="images/ajax-loader.gif" /></div>').show();

        var xmlHttp = getXmlHttpObject();
        var html = '';
        xmlHttp.open("GET","?gdo=1&test="+test+'&centerid='+id+'&start='+start+'&lg='+lang+'&end='+end+'&type=book&aff='+aff+'&tpl='+tpl,true);
        xmlHttp.setRequestHeader("If-Modified-Since", new Date(0));
        xmlHttp.send(null);
        xmlHttp.onreadystatechange=function() {
            if(xmlHttp.readyState==4) {
                var html = xmlHttp.responseText;
                dive = true;
                document.getElementById('diveoffers').innerHTML = html;
                getRentalEquipment($('#serviceid').val(),aff);
            }
        }
  } catch(err) {
	  document.getElementById('diveoffers').innerHTML = '<div class="proof">'+nocheck+'</div>';
  }
}
function getRentalEquipment(id,aff) {
try {
          document.getElementById('diverentals').style.display = 'block';
	      var xmlHttpR = getXmlHttpObject();
          var htmlR = '';
          if(lang != 'de') popental  = 'L=en&';
		  xmlHttpR.open("GET","?gdo=1&test="+test+'&serviceid='+id+'&lg='+lang+'&aff='+aff+'&tpl='+tpl,true);
		  xmlHttpR.setRequestHeader("If-Modified-Since", new Date(0));
		  xmlHttpR.send(null);
		  xmlHttpR.onreadystatechange=function() {
				if(xmlHttpR.readyState==4) {
                var htmlR = xmlHttpR.responseText;
                         document.getElementById('diverentals').innerHTML = htmlR;
			   }
		  }
          return htmlR;
  } catch(err) {
  }
}
function checkVakanzTB() {
    var offers = '';
    var f = window.document.F;
    var z = 0;
    if( !f ) return;
    for( var i = f.length; i--; ) {
        var id = 0;
		var n = f[i].name;
		var v = f[i].value;
		var tang = n.substr( 0, 9 ) == "DIVEOFFER";

		if( !v  || v == '') v = 0;
			if(tang) {
				if(isNumeric(v) && v != 0) { 
                    pid = n.substr( 10, n.length - 11 );
                    sid = $('.'+pid).attr("id");
                    offers += sid+','+v+'|';
                    
				}
			}
    }
    offers = offers.substr(0,offers.length - 1);

if(offers != '') {
try {
      var available = true;
	  var xmlHttp = getXmlHttpObject();
      xmlHttp.open("GET","?gdo=1&test="+test+"&L="+lang+"&aff="+affid +"&offers="+offers+'&start='+$('#TERMIN').val()+'&end='+$('#RRTAG').val()+'&type=avails&tpl='+tpl,true);
      xmlHttp.setRequestHeader("If-Modified-Since", new Date(0));
	  xmlHttp.send(null);
	  xmlHttp.onreadystatechange=function() {
        if(xmlHttp.readyState==4) {
                var oJSON = eval('('+xmlHttp.responseText+')');
                if(typeof(oJSON['divexmloffer']['Services']['Service'].length) != 'undefined') {
                    for(var i=0;i<oJSON['divexmloffer']['Services']['Service'].length;i++) {
                        if(typeof(oJSON['divexmloffer']['Services']['Service'][i]['Errors'])  != 'undefined') {
                            try { $("."+oJSON['divexmloffer']['Services']['Service'][i]['@attributes']['ServiceID']).attr("readonly", "readonly");
                                  $("."+oJSON['divexmloffer']['Services']['Service'][i]['@attributes']['ServiceID']).addClass("input_error ");
                                  $("."+oJSON['divexmloffer']['Services']['Service'][i]['@attributes']['ServiceID']).val('');
                                  available = false;
                        } catch(e){}
                            }
                    }
                } else {
                    if(typeof(oJSON['divexmloffer']['Services']['Service']['Errors'])  != 'undefined') {
                        try { $("."+oJSON['divexmloffer']['Services']['Service']['@attributes']['ServiceID']).attr("readonly", "readonly");
                              $("."+oJSON['divexmloffer']['Services']['Service']['@attributes']['ServiceID']).addClass("input_error ");
                              $("."+oJSON['divexmloffer']['Services']['Service']['@attributes']['ServiceID']).val('');
                              available = false;
                        } catch(e){}
                    }
                }
                if(available == false) return false;
                else return true;
        }
      }
    } catch(err) {return false }
 }
}
function checkvakanz(id, ref,rec,divecenter,seltours,fullid) {
    var weg = messages.sold_out;
    var verf = messages.check_availability;
    var elem = null;
    //if(divecenter == '') document.getElementById('r_'+id).innerHTML = '<div class="proof">'+verf+' <img src="images/ajax-loader.gif" /></div>';
	//else document.getElementById('r_'+id+'%%'+divecenter).innerHTML = '<div class="proof">'+verf+' <img src="images/ajax-loader.gif" /></div>';
    if(divecenter == '') elem = $(document.getElementById('r_'+id));
	else elem = $(document.getElementById('r_'+id+'%%'+divecenter));
    elem.removeClass("button").html('<div class="proof color0">'+verf+' <img src="images/ajax-loader.gif" /></div>');
    $(document.getElementById("termin_cnt_"+fullid)).addClass("selected");
    
    var href = window.location.href.replace(/#diving/,"");
	if(landingpage_deeplink && landingpage_deeplink != '')
		href = landingpage_deeplink;
	var checkhref = DelHttpParam("proof", href);
	checkhref = DelHttpParam("shop", checkhref);
	checkhref = DelHttpParam("link", checkhref);
	checkhref = DelHttpParam("iframe", checkhref);
	checkhref = DelHttpParam("curl", checkhref);

    $.ajax({
        type: "GET",
        url: rec == '' ? checkhref+"&proof=1&BOOK="+ref : checkhref+"&proof=1&REC="+rec+"&BOOK="+ref,
        dataType: "json",
        success: function(oJSON, textStatus) {
            var u = "";
            if(rec == '') u = href+"&BOOK="+ref+"&DCENTER="+divecenter+"&TOURS="+encodeURIComponent(seltours);
            else  u = href+"&REC="+rec+"&BOOK="+ref+"&DCENTER="+divecenter+"&TOURS="+encodeURIComponent(seltours);

            if(oJSON['xmloject']['PAGE'] == "book") {
                var trs = $(document.getElementById("termin_cnt_"+fullid));
                if(document.getElementById("termin_cnt_"+fullid)) {
                    if(divecenter == '') elem = $(document.getElementById('r_'+id));
                    else elem = $(document.getElementById('r_'+id+'%%'+divecenter));
                    elem.html('<div class="available">'+messages.verfuegbarbook+'</div>');
                    trs.find(".tourgetter").click();
                    trs.find(".bookit").show().bind("click",function(e) {
                        var it = $(this).attr("id").split("_")[1];
                        var selectedtours = getSelectedTours(it);
                        u = DelHttpParam("TOURS", u);
                        u += "&TOURS="+encodeURIComponent(selectedtours);
                        u = u.replace(/#diving/,"");
                        if($.browser.msie) {
                            u = u.replace(/&/g,"&amp;");
                        }
                        window.location.href = u;
                        window.scrollTo(0,0);
                    })
                }
                else {
                    window.scrollTo(0,0);
                    window.location.href = u;
                }
			} else {
                var elem = null;
				if(divecenter == '') elem = document.getElementById('r_'+id);
                else elem = document.getElementById('r_'+id+'%%'+divecenter);
                $(elem).html('<div class="soldout color5">'+weg+'</div>');
			}
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus+"\n"+errorThrown);
        }

    });

}

function checkvakanzTBM(id, ref,rec,cid,divecenter) {
try {
    var weg1 = messages.sold_out;
    var verf1 = messages.check_availability;
    
    if(divecenter == '') document.getElementById('r_'+id+'_'+cid).innerHTML = '<span class="proof">'+verf1+' <img src="images/ajax-loader.gif" /></span>';
        else document.getElementById('r_'+id+'_'+cid+'%%'+divecenter).innerHTML = '<span class="proof">'+verf1+' <img src="images/ajax-loader.gif" /></span>';
    var xmlHttp = getXmlHttpObject();
		var href = window.location.href.replace(/#diving/,"");
		var checkhref = DelHttpParam("proof", href);
		checkhref = DelHttpParam("shop", checkhref);
		checkhref = DelHttpParam("link", checkhref);
		checkhref = DelHttpParam("iframe", checkhref);
		checkhref = DelHttpParam("curl", checkhref);
        if(rec == '') xmlHttp.open("GET",checkhref+"&proof=1&BOOK="+ref,true);
        else  xmlHttp.open("GET",checkhref+"&proof=1&REC="+rec+"&BOOK="+ref,true);
        xmlHttp.setRequestHeader("If-Modified-Since", new Date(0));
        xmlHttp.send(null);
        xmlHttp.onreadystatechange=function() {
            if(xmlHttp.readyState==4) {
                var oJSON = eval('('+xmlHttp.responseText+')');
                if(oJSON['status'] == "true") {
                    window.scrollTo(0,0);
                    
                    if(rec == '') window.location.href=href+"&checked="+oJSON['token']+"&BOOK="+ref+"&CID="+cid+"&DCENTER="+divecenter;
                    else  window.location.href=href+"&REC="+rec+"&checked="+oJSON['token']+"&BOOK="+ref+"&CID="+cid+"&DCENTER="+divecenter;
                } else {
                  // document.getElementById('R'+id).appendChild(document.createTextNode("Leider ausgebucht!"));
                   if(divecenter == '') document.getElementById('r_'+id+'_'+cid).innerHTML = '<span class="weg">'+weg1+'</span>';
                       else document.getElementById('r_'+id+'_'+cid+'%%'+divecenter).innerHTML = '<span class="weg">'+weg1+'</span>';
                }
            }
        }
  } catch(err) {
    window.scrollTo(0,0);
    
       if(rec == '') window.location.href=window.location.href+"&BOOK="+ref+"&CID="+cid+"&DCENTER="+divecenter;
       else window.location.href=window.location.href+"&REC="+rec+"&BOOK="+ref+"&CID="+cid+"&DCENTER="+divecenter;
  }

}

function showit(VA,CODE,url,width) {
	var ie = $.browser.msie ? true : false;
	//var pop = framed || curled ? true : false;
	var pop = false;
	//alert(framed);
	if(ie) {
		var bver = $.browser.version;
		if(parseInt(bver.substr(0,1)) < 7) { pop = true; }
	}
    if(iframecontent == 1 || Number(ibestep) > 4){ pop = true; }
	if(pop) {
		if((VA != 'BU' && VA != '' && CODE != '') || provider != '6') {
			//url = "http://www.specials.de/thomas/htdoc/?reg=1&detail=1&VA="+VA+"&CODE="+encodeURI(CODE)+"&AS="+encodeURIComponent(url);
			url = baseUrl.replace(/https:/,"http:",baseUrl)+"?reg=1&detail=1&VA="+VA+"&CODE="+encodeURI(CODE)+"&AS="+encodeURIComponent(url)+"&aff="+affid+"&provider="+provider;
		}
		window.open(url,"infopopup","width=750,height=770,top=100,left=100,scrollbars=yes");
	}
	else {
		var hoffest = 25;
		var wh = $(window).height();
		$("#overlay")
			.appendTo("body")
			.height(wh + 10)
			.show()
			.click(function(e){
				hideit();
			})
			.css({
				top: "0px",
				left: "0px"
			});
		$("#popUpDiv").width(width != undefined ? width : 750);

		$("#popUpDiv")
			.appendTo("body")
			.height((wh - hoffest * 2))
			.css({
				top: Number(hoffest)+"px",
				left: Number(($(window).width()-$("#popUpDiv").outerWidth())/2)+"px"
			})
			.show();
		$("#infoframe")
			.height($("#popUpDiv")
			.height()-$("#hideit")
			.outerHeight()-10);

		if((VA != 'BU' && VA != '' && CODE != '') || provider == '6') {
			$("#infoframe")
			.attr("src",baseUrl.replace(/https:/,"http:",baseUrl)+"?reg=1&detail=1&VA="+VA+"&CODE="+CODE+"&AS="+encodeURIComponent(url)+"&aff="+affid+"&provider="+provider);
		}
		else {
			$("#infoframe").attr("src",url);
		}
	}

}
function hideit() {
	$("#popUpDiv").hide();
	$("#overlay").hide();
	$("#infoframe").attr("src","about:blank");
	if(!$.browser.msie) {
		//history.back();
	}
}

function compareHotel(id) {
	pos = id.indexOf(".php")
    window.scrollTo(0,0);
    
    var href = window.location.href;
    href = DelHttpParam("match",DelHttpParam("hotel", window.location.href));
	if(pos != -1) {
		var ref = id.split('?');
		ref = ref[1].split('&');
		ref = ref[0].split('=');
        href += "&match="+ref[1];
	} else {
		href += "&match="+id;
	}
    if($.browser.msie) {
        href = href.replace(/&/g,"&amp;");
    }
    window.location.href = href;
}

function BA(Ref,Rec,cid,divecenter,stours,fullid) {
	pos = Ref.indexOf("|")
	if(pos != -1) {
		TBMRef = Ref.substring(1);
		checkvakanzTBM(Ref,TBMRef,Rec,cid,divecenter,stours);
	} else {
		checkvakanz(Ref,Ref,Rec,divecenter,stours,fullid);
   }
}

function beforeBA(elem,tid){
	var divecenter = '';
    var selectedtours = '';
    selectedtours = getSelectedTours(tid);
	var next       = '';
	var id = $(elem).attr("id");
	if(id.split("%%")[1]) {
		divecenter = id.split("%%")[1];
		next       = id.split("%%")[0];
	} else {
		divecenter = '';
		next       = id;
	}
    //$("#termin_cnt_"+tid).addClass("selected");
	if(next.split("_")[2]) BA(next.split("_")[1],'',next.split("_")[2],divecenter,selectedtours,id);
	else BA(next.split("_")[1],'','',divecenter,selectedtours,id);
}

function selectOrt(el) {
	var name = String($(el).attr("name"));
	var ref = $(el).val();
	if(name == 'ORT') {
		LINK("ORT",ref);
	} else if (name == 'sort'){
		LINK("SORT",ref);
	} else if (name == 'TSORT'){
		LINK("TSORT",ref);
	}
}

function switchPA(what) {
	if(what == "PA") {
		$(".PA, .NH").show();
	}
	if (what == "FL"){
		$(".PA").hide();
		$(".NH").show();
	}
	if( what == "NH") {
		$(".NH").hide();
		$(".PA").show();
	}
}