// root.js

// if the date format is m/d/yyyy or mm/d/yyyy , we convert it to mm/dd/yyyy
function convertDateTo10Char(inDate)
{
	var dateBits = new Array();
	dateBits = inDate.split("/");
	if (dateBits[0].length == 1)
    	{
    		dateBits[0] = "0" + dateBits[0];
    	}

	if (dateBits[1].length == 1)
    	{
    		dateBits[1] = "0" + dateBits[1];
    	}

	if (dateBits[2].length == 1)
    	{
    		dateBits[2] = "0" + dateBits[2];
    	}

	return dateBits[0]+"/"+dateBits[1]+"/"+dateBits[2];

}

//to verify the date has 2 '/' in it, return true means BAD format
function DateFormatNotCorrect(inDate)
{
	if (inDate.indexOf("/") > 0)
	{
    		inDate = inDate.substring(inDate.indexOf("/")+1, inDate.length);
		if (inDate.indexOf("/") > 0)
			return false;
		else
			return true;

    	}
    	else
    	return true;

}

// This function takes a layer's id as input and
// switches it from visible to invisible or vica versa
function alternateLayerVisibility(whichLayer) {

	var layer;

	if (document.getElementById) {
		// this is the way the standards work

		layer = document.getElementById(whichLayer);
		if(layer.style.visibility == "visible" || layer.style.visibility == "") {
			hideNavLayer(whichLayer);
		}
		else {
			showNavLayer(whichLayer);
		}
	}
	else if (document.all) {
	// this is the way old msie versions work
		layer = document.all[whichlayer];

		if(layer.style.visibility == "visible" || layer.style.visibility == "") {
			hideNavLayer(whichLayer);
		}
		else {
			showNavLayer(whichLayer);
		}
	}
	else if (document.layers) {
	// this is the way nn4 works
		layer = document.layers[whichLayer];

		if(layer.style.visibility == "visible" || layer.style.visibility == "") {
			hideNavLayer(whichLayer);
		}
		else {
			showNavLayer(whichLayer);
		}
	}
}

function hideNavLayer(whichLayer) {

	if (document.getElementById) {
	// this is the way the standards work
	document.getElementById(whichLayer).style.visibility = "hidden";
	document.getElementById(whichLayer).style.position = "absolute";
	}
	else if (document.all) {
	// this is the way old msie versions work
	document.all[whichlayer].style.visibility = "hidden";
	}
	else if (document.layers) {
	// this is the way nn4 works
	document.layers[whichLayer].visibility = "hidden";
	}

}

function showNavLayer(whichLayer) {
	if (document.getElementById) {
	// this is the way the standards work
	document.getElementById(whichLayer).style.visibility = "";
	document.getElementById(whichLayer).style.position = "";
	}
	else if (document.all) {
	// this is the way old msie versions work
	document.all[whichlayer].style.visibility = "";
	document.all[whichlayer].style.position = "";
	}
	else if (document.layers) {
	// this is the way nn4 works
	document.layers[whichLayer].visibility = "";
	//document.layers[whichLayer].position = "";
	}

}

function check_uncheck_all(field,object)
{
	if(field != null) {
		field.checked=object.checked;

		for (i = 0; i < field.length; i++)
			field[i].checked = object.checked ;
	}
}

function postToLayer(whichLayer,content,frame) {
	if (frame.document.getElementById) {
		frame.document.getElementById(whichLayer).innerHTML = content;
	}
	else if (frame.document.all) {
		frame.document.all[whichlayer].innerHTML = content;
	}
	else if (frame.document.layers) {
		lyr.open()
		lyr.write(content)
		lyr.close()
	}
}

/*
Set the mouse cursor to an hour glass icon in the given frame
*/
function setPointerBusy(frame) {
    if (frame.document.all)
        for (var i=0;i < frame.document.all.length; i++)
             frame.document.all(i).style.cursor = 'wait';
}

/*
Reset the mouse pointer to the default icon
*/
function resetPointerFrame(frame) {
    if (frame.document.all)
        for (var i=0;i < frame.document.all.length; i++)
             frame.document.all(i).style.cursor = '';
}

/*
Set the mouse cursor to an hour glass icon
*/
function setPointerBusy() {
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = 'wait';
}

/*
Reset the mouse pointer to the IE's default icon
*/
function resetPointer() {
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = '';
}

/*
Reset the mouse pointer to the pointer icon
*/
function setPointerBlank() {
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = 'default';
}

/*
Reset the mouse pointer to the pointer icon
*/
function setPointerBlankFrame(frame) {
    if (frame.document.all)
        for (var i=0;i < frame.document.all.length; i++)
             frame.document.all(i).style.cursor = 'default';
}

/*
Converts src of images with id image from node_open to node_closed or vica versa
*/
function alternateNodeHandle(image) {
	alternateImageBasedOnState(image,"/common/resources/shared/images/node-closed.gif","/common/resources/shared/images/node-open.gif","closed","open");
}

function alternateImageBasedOnState(image,one_src,two_src,state_one,state_two) {

	var object

	if (document.getElementById) {
	// this is the way the standards work
		object = document.getElementById(image);
	}
	else if (document.all) {
	// this is the way old msie versions work
		object = document.all[image];
	}
	else if (document.layers) {
	// this is the way nn4 works
		object = document.layers[image];
	}

	if (object.object_state == state_one) {
		object.src = two_src;
		object.object_state = state_two;
	}
	else {
		object.src = one_src;
		object.object_state = state_one;
	}
}

function window_popup(name,url,width,height,scrollbars,resizeable){
	a=window.open(url,name,'width=' + width + ',height=' + height + ',screenX=100,screenY=100,resizable=' + resizeable + ',scrollbars=' + scrollbars + ',dependent=yes');
}

function controls_to_form_field(control_name,hidden_field) {
	var temp;
	temp="";
	if(control_name != null) {
		if (typeof control_name.value != "undefined") {
			temp = control_name.value;
		}
		else {
			for (i = 0; i < control_name.length; i++) {
				if(control_name[i].checked)
					temp = temp + control_name[i].value + ',';
				}
		}
	} else {
		if (control_name.checked)
			temp = control_name.value;
	}
	hidden_field.value=temp;
}

function object_move(workspace_id,from_object_id) {
	var temp;
	temp="";
	control_name = document.subobjects.object_id;

	if(control_name) {
		if(control_name != null) {
			if (typeof control_name.value != "undefined") {
	//			alert('singleton');
				temp = control_name.value + ',';
			}
			else {
	//			alert('else');
				for (i = 0; i < control_name.length; i++) {
					if(control_name[i].checked)
						temp = temp + control_name[i].value + ',';
					}
			}
		} else {
			if (control_name.checked)
				temp = control_name.value;
		}
	}

	temp = temp.substring(0,temp.length-1);
	if(!temp.length) {
		alert(JS_message1);
	}
	else {
		window_popup('move','/objects/browse.cfm?workspace_id=' + workspace_id + '&return_to=' + escape('/objects/move.cfm?source_ids=' + temp + '&parent_id=' + from_object_id) + '&action_type=move',400,400,'yes','yes');
	}
}

function object_move_to_swf_destination(workspace_id, from_object_id, to_object_id) {
	var temp;
	temp="";
	control_name = subobjects.object_id;
	if(control_name) {
		if(control_name != null) {
			if (control_name.value != null) {
	//			alert('singleton');
				temp = control_name.value + ',';
			}
			else {
	//			alert('else');
				for (i = 0; i < control_name.length; i++) {
					if(control_name[i].checked)
						temp = temp + control_name[i].value + ',';
					}
			}
		} else {
			if (control_name.checked)
				temp = control_name.value;
		}
	}
	temp = temp.substring(0,temp.length-1);
	if(!temp.length) {
		alert(JS_message1);
	}
	else {
		document.location='/objects/move.cfm?workspace_id=' + workspace_id + '&source_ids=' + temp + '&parent_id=' + from_object_id + '&destination_id=' + to_object_id;
	}
}

function workflow_add_destination(workspace_id, object_id) {
	window_popup('move','/objects/browse.cfm?workspace_id=' + workspace_id + '&return_to=' + escape('/objects/content_folder/workflow_destination_add.cfm?object_id=' + object_id) + '&action_type=workflow_add',400,400,'yes','yes');
}

function workflow_remove_destination(workspace_id, object_id) {
	controls_to_form_field(temp_selected_parties,parties.selected_parties);parties.submit();
}

function object_copy(workspace_id,from_object_id) {

	var temp;
	temp="";
	control_name = document.subobjects.object_id;
	if(control_name) {
		if(control_name != null) {
			if (typeof control_name.value != "undefined") {
	//			alert('singleton');
				temp = control_name.value + ',';
			}
			else {
	//			alert('else');
				for (i = 0; i < control_name.length; i++) {
					if(control_name[i].checked)
						temp = temp + control_name[i].value + ',';
					}
			}
		} else {
			if (control_name.checked)
				temp = control_name.value;
		}
	}
	temp = temp.substring(0,temp.length-1);
	if(!temp.length) {
		alert(JS_message2);
	}
	else {
		window_popup('copy','/objects/browse.cfm?workspace_id=' + workspace_id + '&return_to=' + escape('/objects/copy.cfm?source_ids=' + temp + '&parent_id=' + from_object_id) + '&action_type=copy',400,400,'yes','yes');
	}
}

// for IM ContactList window
function launchContactListWindow()
{
	winwidth = 238; // width of the new window
     	winheight = 310; // height of the new window
	winleft = (screen.width / 2) - (winwidth) ; // center the window right to left
	wintop = (screen.height / 2) - (winheight); // center the window top to bottom

	var features = 'toolbar=0,scrollbars=0,location=0,frameborder=no,border=0,status=0,menubar=0';
	features += ',height=' + winheight + ',width=' + winwidth+',top=' + wintop + ',left=' + winleft ;
	windowHandle = window.open('/im/IM_show_contact_list.cfm?chat_with=','contactListWindow',features);
}

// for IM ContactList then begin  chat with user
function launchContactListWindow2( chat_with )
{
	winwidth = 238; // width of the new window
     	winheight = 310; // height of the new window
	winleft = (screen.width / 2) -(winwidth/2); // center the window right to left
	wintop = (screen.height / 2) - (winheight); // center the window top to bottom

	var features = 'toolbar=0,scrollbars=0,location=0,frameborder=no,border=0,status=0,menubar=0';
	features += ',height=' + winheight + ',width=' + winwidth+',top=' + wintop + ',left=' + winleft ;
	windowHandle = window.open('/im/IM_show_contact_list.cfm?chat_with='+chat_with,'contactListWindow',features);
}


//for Converting PowerPoint to Flash , then show progress bar
function launchProgressBarWindow()
{
	winwidth = 600; // width of the new window
	winheight = 150; // height of the new window
	winleft = (screen.width / 2) - (winwidth/2) ; // center the window right to left
	wintop = (screen.height / 2) - winheight-30; // center the window top to bottom
	var features = 'toolbar=0,scrollbars=0,location=0,frameborder=no,border=0,status=0,menubar=0';
	features += ',height=' + winheight + ',width=' + winwidth+',top=' + wintop + ',left=' + winleft ;

	progressHandle = window.open('/rtc/progress.cfm','progressWindow',features);
	progressHandle.focus();
}
//close the window opened above
function closeProgressBarWindow()
{
	closeHandle=window.open('','progressWindow');
	closeHandle.close();
}



function show_av_clip(unique_av_id, flashcom_ip, enable_ssl)
{
	if(flashcom_ip == null)
	{
		flashcom_ip="192.168.1.10";
	}

	if(enable_ssl == null)
	{
		enable_ssl="0";
	}

	var av_div=getDiv(unique_av_id);
	if (av_div.style.display == "none")
	{
		if(av_div.innerHTML =="&nbsp;")
		{
			 base_url="flashcom_server_ip="+flashcom_ip+"&enable_ssl_flashcom="+enable_ssl+"&unique_id="+unique_av_id;
			 av_div.innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH=215 HEIGHT=241 id=av_recorder ALIGN= >';
			 av_div.innerHTML+='<PARAM NAME=movie VALUE="/im/av_recorder.swf?'+base_url+'"> <PARAM NAME=quality VALUE=high> ';
			 av_div.innerHTML+='<PARAM NAME=bgcolor VALUE=#FFFFFF> ';
			 av_div.innerHTML+='<EMBED src="/im/av_recorder.swf?'+base_url+'" quality=high bgcolor="#FFFFFF" WIDTH=215 HEIGHT=241 NAME=av_recorder ALIGN=  TYPE=application/x-shockwave-flash></EMBED>';
			 av_div.innerHTML+='</OBJECT>';
		}
		av_div.style.display = "";
	}
	else
	{
		av_div.style.display = "none";
	}
}
function getDiv(name)
{
	if (document.all)
	return document.all(name);
	else if( document.layers)
	return document.layers[name];
	else
	return "CANNOT GET DIV";

}

function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style)
    link.style.cursor = 'default';
}
function enableLink (link) {
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style)
    link.style.cursor =
      document.all ? 'hand' : 'pointer';
}
function toggleLink (link) {
  if (link.disabled)
    enableLink (link)
  else
    disableLink (link);
  link.disabled = !link.disabled;
}

var is_popup_calendar;

// cms.js
function createWindow(location,name,properties) {
	window.open(location,name,properties);
}

function createWindowBare(location,name,properties) {
	createWindow(location,name,'status=yes,toolbar=no,location=no,menubar=yes,scrollbars=yes,directories=no,resizeable=yes,'+properties);
}

