//***********************************************************************
//	File: 			/js/_function.js
//	Description:	global javascript functions
//
//	Date		Author		Description
//
//
//***********************************************************************

//*************************************************************
//				PROTOTYPE FUNCTIONS START
//*************************************************************

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s*/,"").replace(/\s*$/,"");
}


// Setup the Prototypes
String.prototype.trim = trimString;  // Usage: [string].trim();

//*************************************************************
//				PROTOTYPE FUNCTIONS START
//*************************************************************


//*************************************************************
//				ARRAY FUNCTIONS START
//*************************************************************
function arrayInsert(arrayObj,insertVal,i){
	var tempArray = arrayObj;
	var newArray = new Array();

	if(arrayObj.length == undefined || arrayObj.length < 0){
		alert("Invalid array object.")
		return false;
	}
	
	if(!isNumeric(i) || isDecimal(i)){
		alert("Index " + i + " is not an integer.");
		return false;
	}
	
	if(i < 0){
		alert("An index that is 0 or greater is required.");
		return false;
	}
	
	if(i > arrayObj.length){
		alert("Your array has " + arrayObj.length + " elements.\r\nPlease enter a positive, zero-based index that is no greater than " + eval(arrayObj.length));
		return false;
	}
	
	tempArrayIndex = 0;
	for(j=0;j<=tempArray.length;j++){
		if(j==i){
			newArray[j] = insertVal;
		}
		else{
			newArray[j] = tempArray[tempArrayIndex];
			tempArrayIndex++;
		}
	}
	return newArray;
}

function arrayAppend(arrayObj,insertVal){
	var tempArray = arrayObj;
	var newArray = new Array();

	if(arrayObj.length == undefined || arrayObj.length < 0){
		alert("Invalid array object.")
		return false;
	}
	
	var i = arrayObj.length;
	tempArrayIndex = 0;
	for(j=0;j<=tempArray.length;j++){
		if(j==i){
			newArray[j] = insertVal;
		}
		else{
			newArray[j] = tempArray[tempArrayIndex];
			tempArrayIndex++;
		}
	}
	return newArray;
}

function arrayDelete(arrayObj,i){
	var tempArray = arrayObj;
	var newArray = new Array();

	if(arrayObj.length == undefined || arrayObj.length < 0){
		alert("Invalid array object.")
		return false;
	}
	
	if(!isNumeric(i) || isDecimal(i)){
		alert("Index " + i + " is not an integer.");
		return false;
	}
	
	if(i < 0){
		alert("An index that is 0 or greater is required.");
		return false;
	}
	
	if(i > arrayObj.length - 1){
		alert("Your array has " + arrayObj.length + " elements.\r\nPlease enter a positive, zero-based index that is no greater than " + eval(arrayObj.length - 1));
		return false;
	}

	tempArrayIndex = 0;
	for(j=0;j<tempArray.length;j++){
		if(j==i){
			// do nothing and skip value
		}
		else{
			newArray[tempArrayIndex] = tempArray[j];
			tempArrayIndex++;
		}
	}
	return newArray;
}
//*************************************************************
//				ARRAY FUNCTIONS END
//*************************************************************



//*************************************************************
//				STRING and NUMBER FUNCTIONS START
//*************************************************************
function replaceAll(str,char1,char2){
	str = str.replace(char1,char2);
	if(str.indexOf(char1) != -1){
		return replaceAll(str,char1,char2);
	}
	else{
		return str;
	}
}

// check value to see if it is numeric
function isNumeric(num){
	var i;
	num = num.toString();
	
	if(num == ""){
		return false;
	}

	if(num.charAt(0) == "-"){
		start = 1;
	}
	else{
		start = 0;
	}

	for(i=start;i<num.length;i++){
		if(num.charAt(i) < "0" && num.charAt(i) != "."){
			return false;
		}
		if(num.charAt(i) > "9" && num.charAt(i) != "."){
			return false;
		}
	}

	return true;
}

function isDecimal(num){
	//convert to a string
	num = num.toString();
	
	if(!isNumeric(num)){
		//not a number
		//alert("Not a number.");
		return false;
	}
	else if(num.indexOf(".") != -1){
		return true;
	}
	else{
		return false;
	}
}


