/*Timer*/
function timer() {
  setTimeout("window.status=''", 50000);}
/*END Timer*/

/* Get Help Information */
	function gethelp(st_object,st_id)
		{	
			var help_url = new String();
			if (st_object.length > 0)
				{
					help_url = myhttp_mode+":/"+"/"+mydomain_data_path+"task/std.cfm?&def_smart_tips.st_object="+st_object;
				}
			else
				{
					if (st_id.length > 0)
						{
							help_url = myhttp_mode+":/"+"/"+mydomain_data_path+"task/std.cfm?&def_smart_tips.def_smart_tips_id="+st_id;
						}
					else
						{
							help_url = "getfield";
						}
				}
			

			if (help_url == "getfield") //make the st_table and st_field from the input
				{
					var dx_loc = new Number();
					var myfield_help = new Object();
					myfield_help = event.srcElement;
					dx_loc = myfield_help.name.indexOf("_dx_");
					if (dx_loc != -1)
						{
							var st_table = new String();
							var st_field = new String();
							st_table = myfield_help.name.substr(0,dx_loc);
							st_field = myfield_help.name.substr(dx_loc+4);
							if(st_field.indexOf("_dx_")!=-1)
							{dx_loc = st_field.indexOf("_dx_");st_field = st_field.substr(0,dx_loc)}
							help_url = myhttp_mode+":/"+mydomain_data_path+"task/std.cfm?def_smart_tips.st_table="+st_table+"&def_smart_tips.st_field="+st_field;
						}
					else
						{
							dx_loc = myfield_help.name.indexOf(".");
							if (dx_loc != -1)
							{
								var st_table = new String();
								var st_field = new String();
								st_table = myfield_help.name.substr(0,dx_loc);
								st_field = myfield_help.name.substr(dx_loc+1);
								if(st_field.indexOf(".")!=-1)
								{dx_loc = st_field.indexOf(".");st_field = st_field.substr(0,dx_loc)}
								help_url = myhttp_mode+":/"+mydomain_data_path+"task/std.cfm?def_smart_tips.st_table="+st_table+"&def_smart_tips.st_field="+st_field;
							}
						else
							{							
							help_url = "";
							}
						}
					
				}
			
			if (help_url != "")
				{
					link_def_smart_tips (st_id, st_field, st_table)
					//window.open(help_url,'Help','width=500,height=550,resizable=1,status=0,toolbar=0,menubar=0,scrollbars,screenX=10,screenY=40,top=10,left=40');
				}
			else
				{
					alert("Currently there is no help text available for this item.");
				}
			
			if(event!=null)
			{
				event.cancelBubble = true;							
			}
		}
/* END Get Help Information */

/* Open a new window */
function openWin(urln,winn,paramn) {
	MSCwin=window.open(urln,winn,paramn);
}
/* END Open a new window */

/* change class */
function classchange(s)
  		{
		event.srcElement.className=s;
		}
/* END change class*/

/* select text */
function ms()
	{
	if(event.srcElement.type == "text")
		{
			var sel = document.selection; 
			if (sel!=null) { 
			    var rng = sel.createRange(); 
			    if (rng==null) 
			      {event.srcElement.select()} 
			} 			

		}
	}
/* END select text */

/* change_dx_to_dot*/
	function change_dx_to_dot(theform)
		{	
			var myfield = new Object();
			var myfield_name = new String();
			var myfield_last = new Object();
			var myfield_last_name = new String();
			var myfield_length = new Number();
			var myform = new Object();
			
			if(event.srcElement.tagName.toLowerCase()=="form")
				{
					myform = event.srcElement;
				}
			else
				{
					myform = event.srcElement.form;
				}
				/*J Grubb: 01/27/2004 - Added the following block so we can use "change_dx_to_dot()" when
				  we submit forms via onclick of a non-form element, i.e., a "<span>". It requires
				  that the form element be submitted with the function call, i.e. 
				  "change_dx_to_dot(document.formname);", and that the traditional form tag
				  "onSubmit" call be ommitted. */
				  
			if(!myform){
				myform=theform;
			}
			
			for (i=0; i<myform.elements.length; i++)
				{
				
				if(myform.elements(i).name)
					{
						window.status = 'ERROR CHECK: '+myform.elements(i).name
						
						myfield_length = myform.elements(i).name.length;
						if (myform.elements(i).name.substr(myfield_length-5,5) == '.last')
							{
								myfield_last = myform.elements(i);
								myfield = myform.elements(myform.elements(i).name.substr(0,myfield_length-5));
							}
						else
							{
								myfield = myform.elements(i);
								myfield_last = myform.elements(i+'.last');
							}
					
					if (myfield && myfield_last) // Yes - compare value & enable or disable
						{
							if (myfield.value == myfield_last.value)
								{
									myfield_length = myfield.name.length;
									if (myfield.name.substr(myfield_length-3,3)=='_id' || myfield.name.substr(myfield_length-7,7)=='regisno')
										{}
									else
										{
											// myfield.disabled=true;
											// myfield_last.disabled=true;
										}
								}
						}
					else //No
						{
						
							if (myfield_last) //Yes - disable because no base field
								{
									myfield_last.disabled=true;							
								}
						}
					
					}
			
				}
				
			// This cleans up the _dx_
			for (i=0; i<myform.elements.length; i++)
			{
				
				window.status = 'CLEANING UP: '+myform.elements(i).name
				
				if (myform.elements(i).disabled!=true)
					{
						if(myform.elements(i).name)
							{
	
							while (myform.elements(i).name.indexOf('_dx_')>-1)
								{
									myform.elements(i).name=myform.elements(i).name.replace('_dx_', '.');
								}
							}
					}
			}
				window.status = 'Data has been submitted to the Server for processing.... Please wait'
			}
/* END change_dx_to_dot*/

/* change_dx_to_dot LITE*/
	function change_dx_to_dot_lite()
		{	
			var myform = new Object();
						
			if(event.srcElement.tagName.toLowerCase()=="form")
				{
					myform = event.srcElement;
				}
			else
				{
					myform = event.srcElement.form;
				}

			// This cleans up the _dx_
			for (i=0; i<myform.elements.length; i++)
			{
				if (myform.elements(i).disabled!=true)
					{
						if(myform.elements(i).name)
							{

								while (myform.elements(i).name.indexOf('_dx_')>-1)
									{
										myform.elements(i).name=myform.elements(i).name.replace('_dx_', '.');
									}
							}
					}
			}
		}
/* END change_dx_to_dot LITE*/

