/*
	Lighting Site related javascripts 
*/

//JS function tabs for luminaries

/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be removed, eventType:"+evType);
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}



function tabMenu(id,tabcont){	
	var str=id;
	var chk;
	var tab;
		for (var i=1; i <= tabcont; i++) {			
			if(tabcont==2){
				tab="rawone_tab_prod"+i;
			}else{
				tab="rawtwo_tab_prod"+i;
			}
			chk=getInnerText(tab);			
			document.getElementById(tab).innerHTML="<a href='javascript:void(0)'>"+chk+"</a>";			
			var container="tab_container"+i;
			document.getElementById(tab).className="taboff";
			document.getElementById(container).style.display="none";
		}
	chk=getInnerText(id);
	document.getElementById(str).className="tabon";
	document.getElementById(str).innerHTML=chk;
	var contid="tab_container"+str.charAt(str.length-1);
	
	document.getElementById(contid).style.display="block";
}


function getInnerText(elt) {
	var innerText = document.getElementById(elt).innerText;
	if (innerText == undefined || innerText == "") {
  		var innerText = document.getElementById(elt).innerHTML.replace(/<[^>]+>/g,"");
	}	
	return innerText;
}

// Handle the tabs on the basis of the tab number
function handleTab(tab){
		document.getElementById(tab).style.display="block";
}

function colapseMenu(id){	
	var clname=document.getElementById(id).className;
	if(clname=="subactive"){
		document.getElementById(id).className="subdeactive";
		document.getElementById("child_menu").style.display="block";
	}else{
		document.getElementById(id).className="subactive";
		document.getElementById("child_menu").style.display="none";
	}
}

function closePopup(){
	document.getElementById("popupWindow").style.display="none";
}

function closeRMPPopup(){
	document.getElementById("popupRMPWindow").style.display="none";
}
//Js function for collapse more deatils section on specifcation tab
function moreInfo(){
	if(document.getElementById("moreinfo").style.display=="none"){
		document.getElementById("moreinfo").style.display="block";	
		document.getElementById("more").style.display="none";
		document.getElementById("less").style.display="block";
	}else{
		document.getElementById("moreinfo").style.display="none";	
		document.getElementById("more").style.display="block";
		document.getElementById("less").style.display="none";
	}
}

//JS function for closing the popup window
function handlePopup(action){
	if(action=="open"){
		document.getElementById("popupWindow").style.display="block";
	}else{
		document.getElementById("popupWindow").style.display="none";
	}
}

//function for poplayer
var ie6PNGfix=function(obj,img){
	$(obj).attr("writing-mode","tb-rl");
	$(obj).css("background-image","none");
	$(obj).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"',sizingMethod='scale')");
};

function loadGallery(jspToLoad,pScene7AssetId,initialAssetIndex){
   
	loadContentIntoMovieWindow(jspToLoad,{"scene7Id":pScene7AssetId,"initialAssetIndex":initialAssetIndex});
}

function loadWarningSafety(jspToLoad,pWarningText,prdId){
   
	loadContentIntoMovieWindow(jspToLoad,{"warningText":pWarningText,"prdId":prdId});
	}
	
function loadRichMediaPlayerWindow(jspToLoad,productId,country, language, catalogType, catalogLocale,group,assetDocType){
	if(assetDocType != "undefined" && assetDocType != null){
		loadContentIntoRichMediaPlayerWindow(jspToLoad,{"productId":productId, "group":group, "assetDocType":assetDocType,"userCountry":country, "userLanguage":language, "catalogType":catalogType, "catalogLocale":catalogLocale});
	}else{
		loadContentIntoRichMediaPlayerWindow(jspToLoad,{"productId":productId, "group":group,"userCountry":country, "userLanguage":language, "catalogType":catalogType, "catalogLocale":catalogLocale});
	}
}

