/* Lufthansa KOSA RD - JavaScripts */
// -------- START: browser check 
var ns4 = (document.layers) ? 1 : 0; // Netscape 4
var op = (window.opera) ? 1 : 0; // Opera
var op7 = (navigator.userAgent.match(new RegExp("[\w\s ]*Opera.7[\w\s ]*"))) ? 1 : 0; // Opera 7
var op8 = (navigator.userAgent.match(new RegExp("[\w\s ]*Opera.8[\w\s ]*"))) ? 1 : 0; // Opera 8
var ie = (document.all && !op) ? 1 : 0; // MS Internet Explorer
var ie50 = (ie && !document.createEventObject) ? 1 : 0; // MS Internet Explorer 5.0
var moz = (document.getElementById && !ie) ? 1 : 0; // Mozilla/Gecko Browser
var saf = (navigator.userAgent.lastIndexOf("Safari") > 0);
var osx = (navigator.userAgent.lastIndexOf("OS X") > 0);
// -------- END: browser check

if(typeof lh == "undefined"){
	if(typeof this["lh"] == "undefined"){
		this.lh = {};
	}
	lh.global = this;
	lh.app = {}; // apps package
	lh.helper = {};
	lh.topics = {};
}
lh.INVISCLASS = "hide-dn";
lh.topics.EYECATCHERLOADED = "eyecatcherloaded";
lh.topics.EYECATCHERCLICKED = "eyecatcherclicked";

// global fkt overwrites
String.prototype.trim = function() { // Sometimes strings contain uneccessary chars
	return this.replace( /^\s+|\s+$/, "" ); 
}
//
window.addEvent = function(evnt,func) { // Adds more than one functions to window-events
		if(!this.attachEvent)
		{
			var old = eval("(this."+evnt+")");
			if(!old) old = function () {};
			eval("this."+evnt+" = function (){old();"+func+"()};");
		}else{
			this.attachEvent(evnt,eval(func));
		}
	}
// from Prototype JavaScript framework, version 1.4.0
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}
// -------- START: on select input switch radio
function changeRadioSelection(formId,fieldName,val) {
	var tmpN;
	var tmpE = document.getElementById(formId);
	for(var i=0; i<tmpE[fieldName].length; i++) {
		tmpE[fieldName][i].checked = false;
		if(tmpE[fieldName][i].value==val) tmpN=i;
	}
	tmpE[fieldName][tmpN].checked = true;
}
// -------- END: on select input switch radio

// generic search function for nodeTypes (eg. DIV) with specific CSS classes
function getElementsByClassName(cName, nType, mNode) { // cName=className, nType=nodeType(e.g. nType="DIV"), mNode=mothernode to start the search
	var nType = (nType==null) ? "DIV" : nType;
	var mNode = (mNode==null) ? window.document : mNode;
	var nodepts = mNode.getElementsByTagName(nType);
	var hits = new Array();
	for(var count=0; count<nodepts.length; count++) {
		if(nodepts[count].className.indexOf(cName,0)!= -1) {
			hits.push(nodepts[count]);
		}
	}
	return hits;
}

// cssClassChanger(flip|add|remove|verify,object,classname,second classname (needed with 'flip')
function cssClassChanger(strAct,obj,strClass1,cstrClass2){
	if(strAct=="flip"){
		obj.className=!cssClassChanger('verify',obj,strClass1)?obj.className.replace(strClass2,strClass1):
		obj.className.replace(strClass1,strClass2);
	}
	else if(strAct=="add"){
		if(!cssClassChanger('verify',obj,strClass1)){obj.className+=obj.className?' '+strClass1:strClass1;}
	}
	else if(strAct=="remove"){
		var rep=obj.className.match(' '+strClass1)?' '+strClass1:strClass1;
		obj.className=obj.className.replace(rep,'');
	}
	else if(strAct=="verify"){
		return new RegExp('\\b'+strClass1+'\\b').test(obj.className);
	}
}

// add events to objects
function addEventToObject(obj, evt, func) {
                try{
                	var oldhandler = obj[evt];
                	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
                 }catch(e){}
} 

// print dialog
function printWindow() {
	window.print();
}

// cookieEnable for testing if browser supports cookies
function cookieEnable(){
    if (document.cookie.indexOf("lhcookietest",0) < 0) {
	    var today = new Date();
	  	var expiry = new Date(today.getTime() + 5*60*1000);
	   	var cookie_string = "lhcookietest" + "=" + today.getTime();
	   	cookie_string += "; expires=" + expiry.toGMTString();
	   	cookie_string += "; path=" + "/";
	   	document.cookie = cookie_string;
	    if (document.cookie.indexOf((today.getTime()),0) < 0) {
	      return false;
	      }
	    else {
	      return true;
	    }
	 }
	 //alert("cookietest: " +document.cookie);
	 return true;
}
function setNoCookieUrlForForm(idForm,ncurl){
	if(!cookieEnable()){
		var obj = document.getElementById(idForm);
		for(var h=0;h<obj.attributes.length;h++)
		{
			if(obj.attributes[h].nodeName=="action")obj.attributes[h].nodeValue = ncurl;
		}
	}
	return true;
}

// -------- START: popupExtWin
// popup opener function, used for popups from content
function popupExtWin(wurl, wname, size, resize, navi) {
	size=new String(size);
	if (navi == 0) {
		var wfeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,';
	} else {
		var wfeatures = 'toolbar=yes,menubar=yes,location=yes,status=yes,directories=yes,';
	}
	
	if (resize == 0) {
		wfeatures = wfeatures + 'scrollbars=no,resizable=no,'
		widthOffSet = 0;
	} else {
		wfeatures = wfeatures + 'scrollbars=yes,resizable=yes,'
		widthOffSet = 16;
	}
	
	newWinSize = size.charAt(0);
	switch(parseInt(newWinSize)) {
		case 0: 
			theFirst	= size.indexOf("-");
			theSecond	= size.lastIndexOf("-");
			winWidth	= size.slice(theFirst+1,theSecond) ;
			winHeight	= size.slice(theSecond+1) ;
			break;
		case 1:
			// 5 columns - old: width=400,height=400
			winWidth	= 390;
			winHeight	= 393;
			break;
		case 2:
			// 7 columns - old: width=600,height=500
			winWidth	= 546;
			winHeight	= 493;
			break;
		case 3:
			// 8 columns - old: width=800,height=600
			winWidth	= 624;
			winHeight	= 493;
			break;
		case 4:
			// ?
			winWidth	= 1024;
			winHeight	= 768;
			break;
		default:
			// 8 columns is default - old: width=800,height=600
			winWidth	= 624;
			winHeight	= 493;
			break;
	} 
	wfeatures = wfeatures + 'width=' + (parseInt(winWidth)+parseInt(widthOffSet)) + ',height=' + winHeight
	jetzt = new Date();
	windowName = "newExtPopupWin" + jetzt.getHours() + jetzt.getMinutes() + jetzt.getSeconds();

	//now we need to escape th wurl afer the second questionmark. this could be when a visuaal scope is used
	wurllist = wurl.split('?');
	newwurlback = '';
	i = 2;
	while ( i < wurllist.length) {
		newwurlback = newwurlback + '?' + wurllist[i];
		i++;
	}
	
	newwurlback = escape(newwurlback);
	wurl = wurllist[0];
	
	if (wurllist.length > 1) {wurl = wurl + '?' + wurllist[1];}
	wurl = wurl + newwurlback;
    
	// adding Banner Link Tracking parameter CR 475
    if(typeof wt_global !='undefined'){
    	if(wt_global!=""){
    		if(url.indexOf("blank")<0){
    			// only if url is not 'about:blank' which is used for search popup (this is a bugfix)
				if(wurl.indexOf("?")>-1){
					wurl = wurl + "&" + wt_global;
				}else{
					wurl = wurl + "?" + wt_global;
				}
    		}
    	}
    }
	newCmd = windowName + "= window.open('"+wurl+"', '"+windowName+"', '"+wfeatures+"');";
	eval(newCmd);
}

// -------- END: popupExtWin
// -------- START: popupWin
/*
New general popup function with JSON parameter transfer
(also known as "named functions"), used for popups from apps, but not from content
Parameter must used as follows (e.g.):

popupWin({url:'http://www.lufthansa.de',width:100,height:200})
popupWin({url:'URL',predef_size:1,predef_navi:0,scrollbars:'yes',resizable:'no',px:200,py:200})

Parameter:

url --> URL of the new popup - required parameter!
nocookieurl --> URL for a browser without cookie support (but with JS support :-) )

predef_size --> 3 predefined sizes are possible
	predef_size:1 => 390x393
	predef_size:2 => 546x493
	predef_size:3 => 624x493
	predef_size:4 => 1024x768 (from old system)
	
predef_navi --> 2 predefined navigation states of the browser are possible
	predef_navi:0 => popup with: no toolbar,no locationbar,no directoriesbar,no statusbar and no menubar.
	predef_navi:1 => popup with: toolbar,locationbar,directoriesbar,statusbar and menubar.

predef_resize --> 2 predefined resize states of the browser are possible
	predef_resize:0 => popup without scrollbars and the popup is not resizable.
	predef_resize:1 => popup with scrollbars and the popup is resizable.

With the predef-parameters it is possible to generate the same popup behavior like the content-popup-function (popupExtWin) above do.
Hint: predef-parameters overrides some the following single parameter

width --> width of the new popup as integer
height --> height of the new popup as integer
px --> x-position of the new popup as integer (0,0 is the top left corner of the browser, x is horizontal)
py --> y-position of the new popup as integer (0,0 is the top left corner of the browser, y is vertical)
toolbar --> "yes" or "no" for a popup with/without a toolbar
location --> "yes" or "no" for a popup with/without a locationbar
directories --> "yes" or "no" for a popup with/without a directoriebar
status --> "yes" or "no" for a popup with/without a statusbar
menubar --> "yes" or "no" for a popup with/without a menubar

scrollbars --> "yes" or "no" for a popup with/without scrollbars
resizable --> "yes" for a resizable popupwindow, or "no" for a popupwindow with a fix size
dependent --> "yes for a popupwindow, which will be closed if the parentwindow will be closed (Gecko only, no IE)

anchorId --> Id of an HTML-Element, normaly an anchor, where the new popup should be places.
	If it is necessary to place a popup near the "open popup"-link, the Id of that link is needed.
	The right x-/y-parameter for that link are acquired by the script. Overrides given x-/y-parameters!

pxoffset --> horizontal pixel offset for an "anchor-placed" popup
pyoffset --> vertical pixel offset for an "anchor-placed" popup

framename --> for the new popup the given framename is used as framename (important for formsubmits into popups, because
	the form must have a known name for the target attribute. The framename is also used as the objectname for the windowobject in JS.
	It's optinal. If framename is not given a unique framename will be generated.

fullscreen --> "yes" or "no" for a new popup in fullscreen. Used if a link from a popup (eg. h+c/search) should open a new "parent"-Window, in
	case of the old/real parent window is closed by the user. Default is "no". Is it is set to "yes" position- and width/height-parameter widl be ignored.

focus --> "yes" or "no" for setting the focus to the opened new popup window. Default is "yes". Used if a link from a popup (eg. h+c/search)
	loads the page in the parentwindow.
	
Hint:
It is possible to leave out all or some parameter - only the url-parameter is required.
*/

