var iMajorVersion = 8; // Major version of Flash required
var iMinorVersion = 0; // Minor version of Flash required
var iRevision = 0;    // Minor version of Flash required
var sPathname = unescape(window.location.href);


/**
 * �ffnet ein Popupfenster
 *
 * @param string der Link zur darzustellenden Seite
 * @param int die H�he des Popups
 * @param int die Breite des Popups
 * @return void
 */
function openPopup(psLink, windowName, piHeight, piWidth, pbAppendParams)
{
	iWidth = (0 == piWidth) ? 500 : piWidth;
	iHeight = (0 == piHeight) ? 500 : piHeight;
	
	var padding = (navigator.appName == "Microsoft Internet Explorer") ? 10 : 0;

	var screenw = screen.availWidth;
	var screenh = screen.availHeight;
	
	var winw = (iWidth + padding);
	var winh = (iHeight + padding);
	
	var posx = (screenw - winw) / 2;
	var posy = (screenh - winh) / 2; 
	pbAppendParams = (typeof(pbAppendParams) == "undefined") ? 1 : 0;
	var sParams = (pbAppendParams) ? "&sLayout=popup" : "";

	win = window.open(psLink+sParams, windowName,'width='+iWidth+',height='+iHeight+',top='+posy+',left='+posx+',scrollbars=no');
	win.focus();
}


/**
 * Suchfunktion f�r Produktseiten
 *
 * @param	string Name des Formulars
 * @param	string Name des Select-Felds
 */
function search(psForm, psFormElem)
{
	var search = eval("document."+psForm+"."+psFormElem+".value");
	if('' != search)
	{
		location.href = search;
	}
}


// Version check based upon the values entered above
if(!DetectFlashVer(iMajorVersion, iMinorVersion, iRevision))
{
	// flash not installed - proceed to fallback pages
	switch(sPathname)
	{
		default:
			break;
//		case 'http://be.selfip.info:8088/beg/en/boschengineeringgmbh/overview/':			
		case 'http://be.selfip.info:8088/beg/de/boschengineeringgmbh/uebersicht/':
			location.href = 'fb_fb_beg.html';
			break;
	}
}


/**
 * Fetch text from webassistant-input-field and 
 * redirect input to openAndQueryWebAssistant function
 */
function getWebQuery(psCountry, psLanguage)
{
	if (document.forms.webassistant.webassistant.value != "") 
	{
		var sQuery = urlEncode(document.forms.webassistant.webassistant.value);
		openWebAssistant(psCountry, psLanguage, sQuery);
	} 
	else 
	{
		openWebAssistant(psCountry, psLanguage);
	}
}


/**
 * �ffnet den Web-Assistenten
 * 
 * @param string
 * @param string
 * @param string
 */
function openWebAssistant(psCountry, psLanguage, psQuery) 
{
	psCountry = ("string" != typeof psCountry) ? "de" : psCountry;
	psLanguage = ("string" != typeof psLanguage) ? "en" : psLanguage;
	psQuery = ("string" != typeof psQuery) ? "" : psQuery;
	
	var sPath = "http://servicefunctions.bosch.com/user/webassistant/search.asp?country="+psCountry+"&lang="+psLanguage+"&query="+psQuery;
	
	window.open(sPath, "webassistant", "width=575,height=475,left=100,top=200,resizable=yes,scrollbars=yes,status=yes,location=yes");
}


/**
 * converts given string into x-www-form-urlencoded format (and space to "%20")
 * @param string
 */
function urlEncode(psText)
{
	var sEncodedText = "";
	for (var n = 0; n < psText.length; n++) 
	{
		var c = psText.charCodeAt(n);
		if (c < 128) 
		{
			if (c >= 65 && c <= 90 ||
				c >= 97 && c <= 122 ||
				c >= 48 && c <= 57 ||
				c == 42 || c == 45 || c == 46 || c == 95) {
				sEncodedText += String.fromCharCode(c);
			} 
			else 
			{
				sEncodedText += "%" + c.toString(16);
			}
		} 
		else if (c > 127 && c < 2048) 
		{
			sEncodedText += "%" + (c >> 6 | 192).toString(16);
			sEncodedText += "%" + (c & 63 | 128).toString(16);
		} 
		else 
		{
			sEncodedText += "%" + (c >> 12 | 224).toString(16);
			sEncodedText += "%" + (c >> 6 & 63 | 128).toString(16);
			sEncodedText += "%" + (c & 63 | 128).toString(16);
		}
	}
	return sEncodedText;
}		