// ----------------------------------------------------------------------------
//------ Global Variables
	
	var global_selected = false;
	var calendar_created = false;
	var calendar_1 = null;

// ----------------------------------------------------------------------------
	function check_calendar()
	{
		if(calendar_created)
			return;
		
		calendar_1 = new CalendarPopup("calendar_div");
		calendar_1.showNavigationDropdowns();	
		calendar_created = true;
	}
// ----------------------------------------------------------------------------
	function clearElement(txt)
	{
		if(!txt)
			return;
			
		txt.value = "";
	}
// ----------------------------------------------------------------------------
	function clearDate(date_prefix)
	{
		var dt = getElement(date_prefix + "_month");
		
		if(!dt)
			return;
		
		dt.value = "";
		dt.focus();
		
		dt = getElement(date_prefix + "_day");
		dt.value = "";
			
		dt = getElement(date_prefix + "_year");
		dt.value = "";
	}
// ----------------------------------------------------------------------------
	function dms(link, requestor, txt)
	{
		var str = link + '?r=' + requestor;
		str += '&cv=' + txt.value;
		jwindow(str);
	}
// ----------------------------------------------------------------------------
	function empty(value)
	{
		if(!value || value == null || trim(value).length < 1)
			return true;
		else
			return false;
	}
// ----------------------------------------------------------------------------
	function endswith(value, search)
	{
		var total = len(value);
		var total2 = len(search);
		var start = total - total2;
		var temp = 	value.substr(start, total);
		
		return trim(lower(temp)) == trim(lower(search));
	}
// ----------------------------------------------------------------------------
	function error(message)
	{
		alert(message);
		return false;
	}
// ----------------------------------------------------------------------------
	function getCheckboxValues(chk)
	{
		if(!chk)
			return "";
			
		var total = chk.length;
		var str = "";
		
		if(total == null && chk.checked)
			return chk.value;
		else
		{
			var count = 0;
			
			for(var i = 0; i < total; i++)
			{
				if(chk[i].checked)
				{
					if(count > 0)
						str += ",";
					
					str += chk[i].value;
					
					count++;
				}
			}
		}
		
		return str;
	}		
// ----------------------------------------------------------------------------
	function getElement(name)
	{
		var frm = document.frmMain;
		return eval("frm." + name);
	}
// ----------------------------------------------------------------------------
	function getElementByIndex(name, index)
	{
		var frm = document.frmMain;
		
		var obj = eval("frm." + name);
		
		if(!obj)
		{
			error("Invalid GetElement By Index Element");
			return null;
		}
		
		if(obj.length == null)
			return obj;
		else
			return eval("frm." + name + "[" + index + "]");
	}	
// ----------------------------------------------------------------------------	
	function getInteger(txt)
	{
		if(!txt)
		{
			error("Invalid GetInteger Element");
			return 0;
		}
		
		if(!numeric(txt.value))
			return 0;
		else
		{
			var val = trim(txt.value);
			var len = len(val);
			
			if(len > 1)
				if(val.charAt(0) == "0")
					val = val.substr(1);
			
			return parseInt(trim(val));
		}
	}	
// ----------------------------------------------------------------------------
	function getNumber(txt)
	{
		if(!txt)
		{
			error("Invalid Get Number Element");
			return 0;
		}
				
		if(!numeric(txt.value))
			return 0;
		else
		{
			var fv = replaceChar(txt.value,"$","");
			fv = replaceChar(fv,",","");			
			return parseFloat(trim(fv));
		}
	}	
// ----------------------------------------------------------------------------
	function getRadioButtonValue(rb)
	{
		if(!rb)
		{
			error("Invalid GetRadioButtonValue Object");
			return "";
		}
		
		var total = rb.length;
		
		if(total == null)
			return rb.value;
		else
		{
			for(var i = 0; i < total; i++)
				if(rb[i].checked)
					return rb[i].value;
		}
		
		return "";
	}	
// ----------------------------------------------------------------------------
	function getSelectboxText(sel)
	{
		if(!sel)
		{
			error("Invalid GetSelectBoxText Object");
			return "";
		}
			
		var total = sel.options.length;
		
		if(total == null)
			return "";
		else if(!is_selectbox_selected(sel))
			return "";
		else					
			return sel.options[sel.selectedIndex].text;
	}		