function popupWin(p)
{
	var widthOffSet = 16;
	if(typeof p == "object"){
		
		var debug = p.debug?true:false;
		var url = p.url?p.url:"";
		var ncurl = p.nocookieurl?p.nocookieurl:""; 

		var predef_size = p.predef_size?p.predef_size:100; // default 100 do nothing
		var width = p.width?p.width:624;
		var height = p.height?p.height:493;

		var predef_navi = p.predef_navi?p.predef_navi:100; // default 100 do nothing
		var toolbar = p.toolbar?p.toolbar:"";
		var location = p.location?p.location:"";
		var directories = p.directories?p.directories:"";
		var status = p.status?p.status:"";
		var menubar = p.menubar?p.menubar:"";

		var predef_resize = p.predef_resize?p.predef_resize:100; // default 100 do nothing
		var scrollbars = p.scrollbars?p.scrollbars:"";
		var resizable = p.resizable?p.resizable:"";
	
		var dependent = p.dependent?p.dependent:"";
		var anchorId = p.anchorId?p.anchorId:"";
		
		var pxoffset = p.pxoffset?p.pxoffset:0;
		var pyoffset = p.pyoffset?p.pyoffset:0;
		
		var px = p.px?p.px:"";
		var py = p.py?p.py:"";
		
		var framename = p.framename?p.framename:"";
		var fullscreen = p.fullscreen?p.fullscreen:"";
		var focus = p.focus?p.focus:"yes";
		var objectreturn = p.objectreturn?p.objectreturn:"";
		
		if (ncurl.indexOf("http") == -1) {
			ncurl = "";
		}
		
	}else{alert("JS-function 'popupWin': No Parameter!");return false}
	if(url==""){alert("JS-function 'popupWin': No URL!");return false}
	if(ncurl!=""){
		if(!cookieEnable()){
			url = ncurl;
		}
	}

	switch(parseInt(predef_size)){
		case 1:
			width	= 390;
			height	= 393;
			break;
		case 2:
			width	= 546;
			height	= 493;
			break;
		case 3:
			width	= 624;
			height	= 493;
			break;
		case 4:
			// ?
			width	= 1024;
			height	= 768;
			break;
		default:
			//
			break;
	}
	switch(parseInt(predef_navi)){
		case 0:
			toolbar="no";
			location="no";
			directories="no";
			status="no";
			menubar="no";
			break;
		case 1:
			toolbar="yes";
			location="yes";
			directories="yes";
			status="yes";
			menubar="yes";
			break;
		default:
			//
			break;
	}
	switch(parseInt(predef_resize)){
		case 0:
			scrollbars="no";
			resizable="no";
			break;
		case 1:
			scrollbars="yes";
			resizable="yes";
			break;
		default:
			//
			break;
	}
	if(scrollbars=="yes")width = width+ widthOffSet;
	if(anchorId!="")
	{
		try {
			var obj = document.getElementById(anchorId);
			px = findPosX(obj)+pxoffset;
			py = findPosY(obj)+pyoffset;
			// correction for popup, because findPosX/Y is related to the document, but scrolling / position and config of parent window is not include in this coordinates
			if (document.getElementById) {
				if (isNaN(window.screenX)) {
					px=px-document.body.scrollLeft+window.screenLeft;
					py=py-document.body.scrollTop+window.screenTop;
					}
				else {
					px=px+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
					py=py+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
					}
				}
			else if (document.all) {
				px=px-document.body.scrollLeft+window.screenLeft;
				py=py-document.body.scrollTop+window.screenTop;
			}			
			// find out if new popupwindow is full or partial out of the visual range of the screen. If so, coordinates will be corrected
			if(screen.availWidth<(px+width))
			{
				px = px+((screen.availWidth)-(px+width));
			}		
			if(screen.availHeight<(py+height))
			{
				py = py+((screen.availHeight)-(py+height));
			}
		} catch (error) {
			// defaults
			px = 100;
			py = 100;
		}	
	}	
	strAttr = "width="+width+",height="+height;
	if(toolbar!="") strAttr=strAttr+",toolbar="+toolbar;
	if(location!="") strAttr=strAttr+",location="+location;
	if(directories!="") strAttr=strAttr+",directories="+directories;
	if(status!="") strAttr=strAttr+",status="+status;
	if(menubar!="") strAttr=strAttr+",menubar="+menubar;
	if(scrollbars!="") strAttr=strAttr+",scrollbars="+scrollbars;
	if(resizable!="") strAttr=strAttr+",resizable="+resizable;
	if(dependent!="") strAttr=strAttr+",dependent="+dependent;
	if(px!="") strAttr=strAttr+",left="+px;
	if(py!="") strAttr=strAttr+",top="+py;
	
	if(debug)alert(strAttr);
	if(framename==""){
		objNow = new Date();
		framename= "newPopupWin" + objNow.getHours() + objNow.getMinutes() + objNow.getSeconds();
	}

	// adding Banner Link Tracking parameter CR 475
	if(typeof wt_global !='undefined'){
    	if(wt_global!=""){
    		if(url.indexOf("blank")<0){
    			// only if url is not 'about:blank' which is used for search popup (this is a bugfix)
				if(url.indexOf("?")>-1){
					url = url + "&" + wt_global;
				}else{
					url = url + "?" + wt_global;
				}
    		}
    	}
    }
	
	if(fullscreen=="yes")strNewCmd = framename + "= window.open('"+url+"', '"+framename+"');";
	else strNewCmd = framename + "= window.open('"+url+"','"+framename+"', '"+strAttr+"');";
	eval(strNewCmd);
	try {
		if(fullscreen=="yes"){
			eval(framename+".resizeTo(screen.availWidth,screen.availHeight)");
			eval(framename+".moveTo(0,0)");
		}
		if(focus=="yes")eval(framename+".focus()");
		if(objectreturn=="yes") return eval(framename);
		else return false;
	} catch (e) {
		return false;
	}
}

// Popup (copied from 1b)
// START openPopup
function openPopup(popupurl, popupname, size, resize, navi, xposition, yposition, body, cookieName, cookieExpire) {
	// cntIDxxxxx_popIDxxxxx
	// cntID: ID of the content invoking the popupwindow
	// popID: ID of the content within the popwindow 
	// cntID_popIDxxxxx means, that ID of invoking page is not defined

	showPopup = true;	

	if (cookieName.indexOf('_') != 5) {
		if (getCookie(cookieName) == null) {
			if (cookieExpire != "") {
				if (cookieExpire == -1) {
					setCookie(cookieName,"TRUE","")
				} else {
					setCookie(cookieName,"TRUE",cookieExpire)
				}
			}
		} else {
			showPopup = false;
		}
	}

	var htmlString	= '';
	if (showPopup) {
	/*	if (popupStartStr && typeof(popupStartStr)) htmlString += popupStartStr;
		htmlString += body;
		if (popupEndStr && typeof(popupEndStr)) htmlString	+= popupEndStr; */
		popupExtWinText(popupurl, popupname, size, resize, navi, xposition, yposition, htmlString);
	}
}//END openPopup
// -------- END : popupWin

// Helper function to detect the position of an element
// Used in 'popupWin', ...
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//
function lnkToParentWin(url)
{
	try {
		if(!window.opener) throw "error";
		if(window.opener.closed) throw "error";
		window.opener.location.href=url;
	}
	catch (e) {
		window.opener = eval("popupWin({url:'"+url+"',fullscreen:'yes',focus:'no',objectreturn:'yes'})");
	}
	window.focus();
	return false;
}

// MAMCard check
function checkMAMCard(pNumber) {

	// valid number-ranges:
	pValidPrefix5="99200,22201,99222,33303,99990";
	pValidPrefix6="401000,403400,531000,523400,401001,531001,401002,531002,401003,531003";

	// check empty card
	if (pNumber=="") return false;
	// check correct length
	if (((new String(pNumber)).length<14 ) || ((new String(pNumber)).length > 16 )) return false;
	var num5 = new String(pNumber.substring(0,5));
	var num6 = new String(pNumber.substring(0,6));
	// check valid prefix
	if ((pValidPrefix5.indexOf(num5) != 0) && (pValidPrefix6.indexOf(num6) != 0))  return false;
	// found MAM Card	
	return true;
}

// submitter for header navigation (added for RSB_COM language selection)
function lh_navhdjump(field) {
	self.location.href = field.options[field.selectedIndex].value; 
}

// select list (SEL) submitter (legacy support)
function lh_selSubmit(field) {

	var selectedData  = field.options[field.selectedIndex].value; 
	var selectedPopupSize   = Number(selectedData.charAt(0)); 
	var selectedPopupResize = Number(selectedData.charAt(1)); 
	var selectedPopupNavi   = Number(selectedData.charAt(2)); 
	var selectedURL   = selectedData.substr(4,selectedData.length-1); 
	if (selectedData.charAt(0) != " " && selectedPopupSize != 0) {
		popupExtWin(selectedURL,"newWin",selectedPopupSize,selectedPopupResize,selectedPopupNavi); 
	} else {
		if (selectedData != '   ##' && selectedURL != '') {
			window.location.href = selectedURL; 
		}
	}
}

/* This functions resets all formfields of a form with the given Id.
 * This is necessary because a reset-button only sets the values back to the values before the use change some data.
 * Only the non-readonly fields will be reseted. On every element the onchange-event is fired.
 * Parameters: sID --> the Id of the form
 */
function lh_form_reset(sId) {
	if((sId==null)||(sId==""))return;
	try {
			oForm = document.getElementById(sId);
			for(i=0;i<oForm.elements.length;i++) {
				oEle = oForm.elements[i];
				if(!oEle.readOnly){
					oCurrentTyp = oEle.type;
					switch(oCurrentTyp) {
						case "text":
							oEle.value = "";
							break;
						case "textarea":
							oEle.value = "";
							break;
						case "checkbox":
							oEle.checked = false;
							break;
						case "radio":
							oEle.checked = false;
							break;
						case "select-multiple":
							for(j=0;j<oEle.options.length;j++) {
								oEle.options[j].selected = false;
							}
							break;
						case "select-one":
							oEle.selectedIndex = 0;
							break;
					}
					if(oEle.fireEvent)oEle.fireEvent("onchange"); // easy way for IE 5.5 and later.
					else {
						sChangeCode = oEle.getAttribute("onchange");
						if((sChangeCode!=null)&&(sChangeCode!="")) {
							if((typeof sChangeCode)=="function") // for IE 5.0
							{
								sChangeCode = String(sChangeCode);
								tmpFrsPos = sChangeCode.indexOf("{");
								tmpLstPos = sChangeCode.indexOf("}");
								sChangeCode = sChangeCode.slice(tmpFrsPos+1,tmpLstPos);
							}
							try {
								eval(sChangeCode);
							}
							catch(e){
								// nothing
							}
						}
					}
				}
			}
	}
	catch(e){
		// nothing
	}
}

/* This function is a submit function which checks before submit,
 * if terms and conditions are accepted by the user. If not,
 * an error message is displayed. After a successful test,
 * the screen for "transaction in progress" is displayed 
 * until submit is finished.  
 * Paramters: actionname: submit action, frmId: name/id submit form, checkId: id checkbox 
*/
function submitCheck(actionname,frmId,checkId) {

	if ((document.getElementById(checkId)).checked) {
		/* show transaction screen */
		(document.getElementById("part1")).style.display="none";
		(document.getElementById("part2")).style.display="block";
		submitFormOld(actionname,frmId);		
		document.getElementById("top").focus(); 
		
	}
	else {
		/* show error message */
		(document.getElementById("checkError")).style.display="block";		
	}
}

/* This function is a submit function which checks before submit,
 * if terms and conditions are accepted by the user. If not,
 * an error message is displayed. After a successful test,
 * the screen for "transaction in progress" is displayed 
 * until submit is finished.  
 * Paramters: actionname: submit action, frmId: name/id submit form, checkId: id checkbox 
*/
function submitTcAndCvcCheck(actionname,frmId,checkId,cvcId) {
	var cvcValue = (document.getElementById(cvcId)).value;
	var cvc = (isNumeric(cvcValue) && (cvcValue.length == 3 || cvcValue.length == 4));
	
	if ((document.getElementById(checkId)).checked && cvc) {
		/* show transaction screen */
		(document.getElementById("part1")).style.display="none";
		(document.getElementById("tc")).style.display="none";
		(document.getElementById("cvcEmpty")).style.display="none";
		(document.getElementById("cvcInvalid")).style.display="none";
		(document.getElementById("part2")).style.display="block";
		submitFormOld(actionname,frmId);		
		document.getElementById("top").focus(); 		
	}
	else {
		/* show error message */
		(document.getElementById("checkError")).style.display="block";
		if((document.getElementById(checkId)).checked){
			(document.getElementById("tc")).style.display="none";	
		} else{
			(document.getElementById("tc")).style.display="block";
		}
		if(document.getElementById(cvcId).value == ""){
		 	(document.getElementById("cvcEmpty")).style.display="block";
		 	(document.getElementById("cvcInvalid")).style.display="none";
		} else{
			(document.getElementById("cvcEmpty")).style.display="none";
			if(cvc){
				(document.getElementById("cvcInvalid")).style.display="none";
			} else{
				(document.getElementById("cvcInvalid")).style.display="block";
			}	
		}
	}
}

function isNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}

function submitFormOld(actionname,frmId) {	
	document.getElementById(frmId).action= actionname;
	document.getElementById(frmId).submit();
}

/* This function changes the value of the euro-textfields dependent on the selected number of miles.
 * The textfields must have an ID (e.g.'costs_rec') + counter for the # of recipients.
 * Parameters: element: drop-down-list for miles, idname: id of the textfield without counter,
 * idnumber: counter of ID, app: application which calls the function (at the moment it
 * can be 'bm' or 'gm')  
 * Calls: sum_costs(idname) to add all values 
 */
function get_costs(element,idname,idnumber,app) {

	var elem= document.getElementById(element);	
	if (elem.value=="") {
		document.getElementById(idname + idnumber).value= "0.00";  
	} else {
		/*document.getElementById(idname + idnumber).value= (Number(elem.value)).toFixed(2);*/
		document.getElementById(idname + idnumber).value= elem.value;
	}	
	//only app_gm has a textfield to summarize all costs
	if (app=="gm") {
		sum_costs(idname);
	}
}

/* This functions adds all values in the euro-textfields. The textfields must 
 * have an ID (e.g. 'costs_rec') + counter for the # of recipients. The textfield for the sum
 * must have the ID 'costs_all'.
 * Parameters: id_name: ID of the textfields without counter
 */
function sum_costs(idname) {
	var err= false;
	var i= 0.00;
	var n= 0.00;
	
	while (!err) {
		try {
			n+= Number(document.getElementById(idname + i).value);
			document.getElementById('costs_all').value= n + '.00';
			++i;	
		}
		catch (e) {
			err= true;
		}
	}
}

// retrieve info on cookie (copied from 1b). 
function getCookie(name) {
	var cookieStr = getCookieRaw(name);
	if (cookieStr != null) {
		cookieStr = urlEscape2htmlEscape(cookieStr);
	}
	return cookieStr;
}

// retrieve info on cookie - but not unescaped
function getCookieRaw(name) {
	var startIndex = document.cookie.indexOf(name); 
	var result = null;
	if (startIndex != -1) {
		var endIndex = document.cookie.indexOf(";", startIndex); 
		if (endIndex == -1) endIndex = document.cookie.length;
		result = document.cookie.substring(startIndex+name.length+1, endIndex)
	}
	return result
}