function createWindowBareSize(location,name,properties,width,height) {
	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;

	createWindowBare(location,name,properties + ',width=' + width + ',height=' + height + ',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}

function resizeWindow(window,width,height) {

	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;
	window.moveTo(xOffset,yOffset);
	window.resizeTo(width, height);
}

function resizeWindowNewURL(window,url,width,height) {
	window.location.href = url;
	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;
	window.moveTo(xOffset,yOffset);
	window.resizeTo(width, height);
}

/* object must be a div tag */
function openClose(object,cb) {
	if(!cb.checked) {
		object.style.visibility='hidden';
		object.style.height='1px';
	} else {
		object.style.visibility='';
		object.style.height='';
	}
}

/* object must be a div tag */
function greyOut(object,cb) {
	if(!cb.checked) {
		object.disabled=true;
		object.style.background_color='gray';
	} else {
		object.disabled=false;
		object.readonly=false;
		object.style.background_color='white';
	}
}

// sorttable.js
//*****************************************************************************
// Filename: sortTable.js
// Description: This javascript file can be applied to convert record tables
// in a HTML file to be client-side sortable by associating title columns with
// sort events.
//
// COPYRIGHT (C) 2002 HAN J. YU
// THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT
// UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE
// SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION)
// ANY LATER VERSION. THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE
// USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
// MERCHANTABILITY OF FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU GENERAL
// PUBLIC LICENSE FOR MORE DETAILS.
//
// YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE ALONG
// WITH THIS PROGRAM; IF NOT, WRITE TO:
//
// THE FREE SOFTWARE FOUNDATION, INC.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
//
// Bugs/Comments: han@velocityhsi.com
//
// Change History:
//
// 11-26-01:
//	o Made a few more settings configurable (i.e. data delimiter etc).
//	o Added a check for the browser type/version (>= IE 5.0 allowed).
// 11-27-01:
//	o Used document.getElementById method to retrieve object
//	o Now supports both IE 5.0 or greater and Netscape 6.0 or greater
// 11-28-01:
//	o Fixed the status display for Netscape.
//	o Fixed the cursor shape for Netscape. Used pointer instead of hand.
// 11-29-01:
//	o Fixed a cursor bug for IE 5.5
// 12-03-01:
//	o Uses delete/insert cell when doing the sort.
//	o Uses delete/insert cell for the title.
// 12-04-01:
//	o Created redrawTitle function to tidy things up a bit.
// 12-09-01:
//	o Used the innerMost cell's nodeValue to display title name.
// 12-10-01:
//	o Now preserves the align property of the title cell.
//	o Allows to have multiple child nodes inside the title cell.
//	o Simulates <TH> by centeing and bold-facing title cell contents.
// 01-21-02: (Thanks to Ric Shumack ...)
//	o Added one more condition for table init call (table.tainted == false)
//	o Used the preferred method for checking the browser version
// 03-01-02: (Recommendation from Dan ...)
//	o Default sorting will be applied to all tables upon loading
// 03-12-02:
//	o Changed parseInt to parseFloat in compare function
// 03-13-02:
//	o Ignores THEAD, TFOOT in the data row list
// 03-18-02:
//	o Compare as numbers only if both inputs are number
// 03-19-02:
//	o Now compares IETF recognized date string inputs
// 03-29-02: (Recommendation from Ashley ...)
//	o New global settings for up/down images and title font face
// 03-31-02:
//	o Retains various cell properties
//	o align, vAlign, bgColor, noWrap, width, height
//	o borderColor, borderColorLight, borderColorDark
//	o Bug fix in isDate method.
// 04-04-02: (Thanks to Steen ...)
//	o Can have separate table for titles
// 04-06-02: (Thanks to Steen ...)
//	o CSS properties are preserved
//	o Bug fix (&nbsp; removed)
//	o Title cell events applied to cells
// 04-08-02:
//	o Used eval to simplify the code
// 04-24-02:
//	o Removes HTML tags when comparing cell content
//*****************************************************************************

//*****************************************************************************
// sortTable.js
//
// This script contains useful functions that can be used to convert ordinary
// tables into sortable tables by modifying the HTML sources.
//
// Here is how one can do that. The following assumptions are required
// for the tables to be sorted.
//
// 1. All the record columns must be the same lengh. Otherwise (i.e. the ones
//    that contain colspan) the rows will be ignored.
//
// 2. Row spans can not happen in the record rows though column spans
//    can be one of the record rows.
//
// 3. Row-spanned single column will be considered as title.
//
// To enable the sorting, simply include this javascript source file and
// add an onLoad event to the <body> like below:
//
// <body onLoad='initTable("table1");initTable("table2");' ...>
//
// Note that all the tables that need to be sorted MUST contain ID tag.
// So, if they do not exist, you must create one for each table that
// needs to be sorted. Also, the table names/ids MUST BE UNIQUE.
//*****************************************************************************
// Global variables
var table;				// Table object
var ttable;				// Title Table object
var tableId;				// Current Table ID
var ttableId;				// Current Title Table ID
var rowArray = new Array();		// Data row array
var rowIdArray = new Array();		// Data row ID array
var rowPropArray = new Array();		// Data row property array
var titleRowArray = new Array();	// Contains row pointer for titles
var titleInnerHTMLArray = new Array();	// Contains innerHTML for title cells
var titleSpanCountArray = new Array();	// Contains the row-span count
var titleRowCellArray = new Array();	// Dynamically constructed title cells
var titleSpanCellArray = new Array();	// Title elelments from row-spanned
var colSpanArray = new Array();		// Rows col-spanned
var colTitleFilled = new Array();	// Indicates whether title is filled
var sortIndex;				// Selected index for sort
var descending = false;			// Descending order
var nRow, actualNRow, maxNCol;		// Various table stats
var origColor;				// Holds original default color
var isIE;				// True if IE
var pageLoaded = false;			// Has page been loaded
var separateTitle = false;		// Has separate title table
var linkEventString =			// What's insider <a> tag
	'onMouseOver=\'setCursor(this);' +
	'setColor(this,"selected");\' ' +
	'onMouseOut=\'setColor(this,"default");\' ' +
	'onClick=\'sortTable(';
var cellPropArray = new Array(		// Cell properties to preserve
	"align", "vAlign", "bgColor",
	"noWrap", "width", "height",
	"borderColor",
	"borderColorLight",
	"borderColorDark");

// Configurable constants
var useImg = false;		// Uses images if true
var ascChrFile = "up.gif";	// Image for ascending sort
var desChrFile = "down.gif";	// Image for descending sort
var ascChr = "^";		// Symbol for ascending sort
var desChr = "v";		// Symbol for descending sort
var useCustomTitleFont = false;	// Uses custom fonts for titles
var titleFont = "Trebuchet MS";	// Title Font
var selectedColor = "blue";	// Color for sort focus
var defaultColor = "black";	// Default color for sort off-focus
var recDelimiter = '|';		// Char used as a record separator
var cellPropDelimiter = ",";	// Char used as a cell prop separator
var updownColor = 'gray';	// Specified the color for up/downs
var doSortUponLoad = true;	// Do the sort upon page load
var defaultSortColumn = 0;	// Indicates the default sort column index
var columnSortableString='';
var hasCheckBox=0;       	//determine the first column is for checkbox
				//so when resort, should reflect this option's value


//*****************************************************************************
// Main function. This is to be associated with onLoad event in <BODY>.
//
// IMPORTANT: This is the only function that needs to be included in the pages
// to be sorted. The rest of the functions are simply called by this
// function.
//*****************************************************************************
function initTable(obj, defaultColumn, columnString, descending_temp)
{
	// Check whether it's viewed by IE 5.0 or greater
	if (! checkBrowser()) return;

	if(descending_temp != null)
	{
		descending=descending_temp;
	}


	defaultSortColumn=defaultColumn;
	columnSortableString=columnString;
	// Local variables
	var countCol;
	var currentCell;
	var nColSpan, nRowSpannedTitleCol, colPos;
	var titleFound = false;
	var skipRow = false;
	var rNRowSpan, rNColSpan, parentNodeName;
	var cCellContent, cCellSetting;
	var sObj;
	var ctable;
	var doneftable = false;
	var cmd;

	// Initializing global table object variable
	if (obj.tagName == "TABLE")
	{
		// Assumes that the obj is THE OBJECT
		table = obj;
	}
	else
	{
		// Assumes that the obj is the id of the object
		table = document.getElementById(obj);
		sObj = obj + "title";
		ttable = document.getElementById(sObj);
	}

	// Check whether it's an object
	if (table == null) return;

	// Check whether it's a table
	if (table.tagName != "TABLE") return;

	if (ttable != null && ttable.tagName == "TABLE")
		separateTitle = true;

	// No need to re-init if it's already done
	if (tableId == table.id && table.tainted == false) return;

	// Setting table id
	tableId = table.id;

	if (separateTitle) ttableId = ttable.id;

	// Initializing the max col number with the size of last data row
	maxNCol = table.rows[table.rows.length-1].cells.length;


	// Initializing arrays
	rowArray = new Array();
	rowIdArray = new Array();
	rowPropArray = new Array();
	colSpanArray = new Array();
	colTitleFilled = new Array();
	titleRowArray = new Array();
	titleInnerHTMLArray = new Array();
	titleSpanCountArray = new Array();
	titleRowCellArray = new Array();

	for (var i=0; i<maxNCol; i++)
		colTitleFilled[i] = false;

	// Setting the number of rows
	nRow = table.rows.length;

	// Should have at least 1 row
	if (nRow < 1) return;

	// Initialization of local variables
	actualNRow = 0;			// Number of actual data rows
	rNRowSpan = 0;			// Remaining rows in the row span
	rNColSpan = 0;			// Remaining cols in the col span
	nRowSpannedTitleCol = 0;	// Number of title cols from row span

	// Loop through rows
	for (var i=0; i<nRow; i++)
	{
		if (! separateTitle)
		{
			ctable = table;
		}
		else if (i == 0 && separateTitle && titleFound == false)
		{
			ctable = ttable;
			nRow = ttable.rows.length + 1;
		}

		if (! doneftable && separateTitle && titleFound)
		{
			ctable = table;
			nRow = table.rows.length;
			i = 0;
			doneftable = true;
		}

		skipRow = false;
		// Skip if it's THEAD, TFOOT
		if (ctable.rows[i].parentNode != null)
		{
			parentNodeName = ctable.rows[i].parentNode.nodeName;
			parentNodeName.toUpperCase();
			if (parentNodeName == 'THEAD' ||
				parentNodeName == 'TFOOT')
			{
				skipRow = true;
			}
		}
		nColSpan = 1, colPos = 0;
		// Loop through columns
		// Initializing
		for (var j=0; j<ctable.rows[i].cells.length; j++)
		{
			// Do this iff title has not been found
			if (titleFound == false)
			{
				if (ctable.rows[i].cells[j].rowSpan > 1)
				{
					if (ctable.rows[i].cells[j].colSpan < 2)
					{
						titleSpanCellArray[colPos] =
							ctable.rows[i].cells[j];
						titleRowArray[colPos] =
							ctable.rows[i];
						colTitleFilled[colPos] = true;
						nRowSpannedTitleCol++;
					}
					if (ctable.rows[i].cells[j].rowSpan - 1
						> rNRowSpan)
					{
						rNRowSpan =
							ctable.
							rows[i].cells[j].
							rowSpan - 1;

						if (ctable.rows[i].
							cells[j].colSpan > 1)
							rNColSpan =
								rNRowSpan + 1;
					}
				}
			}
			if (ctable.rows[i].cells[j].colSpan > 1 &&
				rNColSpan == 0)
			{
				nColSpan = ctable.rows[i].cells[j].colSpan;
				colPos += nColSpan;
			}
			else
			{
				colPos++;
			}
		}

		// Setting up the title cells
		if (titleFound == false && nColSpan == 1 &&
			rNRowSpan == 0 && rNColSpan == 0)
		{
			colSpanArray[i] = true;
			titleFound = true;

			// Using indivisual cell as an array element
			countCol = 0;
			for (var j=0;
				j<ctable.rows[i].cells.length
					+ nRowSpannedTitleCol; j++)
			{
				if (colTitleFilled[j] != true)
				{
					titleRowCellArray[j] =
						ctable.rows[i].cells[countCol];
					titleRowArray[j] =
						ctable.rows[i];
					countCol++;
				}
				else
				{
					titleRowCellArray[j] =
						titleSpanCellArray[j];

				}
				titleInnerHTMLArray[j] =
					String(titleRowCellArray[j].innerHTML);
				titleSpanCountArray[j] =
					titleRowCellArray[j].rowSpan;
			}
		}
		// Setting up the data rows
		else if (titleFound == true && nColSpan == 1 &&
			rNRowSpan == 0 && !skipRow)
		{
			for (var j=0; j<ctable.rows[i].cells.length; j++)
			{
				// Can't have row span in record rows ...
				if (ctable.rows[i].cells[j].rowSpan > 1) return;

				currentCell = ctable.rows[i].cells[j];
				cCellContent = String(currentCell.innerHTML);
				for (var k=0; k<cellPropArray.length; k++)
				{
					if (k == 0)
						cmd = "cCellSetting=" +
							"String(currentCell." +
							cellPropArray[k] + ");"
					else
						cmd = "cCellSetting+=" +
							"cellPropDelimiter+" +
							"String(currentCell." +
							cellPropArray[k] + ");"
					eval(cmd);
				}

				if (j == 0)
				{
						rowArray[actualNRow] = cCellContent;
						rowPropArray[actualNRow] = cCellSetting;
				}
				else
				{
					rowArray[actualNRow] += recDelimiter +
						cCellContent;
					rowPropArray[actualNRow] +=
						recDelimiter + cCellSetting;
				}
				if (j == ctable.rows[i].cells.length-1)
					rowArray[actualNRow] += recDelimiter +
						String(actualNRow);
			}
			// Inconsistent col lengh for data rows
			if (ctable.rows[i].cells.length > maxNCol)
				return;
			actualNRow++;
			colSpanArray[i] = false;
		}
		else if (nColSpan == 1 && rNRowSpan == 0 &&
			rNColSpan == 0 && titleFound == false && !skipRow)
		{
			colSpanArray[i] = false;
		}
		else
		{
			colSpanArray[i] = true;
		}

		// Counters for row/column spans
		if (rNRowSpan > 0) rNRowSpan--;
		if (rNColSpan > 0) rNColSpan--;
	}

	// If the row number is < 1, no need to do anything ...
	if (actualNRow < 1) return;

	// Re-drawing the title row
	redrawTitle(false);

	// Sorting upon loading the page
	if (doSortUponLoad) sortTable(defaultSortColumn, table.id, 0);
}

//*****************************************************************************
// Function called to re-draw title row
//*****************************************************************************
function redrawTitle(isSort)
{
	var currentRow, innerHTML, newInnerHTML, cellIndex;
	var reAnchor, reUpDown, reLabel, cellAlign, makeBold;
	var cellOnclick, cellOnmouseover, cellOnmouseout;
	var cellClass;
	var cmd;
	var cCellPropArray = new Array();

	cellAlign = "";
	makeBold = false;
	reAnchor = / *\<a[^\>]*\>(.*) *\<\/a\>/i;
	reUpDown = /\<font *id=.*updown.* *color\=.*\>.*\<\/font\>/i;
	reLabel = /\>([^\<]*)\</g;

	// Re-drawing the title row
	for (var j=0; j<maxNCol; j++)
	{
		if (j==0)
			continue;
		currentRow = titleRowArray[j];
		innerHTML = String(titleInnerHTMLArray[j]);
		cellIndex = titleRowCellArray[j].cellIndex;

		// Recording cell settings
		for (var k=0; k<cellPropArray.length; k++)
		{
			cmd = "cCellPropArray[" + k +
				"]=titleRowCellArray[j]." +
				cellPropArray[k] + ";";
			eval(cmd);
		}
		cellClass = titleRowCellArray[j].getAttribute('className');

		currentRow.deleteCell(cellIndex);
		currentRow.insertCell(cellIndex);

		// Setting the font type for the title
		if (cellAlign != "")
			currentRow.cells[cellIndex].align =
				cellAlign;
		if (titleRowCellArray[j].tagName == "TH")
		{
			makeBold = true;
		}

		// Restoring cell settings
		for (var k=0; k<cellPropArray.length; k++)
		{
			cmd = "currentRow.cells[cellIndex]." +
				cellPropArray[k] +
				"=cCellPropArray[" + k + "];";
			eval(cmd);
		}

		currentRow.cells[cellIndex].setAttribute(
			'className', cellClass, 0);

		if (titleSpanCountArray[j] > 1)
			currentRow.cells[cellIndex].rowSpan =
				titleSpanCountArray[j];
		newTitle = '';
		if (j == sortIndex && isSort)
		{
			newTitle = '<font id=updown color=' +
				updownColor + '>&nbsp;';
			if (descending)
				if (useImg)
					newTitle += '<img src="' +
						desChrFile + '" alt="' +
						desChr + '">';
				else
					newTitle += desChr;
			else
				if (useImg)
					newTitle += '<img src="' +
						ascChrFile + '" alt="' +
						ascChr + '">';
				else
					newTitle += ascChr;
			newTitle += '</font>';
		}
		// Remove carriage return, linefeed, and tab
		innerHTML = innerHTML.replace(/\r|\n|\t/g, "");
		if (makeBold)
		{
			if (innerHTML.match(reLabel))
				innerHTML =
					innerHTML.replace(reLabel, "<b>$1</b>");
			else
				innerHTML =
					innerHTML.replace(
						/(^.*$)/, "<b>$1</b>");
		}
		innerHTML = innerHTML.replace(reUpDown, "");
		innerHTML = innerHTML.replace(reAnchor, "$1");
		newInnerHTML =
			'<a ' + linkEventString + j + ',' +
			'"' + table.id + '"' + ',' + 0 + ');\'>';
		if (useCustomTitleFont)
			newInnerHTML += '<font face="' + titleFont + '">' +
				innerHTML + '</font>';
		else
			newInnerHTML += innerHTML;
		newInnerHTML += '</a>' + newTitle;
		currentRow.cells[cellIndex].innerHTML = newInnerHTML;

		if(columnSortableString.indexOf(j)>=0)
		{
			cellOnClick =
				currentRow.cells[cellIndex].childNodes[0].onclick;
			cellOnmouseover =
				currentRow.cells[cellIndex].childNodes[0].onmouseover;
			cellOnmouseout =
				currentRow.cells[cellIndex].childNodes[0].onmouseout;
			currentRow.cells[cellIndex].onclick = cellOnClick;
			currentRow.cells[cellIndex].onmouseover = cellOnmouseover;
			currentRow.cells[cellIndex].onmouseout = cellOnmouseout;
		}

		titleRowCellArray[j] = currentRow.cells[cellIndex];
	}
}

//*****************************************************************************
// Function called when user clicks on a title to sort
//*****************************************************************************
function sortTable(index,obj,doInit)
{
	if(hasCheckBox)
	initCheckBox();

	// Re-inializing the table object
	if (doInit) initTable(obj);

	// Local variables
	var rowContent, rowProp, cellProp;
	var rowCount;
	var rowIndex;
	var cellClass;
	var cmd;

	// Can't sort past the max allowed column size
	if (index < 0 || index >= maxNCol) return;

	// Assignment of sort index
	sortIndex = index;
	// Doing the sort using JavaScript generic function for an Array
	rowArray.sort(compare);

	// Re-drawing the title row
	//if (doInit)
	redrawTitle(true);

	// Re-drawing the table
	rowCount = 0;
	for (var i=0; i<nRow; i++)
	{
		if (! colSpanArray[i])
		{
			//alert(rowArray[rowCount]+"         i="+i );
			for (var j=0; j<maxNCol; j++)
			{
				rowContent = rowArray[rowCount].
					split(recDelimiter);
				rowIndex = rowContent[maxNCol];
				rowProp = rowPropArray[rowIndex].
					split(recDelimiter);
				cellProp = rowProp[j].split(cellPropDelimiter);
				cellClass =
					table.rows[i].cells[j].getAttribute(
						'className');

				table.rows[i].deleteCell(j);
				table.rows[i].insertCell(j);

				// Restoring cell properties
				for (var k=0; k<cellPropArray.length; k++)
				{
					cmd = "table.rows[i].cells[j]." +
						cellPropArray[k] +
						"=cellProp[" + k + "];";
					eval(cmd);
				}

				// *;* is the delimiter to seperate the dummy string
				//like 05/15/2002 5:56 PM *;*15 May 02 5:56 PM
				// as it sorts according to 05/15/2002 , show it according to 15 May 02 5:56 PM
				var index1=rowContent[j].indexOf("*;*");
				var index2=rowContent[j].indexOf("*=*");
				///alert(rowContent[j]);

				if(index1>0)
				{
					if(index2>0)
					{
						var tempHTML=rowContent[j].substring( 0, index2)+"" + rowContent[j].substring(index1+3, rowContent[j].length);
						table.rows[i].cells[j].innerHTML =tempHTML;
					}
					else
						table.rows[i].cells[j].innerHTML =rowContent[j].substring(index1+3, rowContent[j].length);
				}
				else
				table.rows[i].cells[j].innerHTML =
						rowContent[j];


					table.rows[i].cells[j].setAttribute(
						'className', cellClass, 0);

    		    if (i%2 == 0)
    		        table.rows[i].cells[j].bgColor="#f5f5f5";
    		    else
    		        table.rows[i].cells[j].bgColor="white";

			}
			rowCount++;
		}
	}

	// Switching btw descending/ascending sort
	//if (doInit)
	//{
		if (descending)
			descending = false;
		else
			descending = true;
	//}
}

//*****************************************************************************
// Function to be used for Array sorting
//*****************************************************************************
function compare(a, b)
{
	// Getting the element array for inputs (a,b)
	var aRowContent = a.split(recDelimiter);
	var bRowContent = b.split(recDelimiter);

	// Needed in case the data conversion is necessary
	var aToBeCompared, bToBeCompared;

	// Remove HTML tags (hey! but we want to leave comments!!!!!)
	reRowText = /(\< *[^\>]*\>|\&nbsp\;)/g;

	aRowContent[sortIndex] = aRowContent[sortIndex].replace(reRowText, "");
	bRowContent[sortIndex] = bRowContent[sortIndex].replace(reRowText, "");

	if (isDate(aRowContent[sortIndex]) && isDate(bRowContent[sortIndex]))
	{
		aToBeCompared = new Date(aRowContent[sortIndex]);
		bToBeCompared = new Date(bRowContent[sortIndex]);
	}
	else if (! isNaN(aRowContent[sortIndex]) &&
		! isNaN(bRowContent[sortIndex]))
	{
		aToBeCompared = parseFloat(aRowContent[sortIndex], 10);
		bToBeCompared = parseFloat(bRowContent[sortIndex], 10);
	}
	else
	{
		aToBeCompared = aRowContent[sortIndex];
		bToBeCompared = bRowContent[sortIndex];
	}

	if (aToBeCompared < bToBeCompared)
		if (!descending)
		{
			return -1;
		}
		else
		{
			return 1;
		}
	if (aToBeCompared > bToBeCompared)
		if (!descending)
		{
			return 1;
		}
		else
		{
			return -1;
		}
	return 0;
}

//*****************************************************************************
// Function to determine whether it's a IETF recognized date string
//*****************************************************************************
function isDate(x)
{
	var xDate;
	xDate = new Date(x);
	if (xDate.toString() == 'NaN' ||
		xDate.toString() == 'Invalid Date')
		return false;
	else
		return true;
}

//*****************************************************************************
// Function to set the cursor
//*****************************************************************************
function setCursor(obj)
{
	var rowText, reRowText;

	reRowText = /(\< *[^\>]*\>|\&nbsp\;)/g;
	// Show hint text at the browser status bar
	rowText = String(obj.innerHTML);

	// Remove up/down
	rowText = rowText.replace(/\<font id\=updown.*\<\/font\>/ig, "");
	// Remove HTML tags and &nbsp;
	rowText = rowText.replace(reRowText, "");
	// Remove carriage return, linefeed, and tab
	rowText = rowText.replace(/\r|\n|\t/g, "");

	// Setting window's status bar
	window.status = JS_message3 + String(rowText);

	// Change the mouse cursor to pointer or hand
	if (isIE)
		obj.style.cursor = "hand";
	else
		obj.style.cursor = "pointer";
}

//*****************************************************************************
// Function to set the title color
//*****************************************************************************
function setColor(obj,mode)
{
	if (mode == "selected")
	{
		// Remember the original color
		if (obj.style.color != selectedColor)
			defaultColor = obj.style.color;
		obj.style.color = selectedColor;
	}
	else
	{
		// Restoring original color and re-setting the status bar
		obj.style.color = defaultColor;
		window.status = '';
	}
}

//*****************************************************************************
// Function to check browser type/version
//*****************************************************************************
function checkBrowser()
{
	if (navigator.appName == "Microsoft Internet Explorer"
		&& parseInt(navigator.appVersion) >= 4)
	{
		isIE = true;
		return true;
	}
	// For some reason, appVersion returns 5 for Netscape 6.2 ...
	else if (navigator.appName == "Netscape"
		&& navigator.appVersion.indexOf("5.") >= 0)
	{
		isIE = false;
		return true;
	}
	else
		return false;
}

function initCheckBox()
{
	var currentCell;
	var cCellContent;

	// Should have at least 1 row
	if (nRow < 1) return;

	// Loop through rows
	for (var i=1; i<nRow; i++)
	{
		currentCell = table.rows[i].cells[0];
		cCellContent = String(currentCell.innerHTML);

		if(rowArray[i-1]!=null)
		rowArray[i-1] = cCellContent + rowArray[i-1].substring(rowArray[i-1].indexOf(recDelimiter));
	}

}

// menus.js



//// Called to parse the config and initialize/draw the menuing elements
function _init(){

	//alert(document.all.tags("IMG").length);
	//for(var i=0;i<document.all.length;i++){
	//	var identify=document.all[i].getAttribute("id");
    if(!ns4)
    {
	for(var i=0;i<document.all.tags("IMG").length;i++){
		var identify=document.all.tags("IMG")[i].getAttribute("id");
		if(identify){

			if(identify.indexOf('src:menusrc')>=0)
			{
			var document_all_i=document.all.tags("IMG")[i];

			countall++;

			parentMenuTop=getPageCoordinates(document_all_i).y;
			parentMenuLeft=getPageCoordinates(document_all_i).x;

			var attribs = _eat_attrib(identify);

			var tree = new Array();
			var src = document.all.item(attribs["src"]).innerText;	// get the config info from the contents of the designated source element

			src = _strip(src);	// remove whitespace informatin
			tree = _compile(tree,src);	// turn it into a multilevel array

			// at this time, associate the element the
			// menu is attached to with the created menuing elements
			var menuId = _menus.length;

			document_all_i.menuId = menuId;
			document_all_i.onmouseover = _rootmouseover;
			document_all_i.onmouseout = _rootmouseout;


			// get and preset designer preferences
			//var attribs = _eat_attrib(document.all[i].getAttribute("id"));
			attribs["border-width"] = (attribs["border-width"]!=null?attribs["border-width"]:0);
			attribs["border-color"] = (attribs["border-color"]!=null?attribs["border-color"]:"black");
			attribs["background"] = (attribs["background"]!=null?attribs["background"]:"#cccccc");
			attribs["highlight"] = (attribs["highlight"]!=null?attribs["highlight"]:"#DCDCDC");
			attribs["font-size"] = (attribs["font-size"]!=null?attribs["font-size"]:"7pt");
			attribs["font-family"] = (attribs["font-family"]!=null?attribs["font-family"]:"Verdana,Arial");
			attribs["font-color"] = (attribs["font-color"]!=null?attribs["font-color"]:"#000000");
			attribs["icon-color"] = (attribs["icon-color"]!=null?attribs["icon-color"]:"black");
			attribs["arrow"] = (attribs["arrow"]!=null?attribs["arrow"]:true);
			attribs["showrow"] = (attribs["showrow"]!=null?attribs["showrow"]:true);
			attribs["height"] = (attribs["height"]!=null?attribs["height"]:22);
			attribs["width"] = (attribs["width"]!=null?attribs["width"]:150);
			attribs["arrow-offset"] = (attribs["arrow-offset"]!=null?Number(attribs["arrow-offset"]):170);
			attribs["menu-offset"] = (attribs["menu-offset"]!=null?Number(attribs["menu-offset"]):1);
			attribs["menu-topoffset"] = (attribs["menu-topoffset"]!=null?Number(attribs["menu-topoffset"]):0);
			attribs["wait"] = (attribs["wait"]!=null?Number(attribs["wait"]):50);
			if(attribs["top"]!=null)
			{
				menuRootTop[menuId]=Number(attribs["top"]);
			}
			else
			{
				menuRootTop[menuId]=parentMenuTop+menuRootHeight;
				parentMenuTop=0;
			}

			if(attribs["left"]!=null)
			{
				menuRootLeft[menuId]=Number(attribs["left"]);
			}
			else
			{
				menuRootLeft[menuId]=parentMenuLeft+5;
				parentMenuLeft=0;
			}

			document_all_i.attribs = attribs;

			// create all of the needed elements for this menu
			treeArray[menuId]=tree;
			attribArray[menuId]=attribs;

			_create(document_all_i,tree);
		}


		}

	}
   }
   //alert("countall is "+countall);  //count is 66

}
window.onload = _init;
/////////////////////////

function getPageCoordinates (element) {
  var x = y = 0;
  do {
    x+= element.offsetLeft;
    y += element.offsetTop;
  }
  while ((element = element.offsetParent));
  return {x: x, y: y};
}



/////////////////////////
//// takes a position and a string,
//// returns the position of the next unpaired "]" character
function _pair(after,str){
	while(1){
		var nextA = str.indexOf("[",after + 1);
		var nextB = str.indexOf("]",after + 1);
		if(nextA == -1){
			return nextB;
		}
		if(nextA > nextB){
			return nextB;
		}
		after = _pair(nextA,str);
	}
}

/////////////////////////
//// transforms raw text input into a multilevel array
//// returns an array based on the string input
function _compile(ary,str){
	while(1){ // keep circling and eating the str

		// when the str is empty, return the built array
		if(str.length == 0){
			return ary;
		}

		// is there any more sub-arrays?
		var nextA = str.indexOf("[");
		if(nextA == -1){
			var go = str;
			var spawn = "";
			str = "";
		}else{
			var go = str.substring(0,nextA);
			var spawn = str.substring(str.indexOf("[") + 1,_pair(str.indexOf("["),str))
			str = str.substring(_pair(str.indexOf("["),str) + 1,str.length);
		}

		// build a flat array of key/value pairs and strip out the empty elements
		var A = go.split(";");
		var A2 = new Array();
		for(var j=0;j<A.length;j++){
			if(A[j].indexOf("!") != -1){
				A2[A2.length] = A[j];
			}
		}
		A = A2;

		// parse the flat array
		for(var i = 0;i < A.length;i++){
			var tmpA = A[i].split("!");
			var thisary = ary.length;
			ary[thisary] = new Array();

			// attach a sub array if needed
			if((i+1)==A.length && spawn.length != ""){
				ary[thisary] = _compile(ary[thisary],spawn);
			}
			// assign properties to this array based on the parsed array key/value pairs
			ary[thisary].name = tmpA[0];
			ary[thisary].url = tmpA[1];
			ary[thisary].desc = tmpA[2];
			ary[thisary].icon = tmpA[3];
		}
	}
}
///////////////////////


///////////////////////
//// Actually draw and initialize elements from the array
function _create(e,ary){

	var str = new String();
	var menuId = _menus.length;	// save the ID for this menu
	str 	= '<DIV ID="_div_'
		+ menuId		// give it a unique name
		+ '" STYLE="visibility:hidden;position:absolute;top:0;left:0;width:'
		+ e.attribs["width"]
		+ ';height:10;background-color:black;">';
	e.insertAdjacentHTML("AfterEnd",str);	// paste it in below the root element
	var thismenu = document.all.item("_div_" + menuId);	// save a reference to the element object
	_menus[menuId] = thismenu;	// save a reference to the element object in a global array for later use
	thismenu.menuId = menuId;	// tell the element object where it is in the global array
	thismenu.close = _close;	// assign a close function to it
	thismenu.menuParent = null;	// initialize some variables to null
	thismenu.menuChild = null;
	thismenu.highlightBG = e.attribs["highlight"];
	thismenu.normalBG = e.attribs["background"];
	thismenu.menuOffset = e.attribs["menu-offset"];
	thismenu.menuTopoffset = e.attribs["menu-topoffset"];
	thismenu.waitDelay = e.attribs["wait"];
	thismenu.realtime=1;
	var prevBottom = 0;		// initialize where the option elements should start drawing

	thismenu.style.pixelHeight = prevBottom;	// set the height on the menu element
}
/////////////////////


function _realtimecreate(e,ary, thismenu, menuId)
{
	var str = new String();
	var prevBottom = 0;

	// create a span element for every option
	for(var i=0;i<ary.length;i++){
		var tempS=ary[i].name;

		eval('urlArray['+menuId+''+i+'] = ary['+i+'].url;');

		///alert("  URL "+i+"  ="+ary[i].url);

		if(tempS.indexOf("menu_division")>=0)
		{
			str 	= '<SPAN ID="_link_d'	// assign a unique name
				+ menuId
				//+ '_'
				+ i
				+ '" STYLE="position:absolute;top:'
				+ prevBottom		// position it correctly
				+ ';left:0;height:'
				+ e.attribs["height"]
				+ ';overflow:hidden;width:'
				+ e.attribs["width"]
				+ ';background:'
				+ e.attribs["background"]
				+ ';border-width:'
				+ 0
				+ ';border-style:solid;border-color:'
				+ e.attribs["border-color"]
				+ ';';
				if(e.attribs["showrow"]!=true && i != 0){
					str	+='border-top-width:0;';
				}
				str	+='text-align:left;font-size:'
					+ e.attribs["font-size"]
					+ ';padding-left:4;">';
				if(ary[i].icon!=null){
						str	+='<SPAN><img border=0 src="'+ ary[i].icon+'">'
					+ '</SPAN>';
			}
			str	+='<hr style="color: #aaaaaa" width=90% align=center> '
			str	+='</SPAN>';

		}
		else
		{
		str 	= '<SPAN ID="_link_'	// assign a unique name
			+ menuId
			//+ '_'
			+ i
			+ '" STYLE="position:absolute;top:'
			+ prevBottom		// position it correctly
			+ ';left:0;height:'
			+ e.attribs["height"]
			+ ';overflow:hidden;width:'
			+ e.attribs["width"]
			+ ';background:'
			+ e.attribs["background"]
			+ ';border-width:'
			+ e.attribs["border-width"]
			+ ';border-style:solid;border-color:'
			+ e.attribs["border-color"]
			+ ';';
		if(e.attribs["showrow"]!=true && i != 0){
			str	+='border-top-width:0;';
		}
		str	+='text-align:left;font-size:'
			+ e.attribs["font-size"]
			+ ';padding-left:4;">';
		if(ary[i].icon!=null){

			str	+='<SPAN><img border=0 src="'+ ary[i].icon+'">'
				+ '</SPAN>';
		}
		str	+='<A HREF="'
			+ ary[i].url
			+ '" TITLE="'
			+ ary[i].desc
			+ '" STYLE="font-family:'
			+ e.attribs["font-family"]
			+ ';color:'
			+ e.attribs["font-color"]
			+ ';font-weight: bold; text-decoration: none'
			+ ';padding-left:3;"'
			+ ' ID="_link_a'	// assign a unique name
			+ menuId
			//+ '_'
			+ i
			+ '"'
			+'>'
			+ ary[i].name		// fill in the content/name
			+ '</A>';
		if(ary[i].length > 0 && e.attribs["arrow"]){
			str	+='<SPAN STYLE="font-family:webdings;position:absolute;top:0;left:'
				+ e.attribs["arrow-offset"]
				+ ';width:'
				+ (e.attribs["width"] - e.attribs["arrow-offset"])
				+ ';overflow:hidden;color:'
				+ e.attribs["icon-color"]
				+ '">&#052;</SPAN>';
		}
		str	+='</SPAN>';
		}

		thismenu.insertAdjacentHTML("BeforeEnd",str);	// insert it inside the menu element

		if(tempS.indexOf("menu_division")>=0)
		{
			thisoption = document.all.item('_link_d' + menuId  + i);//'_'
		}
		else
		{
			thisoption = document.all.item('_link_' + menuId  + i);//'_'
		}

		thisoption.menuId = menuId;	// save some references and initialize some variables

		thisoption.onmouseover = _optionmouseover;//Division;
		thisoption.onmouseout = _optionmouseout;//Division;

		if(tempS.indexOf("menu_division")<0)
		{
			thisoption.onclick = _optiononclick;
		}

		if(thisoption.style!=null)
		{
			prevBottom = thisoption.style.pixelTop + (e.attribs["height"] - e.attribs["border-width"]);	// where should the next one draw?
		}
		else
		{
			prevBottom = (e.attribs["height"] - e.attribs["border-width"]);	// where should the next one draw?
		}
		if(ary[i].length > 0){		// For submenu here, better draw it!
			alert("ERROR with submenu, not dynamic");
			thisoption.menuChild=_menus.length;	// tell this option that it has a child
			_create(e,ary[i]);
		}
	}


}


///////////////////////////////////////////
///////////////////////////////////////////
//// All the following are used on the "fly"
//// as needed during the documents life
////
////

// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;



var _menus = new Array();	// global array of menus
var _currentMenu = null;	// temporary storage of the current and current root menu elements
var _rootMenu = null;
var _rootKludge = null;
var _zIndex = 1;
_menus[0]=_zIndex;

var menuRootTop=new Array();
var menuRootLeft=new Array();
var urlArray=new Array();
var treeArray=new Array();

var attribArray=new Array();

var parentMenuTop=0;
var parentMenuLeft=0;
var countall=0;

var menuRootHeight=10;
var shouldNotShowRoot=0;
var menu_offsetHeight=200;
var menu_offsetWidth=150;

/////////////////////
//// show the menu for this object
function _rootmouseover(){
	var e = window.event.srcElement;


	var thismenu = _menus[e.menuId];

	if(thismenu.realtime)
	{
		thismenu.realtime=0;
		e.attribs=attribArray[e.menuId];
		_realtimecreate(e, treeArray[e.menuId], thismenu, e.menuId);

	}

	if(_rootMenu != null){
		_menus[_rootMenu].close();
	}



	_rootMenu = e.menuId;	// store a temporary reference
	_rootKludge = e.menuId;
	//var attribs = _eat_attrib(e.getAttribute("id"));	// initialize its position based on the config

	var rightedge = document.body.clientWidth- event.screenX;//event.clientX;
	var bottomedge = document.body.clientHeight - event.screenY;//event.clientY;

	if (rightedge < menu_offsetWidth)
	rightedge = menuRootLeft[e.menuId] - menu_offsetWidth;//document.body.scrollLeft
	else
	rightedge =  menuRootLeft[e.menuId];

	if (bottomedge < menu_offsetHeight)
	bottomedge =  menuRootTop[e.menuId] - menu_offsetHeight;//document.body.scrollTop
	else
	bottomedge = menuRootTop[e.menuId];


	_menus[e.menuId].style.pixelTop =bottomedge ;
	_menus[e.menuId].style.pixelLeft =rightedge;




	_menus[e.menuId].style.visibility = "visible";
	_menus[e.menuId].style.zIndex = _zIndex++;
}
////////////////////

////////////////////
//// if the mouse leaves the main element,
//// try to close the displayed menu
function _rootmouseout(){
	if(shouldNotShowRoot)
	{
		_rootKludge = null;
		window.setTimeout("if(_rootKludge != " + _rootMenu + "){_menus[" + _rootMenu + "].close();}",_menus[_rootMenu].waitDelay);
	}

}
////////////////////


////////////////////
//// nifty little IMPORTANT recursive function that
//// returns true only if the id to check
//// is in the heritage of the current menu!
function _heritage(menu,check){
	if(_menus[menu].menuId == check){
		return true;
	}else{
		// if I have a parent, check it, otherwise the answer is no
		if(_menus[menu].menuParent != null){
			return _heritage(_menus[menu].menuParent,check);
		}else{
			return false;
		}
	}
}
///////////////////


///////////////////
//// associated with every menu element object,
//// close this menu unless it is still active
function _close(){
	if(_currentMenu != null){
		if(_heritage(_currentMenu,this.menuId)){
			return;
		}
	}
	if(this.menuChild != null){
		_menus[this.menuChild].close();
	}
	this.style.visibility = "hidden";
	this.menuChild = null;
	this.menuParent = null;
}
//////////////////



function _optiononclick()
{
	var thisID=window.event.srcElement.getAttribute("id");
	if(thisID.indexOf("_link_")>=0)
	{
		//close root window, otherwise with popup window showing, this menu still showing
		window.setTimeout("_menus[_rootMenu].close()",_menus[_rootMenu].waitDelay);
		_currentMenu = null;

		var dest=thisID.substring(6,thisID.length);
		if(dest.indexOf("a")>=0)
		{
			dest=dest.substring(1,dest.length);
		}


		//eval('window.location.href=urlArray['+thisID.substring(6,thisID.length)+'];');
		window.location.href=urlArray[dest];

	}
	// Do not let <A> tag process this event again
	window.event.returnValue = false;
	//window.event.cancelBubble = true;
}


//////////////////
//// when the mouse passes over an option
function _optionmouseover(){
	if(window.event.srcElement==null||window.event.fromElement==null)
	{
		return;
	}

	// some ugly kludges to reduce flashing when the mouse passes through a subelement of the option
	if(window.event.srcElement.menuId==null && window.event.fromElement.id == window.event.srcElement.offsetParent.id){
		return;
	}
	if(window.event.fromElement.offsetParent!=null){
		if(window.event.fromElement.menuId==null && window.event.srcElement.id == window.event.fromElement.offsetParent.id){
			return;
		}
	}

	shouldNotShowRoot=0;

	if(window.event.srcElement.menuId==null){
		var e = window.event.srcElement.offsetParent;
	}else{
		var e = window.event.srcElement;
	}

	var thisID1=window.event.srcElement.getAttribute("id");
	if(thisID1.indexOf("_link_d")<0)
	{
		e.style.background = _menus[e.menuId].highlightBG;		// highlight it
	}

	_currentMenu = e.menuId;		// reset the current menu
	if(_menus[_currentMenu].menuChild != null){	// close any previous children
		_menus[_menus[_currentMenu].menuChild].close();
	}
	if(e.menuChild!=null){		// if this option has a submenu, display it
		_menus[_currentMenu].menuChild = e.menuChild;	// tell the menu it has a child
		_menus[e.menuChild].menuParent = _currentMenu;	// tell the child it has a parent
		_menus[e.menuChild].style.pixelTop = _menus[_currentMenu].style.pixelTop + e.style.pixelTop + _menus[_currentMenu].menuTopoffset;
		_menus[e.menuChild].style.pixelLeft = _menus[_currentMenu].style.pixelLeft + _menus[_currentMenu].style.pixelWidth + _menus[_currentMenu].menuOffset;
		_menus[e.menuChild].style.visibility = "visible";
		_menus[e.menuChild].style.zIndex = _zIndex++;
	}
}
/////////////////


/////////////////
//// when the mouse leaves the option
function _optionmouseout(){

	// some ugly kludges to reduce flashing when the mouse passes through a subelement of the option
	if(window.event.srcElement==null||window.event.toElement==null)
	{
		return;
	}

	if(window.event.srcElement.menuId==null && window.event.toElement.id == window.event.srcElement.offsetParent.id){
		return;
	}
	if(window.event.toElement.offsetParent!=null){
		if(window.event.toElement.menuId==null && window.event.srcElement.id == window.event.toElement.offsetParent.id){
			return;
		}
	}

		shouldNotShowRoot=1;

	if(window.event.srcElement.menuId==null){
		var e = window.event.srcElement.offsetParent;
	}else{
		var e = window.event.srcElement;
	}

	var thisID2=window.event.srcElement.getAttribute("id");
	if(thisID2.indexOf("_link_d")<0)
	{
		e.style.background = _menus[e.menuId].normalBG;		// unhighlight it
	}

	var to = window.event.toElement.menuId;		// greener pasture?
	if(to!=null){	// leaving to a menu element
		if(to!=e.menuId){	// not this menu
			_menus[_currentMenu].close();
		}else{			// this menu, but hide any existing children
			if(_menus[e.menuId].menuChild!=null){
				_menus[_menus[e.menuId].menuChild].close();
			}
		}
	}else{		// wait a bit, and close the whole menu
		window.setTimeout("_menus[_rootMenu].close()",_menus[_rootMenu].waitDelay);
	}
	_currentMenu = null;
}
//////////////////




///////////////////////////////////////////
///////////////////////////////////////////
//// Common Utility Functions
////
////
////


//////////////////
//// util for element attribute parsing
//// returns an array of all of the keys = values
function _eat_attrib(str){
	var chunks = new Array();
	var all = new Array();

	chunks=str.split(";");

	for(var i=0;i<chunks.length;i++){
		var tmpA = new Array();
		tmpA=chunks[i].split(":");
		all[tmpA[0]]=tmpA[1];
	}
	return all;
}
////////////////////


//////////////////////
//// util to remove characters from input string
//// and return flattened string
function _strip(str){
	var A = new Array();

	A = str.split("\t");
	str = A.join("");

	A = str.split("\n");
	str = A.join("");

	A = str.split("\r");
	str = A.join("");

	return str;
}
//////////////////


// overlib.js
var INARRAY		=	1;
var CAPARRAY		=	2;
var STICKY		=	3;
var BACKGROUND		=	4;
var NOCLOSE		=	5;
var CAPTION		=	6;
var LEFT		=	7;
var RIGHT		=	8;
var CENTER		=	9;
var OFFSETX		=	10;
var OFFSETY		=	11;
var FGCOLOR		=	12;
var BGCOLOR		=	13;
var TEXTCOLOR		=	14;
var CAPCOLOR		=	15;
var CLOSECOLOR		=	16;
var WIDTH		=	17;
var BORDER		=	18;
var STATUS		=	19;
var AUTOSTATUS		=	20;
var AUTOSTATUSCAP	=	21;
var HEIGHT		=	22;
var CLOSETEXT		=	23;
var SNAPX		=	24;
var SNAPY		=	25;
var FIXX		=	26;
var FIXY		=	27;
var FGBACKGROUND	=	28;
var BGBACKGROUND	=	29;
var PADX		=	30; // PADX2 out
var PADY		=	31; // PADY2 out
var FULLHTML		=	34;
var ABOVE		=	35;
var BELOW		=	36;
var CAPICON		=	37;
var TEXTFONT		=	38;
var CAPTIONFONT		=	39;
var CLOSEFONT		=	40;
var TEXTSIZE		=	41;
var CAPTIONSIZE		=	42;
var CLOSESIZE		=	43;
var FRAME		=	44;
var TIMEOUT		=	45;
var FUNCTION		=	46;
var DELAY		=	47;
var HAUTO		=	48;
var VAUTO		=	49;
var CLOSECLICK		=	50;
var CSSOFF		=	51;
var CSSSTYLE		=	52;
var CSSCLASS		=	53;
var FGCLASS		=	54;
var BGCLASS		=	55;
var TEXTFONTCLASS	=	56;
var CAPTIONFONTCLASS	=	57;
var CLOSEFONTCLASS	=	58;
var PADUNIT		=	59;
var HEIGHTUNIT		=	60;
var WIDTHUNIT		=	61;
var TEXTSIZEUNIT	=	62;
var TEXTDECORATION	=	63;
var TEXTSTYLE		=	64;
var TEXTWEIGHT		=	65;
var CAPTIONSIZEUNIT	=	66;
var CAPTIONDECORATION	=	67;
var CAPTIONSTYLE	=	68;
var CAPTIONWEIGHT	=	69;
var CLOSESIZEUNIT	=	70;
var CLOSEDECORATION	=	71;
var CLOSESTYLE		=	72;
var CLOSEWEIGHT		=	73;


////////////////////////////////////////////////////////////////////////////////////
// DEFAULT CONFIGURATION
// You don't have to change anything here if you don't want to. All of this can be
// changed on your html page or through an overLIB call.
////////////////////////////////////////////////////////////////////////////////////

// Main background color (the large area)
// Usually a bright color (white, yellow etc)
if (typeof ol_fgcolor == 'undefined') { var ol_fgcolor = "#CCCCFF";}

// Border color and color of caption
// Usually a dark color (black, brown etc)
if (typeof ol_bgcolor == 'undefined') { var ol_bgcolor = "#333399";}

// Text color
// Usually a dark color
if (typeof ol_textcolor == 'undefined') { var ol_textcolor = "#000000";}

// Color of the caption text
// Usually a bright color
if (typeof ol_capcolor == 'undefined') { var ol_capcolor = "#FFFFFF";}

// Color of "Close" when using Sticky
// Usually a semi-bright color
if (typeof ol_closecolor == 'undefined') { var ol_closecolor = "#9999FF";}

// Font face for the main text
if (typeof ol_textfont == 'undefined') { var ol_textfont = "Verdana,Arial,Helvetica";}

// Font face for the caption
if (typeof ol_captionfont == 'undefined') { var ol_captionfont = "Verdana,Arial,Helvetica";}

// Font face for the close text
if (typeof ol_closefont == 'undefined') { var ol_closefont = "Verdana,Arial,Helvetica";}

// Font size for the main text
// When using CSS this will be very small.
if (typeof ol_textsize == 'undefined') { var ol_textsize = "1";}

// Font size for the caption
// When using CSS this will be very small.
if (typeof ol_captionsize == 'undefined') { var ol_captionsize = "1";}

// Font size for the close text
// When using CSS this will be very small.
if (typeof ol_closesize == 'undefined') { var ol_closesize = "1";}

// Width of the popups in pixels
// 100-300 pixels is typical
if (typeof ol_width == 'undefined') { var ol_width = "200";}

// How thick the ol_border should be in pixels
// 1-3 pixels is typical
if (typeof ol_border == 'undefined') { var ol_border = "1";}

// How many pixels to the right/left of the cursor to show the popup
// Values between 3 and 12 are best
if (typeof ol_offsetx == 'undefined') { var ol_offsetx = 10;}

// How many pixels to the below the cursor to show the popup
// Values between 3 and 12 are best
if (typeof ol_offsety == 'undefined') { var ol_offsety = 10;}

// Default text for popups
// Should you forget to pass something to overLIB this will be displayed.
if (typeof ol_text == 'undefined') { var ol_text = "Default Text"; }

// Default caption
// You should leave this blank or you will have problems making non caps popups.
if (typeof ol_cap == 'undefined') { var ol_cap = ""; }

// Decides if sticky popups are default.
// 0 for non, 1 for stickies.
if (typeof ol_sticky == 'undefined') { var ol_sticky = 0; }

// Default background image. Better left empty unless you always want one.
if (typeof ol_background == 'undefined') { var ol_background = ""; }

// Text for the closing sticky popups.
// Normal is "Close".
if (typeof ol_close == 'undefined') { var ol_close = "Close"; }

// Default vertical alignment for popups.
// It's best to leave RIGHT here. Other options are LEFT and CENTER.
if (typeof ol_hpos == 'undefined') { var ol_hpos = RIGHT; }

// Default status bar text when a popup is invoked.
if (typeof ol_status == 'undefined') { var ol_status = ""; }

// If the status bar automatically should load either text or caption.
// 0=nothing, 1=text, 2=caption
if (typeof ol_autostatus == 'undefined') { var ol_autostatus = 0; }

// Default height for popup. Often best left alone.
if (typeof ol_height == 'undefined') { var ol_height = -1; }

// Horizontal grid spacing that popups will snap to.
// 0 makes no grid, anything else will cause a snap to that grid spacing.
if (typeof ol_snapx == 'undefined') { var ol_snapx = 0; }

// Vertical grid spacing that popups will snap to.
// 0 makes no grid, andthing else will cause a snap to that grid spacing.
if (typeof ol_snapy == 'undefined') { var ol_snapy = 0; }

// Sets the popups horizontal position to a fixed column.
// Anything above -1 will cause fixed position.
if (typeof ol_fixx == 'undefined') { var ol_fixx = -1; }

// Sets the popups vertical position to a fixed row.
// Anything above -1 will cause fixed position.
if (typeof ol_fixy == 'undefined') { var ol_fixy = -1; }

// Background image for the popups inside.
if (typeof ol_fgbackground == 'undefined') { var ol_fgbackground = ""; }

// Background image for the popups frame.
if (typeof ol_bgbackground == 'undefined') { var ol_bgbackground = ""; }

// How much horizontal left padding text should get by default when BACKGROUND is used.
if (typeof ol_padxl == 'undefined') { var ol_padxl = 1; }

// How much horizontal right padding text should get by default when BACKGROUND is used.
if (typeof ol_padxr == 'undefined') { var ol_padxr = 1; }

// How much vertical top padding text should get by default when BACKGROUND is used.
if (typeof ol_padyt == 'undefined') { var ol_padyt = 1; }

// How much vertical bottom padding text should get by default when BACKGROUND is used.
if (typeof ol_padyb == 'undefined') { var ol_padyb = 1; }

// If the user by default must supply all html for complete popup control.
// Set to 1 to activate, 0 otherwise.
if (typeof ol_fullhtml == 'undefined') { var ol_fullhtml = 0; }

// Default vertical position of the popup. Default should normally be BELOW.
// ABOVE only works when HEIGHT is defined.
if (typeof ol_vpos == 'undefined') { var ol_vpos = BELOW; }

// Default height of popup to use when placing the popup above the cursor.
if (typeof ol_aboveheight == 'undefined') { var ol_aboveheight = 0; }

// Default icon to place next to the popups caption.
if (typeof ol_caption == 'undefined') { var ol_capicon = ""; }

// Default frame. We default to current frame if there is no frame defined.
if (typeof ol_frame == 'undefined') { var ol_frame = self; }

// Default timeout. By default there is no timeout.
if (typeof ol_timeout == 'undefined') { var ol_timeout = 0; }

// Default javascript funktion. By default there is none.
if (typeof ol_function == 'undefined') { var ol_function = Function(); }

// Default timeout. By default there is no timeout.
if (typeof ol_delay == 'undefined') { var ol_delay = 0; }

// If overLIB should decide the horizontal placement.
if (typeof ol_hauto == 'undefined') { var ol_hauto = 0; }

// If overLIB should decide the vertical placement.
if (typeof ol_vauto == 'undefined') { var ol_vauto = 0; }



// If the user has to click to close stickies.
if (typeof ol_closeclick == 'undefined') { var ol_closeclick = 0; }

// This variable determines if you want to use CSS or inline definitions.
// CSSOFF=no CSS    CSSSTYLE=use CSS inline styles    CSSCLASS=use classes
if (typeof ol_css == 'undefined') { var ol_css = CSSOFF; }

// Main background class (eqv of fgcolor)
// This is only used if CSS is set to use classes (ol_css = CSSCLASS)
if (typeof ol_fgclass == 'undefined') { var ol_fgclass = ""; }

// Frame background class (eqv of bgcolor)
// This is only used if CSS is set to use classes (ol_css = CSSCLASS)
if (typeof ol_bgclass == 'undefined') { var ol_bgclass = ""; }

// Main font class
// This is only used if CSS is set to use classes (ol_css = CSSCLASS)
if (typeof ol_textfontclass == 'undefined') { var ol_textfontclass = ""; }

// Caption font class
// This is only used if CSS is set to use classes (ol_css = CSSCLASS)
if (typeof ol_captionfontclass == 'undefined') { var ol_captionfontclass = ""; }

// Close font class
// This is only used if CSS is set to use classes (ol_css = CSSCLASS)
if (typeof ol_closefontclass == 'undefined') { var ol_closefontclass = ""; }

// Unit to be used for the text padding above
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
// Options include "px", "%", "in", "cm" and more
if (typeof ol_padunit == 'undefined') { var ol_padunit = "px";}

// Unit to be used for height of popup
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
// Options include "px", "%", "in", "cm" and more
if (typeof ol_heightunit == 'undefined') { var ol_heightunit = "px";}

// Unit to be used for width of popup
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
// Options include "px", "%", "in", "cm" and more
if (typeof ol_widthunit == 'undefined') { var ol_widthunit = "px";}

// Font size unit for the main text
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_textsizeunit == 'undefined') { var ol_textsizeunit = "px";}

// Decoration of the main text ("none", "underline", "line-through" or "blink")
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_textdecoration == 'undefined') { var ol_textdecoration = "none";}

