///Collection
///Summary:Collection object definition.
function Collection(){
	this.Add=_add;
	this.Get=_get;
	this.Keys=_getkeys;
	this.Items=_getitems;
	this.Count=_getcount;
	this.Clear=_clear;
	this.Set=_set;
	this.Contains=_contains;
	var _items=new Array();
	var _keys=new Array();
	
	function _getkeys(){return _keys;}
	function _getitems(){return _items;}
	
	function _clear(){
		_items=new Array();
		_keys=new Array();
	}
	function _getcount(){
		if(_keys)
			return _keys.length;
		else
			return 0;
	}
	function _add(key,obj){
		_keys[_keys.length]=key;
		_items[_items.length]=obj;
	}
	function _contains(key){
		for(var j=0;j<_items.length;j++){
			if(_keys[j]==key){
				return true;
			}
		}
		return false;
	}
	function _get(key){
		for(var j=0;j<_items.length;j++){
			if(_keys[j]==key){
				return _items[j];
			}
		}
	}
	function _set(key,newvalue){
		for(var j=0;j<_items.length;j++){
			if(_keys[j]==key){
				_items[j]=newvalue;
				break;
			}
		}
	}
}
//------------------------------------------------------------
///ResizeDiv
///Summary:ResizeDiv object definition. Used to define a div to resize
function ResizeDiv(id,h_offset,w_offset){
	this.DivID=id;
	this.H_OffSet=h_offset;
	this.W_OffSet=w_offset;
}

var _SessionTimer;

