/************************************************
file:	honeywell.js
author:	Richard Schmid
************************************************/

function getDirectoryName(sURL_) {
	var iSlashPos = sURL_.lastIndexOf('/');
	var iBSlashPos = sURL_.lastIndexOf('\\');
	if (iBSlashPos > iSlashPos) iSlashPos = iBSlashPos;
	
	if (iSlashPos == -1) {
		return "/";
	}
	else {
		var sDirectoryName = sURL_.substr(0, iSlashPos+1);
		return sDirectoryName;
	}
}

var HTMLFILEEXTENSION		= ".html";
var HTMLDOCTYPE				= "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'>";
var HTMLSTYLESHEET			= "<link rel='stylesheet' href='styles/content.css' type='text/css'></head>";
var HTMLEND					= "</body></html>";
var BASEPATH				= getDirectoryName(top.location.href);
var TOCPATH					= BASEPATH + "tocs/";
var DOCPATH					= BASEPATH + "ecatdata/";
var PDFPATH					= BASEPATH + "pdf/";

var gToc					= null;
var gDoc					= null;
var gOSNo					= null;
var gBrowser				= null;
var gPdfWinCD				= null;
var goCatWin 				= null;
var goPopupWin				= null;

function _getOpenOptions(sURL, sWidth, sHeight) {
	var sOptions = 'Toolbar=1,Location=1,Directories=1,Status=1,Menubar=1,scrollbars=1,resizable=1,left=0,top=0,width=';
	if (sWidth) {
		if (sURL == '') {
			sOptions = 'Toolbar=0,Location=0,Directories=0,Status=0,Menubar=0,scrollbars=1,resizable=1,left=0,top=0,width=';
		}
		else {
			sOptions = 'Toolbar=1,Location=1,Directories=1,Status=1,Menubar=0,scrollbars=1,resizable=1,left=0,top=0,width=';
		}
		sOptions += sWidth;
	}
	else {
		if (screen.availWidth)
			sOptions += screen.availWidth;
		else
			sOptions += '800';
	}
	
	sOptions += ',height=';
	if (sHeight) {
		sOptions += sHeight;
	}
	else {
		if (screen.availHeight)
			sOptions += (screen.availHeight-150);
		else
			sOptions += '600';
	}
	return sOptions;
}

function openCatWin(sURL, sWidth, sHeight) {
	if (goCatWin) {
		if (!goCatWin.closed)
			goCatWin.close();
	}	
	var sOptions = _getOpenOptions(sURL, sWidth, sHeight);
	goCatWin = window.open(sURL, 'catWin', sOptions);
	goCatWin.focus();
}

function openPopupWin(sURL, sWidth, sHeight) {
	if (goPopupWin) {
		if (!goPopupWin.closed)
			goPopupWin.close();
	}	
	var sOptions = _getOpenOptions(sURL, sWidth, sHeight);
	goPopupWin = window.open(sURL, 'popupWin', sOptions);
	goPopupWin.focus();
}

function VAPS_Summary1(sValveTypeNo, iActuatorDataIdx) {
	var wPSDefWin = parent.frames['HON_DEF'];
	var wASDefWin = parent.frames['HON_AS_DEF'];
	if (!wPSDefWin || !wASDefWin)
		return false;
	var nWidth = 600;
	if (screen.availWidth)
		nWidth = screen.availWidth;
	parent.openPopupWin('', nWidth, 150);
	if (!goPopupWin)
		return false;
	self.setTimeout("parent.frames['HON_DEF']._VAPS_Summary1(parent.frames['HON_DEF'], parent.frames['HON_AS_DEF'], goPopupWin, '" + sValveTypeNo + "', " + iActuatorDataIdx + ")", 100);
}

function gotoCatURL(sFrame, sCatURL){
	if (sFrame == "_top") {
		top.location.href = BASEPATH + sCatURL;
	}
	else {
		top.frames[sFrame].location.href = BASEPATH + sCatURL;
	}
}

