   //----------------------------------------------------------------
function windowHeight() {
	// Standard browsers (Mozilla, Safari, etc.)
	if (self.innerHeight)
		return self.innerHeight;
	// IE 6
	if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	// IE 5
	if (document.body)
		return document.body.clientHeight;
	// Just in case. 
	return 0;
}

//----------------------------------------------------------------
function GetURLWithoutParams()
{
	var url = window.location.toString();
	return url.substring(0,url.search(/[\?#]/));
}

//----------------------------------------------------------------
function GetURLParameter( name )
//if a requested parameter doesn't exist in the query string then an empty string is returned instead of a null.
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//----------------------------------------------------------------
// e.g. 
// var list = GetALLURLParameters();
// for(var param in list)
//     document.write(param+" = "+list[param]+"<br/>");

function GetAllURLParameters() {
    // get the current URL
     var url = window.location.toString();
     //get the parameters
     url.match(/\?(.+)$/);
     var params = RegExp.$1;
     // split up the query string and store in an
     // associative array
     var params = params.split("&");
     var queryStringList = {};
     
     for(var i=0;i<params.length;i++)
     {
         var tmp = params[i].split("=");
         queryStringList[tmp[0]] = tmp[1];
     }
     
     return queryStringList;
}

//----------------------------------------------------------------
function changeText(id, txt){
	var textContent = document.getElementById(id)
	textContent.innerHTML= txt
}

//----------------------------------------------------------------
function appendText(id, txt){
	var textContent = document.getElementById(id)
	textContent.innerHTML += txt
}


//----------------------------------------------------------------
// Used with textareas that have a max amount of text
// field = textarea
// countfield = textbox containing number showing how many characters remain
// maxlimit = maximum number of characters allowed
// Include the following in the HTML for the textarea:
//  onKeyDown="textCounter(this.form.TEXTAREA_ID,this.form.COUNTFIELD_ID,MAXLIMIT);" 
//  onKeyUp="textCounter(this.form.TEXTAREA_ID,this.form.COUNTFIELD_ID,MAXLIMIT);" 
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}


//----------------------------------------------------------------
// Returns true if element denoted by string 'id' contains a valid date
function validateDate(id) {
	var fld = document.getElementById(id);
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    return ((fld.value.match(RegExPattern)) && (fld.value!=''));
}

//----------------------------------------------------------------
function Trim(s) {
	return s.replace(/^\s+|\s+$/g, "");
} 

//----------------------------------------------------------------
function LTrim(s) {
	return s.replace(/^\s+/, "");
} 

//----------------------------------------------------------------
function RTrim(s) {
	return s.replace(/\s+$/, "");
} 

//----------------------------------------------------------------
function removePunctuation(s) {
    return s.replace(/\W/g, " ");
}

//----------------------------------------------------------------
function getNextWord(s,n) {// s=string, n=locate within string to start looking
// returns next word after n
// e.g. "This is a test" n=1 -> "is"
	var i,l;
	var ws, retv;

    l = s.length;
    if (n>l) { return ""; }
    retv = "";
    ws = removePunctuation(s);
    // find next space, i.e. start of next word
    i = n; // start at n
    while (i < l && ws.substring(i,i+1) != " ") i++;
    // find next letter
	while (i < l && ws.substring(i,i+1) == " ") i++;
    // start adding to retv until getting to next space
    while (i < l && ws.substring(i,i+1) != " ") {
        retv += ws.substring(i,i+1); 
		i++;
	}
	return retv;
}

//----------------------------------------------------------------
function removeParam (bURL, param) {
   var result = bURL;
   var x = result.indexOf(param);
   if (x != -1) {
      var str1 = result.substring(x);
      var n = str1.indexOf('&');
      var str2 = "";
      if(n == -1) { str2=result.substring(0,x-1); } // remove last &
      else { str2 = result.substring(0,x) + result.substring(x+n+1); }
      result = str2;
    }
   return result;
}

//----------------------------------------------------------------
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return URLDecode(pair[1]);
		}
	} 
	return "";
}

//----------------------------------------------------------------
function URLDecode(encoded) {
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

   //----------------------------------------------------------------
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}
//----------------------------------------------------------------
function getElement(id){ return document.getElementById(id);}

//----------------------------------------------------------------
function gotoPage(href){window.location.href = href;}


