var IE = (document.all) ?true:false;
var IE6 = getInternetExplorerVersion()==6;

var NS6 = (document.getElementById) ?true:false;

var currentWindowWidth = 800;
var currentWindowHeight = 600;

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function setupWindowSizeVars()
{
	
	if (IE) {
		currentWindowWidth=document.body.offsetWidth;
		currentWindowHeight=document.body.offsetHeight;
	}
	else if (window.innerWidth) {
		currentWindowWidth=window.innerWidth - 13;
		currentWindowHeight=window.innerHeight;
	}
}

var amt_mins = 0;
var amt_mins2 = 0;

// turned this check off when implemented timeout alert mechanism 
//var oInterval = window.setInterval("incTime()", 60000); // check every minute

function incTime() 
{
	amt_mins++;
	amt_mins2++;
	
	if (amt_mins > 1)
		window.status = 'Idle for ' + amt_mins + ' mins';
	if (amt_mins >= max_mins)
		location.href='logout.php?page=./%3Fstatus%3DYour%2BSession%2BTimed%2BOut.%2BPlease%2Blogin%2Bagain.';
}

function resetTime()
{
	window.status = '';
	anyUserActivity = true;
	return;
	
	amt_mins = 0;
	
	if (amt_mins2 > 0) {
		if (document.timerpic && document.images)
			document.timerpic.src = 'timerpic.php';
		
		amt_mins2 = 0;
	}
}

function helpWd()
{
	var page = 'help.php';
	
	if (helpWd.arguments.length == 1) {
		page += '?section=' + helpWd.arguments[0];
	}
	
	helpwin = window.open(page, 'BigPic', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=400'); 
	helpwin.focus();
}

function newWd(page, width, height /*, scrollbars [optional], resizable [optional], modal [optional] */)
{	
	var putItThere = null; 
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var w = 0;
	var h = 0;
	var scrollbars = true;
	var resizable = true;
	var modal = false;
	if (modal) confirm('modal');
	if (newWd.arguments.length >= 4) {
		scrollbars = newWd.arguments[3];
		if (newWd.arguments.length >= 5) {
			resizable = newWd.arguments[4];
			if (newWd.arguments.length >= 6) {
				modal = newWd.arguments[5];
			}
		}
	}
	if (window.showModalDialog && modal) 
		var newwin = window.showModalDialog(page, 'BigPic'+width, 'status:no;dialogWidth:'+width+'px;dialogHeight:'+height+'px;dialogLeft:' + ((chasm - w - 10) * .5) + ';dialogTop:' + ((mount - h - 200) * .5)+ ';scroll:'+((scrollbars) ? 'yes' : 'no')+';resizable='+((resizable) ? 'yes' : 'no')); 
	else 
		var newwin = window.open(page, 'BigPic'+width, 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,modal='+((modal) ? 'yes' : 'no')+',scrollbars='+((scrollbars) ? 'yes' : 'no')+',resizable='+((resizable) ? 'yes' : 'no')+',width='+width+',height='+height+',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 200) * .5)); 
		
	if (!modal)
		newwin.focus();
	return false;
}

function showUploadWd() {
	newWd('uploading.html',250,90);
}

function showLoggingInWd() {
	newWd('loggingin.html',250,90);
}

function showUpdater(visibility){
	var visMode = (visibility == 'hide'?'hide':'visible');
	if (document.theForm)
		if (document.theForm.updated_form)
				document.theForm.updated_form.value=true;
	
	if (document.getElementById) {	
		if (document.getElementById("message1")) {
			document.getElementById("message1").style.visibility = visMode;
			document.getElementById("message1").style.display = 'block';
		}
		if (document.getElementById("message2")) {
			document.getElementById("message2").style.visibility = visMode;
			document.getElementById("message2").style.display = 'block';
		}
	}
	else {
		if (document.all['message1'])
			document.all['message1'].style.visibility = visMode;
		if (document.all['message1'])
			document.all['message1'].style.display = 'block';
		if (document.all['message2'])
			document.all['message2'].style.visibility = visMode;
		if (document.all['message2'])
			document.all['message2'].style.display = 'block';
	}
	setPageUpdated();
}

/* ***********************************************************************************************
   UPDATER LOGIC - 
   when setPageUpdated() is called (either directly or from showUpdater()):
   		1) a page trap is set to prompt before navigating away from the page 
   		2) any buttons on the page named 'update' (or in list below) have their onclick event modified to prevent 
   		   a prompt when they are clicked.
*/
   
var trapUpdaterBypass = false;
var pageUpdated = false;

// look for FCKeditor textareas and add an onchange event that calls setPageUpdated

function myOnPaste(fck){
	setPageUpdated();
	var data = fck.GetClipboardHTML();
	fck.InsertHtml(data);
	return false;
}

function FCKeditor_OnComplete( editorInstance )
{
    editorInstance.Events.AttachEvent( 'OnSelectionChange', setPageUpdated ) ;
    editorInstance.Events.AttachEvent( 'OnPaste', myOnPaste ) ;
} 

function setPageNotUpdated() {
	pageUpdated = false;
}

function setPageUpdated() {
	if (pageUpdated) 
		return;

	pageUpdated = true;

	// call this function at the top of a page that calls showUpdater, to set pageunload trapping. if showUpdater was called
	// at any time, trapUpdater will prompt the user prior to navigating to doing another GET or POST

	// look for a button whose first word is one of a list, and set an onclick event on it to bypass page prompting 
	// the idea is that if there is a button on a page with this name, it is a submission of information and not a
	// navigation away from the page before saving uncommitted information 
	var ahref = document.getElementsByTagName('a');	
	for(var no=0;no<ahref.length;no++) {
		if (ahref[no].href.search("dtabSelectTab") != -1)		
			ahref[no].onmouseup = function() { trapUpdaterBypass = true; }
	}
	
	var links = document.getElementsByTagName('input');	
	for(var no=0;no<links.length;no++) {
		button_words = links[no].defaultValue.toLowerCase().split( /[\s+|\/]/ );

		if (links[no].id != 'search_query') {
			if (button_words[0]=='update' || 
				button_words[0]=='submit' || 
				button_words[0]=='insert' || 
				button_words[0]=='change' || 
				button_words[0]=='new' || 
				button_words[0]=='edit' || 
				button_words[0]=='save' || 
				button_words[0]=='done' || 
				button_words[0]=='post' || 
				button_words[0]=='discharge' || 
				button_words[0]=='archive' || 
				button_words[0]=='unarchive' || 
				button_words[0]=='publish' || 
				button_words[0]=='add') 
				links[no].onmouseup = function() { trapUpdaterBypass = true; }
		}
	}
	
	addEvent(window, 'beforeunload', checkPageChanged);
}

function checkPageChanged(evt) {
	if (trapUpdaterBypass) {
		trapUpdaterBypass = false;
		return;
	}
	var confMsg = "You have made changes on this page without saving.";

	if (pageUpdated) {
		if (typeof evt == 'undefined') {
			evt = window.event;
		}
		if (evt) {
			evt.returnValue = confMsg;
		}
		return confMsg;
	}
  	// no changes - return nothing      
}

/* END OF UPDATER LOGIC 
************************************************************************************************/

function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function checkAmount(frmFld)
{	
	var places = 2;
	if(checkAmount.arguments.length > 1)
		places = checkAmount.arguments[1];
	if (!validateDollars(frmFld)) {
		frmFld = '0.00';
		alert("Invalid Amount");
		return false;
	}
	else {
		frmFld= dollars(frmFld,places);
		return true;
	}
}

// round to 2 decimal places
function dollars(x) 
{	
var places = 2;
var zeroes='';
var amount;
var roundto;
if(dollars.arguments.length > 1)
	places = dollars.arguments[1];
for(var i=0; i < places ;i++){
	zeroes +='0' 
}
roundto = parseInt(1 + zeroes);
// round number
amount = Math.round(x*roundto)/roundto;
// convert to string
amount = amount.toString();
// get position of decimal
dPlace = amount.indexOf('.',0);


if (dPlace == -1)  // no decimal found
	return amount + '.' + zeroes;
	//return amount + '.00';
else {
	decimals = amount.substring(dPlace+1,amount.length);	
	if (decimals.length == places)
		return amount;
	else
		return amount + '0';
}
}

function validateDollars(string) 
{
if (!string) return false;
var chars = "0123456789.";

for (var i = 0; i < string.length; i++) {
   if (chars.indexOf(string.charAt(i)) == -1)
      return false;
}
return true;
}

function trunc(string){
	/* remove leading and trailing spaces*/
	var myString = string.replace(/\s*/,"");
	myString = myString.replace(/\s+$/,"");
	return myString;
}

function showSplit(e,div_ref,str,str_left)
{
	var split_display;
	var div;
	
	if (document.getElementById) {
		split_display = document.getElementById('split_display');
		div = document.getElementById(div_ref);
	}
	else if (document.all) {
		split_display = document.all['split_display'];
		div = document.all[div_ref];
	}
	else {
		return false;
	}
	
	if(document.all)e = event;
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var windowwidth = IE? document.body.clientWidth: window.innerWidth;
	var leftPos = e.clientX + 70;
	var rightPos=e.clientX + split_display.offsetWidth + 70;
	if(rightPos>(windowwidth)) {
		split_display.innerHTML = str_left;
		leftPos = e.clientX - split_display.offsetWidth - 70;
	} else
		split_display.innerHTML = str;

	if(leftPos<0)leftPos = 0;
	split_display.style.left = leftPos + 'px';
	split_display.style.top = e.clientY - div.offsetHeight -1 + st + 'px';
	split_display.style.visibility = 'visible';
	return true;
}

