/*System core functions*/
document.onhelp=anchor_menu
document.onkeyup = processOnKeyUp

var sf1_table = new String()
sf1_table = ''
var sf1_field = new String()
sf1_field = ''
var system_f1_help_id = new String()
system_f1_help_id = ''
var sf1_subject = new String()
sf1_subject = ''
var sf1_subject_technical = new String()
sf1_subject_technical = 'IST_system1'

if(typeof always_on_load == 'function')
	{setTimeout("always_on_load()",500)}

var retain_menu = 0;
var default_statusnote = 'IST Management Services'
var myhttp_mode = 'https'
var mydomain_data_path = self.location.hostname //'istists2.istmanagement.com'

menu_status = 3

var help_search_text = new String()
help_search_text = 'system'
var help_file = new String()
help_file = 'system_help_main.cfm'


function anchor_menu()
	{
		getF1Help(system_f1_help_id,sf1_table,sf1_field,sf1_subject,sf1_subject_technical);return false;
	}
	/*gethelp(help_search_text, help_file);return false;*/
		

function show_current_keys()
	{	
		window.status = 'IST Management Services'
	}

/*Timer*/
function timer() {
  setTimeout("window.status=''", 50000);}
/*END Timer*/




/* change class */
function classchange(s,id,name)
  		{ 
			if(typeof(event) != 'undefined')
				{
					event.srcElement.className=s;
				}
			else if(id != null && document.getElementById(id))
				{		
					document.getElementById(id).className=s;
				}
			else if(name != null && document.getElementsByName(name))
				{		
					document.getElementsByName(name).className=s;
				}
			else
				{
					//alert('This element needs id attributes set for the class change.')	
				}
		}
/* END change class*/

function count_characters(obj, maxCount)
	{				
		if(obj.innerText.length > maxCount)
			{alert('You have exceeded the maximum character count ('+maxCount+') for this text box.\n\nPlease remove '+eval(Math.abs(maxCount-obj.innerText.length))+' characters before submitting the record.')}
	}

/* Form builder */
function make_input(oNewForm,iname,ivalue)
	{	
		var oNewElement = document.createElement('INPUT');
		oNewElement.setAttribute("type","hidden");
		oNewElement.setAttribute("name",iname);
		oNewElement.setAttribute("id",iname);
		oNewElement.setAttribute("value",ivalue); 		
		oNewForm.appendChild(oNewElement)
	}

function xmake_form(name, sNewFormAction, sTarget)
	{
		var sNewFormName = 'frm_'+name
		for(var fi=0;fi<document.getElementsByTagName("FORM").length;fi++)
			{
				if(document.getElementsByTagName("FORM")[fi].name == sNewFormName)
					{						
						var menuform = new Object();
						menuform = document.getElementsByTagName("FORM")[fi]
						
						if(typeof (menuform) != 'undefined')
						{	//alert('removed')
							try{menuform.removeNode(true);}
							catch(e){}
						}

					}
			}
			
		var oNewForm = document.createElement('FORM')
		oNewForm.name = sNewFormName
		oNewForm.id = sNewFormName
		oNewForm.action = sNewFormAction
		oNewForm.method = 'post'
		if(sTarget!=null)oNewForm.target = sTarget

		if (typeof(document) != 'undefined') {
			var objBody = new Object();
			
			if (typeof(document.getElementById("body_main")) == 'object') {
				objBody = document.getElementById("body_main");
			}
			else {
				objBody = document.body;
			}
			
			if (!objBody || objBody == 'null'){alert('No Body Found');} //objBody = document.body
			
			var s = window.top.location.href.split("/")
			var file = s[s.length-1]
			
			if (file == 'employee_hr_manage.cfm') // Temp fix
				{objBody.childNodes[0].insertBefore(oNewForm)}
			else if (typeof objBody == 'object' && typeof oNewForm == 'object')
				{
					try{objBody.appendChild(oNewForm);} 
					catch(e){ 
								try{objBody.insertBefore(oNewForm);}
								catch(e2){
											try{objBody.childNodes[0].insertAfter(oNewForm);}
											catch(e3){alert(e3.message + ' The Dynamic Form cannot be created');}}}
				}
			else {alert('Body is not an Object');}
		}
		
		//document.body.appendChild(oNewForm);
		return oNewForm
	}


function make_form(name, sNewFormAction, sTarget)
	{
		var sNewFormName = 'frm_'+name
		for(var fi=0;fi<document.getElementsByTagName("FORM").length;fi++)
			{
				if(document.getElementsByTagName("FORM")[fi].name == sNewFormName)
					{						
						var menuform = new Object();
						menuform = document.getElementsByTagName("FORM")[fi]
						
						if(typeof (menuform) != 'undefined')
						{	//alert('removed')
							try{menuform.removeNode(true);}
							catch(e){}
						}

					}
			}
			
		var oNewForm = document.createElement('FORM')
		oNewForm.name = sNewFormName
		oNewForm.id = sNewFormName
		oNewForm.action = sNewFormAction
		oNewForm.method = 'post'
		if(sTarget!=null)oNewForm.target = sTarget

		if(typeof(document) != 'undefined')
		{
			var objBody = new Object();
									
			if(document.getElementById("body_main"))
				{objBody = document.getElementById("body_main");}
			else if(document.body) 
				{objBody = document.body;}
			else
				{
					// If the body tag has been destroyed in the DOM, add it back.
					objBody = document.createElement('BODY');
					objBody.id = "body_main";		
				}	
			
			if(!objBody || objBody == 'null') alert('No Body Found') //objBody = document.body
			
			var s = window.top.location.href.split("/")
			var file = s[s.length-1]
			
			if (file == 'employee_hr_manage.cfm') // Temp fix
				{objBody.childNodes[0].insertBefore(oNewForm)}
			else if (typeof objBody == 'object' && typeof oNewForm == 'object')
				{		
					try{objBody.appendChild(oNewForm);} 
					catch(e){ alert(e.message)
								try{objBody.insertBefore(oNewForm);}
								catch(e2){alert(e2.message)
											try{objBody.childNodes[0].insertAfter(oNewForm);}
											catch(e3){alert(e3.message + ' The Dynamic Form cannot be created');}}}
				}
			else {alert('Body is not an Object');}
		}
		
		//document.body.appendChild(oNewForm);
		return oNewForm
	}

/* Form builder */


/*END: System core functions*/


function reset_session_variables()
	{
		var sAction = '/ist_auth/function/reset_application_variables_target.cfm'
		var sTarget = 'reset_app_vars'
		
		var oNewForm = make_form('fx100', sAction, sTarget)
		make_input(oNewForm, 'from_where','reset_app_session_vars_for_me')
		//oNewForm.submit()
		doIoBind_XmlAlertC1(oNewForm);
		alert('Your Session Variables have been reset.')
	}
	
	