/*Reverse a checkbox*/
	function checkbox_reverse()
		{
			myform = new Object;
			myform = event.srcElement.form
			
			for(i=0;i<myform.elements.length;i++)
				{
				if(myform.elements(i).type=='checkbox')
					{
						if(myform.elements(i).checked==true)
							{
								myform.elements(i).checked=false;
							}
						else
							{
								myform.elements(i).checked=true;
							}
					}
				}
		}
/* END Reverse a checkbox*/

/* Reset fields on override*/
function do_override()
	{

		var do_value_reset = new String();

		if(event.srcElement.type=='button')
			{
				var do_value_reset = confirm(event.srcElement.ruleid+': '+event.srcElement.x_explanation+'\n===================================\nDo you want these values placed in the form?\n'+event.srcElement.x_title+'\n===================================\n*In the event of a Rule Override, these values are REQUIRED and will be placed in the form automatically. \n*If one of these values is changed, the override becomes invalid and the record must be processed again for validation.\n*If the animal has not been assigned a registration number or this specific information is in the pre-entry database, the values will already be in the form.')
			}
		
		if(event.srcElement.checked==true || (event.srcElement.type=='button' && do_value_reset == true))
		{
		rule = new String();
		rule = event.srcElement.ruleid;
		
		myform = new Object;
		myform = event.srcElement.form;
		
		for(i=0;i<myform.elements.length;i++)
			{

				if(myform.elements(i).name)
				{
					if(myform.elements(i).name.substr(0,rule.length)==rule)
						{
							target_field = new String;
							target_field = myform.elements(i).name.substr(rule.length+4);					
						
							if(myform.elements(target_field))
								{
									myform.elements(target_field).value = myform.elements(i).value
								}
						}
				}
			}
		}
	}
/* END: Reset fields on override*/

/* Disable Override when appropriate */
function verify_override(additional_name_text_src)
	{		


		additional_name_text = new String(); 
		if(typeof additional_name_text_src != "undefined")
			{
				additional_name_text = additional_name_text_src
			}
		
		do_verify = new String();
		rule = new String();
		field = new String();
		
		oMyfield = new Object();
		oMyfield = event.srcElement;

		sMyfield = new String();
		sMyfield = event.srcElement.name;

		dx_loc = new Number();
		
		sCompare_field = new String();
		
		myform = new Object;
		myform = event.srcElement.form;
		
		sMessage = new String();
		sMessage = ""

		if (typeof rule_errors_4_list !="undefined")
		{
			for(i=0;i<rule_errors_4_list.length;i++)
				{
					//if(myform.elements(i).value)
					dx_loc = rule_errors_4_list[i].indexOf("_dx_");
					field = rule_errors_4_list[i].substr(dx_loc+4,rule_errors_4_list[i].length);
					//alert(field)
					//alert(sMyfield)
					if(sMyfield==field)
					{do_verify = 1;break}
					
				}
		}

		if(do_verify == 1)
		{		
		for(i=0;i<myform.elements.length;i++)
			{
				if(myform.elements(i).type=='hidden')
					{ 
						//if(myform.elements(i).name == sMyfield){alert(myform.elements(i).name +' '+ myform.elements(i).name.substr(myform.elements(i).name.length-5))}
						/* We are looking for the value field associated with the error, not the .last value, so it will be a hidden input begining r??_dx_*/
						if(myform.elements(i).name.indexOf("_dx_") > 0)
						{
							if(myform.elements(i).name.substr(myform.elements(i).name.length-5)!='.last')
							{
	
							 //alert(myform.elements(i).name +'   '+ sMyfield +'   '+myform.elements(i).name.substr(myform.elements(i).name.length-5))
							dx_loc = myform.elements(i).name.indexOf("_dx_");
							sCompare_field = myform.elements(i).name.substr(dx_loc+4);
							 //alert(sCompare_field)
	
							if(sCompare_field == sMyfield)
								{
									//alert("field="+sCompare_field+" Rule = "+myform.elements(i).name.substr(0,dx_loc))
									//alert(oMyfield.value.toUpperCase()+'  '+myform.elements(i).value.toUpperCase())
									
									if(oMyfield.value.toUpperCase()!=myform.elements(i).value.toUpperCase())
									{
										rule = myform.elements(i).name.substr(0,dx_loc);
										if(myform.elements(rule+"override"+additional_name_text).checked)
										{
											myform.elements(rule+"override"+additional_name_text).checked=false;
											sMessage += "The value ["+oMyfield.value+"] is not the value validated by "+rule+"\n"+rule+" has validated the value ["+myform.elements(i).value+"]\n------------------------\n";
										}
										
									}
								}
							}
						}
					}
				
			}
		}
	
		if(sMessage!="")
			{
				alert("Override cancelled:\n\n"+sMessage)
	}		}
/* END: Disable Override when appropriate */

/* Indicate error condition */ 
function error_indicate_on()
	{			
		if(typeof error_indicator != "undefined")
		{
			if(error_indicator.className=='inactive_titlebar')
				{error_indicator.className='titlebar'} 
			else
				{error_indicator.className='inactive_titlebar'}
	
			error_indicate_timer_id = setTimeout("error_indicate_on()",1500)
		}
	}
	
function error_indicate_off()
	{
		if(typeof error_indicator != "undefined")
		{
			error_indicator.className='titlebar'
			if(typeof error_indicate_timer_id != "undefined")
				{
					clearTimeout(error_indicate_timer_id)					
				}
		}
	}
/* END: Indicate error condition */ 


/* Show and Hide function */
var td_list = new Array("tr_1")

function show_cells()
	{			
		if(event.srcElement.type == "checkbox")
			{
			if(event.srcElement.checked == true)
				{var action = ""}
			else
				{var action = "none"}
				
			for(sc_i=0; sc_i < td_list.length; sc_i++)
				{
					eval(td_list[sc_i]+'.style.display = action');
				}
			}
	}
/* END: Show and Hide function */


/* Verify sort object */
function verify_sort_object(select_form, select_name)
	{
		var object_passed = new Number();
		object_passed = 0
		
		var myform = new Object();
		if(eval("document."+select_form))
			{

				myform = eval("document."+select_form);
				
				var myselect = new Object;
				if(eval("myform."+select_name))
					{
					myselect = eval("myform."+select_name)
					object_passed = 1		
					}
				else
					{
						alert("Select Tool Error:\n Referenced Select does not exist \n["+select_name+"]")
					}

			}
		else
			{
				alert("Select Tool Error:\n Referenced Form does not exist \n["+select_form+"]")
			}
		return object_passed;
	}
/* END Verify sort object */

