var dateXM = {}
var isBrowserIE = (navigator.appName.indexOf("Microsoft") > -1);
var dispTRTag = (isBrowserIE)?"block":"table-row";

/*	EventCache Version 1.0
	Copyright 2005 Mark Wubben

	Provides a way for automagically removing events from nodes and thus preventing memory leakage.
	See <http://novemberborn.net/javascript/event-cache> for more information.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

/*	Implement array.push for browsers which don't support it natively.
	Please remove this if it's already in other code */
if(Array.prototype.push == null){
	Array.prototype.push = function(){
		for(var i = 0; i < arguments.length; i++){
			this[this.length] = arguments[i];
		};
		return this.length;
	};
};

/*	Event Cache uses an anonymous function to create a hidden scope chain.
	This is to prevent scoping issues. */
var EventCache = function(){
	var listEvents = [];
	
	return {
		listEvents : listEvents,
	
		add : function(node, sEventName, fHandler, bCapture){
			listEvents.push(arguments);
		},
	
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				
				/* From this point on we need the event names to be prefixed with 'on" */
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				
				item[0][item[1]] = null;
			};
		}
	};
}();

function addEvent(obj, evType, fn, useCapture){
	if (!obj) return;
    var result;
	if (typeof(useCapture) == "undefined") useCapture = false;
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, useCapture);
        result = true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        result = r;
    } else {
        return false;
    }
    EventCache.add(obj, evType, fn, useCapture);
    return result;
}
addEvent(window, "unload", EventCache.flush);

function $(id) {
	return document.getElementById(id);	
}

function $xm(id) {
	return document.getElementById(id);	
}

function GetFormObj(form,id) {
	return document.forms[form][id];	
}


var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
};

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
};

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
};

ajax = Class.create();
ajax.prototype = {
	initialize: function(url, options){
		this.transport = this.getTransport();
		this.postBody = options.postBody || '';
		this.method = options.method || 'post';
		this.onComplete = options.onComplete || null;
		this.update = $(options.update) || null;
		this.request(url);
	},

	request: function(url){
		this.transport.open(this.method, url, true);
		this.transport.onreadystatechange = this.onStateChange.bind(this);
		if (this.method == 'post') {
			this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
		}
		this.transport.send(this.postBody);
	},

	onStateChange: function(){
		if (this.transport.readyState == 4 && this.transport.status == 200) {
			if (this.onComplete) 
				setTimeout(function(){this.onComplete(this.transport.responseText);}.bind(this), 10);
			if (this.update)
				setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
			this.transport.onreadystatechange = function(){};
		}
	},

	getTransport: function() {
		if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else return false;
	}
};

var remoteXMRequestCounter = 0;
var webServices = new Array();