function changeUserPasswordIst()
	{
		var sAction = '../../ist_auth/logon/logon_change_password.cfm'
		var sTarget = 'auth_security_anlysis'
		
		var sec_user_id = 0;
		/*For use with the pop up menu*/
		if(typeof my_p0 != "undefined")
			{sec_user_id = my_p0}
		/*For use with the pop up menu*/

		
		h = setHeight(300);
		w = setWidth(425);
		temp = small_window(sTarget,h,w);					

		var oNewForm = make_form('fx1', sAction, sTarget)
		make_input(oNewForm, 'from_where','Search')
		make_input(oNewForm, 'sec_user_id',sec_user_id)
		oNewForm.submit()
		
	}

	
/*Menu and app based functions*/
function gethelp(help_search_text,help_file)
	{
	
		var sAction = '/ist_shared/ist_help/'+help_file
		var sTarget = 'help_window'
		if(event!=null)
			{		
				var oNewForm = make_form(event.srcElement.name, sAction, sTarget)
			}
		else
			{
				var oNewForm = make_form('no_srcElement', sAction, sTarget)
			}

		h = 600
		w = 500
		small_window(sTarget,h,w)
		
		//help_window=window.open('',sTarget,'height=600,width=500,status=yes,toolbar=yes,menubar=yes,location=no,resizable=yes,screenX=10,screenY=40,top=10,left=40,scrollbars');
		//help_window.window.focus()
		
		make_input(oNewForm, 'from_where','Search')
		make_input(oNewForm, 'help_search_text',help_search_text)
		oNewForm.submit()
		
		if(event!=null)
		{
			event.cancelBubble = true;							
		}		
	}	
/*END: Menu and app based functions*/


/*Menu and app based functions*/
function editF1Help(help_titlebar_text, system_f1_help_id,sf1_table,sf1_field,sf1_subject_technical)
	{
	
		var sf1_subject = new String()
				
		var sAction = '/ist_shared/ist_help/system_f1_help_edit.cfm'
		var sTarget = 'help_window_edit'
		if(event!=null)
			{		
				var oNewForm = make_form(event.srcElement.name, sAction, sTarget)
			}
		else
			{
				var oNewForm = make_form('no_srcElement', sAction, sTarget)
			}

		h = screen.availHeight*0.75
		w = screen.availWidth*0.75
		if(w<700){w = screen.availWidth*0.98;}
		small_window(sTarget,h,w)

		//help_window_edit=window.open('',sTarget,'height=600,width=800,status=yes,toolbar=yes,menubar=yes,location=no,resizable=yes,screenX=10,screenY=40,top=10,left=40,scrollbars');
		//help_window_edit.window.focus()
		
		make_input(oNewForm, 'from_where','Edit')
		make_input(oNewForm, 'system_f1_help_id',system_f1_help_id)
		make_input(oNewForm, 'sf1_table',sf1_table)
		make_input(oNewForm, 'sf1_field',sf1_field)
		make_input(oNewForm, 'sf1_subject_technical',sf1_subject_technical)
		make_input(oNewForm, 'help_titlebar_text',help_titlebar_text)
		oNewForm.submit()
	
	}
	

function getF1HelpImages()
	{
		var sAction = '/ist_shared/ist_help/system_f1_help_images.cfm'
		var sTarget = 'help_image'
		
		h = screen.availHeight*0.70
		w = screen.availWidth*0.70
		if(w<700){w = screen.availWidth*0.90;}
		small_window(sTarget,h,w)
		
		var oNewForm = make_form(event.srcElement.name, sAction, sTarget)
		make_input(oNewForm, 'from_where','Search')
		oNewForm.submit()
	}


function create_new_help_record(help_titlebar_text,sf1_table, sf1_field,sf1_subject_technical)
	{
		var sAction = '/ist_shared/ist_help/system_f1_help_edit.cfm'
		var sTarget = 'help_window_edit'


		h = screen.availHeight*0.75
		w = screen.availWidth*0.75
		if(w<700){w = screen.availWidth*0.98;}
		small_window(sTarget,h,w)
		
		//help_window=window.open('',sTarget,'height=600,width=800,status=yes,toolbar=yes,menubar=yes,location=no,resizable=yes,screenX=10,screenY=40,top=10,left=40,scrollbars');
		//help_window.window.focus()

		var oNewForm = make_form('New_record', sAction, sTarget)	
		make_input(oNewForm, 'from_where','New')
		make_input(oNewForm, 'sf1_table',sf1_table)
		make_input(oNewForm, 'sf1_field',sf1_field)
		make_input(oNewForm, 'sf1_subject_technical',sf1_subject_technical)
		make_input(oNewForm, 'help_titlebar_text',help_titlebar_text)
		oNewForm.submit()			
	}

function delete_help_record(system_f1_help_id)
	{
		var do_delete = confirm('Are you sure you want to Permanently DELETE this Record?')
		
		if(do_delete)
			{
				var sAction = '/ist_shared/ist_help/system_f1_help_edit.cfm'
				var sTarget = 'help_window_edit'
				var oNewForm = make_form('Delete_record', sAction, sTarget)
			
				make_input(oNewForm, 'from_where','Delete')
				make_input(oNewForm, 'system_f1_help_id',system_f1_help_id)
				oNewForm.submit()			
			}
	}


function getF1Help(system_f1_help_id,sf1_table,sf1_field,sf1_subject,sf1_subject_technical)
	{

		var sAction = '/ist_shared/ist_help/system_f1_help.cfm'
		var sTarget = 'help_window'
		if(event!=null)
			{		
				var oNewForm = make_form(event.srcElement.name, sAction, sTarget)
			}
		else
			{
				var oNewForm = make_form('no_srcElement', sAction, sTarget)
			}

		h = screen.availHeight*0.50
		w = screen.availWidth*0.65
		if(w<500){w = screen.availWidth*0.75;}
		small_window(sTarget,h,w)
		
		//help_window=window.open('',sTarget,'height=600,width=800,status=yes,toolbar=yes,menubar=yes,location=no,resizable=yes,screenX=10,screenY=40,top=10,left=40,scrollbars');
		//help_window.window.focus()

		var tagName = new String();
		var name = new String();
		var Parent_tagName = new String();
		var Parent_name = new String();
		var GrandParent_tagName = new String();
		var GrandParent_name = new String();
		
		if(event.srcElement)
		{
			x = event.srcElement
			make_input(oNewForm, 'tagName',x.tagName)
			make_input(oNewForm, 'name',x.name)
			make_input(oNewForm, 'help',x.onhelp)

			if(x.parentElement)
				{
					x = x.parentElement
					make_input(oNewForm, 'Parent_tagName',x.tagName)
					make_input(oNewForm, 'Parent_name',x.name)
					make_input(oNewForm, 'Parent_help',x.onhelp)
					
					if(x.parentElement)
					{
						x = x.parentElement
						make_input(oNewForm, 'GrandParent_tagName',x.tagName)
						make_input(oNewForm, 'GrandParent_name',x.name)
						make_input(oNewForm, 'GrandParent_help',x.onhelp)
					}
			}
		}		

				
		make_input(oNewForm, 'from_where','Search')
		make_input(oNewForm, 'sf1_table',sf1_table)
		make_input(oNewForm, 'sf1_field',sf1_field)
		make_input(oNewForm, 'system_f1_help_id',system_f1_help_id)
		make_input(oNewForm, 'sf1_subject',sf1_subject)
		make_input(oNewForm, 'sf1_subject_technical',sf1_subject_technical)
		oNewForm.submit()
		
		if(event!=null)
		{
			event.cancelBubble = true;							
		}		
	}	
	

