// Version 1.0.5 - 4/20/2009
// 09/11/2008 - added .toGMTString() to date in setCookie() cookie string for Safari
// 12/09/2008 - added dependent listbox and logging functions.  corrected FireFix bug in popup code.
// 04/05/2009 - added serial number to ajax calls to defeat caching
// 04/17/2009 - changed innerHTML to DOM object appendChild on popUp and iframePop
// 04/17/2009 - changed logIt function to dynamically add <div> for log content
// 04/20/2009 - added Head First Ajax functions

//determine browser type
var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isOp=self.opera?1:0;
var isDyn=isDOM||isIE||isNS4;
var serializeURLcallId = true;

/*** Positioning ***/
/**
 * returns the absolute top of any object
 * @param {Object} which - an Element
 * @return {Number} theTop
 */
function absoluteTop(which) {
	var theTop = 0;
	var mySelf = which;
	try {
		do {
			theTop += mySelf.offsetTop;
			mySelf = mySelf.parentElement;
		} while (mySelf.offsetTop);
	}
	catch (e) {}
	return theTop;
}

/**
 * returns the absolute left of any object
 * @param {Object} which - an Element
 * @return {Number} theLeft
 */
function absoluteLeft(which) {
	var theLeft = 0;
	var mySelf = which;
	try {
		do {
			theLeft += mySelf.offsetLeft;
			mySelf = mySelf.parentElement;
		} while (mySelf.offsetLeft);
	}
	catch (e) {}
	return theLeft
}

/*** IFrame support ***/
//writes header to iframe
function writeframeheader(myframe){
	document.frames(myframe).document.open();
	document.frames(myframe).document.writeln('<html>');
	document.frames(myframe).document.writeln('<head>');
	document.frames(myframe).document.writeln('<link href="stylesheets/theme.css" rel="stylesheet">');
	document.frames(myframe).document.writeln('<link href="stylesheets/color.css" rel="stylesheet">');
	document.frames(myframe).document.writeln('<script src="commonFunctions.js"></script>');
	document.frames(myframe).document.writeln('</head>');
	document.frames(myframe).document.writeln('<body class="mstheme">');
}

//writes footer to frame
function writeframefooter(myframe){
	document.frames(myframe).document.writeln('</body>');
	document.frames(myframe).document.writeln('</html>');
	document.frames(myframe).document.close();
}

/*** Location support ***/
// return the path portion of the current URL reference
function extractCurrentPath(aPathName) {
	var x1 = aPathName.lastIndexOf("\\");
	var x2 = aPathName.lastIndexOf("/");
	if (x1 == -1 && x2 == -1) {
		return aPathName;
	}
	else {
		if (x1 > x2) {
			return aPathName.substring(0, x1 + 1);
		}
		else {
			return aPathName.substring(0, x2 + 1);
		}
	}
}

/*** Object support ***/
/**
 * retrieve object by HTML id
 * @param {String} id
 * @return {Object} the Object
 */
function getObject(id) {
    if (document.getElementById != null) {
        return document.getElementById(id);
    }
    else if (document.all != null) {
        return document.all[id];
    } else {
        return null;
    }
}

/**
 * update the innerHTML of named object with passed value
 * @param {String} which - id of element
 * @param {String} passed
 */
function setInnerHtml(which, passed) {
    var element = getObject(which);
    element.innerHTML = passed;
}

/**
 * append to the innerHTML of named object with passed value
 * @param {String} which - id of element
 * @param {String} passed
 */
function addInnerHtml(which, passed) {
    var element = getObject(which);
    element.innerHTML = element.innerHTML + passed;
}

/*** Ajax Functions ***/
/**
 * Set object's HTML from url (sync)
 * @param {String} target - id of element
 * @param {String} url
 */
function ajaxSetObject(target, url) {
    element = getObject(target);
    if (element != null) {
        element.innerHTML = ajaxGet(url);
    }
}