// ----------------------------------------------------------------------------
	function getSelectboxValue(sel)
	{
		if(!sel)
		{
			error("Invalid GetSelectBoxValue Object");
			return "";
		}
			
		var total = sel.options.length;
		
		if(total == null)
			return "";
		else if(!is_selectbox_selected(sel))
			return "";
		else					
			return sel.options[sel.selectedIndex].value;
	}	
// ----------------------------------------------------------------------------
	function getSelectboxValues(sel, start)
	{
		if(!sel)
		{
			error("Invalid GetSelectBoxValues Object");
			return "";
		}
			
		var total = sel.options.length;
		
		if(total == null)
			return "";
		
		if(!start)
			start = 0;
		
		var str = "";
		
		for(var i = start; i < total; i++)
		{
			if(i > 0)
				str += ",";
				
			str += sel.options[i].value;
		}
		
		return str;
	}	
// ----------------------------------------------------------------------------	
	function getTextboxValues(txt)
	{
		if(!txt)
		{
			alert("Invalid GetTextBoxValues Object");
			return "";
		}
			
		var total = txt.length;
		
		var str = "";
		var count = 0;
		var temp = "";
		
		if(total == null)
			return txt.value;
		else
		{
			for(var i = 0; i < total; i++)
			{
				if(count > 0)
					str += ",";
				
				temp = txt[cc_count].value;
				
				if(empty(temp))
					temp = 'null';
				
				str += temp;
				
				count++;
			}
		}
		
		return str;
	}	
// ----------------------------------------------------------------------------	
	function hideDiv(div_name)
	{
		if(document.all)
			document.all[div_name].style.display = 'none';
		else
		{
			var el = document.getElementById(div_name);
			el.style.display = 'none';
		}
	}	
// ----------------------------------------------------------------------------		
	function invalidate_form()
	{
		if(document.frmMain.c9xSubmitted)
			document.frmMain.c9xSubmitted.value = "false";
	}	
// ----------------------------------------------------------------------------
	function is_a_checkbox_checked(chk)
	{
			if(!chk)
			{
				error("Invalid Is A CheckBox Checked Object");
				return false;
			}
				
			var total = chk.length;
			
			if(total == null)
				return chk.checked;
			else
			{
				for(var i = 0; i < total; i++)
					if(chk[i].checked)
						return true;
			}
			
			return false;
	}
// ----------------------------------------------------------------------------
	function is_selectbox_selected(sel)
	{
		if(!sel)
		{
			error("Invalid Is A Selectbox Selected Object");
			return false;
		}
			
		var total = sel.options.length;
		
		if(total == null)
			return false;
	
		return (sel.selectedIndex > -1);
	}
// ----------------------------------------------------------------------------
	function jwindow(url, width, height, resizable, address)
	{
		if(width == undefined)
			width = 640;
		if(height == undefined)
			height = 480;
		if(address == undefined)
			address = false;
		if(resizable == undefined)
			resizable = true;

		var d = new Date();
		var title = 'c9x_' + d.getHours() + "_" + d.getMinutes() + "_" + d.getSeconds();
		var params = 'scrollbars=yes';
		
		if(resizable)
			params += ',resizable=yes';
			
		if(address)
			params += ',location=yes';
		
		openCenteredWindow(url, width, height, title, params);
	}
// ----------------------------------------------------------------------------
	function left(value, total)
	{
		if(empty(value))
			return "";
		else
			return trim(value).substr(0, total);
	}		
// ----------------------------------------------------------------------------
	function last(value)
	{
		var l = len(value);
		
		if(l < 2)
			return 0;
		else
			return l - 1;
	}
// ----------------------------------------------------------------------------
	function len(value)
	{
		if(!value || value == null || value == "")
			return 0;
			
		var total = value.length;

		if(total == null)
			return 0;
		else
			return parseInt(total);
	}
// ----------------------------------------------------------------------------
	function lower(value)
	{
		if(value)
			return value.toLowerCase();
		else
			return "";
	}
// ----------------------------------------------------------------------------
	function ltrim(value)
	{
		if(!value || value == null || value == "")
			return "";
			
		var forward = "";
		var start = false;
		
		for(var i = 0; i < value.length; i++)
		{
			if(!start && value.charAt(i) == " ")
				continue;
			else if(!start && value.charAt(i) != " ")
			{
				start = true;
				forward += value.charAt(i);
			}
			else
				forward += value.charAt(i);
		}
		
		return forward;
	}	
