var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
var ns = (navigator.appName.indexOf('Netscape')>-1);
var scnt = 0;
var suggestCount = -1;
var sugVisible = false;
var lastSuggest = "";

if (document.images) {
	 checkbox_checked = new Image;
	 checkbox_unchecked = new Image;
	 
	 checkbox_checked = '/images/checkboxchecked.gif';
	 checkbox_unchecked = '/images/checkboxunchecked.gif';
 }
 
function hilite(id) {
	document.getElementById('menu'+id).style.backgroundImage = "url(/images/1x23-menu-bar-light.jpg)";
}
function unhilite(id) {
	document.getElementById('menu'+id).style.backgroundImage = "url(/images/1x23-menu-bar.jpg)";
}

function clearSearchBox()
{	
	if (document.getElementById("search1").value == 'Search') {
		document.getElementById("search1").value = ''
		document.getElementById("search1").style.color = "#3f4147";
		document.getElementById("search1").style.fontWeight = "normal";
	}
	if (document.getElementById("search1").value.length > 1){document.getElementById("suggestions").style.visibility = "visible";}
	return true;
}

function checkSearchBox() {
	if (document.getElementById("search1").value == '') {
		document.getElementById("search1").style.color = "#ae0f21";
		document.getElementById("search1").style.fontWeight = "bold";
		document.getElementById("search1").value = 'Search';
	}
}
function checkSuggest() {
	if(suggestCount >=0) {return false;}
}

function hideSuggestions() {
	document.getElementById("suggestions").style.visibility = "hidden";
}
function myEncode(str) {
	str = escape(str);
	str = str.replace('%','%*');
    return str;
}
function getSuggestions(str,keycode) {
	str = myEncode(document.getElementById("search1").value);
	if (keycode == 40 && sugVisible) {
		suggestCount++;
		if(document.getElementById("sug"+suggestCount)) {
			document.getElementById("sug"+suggestCount).style.backgroundColor="#ae0f21";
			document.getElementById("sug"+suggestCount).style.color="white";
			if(document.getElementById("sug"+(suggestCount-1))) {
				document.getElementById("sug"+(suggestCount-1)).style.backgroundColor="#ffffff";
				document.getElementById("sug"+(suggestCount-1)).style.color="#3f4147";
			}
		} else {suggestCount--;}
		return;
	}
	if (keycode == 38 && sugVisible) {
		if(document.getElementById("sug"+suggestCount)) {
			document.getElementById("sug"+suggestCount).style.backgroundColor="#ffffff";
			document.getElementById("sug"+suggestCount).style.color="#3f4147";
		}
		if (suggestCount >= 0) {
			suggestCount--;
			if(document.getElementById("sug"+suggestCount)) {
				document.getElementById("sug"+suggestCount).style.backgroundColor="#ae0f21";
				document.getElementById("sug"+suggestCount).style.color="#ffffff";
			} 
		}
		return;
	}
	if (keycode == 13 && suggestCount >=0) {
//		alert(document.getElementById("sug"+suggestCount).href);
		window.location=document.getElementById("sug"+suggestCount).href;
		return false;
	}
	if(str.length > 6) {
		if (str.substr(0,6) == 'Search') {
			str = str.substring(6);document.getElementById("search1").value = str;
			document.getElementById("search1").style.color = "#3f4147";
			document.getElementById("search1").style.fontWeight = "normal";
		}
	}
	if(str.length < 2) {
		// hide the suggestions area
		document.getElementById("suggestions").style.visibility = "hidden";
		suggestCount = -1;
	} else {
		scnt = 0;
		suggestDelay(str);
	}				
}

function suggestDelay(str) {
	scnt++;
	if (scnt < 10) {setTimeout("suggestDelay('" + str + "');",50);}
	if (scnt >= 10 && str == myEncode(document.getElementById("search1").value)) {getSuggestion();}
}

function getSuggestion() {
	var thisSuggest = myEncode(document.getElementById("search1").value);
	if (thisSuggest != lastSuggest && thisSuggest.length >= 2){
		lastSuggest = thisSuggest;
		xmlHttp = GetXmlHttpObject();
		xmlHttp.onreadystatechange = showSuggestion;
		var suggestURL = "/suggest.asp?q="+thisSuggest;
		xmlHttp.open("GET", suggestURL, true);		
		xmlHttp.send(null)
	}	
}	