/*Sort a select list*/
function sort_options(select_form, select_name)
	{

		var object_passed = new Number();		
		object_passed = verify_sort_object(select_form, select_name);
		
		if(typeof(current_dx_regisno_key_list)=='undefined')
			{object_passed = 0;}
			
		if(object_passed == 1)
		{
		
			var myform = new Object();				
			myform = eval("document."+select_form);
			
			var myselect = new Object;			
			myselect = eval("myform."+select_name)

			var option_id = new Number();
			option_id = 4;
			var got_label = new String();
			var option_key_list = new Object();
			option_key_list = eval(select_name+"_key_list");
			
			if(myselect.options[2])
				{
					myselect.options[2].innerText = animal_tool_label;
				}
			
			/* greater than */			
			for (i=0; i < option_key_list.length; i++)
			{
				if(option_key_list[i] >= myregisno)
					{
						if(myselect.options[option_id])
						{
							myselect.options[option_id].value = option_key_list[i];
							myselect.options[option_id].innerText = get_option_label(select_name, option_key_list[i])
							option_id++
						}
						else
						{
							got_label = get_option_label(select_name, option_key_list[i]);
							if(typeof(got_label) == "undefined")
								{got_label = option_key_list[i]}
							add_option(myselect, option_key_list[i], got_label)
							option_id++
						}
					}

		
			}
			/* End greater than */

			/* Less than */			
			for (i=0; i < option_key_list.length; i++)
			{
				if(option_key_list[i] < myregisno)
					{
						if(myselect.options[option_id])
						{
							myselect.options[option_id].value = option_key_list[i];
							myselect.options[option_id].innerText = get_option_label(select_name, option_key_list[i])
							option_id++
						}
						else
						{
							got_label = get_option_label(select_name, option_key_list[i])
							if(typeof(got_label) == "undefined")
								{got_label = option_key_list[i]}
							add_option(myselect, option_key_list[i], got_label)
							option_id++
						}
					}

		
			}
			/* End less than */
			
			
		}

	}
/*END Sort a select list*/


/* Get the matching label */
function get_option_label(select_name, label_key)
	{ //alert(current_dx_regisno_stable_key_list +''+ current_dx_regisno_key_list)
		//if(!current_dx_regisno_stable_key_list){var current_dx_regisno_stable_key_list = current_dx_regisno_key_list}
		var option_label_list = new Object();
		option_label_list = eval(select_name+"_label_list")

		var option_stable_key_list = new Object();
		option_stable_key_list = eval(select_name+"_stable_key_list")

		
	for (i_label=0; i_label < option_label_list.length; i_label++)
		{ 
			if(option_stable_key_list[i_label] == label_key)
				{
					if(option_stable_key_list[i_label])
					{
						return option_label_list[i_label];
					}
					else
					{
						return option_stable_key_list[i_label];
					}
				}
		}
	}
/* END Get the matching label */


/*Set selected value */	
function set_option_zero(select_form, select_name)
	{
	
		var select_is_set = new Boolean();
		select_is_set = false;
		
		var myform = new Object();
		if(eval("document."+select_form))
			{

				myform = eval("document."+select_form);
				
				var myselect = new Object;
				var mylastoption = new Object;
				if(eval("myform."+select_name))
					{
					myselect = eval("myform."+select_name)

					if(myregisno)
					{

					if(myregisno > 0)
						{		
							for (i=0; i < myselect.options.length; i++)
							{

								if(myselect.options[i].value == myregisno)
									{
										myselect.options[0].value = myregisno;
										myselect.options[0].innerText = myselect.options[i].innerText;
										// alert("regisno: "+myregisno+"\nLabel: "+myselect.options[i].innerText+"\n Value: "+myselect.options[i].value);
										/**/
										if(eval("myform."+select_name+"_dx_option_label"))
											{
												mylastoption = eval("myform."+select_name+"_dx_option_label")
												mylastoption.value = myselect.options[i].innerText
											}
										if(document.f53)
										{
										if(eval("document.f53."+select_name+"_dx_option_label"))
											{
												mylastoption = eval("document.f53."+select_name+"_dx_option_label")
												mylastoption.value = myselect.options[i].innerText
											}
										}
										/**/
										select_is_set = true;
										break;
									}
				
						
							}
						}
					} // End of myregisno present
				}
			else
				{
					alert("Select Tool Error:\n Referenced Select does not exist \n["+select_name+"]")
				}

			}
		else
			{
				alert("Select Tool Error:\n Referenced Form does not exist \n["+select_form+"]")
			}



		if(!select_is_set)
			{
				if(myselect)
					{
					if(myselect.options[0])
						{
							myselect.options[0].value = "";
							myselect.options[0].innerText = "None Selected";
						}
					}
			}
	}
/*END Set selected value */

/*Add an option to a select*/
function add_option(obj_select, option_value, option_text)
	{
		var curlen = new Number();
		curlen = obj_select.length
		var newOpt = new Object();
		newOpt=document.createElement("OPTION");
		obj_select.add(newOpt,curlen);
		obj_select[curlen].innerText = option_text;
		obj_select[curlen].value = option_value;
	}
/*END Add an option to a select*/

/* Get next and previous */
function get_next_animal(select_name, get_which)
	{
		var option_key_list = new Object();
		option_key_list = eval(select_name+"_key_list");

		var myform = new Object();
		myform = event.srcElement.form;
		
		var myselect = new Object();
		myselect = eval("myform."+select_name);

		var get_focus = new Number();
		
		if(get_which == -10)
			{get_focus=0;}
		else
			{
			if(get_which == 10)
				{get_focus = option_key_list.length-1;}
			else
			{
	
				for(gna=0; gna < option_key_list.length; gna++)
					{
						if(option_key_list[gna] == myregisno)
							{
		
							if(gna+get_which < 0)
								{
									get_focus = 0;
								}
							else
								{
									if(gna+get_which >= option_key_list.length)
										{
											get_focus = option_key_list.length-1;
										}
									else
									{
										get_focus = gna+get_which;	
									}
			
								}			
		
							}
					}
	
			}
		}

			myselect.value = option_key_list[get_focus];
			
			if(myselect.value != myregisno)	
				{
					myform.hidden_submit.click();
				}
	}
/* END Get next and previous */



/* Menu related */

/* cookie code */
var expdate = new Date (2020,01,01);

/* "Internal" function to return the decoded value of a cookie */
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
/* END: cookie code */

var mmove_mode = new Number();
mmove_mode = -1;
var menu_action = GetCookie('m1_act')
if(menu_action == null)
	{SetCookie ("m1_act", "0",expdate,"/");}
var retain_menu = menu_action;



var no_context = new Number();
var no_context = 0
var menu_status = new Number();
if(GetCookie('m1_state')=='block'){menu_status = 2}else{menu_status = 0}