//round numbers to specified dec places
function round (n, d) {
  n = n - 0; // force number
  if (d == null) d = 2;
  var f = Math.pow(10, d);
  n += Math.pow(10, - (d + 1)); // round first
  n = Math.round(n * f) / f;
  n += Math.pow(10, - (d + 1)); // and again
  n += ''; // force string
  return d == 0 ? n.substring(0, n.indexOf('.')) :
      n.substring(0, n.indexOf('.') + d + 1);
}


// ******************************************************************
// This function accepts a string variable and verifies if it is a
// proper date or not. It validates format matching either
// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
// has the proper number of days, based on which month it is.
// call function example as follows: isDate(this.value, 1) <!--- alan english:02/26/2004 --->
// The function returns true if a valid date, false if not.
// ******************************************************************

function isDate(dateStr,showAlert) {
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) {
		if(showAlert){
			alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		}
		return false;
	}
	
	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];
	
	if (month < 1 || month > 12) { // check month range
		if(showAlert){
			alert("Month must be between 1 and 12.");
		}
		return false;
	}
	
	if (day < 1 || day > 31) {
		if(showAlert){
			alert("Day must be between 1 and 31.");
		}
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		if(showAlert){
			alert("Month "+month+" doesn`t have 31 days!")
		}
		return false;
	}
	
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			if(showAlert){
				alert("February " + year + " doesn`t have " + day + " days!");
			}
			return false;
		}
	}
	return true; // date is valid
}

function isEmail(str){
	return true;
}

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s*/,"").replace(/\s*$/,"");
}

//*************************************************************
//				STRING and NUMBER FUNCTIONS END
//*************************************************************


//*************************************************************
//				FORM and DOCUMENT FUNCTIONS START
//*************************************************************
selectElementArray = document.getElementsByTagName('select');
selectState = 1; // visible

function hideSelect(bool) {
	/*alert(val);*/
	if(bool == true){
		for(i=0;i<selectElementArray.length;i++){
			if(selectElementArray[i].doHide == "1"){
				selectElementArray[i].style.visibility = 'hidden';
			}
		}
	}
	else if(bool == false){
		for(i=0;i<selectElementArray.length;i++){
			if(selectElementArray[i].doHide == "1"){
				selectElementArray[i].style.visibility = 'visible';
			}
		}
	}
}

function showDiv(div){
	if(div.style.visibility == "hidden"){
		div.style.visibility = "visible";
	}
	else{
		div.style.visibility = "hidden";
	}
}