//------------------------------------------------------------
///Page
///Summary:Page object definition. One is created for each html page that references this file, called thisPage
function Page(){
	this.OnKeyPress=_press;						//keypress event handler: handlername(event)
	this.OnResize=_resize;						//private
	this.DivsToResize=new Collection();			//new name/value collection object to hold a list of ResizeDiv objects that will be used to resize the div
	this.AddDivToResize=_adddiv;				//method to add a div to the DivsToResize collection: AddDivToResize(divid,h_offset,w_offset)
	this.OnLoad=_onload;						//private				
	this.SetOnResize=_setOnResize;				//Set property to set an event handler for the OnResize event
	this.SetOnEnterPress=_setOnEnterKey;		//Set property to set an event handler for the Enter key press event
	this.SetOnEscPress=_setOnEscKey;			//Set property to set an event handler for the ESC key press event
	this.SetOnLoad=_setOnLoad;					//Set property to set an event handler for the page onload event
	this.Navigate=_nav;							//method to open a new window or change pages: Navigate(url,[bNewWindow],[WindowOptions])
	this.Alert=_alert;							//method to invoke html alert box: Alert(msg)
	this.MessageBox=_msgBox;					//method to invoke html message box: MessageBox(msg)
	this.InvokeLoginDialog=_invokelogin;		//method to invoke html login dialog box: _invokelogin([bSessionTimeOut])
	this.SingleSignOnCapable=false;				//bool passed with every ajax request. not currently set
	this.SetMessageBoxOkClick=_setMsgBoxClick;	//Set property for event handler for message box OK click event
	this.SetAlertBoxOkClick=_setAlertBoxClick;  //Set property for event handler for alert box OK click event
	this.SetWorking=_setworking;				//Set property to open or close the working please wait notice
	this.CurrentAjaxRequest=null;				//type=CurrentAjaxRequest, used to store last ajax request object so it can be reinvoked after a logon query
	this.OnAjaxError=_AjaxError;				//Generic ajax error event handler (pass in ajax response object): OnAjaxError(response)
	this.OnBeforeUnLoad=_onbeforeunload;
	this.SetOnBeforeUnLoad=_setUnload;
	this.Print=_print;
	this.RegisterDetailsPane=_registerPane;     //function to add a details pane to the list. All panes in the list will be resized if the window size is less than 610 h
	this.SetOnResizeStop=_setOnResizeStop;
	this.IsBrochurePage=false;
	this.IsUserAuthenticated=false;
	this.CancelResize=false;
	
	this.Tip=_openTip;
	this.ClearTips=_clearTip;
	
	this.OpenInfoBubble=_openinfobubble;
	this.OpenInfoBubbleNow=_openinfobubbleNow;
	this.CancelInfoBubble=_cancelinfobubble;
	
	this.OnMouseUp=_mouseup;
	this.RenewSession=_renewSess;
	
	
	function _mouseup(event){
		if(thisPage.IsUserAuthenticated){
			window.clearTimeout(_SessionTimer);
			_SessionTimer=window.setTimeout('OpenSessionWarningMessage();',1080000);
			thisPage.SetMessageBoxOkClick(thisPage.RenewSession);
		}
	}
	function _renewSess(){
		var a =new AjaxMessage();
		a.SetURL('/handlers/UpdateSession.ashx');
		a.Action=3;
		a.Post();
		thisPage.SetMessageBoxOkClick(null);
	}
	
	var _timer;
	
	function _openTip(Msg,top,left,right,boolRH, boolRBT){
		TipBubble_Open(top,left,right,Msg,boolRH, boolRBT);
	}
	function _clearTip(){
		TipBubble_Close();
	}
	
	function _openinfobubbleNow(InstitutionID,e){
		var target,tempX,tempY;
		if (document.all) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
		} 
		InfoBubble_Open(tempY,tempX,InstitutionID);
		window.clearTimeout(_timer);
	}
	function _openinfobubble(InstitutionID,e){
		var target,tempX,tempY;
		if (document.all) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
		} 
		_timer=window.setTimeout('InfoBubble_Open('+tempY+','+tempX+','+InstitutionID+')',2000);
	}
	function _cancelinfobubble(e){
//		if(document.all){
//			InfoBubble_Close();
//		}else{
//			if(e.target.tagName=='DIV'){ //workaround for non-IE browsers. It was firing for the TD tag as well causing a blink
//				InfoBubble_Close();			
//			}
//		}

		window.clearTimeout(_timer);

		
	}
	
	var _aDetailPanes=new Array();
	
	function _registerPane(paneID){
		_aDetailPanes[_aDetailPanes.length]=paneID;
	}
	
	var _funcOnLoad=null;
	var _funcOnResize=null;
	var _funcOnEnterKey=null;
	var _funcOnEscKey=null;
	var _funcOnUnLoad=null;
	var _funcOnResizeStop=null;
	var _workingIndicatorQueue=new Array();
	
	function _setOnResizeStop(func){
		_funcOnResizeStop=func;
	}
	function _setUnload(func){
		_funcOnUnLoad=func;
	}
	function _setMsgBoxClick(func){
		messageMaster.SetClick(func);
	}
	function _setAlertBoxClick(func){
		alertMaster.SetClick(func);
	}
	function _setOnEnterKey(func){
		_funcOnEnterKey=func;
	}
	function _setOnEscKey(func){
		_funcOnEscKey=func;
	}
	function _setOnResize(func){
		_funcOnResize=func;
	}
	function _setOnLoad(func){
		_funcOnLoad=func;
	}
	function _setworking(value,key){
		if(key!=null){
			if(value){
				//alert('true:'+key);
				_workingIndicatorQueue[_workingIndicatorQueue.length]=key;
				document.getElementById('master_loading_parent').style.display='block';
			}else{
			//	alert('false:'+key);
				for(var k=0;k<_workingIndicatorQueue.length;k++){
					if(_workingIndicatorQueue[k]==key){
						_workingIndicatorQueue[k]=null;
						//break;
					}
				}
				var _tmp=_workingIndicatorQueue;
				_workingIndicatorQueue=new Array();
				for(var j=0;j<_tmp.length;j++){
					if(_tmp[j]!=null)
						_workingIndicatorQueue[_workingIndicatorQueue.length]=_tmp[j];
				}
				if(_workingIndicatorQueue.length==0){
					document.getElementById('master_loading_parent').style.display='none';		
				}
			}
		}else{
			var divMLP=document.getElementById('master_loading_parent');
			if(divMLP){
				if(value){
					divMLP.style.display='block';
				}else{
					divMLP.style.display='none';		
				}
			}
		}
	}
	function _print(){
		var div=document.getElementById('divContent');
		var win=window.open('/Print.aspx','printw');
		if(!win){
			thisPage.Alert('The print window could not be opened. A pop-up blocker may have blocked it, please disable any pop-up blocking software and try again.');
			return;
		}
	}
	function _AjaxError(response){
		_alert(response.Message);
		_setworking(false);		
	}
	function _press(e){
		var pK = document.all? window.event.keyCode:e.which;
		var tar = document.all? window.event.srcElement:e.target;
		if(pK==13){//enter key
			if(_funcOnEnterKey)
				_funcOnEnterKey(tar);
			if(dLogin.IsOpen){
				_dLogin_OnEnterPress();//_dLogin_OnEnterPress in defined on the master page
			}
		}
		if(pK==27){//escape key
			_setworking(false);
			if(_funcOnEscKey)
				_funcOnEscKey(tar);
		}
	}
	function _onbeforeunload(){
		if(_funcOnUnLoad)
			_funcOnUnLoad();
	}
	function _onload(){
		if(dLogin)
			dLogin.SetOnOpen(_dLogin_OnOpen);	//_dLogin_OnOpen in defined on the master page
		if(_funcOnLoad)
			_funcOnLoad();
		_resize(true);
	}
	
	function _nav(url,bNewWindow,options,UseSecureConnection){
		if(url){
			if(url!=''){
				if(!bNewWindow){
					if(UseSecureConnection){
						if(url.indexOf('http://')>-1){
							window.location=url.replace('htttp://www','https://secure');
						}else{
							if(url.indexOf('/')==0)
								window.location='https://secure.sightlines.com'+url;
							else
								window.location='https://secure.sightlines.com/'+url;
						}
					}else{
						window.location=url;
					}
				}else{
				    var nw = null;
				    if (options != null) {
				        nw = window.open(url, 'newwin', options);
				    } else {
				        nw = window.open(url, 'newwin');
				    }
					if(!nw){
						alert('the child window you have requested did not be open. Please disable any pop-up blocker software and retry.');
					}
				}
			}
		}
	}
		
	function _adddiv(divid,h_offset,w_offset){
		this.DivsToResize.Add(divid,new ResizeDiv(divid,h_offset,w_offset));
	}
	
	var _bResizeInProgress=false;
	var _timer=null;
	function _resize(bOnload){
	    if(thisPage.CancelResize){	       
	        return;
	    }
		_resizeTemplate(thisPage);
		var master=document.getElementById('master');
		var ws=document.getElementById('master_workspace');
		if(!ws)
			ws=document.getElementById('brochure_workspace');
		
		if(document.getElementById('master_menubar_more')){
			if(_menuitemcount){
				if(master.offsetWidth<(140*_menuitemcount)+10){
					document.getElementById('master_menubar_more').style.display='block';
				}else{
					document.getElementById('master_menubar_more').style.display='none';
				}	
						
			}
		}
		if(document.getElementById('menu_more_members')){
			if(_menuitemcount){
				if(master.offsetWidth<(114*_menuitemcount)+182){
					document.getElementById('menu_more_members').style.display='block';
				}else{
					document.getElementById('menu_more_members').style.display='none';
				}
			}
		}
	    
		if(_funcOnResize){
			_funcOnResize(ws.offsetWidth,ws.offsetHeight);
		}
		
		if(bOnload==null)
			bOnload=false;
		
		if(!(bOnload.toString()=='true')){
			if(document.all){
				if(!_bResizeInProgress){
					if(_timer!=null){
						window.clearTimeout(_timer);
					}
					_timer = window.setTimeout(_resizecheck, 200);
				}
			}else{
				if(_funcOnResizeStop){
					_funcOnResizeStop();
				}
			}
		}
		
	}
	function _resizecheck(){
		window.clearTimeout(_timer);
		_timer = window.setTimeout(_resizeStop, 400);
		_bResizeInProgress=true;
	}
	
	function _resizeStop(){
		window.clearTimeout(_timer);
		_bResizeInProgress=false;
		if(_funcOnResizeStop)
			_funcOnResizeStop();
	}
	
	function _resizeTemplate(thisObj){
		var master=document.getElementById('master');
		var top=document.getElementById('master_topbar');
		var logo=document.getElementById('master_logo');
		var menu=document.getElementById('master_menubar');
		var ws=document.getElementById('master_workspace');
		var bws=null;
		if(!ws){
			bws=document.getElementById('brochure_workspace');
		}
		var brn=document.getElementById('brochure_right_nav');
		
		if(master){
			var h;
			var w;
			if(document.all){
				h=document.documentElement.clientHeight;
				w=document.documentElement.clientWidth;
			}else{
				h=window.innerHeight;
				w=window.innerWidth;
			}
			
			if(thisObj.IsBrochurePage)
				w=1001;
			
			if(w<1000)
				master.style.width='1000px';
			else
				master.style.width=(w-13)+'px';
			
			if(h<720){
				for(var i=0;i<_aDetailPanes.length;i++){
					_PaneResize(_aDetailPanes[i],null,250);
				}
			}else{
				for(var i=0;i<_aDetailPanes.length;i++){
					_PaneResize(_aDetailPanes[i],null,400);
				}
			}
			
			var _hx=75;
			if(thisObj.IsBrochurePage){
				_hx=113;
			}
			
			if(h<610){
				master.style.height=(610-13)+'px';	
				if(ws)
					ws.style.height=(610-_hx)+'px';	
				if(bws){
					bws.style.height=(610-_hx)+'px';	
					brn.style.height=(610-_hx)+'px';	
				}
			}else{
				master.style.height=(h-8)+'px';
				if(ws)
					ws.style.height=(h-_hx)+'px';
				if(bws){
					bws.style.height=(h-_hx)+'px';
					brn.style.height=(h-_hx)+'px';
				}
			}
			
			if(bws){
				if(w>1000)
					bws.style.width=(w-212)+'px';
			}
			
			
			if(thisObj.DivsToResize.Count()>0){
				var o;
				for(var c=0;c<thisObj.DivsToResize.Count();c++){
					o=thisObj.DivsToResize.Items()[c];
					_resizeOther(o.DivID,o.H_OffSet,o.W_OffSet);
				}
			}
			
			
		}
	}
	
	function _resizeOther(divID,h_offset,w_offset){
		var m=document.getElementById('master');
		var div=document.getElementById(divID);
		if(div){
		
		
			if(h_offset!=null)
				div.style.height=(m.offsetHeight-h_offset)+'px';
			if(w_offset!=null)
				div.style.width=(m.offsetWidth-w_offset)+'px';
		}
	}
	
	function _alert(msg){
	 //   document.getElementById(alertMaster.ID).style.zIndex=1000000;
	    alertMaster.Alert(msg);
	}
	function _msgBox(msg){
	 //   document.getElementById(messageMaster.ID).style.zIndex=1000000;
		messageMaster.Alert(msg);
	}
	function _invokelogin(bSessionTimeOut){
		if(bSessionTimeOut)
			document.getElementById('dLogin_Heading').innerHTML='<span class=font_warning>Your Session Has Expired.</span><br>Please enter your login credentials.';
		else
			document.getElementById('dLogin_Heading').innerHTML='Please enter your login credentials.';
		dLogin.Open();
	}
}
//------------------------------------------------------------
//class for thisPage.CurrentAjaxRequest. It houses all the request parameters so that when a handler is
//requested and a login is required and the login dialog is displayed, the orginal request can be
//recreated and executed after a successful login.
function CurrentAjaxRequest(){
	this.URL=null;
	this.DataKeys=new Array();
	this.DataValues=new Array();
	this.OnCallBack=null;
	this.OnError=null;
	this.IsPost=true;
	this.ThrowErrorOnServerError=false;
	this.HadError=false;
	this.ErrorMessage=null;
	//not needed since they're already in the datakeys and datavalues arrays
	//this.Action=null;
	//this.CommandArgument=null;
}
//------------------------------------------------------------