/**
 * Append to an object's HTML from url (sync)
 * @param {String} target - id of element
 * @param {String} url
 */
function ajaxAddObject(target, url) {
    element = getObject(target);
    if (element != null) {
        element.innerHTML = element.innerHTML + ajaxGet(url);
    }
}

/**
 * Get the page request from a url (sync)
 * @param {String} url
 * @return {String} the html
 */
function ajaxGet(url) {
    var page_request = null;
	page_request = createRequest();
    if (page_request != null) {
        try {
	        page_request.open('GET', serializeURL(url), false); // false = synchronously
            page_request.send(null);
            //if (window.location.href.indexOf("http") == -1 || page_request.status == 200) {
            if (page_request.status == 0 || page_request.status == 200) {
                return page_request.responseText;
            }
            return "Error:  HTTP Status: " + page_request.status;
        } catch (e) {
			if (e.toString() == "[object Error]") {
	            return "Error:  This web page must be invoked from the server.";
			}
			else {
	            return "Error:  No page found or server not running.  " + e.toString();
			}
        }                    
    }
    return "Error:  No transport found in browser.";

}

/**
 * Asynchronous update/append of innerHTML using name of HTML object and url
 * @param {String} target - name of target HTML element
 * @param {String} url
 * @param {String} method - "add" to append, anything else to overwrite
 */
function updateInnerHtmlFromUrl(target, url, method) {
	var page_request = null;
	var element = null;
	element = getObject(target);
	if (element != null) {
		page_request = createRequest();
	}
	if (page_request != null) {
		try {
			page_request.onreadystatechange=function() {
				if (page_request.readyState==4) {
					if (page_request.status == 0 || page_request.status == 200) {
						if (method == "add") {
							element.innerHTML = element.innerHTML + page_request.responseText;
						}
						else {
							element.innerHTML = page_request.responseText;
						}
					}
					else {
						element.innerHTML = page_request.status;
					}
				}
			}
	      	page_request.open('GET', serializeURL(url), true); // true = asynchronously
           	page_request.send(null);
		} catch (e) {}                    
	}
}

/**
 * Serialize Url
 */
function serializeURL(passed) {
    if (serializeURLcallId) {
        if (passed.indexOf("?") > -1) {
            return passed + "&serializedURLcallId=" + Math.random();
        }
        else {
            return passed + "?serializedURLcallId=" + Math.random();
        }
    }
    else {
        return passed
    }
}

/*** date time functions ***/
var thisDate;
var thisTime;
/**
 * Updates the "thisDate" and "thisTime" strings
 */
function updateTime() {
    var toDay = new Date();
    var thisYear = toDay.getYear(); 
    if (thisYear < 1900) {
            thisYear = thisYear + 1900;
    }
    var thisMonth = toDay.getMonth() + 1;
    if (thisMonth < 10) {
            thisMonth = "0" + thisMonth;
    }
    var thisDay = toDay.getDate();
    if (thisDay < 10) {
            thisDay = "0" + thisDay;
    }
    thisDate = thisYear + "" + thisMonth + "" + thisDay; 
    var thisWeekday = toDay.getDay();
    var thisHour = toDay.getHours();
    if (thisHour < 10) {
            thisHour = "0" + thisHour;
    }
    var thisMinute = toDay.getMinutes();
    if (thisMinute < 10) {
            thisMinute = "0" + thisMinute;
    }
    var thisSecond = toDay.getSeconds();
    if (thisSecond < 10) {
            thisSecond = "0" + thisSecond;
    }
    var thisMillis = toDay.getMilliseconds();
    if (thisMillis < 10) {
            thisMillis = "00" + thisMillis;
    }
    else if (thisMillis < 100) {
            thisMillis = "0" + thisMillis;
    }
    thisTime = thisHour + "" + thisMinute + "" + thisSecond + "" + thisMillis;
}