function correctSize(width, height, inApp){	
	var isIE = false;

	if (self.innerWidth){
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth){
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body){
		isIE = true;
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else 
		return;

	var widthOffset = 0;
				
	// the app thinks there's scrollbars there
	if (isIE && inApp)
		widthOffset = -16;

	if (width != frameWidth || height != frameHeight){	
		parent.window.resizeBy((width - frameWidth + widthOffset), (height - frameHeight));
	}
}

function checkAll(chk){
	if(chk[0] != undefined){
		if(chk[0].checked == false){
			for(var i=0;i<chk.length;i++){
				chk[i].checked = true;
			}
		}
		else{
			for(var i=0;i<chk.length;i++){
				chk[i].checked = false;
			}
		}
	}
	else{
		chk.checked = !chk.checked;
	}
}

function clipText(txtField) {
	//var tempval = txtField;
	//tempval.focus();
	//tempval.select();
	if (document.all){
		therange=txtField.createTextRange();
		therange.execCommand("Copy");
	}
}

function pasteText(txtField) {
	//var tempval = txtField;
	//tempval.focus();
	//tempval.select();
	if (document.all){
		therange=txtField.createTextRange();
		therange.execCommand("Paste");
	}
}

function setCheckValue(obj,chk){
	var checkMe = false;
	if(chk.checked == true){
		checkMe = true;
	}
	for(i=0;i<obj.length;i++){
		obj[i].checked = false;
	}
	if(checkMe){
		chk.checked = true;
	}
}

function hiliteBox(txtField,bit){
	if(bit == 1){
		txtField.style.backgroundColor = '#FFEE00';
	}
	else if(bit == 0){
		txtField.style.backgroundColor = 'white';
	}
}

//uncomment 2 lines below to enable no right-click
//document.onmousedown = noRightClick;
//document.oncontextmenu = noContextMenu;
function noRightClick(e) {
	if (document.layers || document.getElementById && !document.all) {
		if (e.which == 2 || e.which == 3) {
			document.captureEvents(Event.MOUSEDOWN);
			return false;
		}
	} 
	else if (document.all && !document.getElementById) {
		if (event.button == 2)
		return false;
	}
}

function noContextMenu () {
	return false;
}

function disableRightClick(){
	document.onmousedown = noRightClick;
	document.oncontextmenu = noContextMenu;
}

//checks the length of the value of an object and compares it with the maximum length
//use with both onKeyPress and onKeyUp events
function charCounter(obj,maxCount,counterObj){
	if(obj.value.length > maxCount){
		alert("You may only enter up to " + maxCount + " characters in this field.");
		obj.value = obj.value.substr(0,maxCount);
		counterObj.value = maxCount - obj.value.length;
		return false;
	}
	counterObj.value = maxCount - obj.value.length;
}

// An onKeypress event function that will only allow numeric 
// input. All others are ignored. Note, this WILL not
// catch a copy/paste insert. Use the isNumeric
// function above to check for those.
function inputOnlyNumeric(iKeyCode) {
	// Check the ASCII equivalents
	if ((event.keyCode < 48) || (event.keyCode > 57)) 
		event.returnValue = false;
}
/******************************************************
noSubmit:
use: place in onKeyPress event for form text box fields
purpose: prevents Enter key from submitting form while focus is in text box field
ex.: <input type="text" name="txtField" onKeyPress="javascript: noSubmit();">
******************************************************/
function noSubmit(){
	if(event.keyCode == 13){
		event.cancelBubble = true;
		event.returnValue = false;
	}
}
/******************************************************
	getTextElements:
	use: helper function for noSubmit. function searches the
	form collection for all text elements and attaches the
	noSubmit function to the onkeydown event
	caveat: since page needs to be loaded, put the reference
	at the end of the form: however, putting js at the end of
	our file was recommended, so this func should not be a 
	problem.
******************************************************/
function getTextElements(){						
	//loop the form[s]
	for(t=0; t < document.forms.length; t++){
		var f = document.forms[t].elements;
		//loop the elements
		for(x=0; x < f.length; x++){
			var ele = f[x].type.toLowerCase();
			//attach the noSubmit function to onkeyup events for all text controls
			if(ele == "text"){
				var curId = document.getElementById(f[x].uniqueID);
				curId.attachEvent("onkeydown", noSubmit);
			}
		}
	}

}
document.onload = getTextElements();//init

/**********************************************************
	form2URL:
	Converts all form fields and values into a url string similar to that 
	which is passed using the GET method. This function is most useful for passing
	form data using the getHTTPRequest function. This function requires the
	form object itself as its only argument and returns the url string in the 
	following format:
	field1Name=field1Value&field2Name=field2Value&...
**********************************************************/
function form2URL(form){
	var urlString = "";
	var elementName = "";
	var elementValue = "";
	var valueList = "";
	
	//loop through form elements
	for(var i=0;i<form.length;i++){
		//set element name variable
		elementName = escape(form.elements[i].name);
		
		//check element type
		if(form.elements[i].type == "radio"){
			if(form.elements[i].checked){
				elementValue = escape(form.elements[i].value);
			}
			else{
				elementName = "";
				elementValue = "";
			}
		}
		else if(form.elements[i].type == "checkbox"){
			if(form.elements[i].checked){
				elementValue = escape(form.elements[i].value);
			}
			else{
				elementName = "";
				elementValue = "";
			}
		}
		else{
			elementValue = escape(form.elements[i].value);
		}
		
		if(elementName != ""){
			if(i == (form.length - 1)){ //last element in array so do not append "&"
				urlString = urlString + elementName + '=' + elementValue;
			}
			else{
				urlString = urlString + elementName + '=' + elementValue + '&';
			}
		}
		
		elementName = "";
		elementValue = "";
	}
	
	return urlString;
}

function getAbsLeft(obj) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = obj
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsTop(obj) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = obj
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}



  var elDragged = null  // Track current item.

  function doMouseMove() {
    // Check if mouse button is down and if an element is being dragged
    if ((1 == event.button) && (elDragged != null)) {
      // Move the element
      // Where the mouse is in the document
      var intTop = event.clientY + document.documentElement.scrollTop;
      var intLeft = event.clientX + document.documentElement.scrollLeft;
      // Calculate what element the mouse is really in
      var intLessTop  = 0; var intLessLeft = 0;
      var elCurrent = elDragged.offsetParent;
      while (elCurrent.offsetParent!=null) {
        intLessTop+=elCurrent.offsetTop;
        intLessLeft+=elCurrent.offsetLeft;
        elCurrent = elCurrent.offsetParent;
      }
     
      // Set new position
      elDragged.style.pixelTop = intTop  - intLessTop - elDragged.y;
      elDragged.style.pixelLeft = intLeft - intLessLeft  - elDragged.x;
      event.returnValue = false;
    };
  };

  function checkDrag(elCheck) {
    // Check if the clicked inside an element that supports dragging
    while (elCheck!=null) {
      if (null!=elCheck.getAttribute("dragEnabled")) 
        return elCheck
      elCheck = elCheck.parentElement
    }      
    return null
  }

  function doMouseDown() {
    // Store element on mousedown.  Called from click handler in code below .
    // All elements that have a "dragEnabled" attribute and are positioned
    // can be dragged.
    var elCurrent = checkDrag(event.srcElement)
    if (null!=elCurrent) {
        elDragged = elCurrent;
        // Determine where the mouse is in the element
        elDragged.x = event.offsetX
        elDragged.y = event.offsetY
        var op = event.srcElement
        // Find real location in respect to element being dragged.
        if ((elDragged!=op.offsetParent) && (elDragged!=event.srcElement)) {
          while (op!=elDragged) {
            elDragged.x+=op.offsetLeft
            elDragged.y+=op.offsetTop
            op=op.offsetParent
          }
        }
    }
  }

  function doSelectStart() {
    // Don't start text selections in dragged elements.
    return (null==checkDrag(event.srcElement) && (elDragged!=null))
  }
  
  function DragInit(){
	  // Process mousemove.
	  document.onmousedown = doMouseDown;
	  document.onmousemove = doMouseMove;
	  // Reset element on mouseup.
	  document.onmouseup = new Function("elDragged=null");
	  document.onselectstart = doSelectStart;
  }