document.onmousedown=handle_menu
document.onmousemove=do_mousemove
document.onhelp=anchor_menu
document.onselectstart = stopselect

function stopselect()
	{if(mmove_mode>0)return false}


/* Decide whether to get the menu */
function handle_menu()
	{		
		var menu_action = GetCookie('m1_act')
		if (document.all)
		{				
		    if (window.event.ctrlKey)
			{window.event.cancelBubble = true;}
		else
			{
				if(event.button==2)
					{	
						/*MSC Add 04072004 for menu_viewer*/
						if(!document.all.cancel_epdi_menu)
						{
						if(menu_action==0)
							{hide_select(1)}
						++menu_status					
						get_menu(7, 30);
						}
						else
						{menu_viewer_click_capture()}
						/*END: MSC Add 04072004 for menu_viewer*/
					}
				else
					{ 						
						if(typeof event.srcElement.name != 'undefined')
							{
							if(event.button==1 && 
								event.srcElement.name != 'menu1_txt'  && 
								event.srcElement.name != 'epdi_menu' && 								
								event.srcElement.name.indexOf('menu_sel')<0)
								{	
									++menu_status

									if(retain_menu == 0 && menu_action==0)
										{
											hide_menu();
											hide_select(0);
										}
										
									if(typeof do_on_left_click == 'function')
										{do_on_left_click()}

								}
							}
						else
							{
								if(event.button==1)
									{	
										++menu_status

										if(retain_menu == 0 && menu_action==0)
											{
												hide_menu();
												hide_select(0);
											}

										if(typeof do_on_left_click == 'function')
											{do_on_left_click()}

									}
							}
					}	
			}
		}
		retain_menu = 0 //reset the menu retainer
	}
/* END: Decide whether to get the menu */			

/* Hide select */
function hide_select(action)
	{ 
		for(var fi=0;fi<document.all.tags("SELECT").length;fi++)
			{
				if(action == 1)
					{document.all.tags("SELECT")[fi].style.visibility='hidden'}
				else
					{document.all.tags("SELECT")[fi].style.visibility='visible'}
			}
	}
/* END: Hide select */


/* Anchor the menu */
function anchor_menu()
	{

	if(GetCookie('m1_state')=='block')
		{
		
		if(event.srcElement.id!='btnanchor' || true)
			{var do_anchor = confirm("Anchor the menu?")}
		else
			{var do_anchor = 1}
		
		if(do_anchor)
			{
				var myzindex = 20
				epdi_menu.style.display = 'none';
				epdi_menu.style.posLeft = 0+document.body.scrollLeft;
				epdi_menu.style.posTop = 0+document.body.scrollTop;
				epdi_menu.style.display = 'block';
				epdi_menu.style.zIndex=myzindex;			
				SetCookie ("m1_x", 0,expdate,"/");
				SetCookie ("m1_y", 0,expdate,"/");
				SetCookie ("m1_state", epdi_menu.style.display,expdate,"/");
				return false;
			}
		else
			{gethelp('','25135');return false;}
		}
		else
		{gethelp('','25135');return false;}		
	}
/* END: Anchor the menu */

/* Get the menu */
function get_menu(nmenu_grab_loc_x, nmenu_grab_loc_y)
	{
		window.status = '' // temp
		if(typeof epdi_menu!="undefined")
		{
			var myzindex = 20
		if(epdi_menu.style.display=='none')/* && !document.all.cancel_epdi_menu*/
			{					
				var menu_action = GetCookie('m1_act')
				menu_status = 1
				if(menu_action==0)
					{hide_select(1)}
				epdi_menu.style.visibility = 'hidden';
				epdi_menu.style.display = 'block';				
				


				if(menu_action==0)
					{

						m_up = vertical_position_adjust(event.clientY,epdi_menu.offsetHeight)
						m_over = horizontal_position_adjust(event.clientX,epdi_menu.offsetWidth)				

						if(m_up==0)
						{
							epdi_menu.style.posLeft = event.clientX-nmenu_grab_loc_x+document.body.scrollLeft-m_over;
							epdi_menu.style.posTop = event.clientY-nmenu_grab_loc_y+document.body.scrollTop-m_up;
						}
						else
						{
							epdi_menu.style.posLeft = event.clientX+document.body.scrollLeft-m_over;
							epdi_menu.style.posTop = event.clientY+document.body.scrollTop-m_up;						
						}

					}
				else
					{

						var oldX = GetCookie('m1_x')
						var oldY = GetCookie('m1_y')
						
						m_up = vertical_position_adjust(parseInt(oldY),epdi_menu.offsetHeight)
						m_over = horizontal_position_adjust(parseInt(oldX),epdi_menu.offsetWidth)

						epdi_menu.style.posLeft=parseInt(oldX)+document.body.scrollLeft-m_over
						epdi_menu.style.posTop=parseInt(oldY)+document.body.scrollTop-m_up
					}
					
				epdi_menu.style.visibility = 'visible';
				epdi_menu.style.display = 'block';
				epdi_menu.style.zIndex=myzindex;
				SetCookie ("m1_state", "block",expdate,"/");

				setTimeout("frm_menu.menu1_txt.select()",10);
				setTimeout("frm_menu.menu1_txt.focus()",10);				

			}
		else
			{
			
			if(mmove_mode > 0)
				{	
					menu_status = 2
					epdi_menu.style.posLeft = event.clientX-nmenu_grab_loc_x+document.body.scrollLeft;
					epdi_menu.style.posTop = event.clientY-nmenu_grab_loc_y+document.body.scrollTop;
					epdi_menu.style.display = 'block';
					epdi_menu.style.zIndex=myzindex;
					
					setTimeout("frm_menu.menu1_txt.select()",10);
					setTimeout("frm_menu.menu1_txt.focus()",10);
				}
			}
		}
	}
/* END: Get the menu */	


/* Actions to take on mousemove */
function do_mousemove()
	{
		if(mmove_mode==1)
			{
			var bmenu_grab_loc = new Boolean();
			bmenu_grab_loc = false;
			if(!bmenu_grab_loc)
				{
					var nmenu_grab_loc_x = new Number();
					var nmenu_grab_loc_y = new Number();
					nmenu_grab_loc_x = 7
					nmenu_grab_loc_y = 8
					bmenu_grab_loc = true;
				}
			
			get_menu(nmenu_grab_loc_x, nmenu_grab_loc_y);

			}
			
		if(mmove_mode<1)
			{
				//not used now 
				//window.status = event.clientX+","+event.clientY
			}
	}
/* END: Actions to take on mousemove */

