/* TOPRAIL JavaScript FILE */
var SiteSearchFieldDefault = new String("");

// The prepSiteSearch function clears the (site) search field or sets it to msg.
// prepSiteSearch takes a DOM object as well as a boolean value for arguments.
// objSearchField is the site search field (object) and fieldHasFocus is true/false.
function prepSiteSearch (objSearchField,fieldHasFocus) 
{
	if (SiteSearchFieldDefault == "") SiteSearchFieldDefault = objSearchField.value;
	if (objSearchField.value == SiteSearchFieldDefault) objSearchField.value = ""; 
	else if (objSearchField.value.search(/[0-9A-z]+/g) == -1) {
		objSearchField.value = SiteSearchFieldDefault;
		SiteSearchFieldDefault = ""; //reset variable
	}
}

// The filterSiteSearch function redirects a search to a specific page if a keyword
// starts with bl and is followed by 5-8 numbers. The redirect is based on the site 
// argument and the numerical part of the value of the criteria argument.
function filterSiteSearch ( site, criteria ) 
{
	var regExp = /\b[Bb][Ll]([0-9]{5,8})\b/g;
	if (!regExp.test(criteria)) return true;
	// Test keywords for a client-side redirect based on the format: bl12345[..8].
	location.href = "http://businessfinder."+ site +"/BL/Profile.aspx?adv="+ RegExp.$1;	return false;
}

/* 
Generic function for browser detection. 
Note: There is an SSF conflict with Microsoft's <!--[if IE 6]> detection method 
which makes it necessary to use the javascript-based detection method below
*/
function isBrowserOfType (appString) { 
	return (eval("navigator.userAgent.search(/"+ appString +"/gi)") > -1) ? true : false;
}

/* 
The code below uses mouseover/mouseout to switch the class of list items in level1 
to achieve the hover effect for IE6 only.
*/
if (isBrowserOfType("MSIE 6")) 
{		/* START: IE6 Hover */
	window.onload = function() {
	var sfEls = document.getElementById("level1").getElementsByTagName("LI");
	
	//hover for tabs except first and last buttons
	for (var i=1; i<11; i++) 
	{		//start 'for' loop
	
		//prevent hover on active tabs
		if (sfEls[i].className != "active")
		{
			sfEls[i].onmouseover = function() {
				if (this.className != " active") this.className+=" sfhover";
				}
			sfEls[i].onmouseout = function() {
				if (this.className != " active") this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
			}					
		}
	}	//end 'for' loop

	/** IMPORTANT: the id has to be removed for the hover to work  **/
	
	/* Only remove the id from the first button when its not active to prevent hovering if tab is active */
	if (sfEls[0].className != "active")
	{
		sfEls[0].id = null;
		sfEls[0].className = "level1_first_ie6";	
	}

	/* Only remove the id from the last button when its not active to prevent hovering if tab is active */
	if (sfEls[11].className != "active")
	{
		sfEls[11].id = null;
		sfEls[11].className = "level1_last_ie6";	
	}
		
	//To prevent hover when "Shopping" tab is active (note: it has no submenu, hence displayed differently)
	if (sfEls[10].className == "active_solo")
	{
		sfEls[10].onmouseover = null;
		sfEls[10].onmouseout = null;
	}
	
	/* Attach the hover function on the first button only if its NOT inherently active */
	if (sfEls[0].className != "active")
	{
		sfEls[0].onmouseover = function() 	{ this.className = "level1_first_ie6_hover";}
		sfEls[0].onmouseout = function() { 	this.className = "level1_first_ie6";}	
	}

	/* Attach the hover function on the last button only if its NOT inherently active */
	if (sfEls[11].className != "active")
	{
		sfEls[11].onmouseover = function() 	{ this.className = "level1_last_ie6_hover";}
		sfEls[11].onmouseout = function() { 	this.className = "level1_last_ie6"; }	
	}
	
	/* START: For First Button "Prior" Case (when adjacent tab is active) */
	if (sfEls[1].className == "active")
	{
		sfEls[0].className = "level1_first_ie6_prior";	
		sfEls[0].onmouseover = function() 	{ this.className = "level1_first_ie6_prior_hover";	}
		sfEls[0].onmouseout = function() { 	this.className = "level1_first_ie6_prior"; 	}	
	}
	/* END: For First Button "Prior" Case */		
	} //end of window.onload function
} /* END: IE6 Hover */
else if (isBrowserOfType("MSIE 7")) 
{	
	document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.nj.com/08design/toprail/css/toprail_ie7.css\" />");
}
else if (isBrowserOfType("mac|safari")) 
{	
	document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.nj.com/08design/toprail/css/toprail_mac.css\" />");	
	/* For Firefox 3.0 (has to come after mac detection */
	if (navigator.userAgent.search(/Mac(.*)?Firefox\/3/gi) > -1) 
	{	
		document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.nj.com/08design/toprail/css/toprail_mac_ff3.css\" />");
	}	
}



