////////////////////////////////////////////////////////
// common.js
//
// This file contains JavaScript helper functions that 
// are used throughout the application.
//
////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////
// Global variables for this JS file - all must be
// preceeded by common_global_ to ensure no collisions.
// These variables are intended to be referenced outside
// of this file by JSP pages that include this JS file.
////////////////////////////////////////////////////////


// default callback function for cancelation of reason code
var common_global_onReasonCodeCancelCallback = 
	function()
	{
	
	}
// default callback function for submission of reason code
var common_global_onReasonCodeSubmitCallback = 
	function()
	{
	
	}

var common_global_fieldSeparatorChar = "\x1F";

////////////////////////////////////////////////////////
// Local variables for this JS file - all must be
// preceeded by common_local_ to ensure no collisions.
// These variables are NOT to be referenced outside
// of this file.
////////////////////////////////////////////////////////

// Used to stop navigation
var common_local_disableNav = false;
// Array of pointers to actual frame instances
var common_local_framePointers = null;
// Stores the master tab index for dynamically generating HTML
var common_local_tabIndex = "0";
// Array of HTML sections to detect changes
var common_local_HTMLState = null;
// Stores the current date from the system
var common_local_currentDate = null;
// Maximum and minimum values for an integer in Java
var common_local_maxint = 2147483647;
var common_local_minint = -2147483647;
// Stores nav menus
var common_local_navMenus = null;
var common_local_navMenusTimeoutId = null;
var common_local_submitcounter = 0;
var common_local_http_request = false;
var common_ping_count = 0;

////////////////////////////////////////////////////////
// Function: common_makeAjaxRequest
// Description:
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_makeAjaxRequest(param_geturl, param_returnHandler) 
{
		param_geturl = param_geturl + "&submitcounter=" + common_local_submitcounter + "&AJAX=true";
		common_local_submitcounter++;

		common_local_http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
		 common_local_http_request = new XMLHttpRequest();
		 if (common_local_http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
		  common_local_http_request.overrideMimeType('text/html');
		 }
		} else if (window.ActiveXObject) { // IE
		 try {
		    common_local_http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
		    try {
		       common_local_http_request = new ActiveXObject("Microsoft.XMLHTTP");
		    } catch (e) {}
		 }
		}
		if (!common_local_http_request) {
		 alert('Cannot handle your request! Your browser is likely too old.');
		 return false;
		}
		common_local_http_request.onreadystatechange = param_returnHandler;		
		common_local_http_request.open('GET', param_geturl, true);
		common_local_http_request.send(null);
}


function common_ajaxPingReturn()
{
		if (common_local_http_request.readyState == 4) 
		{
			if (common_local_http_request.status == 200) 
			{
				common_startAjaxPing();
			} else 
			{
				alert('There was a problem handling your request. Please try again. (01)');
			}
		}
		return false;
}


function common_doAjaxPing()
{
	common_makeAjaxRequest("/ajaxping.cfm?count=" + common_ping_count, common_ajaxPingReturn);
	common_ping_count++;
}


function common_startAjaxPing()
{
	common_setInnerHTML(null, '_id_pingStatus', "Status OK(" + common_ping_count + ")");
	setTimeout('common_doAjaxPing()', 300000)
}


////////////////////////////////////////////////////////
// Function: common_getFrameReadyState
// Description: convenience method to get the ready state
// of the primary document in a frame 
// returns frame.document.readyState
// Parameters: 
// param_frameName = name of frame to check
// Returns: document.readyState
////////////////////////////////////////////////////////
function common_getFrameReadyState( param_frameName )
{
	var frameObj = common_local_getFramePointer(param_frameName);
	if( frameObj != null && frameObj.document != null )
	{
		return frameObj.document.readyState;
	}

	return null;
}

////////////////////////////////////////////////////////
// Function: common_submitTest()
// Description: makes sure all test questions are answered
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_submitTest(param_form)
{
	var elementCount = param_form.elements.length;
	var field = null;
	var name = null;
	var fieldsNotDone = 0;
	
	for( var i = 0; i < elementCount; i++ )
	{
		field = param_form.elements[i];
	
		if( field.type == "radio" || field.type == "checkbox" )
		{
			if(field.checked == false)
			{
				var fldname = field.name;
				var ischecked = false;
				for( var j = 0; j < elementCount; j++ )
				{
					if(i != j && param_form.elements[j].name == fldname && param_form.elements[j].checked == true)
					{	
							ischecked = true;
							break;
					}
				}
				if(ischecked == false)
				{
					fieldsNotDone++;	
				}
			} 
		} else if( field.type == "text" || field.type == "textarea" )
		{
			if(common_isNotEmpty(field, null) == false)
			{
				fieldsNotDone++;
			}
		}
	}
	if(fieldsNotDone > 0)
	{
		alert("There are questions you have not answered.\nPlease answer all of the questions and click 'Submit' again.");	
		return false;
	}
	
	return true;
}

////////////////////////////////////////////////////////
// Function: common_printDocument()
// Description: sends a DOM document to the printer 
// (prints the current page)
// Parameters: 
// param_document - document to print;
// Returns:
////////////////////////////////////////////////////////
function common_printDocument( param_document )
{
	if( param_document.parentWindow != null )
	{
		param_document.parentWindow.print();
	}
}

////////////////////////////////////////////////////////
// Function: common_setMultiSelectCheckedState()
////////////////////////////////////////////////////////
function common_validatePayment(param_maxamount, param_amount, param_ctx)
{
	if(param_maxamount != null)
		if(!common_isAFloat(param_maxamount)) 
		{
			alert("Maximum payment amount is not valid.");
			return false;
		}

	if(!common_isAFloat(param_amount)) 
	{
		alert("Payment amount is not valid.");
		return false;
	}

	if(param_maxamount != null)
	{		
		var retVal = parseFloat(param_maxamount.value) - parseFloat(param_amount.value);
		if(retVal < 0)
		{
			alert("The amount to pay must be less than your account balance ($" + param_maxamount.value + ")"); 
			return false;
		}
	}
	
	if(param_ctx != null)
	{
		if(param_ctx == "NECI")
		{
			param_ctx = "This payment will be applied to outstanding NECI registration balances.\nIf you are intending to make a payment for an NEAWP membership, this is not the correct payment form.\nDo you wish to continue to make a payment to NECI?";					
		} else
		{
			param_ctx = "This payment will be applied to outstanding NEAWP membership balances.\nIf you are intending to make a payment for an NECI registration, this is not the correct payment form.\nDo you wish to continue to make a payment to NEAWP?";		
		}
	  if(common_confirmPrompt(param_ctx) == false)
	  {
	  	return false;
	  }
	}
	
	return true;
}

////////////////////////////////////////////////////////
// Function: common_setMultiSelectCheckedState()
// Description: set the checked state of a set of checkbox 
// inputs most commonly used in multi select components
// Parameters: 
// param_form - form where checkboxes are contained
// param_checkbox_name - name of checkbox or regexp to select
// checbox name
// param_checkedState - true or false
// Returns:
////////////////////////////////////////////////////////
function common_setMultiSelectCheckedState( param_form, param_checkbox_name, param_checkedState )
{
	var elementCount = param_form.elements.length;
	var field = null;
	var name = null;
	
	for( var i = 0; i < elementCount; i++ )
	{
		field = param_form.elements[i];
	
		if( (field.type == "checkbox")  && (field.name.search( param_checkbox_name ) != -1) )
		{
			field.checked = param_checkedState;
		}
		
	}
}

////////////////////////////////////////////////////////
// Function: common_addRefreshParam(url)
// Description: adds a parameter with some random data
// to ensure that url is refreshed by the browser
// Parameters: 
// url - url to add parameter to 
// Returns: new url with parameter 
////////////////////////////////////////////////////////

function common_addRefreshParam( url )
{
	if( url.indexOf( "?" ) == -1 )
	 url += "?";
	else
	 url += "&";
	 
	var date = new Date();
	url += "refresh=" + date.getTime();
	return url;
}


////////////////////////////////////////////////////////
// Function: common_openSpaceSaverTooltip()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_openSpaceSaverTooltip(param_common_startelement, param_common_text)
{

}

////////////////////////////////////////////////////////
// Function: common_closeSpaceSaverTooltip()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_closeSpaceSaverTooltip()
{

}


////////////////////////////////////////////////////////
// Function: common_cancelReasonCode
// Description: 
// Parameters: 
//	
// Returns: 
////////////////////////////////////////////////////////
function common_cancelReasonCode()
{
	if( common_global_onReasonCodeCancelCallback != null )
		common_global_onReasonCodeCancelCallback();
	
	common_disableHTML(null, '_id_reasonCode');
	common_enableHTML(null, '_id_form');
}

////////////////////////////////////////////////////////
// Function: common_setSubmitReasonCodeCallback
// Description: sets callback function for reason code submission
// Parameters: callbackFunc - reference to callback function
//	
// Returns: 
////////////////////////////////////////////////////////
function common_setSubmitReasonCodeCallback( callbackFunc )
{
	common_global_onReasonCodeSubmitCallback = callbackFunc;
}

////////////////////////////////////////////////////////
// Function: common_setCancelReasonCodeCallback
// Description: sets callback function for reason code cancelation
// Parameters: callbackFunc - reference to callback function
//	
// Returns: 
////////////////////////////////////////////////////////
function common_setCancelReasonCodeCallback( callbackFunc )
{
	common_global_onReasonCodeCancelCallback = callbackFunc;
}

////////////////////////////////////////////////////////
// Function: common_promptReasonCode
// Description: 
// Parameters: 
//	
// Returns: 
////////////////////////////////////////////////////////
function common_promptReasonCode(common_param_frame)
{
	common_endValidateWorkspaceForm();
	common_endValidatePopupForm();
	common_disableHTML(common_param_frame, '_id_form');
   	common_disableHTML(common_param_frame, '_id_user_action_message');
   	common_disableHTML(common_param_frame, '_id_struts_errors');
   	common_disableHTML(common_param_frame, '_id_all_conflicts');
	common_enableHTML(common_param_frame, '_id_reasonCode');
	return false;
}

////////////////////////////////////////////////////////
// Function: common_processReasonCode
// Description: 
// Parameters: 
//	
// Returns: 
////////////////////////////////////////////////////////
function common_processReasonCode()
{
   	var wForm = document.forms[common_local_workspaceFormName];
    var rcForm = document.forms["reasonCode"];
   
   	if(common_isNotEmpty(rcForm.reasonCode, null) == false)
	{ 
		common_showDataError("Please enter a Change Reason.");
		return false;
	}
	if(common_checkLength(rcForm.reasonCode, null, 255) == false)
	{
		common_showDataError("Change Reason must be less than 255 characters long.");
		return false;
	}
	
	if( common_global_onReasonCodeSubmitCallback != null )
		common_global_onReasonCodeSubmitCallback();
		
	common_setFormField(wForm.reasonCode, rcForm.reasonCode.value);
	common_submitWorkspaceForm(wForm);
	return false;
}

////////////////////////////////////////////////////////
// Function: common_cancelConflicts
// Description: 
// Parameters: 
//	
// Returns: 
////////////////////////////////////////////////////////
function common_cancelConflicts()
{
	common_disableHTML(common_global_workspaceFrameObject, '_id_all_conflicts');
	common_setInnerHTML(common_global_workspaceFrameObject, '_id_conflict_list', "")
	common_enableHTML(common_global_workspaceFrameObject, '_id_form');
}

////////////////////////////////////////////////////////
// Function: common_processConflicts
// Description: 
// Parameters: 
//	
// Returns: 
////////////////////////////////////////////////////////
function common_processConflicts()
{
   var frame = common_local_getFramePointer(common_global_workspaceFrameObject);

   	if(frame != null)
   	{
    	var wForm = frame.document.forms[common_local_workspaceFormName];
    	var cForm = frame.document.forms["conflicts"];
   	}
    var len = cForm.length;
	for(var lpctr=0; lpctr<len; lpctr++)
	{
		var formfield = cForm[lpctr];
		var fieldID = formfield.getAttribute("name");
		
		// It's possible that there are 2 Conflict Resolutions for
		// a single item (name) because you can change both the
		// start and end date of an object which will require that
		// the prev and next neighbors be adjusted or gaps filled.
		// So, get the current value of the field and ADD the new
		// resolution to it.
		if(fieldID.indexOf("_conflictResolution") != -1)
		{
			var outval = common_getFormFieldById(fieldID);
			if(outval != "")
			{
				outval = outval + "," + formfield.value;
			} else
			{
				outval = formfield.value;
			}	
			common_setFormFieldById(fieldID, outval);
		}
	}
		
	common_promptReasonCode();
	
	return false;
}

////////////////////////////////////////////////////////
// Function: common_getHTMLState()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getHTMLState(param_section)
{
	alert("common_getHTMLState: This method has been depricated.");
}

////////////////////////////////////////////////////////
// Function: common_saveHTMLState()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_saveHTMLState(param_section)
{
	alert("common_saveHTMLState: This method has been depricated.");
}

////////////////////////////////////////////////////////
// Function: common_compareHTMLState()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_compareHTMLState(param_section)
{
	alert("common_compareHTMLState: This method has been depricated.");
}

////////////////////////////////////////////////////////
// Function: common_getHTMLValueFromGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getHTMLValueFromGroup(param_common_group, param_common_id)
{
	var val = "";
	var grp = common_getHTMLGroup(param_common_group);
	if(grp == null) alert("GRP IS NULL: " + param_common_group);
	var len = grp.length;
	for(var x=0;x<len;x++)
	{
		var valarray = grp[x];
		if(valarray["name"] == param_common_id)
		{
			val = valarray["value"];
			return val;
		}
	}
	return val;
}

////////////////////////////////////////////////////////
// Function: common_getHTMLValueFromNewGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getHTMLValueFromNewGroup(param_common_group, param_common_id)
{
	var val = "";
	var grp = param_common_group;
	var len = grp.length;
	for(var x=0;x<len;x++)
	{
		var valarray = grp[x];
		if(valarray["name"] == param_common_id)
		{
			val = valarray["value"];
			return val;
		}
	}
	return val;
}

////////////////////////////////////////////////////////
// Function: common_getHTMLGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getHTMLGroup(param_common_group)
{
	var win = window;
	var retvalue = null;
	
	if(win.common_local_HTMLGroup == null)
	{
		return null;
	}
	retvalue = win.common_local_HTMLGroup[param_common_group];
   	return retvalue;
}

////////////////////////////////////////////////////////
// Function: common_buildHTMLGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_buildHTMLGroup(param_common_form, param_common_group)
{
	var tmp_array = new Array();
	var matchctr = 0;	
	var len = param_common_form.length;
	for(var x=0;x<len;x++)
	{
		if(param_common_form[x].getAttribute("group") != null && 
			param_common_form[x].getAttribute("group") == param_common_group)
		{
			var tmp_array2 = new Array();
			var fvalue = common_getValue(param_common_form[x]);
			var fname = param_common_form[x].getAttribute("name");
			tmp_array2["name"] = fname;
			tmp_array2["value"] = fvalue;
			tmp_array[matchctr] = tmp_array2;
			matchctr++;
		}
	}
	return tmp_array;
}

////////////////////////////////////////////////////////
// Function: common_addValueToHTMLGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_addValueToHTMLGroup(param_common_group, param_common_field, param_common_saveToTemp)
{
	var win = window;
	var tmp_array = null;
	if(param_common_saveToTemp != null && param_common_saveToTemp == true)
	{
		tmp_array = win.common_local_HTMLGroupTemp[param_common_group];
	} else
	{
		param_common_saveToTemp = false;
		tmp_array = win.common_local_HTMLGroup[param_common_group];
	}
	if(tmp_array == null)
	{
		tmp_array = new Array();
		if(param_common_saveToTemp == false)
			win.common_local_HTMLGroupNames[win.common_local_HTMLGroupNames.length] = param_common_group;
	}
	var tmp_array2 = new Array();
	var fname = param_common_field.getAttribute("name");
	var fvalue = common_getValue(param_common_field);
	var fname = param_common_field.getAttribute("name");
	tmp_array2["name"] = fname;
	tmp_array2["value"] = fvalue;
	tmp_array[tmp_array.length] = tmp_array2;
	if(param_common_saveToTemp == false)
		win.common_local_HTMLGroup[param_common_group] = tmp_array;
	else win.common_local_HTMLGroupTemp[param_common_group] = tmp_array;
	return;
}

////////////////////////////////////////////////////////
// Function: common_setHTMLGroupNameToCheck()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_setHTMLGroupNameToCheck(param_common_group)
{
	var win = window;
	if(win.common_local_HTMLGroupNamesToCheck == null)
	{
		win.common_local_HTMLGroupNamesToCheck = new Array();
		win.common_local_HTMLGroupNamesToCheck2 = new Array();
	}
	if(common_getHTMLGroupNameToCheck(param_common_group) == false)
	{
		win.common_local_HTMLGroupNamesToCheck[win.common_local_HTMLGroupNamesToCheck.length] = param_common_group;
		win.common_local_HTMLGroupNamesToCheck2[param_common_group] = true;
	}
}

////////////////////////////////////////////////////////
// Function: common_getHTMLGroupNameToCheck()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getHTMLGroupNameToCheck(param_common_group)
{
	var win = window;
	if(win.common_local_HTMLGroupNamesToCheck == null)
	{
		win.common_local_HTMLGroupNamesToCheck = new Array();
		win.common_local_HTMLGroupNamesToCheck2 = new Array();
	}
	var names = win.common_local_HTMLGroupNamesToCheck2;
	if(names[param_common_group] == true)
		return true;
	return false;
}

////////////////////////////////////////////////////////
// Function: common_compareAllHTMLGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_compareAllHTMLGroup(param_common_form, param_common_returnChangedGroups, param_common_zeroGroup, param_common_hasChangedID)
{
	var win = window;
	var changedGroups = new Array();
	
	if(param_common_returnChangedGroups == null)
		param_common_returnChangedGroups = false;
		
	if(win.common_local_HTMLGroup == null)
	{
		win.common_local_HTMLGroup = new Array();
		win.common_local_HTMLGroupNames = new Array();
	}

	if(win.common_local_HTMLGroupNamesToCheck == null ||
			win.common_local_HTMLGroupNamesToCheck.length == 0)
	{
		if(param_common_returnChangedGroups) return changedGroups;
		return false;
	}
	common_saveAllHTMLGroups( param_common_form, true, true );
	var names = win.common_local_HTMLGroupNamesToCheck;
	var len = names.length;
	
	for(var x=0;x<len;x++)
	{
		var val = names[x];
		var different = win.common_compareHTMLGroup(param_common_form, val, true);
		if(different == true) 
		{
			if(param_common_returnChangedGroups || param_common_zeroGroup || param_common_hasChangedID)
			{
				changedGroups[changedGroups.length] = val;
			} else
			{
				return true;
			}
		}
	}
	if(param_common_returnChangedGroups) return changedGroups;
	var hasChanged = false;
	if(param_common_zeroGroup != null && param_common_hasChangedID != null)
	{
		if(changedGroups != null && changedGroups.length > 0)
	  	{
		  if(common_doesArrayNOTContainString( changedGroups, param_common_zeroGroup ) == true)
		  {
		  	hasChanged = true;
		  } else
		  {
		  	// The 0 object has changed... see if the object is marked for use
		  	if(common_getFormFieldById(param_common_hasChangedID) == "1")
			{
				hasChanged = true;
			}
		  }
	  	}
	}
	
	return hasChanged;
}