function loadRichMediaPlayerWindowForFamily(jspToLoad,categoryId,country, language, catalogType, catalogLocale,group,assetDocType){
	if(assetDocType != "undefined" && assetDocType != null){
		loadContentIntoRichMediaPlayerWindowForFamily(jspToLoad,{"categoryId":categoryId, "group":group, "assetDocType":assetDocType,"userCountry":country, "userLanguage":language, "catalogType":catalogType, "catalogLocale":catalogLocale});
	}else{
		loadContentIntoRichMediaPlayerWindowForFamily(jspToLoad,{"categoryId":categoryId, "group":group,"userCountry":country, "userLanguage":language, "catalogType":catalogType, "catalogLocale":catalogLocale});
	}
}

function hideOpenLayers(){
	if($("#popupWindow").length>0){
		$("#popupWindow").remove();
	}if($("#buyLayer").length>0){
		$("#buyLayer").remove();
	}if($("#movieLayer").length>0){
		$("#movieLayer").remove();
	}if($("#viewLayer360").length>0){
		$("#viewLayer360").remove();
	}if($(".popuplayer").length>0){
		$(".popuplayer").remove();
	}if($(".popuplayer2").length>0){
		$(".popuplayer2").remove();
	}
}
function createMovieWindow(contentPage){
       
       var warningPage = "/l/catalog/fragments/warning_Safety_Viewer.jsp";
       var familyWarningPage = "/l/catalog/fragments/family_Warning_Safety_Viewer.jsp";
       var movieWindowHTML;
       if(contentPage.toString()== warningPage.toString() || contentPage.toString()== familyWarningPage.toString())
       {
           movieWindowHTML='<div id="popupWindow"><div id="popupWindow-content-frame"><div id="popupWindow-contentWarning" class="clearfix"><div id="popupWindow-closeButton" class="clearfix"><a href="javascript:void(0)" onclick="removeMovieWindow()"><img src="/assets_lt/img/popupWindow/btn-close-popupWindow.png" alt="close"/></a></div><div id="popupWindow-content-loaded" class="clearfix"></div></div></div><div id="popupWindow-bottom"></div></div>';
       }
       else
       {
           movieWindowHTML='<div id="popupWindow"><div id="popupWindow-content-frame"><div id="popupWindow-content" class="clearfix"><div id="popupWindow-closeButton" class="clearfix"><a href="javascript:void(0)" onclick="removeMovieWindow()"><img src="/assets_lt/img/popupWindow/btn-close-popupWindow.png" alt="close"/></a></div><div id="popupWindow-content-loaded" class="clearfix"></div></div></div><div id="popupWindow-bottom"></div></div>';
       }
		
		$("body").append(movieWindowHTML);
		centerPosition($("#popupWindow"),243);
}
function createRichMediaPlayerWindow(){
	var richMediaPlayerWindowHTML='<div id="popupRMPWindow"><div id="popupRMPWindow-content-frame"><div id="popupRMPWindow-content" class="clearfix"><div id="popupWindow-content-loaded" class="clearfix"></div></div></div><div id="popupWindow-bottom"></div></div>';
	$("body").append(richMediaPlayerWindowHTML);
	
	// Prevent the page from scrolling (scrolling needs to be handled by the popup) - Robin van der Vleuten (NLY41975)
	$( 'body' ).css( 'overflow', 'hidden' );
	
	centerPosition($("#popupRMPWindow"),150);
}

function createRichMediaPlayerWindowForFamily(){
	var richMediaPlayerWindowHTML='<div id="popupRMPWindow"><div id="popupRMPWindow-content-frame"><div id="popupRMPWindow-content" class="clearfix"><div id="popupWindow-content-loaded" class="clearfix"></div></div></div><div id="popupWindow-bottom"></div></div>';
	$("body").append(richMediaPlayerWindowHTML);
	centerPosition($("#popupRMPWindow"),150);
	
	// event handlers
	$("body").mousedown(popupClickoutHandler); // use mousedown instead of click to stop the previous click from triggering it!
	if (!$.browser.mozilla) // not for Firefox as it causes Flash to reload due to this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=90268
		$("#popupWindow-content-loaded").hover(popupMouseOverHandler, popupMouseOutHandler);
}