function hideSplit()
{
	var split_display;
	
	if (document.getElementById) {
		split_display = document.getElementById('split_display');
	}
	else if (document.all) {
		split_display = document.all['split_display'];
	}
	else {
		return false;
	}
	
	split_display.style.visibility = 'hidden';
	return true;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// calendar functions

function togglePulldown(key){
	var pulldown;
	if (IE) {
		pulldown = (key == 1) ? pulldown1 : pulldown2;
		pulldown.style.visibility = (pulldown.style.visibility == 'visible') ? "hidden" : "visible";
	}
	else if (NS6) {
		pulldown = 'pulldown'+key;
		document.getElementById(pulldown).style.visibility = (document.getElementById(pulldown).style.visibility  == 'visible') ? "hidden" : "visible";
	}
}

function setDisplay(d){
	var id=d;
	var text;
	
	if (IE)
		text=document.all["event"+id];
	else
		text=document.getElementById("event"+id);	

	if (text)
		text.style.visibility='visible';
}

function resetDisplay(d){
	var id=d;
	var text;
	
	if (IE)
		text=document.all["event"+id];
	else
		text=document.getElementById("event"+id);	
	if (text)
		text.style.visibility='hidden';
}


function _getElement(id)
{
	if (document.getElementById && document.getElementById(id)) {
		return document.getElementById(id);
	}
	else if (document.all && document.all[id]) {
		return document.all[id];
	}
	else {
		return false;
	}
}

function setBlockDisplay(id,display_type)
{
	_getElement(id).style.display = display_type;
}

var displayType = (IE) ? 'block' : 'table-row-group';

function toggleBlock(id,state)
{
	_getElement(id).style.display = (state) ? displayType : 'none';
}

function getSelectedValue(select)
{
	if (!select ||
		select.options == null || 
		!select.options || 
		select.options.length == 0) {
			return '';
	}
	
	return select.options[select.selectedIndex].value;	
}

function getElementsByClass(classname)
{
	var rootobj=document.all? document.all : document.getElementsByTagName("*");
	
	var temparray=new Array();
	var inc=0;
	var rootlength=rootobj.length;
	
	for (var i=0; i<rootlength; i++){
		if (rootobj[i].className==classname)
			temparray[inc++]=rootobj[i];
	}
	
	return temparray;
}

function setPointer(theRow,classn)
{
	if (typeof(theRow.style) == 'undefined') {
        return false;
    }
    
    /*
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        	theRow.cells[c].bgColor = thePointerColor;
    }*/
    
    theRow.className = classn;
}

function isIdVisible(id)
{
	var elem = _getElement(id);
	if (elem) 
	{ 
		return (!(elem.style.display == 'none' || elem.style.display=='' ));
    } else 
    	return false;
}

function showHideContent(id,show,txtLinkId,txtShow,txtHide)
// if txtLinkId is given, it is the css id of the text link to toggle between 'txtShow' and 'txtHide' values
// if id is an array (typeof=object), then apply the show/hide to each DIV id in that array
{
//  var elem = document.getElementById(id);
  var txtElem = _getElement(txtLinkId);
  var idArr = new Array();

  /* build array of ids to process - if parm 'id' is object, then extract ids from it, if part is string, just add it */
  if (typeof(id)=='object') {
  	for(var no=0;no<id.length;no++) {
  		idArr[idArr.length]=id[no];
  	}
  } else {
  	idArr[idArr.length]=id;
  }

  for(var no=0;no<idArr.length;no++) {
	  var elem = _getElement(idArr[no]);
	  if (elem) 
	  { 
	    if (show == 'toggle') 
	    { 
	    	if (elem.style.display == 'none' || elem.style.display=='' ) {
	    		//elem.style.display = 'block';
	    		setBlockDisplay(idArr[no],'block')
	    		elem.style.visibility = 'visible';
	    		if (txtElem) txtElem.innerHTML = txtHide;
	    	} else {
	    		//elem.style.display = 'none';
	    		setBlockDisplay(idArr[no],'none')
	    		if (!IE) {
	    			elem.style.visibility = 'collapse';
	    		}
	   			if (txtElem) txtElem.innerHTML = txtShow;
	    	}
	    }
	    else if (show == 'show') 
	    { 
	      //elem.style.display = 'block';
	      setBlockDisplay(idArr[no],'block')
	      elem.style.visibility = 'visible';
	      if (txtElem) txtElem.innerHTML = txtHide;
	    } 
	    else
	    { 
	      //elem.style.display = 'none';
	      setBlockDisplay(idArr[no],'none')
	      if (!IE) {
	      	elem.style.visibility = 'collapse';
	      	if (txtElem) txtElem.innerHTML = txtShow;
	      }
	    }
	  }
  }
}   

function expandContractContent(id,show,txtLinkId,txtExpand,txtContract,contractHeight)
// if txtLinkId is given, it is the css id of the text link to toggle between 'txtShow' and 'txtHide' values
// contractHeight is the height of the div when in contracted mode; expanded is always 'auto'
// if id is an array (typeof=object), then apply the show/hide to each DIV id in that array
{
//  var elem = document.getElementById(id);
  var txtElem = _getElement(txtLinkId);
  var idArr = new Array();

  /* build array of ids to process - if parm 'id' is object, then extract ids from it, if part is string, just add it */
  if (typeof(id)=='object') {
  	for(var no=0;no<id.length;no++) {
  		idArr[idArr.length]=id[no];
  	}
  } else {
  	idArr[idArr.length]=id;
  }

  for(var no=0;no<idArr.length;no++) {
	  var elem = _getElement(idArr[no]);
	 
	  if (elem) 
	  { 
	    if (show == 'toggle') 
	    { 
	    	if (elem.style.height == 'auto' || elem.style.height=='' ) {
	    		elem.style.height=contractHeight;
	    		if (txtElem) txtElem.innerHTML = txtContract;
	    	} else {
	    		//elem.style.display = 'none';
	    		elem.style.height='auto';
	   			if (txtElem) txtElem.innerHTML = txtExpand;
	    	}
	    }
	    else if (show == 'show') 
	    { 
    		elem.style.height=contractHeight;
    		if (txtElem) txtElem.innerHTML = txtContract;
	    } 
	    else
	    { 
    		elem.style.height='auto';
   			if (txtElem) txtElem.innerHTML = txtExpand;
	    }
	  }
  }
}   
var ajaxDel;
function deleteWfile(node_id,file,parentpage) {
	if (confirm('Are you sure you would want to delete this file "'+file+'"?')) { 
		ajaxDel = new sack();
		ajaxDel.requestFile = 'browse_web_drive.php?mode=deletewfile&filename=' + file + '&parentpage='+parentpage;
		ajaxDel.onCompletion = function() {
			if (ajaxDel.response && ajaxDel.response.length > 0)
				alert(ajaxDel.response);
			else 
				refreshTreeNode(node_id);
			ajaxDel = false; 
		};
		ajaxDel.runAJAX();
	}
	return false;

}

/* DHTML tabs area - for top of forum pages */
var dtabIds = new Array();
var dtabCurrentTab = 0; //current selected tab
var dtabCurrentCaption  = ""; //curent selected caption

function dtabSetup(tabArea,navbarClassName,initTab,initTabActive) {
	// This routine scans the page for DIVs with a class of 'dtab'. Then dynamically , it inserts a UL-LI list in the
	// tabArea DIV, consisting of the dtab DIVs it found. Each LI is css-formatted to a navbar tab and when clicked, enables
	// that tab and shows the dtab DIV associated with (hiding the other tabs associated DIVs)
	
	// Steps to implement:
	// 1. Put this where you want the tab navbar:
	//	  <div id="navcontainer"></div>
	// 2. Put this in front of all of your tab content DIVs (put a </div> after them all):
	//    <div id="dtabcontent">
	// 3. Put this in front of each tab content area (class must equal 'dtab', but caption is what shows on the tab:
	//	  <div class="dtab" caption="tab caption goes here">
	// 4. Execute this script after all DIVs are closed like this (this is already done in /members/office.php):
	//	  /* div id for tabs,starting tab,navbarclassname  */ 
	//	  dtabSetup("dtabcontainer","caption of initial selected tab","dtabnavlist");
	
	// Parameters:
	// tabArea is the DIV id where the navbar goes
	// initTab is the caption text of the tab to select on startup
	// navbarClassName is the CSS class name of the navbar
	// initTabActive is passed to 
	// call this function at the bottom of a page that contains tabs

	if (tabArea=='') 			tabArea='dtabcontainer';
	if (navbarClassName=='')	navbarClassName = 'dtabnavlist';

	var navbar = document.getElementById(tabArea);
	if (!navbar) return;
	var el = document.createElement("UL");
	el.className = navbarClassName;

	/* look for a DIVs with a class of 'dtab' - save their ids in an array & build tab navbar via DOM */
	var divs = document.getElementsByTagName('div');	
	for(var no=0;no<divs.length;no++) {
		if (divs[no].className=='dtab') {
			var eLI = document.createElement("LI")
			var eALink = document.createElement("A");
			var divObj = new Object;
//			divObj.id = divs[no].id;
			divs[no].id = "__dtabPanel" + no;
			divObj.id   = "__dtabPanel" + no;
			divObj.caption = divs[no].getAttribute('caption');
			divObj.ajaxinit = divs[no].getAttribute('ajaxinit');
			divObj.caching = divs[no].getAttribute('caching')!='false';
			divObj.ajaxpostjs = divs[no].getAttribute('ajaxpostjs');
			divObj.linkhilite = false;
			dtabIds[dtabIds.length] = divObj;
			eALink.href = "javascript:dtabSelectTab('"+divObj.caption+"')";
			eALink.onclick= function() {trapUpdaterBypass = true;};	//handles case where IE thinks page is unloading if a link with a "href" is clicked; this is reset inside dtabSelectTab
			try 
				{if (divs[no].onclick) 
					var onclick_exists = true;
				}
			catch (err) {
				var onclick_exists = false;
			}
			if (onclick_exists) {
			
				eALink.onclick = divs[no].onclick;
				divs[no].onclick='';
			}
//				eALink.href = eALink.href + ';document.getElementById(\''+divs[no].id+'\').onclick();';
			eALink.id = "__dtablink" + divObj.id;
			var eLIText = document.createTextNode(divObj.caption);
			eALink.appendChild(eLIText);

			/* save the initialization ajax url */
			var eLIAttr1 = document.createAttribute("ajaxinit");
			eLIAttr1.nodeValue = divObj.ajaxinit;
			eALink.setAttributeNode(eLIAttr1);

			/* save the post ajax execution js script */
			var eLIAttr2 = document.createAttribute("ajaxpostjs");
			eLIAttr2.nodeValue = divObj.ajaxpostjs;
			eALink.setAttributeNode(eLIAttr2);
			eLI.appendChild(eALink);
			el.appendChild(eLI);
		}
	}
	navbar.appendChild(el);
	dtabSelectTab(initTab);
	dtabSetActiveALink(initTabActive); /* sets initial state of initial tab*/
	
//<div id="dtab">
//	<ul id="navlist">
//		<li><a id="link0" href="javascript:selectTab('0')" class="current">Introduction</a></li>
//		<li><a id="link1" href="javascript:selectTab('1')">library</a></li>
//		<li><a id="link2" href="javascript:selectTab('2')">participants</a></li>
//		<li><a id="link3" href="javascript:selectTab('3')">Item three</a></li>
//		<li><a id="link4" href="javascript:selectTab('4')">topics</a></li>
//		<li><a id="link5" href="javascript:selectTab('5')">archive</a></li>
//		<li><a id="link6" href="javascript:selectTab('6')">help</a></li>
//	</ul>
//</div>		
		
}

function dtabClearAllTabs() {
	for(k=0;k<dtabIds.length;k++) {
		document.getElementById("__dtablink" + dtabIds[k].id).className='normal';
		document.getElementById(dtabIds[k].id).style.display='none';
	}
}

function dtabSetActiveALink(bool) {
	dtabIds[dtabCurrentTab].linkhilite = bool;
	if (dtabIds[dtabCurrentTab].linkhilite && document.getElementById("__dtablink" + dtabIds[dtabCurrentTab].id).onclick)
		document.getElementById("__dtablink" + dtabIds[dtabCurrentTab].id).className='current link';
	else
		document.getElementById("__dtablink" + dtabIds[dtabCurrentTab].id).className='current';
}

function dtabSelectTab(caption) {
	dtabClearAllTabs();
	trapUpdaterBypass = false;  //
	for(var no=0;no<dtabIds.length;no++) {
		if (dtabIds[no].caption==caption) {
			if (dtabIds[no].ajaxinit && (document.getElementById(dtabIds[no].id).innerHTML=='' || !dtabIds[no].caching) ) {
				ajax_loadContent(dtabIds[no].id,dtabIds[no].ajaxinit,!dtabIds[no].caching,dtabIds[no].ajaxpostjs);
			}
			dtabCurrentTab = no;
			dtabCurrentCaption = caption;
			if (dtabIds[no].linkhilite && document.getElementById("__dtablink" + dtabIds[no].id).onclick)
				document.getElementById("__dtablink" + dtabIds[no].id).className='current link';
			else
				document.getElementById("__dtablink" + dtabIds[no].id).className='current';
			document.getElementById(dtabIds[no].id).style.display='inline';
		}
	}
}

function dtabRefreshTab(caption,passedparm,replaceurl) {
	for(var no=0;no<dtabIds.length;no++) {
		if (dtabIds[no].caption==caption) {
			if (dtabIds[no].ajaxinit) {
				if (replaceurl)
					ajax_loadContent(dtabIds[no].id,((typeof passedparm == "undefined")?'':passedparm),1,dtabIds[no].ajaxpostjs);
				else
					ajax_loadContent(dtabIds[no].id,dtabIds[no].ajaxinit+((typeof passedparm == "undefined")?'':passedparm),1,dtabIds[no].ajaxpostjs);
			}
		}
	}
}

/* end of DHTML tabs area */

/*
 * Javascript Diff Algorithm
 *  By John Resig (http://ejohn.org/)
 *
 * More Info:
 *  http://ejohn.org/projects/javascript-diff-algorithm/
 */

function diffString( o, n ) {
  var out = diff( o.split(/\s+/), n.split(/\s+/) );
  var str = "";

  for ( var i = 0; i < out.n.length - 1; i++ ) {
    if ( out.n[i].text == null ) {
      if ( out.n[i].indexOf('"') == -1 && out.n[i].indexOf('<') == -1 )
        str += "<ins style='background:#E6FFE6;'> " + out.n[i] +"</ins>";
      else
        str += " " + out.n[i];
    } else {
      var pre = "";
      if ( out.n[i].text.indexOf('"') == -1 && out.n[i].text.indexOf('<') == -1 ) {
        
        var n = out.n[i].row + 1;
        while ( n < out.o.length && out.o[n].text == null ) {
          if ( out.o[n].indexOf('"') == -1 && out.o[n].indexOf('<') == -1 && out.o[n].indexOf(':') == -1 && out.o[n].indexOf(';') == -1 )
            pre += " <del style='background:#FFE6E6;'>" + out.o[n] +" </del>";
          n++;
        }
      }
      str += " " + out.n[i].text + pre;
    }
  }
  
  return str;
}

function diff( o, n ) {
  var ns = new Array();
  var os = new Array();
  
  for ( var i = 0; i < n.length; i++ ) {
    if ( ns[ n[i] ] == null )
      ns[ n[i] ] = { rows: new Array(), o: null };
    ns[ n[i] ].rows.push( i );
  }
  
  for ( var i = 0; i < o.length; i++ ) {
    if ( os[ o[i] ] == null )
      os[ o[i] ] = { rows: new Array(), n: null };
    os[ o[i] ].rows.push( i );
  }
  
  for ( var i in ns ) {
    if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) {
      n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
      o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
    }
  }
  
  for ( var i = 0; i < n.length - 1; i++ ) {
    if ( n[i].text != null && n[i+1].text == null && o[ n[i].row + 1 ].text == null && 
         n[i+1] == o[ n[i].row + 1 ] ) {
      n[i+1] = { text: n[i+1], row: n[i].row + 1 };
      o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 };
    }
  }
  
  for ( var i = n.length - 1; i > 0; i-- ) {
    if ( n[i].text != null && n[i-1].text == null && o[ n[i].row - 1 ].text == null && 
         n[i-1] == o[ n[i].row - 1 ] ) {
      n[i-1] = { text: n[i-1], row: n[i].row - 1 };
      o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 };
    }
  }
  
  return { o: o, n: n };
}
 /* end of Javascript Diff Algorithm */
 

 /* 
	START of modal message routines
*/