//Create new Page object and setup the resize event handler
var thisPage=new Page();
window.onresize=thisPage.OnResize;
document.onmouseup=thisPage.OnMouseUp;
//window.onerror=__onJSerror;
//document.onclick=__closeall;

function __closeall(e){
	try{
		_closeselect(e);
		//InfoBubble_Close();
	}catch(ex){}
}


function __onJSerror(msg){
	thisPage.Alert('An application error has occurred on your client. Please refresh the current page. We apologize for the inconvenience.<br>(error: '+msg+')');
	return true;
}

var _CntDwnTimer=null;
function OpenSessionWarningMessage(){
	window.clearTimeout(_SessionTimer);
	thisPage.MessageBox("<span id=spanSessExMsg>Are you still there?<br><br>Your session will expire in <span id=spanCntDwn>2 minutes</span>.<br><br>Please click OK to resume your session.</span>");
	_CntDwnTimer=window.setInterval('UpdateCntDwn()',15000);
}
var aCntDwn=new Array();
aCntDwn[0]='1 min 45 sec';
aCntDwn[1]='1 min 30 sec';
aCntDwn[2]='1 min 15 sec';
aCntDwn[3]='1 minute';
aCntDwn[4]='45 seconds';
aCntDwn[5]='30 seconds';
aCntDwn[6]='15 seconds';
var CntDwnCnt=0;
function UpdateCntDwn(){
	if(CntDwnCnt>6){
		document.onmouseup=null;
		thisPage.SetMessageBoxOkClick(_RedirToLogin);
		document.getElementById('spanSessExMsg').innerHTML='Your session has expired.<br><br>Please login again to continue.';
		window.clearInterval(_CntDwnTimer);
		_CntDwnTimer=null;
		return;
	}
	document.getElementById('spanCntDwn').innerHTML=aCntDwn[CntDwnCnt];
	CntDwnCnt++;
}
function _RedirToLogin(){
	thisPage.Navigate('/login.aspx',false);
}