// Font style of the main text ("normal" or "italic")
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_textstyle == 'undefined') { var ol_textstyle = "normal";}

// Font weight of the main text ("normal", "bold", "bolder", "lighter", ect.)
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_textweight == 'undefined') { var ol_textweight = "normal";}

// Font size unit for the caption
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_captionsizeunit == 'undefined') { var ol_captionsizeunit = "px";}

// Decoration of the caption ("none", "underline", "line-through" or "blink")
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_captiondecoration == 'undefined') { var ol_captiondecoration = "none";}

// Font style of the caption ("normal" or "italic")
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_captionstyle == 'undefined') { var ol_captionstyle = "normal";}

// Font weight of the caption ("normal", "bold", "bolder", "lighter", ect.)
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_captionweight == 'undefined') { var ol_captionweight = "bold";}

// Font size unit for the close text
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_closesizeunit == 'undefined') { var ol_closesizeunit = "px";}

// Decoration of the close text ("none", "underline", "line-through" or "blink")
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_closedecoration == 'undefined') { var ol_closedecoration = "none";}

// Font style of the close text ("normal" or "italic")
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_closestyle == 'undefined') { var ol_closestyle = "normal";}

// Font weight of the close text ("normal", "bold", "bolder", "lighter", ect.)
// Only used if CSS inline styles are being used (ol_css = CSSSTYLE)
if (typeof ol_closeweight == 'undefined') { var ol_closeweight = "normal";}