////////////////////////////////////////////////////////
// Function: common_doesArrayNOTContainString()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_doesArrayNOTContainString( param_form_array, param_form_string )
{
	var len = param_form_array.length;
	
	for(var x=0;x<len;x++)
	{
		var val = param_form_array[x];
		if(val.indexOf(param_form_string) == -1)
			return true; 
	}
	return false;
}

////////////////////////////////////////////////////////
// Function: common_collectFormFields()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_collectFormFields( param_form_object )
{
	var nameValue = new Array(param_form_object.length);
	
	for (var x = 0; x < param_form_object.length; x++)
	{
	  var paramName = param_form_object[x].getAttribute("name");
	  var paramValue = common_getValue(param_form_object[x]);
	  nameValue[x] = "Field Name: " + paramName + "&nbsp;&nbsp;&nbsp;Field Value: " + paramValue;
	}
	return nameValue;
}

////////////////////////////////////////////////////////
// Function: common_saveHTMLGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_saveHTMLGroup(param_common_form, param_common_group)
{
	var win = window;
	if(win.common_local_HTMLGroup == null)
	{
		win.common_local_HTMLGroup = new Array();
		win.common_local_HTMLGroupNames = new Array();
	}
	
	if(common_getHTMLGroupNameToCheck(param_common_group) == false)
	{
		var tmp_array = common_buildHTMLGroup(param_common_form, param_common_group);
		win.common_setHTMLGroupNameToCheck(param_common_group);
		win.common_local_HTMLGroup[param_common_group] = tmp_array;
		win.common_local_HTMLGroupNames[win.common_local_HTMLGroupNames.length] = param_common_group;
	}
	return;
}


////////////////////////////////////////////////////////
// Function: common_saveAllHTMLGroups()
// Description: saves all group in the form 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_saveAllHTMLGroups( param_common_form, param_common_saveToTemp, param_common_filterGroups )
{
	var win = window;
	if(param_common_filterGroups == null)
	{
		param_common_filterGroups = false;
	}
	if(param_common_saveToTemp != null && param_common_saveToTemp == true)
	{
		win.common_local_HTMLGroupTemp = new Array();
	} else
	{
		win.common_local_HTMLGroup = new Array();
		win.common_local_HTMLGroupNames = new Array();
	}

	var lastGroup = null;
	var lastCheck = false;
	var len = param_common_form.length;
	for(var x=0;x<len;x++)
	{
		var groupName = param_common_form[x].getAttribute("group");
		if(groupName != null )
		{
			if(param_common_filterGroups == false)
			{
				win.common_addValueToHTMLGroup(groupName, param_common_form[x], param_common_saveToTemp);
			} else
			{
				if (lastGroup != groupName)
				{
					lastCheck = win.common_getHTMLGroupNameToCheck(groupName);
					lastGroup = groupName;
				}
				if(lastCheck == true)
				{
					win.common_addValueToHTMLGroup(groupName, param_common_form[x], param_common_saveToTemp);
				}
			}
		}
	}
}

////////////////////////////////////////////////////////
// Function: common_spinThruForm()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_spinThruForm(param_common_form)
{
	common_showDebug("Starting common_spinThruForm");
	var f = param_common_form;
	var len = f.length;
	for(var x=0;x<len;x++)
	{
		var groupName = f[x].getAttribute("group");
		if(groupName != null )
		{
			
		}
	}
	common_showDebug("Ending common_spinThruForm");
}

////////////////////////////////////////////////////////
// Function: common_compareHTMLGroup()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_compareHTMLGroup(param_common_form, param_common_group, param_common_compareToTemp, param_common_returnCount)
{
	var win = window;
	if(param_common_compareToTemp == null)
		param_common_compareToTemp = true;
	if(param_common_returnCount == null)
		param_common_returnCount = false;
	if(win.common_local_HTMLGroup == null)
	{
		win.common_local_HTMLGroup = new Array();
	}
	var tmp_array = null;
	if(param_common_compareToTemp == false)
	{
		tmp_array = common_buildHTMLGroup(param_common_form, param_common_group);
	} else 
	{
		if(win.common_local_HTMLGroupTemp == null)
		{
			win.common_local_HTMLGroupTemp = new Array();
		}
		tmp_array = win.common_local_HTMLGroupTemp[param_common_group];
		if(tmp_array == null)
		{
			return false;
		}
	}
	
	var tmp_array2 = win.common_local_HTMLGroup[param_common_group];
	
	if(tmp_array2 == null)
	{
		if(param_common_returnCount == false)
			return true;
	}
	if(tmp_array == null)
	{
		return false;
	}	
	if(tmp_array.length != tmp_array2.length)
	{
		if(param_common_returnCount == false)
			return true;
	}
	var len = tmp_array.length;
	var countMissed = 0;
	
	for(var x=0;x<len;x++)
	{
		var item1 = tmp_array[x];
		var item2 = tmp_array2[x];
		if(item1 != null)
			tocheck1 = item1["value"];
		if(item2 != null)
			tocheck2 = item2["value"];
		if(tocheck1 != tocheck2)
		{
			if(param_common_returnCount == true)
				countMissed++;
			else
			{
				return true;
			}
		}
	}
	if(param_common_returnCount == true) 
		return countMissed;
	return false;
}

////////////////////////////////////////////////////////
// Function: common_setEffectiveBirthAndDeathDates()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_setEffectiveBirthAndDeathDates(param_common_birth, param_common_death)
{
	if(common_local_effectiveDates == null)
	{
		common_local_effectiveDates = new Array();
	}
	var effectiveDates = new Array();
	effectiveDates["birth"] = param_common_birth;
	effectiveDates["death"] = param_common_death;
	common_local_effectiveDates["birth_and_death"] = effectiveDates;
}

////////////////////////////////////////////////////////
// Function: common_getEffectiveBirthDate()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getEffectiveBirthDate()
{
	if(common_local_effectiveDates == null)
	{
		common_showDebug("GettingMBD1: null");
		return null;
	}
	var effectiveDates = common_local_effectiveDates["birth_and_death"];
	if(effectiveDates == null)
	{
		common_showDebug("GettingMBD2: null");
		return null;
	}
	common_showDebug("GettingMBD3: " + effectiveDates["birth"]);
	return effectiveDates["birth"];
}

////////////////////////////////////////////////////////
// Function: common_getEffectiveDeathDate()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getEffectiveDeathDate()
{
	if(common_local_effectiveDates == null)
	{
		return null;
	}
	var effectiveDates = common_local_effectiveDates["birth_and_death"];
	if(effectiveDates == null)
	{
		return null;
	}
	return effectiveDates["death"];
}

////////////////////////////////////////////////////////
// Function: common_setEffectiveDates()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_setEffectiveDates(param_common_id, param_common_prev_start, param_common_prev_end, param_common_next_start, param_common_next_end)
{
	if(common_local_effectiveDates == null)
	{
		common_local_effectiveDates = new Array();
	}

	var effectiveDates = new Array();
	effectiveDates["id"] = param_common_id;
	effectiveDates["prev_start"] = param_common_prev_start;
	effectiveDates["prev_end"] = param_common_prev_end;
	effectiveDates["next_start"] = param_common_next_start;
	effectiveDates["next_end"] = param_common_next_end;
	common_local_effectiveDates[param_common_id] = effectiveDates;
	
	return;
}

////////////////////////////////////////////////////////
// Function: common_getEffectiveDate()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getEffectiveDate(param_common_id, param_common_which)
{
	if(common_local_effectiveDates == null)
	{
		common_local_effectiveDates = new Array();
	}
	
	var effectiveDates = common_local_effectiveDates[param_common_id];
	if(effectiveDates != null)
	{
		return effectiveDates[param_common_which];
	}		
	return "";
}