///CanAuthenticate()
///Summary: function makes an async call to TestCanAuthenticate.xml which has had anonymous access revoked in IIS
///			called from prelogin.aspx
function CanAuthenticate()
{
	try
	{
		var dom = new ActiveXObject("Msxml2.DOMDocument");
		dom.async=false;
		//dom.load("/configuration/TestCanAuthenticate.xml");
		dom.load("/handlers/IntegratedAuth.ashx");
		//dom.ondataavailable=next;
		//alert(dom.documentElement.xml);
	}
	catch(e)
	{
		//alert('error');
		return false;
	}
	return true;
}

///_PaneDisplay(paneID,display)
///Summary: used to change display property of pane
function _PaneDisplay(paneID,display){
	var d=document.getElementById(paneID);
	d.style.display=display;
}

///_PaneHide(paneID)
///Summary: function (used by benchmarking.aspx) to collapse a pane
function _PaneHide(paneID){
	var img=document.getElementById(paneID+'_hideimg');
	var d=document.getElementById(paneID);
	var b=document.getElementById(paneID+'_body');
	
	if(b){
		if(b.style.display!='none'){
			d.setAttribute('oldh',d.offsetHeight);
			b.style.display='none';
			img.src='/images/titlebar_expand.gif';
			img.alt='show';
			d.style.height='22px';
		}
	}	 
}