/*** Cookie functions ***/
/**
 * Get a cookie
 * @param {String} sName
 */
function getCookie(sName) 
{
	var sCookie = " " + document.cookie;
	var sSearch = " " + sName + "=";
	var sStr = null;
	var iOffset = 0;
	var iEnd = 0;
	if (sCookie.length > 0) 
	{
		iOffset = sCookie.indexOf(sSearch);
		if (iOffset != -1) 
		{
			iOffset += sSearch.length;
			iEnd = sCookie.indexOf(";", iOffset)
			if (iEnd == -1) 
				iEnd = sCookie.length;
			sStr = unescape(sCookie.substring(iOffset, iEnd));
		}
	}
	return(sStr);
}

/**
 * Set a cookie
 * @param {String} sName
 * @param {String} sVal
 * @param {Number} iDays
 * @param {String} sPath
 * @param {String} sDomain
 * @param {Boolean} bSecure
 */
function setCookie(sName, sVal, iDays, sPath, sDomain, bSecure) 
{
	var sExpires = new Date();
	if (iDays)
	{	
		sExpires.setTime(sExpires.getTime()+(iDays*24*60*60*1000));
	}
	else {
		sExpires.setTime(sExpires.getTime()+1);
	}
	var workString = sName + "=" + escape(sVal) + ((sExpires) ? "; expires=" + sExpires.toGMTString() : "") + 
		((sPath) ? "; path=" + sPath : "") + ((sDomain) ? "; domain=" + sDomain : "") + ((bSecure) ? "; secure" : "");
	
	alert(workString);
	
	document.cookie = workString;
	
	if (document.cookie.length > 0)
		return true;
	return false;
}

/**
 * Get the pixels the user has the window scrolled right
 */
function getScrollLeft() {
	return (window.pageXOffset ? window.pageXOffset : (document.documentElement ? (document.documentElement.scrollLeft) : 0));
}

/**
 * Get the pixels the user has the window scrolled doen
 */
function getScrollTop() {
	return (window.pageYOffset ? window.pageYOffset : (document.documentElement ? (document.documentElement.scrollTop) : 0));
}

/*** popup functions ***/
/*
 * Put this commented stuff in your target HTML...
 */
/*
<style type="text/css">
	p.myPopUpObject {
		border-style: dashed;
		border-width: 1px;
		background-color: #EEFFFF;
		padding: 3px;
		color: #4444FF;
	}
</style> 
*/

var myPopUpObject;	
var myPopUpTimer;
var myPopUpDebug = true;
var myPopUpLastText;
var myPopUpLastObjectName;
var myPopUpLastEventClientX;
var myPopUpLastEventClientY;
var myPopUpLastLeftOffset;
var myPopUpLastTopOffset;
var myPopUpDelay = 500;

/**
 * Create a new popup.  Invoke from the "onmouseover" event
 * @param {String} theText
 * @param {String} theObjectName
 * @param {Event} theEvent
 */
function showPopUp(theText, theObjectName, theEvent) {
	showPopUp(theText, theObjectName, theEvent, 0);
}

/**
 * Create a new popup.  Invoke from the "onmouseover" event
 * @param {String} theText
 * @param {String} theObjectName
 * @param {Event} theEvent
 * @param {Number} theLeftOffset
 */
function showPopUp(theText, theObjectName, theEvent, theLeftOffset) {
	showPopUp(theText, theObjectName, theEvent, theLeftOffset, 0);
}

/**
 * Create a new popup.  Invoke from the "onmouseover" event
 * @param {String} theText
 * @param {String} theObjectName
 * @param {Event} theEvent
 * @param {Number} theLeftOffset
 * @param {Number} theTopOffset
 */