////////////////////////////////////////////////////////////////////////////////////
// ARRAY CONFIGURATION
// You don't have to change anything here if you don't want to. The following
// arrays can be filled with text and html if you don't wish to pass it from
// your html page.
////////////////////////////////////////////////////////////////////////////////////

// Array with texts.
if (typeof ol_texts == 'undefined') { var ol_texts = new Array("Text 0", "Text 1"); }

// Array with captions.
if (typeof ol_caps == 'undefined') { var ol_caps = new Array("Caption 0", "Caption 1"); }


////////////////////////////////////////////////////////////////////////////////////
// END CONFIGURATION
// Don't change anything below this line, all configuration is above.
////////////////////////////////////////////////////////////////////////////////////







////////////////////////////////////////////////////////////////////////////////////
// INIT
////////////////////////////////////////////////////////////////////////////////////

// Runtime variables init. Used for runtime only, don't change, not for config!
var o3_text = "";
var o3_cap = "";
var o3_sticky = 0;
var o3_background = "";
var o3_close = "Close";
var o3_hpos = RIGHT;
var o3_offsetx = 2;
var o3_offsety = 2;
var o3_fgcolor = "";
var o3_bgcolor = "";
var o3_textcolor = "";
var o3_capcolor = "";
var o3_closecolor = "";
var o3_width = 100;
var o3_border = 1;
var o3_status = "";
var o3_autostatus = 0;
var o3_height = -1;
var o3_snapx = 0;
var o3_snapy = 0;
var o3_fixx = -1;
var o3_fixy = -1;
var o3_fgbackground = "";
var o3_bgbackground = "";
var o3_padxl = 0;
var o3_padxr = 0;
var o3_padyt = 0;
var o3_padyb = 0;
var o3_fullhtml = 0;
var o3_vpos = BELOW;
var o3_aboveheight = 0;
var o3_capicon = "";
var o3_textfont = "Verdana,Arial,Helvetica";
var o3_captionfont = "Verdana,Arial,Helvetica";
var o3_closefont = "Verdana,Arial,Helvetica";
var o3_textsize = "1";
var o3_captionsize = "1";
var o3_closesize = "1";
var o3_frame = self;
var o3_timeout = 0;
var o3_timerid = 0;
var o3_allowmove = 0;
var o3_function = Function();
var o3_delay = 0;
var o3_delayid = 0;
var o3_hauto = 0;
var o3_vauto = 0;
var o3_closeclick = 0;

var o3_css = CSSOFF;
var o3_fgclass = "";
var o3_bgclass = "";
var o3_textfontclass = "";
var o3_captionfontclass = "";
var o3_closefontclass = "";
var o3_padunit = "px";
var o3_heightunit = "px";
var o3_widthunit = "px";
var o3_textsizeunit = "px";
var o3_textdecoration = "";
var o3_textstyle = "";
var o3_textweight = "";
var o3_captionsizeunit = "px";
var o3_captiondecoration = "";
var o3_captionstyle = "";
var o3_captionweight = "";
var o3_closesizeunit = "px";
var o3_closedecoration = "";
var o3_closestyle = "";
var o3_closeweight = "";



// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_allow = 0;
var o3_showingsticky = 0;
var o3_removecounter = 0;

// Our layer
var over = null;


// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;

// Microsoft Stupidity Check(tm).
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}


// Capture events, alt. diffuses the overlib function.
if ( (ns4) || (ie4) || (ns6)) {
	document.onmousemove = overlib_mouseMove
	if (ns4) document.captureEvents(Event.MOUSEMOVE)
} else {
	overlib = no_overlib;
	nd = no_overlib;
	ver3fix = true;
}


// Fake function for 3.0 users.
function no_overlib() {
	return ver3fix;
}



////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////

function decodeString(val)
{
	var clean = '';
	for (var i = 0; i <val.length; i++)
    	{
		var c = val.charAt(i);
		switch(c)
	    	{
	    		case '<':
				clean+='<';
				break;
	    		case '>':
	    			clean+='>';
				break;

	    		case '\'':
				clean+='\\\'';
				break;

			case '\"':
				clean+='\\"';
				break;
			case '\\':
				clean+='\\\\';
				break;

  		default:
				clean+=c;
				break;
		}
    	}
	return clean;
}


// overlib(arg0, ..., argN)
// Loads parameters into global runtime variables.
function overlib() {

	// Load defaults to runtime.
	o3_text = ol_text;
	o3_cap = ol_cap;
	o3_sticky = ol_sticky;
	o3_background = ol_background;
	o3_close = ol_close;
	o3_hpos = ol_hpos;
	o3_offsetx = ol_offsetx;
	o3_offsety = ol_offsety;
	o3_fgcolor = ol_fgcolor;
	o3_bgcolor = ol_bgcolor;
	o3_textcolor = ol_textcolor;
	o3_capcolor = ol_capcolor;
	o3_closecolor = ol_closecolor;
	o3_width = ol_width;
	o3_border = ol_border;
	o3_status = ol_status;
	o3_autostatus = ol_autostatus;
	o3_height = ol_height;
	o3_snapx = ol_snapx;
	o3_snapy = ol_snapy;
	o3_fixx = ol_fixx;
	o3_fixy = ol_fixy;
	o3_fgbackground = ol_fgbackground;
	o3_bgbackground = ol_bgbackground;
	o3_padxl = ol_padxl;
	o3_padxr = ol_padxr;
	o3_padyt = ol_padyt;
	o3_padyb = ol_padyb;
	o3_fullhtml = ol_fullhtml;
	o3_vpos = ol_vpos;
	o3_aboveheight = ol_aboveheight;
	o3_capicon = ol_capicon;
	o3_textfont = ol_textfont;
	o3_captionfont = ol_captionfont;
	o3_closefont = ol_closefont;
	o3_textsize = ol_textsize;
	o3_captionsize = ol_captionsize;
	o3_closesize = ol_closesize;
	o3_timeout = ol_timeout;
	o3_function = ol_function;
	o3_delay = ol_delay;
	o3_hauto = ol_hauto;
	o3_vauto = ol_vauto;
	o3_closeclick = ol_closeclick;

	o3_css = ol_css;
	o3_fgclass = ol_fgclass;
	o3_bgclass = ol_bgclass;
	o3_textfontclass = ol_textfontclass;
	o3_captionfontclass = ol_captionfontclass;
	o3_closefontclass = ol_closefontclass;
	o3_padunit = ol_padunit;
	o3_heightunit = ol_heightunit;
	o3_widthunit = ol_widthunit;
	o3_textsizeunit = ol_textsizeunit;
	o3_textdecoration = ol_textdecoration;
	o3_textstyle = ol_textstyle;
	o3_textweight = ol_textweight;
	o3_captionsizeunit = ol_captionsizeunit;
	o3_captiondecoration = ol_captiondecoration;
	o3_captionstyle = ol_captionstyle;
	o3_captionweight = ol_captionweight;
	o3_closesizeunit = ol_closesizeunit;
	o3_closedecoration = ol_closedecoration;
	o3_closestyle = ol_closestyle;
	o3_closeweight = ol_closeweight;


	// Special for frame support, over must be reset...
	if ( (ns4) || (ie4) || (ns6) ) {
		o3_frame = ol_frame;
		if (ns4) over = o3_frame.document.overDiv
		if (ie4) over = o3_frame.overDiv.style
		if (ns6) over = o3_frame.document.getElementById("overDiv");
	}


	// What the next argument is expected to be.
	var parsemode = -1;

	var ar = arguments;

	for (i = 0; i < ar.length; i++) {

		if (parsemode < 0) {
			// Arg is maintext, unless INARRAY
			if (ar[i] == INARRAY) {
				o3_text = ol_texts[ar[++i]];
			} else {
				o3_text = ar[i];
			}

			parsemode = 0;
		} else {
			// Note: NS4 doesn't like switch cases with vars.
			if (ar[i] == INARRAY) { o3_text = ol_texts[ar[++i]]; continue; }
			if (ar[i] == CAPARRAY) { o3_cap = ol_caps[ar[++i]]; continue; }
			if (ar[i] == STICKY) { o3_sticky = 1; continue; }
			if (ar[i] == BACKGROUND) { o3_background = ar[++i]; continue; }
			if (ar[i] == NOCLOSE) { o3_close = ""; continue; }
			if (ar[i] == CAPTION) { o3_cap = ar[++i]; continue; }
			if (ar[i] == CENTER || ar[i] == LEFT || ar[i] == RIGHT) { o3_hpos = ar[i]; continue; }
			if (ar[i] == OFFSETX) { o3_offsetx = ar[++i]; continue; }
			if (ar[i] == OFFSETY) { o3_offsety = ar[++i]; continue; }
			if (ar[i] == FGCOLOR) { o3_fgcolor = ar[++i]; continue; }
			if (ar[i] == BGCOLOR) { o3_bgcolor = ar[++i]; continue; }
			if (ar[i] == TEXTCOLOR) { o3_textcolor = ar[++i]; continue; }
			if (ar[i] == CAPCOLOR) { o3_capcolor = ar[++i]; continue; }
			if (ar[i] == CLOSECOLOR) { o3_closecolor = ar[++i]; continue; }
			if (ar[i] == WIDTH) { o3_width = ar[++i]; continue; }
			if (ar[i] == BORDER) { o3_border = ar[++i]; continue; }
			if (ar[i] == STATUS) { o3_status = ar[++i]; continue; }
			if (ar[i] == AUTOSTATUS) { o3_autostatus = 1; continue; }
			if (ar[i] == AUTOSTATUSCAP) { o3_autostatus = 2; continue; }
			if (ar[i] == HEIGHT) { o3_height = ar[++i]; o3_aboveheight = ar[i]; continue; } // Same param again.
			if (ar[i] == CLOSETEXT) { o3_close = ar[++i]; continue; }
			if (ar[i] == SNAPX) { o3_snapx = ar[++i]; continue; }
			if (ar[i] == SNAPY) { o3_snapy = ar[++i]; continue; }
			if (ar[i] == FIXX) { o3_fixx = ar[++i]; continue; }
			if (ar[i] == FIXY) { o3_fixy = ar[++i]; continue; }
			if (ar[i] == FGBACKGROUND) { o3_fgbackground = ar[++i]; continue; }
			if (ar[i] == BGBACKGROUND) { o3_bgbackground = ar[++i]; continue; }
			if (ar[i] == PADX) { o3_padxl = ar[++i]; o3_padxr = ar[++i]; continue; }
			if (ar[i] == PADY) { o3_padyt = ar[++i]; o3_padyb = ar[++i]; continue; }
			if (ar[i] == FULLHTML) { o3_fullhtml = 1; continue; }
			if (ar[i] == BELOW || ar[i] == ABOVE) { o3_vpos = ar[i]; continue; }
			if (ar[i] == CAPICON) { o3_capicon = ar[++i]; continue; }
			if (ar[i] == TEXTFONT) { o3_textfont = ar[++i]; continue; }
			if (ar[i] == CAPTIONFONT) { o3_captionfont = ar[++i]; continue; }
			if (ar[i] == CLOSEFONT) { o3_closefont = ar[++i]; continue; }
			if (ar[i] == TEXTSIZE) { o3_textsize = ar[++i]; continue; }
			if (ar[i] == CAPTIONSIZE) { o3_captionsize = ar[++i]; continue; }
			if (ar[i] == CLOSESIZE) { o3_closesize = ar[++i]; continue; }
			if (ar[i] == FRAME) { opt_FRAME(ar[++i]); continue; }
			if (ar[i] == TIMEOUT) { o3_timeout = ar[++i]; continue; }
			if (ar[i] == FUNCTION) { opt_FUNCTION(ar[++i]); continue; }
			if (ar[i] == DELAY) { o3_delay = ar[++i]; continue; }
			if (ar[i] == HAUTO) { o3_hauto = (o3_hauto == 0) ? 1 : 0; continue; }
			if (ar[i] == VAUTO) { o3_vauto = (o3_vauto == 0) ? 1 : 0; continue; }
			if (ar[i] == CLOSECLICK) { o3_closeclick = (o3_closeclick == 0) ? 1 : 0; continue; }
			if (ar[i] == CSSOFF) { o3_css = ar[i]; continue; }
			if (ar[i] == CSSSTYLE) { o3_css = ar[i]; continue; }
			if (ar[i] == CSSCLASS) { o3_css = ar[i]; continue; }
			if (ar[i] == FGCLASS) { o3_fgclass = ar[++i]; continue; }
			if (ar[i] == BGCLASS) { o3_bgclass = ar[++i]; continue; }
			if (ar[i] == TEXTFONTCLASS) { o3_textfontclass = ar[++i]; continue; }
			if (ar[i] == CAPTIONFONTCLASS) { o3_captionfontclass = ar[++i]; continue; }
			if (ar[i] == CLOSEFONTCLASS) { o3_closefontclass = ar[++i]; continue; }
			if (ar[i] == PADUNIT) { o3_padunit = ar[++i]; continue; }
			if (ar[i] == HEIGHTUNIT) { o3_heightunit = ar[++i]; continue; }
			if (ar[i] == WIDTHUNIT) { o3_widthunit = ar[++i]; continue; }
			if (ar[i] == TEXTSIZEUNIT) { o3_textsizeunit = ar[++i]; continue; }
			if (ar[i] == TEXTDECORATION) { o3_textdecoration = ar[++i]; continue; }
			if (ar[i] == TEXTSTYLE) { o3_textstyle = ar[++i]; continue; }
			if (ar[i] == TEXTWEIGHT) { o3_textweight = ar[++i]; continue; }
			if (ar[i] == CAPTIONSIZEUNIT) { o3_captionsizeunit = ar[++i]; continue; }
			if (ar[i] == CAPTIONDECORATION) { o3_captiondecoration = ar[++i]; continue; }
			if (ar[i] == CAPTIONSTYLE) { o3_captionstyle = ar[++i]; continue; }
			if (ar[i] == CAPTIONWEIGHT) { o3_captionweight = ar[++i]; continue; }
			if (ar[i] == CLOSESIZEUNIT) { o3_closesizeunit = ar[++i]; continue; }
			if (ar[i] == CLOSEDECORATION) { o3_closedecoration = ar[++i]; continue; }
			if (ar[i] == CLOSESTYLE) { o3_closestyle = ar[++i]; continue; }
			if (ar[i] == CLOSEWEIGHT) { o3_closeweight = ar[++i]; continue; }
		}
	}

	if (o3_delay == 0) {
		return overlib350();
	} else {
		o3_delayid = setTimeout("overlib350()", o3_delay);

		if (o3_sticky) {
			return false;
		} else {
			return true;
		}
	}
}