/*
EXAMPLES OF USAGE:
<a href="#" onclick="displayMessage('includes/demo-modal-message-1.inc');return false">Message from url (example 1)</a><br> 

<a href="#" onclick="displayMessage('includes/demo-modal-message-2.inc');return false">Message from url (example 2)</a><br> 

<a href="#" onclick="displayMessage('includes/demo-modal-message-3.inc');return false">Alternative confirm dialog (example 3)</a>

<a href="#" onclick="displayStaticMessage('<h1>Static message</h1><p>This is a static message</p><p><a href=\'#\' onclick=\'closeMessage();return false\'>Close</a>',false);setTimeout('closeMessage();window.location=\'www.google.com\';',4000);return false">Static message (Example 1)</a><br>

<a href="#" onclick="displayStaticMessage('<h1>Error message</h1><p>This is a static message with a different layout(css class)</p><p><a href=\'#\' onclick=\'closeMessage();return false\'>Close</a>','modalDialog_contentDiv_error');return false">Static message (Example 2 - different layout)</a>
*/

var messageObjPopup;          //modal dialog for other uses
function displayPopup(url,width,height,cache)
{
	if (width=='') width=400;
	if (height=='') height=200;
	if (cache=='') cache=true;
	messageObjPopup.setSource(url);
	messageObjPopup.setCssClassMessageBox(false);
	messageObjPopup.setSize(width,height);
	messageObjPopup.setShadowDivVisible(true);			// Enable shadow for these boxes
	messageObjPopup.setCache(false);					// Enable cache by default
	var clsName = 'modalDialog_transparentDivs';	  	//dimmed
	messageObjPopup.display(clsName);
}

function displayPopupStatic(messageContent,width,height,cache)
{
	if (width=='') width=400;
	if (height=='') height=200;
	if (cache=='') cache=true;
	messageObjPopup.setHtmlContent(messageContent);
	messageObjPopup.setSource(false);
	messageObjPopup.setCssClassMessageBox(false);
	messageObjPopup.setSize(width,height);
	messageObjPopup.setShadowDivVisible(true);			// Enable shadow for these boxes
	messageObjPopup.setCache(false);					// Enable cache by default
	var clsName = 'modalDialog_transparentDivs';	  	//dimmed
	messageObjPopup.display(clsName);
}

function closePopup()
{
	messageObjPopup.close();
}


var messageObjTimeoutInst;  //message timeout instance-used to cancel timeout
var saveTrapUpdaterBypass;  

function displayMsg(modal) {
	//save setting of the update bypass flag prior to setting it to true, so that the modal message box doesn't trigger the 'update prompt'
	if (modal=='') modal=true;
	saveTrapUpdaterBypass = trapUpdaterBypass;
	trapUpdaterBypass = true;
	if (openAlert==1)
		var clsName = 'modalDialog_transparentDivs';	  //dimmed
	if (openAlert==2)
		var clsName = 'modalDialog_allWhiteLogoedDivs';  //all white w/EMA logo
	messageObj.display(clsName);
	if (modal)
		self.focus();
}

function displayMessage(url,width,height,modal,delay,timeoutFunc,timeoutSecs)
{
	// parms: delay - wait this many milliseconds before displaying message
	// parms: after display message, wait 'timeoutSecs' millisecs, then execute 'timeoutFunc'
	if (width=='') width=400;
	if (height=='') height=200;
	if (modal=='') modal=true;
	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(width,height);
	messageObj.setShadowDivVisible(true);	// Enable shadow for these boxes
	if (timeoutFunc!='' && timeoutSecs>0)
		messageObjTimeoutInst = setTimeout(timeoutFunc,timeoutSecs);
	if (delay>0)
		setTimeout('displayMsg('+modal+')',delay);
	else 
		displayMsg(modal);
}

var myIFrame;
function displayDialog(url,width,height,title)
{
    if (!title) title='';
    if (!width) width=800;
    if (!height) height=400;
    var messageContent = '<table border=0 width="100%" cellpadding=0 cellspacing=0 style="margin:0 0 5px 0" ><tr bgcolor="DDE6E5">';
    messageContent += '<td><b>'+title+'</td><td align=right width="1%"><a href="#" onclick="closeMessage();return false"><img src="pics/closebox.gif" border=0></a></td>';
    
    messageContent += '</tr></table>';
    
    messageContent += '<iframe id=displayDialogIFrame height=\''+(height-20)+'\' width=\''+width+'\' src=\''+url+'\' scrolling=auto frameborder=0></iframe>';
    displayStaticMessage(messageContent,'',width,height)
}
function displayDialogStatic(html,width,height,title)
{
    if (!title) title='';
    if (!width) width=800;
    if (!height) height=400;
    var messageContent = '<table border=0 width="100%" cellpadding=0 cellspacing=0 style="margin:0 0 5px 0" ><tr bgcolor="DDE6E5">';
    messageContent += '<td><b>'+title+'</td><td align=right width="1%"><a href="#" onclick="closeMessage();return false"><img src="pics/closebox.gif" border=0></a></td>';
    
    messageContent += '</tr></table>';
    
    messageContent += '<div id=displayDialogIFrame style="overflow-x: hidden; overflow-y: hidden; height:'+(height-20)+'; width:'+width+';">';
    messageContent += html;
    messageContent += '</div>';
    displayStaticMessage(messageContent,'',width,height)
}
        
function displayStaticMessage(messageContent,cssClass,width,height,modal,delay,timeoutFunc,timeoutSecs)
{
	if (width=='') width=300;
	if (height=='') height=150;
	if (modal=='') modal=true;
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(width,height);
	messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	if (timeoutFunc!='' && timeoutSecs>0)
		messageObjTimeoutInst = setTimeout(timeoutFunc,delay+timeoutSecs);
	if (delay>0)
		setTimeout('displayMsg('+modal+')',delay);
	else 
		displayMsg(modal);
}

function cancelTimeout() {
	clearTimeout(messageObjTimeoutInst);
}

function closeMessage(parm)
{
	openAlert = 0;
	cancelTimeout();
	messageObj.setHtmlContent(null);
	messageObj.close();	
}


/**
* @constructor
*/

DHTML_modalMessage = function()
{
	var url;								// url of modal message
	var htmlOfModalMessage;					// html of modal message
	
	var divs_transparentDiv;				// Transparent div covering page content
	var divs_content;						// Modal message div.
	var iframe;								// Iframe used in ie
	var iframe_transparent;					// Iframe used in ie (for transparent modal background)
	var layoutCss;							// Name of css file;
	var width;								// Width of message box
	var height;								// Height of message box
	
	var existingBodyOverFlowStyle;			// Existing body overflow css
	var dynContentObj;						// Reference to dynamic content object
	var cssClassOfMessageBox;				// Alternative css class of message box - in case you want a different appearance on one of them
	var shadowDivVisible;					// Shadow div visible ? 
	var shadowOffset; 						// X and Y offset of shadow(pixels from content box)
	var MSIE;
		
	this.url = '';							// Default url is blank
	this.htmlOfModalMessage = '';			// Default message is blank
	this.layoutCss = 'modal-message.css';	// Default CSS file
	this.height = 200;						// Default height of modal message
	this.width = 400;						// Default width of modal message
	this.cssClassOfMessageBox = false;		// Default alternative css class for the message box
	this.shadowDivVisible = true;			// Shadow div is visible by default
	this.shadowOffset = 5;					// Default shadow offset.
	this.enablecache = true;				// Default jscache is enabled
	this.MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0) this.MSIE = true;
	

}