/* New Cross Browser Help Code*/
function returnNode(evt)
	{
		var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		return node;
	}
	
function processOnKeyUp(evt)
	{
		var evt = (evt) ? evt : ((event) ? event : null);
		var node = returnNode(evt);

		if((evt.keyCode == 191 || evt.keyCode == 47) && evt.ctrlKey) 
			{
				var helpId = null;
				getHelp(helpId, evt);
			}
	}
	
function getHelpTable(node)
	{
		var helpTable = null;
		if(node.attributes['helpTable']) helpTable = node.attributes['helpTable'].value;
		else if(node && node.name && node.name.indexOf('.',0) > 0) helpTable = node.name.split('.',1)
		return helpTable;
	}
	
function getHelpField(node)
	{
		var getHelpField = null;
		if(node.attributes['getHelpField']) getHelpField = node.attributes['getHelpField'].value;
		else if(node && node.name && node.name.indexOf('.',0) > 0) getHelpField = node.name.split('.',2)[1]
		return getHelpField;
	}

function getHelp(helpId, evt)
	{
		
		var node = returnNode(evt);
		
		var helpTable = getHelpTable(node)
		var helpField = getHelpField(node)
		
	
		if(helpId == null && node.attributes['helpId']) helpId = node.attributes['helpId'].value;				

		var sAction = '/ist_shared/ist_help/system_f1_help.cfm'
		var sTarget = 'help_window'
		
		var oNewForm = make_form('helpForm', sAction, sTarget)
		
		var h = setHeight(450);
		var w = setWidth(750);
		small_window(sTarget,h,w)
		
		var tagName = new String();
		var name = new String();
		var Parent_tagName = new String();
		var Parent_name = new String();
		var GrandParent_tagName = new String();
		var GrandParent_name = new String();
		
		if(node)
		{
			x = node
			make_input(oNewForm, 'tagName',x.tagName)
			make_input(oNewForm, 'name',x.name)
			make_input(oNewForm, 'help',x.onhelp)

			if(x.parentElement)
				{
					x = x.parentElement
					make_input(oNewForm, 'Parent_tagName',x.tagName)
					make_input(oNewForm, 'Parent_name',x.name)
					make_input(oNewForm, 'Parent_help',x.onhelp)
					
					if(x.parentElement)
					{
						x = x.parentElement
						make_input(oNewForm, 'GrandParent_tagName',x.tagName)
						make_input(oNewForm, 'GrandParent_name',x.name)
						make_input(oNewForm, 'GrandParent_help',x.onhelp)
					}
			}
		}		


		make_input(oNewForm, 'from_where','Search')
		make_input(oNewForm, 'sf1_table',helpTable)
		make_input(oNewForm, 'sf1_field',helpField)
		make_input(oNewForm, 'system_f1_help_id',helpId)
		make_input(oNewForm, 'sf1_subject',sf1_subject)
		make_input(oNewForm, 'sf1_subject_technical',sf1_subject_technical)
		oNewForm.submit()
		
		if(evt!=null)
		{
			evt.cancelBubble = true;							
		}		
	}	
/* END: New Cross Browser Help Code*/

/*END: Menu and app based functions*/


/* Display tbody function*/
function display_access_list(which,force)
	{	
	
		var myObj = document.getElementById(which);
		
		if(typeof (myObj) != 'undefined')
		{
			action = null
			
			if(myObj.style.display == 'none')
				{
					if(force == 'open' || force == null)
						{action = 'block'}
				}
			else
				{
					if(force == 'close' || force == null)
						{action = 'none'}
				}
			
			if(action)
				{myObj.style.display = action}
		}
		else
		{
			alert('ERROR: '+which+' is not properly referenced on this form.')
		}
	}
	
function closeAll_display_access_list(label, force)
	{
		open_all_hidden_tbody('','close');
		display_access_list(label, force);
	}
	
function open_all_hidden_tbody(label, force)
	{
		len = label.length
		force = force.toLowerCase();
		var tbodyList = document.getElementsByTagName("TBODY");
		for(var i = 0; i< tbodyList.length; i++)
			{
				if(len == 0 && tbodyList[i].id.length > 0)
					{display_access_list(tbodyList[i].id,force)}
				else if(len > 0 && tbodyList[i].id.substring(0,len) == label)
					{display_access_list(tbodyList[i].id,force)}
			}
	}
/* END: Display tbody function*/

/*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/


function setHeight(h)
	{
		availH = screen.availHeight;
		if(h > availH) h = availH*0.95;
		return h;
	}
	
function setWidth(w)
	{
		availW = screen.availWidth;
		if(w > availW) w = availW*0.95;
		return w;
	}
	



function off_screen_win(sTarget)
	{
		vOff_screen_win=window.open('',sTarget,'height=0,width=0,status=no,toolbar=no,menubar=no,location=no,resizable=yes,screenX=10000,screenY=10000,top=10000,left=10000,scrollbars=no')
	}

function small_window(sTarget,h,w,sAction)
	{
		var thisWin = new Object();
		
		if(sAction == null) sAction = '';
		
		var shiftTop = (screen.availHeight/2)-(h/2)
		var shiftLeft = (screen.availWidth/2)-(w/2)
		
		thisWin = window.open(sAction,sTarget,'height='+h+',width='+w+',status=no,toolbar=no,menubar=no,location=no,resizable=yes,screenX='+shiftLeft+',screenY='+shiftTop+',top='+shiftTop+',left='+shiftLeft+',scrollbars=yes');
		if(sAction == '' && thisWin.document && thisWin.document.body && thisWin.document.body.innerHTML && thisWin.document.body.innerHTML == 0) thisWin.document.write('<span>Please wait...<img src="/ist_shared/ist_images/ist_icons/progress/indicator_arrows.gif"></span>');
		thisWin.focus();
	
		return thisWin;
	}
	
function standard_window(sTarget,h,w,sAction)
	{
		var shiftTop = (screen.availHeight/2)-(h/2)
		var shiftLeft = (screen.availWidth/2)-(w/2)
		
		thisWin = window.open('',sTarget,'height='+h+',width='+w+',status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,screenX='+shiftLeft+',screenY='+shiftTop+',top='+shiftTop+',left='+shiftLeft+',scrollbars=yes');
		if(sAction == '' && thisWin.document.body.innerHTML == 0) thisWin.document.write('<span>Please wait...<img src="/ist_shared/ist_images/ist_icons/progress/indicator_arrows.gif"></span>');
		thisWin.focus();
		
		return thisWin;
	}


/*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/

/* docStor functions */

/* Docstor menu functions - duplicated in ist_docstor.js */
function menu_locate_document_by_storage_profile()
	{			
			var win = "";
			var sAction ='https://ist.istdocstor.com/ist_docStor/form_select/call_fm_docstor_manage.cfm';
			var sTarget = 'docstor_forms_manager_parent';

			h = 600;
			w = 800;
			win = small_window(sTarget,h,w, '');
						
			var oNewForm = make_form('locate_file', sAction, sTarget)
			make_input(oNewForm, 'from_where_response_mode','find_storage_profile_list_istcopy')
			make_input(oNewForm, 'profile_id', 0)
	
			oNewForm.submit()
	}	