// Clears popups if appropriate
function clearPopup() {
	if ( o3_removecounter >= 1 ) { o3_showingsticky = 0 };
	if ( (ns4) || (ie4) || (ns6) ) {
		if ( o3_showingsticky == 0 ) {
			o3_allowmove = 0;
			if (over != null) hideObject(over);
		} else {
			o3_removecounter++;
		}
	}

	return true;
}







////////////////////////////////////////////////////////////////////////////////////
// OVERLIB 3.50 FUNCTION
////////////////////////////////////////////////////////////////////////////////////


// This function decides what it is we want to display and how we want it done.
function overlib350() {

	// Make layer content
	var layerhtml;

	if (o3_background != "" || o3_fullhtml) {
		// Use background instead of box.
		layerhtml = ol_content_background(o3_text, o3_background, o3_fullhtml);
	} else {
		// They want a popup box.

		// Prepare popup background
		if (o3_fgbackground != "" && o3_css == CSSOFF) {
			o3_fgbackground = "BACKGROUND=\""+o3_fgbackground+"\"";
		}
		if (o3_bgbackground != "" && o3_css == CSSOFF) {
			o3_bgbackground = "BACKGROUND=\""+o3_bgbackground+"\"";
		}

		// Prepare popup colors
		if (o3_fgcolor != "" && o3_css == CSSOFF) {
			o3_fgcolor = "BGCOLOR=\""+o3_fgcolor+"\"";
		}
		if (o3_bgcolor != "" && o3_css == CSSOFF) {
			o3_bgcolor = "BGCOLOR=\""+o3_bgcolor+"\"";
		}

		// Prepare popup height
		if (o3_height > 0 && o3_css == CSSOFF) {
			o3_height = "HEIGHT=" + o3_height;
		} else {
			o3_height = "";
		}

		// Decide which kinda box.
		if (o3_cap == "") {
			// Plain
			layerhtml = ol_content_simple(o3_text);
		} else {
			// With caption
			if (o3_sticky) {
				// Show close text
				layerhtml = ol_content_caption(o3_text, o3_cap, o3_close);
			} else {
				// No close text
				layerhtml = ol_content_caption(o3_text, o3_cap, "");
			}
		}
	}

	// We want it to stick!
	if (o3_sticky) {
		o3_showingsticky = 1;
		o3_removecounter = 0;
	}

	// Write layer
	layerWrite(layerhtml);

	// Prepare status bar
	if (o3_autostatus > 0) {
		o3_status = o3_text;
		if (o3_autostatus > 1) {
			o3_status = o3_cap;
		}
	}

	// When placing the layer the first time, even stickies may be moved.
	o3_allowmove = 0;

	// Initiate a timer for timeout
	if (o3_timeout > 0) {
		if (o3_timerid > 0) clearTimeout(o3_timerid);
		o3_timerid = setTimeout("cClick()", o3_timeout);
	}

	// Show layer
	disp(o3_status);

	// Stickies should stay where they are.
	if (o3_sticky) {
		o3_allowmove = 0;
		return false;
	} else {
		return true;
	}
}



////////////////////////////////////////////////////////////////////////////////////
// LAYER GENERATION FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////

// Makes simple table without caption
function ol_content_simple(text) {
	if (o3_css == CSSCLASS) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING="+o3_border+" CELLSPACING=0 class=\""+o3_bgclass+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 class=\""+o3_fgclass+"\"><TR><TD VALIGN=TOP><FONT class=\""+o3_textfontclass+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
	if (o3_css == CSSSTYLE) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING="+o3_border+" CELLSPACING=0 style=\"background-color: "+o3_bgcolor+"; height: "+o3_height+o3_heightunit+";\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 style=\"color: "+o3_fgcolor+"; background-color: "+o3_fgcolor+"; height: "+o3_height+o3_heightunit+";\"><TR><TD VALIGN=TOP><FONT style=\"font-family: "+o3_textfont+"; color: "+o3_textcolor+"; font-size: "+o3_textsize+o3_textsizeunit+"; text-decoration: "+o3_textdecoration+"; font-weight: "+o3_textweight+"; font-style:"+o3_textstyle+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
	if (o3_css == CSSOFF) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING="+o3_border+" CELLSPACING=0 "+o3_bgcolor+" "+o3_height+"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 "+o3_fgcolor+" "+o3_fgbackground+" "+o3_height+"><TR><TD VALIGN=TOP><FONT FACE=\""+o3_textfont+"\" COLOR=\""+o3_textcolor+"\" SIZE=\""+o3_textsize+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";

	set_background("");
	return txt;
}




// Makes table with caption and optional close link
function ol_content_caption(text, title, close) {
	closing = "";
	closeevent = "onMouseOver";

	if (o3_closeclick == 1) closeevent = "onClick";
	if (o3_capicon != "") o3_capicon = "<IMG SRC=\""+o3_capicon+"\"> ";

	if (close != "") {
		if (o3_css == CSSCLASS) closing = "<TD ALIGN=RIGHT><A HREF=\"/\" "+closeevent+"=\"return cClick();\" class=\""+o3_closefontclass+"\">"+close+"</A></TD>";
		if (o3_css == CSSSTYLE) closing = "<TD ALIGN=RIGHT><A HREF=\"/\" "+closeevent+"=\"return cClick();\" style=\"color: "+o3_closecolor+"; font-family: "+o3_closefont+"; font-size: "+o3_closesize+o3_closesizeunit+"; text-decoration: "+o3_closedecoration+"; font-weight: "+o3_closeweight+"; font-style:"+o3_closestyle+";\">"+close+"</A></TD>";
		if (o3_css == CSSOFF) closing = "<TD ALIGN=RIGHT><A HREF=\"/\" "+closeevent+"=\"return cClick();\"><FONT COLOR=\""+o3_closecolor+"\" FACE=\""+o3_closefont+"\" SIZE=\""+o3_closesize+"\">"+close+"</FONT></A></TD>";
	}

	//alert("o3_css ="+o3_css);
	if (o3_css == CSSCLASS) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING="+o3_border+" CELLSPACING=0 class=\""+o3_bgclass+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><FONT class=\""+o3_captionfontclass+"\">"+o3_capicon+title+"</FONT></TD>"+closing+"</TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 class=\""+o3_fgclass+"\"><TR><TD VALIGN=TOP><FONT class=\""+o3_textfontclass+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
	if (o3_css == CSSSTYLE) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING="+o3_border+" CELLSPACING=0 style=\"background-color: "+o3_bgcolor+"; background-image: url("+o3_bgbackground+"); height: "+o3_height+o3_heightunit+";\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><FONT style=\"font-family: "+o3_captionfont+"; color: "+o3_capcolor+"; font-size: "+o3_captionsize+o3_captionsizeunit+"; font-weight: "+o3_captionweight+"; font-style: "+o3_captionstyle+";\">"+o3_capicon+title+"</FONT></TD>"+closing+"</TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 style=\"color: "+o3_fgcolor+"; background-color: "+o3_fgcolor+"; height: "+o3_height+o3_heightunit+";\"><TR><TD VALIGN=TOP><FONT style=\"font-family: "+o3_textfont+"; color: "+o3_textcolor+"; font-size: "+o3_textsize+o3_textsizeunit+"; text-decoration: "+o3_textdecoration+"; font-weight: "+o3_textweight+"; font-style:"+o3_textstyle+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
	if (o3_css == CSSOFF) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING="+o3_border+" CELLSPACING=0 "+o3_bgcolor+" "+o3_bgbackground+" "+o3_height+"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR align=center><TD><B><FONT COLOR=\""+o3_capcolor+"\" FACE=\""+o3_captionfont+"\" SIZE=\""+o3_captionsize+"\">"+o3_capicon+title+"</FONT></B></TD>"+closing+"</TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 "+o3_fgcolor+" "+o3_fgbackground+" "+o3_height+"><TR><TD VALIGN=TOP><FONT COLOR=\""+o3_textcolor+"\" FACE=\""+o3_textfont+"\" SIZE=\""+o3_textsize+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";

	set_background("");
	return txt;
}

// Sets the background picture, padding and lots more. :)
function ol_content_background(text, picture, hasfullhtml) {
	if (hasfullhtml) {
		txt = text;
	} else {
		if (o3_css == CSSCLASS) txt = "<TABLE WIDTH="+o3_width+o3_widthunit+" BORDER=0 CELLPADDING=0 CELLSPACING=0 HEIGHT="+o3_height+o3_heightunit+"><TR><TD COLSPAN=3 HEIGHT="+o3_padyt+o3_padunit+"></TD></TR><TR><TD WIDTH="+o3_padxl+o3_padunit+"></TD><TD VALIGN=TOP WIDTH="+(o3_width-o3_padxl-o3_padxr)+o3_padunit+"><FONT class=\""+o3_textfontclass+"\">"+text+"</FONT></TD><TD WIDTH="+o3_padxr+o3_padunit+"></TD></TR><TR><TD COLSPAN=3 HEIGHT="+o3_padyb+o3_padunit+"></TD></TR></TABLE>";
		if (o3_css == CSSSTYLE) txt = "<TABLE WIDTH="+o3_width+o3_widthunit+" BORDER=0 CELLPADDING=0 CELLSPACING=0 HEIGHT="+o3_height+o3_heightunit+"><TR><TD COLSPAN=3 HEIGHT="+o3_padyt+o3_padunit+"></TD></TR><TR><TD WIDTH="+o3_padxl+o3_padunit+"></TD><TD VALIGN=TOP WIDTH="+(o3_width-o3_padxl-o3_padxr)+o3_padunit+"><FONT style=\"font-family: "+o3_textfont+"; color: "+o3_textcolor+"; font-size: "+o3_textsize+o3_textsizeunit+";\">"+text+"</FONT></TD><TD WIDTH="+o3_padxr+o3_padunit+"></TD></TR><TR><TD COLSPAN=3 HEIGHT="+o3_padyb+o3_padunit+"></TD></TR></TABLE>";
		if (o3_css == CSSOFF) txt = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING=0 CELLSPACING=0 HEIGHT="+o3_height+"><TR><TD COLSPAN=3 HEIGHT="+o3_padyt+"></TD></TR><TR><TD WIDTH="+o3_padxl+"></TD><TD VALIGN=TOP WIDTH="+(o3_width-o3_padxl-o3_padxr)+"><FONT FACE=\""+o3_textfont+"\" COLOR=\""+o3_textcolor+"\" SIZE=\""+o3_textsize+"\">"+text+"</FONT></TD><TD WIDTH="+o3_padxr+"></TD></TR><TR><TD COLSPAN=3 HEIGHT="+o3_padyb+"></TD></TR></TABLE>";
	}
	set_background(picture);
	return txt;
}

// Loads a picture into the div.
function set_background(pic) {
    if (over != null)
    {
    	if (pic == "") {
    		if (ie4) over.backgroundImage = "none";
    		if (ns6) over.style.backgroundImage = "none";
    	} else {
    		if (ns4) {
    			over.background.src = pic;
    		} else if (ie4) {
    			over.backgroundImage = "url("+pic+")";
    		} else if (ns6) {
    			over.style.backgroundImage = "url("+pic+")";
    		}
    	}
    }
}



////////////////////////////////////////////////////////////////////////////////////
// HANDLING FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


// Displays the popup
function disp(statustext) {
//	if ( (ns4) || (ie4) || (ns6) ) {
	if ( (ie4) ) {
		if (o3_allowmove == 0) 	{
			placeLayer();
			showObject(over);
			o3_allowmove = 1;
		}
	}

	if (statustext != "") {
		self.status = statustext;
	}
}

// Decides where we want the popup.
function placeLayer() {
	var placeX, placeY;

	// HORIZONTAL PLACEMENT
	if (o3_fixx > -1) {
		// Fixed position
		placeX = o3_fixx;
	} else {
		winoffset = (ie4) ? o3_frame.document.body.scrollLeft : o3_frame.pageXOffset;
		if (ie4) iwidth = o3_frame.document.body.clientWidth;
		if (ns4) iwidth = o3_frame.innerWidth; // was screwed in mozilla, fixed now?
		if (ns6) iwidth = o3_frame.outerWidth;

		// If HAUTO, decide what to use.
		if (o3_hauto == 1) {
			if ( (o3_x - winoffset) > ((eval(iwidth)) / 2)) {
				o3_hpos = LEFT;
			} else {
				o3_hpos = RIGHT;
			}
		}

		// From mouse
		if (o3_hpos == CENTER) { // Center
			placeX = o3_x+o3_offsetx-(o3_width/2);
		}
		if (o3_hpos == RIGHT) { // Right
			placeX = o3_x+o3_offsetx;
			if ( (eval(placeX) + eval(o3_width)) > (winoffset + iwidth) ) {
				placeX = iwidth + winoffset - o3_width;
				if (placeX < 0) placeX = 0;
			}
		}
		if (o3_hpos == LEFT) { // Left
			placeX = o3_x-o3_offsetx-o3_width;
			if (placeX < winoffset) placeX = winoffset;
		}

		// Snapping!
		if (o3_snapx > 1) {
			var snapping = placeX % o3_snapx;
			if (o3_hpos == LEFT) {
				placeX = placeX - (o3_snapx + snapping);
			} else {
				// CENTER and RIGHT
				placeX = placeX + (o3_snapx - snapping);
			}
			if (placeX < winoffset) placeX = winoffset;
		}
	}



	// VERTICAL PLACEMENT
	if (o3_fixy > -1) {
		// Fixed position
		placeY = o3_fixy;
	} else {
		scrolloffset = (ie4) ? o3_frame.document.body.scrollTop : o3_frame.pageYOffset;

		// If VAUTO, decide what to use.
		if (o3_vauto == 1) {
			if (ie4) iheight = o3_frame.document.body.clientHeight;
			if (ns4) iheight = o3_frame.innerHeight;
			if (ns6) iheight = o3_frame.outerHeight;

			iheight = (eval(iheight)) / 2;
			if ( (o3_y - scrolloffset) > iheight) {
				o3_vpos = ABOVE;
			} else {
				o3_vpos = BELOW;
			}
		}


		// From mouse
		if (o3_vpos == ABOVE) {
			if (o3_aboveheight == 0) {
				var divref = (ie4) ? o3_frame.document.all['overDiv'] : over;
				o3_aboveheight = (ns4) ? divref.clip.height : divref.offsetHeight;
			}

			placeY = o3_y - (o3_aboveheight + o3_offsety);
			if (placeY < scrolloffset) placeY = scrolloffset;
		} else {
			// BELOW
			placeY = o3_y + o3_offsety;
		}

		// Snapping!
		if (o3_snapy > 1) {
			var snapping = placeY % o3_snapy;

			if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
				placeY = placeY - (o3_snapy + snapping);
			} else {
				placeY = placeY + (o3_snapy - snapping);
			}

			if (placeY < scrolloffset) placeY = scrolloffset;
		}
	}


	// Actually move the object.
	repositionTo(over, placeX, placeY);
}


// Moves the layer
function overlib_mouseMove(e) {
//	if ( (ns4) || (ns6) ) {o3_x=e.pageX; o3_y=e.pageY;}
	if (ie4) {o3_x=event.x; o3_y=event.y;}
	//if (ie5) {o3_x=event.x+o3_frame.document.body.scrollLeft; o3_y=event.y+o3_frame.document.body.scrollTop;}

	if (o3_allowmove == 1) {
		placeLayer();
	}
}

// The Close onMouseOver function for stickies
function cClick() {
	hideObject(over);
	o3_showingsticky = 0;

	return false;
}


// Makes sure target frame has overLIB
function compatibleframe(frameid) {
	if (ns4) {
		if (typeof frameid.document.overDiv =='undefined') return false;
	} else if (ie4) {
		if (typeof frameid.document.all["overDiv"] =='undefined') return false;
	} else if (ns6) {
		if (frameid.document.getElementById('overDiv') == null) return false;
	}

	return true;
}



////////////////////////////////////////////////////////////////////////////////////
// LAYER FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


// Writes to a layer
function layerWrite(txt) {
	txt += "\n";

        if (ns4) {
                var lyr = o3_frame.document.overDiv.document

                lyr.write(txt)
                lyr.close()
        } else if (ie4) {
		o3_frame.document.all["overDiv"].innerHTML = txt
	} else if (ns6) {
		range = o3_frame.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
	}
}

// Make an object visible
function showObject(obj) {
    if (obj != null)
    {
        if (ns4) obj.visibility = "show";
        else if (ie4) obj.visibility = "visible";
    	else if (ns6) obj.style.visibility = "visible";
	}
}

// Hides an object
function hideObject(obj) {
        if (ns4) obj.visibility = "hide";
        else if (ie4) obj.visibility = "hidden";
	else if (ns6) obj.style.visibility = "hidden";

	if (o3_timerid > 0) clearTimeout(o3_timerid);
	if (o3_delayid > 0) clearTimeout(o3_delayid);
	o3_timerid = 0;
	o3_delayid = 0;
        self.status = "";
}

// Move a layer
function repositionTo(obj,xL,yL) {
    if (obj != null)
    {
    	if ( (ns4) || (ie4) ) {
    	        obj.left = xL;
    	        obj.top = yL;
    	} else if (ns6) {
    		obj.style.left = xL + "px";
    		obj.style.top = yL+ "px";
    	}
    }
}





////////////////////////////////////////////////////////////////////////////////////
// PARSER FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


// Defines which frame we should point to.
function opt_FRAME(frm) {
        o3_frame = compatibleframe(frm) ? frm : ol_frame;

	if ( (ns4) || (ie4 || (ns6)) ) {
		if (ns4) over = o3_frame.document.overDiv;
		if (ie4) over = o3_frame.overDiv.style;
		if (ns6) over = o3_frame.document.getElementById("overDiv");
	}

	return 0;
}

// Calls an external function
function opt_FUNCTION(callme) {
	o3_text = callme()
	return 0;
}




//end (For internal purposes.)
////////////////////////////////////////////////////////////////////////////////////
// OVERLIB 2 COMPATABILITY FUNCTIONS
// If you aren't upgrading you can remove the below section.
////////////////////////////////////////////////////////////////////////////////////

// Converts old 0=left, 1=right and 2=center into constants.
function vpos_convert(d) {
	if (d == 0) {
		d = LEFT;
	} else {
		if (d == 1) {
			d = RIGHT;
		} else {
			d = CENTER;
		}
	}

	return d;
}

// Simple popup
function dts(d,text) {
	o3_hpos = vpos_convert(d);
	overlib(text, o3_hpos, CAPTION, "");
}

// Caption popup
function dtc(d,text, title) {
	o3_hpos = vpos_convert(d);
	overlib(text, CAPTION, title, o3_hpos);
}

// Sticky
function stc(d,text, title) {
	o3_hpos = vpos_convert(d);
	overlib(text, CAPTION, title, o3_hpos, STICKY);
}

// Simple popup right
function drs(text) {
	dts(1,text);
}

// Caption popup right
function drc(text, title) {
	dtc(1,text,title);
}

// Sticky caption right
function src(text,title) {
	stc(1,text,title);
}

// Simple popup left
function dls(text) {
	dts(0,text);
}

// Caption popup left
function dlc(text, title) {
	dtc(0,text,title);
}

// Sticky caption left
function slc(text,title) {
	stc(0,text,title);
}

// Simple popup center
function dcs(text) {
	dts(2,text);
}

// Caption popup center
function dcc(text, title) {
	dtc(2,text,title);
}

// Sticky caption center
function scc(text,title) {
	stc(2,text,title);
}


// popupcalendar.js