var browser = navigator.appName;
function createRequestObject() {
	var ro;
	if (browser == "Microsoft Internet Explorer") {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}

function coolTip(obj,thetext, posVar){
	var pos = (typeof(posVar) != "undefined")?posVar:"top";
	var hintObj = $("XMBubble");
	if (hintObj) {
		hintObj.innerHTML = thetext;
		showObj(obj,"XMBubble",pos);
	}
}

function hidecoolTip(){
	hideObj("XMBubble");
}



var enabletip=false;
var tipobj=null;
var pointerobj=null;
function showTitleTip(obj,thetext, thewidth, thecolor,pos){
	if (thetext == "") return;
	if (tipobj == null) {
		tipobj = document.createElement("DIV");
		tipobj.id = "dhtmltooltip";
		document.body.appendChild(tipobj);
	}
	if (pointerobj == null) {
		pointerobj = document.createElement("DIV");
		pointerobj.id = "dhtmlpointer";
		pointerobj.innerHTML = "<img src=\"/lib/img/arrow_tip_up.gif\">";
		document.body.appendChild(pointerobj);
	}
	if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
	if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
	tipobj.innerHTML=thetext;
	enabletip=true;
	document.onclick=hideddrivetip;
	document.body.onscroll=hideddrivetip;
	var offsetfromcursorX=12; //Customize x offset of tooltip
	var offsetfromcursorY=10; //Customize y offset of tooltip
	
	var offsetdivfrompointerX=10; //Customize x offset of tooltip DIV relative to pointer image
	var offsetdivfrompointerY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
	
	var offsetX = 0;
	var offsetY = 0;
	var nondefaultpos=false;

	var objPos = getObjectPosition(obj);
	var curX=objPos["x"]-offsetX;
	var curY=objPos["y"]-offsetY+10;

	//Let's see if the tooltip will be too wide;
	if ((curX+tipobj.offsetWidth) > document.body.scrollWidth) {
		curX = objPos["x"]-offsetX-tipobj.offsetWidth+40;
		offsetfromcursorX = tipobj.offsetWidth-30;
	} else if (curY+tipobj.offsetHeight > document.body.offsetHeight) { //If the tooltip will be too tall for the page
		//curX = objPos["y"]-offsetY-tipobj.offsetHeight+40;
		//offsetfromcursorY = tipobj.offsetHeight-30;
		//alert(0);
	}
	//window.status = offsetfromcursorX+" "+curX;
	var tooltipX = curX;
	var tooltipY = curY+offsetfromcursorY+offsetdivfrompointerY;
	var pointerX = curX+offsetfromcursorX;
	var pointerY = curY+offsetfromcursorY;
	
	tipobj.style.left = tooltipX+"px";
	tipobj.style.top=tooltipY+"px";
	pointerobj.style.left = pointerX+"px";
	pointerobj.style.top=pointerY+"px";

	tipobj.style.visibility="visible";
	pointerobj.style.visibility=(!nondefaultpos)?"visible":"hidden";
	return false;
}

function positiontip(objId){
	if (enabletip){
		document.onclick=hideddrivetip;
		document.body.onscroll=hideddrivetip;
		var offsetfromcursorX=12; //Customize x offset of tooltip
		var offsetfromcursorY=10; //Customize y offset of tooltip
		
		var offsetdivfrompointerX=10; //Customize x offset of tooltip DIV relative to pointer image
		var offsetdivfrompointerY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
		
		var obj = $xm(objId);
		var offsetX = 0;
		var offsetY = 0;
		var nondefaultpos=false;

		var objPos = getObjectPosition(obj);
		var curX=objPos["x"]-offsetX;
		var curY=objPos["y"]-offsetY;

		//Let's see if the tooltip will be too wide;
		if ((curX+tipobj.offsetWidth) > document.body.scrollWidth) {
			curX = objPos["x"]-offsetX-tipobj.offsetWidth+40;
			offsetfromcursorX = tipobj.offsetWidth-30;
		} else if (curY+tipobj.offsetHeight > document.body.offsetHeight) { //If the tooltip will be too tall for the page
			//curX = objPos["y"]-offsetY-tipobj.offsetHeight+40;
			//offsetfromcursorY = tipobj.offsetHeight-30;
			//alert(0);
		}
		//window.status = offsetfromcursorX+" "+curX;
		var tooltipX = curX;
		var tooltipY = curY+offsetfromcursorY+offsetdivfrompointerY;
		var pointerX = curX+offsetfromcursorX;
		var pointerY = curY+offsetfromcursorY;
		
		tipobj.style.left = tooltipX+"px";
		tipobj.style.top=tooltipY+"px";
		pointerobj.style.left = pointerX+"px";
		pointerobj.style.top=pointerY+"px";

		tipobj.style.visibility="visible";
		pointerobj.style.visibility=(!nondefaultpos)?"visible":"hidden";
	}
}

function hideddrivetip(){
	enabletip=false;
	pointerobj.style.visibility="hidden";
	if (tipobj != null) {
		tipobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}


function sendToBack(obj) {
	var ifrm = $("XMFrameOverlay");
	if (ifrm) ifrm.style.display = "none";
	if (!obj) return;
};

function bringToFront(obj,ht,wdt,lft,top) {
	if (!browserIE || obj.tagName.toLowerCase() == "iframe") return;
	var objPos = getObjectPosition(obj);
	var ifrm = $("XMFrameOverlay");
	if (!ifrm) {
		ifrm = document.createElement("IFRAME");
		ifrm.style.border=0;
		ifrm.id="XMFrameOverlay";
		ifrm.setAttribute("scrolling","no");
		ifrm.setAttribute("frameborder","no");
		ifrm.src = "/lib/tag/xm/inc/blank.htm";
		document.body.appendChild(ifrm);
	}
	ifrm.style.height = ((ht)?ht:obj.offsetHeight)+"px";
	ifrm.style.top = ((top)?top:objPos["y"])+"px";
	ifrm.style.left = ((lft)?lft:objPos["x"])+"px";		
	ifrm.style.width = ((wdt)?wdt:obj.offsetWidth)+"px";
	ifrm.style.display = "block";
	ifrm.style.zIndex = 10;
	obj.style.zIndex = 20;
	ifrm = null;
};

var overObj = new Object();
function showObj(e,el,pos,clickToClose,bringToFrontVar,scrollVar) {
	var bringToFrontFlag = (typeof(bringToFrontVar) != "undefined")?bringToFrontVar:true;
	var scrollOpt = (typeof(scrollVar) != "undefined")?scrollVar:true;
	var obj = $xm(el);
	var clickToClose = (typeof(clickToClose) != "undefined")?clickToClose:true;
	var docWidth = document.body.offsetWidth;
	if (obj) {
		if (typeof overObj[el] == "undefined") overObj[el] = false;
		var pos = (typeof(pos) != "undefined")?pos:"bottom";
		var eProp = getObjectProperties(e);
		obj.onmouseover = function(){overObj[el]=true;};
		obj.onmouseout = function(){overObj[el]=false;};
		obj.style.display = "block";
		obj.style.left  = Math.min(eProp["x"],(docWidth-obj.offsetWidth))+"px";
		var mainContainer = $xm("MainContainer");
		if (mainContainer) {
			var mainProp = getObjectProperties(mainContainer);
			obj.style.left  = Math.min(eProp["x"],(mainProp["x"]+mainProp["w"]-obj.offsetWidth))+"px";
		}

		obj.style.top = eProp["y"]+eProp["h"]+"px";

		if (pos == "top") {
			 obj.style.top = eProp["y"]-obj.offsetHeight-15+"px";
		} else if (pos == "right") {
			obj.style.left  = Math.min(eProp["x"]+eProp["w"],(docWidth-obj.offsetWidth-60))+"px";
			var pgH = document.all ? document.documentElement.scrollHeight : document.body.scrollHeight;
			var u = document.all ? document.documentElement.scrollTop : document.body.scrollTop;
			var h = obj.offsetHeight;
			var posTop = eProp["y"] - (h/2);
			obj.style.top = Math.max(u,posTop) + 'px';//eProp["y"]-10+"px";
		} else if (pos == "menuright") {
			obj.style.left  = Math.min(eProp["x"]+(eProp["w"]/2),(docWidth-obj.offsetWidth-60))+"px";
			var pgH = document.all ? document.documentElement.scrollHeight : document.body.scrollHeight;
			var u = document.all ? document.documentElement.scrollTop : document.body.scrollTop;
			var h = obj.offsetHeight;
			obj.style.top = eProp["y"]+(eProp["h"]/2)+"px";
		} else if (pos == "left") {
			obj.style.left  = Math.min(eProp["x"]-eProp["w"],(docWidth-obj.offsetWidth-60))+"px";
			var pgH = document.all ? document.documentElement.scrollHeight : document.body.scrollHeight;
			var u = document.all ? document.documentElement.scrollTop : document.body.scrollTop;
			var h = obj.offsetHeight;
			var posTop = eProp["y"] - (h/2);
			obj.style.top = Math.max(u,posTop) + 'px';//eProp["y"]-10+"px";
		}
		if (obj.offsetHeight > (document.body.offsetHeight-(eProp["y"]+eProp["h"])) && scrollOpt) {
			if (document.body.offsetHeight-(eProp["y"]+eProp["h"]) > 0)
				obj.style.height = Math.min(200,document.body.offsetHeight-(eProp["y"]+eProp["h"]))+"px";
			obj.style.overflow = "auto";
		}
		if (bringToFrontFlag) bringToFront(obj);
		if (clickToClose) {
			document.onmouseup = function(e) {
				for (var m in overObj) {
					if (!overObj[m]) {
						this.onmouseup = null;
						hideObj(m); 
					}
				}
			}
		}
	}
}

function hideObj(el) {
	var obj = $xm(el);
	if (obj) obj.style.display = "none";
	sendToBack(obj);
}

var currPreviewKey;
function showPreview(key) {
	if (typeof showPreviewItem == "function") {
		showPreviewItem(key);
	} else if (parent && parent.Detail && currPreviewKey != key && parent.previewOn) {
		currPreviewKey = key;
		var baseURL = "detail.cfm?preview=1&id=";
		var url = (key == 0)?'/htm/shared/blank.cfm?bgcolor=808080':baseURL+escape(key);
		parent.Detail.location.href=url;
		//if (key != 0 && showNotifyBox) showNotifyBox("","Loading Details...",1000);
	} else if (!parent.Detail) {
		return;
		currPreviewKey = key;
		//if (key != 0 && showNotifyBox) showNotifyBox("","Loading Details...",1000);
		var url = (key == 0)?'/htm/shared/blank.cfm?bgcolor=808080':'../detail.cfm?preview=1&id='+escape(key);
		//window.location.href=url;
	};
};

function getObjectProperties(elObj) {
	var o = elObj;
	var elPos = getObjectPosition(o);
	var objArr = new Array();
	objArr["x"] = elPos["x"];
	objArr["y"] = elPos["y"];
	objArr["h"] = o.offsetHeight;
	objArr["w"] = o.offsetWidth;
	return objArr;
};

function getObjectPosition(elObj) {
	var objRealPos = Position.get(elObj);
	var posArr = new Array();
	posArr["x"] = objRealPos["left"];
	posArr["y"] = objRealPos["top"];
	return posArr;
};


var Position =(function(){function resolveObject(s){if(document.getElementById && document.getElementById(s)!=null){return document.getElementById(s);}else if(document.all && document.all[s]!=null){return document.all[s];}else if(document.anchors && document.anchors.length && document.anchors.length>0 && document.anchors[0].x){for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==s){return document.anchors[i]}}}}var pos ={};
pos.set = function(o,left,top){if(typeof(o)=="string"){o = resolveObject(o);}if(o==null || !o.style){return false;}o.style.position = "absolute";if(typeof(left)=="object"){var pos = left;left = pos.left;top = pos.top;}o.style.left = left + "px";o.style.top = top + "px";return true;};
pos.get = function(o){var fixBrowserQuirks = true;if(typeof(o)=="string"){o = resolveObject(o);}if(o==null){return null;}var left = 0;var top = 0;var width = 0;var height = 0;var parentNode = null;var offsetParent = null;offsetParent = o.offsetParent;var originalObject = o;var el = o;while(el.parentNode!=null){el = el.parentNode;if(el.offsetParent==null){}else{var considerScroll = true;if(fixBrowserQuirks && window.opera){if(el==originalObject.parentNode || el.nodeName=="TR"){considerScroll = false;}}if(considerScroll){if(el.scrollTop && el.scrollTop>0){top -= el.scrollTop;}if(el.scrollLeft && el.scrollLeft>0){left -= el.scrollLeft;}}}if(el == offsetParent){left += o.offsetLeft;if(el.clientLeft && el.nodeName!="TABLE"){left += el.clientLeft;}top += o.offsetTop;if(el.clientTop && el.nodeName!="TABLE"){top += el.clientTop;}o = el;if(o.offsetParent==null){if(o.offsetLeft){left += o.offsetLeft;}if(o.offsetTop){top += o.offsetTop;}}offsetParent = o.offsetParent;}}if(originalObject.offsetWidth){width = originalObject.offsetWidth;}if(originalObject.offsetHeight){height = originalObject.offsetHeight;}return{'left':left, 'top':top, 'width':width, 'height':height};};
pos.getCenter = function(o){var c = this.get(o);if(c==null){return null;}c.left = c.left +(c.width/2);c.top = c.top +(c.height/2);return c;};return pos;})();

/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
//tooltip

//General Scripts
var ie = (navigator.userAgent.indexOf('MSIE') != -1);
var moz = !ie && document.getElementById != null && document.layers == null;
var browserIE = ie;
var browserMozilla = moz;
var browserSafari = (navigator.userAgent.indexOf('Safari') != -1);
var browserOpera = (navigator.userAgent.indexOf('Opera') != -1);

var windowLoaded = false;
var filtering = false; //Used when filtering on a list page - flag set so we don't fire the "ENTER" key event
var BreadCrumbs = null;//Track breadcrumb path

/*===================================================================
 Author: Matt Kruse
 View documentation, examples, and source code at:
     http://www.JavascriptToolbox.com/
 ===================================================================*/
