

var lastIdField;

// set global browser identification variables
browser = navigator.appName;
browserNum = parseInt(navigator.appVersion);
N4 = false;
N6 = false;
IE = false;

if ((browser == "Netscape") && (browserNum < 5))
{
	// Netscape 4.x
	layerRef = "document.layers['";
	endLayerRef = "']";
	styleRef = "";
	N4 = true;
}
else if ((browser == "Netscape") && (browserNum >= 5))
{
	// Netscape 6
	layerRef = "document.getElementById('";
	styleRef = ".style";
	endLayerRef = "')";
	N6 = true;
}
else
{
	// Internet Explorer
	layerRef = "document.all['";
	endLayerRef = "']";
	styleRef = ".style";
	IE = true;
}

function positionUnit(inValue) 
{
    if (N6)     return "\'" + inValue + "px\'";
    else        return inValue
}

// create way to remember which layer is visible
oldLayer = "none";
menuDelay = 50; //delay in milliseconds
thisDelay = 0;
varX=0;
finalOpacity=98;
mcMoreCount=0;
menuOut=0;
wuOver = "none";
cancelHide = false;
pendingHide = "";

function showMenuById(layerName, inPosition)
{
    return showMenu(document.getElementById(layerName), inPosition);
}
function showMenu(inLayer, inPosition)
{
	var layerName = inLayer.id;
	// check if clicking on same layer

	if (pendingHide != "" && pendingHide != layerName)  
	{
		eval(   "hideMenuById(\'" + pendingHide + "\',0)"   );
	}
	
	if (oldLayer == layerName)
	{
		// simply do nothing...
		eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'visible'");
		eval(layerRef + layerName + endLayerRef + styleRef + ".display = 'block'");
		oldLayer = layerName;
		varX=0;
		return;
	}
	else
	{
		// hide old menu if there is one...
		if (oldLayer != "none")
		{
//			eval(layerRef + oldLayer + endLayerRef + styleRef + ".visibility = 'hidden'");
		}

		eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'visible'");
		eval(layerRef + layerName + endLayerRef + styleRef + ".display = 'block'");
		menuOut=1;
		oldLayer = layerName;

		var leftPos = getLeft(inPosition);
		if (leftPos+inLayer.offsetWidth+20 > document.body.offsetWidth)
		{
			leftPos = document.body.offsetWidth - inLayer.offsetWidth - 20;
			leftPos = (leftPos < 0 ? 0 : leftPos);
		}

		eval(layerRef + layerName + endLayerRef + styleRef + ".left = " + positionUnit(leftPos));
		eval(layerRef + layerName + endLayerRef + styleRef + ".top  = " + positionUnit(getTop(inPosition) + inPosition.offsetHeight));
//		eval(layerRef + layerName + endLayerRef + styleRef + ".top  = " + (inPosition.offsetTop + inPosition.offsetHeight));

		//if (IE) {
		//	fadeUp(layerName,finalOpacity - 90);
		//}
		//eval(layerRef + layerName + endLayerRef + styleRef + ".filter = 'alpha(opacity=" + finalOpacity + ")'");
	}
}

function fadeUp(layerName,op)
{
	if(op < finalOpacity)	{
		newOp = op + 45
		eval(layerRef + layerName + endLayerRef + styleRef + ".filter = 'alpha(opacity=" + newOp + ")'");
	}
	else	{
		eval(layerRef + layerName + endLayerRef + styleRef + ".filter = 'alpha(opacity=" + finalOpacity + ")'");
		return;
	}
	// wait a bit, then call this function again
	setTimeout("fadeUp('" + layerName + "'," + newOp + ")",1);
}