function showPopUp(theText, theObjectName, theEvent, theLeftOffset, theTopOffset) {
	if (!myPopUpObject) {
		// document.body.innerHTML += "<div id=\"myPopUpObject\" onmouseover=\"inPopUp();\" onmouseout=\"hidePopUp();\"></div>";
		myPopUpObject = document.createElement("div");
		myPopUpObject.id = "myPopUpObject";
		myPopUpObject.onmouseover = inPopUp;
		myPopUpObject.onmouseout = hidePopUp;
		document.body.appendChild(myPopUpObject);
		myPopUpObject.style.zIndex=999;
		myPopUpObject.style.display="none";
		myPopUpObject.style.position="absolute";
	}
	else {
		myPopUpObject = getObject("myPopUpObject");
	}
	clearTimeout(myPopUpTimer);
	myPopUpLastText = theText;
	myPopUpLastObjectName = theObjectName;
	myPopUpLastEventClientX = theEvent.clientX;
	myPopUpLastEventClientY = theEvent.clientY;
	myPopUpLastLeftOffset = theLeftOffset;
	myPopUpLastTopOffset = theTopOffset;
	// set delay for popup
	myPopUpTimer=setTimeout("showPopUpNow();", myPopUpDelay);
}

// show popup
function showPopUpNow() {
	try {
		window.clearTimeout(myPopUpTimer);
		// var theBody;
		// try {
		//     theBody = document.documentElement || document.body || (document.getElementsByTagName ? document.getElementsByTagName("body")[0] : null);
		// } catch (e) {}
		var windowWidth;
		try {
			windowWidth = document.body && (typeof(document.body.clientWidth) != "undefined") ? document.body.clientWidth : (typeof(window.innerWidth) != "undefined") ? window.innerWidth : document.body ? (document.body.clientWidth || 0) : 0
		} catch (e) {}
		var popUpWidth = 200;
		var scrollLeft = getScrollLeft();
		var scrollTop = getScrollTop();
		var theObject = getObject(myPopUpLastObjectName);
		// var theLeft = absoluteLeft(theObject);
		var theLeft = myPopUpLastEventClientX + scrollLeft;
		// var theTop = absoluteTop(theObject);
		var theTop = myPopUpLastEventClientY + scrollTop;
		var leftOffset = 20;
		var topOffset = 20;
		if (myPopUpLastLeftOffset) {
			leftOffset = myPopUpLastLeftOffset;
		}
		if (myPopUpLastTopOffset) {
			topOffset = myPopUpLastTopOffset;
		}
		if (isDOM && !isIE) {
			topOffset = topOffset - 15;
		}
		try {
			myPopUpObject.style.left = (theLeft + leftOffset) + "px";
			popUpWidth = windowWidth - (myPopUpLastEventClientX + leftOffset) - 10;
			if (popUpWidth > 640) {
				popUpWidth = 640;
			}
		} catch (e) {}
		try {
			myPopUpObject.style.top = (theTop + topOffset) + "px";
		} catch (e) {}
		var comment = "";
		// comments for debugging...
		if (myPopUpDebug) {
			comments = "<br><br>Left=" + theLeft + " &nbsp;&nbsp; Top=" + theTop + " &nbsp;&nbsp; LeftOffset=" + leftOffset + " &nbsp;&nbsp; TopOffset=" + topOffset;
			try {
				comments = comments + "<br>" + navigator.appName;
			} catch (e) {}
			comments = comments + "<br>" + "aX=" + absoluteLeft(theObject) + ", aY=" + absoluteTop(theObject);
			comments = comments + "<br>" + "cbX=" + (myPopUpLastEventClientX + scrollLeft) + ", cbY=" + (myPopUpLastEventClientY + scrollTop);
			comments = comments + "<br>" + "cX=" + myPopUpLastEventClientX + ", cY=" + myPopUpLastEventClientY;
			comments = comments + "<br>" + "bdX=" + scrollLeft + ", bdY=" + scrollTop;
			comments = comments + "<br>" + "pme=" + popUpWidth + ", wme=" + windowWidth;
			comments = comments + "<br>" + "wX1=" + document.body.clientWidth + ", wY1=" + document.body.clientHeight;
			comments = comments + "<br>" + "wX2=" + document.body.scrollWidth + ", wY1=" + document.body.scrollHeight;
		}
		var tempResult = "";
		// use this one without a style sheet
		// tempResult = "<p style=\"border-style: dashed; border-width: 1px; background-color: #EEFFFF; padding: 3px; color: #4444FF; width: " + popUpWidth + "px\">" + cleanUpPopUpField(myPopUpLastText) + comments + "</p>";
		// use this one with a style sheet
		tempResult = "<p class=\"myPopUpObject\" style=\"width: " + popUpWidth + "px\">" + cleanUpPopUpField(myPopUpLastText) + comments + "</p>";
		// alert(tempResult);
		myPopUpObject.innerHTML = tempResult;
		myPopUpObject.style.display = "block";
	}
	catch (e) {
		alert(e);
	}
}