var windowCounter = 0;
function popupExtWinText(wurl, wname, size, resize, navi, xpos, ypos, windowText) {
	size=new String(size);
	
	if (navi == 0) {
		var wfeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,';
	} else {
		var wfeatures = 'toolbar=yes,menubar=yes,location=yes,status=yes,directories=yes,';
	}
	
	if (resize == 0) {
		wfeatures = wfeatures + 'scrollbars=no,resizable=no,'
	} else {
		wfeatures = wfeatures + 'scrollbars=yes,resizable=yes,'
	}
	
	winWidth	= 800;
	winHeight	= 600;
	newWinSize	= size.charAt(0);
	switch(parseInt(newWinSize)) {
		case 0: 
			theFirst	= size.indexOf("-");
			theSecond	= size.lastIndexOf("-");
			winWidth	= size.slice(theFirst+1,theSecond) ;
			winHeight	= size.slice(theSecond+1);
			wfeatures	= wfeatures + 'width=' + winWidth + ',height=' + winHeight
			break;
		case 1:
			wfeatures	= wfeatures + 'width=400,height=400'
			winWidth	= 400;
			winHeight	= 400;
			break;
		case 2:
			wfeatures	= wfeatures + 'width=600,height=500'
			winWidth	= 600;
			winHeight	= 500;
			break;
		case 3:
			wfeatures	= wfeatures + 'width=800,height=600'
			winWidth	= 800;
			winHeight	= 600;
			break;
		case 4:
			wfeatures	= wfeatures + 'width=1024,height=768'
			winWidth	= 1024;
			winHeight	= 768;
			break;
		default:
			winWidth	= 800;
			winHeight	= 600;
			wfeatures	= wfeatures + 'width=800,height=600'
			break;
	} 

	windowCounter++;
	if (wname == '') {
		jetzt = new Date();
		windowName = "newExtPopupWinText" + windowCounter + "_" +jetzt.getHours() + jetzt.getMinutes() + jetzt.getSeconds();

	} else {
		windowName = wname;
	}
	
	//now we need to escape th wurl afer the second questionmark. this could be when a visuaal scope is used
	wurllist = wurl.split('?');
	newwurlback = '';
	i = 2;
	while ( i < wurllist.length) {
		newwurlback = newwurlback + '?' + wurllist[i];
		i++;
	}
	newwurlback = escape(newwurlback);

	wurl = wurllist[0];
	if (wurllist.length > 1) {wurl = wurl + '?' + wurllist[1];}
	wurl = wurl + newwurlback;
	
	cmdOpenwindow = windowName + "= window.open('"+wurl+"', '"+windowName+"', '"+wfeatures+"');";
	eval(cmdOpenwindow);
	
	if (wurl == "")	{
		cmdWriteText = '';
		if (document.layers) {
			cmdWriteText += windowName + '.document.open();'
			cmdWriteText += windowName + '.document.write(\'' +windowText+ '\');'
			cmdWriteText += windowName + '.document.close();'
		} else {
			cmdWriteText += windowName + '.document.write(\'' +windowText+ '\');'
		}
		eval(cmdWriteText);
	}

	// calculate the window-position, problem: it is not necessary to detect 
	// the outer width of the window of the ie by javascript
	var winWidthOffset	= 0;
	var winHeightOffset	= 0;
	var screenWidth		= screen.availWidth;
	var screenHeight	= screen.availHeight;
	var winPosx			= xpos;
	var winPosy			= ypos;
	if (document.all) {
		if (navi == 0) {
			winWidth	= parseInt(winWidth)	+ 10
			winHeight	= parseInt(winHeight)	+ 30;
		} else {
			winHeight	= parseInt(winHeight)	+ 50;
		}
	} else {
		winWidth		= eval(windowName +'.outerWidth');
		winHeight		= eval(windowName +'.outerHeight');
	}
	if (winPosx == '') {
		winPosx = (screenWidth - winWidth) / 2;
	}
	winPosx = Math.floor(winPosx)
	if (winPosx < 0) winPosx = 10;

	if (winPosy == '') {
		winPosy = (screenHeight - winHeight ) / 2;
	}
	if (winPosy < 0) winposy = 10;
	
	eval(windowName + '.moveTo(winPosx, winPosy);');
	eval(windowName + '.focus();');
}

function countChars(inpfld,charcId,maxlen) {
	// add e.g. onKeyDown & onKeyUp="countChars(this,'charcounter',4000);" to input field
	if (inpfld.value.length > maxlen) inpfld.value = inpfld.value.substring(0,maxlen);
	else $(charcId).firstChild.nodeValue = maxlen-inpfld.value.length;
}
FormHelper = {
	form:null,
	submitForm: function (obj, /*function*/ popupTarget) {
		this.form = this.locateForm(obj);
		if (this.form != null) { 
			if (popupTarget != null) { popupTarget; }
			this.form.submit() ;
		}
	},
	locateForm: function (obj) {
		while(obj != null) {
			obj = obj.parentNode;
			if (obj.tagName == "FORM" || obj.tagName == "form") break;
		}
		return obj;
	}
}

// Login Layer with Tabs + Login Portlet Tabs
dojo.declare(
	"lh.widget.LoginTabHandler", null,
	{
		_initTabId: "",
		_resultUserId: null,
		_resultMamNo: null,
		
		constructor: function(params){
			dojo.mixin(this, params);
			this.tabAnkerNodeUser = dojo.byId(this.prefixIdAnker+this.sufixIdUserID);
			this.tabAnkerNodeMAMNo = dojo.byId(this.prefixIdAnker+this.sufixIdMAMNo);
			this.tabLiNodeUser = dojo.byId(this.prefixIdList+this.sufixIdUserID);
			this.tabLiNodeMAMNo = dojo.byId(this.prefixIdList+this.sufixIdMAMNo);
			this.formDivNodeUser = dojo.byId(this.frmDivUserID);
			this.formDivNodeMAMNo = dojo.byId(this.frmDivMAMNo);
			this.focusNodeUserID = dojo.byId(this.focusIDUserID);
			this.focusNodeMamNo = dojo.byId(this.focusIDMAMNo);
			if(this.initTab)this._initTabId = this.prefixIdAnker+this.initTab;
			this._tabHandler();
		},
		
		_tabHandler: function(){
			dojo.subscribe(this.topic ,this,"_tabClick");
			dojo.connectPublisher(this.topic, this.tabAnkerNodeUser,"onclick");
			dojo.connectPublisher(this.topic, this.tabAnkerNodeMAMNo,"onclick");
		},
		
		initActivTab: function(){
			dojo.publish(this.topic,[{iid:this._initTabId}])
		},
		
		_tabClick: function(event){

				if(!this._resultUserId){this._resultUserId = dojo.query(this.xClassUserId);}
				if(!this._resultMamNo){this._resultMamNo = dojo.query(this.xClassMAMNo);}
				
				try{
					lid=event.currentTarget.id;
				}catch(e){
					lid=event.iid;
				}
				
				if(lid == this.tabAnkerNodeUser.id){
					// for tabs
					dojo.addClass(this.tabAnkerNodeUser,"tabact");
					dojo.addClass(this.tabLiNodeUser,"act");		
					dojo.removeClass(this.tabAnkerNodeMAMNo,"tabact");
					dojo.removeClass(this.tabLiNodeMAMNo,"act");
					// for other elements with the same "execute"-class
					for(var i=0; i<this._resultMamNo.length; i++){
						dojo.style(this._resultMamNo[i],"display","none");	
					}
					for(var i=0; i<this._resultUserId.length; i++){
						dojo.style(this._resultUserId[i],"display","block");	
					}
					this.focusNodeUserID.focus();
				}
				if(lid == this.tabAnkerNodeMAMNo.id){
					// for tabs
					dojo.addClass(this.tabAnkerNodeMAMNo,"tabact");
					dojo.addClass(this.tabLiNodeMAMNo,"act");
					dojo.removeClass(this.tabAnkerNodeUser,"tabact");
					dojo.removeClass(this.tabLiNodeUser,"act");
					// for other elements with the same "execute"-class
					for(var i=0; i<this._resultUserId.length; i++){
						dojo.style(this._resultUserId[i],"display","none");	
					}
					for(var i=0; i<this._resultMamNo.length; i++){
						dojo.style(this._resultMamNo[i],"display","block");	
					}
					this.focusNodeMamNo.focus();
				}
				this._initTabId = lid;
				if(!event.iid)event.preventDefault();
		}
});


dojo.declare(
		"lh.widget.LoginLayerHandler",null,
		{
			
			_layer: null,
			_tabHandler: null,
			
			constructor: function(params){
				dojo.mixin(this, params);
				
				loginText = document.createTextNode(this.strText);
				this.linkOpenNode.appendChild(loginText);
				
				dojo.connect(this.linkNode , "onclick", this, "_buttonClick");
				dojo.connect(this.linkOpenNode , "onclick", this, "_buttonOpenClick");
				
			},
			_buttonClick: function(event){
				if(!this._layer){
					this._layer = new lh.widget.LoginLayer({
									srcNodeRef:this.layerNode,
									appendNode:this.appendNode,
									parent: this
									});
				}
				this._layer.toggle();
				
				dojo.style(this.linkNode,"display","none");
				dojo.style(this.linkOpenNode,"display","block");
				dojo.style(this.barNode,"display","block");
				pos = dojo.marginBox(this.linkOpenNode);
				dojo.style(this.barNode,"width",(pos.w-1)+"px");
				dojo.style(this.barNode,"height","150px");
				dojo.style(this.barNode,"zIndex","990");
				
				
				if(!this._tabHandler){
					this._tabHandler = new lh.widget.LoginTabHandler({
											initTab: this.initTab,
											prefixIdAnker: this.prefixIdAnker,
											prefixIdList: this.prefixIdList,
											sufixIdUserID: this.sufixIdUserID,
											sufixIdMAMNo: this.sufixIdMAMNo,
											xClassUserId: this.xClassUserId,
											xClassMAMNo: this.xClassMAMNo,
											focusIDUserID: this.focusIDUserID,
											focusIDMAMNo: this.focusIDMAMNo,
											topic: "LOGINLAYERTAPCLICKED"
											});
				}
				this._tabHandler.initActivTab();
				event.preventDefault();
			},			
			_buttonOpenClick:  function(event){
				dojo.style(this.linkNode,"display","block");
				dojo.style(this.linkOpenNode,"display","none");
				dojo.style(this.barNode,"display","none");
				if(event)dojo.stopEvent(event);
			}
		}
);