// ----------------------------------------------------------------------------
	function mid(value, start, stop)
	{
		return value.substring(start, stop);	
	}
// ----------------------------------------------------------------------------
	function money(value)
	{
		value = trim(value);
		value = replaceChar(value, "$","");
		value = replaceChar(value, ",","");

		var neg = "";
		
		if(value.charAt(0) == "-")		
			neg = "-";
			
		value = replaceChar(value, "-", "");

		var suffix = "";
		var prefix = "";
		
		var index = value.indexOf(".");
		
		if(index > -1)
		{
			prefix = value.substring(0, index);
			suffix = value.substring(index + 1);
			suffix = left(suffix, 2);
		}
		else
		{
			prefix = trim(value);
			suffix = "";
		}
		
		if(!numeric(prefix))
		{
			prefix = "0";
			suffix = "0";
		}
		else if(!numeric(suffix))
			suffix = "0";

		if(len(suffix) == 1)
			suffix += "0";
			
		var str = "";
		var count = 0;
		var total = len(prefix);
		
		for(var i = total; i > -1 ; i--)
		{
			if(count == 4)
			{
				str += ",";
				count = 1;
			}	
			
			str += prefix.charAt(i);
			
			count++;
		}

		prefix = "";
		total = len(str);		
		
		for(var i = total; i > -1; i--)
			prefix += str.charAt(i);	

		return neg + "$" + prefix + "." + suffix;	
	}
// ----------------------------------------------------------------------------
	function money_element(fld)
	{
		fld.value = money(fld.value);
	}	
// ----------------------------------------------------------------------------
	function numeric(value)
	{
		if(empty(value))
			return false;
			
		value = trim(value);
		value = replaceChar(value, "$","");
		value = replaceChar(value, ",","");		
	
		var valid = "0123456789";
		var period_count = 0;
		var start = 0;
		
		if(value.charAt(0) == "-")
			start = 1;
		
		var ch = "";
		
		for(var i = start; i < len(value); i++)
		{
			ch = value.charAt(i);
			
			if(ch == ".")
			{
				period_count++;
				
				if(period_count > 1)
					return false;
			}		
			else if(valid.indexOf(ch) < 0)
				return false;
		}
	
		return true;	
	}	
// ----------------------------------------------------------------------------
	function openCenteredWindow(url, width, height, name, parms) 
	{
	   var left = Math.floor( (screen.width - width) / 2);
	   var top = Math.floor( (screen.height - height) / 2);
	   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	   if (parms) { winParms += "," + parms; }
	   var win = window.open(url, name, winParms);
	   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	   return win;
	}
// ----------------------------------------------------------------------------	
	function print_page()
	{
		var html = '<html><head><link href="shared/c9x.css" rel="stylesheet" type="text/css"></head><body>';
		var value = '';
		
		if(document.all)
			value = document.all['print_div'].innerHTML;
		else
			value = document.getElementById('print_div').innerHTML;			
		
		html += value;
		html += '</body></html>';
		
		var printWin = window.open("","c9x_print", "width=1,height=1,scrollbars=no,title=no");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();		
		printWin.print();
		printWin.close();
	}	
// ----------------------------------------------------------------------------
	function reload_page()
	{
		frm = document.frmMain;
		
		if(frm.command)
			frm.command.value = 0;
		
		invalidate_form();
		
		frm.submit();
	}
// ----------------------------------------------------------------------------
	function replaceChar(value, search, replace)	
	{
		if(empty(value))
			return "";
			
		var ret = "";
		var ch = "";
		
		for(var i = 0; i < len(value); i++)
		{
			ch = value.charAt(i);
			
			if(ch == search)
				ret += replace;
			else
				ret += ch;
		}
		
		return ret;
	}	
// ----------------------------------------------------------------------------
	function right(value, total)
	{
		if(empty(value))
			return "";
			
		value = trim(value);
		var count = len(value);
		var start = count - total;
		
		if(start > count)
			return "";
		else
			return value.substr(start, total);
	}			
// ----------------------------------------------------------------------------
	function rtrim(value)
	{
		if(!value || value == null || value == "")
			return "";
			
		var back = "";
		var start = false;
		
		for(var i = value.length - 1; i > -1; i--)
		{
			if(!start && value.charAt(i) == " ")
				continue;
			else if(!start && value.charAt(i) != " ")
			{
				start = true;
				back += value.charAt(i);
			}
			else
				back += value.charAt(i);
		}
		
		forward = "";
		
		for(var i = back.length - 1; i > - 1; i--)
			forward += back.charAt(i);
		
		return forward;
	}	