function hideCancel() {
	cancelHide = true;
}
function hideMenuById(layerName, curDelay)
{
    return hideMenu(document.getElementById(layerName), curDelay);
}
function hideMenu(inLayer, curDelay)
{
	var layerName = inLayer.id;
	if (!cancelHide) {
		if (curDelay <= 0) {		//= menuDelay) {
			eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'hidden'");
		    eval(layerRef + layerName + endLayerRef + styleRef + ".display = 'none'");
			if (layerName == pendingHide) pendingHide = "";
			oldLayer = 'none';
			menuOut=0;
			return;
		}
		else
		{
			newDelay = curDelay - 1;		
			pendingHide = layerName;
			setTimeout("hideMenuById(\'" + layerName + "\'," + newDelay +")",1);	
		}
	}				
}
function hideMenuParent(inElement) {
	var item = inElement;
	while ( item.tagName != 'BODY' ) {
		if (item.tagName == 'DIV' ) { hideMenu(item, 0); return; }
		item = (IE ? item.parentElement : item.parentNode);
	}
}
function hideMenuNow(inLayer)
{
	var layerName = inLayer.id;
	eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'hidden'");
	eval(layerRef + layerName + endLayerRef + styleRef + ".display = 'none'");
	oldLayer = 'none';				
	menuOut = 0;
}
function hideMenus()
{
	eval(layerRef + 'menu_engine' + endLayerRef + styleRef + ".visibility = 'hidden'");
	oldLayer = 'none';				
	menuOut=0;
}
function hideMenusDelay(curDelay)
{
if (menuOut=1){
	if (curDelay == menuDelay) {
		eval(layerRef + 'menu_engine' + endLayerRef + styleRef + ".visibility = 'hidden'");
		oldLayer = 'none'; menuOut=0; return;
	}
	else {
		newDelay = curDelay + 1;		
		setTimeout("hideMenusDelay(" + newDelay +")",1);
	}
}
else {
	return;
}
				
}
function getLayerHeight(layerName)
{
	// find layer height
	if(N4) {
		height = eval(layerRef + layerName + endLayerRef + ".clip.height");
	}
	else {
		height = eval(layerRef + layerName + endLayerRef + ".offsetHeight");
	}
	startPos = initialTop - height + 20; 	//alert(startPos);
	return;	
}

function getTop(inItem)
{
	var result  = inItem.offsetTop;
	/*
	var enumItm = (IE ? inItem.parentElement : inItem.parentNode);
	while (enumItm) {
		if(enumItm.tagName) {
			if (enumItm.tagName == "DIV") {	result += enumItm.offsetTop; }
		}
		enumItm = (IE ? enumItm.parentElement : enumItm.parentNode);
	}
	*/
	var enumItm = inItem.offsetParent;
	while (enumItm) {
		if(enumItm.tagName) {
			if (enumItm.tagName == "DIV") {	result += enumItm.offsetTop; }
		}
		enumItm = enumItm.offsetParent;
	}	
	return result;	
}
function getLeft(inItem)
{
	var result  = inItem.offsetLeft;
	/*
	var enumItm = (IE ? inItem.parentElement : inItem.parentNode);	
	while (enumItm) {
		if(enumItm.tagName) {
			if (enumItm.tagName == "DIV") result += enumItm.offsetLeft;
		}
		enumItm = (IE ? enumItm.parentElement : enumItm.parentNode);
	}
	*/	
	var enumItm = inItem.offsetParent;
	while (enumItm) {
		if(enumItm.tagName) {
			if (enumItm.tagName == "DIV") {	result += enumItm.offsetLeft; }
		}
		enumItm = enumItm.offsetParent;
	}	
	return result;	
}
		
				
function moveLayerDown(layerName,height,startPos)
{
	newTopDown = startPos
	endTopDown = initialTop;
	//alert(layerName + ", " + newTopDown);
	
	if(newTopDown <= endTopDown)
	{
		// move layer again
		newTopDown = newTopDown + 8;
		//work out if gone too far!
		if(newTopDown >= endTopDown)
		{
			newTopDown=endTopDown		
			eval(layerRef + layerName + endLayerRef + styleRef + ".top = " + positionUnit(newTopDown));
			// reset global variable in preparation for the next menu
			newTopDown = initialTop;
			return;
		}
		else
		{
		eval(layerRef + layerName + endLayerRef + styleRef + ".top = " + positionUnit(newTopDown));
		//eval(layerRef + layerName + endLayerRef + ".offsetHeight = " + newHeight);
		}
	}
	else
	{
		// reset global variable in preparation for the next menu
		newTopDown = initialTop;
		return;
	}

	// wait a bit, then call this function again
	setTimeout("moveLayerDown('" + layerName + "'," + height + "," + newTopDown +")",1);
}