/* Hide the menu */
function hide_menu()
	{
		if(event.button==1 && typeof epdi_menu != 'undefined')
		{	menu_status = 0
			epdi_menu.style.display = 'none';
			SetCookie ("m1_state", "none",expdate,"/");
			window.event.cancelBubble = true;			
		}
	}
/* END: Hide the menu */

/* Grab and drag the menu */
function grab_menu(mode)
	{
		if(event.button==1)
		{
		
			if(event.button==1 & event.srcElement.id=='btnhide')
			{
				epdi_menu.style.display = 'none';
				SetCookie ("m1_state", "none",expdate,"/");
				//epdi_menu.style.position = 'absolute'
				mmove_mode = -1
				window.event.cancelBubble = true;
			}
	
			else
			{
				mmove_mode = mode
				if(mmove_mode > 0)
				{
		 		epdi_menu.style.display = 'none';
		 		setTimeout("epdi_menu.style.display = 'block'",1);
				get_menu(7, 8);
				}
				
				var cur_x = event.clientX-7;
				var cur_y = event.clientY-8;
				
				SetCookie ("m1_x", cur_x,expdate,"/");
				SetCookie ("m1_y", cur_y,expdate,"/");
				SetCookie ("m1_state", epdi_menu.style.display,expdate,"/");
				window.event.cancelBubble = true;
			}
		}
	else
		{
			if(event.button==2)
				{
					menu_status = 0
					get_context_menu(event.srcElement.name)
				}
		}
	}
/* END: Grab and drag the menu */

function epdi_menu_load(thisMenuName)
	{
	
	var thisMenu = new Object()
	try
		{
			thisMenu = eval(thisMenuName)
		}
	catch(e)
		{
			// alert(e)
			thisMenu = 0			
		}

	if(typeof thisMenu == "object")
	{	

	if(GetCookie('m1_state')==null)
		{
		SetCookie ("m1_state", "none",expdate,"/");		
		}
		
	if(GetCookie('m1_x')==null)
		{
		SetCookie ("m1_x", 0,expdate,"/");

		}
		
	if(GetCookie('m1_y')==null)
		{
			SetCookie ("m1_y", 0,expdate,"/");
		}
		
	if(GetCookie('m1_sel')==null)
		{
			SetCookie ("m1_sel", 1,expdate,"/");
		}
		
	if(typeof thisMenu.style != "undefined")
		{
			thisMenu.style.display= GetCookie('m1_state');
			thisMenu.style.left=GetCookie('m1_x');
			thisMenu.style.top=GetCookie('m1_y');
			// Input label reference needs to be made more systemic
			frm_menu.menu1_txt.value=GetCookie('m1_srch');
			if(frm_menu.menu1_txt.value=='null')
				{frm_menu.menu1_txt.value=''}
		
			// Now we build the table
			build_menu(thisMenu)
		
			var oTable = new Object();
			oTable = thisMenu;
		
			while(oTable.tagName.toLowerCase()!='table')
				{			
					var oTable = oTable.parentElement
				}		
				
				btnhide.title="Hide the menu - right click to retrieve - ctrl+right click for normal menu - Current User: "+myusername +' - User ID: '+ myuser_id
		
		
				var rows=oTable.rows;		
				var image_list = new Array();
				var image_type = new Array("_m");//,"_d","_o"
				var image_name = new String();
				var counter = new Number();
					counter = 0
		
		
			  for(var i=0;i<rows.length;i++)
			  {	  	
				for(var c=0;c<rows(i).cells.length;c++)
			  	{ 
					if(rows(i).cells[c].firstChild=="[object]")
					{//alert(rows(i).cells[c].firstChild.name)
					if(rows(i).cells[c].firstChild.tagName=='IMG')
						{
							image_name = rows(i).cells[c].firstChild.name
							for(var it=0; it<image_type.length; it++)
							{
							//Make list							
							image_list[counter] = epdi_menu_image_path+image_name+image_type[it]+'.gif'

							if(image_type[it]=='_m')					
								{	
													
									rows(i).cells[c].id = image_name+'_td' // id the td
									
									document.images[image_name].src=image_list[counter]
									
									set_title = do_set_title(image_name)
									
									document.images[image_name].title = set_title
									
									if(image_name.indexOf('menu_sel')>-1)
										{document.images[image_name].className = ''}
									else
										{document.images[image_name].className = 'gray'}
									
									document.images[image_name].onmousedown=epdi_menu_mouse
									document.images[image_name].onmouseup=epdi_menu_mouse
									document.images[image_name].onmouseover=epdi_menu_mouse
									document.images[image_name].onmouseout=epdi_menu_mouse
									//document.images[image_name].oncontextmenu=epdi_menu_test
									
									
								}
								counter++
							}
		
						}
					}
				}
			  }
		
			/*
			var preload_images = new Image();
			for(var i2=0;i2<image_list.length;i2++)
			  	{
					preload_images[i2] = new Image();
					preload_images[i2].src = image_list[i2];
				}
			*/
			epdi_menu_wrap.style.display='block'
			var menu_lastbutton = GetCookie('m1_lastbutton')
			frm_menu.menu1_txt.title = do_set_title(menu_lastbutton)
		}

	}//epdi_menu present
	}

function do_set_title(source_name)
	{
		try
			{
				set_title = eval(source_name+'_title()')
			}
		catch(e)
			{
				//alert(e)
				set_title = 0
			}

		if(set_title == 0)
			{
				for(var sel=0; sel<=max_menu; sel++)
				{
					if(source_name == fmg_name[sel])
						{
							break
						}
				}

				try
					{
						set_title = fmg_title[sel]
					}
				catch(e)
					{
						//alert(e)
						set_title = source_name
					}											
			}

			if(typeof set_title == 'undefined')
				{
					set_title = '?'
				}				
				
			return set_title
	}


