function bookmark( title, url ) {
	if ( ( navigator.appName == 'Microsoft Internet Explorer' ) && ( parseInt( navigator.appVersion ) >= 4 ) ) {
		window.external.AddFavorite( url, title );
	} else if ( navigator.appName == 'Netscape' ) {
		window.sidebar.addPanel( title, url,'' );
	}/* else {
		alert( 'Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark' );
	}*/
}

function imageSource( obj, newsrc ) {
	document.getElementById( obj ).src = newsrc;
}

function preloadImages( img ) {
	if ( document.images ) {
		preload_image_object = new Array();
		/*// set image url
		image_url = new Array();
		image_url[0] = "http://mydomain.com/image0.gif";
		image_url[1] = "http://mydomain.com/image1.gif";
		image_url[2] = "http://mydomain.com/image2.gif";
		image_url[3] = "http://mydomain.com/image3.gif";*/
		var i;
		for ( i in img ) {
			preload_image_object[i] = new Image()
			preload_image_object[i].src = img[i];
		}
	}
}

function textsize( size ) {
	if ( size == 2 ) {
		size = '12pt';
		lineheight = 'normal';
	} else if ( size == 3 ) {
		size = '14pt';
		lineheight = 'normal';
	} else {
		size = '8pt';
		lineheight = '14pt';
	}
	document.getElementById( 'content' ).style.fontSize = size;
	document.getElementById( 'content' ).style.lineHeight = lineheight;
	var today = new Date();
	today.setTime( today.getTime() );
	var expiredate = new Date( today.getTime() + 1000 * 60 * 60 * 24 * 30 ); // 30 days from now, in milliseconds
	document.cookie = 'textsize=' + size + ';expires=' + expiredate.toGMTString() + ';path=/';
}

function toggleDisplay( obj_id ) {
	var obj = document.getElementById( obj_id );
	if ( document.getElementById( obj_id ).style.display == 'none' ) {
		document.getElementById( obj_id ).style.display = 'block';
		return true;
	} else {
		document.getElementById( obj_id ).style.display = 'none';
		return false;
	}
}

/* FP Headlines Box funcs */
headlineto = null;
autorotate = 0;
function autoRotateHeadline() {
	imageSource( 'headline_p', '/files/gfx/fp/headline_p_h.gif' );
	imageSource( 'headline_s', '/files/gfx/fp/headline_s.gif' );
	headlineto = window.setTimeout( 'autoRotateHeadline();rotateHeadline(2);', 15000 );
	autorotate = 1;
}

var curhead = 1;
function headline( div ) {
	if ( div > 4 ) {
		div -= 4;
	} else {
		pauseRotateHeadline();
	}
	document.getElementById( 'head_' + curhead ).style.display = 'none';
	document.getElementById( 'lhead_' + curhead ).style.fontWeight = 'normal';
	document.getElementById( 'thumb_' + curhead ).style.borderBottomColor = '#CCCCCC';
	curhead = div;
	document.getElementById( 'head_' + div ).style.display = 'block';
	document.getElementById( 'lhead_' + div ).style.fontWeight = 'bold';
	document.getElementById( 'thumb_' + div ).style.borderBottomColor = '#800000';
}

function pauseRotateHeadline() {
	window.clearTimeout( headlineto );
	autorotate = 0;
	imageSource( 'headline_s', '/files/gfx/fp/headline_s_h.gif' );
	imageSource( 'headline_p', '/files/gfx/fp/headline_p.gif' );
}

function resumeRotateHeadline() {
	if ( autorotate != 1 ) { // prevent this function from recurring too often if a user clicks "play" several times
		autoRotateHeadline();
	}
}