function popupClickoutHandler(e){
    var target = $(e.target);
	var popup = $("#popupRMPWindow");
	if(popup.length && target != popup && !target.parents('#popupRMPWindow').length){
		popup.remove(); 
		$("body").unbind('mousedown', popupClickoutHandler);
    }
	return true;
}
function popupMousewheelHandlerFirefox(e){
	// Disable scrolling in the main window when mouse is over the popup (to allow zooming of the media using the mousewheel).
	// For Firefox only (other browsers use popupMouseOverHandler and popupMouseOutHandler).
	// IE can not use this method since e.cancelBubble=true doesn't stop the page scrolling, but e.returnValue=false stops the Flash zoom.
	if (e.stopPropagation) e.stopPropagation();
	if (e.preventDefault) e.preventDefault();
}
function popupMouseOverHandler(){
	// Disable scrolling in the main window when mouse is over the popup (to allow zooming of the media using the mousewheel)
	// Not for Firefox (uses popupMousewheelHandlerFirefox instead)
	var width=document.documentElement.clientWidth+"px"; // stop the body resizing when the scrollbar hides
	document.documentElement.style.overflow="hidden";
	document.documentElement.style.width=width;
}
function popupMouseOutHandler(){
	// re-enable scrolling in the main window when mouse leaves the popup
	// Not for Firefox (uses popupMousewheelHandlerFirefox instead)
	// IE does not support document.body.style unless in quirks mode
	document.documentElement.style.width="";
	document.documentElement.style.overflow="";
}

function removeMovieWindow(){
	$("#popupWindow").remove();
	posx =0;
	posy =0;
}
function loadContentIntoRichMediaPlayerWindow(contentPage,paramValues){
	hideOpenLayers();
	createRichMediaPlayerWindow();
	
	$("#popupWindow-content-loaded").load(contentPage,paramValues,function(){
		$("#popupRMPWindow").show();
		var isIE6=/msie|MSIE 6/.test(navigator.userAgent);
		if(isIE6){$("#popupWindow-content-frame").css({"height":$("#popupWindow-content-frame").height()});
		$("#popupWindow-content").css({"height":$("#popupWindow-content").height()});
		ie6PNGfix($("#popupWindow-content-frame"),"/assets_lt/img/popupWindow/bg-popupWindowTop-ie6.png");
		ie6PNGfix($("#popupWindow-bottom"),"/assets_lt/img/popupWindow/bg-popupWindowBottom-ie6.png");
	}
	if(typeof sIFRinit!="undefined"){sIFRinit();}});
}

function loadContentIntoRichMediaPlayerWindowForFamily(contentPage,paramValues){
	hideOpenLayers();
	createRichMediaPlayerWindowForFamily();
	
	$("#popupWindow-content-loaded").load(contentPage,paramValues,function(){
		if ($.browser.mozilla)
			$("#popupWindow-content-loaded").children().get(0).addEventListener("DOMMouseScroll", popupMousewheelHandlerFirefox, false);
		
		$("#popupRMPWindow").show();
		var isIE6=/msie|MSIE 6/.test(navigator.userAgent);
		if(isIE6){$("#popupWindow-content-frame").css({"height":$("#popupWindow-content-frame").height()});
		$("#popupWindow-content").css({"height":$("#popupWindow-content").height()});
		ie6PNGfix($("#popupWindow-content-frame"),"/assets_lt/img/popupWindow/bg-popupWindowTop-ie6.png");
		ie6PNGfix($("#popupWindow-bottom"),"/assets_lt/img/popupWindow/bg-popupWindowBottom-ie6.png");
		
	}
	if(typeof sIFRinit!="undefined"){sIFRinit();}});
}