function curtainExplanation()
	{
		alert('This folder can be hidden behind a Curtain.\n(All Child Folders will be hidden behind the same Curtain or a Higher Level Curtain.)\n\nThe "Curtain" hides Folders based on User Rights Level.\n\nThe Curtain Rights Level blocks access by Users whose Rights Level is less than the Curtain Rights Level.\n\nSelect "Folder Security Level" on the Folder menu to define the Curtain.')	
	}



/* DocStor & Shopping Cart */
function send_document_id_to_shopping_cart()
	{
		document_id = my_p0
		parent.handleDocStorRemoteLink(document_id)
		//alert(parent.document.getElementById("product_dx_product_description").value)
	}
/* DocStor & Shopping Cart */


var my_p0 = null
var context_p0 = null

	
function hide_row(rowId)
	{
		var record = new Object()
		if(typeof document.getElementById(rowId) == "object" && rowId != null)
			{
				record = document.getElementById(rowId)			
				record.style.display = 'none'
			}			
	}



// Generic
function showIsWorking()
	{				
		var iconIsWorking = document.getElementById("iconIsWorking");
		iconIsWorking.style.display = 'inline';
	}
// Generic



/* onScreen Edit */
function toggleEditFieldMain(rowId, fieldName)
	{
		var input = new Object();
		var span = new Object();
		
		input = document.getElementById(fieldName+"_"+rowId);
		span = document.getElementById(fieldName+"_span_"+rowId);
		
		if(input.style.display == 'none')
			{	
				input.style.display = 'inline';
				input.focus();
				input.select();
				span.style.display = 'none';
			}
		else
			{
				input.style.display = 'none';
				span.innerText = input.value;
				span.style.display = 'inline';
			}
	}
/* END: onScreen Edit */



/*Error Table display */
function center_msg()
	{
		if(typeof document.body == "object")
		{
			var body_height_half = document.body.clientHeight/2
			document.all.error_div.style.display = 'block'
			var table_height_half = document.all.error_div.offsetHeight/2
			document.all.error_div.style.display = 'none'
			document.all.error_div.style.top = body_height_half-table_height_half
			document.all.error_div.style.display = 'block'			
			setTimeout("blink_error()", 750)
		}
	}

function blink_error(flash_cnt)
	{
		if(typeof flash_cnt == 'undefined')
			{flash_cnt = 1}
		flash_cnt++

		if(flash_cnt < 2)
			{
				if(document.all.error_div.style.display == 'block')			
					{
						document.all.error_div.style.display = 'none'
						setTimeout("blink_error("+flash_cnt+")", 500)
					}
				else
					{
						document.all.error_div.style.display = 'block'
						setTimeout("blink_error("+flash_cnt+")", 750)
					}
			}
		else
			{
				document.all.error_table.className = 'logon_editform'
				document.all.error_div.style.display = 'block'
			}
	}
/*Error Table display */

	
function toggle_image(image_switch){
	// jev20050224
	var image_src = event.srcElement.src;
	var image_ext = image_src.substring(image_src.length-3,image_src.length);
	var image_root = image_src.substring(0,image_src.lastIndexOf("_"));
	var image_src_new = '';

	image_src_new = image_root + '_' + image_switch + '.' + image_ext;
	classchange('');
	event.srcElement.src = image_src_new;
}	
	
	
function logout_auth()
	{
		var logout_question = confirm('Click OK to Log Out and Cancel to remain Logged On.')
		
		if(logout_question)
		{
			var sAction = '/ist_auth/logon/logout.cfm'
			var sTarget = 'logout'
			logon_window = window.open('',sTarget,'height=150,width=500,status=no,toolbar=no,menubar=no,location=no,resizable=yes,screenX=10,screenY=40,top=10,left=40,scrollbars=no');
			logon_window.document.write('<span>Please wait...<img src="/ist_shared/ist_images/ist_icons/progress/indicator_arrows.gif"></span>');
			logon_window.window.focus()
			var oNewForm = make_form('file_viewer', sAction, sTarget)
			make_input(oNewForm, 'from_where','logout')
			oNewForm.submit()
		}
	}
	
function openLogonPerspective()
	{
		
		var sAction = '../../ist_auth/logon/logon_perspective.cfm'
		var sTarget = 'logon_perspective'
		h = setHeight(400);
		w = setWidth(600);
		small_window(sTarget,h,w)
		var oNewForm = make_form(event.srcElement.name, sAction, sTarget)		
		oNewForm.submit()		
	}
	



