function copyToList(from,to)
{
  fromList = eval('document.forms[0].' + from);
  toList = eval('document.forms[0].' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp')
  {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];
    if (current.selected)
    {
      sel = true;
      if (current.value == 'temp')
      {
        alert ('You cannot move this text!');
        return;
      }
      txt = current.text;
      val = current.value;
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any options!');
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}	

function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { 
		return true; 
	}
		return false;
}

function addOption(selectObject,optionText,optionValue) { 
	var optionObject = new Option(optionText,optionValue); 
	var optionRank = selectObject.options.length; 
	selectObject.options[optionRank]=optionObject; 
} 
  	
function deleteOption(selectObject,optionRank) {
	if (selectObject.options.length!=0) { selectObject.options[optionRank]=null }
}
		
function ExpandCollapse(divID) { 
	var displayValue = document.getElementById(divID).style.display;   		
	if (displayValue == "none"){
			document.getElementById(divID).style.display = "";
	} 
	else {
			document.getElementById(divID).style.display = "none";	
	}
}

function run_xajax(elementID, oldValue, xajax_command) {
	
	var currentValue = document.getElementById(elementID).value;
	
	if(currentValue == oldValue) { 
		eval(xajax_command);
	}
}

function stable_b4_xajax(elementID, delayTime, xajax_command) {
	
	var currentValue = document.getElementById(elementID).value;
	
	setTimeout("run_xajax('" + elementID + "', '" + currentValue + "', '" + xajax_command + "')", delayTime);
}

// SUBTRACT HOUR FROM TIME IN TIME FIELD
function timeSubtractHour(elementID) {
	var timeBox = document.getElementById(elementID);
	var time = timeBox.value;
	var hour;
	var minute;
	var ampm;
	if (time == '') {
		timeBox.value = '12:00 AM';
	}
	else {
		hour = time.substr(0,time.indexOf(':'));
		minute = time.substr(time.indexOf(':')+1,2);
		ampm = time.substr(time.indexOf(' ')+1,2);
		if (hour != 1) {
			if (hour == 12) {
				if (ampm == 'AM') {
					ampm = 'PM';
				}
				else {
					ampm = 'AM';
				}
			}
			hour--;
		}
		else {
			hour = 12;					
		}
		time = hour + ':' + minute + ' ' + ampm;
		timeBox.value = time;
	}
}
	
// SUBTRACT FIVE MINUTES FROM TIME IN TIME FIELD
function timeSubtractMinute(elementID) {
	var timeBox = document.getElementById(elementID);
	var time = timeBox.value;
	var hour;
	var minute;
	var ampm;
	if (time == '') {
		timeBox.value = '12:00 AM';
	}
	else {
		hour = time.substr(0,time.indexOf(':'));
		minute = time.substr(time.indexOf(':')+1,2);
		ampm = time.substr(time.indexOf(' ')+1,2);
		if (minute != '00') {
			minute-=5;
		}
		else {
			minute = '55';				
		}
		if (String(minute).length == 1) { minute = '0' + minute; }
		time = hour + ':' + minute + ' ' + ampm;
		timeBox.value = time;
	}
}

// ADD FIVE MINUTES TO TIME IN TIME FIELD
function timeAddMinute(elementID) {
	var timeBox = document.getElementById(elementID);
	var time = timeBox.value;
	var hour;
	var minute;
	var ampm;
	if (time == '') {
		timeBox.value = '12:00 AM';
	}
	else {
		hour = time.substr(0,time.indexOf(':'));
		minute = time.substr(time.indexOf(':')+1,2);
		ampm = time.substr(time.indexOf(' ')+1,2);
		if (minute != '55') {
			var minutenum = Number(minute) + 5;
			minute = minutenum
		}
		else {
			minute = '00';				
		}
		if (String(minute).length == 1) { minute = '0' + minute; }
		time = hour + ':' + minute + ' ' + ampm;
		timeBox.value = time;
	}
}

// ADD HOUR TO TIME IN TIME FIELD
function timeAddHour(elementID) {
	var timeBox = document.getElementById(elementID);
	var time = timeBox.value;
	var hour;
	var minute;
	var ampm;
	if (time == '') {
		timeBox.value = '12:00 AM';
	}
	else {
		hour = time.substr(0,time.indexOf(':'));
		minute = time.substr(time.indexOf(':')+1,2);
		ampm = time.substr(time.indexOf(' ')+1,2);
		if (hour != 12) {
			hour++;
			if (hour == 12) {
				if (ampm == 'AM') {
					ampm = 'PM';
				}
				else {
					ampm = 'AM';
				}
			}
		}
		else {
			hour = 1;					
		}
		time = hour + ':' + minute + ' ' + ampm;
		timeBox.value = time;
	}
}

function checkMoney(elementID) {
	var result = true;
	var money = document.getElementById(elementID);
	var moneyPattern = /(^\d*$)/;
	if (trim(money.value) != '') {
		var match = money.value.match(moneyPattern);
		if (match == null) {
			money.focus();
			alert('Incorrect Cost Format!  Please enter value in whole US Dollars.')
			result = false;
		}
	}		
	return result;	
}