//*************************************************************
//				FORM and DOCUMENT FUNCTIONS END
//*************************************************************



//*************************************************************
//					POPUP WINDOW FUNCTIONS START 
//*************************************************************
//Modal window  (always on top; retains focus)
function fnOpenModal(url,ht,wt,cntr,scrl,sts){
   ModalWind = window.showModalDialog(url, window, "dialogheight:" + ht + "px;dialogwidth:" + wt + "px;center:" + cntr + ";scroll:" + scrl + ";status:" + sts + ";help:no;edge:raised;")
   return ModalWind;
}

//Modeless window (always on top)
function fnOpenModeless(url,ht,wt,cntr,scrl,sts){
   ModelessWind = window.showModelessDialog(url, window, "dialogheight:" + ht + "px;dialogwidth:" + wt + "px;center:" + cntr + ";scroll:" + scrl + ";status:" + sts + ";help:no;edge:raised;")
   return ModelessWind;
}

var helpWindow = null;
function launchHelp(i){
	if(!helpWindow || helpWindow.closed){
		helpWindow = fnOpenModeless(webroot + "/help/help.cfm?helpID=" + i,500,350,0,0,0);
		helpWindow.dialogTop = 0;
		helpWindow.dialogLeft = screen.width - 350;
	}
	else{
		helpWindow.focus();
	}
}

function popup(HTMLContent,Xpos,Ypos,wt,ht) {
	var oPopup = window.createPopup();
    var oPopupBody = oPopup.document.body;
	oPopupBody.style.backgroundColor = "lightyellow";
	oPopupBody.style.border = "solid black 1px";    
    oPopupBody.innerHTML = HTMLContent;
    oPopup.show(Xpos, Ypos, wt, ht, document.body);
	
}

