var l_window = '';
var layerRef,styleSwitch;

//************************************************************************
//* Populate pulldown layer reference and style switch based on browser. *
//************************************************************************
if (navigator.appName == "Netscape") {
	layerRef="document.layers";
  	styleSwitch="";
    } else {
    	layerRef="document.all";
    	styleSwitch=".style";
    }
    
function Netscape()
{
	if (navigator.appName.indexOf("Netscape") >= 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
	
//*********************************************
//* Close map legend window when appropriate. *
//*********************************************
function unload() 
{
	closeWin();
}
	
function closeWin() 
{
	if (l_window != '')
		l_window.close()
}

//********************************************
//* Open map legend window when appropriate. *
//********************************************
function openWin(p_type) 
{
	l_window = window.open("SelectHome/Maps/legend.asp?ls_type="+p_type+"&mapname="+l_mapname,"winLegend","scrollbars,height=200,width=400");
	l_window.moveTo(0,screen.availHeight - 225);
	l_window.focus();
}

function openSlideWin(p_highlightID,p_path,p_slideType)
{
	l_window = window.open(p_path+"slideViewer.asp?ls_slideType="+p_slideType+"&highlightID="+p_highlightID,"winSlideViewer","height=400,width=400");
	l_window.moveTo((screen.availWidth / 2) - 200,(screen.availHeight / 2) - 200);
	l_window.focus();
}

//*******************************
//* Display Guide pulldown menu *
//*******************************
function CshowLayer(layerName) 
{
 	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
}
  	
//****************************
//* Hide Guide pulldown menu *
//****************************
function ChideLayer(layerName) 
{
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
}

//********************************************
//* Removes "$" and "," from currency fields *          *
//********************************************
function filterCurrencyNum(str) 
{
	return str.toString().replace(/\$|\,/g,'');
}

//********************************************
//* Formats currency fields with the dollar  *
//* sign, commas,and 2 decimal places        *
//********************************************
function formatCurrency(pc_Num) 
{
	var lc_Cents
	
	// First strip off "$" and "," characters
	pc_Num = pc_Num.toString().replace(/\$|\,/g,'');
	
	// Replace non-numerics or negative numbers with 0
	if(isNaN(pc_Num)) pc_Num = "0";
	if(pc_Num < 0) pc_Num = "0";
	
	// Round to 2 decimal places
	lc_Cents = Math.floor((pc_Num*100+0.5)%100); 
	if(lc_Cents < 10) lc_Cents = "0" + lc_Cents; 

	// Determine if we need to round
	if (lc_Cents == 0) pc_Num = Math.round(pc_Num).toString();
	else pc_Num = Math.floor(pc_Num).toString();

	// Add commas where necessary
	for (var i = 0; i < Math.floor((pc_Num.length-(1+i))/3); i++) 
	pc_Num = pc_Num.substring(0,pc_Num.length-(4*i+3))+','+pc_Num.substring(pc_Num.length-(4*i+3)); 

	// Return the formatted currency value
	return ('$' + pc_Num + '.' + lc_Cents); 
}

//***********************************************
//* The following functions are used to         *
//* automatically tab to the next field on the  *
//* form when a specified number of characters  *
//* has been reached.                           *
//***********************************************
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];	
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	return true;
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele) found = true;
		else index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
	return index;
}

//***********************************************
//* Displays the specified message and set the  *
//* focus to the specified field (i.e., when    *
//* the field is in error).                     *                               *
//***********************************************
function fixElement(element, message) {
	alert(message);
	element.focus();
	element.select();
}

//***********************************************
//* Validates that the specified field contains *
//* only numbers.                               *
//***********************************************
function validateNumbers(field) {
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	var lb_Result = true;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") 
	{
		fixElement(field, "Invalid entry.  Only numbers are allowed.");
		lb_Result = false;
	}
	return lb_Result;
}

//***********************************************
//* Validates that the specified field contains *
//* only letters from the english alphabet.     *
//***********************************************
function validateLetters(field) 
{
	var valid = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz "
	var ok = "yes";
	var temp;
	var lb_Result = true;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") 
	{
		fixElement(field, "Invalid entry.  Please enter only letters in this field.");
		lb_Result = false;
	}
	return lb_Result;
}