function showCalendar(anchorname, datefield, dateformat, defaultDate)
{
    if(defaultDate ==null || defaultDate =="")
    {
    	defaultYear=null;
    	defaultMonth=null;
    	defaultDay=null;
    }
    else
    {

	if(verifyDate(defaultDate))
	{
	   	defaultDate=convertDateTo10Char(defaultDate);
	   	defaultMonth = defaultDate.substr(0,2) ;
		defaultDay = defaultDate.substr(3,2);
		defaultYear = defaultDate.substr(6,4);

		if (defaultMonth.indexOf('0')==0)
		defaultMonth=defaultMonth.substring(1);

		if (defaultDay.indexOf('0')==0)
		defaultDay=defaultDay.substring(1);
		//alert("defaultDay "+defaultDay+"       "+"defaultMonth "+defaultMonth);
		defaultDay=parseInt(defaultDay);
		defaultYear=parseInt(defaultYear);
		defaultMonth=parseInt(defaultMonth);
	}
	else
	{
		alert(alert_msg);
	    	defaultYear=null;
    		defaultMonth=null;
    		defaultDay=null;
	}
    }
    popupCalendar = new PopupCalendar(anchorname, datefield, dateformat, defaultYear, defaultMonth, defaultDay);
}
//true means date format is ok
function verifyDate(inDate)
{
	if(inDate.length>10 || inDate.length < 8||DateFormatNotCorrect(inDate))
	{
		return false;
	}

	if(inDate.length==9 || inDate.length == 8)
	{
		inDate=convertDateTo10Char(inDate);
	}

	var CorrectFormat = /[0-1][0-9]\/[0-3][0-9]\/[0-9][0-9][0-9][0-9]/;

	// Test to see if the format of the date is correct.
	if (CorrectFormat.test(inDate))
	return true;
	else
	return false;

}

var alert_msg=JS_message4;//the date is not correct, use today

var use_css=false;
var use_layers=false;
if (document.all)    { use_css    = true; }
if (document.layers) { use_layers = true; }

var CALWINDOW;

// Write out default styles to document or return string
function writestyles(doc)
{
    var result = "";
    result += "<STYLE>\n";
    result += "TD.cal { font-family:arial; font-size: 8pt; }\n";
    result += "TD.calmonth { font-family:arial; font-size: 8pt; text-align: right;}\n";
    result += "TD.caltoday { font-family:arial; font-size: 8pt; text-align: right; color: white; background-color:Lime; border-width:1; border-type:solid; border-color:#800000; }\n";
    result += "INPUT.caltoday { font-family:arial; font-size: 8pt; width:47px; height: 20px; }\n";
    result += "A.cal { text-decoration:none; color:#000000; }\n";
    result += "A.calthismonth { text-decoration:none; color:#000000; }\n";
    result += "A.calothermonth { text-decoration:none; color:#808080; }\n";
    result += "</STYLE>\n";
    if (doc != "")
    {
        doc.write(result);
    }
    else
    {
        return result;
    }
}
writestyles(this.document);

function PopupCalendar(anchorname, datefield, dateformat, defaultYear, defaultMonth, defaultDay)
{
    this.anchorname = anchorname;
    this.datefield = datefield;
    this.dateformat = dateformat;
    this.monthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

    this.getOffsetLeft = PopupCalendar_getOffsetLeft;
    this.getOffsetTop = PopupCalendar_getOffsetTop;
    //this.moveTo(screen.width/2,screen.height/2)
    this.hideCalendar = PopupCalendar_hideCalendar;
    this.outputCalendar = PopupCalendar_outputCalendar;
    this.printDate = PopupCalendar_printDate;

    /*
    // Find position relative to anchor
    if (use_css)
    {
        var x = this.getOffsetLeft(document.all[anchorname]);
        var y = this.getOffsetTop(document.all[anchorname]);
    }
    else
    {
        var found=0;
        for (var i=0; i<document.anchors.length; i++)
        {
            if (document.anchors[i].name == anchorname)
            {
                var x=document.anchors[i].x;
                var y=document.anchors[i].y;
                found=1;
                break;
            }
        }
        if (found == 0)
        {
            for (var j=0; j<document.layers.length; j++)
            {
                for (var i=0; i<document.layers[j].document.anchors.length; i++)
                {
                    if (document.layers[j].document.anchors[i].name == anchorname)
                    {
                        var x=document.layers[j].document.anchors[i].x;
                        var y=document.layers[j].document.anchors[i].y;
                        found=1;
                        break;
                    }
                }
            }
        }
        if (found == 0)
        {
            return;
        }
        x=x-window.pageXOffset;
        y=y-window.pageYOffset;
    }
	//    x = x-152;
    y = y+20;
    // WRITE CALENDAR TO POPUP WINDOW
    if (use_layers)
    {
        var windowx = window.screenX;
        var windowy = window.screenY + (window.outerHeight-24-window.innerHeight);
    }
    if (use_css)
    {
        var windowx = window.screenLeft;
        var windowy = window.screenTop;
    }
    */

    //x = x + windowx;
    //y = y + windowy;
    x=(window.screen.width-170)/2;
    y=(window.screen.height-180)/2;
    if (!CALWINDOW || CALWINDOW.closed)
    {
        CALWINDOW = window.open("about:blank","calwindow","status=no,width=150,height=160,screenX="+x+",left="+x+",screenY="+y+",top="+y+",resizable");
    //CALWINDOW.moveTo((window.screen.width-150)/2,(window.screen.height-160)/2);
    }
    // Write output to popup window
    this.outputCalendar(defaultYear, defaultMonth, defaultDay);

}

function PopupCalendar_getOffsetLeft (el)
{
    var scrollamount = document.body.scrollLeft;
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null) { ol += el.offsetLeft; }
    ol = ol - scrollamount;
    return ol;
}

function PopupCalendar_getOffsetTop (el)
{
    var scrollamount = document.body.scrollTop;
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null) { ot += el.offsetTop; }
    ot = ot - scrollamount;
    return ot;
}

function PopupCalendar_hideCalendar()
{
    if (CALWINDOW && !CALWINDOW.closed)
    {
        CALWINDOW.close();
    }
}

function PopupCalendar_outputCalendar(defaultYear, defaultMonth, defaultDay)
{
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth()+1;

    if (defaultYear != null && defaultYear != "")
    year = defaultYear;
    else
    defaultYear=year;

    if (defaultMonth != null && defaultMonth != "")
    month = defaultMonth;
    else
    {
    	defaultMonth=month;
    	defaultDay=now.getDate();
    }


    var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);

    if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) )
    { // leap year
        daysinmonth[2] = 29;
    }
    var current_month = new Date(year,month-1,1);

    var display_year = year;
    var display_month = month;
    var display_date = 1;

    var offset = 0;
    var weekday= current_month.getDay();
    if (weekday > 0)
    {
        display_month--;
        if (display_month < 1) { display_month = 12; display_year--; }
        display_date = daysinmonth[display_month]-weekday+1;
    }

    var next_month = month+1;
    var next_month_year = year;

    if (next_month > 12) { next_month=1; next_month_year++; }
    var last_month = month-1;
    var last_month_year = year;
    if (last_month < 1) { last_month=12; last_month_year--; }

    var date_class;
    var result = "";
    result += "<HTML><HEAD><title>Choose Date</title>"+writestyles('')+"<BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0 onBlur='window.focus()'>\n";
    result += '<FORM>\n';
    result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
    result += '<TR BGCOLOR="#C0C0C0">\n';
    result += '    <TD CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:window.opener.popupCalendar.outputCalendar('+last_month_year+','+last_month+')">&lt;&lt;</A></B></TD>\n';
    result += '    <TD CLASS="cal" WIDTH=100 ALIGN=CENTER>'+this.monthNames[month-1]+' '+year+'</TD>\n';
    result += '    <TD CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:window.opener.popupCalendar.outputCalendar('+next_month_year+','+next_month+')">&gt;&gt;</A></B></TD>\n';
    result += '</TR>\n';
    result += '</TABLE>\n';
    result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
    result += '<TR>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>S</TD>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>M</TD>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>T</TD>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>W</TD>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>T</TD>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>F</TD>\n';
    result += '    <TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>S</TD>\n';
    result += '</TR>\n';
    result += '<TR><TD COLSPAN=7 ALIGN=CENTER><IMG SRC="graypixel.gif" WIDTH=120 HEIGHT=1></TD></TR>\n';
    for (var row=1; row<=6; row++)
    {
        result += '<TR>\n';
        for (var col=1; col<=7; col++)
        {
            if (display_month == month)
            {
                date_class = "calthismonth";
            }
            else
            {
                date_class = "calothermonth";
            }
            if ((display_month == defaultMonth) && (display_date==defaultDay) && (display_year==defaultYear))
            {
                td_class="caltoday";
            }
            else
            {
                td_class="calmonth";
            }
            result += '    <TD CLASS="'+td_class+'"><A HREF="javascript:window.opener.popupCalendar.printDate('+display_year+','+display_month+','+display_date+');window.opener.popupCalendar.hideCalendar();" CLASS="'+date_class+'">'+display_date+'</A></TD>\n';
            display_date++;
            if (display_date > daysinmonth[display_month])
            {
                display_date=1;
                display_month++;
            }
            if (display_month > 12)
            {
                display_month=1;
                display_year++;
            }
        }
        result += '</TR>\n';
    }
    result += '<TR><TD COLSPAN=7 ALIGN=CENTER><IMG SRC="graypixel.gif" WIDTH=120 HEIGHT=1></TD></TR>\n';
    result += '<TR>\n';
    result += '    <TD COLSPAN=7 ALIGN=CENTER>\n';
    result += '        <INPUT CLASS="caltoday" TYPE="button" VALUE="Today" onClick="window.opener.popupCalendar.printDate('+now.getFullYear()+','+(now.getMonth()+1)+','+now.getDate()+');window.opener.popupCalendar.hideCalendar();">\n';
    result += '        <BR>\n';
    result += '    </TD>\n';
    result += '</TR>\n';
    result += '</TABLE>\n';
    result += '</CENTER>\n';
    result += '</TD></TR>\n';
    result += '</TABLE>\n';
    result += '</FORM>\n';
    result += '</BODY></HTML>\n';

    CALWINDOW.document.open();
    CALWINDOW.document.write(result);
    CALWINDOW.document.close();
}

function PopupCalendar_printDate(year,month,date)
{
    var yyyy = new String(year);
    var yy = yyyy.substring(2, 4);
    var M = month;
    var MM = (M<10?'0':'') + M;
    var MMM = this.monthNames[month-1].substring(0, 3);
    var MMMM = this.monthNames[month-1];
    var d = date;
    var dd = (date<10?'0':'') + date;
    var retVal = this.dateformat;

    retVal = retVal.replace(/yyyy/,yyyy);
    retVal = retVal.replace(/yy/,yy);
    if (retVal.match(/MMMM/)) retVal = retVal.replace(/MMMM/,MMMM)
    else if (retVal.match(/MMM/)) retVal = retVal.replace(/MMM/,MMM)
    else if (retVal.match(/MM/)) retVal = retVal.replace(/MM/,MM)
    else if (retVal.match(/M/)) retVal = retVal.replace(/M/,M);
    retVal = retVal.replace(/dd/,dd);
    retVal = retVal.replace(/d/,d);
    this.datefield.value=retVal;
}

// workspace_event_ae.js

//confirm every parameter is correct, called when user click the submit or update button
function confirmSubmit()
{
	return_bool=false;
	//check event name is blank or not
	if(document.event.name.value!='')
	{
		//check start date
		if(date_validate(document.event.start_date))
		{
			if(document.event.end_date.value)
			{
				if(date_validate(document.event.end_date))
				{
					if(compareDate(convert_date_format(document.event.end_date.value), convert_date_format(document.event.start_date.value) ))
					return_bool=true;
					else
					{
						//message=message_string01;
						// as requested by Kennametal , "When adding an event to the calendar when the start date is > end date make the end date the start date "
						document.event.end_date.value=document.event.start_date.value;
						return_bool=true;
					}
				}
			}
			else
			{
				document.event.end_date.value=document.event.start_date.value;
				return_bool=true;
			}
		}
	}
	else
	{
		message=message_string02;
	}


	if(return_bool)
	{
		if(document.event.hasrepeat.value==1)
		confirmRepeatDate();
	}

	if(return_bool)
	{

		document.event.repeat_pattern.value=recur_pattern_string;
		datetime_finalize_js(document.event);
	}
	else
	{
		alert(msg_header+message);
	}

	// if this is Update action, then will confirm the user to update all related events or just this one only
	if(is_update==1 && return_bool)
	{
		//check if this event is a recurring event already, if it is not, it will generate recurring event
		if(global_repeat_pattern!='')
		{
			//check if recurring condition got changed or not, if it is , it need to delete old ones and create new ones
			if(recur_pattern_string!=global_repeat_pattern)
			{
				if(confirm(message_string03+". \n "+message_string04+"?   \n\n "+message_string05+". "))
				{
					document.event.need_delete_old.value='2';
				}
				else
				{
					//if user choose Cancel, then restore old values and return
					onLoadUpdate();
					return_bool=false;
				}
			}
			else
			{
				if(document.event.updateType[1].checked)
				{
					//check if the date and time of both start or end get changed,
					//as we cannot update the whole series of recurring events with
					//date and time get changed, we only allow user to change current event
					//for date and time
					if(!isDateTimeChanged())
					{
						//if datetime is NOT changed
						if(confirm(message_string06+".    \n\n "+message_string07+". "))
						document.event.need_delete_old.value='1';
						else
						return_bool=false;
					}
					else
					{	//if datetime is changed
						alert(message_string20);
						if(confirm(" "+message_string07+". "))
						document.event.need_delete_old.value='2';
						else
						return_bool=false;
					}
				}

			}
		}
		else
		{
			//if this event is not a recurring event, then user add recurring info
			if(recur_pattern_string!='')
			document.event.need_delete_old.value='2';

		}
	}
	//alert(document.event.ids.value);
	//alert(document.event.need_delete_old.value);
	//return false;
	return return_bool;
}

//convert the date format always to MM/DD/YYYY when processing
function convert_date_format(in_date)
{
	var out_date="";
	if(global_date_format=="MM/DD/YYYY")
		out_date= in_date;
	else if(global_date_format=="DD/MM/YYYY")
		out_date= ""+in_date.substr(3,2)+"/"+in_date.substr(0,2)+"/"+in_date.substr(6,4);
	else if(global_date_format=="YYYY/MM/DD")
		out_date= ""+in_date.substr(5,2)+"/"+in_date.substr(8,2)+"/"+in_date.substr(0,4);
	else
		out_date= "ERROR CONVERT DATE FORMAT JS";

	return out_date;
}

//convert the date format from the MM/DD/YYYY to what ever it is
function convertBack_date_format(in_date)
{
	var out_date="";
	if(global_date_format=="MM/DD/YYYY")
		out_date= in_date;
	else if(global_date_format=="DD/MM/YYYY")
		out_date= ""+in_date.substr(3,2)+"/"+in_date.substr(0,2)+"/"+in_date.substr(6,4);
	else if(global_date_format=="YYYY/MM/DD")
		out_date= ""+in_date.substr(6,4)+"/"+in_date.substr(0,2)+"/"+in_date.substr(3,2);
	else
		out_date= "ERROR CONVERT DATE FORMAT JS";

	return out_date;
}


//if changed return true
function isDateTimeChanged()
{
	if(document.event.end_time.value!=end_time_old)
	return true;
	if(document.event.start_time.value!=start_time_old)
	return true;
	if(document.event.end_date.value!=end_date_old)
	return true;
	if(document.event.start_date.value!=start_date_old)
	return true;

	return false;
}


function getDayofWeek(dow)
{
	var tempS="";
	switch (dow){
  	case 1:
	      	tempS="Monday";
      		break;
   	case 2:
      		tempS="Tuesday";
      		break;
   	case 3:
      		tempS="Wednesday";
      		break;
   	case 4:
      		tempS="Thursday";
      		break;
   	case 5:
      		tempS="Friday";
      		break;
   	case 6:
		tempS="Saturday";
      		break;
   	case 7:
      		tempS="Sunday";
      		break;

   	default : tempS="ERROR No DAY ";
	}
	return tempS;
}

//get the recurring pattern and determine  the start date
function confirmRepeatDate()
{

		var ISO_date=YMD_To_YWD(convert_date_format(document.event.start_date.value));
		var recur_pattern=document.event.RecurrencePattern.value;
		recur_pattern_string="";
		var start_end_diff=DiffDays(convert_date_format(document.event.end_date.value), convert_date_format(document.event.start_date.value))

		if(recur_pattern==1)
		{
			var field=document.event.week_weekday;
			var i=0;
			recur_pattern_string="W"+document.event.week_every.value+" ";
			var week_weekday_no='';
			 for(i = 0; i < field.length; i++)
        		{
        			if(field[i].checked)
				{
					recur_pattern_string+=field[i].value.substring(0,2)+" ";
					week_weekday_no+=field[i].value.substring(3,4);
				}
			}

			//alert("week_weekday_no ="+week_weekday_no);

			if(week_weekday_no!='')
			{
				if(isOverLap(week_weekday_no,start_end_diff))
				{
					var converted_date1=convert_date_format(document.event.start_date.value);
					var converted_date2=convert_date_format(document.event.end_date.value);
					var newStartDateNo=getNearestDateNo(week_weekday_no,converted_date1,ISO_date[2]);
					var tempDate= addDate(converted_date1, newStartDateNo);
					document.event.start_date.value= convertBack_date_format(tempDate);
					tempDate  = addDate(converted_date2, newStartDateNo);
					document.event.end_date.value  = convertBack_date_format(tempDate);
				}
				else
				{
					message=" "+message_string10+" "+(start_end_diff+1)+" "+message_string11+". \n "+message_string12+". \n "+message_string09+".";
					return_bool=false;
				}

			}
			else
			{
				message=" "+message_string08+".";
				return_bool=false;
			}


		}
		else if(recur_pattern==2)
		{
			if(start_end_diff>28)
			{
				return_bool=false;
					message=" "+message_string10+" "+start_end_diff+" "+message_string11+". \n "+message_string12+". \n "+message_string09+".";
			}
			else if(document.event.monthType[0].checked)
			{
				recur_pattern_string="MD"+document.event.month_every.value+" ";

				if(document.event.DayOfMonth.value>28)
				{
					if(confirm("Some months have fewer than "+document.event.DayOfMonth.value+" days. For these months, the occurrence will fall on the last day of the month."))
					{
						recur_pattern_string+=document.event.DayOfMonth.value+" ";
						var tempDate=getDatebyDayNo( convert_date_format(document.event.start_date.value), document.event.DayOfMonth.value);
						document.event.start_date.value=convertBack_date_format(tempDate);
						tempDate=addDate(convert_date_format(document.event.start_date.value), start_end_diff);
						document.event.end_date.value=convertBack_date_format(tempDate);
					}
					else
					return_bool=false;
				}
				else
				{
					recur_pattern_string+=document.event.DayOfMonth.value+" ";
					var tempDate=getDatebyDayNo(convert_date_format(document.event.start_date.value) ,document.event.DayOfMonth.value);
					document.event.start_date.value=convertBack_date_format(tempDate);
					tempDate=addDate(convert_date_format(document.event.start_date.value), start_end_diff);
					document.event.end_date.value=convertBack_date_format(tempDate);
				}
			}
			else
			{
				recur_pattern_string="MP"+document.event.n_month_every.value+" ";
				recur_pattern_string+=document.event.n_week.value+"+ ";

				var tempDate=getNearestMP(document.event.n_dayOfWeek.value.substring(3,4), convert_date_format(document.event.start_date.value),document.event.n_week.value);
				document.event.start_date.value=convertBack_date_format(tempDate);
				tempDate=addDate(convert_date_format(document.event.start_date.value), start_end_diff);
				document.event.end_date.value=convertBack_date_format(tempDate);

				recur_pattern_string+=document.event.n_dayOfWeek.value.substring(0,2)+" ";
			}

		}
		else if(recur_pattern==3)
		{
			if(start_end_diff>364)
			{
				return_bool=false;
				message=" "+message_string10+" "+start_end_diff+" "+message_string11+". \n "+message_string12+". \n "+message_string09+".";
			}
			else if(document.event.yearType[0].checked)  //yearly by day
			{
				recur_pattern_string="YD1"+" ";
			}
			else  //by month
			{
				recur_pattern_string="YM1"+" ";
				recur_pattern_string+=document.event.year_n_week.value+"+ ";

				var convert_date1=convert_date_format(document.event.start_date.value);
				var convert_date2=getNearestMP(document.event.year_dow.value.substring(3,4),
							     document.event.startmonth.value+'/01/'+convert_date1.substr(6,4),
							     document.event.year_n_week.value);
				document.event.start_date.value=convertBack_date_format(convert_date2);

				convert_date2=addDate(convert_date1, start_end_diff);
				document.event.end_date.value=convertBack_date_format(convert_date2);

				recur_pattern_string+=document.event.year_dow.value.substring(0,2)+" ";

			}



		}

		if(return_bool)
		confirmEndDate();
}