///_PaneShowHide(img,divID)
///Summary: show or hide a pane control's body
function _PaneShowHide(img,divID){
	var d=document.getElementById(divID);
	var b=document.getElementById(divID+'_body');
	if(d){
		if(b.style.display=='none'){
			b.style.display='block';
			img.src='/images/titlebar_collapse.gif';
			img.alt='hide';
			if(d.getAttribute('oldh')!=null){
				d.style.height=d.getAttribute('oldh')+'px';
			}
		}else{
			d.setAttribute('oldh',d.offsetHeight);
			b.style.display='none';
			img.src='/images/titlebar_expand.gif';
			img.alt='show';
			d.style.height='22px';
		}
			
	}
}

///Summary: position a pane control
function _PanePosition(paneid,t,l){
	
	var main=document.getElementById(paneid);
	if(t){
		main.style.top=t+'px';
	}
	if(l){
		main.style.left=l+'px';		
	}
}

///Summary: resize a pane control
function _PaneResize(paneid,w,h){
	var body=document.getElementById(paneid+'_body');
	var main=document.getElementById(paneid);
	if(!body)
		return;
	if(w){
		body.style.width=w+'px';
		main.style.width=w+'px';
	}
	if(h){
		body.style.height=h+'px';
		if(body.style.display!='none'){
			main.style.height=(h+30)+'px';
		}else{
			main.setAttribute('oldh',h+30);
		}
	}
}
///_PaneChangeTitle(paneid,title)
///Summary: change the title text of a pane control
function _PaneChangeTitle(paneid,title){
	var t=document.getElementById(paneid+'_title');
	t.innerHTML=title;
}
///ReadCookie(cookieName)
///Summary: returns value for a given cookie name
function ReadCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
///SetCookie(cookieName,cookieValue,nDays)
///Summary: writes cookie to disk
function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
}
///URLEncode(value)
///Summary: escapes a string
function URLEncode(value){
	return escape(value);
}
///FileType
///Summary: enum of file formats
var FileType={
	PDF:1,
	Word_Document:2,
	Excel_Spreadsheet:3,
	Power_Point_Presentation:4,
	Image:5,
	Sightlines_Application:6,
	Unknown:7
}
//GetSelectValue
//function to get the selected value from a select box
function GetSelectValue(dd){
	if(dd){
		if(dd.options.length>0)
			return dd.options[dd.selectedIndex].value;
	}
	return null;
}
//GetSelectText
//function to get the selected text from a select box
function GetSelectText(dd){
	if(dd){
		if(dd.options.length>0)
			return dd.options[dd.selectedIndex].text;
	}
	return null;
}
//SetSelectValue
//function to set the selected value of a select box
function SetSelectValueByText(dd,text){
	if(dd){
		for(var i=0;i<dd.options.length;i++){
			if(dd.options[i].text==text){
				dd.options[i].selected=true;
			}
		}
	}
}
//SetSelectValue
//function to set the selected value of a select box
function SetSelectValue(dd,value){
	if(dd){
		if(value==null)
			value='-1';
		if(value.toString()==''){
			//alert('value:'+value);
			value='-1';
		}
		for(var i=0;i<dd.options.length;i++){
//			if(dd.id.indexOf('ddStatus')>0){
//				alert(dd.id+' v:'+value+' i:'+dd.options[i].value+' '+(parseInt(dd.options[i].value)==parseInt(value)))
//			}
			if(parseInt(dd.options[i].value)==parseInt(value)){
				dd.options[i].selected=true;
			}
		}
	}
}
//SetSelectStringValue
//function to set the selected value of a select box, used when the values of the options in the select are strings and not int
function SetSelectStringValue(dd,value){
	if(dd){
		
		if(value.toString()==''){
			value='-1';
		}
		for(var i=0;i<dd.options.length;i++){
			if(dd.options[i].value.toString()==value.toString()){
				dd.options[i].selected=true;
			}
		}
	}
}
///
///helper function to see if the specified array contains the value given
function _inArray(val,array){
	for(var i=0;i<array.length;i++){
		if(array[i]==val){
			return true;
			break;
		}
	}
	return false;
}
//SetPaneContents
//function to set the inner contents of a Sightlines Pane web control
function SetPaneContents(paneid,content){
	var pane=document.getElementById(paneid+'_body')
	if(pane)
		pane.innerHTML=content;
}
//ExportAjaxGridToExcel
//function to export the contents of an AjaxGrid control to excel
//the function converts the grid control's datasource into xml
//then places that xml in a form defined on the master page
//this form is them posted to the exporttoexcel handler 
//that then creates the xls file
function ExportAjaxGridToExcel(grid,filename){
	var frm=document.getElementById('frmExportToExcel');
	if(frm){
		var contents=document.getElementById('hidContents');
		var fn=document.getElementById('hidFilename');
		fn.value=filename;
		var table=grid.DataSourceTable;
		
		if(table.RowArray.length==0)
			return;
		if(table.ColumnArray.length==0)
			return;
		
		var xdoc=new XMLDom();
		xdoc.AddRoot('DataTable');
		var elCols=new XMLElement();
		elCols.TagName='Columns';
		var colIndxArray=new Array();
		var elCol;
		for(var c=0;c<table.ColumnArray.length;c++){
			if(table.ColumnArray[c].ColumnName.substring(0,5)!='empty'){
				elCol=new XMLElement();
				elCol.TagName='Column';
				elCol.Value=table.ColumnArray[c].ColumnName;
				elCols.AddChild(elCol);
				colIndxArray[colIndxArray.length]=c;
			}
		}
		xdoc.AddElementByObj(elCols);
		
		
		var elRows=new XMLElement();
		elRows.TagName='Rows';
		var elRow;
		for(var r=0;r<table.RowArray.length;r++){
			elRow=new XMLElement();
			elRow.TagName='Row';
			var elItem;
			for(var i=0;i<colIndxArray.length;i++){
				elItem=new XMLElement();
				elItem.TagName='Item';
				if(table.RowArray[r].ItemArray[colIndxArray[i]])
					elItem.Value=table.RowArray[r].ItemArray[colIndxArray[i]].toString().replace('&nbsp;',' ').replace('&',' and ');
				else
					elItem.Value='';
				elRow.AddChild(elItem);
			}
			elRows.AddChild(elRow);
		}
		xdoc.AddElementByObj(elRows);
		
		contents.value=xdoc.toXML();
		//uncomment this stuff out when we get T&C text
		//if(ReadCookie('rememberTC')=='true'){
		//	master_SetcbRememberTCStatus(true);
			ExportToExcelTermsAndConditionsAgree();
			return;
		//}
		//dgTermsAndConditions.Open();
		
	}
}
//ExportToExcelTermsAndConditionsAgree
//function is called either from the I Agree button on the T&C diaglog or from ExportAjaxGridToExcel if the T&C has already been agreed too.
function ExportToExcelTermsAndConditionsAgree(){
	if(master_cbRememberTCIsChecked()){
		SetCookie('rememberTC','true',30);
	}else{
		SetCookie('rememberTC','false',30);		
	}
	try{
		dgTermsAndConditions.Close();	
	}catch(ex){}
	var filename=document.getElementById('hidFilename').value;
	var frm=document.getElementById('frmExportToExcel');
	frm.action='/handlers/ExportToExcel.ashx?Action='+ExportAjaxGridToExcelActions.ExportAjaxGridDataTable+'&FileName='+filename;
	frm.submit();	
}
//enum for ExportAjaxGridToExcel
var ExportAjaxGridToExcelActions={
	ExportAjaxGridDataTable:2
}
///SetCheckBoxListValues
///helper function to set the checked checkboxes in a checkbox list
function SetCheckBoxListValues(cblID,selectedValueArray){
	var cblMain=document.getElementById(cblID);
	var cbs=cblMain.getElementsByTagName('input');
	
	if(cbs.length>0){
		if(selectedValueArray){
			for(var i=0;i<cbs.length;i++){
				var cb=document.getElementById(cblID+'_'+i);
				cb.checked=_inArray(cb.value,selectedValueArray);
			}
		}else{
			for(var i=0;i<cbs.length;i++){
				var cb=document.getElementById(cblID+'_'+i);
				cb.checked=false;
			}
		}
	}
}
function _openinfobubble(InstitutionID,e){
		var target,tempX,tempY;
		if (document.all) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
		} 
		_timer=window.setTimeout('InfoBubble_Open('+tempY+','+tempX+','+InstitutionID+')',2000);
}
	