// ----------------------------------------------------------------------------
	function rowOver(row, color)
	{
		row.style.cursor = "hand";
		row.bgColor = color;
	}
// ----------------------------------------------------------------------------
	function rowOut(row, color)
	{
		row.style.cursor = "default";
		row.bgColor = color;
	}	
// ----------------------------------------------------------------------------
	function select_all_checkboxes(chk)
	{
		if(!chk)
			return;
			
		var total = chk.length;
		
		global_selected = !global_selected;
		
		if(total == null)
			chk.checked = global_selected;
		else
		{
			for(var i = 0; i < total; i++)
				chk[i].checked = global_selected;
		}
	}	
// ----------------------------------------------------------------------------
	function selectbox_add(sel, display, value)
	{
		if(!sel)
		{
			error("Invalid Selectbox Add Object");
			return;
		}
			
		var total = sel.options.length;
		
		if(total == null)
			return;
			
		sel.options[total] = new Option(display, value);
	}	
// ----------------------------------------------------------------------------
	function selectbox_clear(sel, all)
	{
		if(!sel)
		{
			error("Invalid Selectbox Clear Object");
			return;
		}
			
		if(!all)
			all = false;
			
		var total = sel.options.length;
		
		if(total == null)
			return;
		
		for(var i = total; i > -1; i--)
			sel.options[i] = null;
	}		
// ----------------------------------------------------------------------------
	function setDate(date_prefix, month, day, year)
	{
		var dt = element(date_prefix + "_month");
		
		if(!dt)
		{
			error("Invalid Set Date Object");
			return;
		}
		
		dt.value = month;
		dt.focus();
		
		dt = getElement(date_prefix + "_day");
		dt.value = day;
			
		dt = getElement(date_prefix + "_year");
		dt.value = year;
	}	
// ----------------------------------------------------------------------------
	function showDiv(div_name)
	{
		if(document.all)
			document.all[div_name].style.display = 'block';
		else
		{
			var el = document.getElementById(div_name);
			el.style.display = 'show';
		}
	}				
// ----------------------------------------------------------------------------
	function strip(value, total)
	{
		return mid(value, 0, len(value) - total);	
	}
// ----------------------------------------------------------------------------
	function trim(str)
	{
		var tv = ltrim(str);
		return rtrim(tv);
	}
// ----------------------------------------------------------------------------
	function update_time(h, m, pm, type)
	{
		if(type == 0)
		{
			h.value = '09';
			m.value = '00';
			pm.selectedIndex = 0;
		}
		else
		{
			h.value = '';
			m.value = '';
			pm.selectedIndex = 0;			
		}
	}	
// ----------------------------------------------------------------------------
	function valid_date(month_obj, day_obj, year_obj)
	{
		var m = getInteger(month_obj);
		var d = getInteger(day_obj);
		var y = getInteger(year_obj);
		
		 if(m == 0 || d == 0 || y == 0)
			return false;		
		else if(m < 1 || m > 12 || d < 1 || d > 31 || y < 1900 || y > 2999)
			return false;
		else if( (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)  && ( d > 31 )    )
			return false;
		else if( (m == 4 || m == 6 || m == 9 || m == 11)  && ( d > 30 )    )
			return false;			
		else if(m == 2 && d >= 30)
			return false;
		else
			return true;
	}
// ----------------------------------------------------------------------------
	function validate(txt, display)
	{
		if(!txt)
			return error("Invalid Validate Object");		
		else if(trim(txt.value) == "")
		{
			alert("Please enter a value for: " + display);
			txt.focus();
		}
		else
			return true;
			
		return false;	
	}
// ----------------------------------------------------------------------------		
	function validate_date(month_object, day_object, year_object, display_name)
	{
		if(!month_object)
			return error("Invalid Validate Date Object");		
		else if(!valid_date(month_object, day_object, year_object))
		{	
			alert("Please enter a valid date for: " + display_name);
			month_object.focus();
			return false;
		}
		
		return true;
	}
