function change_product(selectbox) {
	if (selectbox.value != '') {
		for (var i=0; i<selectbox.length; i++) {
			if (selectbox.options[i].selected == true) window.location = selectbox.options[i].title;
		}
	}
}

function decryptThis(s) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) { 
		n=s.charCodeAt(i); 
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(2)); 
	}
	return r;
}

function decrypt_mail(element, email, params) {
	if (!params) var params = '';
	element.href = 'mailto:' + decryptThis(email) + params;
}

function toggleLWKat(id) {
	if (document.getElementById('lw' + id).style.display == 'block') {
		document.getElementById('lw' + id).style.display = 'none';			
	} else {
		document.getElementById('lw' + id).style.display = 'block';
	}
}

/* Neues Fenster für Großbildanzeige */
var coverzoom = null;
function cz(img,titel,w,h) {
	var url = rpfad + "katalog/coverzoom.cfm?image=" + img + "&titel=" + titel;
	if (w && h) {
		url =  url + "&w=" + w + "&h=" + h;
		coverzoom = window.open(url,"Bigimage","width="+w+",height="+h+",top=0,left=0");
	} else {
		coverzoom = window.open(url,"Bigimage","width=150,height=30,top=0,left=0");
	}
	coverzoom.focus();
}

/* Popup Fenster für Flashclips oder sonstige Teaser und Links */
var lkgW_popup = null;
function openlkgWin(url,w,h,name,params) {
	if (!name) var name = "lkgpopupwin";
	if (!params) var params = "";
	lkgW_popup = window.open(url,name,"width="+w+",height="+h + params);
	lkgW_popup.focus();
}

function getPosX(obj) {
	var ret=0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			ret += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		ret += obj.x;
	}
	return ret;
}
function getPosY(obj) {
	var ret=0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			ret += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		ret += obj.y;
	}
	return ret;
}

// Scroll to Anker (geht nur im Firefox, nicht mit Position:absolute)
function scroll2(anker,h) {
	if (!h) var h = -144;
	var obj = document.getElementsByName(anker)[0];
	var offset = getPosY(obj) + h;
	window.scrollTo(0,offset);
	return false;
}

// setActiveStyleSheet (alternate Stylesheet)
function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}
function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

// open Details
var ActiveISBNDetails = null;
function openISBN(id,detail) {
	var myObj = document.getElementById(id);
	var myDetail = document.getElementById(id + '_' + detail);
	if (myObj.style.display == 'none') {
		myObj.style.display='block';
		myObj.innerHTML = myDetail.innerHTML;
		ActiveISBNDetails = detail;
	} else {
		if (ActiveISBNDetails != detail) {
			myObj.innerHTML = myDetail.innerHTML;
			ActiveISBNDetails = detail;
		} else {
			myObj.style.display='none';
			ActiveISBNDetails = null;
		}
	}
}

// smooth div rollout
var smooth_timer;
function smoothHeight(id, curH, targetH, stepH, mode) {
	diff = targetH - curH;
	if (diff != 0) {
		newH = (diff > 0) ? curH + stepH : curH - stepH;
		document.getElementById(id).style.height = newH + "px";
		if (smooth_timer) window.clearTimeout(smooth_timer);
		smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 6 );
	}
	if (!mode) document.getElementById(id).style.display='none';
}

// Pop-Up-Window für Mozilla bei Bug in Flash-Embeds
// Verwendung: onclick="return moz_pop(url, name, width, height);"
function moz_pop(url, name, width, height) {
	if (navigator.appName.indexOf('Internet Explorer') == -1) {
		window.open(url, name, 'width=' + width + ', height=' + height + ', resizable=no, status=no');
		return false;
	}
	return true;
}

function AjaxObject(url) {                                           // This is the object constructor
	var that=this;                                                    // A workaround for some javascript idiosyncrocies
	var updating = false;                                             // Set to true if this object is already working on a request
	this.callback = function() {}                                     // A post-processing call -- a stub you overwrite.

	this.update = function(passData, method) {                        // Initiates the server call.
		if (!method) { method = "POST"; }
		if (updating==true) { return false; }                          // Abort if we're already processing a call.
//		updating=true;                                                 // Set the updating flag.
		var AJAX = null;                                               // Initialize the AJAX variable.
		try {
			AJAX = new XMLHttpRequest();
		} catch (trymicrosoft) {
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (othermicrosoft) {
				try {
					AJAX = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					AJAX = null;
				}
			}
		}
		if (AJAX==null) {                                              // If we couldn't initialize Ajax...
			alert("Ihre Browser unterstützt kein AJAX.");               // Sorry msg.                                              
			return false                                                // Return false (WARNING - SAME AS ALREADY PROCESSING!)
		} else {
			AJAX.onreadystatechange = function() {                      // When the browser has the request info..
				if (AJAX.readyState==4 || AJAX.readyState=="complete") { //   see if the complete flag is set.
					if (AJAX.status == 200) {
						that.data = AJAX.responseText.replace(/^\s*([\S ]+)\s*$/,'$1'); //   It is, so put the new data in the object's layer
						that.responseText = AJAX.responseText;
						that.responseXML = AJAX.responseXML;
						delete AJAX;                                       //   delete the AJAX object since it's done.
						updating=false;                                    //   Set the updating flag to false so we can do a new request
						that.callback();                                   //   Call the post-processing function.
					} else {
						// AJAX response error
						alert("Fehler in AJAX Antwort.");
					}
				}                                                        // End Ajax readystate check.
			}                                                           // End create post-process fucntion block.
			var timestamp = new Date();                                 // Get a new date (this will make the url unique)
			if (method == 'POST') {
				AJAX.open(method, urlCall, true);                        // Open the url this object was set-up with.
				AJAX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				AJAX.setRequestHeader('Content-length', passData.length);
				AJAX.send(passData);
			} else {
				var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1); // Append date to url (so the browser doesn't cache the call)
				AJAX.open(method, uri, true);                             // Open the url this object was set-up with.
				AJAX.send(null);                                          // Send the request.
			}
			return true;                                                // Everything went a-ok.
		}                                                              // End Ajax setup aok if/else block                 
	}
	
	// This area set up on constructor calls.
	var urlCall = url;                                                // Remember the url associated with this object.
}                                                                    // End AjaxObject