DHTML_modalMessage.prototype = {
	// {{{ setSource(urlOfSource)
    /**
     *	Set source of the modal dialog box
     * 	
     *
     * @public	
     */		
	setSource : function(urlOfSource)
	{
		this.url = urlOfSource;
		
	}	
	// }}}	
	,
	// {{{ setHtmlContent(newHtmlContent)
    /**
     *	Setting static HTML content for the modal dialog box.
     * 	
     *	@param String newHtmlContent = Static HTML content of box
     *
     * @public	
     */		
	setHtmlContent : function(newHtmlContent)
	{
		this.htmlOfModalMessage = newHtmlContent;
		
	}
	// }}}		
	,
	// {{{ setSize(width,height)
    /**
     *	Set the size of the modal dialog box
     * 	
     *	@param int width = width of box
     *	@param int height = height of box
     *
     * @public	
     */		
	setSize : function(width,height)
	{
		if(width)this.width = width;
		if(height)this.height = height;		
	}
	// }}}		
	,
	// {{{ setCache(onoff)
    /**
     *	Turn the js caching on or off
     * 	
     *	@param bool onoff = true to enable; false to disable
     *
     * @public	
     */		
	setCache : function(onoff)
	{
		this.enablecache = onoff;
	}
	// }}}		
	,		
	// {{{ setCssClassMessageBox(newCssClass)
    /**
     *	Assign the message box to a new css class.(in case you wants a different appearance on one of them)
     * 	
     *	@param String newCssClass = Name of new css class (Pass false if you want to change back to default)
     *
     * @public	
     */		
	setCssClassMessageBox : function(newCssClass)
	{
		this.cssClassOfMessageBox = newCssClass;
		if(this.divs_content){
			if(this.cssClassOfMessageBox)
				this.divs_content.className=this.cssClassOfMessageBox;
			else
				this.divs_content.className='modalDialog_contentDiv';	
		}
					
	}
	// }}}		
	,	
	// {{{ setShadowOffset(newShadowOffset)
    /**
     *	Specify the size of shadow
     * 	
     *	@param Int newShadowOffset = Offset of shadow div(in pixels from message box - x and y)
     *
     * @public	
     */		
	setShadowOffset : function(newShadowOffset)
	{
		this.shadowOffset = newShadowOffset
					
	}
	// }}}		
	,	
	// {{{ display()
    /**
     *	Display the modal dialog box
     * 	
     *
     * @public	
     */		
	display : function(clsName)
	{
		if(!this.divs_transparentDiv){
			this.__createDivs();
		}	
		if (clsName) {
			this.divs_transparentDiv.className=clsName;
		} else {
			this.divs_transparentDiv.className='modalDialog_transparentDivs';
		}
		
		// Redisplaying divs
		this.divs_transparentDiv.style.display='block';
		this.divs_content.style.display='block';
		this.divs_shadow.style.display='block';		
		if(this.MSIE)this.iframe.style.display='block';	
		
		/* if showing the white blanked out background, put up the iframe to block out high z-level elements like drop-down controls */
		if(this.MSIE) {
			if(clsName=='modalDialog_allWhiteLogoedDivs') 
				this.iframe_transparent.style.display='block';	
			else
				this.iframe_transparent.style.display='none';
		}
		
		this.__resizeDivs();
		
		/* Call the __resizeDivs method twice in case the css file has changed. The first execution of this method may not catch these changes */
		window.refToThisModalBoxObj = this;		
		setTimeout('window.refToThisModalBoxObj.__resizeDivs()',150);
		
		this.__insertContent();	// Calling method which inserts content into the message div.
	}
	// }}}		
	,
	// {{{ ()
    /**
     *	Display the modal dialog box
     * 	
     *
     * @public	
     */		
	setShadowDivVisible : function(visible)
	{
		this.shadowDivVisible = visible;
	}
	// }}}	
	,
	// {{{ close()
    /**
     *	Close the modal dialog box
     * 	
     *
     * @public	
     */		
	close : function()
	{
		//document.documentElement.style.overflow = '';	// Setting the CSS overflow attribute of the <html> tag back to default.
		
		/* Hiding divs */
		if (this.divs_transparentDiv) {
			this.divs_transparentDiv.style.display='none';
			this.divs_content.style.display='none';
			this.divs_shadow.style.display='none';
			if(this.MSIE)this.iframe.style.display='none';
			if(this.MSIE)this.iframe_transparent.style.display='none';
		}
		
	}	
	// }}}	
	,
	// {{{ __addEvent()
    /**
     *	Add event
     * 	
     *
     * @private	
     */		
	addEvent : function(whichObject,eventType,functionName,suffix)
	{ 
	  if(!suffix)suffix = '';
	  if(whichObject.attachEvent){ 
	    whichObject['e'+eventType+functionName+suffix] = functionName; 
	    whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );} 
	    whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName+suffix] ); 
	  } else 
	    whichObject.addEventListener(eventType,functionName,false); 	    
	} 
	// }}}	
	,
    __countDivs : function(clsName)
    {
        // find number of DIVs with classname
        var count = 0;
        var o = document.getElementsByTagName("div");
        for(var i=0; i<o.length; i++){
            if(o[i].className == clsName)
                count ++;
        }
        return count;
    }
    ,
	// {{{ __createDivs()
    /**
     *	Create the divs for the modal dialog box
     * 	
     *
     * @private	
     */		
	__createDivs : function()
	{
		// Creating transparent div
		this.divs_transparentDiv = document.createElement('DIV');
		this.divs_transparentDiv.className='modalDialog_transparentDivs';
		this.divs_transparentDiv.style.left = '0px';
		this.divs_transparentDiv.style.top = '0px';
		
		document.body.appendChild(this.divs_transparentDiv);
		// Creating content div
		this.divs_content = document.createElement('DIV');
		this.divs_content.className = 'modalDialog_contentDiv';
        this.divs_content.id = this.__countDivs(this.divs_content.className) + '_DHTMLSuite_modalBox_contentDiv'
		//this.divs_content.id = 'DHTMLSuite_modalBox_contentDiv';
		this.divs_content.style.zIndex = 100000;
		
		if(this.MSIE){
			this.iframe = document.createElement('<IFRAME src="about:blank" frameborder=0>');
			this.iframe.style.zIndex = 90000;
			this.iframe.style.position = 'absolute';
			document.body.appendChild(this.iframe);	
			
			this.iframe_transparent = document.createElement('<IFRAME src="about:blank" frameborder=0>');
			this.iframe_transparent.style.zIndex = 89000;
			this.iframe_transparent.style.position = 'absolute';
			document.body.appendChild(this.iframe_transparent);	

		}
			
		document.body.appendChild(this.divs_content);
		// Creating shadow div
		this.divs_shadow = document.createElement('DIV');
		this.divs_shadow.className = 'modalDialog_contentDiv_shadow';
		this.divs_shadow.style.zIndex = 95000;
		document.body.appendChild(this.divs_shadow);
		window.refToModMessage = this;
		this.addEvent(window,'scroll',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		

	}
	// }}}
	,
	// {{{ __getBrowserSize()
    /**
     *	Get browser size
     * 	
     *
     * @private	
     */		
	__getBrowserSize : function()
	{
    	var bodyWidth = document.documentElement.clientWidth;
    	var bodyHeight = document.documentElement.clientHeight;
    	
		var bodyWidth, bodyHeight; 
		if (self.innerHeight){ // all except Explorer 
		 
		   bodyWidth = self.innerWidth; 
		   bodyHeight = self.innerHeight; 
		}  else if (document.documentElement && document.documentElement.clientHeight) {
		   // Explorer 6 Strict Mode 		 
		   bodyWidth = document.documentElement.clientWidth; 
		   bodyHeight = document.documentElement.clientHeight; 
		} else if (document.body) {// other Explorers 		 
		   bodyWidth = document.body.clientWidth; 
		   bodyHeight = document.body.clientHeight; 
		} 
		return [bodyWidth,bodyHeight];		
		
	}
	// }}}	
	,
	// {{{ __resizeDivs()
    /**
     *	Resize the message divs
     * 	
     *
     * @private	
     */	
    __resizeDivs : function()
    {
    	
    	var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

		if(this.cssClassOfMessageBox)
			this.divs_content.className=this.cssClassOfMessageBox;
		else
			this.divs_content.className='modalDialog_contentDiv';	
			    	
    	if(!this.divs_transparentDiv)return;
    	
    	// Preserve scroll position
    	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
    	var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
    	
    	window.scrollTo(sl,st);
    	setTimeout('window.scrollTo(' + sl + ',' + st + ');',10);

    	this.__repositionTransparentDiv();
    	

		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];
    	
    	// Setting width and height of content div
      	this.divs_content.style.width = this.width + 'px';
    	this.divs_content.style.height= this.height + 'px';  	
    	// Creating temporary width variables since the actual width of the content div could be larger than this.width and this.height(i.e. padding and border)
    	var tmpWidth = this.divs_content.offsetWidth;	
    	var tmpHeight = this.divs_content.offsetHeight;
    	
    	
    	// Setting width and height of left transparent div
    	
    	

    	
    	
		
    	this.divs_content.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px';;
    	this.divs_content.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
    	
 		if(this.MSIE){
 			this.iframe.style.left = this.divs_content.style.left;
 			this.iframe.style.top = this.divs_content.style.top;
 			this.iframe.style.width = tmpWidth + 'px';
 			this.iframe.style.height = tmpHeight + 'px';

 			this.iframe_transparent.style.left = this.divs_transparentDiv.style.left;
 			this.iframe_transparent.style.top = this.divs_transparentDiv.style.top;
 			this.iframe_transparent.style.width = this.divs_transparentDiv.style.width;
 			this.iframe_transparent.style.height = this.divs_transparentDiv.style.height;
 		}
 		
    	this.divs_shadow.style.left = (this.divs_content.style.left.replace('px','')/1 + this.shadowOffset) + 'px';
    	this.divs_shadow.style.top = (this.divs_content.style.top.replace('px','')/1 + this.shadowOffset) + 'px';
    	this.divs_shadow.style.height = tmpHeight + 'px';
    	this.divs_shadow.style.width = tmpWidth + 'px';
    	
    	
    	
    	if(!this.shadowDivVisible)this.divs_shadow.style.display='none';	// Hiding shadow if it has been disabled
    	
    	
    }
    // }}}	
    ,
	// {{{ __insertContent()
    /**
     *	Insert content into the content div
     * 	
     *
     * @private	
     */	    
    __repositionTransparentDiv : function()
    {
    	this.divs_transparentDiv.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
    	this.divs_transparentDiv.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];
    	this.divs_transparentDiv.style.width = bodyWidth + 'px';
    	this.divs_transparentDiv.style.height = bodyHeight + 'px';		
		   	
    }
	// }}}	
	,
	// {{{ __insertContent()
    /**
     *	Insert content into the content div
     * 	
     *
     * @private	
     */	
    __insertContent : function()
    {
		if(this.url){	// url specified - load content dynamically
			//ajax_loadContent('DHTMLSuite_modalBox_contentDiv',this.url,!this.enablecache);
            ajax_loadContent(this.divs_content.id,this.url,!this.enablecache);            
		}else{	// no url set, put static content inside the message box
			this.divs_content.innerHTML = this.htmlOfModalMessage;	
		}
    }		
}

messageObj = new DHTML_modalMessage();	// We only create one object of this class
messageObj.setShadowOffset(5);	// Large shadow

messageObjPopup = new DHTML_modalMessage();	// We only create one object of this class
messageObjPopup.setShadowOffset(5);	// Large shadow

/* dynamic loading component */
var enableCache = true;
var jsCache = new Array();

var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex,url)
{
	var targetObj = document.getElementById(divId);
	targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
	ajax_parseJs(targetObj)
}

function ajax_loadContent(divId,url,force,postjs,ifemptytxt)
{
	/* url - url to execute to generate content 
	   postjs - javascript to execute after content is generated 
	*/
	if(enableCache && jsCache[url] && !force){
		document.getElementById(divId).innerHTML = jsCache[url];
		return;
	}
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	document.getElementById(divId).innerHTML = '<img src="pics/icons/ajax-loader.gif" border="0"><br>Loading... please wait';
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ 
								if ( dynamicContent_ajaxObjects[ajaxIndex].response.length==0 && ifemptytxt!='')
									dynamicContent_ajaxObjects[ajaxIndex].response = ifemptytxt;
								ajax_showContent(divId,ajaxIndex,url);
								if (postjs) eval(postjs);
								};	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}

function ajax_execute(url,callback)
{
	/* url - url to execute to generate content 
	   postjs - javascript to execute after content is generated 
	*/
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	if (callback)
		dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function () { callback(dynamicContent_ajaxObjects[ajaxIndex].response); };
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
}

function ajax_parseJs(obj)
{
	var scriptTags = obj.getElementsByTagName('SCRIPT');
	var string = '';
	var jsCode = '';

	for(var no=0;no<scriptTags.length;no++){	
		if(scriptTags[no].src){
	        var head = document.getElementsByTagName("head")[0];
	        var scriptObj = document.createElement("script");
	
	        scriptObj.setAttribute("type", "text/javascript");
	        scriptObj.setAttribute("src", scriptTags[no].src);  	
		}else{
			if(navigator.userAgent.indexOf('Opera')>=0){
				jsCode = jsCode + scriptTags[no].text + '\n';
			}
			else
				jsCode = jsCode + scriptTags[no].innerHTML;	
		}
		
	}
	if(jsCode)ajax_installScript(jsCode);
}


function ajax_installScript(script)
{		
    if (!script)
        return;		
    if (window.execScript){        	
    	window.execScript(script)
    }else if(window.jQuery && jQuery.browser.safari){ // safari detection in jQuery
        window.setTimeout(script,0);
    }else{        	
        window.setTimeout( script, 0 );
    } 
}	
	
/* 
	end of modal message class 
*/

function isNumeric(sText) {
	var ValidChars = "0123456789.-";
	var IsNumber=true;
	var Char;

	if (sText) {
		for (var i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) {
				IsNumber = false;
      		}
		}
		return IsNumber;
	} else 
		return false;
}

function isInteger(sText) {
	var ValidChars = "0123456789-";
	var IsNumber=true;
	var Char;

	if (sText) {
		for (var i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) {
				IsNumber = false;
      		}
		}
		return IsNumber;
	} else 
		return false;
}