function moveLayerUp(layerName,height)
{
	endTopUp = initialTop - height + 20;
	//alert(layerName + ", " + newTopUp);
	
	if(newTopUp >= endTopUp)
	{
		// move layer again
		newTopUp = newTopUp - 10;
		//work out if gone too far!
		if(newTopUp <= endTopUp)
		{
			newTopUp=endTopUp		
			eval(layerRef + layerName + endLayerRef + styleRef + ".top = " + positionUnit(newTopUp));
			eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'hidden'");
			eval(layerRef + layerName + "_top" + endLayerRef + styleRef + ".visibility = 'visible'");
			newTopUp = initialTop;
			return;
		}
		else
		{
		eval(layerRef + layerName + endLayerRef + styleRef + ".top = " + positionUnit(newTopUp));
		//eval(layerRef + layerName + endLayerRef + ".offsetHeight = " + newHeight);
		}
	}
	else
	{
		// reset global variable in preparation for the next menu
		eval(layerRef + layerName + endLayerRef + styleRef + ".visibility = 'hidden'");
		eval(layerRef + layerName + "_top" + endLayerRef + styleRef + ".visibility = 'visible'");
		newTopUp = initialTop;
		return;
	}

	// wait a bit, then call this function again
	setTimeout("moveLayerUp('" + layerName + "'," + height + ")",1);
}


function getParent(inElement) {
	return (IE ? inElement.parentElement : inElement.parentNode);
}

function getParentTAG(inElement, inTag) {
	var item = inElement;
	while ( item.tagName != 'BODY' ) {
		if (item.tagName == inTag ) { return item; }
		item = (IE ? item.parentElement : item.parentNode);
	}
	return null;
}


var checktime_alert = true;

function checktime(objName) {
 var datefield = objName;
 if (chktime(objName) == false) {
	if (checktime_alert) {
		datefield.select();
		alert("That time is invalid.  Please try again.");
		datefield.focus();
		checktime_alert = false;
	}
	return false;
 }
 else {
	// checktime_alert = true;
	return true;
 }
}

function chktime(datefield) 
{
	var strDate = '' + datefield.value;
	if (strDate.length < 1) return true;
	var myDate = ParseTime(strDate);
	if (myDate) datefield.value = FormatMediumTime(myDate);
	return (myDate ? true : false);
}

function ParseTime(inStringToParse)
{
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strMin = '0'; var intMin = 0;
	var strHrs = '0'; var intHrs = 0;
	var strSec = '0'; var intSec = 0;
	
	var booFound = false;
	var strSeparatorArray = new Array(" ",".",";");
	var strDateArray = null;
	var err = 0;

	var strDate = '' + inStringToParse;
	if (strDate.length < 1) return null;
	
	for (var intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		while (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDate = strDate.replace(strSeparatorArray[intElementNr], ':');
		}
	}
	strDateArray = strDate.split(':');
	if (strDateArray == null) return null;
	if (strDateArray.length < 1) return null;
	if (strDateArray.length > 3) return null;
	if (strDateArray.length > 0) strHrs = strDateArray[0];
	if (strDateArray.length > 1) strMin = strDateArray[1];
	if (strDateArray.length > 2) strSec = strDateArray[2];
	
	intHrs = parseInt(strHrs, 10);
	intMin = parseInt(strMin, 10);
	intSec = parseInt(strSec, 10);
	
	if (isNaN(intHrs)) return null;
	if (isNaN(intMin)) return null;
	if (isNaN(intSec)) return null;
	
	var finalDate = new Date(2000,1,1,intHrs,intMin,intSec);
	return finalDate;
}
function FormatMediumTime(inDateVal)
{
	var strHrs = ''; var strMin = ''; var strSec = '';
	if (inDateVal.getHours() < 10)		strHrs = '0' + inDateVal.getHours();
	else								strHrs = ''  + inDateVal.getHours();
	if (inDateVal.getMinutes() < 10)	strMin = '0' + inDateVal.getMinutes();
	else								strMin = ''  + inDateVal.getMinutes();
	if (inDateVal.getSeconds() < 10)	strSec = '0' + inDateVal.getSeconds();
	else								strSec = ''  + inDateVal.getSeconds();	
	if (inDateVal.getSeconds() > 0)		return strHrs + ":" + strMin + ":" + strSec;
	else								return strHrs + ":" + strMin;
}