function getNearestMP(dow_start, startDate, no_week)  //DayofWeek ,  startDate,  n_week
{
	var first_day_month_ISO_date=startDate.substr(0,2)+'/01/'+ startDate.substr(6,4);
	var first_day_month_dow=YMD_To_YWD(first_day_month_ISO_date)[2];
	var add_diff=0;

	if (first_day_month_dow <= dow_start)
	add_diff=parseInt(no_week)*7 + parseInt(dow_start)- first_day_month_dow - 7;
	else
	add_diff=parseInt(no_week)*7+ parseInt(dow_start)-first_day_month_dow;

	return addDate(first_day_month_ISO_date, add_diff);

}

//this function finds out the shortest duration between the recurring pattern and
//compare to Date_diff to find out is it overlapping involved
function isOverLap(stringRecurringPattern, duration)
{
	if(duration==0)
	return true;

	if(stringRecurringPattern.length==1)
	return (duration<7);
	else
	{
		var tempNo_0=stringRecurringPattern.substr(0,1);
		for (var i=1; i<stringRecurringPattern.length; i++)
		{
			var tempNo_next=stringRecurringPattern.substr(i,1);
			var final_diff=parseInt(tempNo_next)-parseInt(tempNo_0);
			//if diff >3 then it can shorted in reverse order
			if( final_diff>3)
			final_diff=7-final_diff;

			if(duration>=final_diff)
			return false;
		}
		return true;

	}
}


// get the nearest date of the sDate in Day of Week pattern
function getNearestDateNo(stringDOW, startDate, sDateDOW)
{

	var index1=stringDOW.indexOf(sDateDOW);
	if(index1>=0)
	return 0;
	else
	{
		for(var i = 1; i <7; i++)
		{
			var dow1=sDateDOW+i;

			if(dow1>7)
			dow1=dow1-7;

			if(stringDOW.indexOf(dow1)>=0)
			{
				return i;//addDate(startDate, i);
			}

		}
	}
	return "ERROR DATE";

}

//add the specific days to certain Date
function addDate(sDate, add_days)
{
		if(add_days==0)
		return sDate;

		// Strip out the month, day and year, JavaScript stores months as 0-11 as opposed to 1-12
		var EnteredMonth = sDate.substr(0,2) - 1;
		var EnteredDay = sDate.substr(3,2);
		var EnteredYear = sDate.substr(6,4);

		// Create a new date object with the entered month, day and year
		var EnteredDate = new Date(EnteredYear, EnteredMonth, EnteredDay, 0, 0, 0);
		// Determine the milliseconds in the timespan ,  Set the default (1 day)
		var MilliSecondsBase = 86400000

		// If the timespan is weeks, multiply the default by 7
		//	MilliSecondsBase *= 7;

		// Multiply the millisecons by the period entered
		MilliSecondsToAdd  = MilliSecondsBase * add_days;

		// Create the new date using the correct operation
		var NewDateAsNumber = EnteredDate.getTime() + MilliSecondsToAdd;
		//substract 	var NewDateAsNumber = EnteredDate.getTime() - MilliSecondsToAdd;

		// Create the new date object
		var NewDate = new Date(NewDateAsNumber);
		// Get the month, day and year values from the new date object
		// Set the month and day to two digits if they are less than 10
		var NewMonth = NewDate.getMonth() + 1;
		if (NewMonth < 10)
		{
			NewMonth = "0" + NewMonth;
		}
		var NewDay = NewDate.getDate();
		if (NewDay < 10)
		{
			NewDay = "0" + NewDay;
		}
		var NewYear = NewDate.getFullYear();

		return NewMonth + "/" + NewDay + "/" + NewYear;
}

function confirmEndDate()
{

	if(document.event.enddatetype[0].checked)
	{
		var field_v=document.event.RecurrenceEnd.value;

		if(field_v=="")
		{
			message=" "+message_string13+".";
			return_bool=false;
			return;
		}

		if(date_validate(document.event.RecurrenceEnd))
		{

			field_v=convert_date_format(field_v);
			recur_pattern_string+=field_v.substr(6,4)+field_v.substr(0,2)+field_v.substr(3,2)+"T000000Z ";
			document.event.generate_until.value=field_v;
		}
		else
		{
			return_bool=false;
		}

	}
	else if(document.event.enddatetype[1].checked)
	{
		if(document.event.end_after_x.value==""||NotInteger(document.event.end_after_x.value)|| document.event.end_after_x.value<1)
		{
			return_bool=false;
			message=message_string14+".";
		}
		else
		recur_pattern_string += '#' + document.event.end_after_x.value +' ';
	}
	else if(document.event.enddatetype[2].checked)
	{
		recur_pattern_string+="#0 ";
		var no_end_date=convert_date_format(document.event.start_date.value);
		no_end_date = no_end_date.substr(0,2) +'/'+no_end_date.substr(3,2)+'/'+(parseInt(no_end_date.substr(6,4))+1);
		document.event.generate_until.value=no_end_date;
		document.event.repeat_until.value=no_end_date;
	}

	return;
}



function doPattern()
{
		//alert("RecurrencePattern is " +document.event.RecurrencePattern.value);
	  	var repeatElemnet, repeatId;
		for (i=1; i < 4; i++)
		{
			repeatId="repeatpattern"+i;
			hideLayer(repeatId);
			//repeatElement = getDiv(repeatId);
   			//repeatElement.style.display = "none";
		}
		repeatId="repeatpattern"+document.event.RecurrencePattern.value;
		showLayer(repeatId);
		//repeatElement = getDiv(repeatId);
		//repeatElement.style.display = "";
}

function showLayer(nameOfLayer)
// Needs to be sent the fully qualified name of the layer.
{
	if (document.all)
	{
		var thisElement = getDiv(nameOfLayer);
		thisElement.style.display = "";
	}
	else
		eval ("document.layers."+nameOfLayer + '.visibility = "show";');
}

function hideLayer(nameOfLayer)
// Needs to be sent the fully qualified name of the layer.
{
	if (document.all)
	{
		var thisElement = getDiv(nameOfLayer);
		thisElement.style.display = "none";
	}
	else
		eval ("document.layers."+nameOfLayer + '.visibility = "hide";');
}


function compareDate(date1,date2)
{
			var Month1 = date1.substr(0,2);
			var Day1 = date1.substr(3,2);
			var Year1 = date1.substr(6,4);
			var Month2 = date2.substr(0,2);
			var Day2 = date2.substr(3,2);
			var Year2 = date2.substr(6,4);

			if(Year1<Year2)
				return false;
			else if(Year1==Year2&&Month1<Month2)
				return false;
			else if(Year1==Year2&&Month1==Month2&&Day1<Day2)
				return false;


			return true;
}


function date_validate(element)  //date_validate DATE
{
	var Proceed = 0;
	// Create a variable to hold the correct format.

	var CorrectFormat = /[0-1][0-9]\/[0-3][0-9]\/[0-9][0-9][0-9][0-9]/;
	// If the field has value, date_validate the date.
	 message = "[ "+ element.id + " ]  "+message_string15+". ";

	//alert("message_string19 :"+message_string19);

	var element_date=element.value;

	if (element_date)
	{
		if(element_date.length>10 || element_date.length < 8||DateFormatNotCorrect(element_date))
		{
			message="[ "+ element.id + " ]  "+message_string16+". ";
			return false;
		}

		if(element_date.length==9 || element_date.length == 8)
		{
			element_date=convertDateTo10Char(element_date);
		}

		//convert date to standard MM/DD/YYYY then process
		element_date=convert_date_format(element_date);
		element.value=convertBack_date_format( element_date);


		// Test to see if the format of the date is correct , this date format is always MM/DD/YYYY.
		if (CorrectFormat.test(element_date))
		{
			// Split out the month, day and year variables.
			var Month = element_date.substr(0,2);
			var Day = element_date.substr(3,2);
			var Year = element_date.substr(6,4);
			// Ensure all the values are greater than 0
			if (Month > 0 && Day > 0 && Year > 0)
			{
				// Find the max day for the month,  default max day is 31
				var maxDays = 31;
				// If the month is April, June, September or November the max day is 30
				if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
				{
					maxDays = 30;
				}
				if (Month == 2)
				{
					if (Year % 4 > 0)
						maxDays =28;
					else
					if (Year % 100 == 0 && Year % 400 > 0)
						maxDays = 28;
					else
						maxDays = 29;
				}
				// Determine if the day entered is less than the max days for that month.
				if (Day <= maxDays)
				Proceed = 1;
				else
				message = "[ "+ element.id + " ]  "+message_string18+". ";

				if (Month >12 )
				{
					Proceed = 0;
					message = "[ "+ element.id + " ]  "+message_string17+". ";
				}

			}
		}
		else
		{
			message = "[ "+ element.id + " ]  "+message_string19+". ";
		}
	}
	if (Proceed == 0)
	{

		return false;
	}
	else
	{
		return true;
	}
}

function getDatebyDayNo(element_date, dayNo)  //date_validate DATE
{
	// Split out the month, day and year variables.
	var Month = element_date.substr(0,2);
	var Day = element_date.substr(3,2);
	var Year = element_date.substr(6,4);

		// Find the max day for the month,  default max day is 31
		var maxDays = 31;
		// If the month is April, June, September or November the max day is 30
		if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
		{
			maxDays = 30;
		}
		if (Month == 2)
		{
			if (Year % 4 > 0)
			maxDays =28;
			else
			if (Year % 100 == 0 && Year % 400 > 0)
			maxDays = 28;
			else
			maxDays = 29;
		}
		// Determine if the day entered is less than the max days for that month.

		if (dayNo <= maxDays)
		{
			if (dayNo < 10)
			{
				dayNo = "0" + dayNo;
			}
			return Month+'/'+dayNo+'/'+Year;
		}
		else
		return Month+'/'+maxDays+'/'+Year;
}


function DiffDays(S2, S1) {


 	var X=[S2.substr(6,4),S2.substr(0,2),S2.substr(3,2)];
 	var Y=[S1.substr(6,4),S1.substr(0,2),S1.substr(3,2)];

 	return (Date.UTC(X[0], X[1]-1, X[2])-Date.UTC(Y[0], Y[1]-1, Y[2]))/86400000
 }


function YMD_To_YWD( dateS) {

	var S=[dateS.substr(6,4),dateS.substr(0,2),dateS.substr(3,2)];

	 with (new Date(S[0], S[1]-1, S[2]))
	 { var DoW = getDay()
 		 setDate(getDate() - (DoW+6)%7 + 3 ) // Nearest Thu
		  var ms = valueOf() // GMT
		  setMonth(0) ;
		  setDate(4) // In Week 1
		  var WN = Math.round( (ms-valueOf()) / (7*86400000) ) + 1
		  if (DoW==0) DoW = 7 // JS to ISO DoW
		  //alert("DoW= "+DoW);
		  return [getFullYear(), WN, DoW]
  	}

}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}


function NotInteger (s)

{
	var i;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return true;
    }

    // All characters are numbers.
    return false;
}

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c)
{
	return ((c >= "0") && (c <= "9"));
}

// calendarpopup.js
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/*
CalendarPopup.js
Author: Matt Kruse
Last modified: 3/21/02

DESCRIPTION: This object implements a popup calendar to allow the user to
select a date, month, quarter, or year.

COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the
Macintosh platform.
The calendar can be modified to work for any location in the world by
changing which weekday is displayed as the first column, changing the month
names, and changing the column headers for each day.

USAGE:
// Create a new CalendarPopup object of type WINDOW
var cal = new CalendarPopup();

// Create a new CalendarPopup object of type DIV using the DIV named 'mydiv'
var cal = new CalendarPopup('mydiv');

// Easy method to link the popup calendar with an input box.
cal.select(inputObject, anchorname, dateFormat);
// This is an example call to the popup calendar from a link to populate an
// input box. Note that to use this, date.js must also be included!!
<A HREF="#" onClick="cal.select(document.forms[0].date,'anchorname','MM/dd/yyyy'); return false;">Select</A>

// Set the type of date select to be used. By default it is 'date'.
cal.setDisplayType(type);

// When a date, month, quarter, or year is clicked, a function is called and
// passed the details. You must write this function, and tell the calendar
// popup what the function name is.
// Function to be called for 'date' select receives y, m, d
cal.setReturnFunction(functionname);
// Function to be called for 'month' select receives y, m
cal.setReturnMonthFunction(functionname);
// Function to be called for 'quarter' select receives y, q
cal.setReturnQuarterFunction(functionname);
// Function to be called for 'year' select receives y
cal.setReturnYearFunction(functionname);

// Show the calendar relative to a given anchor
cal.showCalendar(anchorname);

// Hide the calendar. The calendar is set to autoHide automatically
cal.hideCalendar();

// Set the month names to be used. Default are English month names
cal.setMonthNames("January","February","March",...);

// Set the month abbreviations to be used. Default are English month abbreviations
cal.setMonthAbbreviations("Jan","Feb","Mar",...);

// Set the text to be used above each day column. The days start with
// sunday regardless of the value of WeekStartDay
cal.setDayHeaders("S","M","T",...);

// Set the day for the first column in the calendar grid. By default this
// is Sunday (0) but it may be changed to fit the conventions of other
// countries.
cal.setWeekStartDay(1); // week is Monday - Saturday

// Set the weekdays which should be disabled in the 'date' select popup. You can
// then allow someone to only select week end dates, or Tuedays, for example
cal.setDisabledWeekDays(0,1); // To disable selecting the 1st or 2nd days of the week

// When the 'year' select is displayed, set the number of years back from the
// current year to start listing years. Default is 2.
cal.setYearSelectStartOffset(2);

// Text for the word "Today" appearing on the calendar
cal.setTodayText("Today");

// Set the calendar offset to be different than the default. By default it
// will appear just below and to the right of the anchorname. So if you have
// a text box where the date will go and and anchor immediately after the
// text box, the calendar will display immediately under the text box.
cal.offsetX = 20;
cal.offsetY = 20;

NOTES:
1) Requires the functions in AnchorPosition.js and PopupWindow.js

2) Your anchor tag MUST contain both NAME and ID attributes which are the
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the
   anchor tag correctly. Do not do <A></A> with no space.

4) When a CalendarPopup object is created, a handler for 'onmouseup' is
   attached to any event handler you may have already defined. Do NOT define
   an event handler for 'onmouseup' after you define a CalendarPopup object
   or the autoHide() will not work correctly.

5) The calendar display uses "graypixel.gif" which is a 1x1 gray pixel of
   color #C0C0C0. If this file is not present, the calendar display should
   still be fine but will not show the gray lines.

6) The calendar popup display uses style sheets to make it look nice.

*/

// CONSTRUCTOR for the CalendarPopup Object
function CalendarPopup() {
	var c;
	if (arguments.length>0) {
		c = new PopupWindow(arguments[0]);
		}
	else {
		c = new PopupWindow();
		c.setSize(150,175);
		}
	c.offsetX = -105;
	c.offsetY = 5;
	c.autoHide();
	// Calendar-specific properties
	c.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	c.monthAbbreviations = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	c.dayHeaders = new Array("S","M","T","W","T","F","S");
	c.returnFunction = "CalendarPopup_tmpReturnFunction";
	c.returnMonthFunction = "CalendarPopup_tmpReturnMonthFunction";
	c.returnQuarterFunction = "CalendarPopup_tmpReturnQuarterFunction";
	c.returnYearFunction = "CalendarPopup_tmpReturnYearFunction";
	c.weekStartDay = 0;
	c.isShowYearNavigation = false;
	c.displayType = "date";
	c.disabledWeekDays = new Object();
	c.yearSelectStartOffset = 2;
	c.currentDate = null;
	c.todayText="Today";
	window.CalendarPopup_targetInput = null;
	window.CalendarPopup_dateFormat = "mm/dd/yyyy";
	// Method mappings
	c.setReturnFunction = CalendarPopup_setReturnFunction;
	c.setReturnMonthFunction = CalendarPopup_setReturnMonthFunction;
	c.setReturnQuarterFunction = CalendarPopup_setReturnQuarterFunction;
	c.setReturnYearFunction = CalendarPopup_setReturnYearFunction;
	c.setMonthNames = CalendarPopup_setMonthNames;
	c.setMonthAbbreviations = CalendarPopup_setMonthAbbreviations;
	c.setDayHeaders = CalendarPopup_setDayHeaders;
	c.setWeekStartDay = CalendarPopup_setWeekStartDay;
	c.setDisplayType = CalendarPopup_setDisplayType;
	c.setDisabledWeekDays = CalendarPopup_setDisabledWeekDays;
	c.setYearSelectStartOffset = CalendarPopup_setYearSelectStartOffset;
	c.setTodayText = CalendarPopup_setTodayText;
	c.showYearNavigation = CalendarPopup_showYearNavigation;
	c.showCalendar = CalendarPopup_showCalendar;
	c.hideCalendar = CalendarPopup_hideCalendar;
	c.getStyles = CalendarPopup_getStyles;
	c.refreshCalendar = CalendarPopup_refreshCalendar;
	c.getCalendar = CalendarPopup_getCalendar;
	c.select = CalendarPopup_select;
	// Return the object
	return c;
	}

// Temporary default functions to be called when items clicked, so no error is thrown
function CalendarPopup_tmpReturnFunction(y,m,d) {
	if (window.CalendarPopup_targetInput!=null) {
		var dt = new Date(y,m-1,d,0,0,0);
		window.CalendarPopup_targetInput.value = formatDate(dt,window.CalendarPopup_dateFormat);
		}
	else {
		alert('Use setReturnFunction() to define which function will get the clicked results!');
		}
	}
function CalendarPopup_tmpReturnMonthFunction(y,m) {
	alert('Use setReturnMonthFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , month='+m);
	}
function CalendarPopup_tmpReturnQuarterFunction(y,q) {
	alert('Use setReturnQuarterFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , quarter='+q);
	}
function CalendarPopup_tmpReturnYearFunction(y) {
	alert('Use setReturnYearFunction() to define which function will get the clicked results!\nYou clicked: year='+y);
	}

// Set the name of the functions to call to get the clicked item
function CalendarPopup_setReturnFunction(name) { this.returnFunction = name; }
function CalendarPopup_setReturnMonthFunction(name) { this.returnMonthFunction = name; }
function CalendarPopup_setReturnQuarterFunction(name) { this.returnQuarterFunction = name; }
function CalendarPopup_setReturnYearFunction(name) { this.returnYearFunction = name; }

// Over-ride the built-in month names
function CalendarPopup_setMonthNames() {
	for (var i=0; i<arguments.length; i++) { this.monthNames[i] = arguments[i]; }
	}

// Over-ride the built-in month abbreviations
function CalendarPopup_setMonthAbbreviations() {
	for (var i=0; i<arguments.length; i++) { this.monthAbbreviations[i] = arguments[i]; }
	}

// Over-ride the built-in column headers for each day
function CalendarPopup_setDayHeaders() {
	for (var i=0; i<arguments.length; i++) { this.dayHeaders[i] = arguments[i]; }
	}

// Set the day of the week (0-7) that the calendar display starts on
// This is for countries other than the US whose calendar displays start on Monday(1), for example
function CalendarPopup_setWeekStartDay(day) { this.weekStartDay = day; }

// Show next/last year navigation links
function CalendarPopup_showYearNavigation() { this.isShowYearNavigation = true; }

// Which type of calendar to display
function CalendarPopup_setDisplayType(type) {
	if (type!="date"&&type!="week-end"&&type!="month"&&type!="quarter"&&type!="year") { alert("Invalid display type! Must be one of: date,week-end,month,quarter,year"); return false; }
	this.displayType=type;
	}

// How many years back to start by default for year display
function CalendarPopup_setYearSelectStartOffset(num) { this.yearSelectStartOffset=num; }

// Set which weekdays should not be clickable
function CalendarPopup_setDisabledWeekDays() {
	this.disabledWeekDays = new Object();
	for (var i=0; i<arguments.length; i++) { this.disabledWeekDays[arguments[i]] = true; }
	}

// Set the text to use for the "Today" link
function CalendarPopup_setTodayText(text) {
	this.todayText = text;
	}

// Hide a calendar object
function CalendarPopup_hideCalendar() {
	if (arguments.length > 0) { window.popupWindowObjects[arguments[0]].hidePopup(); }
	else { this.hidePopup(); }
	}

// Refresh the contents of the calendar display
function CalendarPopup_refreshCalendar(index) {
	var calObject = window.popupWindowObjects[index];
	if (arguments.length>1) {
		calObject.populate(calObject.getCalendar(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]));
		}
	else {
		calObject.populate(calObject.getCalendar());
		}
	calObject.refresh();
	}

// Populate the calendar and display it
function CalendarPopup_showCalendar(anchorname) {
	this.populate(this.getCalendar());
	this.showPopup(anchorname);
	}

// Simple method to interface popup calendar with a text-entry box
function CalendarPopup_select(inputobj, linkname, format) {
	if (!window.getDateFromFormat) {
		alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
		return;
		}
	if (this.displayType!="date"&&this.displayType!="week-end") {
		alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
		return;
		}
	if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") {
		alert("calendar.select: Input object passed is not a valid form input object");
		window.CalendarPopup_targetInput=null;
		return;
		}
	window.CalendarPopup_targetInput = inputobj;
	if (inputobj.value!="") {
		var time = getDateFromFormat(inputobj.value,format);
		if (time==0) { this.currentDate=null; }
		else { this.currentDate=new Date(time); }
		}
	else { this.currentDate=null; }
	window.CalendarPopup_dateFormat = format;
	this.showCalendar(linkname);
	}