/**
 * Hides the recently created popup.  Invoke from the "onmouseout" event.
 */
function hidePopUp(){
	window.clearTimeout(myPopUpTimer);
	// set delay for hide
	myPopUpTimer=window.setTimeout("outPopUp();", myPopUpDelay);
}

// keep popup
function inPopUp(){
	window.clearTimeout(myPopUpTimer);
}

// remove popup
function outPopUp(){
	myPopUpObject.style.display="none";
}

// clean up data
function cleanUpPopUpField(passed) {
        return passed.replace(/&/, "&amp;").replace(/>/, "&gt;").replace(/</, "&lt;");
}

/*** dependent listbox functions ***/
/**
 * Create a new Dependent List Box Handler
 * To use this handler, create the list box TEXT field with three columns, you choose
 * the delimiter.  The columns are (1) Text, (2) Parent Key, and (3) Child Key.  The
 * parent key of the child listbox must match the child key of the parent list box.
 * @param {String} mainName - name of main listbox
 * @param {String} mainDelim - delimiter for keys on the main listbox option text field
 * @param {String} childName - name of child list box
 * @param {String} childDelim - delimiter for keys on the child listbox option text field
 * @param {dependentListBoxHandler} childHandler - if the child list box has a dependent listbox, that handler
 */
function dependentListBoxHandler(mainName, mainDelim, childName, childDelim, childHandler) {
	this.mainKeys = new Array();
	this.mainParentKeys = new Array();
	this.mainTexts = new Array();
	this.mainValues = new Array();
	this.mainName = mainName;
	this.mainDelim = mainDelim;
	this.childKeys = new Array();
	this.childTexts = new Array();
	this.childValues = new Array();
	this.childName = childName;
	this.childDelim = childDelim;
	this.Load = dependentListBoxHandlerLoad;
	this.Change = dependentListBoxHandlerChange;
	try {
		this.childHandler = childHandler;
	} catch (e) {}
}

/**
 * Invoke to load a new Dependent List Box Handler
 */