function popupSized(sTextMessage) {
// Bring up a Popup that is sized to the content provided

	var myPopup = window.createPopup();
	var myPopBody = myPopup.document.body;
	var myPopupDiv = document.createElement('DIV');
	var myPopupWidth = 0;
	var myPopupHeight = 0;
	var myPopupOffSet = 20;
	var myPopupXBuffer = 4;
	var myPopupYBuffer = 4;
	var modifiedtextMessage = new String(sTextMessage).replace(/ /gi,'&nbsp;');

	//Set Up Da' Pop Up
	with(myPopBody)
	{
		//General Appearance
		style.textAlign = 'center';
		style.verticalAlign = 'middle';
		style.backgroundColor = 'lightyellow';
		style.border = 'solid black 1px';
		//Font Settings
		style.fontFamily = 'Arial';
		style.fontWeight = 500;
		style.fontStyle = 'normal';
		style.fontSize = '8pt';
		style.color = '##004080';
	}

	//Determine Actual Width
	with(myPopupDiv)
	{
		id = 'myPopupDiv';
		style.position = 'absolute';
		style.visibility = 'hidden';
		style.fontFamily = myPopBody.style.fontFamily;
		style.fontWeight = myPopBody.style.fontWeight;
		style.fontSize = myPopBody.style.fontSize;
		style.fontStyle = myPopBody.style.fontStyle;
		innerHTML = modifiedtextMessage;
	}
	this.document.body.appendChild(myPopupDiv);

	//Display Da' Pop Up
	myPopupWidth = (myPopupDiv.clientWidth + myPopupXBuffer)
	myPopupHeight = (myPopupDiv.clientHeight + myPopupYBuffer);
	myPopBody.innerHTML = modifiedtextMessage;
	myPopup.show((window.event.x + myPopupOffSet), window.event.y, myPopupWidth, myPopupHeight, this.document.body);
}
//*************************************************************
//					POPUP WINDOW FUNCTIONS END
//*************************************************************



//*************************************************************
//					IMAGE FUNCTIONS START
//*************************************************************
function swapImage(imgObj,img1,img2){
	if(imgObj.src.indexOf(img1) > 0){
		imgObj.src = img2;
	}
	else{
		imgObj.src = img1;
	}
}

function swapImg(imgObj,img1){
	imgObj.src = img1;
}

//hides background image
function showBGImage(mBit){
	if(mBit == 1){
		document.body.style.backgroundImage = "url('/images/pageBG2.gif')";
	}
	else{
		document.body.style.backgroundImage = "";
	}
}

//hides buttons contained within a div tag called divButtons
function showButtons(mBit){
	if(mBit == 1){
		if(divButtons.length != undefined){
			for(var i = 0;i<divButtons.length;i++){
				divButtons[i].style.visibility = 'visible';
			}
		}
		else{
			divButtons.style.visibility = 'visible';
		}
	}
	else{
		if(divButtons.length != undefined){
			for(var i = 0;i<divButtons.length;i++){
				divButtons[i].style.visibility = 'hidden';
			}
		}
		else{
			divButtons.style.visibility = 'hidden';
		}
	}
}
//*************************************************************
//					IMAGE FUNCTIONS END
//*************************************************************