/*****
<!-- Original:  Mike Welagen (welagenm@hotmail.com) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
**/
var checkdate_alert = true;

function checkdate(objName) {
 var datefield = objName;
 if (chkdate(objName) == false) {
	if (checkdate_alert) {
		datefield.select();
		alert("That date is invalid.  Please try again.");
		datefield.focus();
		checkdate_alert = false;
	}
	return false;
 }
 else {
	// checkdate_alert = true;
	return true;
 }
}

function chkdate(datefield) 
{
	var strDate = '' + datefield.value;
	if (strDate.length < 1) return true;
	var myDate = ParseDate(strDate);
	if (myDate) datefield.value = FormatMediumDate(myDate);
	return (myDate ? true : false);
}

function ParseDate(inStringToParse)
{
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	strDate = '' + inStringToParse;
	if (strDate.length < 1) {
	return null;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
	strDateArray = strDate.split(strSeparatorArray[intElementNr]);
	if (!strDateArray) return null;
	if (strDateArray.length == 2) {
	var curdate = new Date();
	var year = curdate.getFullYear();
	strDateArray[2] = '' + year;
	}
	if (strDateArray.length != 3) {
	err = 1; return null;
	}
	else {
	strDay = strDateArray[0];
	strMonth = strDateArray[1];
	strYear = strDateArray[2];
	}
	booFound = true;
	   }
	}
	if (booFound == false) {
	if (strDate.length>5) {
	strDay = strDate.substr(0, 2);
	strMonth = strDate.substr(2, 2);
	strYear = strDate.substr(4);
	   }
	}
	if (!strYear)			 { strYear = '' + year; }
	if (strYear.length == 1) { strYear = '200' + strYear; }
	if (strYear.length == 2) { strYear = '20' + strYear; }
	// US style
	if (strDatestyle == "US") {
	strTemp = strDay; strDay = strMonth; strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
	err = 2; return null;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
		if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
			intMonth = i+1;
			strMonth = strMonthArray[i];
			i = 12;
		}
	}
	if (isNaN(intMonth)) { err = 3; return null; }
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) { err = 4; return null; }
	if (intMonth>12 || intMonth<1) { err = 5; return null; }
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6; return null;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7; return null;
	}
	if (intMonth == 2) {
		if (intday < 1) { err = 8; return null; }
		if (LeapYear(intYear) == true) {
			if (intday > 29) { err = 9; return null; }
		}
		else {
			if (intday > 28) { err = 10; return null; }
		}
	}
	var finalDate = new Date(intYear, intMonth-1, intday);
	return finalDate;
}
function FormatMediumDate(inDateVal)
{
	var strDay = '';
	var strMonthArray = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	if (inDateVal.getDate() < 10) strDay = '0' + inDateVal.getDate();
	else						  strDay = ''  + inDateVal.getDate();
	return strDay + "-" + strMonthArray[inDateVal.getMonth()] + "-" + inDateVal.getFullYear();
	 

}