dojo.declare(
		"lh.widget.LoginLayer",[dijit._Widget],
		{
			isActive: false,
			_iframe: null,
			
			constructor: function(params){
				dojo.mixin(this, params);
				this.domNode = this.srcNodeRef;
				dojo.query("body")[0].appendChild(this.domNode);
				dojo.style(this.domNode,"position","absolute");
				dojo.style(this.domNode,"top","10px");
				dojo.style(this.domNode,"left","10px");
				dojo.style(this.domNode,"zIndex","1000");

			},
			toggle: function(){
				if(!this.isActive)this._show();
				else this._hide();
			},
			_show: function(){
				dojo.style(this.domNode,"display","block");
				this.pos = dojo.coords(this.appendNode,true);
				dojo.style(this.domNode,"top",this.pos.y+this.pos.h+11+"px");
				dojo.style(this.domNode,"left",this.pos.x+"px");
				dojo.style(this.domNode,"width","224px");
				
				if((dojo.isIE)&&(dojo.isIE < 7)){
					if(!this._iframe) this._iframe= new dijit.BackgroundIframe(this.domNode);
				}
				this.isActive = true;
			},
			_hide: function(){
				dojo.style(this.domNode,"display","none");
				this.parent._buttonOpenClick();
				this.isActive = false;
			},

			_onBlur: function(){
				// summary: called magically when focus has shifted away from this widget
				this._hide();
				this.inherited(arguments);
			},
			postMixInProperties:function(){
				this.inherited(arguments);
			}
		}
);
/* Type ahead for lh in theme and search */
/* the store with additional query parameters */
dojo.declare("lh.TypeAheadReadStore",dojox.data.QueryReadStore,
{
	fetch:function(request) {
    	request.serverQuery = {
    		query:request.query.result,
	    	rep: this.rep,
    		site: this.site,
	    	lang: this.lang,	
    		portal: this.portal,
    		apptype: this.apptype
    	};
		return this.inherited("fetch", arguments);
    }
});
/* END Login Layer */
/* the type ahead widget */
dojo.declare("lh.widget.TypeAhead",[dijit._Widget, dijit.form.ComboBoxMixin],
        {
	     	// switch for debug messages
	     	debug:false,
	     	// Necessary to keep Dijit from using templateString in AccordionPane
	        templateString: "",
			
			// if set to true, request to backend will be fired
			isActive: true,
			// default false, no searchterm highlighting
			highlightSearchTerm: false,
			
			MIN_QUERY_LENGTH: 3,
			
			// default
			requestMethod: "get",

			postCreate: function (){},
			
			constructor: function(params) {
				dojo.mixin(this, params);
				this.searchAttr ="result";
				this.domNode = dojo.byId(this.idSearchInput);
				this.focusNode = this.domNode;
				this.comboNode = this.domNode;
				
				this.store = new lh.TypeAheadReadStore({
						jsId:this.jsId,
						url:this.url,
						requestMethod:this.requestMethod,
						site: this.site,
						rep: this.rep,
	            	   	site: this.site,
		           		lang: this.lang,
    	    	       	portal: this.portal,
    	    	       	apptype: this.apptype
				}, dojo.byId(this.storeId));
				
				dojo.connect(this.focusNode, "onkeypress", this, "_onKeyPress");
				dojo.connect(this.focusNode, "onfocus", this, "onFocus");
				dojo.connect(this.focusNode, "compositionend", this, "compositionend");
				this.setInactiveOnBlurHandler = dojo.connect(this.focusNode, "onblur", this, "_setListInactive");
			},
			onkeyup: function(evt){
				this.onfocus(evt);
			},
			_onMouse: function(/*Event*/ event){
				return;	
			},
			_arrowPressed: function(){
				return;
			},
			_arrowIdle: function(){
				return;
			},
			displayMessage: function(){
				return;
			},
			getValue:function(){
				return this.focusNode.value;
			},
			setValue:function(pValue){
				this.focusNode.value = pValue;
			},
			getDisplayedValue: function(){
				return this.getValue();
			},
			
			_startSearch: function(/*String*/ key){
				// Minimum length is 3
				if (key.length >= this.MIN_QUERY_LENGTH && this.isActive) {
					if(this.debug)console.debug("Minimum length reached, firing search!");
					if(!this._popupWidget){
						this._popupWidget = new lh.widget._TypeAheadPopUp({
							onChange: dojo.hitch(this, this._selectOption),
							idAppendNode: this.idAppendNode,
							idCloseNode: this.idCloseNode
						}, dojo.byId(this.idAppendNode));
						this._popupWidget._messages = [];
					}
					// create a new query to prevent accidentally querying for a hidden value from FilteringSelect's keyField
					var query=this.query;
					this._lastQuery=query[this.searchAttr]=key;
					var dataObject=this.store.fetch({queryOptions:{ignoreCase:this.ignoreCase, deep:true}, query: query, onComplete:dojo.hitch(this, "_openResultList"), start:0, count:this.pageSize});			
				}
			},

			_announceOption: function(/*Node*/ node){
				// summary:
				//	a11y code that puts the highlighted option in the textbox
				//	This way screen readers will know what is happening in the menu
	
				if(node==null){return;}
				// pull the text value from the item attached to the DOM node
				var newValue;
				if(!(this._popupWidget && node==this._popupWidget.closeButton)){
					newValue=this.store.getValue(node.item, this.searchAttr);
				}
				// get the text that the user manually entered (cut off autocompleted text)
				this.focusNode.value=this.focusNode.value.substring(0, this._getCaretPos(this.focusNode));
				// autocomplete the rest of the option to announce change
				if (this.autoComplete)
					this._autoCompleteText(newValue);
			},
			
			_selectOption: function(/*Event*/ evt){
				var tgt = null;
				if(!evt){
					evt ={ target: this._popupWidget.getHighlightedOption()};
				}
					// what if nothing is highlighted yet?
				if(!evt.target){
					// handle autocompletion where the the user has hit ENTER or TAB
					this.setDisplayedValue(this.getDisplayedValue());
					return;
				// otherwise the user has accepted the autocompleted value
				} else {
					if (evt.noHide) {
						this.closeResultList();
						return;
					} else {
						tgt = evt.target;
					}
				}
				if(!evt.noHide){		
					this._hideResultList();
					this._setCaretPos(this.focusNode, this.store.getValue(tgt.item, this.searchAttr).length);
				}
				this._doSelect(tgt);
				this._submitForm();
			},

			closeResultList: function () {
				// call on_blur superclass
				// dijit.form.ComboBoxMixin.prototype._onBlur.apply(this, arguments);
				// deactivate our widget
				this._hasFocus=false;
				this._hasBeenBlurred = true;
				this._hideResultList();
				this._arrowIdle();
				this.isActive = false;
			},

			_onKeyPress: function(/*Event*/ evt){
				// summary: handles keyboard events
				//except for pasting case - ctrl + v(118)
				if(evt.altKey || (evt.ctrlKey && evt.charCode != 118)){
					return;
				} 
				if (this._popupWidget) {
					var highlighted = this._popupWidget.getHighlightedOption();
					// if enter was hit from within the popup
					if((evt.keyCode==dojo.keys.ENTER && (highlighted == this._popupWidget.closeButton))) {
						this.closeResultList();
						// default case:
						// prevent submit, but allow event to bubble
						evt.preventDefault();
						// fall through
					} else if (evt.keyCode==dojo.keys.DOWN_ARROW && (highlighted == this._popupWidget.closeButton)) {
						// if it's the close button, our last element
						dojo.stopEvent(evt);
					} else if (evt.keyCode==dojo.keys.ENTER && !this._isShowingNow) {
						// user hit enter and no popup is up
						// submitting form
						this._submitForm();
						dojo.stopEvent(evt);
						return;
					} else if (evt.keyCode==dojo.keys.ENTER && this._isShowingNow) {
						// user entered on a search value, so fill value and fire the search
						this._autoCompleteText(this.store.getValue(this._popupWidget.getHighlightedOption().item, this.searchAttr));
						this._submitForm();
						dojo.stopEvent(evt);
					} else if (evt.keyCode==dojo.keys.ESCAPE){
						this.closeResultList();
						evt.preventDefault();
					}else if(evt.keyCode==dojo.keys.BACKSPACE && this._isShowingNow && (highlighted!=null)){
						// Needed for IE because of problems in 'dijit.scrollIntoView':
						// if resultlist is displayed + backspace is used the closing of the resultlist must be ensured
						this.closeResultList();
						this._setListInactive(); //special needed for IE
						this.isActive = true; //set it active again, so a new keyhit will invoke the typeahead again
						evt.preventDefault(); // Backspace will only close the list, but not delete a charactar in input field.
					} else {
						// call superclass
						dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);					}
				}else {
					// call superclass
					if (evt.keyCode==dojo.keys.ENTER) {
						this._submitForm();
						dojo.stopEvent(evt);
					}else{
						dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);
					}
				}
			},
			postMixInProperties: function(){
				dijit.form.ComboBoxMixin.prototype.postMixInProperties.apply(this, arguments);
			},
			_submitForm: function(){
				if(this.resultPopupName){
					popupWin({framename:this.resultPopupName,url:'about:blank',predef_size:3,predef_navi:0,scrollbars:'yes',resizable:'no'})
					FormHelper.submitForm(this.domNode);					
					this.closeResultList();
				} else FormHelper.submitForm(this.domNode);
				this.isActive = true;
			},
			_autoCompleteText: function(/*String*/ text){
				// overwrites same method in dijit.form.ComboBoxMixin
				// the autocomplete removed and also the hightlighting
				var fn = this.focusNode;
				dijit.selectInputText(fn, fn.value.length);
				fn.value = text;
			},
			_setListInactive: function(){
				// Needed for IE because of problems in 'dijit.scrollIntoView'
				// if a second usage of typeahead is invoked, after hiding first suggestlist.
				if(this._popupWidget){
					this._popupWidget._highlighted_option = null;
				}
			},
			_getMenuLabelFromItem:function(/*Item*/ item){
				if(this.highlightSearchTerm){
					var searchResultLabel = this.store.getValue(item, this.searchAttr);
					var searchTerm = this._lastQuery.split(" ");
					for(var j=0;j<searchTerm.length;j++){
						if(searchTerm[j]!=""){
							var regSearch = new RegExp("("+searchTerm[j]+")","gi");
							var regResult = searchResultLabel.match(regSearch);
							if(regResult){
								for(var i=0;i<regResult.length;i++){
									tempRegSearch = new RegExp("("+regResult[i]+")","g");
									searchResultLabel = searchResultLabel.replace(tempRegSearch,"<b>"+regResult[i]+"</b>");
								}
							}
						}
					}
					return {html: true, label: searchResultLabel};
				}else{
					return {html: false, label: this.store.getValue(item, this.searchAttr)};
				}
			}
        } // end param in declare
); // end declare
/* special typeahead for airports */
dojo.declare(
		"lh.widget.AirportTypeAhead",
        [lh.widget.TypeAhead],
	 	{
			// Maybe different from search type ahead
			MIN_QUERY_LENGTH: 3,
			
			// Visual Lenght of the result list (only for AirportTypeAhead!)
			// only works with pageSize = 0
			resultListLength: 10,
			
			// hidden airportcode field
			idHiddenCode: "",
			objHiddenCode: null,
			highlightSearchTerm: true,

			constructor: function(params) {
				lh.widget.TypeAhead.superclass.constructor.call(this);
				this.setActiveOnFocusHandler = dojo.connect(this.focusNode, "onfocus", this, "_setActive");
				if(this.idHiddenCode!="")this.objHiddenCode = dojo.byId(this.idHiddenCode);
				this.oldInputValue = "";
				this.airportCodeOnFocusHandler = dojo.connect(this.focusNode, "onfocus", this, "_prepareDeleteAirportCode");
				dojo.connect(this.focusNode, "onblur", this, "_checkToDeleteAirportCode");
				this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
			},

			_startSearch: function(/*String*/ key){
				// airport code will be deleted if user jumps back into the field and change the text
				if((this.oldInputValue!="")&&(this.oldInputValue!=this.focusNode.value)){
					this._deleteAirportCode();
				}
				// Minimum length is 3
				if (key.length >= this.MIN_QUERY_LENGTH && this.isActive) {
					dojo.disconnect(this.onBlurCopyNameAndCodeHandler);
					if(this.debug)console.debug("Minimum length reached, firing search!");
					if(!this._popupWidget){
						this._popupWidget = new lh.widget._TypeAheadPopUp({
							onChange: dojo.hitch(this, this._selectOption),
							idAppendNode: this.idAppendNode,
							idCloseNode: this.idCloseNode,
							listLength: this.resultListLength
						}, dojo.byId(this.idAppendNode));
						this._popupWidget._messages = [];
					}
					if(this.debug){
						if(!this.surl)this.surl = this.url;
						if(!this.z)this.z = 0;
						if(this.z < this.debug.length){
							this.url = this.surl+"?quantity="+this.debug[this.z];
							this.z++;
						}else{
							this.z = 0;
							this.url = this.surl+"?quantity="+this.debug[this.z];
							this.z++;
						}
						
						this.store = new lh.TypeAheadReadStore({
						jsId:this.jsId,
						url:this.url,
						requestMethod:this.requestMethod,
						site: this.site,
						rep: this.rep,
	            	   	site: this.site,
		           		lang: this.lang,
    	    	       	portal: this.portal,
    	    	       	apptype: this.apptype
						}, dojo.byId(this.storeId));
					}
					// create a new query to prevent accidentally querying for a hidden value from FilteringSelect's keyField
					var query=this.query;
					this._lastQuery=query[this.searchAttr]=key;
					var dataObject=this.store.fetch({queryOptions:{ignoreCase:this.ignoreCase, deep:true}, query: query, onComplete:dojo.hitch(this, "_openResultList"), start:0, count:0});			
				}else if(key.length<this.MIN_QUERY_LENGTH){
					this.closeResultList();
					this.isActive = true;
				}
			},

			_selectOption: function(/*Event*/ evt){
				// this methode must overwrite due to the fact that the airportcode must store in a hidden field.
				var tgt = null;
				if(!evt){
					evt ={ target: this._popupWidget.getHighlightedOption()};
				}
					// what if nothing is highlighted yet?
				if(!evt.target){
					// handle autocompletion where the the user has hit ENTER or TAB
					this.setDisplayedValue(this.getDisplayedValue());
					return;
				// otherwise the user has accepted the autocompleted value
				} else {
					if (evt.noHide) {
						this.closeResultList();
						return;
					} else {
						tgt = evt.target;
					}
				}
				if(!evt.noHide){		
					this._hideResultList();
					this._setCaretPos(this.focusNode, this.store.getValue(tgt.item, this.searchAttr).length);
				}
				// put airportcodevalue into hidden field.
				this._setAirportCode(tgt.item.i[this.keyForCode]);
				this._doSelect(tgt);
				this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
			},
		
			_onKeyPress: function(/*Event*/ evt){
				// summary: handles keyboard events
				//except for pasting case - ctrl + v(118)
				if(evt.altKey || (evt.ctrlKey && evt.charCode != 118)){
					return;
				}
				if(this._popupWidget) {
					var highlighted = this._popupWidget.getHighlightedOption();
					// if enter was hit from within the popup
					if((evt.keyCode==dojo.keys.ENTER && (highlighted == this._popupWidget.closeButton))) {
						// user hit enter on the close button -> close list
						this.closeResultList();
						dojo.stopEvent(evt);
						this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
					} else if (evt.keyCode==dojo.keys.DOWN_ARROW && (highlighted == this._popupWidget.closeButton)) {
						// if it's the close button, our last element -> do nothing
						dojo.stopEvent(evt);
					} else if (evt.keyCode==dojo.keys.ENTER && !this._isShowingNow) {
						// user hit enter and no suggest list is displayed -> do nothing
						dojo.stopEvent(evt);
					} else if (evt.keyCode==dojo.keys.ENTER && this._isShowingNow && (highlighted!=null)){
						// user entered 
						this._autoCompleteText(this.store.getValue(this._popupWidget.getHighlightedOption().item, this.searchAttr));
						this._setAirportCode(this._popupWidget.getHighlightedOption().item.i[this.keyForCode]);
						this.closeResultList();
						dojo.stopEvent(evt);
						this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
					} else if (evt.keyCode==dojo.keys.TAB && this._isShowingNow && (highlighted!=null)){
						//
						this._autoCompleteText(this.store.getValue(this._popupWidget.getHighlightedOption().item, this.searchAttr));
						this._setAirportCode(this._popupWidget.getHighlightedOption().item.i[this.keyForCode])
						this.closeResultList();
						this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
						dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);
					} else if (evt.keyCode==dojo.keys.ESCAPE){
						this.closeResultList();
						this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
						dojo.stopEvent(evt);
					} else if (evt.keyCode==dojo.keys.ENTER){
						dojo.stopEvent(evt);
					}else if(evt.keyCode==dojo.keys.BACKSPACE && this._isShowingNow && (highlighted!=null)){
						// Needed for IE because of problems in 'dijit.scrollIntoView':
						// if resultlist is displayed + backspace is used the closing of the resultlist must be ensured
						this.closeResultList();
						this._setListInactive(); //special needed for IE
						this.isActive = true; //set it active again, so a new keyhit will invoke the typeahead again
						evt.preventDefault(); // Backspace will only close the list, but not delete a charactar in input field.
					} else if (evt.keyCode==dojo.keys.DOWN_ARROW && (!highlighted)) {
						this._popupWidget.highlightFirstOption();
						//dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);
					} else if (evt.keyCode==dojo.keys.DOWN_ARROW || evt.keyCode==dojo.keys.UP_ARROW) {
						dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);
					} else {
						if(evt.keyCode==dojo.keys.TAB){
							this._onBlurCopyNameAndCode(); //call it direct
							//this.onBlurCopyNameAndCodeHandler = dojo.connect(this.focusNode, "onblur", this, "_onBlurCopyNameAndCode");
						}
						this.closeResultList();
						this._setListInactive();
						this.isActive = true;
						dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);
					}
				}else {
					// call superclass
					if((evt.keyCode==dojo.keys.ENTER)||(evt.keyCode==dojo.keys.ESCAPE)){
						dojo.stopEvent(evt);
					}else{
						dijit.form.ComboBoxMixin.prototype._onKeyPress.apply(this, arguments);
					}
				}
			},
			_prepareDeleteAirportCode:function(){
				// user jumpt back in the input field again - so current 'old' value will be stored
				// for later change test - all this because "onchange" works a bit confused here.
				if(this.airportCodeOnFocusHandler)dojo.disconnect(this.airportCodeOnFocusHandler);
				if(this.objHiddenCode.value != "")this.oldInputValue = this.focusNode.value;				
			},
			_checkToDeleteAirportCode:function(){
				// ensure that the field for airport code is empty if inputfield is also empty
				if(this.focusNode.value=="")this._deleteAirportCode();
			},
			_setAirportCode:function(code){
				if(this.objHiddenCode)this.objHiddenCode.value = code;
				this.oldInputValue = this.focusNode.value;
			},
			_onBlurCopyNameAndCode:function(){
				// first the onfocus connect is invoked again to ensure that a 2nd + 3rd revisit of the fields with changes will delete the airportcode again.
				this.airportCodeOnFocusHandler = dojo.connect(this.focusNode, "onfocus", this, "_prepareDeleteAirportCode");
				if(this.idsCopyTo){
					if(this.focusNode.value!=""){
						for(var i=0;i<this.idsCopyTo.length;i++){
							if(dojo.byId(this.idsCopyTo[i].name).value==""){
								dojo.byId(this.idsCopyTo[i].name).value = this.focusNode.value;
								dojo.byId(this.idsCopyTo[i].code).value = this.objHiddenCode.value;
							}
						}	
					}
				}
				dojo.disconnect(this.onBlurCopyNameAndCodeHandler);
			},
			_deleteAirportCode: function(){
				// after a airport code is set via typeahead suggest
				// and the user change the inputfield later the hidden airport code value will be deleted.
				if(this.objHiddenCode)this.objHiddenCode.value = "";
				this.oldInputValue = ""; //reset the test property for late usage
			},

			_setActive: function(){
				this.isActive = true;			
			},
			
			// needed for scrollbar in resultlist - overwrites same methode in 'dijit.form.ComboBoxMixin'
			// with some tweaks for a resultlist with scrollbars.
			_showResultList: function(){
				this._hideResultList();
				var items = this._popupWidget.getItems(),
					visibleCount = Math.min(items.length,this.maxListLength);
				this._arrowPressed();
				// hide the tooltip
				this.displayMessage("");
				
				// Position the list and if it's too big to fit on the screen then
				// size it to the maximum possible height
				// Our dear friend IE doesnt take max-height so we need to
				// calculate that on our own every time
	
				// TODO: want to redo this, see 
				//		http://trac.dojotoolkit.org/ticket/3272
				//	and
				//		http://trac.dojotoolkit.org/ticket/4108
	
				with(this._popupWidget.domNode.style){
					// natural size of the list has changed, so erase old
					// width/height settings, which were hardcoded in a previous
					// call to this function (via dojo.marginBox() call) 
					width = "";
					height = "";
				}
	
				if(this._popupWidget.scrollWrp){
					// resultlist with scrollbar
					var best = this.open();
					var newwidth = best.w;
					var widthScrollBar = lh.helper.gui.getScrollBarWidth();
					var hItems = this._popupWidget.listLength*(dojo.marginBox(this._popupWidget.scrollWrp.firstChild).h);
					var hClose = dojo.marginBox(this._popupWidget.scrollWrp.firstChild).h;


					// resize complete list widget with close button
					this._popupWidget.domNode.style.overflow = "hidden";
					dojo.marginBox(this._popupWidget.domNode, {
						h: hItems+hClose+3,
						w: Math.max(newwidth, this.domNode.offsetWidth)+widthScrollBar+3
					});
					
					// resize only scrollwrapper div
					dojo.style(this._popupWidget.scrollWrp,"overflow","auto");
					dojo.marginBox(this._popupWidget.scrollWrp, {
						h: hItems,
						w: Math.max(newwidth, this.domNode.offsetWidth)+widthScrollBar
					});

					// once again fire repositioning logic if dropdown is above inputelement
					var domBox = dojo.coords(this.domNode);
					if(best.y<domBox.y){
						dijit.popup.close(this._popupWidget);
						this.open();
					}
				}else{
					var best = this.open();
					// #3212:
					//		only set auto scroll bars if necessary prevents issues with
					//		scroll bars appearing when they shouldn't when node is made
					//		wider (fractional pixels cause this)
					var popupbox = dojo.marginBox(this._popupWidget.domNode);
					this._popupWidget.domNode.style.overflow = 
						((best.h==popupbox.h)&&(best.w==popupbox.w)) ? "hidden" : "auto";
					// #4134:
					//		borrow TextArea scrollbar test so content isn't covered by
					//		scrollbar and horizontal scrollbar doesn't appear
					var newwidth = best.w;
					if(best.h < this._popupWidget.domNode.scrollHeight){
						newwidth += 16;
					}
					// resultlist without scrollbar
					dojo.marginBox(this._popupWidget.domNode, {
						h: best.h,
						w: Math.max(newwidth, this.domNode.offsetWidth)
					});
				}
				dijit.setWaiState(this.comboNode, "expanded", "true");
			}
     }
);