Date.$VERSION = 1.02;
Date.LZ = function(x){return(x<0||x>9?"":"0")+x};Date.monthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');Date.monthAbbreviations = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');Date.dayNames = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');Date.dayAbbreviations = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');Date.preferAmericanFormat = true;if(!Date.prototype.getFullYear){Date.prototype.getFullYear = function(){var yy=this.getYear();return(yy<1900?yy+1900:yy);}}
Date.parseString = function(val, format){if(typeof(format)=="undefined" || format==null || format==""){var generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d','MMM-d','d-MMM');var monthFirst=new Array('M/d/y','M-d-y','M.d.y','M/d','M-d');var dateFirst =new Array('d/M/y','d-M-y','d.M.y','d/M','d-M');var checkList=new Array(generalFormats,Date.preferAmericanFormat?monthFirst:dateFirst,Date.preferAmericanFormat?dateFirst:monthFirst);for(var i=0;i<checkList.length;i++){var l=checkList[i];for(var j=0;j<l.length;j++){var d=Date.parseString(val,l[j]);if(d!=null){return d;}}}return null;}
this.isInteger = function(val){for(var i=0;i < val.length;i++){if("1234567890".indexOf(val.charAt(i))==-1){return false;}}return true;};
this.getInt = function(str,i,minlength,maxlength){for(var x=maxlength;x>=minlength;x--){var token=str.substring(i,i+x);if(token.length < minlength){return null;}if(this.isInteger(token)){return token;}}return null;};val=val+"";format=format+"";var i_val=0;var i_format=0;var c="";var token="";var token2="";var x,y;var year=new Date().getFullYear();var month=1;var date=1;var hh=0;var mm=0;var ss=0;var ampm="";while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(token=="yyyy" || token=="yy" || token=="y"){if(token=="yyyy"){x=4;y=4;}if(token=="yy"){x=2;y=2;}if(token=="y"){x=2;y=4;}year=this.getInt(val,i_val,x,y);if(year==null){return null;}i_val += year.length;if(year.length==2){if(year > 70){year=1900+(year-0);}else{year=2000+(year-0);}}}else if(token=="MMM" || token=="NNN"){month=0;var names =(token=="MMM"?(Date.monthNames.concat(Date.monthAbbreviations)):Date.monthAbbreviations);for(var i=0;i<names.length;i++){var month_name=names[i];if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()){month=(i%12)+1;i_val += month_name.length;break;}}if((month < 1)||(month>12)){return null;}}else if(token=="EE"||token=="E"){var names =(token=="EE"?Date.dayNames:Date.dayAbbreviations);for(var i=0;i<names.length;i++){var day_name=names[i];if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val += day_name.length;break;}}}else if(token=="MM"||token=="M"){month=this.getInt(val,i_val,token.length,2);if(month==null||(month<1)||(month>12)){return null;}i_val+=month.length;}else if(token=="dd"||token=="d"){date=this.getInt(val,i_val,token.length,2);if(date==null||(date<1)||(date>31)){return null;}i_val+=date.length;}else if(token=="hh"||token=="h"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>12)){return null;}i_val+=hh.length;}else if(token=="HH"||token=="H"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>23)){return null;}i_val+=hh.length;}else if(token=="KK"||token=="K"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>11)){return null;}i_val+=hh.length;hh++;}else if(token=="kk"||token=="k"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>24)){return null;}i_val+=hh.length;hh--;}else if(token=="mm"||token=="m"){mm=this.getInt(val,i_val,token.length,2);if(mm==null||(mm<0)||(mm>59)){return null;}i_val+=mm.length;}else if(token=="ss"||token=="s"){ss=this.getInt(val,i_val,token.length,2);if(ss==null||(ss<0)||(ss>59)){return null;}i_val+=ss.length;}else if(token=="a"){if(val.substring(i_val,i_val+2).toLowerCase()=="am"){ampm="AM";}else if(val.substring(i_val,i_val+2).toLowerCase()=="pm"){ampm="PM";}else{return null;}i_val+=2;}else{if(val.substring(i_val,i_val+token.length)!=token){return null;}else{i_val+=token.length;}}}if(i_val != val.length){return null;}if(month==2){if( ((year%4==0)&&(year%100 != 0) ) ||(year%400==0) ){if(date > 29){return null;}}else{if(date > 28){return null;}}}if((month==4)||(month==6)||(month==9)||(month==11)){if(date > 30){return null;}}if(hh<12 && ampm=="PM"){hh=hh-0+12;}else if(hh>11 && ampm=="AM"){hh-=12;}return new Date(year,month-1,date,hh,mm,ss);}
Date.isValid = function(val,format){return(Date.parseString(val,format) != null);}
Date.prototype.isBefore = function(date2){if(date2==null){return false;}return(this.getTime()<date2.getTime());}
Date.prototype.isAfter = function(date2){if(date2==null){return false;}return(this.getTime()>date2.getTime());}
Date.prototype.equals = function(date2){if(date2==null){return false;}return(this.getTime()==date2.getTime());}
Date.prototype.equalsIgnoreTime = function(date2){if(date2==null){return false;}var d1 = new Date(this.getTime()).clearTime();var d2 = new Date(date2.getTime()).clearTime();return(d1.getTime()==d2.getTime());}
Date.prototype.format = function(format){format=format+"";var result="";var i_format=0;var c="";var token="";var y=this.getYear()+"";var M=this.getMonth()+1;var d=this.getDate();var E=this.getDay();var H=this.getHours();var m=this.getMinutes();var s=this.getSeconds();var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;var value=new Object();if(y.length < 4){y=""+(+y+1900);}value["y"]=""+y;value["yyyy"]=y;value["yy"]=y.substring(2,4);value["M"]=M;value["MM"]=Date.LZ(M);value["MMM"]=Date.monthNames[M-1];value["NNN"]=Date.monthAbbreviations[M-1];value["d"]=d;value["dd"]=Date.LZ(d);value["E"]=Date.dayAbbreviations[E];value["EE"]=Date.dayNames[E];value["H"]=H;value["HH"]=Date.LZ(H);if(H==0){value["h"]=12;}else if(H>12){value["h"]=H-12;}else{value["h"]=H;}value["hh"]=Date.LZ(value["h"]);value["K"]=value["h"]-1;value["k"]=value["H"]+1;value["KK"]=Date.LZ(value["K"]);value["kk"]=Date.LZ(value["k"]);if(H > 11){value["a"]="PM";}else{value["a"]="AM";}value["m"]=m;value["mm"]=Date.LZ(m);value["s"]=s;value["ss"]=Date.LZ(s);while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(typeof(value[token])!="undefined"){result=result + value[token];}else{result=result + token;}}return result;}
Date.prototype.getDayName = function(){return Date.dayNames[this.getDay()];}
Date.prototype.getDayAbbreviation = function(){return Date.dayAbbreviations[this.getDay()];}
Date.prototype.getMonthName = function(){return Date.monthNames[this.getMonth()];}
Date.prototype.getMonthAbbreviation = function(){return Date.monthAbbreviations[this.getMonth()];}
Date.prototype.clearTime = function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);
return this;}
Date.prototype.add = function(interval, number){if(typeof(interval)=="undefined" || interval==null || typeof(number)=="undefined" || number==null){
return this;}number = +number;if(interval=='y'){this.setFullYear(this.getFullYear()+number);}else if(interval=='M'){this.setMonth(this.getMonth()+number);}else if(interval=='d'){this.setDate(this.getDate()+number);}else if(interval=='w'){var step =(number>0)?1:-1;while(number!=0){this.add('d',step);while(this.getDay()==0 || this.getDay()==6){this.add('d',step);}number -= step;}}else if(interval=='h'){this.setHours(this.getHours() + number);}else if(interval=='m'){this.setMinutes(this.getMinutes() + number);}else if(interval=='s'){this.setSeconds(this.getSeconds() + number);}
return this;}