//***********************************************
//* Validates a percentage field.               *
//***********************************************
function validatePercent(field, showMsg) {
	var valid = "0123456789."
	var ok = true;
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = false;
	}
	if (ok == true)
		if (eval(field.value) > 100) ok = false;

	if (ok == false && showMsg) fixElement(field, "Invalid entry.  Only positive numbers less than 100 are allowed.");
	
	return ok;
}


//***********************************************
//* Formats a percentage field with 1 decimal   *
//* place.                                      *
//***********************************************
function formatPercent(pc_Num) {
	var lc_Decimal
	var li_NumDecimals

	// Replace percent sign (%)
	pc_Num = pc_Num.toString().replace(/\%|\,/g,'');

	// Replace non-numerics or negative numbers with 0
	if(isNaN(pc_Num)) pc_Num = "0";
	if(pc_Num < 0) pc_Num = "0";
	
	// Set to 2 decimal places
	li_NumDecimals = 2
	li_NumDecimals = (!li_NumDecimals ? 2 : li_NumDecimals);
	
	// Return the rounded percentage
	return Math.round(pc_Num*Math.pow(10,li_NumDecimals))/Math.pow(10,li_NumDecimals);
}

function ValidateAdhoc(form) {

	// Check if the user is performing an ad-hoc
	// calculation - if so, validate required fields
	if(form.lb_Loans.selectedIndex > 0)
		{
		if(form.tb_Term.value=="") 
			{
			fixElement(form.tb_Term, "You must enter a Term when performing Ad-hoc calculations");
			return (false);
			}
		if(form.tb_Rate.value=="") 
			{
			fixElement(form.tb_Rate, "You must enter a Rate when performing Ad-hoc calculations");
			return (false);
			}
		if(!validateNumbers(form.tb_Term)) 
			{
			return (false);
			}
		if(!validatePercent(form.tb_Rate, true)) 
			{
			return (false);
			}
		}

	return (true);

}