///GetCheckBoxListValues
///helper function to get the checked checkboxes in a checkbox list
function GetCheckBoxListValues(cblID){
	var cblMain=document.getElementById(cblID);
	var cbs=cblMain.getElementsByTagName('input');
	var ret='';
	
	if(cbs.length>0){
		for(var i=0;i<cbs.length;i++){
			var cb=document.getElementById(cblID+'_'+i);
			if(cb.checked){
				ret+=cb.value+',';
			}
		}
	}
	if(ret!='')
		ret=ret.substring(0,ret.length-1);
	return ret;
}
///GetRadioButtonListValue
///helper function to get the selected radio button from a radiobuttonlist
function GetRadioButtonListValue(groupname){
	var g=document.getElementsByName(groupname);
	for(var i=0;i<g.length;i++){
		if(g[i].checked){
			return g[i].value;
		}
	}
}

///SetRadioButtonListValue
///helper function to set the selected radio button in a radiobuttonlist
function SetRadioButtonListValue(groupname,val){
	var g=document.getElementsByName(groupname);
	for(var i=0;i<g.length;i++){
		if(g[i].value==val){
			g[i].checked=true;
		}else{
			g[i].checked=false;		
		}
	}
}

///SetCheckBoxListSelectAll
///helper function select or deselect all the items in a checkbox list
function SetCheckBoxListSelectAll(cblID,selectAll){
	var cblMain=document.getElementById(cblID);
	var cbs=cblMain.getElementsByTagName('input');
	
	if(cbs.length>0){
		for(var i=0;i<cbs.length;i++){
			var cb=document.getElementById(cblID+'_'+i);
			cb.checked=selectAll;
		}
	}
}