function loadContentIntoMovieWindow(contentPage,paramValues){
   (contentPage);
	hideOpenLayers();
	createMovieWindow(contentPage);
	
	$("#popupWindow-content-loaded").load(contentPage,paramValues,function(){
		$("#popupWindow").show();
		var isIE6=/msie|MSIE 6/.test(navigator.userAgent);
		if(isIE6){$("#popupWindow-content-frame").css({"height":$("#popupWindow-content-frame").height()});
		$("#popupWindow-content").css({"height":$("#popupWindow-content").height()});
		ie6PNGfix($("#popupWindow-content-frame"),"/assets_lt/img/popupWindow/bg-popupWindowTop-ie6.png");
		ie6PNGfix($("#popupWindow-bottom"),"/assets_lt/img/popupWindow/bg-popupWindowBottom-ie6.png");
	}
	if(typeof sIFRinit!="undefined"){sIFRinit();}});
}

//To hide the autosuggest div, if user click outside the div

document.onclick=check;
function check(e){
	var obj = document.getElementById("search_cat_suggestlist");
	if(obj){
		var target = (e && e.target) || (event && event.srcElement);
		var obj = document.getElementById('search_cat_suggestlist');
		checkParent(target)?obj.style.display='none':null;
	}
}
function checkParent(t){
	while(t.parentNode){
		if(t==document.getElementById('search_cat_suggestlist')){
			return false
		}
		t=t.parentNode
	}
	return true
}


var posx = 0;
var posy = 0;
function centerPosition(objlyr,topPos){
                var botPos=posy;

                var screenCenter=$("body").width()/2;
                var centerPos=screenCenter-($(objlyr).width()/2);
                if(botPos != 0){
	                  $(objlyr).css({left:centerPos,top:botPos-400});
	                  window.scrollTo(0,botPos-400);
                }else{
                      $(objlyr).css({left:centerPos,top:topPos});
                      window.scrollTo(0,topPos-50);
                }
                
}


function getMousePos(e) {
                if (!e) var e = window.event;
                if (e.pageX || e.pageY)                 {
                                posx = e.pageX;
                                posy = e.pageY;
                }
                else if (e.clientX || e.clientY)      {
                                posx = e.clientX + document.body.scrollLeft
                                                + document.documentElement.scrollLeft;
                                posy = e.clientY + document.body.scrollTop
                                                + document.documentElement.scrollTop;
                }
}


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip1").hover(function(e){										  
		this.t = this.title;
		this.t = document.getElementById('content'+this.id).innerHTML;
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		$("#tooltip").remove();
    });	
	$("a.tooltip1").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


