var dom = (document.getElementById) ? true : false; 
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false; 
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false; 
var ns4 = (document.layers && !dom) ? true : false; 
var ie4 = (document.all && !dom) ? true : false; 

function state(id, dsply) {
  obj = document.getElementById(id);
  if (dsply=='hide') obj.style.visibility = 'hidden';
  if (dsply=='show') obj.style.visibility = 'visible';
  return;
}

function isIn(x, seq) {
// check to see if x is in seq
  l = seq.length; found = 0; i = 0;
  while ((found==0) && (i < l)) {
    if (seq[i] == x) found = 1;
    i++;
  }
  return found;
}

function printLine(str) {
// writes str to the position in the HTML file where 'printLine()' is called
// use this to write Active X content (object, embed, applet tags) as a workaround for the clicking required to activate an Active X control
  document.write(str);
}

function pageId(page_url) {
// return the id (folder) of the page in the url (without arguments or hashes or "index.html" etc.)
  var p_url = page_url;

  // test for trailing slash on url, remove it if it is present
  if (page_url.charAt(page_url.length-1)=="/") {
    p_url = page_url.substr(0, page_url.length-1);}

  var temp = p_url.split("/");
  var temp2;
  if (temp.length > 1) temp2 = temp[temp.length - 2];
  else temp2 = temp;
  temp = temp[temp.length - 1].split("#");
  temp = temp[temp.length - 1].split("?");
  temp = temp[temp.length - 1];

  // do not return "index.html" etc, return previous page id instead
  var test_for = new Array("index.html", "index_html", "index.php", "index.asp");
  if (isIn(temp, test_for)) return temp2;
  else return temp;
}

function getQuery(key_str) {
// return value of key_str variables query string of url
// Example: url = "index.html?alert=5&page=index"; if key_str = "alert" then getQuery('alert') returns "5"
  if(window.location.search) {
    var query = window.location.search.substr(1);
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
      var pair = pairs[i].split("=");
      if(unescape(pair[0]) == key_str) return unescape(pair[1]);
    }
  return null;
  }
}

function getObj(id) 
{ 
  if (dom) return document.getElementById(id);
  return (ns4) ? document.layers[id] : (ie4) ? document.all[id] : (ie5||ns5) ? document.getElementById(id) : null; 
}

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// remove array element if present, returns boolean
Array.prototype.reMove = function (element) {
	var result = false;
	var array = [];
	for (var i = 0; i < this.length; i++) {
		if (this[i] == element) {
			result = true;
		} else {
			array.push(this[i]);
		}
	}
	this.clear();
	for (var i = 0; i < array.length; i++) {
		this.push(array[i]);
	}
	array = null;
	return result;
};

// Array.splice() - Remove or replace several elements and return any deleted elements
if( typeof Array.prototype.splice==='undefined' ) {
 Array.prototype.splice = function( a, c ) {
  var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
  if( !c ) { c = l - a; }
  for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
  for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
  this.length -= c - e.length + 2;
  return d.slice( f, f + c );
 };
}

function showHTML(id, str) {
// display a string inside an HTML block element
  obj = getObj(id);
  obj.innerHTML = str;
  return;
}

function setState(id, dsply) {
  obj = getObj(id);
  if (dsply=='hide') obj.style.visibility = 'hidden';
  if (dsply=='show') obj.style.visibility = 'visible';
  return;
}

function setDisplay(id, dsply) {
  obj = getObj(id);
  if (dsply=='none') obj.style.display = 'none';
  if (dsply=='block') obj.style.display = 'block';
  return;
}

function rollOver(id) {
  var doc = window.document;
  var img_on = id + '_on', img_off = id  + '_off';
  img_off = doc.getElementById(img_on);
  img_on = doc.getElementById(img_on);
  img_off.style.display = 'none';
  img_on.style.display = 'block';
}

function rollOut(id) {
  var doc = window.document;
  var img_on = id + '_on', img_off = id  + '_off';
  img_off = doc.getElementById(img_on);
  img_on = doc.getElementById(img_on);
  img_off.style.display = 'block';
  img_on.style.display = 'none';
}

function isValidEmail() {
  var email = document.session.email.value;
  var AtPos = email.indexOf("@");
  var StopPos = email.lastIndexOf(".");
  if (email == "") return 0;
  if (AtPos == -1 || StopPos == -1) return 0;
  if (StopPos < AtPos) return 0;
  if (StopPos - AtPos == 1) return 0;
  return 1;
}