lh.helper.gui = {
	returnWidth:null,
	
	getScrollBarWidth: function(){
		if(!this.returnWidth){
			var inner = document.createElement("p");
			dojo.style(inner,{
						"width":"100%",
						"height":"200px"
						});

			var outer = document.createElement("div");
			dojo.style(outer,{
				"position":"absolute",
				"top":"0px",
				"left":"0px",
				"visibility":"hidden",
				"width":"200px",
				"height":"150px",
				"overflow":"hidden"
			});
			
			outer.appendChild(inner);
			document.body.appendChild(outer);

			var w1 = inner.offsetWidth;
			dojo.style(outer,"overflow","scroll");
			var w2 = inner.offsetWidth;
			if (w1 == w2) w2 = outer.clientWidth;
			document.body.removeChild (outer);
			this.returnWidth = (w1 - w2);
		}
		return this.returnWidth;
	}
};

/* the result list */
dojo.declare(
		"lh.widget._TypeAheadPopUp",
		dijit._Widget,
		{
			scrollWrp: null,
			listLength: -1,
			
			constructor: function(params) {
				dojo.mixin(this, params);
				this.menueNode = dojo.byId(this.idAppendNode);
				this.domNode = this.menueNode;
				this.closeButton = dojo.byId(this.idCloseNode);
				dojo.connect(this.menueNode , "onmousedown", this, "onmousedown");
				dojo.connect(this.menueNode , "onmouseup", this, "onmouseup");
				dojo.connect(this.menueNode , "onmouseover", this, "onmouseover");
				dojo.connect(this.menueNode , "onmouseout", this, "onmouseout");
			},

			postMixInProperties:function(){
				this.inherited(arguments);
			},

			clearResultList:function(){
				// keep the close buttons of course
				if(!this.scrollWrp){
					while(this.domNode.childNodes.length>1){
						this.domNode.removeChild(this.domNode.childNodes[this.domNode.childNodes.length-2]);
					}
				}else{
					// if scrollbarlist all items in wrapper div must be removed
					while(this.scrollWrp.childNodes.length>0){
						this.scrollWrp.removeChild(this.scrollWrp.childNodes[this.scrollWrp.childNodes.length-1]);
					}
					// finaly wrapper div must be removed - only the close button is keept
					this.domNode.removeChild(this.scrollWrp);
					this.scrollWrp = null;
				}
			},
		
			createOptions:function(results, dataObject, labelFunc){
				var _this=this;
				if((this.listLength>0)&&(results.length>this.listLength)){
					var menuscrollwrapper = document.createElement("div");
					menuscrollwrapper.id = "typeheadScrollWrp";
					//menuscrollwrapper.className = "dijitMenuItem";
					dojo.forEach(results, function(item){
						var menuitem=_this._createOption(item, labelFunc);
						menuitem.className = "dijitMenuItem";
						menuscrollwrapper.appendChild(menuitem);
					});
					_this.domNode.insertBefore(menuscrollwrapper, _this.closeButton);
					this.scrollWrp = menuscrollwrapper;
				}else{
					dojo.forEach(results, function(item){
						var menuitem=_this._createOption(item, labelFunc);
						menuitem.className = "dijitMenuItem";
						_this.domNode.insertBefore(menuitem, _this.closeButton);
					});
				}
			},
			
			onmousedown:function(/*Event*/ evt){
				if(evt.target === this.domNode){
					return;
				}else if(evt.target === this.scrollWrp){
					return;	
				}else if(evt.target==this.closeButton) {
					// Here's the trick, set this to noHide to close the popup in closeButton!
					this.setValue({noHide:true, target:evt.target}, false);
				}else{
					var tgt=evt.target;
					// while the clicked node is inside the div
					while(!tgt.item){
						// recurse to the top
						//alert(tgt.innerHTML);
						tgt=tgt.parentNode;
					}
					this.setValue({target:tgt}, true);
				}
			},
			
			onmouseover:function(/*Event*/ evt){
				if(evt.target === this.domNode){ return; }
				if(evt.target === this.scrollWrp){ return; }
					var tgt=evt.target;
					if(!(tgt==this.closeButton)){
						// while the clicked node is inside the div
						while(!tgt.item){
							// recurse to the top
							tgt=tgt.parentNode;
						}
					}
					//alert(tgt.innerHTML);
					this._focusOptionNode(tgt);
			},
			
			getHighlightedOption:function(){
			// summary:
			//	Returns the highlighted option.
				return this._highlighted_option&&this._highlighted_option.parentNode ? this._highlighted_option : null;
			},
			
			_createOption:function(/*Object*/ item, labelFunc){
				// summary: creates an option to appear on the popup menu
				// subclassed by FilteringSelect
	
				var labelObject=labelFunc(item);
				var menuitem = document.createElement("div");
				if(labelObject.html){menuitem.innerHTML=labelObject.label;}
				else{menuitem.appendChild(document.createTextNode(labelObject.label));}
				// #3250: in blank options, assign a normal height
				if(menuitem.innerHTML==""){
					menuitem.innerHTML="&nbsp;"
				}
				menuitem.item=item;
				return menuitem;
			},
			
			// these functions are called in showResultList
			getItems:function(){
				return this.domNode.childNodes;
			},
			
			handleKey:function(evt){
				switch(evt.keyCode){
					case dojo.keys.DOWN_ARROW:
						this._highlightNextOption();
						break;
					case dojo.keys.UP_ARROW:
						this._highlightPrevOption();
						break;
				}
			},
			
			_highlightNextOption:function(){
				// because each press of a button clears the menu,
				// the highlighted option sometimes becomes detached from the menu!
				// test to see if the option has a parent to see if this is the case.
				if(!this.getHighlightedOption()){
					this._focusOptionNode(this.domNode.firstChild.style.display=="none"?this.domNode.firstChild.nextSibling:this.domNode.firstChild);
				}else if(this._highlighted_option.nextSibling&&this._highlighted_option.nextSibling.style.display!="none"){
					this._focusOptionNode(this._highlighted_option.nextSibling);
				}else if(this.scrollWrp){
					if(this._highlighted_option == this.scrollWrp.lastChild){
						this._focusOptionNode(this.closeButton);
					}
				}
				// scrollIntoView is called outside of _focusOptionNode because in IE putting it inside causes the menu to scroll up on mouseover
				dijit.scrollIntoView(this._highlighted_option);
			},

			highlightFirstOption:function(){
				// highlight the non-Previous choices option
				if(!this.scrollWrp){
					this._focusOptionNode(this.domNode.firstChild);
					dijit.scrollIntoView(this._highlighted_option);
				}else{
					this._focusOptionNode(this.scrollWrp.firstChild);
					dijit.scrollIntoView(this._highlighted_option);
				}
			},

			highlightLastOption:function(){
				// highlight the noon-More choices option
				this._focusOptionNode(this.domNode.lastChild.previousSibling);
				dijit.scrollIntoView(this._highlighted_option);
			},

			_highlightPrevOption:function(){
				// if nothing selected, highlight last option
				// makes sense if you select Previous and try to keep scrolling up the list
				if(!this.getHighlightedOption()){
					this._focusOptionNode(this.domNode.lastChild.style.display=="none"?this.domNode.lastChild.previousSibling:this.domNode.lastChild);
				}else if(this._highlighted_option.previousSibling&&this._highlighted_option.previousSibling.style.display!="none"){
					if(!this.scrollWrp){
						this._focusOptionNode(this._highlighted_option.previousSibling);
					}else{
						if(this._highlighted_option == this.closeButton){
							this._focusOptionNode(this.scrollWrp.lastChild);
						}else{
							this._focusOptionNode(this._highlighted_option.previousSibling);
						}
					}
				}
				dijit.scrollIntoView(this._highlighted_option);
			},
			
			_focusOptionNode:function(/*DomNode*/ node){
				// summary:
				//	does the actual highlight
				if(this._highlighted_option != node){
					this._blurOptionNode();
					this._highlighted_option = node;
					if(dojo.isIE){
						if(dojo.isIE < 8){
							dojo.addClass(this._highlighted_option, "dijitMenuItemHover");
						}else{
							// needed for IE 8 beta 2 - scrolls to top of list if addClass and removeClass is used
							dojo.style(this._highlighted_option,"backgroundColor","#dcdcdc");
						}
					}else dojo.addClass(this._highlighted_option, "dijitMenuItemHover");
				}
			},

			_blurOptionNode:function(){
				// summary:
				//	removes highlight on highlighted option
				if(this._highlighted_option){
					if(dojo.isIE){
						if(dojo.isIE < 8){
							dojo.removeClass(this._highlighted_option, "dijitMenuItemHover");						
						}else{
							// needed for IE 8 beta 2 - scrolls to top of list if addClass and removeClass is used
							dojo.style(this._highlighted_option,"backgroundColor","#fff");
						}
					}else dojo.removeClass(this._highlighted_option, "dijitMenuItemHover");
					this._highlighted_option = null;
				}
			},
		
			onmouseout:function(/*Event*/ evt){
				if(evt.target === this.domNode){ return; }
				this._blurOptionNode();
			},
		
			onmouseup:function(/*Event*/ evt){
				dojo.stopEvent(evt);
			},
			
			setValue:function(/*Object*/ value){
				this.value=value;
				this.onChange(value);
			}
	}
);