function build_menu(oTable)
	{		
		
		//alert(fmg_function)
		//document.write(fmg_function)
		
//		var oTable = new Object()
//		oTable = epdi_menu
			
		/* previously used to find existing tbody
		var	oTBody = new Object();
		for(var j=0;j<oTable.childNodes.length;j++)
			if(oTable.childNodes[j].tagName=='TBODY')
				{oTBody = oTable.childNodes[j]}
		*/
		
		// alert(oTable.firstChild.tagName+oTable.childNodes[0].tagName+oTable.childNodes.length)
				
		// Base tbody
		var	oTBody = new Object();
		// Base row
		var oRow=document.createElement("TR");
		// Base Cell
		var oCell=document.createElement('TD');
		// Base Img Object
		var oImg = new Object();

		var col_cnt = new Number();
		col_cnt	= 2

		var row_cnt = new Number();
		row_cnt	= 0

		var current_menu = GetCookie('m1_sel')

	for(var tl=0;tl<=max_menu;tl++)
		{
			if(typeof fmg_function[tl]=="object")
			{

				/* make a line
				if(tl>0)
					{
						row_cnt++
						oRow[row_cnt] = oRow.cloneNode()
						oCell_line = document.createElement('<TD colspan="'+col_cnt+'">')
						oRow[row_cnt].appendChild(oCell_line)
						oTBody[tl-1].appendChild(oRow[row_cnt])
						oCell_line.innerHTML = '<hr style="position:relative">'
					}
				*/
				
				row_cnt++
				oRow[row_cnt] = oRow.cloneNode();

				oTBody[tl] = document.createElement("TBODY");

				oTBody[tl].id = fmg_name[tl]
				oTable.appendChild(oTBody[tl])
				
				if(current_menu == tl)//|| current_menu == 4 || tl == 0
					{
						oTBody[tl].style.display = 'block'
						epdi_menu_title.title = fmg_title[tl]+' -- Right-Click for other menus'
						epdi_menu_title.innerHTML = fmg_title[tl].substr(0,5)+'...'
					}
				else
					{oTBody[tl].style.display = 'none'}

				

				for(var i=0;i<fmg_function[tl].length;i++)
					{				
						oCell[i] = oCell.cloneNode();
						oCell[i].colSpan = 2
						oCell[i].style.color = '000000'						
						
						if(typeof fmg_label[tl] == 'undefined')
							{	
								oImg[i] = document.createElement('<IMG name="'+fmg_function[tl][i]+'" type=menu_bar>');		
								oCell[i].appendChild(oImg[i]);								
								oCell[i].name = fmg_name[tl]+'_menu_sel' // prevents the menu from going away when no button is pressed
							}
						else
							{   
								// By removing the var fmg_label, we effectively disable this else case and only the above case is executed
								//oCell[i].insertAdjacentText('beforeEnd', fmg_label[tl][i]); MSCRemove 03312004
								oCell[i].name=fmg_function[tl][i] // makes the cell call the linked function								
								oCell[i].onmousedown=epdi_menu_mouse
								oCell[i].onmouseup=epdi_menu_mouse
								oCell[i].onmouseover=epdi_menu_mouse
								oCell[i].onmouseout=epdi_menu_mouse
							}

						oRow[row_cnt].appendChild(oCell[i]);
						oTBody[tl].appendChild(oRow[row_cnt]);
						
					
						if(i % col_cnt==1)
							{
								//alert(i % row_cnt+' '+fmg_function[i])
								// New row
								row_cnt++
								oRow[row_cnt] = oRow.cloneNode();								

							}
		
					}
				}
			}

	}

	
//use .type
function epdi_menu_mouse()
	{
		if(event.type=='mouseout')
			{				
				//event.srcElement.src=epdi_menu_image_path+event.srcElement.name+'_m.gif';
				if(event.srcElement.name.indexOf('menu_sel')>-1)
					{
						event.srcElement.className = ''
						event.srcElement.style.color = '000000'
						event.srcElement.style.fontWeight='normal'
					}
				else
					{
						event.srcElement.className = 'gray'
						event.srcElement.style.color = '000000'
						event.srcElement.style.fontWeight='normal'
					}
				
				window.status = ''
				window.status = default_statusnote
			}
			else 
			{
				if(event.type=='mouseover'||event.type=='mouseup')
				{
					/*
					alert(epdi_menu.rows+epdi_menu.rows(2).cells[1].id)
					
					
					var mybutton = new Object();
					mybutton = eval(event.srcElement.name+'_td')
					mybutton.style.display = 'none'
					
					*/
					show_current_keys()
					//event.srcElement.src=epdi_menu_image_path+event.srcElement.name+'_m.gif';//o
					if(event.srcElement.name=="NULL" || typeof event.srcElement.name == "undefined")
						{}
					else
						{
						if(event.srcElement.name.indexOf('menu_sel')>-1)
							{
								if(event.srcElement.tagName == 'TD')
									{
										event.srcElement.className = 'focus'
										event.srcElement.style.color = 'E1E0D2'
										event.srcElement.style.fontWeight=500
									}
							}
						else
							{							
								event.srcElement.className = 'focus';
								event.srcElement.style.color = 'E1E0D2'
								event.srcElement.style.fontWeight=500
							}
						}
				
				}
				else 
				{
					if(event.type=='mousedown')
					{					
						if(event.button==1)
							{
								
								show_current_keys()
								//event.srcElement.src=epdi_menu_image_path+event.srcElement.name+'_m.gif';//d
								if(event.srcElement.name.indexOf('menu_sel')>-1)
									{
										event.srcElement.className = ''
										retain_menu = 1	
									}
								else
									{
										event.srcElement.className = 'click'
									}
			
								//alert(typeof eval(event.srcElement.name))
								try
									{
										eval(event.srcElement.name+'()')
									}
								catch(e)
									{
										//alert(e)
										if(event.srcElement.name.indexOf('menu_sel')>-1)
											{menu_sel_default()}
	
									}
									
								SetCookie ("m1_srch", frm_menu.menu1_txt.value,expdate,"/")
								SetCookie ("m1_lastbutton", event.srcElement.name,expdate,"/")
								frm_menu.menu1_txt.title = do_set_title(event.srcElement.name)
								
			
								// Handle menu action - stay or leave							
								var menu_action = GetCookie('m1_act')
								if(menu_action==0 && event.srcElement.name.indexOf('menu_sel')>-1)
									{retain_menu = 1}
								else
									{
										if(menu_action==1)
											{retain_menu = 1}
									}
															
								if(menu_action==null)
									{
										SetCookie ("m1_act", "0",expdate,"/");		
									}
								else
									{
										if(retain_menu == 0)
											{
												epdi_menu.style.display='none'
												SetCookie ("m1_state", "none",expdate,"/");		
											}
									}				
						}	// button == 1
						else // right click image
							{
								if(event.button==2)
									{
										menu_status = 0
										get_context_menu(event.srcElement.name)
									}
							}
					
					}
				}
	
			}		
	}
	
	
/*MSC CSTELL Add 04072004*/
function menu_viewer_click_capture()
	{
	//alert(event.srcElement.name)
	//alert(event.button)
	if(event.button==1)
		{
			try
				{
					eval(event.srcElement.name+'()')
				}
			catch(e)
				{
					alert(e)	
				}
		}
			else
			{
				if(event.button==2)
				{
					menu_status = 0
					get_context_menu(event.srcElement.name)
				}
			}
	}
/*MSC CSTELL Add 04072004*/


