var load_callback=false;
function LoadUrl(url,div_id)
{
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport)
		{
			$(div_id).innerHTML=transport.responseText;
			if(load_callback)
			{
				eval(load_callback);
				load_callback=false;
			}
		},
		onFailure: function(transport)
		{
			alert('Communication Error: '+transport.responseText);
		}

	});
}

function GetChildCombo(ParentSelect,ChildSelect,AllValuesChild,SelChildValue)
{
	parent_value=$F(ParentSelect);
	var child_obj=$(ChildSelect);
	var all_child_obj=$(AllValuesChild);
	k=child_obj.options.length-1;
	for(i=0;i<k;i++)
	{
		child_obj.options[child_obj.options.length - 1] = null;
	}
	for(i=0;i<all_child_obj.options.length;i++)
	{
		Element.extend(all_child_obj.options[i]);
		if(all_child_obj.options[i].readAttribute('class')==parent_value)
		{
			index=child_obj.options.length;

			child_obj.options[index]=new Option('');
			child_obj.options[index].value=all_child_obj.options[i].value;
			child_obj.options[index].text=all_child_obj.options[i].text;
			if(SelChildValue==all_child_obj.options[i].value)
			{
				child_obj.options[index].selected=true;
			}
		}
	}
}

function ShowSmallWindow(src, width, height)
{
	window.open(src, "message","toolbar=0,scrollbars=1,resizable=1,width="+width+",height="+height+",Left=100,Top=50");
}

function SelectCalendarDay(obj)
{
	Element.extend(obj);
	obj.addClassName('calendar-day-over');
}

function UnSelectCalendarDay(obj)
{
	Element.extend(obj);
	obj.removeClassName('calendar-day-over');
}

function SelectCalendarDaySa(obj)
{
	Element.extend(obj);
	obj.addClassName('calendar-day-7-over');
}

function UnSelectCalendarDaySa(obj)
{
	Element.extend(obj);
	obj.removeClassName('calendar-day-7-over');
}

function hideSelect(id)
{
	if (Prototype.Browser.IE) {
		id = id ==  null ? "" : "#" + id + " ";
		$$(id + 'select').each(function(element) {
			element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
			element.style.visibility = "hidden";
		});
	}
}

function showSelect(id)
{
	if (Prototype.Browser.IE) {
		id = id ==  null ? "" : "#" + id + " ";
		$$(id + 'select').each(function(element) {
			if (isDefined(element.oldVisibility)) {
				// Why?? Ask IE
				try {
					element.style.visibility = element.oldVisibility;
				} catch(e) {
					element.style.visibility = "visible";
				}
				element.oldVisibility = null;
			}
			else {
				if (element.style.visibility)
				element.style.visibility = "visible";
			}
		});
	}
}

function isDefined(object)
{
	return typeof(object) != "undefined" && object != null;
}

function parseAmericanDate(string) {
  // Test these with and without the time
  // 11/11/1111 12pm
  // 11/11/1111 1pm
  // 1/11/1111 10:10pm
  // 11/1/1111 01pm
  // 1/1/1111 01:11pm
  // 1/1/1111 1:11pm
  var regexp = "(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4}) *([0-9]{1,2}(:[0-9]{2})? *(am|pm))?";
  var d = string.match(new RegExp(regexp, "i"));
  if (d==null) {
    return Date.parse(string); // Give javascript a chance to parse it.
  }

  mdy = d[1].split('/');
  hrs = 0;
  mts = 0;
  if(d[3] != null) {
    hrs = parseInt(d[3].split('')[0], 10);
    if(d[5].toLowerCase() == 'pm') { hrs += 12; } // Add 12 more to hrs
    mts = d[4].split(':')[1];
  }
//  return new Date(mdy[2], parseInt(mdy[0], 10)-1, mdy[1], hrs, mts, 0);
  return mdy[2]+'-'+(parseInt(mdy[0], 10))+'-'+mdy[1];
}

function toAmericanDate(date_value,include_time){
  str = Date.padded2(date_value.getMonth() + 1) + '/' +Date.padded2(date_value.getDate()) + '/' + date_value.getFullYear();

  if (include_time) { hour=date_value.getHours(); str += " " + date_value.getAMPMHour() + ":" + date_value.getPaddedMinutes() + " " + date_value.getAMPM() }
  return str;
}


function toISODate(date_value,include_time) {
	var hour;	
    var str = date_value.getFullYear() + "-" + Date.padded2(date_value.getMonth() + 1) + "-" +Date.padded2(date_value.getDate());
    if (include_time) {
        hour = date_value.getHours();
        str += " " + date_value.getHours() + ":" + date_value.getPaddedMinutes();
    }
    return str;
};