lh.validation = {
	/**
	 * Validates that the input value matches the given 
	 * regexp pattern.
	 * 
	 * @param value The string value to be evaluated.
	 * @param pattern The regexp pattern used to match against value.
	 */
	isValidPattern:function(value, pattern){
		if (typeof value != "string" || typeof pattern != "string") { return false; }
		var re = new RegExp(pattern);
		return re.test(value);
	},
	
	isValidMaMNumber:function(value){
		if (typeof value != "string") { return false; }
		return (!((value.length<14 ) || (value.length > 16 )) && value.length!=9);
	},
	
	isValidMaMStatus:function(value, pattern) {
		if (typeof value != "string" || typeof pattern != "string") { return false; }
		if (pattern.indexOf("N/A") > -1) return true; //don't check, if NA
		var statusKeys = pattern.split(" ");
		for (var i = 0; i < statusKeys.length; i++) {
			switch (statusKeys[0]) {
				case "BASE": return lh.validation._checkPrefixes(value, ["401000","403400","99200","531000","523400"]);
							 break;
				case "SEN": return lh.validation._checkPrefixes(value, ["401001","22201","531001"]);
							break;
				case "FTL": return lh.validation._checkPrefixes(value, ["401002","99222","531002"]);
							break;
				case "HON": return lh.validation._checkPrefixes(value, ["401003","33303","531003"]);
							break;
				case "INSTANT": return lh.validation._checkPrefixes(value, ["99990"]);
								break;
				default: return false;
			}
		}
	},
	_checkPrefixes:function(value, prefixes) {
		var isValid = false;
		for (var i = 0; i < prefixes.length; i++) {
			if (value.indexOf(prefixes[i]) == 0) {
				isValid = true;
			}
		}
		return isValid;
	},
	isInteger: function(/*String*/value){
		// summary:
		//	Validates whether a string is in an integer format
		return lh.validation.isValidPattern(value, "^(?:0|[0-9]\\d*)$");
	},
	isAlpha: function(/*String*/value){
		return lh.validation.isValidPattern(value, "^[a-zA-Z\\s]*$");
	},
	isAlphaNumeric: function(/*String*/value){
		return lh.validation.isValidPattern(value, "^[A-Za-z0-9 \\-]*$");
	},
	isValidChars: function(/*String*/value){
		var cSpecialCharacters = "äëïöüÄËÏÖÜáéíóúÁÉÍÓÚàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛåÅãñõÃÑÕçøÇØæÆÐðþÞÿß";
		var validChars = "^[A-Za-z0-9" + cSpecialCharacters + "‘;,.\\-_\\+\\&#\\*=”/ " + "\\u0104\\u0105\\u0106\\u0107\\u0118\\u0119\\u0141\\u0142\\u0143\\u0144\\u015A\\u015B\\u0179\\u017A\\u017B\\u017C]*$";
		return lh.validation.isValidPattern(value, validChars);
	},
	isMaskedCCNumber: function(/*String*/value){
		return lh.validation.isValidPattern(value, "^[0-9\\*]{0,12}[0-9]{4}$");
	},
	isTelephoneNumber: function(/*String*/value){
		return lh.validation.isValidPattern(value, "^[0-9\\+\\-\\(\\)]*$");
	},
	isValidDatePattern: function(value, df){
		df = df.toLowerCase();
		var format = df;
		while(format.indexOf("d") != -1) format = format.replace("d", "");
		while(format.indexOf("m") != -1) format = format.replace("m", "");
		var y = 0;
		while(format.indexOf("y") != -1) {
			format = format.replace("y", "");
			y++;
		}
		var sep = "[" + format.charAt(0) + "]";
		var pattern = "^";
		if (df.charAt(0) == "d" || df.charAt(0) == "m") {
			pattern += "[0-9]{1,2}" + sep + "[0-9]{1,2}" + sep + "[0-9]{" + y + "}$";
		} else {
			pattern += "[0-9]{" + y + "}" + sep + "[0-9]{1,2}" + sep + "[0-9]{1,2}$";
		}
		//alert(pattern);
		return lh.validation.isValidPattern(value, pattern);
	}
}

/*
 * Generic Form Handler for LH Applications, supports validation profile
 */