function dependentListBoxHandlerLoad(){
	var aHandler = this;
	var theListBox;

	// edit and load main list box
	theListBox = document.getElementById(aHandler.mainName);
	for (var x = 0; x < theListBox.options.length; x++) {
		var theText = theListBox.options[x].text;
		aHandler.mainParentKeys[x] = theText.substring(theText.indexOf(aHandler.mainDelim) + aHandler.mainDelim.length, theText.lastIndexOf(aHandler.mainDelim));
		aHandler.mainKeys[x] = theText.substring(theText.lastIndexOf(aHandler.mainDelim) + aHandler.mainDelim.length);
		aHandler.mainTexts[x] = theText.substring(0, theText.indexOf(aHandler.mainDelim));
		aHandler.mainValues[x] = theListBox.options[x].value;
	}
	var saveIndex = theListBox.selectedIndex;
	for (var x = theListBox.options.length - 1; x > -1; x--) {
		theListBox.remove(x);
	}
	for (var x = 0; x < aHandler.mainKeys.length; x++) {
		var theOption = document.createElement('option');
		theOption.text = aHandler.mainTexts[x];
		theOption.value = aHandler.mainValues[x];
		try {
			theListBox.add(theOption, null);
		} 
		catch (e) {
			theListBox.add(theOption);
		}
	}
	theListBox.selectedIndex = saveIndex;
	
	theListBox = document.getElementById(aHandler.childName);
	if (aHandler.childHandler) {
		// load arrays from child
		aHandler.childKeys = aHandler.childHandler.mainParentKeys;
		aHandler.childTexts = aHandler.childHandler.mainTexts;
		aHandler.childValues = aHandler.childHandler.mainValues;
		for (var x = 0; x < aHandler.childKeys.length; x++) {
		}
	}
	else {
		// edit and reload child list box
		for (var x = 0; x < theListBox.options.length; x++) {
			var theText = theListBox.options[x].text;
			aHandler.childKeys[x] = theText.substring(theText.indexOf(aHandler.childDelim) + aHandler.childDelim.length, theText.lastIndexOf(aHandler.childDelim));
			aHandler.childTexts[x] = theText.substring(0, theText.indexOf(aHandler.childDelim));
			aHandler.childValues[x] = theListBox.options[x].value;
		}
	}
	aHandler.Change(true);
}

/**
 * Dependent List Box Change Handler
 * @param {Boolean} skip
 */
function dependentListBoxHandlerChange(skip) {
	var aHandler = this;
	var theListBox;
	theListBox = document.getElementById(aHandler.childName);
	var saveText = theListBox.options[theListBox.selectedIndex].text;
	var saveValue = theListBox.options[theListBox.selectedIndex].value;
	for (var x = theListBox.options.length - 1; x > -1; x--) {
		theListBox.remove(x);
	}
	var lookText = document.getElementById(aHandler.mainName).options[document.getElementById(aHandler.mainName).selectedIndex].text;
	var lookValue = document.getElementById(aHandler.mainName).options[document.getElementById(aHandler.mainName).selectedIndex].value;
	var theKey = "This is a string that I do not expect to ever find...";
	for (var x = 0; x < aHandler.mainKeys.length; x++) {
		if (aHandler.mainTexts[x] == lookText && aHandler.mainValues[x] == lookValue) {
			theKey = aHandler.mainKeys[x];
		}
	}
	for (var x = 0; x < aHandler.childKeys.length; x++) {
		if (theKey == aHandler.childKeys[x]) {
			var theOption = document.createElement('option');
			theOption.text = aHandler.childTexts[x];
			theOption.value = aHandler.childValues[x];
			try {
				theListBox.add(theOption, null);
			} 
			catch (e) {
				theListBox.add(theOption);
			}
		}
	}
	theListBox.selectedIndex = 0;
	for (var x = 0; x < theListBox.options.length; x++) {
		theOption = theListBox.options[x];
		if (theOption.text == saveText && theOption.value == saveValue) {
			theListBox.selectedIndex = x;
		}
	}
	try {
		if (!skip) {
			aHandler.childHandler.Change(skip);
		}
	} catch (e) {}
}

/**
 * Return the index into an array of a value/object
 * @param {Array} array
 * @param {Object} value
 * @return {Number}
 */
function getArrayIndexForValue(array, value) {
	for (var x = 0; x < array.length; x++) {
		if (value == array[x]) {
			return x;
		}
	}
	return -1;	
}

/**
 * Return the index of the listbox option with certain value
 * @param {ListBox} listBox
 * @param {String} value
 * @return {Number}
 */
function getListBoxIndexForValue(listBox, value) {
	for (var x = 0; x < listBox.options.length; x++) {
		theOptions = listBox.options[x];
		if (value == theOptions.value) {
			return x;
		}
	}
	return -1;
}