var CGI = new Array(); CGI.script_name = location.href; CGI.http_host = location.host; CGI.query_string = document.location.search; var URL = new Array(); var queryString = document.location.search; if (queryString.length > 1) { var nmValPairs = queryString.substring(1,queryString.length); for (var q=1;q <= ListLen(nmValPairs,"&");q++) { var nmVal = ListGetAt(nmValPairs,q,"&"); URL[ListFirst(nmVal,"=")] = ListLast(nmVal,"=");}
}
function getURL(str) { return (typeof(URL[str]) != "undefined")?URL[str]:"";}
function setCookie(name,value) {document.cookie = name+"="+value+"; path=/";}
function getCookie(name) { if (document.cookie) { var cookies=document.cookie.split(";"); for (var i=0; i<cookies.length; i++) { var varName=(cookies[i].split("=")[0]); var varValue=(cookies[i].split("=")[1]); while (varName.charAt(0)==" ")
varName=varName.substr(1,varName.length); if (varName.toLowerCase()==name.toLowerCase())
return varValue;}
}
return "";}
function TRIM(strValue) { var objRegExp = /^(\s*)$/; if(objRegExp.test(strValue)) { strValue = strValue.replace(objRegExp, ''); if( strValue.length == 0) return strValue;}
objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/; if(objRegExp.test(strValue)) { strValue = strValue.replace(objRegExp, '$2');}
return strValue;}
function XMLFormat(xmlStr) { var regEx = new RegExp("\r\n","ig"); xmlStr = TRIM(xmlStr); var xml = "<![CDATA["+xmlStr.replace(regEx, "<br>")+"]]>"; return xml;}
function ListFind(lst,val,del) { if (lst == null) return 0;var lstArr = lst.split(del); var fnd = 0; for (var a=0;a<lstArr.length;a++) { if (lstArr[a] == val) { fnd = a+1; break;}
}
return fnd;}
function ListFindNoCase(lst,val,del) { var lstArr = lst.split(del); var fnd = 0; for (var a=0;a<lstArr.length;a++) { if (lstArr[a].toLowerCase() == val.toLowerCase()) { fnd = a+1; break;}
}
return fnd;}
function getLeadingZero(nbr) {var nr = nbr;var nrStr = ""+nbr;if (nr < 10 && nrStr.length == 1) nr = "0"+nr;return nr;}
function ListToArray(lst,del) { return lst.split(del);}
function ArrayToList(arr,del) { return arr.join(del);}
function Val(nbr) { return (isNaN(nbr) || nbr == "")?parseInt(0):parseInt(nbr);}
function ListAppend(lst,val,del) { var del=del?del:",";if (lst == "") return val; var lstArr = ListToArray(lst,del); lstArr[lstArr.length] = val; var newlst = ArrayToList(lstArr,del); return newlst;}
function ListLen(lst,del) { var del=del?del:",";var lstArr = lst.split(del); return lstArr.length;}
function ListDeleteAt(lst,pos,del) { var del=del?del:",";var lstArr = lst.split(del); remArr = lstArr.splice(pos-1,1); var newlst = ArrayToList(lstArr,del); return newlst;}
function ListGetAt(lst,pos,del) { var del=del?del:",";var lstArr = lst.split(del); return lstArr[pos-1];}
function ListLast(lst,del) { var del=del?del:",";return ListGetAt(lst,ListLen(lst,del),del);}
function ListFirst(lst,del) {var del=del?del:","; return ListGetAt(lst,1,del);}
function NumberFormat(num) { return FormatNumber(num,0);}
function DecimalFormat(num) { return FormatNumber(num,2);}
function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas) { if (isNaN(parseInt(num))) return "NaN"; var tmpNum = num; var iSign = num < 0 ? -1 : 1; tmpNum *= Math.pow(10,decimalNum); tmpNum = Math.round(Math.abs(tmpNum));tmpNum /= Math.pow(10,decimalNum); tmpNum *= iSign; var tmpNumStr = new String(tmpNum); if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
if (num > 0)
tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length); else
tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length); if (bolCommas && (num >= 1000 || num <= -1000)) { var iStart = tmpNumStr.indexOf("."); if (iStart < 0)
iStart = tmpNumStr.length; iStart -= 3; while (iStart >= 1) { tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
iStart -= 3;}
}
if (bolParens && num < 0) tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")"; return tmpNumStr;}
function isDate(p_Expression){ return !isNaN(new Date(p_Expression));}
function dateAdd(p_Interval, p_Number, p_Date){ if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
if(isNaN(p_Number)){return "invalid number: '" + p_Number + "'";}
p_Number = new Number(p_Number); var dt = new Date(p_Date); switch(p_Interval.toLowerCase()){ case "yyyy": { dt.setFullYear(dt.getFullYear() + p_Number); break;}
case "q": { dt.setMonth(dt.getMonth() + (p_Number*3)); break;}
case "m": { dt.setMonth(dt.getMonth() + p_Number); break;}
case "y":
case "d":
case "w": { dt.setDate(dt.getDate() + p_Number); break;}
case "ww": { dt.setDate(dt.getDate() + (p_Number*7)); break;}
case "h": { dt.setHours(dt.getHours() + p_Number); break;}
case "n": { dt.setMinutes(dt.getMinutes() + p_Number); break;}
case "s": { dt.setSeconds(dt.getSeconds() + p_Number); break;}
case "ms": { dt.setMilliseconds(dt.getMilliseconds() + p_Number); break;}
default: { return "invalid interval: '" + p_Interval + "'";}
}
return dt;}
function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){ if(!isDate(p_Date1)){return "invalid date: '" + p_Date1 + "'";}
if(!isDate(p_Date2)){return "invalid date: '" + p_Date2 + "'";}
var dt1 = new Date(p_Date1); var dt2 = new Date(p_Date2); var iDiffMS = dt2.valueOf() - dt1.valueOf(); var dtDiff = new Date(iDiffMS); var nYears = dtDiff.getUTCFullYear()-1970; var nMonths = dtDiff.getUTCMonth() + (nYears!=0 ? nYears*12 : 0); var nQuarters = parseInt(nMonths/3); var nWeeks = parseInt(iDiffMS/1000/60/60/24/7); var nDays = parseInt(iDiffMS/1000/60/60/24); var nHours = parseInt(iDiffMS/1000/60/60); var nMinutes = parseInt(iDiffMS/1000/60); var nSeconds= parseInt(iDiffMS/1000); var nMilliseconds = iDiffMS; var iDiff = 0; switch(p_Interval.toLowerCase()){ case "yyyy": return nYears; case "q": return nQuarters; case "m": return nMonths; case "y":
case "d": return nDays; case "w": return nDays; case "ww":return nWeeks; case "h": return nHours; case "n": return nMinutes; case "s": return nSeconds; case "ms":return nMilliseconds; default: return "invalid interval: '" + p_Interval + "'";}
}
function datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear){ if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
var dtPart = new Date(p_Date); switch(p_Interval.toLowerCase()){ 
case "yyyy": return dtPart.getFullYear(); 
case "q": return parseInt(dtPart.getMonth()/3)+1; case "m": return dtPart.getMonth()+1; 
case "y": return dateDiff("y", "1/1/" + dtPart.getFullYear(), dtPart); 
case "d": return dtPart.getDate(); case "w": return dtPart.getDay(); case "ww":return dateDiff("ww", "1/1/" + dtPart.getFullYear(), dtPart); 
case "h": return dtPart.getHours(); case "n": return dtPart.getMinutes(); case "s": return dtPart.getSeconds(); case "ms":return dtPart.getMilliseconds(); 
default: return "invalid interval: '" + p_Interval + "'";}
}
function weekdayName(p_Date, p_abbreviate){ if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
var dt = new Date(p_Date); var retVal = dt.toString().split(' ')[0]; var retVal = Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[dt.getDay()]; if(p_abbreviate==true){retVal = retVal.substring(0, 3)}
return retVal;}
function monthName(p_Date, p_abbreviate){ if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
var dt = new Date(p_Date); var retVal = Array('January','February','March','April','May','June','July','August','September','October','November','December')[dt.getMonth()]; if(p_abbreviate==true){retVal = retVal.substring(0, 3)}
return retVal;}
function IsDate(p_Expression){ return isDate(p_Expression);}
function DateAdd(p_Interval, p_Number, p_Date){ return dateAdd(p_Interval, p_Number, p_Date);}
function DateDiff(p_interval, p_date1, p_date2, p_firstdayofweek, p_firstweekofyear){ return dateDiff(p_interval, p_date1, p_date2, p_firstdayofweek, p_firstweekofyear);}
function DatePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear){ return datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear);}
function WeekdayName(p_Date){ return weekdayName(p_Date);}
function MonthName(p_Date){ return monthName(p_Date);}
function DateTimeFormat(dt) {return getLeadingZero(DatePart("m",dt))+"/"+getLeadingZero(DatePart("d",dt))+"/"+DatePart("yyyy",dt)+" "+getLeadingZero(DatePart("h",dt))+":"+getLeadingZero(DatePart("n",dt));}

/* Duplicating rows */

var dynCounter = new Object();

function createDynRow(ind,prefix,rowInit, data) {
	if (arguments.length < 3) rowInit=0;
	var tblObj = $xm(prefix+"_table");
	var rowSrc = tblObj.tBodies[ind].rows[0];
	cleanupChildrenBeforeClone(rowSrc);
	var rowDest = rowSrc.cloneNode(true);
	if (typeof dynCounter[prefix] == "undefined") dynCounter[prefix] = rowInit;
	rowDest.style.display = dispTRTag;
	//Update the clone to have its own identity.
	tblObj.tBodies[ind].appendChild(rowDest);
	var a = document.createElement("span");
	a.innerHTML = "<span style='cursor:pointer;font-size:10px;'><img src='/lib/img/icon/icon_delete_small.gif' alt='Delete' border='0' align='absmiddle'> Delete</span>";
	a.onclick = function() {if (window.confirm('Are you sure you want to delete this item?')) deleteDynRow(rowDest,ind,prefix);};
	rowDest.cells[rowDest.cells.length-1].appendChild(a);
	var cntr = ++dynCounter[prefix];
	rowDest.id = prefix+"_Row"+cntr;
	a.id = prefix+"_Del";
	//get input boxes so we can rename them
	renameChildObjects(rowDest,cntr, data);
	var tsrows = $xm(prefix+"_rows");
	tsrows.value = ListAppend(tsrows.value,cntr,",");
	return cntr;
}

function cleanupChildrenBeforeClone(obj) {
	var inBoxes = obj.getElementsByTagName("*");
	for (var i=0;i<inBoxes.length;i++) {
		var prvNm = (typeof inBoxes[i].getAttribute('name') != null && inBoxes[i].getAttribute('name') != null && inBoxes[i].getAttribute('name') != '')?inBoxes[i].getAttribute('name'):inBoxes[i].getAttribute('id');
		//DatePickerFix
		if (inBoxes[i].getAttribute("datetype") == "date") {
			//jQuery("#"+prvNm).datepicker("destroy");
		}
	}
}