dojo.declare("lh.app.LHFormApplication", null, {
	formId:null,
	messageBoxId:null,
	multiple:false,
	formProfile : null,
	scrollToError:true,
	highlightErrors:false,
	trackErrors:false,
	hasErrors:false,
	errorClass:"mam-msg-error",
	successClass:"mam-msg-success",
	messageHeader:null,
	containerNode:null,
	prefillData:null,
	ignoreNullValues:true, //do not reset fields in setValues, if they are not explicely set in the prefillData
	_labels:null,
	_combinedLabels:null,
	constructor: function(p) {
		dojo.mixin(this, p);
		this.containerNode = dojo.byId(this.formId);
		if (this.prefillData && this.containerNode) {
			var prefillDataObj = eval(this.prefillData);
			if (typeof prefillDataObj!="undefined") {
				this.setValues(prefillDataObj);
			}
		}
		
	},
	validate: function() {
		var f = this.containerNode;
		if (!f) return false;
		var results = dojox.validate.check(f, this.formProfile);
		if (!this._processResults(f, results, this.formProfile)) {
			this._summarizeErrors(f, results, this.formProfile);
			return false;
		} else {
			this._clearMessage();
			return true;
		}
	},
	resetHighlighting: function(){ // clears the form from any highlighting. Also stores the found labels in an internal variable
		this._clearMessage();
		// no webreporting on validation errors at the moment
		// if (this.trackErrors) mam.webRep.clearStack(mam.WT_ERRORKEY);
		this._labels = dojo.query("label", this.containerNode).forEach(
			function(label) {
				dojo.removeClass(label, "labelError");
			}
		);
		dojo.query(".fieldError", this.containerNode).forEach(
			function(field) {
				dojo.removeClass(field, "fieldError");
				if (dojo.isIE && dojo.isIE < 8 && (field.tagName == "div" || field.tagName == "DIV")) {
					var divParent = field.parentNode;
					var divChild = field.getElementsByTagName("select")[0];
					divParent.replaceChild(divChild, field);
				}
			}
		);
		this._combinedLabels = dojo.query(".mam-xlabel", this.containerNode).forEach(
			function(combinedLabel) {
				dojo.removeClass(combinedLabel, "labelError");
			}
		);	
	},
	_processResults: function(f, r, profile) {
		if (r.isSuccessful() && !this.hasErrors) {
			return true;
		} else if (this.hasErrors || r.hasMissing() || r.hasInvalid()) {
			if (this.highlightErrors) {
				this.resetHighlighting();
				
			}
			if ((r.hasMissing()  || r.hasInvalid()) && this.highlightErrors) {
				this.hasErrors = true;
				var fields = r.getMissing();
				if (fields.length == 0) {
					fields = r.getInvalid();
				} else {
					fields = fields.concat(r.getInvalid());
				}
				this._labels.forEach(
					function(label) {
						for (var i = 0; i < fields.length; i++) {
							if (label.getAttributeNode("for").value === (fields[i]) || label.getAttributeNode("for").value.indexOf(fields[i] + "$$") === 0) {
								dojo.addClass(label, "labelError");
							}
						}
					},
					this);
				this._combinedLabels.forEach(
					function(combinedLabel) {
						for (var i = 0; i < fields.length; i++) {
							if (dojo.hasClass(combinedLabel, "mam-xfor-" + fields[i])) {
								dojo.addClass(combinedLabel, "labelError");
							}
						}
					}
				)
				var f = this.containerNode;
				for (var i = 0; i < fields.length; i++) {
					var field = f[fields[i]];
					if (field) {
						if (dojo.isIE && dojo.isIE < 8 && (field.type == "select-multiple" || field.type == "select-one")) {
							var newdiv = document.createElement("div");
							dojo.addClass(newdiv, "fieldError");
							var fieldParent = field.parentNode;
							var fieldClone = dojo.clone(field);
							fieldClone.selectedIndex=field.selectedIndex;
							newdiv.appendChild(dojo.clone(fieldClone));
							fieldParent.replaceChild(newdiv, field);
						} else if (field.type != "checkbox" && field.type != "radio") {
							dojo.addClass(field, "fieldError");
						}
					}
				}
			} else {
				this.hasErrors = (r.hasMissing() || r.hasInvalid());
				return !this.hasErrors; //fail validation
			}
		}
		return false;
	},
	_summarizeErrors: function(f, r, p) {
		var merrs=[];
		var errKeys=[];
		if (r.hasMissing()){
			if (p.singleRequiredMissingMessage) {
				merrs.push(p.singleRequiredMissingMessage);
			} else { 
				var fields=r.getMissing();
				for (var i=0; i<fields.length; i++){
					if (p[fields[i]] && p[fields[i]]["required"]){
						if (dojo.isArray(p[fields[i]]["required"])) {
							for (var z=0; z < p[fields[i]]["required"].length; z++) {
								var errKey = p[fields[i]]["reqKey"][z];
								if (typeof(errKey) != "undefined")
									// no webreporting on validation errors at the moment
									//mam.webRep.addKeyToStack(mam.WT_ERRORKEY, errKey);
								if ((dojo.indexOf(errKeys, errKey) > -1 && this.multiple != true) ||
									(dojo.indexOf(merrs, p[fields[i]]["required"]) > -1 && typeof(p[fields[i]]["skipMsg"]) != "undefined")) {
									continue; // skip message, if its already there
								} else {
									errKeys.push(errKey); // internal tracker to skip multiple similar messages
									merrs.push(p[fields[i]]["required"][z]);
								}
							}
						} else {

							var errKey = p[fields[i]]["reqKey"];
							if (typeof(errKey) != "undefined")
							// no webreporting on validation errors at the moment
								//mam.webRep.addKeyToStack(mam.WT_ERRORKEY, errKey);
							if ((dojo.indexOf(errKeys, errKey) > -1 && this.multiple != true) ||
								(dojo.indexOf(merrs, p[fields[i]]["required"]) > -1 && typeof(p[fields[i]]["skipMsg"]) != "undefined")) {
								continue; // skip message, if its already there
							} else {
								if (typeof(errKey) != "undefined")
									errKeys.push(errKey);
								merrs.push(p[fields[i]]["required"]);
							}
						}
					}
				}
			}
		}
		if (r.hasInvalid()){
			var fields=r.getInvalid();
			for (var i=0; i<fields.length; i++){
				if (p[fields[i]] && p[fields[i]]["constraints"]){
					if (dojo.isArray(p[fields[i]]["constraints"])) {
						for (var z=0; z < p[fields[i]]["constraints"].length; z++) {
							var errKey = p[fields[i]]["conKey"][z];
							if (typeof(errKey) != "undefined")
							// no webreporting on validation errors at the moment
								//mam.webRep.addKeyToStack(mam.WT_ERRORKEY, errKey);
							if ((dojo.indexOf(errKeys, errKey) > -1 && this.multiple != true) ||
								(dojo.indexOf(merrs, p[fields[i]]["constraints"]) > -1 && typeof(p[fields[i]]["skipMsg"]) != "undefined")) {
								continue; // skip message, if its already there
							} else {
								if (typeof(errKey) != "undefined")
									errKeys.push(errKey);
								merrs.push(p[fields[i]]["constraints"][z]);
							}
						}
					} else {
						var errKey = p[fields[i]]["conKey"];
						if (typeof(errKey) != "undefined")
						// no webreporting on validation errors at the moment
							//mam.webRep.addKeyToStack(mam.WT_ERRORKEY, errKey);
						if ((dojo.indexOf(errKeys, errKey) > -1 && this.multiple != true) ||
							(dojo.indexOf(merrs, p[fields[i]]["constraints"]) > -1 && typeof(p[fields[i]]["skipMsg"]) != "undefined")) {
							continue; // skip message, if its already there
						} else {
							if (typeof(errKey) != "undefined")
								errKeys.push(errKey);
							merrs.push(p[fields[i]]["constraints"]);
						}
					}
				}
			}
		}
		
		var msg="";
		// Error Messages are sorted according to their order inside the portlet and displayed in a list
		if (merrs.length > 0) {
			msg+='<ul class="msg-error">';
			if (this.messageHeader) {
				msg+=this.messageHeader;
			}
			var sumerr = new Array();
			var sumcount = 0;
			for (var i=0;i<f.elements.length;i++) {
				if (p[f.elements[i].id] != null && typeof(p[f.elements[i].id]["required"]) != "undefined") {
					for (var k=0; k<merrs.length;k++) {
						if (p[f.elements[i].id]["required"] == merrs[k]) {
							sumerr[sumcount] = merrs[k];
							merrs[k] = null; // Set null to make sure same message is not displayed twice
							sumcount++;
						}
						
					}
				}
				if (p[f.elements[i].id] != null && typeof(p[f.elements[i].id]["constraints"]) != "undefined") {
					for (var k=0; k<merrs.length;k++) {
						if (p[f.elements[i].id]["constraints"] == merrs[k]) {
							sumerr[sumcount] = merrs[k];
							merrs[k] = null; // Set null to make sure same message is not displayed twice
							sumcount++;
						}
					}
				}
			}
			for (var i=0; i<sumerr.length;i++) {
				msg+="<li><div>"+sumerr[i]+"</div></li>";
			}
			msg+="</ul>";
		}
		//TODO: Prepare different box handlers
		if (this.trackErrors) mam.webRep.doTrackStack(mam.WT_ERRORKEY, true);
		this._showMessage(msg);
	},
	_showMessage: function(msg) {
		var msgBox = dojo.byId(this.messageBoxId);
		if (msgBox.tagName == "TD" || msgBox.tagName == "td" || msgBox.tagName == "TR" || msgBox.tagName == "tr") {
			msgBox = msgBox.getElementsByTagName("P")[0];
		}
		if (dojo.hasClass(msgBox, this.successClass)) {
			dojo.removeClass(msgBox, this.successClass);
			dojo.addClass(msgBox, this.errorClass);
		}
		if (msgBox) {
			if (dojo.isIE && dojo.isIE < 8) {
				var newdiv = document.createElement("span");
				newdiv.innerHTML = msg;
				if (msgBox.firstChild) {
					while(msgBox.firstChild) dojo._destroyElement(msgBox.firstChild);
				}
				msgBox.appendChild(newdiv);
			} else {
				msgBox.innerHTML = msg;
			}
			dojo.removeClass(dojo.byId(this.messageBoxId), lh.INVISCLASS);
			if (this.scrollToError) {
				var coords = dojo.coords(msgBox, true);
				window.scrollTo(0, coords.y - 20);
			}
		}
	},
	_clearMessage: function() {
		if (this.highlightErrors) { // try to find and hide server side messages
			dojo.query("p.mam-msg-error", this.containerNode).forEach(
				function(container) {
					dojo.style(container, "display", "none");
				}
			);
		}
		var msgBox = dojo.byId(this.messageBoxId);
		if (msgBox.tagName == "TD" || msgBox.tagName == "td" || msgBox.tagName == "TR" || msgBox.tagName == "tr"){
			msgBox = msgBox.getElementsByTagName("P")[0];
		}
		if (msgBox) {
		//TODO: Externalize in generic message handler
			if (dojo.isIE && dojo.isIE < 7 && msgBox.firstChild) {
				while(msgBox.firstChild) dojo._destroyElement(msgBox.firstChild);
			} else {
				msgBox.innerHTML = "";
			}
			dojo.addClass(dojo.byId(this.messageBoxId), lh.INVISCLASS);
		}
	},
	setValues: function(/*object*/obj) {
		// summary: fill in form values from a JSON structure
		// CN: partially taken over from original dojo form mixin
		dojo.forEach(this.containerNode.elements, function(element){
			if (element.name == ''){return};	// like "continue"	
			var namePath = element.name.split(".");
			var myObj=obj;
			var name=namePath[namePath.length-1];
			for(var j=1,len2=namePath.length;j<len2;++j) {
				var p=namePath[j - 1];
				// repeater support block
				var nameA=p.split("[");
				if (nameA.length > 1) {
					if(typeof(myObj[nameA[0]]) == "undefined") {
						myObj[nameA[0]]=[ ];
					} // if

					nameIndex=parseInt(nameA[1]);
					if(typeof(myObj[nameA[0]][nameIndex]) == "undefined") {
						myObj[nameA[0]][nameIndex]={};
					}
					myObj=myObj[nameA[0]][nameIndex];
					continue;
				} // repeater support ends

				if(typeof(myObj[p]) == "undefined") {
					myObj=undefined;
					break;
				};
				myObj=myObj[p];
			}

			if (typeof(myObj) == "undefined") {
				return;		// like "continue"
			}
			if (typeof(myObj[name]) == "undefined" && this.ignoreNullValues) {
				return;		// like "continue"
			}

			// TODO: widget values (just call setValue() on the widget)

			switch(element.type) {
				case "checkbox":
					element.checked = (name in myObj) &&
						dojo.some(myObj[name], function(val){ return val==element.value; });
					break;
				case "radio":
					element.checked = (name in myObj) && myObj[name]==element.value;
					break;
				case "select-multiple":
					element.selectedIndex=-1;
					dojo.forEach(element.options, function(option){
						option.selected = dojo.some(myObj[name], function(val){ return option.value == val; });
					});
					break;
				case "select-one":
					element.selectedIndex=0; //CN: careful. Saf shows empty selects, when the index is set but all options.selected are false afterwards.
					dojo.forEach(element.options, function(option){
						option.selected = option.value == myObj[name];
					});
					break;
				case "hidden":
				case "text":
				case "textarea":
				case "password":
					element.value = myObj[name] || "";
					break;
			}
  		}, this); //CN: bugfix. scope loss in foreach inhibits ignoreNullValues check
	},

	getValues: function() {
		// summary: generate JSON structure from form values
		// CN: partially taken over from original dojo form mixin

		var obj = { };
		dojo.forEach(this.containerNode.elements, function(elm){
			if (!elm.name)	{
				return;		// like "continue"
			}
			var namePath = elm.name.split(".");
			var myObj=obj;
			var name=namePath[namePath.length-1];
			for(var j=1,len2=namePath.length;j<len2;++j) {
				var nameIndex = null;
				var p=namePath[j - 1];
				var nameA=p.split("[");
				if (nameA.length > 1) {
					if(typeof(myObj[nameA[0]]) == "undefined") {
						myObj[nameA[0]]=[ ];
					} // if
					nameIndex=parseInt(nameA[1]);
					if(typeof(myObj[nameA[0]][nameIndex]) == "undefined") {
						myObj[nameA[0]][nameIndex]={};
					}
				} else if(typeof(myObj[nameA[0]]) == "undefined") {
					myObj[nameA[0]]={}
				} // if

				if (nameA.length == 1) {
					myObj=myObj[nameA[0]];
				} else {
					myObj=myObj[nameA[0]][nameIndex];
				} // if
			} // for

			if ((elm.type != "select-multiple" && elm.type != "checkbox" && elm.type != "radio") || (elm.type=="radio" && elm.checked)) {
				if(name == name.split("[")[0]) {
					myObj[name]=elm.value;
				} else {
					// can not set value when there is no name
				}
			} else if (elm.type == "checkbox" && elm.checked) {
				if(typeof(myObj[name]) == 'undefined') {
					myObj[name]=[ ];
				}
				myObj[name].push(elm.value);
			} else if (elm.type == "select-multiple") {
				if(typeof(myObj[name]) == 'undefined') {
					myObj[name]=[ ];
				}
				for (var jdx=0,len3=elm.options.length; jdx<len3; ++jdx) {
					if (elm.options[jdx].selected) {
						myObj[name].push(elm.options[jdx].value);
					}
				}
			} // if
			name=undefined;
		}); // forEach
		return obj;
	}
});
/*
 * Little Form Handler for We Fly Home Prehomepage
 */
dojo.declare("lh.app.wfhPrehomepageSubmitHandler", null, {
	frmId:"",
	hId:"",
	arrLinks: [],
	constructor: function(p) {
		dojo.mixin(this, p);
	},
	addSelect: function(id,act){
		dojo.connect(dojo.byId(id),"onchange",this, "selectChanged");
		this.arrLinks.push({fid:id,action:act});
	},
	selectChanged: function(event){
		for(var i=0; i<this.arrLinks.length;i++){
			if(this.arrLinks[i].fid == event.target.id){
				dojo.byId(this.hId).value = this.arrLinks[i].action;
				if(event)dojo.stopEvent(event);
				dojo.byId(this.frmId).submit();
				break;
			}
		}
		if(event)dojo.stopEvent(event);
	},
	deselectSelectList: function(p){
		sObj = dojo.byId(p.selectId);
		if((sObj)&&(sObj.options)){
			sObj.options[0].selected = true;
		}
	}
});	

// to do: ausgrauen optional !