function goSearch() {
	if(suggestCount < 0 && document.getElementById("search1").value != 'Search') {
		window.location.assign("/search_results.asp?kw2="+document.getElementById("search1").value);
	}
	if(suggestCount >= 0) {
		window.location=document.getElementById("sug"+suggestCount).href;
	}
}	

var searchPos;
	// called when xmlHttp object changes state
function showSuggestion() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		// query has returned
		if (xmlHttp.responseText != "-") {	
			searchPos = findPos(document.getElementById("search1"));
			document.getElementById("suggestions").style.left = searchPos[0]+"px";
			document.getElementById("suggestions").innerHTML=xmlHttp.responseText;
			document.getElementById("suggestions").style.visibility = "visible";
			
			sugVisible = true;
		}
		else
		{
			document.getElementById("suggestions").style.visibility = "hidden";
			sugVisible = false;
			suggestCount = -1;
		}	
	} 
} 
		
// wrapper to create an xmlHttp object cross-browser
function GetXmlHttpObject(handler) { 
	var objXMLHttp = null;
	
	if (window.XMLHttpRequest) {
		// we're in mozilla
		objXMLHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// we're in IE
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function initAltText() {
//	the following code is to support the alt text
	navtxt=(NS4)? document.layers['navtxt'] : (IE4)? document.all['navtxt'] : (W3C)? document.getElementById('navtxt') : null;
	getboxwidth();
	getboxheight();
	getwindowdims();
	isloaded=true;
	if((W3C || IE4) && centertext)navtxt.style.textAlign="center";
//	if(W3C)navtxt.style.padding='4px';
	if(IE4 || IE5 && dofade)navtxt.style.filter="alpha(opacity=0)";

}

function initSearch() {
	document.getElementById("search1").value = 'Search';
	document.getElementById("search1").style.color = "#ae0f21";
	document.getElementById("search1").style.fontWeight = "bold";
}

function checkbox(cbid) {
	if (document.getElementById(cbid).value == "on") {
		document.getElementById("cbimg_"+cbid).src = checkbox_unchecked;
		document.getElementById("cbstr_"+cbid).style.fontWeight = "normal";
		document.getElementById(cbid).value = "";
	} else {
		document.getElementById("cbimg_"+cbid).src = checkbox_checked;
		document.getElementById("cbstr_"+cbid).style.fontWeight = "bold";
		document.getElementById(cbid).value = "on";
	}
}
	
function setCookie(name,value,expires,path,domain,secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*	if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24 */
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function getCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
				
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )	{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  ALTTXT V1.2
//  BY: BRIAN GOSSELIN OF SCRIPTASYLUM.COM
//  ADDED FADING EFFECT FOR IE4+ AND NS6+ ONLY AND OPTIMIZED THE CODE A BIT.
//  SCRIPT FEATURED ON DYNAMIC DRIVE (http://www.dynamicdrive.com)
//  Modifed by DD for doctype bug on Nov 13th, 2003


var dofade=true;     // ENABLES FADE-IN EFFECT FOR IE4+ AND NS6 ONLY
var center=false;     // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE
var centertext=false; // CENTERS THE TEXT INSIDE THE BOX. YOU CAN'T SIMPLY DO THIS VIA STYLE BECAUSE OF NS4.
                     // OTHERWISE, TEXT IS LEFT-JUSTIFIED. 


////////////////////////////// NO NEED TO EDIT BEYOND THIS POINT //////////////////////////////////////

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var IE6 = (ie && (typeof document.body.style.maxHeight == "undefined") && (typeof document.body.filters == 'object')) ? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;
var w_y, w_x, navtxt, boxheight, boxwidth, mx, my, mabsx, mabsy;
var ishover=false;
var isloaded=false;
var ieop=0;
var op_id=0;
function getwindowdims(){
w_y=(NS4||NS6||window.opera)? window.innerHeight : (IE5||IE4)? document.body.clientHeight : 0;
w_x=(NS4||NS6||window.opera)? window.innerWidth : (IE5||IE4)? document.body.clientWidth : 0;
if (typeof adjustImages != 'undefined'){adjustImages();}
}

function getboxwidth(){
if(NS4)boxwidth=(navtxt.document.width)? navtxt.document.width : navtxt.clip.width;
if(IE5||IE4)boxwidth=(navtxt.style.pixelWidth)? navtxt.style.pixelWidth : navtxt.offsetWidth;
if(NS6)boxwidth=(navtxt.style.width)? parseInt(navtxt.style.width) : parseInt(navtxt.offsetWidth);
}

function getboxheight(){
if(NS4)boxheight=(navtxt.document.height)? navtxt.document.height : navtxt.clip.height;
if(IE4||IE5)boxheight=(navtxt.style.pixelHeight)? navtxt.style.pixelHeight : navtxt.offsetHeight;
if(NS6)boxheight=parseInt(navtxt.offsetHeight);

}

function movenavtxt(x,y){
if(NS4)navtxt.moveTo(x,y);
if(W3C||IE4){
navtxt.style.left=x+'px';
navtxt.style.top=y+'px';
}}

function getpagescrolly(){
if(NS4||NS6)return window.pageYOffset;
if(IE5||IE4)return ietruebody().scrollTop;
}

function getpagescrollx(){
if(NS4||NS6)return window.pageXOffset;
if(IE5||IE4)return ietruebody().scrollLeft;
}

function writeindiv(text){
if(NS4){
navtxt.document.open();
navtxt.document.write(text);
navtxt.document.close();
}
if(W3C||IE4)navtxt.innerHTML=text;
}

//**** END UTILITY FUNCTIONS ****//

function writetxt(text,imgid){
if(document.getElementById(imgid)) {document.getElementById(imgid).alt="";}
if(isloaded){
if(text!=0){
ishover=true;
if(NS4)text='<div class="navtext">'+((centertext)?'<center>':'')+text+((centertext)?'</center>':'')+'</div>';
writeindiv(text);
getboxheight();
if((W3C || IE4) && dofade){
ieop=0;
incropacity();
}}else{
if(NS4)navtxt.visibility="hide";
if(IE4||W3C){
if(dofade)clearTimeout(op_id);
navtxt.style.visibility="hidden";
}
writeindiv('');
ishover=false;
}}}

function incropacity(){
if(ieop<=100){
ieop+=10;
if(IE4 || IE5) {navtxt.style.filter="alpha(opacity="+ieop+")";}
if(NS6) {navtxt.style.MozOpacity=ieop/100;}
op_id=setTimeout('incropacity()', 50);
}}



if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;
window.onresize=getwindowdims;

function moveobj(evt){
	if (NS4){
		mx=evt.pageX
		my=evt.pageY
	}
	else if (NS6){
		mx=evt.clientX
		my=evt.clientY
	}
	else if (IE5){
		mx=event.clientX
		my=event.clientY
	}
	else if (IE4){
		mx=0
		my=0
	}

	if(NS4){
		mx-=getpagescrollx();
		my-=getpagescrolly();
	}

	if(isloaded && ishover){
		margin=(IE4||IE5)? 1 : 23;
		if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
		if(NS4)if(document.height-window.innerHeight<0)margin=10;

		xoff=(center)? mx-boxwidth/2 : mx+5;
//		yoff=(my+boxheight+30-getpagescrolly()+margin>=w_y)? -15-boxheight: 30;
		yoff=(my+boxheight+25-getpagescrolly()+margin>=w_y)? -5-boxheight: 25;		
		movenavtxt( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getpagescrollx() , my+yoff+getpagescrolly());
		if(NS4)navtxt.visibility="show";
		if(W3C||IE4) {navtxt.style.visibility="visible";}
	}  
	
}

function whyBuy() {
	if(typeof whyBuyWindow == "object") {if (!whyBuyWindow.closed) {whyBuyWindow.close();}}
	whyBuyWindow = window.open("/whyBuy.asp","whybuy","toolbar=0,menubar=0,scrollbars=1,width=762px,height=1505px");
}

function showArticle(anum){
	if(typeof articleWindow == "object") {if (!articleWindow.closed) {articleWindow.close();}}
	articleWindow = window.open("/articleWindow.asp?a="+anum,"article"+anum,"toolbar=0,menubar=0,scrollbars=1,width=774px,height=1505px");
	return false;
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {
	return window.innerWidth != null?window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 

function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop() {
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight() {
	return posLeft()+pageWidth();
} 

function posBottom() {
	return posTop()+pageHeight();
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
                    