
// Lufthansa JavaScripts
// browser check
var MSIE = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1)) ? true : false;
var MSIE50 = (MSIE && !document.createEventObject) ? 1 : 0; // MS Internet Explorer 5.0
var OPERA = (navigator.userAgent.match(new RegExp("[\w\s ]*Opera[\w\s ]*"))) ? 1 : 0; // Opera

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

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

// select list (SEL) submitter, taken from jumpToSite()
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; 
		}
	}
}

// Dropdownbox submitter
function lh_pldSubmit(obj) {
	form = new FormObj();
	form.getNextForm(obj);
	lh_selSubmit(form.theForm.getElementsByTagName("select")[0]);
}

// popup opener function, currently copy paste from original
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,'
	} else {
		wfeatures = wfeatures + 'scrollbars=yes,resizable=yes,'
	}
	
	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'
			break;
		case 2:
			wfeatures	= wfeatures + 'width=600,height=500'
			break;
		case 3:
			wfeatures	= wfeatures + 'width=800,height=600'
			break;
		case 4:
			wfeatures	= wfeatures + 'width=1024,height=768'
			break;
		default:
			wfeatures	= wfeatures + 'width=800,height=600'
			break;
	} 
	
	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;
    
	newCmd = windowName + "= window.open(wurl, windowName, wfeatures);";
	eval(newCmd);
}

function saveDialog() {
	window.document.execCommand("SaveAs");
}

function FormObj() {
	this.theForm = "";
}

FormObj.prototype = new Object();

FormObj.prototype.getNextForm = function(obj) {
	var searchObj = obj.parentNode;
	if(searchObj.tagName == "FORM") {
		this.theForm = searchObj;
	}
	else this.getNextForm(searchObj);
}

function submitApp(obj) {
	form = new FormObj();
	form.getNextForm(obj);
	form.theForm.submit();
}

/* Javascript for app_bm and app_gm */

/* 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 {
			++i;
			n+= Number(document.getElementById(idname + i).value);
			document.getElementById('costs_all').value= n + '.00';	
		}
		catch (e) {
			err= true;
		}
	}
}

/* This function is a general function for the submit/logout buttons.
 * Paramters: actionname: submit action, frmId: name/id submit form.
*/
function submitForm(actionname,frmId) {	
	document.getElementById(frmId).action= actionname;
	document.getElementById(frmId).submit();
}

/* 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";
		submitForm(actionname,frmId);		
		document.getElementById("top").focus(); 
		
	}
	else {
		/* show error message */
		(document.getElementById("checkError")).style.display="block";		
	}
}

/* end javascript for app_gm and app_bm*/

/* 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
	}
}


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);
	}
}

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 setCookie(name, value, minutes) {
	var expire = new Date ();
	if (minutes != "") {
		expire.setTime (expire.getTime() + 60 * 1000 * minutes); 
		document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString(); 
	} else {
		document.cookie = name + "=" + escape(value);
	}
}

// retrieve info on cookie. 
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
}

// delete info on cookie. 
function deleteCookie(name) {
	var expire = new Date ();
	expire.setTime (expire.getTime() - (24 * 60 * 60 * 1000)); 
	document.cookie = name + "=; expires=" + expire.toGMTString();
}

// open a print version window
function printVersion(url, winname) {
	if (url && winname && url != '') {
		newsWin = window.open(url, winname, 'scrollbars,menubar,toolbar=no,status=no,location=no,locationbar=no,resizeable=no,width=550,height=400,top=20,left=20');
		if (!newsWin.opener) newsWin.opener = self;
		newsWin.focus();
	}
}

// set command and submit form for portlet
function portletFormSubmit(strFormId,strHiddenId,strCommand)
{
	switch(arguments.length){
		case 1:
			if(document.getElementById(strFormId))
			{
				oForm = document.getElementById(strFormId);
				oForm.submit();
			}
			break;
		case 3:
			if(document.getElementById(strHiddenId))
			{
				oHidden = document.getElementById(strHiddenId);
				oHidden.value = strCommand;
			}
			if(document.getElementById(strFormId))
			{
				oForm = document.getElementById(strFormId);
				oForm.submit();
			}
			break;
		default:
			break;
	}
}
// fix minor layout issues in popup theme for ie 5.0 and opera
function ieOpPopupFix() {
	if (MSIE50)
		ieHeadSize();
	if (OPERA)
		opSize();
}
function ieHeadSize()
{
	var width = document.getElementById("outerwrap").clientWidth;
	document.getElementById("headwrap").style.width = width;
	document.getElementById("footwrap").style.width = width;	
}
function opSize() {
	if (document.getElementById("box").getElementsByTagName("div")[0]) {
		var width = document.getElementById("box").getElementsByTagName("div")[0].clientWidth;
		document.getElementById("pop").style.minWidth = width +30;
	}	
}
if (MSIE50)
	window.onresize = ieHeadSize;
// end of ie 5.0 and opera fix