this.tooltipImg = function(){	//alert("2");
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		//alert("3");
	$("td.iconImg").hover(function(e){//	alert("4");	alert(document.getElementById('imgcontent'+this.id).innerHTML);									  
		this.t = this.title;
		this.t = document.getElementById('imgcontent'+this.id).innerHTML;//alert(document.getElementById('imgcontent'+this.id).innerHTML);
		$("body").append("<p id='tooltipImg'>"+ this.t +"</p>");
		$("#tooltipImg")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		//this.title = this.t;		
		$("#tooltipImg").remove();
    });	
	$("td.iconImg").mousemove(function(e){
		$("#tooltipImg")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/*
 * URL Manipulation scripts
 * Used to get/set/manipulate window.location.href
 */

var PARAM_SORT = "sort";

function getParam(name, curloc){
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?#&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(curloc);
	if (results == null)
		return "";
	else
		return results[1];
}

function getUrlParam(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?#&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results == null)
		return "";
	else
		return results[1];
}

function setHashParamFromLocation(name,value) {
	var newHash = setHashParam(name,value,window.location.hash);
	window.location.hash = newHash;
}

function setHashParam(name,value,curloc){
	if( value == null || value == ""){
		return removeUrlParam(name, curloc);
	}
	
	var currentParamValue = getParam(name, curloc);
	if( currentParamValue == ""){
		var paramPair = name + "=" + value;
		if( curloc.indexOf("#") > -1 ){
			if (curloc.indexOf('#') == curloc.length-1) {
				curloc = curloc + paramPair;
			} else {
				curloc = curloc + "&" + paramPair;
			}
		}else{
			curloc = curloc + "#" + paramPair;
		}
	}else{
		// replace value
		var oldString = "&" + name + "=" + currentParamValue;
		var newString = "&" + name + "=" + value;
		
		if (curloc.indexOf(oldString) == -1){
			// Not found, first element??
			oldString = "#" + name + "=" + currentParamValue;
			newString = "#" + name + "=" + value;
		}
		curloc = curloc.replace(oldString,newString);
	}
	return curloc;
}

function setParam(name,value,curloc){
	if (value == null ||value == ""){
		return removeUrlParam(name,curloc);
	}	
	
	var currentParamValue =  getParam(name, curloc);
	if ( currentParamValue == ""){
		var paramPair = name + "=" + value;
		if( curloc.indexOf("?") > -1 && curloc.indexOf("#") > -1 ){
			// ....?a=b#c=d
			curloc = curloc.replace("#","&" + paramPair + "#");
		}else if( curloc.indexOf("?") > -1 && curloc.indexOf("#") == -1){
			// ....?a=b
			curloc = curloc + "&" + paramPair;
		}else if( curloc.indexOf("?") == -1 && curloc.indexOf("#") > -1){
			// ....#c=d
			curloc = curloc.replace("#","?" + paramPair + "#");
		}else if( curloc.indexOf("#")== -1 ){
			// ...
			curloc = curloc + "?" + paramPair;
		}
	}else{
		// replace value
		var oldString = "&" + name + "=" + currentParamValue;
		var newString = "&" + name + "=" + value;
		
		if (curloc.indexOf(oldString) == -1){
			// Not found, first element??
			oldString = "?" + name + "=" + currentParamValue;
			newString = "?" + name + "=" + value;
		}
		curloc = curloc.replace(oldString,newString);			
	}
	return curloc;
}

function setUrlParam(name, value){
	if (value == null ||value == ""){
		removeUrlParamFromLocation(name);
		return;
	}	
	
	var curloc = window.location.href;
	var currentParamValue = getUrlParam(name); 
	if ( currentParamValue == ""){
		var paramPair = name + "=" + value;
		if( curloc.indexOf("?") > -1 && curloc.indexOf("#") > -1 ){
			// ....?a=b#c=d
			curloc = curloc.replace("#","&" + paramPair + "#");
		}else if( curloc.indexOf("?") > -1 && curloc.indexOf("#") == -1){
			// ....?a=b
			curloc = curloc + "&" + paramPair;
		}else if( curloc.indexOf("?") == -1 && curloc.indexOf("#") > -1){
			// ....#c=d
			curloc = curloc.replace("#","?" + paramPair + "#");
		}else if( curloc.indexOf("#")== -1 ){
			// ...
			curloc = curloc + "?" + paramPair;
		}
	}else{
		// replace value
		var oldString = "&" + name + "=" + currentParamValue;
		var newString = "&" + name + "=" + value;
		
		if (curloc.indexOf(oldString) == -1){
			// Not found, first element??
			oldString = "?" + name + "=" + currentParamValue;
			newString = "?" + name + "=" + value;
		}
		curloc = curloc.replace(oldString,newString);			
	}
	window.location.href = curloc;
}

function removeUrlParamFromLocation(paramName){
	var curloc = window.location.href;
	
	curloc = removeUrlParam(paramName,curloc);
	
	window.location.href = curloc;
}

function removeUrlParam(paramName, curloc){
	var currentParamValue = getUrlParam(paramName);
	var oldString = paramName+"="+currentParamValue;
	
	if( currentParamValue = "")
		return;
	
	// check previous char
	var itemIndex = curloc.indexOf(oldString);
	
	var prevChar = curloc.substr(itemIndex -1, 1);
	var nextChar = (curloc.length == itemIndex + oldString.length) ? "" : curloc.substr(itemIndex + oldString.length, 1);
	
	if( prevChar == "&" ){
		curloc = curloc.replace("&" + oldString, "");
	}else if( prevChar == "?" && nextChar == "&"){
		curloc = curloc.replace(oldString + "&", "");
	}else if( prevChar == "?" && (nextChar == "#" || nextChar == "") ){
		curloc = curloc.replace("?" + oldString, "");
	}else if( prevChar == "#" && nextChar == "&"){
		curloc = curloc.replace(oldString + "&", "");
	}else if( prevChar == "#" && nextChar == ""){
		curloc = curloc.replace(oldString, "");
	}
	return curloc;
}

function replaceFilterState(filterName, filterValue){
	// Example of filterstate: FG_LP_TYPE|FK_LP_TYPE_LAMPS=checked;FG_LP_APP|FK_LP_APP1_OCOFF=checked
	var originalFilterState =  getUrlParam("filterState");
	var currentFilterState = decodeURIComponent(originalFilterState);
	
	// If no filterstate is found then create one
	if ( currentFilterState.length > 0){
	
		var filterStateList = currentFilterState.split(";");
		var found = false;
		for( var i = 0; i<filterStateList.length;i++){
			var filterSplit = filterStateList[i].split("|");
			if (filterSplit[0] == filterName){
				filterSplit[1] = encodeURIComponent(filterValue);
				found = true;
			}
			filterStateList[i] = filterSplit[0] + "|" + filterSplit[1];
		}
		
		if (!found ){
			currentFilterState = currentFilterState + ";" + filterName + "|" + filterValue; 
		}else{
			currentFilterState = "";
		
			for( var i = 0; i<filterStateList.length;i++){
				if( currentFilterState.length > 0 ){
					currentFilterState = currentFilterState + ";";
				}
				currentFilterState = currentFilterState + filterStateList[i];
			}
		}
		return setHashParam("filterState", encodeURIComponent(currentFilterState),window.location.href);
	}
	return setHashParam("filterState", encodeURIComponent(filterName + "|" + filterValue),window.location.href);	
}

function addFilterState(currentFilterState, filterName, filterValue){
	// Example of filterstate: FG_LP_TYPE|FK_LP_TYPE_LAMPS=checked;FG_LP_APP|FK_LP_APP1_OCOFF=checked
	// If no filterstate is found then create one
	currentFilterState = decodeURIComponent(currentFilterState);
	if ( currentFilterState.length > 0){
			currentFilterState = currentFilterState + ";" + filterName + "|" + filterValue; 
		return encodeURIComponent(currentFilterState);
	}
	return encodeURIComponent(filterName + "|" + filterValue);	
}

// Automatically extend the breadcrumb URL with the current filter
$(document).ready(function() { 
	$('li.filter_bc').find('a').click(function() {
		this.href = setHashParam("filterState", getUrlParam("filterState"), this.href);
		// alert(this.href);
	});
});

/**
 * Remove all jquery tabs from the page 
 */
function removeTabs(){
	$("#tabs").tabs("destroy").tabs();
	while($("#tabs").tabs("length") > 0){
		$("#tabs").tabs("remove",$("#tabs").tabs("length")-1);
	}
}

//This function returns the appropriate reference,
// depending on the browser.
function getFlexApp(appName) {
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		return window[appName];
	} else {
		return document[appName];
	}
}

/**
 * Returns a formatted filtervalue based on the type
 * @param type Type of the filtervalue, tree/checkbox/combobox/stepslider
 * @param value value of the filter
 * @returns {String} filtervalue to be used in search
 */
function getFilterValue(type,value){
	if( type == "tree" || type == "checkbox"){
		return value + "=checked";
	}
	if( type == "combobox"){
		return value + "=true";
	}
	if( type == "stepslider"){
		return "range="+value+","+value;
	}
}