// ----------------------------------------------------------------------------		
	function validate_date_text(fld, display)
	{
		var value = trim(fld.value);
		
		if(empty(value))
		{
			alert("Please enter a valid date for: " + display + " (mm/dd/yyyy)");	
			fld.focus();	
			return false;
		}
		else if(len(value) < 8)
		{
			alert("Please enter a valid date for: " + display + " (mm/dd/yyyy)");	
			fld.focus();	
			return false;
		}
		
		if(len(value) == 8)
		{
			value = '0' + value;
			fld.value = value;
		}
		
		if(value.charAt(2) == "/" && value.charAt(5) == "/")
		{	
			value = replaceChar(value, "/","");

			if(numeric(value))
				return true;	
		}
		
		alert("Please enter a valid date for: " + display + " (mm/dd/yyyy)");
		
		fld.focus();		
		
		return false;
	}	
// ----------------------------------------------------------------------------	
	function validate_email(txt)
	{
		if(!txt)
			return error("Invalid Validate Email Element");
		else if(len(trim(txt.value)) < 3)
		{
			alert("Please enter a valid email address");
			txt.focus();
			return false;
		}
			
		var period_count = 0;
		var count = 0;
		var ch = "";
		
		for(var i = 0; i < len(txt.value); i++)
		{
			ch = txt.value.charAt(i);
			
			if(ch == "@")
				count++;
			else if(ch == ".")
				period_count++;
		}
		
		if(count == 1 && period_count > 0)
			return true;
		else
		{
			alert("Please enter a valid email address");
			txt.focus();		
			return false;
		}
	
	}
// ----------------------------------------------------------------------------
	function validate_min(txt, display, minimum)
	{
		if(!txt)
			return error("Invalid Validate Len Object");		
		else if(empty(txt.value))
		{
			alert("Please enter a value for: " + display);
			txt.focus();
		}
		else if( (parseInt(minimum) > 0) && (txt.value.length < parseInt(minimum))  )
		{
			alert(display + ":  must be at least " + minimum + " characters");
			txt.focus();
		}
		else
			return true;
				
			
		return false;	
	}	
// ----------------------------------------------------------------------------
	function validate_numeric(txt, display, force)
	{
		if(!force) force = false;
		
		if(!txt)
			return error("Invalid Validate Numeric Object");
		else if(!numeric(txt.value))
		{
			alert("Please enter a numeric value for: " + display);
			txt.focus();
		}
		else if(force && parseFloat(trim(txt.value)) <= 0)
		{
			alert("The value for: " + display + " must be greater than zero");
			txt.focus();
		}
		else
			return true;
			
		return false;	
	}	
// ----------------------------------------------------------------------------
	function validate_max(txt, display, maximum)
	{
		if(!txt)
			return error("Invalid Validate Max Object");
		else if( (parseInt(maximum) > 0) && (txt.value.length > parseInt(maximum))  )
		{
			alert(display + ":  must be " + maximum + " characters or less");
			txt.focus();
		}
		else
			return true;
			
		return false;	
	}		
// ----------------------------------------------------------------------------	
	function validate_select(sel, display)
	{
		if(!sel)
			return error("Invalid Validate Select Object");
		else if(sel.selectedIndex < 1)
		{
			alert("Please select a value for: " + display);
			sel.focus();
		}
		else
			return true;
			
		return false;	
	}
// ----------------------------------------------------------------------------
	function validate_time(h, m, display)
	{
		var hour = h.value;
		var minute = m.value;
		
		if(hour.charAt(0) == '0')
			hour = hour.substr(1);
		
		if(!numeric(hour) || parseInt(hour) < 1 || parseInt(hour) > 12)
		{
			alert("Please enter a valid hour (1-12)");
			h.focus();
			return false;
		}
		else
		{
			if(!numeric(minute) || parseInt(minute) < 0 || parseInt(minute) > 59)
			{
				m.value = "00";
				minute = 0;
			}
			
			return true;
		}
		
	}
// ----------------------------------------------------------------------------




//--- Macromedia Crap
	function MpreloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.Mp) d.Mp=new Array();
		var i,j=d.Mp.length,a=MpreloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.Mp[j]=new Image; d.Mp[j++].src=a[i];}}
	}
// ----------------------------------------------------------------------------
	function MswapImgRestore() { //v3.0
	  var i,x,a=document.Msr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
// ----------------------------------------------------------------------------
	function MfindObj(n, d) { //v4.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MfindObj(n,d.layers[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}
// ----------------------------------------------------------------------------
	function MswapImage() { //v3.0
	  var i,j=0,x,a=MswapImage.arguments; document.Msr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MfindObj(a[i]))!=null){document.Msr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
// ----------------------------------------------------------------------------