var tooltip_visible = false;

function gm_tooltip_show(id,pointObj,x,y)
{
	var tooltip = document.getElementById('gm_tooltip_' +id);
	tooltip.style.display 	= "block";		
	tooltip.style.position 	= "absolute";	
	tooltip.style.top 		= y + 5 + "px";	
	tooltip.style.left		= x + 5 + "px";
	console.log(x+"/"+y);
}

function gm_tooltip_close(id,notimeout)
{
	if(notimeout)
	{
		hide_tooltip(id);
	}
	else
	{
		window.setTimeout("hide_tooltip("+id+");",10000);	
	}
}

function hide_tooltip(id)
{
	document.getElementById('gm_tooltip_' +id).style.display = "none";	
}

function popupmenue(show,obj)
{
	if(document.getElementById('popup_button'))
		document.getElementById('popup_button').className = show ? "active" : "";
	if(document.getElementById('popup_menue'))
		document.getElementById('popup_menue').style.display = show ? "block" : "none";	
}

function pageLoad() {
	if(document.getElementById('google_popupmenu')) {
    	document.getElementById('google_popupmenu').style.display = "none";
	}
}

/*********************************************
  Drag & Drop GM Tooltips
 **********************************************/
 
 var mousemove_action = '';
var tooltip_id = '';
 
 // Maus-Position
// =============

var mouseX = 0;
var mouseY = 0;

function getmouseposition(evt) {
	if (evt) {
		mouseX = evt.pageX;
		mouseY = evt.pageY;
	} else if (window.event.clientX) {
		mouseX = window.document.body.scrollLeft+window.event.clientX;
		mouseY = window.document.body.scrollTop+window.event.clientY;
	}
	if (mousemove_action == 'tooltip_view' && tooltip_id != '') {
		tooltip_view(tooltip_id);
	}
	// verschiebe Elemente
	if(dragobjekt != null) {
		if(mouseY > 20) {
			dragobjekt.style.top = (mouseY - dragy) + "px";
		}
		if (mouseX > 20) {
			dragobjekt.style.left = (mouseX - dragx) + "px";
		}
		return false;
	}
}

function getPosX(obj) {
	var ret=0;
	if (typeof obj != 'object') {
		obj = document.getElementById(obj);
	}
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			ret += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		ret += obj.x;
	}
	return ret;
}
function getPosY(obj) {
	var ret=0;
	if (typeof obj != 'object') {
		obj = document.getElementById(obj);
	}
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			ret += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		ret += obj.y;
	}
	return ret;
}
function getHeight(obj) {
	var ret=0;
	if (typeof obj != 'object') {
		obj = document.getElementById(obj);
	}
	if (obj.offsetHeight) {
		return obj.offsetHeight;
	}
}
function getWidth(obj) {
	var ret=0;
	if (typeof obj != 'object') {
		obj = document.getElementById(obj);
	}
	if (obj.offsetWidth) {
		return obj.offsetWidth;
	}
}

// any Mousedown Action
function md_action(evt) {
	if (!evt) evt = window.event;
	// hide any context menu
	if (contexttimer != null) {
		contextoff();
		return false;
	}
	// dont mark other objects while dragging objects
	if (dragobjekt != null) {
		return false;
	}
}

// Verschiebe Objekt (eingebaut von Cornelius)
// =================

var dragobjekt = null;
// Position, an der das Objekt angeklickt wurde.
var dragx = 0;
var dragy = 0;
// Mausposition -> use mouseX / mouseY

// Wird aufgerufen, wenn ein Objekt bewegt werden soll.
function dragstart(element) {
	dragobjekt = element;
	dragx = mouseX - dragobjekt.offsetLeft;
	dragy = mouseY - dragobjekt.offsetTop;
}
// Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
function dragstop() {
	dragobjekt=null;
}


function start_drag(id) {
	dragstart(document.getElementById(id));
}

function stop_drag(id) {
	dragstop(document.getElementById(id));
}
// Initiere Mouseposition + optional DragStart
document.onmousemove = getmouseposition;
// Auskommentiert durch Bene da NS/Firefox Methode! 
//window.addEventListener("load",pageLoad,false);
/*
$(document).ready(function() {
	pageLoad();
})
*/

$(document).ready(function () {
	$('#lp_page').change (function () {
			$('.lp_subpage').hide();
			$('#lp_subpage_' + $(this).val()).show();
		})
	$('.lp_subpage').change (function () {
			var site = $(this).val();
			if(typeof(urchinTracker) != "undefined") {
				urchinTracker("/weltnavigation/" + site + ".html");
			}
			window.location.href = "/online_reisefuehrer/" + site;
		});
});

window.onload = function() {pageLoad()};