function renameChildObjects(obj,suffix, data) {
	var inBoxes = obj.getElementsByTagName("*");
	var newId,prvNm,inp;
	for (var i=0;i<inBoxes.length;i++) {
		inpt = inBoxes[i];
		prvNm = (typeof inpt.getAttribute('name') != null && inpt.getAttribute('name') != null && inpt.getAttribute('name') != '')?inpt.getAttribute('name'):inpt.getAttribute('id');
		newId =  prvNm+"_"+suffix;
		inpt.setAttribute("name",newId);
		inpt.name = newId;
		inpt.setAttribute("id",newId);
		if (inpt.type == "checkbox" || inpt.type == "radio") {
			inpt.checked = false;
			if 	(data && inpt.value == data[prvNm]) inpt.checked = true;
		} else if (inpt.type == "text" || inpt.type == "textarea" || inpt.type == "hidden") {
			inpt.value = "";
			if 	(data && data[prvNm]) inpt.value = data[prvNm];
		} else if (inpt.type && inpt.type.indexOf("select") == 0) {
			if (data) for (var p=0; p < inpt.options.length; p++) if (inpt.options[p].value == data[prvNm]) inpt.options[p].selected = true;
		}
		//if (inpt.outerHTML)
			//inpt.outerHTML=inpt.outerHTML.replace(/name=\S+/,"name="+prvNm+"_"+suffix+"");
		//DatePickerFix
		if (inpt.getAttribute("datetype") == "date") {
			jQuery("#"+newId).datepicker(dateXM[prvNm]);
		} else if (inpt.getAttribute("datetype") == "datetime") {
			jQuery("#"+newId).datetimepicker(dateXM[prvNm]);
		}
	}
	
}

function deleteDynRow(obj,ind,prefix) {
	if (obj.getAttribute("fx") != null) {
		eval(obj.getAttribute("fx"));
	}
	var tsrows = $xm(prefix+"_rows");
	tsrows.value = ListDeleteAt(tsrows.value,ListFind(tsrows.value,obj.id.replace(prefix+"_Row",""),","),",");
	var tblObj = $xm(prefix+"_table");
	tblObj.tBodies[0].removeChild(obj);
}

function SetDateTime(fldNm,dt) {
	var y = dt.getFullYear();
	var m = dt.getMonth()+1;
	var d = dt.getDate();
	var hr = (dt.getHours() > 12)?(dt.getHours()-12):(dt.getHours() == 0 || dt.getHours() == 24)?12:dt.getHours();
	var mn = dt.getMinutes();
	var mr = (dt.getHours() >= 12)?"PM":"AM";
	jQuery("#"+fldNm).datepicker("setDate",dt);
	//$xm(fldNm).value = y+'-'+m+'-'+d+' '+hr+':'+mn+' '+mr;
}

function toggle(objId,flagVar) {
	var obj = $xm(objId);
	var flag = (typeof flagVar != "undefined")?flagVar:(obj.style.display=="none");
	if (obj.tagName.toLowerCase() == "tr") {
		toggleTableRow(objId,flag);
		return;
	}
	obj.style.display=(flag)?"block":"none";
}

function toggleTableRow(row,flag) {
	var rowObj = $xm(row);
	if (rowObj.tagName.toLowerCase() != "tr") {
		//alert(rowObj.outerHTML);
		return;
	}
	rowObj.style.display=(flag)?dispTRTag:"none";
	/*
	var cells = rowObj.cells;
	for (var c=0;c<cells.length;c++) {
		cells[c].style.visibility=(flag)?"visible":"hidden";	
	}
	*/
}


function FireEvent(obj,evt) {
	if(obj.fireEvent)
		obj.fireEvent("on"+evt);
	else if (document.createEvent) {
		var evtObj = document.createEvent("HTMLEvents");
		if (evtObj.initEvent) {
			evtObj.initEvent(evt, true, true);
		}
		if (obj.dispatchEvent) {
			obj.dispatchEvent(evtObj);
		} 
	}
}


var docItems = new Array();
function fillBox(el,mode) {
	if (el == null) return;
	var elObj = $xm(el);
	var offset = 0;
	var parObj = elObj.parentNode;
	if (mode == null) mode = "BODY";
	if (mode == "BODY") parObj = document.body;
	//var elPos = getObjectPosition(elObj);
	parHeight = parObj.offsetHeight;
	if (moz) parHeight = window.innerHeight;

	var newHeight = Math.max((parHeight-(parseInt(elObj.offsetTop)+0)),1);
	var newWidth = Math.max((parObj.offsetWidth-(parseInt(elObj.offsetLeft)+0)),1);
	//if (moz) newWidth = newWidth - 3;
	//window.status = "Parent Height: "+parHeight+" - New Height: "+newHeight;
	elObj.style.height = newHeight+"px";
	elObj.style.width = newWidth+"px";
};

function setupFiller(obj,mode) {
	docItems[docItems.length] = new Array(obj,mode);
	addEvent(window,"load",function(e) {turnOffPageScroll();fillBox(obj,mode);});
	if (pageLoaded) {
		fillBox(obj,mode);
	}
};

function reFillBoxes() {
	for (var d=0;d<docItems.length;d++) {
		fillBox(docItems[d][0],docItems[d][1]);	
	}
};

function turnOffPageScroll() {
	document.body.style.overflow = "hidden";
};

function Nifty(selector,options){
	return;
}

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  
  return elements;
};

var tooltip=function(){
	var id = 'tt';
	var top = 10;
	var left = 18;
	var maxw = 700;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var fadeFlag = true;
	var tt,t,c,b,h,sourceObj;
	var ie = document.all ? true : false;
	return{
		show:function(v,w,sObj,fadeOn){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				tt.appendChild(c);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			sourceObj = sObj;
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
			document.onmousedown=function(){tooltip.hide();};
		},
		pos:function(e){
			var sourceProp = getObjectProperties(sourceObj);
			var pgH = ie ? document.documentElement.scrollHeight : document.body.scrollHeight;
			var u = ie ? document.documentElement.scrollTop : document.body.scrollTop;
			var l = sourceProp["x"];
			var posTop = sourceProp["y"] - (h/2);
			tt.style.top = Math.max(u,posTop) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			if (tt && tt.timer) {
				clearInterval(tt.timer);
				tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
			}
}
	};
}();


var pageLoaded = false;
function globalXMOnload() {
	var id = "XMDock";
	var dockObj = $xm(id);
	if (dockObj) {
		docItems[docItems.length] = new Array(id);
		fillBox(id,"BODY");
	}
	
	var XMBubble = document.createElement("DIV");
	XMBubble.id = "XMBubble";
	XMBubble.className = "XMBubble";
	document.body.appendChild(XMBubble);

	pageLoaded = true;
}

function globalResize() {
	reFillBoxes();
}

function openHelpContent(id) {
	window.open('/modules/portal/help_content.cfm?custom_page_id='+id,'newHTMLWindow','width=400,height=600,toolbar=0,status=1,menubar=0,scrollbars=1,resizable=1,left=10,top=10'); 
	return false;
}

function setOption(t,r,o,v) {
	var key = o.replace("show_","");
	var img = $xm("icon_"+key);
	img.src = (v)?"/lib/img/minus_small.gif":"/lib/img/plus_small.gif";
	toggle(key,v);
	new ajax("/modules/portal/go.cfm?a=SetOption&t="+t+"&r="+r+"&o="+o+"&v="+v,{method:"get",onComplete: function(str){
			;//var obj = eval('('+str+')');
		}
	});				
}

function getOption(t,r,o) {
	var key = o.replace("show_","");
	var img = $xm("icon_"+key);
	new ajax("/modules/portal/go.cfm?a=GetOption&t="+t+"&r="+r+"&o="+o,{method:"get",onComplete: function(str){
		var obj = eval('('+str+')');
		var flag = (obj == "" || obj == "true"|| obj == true);
		toggle(key,flag);
		img.src = (flag)?"/lib/img/minus_small.gif":"/lib/img/plus_small.gif";
		}
	});				
}

var spellBase = "/lib/tag/xm/inc/spell/";
var isSpellChecking = false;
var spellDiv,mnuDiv;
function createRequestObject() { var ro; var browser = navigator.appName; if (browser == "Microsoft Internet Explorer") { ro = new ActiveXObject("Microsoft.XMLHTTP");} else { ro = new XMLHttpRequest();};return ro;}
var http = createRequestObject(); 

function checkSpelling(obj) { 
	var str = obj.value; 
	var splBtn = $xm("SpellControl"+obj.id);
	if (!isSpellChecking && http) { 
		splBtn.src = spellBase+"indicator.gif";
		http.open('post', spellBase+'spellcheck.cfm'); 
		http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 
		http.onreadystatechange = function(){handleSpellingResponse(obj);}; 
		isSpellChecking = true; 
		http.send("textstring="+escape(str));
	};
}

var suggStr = new Object();

function showSugg(splObj) {
	var key = splObj.innerHTML;
	var splMnu = new Array(1);
	for (var s=0; s<suggStr[key].length;s++) {
		splMnu[s] = new Array(suggStr[key][s]);
	}	
	showSpellMenu(splObj, splMnu);
}

function closeSpellCheck(obj) {
	var spellDiv = $xm("splDivLayer"+obj.id);
	if (spellDiv) {
		obj.value = spellDiv.innerHTML.replace(/\<span[^>]*\>(.*?)\<\/span\>/ig,"$1");
		document.body.removeChild(spellDiv);
	}
	
	var splBtn = $xm("SpellControl"+obj.id);
	splBtn.src = spellBase+"spellc.gif";
}

