pathCollection["header.html"] = "custom/header.html";
pathCollection["js/preferences.js"] = "custom/preferences.js";
pathCollection["js/imageview.js"] = "custom/imageview.js";
pathCollection["js/windowmanager.js"] = "custom/windowmanager.js";
pathCollection["js/search.js"] = "custom/search.js";
pathCollection["js/cgm_custom.js"] = "custom/cgm_custom.js";
pathCollection["js/table.js"] = "custom/table.js";
pathCollection["js/basket.js"] = "custom/basket.js";
pathCollection["js/basket_custom.js"] = "custom/basket_custom.js";
pathCollection["js/tools.js"] = "custom/tools.js";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var b_name = "B_name";
var b_street = "B_street";
var b_zip = "B_zip";
var b_city = "B_city";
var b_phone = "B_phone";
var b_fax = "B_fax";
var b_email = "h.sonnerer@jenbacher.com";

var o_name = "O_name";
var o_street = "O_street";
var o_zip = "O_zip";
var o_city = "O_city";
var o_phone = "O_phone";
var o_fax = "O_fax";
var o_email = "O_email";

var presetAddressesSet = false;
var currentCustNum = "";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
colorHighLighted = "#007dc3";
colorNormal = "#e8e8e8";

var currentCGMPath = "";
var setCGMHomeCausedBySearchResult = false;

/*
customEvents['TreeNodeSelected'] = "customOnly";
customEvents['TreeNodeSelected'] = "customAndStd";
customEvents['TreeNodeSelected'] = "stdAndCustom";
*/
customEvents['LoadAdditionalFootNote'] = "customOnly";
customEvents['AddToBasket'] = "customOnly";
customEvents['addItem2BasketJag'] = "customOnly";
customEvents['AddSelectionToBasket'] = "customOnly";
customEvents['SetDeliveryAddress'] = "customOnly";
customEvents['SetOrdererAddress'] = "customOnly";
customEvents['Logout'] = "customOnly";
customEvents['TableCSVExport'] = "customOnly";
customEvents['ImageListChanged'] = "customOnly";
customEvents['LoadImage'] = "stdAndCustom";
customEvents['OpenLink'] = "customAndStd";