//*************************************************************
//					DISPLAY CLOCK START
//*************************************************************
var inactivityPeriod = 0;
function displayClock(expMin,userID){
	var now = new Date();
	var currHour = now.getHours();
	var currMin = now.getMinutes();
	var currSec = now.getSeconds();
	
	var monthArray = new Array();
	monthArray[0] = "Jan";
	monthArray[1] = "Feb";
	monthArray[2] = "Mar";
	monthArray[3] = "Apr";
	monthArray[4] = "May";
	monthArray[5] = "Jun";
	monthArray[6] = "Jul";
	monthArray[7] = "Aug";
	monthArray[8] = "Sep";
	monthArray[9] = "Oct";
	monthArray[10] = "Nov";
	monthArray[11] = "Dec";
	
	var dayArray = new Array();
	dayArray[0] = "Sun";
	dayArray[1] = "Mon";
	dayArray[2] = "Tue";
	dayArray[3] = "Wed";
	dayArray[4] = "Thu";
	dayArray[5] = "Fri";
	dayArray[6] = "Sat";
	
	var currDateStr = "";
	var currDay = dayArray[now.getDay()];
	var currMonthName = monthArray[now.getMonth()];
	
	currDateStr = currDay + " " + currMonthName + " " + now.getDate() + ", " + now.getYear();
	
	var displayTime = currDateStr + " " + (( currHour > 12) ? currHour - 12 : currHour);
	displayTime += ((currMin < 10) ? ":0" : ":") + currMin;
	displayTime += ((currSec < 10) ? ":0" : ":") + currSec;
	displayTime += ((currHour < 12) ? " AM" : " PM");
	
	clock.value = displayTime;
	
	inactivityPeriod += 1;
	if (inactivityPeriod >= expMin*60 && userID > 0){
		fnOpenModal('/loginPopup.cfm',200,300,1,0,0);
		setTimeout("displayClock(" + expMin + "," + userID + ")",1000);
	}
	else{
		setTimeout("displayClock(" + expMin + "," + userID + ")",1000);
	}
}

function sessionClock(expMin,userID){
	totalSecLeft = (expMin*60) - inactivityPeriod;
	if(totalSecLeft < 0){
		totalSecLeft = 0;
	}
	minLeft = parseInt(totalSecLeft/60);
	secLeft = totalSecLeft- parseInt(minLeft*60);
	
	spnSessionExpMin.innerHTML = minLeft;
	spnSessionExpSec.innerHTML = secLeft;
	setTimeout("sessionClock(" + expMin + "," + userID + ")",1000);
}


// display message if window is closed without saving. To use, put the following line incased in script tags
// after the footer of a page: 
// window.onbeforeunload = closeWarning;
// have a function on the page set the variable below, allowNavigate, to true if you do not want this message 
// to appear. A good place to set this variable is in the form validation function.

var allowNavigate = false;
var navWarning = "";
function closeWarning(){
	if(!allowNavigate){
		event.returnValue = navWarning;
	}
}

//*************************************************************
//					DISPLAY CLOCK END
//*************************************************************


//*************************************************************
//					suppress print dialog box
//*************************************************************
	// ====================================================================
	// Original post: Unkown person - I lost my notes on who did this first
	//                Unkown source
	// Modified by:   Walter Torres <walter@torres.ws> [www.torres.ws]
	//                4/29/2001
	//                I found the secret to remove the prompt!
	//                Original post did not have this gem to it.
	//
	// This accesses a built-in Windows command that can perform Magic!
	// and yes, this is a Windows ONLY solution.
	// In fact, it only works in IE. :(
	//
	//          INPUT: intOLEcmd   = integer between 1 and 37,only a few are of use
	//                 intOLEparam = parameter integer for function - optional
	//         OUTPUT: none
	//   DEPENDANCIES: none
	//
	//           NOTE: intOLEparam is not optional in the Object call,
	//                 I just made it optional here to make life easier.
	//                 All command values use '1' execept print, thus my reasoning.
	//
	//        EXAMPLE: // This prints given window/frame WITHOUT prompt!
	//                 <button onclick="objWinName.ieExecWB(6, -1)">
	//                    Print Me! - No Prompt!
	//                 </button>
	//
	//                 // This prints given window/frame WITH prompt!
	//                 <button onclick="objWinName.ieExecWB(6)">
	//                    Print Me! - Prompt
	//                 </button>
	//
	// 	               // This will display the Print Preview window
	//                 <button onclick="objWinName.ieExecWB(7)">
	//                    Print Preview
	//                 </button>
	//
	//         VALUES: intOLEcmd has these possible values
	//                 OLECMDID_OPEN         = 1
	//                 OLECMDID_NEW          = 2    warning, this kills IE windows!
	//                 OLECMDID_SAVE         = 3
	//                 OLECMDID_SAVEAS       = 4
	//                 OLECMDID_SAVECOPYAS   = 5    note: does nothing in IE
	//                 OLECMDID_PRINT        = 6    note: give '-1' as param - no prompt!
	//                 OLECMDID_PRINTPREVIEW = 7
	//                 OLECMDID_PAGESETUP    = 8
	//                          Others have no use in IE
	
	//************************************ does not work with ie modal and modeless dialog boxes **********
	
	function printNoDialog( intOLEcmd, intOLEparam ){
		// Create OLE Object
		var WebBrowser = '<OBJECT id="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	
		// Place Object on page
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	
		// if intOLEparam is not defined, set it
		if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || (intOLEparam > 1 ) )
			intOLEparam = 1;
	
		// Execute Object
		WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
	
		// Destroy Object
		WebBrowser1.outerHTML = "";
	}