function rotateHeadline( dir ) {
	/*if ( curhead == 1 && dir == -1 ) {
		div = 4;
	} else if ( curhead == 4 && dir == 1 ) {
		div = 1;
	} else {
		div = curhead + dir;
	}
	headline( div );*/
	var add4 = 0;
	if ( dir == 2 ) {
		dir = 1;
		add4 = 4;
	} else {
		pauseRotateHeadline();
	}
	if ( curhead == 1 && dir == -1 ) {
		div = 4 + add4;
	} else if ( curhead == 4 && dir == 1 ) {
		div = 1 + add4;
	} else {
		div = curhead + dir + add4;
	}
	headline( div );
	/*document.getElementById( 'head_' + curhead ).style.display = 'none';
	document.getElementById( 'lhead_' + curhead ).style.fontSize = '7pt';
	if ( curhead == 1 && dir == -1 ) {
		curhead = 4;
	} else if ( curhead == 4 && dir == 1 ) {
		curhead = 1;
	} else {
		curhead = curhead + dir;
	}
	document.getElementById( 'head_' + curhead ).style.display = 'block';
	document.getElementById( 'lhead_' + curhead ).style.fontSize = '8pt';*/
}
/* End of FP Headlines Box funcs */

// AJAX functions
var obj = '';

function handleHttpResponse() {
	if ( http.readyState == 4 ) {
		results = http.responseText;
		document.getElementById( obj ).innerHTML = results;
	}
}

function loadPage( url, obj_id ) {
	obj = obj_id;
	http.open( "GET", url, true );
	http.onreadystatechange = handleHttpResponse;
	http.send( null );
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
// End of AJAX functions

//AJAX search box
var prevq;
var toid;
var toid2;
var updateto = 0;
function hideSearchBox( func ) {
	window.clearTimeout( toid );
	if ( func == 1 ) {
		/*if (!e) var e = window.Event;
		var tg = (window.Event) ? e.srcElement : e.target;
		if (tg.nodeName != 'DIV') return;
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		while (reltg != tg && reltg.nodeName != 'BODY')
			reltg= reltg.parentNode
		if (reltg== tg) return;*/
		toid = window.setTimeout( "hideSearchBox(2);", 1500 );
	} else if ( func == 2 ) {
		document.getElementById( 'searchresults' ).style.display = 'none';
	}
}

function showSearchBox() {
	window.clearTimeout( toid );
	document.getElementById( 'searchresults' ).style.display = 'block';
}

function updateQuickSearch( func ) {
	delay = 500; // gives some delay so it's not constantly querying, and only updates when the user pauses typing

	searchq = document.getElementById( 'q' ).value;
	if ( prevq == searchq ) { return; } // if the user has hit an arrow key or otherwise not changed the value, don't update the search results box

	sr = document.getElementById( 'searchresults' );
	if ( !updateto ) {
		sr.innerHTML = '<img src="/files/gfx/icon_loading.gif" width="16" height="16" alt="Loading..." style="float:right">';
	} // Adds a 'loading' icon to the search results box when it's loading results

	if ( func == 1 ) {
		window.clearTimeout( toid2 );
		toid2 = window.setTimeout( "updateQuickSearch(2);", delay );
		updateto = 1;
		return;
	} else if ( func == 2 ) {
		window.clearTimeout( toid2 );
		updateto = 0;
	}

	window.clearTimeout( toid );
	if ( !searchq ) {
		sr.innerHTML = '';
		hideSearchBox( 2 );
		return;
	}
	prevq = searchq; // remembers what the user typed for use above, to see if anything has changed
	loadPage( '/search?quicksearch=1&q=' + encodeURI( searchq ), 'searchresults' );
	showSearchBox();
}
//End of AJAX search box

//Chat Now box
function submitChatNow() {
	document.getElementById( 'chatnow_submit' ).innerHTML = '<img src="/files/gfx/icon_loading.gif" width="16" height="16" border="0" alt="Loading...">';
	chatnow_name_val = encodeURI( document.getElementById( 'chatnow_name' ).value );
	chatnow_phone_val = encodeURI( document.getElementById( 'chatnow_phone' ).value );
	loadPage( '/chatnow?chatnow_mode=submit&chatnow_name=' + chatnow_name_val + '&chatnow_phone=' + chatnow_phone_val, 'chatnow2' );
}
//End of Chat Now box