function showSpellMenu(splObj, s) {
	mnuDiv = $xm("cIMMenu");
	if (mnuDiv) {
		document.body.removeChild(mnuDiv);
	}
	
	// create element and insert last into the body
	var d = document.createElement("DIV");
	d.id = "cIMMenu";
	d.className = "spMenu";

	//str = "<table border=0>";
	for (i=0; i<s.length; i++) {
		var m = document.createElement("DIV");
		m.className = "spMenuItem";
		m.innerHTML = s[i][0];
		m.onclick = function () {splObj.innerHTML = this.innerHTML;splObj.className="spellCorrected";document.body.removeChild($xm("cIMMenu"));};
		m.onmouseover = function(){this.className="spMenuOver"}
		m.onmouseout  = function(){this.className="spMenuItem"}
		d.appendChild(m);
	}
	document.body.appendChild(d);
	d.onmouseover = function() {onMenu = 1;if (d.focus) d.focus();};
	d.onmouseout = function() {onMenu = 0;};
	d.onblur = function() {if (onMenu == 0) document.body.removeChild(d);};	
	
	var objRealPos = Position.get(splObj);
	d.style.top = objRealPos["top"]+splObj.offsetHeight+"px";
	d.style.left = objRealPos["left"]+"px";
	if (d.focus) d.focus();
}	

function handleSpellingResponse(obj) {
	if(http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			var xmlObj = http.responseXML.documentElement;
			suggStr = new Object();

			//alert(xmlObj.xml);
			var new_string = obj.value;
			var string_length = new_string.length;
			var curr_index = string_length+1;
			var suggest_string = "";
			var start,length,end,suggestions,post,splText;

			var sNodes = xmlObj.childNodes;
			var node;
			for (var i = xmlObj.childNodes.length; i >0; i--) {
				node = xmlObj.childNodes[i-1];
				if (!node.firstChild) continue;
				suggestions = node.firstChild.nodeValue;
				start = parseFloat(node.getAttribute("o"));
				length = parseFloat(node.getAttribute("l"));
				end = start + length;
				post = "";
				splText = new_string.substring(start,end);
				
				var sugArr = suggestions.split("\t");
				suggStr[splText] = new Array(1);
				for (var s=0;s<sugArr.length;s++) {
					suggStr[splText][s] = sugArr[s];
				}
				//alert("Start: "+start+" End: "+end+" Length: "+length);
				if (end < curr_index) post = new_string.substring(end,curr_index);
				suggest_string = "<span class='spellErr' onclick='showSugg(this);'>"+splText+"</span>"+post+suggest_string;
				//alert(suggest_string);
				curr_index = start;
			}
			
			if (curr_index > 0) suggest_string = new_string.substring(0,curr_index)+suggest_string;
			
			//Create a div and place above the textarea
			spellDiv = $xm("splDivLayer"+obj.id);
			if (!spellDiv) {
				spellDiv = document.createElement("div");
				spellDiv.id = "splDivLayer"+obj.id;
				spellDiv.className = "spellLayer";
				spellDiv.setAttribute("title","Click OK to resume editing");
				document.body.appendChild(spellDiv);
			}

			var objRealPos = Position.get(obj);
			spellDiv.style.width=obj.offsetWidth+"px";
			spellDiv.style.height=obj.offsetHeight+"px";
			spellDiv.style.top=objRealPos["top"]+"px";
			spellDiv.style.left=objRealPos["left"]+"px";
			spellDiv.innerHTML = suggest_string;
			var splBtn = $xm("SpellControl"+obj.id);
			splBtn.src = spellBase+"ok.gif";
			
			if (xmlObj.childNodes.length == 0) {
				alert("No spelling errors found");
				closeSpellCheck(obj);
			}
			isSpellChecking = false;

		}
	}
}


//START FORM CODE

var formsGlobalsLoaded = false;
var formsSetupFormsCompleted = false;
var checkRequiredFields = true;
var new_fieldname = ""
var form_name = "";
var file_fld = 0;
var gFieldsChanged = 0;
var frmSubmit = 0;
var file_attached = 0;
var error_color = "#FFF8DC"
var off_error_color = "#FFFFFF"
var on_error_color = "#FFF8DC"
var form_color = "#FFFFFF"

var ItemsChecked = new Object();
var frmStr = new Object();

frmStr.formBeginMessage = "The following form field(s) were incomplete or incorrect.  Fields requiring input are highlighted in gray:";
frmStr.formEndMessage = "Please complete or correct the form and submit again.";
frmStr.reqMsg = "is required";

frmStr["numeric"] = new Object();
frmStr["numeric"].message = "must be a numeric value";
frmStr["numeric"].regex = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 

frmStr["integer"] = new Object();
frmStr["integer"].message = "must be a valid number (greater than 0)";
frmStr["integer"].regex = /(^-?\d\d*$)/;

frmStr["phone"] = new Object();
frmStr["phone"].message = "must be a valid phone number (xxx-xxx-xxxx)";
frmStr["phone"].regex = /^(\d\d\d-)*\d\d\d-\d\d\d\d$/;

frmStr["fein"] = new Object();
frmStr["fein"].message = "must be a valid federal employer identification number (xx-xxxxxxx)";
frmStr["fein"].regex = /^(\d\d-)*\d\d\d\d\d\d\d$/;

frmStr["ssn"] = new Object();
frmStr["ssn"].message = "must be a valid social security number (xxx-xx-xxxx)";
frmStr["ssn"].regex = /^\d\d\d-\d\d-\d\d\d\d$/;

frmStr["date"] = new Object();
frmStr["date"].message = "must be a valid date";
frmStr["date"].regex = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

frmStr["datetime"] = new Object();
frmStr["datetime"].message = "must be a valid date";
frmStr["datetime"].regex = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;

frmStr["time"] = new Object();
frmStr["time"].message = "must be a valid time";
frmStr["time"].regex = /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;

frmStr["currency"] = new Object();
frmStr["currency"].message = "must be a valid currency";
frmStr["currency"].regex = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 

frmStr["email"] = new Object();
frmStr["email"].message = "must be a valid email (user@company.com)";
frmStr["email"].regex = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;

frmStr["date"] = new Object();
frmStr["date"].message = "must be a date";
frmStr["date"].regex = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;


function frmValidCheck(frmObj) {
	ItemsChecked = new Object();
	var x = frmObj.elements.length;
	checkBeforeLeaving = false;
	if (frmObj.getAttribute("validate") == "false") return true;
	var invalidFields = new Array();
	var currentMessage,statusMessage,vType,req,fldObj,vReg,vMsg,currentRegex;
  	for (var i = 0; i < x; i++) {
		fldObj = frmObj.elements[i];
		req = fldObj.getAttribute("vrequired");
		vType = fldObj.getAttribute("vtype");
		vReg = fldObj.getAttribute("vReg");
		if (vType != null && vType.toLowerCase() == 'numeric') { fldObj.value = fldObj.value.replace(/,/g,"");	}				
		currentRegex = (typeof(frmStr[vType]) != "undefined")?frmStr[vType].regex:vReg;
		currentMessage = (typeof(frmStr[vType]) != "undefined")?frmStr[vType].message:fldObj.getAttribute('vMsg');
		statusMessage = "";
		if (checkRequiredFields && (req == "1" || req == "true" || req == true)) {
			statusMessage = frmValidRequired(frmObj,fldObj,frmStr.reqMsg);
		}
		if (currentRegex != null && statusMessage == "") {
			statusMessage = frmValidOther(frmObj,fldObj,currentRegex,currentMessage);
		}
		if (fldObj.tagName == "TEXTAREA" && fldObj.getAttribute("maxlength") != null && fldObj.value.length > parseInt(fldObj.getAttribute("maxlength"))) {	
					statusMessage = "You can only enter up to "+fldObj.getAttribute("maxlength")+" characters in the field "+fldObj.getAttribute("vlabel");
		}	
		if (statusMessage != "") {
			var newIndex = invalidFields.length;
			invalidFields[newIndex] = new Object();
			invalidFields[newIndex].message = statusMessage;
			invalidFields[newIndex].field = fldObj.name;
		}
    }
	if (invalidFields.length > 0) {
		var validationMessageJS = frmStr.formBeginMessage+"\n\n"
		var validationMessageHTML = "<div class=\"invalidFieldHeader\">We didn't correctly capture your response to the following item(s). </div><br/>"
		for (var v=0;v<invalidFields.length;v++) { 
			fldIcon = $xm("ValImg"+invalidFields[v].field);
			if (fldIcon) fldIcon.src = "/lib/img/icon/error.gif";;
			validationMessageJS += unescape(invalidFields[v].message) + "\n";
			validationMessageHTML += "<div class=\"invalidFieldMessage\" onclick=\"frmNavigate('"+invalidFields[v].field+"');\" onmouseover=\"this.className='invalidFieldMessageHL';\" onmouseout=\"this.className='invalidFieldMessage';\">"+decodeURIComponent(invalidFields[v].message) + "</div>";
		}
		validationMessageJS += "\n"+frmStr.formEndMessage;
		validationMessageHTML += "<br>"+frmStr.formEndMessage;

		var vObj = $xm("ValidationMessages");
		var formId = frmObj.getAttribute("id");
		if ($("ValidationMessages"+formId)) vObj = $("ValidationMessages"+formId);
		if (vObj) {
			alert("We found some items that need addressing.  \n\Click OK to review them.");
			vObj.innerHTML = validationMessageHTML;
			vObj.style.display = "block";
		} else {
			alert(validationMessageJS);
		}
   		return false;
  	} else if (typeof postValidateForm == 'function') {
		return postValidateForm(frmObj);
  	} else {
		return true;
   	}
} 