/* cookie code */
var expdate = new Date (2010,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 GetCookieV1 (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 SetCookieV1 (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookieV1 (name,path,domain) {
  if (GetCookieV1(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
/* END: cookie code */


/* /////////////////////////// Menu Code /////////////////////////// */

var context_p0 = new String();

// Submenu builder
function getPn_attributes(obj)
	{		
		for (i = 0; i < 5; i++)
			{				
				if(obj.attributes.p0)
					{break}
				else
					{obj = obj.parentElement}
			}
		
		for(i = 0; i < 10; i++)
			{				
				if(typeof eval('obj.p'+i) != 'undefined')
					{						
						pn = eval('obj.p'+i)
						eval('my_p'+i+' = pn')						
					}
				else if(typeof eval('obj.vAdj') != 'undefined')
					{						
						pn = eval('obj.vAdj')
						my_vAdj = pn						
					}

			}
			
		my_obj = obj;
		
		return obj;
	}


function get_context_menu(contextMenu)
	{
		
		// Detect an extender function
		try	{var CM_extender = eval(contextMenu+'_CM_extender')}
		catch(e)
			{var CM_extender = ''}
			
		var menu_passed = new Number();
		menu_passed = 1;
			
		// Clear the menu for reloading a different image	or content
		if(typeof dojo == 'object' && (CM_extender == 'displayThumbImage' || CM_extender == 'displayDocStorThumbImage'))
		{
			menu_div = document.getElementById("epdi_menu_wrap");
			dojo.dom.removeChildren(menu_div);		
		}
		
		//alert(typeof event.srcElement)
		//alert(typeof event.target)
		
		hide_select(1);
		var menu_obj = new Object();
		var menu_obj = event.srcElement;
		
		// This will set the my_pn variables and 
		// identify the object with the P0 attribute
		menu_obj = getPn_attributes(menu_obj);
		
		var menu_title_display_len = 30;

		//alert(menu_obj.p1)
		//alert(menu_obj.tagName)
		//alert(typeof eval(contextMenu+'_CM'))
		
		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)
						menu_title = menu_obj.title.substring(0,menu_title_display_len);
						if(menu_obj.title.length > menu_title_display_len);
							{menu_title += '...';}
						build_context_menu(contextMenu, menu_title);
					try
						{
							oContextMenu = eval(contextMenu+'_contextMenu');
						}
					catch(e)
						{
							menu_passed = 0;
						}
					}
				if(menu_passed == 1)
					{					
					menu_title = menu_obj.title.substring(0,menu_title_display_len);
					if(menu_obj.title.length > menu_title_display_len)
						{menu_title += '...';}
					mt = eval('document.all.'+contextMenu+'_epdi_menuTitle');
					mt.innerHTML = menu_title;
					oContextMenu.style.visibility='hidden';
					oContextMenu.style.display = 'block';
					
					m_up = vertical_position_adjust(event.clientY,oContextMenu.offsetHeight);
					
					if (typeof(my_vAdj) != 'undefined' && !isNaN(my_vAdj)) m_up = m_up+my_vAdj;
	
					if(menu_obj.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);
							

							var myScrollTop = 0;
							if(document.body.scrollTop > 0)
								{myScrollTop = document.body.scrollTop}
							else if (document.documentElement.scrollTop > 0)
								{myScrollTop = document.documentElement.scrollTop}

							
							oContextMenu.style.posLeft = event.clientX-5+document.body.scrollLeft-m_over;
							oContextMenu.style.posTop = event.clientY-5+myScrollTop-m_up;
						}
					
					oContextMenu.style.visibility='visible'
					}
			}
			else{
			
				// jev20050225
				if(typeof no_context == 'undefined'){
					no_context = 0;
				}
			
				if(no_context == 0)
					{
						alert('There are no additional menu items available through clicking your 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 myScrollTop = 0;
		if(document.body.scrollTop > 0)
			{myScrollTop = document.body.scrollTop}
		else if (document.documentElement.scrollTop > 0)
			{myScrollTop = document.documentElement.scrollTop}
		
		
		var mbottom = y+myScrollTop+object_width 
		var window_bottom = document.body.clientHeight+myScrollTop
		
	
		if(mbottom>window_bottom)
			{var m_up = mbottom-window_bottom}
		else
			{var m_up = 0}
		// Vertical		
	
		return m_up;
	}																

function build_context_menu(contextMenu, menu_title)
	{		
		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 = GetCookieV1('m1_sel')
		
	var CM = eval(contextMenu+'_CM')
	var CM_lbl = eval(contextMenu+'_CM_lbl')
	
	try	{var CM_extender = eval(contextMenu+'_CM_extender')}
	catch(e)
		{var CM_extender = ''}

	// 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)
		{
			//alert(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;
			
			if (row_cnt == 1)
				{	
					if(menu_title == null || menu_title == '')
						{
							var menu_title = new String('Menu');
						}
					//  Add a starting row
					//  Add a cell
					oCell[i] = oCell.cloneNode();
					oRow[row_cnt].appendChild(oCell[i]);
					oCell[i].style.paddingRight = 0;
					//oCell[i].epdi_button=contextMenu;
					oCell[i].epdi_isContextMenu=1;
					//  END Add a cell				

					oCell[i] = oCell.cloneNode();
					oRow[row_cnt].appendChild(oCell[i]);
					oCell[i].style.paddingLeft = 10
					oCell[i].style.paddingRight = 20
					oCell[i].style.paddingTop = 1
					oCell[i].style.paddingBottom = 2

					if(self.location.href.indexOf("istdocstor")!=-1 || self.location.href.indexOf("ist_docstor")!=-1 || self.location.href.indexOf("ist_auth")!=-1 || self.location.href.indexOf("ist_master_internal")!=-1)
						{setMenuClass = 'dsTitlebar28';}
					else
						{setMenuClass = 'titlebar';}

					oCell[i].className = setMenuClass
					oCell[i].epdi_isContextMenu=1;
					oCell[i].id = contextMenu+'_epdi_menuTitle';
					oCell[i].colspan = 1;
					oCell[i].align = 'center';
					oCell[i].insertAdjacentText('beforeEnd', menu_title);

					//  Add a cell
					oCell[i] = oCell.cloneNode();
					oRow[row_cnt].appendChild(oCell[i]);
					oCell[i].style.paddingRight = 0;
					//oCell[i].epdi_button=contextMenu;
					oCell[i].epdi_isContextMenu=1;
					//  END Add a cell
					//  END: Add a starting row
										
					oTBody[0].appendChild(oRow[row_cnt]);			
					row_cnt++
					oRow[row_cnt] = oRow.cloneNode();
					oRow.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 = 0;
					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.paddingLeft = 10
					oCell[i].style.paddingRight = 20
					oCell[i].style.paddingTop = 1
					oCell[i].style.paddingBottom = 2
					oCell[i].style.color = 'menutext'

					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].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];
															
					if(typeof eval(CM_extender) == 'function' && i == 0)
					{eval(CM_extender+'(oCell[i],contextMenu, CM[i])')}
					
					//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 = 0;
					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();								

						}
	
				}
			}

					//  Add an ending cell
					oCell[i] = oCell.cloneNode();
					oRow[row_cnt].appendChild(oCell[i]);
					oCell[i].style.paddingRight = 0;
					oCell[i].epdi_isContextMenu=1;
					oCell[i].colspan = 3;
					//  END: Add an ending cell
					oTBody[0].appendChild(oRow[row_cnt]);
					
					
		try{
				if(typeof(epdi_menu_wrap.style) != "undefined")
					{
						document.getElementById("epdi_menu_wrap").appendChild(oTable);
					}
					else
					{
						alert('The Menu Wrap Div is either missing or duplicated (1)');
					}
			}
		
		catch(e)   {alert('The Menu Wrap Div is either missing or duplicated (2)');}
				
		//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'
					hide_select(0)
				}
		}
	}
// END submenu builder


/* Hide select */
function hide_select(action)
	{ 
		for(var fi=0;fi<document.getElementsByTagName("SELECT").length;fi++)
			{
				if(action == 1)
					{document.getElementsByTagName("SELECT")[fi].style.visibility='hidden'}
				else
					{document.getElementsByTagName("SELECT")[fi].style.visibility='visible'}
			}
	}
/* END: Hide select */


//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 = 'menutext'
						event.srcElement.style.fontWeight='normal'
					}
				else
					{
						event.srcElement.className = 'gray'
						event.srcElement.style.color = 'menutext'
						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 = 'inactivecaptiontext'
										event.srcElement.style.fontWeight=500
									}
							}
						else
							{							
								event.srcElement.className = 'focus';
								event.srcElement.style.color = 'inactivecaptiontext'
								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()}
	
									}
									
								//SetCookieV1 ("m1_srch", frm_menu.menu1_txt.value,expdate,"/")
								//SetCookieV1 ("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 = GetCookieV1('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)
									{
										SetCookieV1 ("m1_act", "0",expdate,"/");		
									}
								else
									{
										if(retain_menu == 0)
											{
												//epdi_menu.style.display='none'
												SetCookieV1 ("m1_state", "none",expdate,"/");		
											}
									}				
						}	// button == 1
						else // right click image
							{
								if(event.button==2)
									{
										menu_status = 0
										get_context_menu(event.srcElement.name)
									}
							}
					
					}
				}
	
			}		
	}
	