function make_input(oNewForm,iname,ivalue)
	{
		var oNewElement = document.createElement('<input type="hidden" name="'+iname+'" value="'+ivalue+'">')
		oNewForm.appendChild(oNewElement)
	}

/*function make_input_modified(oNewForm,iname,ivalue,itype)
	{
		var oNewElement = document.createElement('<input type="'+itype+'" name="'+iname+'" value="'+ivalue+'" style="display:none">')
		oNewForm.appendChild(oNewElement)
	}	*/
	
function make_form(name, sNewFormAction, sTarget)
	{
		var sNewFormName = 'frm_'+name
		for(var fi=0;fi<document.all.tags("FORM").length;fi++)
			{
				if(document.all.tags("FORM")[fi].name == sNewFormName)
					{						
						var menuform = new Object();
						menuform = document.all.tags("FORM")[fi]
						
						if(typeof (menuform) != 'undefined')
						{	//alert('removed')
							menuform.removeNode(true)
						}

					}
			}
			
		var oNewForm = document.createElement('FORM')
		oNewForm.name = sNewFormName
		oNewForm.action = sNewFormAction
		oNewForm.method = 'post'
		if(sTarget!=null)oNewForm.target = sTarget
		document.body.appendChild(oNewForm)
		return oNewForm
	}

function menu1_txt_keypress()
	{
		var menu_lastbutton = GetCookie('m1_lastbutton')
		SetCookie ("m1_srch", frm_menu.menu1_txt.value,expdate,"/")
		frm_menu.menu1_txt.title = do_set_title(menu_lastbutton)
		try{eval(menu_lastbutton+'()')}catch(e){}
		mymenu1_txt = frm_menu.menu1_txt.value
		show_current_keys()
	}
	
function menu1_txt_keyup()
	{
		mymenu1_txt = frm_menu.menu1_txt.value
		show_current_keys()
	}
/* END: Menu related */


/*Test
document.onkeypress=doit
	
	function doit()
		{
			if(event.keyCode==99 || event.ctrlKey == true)
			//alert(document.cookie+' '+document.body.scrollLeft+' '+event.ctrlKey)
			alert(context_p0)
		}
*/


/* 
context_p0
Review the test menu in workgroup_editform
A tag can include a series of parameter tags called p0,p1,p2,...pn
The get_context_menu function can look for these and designate the existence 
of each one in the index
A function can then be made aware of the p0-pn variables that can be used to 
determine what action to take
The trick will be in making a standard function call able to use these values
One must make the function able to know that these values are available and
take precedence over other possible values such as myregisno or the input box on the floating menu
*/
var context_p0 = new String();

// Submenu builder
function get_context_menu(contextMenu)
	{
		hide_select(1)
		if(event.srcElement.p0)
			{
				//alert(event.srcElement.name)
				if(myuser_id==-405)alert(event.srcElement.name+'\nThis function is using a p0 var and needs to have menu1_txt converted to my_p0');
				context_p0 = event.srcElement.p0
				frm_menu.menu1_txt.value = context_p0 /*quick workaround for testing - should be converted to my_p0*/
				my_p0 = context_p0
			}
		if(event.srcElement.p1)
			{

				context_p1 = event.srcElement.p1
				my_p1 = context_p1
			}
			
		
		var menu_passed = new Number()
		menu_passed = 1	

		try
			{
				typeof eval(contextMenu+'_CM')=='object'
			}
		catch(e)	
			{
				menu_passed = 0
			}

		if(menu_passed == 1)
			{
				var oContextMenu = new Object()
				try
					{
						oContextMenu = eval(contextMenu+'_contextMenu')
					}
				catch(e)
					{
						//alert(e)
						build_context_menu(contextMenu)
						oContextMenu = eval(contextMenu+'_contextMenu')
					}
				oContextMenu.style.visibility='hidden'
				oContextMenu.style.display = 'block'
				
				m_up = vertical_position_adjust(event.clientY,oContextMenu.offsetHeight)

				if(event.srcElement.name == 'menu_sel')
					{
						m_x = epdi_menu.offsetWidth+event.clientX
						m_over = horizontal_position_adjust(m_x,oContextMenu.offsetWidth)
						
						if(m_over == 0)
							{
								oContextMenu.style.posLeft = epdi_menu.style.posLeft+epdi_menu.offsetWidth-m_over
							}
						else
							{
								oContextMenu.style.posLeft = epdi_menu.style.posLeft-oContextMenu.offsetWidth								
							}
						oContextMenu.style.posTop = epdi_menu.style.posTop-m_up
					}
				else
					{
						m_over = horizontal_position_adjust(event.clientX,oContextMenu.offsetWidth)
										
						oContextMenu.style.posLeft = event.clientX-5+document.body.scrollLeft-m_over
						oContextMenu.style.posTop = event.clientY-5+document.body.scrollTop-m_up
					}
				
				oContextMenu.style.visibility='visible'

			}
			else{
				if(no_context == 0)
					{
						alert('There are no additional menu items available through clicking your Right Mouse Button on this item.')
						++no_context
					}
				else{
						no_context = 0
					}
			}
	}


function horizontal_position_adjust(x,object_height)
	{
		//Horizontal	
		var mright = x+document.body.scrollLeft+object_height
		var window_right = document.body.clientWidth+document.body.scrollLeft
		

		if(mright>window_right)
			{var m_over = mright-window_right}
		else
			{var m_over = 0}
		//Horizontal
		return m_over
	}																

function vertical_position_adjust(y,object_width)
	{
		// Position code
		// Vertical
		var mbottom = y+document.body.scrollTop+object_width 
		var window_bottom = document.body.clientHeight+document.body.scrollTop
		
	
		if(mbottom>window_bottom)
			{var m_up = mbottom-window_bottom}
		else
			{var m_up = 0}
		// Vertical		
		return m_up
	}																