/* SESSION TIMEOUT logic routines */
	var cycler;
	function startTimeoutCycler() {
		/* check timeout status every 15 seconds */
		checkTimeoutAlerts();
		cycler = window.setInterval("checkTimeoutAlerts()", 45000);
	}

	var ajaxCycler;
	var openAlert = 0;	// 0=no alerts open    1=alert 1 open    2=alert 2 open
	  
	//seconds_before_session_timeout_alert0 = $_SESSION['timeout_alert0']; //seconds until the 'continue' alert is shown 
	//seconds_before_session_timeout_alert1 = $_SESSION['timeout_alert1']; //seconds that the 'continue' alert is shown
	//seconds_before_session_timeout_alert2 = $_SESSION['timeout_alert2']; //seconds that the 'password prompt' alert is shown	  
	
	var anyUserActivity = false;
	
	function checkTimeoutAlertHandler(secondsLeft) {
		var disabledFirstTimeout = false;
		if (secondsLeft) {
			if (secondsLeft.substring(0,1)=='+') {
				disabledFirstTimeout = true;
				secondsLeft = secondsLeft.substring(1);
				seconds_before_session_timeout_alert2 = seconds_before_session_timeout_alert1;	/* set password (2nd) prompt to timeout for the same amt of time as the 1st prompt */
			}
		}
		if (isNumeric(secondsLeft)) {
		  	if (secondsLeft > (seconds_before_session_timeout_alert1 + seconds_before_session_timeout_alert2)) {
		  		if(openAlert) {
			  		closeMessage();
		  		}
				if (anyUserActivity) {
					resetTheTimeout = 1;
				}
		  	} else {
			  	if (secondsLeft > seconds_before_session_timeout_alert2) {
			  		if(openAlert && openAlert != 1) {
				  		closeMessage();
			  		}
			  		if (!disabledFirstTimeout)
			  			showTimeOutWarning1(secondsLeft);
			  	} else {
				  	if (secondsLeft > 0) {
				  		if(openAlert && openAlert != 2) {
					  		closeMessage();
				  		}
				  		showTimeOutWarning2(secondsLeft);
				  	} else {
						window.location='logout.php';
				  	}
		  		}
		  	}
		}
		anyUserActivity = false;
	}
	
	var resetTheTimeout = 0;
	function checkTimeoutAlerts() {
		ajaxCycler = new sack();
		ajaxCycler.requestFile = 'timerpic.php?action=checklogin';
		if (resetTheTimeout==1) {
			ajaxCycler.requestFile += '&action2=resettimer';
			resetTheTimeout = 0;
		}
		ajaxCycler.onCompletion = 
			function () {
	  	 		checkTimeoutAlertHandler(ajaxCycler.response);
				ajaxCycler=false;
			 };
		ajaxCycler.runAJAX();
	}
		
	function showTimeOutWarning1(secondsLeft) {
		/* Display the first timeout prompt (requiring no password)
	  	*/
 		openAlert = 1;
 		/*
	  	displayStaticMessage('<h1>Reminder</h1><p>This web session will timeout within '
	  							+friendlyTime(secondsLeft)
	  							+'. If you wish to continue working, please press \'Continue\' below. Otherwise, you can just wait for the timeout or click \'Logout\' now.</p><p><a href=\'#\' onclick=\'closeWindowResetSession();return false\'>Continue</a>&nbsp;<a href=\'#\' onclick=\'closeMessage();window.location=\"logout.php\";return false\'>Logout</a>',
  							false, 300, 150, false);
  							
		displayStaticMessage('<h1>Reminder</h1><form name=TOpasscheck onsubmit="checkPassword(document.TOpasscheck.repass.value,1); return false"><p>This web session will timeout within '+friendlyTime(secondsLeft)+'. If you wish to continue working, please press \&#39;Continue\&#39; below. If you wish to minimize timeout reminders, please re-enter your login password here:<p><input id=repass name=repass type=password></p>then press \&#39;Continue\&#39; below. Otherwise, you can just wait for the timeout or click \'Logout\' now.</p><p><a href=\'#\' onclick=\'if (document.TOpasscheck.repass.value) checkPassword(document.TOpasscheck.repass.value,1); else closeWindowResetSession(); return false\'>Continue</a>&nbsp;<a href=\'#\' onclick=\'closeMessage();window.location=\"logout.php\";return false\'>Logout</a></form>',
  							false, 300, 240, false);
  							
  		*/				

 		displayStaticMessage('<h1>Reminder</h1><form name=TOpasscheck onsubmit="checkPassword(document.TOpasscheck.repass.value,1); return false"><p>This web session will timeout within '+friendlyTime(secondsLeft)+'. If you wish to continue working, please press \&#39;continue\&#39; below. <p><a href=\'#\' onclick=\'closeWindowResetSession();return false\'>continue</a>&nbsp;<a href=\'#\' onclick=\'closeMessage();window.location=\"logout.php\";return false\'>logout</a></p><p>The timer is set to timeout at 20 minutes. To reset the timer to 2 hours, please re-enter your login password here and hit "reset":</p><p><input id=repass name=repass type=password></p><a href=\'#\' onclick=\'if (document.TOpasscheck.repass.value) checkPassword(document.TOpasscheck.repass.value,1); else alert("Please enter your password, then click reset"); return false\'>reset</a></form>',
  							false, 350, 265, false);
	}
	 
	var tenMinWarningSounded = false;
  	function showTimeOutWarning2(secondsLeft) {
		/* Display the second timeout prompt (requiring a password) 
		*/
 		openAlert = 2;
 		
 		/* when we hit T-10 minutes, bring the warning to the foreground */
 		if (secondsLeft < 600 && !tenMinWarningSounded) {
			tenMinWarningSounded = true;
			var focusWindow = true;
 		} else {
 			var focusWindow = false;
 		}
		displayStaticMessage('<h1>Reminder</h1><form name=TOpasscheck onsubmit="checkPassword(document.TOpasscheck.repass.value);return false"><p>This web session will timeout within '
	  						 	+friendlyTime(secondsLeft)
	  						 	+'. If you wish to continue working, you must re-enter your login password here:<p><input id=repass name=repass type=password></p>then press \'Continue\' below. Otherwise, you can just wait for the timeout or click \'Logout\' now.</p><p><a href=\'#\' onclick=\'checkPassword(document.TOpasscheck.repass.value);return false\'>Continue</a>&nbsp;<a href=\'#\' onclick=\'closeMessage();window.location=\"logout.php\";return false\'>Logout</a></form>',
	  						 false, 300, 240, focusWindow);
	  	window.setTimeout("document.getElementById('repass').focus()",200);
	}
	    
	var ajaxChkpass;
	function checkPassword(pwd,disablefirst) {
 		ajaxChkpass = new sack();
		ajaxChkpass.requestFile = 'timerpic.php?action=checkpwd&pwd=' + MD5(pwd) + '&action2=' + disablefirst;
		ajaxChkpass.onCompletion = function () { checkPasswordChallenge(ajaxChkpass.response); ajaxChkpass=false; };
		ajaxChkpass.runAJAX();
	}
	  
	function checkPasswordChallenge(challengeResponse) {
		 if(challengeResponse=='OK') {
		 	closeWindowResetSession();
		 } else {
			passChallenges--;
			if (passChallenges > 0) {
				alert('Sorry, incorrect password.');
			} else {
				closeMessage();
				window.location='logout.php';
			}
	  	}
	  }
	  
	function closeWindowResetSession() {
	  	/* control comes here to close any alerts and reset the session timeout via ajax */
	  	closeMessage();
	  	resetTheTimeout = 1;
	}	  
	  
	function friendlyTime(totseconds) {
		var days = Math.floor(totseconds/60/60/24);
		totseconds = totseconds - days*60*60*24;
	
		var hours = Math.floor(totseconds/60/60);
		totseconds = totseconds - hours*60*60;

		var minutes = Math.floor(totseconds/60);
		totseconds = totseconds - minutes*60;
	    		
		var seconds = Math.floor(totseconds);
		
		var string = '';
	
		if (days > 0) {
	        if (string) string += ' ';
	        string += days + ' day';
	        if (days > 1) string +='s';
	    }
	
	    if (hours > 0) {
	        if (string) string += ' ';
	        string += hours + ' hour';
	        if (hours > 1) string +='s';
	    }
	
	    if (minutes > 0) {
	        if (string) string += ' ';
	        string += minutes + ' minute';
	        if (minutes > 1) string +='s';
	    }
	
	    if (seconds > 0) {
	        if (string) string += ' ';
	        string += seconds + ' second';
	        if (seconds > 1) string +='s';
	    }
	
	    return string;
	}	  
	  
/* SESSION TIMEOUT logic routines END */

/* TIME ACCOUNTING */
	function showDiffNoteArea (div_id,note_name) {
		showHideContent(div_id,'show');
		showHideContent(div_id+'diff','show'); 
		document.theForm.elements[note_name].focus();
	}
	function hideDiffNoteArea (div_id,updater) {
		showHideContent(div_id,'hide');
		showHideContent(div_id+'diff','hide'); 
		if (updater==1)
			showUpdater();
	}
	
	function validDiff(differen_name,glob) {
		var msg='';
		if (document.theForm.elements[differen_name+'[dollars]'])
			if (document.theForm.elements[differen_name+'[dollars]'].value=='') 
				document.theForm.elements[differen_name+'[dollars]'].value = 0;
			else if (!isNumeric(document.theForm.elements[differen_name+'[dollars]'].value))
				msg += 'Dollars/shift must be a number (enter 0 to disable this differential).\n';
				
		if (document.theForm.elements[differen_name+'[dollarsperhr]'])
			if (document.theForm.elements[differen_name+'[dollarsperhr]'].value=='') 
				document.theForm.elements[differen_name+'[dollarsperhr]'].value = 0;
			else if (!isNumeric(document.theForm.elements[differen_name+'[dollarsperhr]'].value))
				msg += 'Dollars/hour must be a number (enter 0 to disable this differential).\n';
				
		if (document.theForm.elements[differen_name+'[factor]'])
			if (document.theForm.elements[differen_name+'[factor]'].value=='')
				document.theForm.elements[differen_name+'[factor]'].value = 1;
			else if (!isNumeric(document.theForm.elements[differen_name+'[factor]'].value))
				msg += 'Factor must be a number (enter 1 to disable this differential).\n';
				
		if (document.theForm.elements[differen_name+'[hours]'])
			if (document.theForm.elements[differen_name+'[hours]'].value=='')
				document.theForm.elements[differen_name+'[hours]'].value = 0;
			else if (!isNumeric(document.theForm.elements[differen_name+'[hours]'].value))
				msg += 'Hours must be a number (enter 0 to disable this differential).\n';
				
		if (msg) {
			alert(msg);
			return false;
		} else {
			if (confirm('Please confirm your change by clicking OK.')) {
				document.theForm.elements[differen_name+'[global]'].value=glob;
				return true;
			} else {
				clearDiffs(differen_name);
				return false;
			}
		}
	
	}	
	function clearDiffs(differen_name) {
		if (document.theForm.elements[differen_name+'[dollars]'])
			document.theForm.elements[differen_name+'[dollars]'].value=''; 
		if (document.theForm.elements[differen_name+'[dollarsperhr]'])
			document.theForm.elements[differen_name+'[dollarsperhr]'].value=''; 
		if (document.theForm.elements[differen_name+'[factor]'])
			document.theForm.elements[differen_name+'[factor]'].value='';
		if (document.theForm.elements[differen_name+'[hours]'])
			document.theForm.elements[differen_name+'[hours]'].value='';
	}
	
	var notes_on = false;
	
	function toggleNotes()
	{
		var block_display = (notes_on) ? 'none' : 'block';
		var elmts = getElementsByClass('ta_note_txt');
		notes_on = !notes_on;
		
		for (var i=0;i<elmts.length;i++) {
			elmts[i].style.display = block_display;
		}
	}
	
	var differen_on = false;
	
	function toggleDifferen()
	{
		var block_display = (differen_on) ? 'none' : 'block';
		var elmts = getElementsByClass('ta_differen_txt');
		differen_on = !differen_on;
		
		for (var i=0;i<elmts.length;i++) {
			elmts[i].style.display = block_display;
		}
	}

/* TIME ACCOUNTING - END */

/* table sorting routines */
	