var currentOrderCache = "";
var currentOrderType="";
function customEventHandler(event, params) {
	var paramArr = queryStringToArray(params);

	if(event == "LoadAdditionalFootNote") {
	  	if(footnoteFrameSize > 0) {
	  		if(paramArr["ClearSelection"] == "true") {
		  		frames.inhalt.document.getElementById("footnote").setAttribute("src","footnote.html");
	  		} else {
		  		var selectedPartsInSPL = getProperty("Global","SelectedParts",null);
				setTimeout("showAdditionalFootNoteInfo('"+selectedPartsInSPL+"')",100); // java->js (liveconnect) unclutching via timeout
		  	}
		}
	} else if(event == "AddToBasket") {
		var partDataArr = "";
		var treeID3rd=null;
		if(paramArr["AddBy"] == "PartData") {

			if(getQueryField(paramArr["PartData"],"Sender") == "SearchResult") {
				treeID3rd = getQueryField(paramArr["PartData"],"treepath").split("/")[5];
				currentOrderCache = paramArr["PartData"]+"&PartsURI="+getQueryField(paramArr["PartData"],"treepath");
			} else {
				treeID3rd = currentTreePath.split("/")[5];
				currentOrderCache = paramArr["PartData"]+"&PartsURI="+currentTreePath+"/"+getQueryField(paramArr["PartData"],"DeviceID")+"/"+getQueryField(paramArr["PartData"],"ItemContextID");
			}
			currentOrderType="PartData";
			document.getElementById("InvisibleFrame2").setAttribute("src","../custom/facilitydata.jsp?id="+treeID3rd);

		} else {
			currentOrderType="ItemPaths";
			currentOrderCache = params;
			treeID3rd = currentTreePath.split("/")[5];
			document.getElementById("InvisibleFrame2").setAttribute("src","../custom/facilitydata.jsp?id="+treeID3rd);
		}

	} else if(event == "addItem2BasketJag") {
		if(currentOrderType=="PartData") {
		currentOrderCache+="&remarks_="+paramArr['g'];
		currentOrderCache+="&motornr="+paramArr['m'];
		currentOrderCache+="&devicenr="+paramArr['a'];
		belenusHome.addItem(currentOrderCache,false,false);
		} else if(currentOrderType=="ItemPaths") {
		  var cachedItemPaths = queryStringToArray(currentOrderCache);
		  var handlingType = "ItemPath";
		  var token = 0;
		  var itemDataSets = new Array();
		  while(cachedItemPaths[handlingType+""+token]) {
		    var PartsURI = null;
		    PartsURI = getProperty("Global","PartsURI", handlingType+"="+cachedItemPaths[handlingType+""+token]);
		    itemDataSets[itemDataSets.length] = belenusHome.getProperty("Table","PartData",handlingType+"="+cachedItemPaths[handlingType+""+token++]) + "&PartsURI="+PartsURI+"&remarks_="+paramArr['g']+"&motornr="+paramArr['m']+"&devicenr="+paramArr['a'];
		  }
		  var partNOs = new Array();
		  for(items in itemDataSets) {
		    var multiSelection = (itemDataSets.length > 1) ? true : false;
		    if(belenusHome.useInternalBasket)
		    	addItem(itemDataSets[items], multiSelection, false);
		  }

		}
		currentOrderCache="";
		currentOrderType="";
	} else if(event == "AddSelectionToBasket") {
		var orderable = getProperty("Table", "SelectionOrderable", null);
		if ("true" == orderable) {
			var selectedParts = getProperty("Table", "SelectedParts", null);
			belenusHome.eventHandler("AddToBasket","AddBy=ItemPaths&" + selectedParts);
		}
    } else if(event == "SetDeliveryAddress") {
    	belenusHome.WM.openWindow("deliveryAdd",belenusHome.currentCustNum);
    } else if(event == "SetOrdererAddress") {
    	belenusHome.WM.openWindow("ordererAdd",belenusHome.currentCustNum);
    } else if(event == "Logout") {
		if(belenusHome.logoutPath && belenusHome.logoutPath != null && belenusHome.logoutPath != "") {
			if(paramArr['ShowMessage'] == "true") alert(belenusHome.ld['session_expired']);
			void(top.location.href=belenusHome.logoutPath+"?language="+currentLanguage);
		}
	} else if(event == "TableCSVExport") {
  		var dID = unescape(belenusHome.getProperty("Table","CurrentItemList",null));
	  	dID = belenusHome.getQueryField(dID,"id");
		belenusHome.frames.mrhidden2.location.href= "../server?command=searchcsv&query=device&id="+dID;
  	} else if(event == "ImageListChanged") {
	    var imageList = new Array();
	      if(currentCGMPath != "" && belenusHome.getModule("ImageView") != null && belenusHome.getModule("ImageView").currentImageType=="image/cgm") {
	      	try {
	      		belenusHome.getModule("ImageView").CGMSetHome(currentCGMPath+"/"+paramArr['CurrentlySelected'],0);
	      	} catch(e) {alert(e.message); }
	      }
	    if(!paramArr['CurrentlySelected'] && !paramArr['Label0']) {
	      sendMessage("ImageView","ClearImageView",null);
	      sendMessage("Toolbar","SetChoiceList","Name=ImageList");
	      if(belenusHome.showImage == "ifAvailable") {
	      sendMessage("Detail", "SetDetailFrameViews", "View=onlyTable");
	      }
	    } else if(paramArr['Label0']){
	      sendMessage("Toolbar","SetChoiceList","Name=ImageList&"+params);
	    }
	    for (var imageNo = 0; paramArr["Label" + imageNo] != null; imageNo++)
	      imageList[imageNo] = paramArr["Label" + imageNo];
  	} else if(event == "LoadImage") {
  		try {
		currentCGMPath = paramArr["URL"].substring(0,paramArr["URL"].lastIndexOf("/"));
		} catch(e) {alert(e.message); }
  	} else if(event == "OpenLink") {
  		try{
		  if(paramArr['URL'].indexOf("parts:/") == 0) setCGMHomeCausedBySearchResult=true;
		} catch(e) {alert(e.message);}
  	}
}

function killNULL(value) {
	if(typeof value == "undefined" || value== null || value == "null") return "";
	else return value;
}

function showAdditionalFootNoteInfo(resultQuery) { // shows the additional info from the spl in the small frame in the bottom of the application
	if(resultQuery.length < 1) return;
	var selectedPartInSPL = getQueryField(resultQuery,"ItemPath0");
  	if(selectedPartInSPL!='null' && selectedPartInSPL!=null) {
	  	var partData = getProperty("Global","ItemData","ItemPath="+selectedPartInSPL);
	  	var ItemContextID = getQueryField(getQueryField(partData,"ItemData"),"ItemContextID");
	  	var DeviceID = getQueryField(getQueryField(partData,"ItemData"),"DeviceID");
	  	var fd = frames.inhalt.frames.footnote.document;
	  	var x = '<table width="100%" cellspacing="1" cellpadding="0"><tr style="background-color:#e8e8e8;border-color:#cccccc">';
	  	var itemData = unescape(getQueryField(partData,"ItemData"));
	  	for(var i = 1; i<7; i++) {
	  		var key = 'sach'+i+'art';
	  		x+='<th style="color:#666666">'+killNULL(getQueryField(itemData,key))+'</th>';
	  	}
	  	x+="</tr><tr>";
	  	for(var i = 1; i<7; i++) {
	  		x+='<td align="center">'+killNULL(getQueryField(itemData,('sach'+i+'werte')))+""+killNULL(getQueryField(itemData,('sach'+i+'einheit')))+'</td>';
	  	}
	  	x+='</tr></table>';

	  	with(fd) {
	  		open();
	  		write('<html><head><link rel="stylesheet" type="text/css" href="custom/content.css"></head><body scroll="no">');
	  		write(x);
	  		write('</body></html>');
	  		close();
	  	}
  	}
}