function LeapYear(intYear) {
	if (intYear % 100 == 0) { if (intYear % 400 == 0) { return true; } }
	else { if ((intYear % 4) == 0) { return true; } }
	return false;
}
function doDateCheck(from, to) {
	if (Date.parse(from.value) <= Date.parse(to.value)) 
	{
		alert("The dates are valid.");
	}
	else {
		if (from.value == "" || to.value == "") 
		alert("Both dates must be entered.");
		else 
		alert("To date must occur after the from date.");
   }
}


function buildCal(m, y, cM, cH, cDW, cD, cDo, brdr, dateSelected)
{
	var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

	var dateVariable = new Date(y, m-1, 1); 	
	var monthStart   = new Date(y, m-1, 1); 	
	dateVariable.od  = (dateVariable.getDay()?dateVariable.getDay():7);
	
	var todaydate	 = new Date() 

	dim[1]=(LeapYear(dateVariable.getFullYear()) ? 29 : 28);
	
	var lastMonthMax = 	(m < 2 ? dim[11] : dim[m-2]);
	
	var t='<table class="'+cM+'" cols="7" cellpadding="0" cellspacing="0" border="'+brdr+'"  width="100%" height="100%"><tr align="center">';
	
	t+='<td class="'+cH+'"><A class="'+cH+'Link" href="javascript:calMove(-1);">&lt;</a></td>';
	t+='<td colspan="5" align="center" class="'+cH+'"><A class="'+cH+'Link" href="javascript:calClose();" style="WIDTH: 120px">'+mn[m-1]+' - '+y+'</a></td>';
	t+='<td class="'+cH+'"><A class="'+cH+'Link" href="javascript:calMove(+1);">&gt;</a></td>';
	t+='</tr><tr align="center">';
	
	for(var s=0;s<7;s++)t+='<td class="'+cDW+'">'+"MTWTFSS".substr(s,1)+'</td>';
	
	t+='</tr><tr align="center">';
	
	for(var i = 1; i <= 42; i++)
	{
		var inMonth; var inYear; var inDay;
		
		if (i < dateVariable.od) {				
			inDay   = 1 + lastMonthMax - dateVariable.od + i;
			inMonth = (m<2?  12: m-1);
			inYear  = (m<2? y-1: y);
		}
		else if ((i-dateVariable.od) >= dim[m-1]) {
			inDay   = 1 + (i-dateVariable.od) - dim[m-1];
			inMonth = (m>11?   1: m+1);
			inYear  = (m>11? y+1: y);
		}
		else {
			inDay	= 1 + i - dateVariable.od;
			inMonth = m;
			inYear	= y;
		}

		if (inDay == dateSelected.getDate() && inMonth == dateSelected.getMonth()+1 && inYear == dateSelected.getFullYear()) 
		{
			inTxt = '<a class="'+cD+'" id="Select" href="javascript:calClick('+inYear+','+inMonth+','+inDay+');" >'+inDay+'</a>';
		}
		else if (inDay == todaydate.getDate() && inMonth == todaydate.getMonth()+1 && inYear == todaydate.getFullYear()) 
		{
			inTxt = '<a class="'+cD+'" id="Today" href="javascript:calClick('+inYear+','+inMonth+','+inDay+');" >'+inDay+'</a>';
		}
		else
		{
			inTxt = '<a class="'+(inMonth == m?cD:cDo)+'" href="javascript:calClick('+inYear+','+inMonth+','+inDay+');">'+inDay+'</a>';
		}
		if(i%7==0||i%7==6)
			t += '<td bgcolor="#FFFFbb">'+inTxt+'</td>';
		else
			t += '<td>'+inTxt+'</td>';
		
		if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
	}
	return t+='</tr></table>';
}