/* 1. surround header row in <THEAD> </THEAD>
   2. surround rest of rows in <TBODY> </TBODY>
   3. in table, if highlighting of the current sorted column is needed, then:
   		- create highlightedColumn class with background color:
				.highlightedColumn{
					background-color:#EEE;
				}
   		- add colgroup for each column numbered as follows: 
			id of <col> tags should be:
		 	"col" + index of table(1 = first table, 2 = second table) + _ (underscore) + column index(1.2.3.4...)
	 	example:
	 		<colgroup>
				<col id="col1_1"></col>
				<col id="col1_2"></col>
				<col id="col1_3"></col>
				<col id="col1_4"></col>
	
				<col id="col1_5"></col>
			</colgroup>
	
	4. finally, add init routine with column type parameters (put empty string if column is not sortable):
		<table id="myTable">...</table>
		<script type="text/javascript">
			initSortTable('myTable',Array('S','N','S','N','S'));
		</script>

		column sort types:
		S - string
		N - numeric
		MMDDYYYY - date
		
*/
	

		
	var tableWidget_okToSort = true;
	var tableWidget_arraySort = new Array();
	var tableWidget_tableCounter = 1;
	var activeColumn = new Array();
	
	var currentColumn = false;
	function sortNumeric(a,b){
		
		a = a.replace(/,/,'.');
		b = b.replace(/,/,'.');
		a = a.replace(/[^\d\.\/]/g,'');
		b = b.replace(/[^\d\.\/]/g,'');
		if(a.indexOf('/')>=0)a = eval(a);
		if(b.indexOf('/')>=0)b = eval(b);
		return a/1 - b/1;
	}
	

	function sortString(a, b) {
	  if ( a.toUpperCase() < b.toUpperCase() ) return -1;
	  if ( a.toUpperCase() > b.toUpperCase() ) return 1;
	  return 0;
	}
		
	function sortMMDDYYYY(a, b) {
		var atemp = a.substr(6,4)+a.substr(0,2)+a.substr(3,2);
		var btemp = b.substr(6,4)+b.substr(0,2)+b.substr(3,2);

	  if ( atemp < btemp ) return -1;
	  if ( atemp > btemp ) return 1;
	  return 0;
	}
		
	function sortTable()
	{
		if(!tableWidget_okToSort)return;
			
		tableWidget_okToSort = false;
		/* Getting index of current column */
		var obj = this;
		var indexThis = 0;
		while(obj.previousSibling){
			obj = obj.previousSibling;
			if(obj.tagName=='TD')indexThis++;		
			else if(obj.tagName=='TH')indexThis++;		
		}
		if(this.getAttribute('direction') || this.direction){
			direction = this.getAttribute('direction');
			if(navigator.userAgent.indexOf('Opera')>=0)direction = this.direction;
			if(direction=='ascending'){
				direction = 'descending';
				this.setAttribute('direction','descending');
				this.direction = 'descending';	
			}else{
				direction = 'ascending';
				this.setAttribute('direction','ascending');		
				this.direction = 'ascending';		
			}
		}else{
			direction = 'ascending';
			this.setAttribute('direction','ascending');
			this.direction = 'ascending';
		}
		
		var tableObj = this.parentNode.parentNode.parentNode;
		//tableObj.scrollIntoView();
		var tBody = tableObj.getElementsByTagName('TBODY')[0];
		
		/* compute number of rows in header*/
		var tHead = tableObj.getElementsByTagName('THEAD')[0];
		var tHeadrowsCt = tHead.getElementsByTagName('TR').length;

		
		var widgetIndex = tableObj.getAttribute('tableIndex');
		if(!widgetIndex)widgetIndex = tableObj.tableIndex;

		if(currentColumn)currentColumn.className='';
		if (document.getElementById('col' + widgetIndex + '_' + (indexThis+1)))
			document.getElementById('col' + widgetIndex + '_' + (indexThis+1)).className='highlightedColumn';
		currentColumn = document.getElementById('col' + widgetIndex + '_' + (indexThis+1));

	
		
		var sortMethod = tableWidget_arraySort[widgetIndex][indexThis]; // N = numeric, S = String
		if(activeColumn[widgetIndex] && activeColumn[widgetIndex]!=this){
			if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');			
		}

		activeColumn[widgetIndex] = this;
		
		var cellArray = new Array();
		var cellObjArray = new Array();
		for(var no=tHeadrowsCt; no<tableObj.rows.length; no++){
			var content = getContent(tableObj.rows[no].cells[indexThis]);
			cellArray.push(content);
			cellObjArray.push(tableObj.rows[no].cells[indexThis]);
		}
		
		if(sortMethod=='N')
			cellArray = cellArray.sort(sortNumeric);
		else
			if(sortMethod=='MMDDYYYY')
				cellArray = cellArray.sort(sortMMDDYYYY);
			else
				cellArray = cellArray.sort(sortString);
		
		
		if(direction=='descending'){
			for(var no=cellArray.length;no>=0;no--){
				for(var no2=0;no2<cellObjArray.length;no2++){
					if(getContent(cellObjArray[no2]) == cellArray[no] && !cellObjArray[no2].getAttribute('allreadySorted')){
						cellObjArray[no2].setAttribute('allreadySorted','1');	
						tBody.appendChild(cellObjArray[no2].parentNode);				
					}				
				}			
			}
		}else{
			for(var no=0;no<cellArray.length;no++){
				for(var no2=0;no2<cellObjArray.length;no2++){
					if(getContent(cellObjArray[no2]) == cellArray[no] && !cellObjArray[no2].getAttribute('allreadySorted')){
						cellObjArray[no2].setAttribute('allreadySorted','1');	
						tBody.appendChild(cellObjArray[no2].parentNode);				
					}				
				}			
			}				
		}
		
		for(var no2=0;no2<cellObjArray.length;no2++){
			cellObjArray[no2].removeAttribute('allreadySorted');		
		}

		tableWidget_okToSort = true;
	}
	

	function getContent(thisNode) {
		if (thisNode.childNodes[0]) {
			idx=findSubNode(thisNode,'INPUT');
			if (idx>=0) {
				if (thisNode.childNodes[idx].type=='checkbox')
					return thisNode.childNodes[idx].checked?"Y":"N";
				else
					return thisNode.childNodes[idx].value;
			}
			idx=findSubNode(thisNode,'SELECT');
			if (idx>=0)
				return thisNode.childNodes[idx][thisNode.childNodes[idx].selectedIndex].value;
				
			if (thisNode.childNodes)
				for(var no=0;no<thisNode.childNodes.length;no++) {
					if (thisNode.childNodes[no].tagName=='A' && thisNode.childNodes[no].childNodes && thisNode.childNodes[no].childNodes[0]) 
						return thisNode.childNodes[no].childNodes[0].nodeValue;
				}
		}
		return thisNode.innerHTML+'';
	}
	
	function findSubNode(thisNode,nodeType) {
		var ret = -1;	
		for(i=0;i<thisNode.childNodes.length;i++) {
			if (thisNode.childNodes[i].tagName==nodeType) {
				ret=i;
				break;
			}
		}
		return ret;
	}
	
	function initSortTable(objId,sortArray)
	{
		var obj = document.getElementById(objId);
		obj.setAttribute('tableIndex',tableWidget_tableCounter);
		obj.tableIndex = tableWidget_tableCounter;
		tableWidget_arraySort[tableWidget_tableCounter] = sortArray;
		var tHead = obj.getElementsByTagName('THEAD')[0];
		var tHeadrows = tHead.getElementsByTagName('TR');
		
		/* get TD's or TH's in the last row of the THEAD */
		for(var thr=0;thr<tHeadrows.length;thr++) {
			var selects = tHeadrows[thr].getElementsByTagName('SELECT');
			if (selects.length==0) {
				var cells = tHeadrows[thr].getElementsByTagName('TD');
				if (cells.length==0)
					var cells = tHeadrows[thr].getElementsByTagName('TH');
			}
		}
		
		
	//	var cells = tHead.getElementsByTagName('TD');
		//if (cells.length==0)
			//var cells = tHead.getElementsByTagName('TH');
		
		for(var no=0;no<cells.length;no++){
			if(sortArray[no]){
				cells[no].onclick = sortTable;	
				cells[no].style.cursor = 'pointer';	
				cells[no].style.textDecoration="underline";
			}else{
				cells[no].style.cursor = 'default';	
			}
		}		
		for(var no2=0;no2<sortArray.length;no2++){	/* Right align numeric cells */
		//	if(sortArray[no2] && sortArray[no2]=='N')obj.rows[tHeadrows.length-1].cells[no2].style.textAlign='right';
		}		
		
		tableWidget_tableCounter++;
	}
		
/* table sorting routines - END */


/************************************************************************************************************
Ajax tooltip
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland
example of usage:
<a href="#" onmouseover="ajax_showTooltip('demo-pages/ajax-tooltip.html',this);return false" onmouseout="ajax_hideTooltip()">

************************************************************************************************************/	


/* Custom variables */

/* Offset position of tooltip */
var x_offset_tooltip = 5;
var y_offset_tooltip = 0;

/* Don't change anything below here */


var ajax_tooltipObj = false;
var ajax_tooltipObj_iframe = false;

var ajax_tooltip_MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0)ajax_tooltip_MSIE=true;


function ajax_showTooltip(externalFile,inputObj,staticHTML)
/* if 'staticHTML' is true, then externalFile is the actual HTML to show */
{
	if(!ajax_tooltipObj)	/* Tooltip div not created yet ? */
	{
		ajax_tooltipObj = document.createElement('DIV');
		ajax_tooltipObj.style.position = 'absolute';
		ajax_tooltipObj.id = 'ajax_tooltipObj';		
		document.body.appendChild(ajax_tooltipObj);

		
		var leftDiv = document.createElement('DIV');	/* Create arrow div */
		leftDiv.className='ajax_tooltip_arrow';
		leftDiv.id = 'ajax_tooltip_arrow';
		ajax_tooltipObj.appendChild(leftDiv);
		
		var contentDiv = document.createElement('DIV'); /* Create tooltip content div */
		contentDiv.className = 'ajax_tooltip_content';
		ajax_tooltipObj.appendChild(contentDiv);
		contentDiv.id = 'ajax_tooltip_content';
		
		if(ajax_tooltip_MSIE){	/* Create iframe object for MSIE in order to make the tooltip cover select boxes */
			ajax_tooltipObj_iframe = document.createElement('<IFRAME frameborder="0">');
			ajax_tooltipObj_iframe.style.position = 'absolute';
			ajax_tooltipObj_iframe.border='0';
			ajax_tooltipObj_iframe.frameborder=0;
			ajax_tooltipObj_iframe.style.backgroundColor='#FFF';
			ajax_tooltipObj_iframe.src = 'about:blank';
			contentDiv.appendChild(ajax_tooltipObj_iframe);
			ajax_tooltipObj_iframe.style.left = '0px';
			ajax_tooltipObj_iframe.style.top = '0px';
		}

			
	}
	// Find position of tooltip
	ajax_tooltipObj.style.display='block';
	if (staticHTML)
		document.getElementById('ajax_tooltip_content').innerHTML=externalFile;
	else	
		ajax_loadContent('ajax_tooltip_content',externalFile,false,'',' ');
	
	if(ajax_tooltip_MSIE){
		ajax_tooltipObj_iframe.style.width = ajax_tooltipObj.clientWidth + 'px';
		ajax_tooltipObj_iframe.style.height = ajax_tooltipObj.clientHeight + 'px';
	}

	ajax_positionTooltip(inputObj);
}

function ajax_positionTooltip(inputObj)
{
	var leftPos = (ajaxTooltip_getLeftPos(inputObj) + inputObj.offsetWidth);
	var topPos = ajaxTooltip_getTopPos(inputObj);
	
	/*
	var rightedge=ajax_tooltip_MSIE? document.body.clientWidth-leftPos : window.innerWidth-leftPos
	var bottomedge=ajax_tooltip_MSIE? document.body.clientHeight-topPos : window.innerHeight-topPos
	*/
	var tooltipWidth = document.getElementById('ajax_tooltip_content').offsetWidth +  document.getElementById('ajax_tooltip_arrow').offsetWidth; 
	// Dropping this reposition for now because of flickering
	//var offset = tooltipWidth - rightedge; 
	//if(offset>0)leftPos = Math.max(0,leftPos - offset - 5);
	
	ajax_tooltipObj.style.left = leftPos + 'px';
	ajax_tooltipObj.style.top = topPos + 'px';	
	
	
}


function ajax_hideTooltip()
{
	ajax_tooltipObj.style.display='none';
}

function ajaxTooltip_getTopPos(inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function ajaxTooltip_getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}

/// ALTERNATE TOOLTIP - via dhtmlgoodies
/*
Usage: <a href="#" onmousemove="showToolTip(event,'This is a simple, simple test');return false" onmouseout="hideToolTip()">A word</a>
*/
var ttFrame;
var ttDelay;
function showToolTip(e,text,offX,offY,align,delay){
	//align=L,M,R - left,middle,right positioning of the tooltip
	//delay = milliseconds delay before the tooltip appears
	if( document.all ) e = event;
	if( text=="" ) return;
	if( typeof(offX)=='undefined' || !offX) offX=0;
	if( typeof(offY)=='undefined' || !offY) offY=0;
	if(!align) align='M';
	if (typeof(delay)=='undefined') delay=0;
	
	if (!IE && delay>0) {
        ttDelay = setTimeout(function(){ showToolTip(e,text,offX,offY,align,0); e=null; text=null; offX=null; offY=null; align=null;}, delay);
        return;
	}
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	var obj_bottom = document.getElementById('bubble_tooltip_bottom');
	
	if(IE && !ttFrame) {	/* Create iframe object for MSIE in order to make the tooltip cover select boxes */
		ttFrame = document.createElement('<IFRAME frameborder="0">');
		ttFrame.style.position = 'absolute';
		ttFrame.border='0';
		ttFrame.frameborder=0;
		ttFrame.style.backgroundColor='#FFF';
		ttFrame.src = 'about:blank';
		ttFrame.style.zIndex = 99;
		document.body.appendChild(ttFrame);	
		ttFrame.style.left = '0px';
		ttFrame.style.top = '0px';
		ttFrame.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	}	
	
	var cleanstr = new String(text);
	if (cleanstr.length > 1200) cleanstr = cleanstr.substr(0,1200)+'...';
	
	if(cleanstr.indexOf("%0D%0A") > -1){
		cleanstr=cleanstr.replace(/%0D%0A/g,'<br>')
	}
	else if(cleanstr.indexOf("%0A") > -1){
		cleanstr=cleanstr.replace(/%0A/g,'<br>');
	}
	else if(cleanstr.indexOf("%0D") > -1){
		cleanstr=cleanstr.replace(/%0D/g,'<br>');
	}	
	obj2.innerHTML = unescape(cleanstr.replace(/\+/g,' '));
	obj.style.display = 'block';
	
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)sl=0; 
	var leftPos = e.clientX + sl + (align=='M'?- 100 : align=='R'?-185 : 100) + offX;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	var ntop = e.clientY - obj.offsetHeight + offY + st;
	if (ntop<st) {
		var ntop = e.clientY - offY + st + (e.target ? e.target.offsetHeight : e.srcElement.offsetHeight);
		obj_bottom.className = 'bubble_bottom_N';
	} else 
		obj_bottom.className = (align=='M'? 'bubble_bottom' : align=='R'?'bubble_bottom_R' : 'bubble_bottom_L');

	obj.style.top = ntop + 'px';
	if (IE) {
		ttFrame.style.width = obj.offsetWidth;
		ttFrame.style.height = obj.offsetHeight;
		ttFrame.style.top= obj.style.top;
		ttFrame.style.left= obj.style.left;
		settingttFrame = true;
		ttFrame.style.display = 'block';
		settingttFrame = false;
	}
}	

function hideToolTip()
{
    if (ttDelay) clearTimeout(ttDelay);
	document.getElementById('bubble_tooltip').style.display = 'none';
	if (IE && ttFrame) {
		ttFrame.style.display = 'none';
	}
}

function resizeTextarea(t) {
// resize passed textarea based on its content; called by the onkey(this) (& onclic	k(this)) attached to textarea
	a = t.value.split('\n');
	b=1;
	for (x=0;x < a.length; x++) {
	 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
	 }
	b+= a.length;
	if (b > t.rows) t.rows = b;
}

function popupTextbox(divORbody,heading,width,height) {
	if (!width) width = 600;
	if (!height) height = 500;
	if (!divORbody) divORbody = '';
	var scrollheight = height - 40;
	var contentDiv = document.getElementById(divORbody);
	var content = '<table border=0 width=100%><tr><td>'+heading+'</td><td align=right width=\"1%\"><a href="#" onclick="closePopup();return false"><img src="pics/closebox.gif" border=0></a></td></tr><tr><td colspan=2><div class=scrollingbox style="height: '+scrollheight+'">';
	if (contentDiv) 
		content += contentDiv.innerHTML;
	else 
		content += divORbody;

	content +='</div></td></tr></table>';

	displayPopupStatic(content,width,height);

}