function frmNavigate(fldName) {
	var rowObj = $xm("form_row_"+fldName);
	var fldObj = $xm(fldName);
	if (rowObj) {
		document.body.scrollTop = getObjectPosition(rowObj).y;
		if (rowObj.focus) rowObj.focus();
		//alert(getObjectPosition(rowObj).y);
	} else if (fldObj.focus) fldObj.focus();
}

function frmValidOther(frmObj,fldObj,expChk,msg) {
	var msg_addition = "";
 	var objRegExp = eval(expChk);
	form_field_value = trimAll(fldObj.value);
    if (form_field_value != "" && (!objRegExp.test(form_field_value))) {
    	msg_addition = unescape(fldObj.getAttribute('vlabel'))+' '+msg;
	    changeColor(frmObj,fldObj,1);
   	}
 	return(msg_addition);
}

function setRequiredField(fldObj,flag) {
	if (fldObj && fldObj.length && fldObj[0].name) {
		try {
			var docImg = $xm("ReqImg"+fldObj[0].name);
			if (docImg) docImg.src =  (flag)?"/lib/img/icon/asterisk.gif":"/lib/img/clear.gif";
		} catch(e) {;}
		try {
			for (var f=0;f<fldObj.length;f++) {
				fldObj[f].setAttribute("vrequired",flag);
			}
		} catch(e) {;}
	} else {
		try {
			var docImg = $xm("ReqImg"+fldObj.name);
			if (docImg) docImg.src =  (flag)?"/lib/img/icon/asterisk.gif":"/lib/img/clear.gif";
		} catch(e) {;}
		try {
			fldObj.setAttribute("vrequired",flag);
		} catch(e) {;}
	}
}
 
function frmValidRequired(frmObj,fldObj,msg) {
	changeColor(frmObj,fldObj,0);
	var form_field_type = fldObj.getAttribute('type');
	var msg_addition = "";
	if ((form_field_type == "radio" || form_field_type == "checkbox") && ItemsChecked != null && typeof(ItemsChecked[fldObj.name]) == "undefined") {
		var anyChecked = false;
		if (typeof frmObj.elements[fldObj.name].length == "undefined") anyChecked = frmObj.elements[fldObj.name].checked;
		for (var i=0; i<frmObj.elements[fldObj.name].length; i++) {
			inst = frmObj.elements[fldObj.name][i];
			if (inst.checked) {
				anyChecked = true;
				break;
			}
		}
		if (!anyChecked) msg_addition = frmObj.elements[fldObj.name][0].getAttribute('vlabel')+' '+msg;
	} else {
		var strTemp = fldObj.value;
		strTemp = trimAll(strTemp);
		if(strTemp.length == 0){
			msg_addition = fldObj.getAttribute('vlabel')+' '+msg;
			changeColor(frmObj,fldObj,1);
		}  
	}
	ItemsChecked[fldObj.name] = true;
	return msg_addition;
}


function frmValidRange(frmObj,fldObj,msg) {
	changeColor(frmObj,fldObj,0);
	var form_field_range = fldObj.getAttribute('range');
	var msg_addition = "";
	if (form_field_range && fldObj.value.length > 0) {
		if (form_field_range.indexOf(',') > -1) { var rng = form_field_range.split(',');} //we're dealing with a list
		else if (form_field_range.indexOf('-') > -1) { var rng = form_field_range.split('-');} //we're dealing with a range
		var val_1 = rng[0]; var val_2 = (rng[1] == 'null')?'':rng[1];

		if (rng[0].indexOf('.value') > -1) val_1 = eval(rng[0]);
		if (rng[1].indexOf('.value') > -1) val_2 = eval(rng[1]);
		var form_field_value = fldObj.value;
		if (val_1 > form_field_value || (val_2.length > 2 && val_2 < form_field_value)) {
			msg_addition = msg;
	 		changeColor(frmObj,fldObj,1);
	    }  
	}
	return msg_addition;
}
 
function changeColor(frmObj,fldObj,tog) {
	fldObj.style.backgroundColor = (tog==1)?error_color:off_error_color;
	//fldObj.style.borderColor = (tog==1)?"red":"";
}

function highlightRequired(frmObj) {
	for (x=0; x < frmObj.elements.length; x++) {
		fldObj = frmObj.elements[x];
		if (fldObj.getAttribute('vrequired') == 1 || fldObj.getAttribute('vrequired') == "true" || fldObj.getAttribute('vrequired') == true)
			changeColor(frmObj,fldObj,1);
	}
 }	
 