dojo.declare("lh.app.bannerEyecatcher",null,{

	cookieName: "lhEyecatcherCookie",
	cookieExpires: 1,
	cookieExpireUnity: "hour", // can be "year", "month", "day", "hour", "minute", "second", "millisecond", "quarter", "week", "weekday" see 'dojo.date.add' 
	cookieValue: true,
	bannerWidth: 546,
	bannerHeigth: 160, /*156*/
	duration: 1000,
	rate: 0,
	url: null,
	closeLinkTxt: "Close",
	modal: false,
	debug:false,
	animate: false,
	
	constructor: function(p) {
		dojo.mixin(this, p);
		this.checkCookie();
	},

	checkCookie: function(){
		if(this.debug)console.debug("enter 'checkCookie'");
		if(!dojo.cookie(this.cookieName)){
			this.calcHappenstance();
		}
	},
	
	setCookie: function(){
		var nowDate = new Date();
		if(this.cookieExpires>0){
			var cookieExpireDate = dojo.date.add(nowDate,this.cookieExpireUnity,this.cookieExpires);
			dojo.cookie(this.cookieName, this.cookieValue,{expires:cookieExpireDate});
		}else{
			if(this.debug)console.debug("session cookie - expires 0 ");
			dojo.cookie(this.cookieName, this.cookieValue);
		}
		if(this.debug)console.debug("cookie placed");
	},

	calcHappenstance: function() {
		if(this.debug)console.debug("enter 'calcHappenstance'");
		var nr = Math.random();
		nr = nr * 100;
		nr  = Math.ceil(nr);
		if(this.debug)console.debug("rate:"+this.rate);
		if(this.debug)console.debug("nr:"+nr);
		if(nr <= this.rate)this.prepareShowIt();
	},
	
	prepareShowIt: function(){
		if(this.debug)console.debug("enter 'prepareShowIt'");
		if(this.url==null){
			if(this.debug)console.debug("No iframe url!");
			return;
		}
		var body = document.getElementsByTagName("body")[0];
		this.bodyDimensions = dojo.marginBox(body);

		this.topPos = (this.bodyDimensions.h/2)-(this.bannerHeigth/2);

		if(this.animate){
			// if animation is need the startposition must be set
			this.leftPos = (this.bannerWidth+30)*(-1);
			this.leftPosEnd = (this.bodyDimensions.w/2)-(this.bannerWidth/2);
			dojo.subscribe(lh.topics.EYECATCHERLOADED, this, "animateIt");
		}else{
			this.leftPos = (this.bodyDimensions.w/2)-(this.bannerWidth/2);
			dojo.subscribe(lh.topics.EYECATCHERLOADED, this, "showIt");
		}
		
		this.divNode = dojo.doc.createElement("div");
		dojo.addClass(this.divNode,"eyecatcher");
		barWidth = lh.helper.gui.getScrollBarWidth();
		if((dojo.isIE)&&(dojo.isIE<8)){barWidth = barWidth/2;}
		if(!this.animate)dojo.style(this.divNode,{"visibility":"hidden"});
		dojo.style(this.divNode,{
				"position":"absolute",
				"top": this.topPos+"px",
				"left": this.leftPos+"px",
				"width": this.bannerWidth+"px",
				"height": this.bannerHeigth+"px",
				"zIndex": "1000",
				"overflow":"hidden",
				"paddingTop": barWidth+"px",
				"paddingLeft": barWidth+"px"
		});

		// close link creating
		this.closeLink = dojo.doc.createElement("a");
		this.closeLink.innerHTML = this.closeLinkTxt;
		this.closeLink.href = "#";
		dojo.addClass(this.closeLink,"lnk-btn");
		
		dojo.connect(this.closeLink,"onclick",this, "closeIt");
		this.divNode.appendChild(this.closeLink);
		
		// iframe creating		
		if(dojo.isIE){
			var html="<iframe src='' style='' frameborder='0' marginheight='0' marginwidth='0'>";
			this.iframeNode = dojo.doc.createElement(html);
		}else{
		 	this.iframeNode = dojo.doc.createElement("iframe");
			this.iframeNode.setAttribute("frameborder","0");
			this.iframeNode.setAttribute("marginheight","0");
			this.iframeNode.setAttribute("marginwidth","0");
		}		

		dojo.style(this.iframeNode,{
				"width": this.bannerWidth+"px",
				"height": this.bannerHeigth+"px",
				"overflowY":"auto",
				"overflowX":"hidden"
		});

		this.divNode.insertBefore(this.iframeNode,this.closeLink);
		document.getElementsByTagName("body")[0].appendChild(this.divNode);
		var closeBoxDim = dojo.marginBox(this.closeLink);
		dojo.style(this.divNode,{"height": this.bannerHeigth+(dojo.marginBox(this.closeLink).h)+"px"});

		// now load content.
		this.iframeNode.src = this.url;
	},
	
	showIt: function(){
		if(this.debug)console.debug("enter 'showIt'");
		this.adjustIt();
		this.setModal();
		dojo.style(this.divNode,{"visibility":"visible"});
		this.setCookie();
		dojo.subscribe(lh.topics.EYECATCHERCLICKED, this, "closeIt");
	},
	
	animateIt: function(){
		if(this.debug)console.debug("enter 'animateIt'");
		this.adjustIt();
		this.setModal();
		var aniEffect = dojo.fx.slideTo({node:this.divNode,duration:this.duration,left:this.leftPosEnd,top: this.topPos, unit:"px"});
		var aniChain = dojo.fx.chain([aniEffect]); // chain not needed, but maybe later 
		aniChain.play();
		this.setCookie();
		dojo.subscribe(lh.topics.EYECATCHERCLICKED, this, "closeIt");
	},
	
	setModal:function(){
		if(this.modal){
			if(this.debug)console.debug("modal eyecatcher");
			// grey opacity
			
			var qresult = dojo.query(".center-wrp-1");
			var docHeight = 0;
			for(var i=0;i<qresult.length;i++){
				docHeight = docHeight + dojo.marginBox(qresult[i]).h;
			}
			if(document.body.clientHeight<=docHeight)var heightForStyle = docHeight+20+"px";
			else var heightForStyle = "100%";
			
			this.fadeNode = dojo.doc.createElement("div");
			dojo.style(this.fadeNode,{
					"position":"absolute",
					"top": "0px",
					"left": "0px",
					"width": "100%",
					"height": heightForStyle,
					"zIndex": "900",
					"overflow":"auto"
			});
			dojo.addClass(this.fadeNode,"eyecatcher-background");
			if(dojo.isIE){
				var result = dojo.query("select");
				for(var i=0;i<result.length;i++){
					dojo.style(result[i],"visibility","hidden");
				}
			}
			document.getElementsByTagName("body")[0].appendChild(this.fadeNode);
		}else{
			if(dojo.isIE){
				var result = dojo.query("select");
				for(var i=0;i<result.length;i++){
					dojo.style(result[i],"visibility","hidden");
				}
			}
		}
	},
	
	adjustIt:function(){
		barWidth = lh.helper.gui.getScrollBarWidth();
		if((dojo.isIE)&&(dojo.isIE<8)){barWidth = barWidth/2;}

		// get some object's for later logic
		if(dojo.isIE){
			var iframeDoc = this.iframeNode.contentWindow.document;
		}else{
			var iframeDoc = this.iframeNode.contentDocument;
		}
		var iframeBody = iframeDoc.body;
		var tdElement = dojo.query(".lay-eyecatcher",iframeDoc);
		
		// adjust width of body in iframe
		var newIframeBodyWidth = this.bannerWidth-barWidth;
		if((dojo.isIE)&&(dojo.isIE<8)){newIframeBodyWidth = newIframeBodyWidth-3;}
		dojo.style(iframeBody,{"width": newIframeBodyWidth+"px"});

		// check if scrollbar is displayed and ajust width if scrollbar appears
		var contentHeight = dojo.marginBox(dojo.byId("mam",iframeDoc)).h;
		if(contentHeight>this.bannerHeigth){
			// scrollbar - add right padding
			dojo.style(this.divNode,{"paddingRight": barWidth+"px"});
			// add padding to iframe body, to have a littel margin between content and scrollbar, looks better!
			// guessing only one + the first element is the eyecatcher layout td.
			dojo.style(tdElement[0],{"paddingRight": "5px"});
		}else{
			// no scrollbar - right border is made by invisible scrollbararea
			dojo.style(this.closeLink,{"paddingRight": barWidth+"px"});
		}	
	},
	
	closeIt: function(event){
		if(this.debug)console.debug("enter 'closeIt'");
		document.getElementsByTagName("body")[0].removeChild(this.divNode);
		if(this.modal){
			document.getElementsByTagName("body")[0].removeChild(this.fadeNode);
		}
		if(dojo.isIE){
			var result = dojo.query("select");
			for(var i=0;i<result.length;i++){
				dojo.style(result[i],"visibility","visible");
			}
		}
		if(event)dojo.stopEvent(event);
	}
});

dojo.declare("lh.helper.keepALive",null,{

	url: "",
	method: "get", // 'get' or 'post'

	constructor: function(p) {
		dojo.mixin(this, p);
		if(this.url=="")console.error("Missing URL in lh.helper.keepALive");
	},
	
	sendKeepAlive: function(queryVars){
		if(this.url!=""){
			if(this.method=="get"){
				dojo.xhrGet({url:this.url,
		            		content:queryVars,
	    	                load: this.handleResponse,
	        	            error: this.handleResponse
				});
			}else if(this.method=="post"){
				dojo.xhrPost({url:this.url,
		            		content:queryVars,
	    	                load: this.handleResponse,
	        	            error: this.handleResponse
				});
			}
		}
	},

	handleResponse: function(response,ioParams){
		// we do nothing here is just a keep alive call
	}
});
// SEO Footer
dojo.declare("lh.footerHandler",null,{ 
	
	topLiList:null,
	bottomLiList:null,
	whiteLine: document.createElement("span"),
	whiteLineClass: "wLine",
	clickedInfoObj: new Object(),
	xLinkName: "x-link",
	xLayerName: "x-layer",
	idLayerName: "ft-layer",
	posBottom: "bottom",
	posTop: "top",
	idFooterParent: "footer",
	idTopWrp: "ft-top",
	idBottomWrp: "ft-bottom",
	topWrpEl: null,
	bottomWrpEl: null,
	liTabClass: "tab",
	prevLiClass: "activLeft",
	aXClass: "x-expand",
	bottomShadowId: "ft-shadow-bottom-wrp",
	
	constructor:function(){
		var results = dojo.query("."+this.aXClass,this.idFooterParent);
		for(var i =0;i<results.length;i++){
			dojo.connect(results[i],"onclick",this, "tapClicked");					
		}
		this.topWrpEl = dojo.byId(this.idTopWrp);
		this.bottomWrpEl = dojo.byId(this.idBottomWrp);
		
		if(this.topWrpEl!=null)this.topLiList = dojo.query("li",this.topWrpEl);
		if(this.bottomWrpEl!=null)this.bottomLiList = dojo.query("li",this.bottomWrpEl);
		this.liList = dojo.query("li",this.idFooterParent);
		
		dojo.addClass(this.whiteLine,this.whiteLineClass);
		// add eventhandler to all other links
		var results = dojo.query("a",this.idFooterParent);
		for(var i =0;i<results.length;i++){
			if(!dojo.hasClass(results[i],this.aXClass)){
				dojo.connect(results[i],"onclick",this, "resetTabsAndLayer");					
			}
		}
	},
	
	tapClicked: function(event){
		var listItemLeft;
		var listItemIndex;
		var ankerObj = event.target;
		var listItem = ankerObj.parentNode;
		
		if(dojo.hasClass(listItem,this.liTabClass)){
			// activ tab was clicked
			this.resetTabsAndLayer();
		}else{
			// not activ tab was clicked
			// first close an other tab if some tab is activ
			this.resetTabsAndLayer();

			// add tab class to li-tag for tab appearance
			dojo.addClass(listItem,this.liTabClass); 

			// getting the link no + in which linklist (top vs. bottom) the link is
			var _this = this;
			var clickedXLinkClass = dojo.filter(ankerObj.className.split(" "),function(_item){
				var s = _item.search(_this.xLinkName);
				if(s>-1)return true;
				else return false;
			});
			if(clickedXLinkClass.length > 0){
				var sp = clickedXLinkClass[0].split("-");
				this.clickedInfoObj.pos = sp[2];
				this.clickedInfoObj.no = sp[3];
			}
			// console.debug(this.clickedInfoObj);
			if(this.clickedInfoObj.pos==this.posTop){
				listItemIndex = dojo.indexOf(this.topLiList,listItem,1);
				listItemLeft = this.topLiList[listItemIndex-1];
				if(this.bottomWrpEl!=null)dojo.style(this.bottomWrpEl,{display:"none"});
			}else if(this.clickedInfoObj.pos==this.posBottom){
				listItemIndex = dojo.indexOf(this.bottomLiList,listItem,1);
				listItemLeft = this.bottomLiList[listItemIndex-1];
				if(this.bottomWrpEl!=null)dojo.style(this.bottomWrpEl,{borderBottom:"1px solid #b4b4b4"});
			}
			// if there is a previous link a class has to be added for visual reasons see css
			if(listItemLeft)dojo.addClass(listItemLeft,this.prevLiClass);
			// the white line covers / overlaps the grey line between tab and layer area
			if(dojo.isSafari){
				if(listItemLeft) wTab = dojo.marginBox(listItem).w - 6;
				else wTab = dojo.marginBox(listItem).w - 8;
			}else {
				if(listItemLeft) wTab = dojo.marginBox(listItem).w - 1;
				else wTab = dojo.marginBox(listItem).w - 2;
			}
			dojo.style(this.whiteLine,{width:wTab+"px",backgroundColor:"#fff",height:"7px"});
			listItem.appendChild(this.whiteLine);
			// show the layer
			dojo.query("."+this.xLayerName+"-"+this.clickedInfoObj.pos+"-"+this.clickedInfoObj.no,this.idFooterParent).style({display:"block"});
			// show the bottom shadow			
			dojo.style(this.bottomShadowId,{display:"block"});
			// scroll it into the view
			var layerNode = dojo.query("."+this.xLayerName+"-"+this.clickedInfoObj.pos+"-"+this.clickedInfoObj.no,this.idFooterParent);
			layerNode[0].scrollIntoView();
		}
		dojo.stopEvent(event);
		ankerObj.blur();
	},
	
	resetTabsAndLayer: function(){
		var _this = this;
		dojo.forEach(this.liList, function(_item){
			dojo.removeClass(_item, _this.liTabClass);
			dojo.removeClass(_item, _this.prevLiClass);
			if(_item.lastChild ==_this.whiteLine){
				_item.removeChild(_this.whiteLine);			
			}
		});
		dojo.query("."+this.xLayerName,this.idFooterParent).style({display:"none"});
		if(this.bottomWrpEl!=null){
			dojo.style(this.bottomWrpEl,{display:"block",borderBottom:"none"});
		}
		dojo.style(this.bottomShadowId,{display:"none"});
	}
});
//  helper for submitting forms with the 'enter'-key
dojo.declare("lh.onEnterSubmitFormHelper", null,{
	formEle: null,
	linkEle: null,
	constructor:function(params){
		if(params.formId){
			this.formEle = dojo.byId(params.formId);
			if(params.aId)this.linkEle = dojo.byId(params.aId);
			var dqResults = dojo.query("input",this.formEle);
			for(var i =0;i<dqResults.length;i++){
				dojo.connect(dqResults[i],"onkeypress",this, "keyPressed");
			}
		}
	},
	keyPressed: function(event){
		if(event.keyCode==dojo.keys.ENTER){
			this.linkEle.onclick();
		}
	}
});
