﻿//determine IE or FF
	var ssIE = false;
	
	if(document.all)
	{
		//IE
		ssIE = true;
	}
	
	var curloadingleft = 0;
	var curloadingtop = 0;
	
	function searchValidate(locale, searchInput)
    	{
		__CMS_PostbackFormBeenReset = true;
        
        
        if(ssIE)
        {
            
            var searchtxt_id = document.getElementById(searchInput);
			var SrchTxt = eval('document.all.' + searchInput + '.value');
			if (SrchTxt != ''){
			document.forms[0].action = '/fnet/' + locale + '/search/searchresult.htm?mode=ShowAll&query='+SrchTxt;
			
			//Show loading text when clicked on Search button
			ShowLoading(searchInput,"headerLoading");
			document.forms[0].submit();
			
			}
			else {
			return false;
			}
        }
        else
        {   
            
            var SrchTxt = document.getElementById(searchInput).value;  
            
            if (SrchTxt != '')
			{
			    
			    document.forms[0].action = '/fnet/' + locale + '/search/searchresult.htm?mode=ShowAll&query='+SrchTxt;
			    //Show loading text when clicked on Search button
			    
			    ShowLoading(searchInput,"headerLoading");
			    
			}
			else
			{
			    return false;
			}
        }
        
    	}
	
	//variables to track number of Search Suggest results and which item is highlighted
	var ssNumResults = 0;
	var ssNumHighlighted = 0;
	//variables to track position of div
	var curleft = 0;
	var curtop = 0;
	var loadingPos =0;
	
	//global var for search box Id
	ssBoxId = "";

    function ShowLoading(searchId,cssClass)
    {
        //var SrchTxt = eval('document.all.' + searchId + '.value');
        var SrchTxt = document.getElementById(searchId).value;
        
        if (SrchTxt != '')
		{
         
			var searchtxt_id = document.getElementById(searchId);
			var div_topSearchId = document.getElementById('topSearchLoading');
				
			
			/*div_topSearchId.innerHTML="<table class='"+ cssClass +"' border=0><tr><td width=20 ><IMG src='/fnet_www/images/loading_sm_gray.gif' height ='16px' width ='16px'></td><td style='color:white;'>"+ sLoading +"...</td></tr></table>";*/
			var tblSearchLoading = document.getElementById('tblLoading');
			tblSearchLoading.className = cssClass;
			//position based on current values
			if(curleft == 0)	
			{
			    findPosForLoading(searchtxt_id);
			}
			
			div_topSearchId.style.position="absolute";
			
			// Adjust the positions for IE and Firefox
			if(ssIE)
			{
				div_topSearchId.style.left = curleft + "px";
				div_topSearchId.style.top = loadingPos + "px";
			}
			else
			{
				div_topSearchId.style.left = curleft-11 + "px";
				div_topSearchId.style.top = loadingPos-3 + "px";
			}
						
			//div_topSearchId.style.color="white";
			//div_topSearchId.display = "block";
			div_topSearchId.style.display = "block";
		
		}
    
    }

	//onkeyup, show suggested products
	function ShowSearchSuggest(divId, txtId, evt)
	{
		if(document.getElementById)
		{
			//set global text id
			ssBoxId = txtId;
			
			//check for arrow keys and move selected item
			if(!evt)
			{
				evt = window.event;
			}
			var k = evt.keyCode;
			if(k == 40 || k == 38)
			{
				if(ssNumResults > 0)
				{
					ssMoveArrow(k);
				}
			}
			else
			{
			
				var div_id = document.getElementById(divId);
				var txt_id = document.getElementById(txtId);
				
				//set left and top
				findPos(txt_id);
				
				var txtString = txt_id.value;
				var prodstring;
				
				//set the results back to zero
				ssNumResults = 0;
				ssNumHighlighted = 0;
				//clear div HTML
				div_id.innerHTML = " ";
				
				//loop through products and look for text field match
				for(ssCount = 0; ssCount < ssProdArr.length; ssCount++)
				{
					prodstring = ssProdArr[ssCount];
					//remove special characters from comparison
					prodstring = prodstring.replace(/®/,"");
					prodstring = prodstring.replace(/™/,"");
					prodstring = prodstring.replace(/²/,"");
					txtString = txtString.replace(/®/,"");
					txtString = txtString.replace(/™/,"");
					txtString = txtString.replace(/²/,"");
					
					if(prodstring.toLowerCase().indexOf(txtString.toLowerCase()) == 0 && txtString.length > 0)
					{
						ssNumResults++;
						div_id.innerHTML += "<div id='ss" + ssNumResults + "' class='ssResult' onmouseover='ssHighlight(" + ssNumResults + ")' onmouseout='ssHighlight(0)'>" + ssProdArr[ssCount] + "</div>";
					}
				} 
				
				//if there were results, show the suggestion div
				if(ssNumResults > 0)
				{
					div_id.style.display = 'block';
					
					//position based on current values
					div_id.style.left = curleft + "px";
					div_id.style.top = curtop + "px";
					
				}
				else
				{
					div_id.style.display = 'none';
				}
			}
			
		}
	}
	
	//trigger highlight based on arrow key
	function ssMoveArrow(k)
	{
		if(k == 40)
		{
			//down arrow
			if(ssNumHighlighted == ssNumResults)
			{
				ssHighlight(1);
			}
			else
			{
				ssHighlight(ssNumHighlighted + 1);
			}
		}
		else if(k == 38)
		{
			//up arrow
			if(ssNumHighlighted < 2)
			{
				ssHighlight(ssNumResults);
			}
			else
			{
				ssHighlight(ssNumHighlighted - 1);
			}
		}
			
	}
	
	//highlight item and place results in text box
	function ssHighlight(h)
	{
		if(document.getElementById)
		{
			for(ssCount = 1; ssCount <= ssNumResults; ssCount++)
			{
				//retore div style for all items
				document.getElementById("ss"+ssCount).className = "ssResult";
			}
			
			if(h != 0)
			{
				//highlight the selected div
				document.getElementById("ss"+h).className = "ssResultHover";
				ssNumHighlighted = h;	
				//place highlight result in text box
				if(ssIE)
				{
					document.getElementById(ssBoxId).value =  document.getElementById("ss"+h).innerText;
				}
				else
				{
					document.getElementById(ssBoxId).value =  document.getElementById("ss"+h).textContent;
				}
			}
			else
			{
				ssNumHighlighted = 0;
			}
		}
	}
	
	function ClearTopSearchSuggest()
	{
		if(document.getElementById)
		{
			var div_id = document.getElementById("topSearchSuggest");
			div_id.style.display = 'none';
		}
	}
	
	function ClearWorkflowDiv()
	{
		if(document.getElementById)
		{
			var div_id = document.getElementById("EmailWorkflow");
			div_id.style.display = 'none';
		}
	}
	
	//used to get position of an object (ie, textboxes) and set the curleft and curtop
	function findPos(obj) { 
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	loadingPos = curtop;
	//adjust for size of text box
	curtop += 21;
	
	}

//used to get position of an Search text box object (ie, textboxes) and set the curleft and curtop
	function findPosForLoading(obj) {
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	loadingPos = curtop-25;
	
	}