/**
*
* MD5 (Message-Digest Algorithm)
* http://www.webtoolkit.info/
*
**/

var MD5 = function (string) {

    function RotateLeft(lValue, iShiftBits) {
        return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
    }

    function AddUnsigned(lX,lY) {
        var lX4,lY4,lX8,lY8,lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    }

    function F(x,y,z) { return (x & y) | ((~x) & z); }
    function G(x,y,z) { return (x & z) | (y & (~z)); }
    function H(x,y,z) { return (x ^ y ^ z); }
    function I(x,y,z) { return (y ^ (x | (~z))); }

    function FF(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function GG(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function HH(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function II(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWords_temp1=lMessageLength + 8;
        var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
        var lWordArray=Array(lNumberOfWords-1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount-(lByteCount % 4))/4;
        lBytePosition = (lByteCount % 4)*8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
        lWordArray[lNumberOfWords-2] = lMessageLength<<3;
        lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
        for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
        }
        return WordToHexValue;
    };

    function Utf8Encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    };

    var x=Array();
    var k,AA,BB,CC,DD,a,b,c,d;
    var S11=7, S12=12, S13=17, S14=22;
    var S21=5, S22=9 , S23=14, S24=20;
    var S31=4, S32=11, S33=16, S34=23;
    var S41=6, S42=10, S43=15, S44=21;

    string = Utf8Encode(string);

    x = ConvertToWordArray(string);

    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

    for (k=0;k<x.length;k+=16) {
        AA=a; BB=b; CC=c; DD=d;
        a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
        d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
        c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
        b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
        a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
        d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
        c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
        b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
        a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
        d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
        c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
        b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
        a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
        d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
        c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
        b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
        a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
        d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
        c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
        b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
        a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
        d=GG(d,a,b,c,x[k+10],S22,0x2441453);
        c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
        b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
        a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
        d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
        c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
        b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
        a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
        d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
        c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
        b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
        a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
        d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
        c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
        b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
        a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
        d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
        c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
        b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
        a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
        d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
        c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
        b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
        a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
        d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
        c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
        b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
        a=II(a,b,c,d,x[k+0], S41,0xF4292244);
        d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
        c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
        b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
        a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
        d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
        c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
        b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
        a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
        d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
        c=II(c,d,a,b,x[k+6], S43,0xA3014314);
        b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
        a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
        d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
        c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
        b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
        a=AddUnsigned(a,AA);
        b=AddUnsigned(b,BB);
        c=AddUnsigned(c,CC);
        d=AddUnsigned(d,DD);
    }

    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);

    return temp.toLowerCase();
}

function windowclose() {
	if (parent) 
		parent.closeMessage();
	else
		window.close();
}

var ajaxRequestOff;

function toggleRequestOffStatus(site,sched_type,date,divCurr,divFlip) {
	ajaxRunning = true;
	standbyAjaxMsg(true);
	ajaxRequestOff = new sack();
	ajaxRequestOff.requestFile = 'request.php?action=toggle_lock&site=' + site + '&sched_type=' + sched_type + '&date=' + date;
	ajaxRequestOff.onCompletion = function() { 
				standbyAjaxMsg(false);
				document.getElementById(divCurr).innerHTML = ajaxRequestOff.response;
				document.getElementById(divFlip).innerHTML = ajaxRequestOff.response=='OPEN'?'CLOSE':'OPEN';
				alert('Requests are now '+ajaxRequestOff.response.toLowerCase()+'.');
				ajaxRequestOff = false;
	};
	ajaxRequestOff.runAJAX();
}

/* STANDBY routines */
	
var standbyAjaxObjTimeoutInst;  //message timeout instance-used to cancel timeout
var standbyIframe;
function standbyAjaxMsg(mode,msg,delay) {
	if (!mode) mode=false;
	if (!delay) delay=0.25;

	var sbMsgObj = document.getElementById('__standby_ajax_msg');
	if (IE && !standbyIframe) {	/* Create iframe object for MSIE in order to make the standby msg covers select boxes */
		standbyIframe = document.createElement('<IFRAME frameborder="0">');
		standbyIframe.style.position = 'absolute';
		standbyIframe.border='0';
		standbyIframe.frameborder=0;
		standbyIframe.style.backgroundColor='#FFF';
		standbyIframe.src = 'about:blank';
		standbyIframe.style.zIndex = 490000;
		standbyIframe.style.left = '-1px';//sbMsgObj.style.left;
		standbyIframe.style.top = '-1px';//sbMsgObj.style.top;
		standbyIframe.style.width = '190px';//sbMsgObj.style.width;
		standbyIframe.style.height = '50px';//sbMsgObj.style.height;
		standbyIframe.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		sbMsgObj.appendChild(standbyIframe);
	}	
		
	/* reposition standby msg box depending on page scroll position */
	if (document.documentElement && document.documentElement.scrollTop) 
		var r=document.documentElement;
	else if (document.body) 
		var r=document.body;
	var w = window;
	var scrtp = r.scrollTop;
	var scrlf = r.scrollLeft;

	var ww=w.innerWidth	?	window.innerWidth	+w.pageXOffset  + scrlf : r.clientWidth;
	var wh=w.innerHeight?	window.innerHeight	+w.pageYOffset	+ scrtp : r.clientHeight;
	
	var bw=sbMsgObj.offsetWidth;
	var bh=sbMsgObj.offsetHeight;
	
	sbMsgObj.style.top=(w.innerHeight?0:scrtp) + parseInt((wh-bh)/2)+'px';// this is to place it in the middle
	sbMsgObj.style.left=(w.innerWidth?0:scrlf) + parseInt((ww-bw)/2)+'px';// this is to place it in the middle
	
	
	if (mode) {
		standbyAjaxObjTimeoutInst = setTimeout('showHideContent(\'__standby_ajax_msg\',\'show\')',delay*1000);
		if (standbyIframe) standbyIframe.style.display = 'block';
	} else {
		clearTimeout(standbyAjaxObjTimeoutInst);
		showHideContent('__standby_ajax_msg','hide');
		if (standbyIframe) standbyIframe.style.display = 'none';
	}
}

function inStandbyMode() {
	var elem = document.getElementById('__standby_msg');
	return !(elem.style.display == 'none' || elem.style.display=='');
}

/*	dragTableColumn				STARTS
    Drag & Drop Table Columns
    
    NOTE: assumes the first row of the table is the drag row
    NOTE: handles COLSPANs only in the first row of the table
*/
 
/* parameters
    id: id of the table that will have drag & drop function
*/
 
function dragTableColumn(id) {
	// store the cell that will be dragged
	this.draggedCell = null
	// true if ghostTd exists
	this.ghostCreated = false
	// store the table itselfs
	this.table = document.getElementById(id)
	if (this.table==null)return;
	// store every row of the table
	this.tableRows = this.table.getElementsByTagName("tr")
	
	// create a handler array, usualy the 1st row of ths in the thead, if not possible the first row of tds
	if (this.table.getElementsByTagName("th").length > 0) {
		var tHead = this.table.getElementsByTagName('THEAD')[0];
		var tRow = tHead.getElementsByTagName('TR')[0];
		this.handler = tRow.getElementsByTagName('TH');
	} else
		this.handler = this.table.tBodies[0].rows[0].getElementsByTagName("td");

	//// create a handler array, usualy the ths in the thead, if not possible the first row of tds
//	this.handler = this.table.getElementsByTagName("th").length > 0 ? this.table.getElementsByTagName("th") : this.table.tBodies[0].rows[0].getElementsByTagName("td")
	
	// create a cell array
	this.cells = this.table.getElementsByTagName("td")
	// store the max index of the column when dropped
	this.maxIndex = this.handler.length
	// store the horizontal mouse position
	this.x;
	// store the vertical mouse position
	this.y;
	// store the index of the column that will be dragged
	this.oldIndex;
	// store the colspan of the column that will be dragged
	this.oldColspan;
	// store the colspan of the column dropped on
	this.newColspan;
	// store the index of the destionation of the column
	this.newIndex;
 
    for (x=0; x<this.handler.length; x++) {
    // associate the object with the cells
	    this.handler[x].dragObj = this
	    this.handler[x].style.cursor = 'move';
	    
	    // override the default action when mousedown and dragging
	    this.handler[x].onselectstart = function() { return false }
		//this.addEvent( this.handler[x],'selectstart',function() { return false });
	
	    // fire the drag action and return false to prevent default action of selecting the text
	    this.handler[x].onmousedown = function(e) { this.dragObj.drag(this,e); return false }
	    //this.addEvent( this.handler[x],'mousedown',function(e) { this.dragObj.drag(this,e); return false });
	    
	    // visual effect
	    this.handler[x].onmouseover = function(e) { this.dragObj.dragEffect(this,e) }
	    //this.addEvent( this.handler[x],'mouseover',function(e) { this.dragObj.dragEffect(this,e) });
	    
	    this.handler[x].onmouseout = function(e) { this.dragObj.dragEffect(this,e) }
	    //this.addEvent( this.handler[x],'mouseout',function(e) { this.dragObj.dragEffect(this,e) });
	    
	    this.handler[x].onmouseup = function(e) { this.dragObj.dragEffect(this,e) }
	    //this.addEvent( this.handler[x],'mouseup',function(e) { this.dragObj.dragEffect(this,e) });
		var eHandlerAttr = document.createAttribute("handler");
		eHandlerAttr.nodeValue = 'Y';
		this.handler[x].setAttributeNode(eHandlerAttr);
    }
   
    for (x=0; x<this.cells.length; x++) {
	    this.cells[x].dragObj = this
	    // visual effect
	    //this.cells[x].onmouseover = function(e) { this.dragObj.dragEffect(this,e) }
	    this.addEvent( this.cells[x],'mouseover',function(e) { this.dragObj.dragEffect(this,e) });
	    
	    //this.cells[x].onmouseout = function(e) { this.dragObj.dragEffect(this,e) }
	    this.addEvent( this.cells[x],'mouseout',function(e) { this.dragObj.dragEffect(this,e) });
	    
	    //this.cells[x].onmouseup = function(e) { this.dragObj.dragEffect(this,e) }
	    this.addEvent( this.cells[x],'mouseup',function(e) { this.dragObj.dragEffect(this,e) });
    }
}
 
dragTableColumn.prototype.dragEffect = function(cell,e) {
	// assign event to variable e
	if (!e) e = window.event
	 
	    // return if the cell being hovered is the same as the one being dragged
	    if (cell.cellIndex == this.oldIndex) return
	   
	    else {
	    	
	        // if there is a cell being dragged
	        if (this.draggedCell) {
	        // change class to give a visual effect
	        ////////////////////////////e.type == "mouseover" ? this.handler[cell.cellIndex].className = "hovering" : this.handler[cell.cellIndex].className = ""
	        }
	    }
}
 
dragTableColumn.prototype.drag = function(cell,e) {
	// reference of the cell that is being dragged
	//this.table.scrollIntoView();
	this.draggedCell = cell;
	if (cell.cellIndex<0) return; /* means its a cell under another cell having colspan>1 */
	 
	// change class for visual effect
	/////this.draggedCell.className = "dragging";
	this.oldColspan = cell.colSpan;
	 
	// store the index of the cell that is being dragged
	this.oldIndex = cell.cellIndex;
	 
	// create the ghost td
	this.createGhostTd(e);
	// start the engine
	this.dragEngine(true);
}
 
dragTableColumn.prototype.createGhostTd = function(e) {
	// if ghost exists return
	if (this.ghostCreated) return
	// assign event to variable e
	if (!e) e = window.event
	// horizontal position
	this.x = e.pageX ? e.pageX : e.clientX + document.documentElement.scrollLeft
	// vertical position
	this.y = e.pageY ? e.pageY : e.clientY + document.documentElement.scrollTop
	 
	    // create the ghost td (visual effect)
	    this.ghostTd = document.createElement("div");
	    this.ghostTd.style.position = 'absolute';
	    this.ghostTd.className = "ghostTd"
	    this.ghostTd.style.top = this.y + 5 + "px"
	    this.ghostTd.style.left = this.x + 10 + "px"
	    // ghost td receives the content of the dragged cell
	    this.ghostTd.innerHTML = this.handler[this.oldIndex].innerHTML
	    document.getElementsByTagName("body")[0].appendChild(this.ghostTd)
	 
	// assign a flag to see if ghost is created
	this.ghostCreated = true
}
 