function focusOSNo(oDocument) {
	var sLocStr = top.location.href;
	var iParamPos = sLocStr.indexOf("?");
	if (iParamPos >= 0) {
		var sParamStr = sLocStr.substring(iParamPos + 1, sLocStr.length);
		var aParams = new Array();
		var iAIdx = 0;
		
		var sNVSep = "=";
		while (sParamStr.indexOf(sNVSep) >= 0) {
			var sParamSep = "&";
			var iEndActParamIdx = 0;
			if (sParamStr.indexOf(sParamSep) >= 0) {
				iEndActParamIdx = sParamStr.indexOf(sParamSep);
			}
			else {
				iEndActParamIdx = sParamStr.length;
			}
			
			var sActParam = sParamStr;
			if (iEndActParamIdx != sParamStr.length) {
				sActParam = sParamStr.substring(0, iEndActParamIdx);
			}
			
			var iNVSep = sActParam.indexOf(sNVSep);
			var sActParamName = sActParam.substring(0, iNVSep);
			var sActParamValue = sActParam.substring(iNVSep + sNVSep.length, sActParam.length);
			if ((sActParamName != "") && (sActParamValue != "")) {
				aParams[iAIdx] = new Array(sActParamName, sActParamValue);
				iAIdx++;
			}
			
			sParamStr = sParamStr.substring(iEndActParamIdx + sParamSep.length, sParamStr.length);
		}
		
		var sOSNr = "";
		for (iAIdx = 0; iAIdx < aParams.length; iAIdx++) {
			if (aParams[iAIdx][0].toUpperCase() == "OSNO") {
				sOSNr = aParams[iAIdx][1];
			}
		}
		
		if (sOSNr != "") {
			if (oDocument.all) {
				var oProduct = oDocument.all[sOSNr];
				if (oProduct) {
					oProduct.style.backgroundColor = "#CCCCCC";
					oProduct.scrollIntoView(true);
				}
			}
			else if (oDocument.getElementById) {
				var oProduct = oDocument.getElementById(sOSNr);
				if (oProduct) {
					oProduct.style.backgroundColor = "#CCCCCC";
					oProduct.scrollIntoView(true);
				}
			}
		}
	}
}

function nvLoadFrameset(oDocument_, sNavID_, sDocID_) {
	if (sDocID_ == "nolink")
		return;
		
	var sRelPath = "";
	if (top.gsRelPath) {
		sRelPath = top.gsRelPath;
	}
	
	var sFrameBaseName = "f_" + sDocID_;
	if (!top.frames["HON_NAV"]) {
		top.location.href = BASEPATH + sRelPath + "frames/" + sFrameBaseName + ".html";
	}
}

// ----------------------------------------------
// Funktion:  loadTocDoc
// Kommentar: Neues Toc und Doc laden.
// Parameter: toc, doc
// Rückgabe:  -
// ----------------------------------------------
function loadTocDoc(toc, doc, iOSNrLink, sOSNr, iFS) {
	var targetToc 	= top.HON_NAV.location;
	var targetDoc	= top.HON_DOC.location;
	var m_browser = 10; //1=IE(>4); 0=IE(>3); 10=IE(something); 6=Netscape(>4); 5=Netscape(>3); 10=something

	var sTocToLoad = toc;
	var sDocToLoad = doc;
	//in case toc actually contains toc AND doc-parameter
	var liTocDoc = toc.split(",");
	if (liTocDoc.length == 2) {
		sTocToLoad = liTocDoc[0];
		sDocToLoad = liTocDoc[1];
	}
	
	if (iOSNrLink == 1) {
		gOSNo = sOSNr;
	}
	else {
		gOSNo = null;
	}
	
	if (navigator.appName.indexOf("Microsoft") == 0) {
		if (parseFloat(navigator.appVersion) >= 4) {
			m_browser = 1;
		}
		else if (parseFloat(navigator.appVersion) >= 3) {
			m_browser = 0;
		}
		else {
			m_browser = 10;
		}
	}
	else if (navigator.appName.indexOf("Netscape") == 0) {
		if (parseFloat(navigator.appVersion) >= 4) {
			m_browser = 6;
		}
		else if (parseFloat(navigator.appVersion) >= 3) {
			m_browser = 5;
		}
		else {
			m_browser = 10;
		}
	}
	
	if (sTocToLoad.toUpperCase() != "NOLINK") {
		targetToc.href = BASEPATH + top.gsRelPath + "tocs/" + sTocToLoad + HTMLFILEEXTENSION;
	}
	
	if (sDocToLoad.toUpperCase() == "NOLINK") {
		targetDoc.href = BASEPATH + top.gsRelPath + "empty.html";
	}
	else {
		targetDoc.href = BASEPATH + top.gsRelPath + "ecatdata/" + sDocToLoad + HTMLFILEEXTENSION;
	}
		
	top.gToc = sTocToLoad;
	top.gDoc = sDocToLoad;
	top.gBrowser = m_browser;
}//end of loadTocDoc