/**
 * Return the index of the listbox option with certain text
 * @param {ListBox} listBox
 * @param {String} text
 * @return {Number}
 */
function getListBoxIndexForText(listBox, text) {
	for (var x = 0; x < listBox.options.length; x++) {
		theOptions = listBox.options[x];
		if (text == theOptions.text) {
			return x;
		}
	}
	return -1;
}

/**
 * Return the listbox as a string
 * @param {ListBox} passed
 * @return {String}
 */
function dumpListBox(passed) {
	var content = "<br>";
	for (var x = 0; x < passed.options.length; x++) {
		theOptions = passed.options[x];
		content = content + "&nbsp;&nbsp;&nbsp;t:" + theOptions.text + " v:" + theOptions.value + " s:" + theOptions.selected + "<br>";
	}
	return content + "&nbsp;&nbsp;&nbsp;sv:" + passed.value + " si:" + passed.selectedIndex + " ol:" + passed.options.length;
}

/*** log functions ***/
var logItDivObject;

/**
 * Add log entry
 * @param {String} textToLog
 */
function logIt(textToLog) {
	if (!logItDivObject) {
		logItDivObject = document.createElement("div");
		logItDivObject.id = "logItDivObject";
		logItDivObject.style.textAlign = "left";
		document.body.appendChild(logItDivObject);
		logItDivObject.innerHTML = "<h3>Log</h3>" + textToLog;
	}
	else {
		logItDivObject.innerHTML = logItDivObject.innerHTML + "<br>" + textToLog;
	}
}

/*** popup iframe ***/
var iframePopUp;
function iframeDisplayURL(url, left, top, width, height){
	if (!iframePopUp) {
		// document.body.innerHTML += "<iframe id=\"iframePopUp\" style=\"z-Index: 998; display: none; position: absolute;\" src=\"" + url + "\"></iframe>";
		iframePopUp = document.createElement("iframe");
		iframePopUp.id = "iframePopUp";
		iframePopUp.src = url;
		iframePopUp.style.display="none";
		iframePopUp.style.position="absolute";
		iframePopUp.style.zIndex="998";
		document.body.appendChild(iframePopUp);
	}
	else {
		iframePopUp = getObject("iframePopUp");
	}
	iframePopUp.style.display="";
	iframePopUp.style.left=left+"px";
	iframePopUp.style.top=top+"px";
	iframePopUp.style.width=width+"px";
	iframePopUp.style.height=height+"px";
}
function iframeReturnValue(passed) {
	iframePopUp = getObject("iframePopUp");
	iframePopUp.style.display="none";
	alert(passed);
}

/*** Head First Ajax functions ***/
/**
 * Create request object
 */
function createRequest() {
  try {
    request = new XMLHttpRequest();
  } catch (tryMS) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (otherMS) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = null;
      }
    }
  }	
  return request;
}

/**
 * get object event handler fired upon
 * @param {Object} e
 */
function getActivatedObject(e) {
  var obj;
  if (!e) {
    // early version of IE
    obj = window.event.srcElement;
  } else if (e.srcElement) {
    // IE 7 or later
    obj = e.srcElement;
  } else {
    // DOM Level 2 browser
    obj = e.target;
  }
  return obj;
}

/**
 * Define Event Handler
 * @param {Object} obj
 * @param {Object} eventName
 * @param {Object} handler
 */
function addEventHandler(obj, eventName, handler) {
  if (document.attachEvent) {
    obj.attachEvent("on" + eventName, handler);
  }
  else if (document.addEventListener) {
    obj.addEventListener(eventName, handler, false);
  }
}

/**
 * Returns true if passed object is an array
 * @param {Object} arg
 */
function isArray(arg) {
	if (typeof arg == 'object') {
		try {
			var criteria = arg.constructor.toString().match(/array/i);
			return (criteria != null);
		} catch (e) {
			return false;
		}
	}
	return false;
}