function selectListItem(inList, inValue)
{
	var pattern = String(inValue).toLowerCase();
	for (var i = 0; i < inList.options.length; ++i)
	{	  
		if (inList.options[i].value.toLowerCase() == pattern)
		{
			inList.selectedIndex = i;
		}
	}
}
function getInnerText(obj) { 
	return (obj.innerText) ? obj.innerText : (obj.textContent) ? obj.textContent : ""; 
} 
function setInnerText(obj, inValue) { 
	if (obj.innerText) obj.innerText = inValue;
	else if (obj.textContent) obj.textContent = inValue; 
	return obj;
}
function setInnerTextById(objName, inValue) { 
	var obj = document.getElementById(objName)
	if (obj) setInnerText(obj, inValue) 
	return obj;
}
function setInnerHtml(obj, inValue) { 
	obj.innerHTML = inValue;
	return obj;
}
function setInnerHtmlById(objName, inValue) { 
	var obj = document.getElementById(objName)
	if (obj) setInnerHtml(obj, inValue) 
	return obj;
}
function FormatNumber(expr, decplaces) 
{
	var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
	while (str.length <= decplaces) {	str = "0" + str;	}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
} 
function FormatMoney(expr, decplaces) 
{	
//	var neg = eval(expr) < 0; var val = Math.abs(eval(expr));
//	return (neg ? "-$" : "$") + FormatNumber(val, 2);
	var neg = (eval(expr) < 0 ? true : false);
	var str = "" + Math.abs(Math.round(eval(expr) * Math.pow(10,decplaces)));
	while (str.length <= decplaces) {	str = "0" + str;	}
	var revstr = strRev(str);
	if (revstr.length > 8)		revstr = strInsertAt(8, revstr, ',');
	if (revstr.length > 5)		revstr = strInsertAt(5, revstr, ',');		
	if (decplaces)				revstr = strInsertAt(decplaces, revstr, '.');
	return ( neg ? '-$'+strRev(revstr)+'' : '$'+strRev(revstr));		
} 
function strRev(str) {
   if (!str) return '';   
   var revstr='';  
   for (i = str.length-1; i>=0; i--)    revstr+=str.charAt(i);
   return revstr;
}
function strInsertAt(inPos, inString, inInsert)
{
	return 	inString.substring(0, inPos) + inInsert + inString.substring(inPos);
}

function URLEncode(inValue)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = inValue;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(inValue)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = inValue;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};


function cleanString(inValue, inAllowed)
{
	var result = new String("");
	var encoded = new String(inValue);
	for (var i = 0; i < encoded.length; ++i) 
	{
	   var ch = encoded.charAt(i);
	   if (inAllowed.indexOf(ch) >= 0) 
	   {
		   result += ch;
	   } 
	}
	return result;
}

function toFloat(inValue)
{
	var cleaned = cleanString(inValue, "-123456789.0");
	return parseFloat(cleaned);
}

/* start:drag and drop functions */
var srcValid = false;
var startId	 = 0;
var finishId = 0;
function startDrag(numb){ var dragData = window.event.dataTransfer;
    dragData.effectAllowed = 'linkMove'; dragData.dropEffect = 'move';
    startId  = numb; srcValid = true;
}
function enterDrag() { window.event.dataTransfer.getData('Text'); }
function endDrag() { window.event.dataTransfer.clearData(); srcValid = false; }
function overDrag() { window.event.returnValue = false; }
function overDrop(objImg) {}
function leaveDrag(objImg) {}
function drop(lttr) { window.event.returnValue = false; if ( srcValid ) { 
 finishId = lttr; window.location = '?drag_from=' + startId + '&drag_dest=' + lttr
 }
}
/* finish:drag and drop functions */

function getFrameById(inId) {
	var a = document.getElementsByTagName("iframe");
	for (var i = 0; i < a.length; ++i) {
		var item = a[i];
		if (item.id == inId) 
			return item;
	}
	return null;
}
function setFrameLocation(inId, inUrl) {
	var f = getFrameById(inId);
	if (f.location) { f.location = inUrl;	return; }
	if (f.src)		{ f.src = inUrl;		return; }
}