//*************************************************************
//					XMLHTTPRequest Functions
//*************************************************************

function getHttpObject() {
// Function creates and returns a valid XMLHttpRequest object
// Will return false if the browser does not support it (IE 4 and below, NS 4 and below)
	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;
}

function postHttpRequest(sPage, fnCallBack, sContentString, bSync, oArgumentList) {
// Function posts an HTTPRequest and runs the callback
// use this function if the URL string is more than 256 characters.
	
	var oXHR = new getHttpObject();
		
	if (arguments[3] == 'undefined')
		bSync = true;

	oXHR.open("POST", sPage, bSync);

	if(navigator.userAgent.toLowerCase().indexOf("firefox") == -1){
		oXHR.onreadystatechange = function() {

			if (oXHR.readyState == 4) {
				oHttpRequest = oXHR;  // For backwards compatability with the oHttpRequest global var.
				// Serialize the callback and then pass it the arguments as well as the calling XHR object
				var fnArgCallBack = eval(fnCallBack);
				fnArgCallBack(oArgumentList,oXHR);
			}
		}
		// Make sure the header is set for a POST method form.
		oXHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

		// Send off the request.
		oXHR.send(sContentString);
		//oXHR = null;
	}
	else{
		// Make sure the header is set for a POST method form.
		oXHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

		// Send off the request.
		oXHR.send(sContentString);
		//oXHR = null;

		// When the request comes in, run callback function on what to do.
		oXHR.onreadystatechange = handleReadyStateChange(oXHR,fnCallBack,oArgumentList);
	
	}
	
}

function getHttpRequest(sPage, fnCallBack, bSync, oArgumentList) {
// Function sends an HTTPRequest and runs the callback with the sArgumentList
// sArgumentList is an object that is passed to the call back function.
// 	Use it to pass back any special values to the function 

	var oXHR = new getHttpObject();
	
	if (arguments[2] == 'undefined')
		bSync = true;
		
	oXHR.open("GET", sPage, bSync);

	if(navigator.userAgent.toLowerCase().indexOf("firefox") == -1){
		oXHR.onreadystatechange = function() {

			if (oXHR.readyState == 4) {
				oHttpRequest = oXHR;  // For backwards compatability with the oHttpRequest global var.
				// Serialize the callback and then pass it the arguments as well as the calling XHR object
				var fnArgCallBack = eval(fnCallBack);
				fnArgCallBack(oArgumentList,oXHR);
			}
		}
		oXHR.send(null);
	}
	else{
		oXHR.send(null);

		// When the request comes in, run callback function on what to do.
		oXHR.onreadystatechange = handleReadyStateChange(oXHR,fnCallBack,oArgumentList);
	
	}
	
	// Send off the request.
	//oXHR = null;
}

function handleReadyStateChange(oXHR,fnCallBack,oArgumentList){
	if (oXHR.readyState == 4) {
		
		oHttpRequest = oXHR;  // For backwards compatability with the oHttpRequest global var.
		// Serialize the callback and then pass it the arguments as well as the calling XHR object
		var fnArgCallBack = eval(fnCallBack);
		fnArgCallBack(oArgumentList,oXHR);
	}
}

//used with the above functions or any other operation where a return value of true and nothing else is required
function doNothing(){
	return true;
}

//used with above functions to debug output; send fnCallBack to the below funtion to output results in a separate window
function debugHttpRequest(){
	newWind = window.open("about:blank");
	newWind.document.write(oHttpRequest.responseText.trim());
}