function removeCurrency( strValue ) {
  var objRegExp = /\(/;
  var strMinus = '';
  var strValue = removeCommas(strValue);
  objRegExp = /\)|\(|[,]/g;
  strValue = (strValue)? strValue.replace(objRegExp,''):'';
  if(strValue.indexOf('$') >= 0){
    strValue = strValue.substring(1, strValue.length);
  }
  return strValue;
}

function removeCommas( strValue ) {
  return strValue.replace(',','');
}

function trimAll( strValue ) {
  var objRegExp = /^(\s*)$/;
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function showProgress(pth) {
  var strAppVersion = navigator.appVersion;
	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.userAgent.indexOf("MSIE") != -1)
      window.showModelessDialog(pth,null,"dialogWidth=375px; dialogHeight:130px; center:yes");
	else 
      window.open(pth,'','width=370,height=115', true);
  return true;
}

function loadFileCopy(abRoot) {
	var el = $xm("FileDialog");
	el.style.pixelTop = window.event.y - 140;
	el.style.pixelLeft = window.event.x - 50;	
	el.style.visibility="visible";
}

var getLookupResults = new Array();

function getDataResults(id,obj) {
	var sp = $xm(id);
	var i;
	var qryObj = obj.result;
	var rc = qryObj.RECORDCOUNT;
	var conMnu = new Array();
	for (i=0;i<rc;i++) {
		txt = qryObj.DATA.OPTION_LABEL[i];
		conMnu[i] = new Array(txt,"setName('"+id+"','"+txt+"');");
	}
	if (rc == 1) {
		setName(txt);
	} else {
		if (rc == 0) conMnu[0] = new Array("No Matches","");
		addEvent(sp,"contextmenu", function(){showMenu(sp, conMnu, e);return false; }, true);
		sp.className = "txtInputFailed";
	}
}

function setName(id,txt) {
	var sp = $xm(id);
	sp.value = txt;
	sp.setAttribute("value",txt);
	sp.className = "txtInputSuccess";
	var conMnu = new Array();
	sp.oncontextmenu = function () {
		//showMenu(sp, conMnu);
		return false;
	}
}				

function FormatField(fldObj) {
	var args = {};
	var fx = "";
	switch(fldObj.getAttribute("mask")) {
		case "usphone":
			args={varInput:fldObj.value,varMask:'us'};
			fx = 'FormatPhone';
		break;
		
	}
	MaskField(fldObj,args,fx);
}

function MaskField(fld,arg,fx) {
	getWebService('com.portalxm.courtreporter.util.format',fx,arg,null,'',function(obj){fld.value=obj.result;});
}

function setupFormHints(frmObj) {
	var fldObj;
	var hintFld;
	var req = false;
	for (x=0; x < frmObj.elements.length; x++) {
		fldObj = frmObj.elements[x];
		hintFld = fldObj.getAttribute('hint');
		addEvent(fldObj,"focus",function(e){showFormHint(e);});
		addEvent(fldObj,"blur",function(e){hideFormHint(e);});
	}	
}

function showFormHint(e) {
	var obj = (e.srcElement)?e.srcElement:e.target;
	var hintObj = $xm("XMBubbleHint");
	var hintText = obj.getAttribute("hint");
	var rowid = obj.getAttribute("rowid");
	var hintLabel = obj.getAttribute("vlabel");
	var required = obj.getAttribute("vrequired");
	var vtype = obj.getAttribute("vtype");
	//obj.className = obj.className.replace("Focus","");
	//obj.className = obj.className+"Focus";
	if (rowid != null) {
		$xm("form_row_"+rowid).className="XMFormRowFocus";
	}
	var hint = "";
	if (hintObj) {
		hint += (hintText != null && hintText != "")?"<p>"+hintText+"</p>":"";
		//hint += (required != null && required != "" && (required == "true" || required == true))?"This field is required.<br>":"";
		if (hint != "") {
			hintObj.innerHTML = hint;
			showObj(obj,"XMBubbleHint","top",false);
		}
	}
}

function hideFormHint(e) {
	var obj = (e.srcElement)?e.srcElement:e.target;
	var rowid = obj.getAttribute("rowid");
	if (rowid != null) {
		$xm("form_row_"+rowid).className="XMFormRow";
	}
	hideObj("XMBubbleHint");
	//obj.className = obj.className.replace("Focus","");
}

//START FORM SAVING CODE
function SubmitForm(frm) {
	var frmChk = frmValidCheck(frm);
	//no need to check if form is dirty (since we ARE submitting the form)
	checkBeforeLeaving = false;
	if (frmChk) frm.submit();
}

function setupForms() {
	var frms = document.forms;
	var frm,fldObj;
	//Add Div for tooltip hints
	
	var XMBubbleHint = document.createElement("DIV");
	XMBubbleHint.id = "XMBubbleHint";
	XMBubbleHint.className = "BubbleTooltip";
	
	document.body.appendChild(XMBubbleHint);
	XMBubbleHint = null;
	for (var f=0;f<frms.length;f++) {
		frm = frms[f];
		//highlightRequired(frm);
		setupFormHints(frm);
		addEvent(frm,"submit",function(e){checkBeforeLeaving=false;});
		for (var e=0;e<frm.elements.length;e++) {
			fldObj = frm.elements[e];
			if (fldObj.getAttribute("required") != null) {
				fldObj.setAttribute("vrequired",fldObj.getAttribute("required"));
				fldObj.removeAttribute("required");
			}
		}
	}
	formsSetupFormsCompleted = true;
}

function checkForms() {
	var form;
	for (var f=0;f<document.forms.length;f++) {
		form = document.forms[f];
		if (checkBeforeLeaving && isFormChanged(form)) {
        	return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
		}
	}
}

var checkBeforeLeaving = true;
function isFormChanged(frmObj) {
	if (!checkBeforeLeaving || frmObj.getAttribute("validate") == "false") return false;
	var rtnVal = false; 
	try {
		var frm = (typeof(frmObj) == "undefined")?document.forms[0]:frmObj;
		var ele = frm.elements;
		for (var i=0; i < ele.length; i++ ) {
			if ((ele[i].type) && ele[i].type.length > 0 && isElementChanged(ele,i) && ele[i].name != "") {
				rtnVal = true;
				break;
			}
		}
	} catch(e){;}
	return rtnVal;
}

function isElementChanged( ele, i ) {
	var isEleChanged = false; 
	
	//Check to see if this the hidden field for the FCKEditor
	var elId = ele[i].getAttribute("id");
	try {
		if (ele[i].type == "hidden" && $xm(elId+"___Frame")) {
			var oEditor = FCKeditorAPI.GetInstance(elId) ;
			var str = oEditor.EditorDocument.body.innerHTML;
			str = str.replace(/<P>/i,"");
			str = str.replace(/<\/P>/i,"");
			str = str.replace(/&nbsp;/i,"");
			var edtEmpty = (str.length == 0);
			if (oEditor.IsDirty() && ((edtEmpty && oEditor.StartupValue != "") || (!edtEmpty && oEditor.StartupValue == "")) ) return true;
			else return false;
		}
	} catch(e){;}
	
	switch ( ele[i].type ) { 
		case "text" : 
			if ( ele[i].value != ele[i].defaultValue ) return true;
			break;
		case "hidden" : 
			if ( ele[i].value != ele[i].defaultValue ) return true;
			break;
		case "textarea" : 
			if ( ele[i].value != ele[i].defaultValue ) return true;
			break;
		case "radio" :
			val = "";
			if ( ele[i].checked != ele[i].defaultChecked ) return true;
			break;
		case "select-one" : 
			return false; //By Pass select boxes
			for ( var x =0 ; x <ele[i].length; x++ ) {
				if ( ele[i].options[ x ].selected != ele[i].options[ x ].defaultSelected ) 
					return true;
			}
		break;
		case "select-multiple" :
			return false; //By Pass select boxes
			for ( var x =0 ; x <ele[i].length; x++ ) {
				if ( ele[i].options[ x ].selected != ele[i].options[ x ].defaultSelected ) 
					return true;
			}
			break;
		case "checkbox" :
			if ( ele[i].checked != ele[i].defaultChecked ) return true;
		default:
			return false;
			break;
	}
}

function toggleFormSection(id,flagVar) {
	var img = $xm("SectionToggleImg"+id);
	var flag = (arguments.length > 1)?flagVar:img.src.indexOf('minus') == -1;
	toggle("SectionBody"+id,flag);
	img.src=!flag?'/lib/img/icon_plus.gif':'/lib/img/icon_minus.gif';	
}

function xmform_toggleimg(selector) {

	var selectorobjids = selector.id.split("___");		
	var selectorobjdynRowIds = selector.id.split("_");			
	var selectorobjdynRowId = selectorobjdynRowIds[selectorobjdynRowIds.length-1];
	if (!isNaN(selectorobjdynRowId))	//check if is a dynamic row. Lame test
		selectorobjdynRowId = '_'+ selectorobjdynRowId;
	else 
		selectorobjdynRowId = '';
		
	var selectorobj = $xm(selectorobjids[0]+selectorobjdynRowId);
	var images = selector.imageslist.split(',');

	for (var i=0; i < images.length; i++) {	//I would like to allow for more than just on or off for the toggle
		if (selector.src.indexOf(images[i]) > -1)
			break;
	}
	
	if (i==0) //it is unchecked, so we make this the newly selected radio
	{
		selectorobj.value = selector.on;
		selector.src = images[1];
		var rows = selectorobjids[2].split('_');
		
		for (var x=0; x < 10; x++) { //assume no more than 10 sibling objects
			if (selectorobjids[2].indexOf('radioselector' + x+'_' + rows[1]) == -1 ) {
				var elementId = selectorobjids[0]+'___' + selectorobjids[1] +'___radioselector' + x + '_' + rows[1];
				var otherselectorobj = $xm(elementId);
				if (!otherselectorobj)
					break;
				otherselectorobj.src = images[0];
			}
		}
	}

}

window.onbeforeunload = function(){
	var form;
	for (var f=0;f<document.forms.length;f++) {
		form = document.forms[f];
		if (checkBeforeLeaving && isFormChanged(form)) {
          	return "You are attempting to leave this page.  If you have made any changes to the form without saving, your changes will be lost.  Are you sure you want to exit this page?";
		}
	}
};

if (!formsGlobalsLoaded) {
	addEvent(window,"load",function(){setupForms();});
	formsGlobalsLoaded = true;
}

//END FORM SAVING CODE

//Check if form is dirty and add an event handler to prevent loss of data.

function switchButton(obj) {
	var swtch = (obj.getAttribute("switch") == "on")?"off":"on";
	var hidObj = $xm(obj.getAttribute("key"));
	var lblObj = $xm(obj.getAttribute("key")+"SwitchLbl");
	obj.setAttribute("switch",swtch);
	obj.className = "Switch"+swtch;
	lblObj.innerHTML = swtch;
	hidObj.value = (swtch == "on")?1:0;
}


//END FORM CODE


var NUMBER_OF_STARS = 5;

function initRating(id,newRate) {
    var obj = $xm(id);
	if (typeof(newRate) != "undefined") obj.setAttribute("rating",newRate);
	
	var rating = obj.getAttribute("rating");
	obj.innerHTML = "";
	var uniqueid = obj.getAttribute("uniqueid");
	//obj.removeChild(obj.firstChild);
	for (var j = 0; j < NUMBER_OF_STARS; j++) {
		var star = document.createElement('img');
		if (rating >= 1) {
			star.setAttribute('src', '/lib/tag/xm/inc/rating/rating_on.png');
			star.className = 'on';
			rating--;
		} else if(rating == 0.5) {
			star.setAttribute('src', '/lib/tag/xm/inc/rating/rating_half.png');
			star.className = 'half';
			rating = 0;
		} else {
			star.setAttribute('src', '/lib/tag/xm/inc/rating/rating_off.png');
			star.className = 'off';
		}
		star.setAttribute('id', 'star_'+uniqueid+'_'+j);
		star.onclick = function() {submitRating(this.id);};
		star.onmouseover = new Function("evt", "displayHover("+uniqueid+", "+j+");");
		star.onmouseout = new Function("evt", "displayNormal("+uniqueid+", "+j+");");
		obj.appendChild(star);
	} 
}

function displayHover(ratingId, star) {
    for (var i = 0; i <= star; i++) {
        $xm('star_'+ratingId+'_'+i).setAttribute('src', '/lib/tag/xm/inc/rating/rating_over.png');
    }
}

function displayNormal(ratingId, star) {
    for (var i = 0; i <= star; i++) {
        var status = $xm('star_'+ratingId+'_'+i).className;
        $xm('star_'+ratingId+'_'+i).setAttribute('src', '/lib/tag/xm/inc/rating/rating_'+status+'.png');
    }
}

addEvent(window,"load",function(e){globalXMOnload();});
addEvent(window,"resize",function(e){globalResize();});