function SetCheckBoxListEnabled(cblID,enabled){
	var cblMain=document.getElementById(cblID);
	var cbs=cblMain.getElementsByTagName('input');
	
	if(cbs.length>0){
		for(var i=0;i<cbs.length;i++){
			var cb=document.getElementById(cblID+'_'+i);
			cb.disabled=!enabled;
		}
	}
}

function swap(obj,cls){
	if(obj)
		obj.className=cls;
}

///ResizeDropDown
///function to resize a dropdown input
function ResizeDropDown(dd,Width){
	if(dd){
		dd.style.width=Width+'px';
	}
}

///addCommas
///function to add commas to a number
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function DisplayInfoBubble_Click(cb){
	if(cb.checked){
		SetCookie('InfoBubble','on',365);
	}else{
		thisPage.MessageBox('The campus information bubble will no longer be shown for this and all subsequent sessions. To turn the information bubble back on check the "Display campus information" checkbox.');
		SetCookie('InfoBubble','off',365);		
	}
}

function _AlertFromChild(msg){
	thisPage.Alert(msg);
}

function FormatCurrency(dec){
	var x,x1,x2;
	var nStr= dec.toFixed(2);
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return '$ '+x1 + x2;
}


function findPosY(oElement)
{
    var iReturnValue = 0;
    while( oElement != null ) {
        if(! isNaN(oElement.offsetTop))
            iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function findPosX(oElement)
{
    var iReturnValue = 0;
    while( oElement != null ) {
        if(! isNaN(oElement.offsetLeft))
            iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
