function get_object (objectname) {
	if (document.getElementById)							// for IE 5+
		x = document.getElementById(objectname);
	//else if (document.all)							// for IE 4
	//	x = document.all[objectname];
	else										// for Netscape
		x = document.layers[objectname];	
	return x;   
   }

function put_cursor (obj_id) {
	var x = get_object(obj_id);
	x.focus();
	}

function required_field (obj_id, emsg) {
	var x = get_object(obj_id);
	if (x.value == 0) {
		alert(emsg);
		return false;
		}
	else
		return true;
	}

function show_or_hide_object (objectname, visible) {
	x = get_object(objectname);
	if (visible)
		x.style.display='';
	else
		x.style.display='none';
   }

function set_item_color (objectname, color) {
	x = get_object(objectname);
	x.style.color = color;
	}
   
function show_array_item (arrayname, count, item) {
	for (i=1; i<=count; i++)
		show_or_hide_object(arrayname + i, (i == item));
   }

function set_array_item_color (arrayname, count, item, on_color, off_color) {
	for (i=1; i<=count; i++)
		set_item_color(arrayname + i, (i == item) ? on_color : off_color);
   }

function show_screen (theimage, newimage, itemno, count) {
	show_screen_path(theimage, 'screens/' + newimage + '.gif', itemno, count);
	}

function show_screen_path (theimage, newimagepath, itemno, count) {
	theimage.src = newimagepath;
	show_array_item('Desc', count, itemno);
	//set_array_item_color('Screen', count, itemno, 'red', 'black');
	}

// if we are in a frame, and the page requested has a bookmark (e.g., faq.html#appversion), make sure we are going to
// that bookmark. if not, reload the page with the bookmark at the end.
function check_hash () {
	if (parent.location.hash && (self.location.hash != parent.location.hash))	// have bookmark but not using?
		self.location.hash = parent.location.hash;				// make frame go to bookmark
	}

// if this page is being displayed not in a frame, go to the frame version of the page.
function check_frame (pagename) {
	if (window == top)								// not in a frame?
		if (top.location.protocol == "http:")
			top.location.href = pagename + parent.location.hash;		// go to the proper frame page
	}

function get_source () {
	var answer = "";
	if (document.cookie != "") {
		var url_string = get_cookie("url");
		var qindex = url_string.indexOf("?");
		if (qindex != -1) {
			var search_string = url_string.substr(qindex);
			if (search_string.length > 1)
				answer = get_variable(search_string.substr(1), "source");    // first skip over ?
			}
		}
	return answer;
	}

function get_referrer_domain () {
	var answer = "";
	if (document.cookie != "") {
		var referrer_string = get_cookie("referrer");
		if (referrer_string && (referrer_string.length > 7) && (referrer_string.substr(0, 7) == "http://")) {
			referrer_string = referrer_string.substr(7);
			var referrer_array = referrer_string.split("/");
			//alert("cookie is :" + document.cookie + ":");
			//alert("referrer is :" + referrer_string + ":");
			if (referrer_array.length > 0)
				answer = referrer_array[0];
			}
		}
	return answer;
	}
	
function get_variable (cstring, varname) {
	var vararray = cstring.split("&");
	for (var i=0; i<vararray.length; i++) {
		var onevar = vararray[i].split("=");
		if (onevar[0] == varname)
			return unescape(onevar[1]);
		}
	return null;
	}

function get_cookie (cname) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i<aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (cname == aCrumb[0]) 
			return unescape(aCrumb[1]);
		}
	return null;
	}

function save_referrer () {
	var mydomain = "http://" + self.location.hostname;
	var exp_date = new Date();

	exp_date = new Date(exp_date.getTime() + 86400000);			// 86400000 = 1 day

	if ((document.referrer != "") &&
	    (document.referrer.substring(0, mydomain.length) != mydomain) &&
	    (document.cookie.indexOf("referrer") == -1)) {
		document.cookie = "referrer=" + escape(document.referrer) + "; expires=" + exp_date.toGMTString() + "; path=/;";
		document.cookie = "url=" + escape(document.URL) + "; expires=" + exp_date.toGMTString() + "; path=/;";
		}

	document.cookie = "url=" + escape(document.URL) + "; expires=" + exp_date.toGMTString() + "; path=/;";
	}