function build_context_menu(contextMenu)
	{		
		var myzindex = 21
		// Base table
		var	oTable = new Object();
		oTable = document.createElement("TABLE");
		
		oTable.id = contextMenu+'_contextMenu'
		
		// Base tbody
		var	oTBody = new Object();
		// Base row
		var oRow=document.createElement("TR");
		// Base Cell
		var oCell=document.createElement('TD');
		// Base Img Object
		var oImg = new Object();

		var col_cnt = new Number();
		col_cnt	= 1

		var row_cnt = new Number();
		row_cnt	= 0

		//var current_menu = GetCookie('m1_sel')

	var CM = eval(contextMenu+'_CM')
	var CM_lbl = eval(contextMenu+'_CM_lbl')
	
	// Load title array
	try
		{
			var CM_title = eval(contextMenu+'_CM_title')			
		}
	catch(e)
		{
			var CM_title = new Array()//CM.length
		}
	// END Load title array
	
	// Load p0 array
	try
		{
			var CM_p0 = eval(contextMenu+'_CM_p0')
		}
	catch(e)
		{
			var CM_p0 = new Array()//CM.length
		}
	// END Load p0 array	
		
	if(typeof CM=="object")
		{

			row_cnt++
			oRow[row_cnt] = oRow.cloneNode();
			oRow.epdi_isContextMenu=1;
			oTBody[0] = document.createElement("TBODY");
			
			oTBody[0].id = contextMenu+'_tbody'
			oTBody[0].epdi_isContextMenu=1;
			oTable.appendChild(oTBody[0])
			oTable.epdi_isContextMenu=1;			
			
			for(var i=0;i<CM.length;i++)
				{
					//  Add a cell
					oCell[i] = oCell.cloneNode();
					oRow[row_cnt].appendChild(oCell[i]);
					oCell[i].style.paddingRight = 3;
					oCell[i].epdi_button=contextMenu;
					oCell[i].epdi_isContextMenu=1;
					//  END Add a cell
					
					oCell[i] = oCell.cloneNode();
					oCell[i].colSpan = 1
					//oCell[i].style.className = 'notfocus'
					oCell[i].style.color = '000000'				
					oCell[i].style.paddingLeft = 10
					oCell[i].style.paddingRight = 20
					oCell[i].style.paddingTop = 1
					oCell[i].style.paddingBottom = 2
					oCell[i].style.borderBottomWidth = 1
					oCell[i].style.borderBottomStyle = 'inset'
					oCell[i].style.borderRightWidth = 1
					oCell[i].style.borderRightStyle = 'inset'
					oCell[i].style.borderRightColor = 'C2BFA5'
					oCell[i].style.borderLeftWidth = 6
					oCell[i].style.borderLeftStyle = 'double'
					oCell[i].style.borderLeftColor = '4F8516'
					oCell[i].style.borderTopWidth = 1
					oCell[i].style.borderTopStyle = 'inset'
					oCell[i].style.borderTopColor = 'C2BFA5'


					
					

					oCell[i].insertAdjacentText('beforeEnd', CM_lbl[i]);
					oCell[i].name=CM[i] // makes the cell call the linked function
					oCell[i].id=CM[i]
					oCell[i].p0=CM_p0[i]
					oCell[i].epdi_button=contextMenu
					oCell[i].index=i
					oCell[i].onmousedown=epdi_menu_mouse
					oCell[i].onmouseup=epdi_menu_mouse
					oCell[i].onmouseover=epdi_menu_mouse
					oCell[i].onmouseout=epdi_menu_mouse
					oCell[i].epdi_isContextMenu=1;
					
					// oCell[i].p0=CM_p0[i]; Not currently implemented
					
					//alert(CM_p0[i])

					// Title Manager
					if(CM_title[i] == null || CM_title[i] == '')
						{
							try
								{
									set_title = eval(CM[i]+'_title()')
								}
							catch(e)
								{
									try
										{
											set_title = eval(CM[i]+'_title')
										}
									catch(e)
										{
											//alert(e)
											set_title = 0
										}											
								}
						}
					else
						{
							set_title=CM_title[i]
						}
	
						if(set_title == 0)
							{
								set_title = ''
							}
	
					oCell[i].title = set_title
					// END Title manager
					
					
					oRow[row_cnt].appendChild(oCell[i]);
					
					//  Add a cell
					oCell[i] = oCell.cloneNode();
					oRow[row_cnt].appendChild(oCell[i]);
					oCell[i].style.paddingRight = 3;
					oCell[i].epdi_isContextMenu=1;
					//  END Add a cell
					
					oTBody[0].appendChild(oRow[row_cnt]);
					
					if(1)//i % col_cnt==1
						{
							// New row
							row_cnt++
							oRow[row_cnt] = oRow.cloneNode();								

						}
	
				}
			}

		epdi_menu_wrap.appendChild(oTable);
				
		//oTable.cellPadding=2
		//oTable.cellSpacing=2
		oTable.style.position = "absolute"			
		oTable.className = 'menu2'				
		oTable.style.zIndex=myzindex;		

		if((navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5.5,navigator.appVersion.indexOf("MSIE")+8)>=6.5)&&(navigator.appName=="Microsoft Internet Explorer"))
		{
		oTable.onmouseleave=hide_contextMenu
		}
		else
		{
		oTable.onmouseout=hide_contextMenu
		}		
		oTable.onmousedown=hide_contextMenu
	}

	
function hide_contextMenu()
	{
		if(retain_menu == 0)
		{
			cnt = 0
			oElement = event.srcElement
			while(oElement.tagName.toLowerCase()!='table' && cnt < 5)
				{
					cnt++
					oElement = oElement.parentElement
				}
			
			if(event.toElement!=null)
			{
				if(event.toElement.epdi_isContextMenu!=1)
				{canClose=1}
				else
				{canClose=0}
			}
			else
			{
				if(event.type=="mousedown")
				{canClose=1}
				else
				{canClose=0}		
			}
			if((oElement.id.indexOf('_contextMenu')>-1)&&(canClose==1))		
				{
					oElement.style.visibility='hidden'
				}
		}
	}
// END submenu builder


// Timer function - MSCadd 020820
var ttmnow=0;
var ths="0";
var thn=0;
var tms="0";
var tmn=0;
var tss="0";
var tsn=0;

function tstarttm()
    {
  ths=thn;
  tms=tmn;
  tss=tsn;
 if (thn<10)
    ths="0" + ths;
  if (tmn<10)
    tms="0"+tms;
  if (tsn<10)
    tss="0"+tss;
  job_timer.innerHTML = "" + ths+":"+tms+":"+tss;
   if (ttmnow)
     {
     clearTimeout(ttmnow);
     ttmnow=0;
     }
    tsn+=1;
    if (tsn>59)
      {
      tmn+=1;
      tsn=0;
      if (tmn>59)
        {
        thn+=1;
        tmn=0;
       if (thn>23)
          thn=0;
        }
    }
   ttmnow=setTimeout("tstarttm()",1000);
  }
// END Timer function

/* Display Code */
/* Center Form */
function center_form()
	{
		var body_height_half = document.body.clientHeight/2
		document.all.editform_div.style.display = 'block'
		var table_height_half = document.all.editform_div.offsetHeight/2
		document.all.editform_div.style.display = 'none'
		document.all.editform_div.style.top = body_height_half-table_height_half
		document.all.editform_div.style.display = 'block'					
	}
/* END: Center Form */
/* END: Display Code */