// Get style block needed to display the calendar correctly
function CalendarPopup_getStyles() {
	var result = "";
	result += "<STYLE>\n";
	result += "TD.cal { font-family:arial; font-size: 8pt; }\n";
	result += "TD.calmonth { font-family:arial; font-size: 8pt; text-align: right;}\n";
	result += "TD.caltoday { font-family:arial; font-size: 8pt; text-align: right; color: white; background-color:#C0C0C0; border-width:1; border-type:solid; border-color:#800000; }\n";
	result += "A.textlink { font-family:arial; font-size: 8pt; height: 20px; color: black; }\n";
	result += ".disabledtextlink { font-family:arial; font-size: 8pt; height: 20px; color: #808080; }\n";
	result += "A.cal { text-decoration:none; color:#000000; }\n";
	result += "A.calthismonth { text-decoration:none; color:#000000; }\n";
	result += "A.calothermonth { text-decoration:none; color:#808080; }\n";
	result += ".calnotclickable { color:#808080; }\n";
	result += "</STYLE>\n";
	return result;
	}

// Return a string containing all the calendar code to be displayed
function CalendarPopup_getCalendar() {
	var now = new Date();
	// Reference to window
	if (this.type == "WINDOW") { var windowref = "window.opener."; }
	else { var windowref = ""; }
	var result = "";
	// If POPUP, write entire HTML document
	if (this.type == "WINDOW") {
		result += "<HTML><HEAD><TITLE>Calendar</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
		result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
		}
	else {
		result += '<TABLE WIDTH=144 BORDER=1 BORDERWIDTH=1 BORDERCOLOR="#808080" CELLSPACING=0 CELLPADDING=1>\n';
		result += '<TR><TD ALIGN=CENTER>\n';
		result += '<CENTER>\n';
		}

	// Code for DATE display (default)
	// -------------------------------
	if (this.displayType=="date" || this.displayType=="week-end") {
		if (this.currentDate==null) { this.currentDate = now; }
		if (arguments.length > 0) { var month = arguments[0]; }
			else { var month = this.currentDate.getMonth()+1; }
		if (arguments.length > 1) { var year = arguments[1]; }
			else { var year = this.currentDate.getFullYear(); }
		var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
		if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) {
			daysinmonth[2] = 29;
			}
		var current_month = new Date(year,month-1,1);
		var display_year = year;
		var display_month = month;
		var display_date = 1;
		var weekday= current_month.getDay();
		var offset = 0;
		if (weekday >= this.weekStartDay) {
			offset = weekday - this.weekStartDay;
			}
		else {
			offset = 7-this.weekStartDay+weekday;
			}
		if (offset > 0) {
			display_month--;
			if (display_month < 1) { display_month = 12; display_year--; }
			display_date = daysinmonth[display_month]-offset+1;
			}
		var next_month = month+1;
		var next_month_year = year;
		if (next_month > 12) { next_month=1; next_month_year++; }
		var last_month = month-1;
		var last_month_year = year;
		if (last_month < 1) { last_month=12; last_month_year--; }
		var date_class;
		if (this.type!="WINDOW") {
			result += '<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
			}
		result += '<TR BGCOLOR="#C0C0C0">\n';
		var refresh = 'javascript:'+windowref+'CalendarPopup_refreshCalendar';
		if (this.isShowYearNavigation) {
			var td = '<TD BGCOLOR="#C0C0C0" CLASS="cal" ALIGN=CENTER VALIGN=MIDDLE ';
			result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+last_month+','+last_month_year+');">&lt;</A></B></TD>';
			result += td + ' WIDTH=58>'+this.monthNames[month-1]+'</TD>';
			result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+next_month+','+next_month_year+');">&gt;</A></B></TD>';
			result += td + ' WIDTH=10>&nbsp;</TD>';
			result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+month+','+(year-1)+');">&lt;</A></B></TD>';
			result += td + ' WIDTH=36>'+year+'</TD>';
			result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+month+','+(year+1)+');">&gt;</A></B></TD>';
			}
		else {
			result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+last_month+','+last_month_year+');">&lt;&lt;</A></B></TD>\n';
			result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=100 ALIGN=CENTER>'+this.monthNames[month-1]+' '+year+'</TD>\n';
			result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+next_month+','+next_month_year+');">&gt;&gt;</A></B></TD>\n';
			}
		result += '</TR></TABLE>\n';
		result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
		result += '<TR>\n';
		var td = '	<TD CLASS="cal" ALIGN=RIGHT WIDTH=14%>';
		for (var j=0; j<7; j++) {
			result += td+this.dayHeaders[(this.weekStartDay+j)%7]+'</TD>\n';
			}
		result += '</TR>\n';
		result += '<TR><TD COLSPAN=7 ALIGN=CENTER><IMG SRC="graypixel.gif" WIDTH=120 HEIGHT=1></TD></TR>\n';
		for (var row=1; row<=6; row++) {
			result += '<TR>\n';
			for (var col=1; col<=7; col++) {
				if (display_month == month) {
					date_class = "calthismonth";
					}
				else {
					date_class = "calothermonth";
					}
				if ((display_month == this.currentDate.getMonth()+1) && (display_date==this.currentDate.getDate()) && (display_year==this.currentDate.getFullYear())) {
					td_class="caltoday";
					}
				else {
					td_class="calmonth";
					}
				if (this.disabledWeekDays[col-1]) {
					date_class="calnotclickable";
					result += '	<TD CLASS="'+td_class+'"><SPAN CLASS="'+date_class+'">'+display_date+'</SPAN></TD>\n';
					}
				else {
					var selected_date = display_date;
					var selected_month = display_month;
					var selected_year = display_year;
					if (this.displayType=="week-end") {
						var d = new Date(selected_year,selected_month-1,selected_date,0,0,0,0);
						d.setDate(d.getDate() + (7-col));
						selected_year = d.getYear();
						if (selected_year < 1000) { selected_year += 1900; }
						selected_month = d.getMonth()+1;
						selected_date = d.getDate();
						}
					result += '	<TD CLASS="'+td_class+'"><A HREF="javascript:'+windowref+this.returnFunction+'('+selected_year+','+selected_month+','+selected_date+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+display_date+'</A></TD>\n';
					}
				display_date++;
				if (display_date > daysinmonth[display_month]) {
					display_date=1;
					display_month++;
					}
				if (display_month > 12) {
					display_month=1;
					display_year++;
					}
				}
			result += '</TR>';
			}
		var current_weekday = now.getDay();
		result += '<TR><TD COLSPAN=7 ALIGN=CENTER><IMG SRC="graypixel.gif" WIDTH=120 HEIGHT=1></TD></TR>\n';
		result += '<TR>\n';
		result += '	<TD COLSPAN=7 ALIGN=CENTER>\n';
		if (this.disabledWeekDays[current_weekday+1]) {
			result += '		<SPAN CLASS="disabledtextlink">'+this.todayText+'</SPAN>\n';
			}
		else {
			result += '		<A CLASS="textlink" HREF="javascript:'+windowref+this.returnFunction+'(\''+now.getFullYear()+'\',\''+(now.getMonth()+1)+'\',\''+now.getDate()+'\');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');">'+this.todayText+'</A>\n';
			}
		result += '		<BR>\n';
		result += '	</TD></TR></TABLE></CENTER></TD></TR></TABLE>\n';
	}

	// Code common for MONTH, QUARTER, YEAR
	// ------------------------------------
	if (this.displayType=="month" || this.displayType=="quarter" || this.displayType=="year") {
		if (arguments.length > 0) { var year = arguments[0]; }
		else {
			if (this.displayType=="year") {	var year = now.getFullYear()-this.yearSelectStartOffset; }
			else { var year = now.getFullYear(); }
			}
		if (this.displayType!="year" && this.isShowYearNavigation) {
			result += '<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
			result += '<TR BGCOLOR="#C0C0C0">\n';
			result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year-1)+');">&lt;&lt;</A></B></TD>\n';
			result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=100 ALIGN=CENTER>'+year+'</TD>\n';
			result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year+1)+');">&gt;&gt;</A></B></TD>\n';
			result += '</TR></TABLE>\n';
			}
		}

	// Code for MONTH display (default)
	// -------------------------------
	if (this.displayType=="month") {
		// If POPUP, write entire HTML document
		result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
		for (var i=0; i<4; i++) {
			result += '<TR>';
			for (var j=0; j<3; j++) {
				var monthindex = ((i*3)+j);
				result += '<TD WIDTH=33% ALIGN=CENTER><A CLASS="textlink" HREF="javascript:'+windowref+this.returnMonthFunction+'('+year+','+(monthindex+1)+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+this.monthAbbreviations[monthindex]+'</A></TD>';
				}
			result += '</TR>';
			}
		result += '</TABLE></CENTER></TD></TR></TABLE>\n';
		}

	// Code for QUARTER display (default)
	// ----------------------------------
	if (this.displayType=="quarter") {
		result += '<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n';
		for (var i=0; i<2; i++) {
			result += '<TR>';
			for (var j=0; j<2; j++) {
				var quarter = ((i*2)+j+1);
				result += '<TD WIDTH=50% ALIGN=CENTER><BR><A CLASS="textlink" HREF="javascript:'+windowref+this.returnQuarterFunction+'('+year+','+quarter+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">Q'+quarter+'</A><BR><BR></TD>';
				}
			result += '</TR>';
			}
		result += '</TABLE></CENTER></TD></TR></TABLE>\n';
		}

	// Code for YEAR display (default)
	// -------------------------------
	if (this.displayType=="year") {
		var yearColumnSize = 4;
		result += '<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
		result += '<TR BGCOLOR="#C0C0C0">\n';
		result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year-(yearColumnSize*2))+');">&lt;&lt;</A></B></TD>\n';
		result += '	<TD BGCOLOR="#C0C0C0" CLASS="cal" WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year+(yearColumnSize*2))+');">&gt;&gt;</A></B></TD>\n';
		result += '</TR></TABLE>\n';
		result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
		for (var i=0; i<yearColumnSize; i++) {
			for (var j=0; j<2; j++) {
				var currentyear = year+(j*yearColumnSize)+i;
				result += '<TD WIDTH=50% ALIGN=CENTER><A CLASS="textlink" HREF="javascript:'+windowref+this.returnYearFunction+'('+currentyear+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+currentyear+'</A></TD>';
				}
			result += '</TR>';
			}
		result += '</TABLE></CENTER></TD></TR></TABLE>\n';
		}
	// Common
	if (this.type == "WINDOW") {
		result += "</BODY></HTML>\n";
		}
	return result;
	}

// date.js
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
//
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}

// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}

// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";

	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					month=i+1;
					if (month>12) { month -= 12; }
					i_val += month_name.length;
					break;
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return false; }
			}
		else { if (date > 28) { return false; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return false; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

// popupwindow.js
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/*
PopupWindow.js
Author: Matt Kruse
Last modified: 3/21/02

DESCRIPTION: This object allows you to easily and quickly popup a window
in a certain place. The window can either be a DIV or a separate browser
window.

COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the
Macintosh platform. Due to bugs in Netscape 4.x, populating the popup
window with <STYLE> tags may cause errors.

USAGE:
// Create an object for a WINDOW popup
var win = new PopupWindow();

// Create an object for a DIV window using the DIV named 'mydiv'
var win = new PopupWindow('mydiv');

// Set the window to automatically hide itself when the user clicks
// anywhere else on the page except the popup
win.autoHide();

// Show the window relative to the anchor name passed in
win.showPopup(anchorname);

// Hide the popup
win.hidePopup();

// Set the size of the popup window (only applies to WINDOW popups
win.setSize(width,height);

// Populate the contents of the popup window that will be shown. If you
// change the contents while it is displayed, you will need to refresh()
win.populate(string);

// Refresh the contents of the popup
win.refresh();

// Specify how many pixels to the right of the anchor the popup will appear
win.offsetX = 50;

// Specify how many pixels below the anchor the popup will appear
win.offsetY = 100;

NOTES:
1) Requires the functions in AnchorPosition.js

2) Your anchor tag MUST contain both NAME and ID attributes which are the
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the
   anchor tag correctly. Do not do <A></A> with no space.

4) When a PopupWindow object is created, a handler for 'onmouseup' is
   attached to any event handler you may have already defined. Do NOT define
   an event handler for 'onmouseup' after you define a PopupWindow object or
   the autoHide() will not work correctly.
*/

// Set the position of the popup window based on the anchor
function PopupWindow_getXYPosition(anchorname) {
	var coordinates;
	if (this.type == "WINDOW") {
		coordinates = getAnchorWindowPosition(anchorname);
		}
	else {
		coordinates = getAnchorPosition(anchorname);
		}
	this.x = coordinates.x;
	this.y = coordinates.y;
	}
// Set width/height of DIV/popup window
function PopupWindow_setSize(width,height) {
	this.width = width;
	this.height = height;
	}
// Fill the window with contents
function PopupWindow_populate(contents) {
	this.contents = contents;
	this.populated = false;

	}
// Refresh the displayed contents of the popup
function PopupWindow_refresh() {
	this.visible = true;
	if (this.divName != null) {
		// refresh the DIV object
		if (this.use_gebi) {
			document.getElementById(this.divName).innerHTML = this.contents;
			}
		else if (this.use_css) {
			document.all[this.divName].innerHTML = this.contents;
			}
		else if (this.use_layers) {
			var d = document.layers[this.divName];
			d.document.open();
			d.document.writeln(this.contents);
			d.document.close();
			}
		}
	else {
		if (this.popupWindow != null && !this.popupWindow.closed) {
			this.popupWindow.document.open();
			this.popupWindow.document.writeln(this.contents);
			this.popupWindow.document.close();
			this.popupWindow.focus();
			}
		}
	}
// Position and show the popup, relative to an anchor object
function PopupWindow_showPopup(anchorname) {
	this.visible = true;
	this.getXYPosition(anchorname);
	this.x += this.offsetX;
	this.y += this.offsetY;
	if (!this.populated && (this.contents != "")) {
		this.populated = true;
		this.refresh();
		}
	if (this.divName != null) {
		// Show the DIV object
		if (this.use_gebi) {
			document.getElementById(this.divName).style.left = this.x;
			document.getElementById(this.divName).style.top = this.y;
			document.getElementById(this.divName).style.visibility = "visible";
			}
		else if (this.use_css) {
			document.all[this.divName].style.left = this.x;
			document.all[this.divName].style.top = this.y;
			document.all[this.divName].style.visibility = "visible";
			}
		else if (this.use_layers) {
			document.layers[this.divName].left = this.x;
			document.layers[this.divName].top = this.y;
			document.layers[this.divName].visibility = "visible";
			}
		}
	else {
		if (this.popupWindow == null || this.popupWindow.closed) {
			// If the popup window will go off-screen, move it so it doesn't
			if (screen && screen.availHeight) {
				if ((this.y + this.height) > screen.availHeight) {
					this.y = screen.availHeight - this.height;
					}
				}
			if (screen && screen.availWidth) {
				if ((this.x + this.width) > screen.availWidth) {
					this.x = screen.availWidth - this.width;
					}
				}
			this.popupWindow = window.open("about:blank","window_"+anchorname,"toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no,width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");
			}
		this.refresh();
		}
	}
// Hide the popup
function PopupWindow_hidePopup() {
	this.visible = false;
	if (this.divName != null) {
		if (this.use_gebi) {
			document.getElementById(this.divName).style.visibility = "hidden";
			}
		else if (this.use_css) {
			document.all[this.divName].style.visibility = "hidden";
			}
		else if (this.use_layers) {
			document.layers[this.divName].visibility = "hidden";
			}

		}
	else {
		if (this.popupWindow && !this.popupWindow.closed) {
			this.popupWindow.close();
			this.popupWindow = null;
			}
		}
	}
// Pass an event and return whether or not it was the popup DIV that was clicked
function PopupWindow_isClicked(e) {
	if (this.divName != null) {
		if (this.use_layers) {
			var clickX = e.pageX;
			var clickY = e.pageY;
			var t = document.layers[this.divName];
			if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
				return true;
				}
			else { return false; }
			}
		else if (document.all) { // Need to hard-code this to trap IE for error-handling
			var t = window.event.srcElement;
			while (t.parentElement != null) {
				if (t.id==this.divName) {
					return true;
					}
				t = t.parentElement;
				}
			return false;
			}
		else if (this.use_gebi) {
			var t = e.originalTarget;
			while (t.parentNode != null) {
				if (t.id==this.divName) {
					return true;
					}
				t = t.parentNode;
				}
			return false;
			}
		return false;
		}
	return false;
	}


// Check an onMouseDown event to see if we should hide
function PopupWindow_hideIfNotClicked(e) {
	if (this.autoHideEnabled && !this.isClicked(e)) {
		this.hidePopup();
		//window.setTimeout("check_window_closed();",500);
		}
	}
// Call this to make the DIV disable automatically when mouse is clicked outside it
function PopupWindow_autoHide() {
	this.autoHideEnabled = true;
	}
// This global function checks all PopupWindow objects onmouseup to see if they should be hidden
function PopupWindow_hidePopupWindows(e) {
	var no_popup_open=true;
	for (var i=0; i<popupWindowObjects.length; i++) {
		if (popupWindowObjects[i] != null) {
			var p = popupWindowObjects[i];
			p.hideIfNotClicked(e);
				if(p.visible)
				{
					no_popup_open=false;
				}
			}
		}
		if(no_popup_open && is_popup_calendar )
		{
			final_hide_popup();
		}
	}
// Run this immediately to attach the event listener
function PopupWindow_attachListener() {
	if (document.layers) {
		document.captureEvents(Event.MOUSEUP);
		}
	window.popupWindowOldEventListener = document.onmouseup;
	if (window.popupWindowOldEventListener != null) {
		document.onmouseup = new Function("window.popupWindowOldEventListener(); PopupWindow_hidePopupWindows();");
		}
	else {
		document.onmouseup = PopupWindow_hidePopupWindows;
		}
	}
// CONSTRUCTOR for the PopupWindow object
// Pass it a DIV name to use a DHTML popup, otherwise will default to window popup
function PopupWindow() {
	if (!window.popupWindowIndex) { window.popupWindowIndex = 0; }
	if (!window.popupWindowObjects) { window.popupWindowObjects = new Array(); }
	if (!window.listenerAttached) {
		window.listenerAttached = true;
		PopupWindow_attachListener();
		}
	this.index = popupWindowIndex++;
	popupWindowObjects[this.index] = this;
	this.divName = null;
	this.popupWindow = null;
	this.width=0;
	this.height=0;
	this.populated = false;
	this.visible = false;
	this.autoHideEnabled = false;

	this.contents = "";
	if (arguments.length>0) {
		this.type="DIV";
		this.divName = arguments[0];
		}
	else {
		this.type="WINDOW";
		}
	this.use_gebi = false;
	this.use_css = false;
	this.use_layers = false;
	if (document.getElementById) { this.use_gebi = true; }
	else if (document.all) { this.use_css = true; }
	else if (document.layers) { this.use_layers = true; }
	else { this.type = "WINDOW"; }
	this.offsetX = 0;
	this.offsetY = 0;
	// Method mappings
	this.getXYPosition = PopupWindow_getXYPosition;
	this.populate = PopupWindow_populate;
	this.refresh = PopupWindow_refresh;
	this.showPopup = PopupWindow_showPopup;
	this.hidePopup = PopupWindow_hidePopup;
	this.setSize = PopupWindow_setSize;
	this.isClicked = PopupWindow_isClicked;
	this.autoHide = PopupWindow_autoHide;
	this.hideIfNotClicked = PopupWindow_hideIfNotClicked;
	}

// anchorposition.js
// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/*
AnchorPosition.js
Author: Matt Kruse
Last modified: 10/11/02

DESCRIPTION: These functions find the position of an <A> tag in a document,
so other elements can be positioned relative to it.

COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the
Macintosh platform.

FUNCTIONS:
getAnchorPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor. Position is relative to the PAGE.

getAnchorWindowPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.

NOTES:

1) For popping up separate browser windows, use getAnchorWindowPosition.
   Otherwise, use getAnchorPosition

2) Your anchor tag MUST contain both NAME and ID attributes which are the
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the
   anchor tag correctly. Do not do <A></A> with no space.
*/

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}


		function check_fck_field_limit(instance_name, len_limit)
		{
			var oEditor = FCKeditorAPI.GetInstance(instance_name) ;
			var new_length=oEditor.GetXHTML( true);
			if( new_length.length > len_limit )
			{
				alert(" Actual ["+instance_name+"] field text length:"+new_length.length+", this field only allow "+len_limit+" chars.");
				return false;
			}
			else
			{
				return true;
			}
		}

    			function check_limit(this_form, limit_int, name_field_name, name_field_title, fck_field_name)
    			{
    				if(this_form[name_field_name].value !="")
    				{
	    				if(check_fck_field_limit(fck_field_name, limit_int))
	    				{
	    					this_form.submit();
	    				}
	    			}
	    			else
	    			{
	    				alert(name_field_title+" cannot be blank.");
	    			}
    			}