function standard_menu_cm()
	{				
		if(typeof event.srcElement.index != 'undefined')
			{
				x = event.srcElement.index
				button = event.srcElement.epdi_button
				standard_menu(eval(button+'_CM_p0['+x+']'))
			}
	}

function standard_menu(path, sTarget)
	{	
		if(sTarget=='' || sTarget == null)
			{sTarget='_parent'}		

		var sAction = myhttp_mode+':/'+'/'+mydomain_data_path+path
		var oNewForm = make_form(event.srcElement.name, sAction, sTarget)
		oNewForm.submit()	
	}


/* END: /////////////////////////// Menu Code /////////////////////////// */




/* /////////////////////////// Date Parsing Code /////////////////////////// */


function formatDate(dateString) 
	{
		var day = new String();
		var month = new String();
		var year = new String();
		
		
		var re = '/\//g';		
		dateString = dateString.replace(re,"-")
				
		var findDate = Date.parse(dateString);
		
		if(isNaN(findDate)) 
			{findDate = parseDateString(dateString); }
		
		var theDateObj = new Date(findDate);

		month = theDateObj.getMonth()+1;
		if(month < 10) month = '0'+month
		
		day = theDateObj.getDate();
		if(day < 10) day = '0'+day
		
		year = theDateObj.getYear();
		if(year < 10) year = '200'+year
		else if(year < 40) year = '20'+year
		
		return month+'-'+day+'-'+year;
	}		


/* 'Magic' date parsing, by Simon Willison (6th October 2003)
   http://simon.incutio.com/archive/2003/10/06/betterDateInput
*/

/* Finds the index of the first occurence of item in the array, or -1 if not found */
/*

----- This has been disabled because the Array prototype is crashing into the editor js 
----- I think both are poorly written!!


Array.prototype._indexOf = function(item) { // May need to remove the _ from _indexOf - when present conflicts with editor
    for (var i = 0; i < this.length; i++) {
        if (this[i] == item) {
            return i;
        }
    }
    return -1;
};
/ Returns an array of items judged 'true' by the passed in test function /
Array.prototype._filter = function(test) { // May need to remove the _ from _filter - when present conflicts with editor
    var matches = [];
    for (var i = 0; i < this.length; i++) {
        if (test(this[i])) {
            matches[matches.length] = this[i];
        }
    }
    return matches;
};

var monthNames = "January February March April May June July August September October November December".split(" ");
var weekdayNames = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");

/ Takes a string, returns the index of the month matching that string, throws
   an error if 0 or more than 1 matches
/
function parseMonth(month) {
    var matches = monthNames._filter(function(item) { 
        return new RegExp("^" + month, "i").test(item);
    });
    if (matches.length == 0) {
        throw new Error("Invalid month string");
    }
    if (matches.length > 1) {
        throw new Error("Ambiguous month");
    }
    return monthNames._indexOf(matches[0]);
}
/ Same as parseMonth but for days of the week /
function parseWeekday(weekday) {
    var matches = weekdayNames._filter(function(item) {
        return new RegExp("^" + weekday, "i").test(item);
    });
    if (matches.length == 0) {
        throw new Error("Invalid day string");
    }
    if (matches.length > 1) {
        throw new Error("Ambiguous weekday");
    }
    return weekdayNames._indexOf(matches[0]);
}
*/

/* Array of objects, each has 're', a regular expression and 'handler', a 
   function for creating a date from something that matches the regular 
   expression. Handlers may throw errors if string is unparseable. 
*/
var dateParsePatterns = [
    // Today
    {   re: /^tod/i,
        handler: function() { 
            return new Date();
        } 
    },
    // Tomorrow
    {   re: /^tom/i,
        handler: function() {
            var d = new Date(); 
            d.setDate(d.getDate() + 1); 
            return d;
        }
    },
    // Yesterday
    {   re: /^yes/i,
        handler: function() {
            var d = new Date();
            d.setDate(d.getDate() - 1);
            return d;
        }
    },
    // 4th
    {   re: /^(\d{1,2})(st|nd|rd|th)?$/i, 
        handler: function(bits) {
            var d = new Date();
            d.setDate(parseInt(bits[1], 10));
            return d;
        }
    },
    // 4th Jan
    {   re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i, 
        handler: function(bits) {
            var d = new Date();
            d.setDate(parseInt(bits[1], 10));
            d.setMonth(parseMonth(bits[2]));
            return d;
        }
    },
    // 4th Jan 2003
    {   re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+),? (\d{4})$/i,
        handler: function(bits) {
            var d = new Date();
            d.setDate(parseInt(bits[1], 10));
            d.setMonth(parseMonth(bits[2]));
            d.setYear(bits[3]);
            return d;
        }
    },
    // Jan 4th
    {   re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i, 
        handler: function(bits) {
            var d = new Date();
            d.setDate(parseInt(bits[2], 10));
            d.setMonth(parseMonth(bits[1]));
            return d;
        }
    },
    // Jan 4th 2003
    {   re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?,? (\d{4})$/i,
        handler: function(bits) {
            var d = new Date();
            d.setDate(parseInt(bits[2], 10));
            d.setMonth(parseMonth(bits[1]));
            d.setYear(bits[3]);
            return d;
        }
    },
    // next Tuesday - this is suspect due to weird meaning of "next"
    {   re: /^next (\w+)$/i,
        handler: function(bits) {
            var d = new Date();
            var day = d.getDay();
            var newDay = parseWeekday(bits[1]);
            var addDays = newDay - day;
            if (newDay <= day) {
                addDays += 7;
            }
            d.setDate(d.getDate() + addDays);
            return d;
        }
    },
    // last Tuesday
    {   re: /^last (\w+)$/i,
        handler: function(bits) {
            throw new Error("Not yet implemented");
        }
    },
    // mm/dd/yyyy (American style)
    {   re: /(\d{1,2})\/(\d{1,2})\/(\d{4})/,
        handler: function(bits) {
            var d = new Date();
            d.setYear(bits[3]);
            d.setDate(parseInt(bits[2], 10));
            d.setMonth(parseInt(bits[1], 10) - 1); // Because months indexed from 0
            return d;
        }
    },
    // yyyy-mm-dd (ISO style)
    {   re: /(\d{4})-(\d{1,2})-(\d{1,2})/,
        handler: function(bits) {
			var dStr = parseInt(bits[2], 10)+"-"+parseInt(bits[3], 10)+"-"+parseInt(bits[1])
            var d = new Date(dStr);
            //d.setYear(parseInt(bits[1]));
            //d.setDate(parseInt(bits[3], 10));
            //d.setMonth(parseInt(bits[2], 10) - 1);

            return d;
        }
    },
];

function parseDateString(s) {
    for (var i = 0; i < dateParsePatterns.length; i++) {
        var re = dateParsePatterns[i].re;
        var handler = dateParsePatterns[i].handler;
        var bits = re.exec(s);
        if (bits) {
            return handler(bits);
        }
    }
    throw new Error("Invalid date string");
}

/* END: /////////////////////////// Date Parsing Code /////////////////////////// */

/* ================================= AJAX ================================== */