dragTableColumn.prototype.drop = function(dragObj,e) {
	// assign event to variable e
	if (!e) e = window.event
	// store the target of the event - mouseup
	e.targElm = e.target ? e.target : e.srcElement
	 
	// end the engine
	dragObj.dragEngine(false,dragObj)
	 
	// remove the ghostTd
	dragObj.ghostTd.parentNode.removeChild(dragObj.ghostTd)
	 
	// remove ghost created flag
	this.ghostCreated = false
	 
    // store the index of the target, if it have one
    if (typeof(e.targElm.cellIndex) !="undefined") {
    	
	    /* store the colSpan of the cell dropped on */
		this.newColspan = e.targElm.colSpan;
		
	    checkTable = e.targElm
   
        // ascend in the dom beggining in the targeted element and ending in a table or the body tag
        while (checkTable.tagName.toLowerCase() !="table") {
        if (checkTable.tagName.toLowerCase() == "html") break
        checkTable = checkTable.parentNode
        }
       
        // check if the table where the column was dropped is equal to the object table
        checkTable == this.table ? this.newIndex = e.targElm.cellIndex : false
    }
	if (this.newIndex>this.maxIndex) return;
	if(!e.targElm.getAttribute('handler')) return;	/* can only drop on handler cells (i.e. cells that can be dragged) */
	
	// start the function to sort the column
	dragObj.sortColumn(this.tableRows,this.oldIndex,this.newIndex,this.oldColspan,this.newColspan);
		
	// remove visual effect from column being dragged
	//////this.draggedCell.className = "";
	// clear the variable
	this.draggedCell = null;
}
 
dragTableColumn.prototype.sortColumn = function(tableRows,o,d,oColSpan,dColSpan) {
	// returns if destination dont have a valid index
	// ncols - number of columns to move
	if (d == null) return
	// returns if origin is equals to the destination
	if (o == d) return
    // loop through every row
    //for (x=0; x<tableRows.length; x++) {
	var netD = this.effColNo(tableRows[0],d);
	var netO = this.effColNo(tableRows[0],o);
	var netOCols = oColSpan;
	var netDCols = dColSpan;
	
    for (x=tableRows.length-1; x>=0; x--) {
        // array with the cells of the row x
        var tds = tableRows[x].cells
    	/* adjust remove and insertion points depending on COLSPANs in row */
    	if (x==0) {
    		var netD = d;
    		var netO = o;
    		var oColSpan = 1;
    		var dColSpan = 1;
    	}
        for(r=0; r<oColSpan; r++) {
			
        	/* adjust for remove and insertion points depending on direction of move, left or right */
	        if (o<d) {
	        	var subnetD = netD+dColSpan-1;
	        	var subnetO = netO;
	        } else {
	        	var subnetD = netD+r;
	        	var subnetO = netO+r;
	        }
	        // remove this cell(s) from the row
       		var cell = tableRows[x].removeChild(tds[subnetO]);
	        // insert the cell(s) in the new index
	        if (tds[subnetD])
        		tableRows[x].insertBefore(cell, tds[subnetD]);
        	else
        		tableRows[x].insertBefore(cell, tds[subnetD-1].nextSibling);
        }
    }
}

dragTableColumn.prototype.effColNo = function (tblRow,origColNo) {
	// add up colspan's in columns 0 thru 'colNo' in passed row and return
		var sumColSpans = 0;
		for(var col=0; col<origColNo; col++) {
			sumColSpans += parseInt(tblRow.cells[col].colSpan);
		}
		return sumColSpans;
	}

 
dragTableColumn.prototype.OLDsortColumn = function(o,d) {
	// returns if destionation dont have a valid index
	if (d == null) return;
	// returns if origin is equals to the destination
	if (o == d) return;
	 
	    // loop through every row
	    for (x=0; x<this.tableRows.length; x++) {
	        // array with the cells of the row x
	        tds = this.tableRows[x].cells;
	        // remove this cell from the row
	        var cell = this.tableRows[x].removeChild(tds[o]);
	        // insert the cell in the new index
	        if (d + 1 >= this.maxIndex) {
	        	this.tableRows[x].appendChild(cell);
	        }
	        else {
	        	this.tableRows[x].insertBefore(cell, tds[d]);
	        }
	    }
}
 
dragTableColumn.prototype.dragEngine = function(bool,dragObj) {
	var _this = this;
	// fire the drop function
	document.documentElement.onmouseup = bool ? function(e) { _this.drop(_this,e) } : null;
	// capture the mouse coords
	document.documentElement.onmousemove = bool ? function(e) { _this.getCoords(_this,e) } : null;
}
	 
dragTableColumn.prototype.getCoords = function(dragObj,e) {
	if (!e) e = window.event;
	 
	// horizontal position
	dragObj.x = e.pageX ? e.pageX : e.clientX + document.documentElement.scrollLeft;
	// vertical position
	dragObj.y = e.pageY ? e.pageY : e.clientY + document.documentElement.scrollTop;
	 
	    if (dragObj.ghostTd) {
	    // make the ghostTd follow the mouse
	    dragObj.ghostTd.style.top = dragObj.y + 5 + "px";
	    dragObj.ghostTd.style.left = dragObj.x + 10 + "px";
	    }
}

	// {{{ __addEvent()
    /**
     *	Add event
     * 	
     *
     * @private	
     */		
dragTableColumn.prototype.addEvent = function(whichObject,eventType,functionName,suffix) { 
	if(!suffix)suffix = '';
	if(whichObject.attachEvent) { 
    	whichObject['e'+eventType+functionName+suffix] = functionName; 
    	whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );} 
    	whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName+suffix] ); 
  	} else 
    	whichObject.addEventListener(eventType,functionName,false);
}

/*	dragTableColumn				ENDS
*/

/* ajax process handling logic */
var ajx_process = new Array();

function get_ajx_process() {
	var nIdx=0;
	for(var nIdx=0; nIdx<ajx_process.length; nIdx++) {
		if (ajx_process[nIdx]==null)
			break;
	}
	ajx_process[nIdx] = new sack;
	return nIdx;
}

function free_ajx_process(idx) {
	ajx_process[idx] = null;
	return true;
}

function free_ajx_process_all() {
	for(var nIdx=0; nIdx<ajx_process.length; nIdx++) {
		ajx_process[idx] = null;
	}
	return true;
}

var ajx_process = new Array();

function valid_email_addr(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}



/*
***** OVERRIDES THE ALERT JAVASCRIPT FUNCTION (all javascript ALERT functions reference this) - displays a DIV-based fading dialog instead - no click required to close
*/

var Alerter=new function(){
	// real alert function placeholder
	this._alert=null;
	// return Alerter object methods
	return {
		// m=message,c=classname,h=message hold
		notify:
			function(m,c,h){
				// we may consider adding frames support
				var w=this.main;
				// shortcut to document
				var d=this.main.document;
				// canvas, window width and window height
				var r=d.documentElement;
				if (typeof(h)=='undefined') h=1000;	//message hold duration before fading start
				
				if (document.documentElement && document.documentElement.scrollTop) {
					var scrtp = document.documentElement.scrollTop;
					var scrlf = document.documentElement.scrollLeft;
				} else if (document.body) {
					var scrtp = document.body.scrollTop;
					var scrlf = document.body.scrollLeft;
				}

				var ww=w.innerWidth	?	w.innerWidth	+w.pageXOffset  + scrlf : r.clientWidth;
				var wh=w.innerHeight?	w.innerHeight	+w.pageYOffset	+ scrtp : r.clientHeight;
				
				// create a block element
				var b=d.createElement('div');
				b.id='Message';
				b.className=c||'';
				b.style.cssText='top:-9999px;left:-9999px;position:absolute;white-space:nowrap;';
				b.style.zIndex=999999;
				// classname not passed, set defaults
				if(b.className.length==0){
					b.style.margin='0px 0px';
					b.style.padding='14px 14px';
					b.style.border='2px solid #DDDB54';
					b.style.backgroundColor='#FFFFCC';
				}
				// insert block in to body
				b=d.body.insertBefore(b,d.body.firstChild);
				
				// replace \n's with <br>
				m = m.replace(/[\n|\r]/g,'<br>');
				
				// write HTML fragment to it
				b.innerHTML=m;
				// save width/height before hiding
				var bw=b.offsetWidth;
				var bh=b.offsetHeight;
				// hide, move and then show
				b.style.display='none';
//				b.style.top=Math.random()*(wh-bh)+'px';// random y position
//				b.style.top=wh-bh+'px';// this is to place it to the bottom
				
				b.style.top=(w.innerHeight?0:scrtp) + parseInt((wh-bh)/2)+'px';// this is to place it in the middle
				
//				b.style.left=Math.random()*(ww-bw)+'px';// random x position
//				b.style.left=ww-bw+'px';// this is to place it to the right
				b.style.left=(w.innerWidth?0:scrlf) + parseInt((ww-bw)/2)+'px';// this is to place it in the middle
				
				if (IE) {	/* Create iframe object for MSIE in order to make the standby msg covers select boxes */
					standbyIframe = document.createElement('<IFRAME frameborder="0">');
					standbyIframe.style.position = 'absolute';
					standbyIframe.border='0';
					standbyIframe.frameborder=0;
					standbyIframe.style.backgroundColor='#FFF';
					standbyIframe.src = 'about:blank';
					standbyIframe.style.zIndex = 999998;
					standbyIframe.style.left = b.style.left;
					standbyIframe.style.top = b.style.top;
					standbyIframe.style.width = (3+bw)+'px';
					standbyIframe.style.height = (3+bh)+'px';
					standbyIframe.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
					standbyIframe.style.display='block';
					document.body.appendChild(standbyIframe);	
					setFading(standbyIframe,1000,100,0,500,function(){document.body.removeChild(standbyIframe);});
				}	
				
				b.style.display='block';
				// fadeout block if supported
                                    
                setTimeout(function(){ setFading(b,1000,100,0,500,function(){d.body.removeChild(b);b=null;});}, h);
			},
		// initialize Alerter object
		init:
			function(w,s){
				// save window
				this.main=w;
				this.classname=s||'';
				// if not set yet
				if(this._alert==null){
					// save old alert function
					this._alert=this.main.alert;
					// redefine alert function
					this.main.alert=function(m){
						Alerter.notify(m,s)
					}
				}
			},
		// shutdown Alerter object
		shut:
			function(){
				// if redifine set
				if(this._alert!=null){
					// restore old alert function
					this.main.alert=this._alert;
					// unset placeholder
					this._alert=null;
				}
			}
	};
};

// apply a fading effect to an object
// by applying changes to its style
// @o = object style
// @p = starting pause at begin opacity (millisec)
// @b = begin opacity
// @e = end opacity
// @d = fade duration (millisec)
// @f = function (optional)
function setFading(o,p,b,e,d,f){
	var t=setInterval(
		function(){
		    if (p<=0) {
    			b=stepFX(b,e,2);
    			setOpacity(o,b/100);
    			if(b==e){
    				if(t){clearInterval(t);t=null;}
    				if(typeof f=='function'){f();}
    			}
		    } else {
		        setOpacity(o,1);
		        p -= 50;
		    }
		},d/50
	);
}
function setFadingOLD(o,b,e,d,f){
	var t=setInterval(
		function(){
			b=stepFX(b,e,2);
			setOpacity(o,b/100);
			if(b==e){
				if(t){clearInterval(t);t=null;}
				if(typeof f=='function'){f();}
			}
		},d/50
	);
}

// set opacity for element
// @e element
// @o opacity
function setOpacity(e,o){
	// for IE
	e.style.filter='alpha(opacity='+o*100+')';
	// for others
	e.style.opacity=o;
}

// increment/decrement value in steps
// checking for begin and end limits
//@b begin
//@e end
//@s step
function stepFX(b,e,s){
	return b>e?b-s>e?b-s:e:b<e?b+s<e?b+s:e:b;
}

var __alert=window.alert;

Alerter.init(window);


function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

function urldecode (str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +   improved by: Orlando
    // %        note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function (search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The hash_map is identical to the one in urlencode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';
    hash_map['\u00C6'] = '%C3%86';
    hash_map['\u00D8'] = '%C3%98';
    hash_map['\u00C5'] = '%C3%85';
 
    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}

function icalSendLink(script,parmhash,devemail,devtype,desc,toname) {
    if (urldecode(devtype)=='Outlook 2003') 
        uri = 'http://';
    else
        uri = 'webcal://';

    new Ajax.Request( 'ical.php',
        {
            method: 'post',
            parameters: 'action=email_link&uri='+uri+'&script='+script+'&parmhash='+parmhash+'&devemail='+devemail+'&devtype='+devtype+'&desc='+desc+'&toname='+toname,
            onComplete: function() {closeMessage(); alert('The email has been sent.');}
        }
    );
}

NS4 = (document.layers) ? true : false;
function blockEnter(event)
{     
    var code = 0;    
    if (NS4)
        code = event.which;
    else
        code = event.keyCode;
    return (code!=13);
}
function goBack() {
	history.go(-1);
}