//******************************
//* Validates email addresses. *
//******************************
function emailCheck(emailStr, lo_eMailField)
{
	// First determine if the email is blank which is ok.  This function
	// only determines if an "Entered" email address is valid.
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat=/^(.+)@(.+)$/

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ]    */
	
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed. */

	var validChars="\[^\\s" + specialChars + "\]"
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")"
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	
	/* The following string represents an atom (basically a series of
	non-special characters.) */
	
	var atom=validChars + '+'

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")"
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Finally, let's start trying to figure out if the supplied address is
	valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
	{
		if(lo_eMailField.value.length == 0)
		{
			return true
		}
		else
		{
			/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
		
			alert("eMail Address is incorrect (check @ and .'s)")
			lo_eMailField.focus()
			lo_eMailField.select()
			return false
		}
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		// user is not valid
		alert("eMail username is invalid.")
		lo_eMailField.focus()
		lo_eMailField.select()
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				alert("eMail Destination IP address is invalid.")
				lo_eMailField.focus()
				lo_eMailField.select()
				return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		alert("eMail domain is invalid.")
		lo_eMailField.focus()
		lo_eMailField.select()
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	three-letter word (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	it consists of. */

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length

	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) 
	{
		// the address must end in a two letter or three letter word.
		alert("eMail Address must end in a three-letter domain, or two letter country.")
		lo_eMailField.focus()
		lo_eMailField.select()
		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		alert("eMail Address is missing a hostname.")
		lo_eMailField.focus()
		lo_eMailField.select()
		return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

//********************************************************
//* Repaints the screen based on list box option chosen. *
//********************************************************
function MM_jumpMenu(targ,selObj,restore)
{ 
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function CheckSSNO(ls_FormName, ls_FieldName, ls_FieldTitle)
{
	//*****************************************************
	//* Expression Metacharacters:                        *
	//*                                                   * 
	//*     / = Escape character                          *
	//*     ^ = Expression begin                          *
	//*     $ = Expression end                            *
	//*    \d = Numeral 0 through 9                       *
	//*   {n} = Last character occuring n or more times   *
	//* [...] = Character set                             *
	//*    \- = Hyphen                                    *
	//*    \s = Single white space                        *
	//*     ? = Last character occurring zero or one time *
	//*****************************************************
	
	var reSSNO = /^\d{3}[\-\s]?\d{2}[\-\s]?\d{4}$/
	var lb_theResult = true;

	if (eval('document.' + ls_FormName + '.' + ls_FieldName + '.value.length') > 0)
	{
		if (! reSSNO.test(eval('document.' + ls_FormName + '.' + ls_FieldName + '.value')))
		{
			alert("The " + ls_FieldTitle + " field contains an invalid Social Security Number (use 999-99-9999 format).");
			lb_theResult = false;
			eval('document.' + ls_FormName + '.' + ls_FieldName + '.focus()')
			eval('document.' + ls_FormName + '.' + ls_FieldName + '.select()')
		}
	}
	return lb_theResult;
	
}

function CheckPhone(ls_FormName, ls_FieldName, ls_FieldTitle)
{
	//*****************************************************
	//* Expression Metacharacters:                        *
	//*                                                   * 
	//*     / = Escape character                          *
	//*     ^ = Expression begin                          *
	//*     $ = Expression end                            *
	//*    \d = Numeral 0 through 9                       *
	//*   {n} = Last character occuring n or more times   *
	//* [...] = Character set                             *
	//*    \- = Hyphen                                    *
	//*    \s = Single white space                        *
	//*     ? = Last character occurring zero or one time *
	//*****************************************************
	
	var rePhone = /^[\(\s]?\d{3}[\)\s]{1}[\s]?\d{3}[\-\s]{1}\d{4}$/
	var lb_theResult = true;

	if (eval('document.' + ls_FormName + '.' + ls_FieldName + '.value.length') > 0)
	{
		if (! rePhone.test(eval('document.' + ls_FormName + '.' + ls_FieldName + '.value')))
		{
			alert("The " + ls_FieldTitle + " field contains an invalid phone number (use (999)999-9999 format).");
			lb_theResult = false;
			eval('document.' + ls_FormName + '.' + ls_FieldName + '.focus()')
			eval('document.' + ls_FormName + '.' + ls_FieldName + '.select()')
		}
	}
	return lb_theResult;
	
}

function CheckDate(lo_Field, ls_FieldName, ls_FieldTitle)
{
	var lb_theResult = true;
	var ld_DateEntered;
	var ls_DateEntered;
	var ls_MonthEntered;
	var li_MonthCalculated;
	var ls_YearEntered;
	var li_YearCalculated;
	var liYearStart;
	var liYearEnd;

	reAlphabetic = new RegExp ("[A-Za-z]");

	ls_DateEntered = lo_Field.value;

	if (ls_DateEntered.length > 0)
	{
		if (!reAlphabetic.test(ls_DateEntered))
		{
			if (ls_DateEntered.indexOf("/") > 0 || ls_DateEntered.indexOf("-") > 0)
			{
				ld_DateEntered = new Date(ls_DateEntered);

				if (ld_DateEntered != "NaN")
				{
					li_YearCalculated = ld_DateEntered.getYear()

					if (ls_DateEntered.indexOf("/") > 0)
					{
						liYearStart = ls_DateEntered.lastIndexOf("/") + 1
					}
					else
					{
						liYearStart = ls_DateEntered.lastIndexOf("-") + 1
					}

					liYearEnd = ls_DateEntered.length

					ls_YearEntered = ls_DateEntered.substring(liYearStart, liYearEnd)

					if (ls_YearEntered.length == 2 || ls_YearEntered.length == 4)
					{
						li_MonthCalculated = ld_DateEntered.getMonth() + 1	//Note:  this is relative zero

						if (ls_DateEntered.substring(1, 2) == "/" || ls_DateEntered.substring(1, 2) == "-")
						{
							ls_MonthEntered = ls_DateEntered.substring(0, 1);
						}
						else
						{
							ls_MonthEntered = ls_DateEntered.substring(0, 2);
						}

						if (ls_YearEntered < 2000)
						{
							ls_YearEntered = ls_DateEntered.substring(liYearEnd - 2, liYearEnd)
						}
						else
						{
							if (Netscape())
							{
								li_YearCalculated = li_YearCalculated + 1900
							}
						}

						if (li_MonthCalculated == ls_MonthEntered && li_YearCalculated == ls_YearEntered)
						{
							lb_theResult = true;
						}
						else
						{
							lb_theResult = false;
						}
					}
					else
					{
						lb_theResult = false;
					}
				}
				else
				{
					lb_theResult = false;
				}
			}
			else
			{
				lb_theResult = false;
			}			
		}
		else
		{
			lb_theResult = false;
		}

		if (lb_theResult == false)
		{
			alert("The " + ls_FieldTitle + " field contains an invalid date (use mm/dd/yyyy format).");
			lb_theResult = false;
			lo_Field.focus();
			lo_Field.select();
		}
	}

	return lb_theResult;
}

//******************************
//* Validates required fields. *
//******************************
function CheckRequired(lo_Field, ls_FieldTitle, ls_FieldType)
{
    var lb_TheResult = true;
    //*************************
    //* 'L' is for listboxes  *
    //*************************
    if (ls_FieldType == 'L')
    {
		if (lo_Field.selectedIndex > -1)
		{
			if (lo_Field.options[lo_Field.selectedIndex].value == 'null')
			{
			    alert('A(n) ' + ls_FieldTitle + ' must be selected.');
   				lo_Field.focus()

			    lb_TheResult = false;
			}
		}
		else
		{
			if (lo_Field.selectedIndex == -1)
			{
				alert('A(n) ' + ls_FieldTitle + ' must be selected.');
   				lo_Field.focus()

				lb_TheResult = false;
			}
		}
    }
    else
    {
		if (lo_Field.value.length == 0)
        {
            alert('The ' + ls_FieldTitle + ' field must contain a value.');
			lo_Field.focus()
			lo_Field.select()

            lb_TheResult = false;
        }
    }
    return lb_TheResult;
}

function CheckZipCode(lo_Field, ls_FieldTitle)
{
	//*****************************************************
	//* Expression Metacharacters:                        *
	//*                                                   * 
	//*     / = Escape character                          *
	//*     ^ = Expression begin                          *
	//*     $ = Expression end                            *
	//*    \d = Numeral 0 through 9                       *
	//*   {n} = Last character occuring n or more times   *
	//*     | = OR operator                               *
	//* [...] = Character set                             *
	//*    \- = Hyphen                                    *
	//*    \s = Single white space                        *
	//*     ? = Last character occurring zero or one time *
	//*****************************************************
	
	var reZipCode = /^\d{5}$|^\d{5}[\-\s]?\d{4}$/
	var lb_theResult = true;

	if (lo_Field.value.length > 0)
	{
		if (! reZipCode.test(lo_Field.value))
		{
			alert("The " + ls_FieldTitle + " field contains an invalid zip code (use 99999 or 99999-9999 format).");
			lb_theResult = false;
			lo_Field.focus()
			lo_Field.select()
		}
	}
	return lb_theResult;
}

function CheckSimplePhone(lo_Field, ls_FieldTitle)
{
	//*****************************************************
	//* Expression Metacharacters:                        *
	//*                                                   * 
	//*     / = Escape character                          *
	//*     ^ = Expression begin                          *
	//*     $ = Expression end                            *
	//*    \d = Numeral 0 through 9                       *
	//*   {n} = Last character occuring n or more times   *
	//* [...] = Character set                             *
	//*    \- = Hyphen                                    *
	//*    \s = Single white space                        *
	//*     ? = Last character occurring zero or one time *
	//*****************************************************
	
	var rePhone = /^\d{3}[\-\s]{1}\d{4}$/
	var lb_theResult = true;

	if (lo_Field.value.length > 0)
	{
		if (! rePhone.test(lo_Field.value))
		{
			alert("The " + ls_FieldTitle + " field contains an invalid phone number (use 999-9999 format).");
			lb_theResult = false;
			lo_Field.focus()
			lo_Field.select()
		}
	}
	return lb_theResult;
}

function CheckAreaCode(lo_Field, ls_FieldTitle)
{
	//*****************************************************
	//* Expression Metacharacters:                        *
	//*                                                   * 
	//*     / = Escape character                          *
	//*     ^ = Expression begin                          *
	//*     $ = Expression end                            *
	//*    \d = Numeral 0 through 9                       *
	//*   {n} = Last character occuring n or more times   *
	//* [...] = Character set                             *
	//*    \- = Hyphen                                    *
	//*    \s = Single white space                        *
	//*     ? = Last character occurring zero or one time *
	//*****************************************************
	
	var reAreaCode = /^\d{3}$|^\d{3}$/
	var lb_theResult = true;

	if (lo_Field.value.length > 0)
	{
		if (! reAreaCode.test(lo_Field.value))
		{
			alert("The " + ls_FieldTitle + " field contains an invalid area code (use 999 format).");
			lb_theResult = false;
			lo_Field.focus()
			lo_Field.select()
		}
	}
	return lb_theResult;
}

//******************************************************************************************
// This function is designed to return the appropriate URL value if all GuestBook
// validation has succeeded.  It is called from the menu creation in SecondaryNavigation.asp
//******************************************************************************************
function URLValue(ps_URL)
{
	var ls_URL = "";
	var ls_path = window.location.search;
		
	if((ls_path == "?ls_Section=Welcome&ls_Page=GuestBook&li_BuyerType=0") || (ls_path == ""))
	{
		if(ValidateForm()==false)
		{
			return ls_URL;
		}
		else
		{
			//Submit the form to be saved
			document.Buyer.submit();
			
			//Determine if it's ok to leave the Guest Book (ie. everything has been saved)
			if(document.Buyer.h_personID.value != 0)
			{
				window.location.href = 'Welcome/LocationAction.asp?ls_Page=' + ps_URL;
			}
		}
	}
	else
	{
		window.location.href = 'Welcome/LocationAction.asp?ls_Page=' + ps_URL;
	}
}

function AddItem(lo_FromList, lo_ToList, li_MaxToItems)
{  
	var li_Counter;
	var li_Counter2;
	var li_FromLength;
	var li_ToLength;
	
	li_FromLength = lo_FromList.length
	li_ToLength = lo_ToList.length
	

	for (li_Counter = 0; li_Counter < li_FromLength; li_Counter++)
	{
		if (lo_FromList.options[li_Counter].selected == 1)
		{
			lb_AlreadyMoved = false;
			for (li_Counter2 = 0; li_Counter2 < li_ToLength; li_Counter2++)			
			{
				if (lo_FromList.options[li_Counter].value == lo_ToList.options[li_Counter2].value)
				{
					lb_AlreadyMoved = true;
				}
			}

			if (lb_AlreadyMoved == false)
			{
				if (lo_ToList.length < li_MaxToItems)
				{
					lo_ToList.length = lo_ToList.length + 1;
			
					lo_ToList.options[lo_ToList.length - 1].value = lo_FromList.options[li_Counter].value;
					lo_ToList.options[lo_ToList.length - 1].text = lo_FromList.options[li_Counter].text;
				}
				else
				{
					alert('Only ' + li_MaxToItems + ' items can be selected.');
					return false;
				}
			}
			else
			{
				alert(lo_FromList.options[li_Counter].text + ' has already been selected.');
			}
		}
	}
}

function RemoveItem(lo_ListBox)
{
	var li_Counter;
	var li_Counter2 = 0;
	var li_Length;
	var li_Length2;
	
	li_Length = lo_ListBox.length
	li_Length2 = li_Length
	
	for (li_Counter = 0; li_Counter < li_Length; li_Counter++)
	{
		if (lo_ListBox.options[li_Counter].selected != 1)
		{
			lo_ListBox.options[li_Counter2].value = lo_ListBox.options[li_Counter].value;
			lo_ListBox.options[li_Counter2].text = lo_ListBox.options[li_Counter].text;
			li_Counter2++
		}
		else
		{
			li_Length2--
		}
	}
	lo_ListBox.length = li_Length2
}


function MoveSelected(lo_FromList, ls_Message, lo_ToList, li_MaxToItems)
{
	if (CheckRequired(lo_FromList, ls_Message, 'L') == true )
	{
		AddItem(lo_FromList, lo_ToList, li_MaxToItems);
	}
}


function RemoveSelected(lo_ListBox, ls_Message)
{
	if (CheckRequired(lo_ListBox, ls_Message, 'L') == true )
	{
		RemoveItem(lo_ListBox);
	}
}


function RemoveAll(lo_ListBox)
{
	SelectAll(lo_ListBox);
	RemoveItem(lo_ListBox);
}


function AddAll(lo_FromList, lo_ToList, li_MaxToItems)
{
	SelectAll(lo_FromList);
	AddItem(lo_FromList, lo_ToList, li_MaxToItems);
}


function SelectAll(lo_ListBox)
{
	var li_Counter;
	var li_Length;
	
	li_Length = lo_ListBox.length
	
	for (li_Counter = 0; li_Counter < li_Length; li_Counter++)
	{
		lo_ListBox.options[li_Counter].selected = 1
	}
}

function FindItem(lo_ListBox, ls_SearchText)
{
	var li_Counter;
	var li_LBLength;
	var li_STEndingPosition;
	var lb_Found = false;
	
	li_LBLength = lo_ListBox.length
	li_STEndingPosition = ls_SearchText.length
		
	for (li_Counter = 0; li_Counter < li_LBLength; li_Counter++)
	{
		if (lo_ListBox.options[li_Counter].text.substring(0, li_STEndingPosition).toUpperCase() == ls_SearchText.toUpperCase())
		{
			lo_ListBox.options[li_Counter].selected = 1;
			lb_Found = true;
			break;
		}
	}
	
	if (lb_Found == false)
	{
		alert(ls_SearchText + ' was not found.')
	}
}

function AutoSave(lo_Form)
{
	if (lo_Form.h_FormChanged.value == 'YES')
	{
		if (confirm('Changes have been made to this form.  Press OK to save changes or Cancel to disregard them.') == true)
		{
			lo_Form.h_SaveChanges.value = 'YES'
		}
	}
}

function SelectDefaultButton(lo_Button)
{
 lo_Button.focus()
}

//******************************************************************************************
// Sets focus to and selects the specified field
//******************************************************************************************
function GoToField(lo_Field)
{
	lo_Field.focus();
	lo_Field.select();
}	

//******************************************************************************************
// Validates state code
//******************************************************************************************
function validateState(field) {

  var str = field.value;        

  var re = /^AL$|^AK$|^AZ$|^AR$|^CA$|^CO$|^CT$|^DE$|^DC$|^FL$|^GA$|^HI$|^ID$|^IL$|^IN$|^IA$|^KS$|^KY$|^LA$|^ME$|^MD$|^MA$|^MI$|^MN$|^MS$|^MO$|^MT$|^NB$|^NV$|^NH$|^NJ$|^NM$|^NY$|^NC$|^ND$|^OH$|^OK$|^OR$|^PA$|^RI$|^SC$|^SD$|^TN$|^TX$|^UT$|^VT$|^VA$|^WA$|^WV$|^WI$|^WY$/i;

  if (field.value == "") {
    alert("Please enter your State code.");
    field.focus();
    return false;
  }
  if (re.test(str)) {
    return true;
  }
  alert("" + str + " is an invalid State code.");
  field.select();
  field.focus();
  return false;
}

function showCalendar(p_element)
{
	var eL=0;var eT=0;
	for(var p=p_element; p&&p.tagName!='BODY'; p=p.offsetParent)
	{
		eL+=p.offsetLeft;
		eT+=p.offsetTop;
	}
	//eT+=document.calImage.offsetHeight;
	document.all.CalFrame.style.top=eT-25;
	document.all.CalFrame.style.left=eL;
	document.all.CalFrame.style.display='block';
}