function ajax_json_fetch(sActionCFM, json_element_handler, element_id, sync_type)
	{
		// Prerequisites:	(1) sActionCFM is a CFM built for a specified task
		//						Example value: "/ist_docstor/ajax/docStorFileListData.cfm"
		//					(2) json_element_handler is the javascript function that process the returned json data (eg. ajax_table_load)
		//					(3) element_id is the name of the element you wish to load (could be a table, a select, etc.)
		// Sync: True, False

		var sAction = js_http_mode + "://" + js_theHttpHost + sActionCFM;
		var sTarget = ''		// leave blank to ensure no conflicts with multiple calls
		var sName = 'ajax_dynamic'
		var oNewForm = make_form(sName, sAction, sTarget)
			
		make_input(oNewForm, 'from_where','json_load')
		
		//unremark to see JSON Data
		//oNewForm.submit();
		//return;
		
		dojo.io.bind({
			formNode: oNewForm,
			sync: sync_type,				// do all your work before the next process
			handle: function(type, ajaxDataJSON, evt)
			{
				if(type == "load")
					{											
						eval(json_element_handler+'(element_id, ajaxDataJSON)');	
						//alert(json_element_handler);														
					}
				else if(type == "error")
					{								
						alert(type+"\n\n"+evt.message+"\n\n"+sAction)
					}						
				else
					{
						alert(type+"\n\n"+sAction)
					}
			},
			mimetype: "text/json"
		});	
	}					


function ajax_table_load(table_id, json_recordset, noTrim)
	{
		// Pre-requisites: 	(1) <table> element with unique ID
		// 					(2) first <tbody> ID set to "tbody_header_fixed"
		//					(3) 2nd <tbody> and all subsequent "tbody_row_{table key of the record}"
		//					(4) Within 2nd <tbody> the first row (<tr>) must have all <td> elements with ID equal to ucase(field_name) to match json_recordset 
		fileListTable = document.getElementById(table_id);
		retainTbody = fileListTable.document.getElementById("tbody_header_fixed");	
		var findPatternTbody = "";		
		for(var i=0;i<10;i++)		// i<10 is arbitary count in order to find 1st instance of <tbody> like ID="tbody_row_"
			{				
				findPatternTbody = fileListTable.childNodes[i]	
				if(findPatternTbody.tagName == 'TBODY' && findPatternTbody.id.substring(0,10) == 'tbody_row_')
					{patternTbody = findPatternTbody;break;}
			}
		dojo.dom.removeChildren(fileListTable);			
		fileListTable.appendChild(retainTbody);		
		var c1 = '#FFFFFF';		// alternating row columns
		var c2 = '#CCCC99';
		var c = c1;
		
		//columnArray = json_recordset.COLUMNLIST.split(",");

		for(var i=0;i<json_recordset.RECORDCOUNT;i++)
		{
			c == c1 ? c = c2 : c= c1;			
			newTbody = patternTbody.cloneNode(1);
			tr = newTbody.firstChild;			
			for(var iTD = 0;iTD<tr.childNodes.length;iTD++)
				{
					td = tr.childNodes[iTD];
					if(typeof(json_recordset.DATA[td.id]) != 'undefined') 
						{
							td.innerText = json_recordset.DATA[td.id][i];
							td.title = td.innerText;
							if(td.innerText.length > 30) td.innerText = td.innerText.substr(0,30)+"...";
							if(td.title == '') td.title = td.innerText;
						}
				}
		
			newTbody.id = "document_"+i;
			newTbody.childNodes[0].bgColor = c;
			fileListTable.appendChild(newTbody);
		}
	}

function ajax_select_load(select_id, json_recordset)
	{
		// Pre-requisites: 	(1) <table> element with unique ID
		// 					(2) first <tbody> ID set to "tbody_header_fixed"
		//					(3) 2nd <tbody> and all subsequent "tbody_row_{table key of the record}"
		//					(4) Within 2nd <tbody> the first row (<tr>) must have all <td> elements with ID equal to ucase(field_name) to match json_recordset 
		selectElement = document.getElementById(select_id);
		dojo.dom.removeChildren(selectElement);			
		
		for(var i=0;i<json_recordset.RECORDCOUNT;i++)
		{	
			selectElement.options[i] = new Option(json_recordset.DATA.SELECT_TEXT[i], json_recordset.DATA.SELECT_VALUE[i]);
		}
	}
/* END: /////////////////////////// AJAX /////////////////////////// */


function genericColumnUpdate(columnId, rowId)
	{
		var sAction = js_http_mode + "://" + js_theHttpHost + "/ist_auth/ajax/genericTableUpdate.cfm";
		var sTarget = '';
		var sName = 'ajax_dynamic';
		var oNewForm = make_form(sName, sAction, sTarget);

		var p99 = '';
		var objInput = document.getElementById(columnId);
		var columnName = objInput.name;
		var columnValue = objInput.value;
		var tableName = columnName.split('_dx_')[0];
		
	
		// Firefox approach to finding attribute p0
		//  May be a better approach
		for(var i=0; i<objInput.attributes.length;i++)
			{
				if(objInput.attributes[i].name == 'p99') 
					{p99 = objInput.attributes[i].value; break;}
			}

		//IE approach... if(typeof(objInput.p0) != 'undefined') p0 = objInput.p0;
	
		make_input(oNewForm, tableName+'_dx_'+tableName+'_id', rowId);
		make_input(oNewForm, columnName, columnValue);
		make_input(oNewForm, 'tableName', tableName);
		make_input(oNewForm, 'from_where','updateField');
		make_input(oNewForm, 'p99', p99);
		make_input(oNewForm, 'useSmartForm',1);
		
		//oNewForm.submit(); return;
		
		dojo.io.bind({
			formNode: oNewForm,
			useCache: false,
			handle: function(type, ajaxData, evt)
			{
				if(type == "load")
					{		
						var taskMsg = new String();
						var myXLMDoc = dojo.dom.createDocumentFromText(ajaxData);
						var XMLRoot = myXLMDoc.documentElement;
						if(XMLRoot && XMLRoot.firstChild && XMLRoot.firstChild.data)
							{
								taskMsg = XMLRoot.firstChild.data;
								try{eval(taskMsg);}
								catch(e){alert(taskMsg);}
							}
														
					}
				else if(type == "error")
					{								
						alert(type+"\n\n"+evt.message+"\n\n"+sAction)
					}						
				else
					{
						alert(type+"\n\n"+sAction)
					}
			},
			mimetype: "text/html"
		});

	}


function globalNoEditAllowed(obj)
	{
		alert('This Record is locked.\n\nYour Edit has not been saved.');
		var sourceId = obj.id;
		var sourceParts = sourceId.split("_");
		var targetId = ""; sourcePart = new Number(); underScore = "";
		for (sourcePart in sourceParts)
			{						
				if(sourcePart == sourceParts.length-1) {targetId = targetId+underScore+'span';}
				targetId = targetId+underScore+sourceParts[sourcePart];
				underScore = "_";
			}

		if(document.getElementById(targetId)) {obj.value = document.getElementById(targetId).innerText;}
		else if(obj.tagName == 'SELECT') {obj.value = obj.options[0].value;}
	}