////////////////////////////////////////////////////////
// Function: common_doEffectiveDateChecks()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_doEffectiveDateChecks(param_common_form,
				param_common_which,
				param_common_title,
				param_common_id,
				param_common_number,
				param_common_oldStartDate,
				param_common_oldEndDate,
				param_common_newStartDate,
				param_common_newEndDate,
				param_common_allowgaps,
				param_common_erroroutput)
{				
	var conflictFieldID = "";
	var which = "";
	var masterBirthDate = null;
	var masterDeathDate = null;
		
	if(param_common_which == "bl") 
	{
		which = "Billing Line";
		conflictFieldID = "_id_conflictResolution";
	} else if(param_common_which == "entity") 
	{	
		which = "Entity";
		conflictFieldID = "_id_conflictResolution";
	} else if(param_common_which == "ia") 
	{	
		which = "Invoice Account";
		conflictFieldID = "_id_conflictResolution";
	} else if(param_common_which == "pp")
	{
		which = "Pricing Plan";
		conflictFieldID = "_id_conflictResolution";	
	} else if(param_common_which == "ag")
	{
		which = "Accumulation Group";
		conflictFieldID = "_id_conflictResolution";	
	} else if(param_common_which == "mappings_im")
	{
		var parentProps = null;
		which = "Invoice Mapping";
		conflictFieldID = "_id_im_" + param_common_number + "_conflictResolution";
		common_showDebug("Validating IM: " + param_common_number); 
	} else if(param_common_which == "entity_im" || 
			param_common_which == "ia_im" ||
			param_common_which == "bl_pp")
	{
		var parentProps = null;
		if(param_common_which == "entity_im")
		{
			parentProps = "_group_entity_props";
			which = "Invoice Mapping";
			conflictFieldID = "_id_im_" + param_common_number + "_conflictResolution";
			common_showDebug("Validating IM: " + param_common_number); 
		} else if(param_common_which == "ia_im")
		{
			parentProps = "_group_ia_props";
			which = "Invoice Mapping";
			conflictFieldID = "_id_im_" + param_common_number + "_conflictResolution";
			common_showDebug("Validating IM: " + param_common_number); 
		} else if(param_common_which == "bl_pp")
		{
			parentProps = "_group_bl_props";
			which = "Pricing Plan";
			conflictFieldID = "_id_pp_" + param_common_number + "_conflictResolution";
			common_showDebug("Validating PP: " + param_common_number); 
		}
		masterBirthDate = common_getEffectiveBirthDate();
		if(masterBirthDate == null)
			masterBirthDate = param_common_form.startDate.value;
		else
		{
			var oldSD = common_getHTMLValueFromGroup(parentProps, 'startDate');
			var startThreshCompare = common_dateCompare("dd-MMM-yyyy", common_getThresholdDate(), oldSD);
			if(masterBirthDate == oldSD && startThreshCompare == -1)
			{
				// Old Start Date is NOT before threshold
				masterBirthDate = param_common_form.startDate.value;
			}
		}	
		masterDeathDate = common_getEffectiveDeathDate();
		if(masterDeathDate == null)		
			masterDeathDate = param_common_form.endDate.value;
		else
		{
			var oldED = common_getHTMLValueFromGroup(parentProps, 'endDate');
			if(masterDeathDate == oldED)
			{
				masterDeathDate = param_common_form.endDate.value;
			}
		}			
	}
	
	var oldStartDate = param_common_oldStartDate;
	var oldEndDate = param_common_oldEndDate;
	var startResult = common_dateCompare("dd-MMM-yyyy", oldStartDate, param_common_newStartDate.value);
	var endResult = common_dateCompare("dd-MMM-yyyy", oldEndDate, param_common_newEndDate.value);
	var overlapThresh = false;
	var threshCompare = common_dateCompare("dd-MMM-yyyy", common_getThresholdDate(), oldStartDate);
	if(threshCompare != -1)
	{
		// Old Start Date is before threshold
		overlapThresh = true;
	}
	var prevVersion = false;
	var nextVersion = false;
	if(common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") != "")
		prevVersion = true;
	if(common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_start") != "")
		nextVersion = true;
	common_showDebug("PrevVersion: " + param_common_which + "_" + param_common_id + " " + prevVersion); 
	common_showDebug("NextVersion: " + param_common_which + "_" + param_common_id + " " + nextVersion); 
	
	if(param_common_erroroutput == true)
	{
		common_doDateChecks(param_common_which,
			param_common_number,
			param_common_newStartDate,
			param_common_newEndDate,
			oldStartDate,
			oldEndDate,
			param_common_form);
	}
	
	var deathResult = 0;
	var birthResult = 0;
	if(masterDeathDate != null)
	{
		var deathResult = common_dateCompare("dd-MMM-yyyy", masterDeathDate, param_common_newEndDate.value);
	}
	common_showDebug("MasterBirthDate: " + masterBirthDate);
	if(masterBirthDate != null)
	{
		var birthResult = common_dateCompare("dd-MMM-yyyy", masterBirthDate, param_common_newStartDate.value);
		common_showDebug("birthResult: " + birthResult + " NEW DATE: " + param_common_newStartDate.value);
	}
	
	if(birthResult == 1)
	{
		common_local_addMsg(param_common_which, param_common_number,
			"The new Start Date (" + param_common_newStartDate.value + ") for this " + which + " can be no earlier than " + masterBirthDate + " because it has a parent with a Start Date of " + masterBirthDate + ".");						
	}
	if(deathResult == -1)
	{
		common_local_addMsg(param_common_which, param_common_number,
			"The new End Date (" + param_common_newEndDate.value + ") for this " + which + " can be no later than " + masterDeathDate + " because it has a parent with an End Date of " + masterDeathDate + ".");								
	}
	
	if(prevVersion == true)
	{
		if(startResult == 1)
		{
			// New StartDate is earlier
			if(param_common_allowgaps == false)
			{
				var startResult2 = common_dateCompare("dd-MMM-yyyy", common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start"), param_common_newStartDate.value);
				common_showDebug("DateCompare: " + param_common_which + "_" + param_common_id + " " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + " " + param_common_newStartDate.value); 
				if(startResult2 == 1)
				{
					// New StartDate is too early
					common_local_addMsg(param_common_which, param_common_number,
						"There is a previous version of this " + which + " with a Start Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ". The new Start Date for this " + which + " can be no earlier than " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ".");						
				} else if(startResult2 == 0)
				{
					// New StartDate perfectly clobbers the previous version
					if(param_common_erroroutput == false) 
					{
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " with a Start Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ". Because the new Start Date for this " + which + " is also " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ", the previous version will be removed.", "select", "Approve:approve");						
					}
				} else if(startResult2 == -1)
				{
					// New StartDate overlaps the previous version
					if(param_common_erroroutput == false) 
					{
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " that the new Start Date overlaps with. To resolve this overlap, the previous version's End Date will be adjusted automatically.", "select", "Approve:approve");						
					}
				}
			} else
			{
				var startResult2 = common_dateCompare("dd-MMM-yyyy", common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_end"), param_common_newStartDate.value);
				if(startResult2 == 1 ||  startResult2 == 0)
				{
					// New StartDate overlaps the previous version
					startResult2 = common_dateCompare("dd-MMM-yyyy", common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start"), param_common_newStartDate.value);
					if(startResult2 == 1)
					{
						// New StartDate is too early
						common_local_addMsg(param_common_which, param_common_number,
							"There is a previous version of this " + which + " with a Start Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ". The new Start Date for this " + which + " can be no earlier than " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ".");						
					} else if(startResult2 == 0)
					{
						// New StartDate perfectly clobbers the previous version
						if(param_common_erroroutput == false) 
						{
							common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " with a Start Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ". Because the new Start Date for this " + which + " is also " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_start") + ", the previous version will be removed.", "select", "Approve:approve");						
						}
					} else if(startResult2 == -1)
					{
						// New StartDate overlaps the previous version
						if(param_common_erroroutput == false) 
						{
							common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " that the new Start Date (" + param_common_newStartDate.value + ") overlaps with. To resolve this overlap, the previous version's End Date will be adjusted automatically.", "select", "Approve:approve");						
						}
					} 
				} else if(startResult2 == -1)
				{
					// If this date change created a NEW GAP that wasn't there before,
					// confirm with user what to do
					if(common_dateCompare("dd-MMM-yyyy", oldStartDate, common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_end")) == 1)
					{
						if(param_common_erroroutput == false) 
						{
							common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " that the new Start Date (" + param_common_newStartDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The previous version's End Date will be adjusted automatically to fill the gap<LI>Option 3 - Leave the previous version untouched, resulting in a gap", "select", "Option 1:extendprev,Option 2:insertgapprev");					
						}					
					}
				}
			}
		} else if(startResult == -1 && overlapThresh == false)
		{
			// New StartDate is later
			if(param_common_allowgaps == false)
			{
				if(param_common_erroroutput == false) 
				{
					if( param_common_which == "pp" || param_common_which == "ag" )
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " that the new Start Date (" + param_common_newStartDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The previous version's End Date will be adjusted automatically to fill the gap", "select", "Option 1:extendprev");						
					else
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " that the new Start Date (" + param_common_newStartDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The previous version's End Date will be adjusted automatically to fill the gap<LI>Option 2 - Insert a new inactive " + which + " to fill the gap", "select", "Option 1:extendprev,Option 2:insertinactiveprev");											
				}
			} else
			{
				// If this date change created a NEW GAP that wasn't there before,
				// confirm with user what to do
				if(common_dateCompare("dd-MMM-yyyy", oldStartDate, common_getEffectiveDate(param_common_which + "_" + param_common_id , "prev_end")) == 1)
				{
					if(param_common_erroroutput == false) 
					{
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a previous version of this " + which + " that the new Start Date (" + param_common_newStartDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The previous version's End Date will be adjusted automatically to fill the gap<LI>Option 2 - Leave the previous version untouched, resulting in a gap", "select", "Option 1:extendprev,Option 2:insertgap");					
					}					
				}		
			}
		}
	}
	if(nextVersion == true)
	{
		if(endResult == -1)
		{
			// New EndDate is later
			if(param_common_allowgaps == false)
			{
				var endResult2 = common_dateCompare("dd-MMM-yyyy", common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end"), param_common_newEndDate.value);
				if(endResult2 == -1)
				{
					// New EndDate is too late
					common_local_addMsg(param_common_which, param_common_number,
						"There is a subsequent version of this " + which + " with an End Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ". The new End Date (" + param_common_newEndDate.value + ") for this " + which + " can be no later than " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ".");						
				} else if(endResult2 == 0)
				{
					// New EndDate perfectly clobbers the subsequent version
					if(param_common_erroroutput == false) 
					{
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " with an End Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ". Because the new End Date for this " + which + " is also " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ", the subsequent version will be removed.", "select", "Approve:approve");						
					}
				} else if(endResult2 == 1)
				{
					// New EndDate overlaps the subsequent version
					if(param_common_erroroutput == false) 
					{
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " that the new End Date (" + param_common_newEndDate.value + ") overlaps with. To resolve this overlap, the subsequent version's Start Date will be adjusted automatically.", "select", "Approve:approve");						
					}
				}
			} else
			{
				var endResult2 = common_dateCompare("dd-MMM-yyyy", common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_start"), param_common_newEndDate.value);
				if(endResult2 == -1 || endResult2 == 0)
				{
					// New EndDate overlaps the subsequent version
					endResult2 = common_dateCompare("dd-MMM-yyyy", common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end"), param_common_newEndDate.value);
					if(endResult2 == -1)
					{
						// New EndDate is too late
						common_local_addMsg(param_common_which, param_common_number,
							"There is a subsequent version of this " + which + " with an End Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ". The new End Date (" + param_common_newEndDate.value + ") for this " + which + " can be no later than " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ".");						
					} else if(endResult2 == 0)
					{
						// New EndDate perfectly clobbers the subsequent version
						if(param_common_erroroutput == false) 
						{
							common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " with an End Date of " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ". Because the new End Date for this " + which + " is also " + common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_end") + ", the subsequent version will be removed.", "select", "Approve:approve");						
						}
					} else if(endResult2 == 1)
					{
						// New StartDate overlaps the subsequent version
						if(param_common_erroroutput == false) 
						{
							common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " that the new End Date (" + param_common_newEndDate.value + ") overlaps with. To resolve this overlap, the subsequent version's Start Date will be adjusted automatically.", "select", "Approve:approve");						
						}
					} 
				} else if(endResult2 == 1)
				{
					// If this date change created a NEW GAP that wasn't there before,
					// confirm with user what to do
					if(common_dateCompare("dd-MMM-yyyy", oldEndDate, common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_start")) == 1)
					{
						if(param_common_erroroutput == false) 
						{
							common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " that the new End Date (" + param_common_newEndDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The subsequent version's Start Date will be adjusted automatically to fill the gap<LI>Option 2 - Leave the subsequent version untouched, resulting in a gap", "select", "Option 1:extendnext,Option 2:insertgap");					
						}					
					}
				}
			}
		} else if(endResult == 1)
		{
			// New EndDate is earlier
			if(param_common_allowgaps == false)
			{
				if(param_common_erroroutput == false) 
				{
					if( param_common_which == "pp" || param_common_which == "ag")
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " that the new End Date (" + param_common_newEndDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The subsequent version's Start Date will be adjusted automatically to fill the gap", "select", "Option 1:extendnext");						
					else
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " that the new End Date (" + param_common_newEndDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The subsequent version's Start Date will be adjusted automatically to fill the gap<LI>Option 2 - Insert a new inactive " + which + " to fill the gap", "select", "Option 1:extendnext,Option 2:insertinactivenext");											
				}
			} else
			{
				// If this date change created a NEW GAP that wasn't there before,
				// confirm with user what to do
				if(common_dateCompare("dd-MMM-yyyy", oldEndDate, common_getEffectiveDate(param_common_which + "_" + param_common_id , "next_start")) == -1)
				{
					if(param_common_erroroutput == false) 
					{
						common_addToConflictArray(null, param_common_title, conflictFieldID, "There is a subsequent version of this " + which + " that the new End Date (" + param_common_newEndDate.value + ") creates a gap between. To resolve this gap, choose:<BR><LI>Option 1 - The subsequent version's Start Date will be adjusted automatically to fill the gap<LI>Option 2 - Leave the subsequent version untouched, resulting in a gap", "select", "Option 1:extendnext,Option 2:insertgapnext");					
					}					
				}		
			}
		}
	}
	if(param_common_erroroutput == false) 
	{
		return;
	}
	return;
}

////////////////////////////////////////////////////////
// Function: common_resetConflicts()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_resetConflicts(param_common_form)
{
	common_local_conflictArray = new Array();
	
	// Loop thru entire FORM and reset all of the conflict fields to ""
	var len = param_common_form.length;
	for(var lpctr=0; lpctr<len; lpctr++)
	{
		var formfield = param_common_form[lpctr];
		var fieldID = formfield.getAttribute("id");
		if(fieldID != null && fieldID.indexOf("_conflictResolution") != -1)
		{
			common_setFormFieldById(fieldID, "");
		}
	}
}

////////////////////////////////////////////////////////
// Function: common_getConflictArray()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getConflictArray()
{
	return common_local_conflictArray;
}

////////////////////////////////////////////////////////
// Function: common_addToConflictArray()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_addToConflictArray(param_common_conflictArray, param_common_title, param_common_fieldid, param_common_text, param_common_type, param_common_options)
{
	var tmp = new Array();
	tmp['title'] = param_common_title;
	tmp['text'] = param_common_text;
	tmp['fieldid'] = param_common_fieldid;
	tmp['type'] = param_common_type;
	tmp['options'] = param_common_options;
	
	if(param_common_conflictArray == null)
	{
		if(common_local_conflictArray == null)
			common_resetConflictArray();
		common_local_conflictArray[common_local_conflictArray.length] = tmp;
	} else
	{		
		param_common_conflictArray[param_common_conflictArray.length] = tmp;
		return param_common_conflictArray;
	}
}

////////////////////////////////////////////////////////
// Function: common_setConflictArrayHTML()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_setConflictArrayHTML(param_common_conflictArray)
{
	common_disableHTML(common_global_workspaceFrameObject, '_id_form');
	common_disableHTML(common_global_workspaceFrameObject, '_id_user_action_message');
	common_disableHTML(common_global_workspaceFrameObject, '_id_struts_errors');
	
	common_endValidateWorkspaceForm();
			
	// Add conflicts to HTML page so user can see them
	var outString = null;
	if(param_common_conflictArray == null)
		param_common_conflictArray = common_local_conflictArray;
		
	var len = param_common_conflictArray.length;

	for(var conflictCtr=0;conflictCtr<len;conflictCtr++)
	{
		if(outString == null)
			outString = new String("<table cellspacing='0' cellpadding='3'>");		
		var elem = param_common_conflictArray[conflictCtr];
		var text = elem['text'];
		var type = elem['type'];
		var title = elem['title'];
		var fieldid = elem['fieldid'];
		var options = elem['options'].split(",");
		var ctr = conflictCtr + 1;		
		var outString = outString + "<tr><td valign='top' align='left'><span class='label required'>Conflict #" + ctr + "</span><BR>";
		if(title != null)
			outString = outString + title + "<BR>";
		outString = outString + text;
		outString = outString + "</td><td valign='top' align='left'>";
		
		if(type == "select")
		{
			outString = outString + "<select name='" + fieldid + "'>";
			for(var optionsctr=0;optionsctr<options.length;optionsctr++)
			{
				var currentOption = options[optionsctr].split(":");
				outString = outString + "<option value='" + currentOption[1] + "'>" + currentOption[0] + "</option>";
			}
			outString = outString + "</select>";
		}
		outString = outString + "</td></tr>";	
	}
	if(outString != null)
		outString = outString + "</table>";
	common_setInnerHTML(common_global_workspaceFrameObject, '_id_conflict_list', outString)
	common_enableHTML(common_global_workspaceFrameObject, '_id_all_conflicts');
	return
}

////////////////////////////////////////////////////////
// Function: common_doEffectiveDateOverlapChecks()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_doEffectiveDateOverlapChecks(param_common_form,
				param_common_which)
{				
	var which = "";
	var ctrmax = 0;
	var prefix = "_group_panel_";
	var prefix2 = "";
	var prefix3 = "";
	var postfix = "";
	var dataarray = common_copyEffectiveDateArray(common_local_hiddenEffectiveDates);

	if(dataarray == null)
		dataarray = new Array();
		
	if(param_common_which == "bl_pp")
	{
		which = "Pricing Plan";
		ctrmax = param_common_form.pp_totalcount.value;
		prefix = "_group_panel_bl_pp_";
		prefix2 = "pp_";
		prefix3 = "bl";
	} else if(param_common_which == "entity_im")
	{
		which = "Invoice Mapping";
		ctrmax = param_common_form.im_totalcount.value;
		prefix = "_group_panel_entity_im_";
		prefix2 = "im_";
		prefix3 = "entity";
		postfix = "_implicit";
	} else if(param_common_which == "ia_im")
	{
		which = "Invoice Mapping";
		ctrmax = param_common_form.im_totalcount.value;
		prefix = "_group_panel_ia_im_";
		prefix2 = "im_";
		prefix3 = "ia";
		postfix = "_implicit";
	} else if(param_common_which == "mappings_im")
	{
		which = "Invoice Mapping";
		ctrmax = param_common_form.im_totalcount.value;
		prefix = "_group_panel_mappings_im_";
		prefix2 = "im_";
		prefix3 = "mappings";
		postfix = "_implicit";
	}
	
	// Loop thru all of the objects on the GUI and load their start and end
	// dates into an array
	for(var linectr=0; linectr<=ctrmax; linectr++)
	{
		var skipNew = false;
		var createNew = document.getElementById("_id_" + prefix2 + linectr + "_CreateNew");
		if(createNew != null)
		{
			if(common_getFormFieldById("_id_" + prefix2 + linectr + "_CreateNew") != "1")
			{
				skipNew = true;
			}
		}
		// Special case for invoice mappings --- if the user has changed an IMPLICIT 
		// mapping they are converting it to an EXPLICIT mapping and, therefore, it needs
		// to be included in the overlap array
		if(common_getFormFieldById("_id_" + prefix2 + linectr + "_Delete") != "true" &&
			skipNew == false)
		{
			var dates_grpname = "" + prefix + "" + linectr + postfix;
			var grpname = "" + prefix + "" + linectr;
			var key = null;
			var sDate = null;
			var eDate = null;
			var im_haschanged = true;
			
			if(common_getFormFieldById("_id_" + prefix2 + linectr + "_Implicit") == "true")
			{
				im_haschanged = false;
				
				// Check if the mapping has changed at all
				var im_haschanged = common_compareHTMLGroup(param_common_form, grpname);
				if(im_haschanged == false)
					im_haschanged = common_compareHTMLGroup(param_common_form, dates_grpname);
			}
			if(im_haschanged == true)
			{
				var dates_grp = common_buildHTMLGroup(param_common_form, dates_grpname);
				var grp = common_buildHTMLGroup(param_common_form, grpname);
				
				var eType = common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_EntityType');
				if(eType == "Default")
				{
					key = "Default " + which;
				} else
				{
					key = "" + which + " for Entity ID " + common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_EntityID') + " (" + eType + ")";
					if(which == "Invoice Mapping")
					{
						key = key + " (" + common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_MappingType') + "-" + common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_MappingValue') + ")";
					}
				}
				
				if(common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_useReusableFlag') == "true")
				{
					common_showDebug("Grp: " + grp + " Getting sDate: " + '' + prefix2 + linectr + '_ReuseStartDate');
					sDate = common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_ReuseStartDate');
					eDate = common_getHTMLValueFromNewGroup(grp, '' + prefix2 + linectr + '_ReuseEndDate');
				} else
				{
					common_showDebug("Grp: " + dates_grp + " Getting sDate: " + '' + prefix2 + linectr + '_StartDate');
					sDate = common_getHTMLValueFromNewGroup(dates_grp, '' + prefix2 + linectr + '_StartDate');
					eDate = common_getHTMLValueFromNewGroup(dates_grp, '' + prefix2 + linectr + '_EndDate');			
				}
				
				if(eDate == "") eDate = "31-Dec-9999";
				common_showDebug("Adding Effective Date: " + key + " sD:" + sDate + " eD:" + eDate);
				dataarray = common_addEffectiveDate(dataarray, key, sDate, eDate, false);
			}
		}
	}
		
	// Now, all of the dates, per item, are lined up and we can make sure dates don't overlap
	if(dataarray != null)
	{
		var len = dataarray.length;
		for(var keyctr=0;keyctr<len;keyctr++)
		{
			var local_message = "";
			var itemarray = dataarray[keyctr];
			
			if(itemarray.length > 1)
			{
				var len2 = itemarray.length;
				for(var itemctr=0;itemctr<len2;itemctr++)
				{
					sDate = itemarray[itemctr]['startDate'];
					eDate = itemarray[itemctr]['endDate'];
					var hidden = itemarray[itemctr]['hidden'];
					var len3 = itemarray.length;
					for(var keyctr2=0;keyctr2<len3;keyctr2++)
					{
						if(itemctr != keyctr2)
						{
							var key = itemarray[keyctr2]['key'];
							var sDate2 = itemarray[keyctr2]['startDate'];
							var eDate2 = itemarray[keyctr2]['endDate'];	
							var hidden2 = itemarray[keyctr2]['hidden'];	
							var startCompare = common_dateCompare("dd-MMM-yyyy", sDate2, sDate);
							var endCompare = common_dateCompare("dd-MMM-yyyy", eDate2, sDate);
							var endCompare2 = common_dateCompare("dd-MMM-yyyy", sDate2, eDate);
							
							if((startCompare == -1 && endCompare == -1) || endCompare2 == 1)
							{
								// Dates are all good... do nothing here
							} else
							{
								// Overlap found!
								common_showDebug("startCompare: " + startCompare + " sD2:" + sDate2 + " sD:" + sDate);
								common_showDebug("endCompare: " + endCompare + " eD2:" + eDate2 + " sD:" + sDate);
								common_showDebug("endCompare2: " + endCompare2 + " sD2:" + sDate2 + " eD:" + eDate);
								common_showDebug("hidden2: " + hidden2 + " hidden: " + hidden);
								local_message = "The Start Date and End Date for a " + key + " overlap another " + key;
								if(hidden == true && hidden2 == false)
									local_message = local_message + " and one of them is not visible (" + sDate + " - " + eDate + "). The Start Date (" + sDate2 + ") and End Date (" + eDate2 + ") of the visible item must be adjusted."  
								else if(hidden == false && hidden2 == true)
									local_message = local_message + " and one of them is not visible (" + sDate2 + " - " + eDate2 + "). The Start Date (" + sDate + ") and End Date (" + eDate + ") of the visible item must be adjusted."  
								else
									local_message = local_message + " and both of them are visible. The Start Dates (" + sDate + " and " + sDate2 + ") and End Dates (" + eDate + " and " + eDate2 + ") of both items must be adjusted."  
								break;
							}
						}
					}
					if(local_message != "")
						break;
				}
			}
			if(local_message != "")
				common_local_addMsg(prefix3, null, local_message);	
		}
	}

	return;
}

////////////////////////////////////////////////////////
// Function: common_addEffectiveDate()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_addEffectiveDate(param_common_array, param_common_key, param_common_start, param_common_end, param_common_hidden)
{
	var arraytouse = null;
	if(param_common_array == null)
		arraytouse = common_local_hiddenEffectiveDates;
	else
		arraytouse = param_common_array;
		
	if(param_common_hidden == null)
		param_common_hidden = true;
		
	if(arraytouse == null)
	{
		arraytouse = new Array();
	}
		
	var keyelem = new Array();
	var len = arraytouse.length;
	for(var keyctr=0;keyctr<len;keyctr++)
	{
		var tmpkeyelem = arraytouse[keyctr];
		if(tmpkeyelem[0]['key'] == param_common_key)
		{
			keyelem = tmpkeyelem;
			break;
		}
	}
	var values = new Array();
			
	values['key'] = param_common_key;
	values['startDate'] = param_common_start;
	values['endDate'] = param_common_end;
	values['hidden'] = param_common_hidden;
	
	keyelem[keyelem.length] = values;
	arraytouse[keyctr] = keyelem;
	
	if(param_common_array == null)
	{		
		common_local_hiddenEffectiveDates = arraytouse;
	} else return arraytouse;
	return;
}

function common_copyEffectiveDateArray(param_common_array)
{
	if(param_common_array == null) return null;
	var newarray = new Array();
	
	var len = param_common_array.length;
	for(var keyctr=0;keyctr<len;keyctr++)
	{
		var tmparray = param_common_array[keyctr];
		var len2 = tmparray.length;
		for(var itemctr=0;itemctr<len2;itemctr++)
		{
			var tmparray2 = tmparray[itemctr];
			newarray = common_addEffectiveDate(newarray, tmparray2['key'], tmparray2['startDate'], tmparray2['endDate'], tmparray2['hidden']);	
		}
	}
	return newarray;
}

function common_dumpArray(param_common_array, param_common_name)
{
	var str = "";
	if(param_common_name != null)
	{
		str = "" + param_common_name + "\n\n";
	}
	
	for( var arrayKey in param_common_array )
	{
		str = str + arrayKey + ": " + param_common_array[arrayKey] + "\n";		
	}

	alert("ARRAY:\n\n" + str);
}

////////////////////////////////////////////////////////
// Function: common_doDateChecks()
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_doDateChecks(param_common_which,
	param_common_linenumber,
	param_common_startDate,
	param_common_endDate,
	param_common_oldStartDate,
	param_common_oldEndDate,
	param_common_form)
{
	// Start Date is required, End Date is not (and End Date must be after Start Date)
	if(common_isNotEmpty(param_common_startDate, null) == false)
	{
		common_local_addMsg(param_common_which, param_common_linenumber, "Start Date cannot be empty");						
	} else
	{
		if(common_isADate(param_common_startDate, "dd-MMM-yyyy") == false)
		{
			common_local_addMsg(param_common_which, param_common_linenumber, "Start Date must be a valid calendar date");						
		} else
		{
			// Start Date must be AFTER the current Threshold Date IF
			// the user modified the properties
			var htmlChanged = 2;
			var htmlsection = "";
			var htmlsection2 = "";
			if(param_common_which == "bl_pp")
				htmlsection = "_group_panel_bl_pp_" + param_common_linenumber;
			else if(param_common_which == "ia_im")
			{
				htmlsection = "_group_panel_ia_im_" + param_common_linenumber;
				htmlsection2 = htmlsection + "_implicit";
			} else if(param_common_which == "entity_im")
			{
				htmlsection = "_group_panel_entity_im_" + param_common_linenumber;
				htmlsection2 = htmlsection + "_implicit";
			} else if(param_common_which == "mappings_im")
			{
				htmlsection = "_group_panel_mappings_im_" + param_common_linenumber;
				htmlsection2 = htmlsection + "_implicit";
			} else if(param_common_which == "bl")
				htmlsection = "_group_bl_props";
			else if(param_common_which == "ia")
				htmlsection = "_group_ia_props";
			else if(param_common_which == "entity")
				htmlsection = "_group_entity_props";
			else if(param_common_which == "pp" )
				htmlsection = "_group_pp_props";
			else if(param_common_which == "ag" )
				htmlsection = "_group_ag_props";							
			if(htmlsection != "")
			{
				htmlChanged = common_compareHTMLGroup(param_common_form, htmlsection, true, true);
				if(htmlsection2 != "")
				{
					htmlChanged = htmlChanged + common_compareHTMLGroup(param_common_form, htmlsection2, true, true);
				}
			} 
			if(htmlChanged > 0)
			{
				if(htmlChanged >= 1) 
				{
					if(htmlChanged == 1 && 
						common_dateCompare("dd-MMM-yyyy", param_common_endDate.value, param_common_oldEndDate) != 0)
					{
						// If only 1 field changed, and it's the END DATE, then we can skip some checks!
					} else
					{
						var dCompare = common_dateCompare("dd-MMM-yyyy", common_getThresholdDate(), param_common_startDate.value);
						if(dCompare != -1)
						{
							common_local_addMsg(param_common_which, param_common_linenumber, "Start Date must be later than the Threshold Date which is " + common_getThresholdDate());
						} else
						{
							if( param_common_oldEndDate != null )
							{
								// Start Date must be less than or equal to the OLD end date...
								// Except for entityChildren which doesn't need this rule.
								// This check just keeps things simple for now.
								dCompare = common_dateCompare("dd-MMM-yyyy", param_common_startDate.value, param_common_oldEndDate);
								if(dCompare > 0)
								{
									common_local_addMsg(param_common_which, param_common_linenumber, "Start Date must be earlier than the old End Date which is " + param_common_oldEndDate);						
								}
							}
						}
					}
				}
			}
		}
	}	

	if(common_isNotEmpty(param_common_endDate, null) == true)
	{
		if(common_isADate(param_common_endDate, "dd-MMM-yyyy") == false)
		{
			common_local_addMsg(param_common_which, param_common_linenumber, "End Date must be a valid calendar date");						
		} else
		{
			var startSooner = common_compareDates("dd-MMM-yyyy", param_common_startDate.value, param_common_endDate.value);
			if(startSooner == false)
			{
				common_local_addMsg(param_common_which, param_common_linenumber, "End Date must be later than Start Date");						
			}
			if( param_common_oldStartDate != null )
			{
				// End Date must be greater than or equal to the OLD start date...
				// Except for entityChildren which doesn't need this rule.
				// This check just keeps things simple for now.
				dCompare = common_dateCompare("dd-MMM-yyyy", param_common_endDate.value, param_common_oldStartDate);
				if(dCompare < 0)
				{
					common_local_addMsg(param_common_which, param_common_linenumber, "End Date must be later than the old Start Date which is " + param_common_oldStartDate);						
				}
			}
		}
	}
	return;
}

////////////////////////////////////////////////////////
// Function: common_putFocusOnFirst()
// Description: 
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_putFocusOnFirst(param_common_form, param_common_startfield)
{

	// If a startfield is provided, then the focus will be on 
	// that particular field rather than the first non-hidden field
	if (param_common_startfield != null)
	{
		param_common_startfield.focus();
		if(param_common_startfield.type == "text")
			param_common_startfield.select();
		return;
	}
	
	var len = param_common_form.length;
	for(var x=0;x<len;x++)
	{
		if(param_common_form[x].type != "hidden" &&
			param_common_form[x].type != "button")
		{
			param_common_form[x].focus();
			if(param_common_form[x].type == "text")
				param_common_form[x].select();
			return;
		}
	}
}

////////////////////////////////////////////////////////
// Function: common_doNav()
// Description: Called before navigating to any page due to
// 		a user click so that we can control the pages
//		when a user might click on things multiple times.
// Parameters: 
// Returns: true if navigating is allowed, false otherwise
////////////////////////////////////////////////////////
function common_doNav()
{
	if(common_local_disableNav == true) return false;
	return true;
}

////////////////////////////////////////////////////////
// Function: common_submitWorkspaceForm()
// Description: Called to setup user messages and remove
//		buttons before submitting the form
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_submitWorkspaceForm(param_common_form)
{
	if(winname.indexOf("popup") == -1)
	{
		common_disableHTML(common_global_workspaceFrameObject, "_id_workspace");
		common_turnOnWait(common_global_workspaceFrameObject);
	} else
	{
		common_disableHTML(common_global_popupFrameObject, "_id_workspace");
		common_turnOnWait(common_global_popupFrameObject);
	}
	
	if(param_common_form != null)
		param_common_form.submit();
}

////////////////////////////////////////////////////////
// Function: common_beginValidateWorkspaceForm()
// Description: 
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_beginValidateWorkspaceForm(param_form_object)
{
    if (common_global_debugMode == "true")
    { 
       if(common_confirmPrompt("Debug mode is enabled. Do you want to output all form fields?") == true)
	   {
       		var msg = "";
       		var formFields = common_collectFormFields(param_form_object);
       		var len = formFields.length;
       		for (var x = 0; x < len; x++)
       		{  
	   			common_showDebug(formFields[x]);
	   		}  
       		if(common_confirmPrompt("Debug mode is enabled. Do you want to continue to validate and submit the form?") == false)
	       		return false;
	   }
    }
	common_turnOnWait(common_global_workspaceFrameObject, "Please wait... validating data...");
	common_disableHTML(common_global_workspaceFrameObject, "_id_workspace");
	common_disableHTML(common_global_workspaceFrameObject, "_id_user_action_message");
	return true;
}

////////////////////////////////////////////////////////
// Function: common_endValidateWorkspaceForm()
// Description: 
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_endValidateWorkspaceForm()
{
	common_turnOffWait(common_global_workspaceFrameObject);
	common_enableHTML(common_global_workspaceFrameObject, "_id_workspace");
}

////////////////////////////////////////////////////////
// Function: common_beginValidatePopupForm()
// Description: 
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_beginValidatePopupForm(param_form_object)
{
    if (common_global_debugMode == "true")
    { 
       if(common_confirmPrompt("Debug mode is enabled. Do you want to output all form fields?") == true)
	   {
       		var msg = "";
       		var formFields = common_collectFormFields(param_form_object);
       		var len = formFields.length;
       		for (var x = 0; x < len; x++)
       		{  
	   			common_showDebug(formFields[x]);
	   		}  
       		if(common_confirmPrompt("Debug mode is enabled. Do you want to continue to validate and submit the form?") == false)
	       		return false;
	   }
    }
	common_turnOnWait(common_global_popupFrameObject, "Please wait... validating data...");
	common_disableHTML(common_global_popupFrameObject, "_id_workspace");
	common_disableHTML(common_global_popupFrameObject, "_id_user_action_message");
	return true;
}

////////////////////////////////////////////////////////
// Function: common_endValidateWorkspaceForm()
// Description: 
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_endValidatePopupForm()
{
	common_turnOffWait(common_global_popupFrameObject);
	common_enableHTML(common_global_popupFrameObject, "_id_workspace");
}

////////////////////////////////////////////////////////
// Function: common_submitSearchForm()
// Description: Called to setup user messages and remove
//		buttons before submitting the form
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_submitSearchForm()
{
	common_disableHTML(common_global_searchResultsFrameObject, "_id_search_results");
	common_turnOnWait(common_global_searchResultsFrameObject);
}

////////////////////////////////////////////////////////
// Function: common_submitPickerSearchForm()
// Description: Called to setup user messages before submitting the form
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_submitPickerSearchForm()
{
	common_disableHTML(common_global_pickerFrameObject, "_id_search_results");
	common_disableHTML(common_global_pickerFrameObject, "_id_search_desc");
	common_disableHTML(common_global_pickerFrameObject, "_id_search_form");
	common_turnOnWait(common_global_pickerFrameObject);
}

////////////////////////////////////////////////////////
// Function: common_showCalendar()
// Description: Called to launch the calendar to help
// 		a user fill out an HTML form field with a date.
//		NOTE that this function uses the calendar defined
//		in calendar.js so caledar.js must be included to use 
//		this function.
// Parameters: 
//	param_common_inputField - the field to fill in with the date
// 	param_common_dateFormat - the format for the date when filled in
//	param_common_buttonTrigger - the image that will trigger the calendar to open
// 	param_common_updateFunction - function to call when field is updated
// Returns: nothing
////////////////////////////////////////////////////////
function common_showCalendar(param_common_inputField, param_common_dateFormat, param_common_buttonTrigger,
	param_common_updateFunction)
{
	var param_showsTime = false;
	if(param_common_dateFormat == "YYYYmmdd")
	{
		param_common_dateFormat = "%Y%m%d"
	}
	if(param_common_dateFormat == "dd-MMM-yyyy")
	{
		param_common_dateFormat = "%d-%b-%Y"
	}
	if (param_common_dateFormat == "dd-MMM-yyyy HH:mm:ss")
	{
		param_common_dateFormat = "%d-%b-%Y %H:%M:%S";
		param_showsTime = true;
	}
	var infield = document.getElementById(param_common_inputField);
	if(infield.disabled != true)
	{	
		Calendar.setup({
			inputField:param_common_inputField,
			ifFormat:param_common_dateFormat,
			button:param_common_buttonTrigger, 
			onUpdate:param_common_updateFunction,
			showsTime:param_showsTime,
			singleClick:true});
	}
}

////////////////////////////////////////////////////////
// Function: common_setFormField
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setFormField(param_common_destination, param_common_value)
{
	try
	{
		param_common_destination.value = param_common_value;
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_setFormFieldById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setFormFieldById(param_common_destination, param_common_value)
{
	try
	{
		var setfield = document.getElementById(param_common_destination);
		setfield.value = param_common_value;
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_getFormFieldById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_getFormFieldById(param_common_field)
{
	var retval = "";
	try
	{
		var setfield = document.getElementById(param_common_field);
		retval = common_getValue(setfield);
	}
	catch(e)
	{
		// Nothing to do...
	}
	return retval;
}

////////////////////////////////////////////////////////
// Function: common_getFormFieldOnlyById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_getFormFieldOnlyById(param_common_field)
{
	var retval = null;
	try
	{
		var retval = document.getElementById(param_common_field);
	}
	catch(e)
	{
		// Nothing to do...
	}
	return retval;
}

////////////////////////////////////////////////////////
// Function: common_setDynamicTabIndex
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setDynamicTabIndex(param_common_number)
{
	common_local_tabIndex = param_common_number;
}

////////////////////////////////////////////////////////
// Function: common_getDynamicTabIndex
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_getDynamicTabIndex(param_common_number)
{
	return common_local_tabIndex;
}

////////////////////////////////////////////////////////
// Function: common_setHiddenFromCheckbox
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setHiddenFromCheckbox(param_common_checkbox, param_common_hidden)
{
	if(param_common_checkbox.checked == true)
	{
		param_common_hidden.value = param_common_checkbox.value;
	} else
	{
		param_common_hidden.value = "0";
	}
}

////////////////////////////////////////////////////////
// Function: common_setFormFieldsByIdFromPicker
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
var common_setFormFieldsByIdFromPicker = function (param_common_pContext, param_common_data) {
	var cbArgs = param_common_pContext.getCallbackFunctionArgs();
	if(cbArgs != null)
	{
		if(param_common_data != null)
		{
			for(var x=0;x<cbArgs.length;x++)
			{
				var curelement = document.getElementById(cbArgs[x]);
				var dynName = "objectValue" + x;
				common_setField(curelement, param_common_data[dynName].value);
			}
		}
	}
}

////////////////////////////////////////////////////////
// Function: common_clearFormField()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_clearFormField(param_common_field)
{

	var defval = "";
	var fieldtype = param_common_field.type;
	
	if(fieldtype == "textarea")
	{
		fieldtype = "text";	
	}
	if(fieldtype == "password")
	{
		fieldtype = "text";
	}
	if(fieldtype == "select")
	{
		fieldtype = "text";
	}
	if(fieldtype == "select-one")
	{
		fieldtype = "text";
	}
	if(fieldtype == "select-multiple")
	{
		fieldtype = "text";
	}
	if(fieldtype == "checkbox" || fieldtype == "radio")
	{
		param_common_field.checked = false;
	} else if(fieldtype == "text")
	{
		common_setField(param_common_field, defval);
	} 
	return;
}

////////////////////////////////////////////////////////
// Function: common_clearSearchForm()
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_clearSearchForm(param_common_form)
{
	var len = param_common_form.length;
	for(var x=0;x<len;x++)
	{
		var defval = "";
		var fieldtype = param_common_form[x].type;
		
		if(fieldtype == "textarea")
		{
			fieldtype = "text";	
		}
		if(fieldtype == "password")
		{
			fieldtype = "text";
		}
		if(fieldtype == "select")
		{
			fieldtype = "text";
		}
		if(fieldtype == "select-one")
		{
			fieldtype = "text";
		}
		if(fieldtype == "select-multiple")
		{
			fieldtype = "text";
		}
		
		if(param_common_form[x].getAttribute("default_value") != null)
		{
			defval = param_common_form[x].getAttribute("default_value");
		}
		if(fieldtype == "checkbox" || fieldtype == "radio")
		{
			if(param_common_form[x].name != "caseSensitive_checkbox")
			{
				if (defval == "checked") {
					param_common_form[x].checked = true;
				} else {
					param_common_form[x].checked = false;
				}
			} else
			{
				param_common_form[x].checked = true;
				common_setHiddenFromCheckbox(param_common_form[x], param_common_form.caseSensitive);
			}
		} else if(fieldtype == "text")
		{
			common_setField(param_common_form[x], defval);
		} 
	}
	return;
}

////////////////////////////////////////////////////////
// Function: common_setField
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setField(param_common_destination, param_common_value)
{
	try
	{
		if(param_common_destination != null)
		{
			if(param_common_destination.value != null)
				param_common_destination.value = param_common_value;
			else
				param_common_destination.innerHTML = param_common_value;
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_setFieldById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setFieldById(param_common_destination, param_common_value)
{
	try
	{
		if(param_common_destination != null)
		{
			var i = document.getElementById(param_common_destination);
			if(i != null)
			{
				common_setField(i, param_common_value);
			}
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_getFieldById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_getFieldById(param_common_which)
{
	var retval = "";
	try
	{
		var i = document.getElementById(param_common_which);
		if(i != null)
		{
			if(i.value != null)
				retval = common_getValue(i);
			else
				retval = i.innerHTML;
		} 
	}
	catch(e)
	{
		// Nothing to do...
	}
	return retval;
}

////////////////////////////////////////////////////////
// Function: common_copyFieldsById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_copyFieldsById(param_common_source, param_common_destination)
{
	try
	{
		var srcfield = document.getElementById(param_common_source);
		var destfield = document.getElementById(param_common_destination);
		
		if(srcfield != null && destfield != null)
		{
			var srcData = null;
			if(srcfield.value != null)
				srcData = srcfield.value;
			else
				srcData = srcfield.innerHTML;
			
			if(destfield.value != null)
				destfield.value = srcData;
			else
				destfield.innerHTML = srcData;
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_setParentWindowFormFieldById
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setParentWindowFormFieldById(param_common_destination, param_common_value)
{
	try
	{
		var setfield = window.opener.document.getElementById(param_common_destination);
		setfield.value = param_common_value;
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_copyField
// Description: Takes value in first field and copies to the
//		second field
// Parameters: 
//	source - field that is copied (object)
//	destination - where field in source is copied to (object)	
// Returns: nothing
////////////////////////////////////////////////////////
function common_copyField(param_common_source, param_common_destination)
{
	if( common_isNotEmpty(param_common_destination, null) == false )
	{
		param_common_destination.value = param_common_source.value;
	}
}

////////////////////////////////////////////////////////
// Function: common_showDebug
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_showDebug(param_msg_string)
{
	var win = window;
	var now = new Date();
	
	if (win.common_global_debugMode == "true")
	{
	    if(param_msg_string == null)
	    	param_msg_string = win.common_global_debugMessage;
	    	
	    if(param_msg_string == null || param_msg_string == "") return;
	    	
		var str = new String(param_msg_string);
		var rege = new RegExp('\n', "g");
		var newstr = str.replace(rege,'<BR>');
		param_msg_string = "<LI> " + now + ": " + newstr;
		var winptr = common_local_getFramePointer(win.common_global_debugFrameObject);
		
		var docptr = null;
		if(winptr == null || winptr.closed == true || winptr.document == null)
		{ 
			winptr = common_openNewWindow(win.common_global_debugFrameObject, "", 6);
			win.common_local_framePointers[win.common_global_debugFrameObject] = winptr;
			docptr = winptr.document;
			docptr.write("<HTML><BODY><P>RBAR DEBUG OUTPUT&nbsp;&nbsp;<input type=button onClick=\"JavaScript:var c=document.getElementById('_id_debug_msg');c.innerHTML='';\" name='Clear' value='Clear'></P><DIV ID='_id_debug_msg'></DIV></BODY></HTML>");
		} else
		{
			docptr = winptr.document;
		}
		
		common_prependToInnerHTML(win.common_global_debugFrameObject, "_id_debug_msg",
			param_msg_string);	
	}
	
	return;
}

////////////////////////////////////////////////////////
// Function: common_showHelp
// Description: Displays help messages to user
// Parameters: 
//	num - which help message to display (integer)
//	showmethod - how to display the help (string)
//		'popup' = JavaScript alert
//		'inline' = inside the HTML page	
// Returns: nothing
////////////////////////////////////////////////////////
function common_showHelp(param_common_num, param_common_showmethod)
{
	 var messagetodisplay = null;
 	var messagetodisplaytitle = null;
    if (param_common_num != null)
    {
	  messagetodisplay = strings_getHelpMessage( param_common_num );	
	  messagetodisplaytitle = strings_getHelpMessageTitle( param_common_num );	
	} else
	{
	  param_common_num = "NA";
	  messagetodisplay = "";
	  messagetodisplaytitle = "";
	}
	if(param_common_showmethod == "inline" && common_local_getFramePointer(common_global_helpFrameObject) != null)
	{
		var str = new String(messagetodisplay);
		var rege = new RegExp('\n', "g");
		var newstr = str.replace(rege,'<BR>');
		messagetodisplay = newstr;
		common_setInnerHTML(common_global_helpFrameObject, common_local_HTMLHelpMsgID,
			messagetodisplaytitle + "<BR><BR>" + messagetodisplay + "<BR>(" + param_common_num + ")");	
		common_enableHTML(common_global_leftFrameObject, common_local_HTMLHelpPanelID, common_local_HTMLHelpPanelImageID, common_local_HTMLHelpPanelImageName);
		common_expandFrame(common_global_leftFrameObject, common_global_defaultLeftFrameExpandedSize, null, null, common_global_defaultLeftFrameCollapsedSize);
	} else if (param_common_showmethod == "alert")
	{
	    if (common_global_debugMode == "true")
	       messagetodisplay = common_global_debugMessage;
		alert(messagetodisplaytitle + "\n\n" +  messagetodisplay + "\n(" + param_common_num + ")");
	} 
	return false;
}

////////////////////////////////////////////////////////
// Function: common_showDataError
// Description: Displays data entry error messages to user
// Parameters: 
//	msg - the message to display (string)
//	showmethod - how to display the message (string)
//		'popup' = JavaScript alert	
// Returns: nothing
////////////////////////////////////////////////////////
function common_showDataError(param_common_msg, param_common_showmethod)
{
	alert(param_common_msg);
	return false;
}

////////////////////////////////////////////////////////
// Function: common_setInnerHTML
// Description: Sets the HTML for a provided tag replacing
//		whatever was there before
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
//	HTMLid - the HTML id of the element to insert into (string)
//	HTMLtoinsert - the actual HTML to insert (string)
// Returns: nothing
////////////////////////////////////////////////////////
function common_setInnerHTML(param_common_HTMLFrame, param_common_HTMLid, param_common_HTMLtoinsert)
{
	try
	{
		if(param_common_HTMLFrame != null)
		{
			param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
			param_common_HTMLFrame = param_common_HTMLFrame.document;
		} else
		{
			param_common_HTMLFrame = document;
		}
		var curelement = param_common_HTMLFrame.getElementById(param_common_HTMLid);	
		curelement.innerHTML = param_common_HTMLtoinsert;
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_appendToInnerHTML
// Description: Sets the HTML for a provided tag by adding
//		the new HTML to the end of whatever was there before
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
//	HTMLid - the HTML id of the element to insert into (string)
//	HTMLtoinsert - the actual HTML to insert (string)
// Returns: nothing	
////////////////////////////////////////////////////////
function common_appendToInnerHTML(param_common_HTMLFrame, param_common_HTMLid, param_common_HTMLtoinsert)
{
	try
	{
		if(param_common_HTMLFrame != null)
		{
			param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
			param_common_HTMLFrame = param_common_HTMLFrame.document;
		} else
		{
			param_common_HTMLFrame = document;
		}
		var curelement = param_common_HTMLFrame.getElementById(param_common_HTMLid);	
		var curvalue = curelement.innerHTML;
		var newvalue = curvalue + param_common_HTMLtoinsert;
		curelement.innerHTML = newvalue;
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_prependToInnerHTML
// Description: Sets the HTML for a provided tag by adding
//		the new HTML to the beginning of whatever was there before
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
//	HTMLid - the HTML id of the element to insert into (string)
//	HTMLtoinsert - the actual HTML to insert (string)
// Returns: nothing
////////////////////////////////////////////////////////
function common_prependToInnerHTML(param_common_HTMLFrame, param_common_HTMLid, param_common_HTMLtoinsert)
{
	try
	{	
		if(param_common_HTMLFrame != null)
		{
			param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
			param_common_HTMLFrame = param_common_HTMLFrame.document;
		} else
		{
			param_common_HTMLFrame = document;
		}
		var curelement = param_common_HTMLFrame.getElementById(param_common_HTMLid);	
		var curvalue = curelement.innerHTML;
		curelement.innerHTML = param_common_HTMLtoinsert + curvalue;
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_turnOffWait
// Description: Turns off the "Please Wait..." messaging so users
//		get some indication that the server is being contacted
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
// Returns: nothing
////////////////////////////////////////////////////////
function common_turnOffWait(param_common_HTMLFrame)
{
	if(param_common_HTMLFrame != null)
	{
		common_setInnerHTML(param_common_HTMLFrame, common_local_HTMLWaitMsgID, "");	
		common_disableHTML(param_common_HTMLFrame, common_local_HTMLWaitSectionID);
	}
	common_setInnerHTML(common_global_topFrameObject, common_local_HTMLWaitMsgID, "");	
	common_disableHTML(common_global_topFrameObject, common_local_HTMLWaitSectionID);
	common_enableHTML(common_global_topFrameObject, common_local_HTMLLastBillingCycleID);
}

////////////////////////////////////////////////////////
// Function: common_turnOnWait
// Description: Turns on the "Please Wait..." messaging so users
//		get some indication that the server is being contacted
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
//	msg - the optional message to display to the user (string)
// Returns: nothing
////////////////////////////////////////////////////////
function common_turnOnWait(param_common_HTMLFrame, param_common_msg)
{
	if(param_common_msg == null)
		param_common_msg = "Please wait... contacting server...";
	common_setInnerHTML(param_common_HTMLFrame, common_local_HTMLWaitMsgID, param_common_msg);	
	common_setInnerHTML(common_global_topFrameObject, common_local_HTMLWaitMsgID, param_common_msg);
	common_disableHTML(common_global_topFrameObject, common_local_HTMLLastBillingCycleID);
	common_enableHTML(param_common_HTMLFrame, common_local_HTMLWaitSectionID);
	common_enableHTML(common_global_topFrameObject, common_local_HTMLWaitSectionID);
}

////////////////////////////////////////////////////////
// Function: common_turnOffUserMessage
// Description: Turns off the message displayed to users
//		after events are returned from the server
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
// Returns: nothing
////////////////////////////////////////////////////////
function common_turnOffUserMessage(param_common_HTMLFrame)
{
	common_setInnerHTML(param_common_HTMLFrame, common_local_HTMLUserMessageMsgID, "");	
	common_disableHTML(param_common_HTMLFrame, common_local_HTMLUserMessageSectionID);
}

////////////////////////////////////////////////////////
// Function: common_turnOnUserMessage
// Description: Turns on the message displayed to users
//		after events are returned from the server
// Parameters: 
//	HTMLFrame - the location/window to insert into (object)
//	HTMLtoinsert - the actual HTML message to insert (string)
// Returns: nothing
////////////////////////////////////////////////////////
function common_turnOnUserMessage(param_common_HTMLFrame, param_common_HTMLtoinsert)
{
	common_setInnerHTML(param_common_HTMLFrame, common_local_HTMLUserMessageMsgID, param_common_HTMLtoinsert);	
	common_enableHTML(param_common_HTMLFrame, common_local_HTMLUserMessageSectionID);
}

////////////////////////////////////////////////////////
// Function: common_navMenuSetup
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_navMenuSetup(param_common_menus)
{
	common_local_navMenus = new Array();
	for(var x=0;x<param_common_menus.length;x++)
	{
		var cmenu = param_common_menus[x];
		common_local_navMenus[x] = cmenu;
	}
}

////////////////////////////////////////////////////////
// Function: common_navMenuMouseOver
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_navMenuMouseOver(param_common_whichmenu)
{
	if(common_local_navMenusTimeoutId != null)
	{
		window.clearTimeout(common_local_navMenusTimeoutId);
		common_local_navMenusTimeoutId = null;
	}
	
	for(var x=0;x<common_local_navMenus.length;x++)
	{
		var cmenu = common_local_navMenus[x];
		if(param_common_whichmenu != cmenu)
			common_disableHTML(null, cmenu);
		else
		{
			common_enableHTML(null, param_common_whichmenu);
		}
	}
}

////////////////////////////////////////////////////////
// Function: common_navMenuMouseOut
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_navMenuMouseOut(param_common_whichmenu)
{
	if(common_local_navMenusTimeoutId != null)
	{
		window.clearTimeout(common_local_navMenusTimeoutId);
		common_local_navMenusTimeoutId = null;
	}
	common_local_navMenusTimeoutId = window.setTimeout("common_navSubMenuTurnOff()", "5000");
}

////////////////////////////////////////////////////////
// Function: common_navSubMenuMouseOver
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_navSubMenuMouseOver(param_common_whichmenu)
{
	if(common_local_navMenusTimeoutId != null)
	{
		window.clearTimeout(common_local_navMenusTimeoutId);
		common_local_navMenusTimeoutId = null;	
	}
}

////////////////////////////////////////////////////////
// Function: common_navSubMenuMouseOut
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_navSubMenuMouseOut(param_common_whichmenu)
{
	if(common_local_navMenusTimeoutId != null)
	{
		window.clearTimeout(common_local_navMenusTimeoutId);
		common_local_navMenusTimeoutId = null;
	}
	common_local_navMenusTimeoutId = window.setTimeout("common_navSubMenuTurnOff()", "5000");
}

////////////////////////////////////////////////////////
// Function: common_navSubMenuTurnOff
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_navSubMenuTurnOff()
{
	if(common_local_navMenusTimeoutId != null)
	{
		window.clearTimeout(common_local_navMenusTimeoutId);
		common_local_navMenusTimeoutId = null;	
	}
	for(var x=0;x<common_local_navMenus.length;x++)
	{
		var cmenu = common_local_navMenus[x];
		common_disableHTML(null, cmenu);
	}
}

////////////////////////////////////////////////////////
// Function: common_clickTableRow
// Description:
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_clickTableRow(param_common_tableID, param_common_rowID)
{
	var tableobject = document.getElementById(param_common_tableID);
	if( tableobject == null ) return;
	if(param_common_rowID == "last")
	{
		param_common_rowID = tableobject.rows.length - 1;
	}
	var activeRow = tableobject.rows[param_common_rowID];
	if( activeRow == null ) return;
	activeRow.click();
}

////////////////////////////////////////////////////////
// Function: common_enableHTML
// Description: Turns a section of HTML "on" so it is visible
// Parameters: 
//	HTMLFrame - the location/window to turn on (object)
//	HTMLid - the HTML id of the element to turn on (string)
//	HTMLimageid  - the HTML id of the image to toggle (string)
//		'null' = no image
//	imagebasename - part of the image name used to dynamically build the
//		'on' and 'off' images - note that /images/<imagebasename>_off.gif and
//		/images/<imagebasename>_on.gif are the names that will be generated.
// Returns: nothing	
////////////////////////////////////////////////////////
function common_enableHTML(param_common_HTMLFrame, param_common_HTMLid, param_common_HTMLimageid, param_common_imagebasename)
{	
	try
	{
		var doc = null;
		if(param_common_HTMLFrame != null)
		{
			param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
			doc	= param_common_HTMLFrame.document;
		} else
		{
			doc = document;
		}
		var curelement = doc.getElementById(param_common_HTMLid);
		var curimage = null;
		
		if(param_common_HTMLimageid != null)
		{
			curimage = doc.getElementById(param_common_HTMLimageid);
		}
		if (curelement.style.display=="none")
		{
			curelement.style.display="";
			if(curimage != null) curimage.src = "images/" + param_common_imagebasename + "_on.gif";
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_isValidHTMLId
// Description:
// Parameters:
////////////////////////////////////////////////////////
function common_isValidHTMLId(param_common_HTMLFrame, param_common_HTMLid)
{
	var doc = null;
	if(param_common_HTMLFrame != null)
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		doc	= param_common_HTMLFrame.document;
	} else
	{
		doc = document;
	}
	var curelement = doc.getElementById(param_common_HTMLid);
	return curelement;
}

////////////////////////////////////////////////////////
// Function: common_disableHTML
// Description: Turns a section of HTML "off" so it is NOT visible
// Parameters: 
//	HTMLFrame - the location/window to turn off (object)
//	HTMLid - the HTML id of the element to turn off	(string)
//	HTMLimageid  - the HTML id of the image to toggle (string)
//		'null' = no image
//	imagebasename - part of the image name used to dynamically build the
//		'on' and 'off' images - note that /images/<imagebasename>_off.gif and
//		/images/<imagebasename>_on.gif are the names that will be generated.// Returns: nothing	
////////////////////////////////////////////////////////
function common_disableHTML(param_common_HTMLFrame, param_common_HTMLid, param_common_HTMLimageid, param_common_imagebasename, param_common_HTMLimage2id, param_common_image2basename)
{	
	try
	{
		var doc = null;
		if(param_common_HTMLFrame != null)
		{
			param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
			doc	= param_common_HTMLFrame.document;
		} else
		{
			doc = document;
		}
		var curelement = doc.getElementById(param_common_HTMLid);
		curelement.style.display="none";
		
		var curimage = null;
		
		if(param_common_HTMLimageid != null)
		{
			curimage = doc.getElementById(param_common_HTMLimageid);
			if (curimage != null) {
				curimage.src = "images/" + param_common_imagebasename + "_off.gif";
			}
	
			curimage2 = doc.getElementById(param_common_HTMLimage2id);
			if (curimage2 != null) {
				curimage2.src = "images/" + param_common_image2basename + "_off.gif";
			}
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_toggleHTML
// Description: Turns a section of HTML "on" so it is visible if
//		it is "off", or vice versa
// Parameters: 
//	HTMLFrame - the location/window to toggle (object)
//	HTMLid - the HTML id of the element to toggle (string)
//	HTMLimageid  - the HTML id of the image to toggle (string)
//		'null' = no image
//	imagebasename - part of the image name used to dynamically build the
//		'on' and 'off' images - note that /images/<imagebasename>_off.gif and
//		/images/<imagebasename>_on.gif are the names that will be generated.
//	HTMLimage2id  - same as HTMLimageid, just another image (support for 2)
//	image2basename - same as imagebasename, just another image (support for 2)
// Returns: nothing	
////////////////////////////////////////////////////////
function common_toggleHTML(param_common_HTMLFrame, param_common_HTMLid, param_common_HTMLimageid, param_common_imagebasename, param_common_HTMLimage2id, param_common_image2basename)
{	
	try
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		param_common_HTMLid = new String(param_common_HTMLid);
		var newlist = param_common_HTMLid.split(",");
		var len = newlist.length;
		for(var lctr=0;lctr<len;lctr++)
		{
			var clistitem = newlist[lctr];
			var curelement = param_common_HTMLFrame.document.getElementById(clistitem);
			var curimage = null;
		
			if(param_common_HTMLimageid != null)
			{
				curimage = param_common_HTMLFrame.document.getElementById(param_common_HTMLimageid);
			}
			var curimage2 = null;
			if(param_common_HTMLimage2id != null)
			{
				curimage2 = param_common_HTMLFrame.document.getElementById(param_common_HTMLimage2id);
			}
			
			if (curelement.style.display=="none")
			{
				curelement.style.display="";
				if(curimage != null) curimage.src = "images/" + param_common_imagebasename + "_on.gif";
				if(curimage2 != null) curimage2.src = "images/" + param_common_image2basename + "_on.gif";
			}
			else
			{
				curelement.style.display="none";
				if(curimage != null) curimage.src = "images/" + param_common_imagebasename + "_off.gif";
				if(curimage2 != null) curimage2.src = "images/" + param_common_image2basename + "_off.gif";
			}
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_makeInvisibleFrame
// Description: 
// Parameters: 
// Returns: nothing	
////////////////////////////////////////////////////////
function common_makeInvisibleFrame(param_common_HTMLFrame, param_common_invisiblesize)
{
	try
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		var frametype = (param_common_HTMLFrame.parent.document.body.cols)? "cols" : "rows";
		
		var newframesize = param_common_invisiblesize;
		if (frametype == "rows")
		{
			param_common_HTMLFrame.parent.document.body.rows = newframesize;
		}
		else if (frametype == "cols")
		{
			param_common_HTMLFrame.parent.document.body.cols = newframesize;
		}
		param_common_HTMLFrame.parent.document.body.frameSpacing = "0";
	}
	catch(e)
	{
		// Nothing to do...
	}
} 

////////////////////////////////////////////////////////
// Function: common_makeVisibleFrame
// Description: 
// Parameters: 
// Returns: nothing	
////////////////////////////////////////////////////////
function common_makeVisibleFrame(param_common_HTMLFrame, param_common_bigsize)
{
	try
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		var frametype = (param_common_HTMLFrame.parent.document.body.cols)? "cols" : "rows";
		
		var newframesize = param_common_bigsize;
		
		if (frametype == "rows")
		{
			param_common_HTMLFrame.parent.document.body.rows = newframesize;
		}
		else if (frametype == "cols")
		{
			param_common_HTMLFrame.parent.document.body.cols = newframesize;
		}
		param_common_HTMLFrame.parent.document.body.frameSpacing = "5";
	}
	catch(e)
	{
		// Nothing to do...
	}
} 

////////////////////////////////////////////////////////
// Function: common_collapseFrame
// Description: collapses a frame to a smaller size 
// Parameters: 
//	HTMLFrame - the location/window to toggle (object)
//  smallsize - size to collapse frame to as a frameset cols/rows attribute value
//	HTMLimageid  - the HTML id of the image to toggle (string)
//		'null' = no image
//	imagebasename - part of the image name used to dynamically build the
//		'on' and 'off' images - note that /images/<imagebasename>_off.gif and
//		/images/<imagebasename>_on.gif are the names that will be generated.
// Returns: nothing	
////////////////////////////////////////////////////////
function common_collapseFrame(param_common_HTMLFrame, param_common_smallsize, param_common_HTMLimageid, param_common_imagebasename)
{
	try
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		var frametype = (param_common_HTMLFrame.parent.document.body.cols)? "cols" : "rows";
		
		var curimage = null;
		if(param_common_HTMLimageid != null)
		{
			curimage = param_common_HTMLFrame.document.getElementById(param_common_HTMLimageid);
		}
	
		var newframesize = param_common_smallsize;
		var newimg = "images/" + param_common_imagebasename + "_off.gif";
		
		if (frametype == "rows")
		{
			param_common_HTMLFrame.parent.document.body.rows = newframesize;
		}
		else if (frametype == "cols")
		{
			param_common_HTMLFrame.parent.document.body.cols = newframesize;
		}
		if(curimage != null) 
		{
			curimage.src = newimg;
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
} 


////////////////////////////////////////////////////////
// Function: common_expandFrame
// Description: expands a frame to a larger size 
// Parameters: 
//	HTMLFrame - the location/window to toggle (object)
//  bigsize - size to expad frame to as a frameset cols/rows attribute value
//	HTMLimageid  - the HTML id of the image to toggle (string)
//		'null' = no image
//	imagebasename - part of the image name used to dynamically build the
//		'on' and 'off' images - note that /images/<imagebasename>_off.gif and
//		/images/<imagebasename>_on.gif are the names that will be generated.
//	smallsize - size the frame would be if it were collapsed
// Returns: nothing	
////////////////////////////////////////////////////////
function common_expandFrame(param_common_HTMLFrame, param_common_bigsize, param_common_HTMLimageid, param_common_imagebasename, param_common_smallsize)
{
	try
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		var frametype = (param_common_HTMLFrame.parent.document.body.cols)? "cols" : "rows";
		
		var curimage = null;
		if(param_common_HTMLimageid != null)
		{
			curimage = param_common_HTMLFrame.document.getElementById(param_common_HTMLimageid);
		}
	
		var newframesize = param_common_bigsize;
		var newimg = "images/" + param_common_imagebasename + "_on.gif";
		
		if (frametype == "rows")
		{
			if(param_common_smallsize != null)
			{
				if(param_common_smallsize == param_common_HTMLFrame.parent.document.body.rows)
				{
					param_common_HTMLFrame.parent.document.body.rows = newframesize;
				}
			} else
			{
				param_common_HTMLFrame.parent.document.body.rows = newframesize;
			}
		}
		else if (frametype == "cols")
		{
			if(param_common_smallsize != null)
			{
				if(param_common_smallsize == param_common_HTMLFrame.parent.document.body.cols)
				{		
					param_common_HTMLFrame.parent.document.body.cols = newframesize;
				}
			} else
			{
				param_common_HTMLFrame.parent.document.body.cols = newframesize;
			}
		}
		if(curimage != null) 
		{
			curimage.src = newimg;
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
} 

////////////////////////////////////////////////////////
// Function: common_toggleFrame
// Description: Turns a frame "on" so it is visible if
//		it is "off", or vice versa
// Parameters: 
//	HTMLFrame - the location/window to toggle (object)
//	HTMLimageid  - the HTML id of the image to toggle (string)
//		'null' = no image
//	imagebasename - part of the image name used to dynamically build the
//		'on' and 'off' images - note that /images/<imagebasename>_off.gif and
//		/images/<imagebasename>_on.gif are the names that will be generated.
// Returns: nothing	
////////////////////////////////////////////////////////
function common_toggleFrame(param_common_HTMLFrame, param_common_HTMLimageid, param_common_smallsize, param_common_bigsize, param_common_imagebasename)
{		
	try
	{
		param_common_HTMLFrame = common_local_getFramePointer(param_common_HTMLFrame);
		var frametype = (param_common_HTMLFrame.parent.document.body.cols)? "cols" : "rows";
		
		var curimage = null;
		if(param_common_HTMLimageid != null)
		{
			curimage = param_common_HTMLFrame.document.getElementById(param_common_HTMLimageid);
		}
		
		var newimg = "images/" + param_common_imagebasename + "_off.gif";
		
		var newframesize = param_common_smallsize;
		
		if (frametype == "rows")
		{
			if(param_common_smallsize == param_common_HTMLFrame.parent.document.body.rows)
			{
				newframesize = param_common_bigsize;
				newimg = "images/" + param_common_imagebasename + "_on.gif";
			}
			param_common_HTMLFrame.parent.document.body.rows = newframesize;
		}
		else if (frametype == "cols")
		{
			if(param_common_smallsize == param_common_HTMLFrame.parent.document.body.cols)
			{
				newframesize = param_common_bigsize;
				newimg = "images/" + param_common_imagebasename + "_on.gif";
			}
			param_common_HTMLFrame.parent.document.body.cols = newframesize;
		}
		if(curimage != null) 
		{
			curimage.src = newimg;
		}
	}
	catch(e)
	{
		// Nothing to do...
	}
}

////////////////////////////////////////////////////////
// Function: common_generateArrayFromStringList
// Description:
// Parameters:
// Returns: 
////////////////////////////////////////////////////////
function common_generateArrayFromStringList(param_common_list)
{
	var newstring = new String(param_common_list);
	var na = newstring.split(",");
	return na;
}

////////////////////////////////////////////////////////
// Function: common_confirmPrompt
// Description: Prompts the user via JavaScript confirm
//		asking if they really want to do something
// Parameters:
//	message - the prompt to display to the user
// Returns: true if the user confirms, false otherwise	(boolean)
////////////////////////////////////////////////////////
function common_confirmPrompt(param_common_message)
{
	if(confirm(param_common_message))
	{
		return true;
	}
	return false;	
}

////////////////////////////////////////////////////////
// Function: common_confirmCancel
// Description: Prompts the user via JavaScript confirm
//		asking if they really want to cancel
// Parameters: 
//	urltogoto - the URL to take the user if they 
//			confirm that they want to cancel (string)
//		'null' = just return true, do not redirect the user
// Returns: true if the user cancelled, false otherwise	(boolean)
////////////////////////////////////////////////////////
function common_confirmCancel(param_common_urltogoto)
{
	if(confirm("Are you sure you want to cancel?"))
	{
		if(param_common_urltogoto != null)
			document.location.href = param_common_urltogoto;
		return true;
	}
	return false;	
}

////////////////////////////////////////////////////////
// Function: common_confirmDelete
// Description: Prompts the user via JavaScript confirm
//		asking if they really want to delete something
// Parameters: 
//	itemtodelete - name of the item being deleted (string)
//	urltogoto - URL to take the user if they
//			confirm that they want to cancel (string)
//		'null' = just return true, do not redirect the user
// Returns: true if the user wants to delete, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_confirmDelete(param_common_itemtodelete, param_common_urltogoto)
{
	if(confirm("Are you sure you want to delete this " + param_common_itemtodelete + "?"))
	{
		if(param_common_urltogoto != null)
			document.location.href = param_common_urltogoto;
		return true;
	}
	return false;	
}

////////////////////////////////////////////////////////
// Function: common_dateCompare
// Description:
// Parameters: 
// Returns: -1, 0 or 1 (int)
////////////////////////////////////////////////////////
function common_dateCompare(param_common_format, param_common_first, param_common_second)
{
	if(param_common_first == "")
		param_common_first = common_global_effectiveMaxDate;
	if(param_common_second == "")
		param_common_second = common_global_effectiveMaxDate;
		
	var first = common_getDateAsNumber(param_common_format, param_common_first);
	var second = common_getDateAsNumber(param_common_format, param_common_second);
	
	if(first == second) return 0;
	
	var firstInt = parseInt(first,10);
	var secondInt = parseInt(second,10);
	if(firstInt < secondInt) return -1;
	if(firstInt == secondInt) return 0;
	if(firstInt > secondInt) return 1;
}

////////////////////////////////////////////////////////
// Function: common_compareDates
// Description:
// Parameters: 
// Returns: true if the first date is <= second date, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_compareDates(param_common_format, param_common_first, param_common_second)
{
	if(param_common_first == "")
		param_common_first = common_global_effectiveMaxDate;
	if(param_common_second == "")
		param_common_second = common_global_effectiveMaxDate;
		
	var start = common_getDateAsNumber(param_common_format, param_common_first);
	var end = common_getDateAsNumber(param_common_format, param_common_second);
	
	if(start == null || end == null) return false;
	
	var startInt = parseInt(start,10);
	var endInt = parseInt(end,10);
	if(endInt < startInt) return false;
	
	return true;
}

////////////////////////////////////////////////////////
// Function: common_dateDiff
// Description:
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_dateDiff(param_common_format, param_common_first, param_common_second)
{
	var first = common_getDateAsDate(param_common_format, param_common_first);
	var second = common_getDateAsDate(param_common_format, param_common_second);
	
	var firstInt = first.getTime();
	var secondInt = second.getTime();
	
	var dateDiff = parseInt(firstInt,10) - parseInt(secondInt,10);
	dateDiff = dateDiff/86400000;
	
	return dateDiff;
}

////////////////////////////////////////////////////////
// Function: common_setCurrentDate
// Description:
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_setCurrentDate(param_common_date)
{
	common_local_currentDate = param_common_date;
}

////////////////////////////////////////////////////////
// Function: common_getCurrentDate
// Description:
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_getCurrentDate()
{
	return common_local_currentDate;
}

////////////////////////////////////////////////////////
// Function: common_setThresholdDate
// Description:
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_setThresholdDate(param_common_date)
{
	common_local_thresholdDate = param_common_date;
}

////////////////////////////////////////////////////////
// Function: common_getThresholdDate
// Description:
// Parameters: 
// Returns: Nothing
////////////////////////////////////////////////////////
function common_getThresholdDate()
{
	return common_local_thresholdDate;
}

////////////////////////////////////////////////////////
// Function: common_getDateAsNumber
// Description:
// Parameters: 
// Returns: Date, converted to a YYYYmmdd formatted number (String)
function common_getDateAsNumber(param_common_format, param_common_date)
{
	var newDate = null;
	var instr = new String(param_common_date);
	
	if(param_common_format == "dd-MMM-yyyy")
	{
		if(instr.length != 11) return null;

		c_year = instr.substr(7,4);
		c_month = instr.substr(3,3);
		c_month = common_local_getMonth(c_month);
		c_day = instr.substr(0,2);
		
		newDate = "" + c_year + "" + c_month + "" + c_day;
	} else if(param_common_format == "mm/dd/yyyy")
	{
		if(instr.length != 10) return null;

		c_year = instr.substr(6,4);
		c_day = instr.substr(3,2);
		c_month = instr.substr(0,2);
		
		newDate = "" + c_year + "" + c_month + "" + c_day;
	}
	return newDate;
}

////////////////////////////////////////////////////////
// Function: common_getDateAsDate
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getDateAsDate(param_common_format, param_common_date)
{
	var tmpdate = null;
	
	var instr = new String(param_common_date);
	
	if(param_common_format == null)
	{
		param_common_format = "YYYYmmdd";
	}
	
	if(instr == null) return null;
	if(instr.length < 1) return null;
	
	var c_year = null;
	var c_month = null;
	var c_day = null;
	var n_year = null;
	var n_month = null;
	var n_day = null;
	
	if(param_common_format == "YYYYmmdd")
	{
		if(instr.length != 8) return null;

		if(common_isANumber(param_common_infield) == false)
		{
			return null;
		}
		
		c_year = instr.substr(0,4);
		c_month = instr.substr(4,2);
		c_month = common_local_getMonthInt(c_month);
		c_day = instr.substr(6,2);
		
		// Create a Date object
		var tmpdate = new Date(c_year,c_month-1,c_day);
		
	} else if(param_common_format == "dd-MMM-yyyy")
	{
		if(instr.length != 11) return null;

		c_year = instr.substr(7,4);
		c_month = instr.substr(3,3);

		c_month = common_local_getMonth(c_month);
		c_day = instr.substr(0,2);
		
		// Create a Date object
		var tmpdate = new Date(c_year, c_month-1, c_day);
		
	} else if(param_common_format == "mm/dd/yyyy")
	{
		if(instr.length != 10) return null;

		c_year = instr.substr(6,4);
		c_month = instr.substr(0,2);

		c_month = common_local_getMonth(c_month);
		c_day = instr.substr(3,2);
		
		// Create a Date object
		var tmpdate = new Date(c_year, c_month-1, c_day);
		
	}
	return tmpdate;
}

////////////////////////////////////////////////////////
// Function: common_isAYear
// Description: Validates if data is a year
// Parameters: 
// Returns: true if the string is a date, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAYear(param_common_infield)
{
	var instr = new String(common_removeWhiteSpace(param_common_infield))
	if(instr.length != 4) return false;
	if(common_isANumber(param_common_infield) == false)
	{
		return false;
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isADate
// Description: Validates if data is a date
// Parameters: 
//	infield - form field to evaluate to see if it is a date (form input object)
//  format - the format the date should be in (string)
//		'YYYYmmdd' = the default format
// Returns: true if the string is a date, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isADate(param_common_infield, param_common_format)
{
	var instr = new String(common_removeWhiteSpace(param_common_infield))
	
	if(param_common_format == null)
	{
		param_common_format = "YYYYmmdd";
	}
	
	if(instr == null) return true;
	if(instr.length < 1) return true;
	
	var c_year = null;
	var c_month = null;
	var c_day = null;
	var n_year = null;
	var n_month = null;
	var n_day = null;
	
	if(param_common_format == "YYYYmmdd")
	{
		if(instr.length != 8) return false;
		if( instr.search( /\d{8}/ ) == -1 ) return false;


		if(common_isANumber(param_common_infield) == false)
		{
			return false;
		}
		
		c_year = instr.substr(0,4);
		c_month = instr.substr(4,2);
		c_month = common_local_getMonthInt(c_month);
		c_day = instr.substr(6,2);
		
		// Create a Date object
		var tmpdate = new Date(c_year,c_month-1,c_day);
		
		// Take resulting Date and reconstruct
		// to original format and see if they match!
		n_year = tmpdate.getFullYear();
		n_month = tmpdate.getMonth() + 1;
		n_day = tmpdate.getDate();

		if(parseInt(n_year,10) != parseInt(c_year,10) || 
			parseInt(n_month,10) != parseInt(c_month,10) || 
			parseInt(c_day,10) != parseInt(n_day,10))
		{
			return false;
		}
	} else if(param_common_format == "dd-MMM-yyyy" || param_common_format == "mm/dd/yyyy" || param_common_format == "dd-MMM-yyyy HH:mm:ss")
	{
		var timeStr = null;
		if(param_common_format == "dd-MMM-yyyy HH:mm:ss")
		{
		 	if(instr.length != 20) return false;
		 	splitDateTime = instr.split(" ");
		 	instr = splitDateTime[0];
		 	timeStr = splitDateTime[1];
			if( instr.search( /\d\d-[A-Za-z]{3}-\d\d\d\d/ ) == -1 ) return false;
		} else if(param_common_format == "mm/dd/yyyy")
		{
		 	if(instr.length != 10) return false;
			if( instr.search( /\d\d\/\d\d\/\d\d\d\d/ ) == -1 ) return false;
		} else
		{
			if(instr.length != 11) return false;
		}
		
		if(param_common_format == "mm/dd/yyyy")
		{
			c_year = instr.substr(6,4);
			c_month = instr.substr(0,2);
			c_day = instr.substr(3,2);			
		} else
		{
			c_year = instr.substr(7,4);
			c_month = instr.substr(3,3);
	
			c_month = common_local_getMonth(c_month);
			c_day = instr.substr(0,2);
		}
				
		// Create a Date object
		var tmpdate = new Date(c_year, c_month-1, c_day);
		// Take resulting Date and reconstruct
		// to original format and see if they match!
		n_year = tmpdate.getFullYear();
		n_month = tmpdate.getMonth() + 1;
		n_day = tmpdate.getDate();

		if(parseInt(n_year,10) != parseInt(c_year,10) || 
			parseInt(n_month,10) != parseInt(c_month,10) || 
			parseInt(c_day,10) != parseInt(n_day,10))
		{
			return false;
		}
		
		if(timeStr != null)
		{
			if( timeStr.search( /\d\d:\d\d:\d\d/ ) == -1 ) return false;
			var timeParts = timeStr.split(":");
			
			if(parseInt(timeParts[0],10) > 24 ||
				parseInt(timeParts[1],10) > 59 ||
				parseInt(timeParts[2],10) > 59)
			{
				return false;
			}
		}
	}
	return true;
}

/////////////////////////
///////////////////////////////
// Function: common_isANumber
// Description: Validates if data is a number
// Parameters: 
//	infield - form field to evaluate to see if it is a number (form input object)
// Returns: true if the string is a number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isANumber(param_common_infield)
{
	var instr = new String(common_removeWhiteSpace(param_common_infield))
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isANumberValue
// Description: Validates if data is a number
// Parameters: 
//	infield - form field to evaluate to see if it is a number (form input object)
// Returns: true if the string is a number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isANumberValue( value )
{
	var instr = common_stringRemoveWhiteSpace( new String( value ));
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isANumber_Negative
// Description: Validates if data is a number (positive or negative)
// Parameters: 
//	infield - form field to evaluate to see if it is a number (form input object)
// Returns: true if the string is a number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isANumber_Negative(param_common_infield)
{
	var instr = new String(common_removeWhiteSpace(param_common_infield))
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
			if ((x == 0) && (instr.charAt(x) == '-'))		
				continue;
				
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isANumberValue_Negative
// Description: Validates if data is a number (positive or negative)
// Parameters: 
//	infield - form field to evaluate to see if it is a number (form input object)
// Returns: true if the string is a number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isANumberValue_Negative( value )
{
	var instr = common_stringRemoveWhiteSpace( new String( value ));
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
			if ((x == 0) && (instr.charAt(x) == '-'))		
				continue;
						
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_hasAnyDigits
// Description: Checks if value has numbers
// Parameters: 
//	infield - form field object to evaluate to see if it contains any numbers
// Returns: true if the string contains any numbers, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_hasAnyDigits(param_common_infield)
{

	var instr = new String(common_removeWhiteSpace(param_common_infield))
	
	if(instr == null) {
		return false;
	}
	if(instr.length < 1) {
		return false;
	}

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) >= '0' && instr.charAt(x) <= '9')
		{
			return true;
		}
	}
	return false;
}

////////////////////////////////////////////////////////
// Function: common_hasOnlyDigits
// Description: Checks if value has numbers
// Parameters: 
//	infield - form field object to evaluate to see if it contains any numbers
// Returns: true if the string contains any numbers, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_hasOnlyDigits(param_common_infield)
{

	var instr = new String(common_removeWhiteSpace(param_common_infield))
	
	if(instr == null) {
		return false;
	}
	if(instr.length < 1) {
		return false;
	}

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' && instr.charAt(x) > '9')
		{
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CSV
// Description: Validates if data is a floating point number
// Parameters: 
//	infield - form field to evaluate to see if it is a float (form input object)
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloat_CSV(param_common_infield)
{
	return common_isAFloatValue_CSV(param_common_infield.value);
}

////////////////////////////////////////////////////////
// Function: common_isAFloatValue_CSV
// Description: Validates if data is a floating point number
// Parameters: 
//	infield - form field to evaluate to see if it is a float (form input object)
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloatValue_CSV(param_common_value)
{
	var str = common_removeCommas(param_common_value);
	return common_isAFloatValue(str);
}

////////////////////////////////////////////////////////
// Function: common_isAFloat
// Description: Validates if data is a floating point number
// Parameters: 
//	infield - form field to evaluate to see if it is a float (form input object)
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloat(param_common_infield)
{
	var instr = new String(common_removeWhiteSpace(param_common_infield));
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

    var foundonedot = false;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(instr.charAt(x) == '.')
		    {
			    if(foundonedot) return false;
			    foundonedot = true;
			} else
			{
				return false;
			}
		}
	}
	return true;
}

function common_isAFloat_CheckLength_CSV_Negative( param_common_infield, param_common_left, param_common_right)
{
	return common_isAFloat_CheckLength_CSV_NegativeValue( common_getValue(param_common_infield), param_common_left, param_common_right);
}

function common_isAFloat_CheckLength_Negative( param_common_infield, param_common_left, param_common_right)
{
	return common_isAFloat_CheckLength_NegativeValue( common_getValue(param_common_infield), param_common_left, param_common_right);
}

function common_isAFloat_CheckLength( param_common_infield, param_common_left, param_common_right)
{
	return common_isAFloat_CheckLength_Value( common_getValue(param_common_infield), param_common_left, param_common_right);
}

function common_isAFloat_CheckLength_CSV( param_common_infield, param_common_left, param_common_right)
{
	return common_isAFloat_CheckLength_CSV_Value( common_getValue(param_common_infield), param_common_left, param_common_right);
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_Negative
// Description: Validates if data is a floating point number (positive or negative)
// Parameters: 
//	infield - form field to evaluate to see if it is a float (form input object)
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloat_Negative( param_common_infield )
{
	return common_isAFloat_NegativeValue( param_common_infield.value );
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CSV_Negative
// Description: Validates if data is a floating point number (positive or negative)
// Parameters: 
//	infield - form field to evaluate to see if it is a float (form input object)
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloat_CSV_Negative( param_common_infield )
{
	return common_isAFloat_CSV_NegativeValue( param_common_infield.value );
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CheckLength_Value
// Description: 
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_isAFloat_CheckLength_Value( param_common_value, param_common_left, param_common_right )
{
	var instr = common_stringRemoveWhiteSpace( new String(param_common_value) );
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

    var founddot = false;
    var beforedot = 0;
    var afterdot = 0;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(instr.charAt(x) == '.')
		    {
			    founddot = true;
			} else
			{
				return false;
			}
		} else
		{
			if(founddot)
			{
				afterdot++;
			} else
			{
				beforedot++;
			}
		}
	}
	if(beforedot <= param_common_left && 
		afterdot <= param_common_right)
	{
		return true;
	}
		
	return false;
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CheckLength_NegativeValue
// Description: 
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_isAFloat_CheckLength_NegativeValue( param_common_value, param_common_left, param_common_right )
{
	var instr = common_stringRemoveWhiteSpace( new String(param_common_value) );
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

    var founddot = false;
    var founddash = false;
    var beforedot = 0;
    var afterdot = 0;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(instr.charAt(x) == '.')
		    {
			    founddot = true;
			} else if(instr.charAt(x) == '-')
			{
				founddash = true;
			} else
			{
				return false;
			}
		} else
		{
			if(founddot)
			{
				afterdot++;
			} else
			{
				beforedot++;
			}
		}
	}
	if(beforedot <= param_common_left && 
		afterdot <= param_common_right)
	{
		return true;
	}
		
	return false;
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CheckLength_CSV_Value
// Description: 
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_isAFloat_CheckLength_CSV_Value( param_common_value, param_common_left, param_common_right )
{
	var str = common_removeCommas(param_common_value);
	return common_isAFloat_CheckLength_Value( str, param_common_left, param_common_right );	
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CheckLength_CSV_NegativeValue
// Description: 
// Parameters: 
// Returns: 
////////////////////////////////////////////////////////
function common_isAFloat_CheckLength_CSV_NegativeValue( param_common_value, param_common_left, param_common_right )
{
	var str = common_removeCommas(param_common_value);
	return common_isAFloat_CheckLength_NegativeValue( str, param_common_left, param_common_right );	
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_CSV_NegativeValue
// Description: Validates if data is a floating point number (positive or negative)
// Parameters: 
//	value - value to check
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloat_CSV_NegativeValue( param_common_value )
{
	var str = common_removeCommas(param_common_value);
	return common_isAFloat_NegativeValue(str);
}

////////////////////////////////////////////////////////
// Function: common_isAFloat_Negative
// Description: Validates if data is a floating point number (positive or negative)
// Parameters: 
//	value - value to check
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloat_NegativeValue( value )
{
	var instr = common_stringRemoveWhiteSpace( new String(value) );
	
	if(instr == null) return true;
	if(instr.length < 1) return true;

    var foundonedot = false;
    var foundonedash = false;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(instr.charAt(x) == '.')
		    {
			    if(foundonedot) return false;
			    foundonedot = true;
			} else if(instr.charAt(x) == '-')
			{
				if(foundonedash) return false;
				if(x != 0) return false;
			    foundonedash = true;
			} else
			{
				return false;
			}
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isAFloatValue
// Description: Validates if data is a floating point number
// Parameters: 
//	infield - value to evaluate to see if it is a float (form input object)
// Returns: true if the string is a floating point number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAFloatValue( value )
{
	var instr = common_stringRemoveWhiteSpace( new String(value) );
	if(instr == null) return true;
	if(instr.length < 1) return true;

    var foundonedot = false;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(instr.charAt(x) == '.')
		    {
			    if(foundonedot) return false;
			    foundonedot = true;
			} else
			{
				return false;
			}
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isAnInteger_CSV
// Description: Validates if data is a valid e-mail address
// Parameters: 
//	param_common_infield - form field to evaluate to see if it is an integer
// Returns: true if the field is an integer, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAnInteger_CSV(param_common_infield)
{
	return common_isAnIntegerValue_CSV(param_common_infield.value);
}

////////////////////////////////////////////////////////
// Function: common_isAnIntegerValue_CSV
// Description: Validates if data is a valid e-mail address
// Parameters: 
//	param_common_infield - form field to evaluate to see if it is an integer
// Returns: true if the field is an integer, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAnIntegerValue_CSV(param_common_value)
{
	var str = common_removeCommas(param_common_value);
	return common_isAnIntegerValue(str);
}

////////////////////////////////////////////////////////
// Function: common_isAnInteger
// Description: Validates if data is a valid e-mail address
// Parameters: 
//	param_common_infield - form field to evaluate to see if it is an integer
// Returns: true if the field is an integer, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAnInteger(param_common_infield)
{
	if (common_isANumber(param_common_infield) == false)
	{
		return false;
	}
	
	if (common_checkLength(param_common_infield, null, 10) == false)
	{
		return false;
	}
	
	// integer values must be <= 2^31
	if (param_common_infield.value > common_local_maxint)
	{
		return false;
	} 
	
	return true;
}

function common_isAnIntegerValue( value )
{
	if (common_isANumberValue(value) == false)
	{
		return false;
	}
	
	// integer values must be <= 2^31
	if (value > common_local_maxint)
	{
		return false;
	} 
	
	return true;
}

// Same as common_isAnInteger, however, the value can be negative as well
function common_isAnInteger_CSV_Negative(param_common_infield)
{
	return common_isAnIntegerValue_CSV_Negative(param_common_infield.value)
}

// Same as common_isAnInteger, however, the value can be negative as well
function common_isAnInteger_CheckLength_CSV_Negative(param_common_infield, param_common_max)
{
	var str = common_removeCommas(param_common_infield.value);
	if(common_isAnIntegerValue_CSV_Negative(str) == true)
	{
		var instr = common_stringRemoveWhiteSpace( new String( str ));
		if(instr.length > param_common_max)
			return false;
	}
	return true;
}

// Same as common_isAnInteger, however, the value can be negative as well
function common_isAnIntegerValue_CSV_Negative(param_common_value)
{
	var str = common_removeCommas(param_common_value);

	return common_isAnIntegerValue_Negative(str);
}

// Same as common_isAnInteger, however, the value can be negative as well
function common_isAnInteger_Negative(param_common_infield)
{
	if (common_isANumber_Negative(param_common_infield) == false)
	{
		return false;
	}
	
	// For negative values, length can be up to 11 (must account for the negative sign)
	if (common_checkLength(param_common_infield, null, 11) == false)
	{
		return false;
	}
	
	// integer values must be <= 2^31
	if (param_common_infield.value >  common_local_maxint || param_common_infield.value < common_local_minint)
	{
		return false;
	} 
	
	return true;
}

// Same as common_isAnIntegerValue, however, the value can be negative as well
function common_isAnIntegerValue_Negative( value )
{
	if (common_isANumberValue_Negative(value) == false)
	{
		return false;
	}
	
	// integer values must be <= 2^31
	if (value > common_local_maxint || value < common_local_minint)
	{
		return false;
	} 
	
	return true;
}

////////////////////////////////////////////////////////
// Function: common_removeCommas
// Description: Removes commas from the value passed in
// Parameters: 
// Returns: the string with the commas removed (String)
////////////////////////////////////////////////////////
function common_removeCommas(param_common_value)
{
	var str = new String(param_common_value);

	var noCSV = str.split(",");
	str = "";
	for(var x=0;x<=noCSV.length-1;x++)
	{		
		str = str + noCSV[x];
	}
	return str;
}

////////////////////////////////////////////////////////
// Function: common_removeCommasFromField
// Description: Removes commas from the input field passed in
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_removeCommasFromField(param_common_field)
{
	var str = common_removeCommas(param_common_field.value);
	param_common_field.value = str;

	return;
}

////////////////////////////////////////////////////////
// Function: common_removeCommasFromFieldById
// Description: same as removeCommasFromField except with one less step
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_removeCommasFromFieldById(param_common_field_id)
{
	var field = document.getElementById(param_common_field_id);
	
	return common_removeCommasFromField(field);
}

////////////////////////////////////////////////////////
// Function: common_isAnEmailAddress
// Description: Validates if data is a valid e-mail address
// Parameters: 
//	infield - form field to evaluate to see if it is an e-mail address (form input object)
// Returns: true if the string is an e-mail address, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAnEmailAddress(param_common_infield)
{
	var instr = new String(param_common_infield.value);

	var at = instr.indexOf("@");
	var name = instr.substring(0, at);
	var isp = instr.substring(at + 1, instr.length);
	var dot = instr.lastIndexOf(".");

	if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (instr.length - 1)) 
	{
		return false;
	} 

	if (instr.indexOf(" ") > -1)
	{
		return false;
	}

	return true;
}

////////////////////////////////////////////////////////
// Function: common_isAPhone
// Description: Validates if data is a valid phone number
// Parameters: 
//	infield - form field to evaluate to see if it is a phone number (form input object)
// Returns: true if the string is a phone number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAPhone(param_common_infield)
{
	var instr = new String(param_common_infield.value);


	var parts = instr.split("-");
	if(parts.length != 3)
	{
		return false;
	}

	if (common_isANumberValue(parts[0]) == false || common_isANumberValue(parts[1]) == false || common_isANumberValue(parts[2]) == false)
	{
		return false;
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_isAURL
// Description: Validates if data is a valid URL
// Parameters: 
//	infield - form field to evaluate to see if it is a URL (form input object)
// Returns: true if the string is a URL, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isAURL(param_common_infield)
{
	var instr = new String(param_common_infield.value);
	
	if(instr == null) return true;
	if(instr.length == 0) return true;

	var fhttp = instr.indexOf("http://", 0);
	if(fhttp != 0)
	{
		return false;
	}

	return true;
}

////////////////////////////////////////////////////////
// Function: common_checkLength
// Description: Validates if data is a valid length
// Parameters: 
//	infield - form field to evaluate (form input object)
//	fieldname - the name of the field to display to the user if the length they
//			entered is invalid (string)
//		'null' = do not message the user at all
//	maxlength - maximum length allowed for the value in infield (integer)
// Returns: true if the string length is <= maxlength, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_checkLength(param_common_infield, param_common_fieldname, param_common_maxlength)
{
	if(param_common_infield.value.length > param_common_maxlength)
	{
		if(param_common_fieldname != null)
			alert(param_common_fieldname + " must be " + param_common_maxlength + " characters or less and you\nand you have entered " + param_common_infield.value.length + " characters.");
		return false;
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_checkLengthMin
// Description: Validates if data is at lease a valid length
// Parameters: 
//	infield - form field to evaluate (form input object)
//	fieldname - the name of the field to display to the user if the length they
//			entered is invalid (string)
//		'null' = do not message the user at all
//	minlength - minimum length needed for the value in infield (integer)
// Returns: true if the string length is >= minlength, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_checkLengthMin(param_common_infield, param_common_fieldname, param_common_maxlength)
{
	if(param_common_infield != null) {
		if (param_common_infield.value.length < param_common_maxlength) {
			if(param_common_fieldname != null)
				alert(param_common_fieldname + " must be at least " + param_common_maxlength + " characters\nand you have entered " + param_common_infield.value.length + " characters.");
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_checkLengthMax
// Description: Validates if data is not greater than the maximum
// Parameters: 
//	infield - form field to evaluate (form input object)
//	fieldname - the name of the field to display to the user if the length they
//			entered is invalid (string)
//		'null' = do not message the user at all
//	maxlength - max length needed for the value in infield (integer)
// Returns: true if the string length is <= maxlength, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_checkLengthMax(param_common_infield, param_common_fieldname, param_common_maxlength)
{
	if(param_common_infield != null) {
		if (param_common_infield.value.length > param_common_maxlength) {
			if(param_common_fieldname != null)
				alert(param_common_fieldname + " must be less than " + param_common_maxlength + " characters\nand you have entered " + param_common_infield.value.length + " characters.");
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_checkLengthMaxValue
// Description: Validates if data is not greater than the maximum
// Parameters: 
//	infield - form field to evaluate (form input object)
//	fieldname - the name of the field to display to the user if the length they
//			entered is invalid (string)
//		'null' = do not message the user at all
//	maxlength - max length needed for the value in infield (integer)
// Returns: true if the string length is <= maxlength, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_checkLengthMaxValue(param_common_value, param_common_fieldname, param_common_maxlength)
{
	if(param_common_value != null) {
		if (param_common_value.length > param_common_maxlength) {
			if(param_common_fieldname != null)
				alert(param_common_fieldname + " must be less than " + param_common_maxlength + " characters\nand you have entered " + param_common_infield.value.length + " characters.");
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_checkLengthEquals
// Description: Validates if data is equal to a length
// Parameters: 
//	infield - form field to evaluate (form input object)
//	fieldname - the name of the field to display to the user if the length they
//			entered is invalid (string)
//		'null' = do not message the user at all
//	requiredlength - required length needed for the value in infield (integer)
// Returns: true if the string length is == minlength, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_checkLengthEquals(param_common_infield, param_common_fieldname, param_common_requiredlength)
{
	if(param_common_infield != null) 
	{
		if(param_common_infield.value.length != param_common_requiredlength)
		{
			if(param_common_fieldname != null)
				alert(param_common_fieldname + " must be " + param_common_requiredlength + " characters\nand you have entered " + param_common_infield.value.length + " characters.");
			return false;
		}
	}
	return true;
}


////////////////////////////////////////////////////////
// Function: common_countWords
// Description: Counts the number of words in the form field
// Parameters: 
//	infield - form field to parse and count the number of words entered (form input object)	
// Returns: the number of words in the form field (integer)
////////////////////////////////////////////////////////
function common_countWords(param_common_infield)
{
	var fieldvalue = new String(param_common_infield.value);
	
	var idx = fieldvalue.indexOf(" ", 0);
	var word = 0;
	var i = 0;
	while(idx != -1)
	{
		i = fieldvalue.indexOf(" ", idx);
	    idx = i+1;
		word++;
	    if(i == -1)
	    {
	        idx=-1;
        }
	}
	if(word == 0 && fieldvalue.length != 0) word = 1;

	return word;
}

////////////////////////////////////////////////////////
// Function: common_countLines
// Description: Counts the number of lines in the form field
// Parameters: 
//	infield - form field to parse and count the number of lines entered (form input object)	
// Returns: the number of lines in the form field (integer)	
////////////////////////////////////////////////////////
function common_countLines(param_common_infield)
{
	var fieldvalue = new String(param_common_infield.value);
	
	var idx = fieldvalue.indexOf("\r\n", 0);
	var line = 0;
	var i = 0;
	while(idx != -1)
	{
		i = fieldvalue.indexOf("\r\n", idx+1);
	    idx = i;
	    line++;
	    if(i == -1)
	    {
	        idx=-1;
        }
	}
	if(line == 0 && fieldvalue.length != 0) line = 1;
	else if(line != 0)
	{
		if(fieldvalue[fieldvalue.length-2] != '\r' && fieldvalue[fieldvalue.length-1] != '\n')
		{
			line++;
		}
	}
	return line;
}

////////////////////////////////////////////////////////
// Function: common_setPickerContext
// Description: 
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setPickerContext(common_param_cbFunction,common_param_args)
{
	common_local_pickerContext = new PickerContext();
	common_local_pickerContext.setCallbackFunction(common_param_cbFunction);
	common_local_pickerContext.setCallbackFunctionArgs(common_param_args);	
}

////////////////////////////////////////////////////////
// Function: common_getPickerContext
// Description: 
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_getPickerContext()
{
	return common_local_pickerContext;
}

////////////////////////////////////////////////////////
// Function: common_setPopupContext
// Description: 
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_setPopupContext(common_param_cbFunction,common_param_args)
{
	common_local_popupContext = new PickerContext();
	common_local_popupContext.setCallbackFunction(common_param_cbFunction);
	common_local_popupContext.setCallbackFunctionArgs(common_param_args);	
}

////////////////////////////////////////////////////////
// Function: common_getPopupContext
// Description: 
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_getPopupContext()
{
	return common_local_popupContext;
}

////////////////////////////////////////////////////////
// Function: common_launchPicker
// Description: Deprecated
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_launchPicker()
{
	alert("This method has been deprecated (common_launchPicker).");
	return false;
}

////////////////////////////////////////////////////////
// Function: common_launchPopup
// Description: Opens up a new brower window with some page inside
// Parameters: 
// Returns: nothing
////////////////////////////////////////////////////////
function common_launchPopup(param_common_url, param_common_callbackFunction, param_common_callbackArgs, param_common_urlArgs, param_common_size)
{
	// Setup the context for the popup
	common_setPopupContext(param_common_callbackFunction, param_common_callbackArgs);
	var urltogoto = param_common_url;
	// Loop through urlArgs and append to the urltogoto
	
	if (param_common_urlArgs != null)
	{
		for (i=0; i<param_common_urlArgs.length; i++)
		{
			var paramPrefix = "param" + i;
			urltogoto = urltogoto + "&" + paramPrefix + "=" + param_common_urlArgs[i];
		}
	}	
	if(param_common_size == null)
		param_common_size = 6;
	common_openNewWindow(common_global_popupFrameObject, urltogoto, param_common_size);
}

////////////////////////////////////////////////////////
// Function: common_launchObjectPicker
// Description: Opens up a new brower window with the picker inside
// Parameters: 
//	which - the context for the picker (what do you want to pick?)
// Returns: nothing
////////////////////////////////////////////////////////
function common_launchObjectPicker(param_common_which, param_common_callbackFunction, param_common_callbackArgs, param_common_urlArgs)
{
	// Setup the context for the picker
	common_setPickerContext(param_common_callbackFunction, param_common_callbackArgs);
	var urltogoto = "/rbarWeb/picker.do?selectedComponent=" + param_common_which + "&rbarUIAction=picker&formTarget=" + common_global_pickerFrameObject;
	// Loop through urlArgs and append to the urltogoto
	
	if (param_common_urlArgs != null)
	{
		for (i=0; i<param_common_urlArgs.length; i++)
		{
			var paramPrefix = "param" + i;
			urltogoto = urltogoto + "&" + paramPrefix + "=" + param_common_urlArgs[i];
		}
	}
	
	common_openNewWindow(common_global_pickerFrameObject, urltogoto, 6);
}

////////////////////////////////////////////////////////
// Function: common_launchViewer
// Description: Opens up a new brower window with the viewer inside
// Parameters: 
//	which - the context for the viewer (what do you want to view?)
//  fieldid - the field ID containing the specific ID, from the database, of the object to view
// Returns: nothing
////////////////////////////////////////////////////////
function common_launchViewer(param_common_which, param_common_fieldid, param_common_urlArgs)
{
	var cobject = document.getElementById(param_common_fieldid);
	if(cobject != null)
	{
		param_common_fieldid = cobject.value;
	}
	if(param_common_fieldid == "")
	{
		common_showDataError("Details are not available for the selected item.", "popup");
	} else
	{
		var urltogoto = "/rbarWeb/viewer.do?selectedComponent=" + param_common_which + "&rbarUIAction=viewer";
		urltogoto = urltogoto + "&viewerID=" + param_common_fieldid;
		if (param_common_urlArgs != null)
		{
			for (i=0; i<param_common_urlArgs.length; i++)
			{
				var paramPrefix = "param" + i;
				urltogoto = urltogoto + "&" + paramPrefix + "=" + param_common_urlArgs[i];
			}
		}
		common_openNewWindow(common_global_viewerFrameObject, urltogoto, 6, false)
	}
	return;
}

////////////////////////////////////////////////////////
// Function: common_launchSubViewer
// Description: Opens up a new browser window with the viewer inside, but with a different
// window name than the main viewer (common_launchViewer)
// Parameters: 
//	which - the context for the viewer (what do you want to view?)
//  fieldid - the field ID containing the specific ID, from the database, of the object to view
// Returns: nothing
////////////////////////////////////////////////////////
function common_launchSubViewer(param_common_which, param_common_fieldid, param_common_urlArgs)
{
	var cobject = document.getElementById(param_common_fieldid);

	if(cobject != null)
	{
		param_common_fieldid = cobject.value;
	}
	if(param_common_fieldid == "")
	{
		common_showDataError("Details are not available for the selected item.", "popup");
	} else
	{
		var urltogoto = "/rbarWeb/viewer.do?selectedComponent=" + param_common_which + "&rbarUIAction=viewer";
		urltogoto = urltogoto + "&viewerID=" + param_common_fieldid;
		if (param_common_urlArgs != null)
		{
			for (i=0; i<param_common_urlArgs.length; i++)
			{
				var paramPrefix = "param" + i;
				urltogoto = urltogoto + "&" + paramPrefix + "=" + param_common_urlArgs[i];
			}
		}
		common_openNewWindow(common_global_subViewerFrameObject, urltogoto, 6, false)
	}
	return;
}

////////////////////////////////////////////////////////
// Function: common_openNewWindow
// Description: Opens up a new brower window
// Parameters: 
//	winName - name to be assigned to the new window (string)
//		'null' = default name to RBARwindow...
//	inUrl - URL to send the new window to (string)
//		'null' = default URL to ''
//	size - number indicated the size of the new window (integer)
//		'null' = default size to a full size window
//	modal - modal or not?
// 		'null' = false
// Returns: nothing
////////////////////////////////////////////////////////
function common_openNewWindow(param_common_winName, param_common_inUrl, param_common_size, param_common_modal)
{
	if(param_common_size == null)
	{
		param_common_size = "full";
	}
	if(param_common_inUrl == null)
	{
		param_common_inUrl = "";
	}
	if(param_common_winName == null)
	{
		param_common_winName = "NewWin_" + param_common_size;
	} 
	if(param_common_modal == null)
	{	
		param_common_modal = false;
	}

	var win_chk = null;
	if(param_common_size == "1")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:200,dialogWidth:300,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=300,height=200',false);
	}
	if(param_common_size == "2")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:400,dialogWidth:500,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=500,height=400',false);
	}
	if(param_common_size == "3")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:400,dialogWidth:600,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=600,height=400',false);
	}
	if(param_common_size == "4")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:600,dialogWidth:700,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=700,height=600',false);
	}
	if(param_common_size == "5")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:600,dialogWidth:975,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=975,height=600',false);
	}
	if(param_common_size == "6")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:400,dialogWidth:550,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=550,height=400',false);
	}
	if(param_common_size == "7")
	{
		if(param_common_modal) win_chk = window.showModalDialog(param_common_inUrl, self, 'scroll:yes,status:yes,resizeable:yes,dialogHeight:400,dialogWidth:800,center:yes');
		else win_chk = window.open( param_common_inUrl, param_common_winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=800,height=400',false);
	}
	if(param_common_size == "full")
	{
		win_chk = window.open( inUrl, winName,'menubar=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes,resizable=yes',false);
	}
	if(!param_common_modal)
		win_chk.focus();
	
	return win_chk;
}

////////////////////////////////////////////////////////
// Function: common_isNotEmpty
// Description: Makes sure the form field has been filled out by the user
// Parameters: 
//	infield - form field to evaluate to see if it is empty (form input object)
//	fieldname - the name of the field to display to the user if is empty (string)
//		'null' = do not message the user at all
// Returns: true if the form field is not empty, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_isNotEmpty(param_common_infield, param_common_fieldname)
{
	if(param_common_infield == null) return false;
	
	var fieldvalue = new String(param_common_infield.value);
	var fieldtype = param_common_infield.type;

	var dofocus = false;
	if(fieldtype == "textarea")
	{
		fieldtype = "text";
		dofocus = false;	
	}
	if(fieldtype == "password")
	{
		fieldtype = "text";
		dofocus = true;	
	}
	
	if(fieldtype == "text" || fieldtype == "hidden")
	{
		// text boxes
		if(fieldvalue.length == 0)
		{
			if(param_common_fieldname != null)
				alert(param_common_fieldname + " cannot be blank.");
			if(dofocus) param_common_infield.focus();
			return false;
		}

		var i = 0;
		for(i=0;i<fieldvalue.length;i++)
		{
			if(fieldvalue.charAt(i) != ' ')
			{
				return true;
			}
		}
		if(i == fieldvalue.length)
		{
			if(param_common_fieldname != null)
				alert(param_common_fieldname + " cannot be blank.");
			if(dofocus) param_common_infield.focus();
			return false;
		}
	} else if(fieldtype == "select" || fieldtype == "select-multiple" || fieldtype == "select-one")
	{
		// pull-downs - must be set to something other than -1
		// and value must NOT ""
		if(param_common_infield.selectedIndex == -1)
		{
			if(param_common_fieldname != null)
				alert("You must select " + param_common_fieldname + ".");
			return false;
		}
		if(param_common_infield[param_common_infield.selectedIndex].value == "")
		{
			if(param_common_fieldname != null)
				alert("You must select " + param_common_fieldname + ".");
			return false;
		}
	}
	return true;
}

////////////////////////////////////////////////////////
// Function: common_getValue
// Description: 
// Parameters: 
// Returns:
////////////////////////////////////////////////////////
function common_getValue(param_common_infield, param_common_form)
{
	if(param_common_infield == null) return null;
	
	var fieldvalue = "";
	var fieldtype = param_common_infield.type;

	if(fieldtype == "textarea")
	{
		fieldtype = "text";	
	}
	if(fieldtype == "password")
	{
		fieldtype = "text";
	}
	if(fieldtype == "hidden")
	{
		fieldtype = "text";
	}
	
	if(fieldtype == "text")
	{
		fieldvalue = param_common_infield.value;
	} else if(fieldtype == "select" || fieldtype == "select-one")
	{
		var gAction = param_common_infield.getAttribute("groupaction");
		if(gAction == null)
		{
			gAction = "";
		}
		if(gAction != "allvalues" && param_common_infield.selectedIndex == -1)
		{
			return "";
		}
		if(gAction != "allvalues")
		{
			fieldvalue = param_common_infield[param_common_infield.selectedIndex].value;
		} else
		{
			for(var x=0;x<param_common_infield.length;x++)
			{
				if(fieldvalue == "")
					fieldvalue = param_common_infield[x].value;
				else
					fieldvalue = fieldvalue + "," + param_common_infield[x].value;
			}
		}
	} else if(fieldtype == "select-multiple")
	{
		var gAction = param_common_infield.getAttribute("groupaction");
		if(gAction == null)
		{
			gAction = "";
		}
		if(gAction != "allvalues" && param_common_infield.selectedIndex == -1)
		{
			return "";
		}
		for(var x=0;x<param_common_infield.length;x++)
		{
			if(gAction == "allvalues" || param_common_infield[x].selected == true)
			{
				if(fieldvalue == "")
					fieldvalue = param_common_infield[x].value;
				else
					fieldvalue = fieldvalue + "," + param_common_infield[x].value;
			}	
		}
	} else if(fieldtype == "checkbox")
	{
		if(param_common_infield.checked == true)
			fieldvalue = param_common_infield.value;
		else fieldvalue = "";
	} else if(fieldtype == "radio")
	{
		if(param_common_infield.checked == true)
			fieldvalue = param_common_infield.value;
		else
		{
			fieldvalue = "";
			var len = param_common_form.length;
			for(var x=0;x<len;x++)
			{
				if(param_common_form[x].name == param_common_infield.name && param_common_form[x].checked == true)
				{
					fieldvalue = param_common_form[x].value;
					break;
				}
			}
		}
	}
	return fieldvalue;
}

////////////////////////////////////////////////////////
// Function: common_checkCreditCardNumber
// Description: Validates if data is a valid credit card number
// Parameters: 
//	infield - form field to evaluate to see if it is a credit card number (form input object)
// Returns: true if the form field is a credit card number, false otherwise (boolean)
////////////////////////////////////////////////////////
function common_checkCreditCardNumber(param_common_infield)
{
	var field = new String(param_common_infield.value);

	if ( (field.length < 13) || (field.length > 19) )
	{
		return false;
	}
	
	if (!common_local_verifyMod10(field))
	{
		return false;
	}

	return true;
}

////////////////////////////////////////////////////////
// Function: common_removeWhiteSpace
// Description: Removes white space from a form field
// Parameters: 
//	infield - form field to remove white space from (form input object)
// Returns: the new value of the form input field (string)	
////////////////////////////////////////////////////////
function common_removeWhiteSpace(param_common_infield)
{
	var fieldvalue = new String(param_common_infield.value);
	
	var startIndex;
	var lastIndex;
	var newFieldName;
	var newC;

	lastIndex = fieldvalue.length-1;
	startIndex = 0;
	
	newC = fieldvalue.charAt(startIndex);
	while ((startIndex<lastIndex) && ((newC == " ") || (newC == "\n") || (newC == "\r") || (newC == "\t"))) {
		startIndex++;
		newC = fieldvalue.charAt(startIndex);
	}

	newC = fieldvalue.charAt(lastIndex);
	while ((lastIndex>=0) && ((newC == " ") || (newC == "\n") || (newC == "\r") || (newC == "\t"))) {
		lastIndex--;
		newC = fieldvalue.charAt(lastIndex);
	}
	if (startIndex<=lastIndex) {
		newFieldName = fieldvalue.substring(startIndex, lastIndex+1);
		return newFieldName;
	} else {
		return fieldvalue;
	}
}

////////////////////////////////////////////////////////
// Function: common_stringRemoveWhiteSpace
// Description: Removes white space from a form field
// Parameters: 
//	infield - form field to remove white space from (form input object)
// Returns: the new value of the form input field (string)	
////////////////////////////////////////////////////////
function common_stringRemoveWhiteSpace( string )
{
	var fieldvalue = string;
	
	var startIndex;
	var lastIndex;
	var newFieldName;
	var newC;

	lastIndex = fieldvalue.length-1;
	startIndex = 0;
	
	newC = fieldvalue.charAt(startIndex);
	while ((startIndex<lastIndex) && ((newC == " ") || (newC == "\n") || (newC == "\r") || (newC == "\t"))) {
		startIndex++;
		newC = fieldvalue.charAt(startIndex);
	}

	newC = fieldvalue.charAt(lastIndex);
	while ((lastIndex>=0) && ((newC == " ") || (newC == "\n") || (newC == "\r") || (newC == "\t"))) {
		lastIndex--;
		newC = fieldvalue.charAt(lastIndex);
	}
	if (startIndex<=lastIndex) {
		newFieldName = fieldvalue.substring(startIndex, lastIndex+1);
		return newFieldName;
	} else {
		return fieldvalue;
	}
}


////////////////////////////////////////////////////////
// Function:  common_arrayContains
// Description: test if a array contains a value
// Parameters: 
//	array - array to test
//  value - the value to determine if the array contains
// Returns: true if array contains value false otherwise	
////////////////////////////////////////////////////////
function common_arrayContains( array, value )
{
	if( array == null )
		return false;
	
	var len = array.length;
	for( var i = 0; i < len; i++ )
	{
		if( array[i] == value )
			return true;	
	}
	
	return false;
}


function common_toggleButtonValue( button, value1, value2 )
{
	if( button.value == value1 )
	{
		button.value = value2;		
	}
	else
	{
		button.value = value1;
	}
	
	return button.value;
}


function common_elementToggleButton( button, value1, value2, elementId1, elementId2, frame )
{
	var newValue = common_toggleButtonValue( button, value1, value2 );
	if( newValue == value1 )
	{
		// enable the opposite of the new value
		common_enableHTML( frame, elementId2 );
		common_disableHTML( frame, elementId1 );	
	}
	else
	{
		common_enableHTML( frame, elementId1 );
		common_disableHTML( frame, elementId2 );		
	}
}


/////////////////
//
// Convenience functions
// Assume vars local_arrowBaseName, local_bulletBaseName, 
// local_frame object, local_subName are set
//
/////////////////
function common_getFullId(id) {
	return local_subName + "_" + id;
}

function common_getArrowId(id) {
	return common_getFullId(id) + "_arrow";
}

function common_getBulletId(id) {
	return common_getFullId(id) + "_bullet";
}	

function common_toggleId(id) {
	//alert("DEBUG:in common_toggleId");
	common_toggleHTML( local_frame, common_getFullId(id), common_getArrowId(id) , local_arrowBaseName, common_getBulletId(id), local_bulletBaseName );
}

function common_disableId(id) {
	//alert("DEBUG:In common_disableId: disabling " + common_getFullId(id));
	common_disableHTML(local_frame, common_getFullId(id), common_getArrowId(id) , local_arrowBaseName, common_getBulletId(id), local_bulletBaseName );
}

function common_enableId(id) {
	//alert("DEBUG:in common_enableId: enabling " + common_getFullId(id));
	common_enableHTML(local_frame, common_getFullId(id));
}

function common_appendUserMessage(running_message, new_message, depth) {
	var INDENT1 = "\n  - ";
	var INDENT2 = "\n    - ";
	var INDENT3 = "\n      - " ;
		
	if (depth==null || depth==1) {
		indent = INDENT1;
	} else if (depth == 2) {
		indent = INDENT2;
	} else if (depth == 3) {
		indent = INDENT3;
	}

	if (running_message==null) {
		running_message = "";
	}
		
	return running_message + indent + new_message;	
}

function common_addUserMessageSubHead(running_message, new_message, depth) {
	var INDENT1 = "\n\n   ";
	var INDENT2 = "\n\n     ";
	var INDENT3 = "\n\n       " ;
		
	if (depth==null || depth==1) {
		indent = INDENT1;
	} else if (depth == 2) {
		indent = INDENT2;
	} else if (depth == 3) {
		indent = INDENT3;
	}

	if (running_message==null) {
		running_message = "";
	}
		
	return indent + new_message + running_message ;	
}

function common_setWorkspaceChangeForm(param_common_formname)
{
	common_local_workspaceFormName = param_common_formname;
}

//////////////////////////////////////////////////////
//  Checks for any changes in workspace. If any prompts user to save or continue
//
//  Assumes: Variable local_workspace_name in workspace to identify name of form to look for changes.
///////////////////////////////////////////////////////

function common_confirmWorkspaceChange()
{
   var frame = common_local_getFramePointer(common_global_workspaceFrameObject);

   var htmlChanged=false;

   if(frame != null && frame.common_local_workspaceFormName != null)
   {
      var wsForm = frame.document.forms[frame.common_local_workspaceFormName];

      if(wsForm != null)
      {
	      htmlChanged = frame.common_compareAllHTMLGroup(wsForm);
	      if(htmlChanged)
	      {
				return confirm("Your workspace has changed.\n\nClick \"OK\" if you wish to continue with your current action and lose your changes.\n\nOtherwise, click \"Cancel\" to keep your changes.");
	      }
      }
   }
   return true;
}

var common_pushIA = function ( param_entity_pContext, param_entity_data) 
{
	var cbArgs = param_entity_pContext.getCallbackFunctionArgs();
	if(cbArgs != null)
	{
		if(param_entity_data != null)
		{
			if(cbArgs[0] != null)
			{
				var curelement = document.getElementById(cbArgs[0]);
				common_setField(curelement, param_entity_data["invoiceAccountId"].value);
			}
			if(cbArgs[1] != null)
			{
				var curelement = document.getElementById(cbArgs[1]);
				common_setField(curelement, param_entity_data["invoiceAccountName"].value);
			}			
			if(cbArgs[2] != null)
			{
				var curelement = document.getElementById(cbArgs[2]);
				common_setField(curelement, param_entity_data["invoiceAccountSysId"].value);
			}
			
			var invoiceAccountDisplayIdParts = param_entity_data["invoiceAccountId"].value.split("-");

			if(cbArgs[3] != null)
			{
				var curelement = document.getElementById(cbArgs[3]);
				common_setField(curelement,  invoiceAccountDisplayIdParts[0]);
			}
			if(cbArgs[4] != null)
			{
				var curelement = document.getElementById(cbArgs[4]);
				common_setField(curelement,  invoiceAccountDisplayIdParts[1]);
			}			
			if(cbArgs[5] != null)
			{
				var curelement = document.getElementById(cbArgs[5]);
				common_setField(curelement,  invoiceAccountDisplayIdParts[2]);
			}			

		}

	}

}
//////////////////////////////////////////////////////
// This function takes a floating point or integer
// value and applies a fixed length and number of 
// digits after the decimal point
//////////////////////////////////////////////////////
function common_format_float( value, param_common_right )
{
	var instr = common_stringRemoveWhiteSpace( new String(value) );
	var x = 0;
	
	if(instr == null) return value;
	if(instr.length < 1) return value;

    var foundonedot = false;

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(instr.charAt(x) == '.')
		    {
			    foundonedot = true;
			    break;
			} 
		}
	}
	var retVal = parseFloat(value);
	var digits = 0;
	if (foundonedot && param_common_right != null)
	{
		digits = param_common_right;	
	}
	else
	{
		digits = 2;
	}
	
	return retVal.toFixed(parseInt(digits,10));
	
}


function common_enableAllFields(param_form_object)
{
	var len = param_form_object.length;
	for (var x = 0; x < len; x++)
	{
	  if (param_form_object[x].type != "button")
		  param_form_object[x].disabled = false;
	}
}

////////////////////////////////////////////////////////
// Use this function to disable a group of HTML form
// elements that have the same name prefix.
// param_form_object :: the form object of the page
// param_name_prefix :: the common prefix for the shared name 
//						of fields that will be disabled
// param_index :: optional field for disabling fields that 
// 				  are iterated over and may share a similar 
//                name with other fields that should not be disabled
////////////////////////////////////////////////////////
function common_disableAllFields(param_form_object, param_name_prefix, param_index)
{
	var formElements = param_form_object.elements;
	var len = formElements.length;
	for (var x = 0; x < len; x++)
	{
        if (param_index != null)
        {
	  		if( formElements[x].name.indexOf( param_name_prefix ) != -1 && formElements[x].name.indexOf( "_" + param_index) != -1 )
	  			formElements[x].disabled = true;
	  	}
	  	else
	  	{
	  		if( formElements[x].name.indexOf( param_name_prefix ) != -1)
		  		formElements[x].disabled = true;
	  	}
	}
}

function common_disableFieldById(param_form_id)
{
    var field =	document.getElementById(param_form_id);
    if(field == null)
    	return;
    	
    field.disabled = true;
}

function common_enableFieldById(param_form_id)
{
    var field =	document.getElementById(param_form_id);
    if(field == null)
    	return;
    	
    field.disabled = false;
}

function common_setCheckbox(param_common_checkbox, param_common_checkbox_value)
{
	var checkbox = document.getElementById(param_common_checkbox);
	
	if (checkbox.type != "checkbox")
	{
		alert("Field must be a checkbox");
	}
	else if (param_common_checkbox_value != true && param_common_checkbox_value != false)
	{
		alert("Value must be true or false");
	}
	else
	{
		checkbox.checked = param_common_checkbox_value;
	}
}
////////////////////////////////////////////////////////
// BELOW THIS POINT ARE FUNCTIONS THAT SHOULD NOT BE USED
// OUTSIDE THIS JS FILE - THEY ARE "INTERNAL" FUNCTIONS	
////////////////////////////////////////////////////////
function common_local_init()
{
	var win = window;
	if(win.common_local_framePointers == null) win.common_local_framePointers = new Array();
	try
	{
		win.common_local_framePointers[win.common_global_helpFrameObject] = window.top.bottomFrame.leftFrame.helpIframe;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_leftFrameObject] = window.top.bottomFrame.leftFrame;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_topFrameObject] = window.top.topFrame;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_searchResultsFrameObject] = window.top.bottomFrame.rightFrame.searchResultsFrame;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_workspaceFrameObject] = window.top.bottomFrame.rightFrame.workspaceFrame;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_pickerFrameObject] = window.top;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_popupFrameObject] = window.top;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_openerFrameObject] = window.opener;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_viewerFrameObject] = window.top;
	} catch(e)
	{
	}
	try
	{
		win.common_local_framePointers[win.common_global_subViewerFrameObject] = window.top;
	} catch(e)
	{
	}	
}

function common_local_getMonth(param_common_month)
{
	param_common_month = param_common_month.toLowerCase();
	if(param_common_month == "jan") return "01";
	
	// BUG: Wierd bug in JavaScript dates --- Setting
	// a date to Feb. requires that the month be 01
	if(param_common_month == "feb") return "02";
	if(param_common_month == "mar") return "03";
	if(param_common_month == "apr") return "04";
	if(param_common_month == "may") return "05";
	if(param_common_month == "jun") return "06";
	if(param_common_month == "jul") return "07";
	if(param_common_month == "aug") return "08";
	if(param_common_month == "sep") return "09";
	if(param_common_month == "oct") return "10";
	if(param_common_month == "nov") return "11";
	if(param_common_month == "dec") return "12";
	return "00";
}

function common_local_addMsg(param_common_which, param_common_linenumber, param_common_text)
{
	var path = null;
	if(param_common_linenumber != null)
	{
		path = param_common_which + "_" + param_common_linenumber;
		if(validation_global_Msgs.getMessageGroup(path) == null)
		{
			var title = "";
			if(param_common_which == "bl_pp")
			{
				title = billingline_buildPPTitle();
				title = title + "...";
			} else if(param_common_which == "entity_im" || 
				param_common_which == "ia_im" ||
				param_common_which == "mappings_im")
			{
				title = invoiceaccount_buildIMTitle();
				title = title + "...";
			}
			validation_global_Msgs.addGroupByPath(null, path, title);
		}
	}
	validation_global_Msgs.addMsgByPath( path, param_common_text );
	
	return;
}

function common_local_getMonthInt(param_common_month)
{
	// BUG: Wierd bug in JavaScript dates --- Setting
	// a date to Feb. requires that the month be 01
	if(param_common_month == "02") return "01";
	return param_common_month;
}

function common_local_getFramePointer(param_common_whichone)
{
	var win = window;
	if(param_common_whichone == null) return window;
	return win.common_local_framePointers[param_common_whichone];
}

function common_local_verifyMod10(param_common_field)
{
	var PAN = removeSpaces(param_common_field);

	var st = PAN;

	if (st.length > 19)
		return false;

	var sum = 0;
	var mul = 1;
	var st_len = st.length;
	var tproduct;
	var digit;
	
	for (i = 0; i < st_len; i++) 
	{
		digit = st.substring(st_len-i-1, st_len-i);
		
		if (digit == " " || digit == "-")
			continue;
			
		tproduct = parseInt(digit ,10) * mul;
	    
	    if (tproduct >= 10)
	      sum += (tproduct % 10) + 1;
	    else
	      sum += tproduct;
	    
	    if (mul == 1)
	      mul++;
	    else
	      mul--;
	}

	if ((sum % 10) != 0)
		return false;

	return true;
}

////////////////////////////////////////
//
// Common method for displaying error messages
//
////////////////////////////////////////

function common_populateUserMessage()
{
	alert("common_populateUserMessage: This method has been depricated.");
}

////////////////////////////////////////
//
// Object used to communicate to the Picker
//
////////////////////////////////////////
PickerContext = function () {
	this.callbackFunction = null;
	this.callbackFunctionArgs = null;
};

PickerContext.prototype.setCallbackFunction = function (cbFunction) {
	this.callbackFunction = cbFunction;
};

PickerContext.prototype.getCallbackFunction = function () {
	return this.callbackFunction;
};

PickerContext.prototype.setCallbackFunctionArgs = function (cbArgs) {
	this.callbackFunctionArgs = cbArgs;
};

PickerContext.prototype.getCallbackFunctionArgs = function () {
	return this.callbackFunctionArgs;
};
