// browser detection

var isMac;
var NS4;
var IEmac;
var IE4plus;
var IE4;
var IE5;
var IE6;
var ver4;
var NS6;
var IE5plus;
var IEMajor;

detectBrowser();

function detectBrowser()
{
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
	IE5plus = IE5 || IE6;
	IEMajor = 0;
	if (IE4plus)
	{
		var start = navigator.appVersion.indexOf("MSIE");
		var end = navigator.appVersion.indexOf(".",start);
		IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
		IE5plus = (IEMajor>=5) ? true : false;
	}
}

// flash detection

var requiredVersion = 6;
var flashAvailable = false;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])?navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i)
	{
		if (isNaN(parseInt(words[i])))
			continue;
		var pluginVersion = words[i]; 
	}
	parts = pluginVersion.split(".");
	majorVersion = parts[0];
	flashAvailable = majorVersion >= requiredVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1))
{
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\>\n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next\n');
	document.write('flashAvailable=( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & requiredVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

/**
* Basic DOM getElementByID
*/
function getElement(elementID)
{
	if (document.getElementById)
		return document.getElementById(elementID);
	else if (document.all)
		return document.all[elementID];
	else if (document.layers)
		return document.elementID;
	else
		return false;
}

function cookieCheck()
{
	document.cookie = "TemporaryTestCookie=yes;";
	if( document.cookie.indexOf("TemporaryTestCookie=") == -1)
	{
		document.write("<span style='color:red'>Important Note: You need to enable Cookies in order to use all features of this web site.</span><br/>");
		document.write("<span style='color:red'>Hinweis: Sie müssen Cookies zulassen um diese Website in ihrem ganzen Umfang zu benutzen.</span>");
	}
}

/**
* Basic DOM getElementByName
*/

/**
* Perform navigation according to the dropdown selection
*/
function navigate(selected)
{
	if (selected.value == 0)
		return;
	primary = getElement('primaryNavigation');
	secondary = getElement('secondaryNavigation');
	primarySel = primary.options[primary.selectedIndex];
	secondaryText = null;
	secondaryValue = null;
	showProduct = null;
	re = /\//gi;
	if (secondary && selected != primarySel)
	{
		if (secondary.value != 0)
		{
			secondarySel = secondary.options[secondary.selectedIndex];
			secondaryText = trim(secondarySel.text); 
			secondaryText = secondaryText.replace(re, '');
			secondaryValue = secondarySel.value;
			if (secondaryValue.charAt(0) == 'p')
			{
				showProduct = 1;
				secondaryValue = secondaryValue.substring(1);
			}
		}
	}
	primaryText = trim(primarySel.text);
	primaryText = primaryText.replace(re, '');
	newLocation = '/catalogue/' + trim(primarySel.text) + '/' + primarySel.value;
	if (secondaryText)
	{
		newLocation = newLocation + '/' + secondaryText;
		newLocation = newLocation + '/' + secondaryValue;
	}
	if (showProduct)
	{
		newLocation = newLocation + '/' + showProduct;
	}
	document.location.href = newLocation;
}

function changeSearchOrder(baseURL, selected)
{
	newLocation = baseURL + selected.value;
	document.location.href = newLocation;
}

function changeResPerPage(baseURL, selected)
{
	newLocation = baseURL + selected.value;
	document.location.href = newLocation;
}

function trim(str)
{
	while (str.charAt(0) == ' ' || str.charCodeAt(0) == 160)
	{
		str = str.substring(1, str.length);
	}
	while (str.charAt(str.length-1) == ' ' || str.charCodeAt(str.length-1) == 160)
	{
		str = str.substring(0, str.length-1);
	}
	return str;
}

function clearDefault(inputField)
{
  if (inputField.defaultValue == inputField.value)
		inputField.value = ""
}