function doIoBind_XmlAlertC1(oNewForm, sync_type)
	{
		// Sync: True, False
		if(sync_type == null || sync_type == '') sync_type = false;
	
		dojo.io.bind({
			sync: sync_type,
			formNode: oNewForm,			
			handle: function(type, ajaxData, evt)
			{
				if(type == "load")
					{								
						var taskMsg = new String();
						var myXLMDoc = dojo.dom.createDocumentFromText(ajaxData);
						var XMLRoot = myXLMDoc.documentElement;
						if(XMLRoot && XMLRoot.firstChild && XMLRoot.firstChild.data)
							{
								taskMsg = XMLRoot.firstChild.data;
								try{eval(taskMsg);}
								catch(e){alert(taskMsg);}								
							}
														
					}
				else if(type == "error")
					{								
						alert(type+"\n\n"+evt.message+"\n\n"+sAction)
					}						
				else
					{
						alert(type+"\n\n"+sAction)
					}
			},
			mimetype: "text/html"
		});				

	}
	
function doIoBind_XmlDataC1(oNewForm, sync_type)
	{
		taskData = "";
		
		// Sync: True, False
		if(sync_type == null || sync_type == '') sync_type = false;
	
		dojo.io.bind({
			sync: sync_type,
			formNode: oNewForm,			
			handle: function(type, ajaxData, evt)
			{
				if(type == "load")
					{								
						var taskMsg = new String();
						var myXLMDoc = dojo.dom.createDocumentFromText(ajaxData);
						var XMLRoot = myXLMDoc.documentElement;
						if(XMLRoot && XMLRoot.firstChild && XMLRoot.firstChild.data)
							{
								taskData = XMLRoot.firstChild.data;								
							}
														
					}
				else if(type == "error")
					{								
						alert(type+"\n\n"+evt.message+"\n\n"+sAction)
					}						
				else
					{
						alert(type+"\n\n"+sAction)
					}
			},
			mimetype: "text/html"
		});	
		
		return taskData;

	}
	
function reloadPageGeneric()
	{
		var sAction = '';
		var sTarget = '_self';
		var sName = 'frm';
		var oNewForm = make_form(sName, sAction, sTarget);
		oNewForm.submit();
	}

/* TIMER FUNCTIONS */

var timerID = 0;
var tStart  = null;
var tEnd = 300;	// in seconds

function UpdateTimer() {
   if(timerID) {
	  clearTimeout(timerID);
	  clockID  = 0;
   }
   if(!tStart)
	  tStart   = new Date();
   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();
   tDate.setTime(tDiff);
   sec_lapse = tDate.getMinutes()*60 + tDate.getSeconds();
   if(sec_lapse > tEnd){
		TimerAutoClose(); return;
   }
   min_left = parseInt((tEnd-sec_lapse)/60);
   sec_left = parseInt((((tEnd-sec_lapse)/60)-min_left)*60);
   objTimerDisplay = document.getElementById("theTimer")
   if (objTimerDisplay != null){
	   if (sec_left < 10) {
			objTimerDisplay.value = min_left.toString() + ":0" + sec_left.toString();
	   }
	   else {
			objTimerDisplay.value = min_left.toString() + ":" + sec_left.toString();
	   }
   }
   timerID = setTimeout("UpdateTimer()", 10000);	// 1 second intervals
}

function TimerStart(nSeconds) {
   tStart   = new Date();
   if (nSeconds != null){
	tEnd = nSeconds
   }
   timerID  = UpdateTimer();	// 1 second intervals
}

function TimerStop() {
   if(timerID) {
	  clearTimeout(timerID);
	  timerID  = 0;
   }	
   tStart = null;
}

function TimerReset() {
   tStart = null;	
   timerID  = UpdateTimer();
   
}

function TimerAutoClose(){
	window.open('','_parent','');
	top.close();
}

/* ///////////////////////////////// END TIMER FUNCTIONS /////////////////////// */

/* /////////////////////////////////FUNCTIONS USED IN MSPT ///////////////////////*/

function IsNumeric(value)
{
	if (isNaN(value))
	{
		return false
	}
	else
	{
		return true
	}
}

function CheckEmail(Email)
{	
	if (trim(Email).length>0)
	{
		if (Email.indexOf("@")==-1 || Email.indexOf(".")==-1)
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

//removed the leading and trailing spaces froma string
function trim(input)
{
	if(input) return input.replace(/^\s+|\s+$/g,"")
}

//Validate a date to make sure that a valid date is passed and the year is before the passed year
function IsDate(DateValue)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var dateMatch=DateValue.match(datePat)
	
	if (dateMatch!=null)
	{
		dateMatch[1]=parseInt(dateMatch[1]);
		dateMatch[3]=parseInt(dateMatch[3]);
		dateMatch[5]=parseInt(dateMatch[5]);
		
		if ((dateMatch[1]<0) || (dateMatch[1]>12))
		{
			return false;
		}
		
		if ((dateMatch[3]<0) || (dateMatch[3]>31))
		{
			return false;
		}
		//For April,June,September,November
		if ((dateMatch[1]==4) || (dateMatch[1]==6)|| (dateMatch[1]==9) ||(dateMatch[1]==11))
		{
			if (dateMatch[3]>30)
			{
				return false;
			}
		}
		else
		{
			if (dateMatch[1]==2)
			{
				if (dateMatch[3]>29)
				{
					return false;
				}
				if ((dateMatch[5]%4)>0)
				{
					if (dateMatch[3]>28)
					{
						return false;
					}
				}
			}
		}
	}
	else
	{
		return false;	
	}
	return true;
}

function CompareDate(First,Second)
{
	var First= new Date(First)
	var Second= new Date(Second)
	
	if (First.getFullYear()<Second.getFullYear())
	{
		return "First Less than Second"
	}
	else
	{
		if (First.getFullYear()>Second.getFullYear())
		{
				return "First Greater than Second"
		}
		else
		{
			if (First.getMonth()<Second.getMonth())
			{
				return "First Less than Second"
			}
			else
			{
				if (First.getMonth()>Second.getMonth())
				{
					return "First Greater than Second"
				}
				else
				{
					if (First.getDate()<Second.getDate())
					{
						return "First Less than Second"
					}
					else
					{
						if (First.getDate()>Second.getDate())
						{
							return "First Greater than Second"
						}
						else
						{
							return "Both are equal"
						}
					}
				}
			}
		}
	}
}

//TO SHOW THE INFO OF PACKAGES
function GetInfoFor(internalId,InOrOut)
{		
	var sAction = new String();

	if (InOrOut=='In')
	{
		sAction = '/IST/MSPT/IncomingPackage.cfm'
	}
	else
	{
		sAction = '/IST/MSPT/outgoingPackage.cfm'
	}
	
	var sTarget = '_self'

	var oNewForm = make_form('fx', sAction, sTarget)			
	make_input(oNewForm, 'from_where','Search')
	make_input(oNewForm, 'InternalId',internalId)
	oNewForm.submit()		
}

/* /////////////////////////////////END OF FUNCITONS USED IN MSPT ////////////////////////////////*/