function scrollToAnchor(oDocument) {
	var j;
	var actRefStr = "javascript:top.loadTocDoc('" + top.gToc + "','" + top.gDoc + "')";
	
	if (top.gBrowser == 1) {
		for (j=0;j<oDocument.all.length;++j) {
			actChoice = "";
			if (oDocument.all[j].tagName == "A") {
				if (oDocument.all[j].href == actRefStr) {
					oDocument.all[j].scrollIntoView(true);
				}
			}
		}
	}
	else if (top.gBrowser == 6) {
		for (j=0;j<oDocument.links.length;++j) {
			if (oDocument.links[j].href == actRefStr) {
				window.scrollTo(oDocument.links[j].x, oDocument.links[j].y-45);	
			}
		}
	}
}

function loadSearchPage(){
	top.HON_DOC.location.href = "search.html";	
}

function loadSearchPageCD(){
	top.HON_DOC.location.href = "ssearch/index.html";	
}

function loadSearchPageWeb(){
	top.HON_DOC.location.href = "ssearch/index.php";	
}

function loadStartPage(){
	top.loadTocDoc("LA", "marketing/ma", 0, "");
}

function hFireLink(oDocument) {
	var sLocStr = oDocument.location.href;
	var iParamPos = sLocStr.indexOf("?");
	if (iParamPos >= 0) {
		var sParamStr = sLocStr.substring(iParamPos + 1, sLocStr.length);
		var aParams = new Array();
		var iAIdx = 0;
		//alert(sParamStr);
		
		var sNVSep = "=";
		while (sParamStr.indexOf(sNVSep) >= 0) {
			var sParamSep = "&";
			var iEndActParamIdx = 0;
			if (sParamStr.indexOf(sParamSep) >= 0) {
				iEndActParamIdx = sParamStr.indexOf(sParamSep);
			}
			else {
				iEndActParamIdx = sParamStr.length;
			}
			
			var sActParam = sParamStr;
			if (iEndActParamIdx != sParamStr.length) {
				sActParam = sParamStr.substring(0, iEndActParamIdx);
			}
			
			var iNVSep = sActParam.indexOf(sNVSep);
			var sActParamName = sActParam.substring(0, iNVSep);
			var sActParamValue = sActParam.substring(iNVSep + sNVSep.length, sActParam.length);
			if ((sActParamName != "") && (sActParamValue != "")) {
				aParams[iAIdx] = new Array(sActParamName, sActParamValue);
				iAIdx++;
			}
			
			sParamStr = sParamStr.substring(iEndActParamIdx + sParamSep.length, sParamStr.length);
		}
		
		//check for toc, group OR marketing-param
		var sTocID = "";
		var sGroupID = "";
		var sMInfID = "";
		var sShowToc = "";
		var sOSNr = "";
		
		for (iAIdx = 0; iAIdx < aParams.length; iAIdx++) {
			if (aParams[iAIdx][0].toUpperCase() == "TOC") {
				sTocID = aParams[iAIdx][1].toLowerCase();
			}
			else if (aParams[iAIdx][0].toUpperCase() == "GROUP") {
				sGroupID = aParams[iAIdx][1].toLowerCase();
			}
			else if (aParams[iAIdx][0].toUpperCase() == "MARKETING") {
				sMInfID = aParams[iAIdx][1].toLowerCase();
			}
			else if (aParams[iAIdx][0].toUpperCase() == "SHOWTOC") {
				sShowToc = aParams[iAIdx][1];
			}
			else if (aParams[iAIdx][0].toUpperCase() == "OSNO") {
				sOSNr = aParams[iAIdx][1];
			}
		}
		
		//(tocid AND ShowToc) OR (groupid [osno] AND ShowToc)
		if ((sTocID != "") && (sShowToc != "0")) {
			//marketing-info, lookup sMInfID
			top.location.href = BASEPATH + top.gsRelPath + "frames/f_" + sTocID + HTMLFILEEXTENSION;
		}
		else if (sGroupID != "") {
			var sOSNrParam = "";
			var iOSNrLink = 0;
			if (sOSNr != "") {
				iOSNrLink = 1;
				sOSNrParam = "?OSNO=" + sOSNr;
			}
							
			if (sShowToc == "1") {
				top.location.href = BASEPATH + top.gsRelPath + "frames/f_" + sGroupID + HTMLFILEEXTENSION + sOSNrParam;
			}
			else {
				//ecatdata loads the frameset - so: it's wrong
				//docs is Group-Only
				top.location.href = BASEPATH + top.gsRelPath + "docs/" + sGroupID + HTMLFILEEXTENSION + sOSNrParam;
			}
		}
		else if (sOSNr != "") {
			gOSNo = sOSNr;
		}
	}
}