function additionalActors() {
	xmlObject.call(this);
	this.myActors = new Array();


	/* 
	 * count
	 *
	 * Returns the number of additional actors
	 */
	this.count = function() {
		return this.myActors.length;
	}
	
	/* 
	 * push
	 *
	 * Adds an actor to the additional array
	 */
	this.push = function(anActor) {
		this.myActors.push(anActor);
	}
	

	/* 
	 * deleteAt
	 *
	 * Deletes the actor at position at iPos
	 */
	this.deleteAt = function(iPos) {
		if (iPos >= 0 && iPos < this.myActors.length)
			this.myActors.splice(iPos, 1);
	}

	/* 
	 * updateAt
	 *
	 * Updates the actor at position iPos
	 */
	this.updateAt = function(iPos, anActor) {
		if (iPos >= 0 && iPos < this.myActors.length)
			this.myActors[iPos] = anActor;
	}
	

	/* 
	 * getAt
	 *
	 * Returns the actor at position iPos
	 */
	this.getAt = function(iPos) {
		if (iPos >= 0 && iPos < this.myActors.length)
			return this.myActors[iPos];
	}


	/* 
	 * clear
	 *
	 * Clears the additional array
	 */
	this.clear = function() {
		this.myActors = new Array();
	}
	

	/* 
	 * returnListBoxText
	 *
	 * Returns a string to add to the additional list box at position iPos
	 */
	this.returnListBoxText = function(iPos) {
		if (this.myActors[iPos].name.businessFlag) {
			return this.trimString(this.myActors[iPos].name.businessName);
		} else {
			var actorName = this.myActors[iPos].name;
			return this.trimString(actorName.lastName + ', ' + actorName.firstName + ' ' + actorName.middleName);
		}
	}


	/* 
	 * Trim String
	 *
	 * Does a VB Trim on a String
	 */
	this.trimString = function(str) {
	   return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}

	
	/* 
	 * toXML
	 *
	 * Writes out the additional XML section
	 */
	this.toXml = function(myXmlDoc) {
		myXmlDoc = myXmlDoc || new XmlDoc();
		var myElement=myXmlDoc.createElement("additional");
		for (i in this.myActors) {
			var e=this.myActors[i].toXml(myXmlDoc);
			if (e) {
				e.setAttribute("role","BA");
				myElement.appendChild(e);
			}
		}
		if (myElement.hasChildNodes())
			return myElement;
		else
			return null;
	}
}	


function actor() {
	xmlObject.call(this);
	
	this.name = new name();
	this.address = new address();

	this.isValid = function(bShow) {
		var	retVal = this.name.isValid();
		retVal = this.address.isValid(bShow) && retVal;
		return retVal;
	}	
}
	
function name() {
	xmlObject.call(this);
	
	this.FullName=FullName_;
	this.firstName="";
	this.middleName="";
	this.lastName="";
	this.businessName = "";
	this.businessFlag=false;
	this.errors = new Array();	
	
	function FullName_() {
		return this.lastName + ", " + this.firstName +" " + this.middleName;
	}
	
	this.isValid = function() {
		this.errors = new Array();
		var myDataError;

		if (this.businessFlag) {
			if (this.trimString(this.businessName).length == 0) {
				myDataError = new dataError();
				myDataError.description = 'Business Name is Required';
				myDataError.element = 'businessName';
				this.errors.push(myDataError);
			}
		} else {
			if (this.trimString(this.firstName).length == 0) {
				myDataError = new dataError();
				myDataError.description = 'First Name is Required';
				myDataError.element = 'firstName';
				this.errors.push(myDataError);
			}
				
			if (this.trimString(this.lastName).length == 0) {
				myDataError = new dataError();
				myDataError.description = 'Last Name is Required';
				myDataError.element = 'lastName';
				this.errors.push(myDataError);
			}
		}

		return this.errors.length == 0;
	}


	/* 
	 * Trim String
	 *
	 * Does a VB Trim on a String
	 */
	this.trimString = function(str) {
	   return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
}	

function address() {
	xmlObject.call(this);

	this.addressTypeFlag = 1;				//Default Value "1"
	this.street1="";
	this.street2="";
	this.city="";
	this.state="GA";						//Default Value = "GA"
	this.zip="";
	this.country = "USA";					//Default Value "USA"
	this.errors = new Array();	

	var ADDRESSTYPEUS = 1;
	var ADDRESSTYPEINTERNATIONAL = 2;
	var ADDRESSTYPEMILITARY = 3;

	
	this.isValid = function(bShow) {
		this.errors = new Array();
		var myDataError;
		if (this.trimString(this.street1).length == 0) {
			myDataError = new dataError();
			myDataError.description = 'Address 1 is Required';
			myDataError.element = 'street1';
			this.errors.push(myDataError);
		}

		if (this.trimString(this.city).length == 0) {
			myDataError = new dataError();
			myDataError.description = 'City is Required';
			myDataError.element = 'city';
			this.errors.push(myDataError);
		}

		if (this.addressTypeFlag == ADDRESSTYPEUS) {
			if (this.trimString(this.state).length == 0) {
				myDataError = new dataError();
				myDataError.description = 'State is Required';
				myDataError.element = 'state';
				this.errors.push(myDataError);
			}
		}

		if (this.trimString(this.zip).length == 0) {
			myDataError = new dataError();
			myDataError.description = 'Zip is Required';
			myDataError.element = 'zip';
			this.errors.push(myDataError);
		} else {
			if (this.addressTypeFlag == ADDRESSTYPEUS) {
				this.validateZIP(this.zip, bShow);
			}
		}

		if (this.trimString(this.country).length == 0) {
			myDataError = new dataError();
			myDataError.description = 'Country is Required';
			myDataError.element = 'country';
			this.errors.push(myDataError);
		}

		return this.errors.length == 0;
	}


	/* 
	 * Trim String
	 *
	 * Does a VB Trim on a String
	 */
	this.trimString = function(str) {
	   return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}

	this.validateZIP = function(str, bShow) {
		var myDataError;
		var valid = "0123456789";
		if (bShow==undefined)
			bShow = true;
		// The else case is to take care of the submit, which truthfully I don't think needs to be validated again
		// but due to time I really don't have time to get back into that.  George's design and I am going with it.
		if (bShow) {
			if(this.trimString(document.getElementById("zip").value).length != 5) {
				myDataError = new dataError();
				myDataError.description = "Please enter all digits of zip code";;
				myDataError.element = 'zip';
				this.errors.push(myDataError);
			} 
						
			if(this.trimString(document.getElementById("zip1").value).length != 4 && this.trimString(document.getElementById("zip1").value).length != 0) {
				myDataError = new dataError();
				myDataError.description = "Please enter all +4 digits of zip code";;
				myDataError.element = 'zip1';
				this.errors.push(myDataError);
			} 
		} else {
			if (str.length!=5 && str.length!=9) {
				if (str.length == 9) {
					myDataError = new dataError();
					myDataError.description = "Please be sure to put the dash into your 5 digit+4 zip code";;
					myDataError.element = 'zip1';
					this.errors.push(myDataError);
					return false;
				} else {
					myDataError = new dataError();
					myDataError.description = "Please enter all of your 5 digit or 5 digit+4 zip code";;
					myDataError.element = 'zip1';
					this.errors.push(myDataError);
					return false;
				}
			}
		}

		for (var i=0; i < str.length; i++) {
			temp = "" + str.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") {
				if (i < 5) {
					myDataError = new dataError();
					myDataError.description = "Invalid characters in your zip code.  Please try again.";;
					myDataError.element = 'zip';
					this.errors.push(myDataError);
					
					i = 5;
				} else {
					myDataError = new dataError();
					myDataError.description = "Invalid characters in your +4 zip code.  Please try again.";;
					myDataError.element = 'zip1';
					this.errors.push(myDataError);

					return false;	// just to return, false means nothing
				}
			}
		}

		return true;
	}

	this.validateZIP_Backup = function(str) {
		var valid = "0123456789-";
		var hyphencount = 0;
		if (str.length!=5 && str.length!=10) {
			if (str.length == 9)
				return "Please be sure to put the dash into your 5 digit+4 zip code";
			else
				return "Please enter all of your 5 digit or 5 digit+4 zip code.";
		}

		for (var i=0; i < str.length; i++) {
			temp = "" + str.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {
				return "Invalid characters in your zip code.  Please try again.";
			}
			if ((hyphencount > 1) || ((str.length==10) && ""+str.charAt(5)!="-")) {
				return "The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.";
			 }
		}
		return true;
	}
}


function SimpleAddress(bSeller, bBuyer) {
	Panel.call(this);
	
	var bShowSeller = bSeller || false;
	var bShowBuyer = bBuyer || false;
	var myAddress=new actor();
	var myAdditionalActors = new additionalActors();
	var additionalListID = -1;
	
	var sLastUSState = '';
	var sLastINTERNATIONALState = '';
	var sLastMILITARYState = '';
	var sLastUSZip = '';
	var sLastINTERNATIONALZip = '';
	var sLastMILITARYZip = '';
	var sLastINTERNATIONALCountry = '';
	var lLastSelectedAddressType;

	var ADDRESSTYPEUS = 1;
	var ADDRESSTYPEINTERNATIONAL = 2;
	var ADDRESSTYPEMILITARY = 3;
	
	var sStateDropLabelHTML = '';							//To hold the HTML from the State Drop Down Label DIV tag
	var sStateDropHTML = '';								//To hold the HTML from the State Drop Down DIV tag
	var sStateTextLabelHTML = '';							//To hold the HTML from the State Text Box Label DIV tag
	var sStateTextHTML = '';								//To hold the HTML from the State Text Box DIV tag

	var sZipSingleLabelHTML = '';							//To hold the HTML from the Zip Single Label DIV tag
	var sZipSingleHTML = '';								//To hold the HTML from the Zip Single DIV tag
	var sZipDoubleLabelHTML = '';							//To hold the HTML from the Zip Double Label DIV tag
	var sZipDoubleHTML = '';								//To hold the HTML from the Zip Double DIV tag

	
	this.display = function () {
		this.getContainer().innerHTML=this.getForm();
		document.getElementById("dvTitle").innerHTML = this.getTitle();

		//Initialize variables to make the system more usable
		lLastSelectedAddressType = myAddress.address['addressTypeFlag'];
		if (lLastSelectedAddressType == ADDRESSTYPEUS) {
			sLastUSState = myAddress.address['state'];
			sLastUSZip = myAddress.address['zip'];
		}
		if (lLastSelectedAddressType == ADDRESSTYPEINTERNATIONAL) {
			sLastINTERNATIONALState = myAddress.address['state'];
			sLastINTERNATIONALZip = myAddress.address['zip'];
			sLastINTERNATIONALCountry = myAddress.address['country'];
		}
		if (lLastSelectedAddressType == ADDRESSTYPEMILITARY) {
			sLastMILITARYState = myAddress.address['state'];
			sLastMILITARYZip = myAddress.address['zip'];
		}

		this.displayValues();
		this.displayAddressTypeFields(true);
		this.focusFirstElement();
	}

	
	this.displayValues = function() {		
		for(var i in myAddress.name) {		
			if(typeof myAddress.name[i] != "object" && typeof myAddress.name[i] != "function"  ){
				if (i == "businessFlag") {
					if (myAddress.name[i]) {
						document.getElementById(i).checked = myAddress.name[i];
						
						document.getElementById("firstName").disabled = true;
						document.getElementById("middleName").disabled = true;
						document.getElementById("lastName").disabled = true;
					} else {
						document.getElementById("individualFlag").checked = true;

						document.getElementById("businessName").disabled = true;
					}
				}
				else {
					document.getElementById(i).value = myAddress.name[i];
				}
			}
		}
		
		for(var i in myAddress.address) {		
			if(typeof myAddress.address[i] != "object" && typeof myAddress.address[i] != "function"  ){
				if (i == 'zip') {
					if (myAddress.address['addressTypeFlag'] == ADDRESSTYPEUS) {
						if (myAddress.address[i].length == 5) {
							document.getElementById(i).value = myAddress.address[i];
							document.getElementById(i + '1').value = '';
						} else if (myAddress.address[i].length == 9) {
							document.getElementById(i).value = myAddress.address[i].substr(0, 5);
							document.getElementById(i + '1').value = myAddress.address[i].substr(5, 4);
						} else {
							document.getElementById(i).value = myAddress.address[i];
						}
					} else {
						document.getElementById(i).value = myAddress.address[i];
					}
				} else {
					if (i == 'addressTypeFlag') {
						if (myAddress.address[i] == ADDRESSTYPEUS) {
							document.getElementById('addressTypeUSFlag').checked = true;
							document.getElementById('addressTypeInternationalFlag').checked = false;
							document.getElementById('addressTypeMilitaryFlag').checked = false;
						} else if (myAddress.address[i] == ADDRESSTYPEINTERNATIONAL) {
							document.getElementById('addressTypeUSFlag').checked = false;
							document.getElementById('addressTypeInternationalFlag').checked = true;
							document.getElementById('addressTypeMilitaryFlag').checked = false;
						} else {
							document.getElementById('addressTypeUSFlag').checked = false;
							document.getElementById('addressTypeInternationalFlag').checked = false;
							document.getElementById('addressTypeMilitaryFlag').checked = true;
						}
					} else {
						document.getElementById(i).value = myAddress.address[i];
					}
				}
			}
		}
		
		if (bShowBuyer) {
			//Write out the additional names
			document.getElementById("AdditionalIndividualFlag").checked = true;
			document.getElementById("AdditionalBusinessName").disabled = true;
			
			var e = document.getElementById("AdditionalNames");
			e.options.length = 0;	//Clear the list box before writing to it again
			for (var i=0; i < myAdditionalActors.count(); i++) {
				var sName = myAdditionalActors.returnListBoxText(i);
				e.options[e.options.length] = new Option(sName);
			}
		}
	}

	
	this.focusFirstElement = function() {
		if ( (myAddress.name.errors.length + myAddress.address.errors.length) == 0) {
			if (document.getElementById("individualFlag").checked) {
				document.getElementById("firstName").focus();
				document.getElementById("firstName").select();
			} else {
				document.getElementById("businessName").focus();
				document.getElementById("businessName").select();
			}
		}
	}

	
	this.setData = function() {
		for(var i in myAddress.name) {		
			if(typeof myAddress.name[i] != "object" && typeof myAddress.name[i] != "function"  ){
				if (i == "businessFlag") {
					myAddress.name[i] = document.getElementById(i).checked;
				} else {
					myAddress.name[i] = document.getElementById(i).value;
					document.getElementById(i).className = 'textFieldNormal';
				}
			}
		}
		for(var i in myAddress.address) {		
			if(typeof myAddress.address[i] != "object" && typeof myAddress.address[i] != "function"  ){
				if (i == 'zip') {
					if (myAddress.address['addressTypeFlag'] == ADDRESSTYPEUS) {
						myAddress.address[i] = this.trimString(document.getElementById(i).value) + this.trimString(document.getElementById(i + '1').value);
					} else {
						myAddress.address[i] = this.trimString(document.getElementById(i).value);
					}
				} else if (i == 'addressTypeFlag') {
					if (document.getElementById('addressTypeUSFlag').checked) {
						myAddress.address[i] = ADDRESSTYPEUS;
					} else if (document.getElementById('addressTypeInternationalFlag').checked) {
						myAddress.address[i] = ADDRESSTYPEINTERNATIONAL;
					} else {
						myAddress.address[i] = ADDRESSTYPEMILITARY;
					}
				} else {
					myAddress.address[i] = this.trimString(document.getElementById(i).value);
				}
			}
		}
	}

	
	this.hide = function() {
		this.setData();
		
		this.getContainer().innerHTML="";
	}


	this.trigger = function(aControl, anEvent) {
		if (anEvent == 'click') {
			/*
			 * For some reason getElementByID does not return the radio array
			 * Because of that I had to code for the radio buttons changing
			 */
			if (aControl.name == 'businessFlag') {
				this.setNameProperties(false);
			} else if (aControl.name == 'individualFlag') {
				this.setNameProperties(true);
			}
		} else if (anEvent == 'clickaddtional') {
			if (aControl.name == 'AdditionalBusinessFlag') {
				this.setAdditionalProperties(false);
			} else if (aControl.name == 'AdditionalIndividualFlag') {
				this.setAdditionalProperties(true);
			}
		} else if (anEvent == 'addresschange') {
			if (aControl.value == ADDRESSTYPEUS) {
				myAddress.address['addressTypeFlag'] = ADDRESSTYPEUS;
				this.displayAddressTypeFields();
			} else {
				if (aControl.value == ADDRESSTYPEINTERNATIONAL) {
					myAddress.address['addressTypeFlag'] = ADDRESSTYPEINTERNATIONAL;
					this.displayAddressTypeFields();
				} else {
					if (aControl.value == ADDRESSTYPEMILITARY) {
						myAddress.address['addressTypeFlag'] = ADDRESSTYPEMILITARY;
						this.displayAddressTypeFields();
					} else {
						alert('Unkown Address Type');
					}
				}
			}
		} else if (anEvent == 'addadditional') {
			this.addAddtional();
		} else if (anEvent == 'updateadditional') {
			this.updateAdditional();
		} else if (anEvent == 'modifyadditional') {
			this.modifyAdditional();
		} else if (anEvent == 'deleteadditional') {
			this.deleteAdditional();
		}
	}
	
	this.displayAddressTypeFields = function(firstLoad) {
		/*********************************************************************
		 **																	**
		 ** Store fields so they display data will not overwrite new data	**
		 **																	**
		 *********************************************************************/
		if (document.getElementById('businessFlag').checked) {
			myAddress.name['businessFlag'] = true;
			myAddress.name['businessName'] = document.getElementById('businessName').value;
			myAddress.name['firstName'] = '';
			myAddress.name['middleName'] = '';
			myAddress.name['lastName'] = '';
		} else {
			myAddress.name['businessFlag'] = false;
			myAddress.name['businessName'] = '';
			myAddress.name['firstName'] = document.getElementById('firstName').value;
			myAddress.name['middleName'] = document.getElementById('middleName').value;
			myAddress.name['lastName'] = document.getElementById('lastName').value;
		}

		myAddress.address['street1'] = this.trimString(document.getElementById('street1').value);
		myAddress.address['street2'] = this.trimString(document.getElementById('street2').value);
		myAddress.address['city'] = this.trimString(document.getElementById('city').value);
		if (lLastSelectedAddressType == ADDRESSTYPEUS) {
			myAddress.address['zip'] = this.trimString(document.getElementById('zip').value) + this.trimString(document.getElementById('zip1').value);
		} else {
			myAddress.address['zip'] = this.trimString(document.getElementById('zip').value);
		}

	
		/*********************************************************************
		 **																	**
		 ** Initialize the variaibles which will hold the original HTML		**
		 **																	**
		 *********************************************************************/
		if (sStateDropHTML == '') {
			// sStateDropLabelHTML - To make easier with the way Divs break I am just going to set this manually
			sStateDropHTML = document.getElementById("dvStateDropDown").innerHTML;;
		}
		
		if (sStateTextHTML == '') {
			sStateTextLabelHTML = document.getElementById("dvStateTextLabel").innerHTML;;
			sStateTextHTML = document.getElementById("dvStateText").innerHTML;;
		}

		if (sZipSingleHTML == '') {
			sZipSingleLabelHTML = document.getElementById("dvZipSingleLabel").innerHTML;;
			sZipSingleHTML = document.getElementById("dvZipSingle").innerHTML;;
		}
		
		if (sZipDoubleHTML == '') {
			sZipDoubleLabelHTML = document.getElementById("dvZipDoubleLabel").innerHTML;;
			sZipDoubleHTML = document.getElementById("dvZipDouble").innerHTML;;
		}


		/*********************************************************************
		 **																	**
		 ** Now do the real work											**
		 **																	**
		 *********************************************************************/
 		if (myAddress.address['addressTypeFlag'] == ADDRESSTYPEUS) {
			//If last Address was a International or Military address, store the state
			if (lLastSelectedAddressType == ADDRESSTYPEINTERNATIONAL) {
				sLastINTERNATIONALState = document.getElementById('state').value;
				sLastINTERNATIONALZip = document.getElementById('zip').value;
				sLastINTERNATIONALCountry = document.getElementById('country').value;
			}
			if (lLastSelectedAddressType == ADDRESSTYPEMILITARY) {
				sLastMILITARYState = document.getElementById('state').value;
				sLastMILITARYZip = document.getElementById('zip').value;
			}

			//Restore the last selected US State
			myAddress.address['state'] = sLastUSState;

			//Restore the last selected US Zip
			myAddress.address['zip'] = sLastUSZip;
				
			//Store the new Selected Address Type as the old one for the next change
			lLastSelectedAddressType = ADDRESSTYPEUS;

			//Set up the Address Type Field
			document.getElementById('addressTypeUSFlag').checked = true;
			document.getElementById('addressTypeInternationalFlag').checked = false;
			document.getElementById('addressTypeMilitaryFlag').checked = false;

			//Set up the State Field
			document.getElementById("dvStateDropDownLabel").innerHTML = '<FONT COLOR="FF0000">*</FONT> State:';
			document.getElementById("dvStateDropDown").innerHTML = sStateDropHTML;
			document.getElementById("dvStateTextLabel").innerHTML = '';
			document.getElementById("dvStateText").innerHTML = '';
			
			//Set up the Zip Field
			document.getElementById("dvZipSingleLabel").innerHTML = '';
			document.getElementById("dvZipSingle").innerHTML = '';
			document.getElementById("dvZipDoubleLabel").innerHTML = sZipDoubleLabelHTML;
			document.getElementById("dvZipDouble").innerHTML = sZipDoubleHTML;
			
			//Set up the County Field
			myAddress.address['country'] = 'USA';
			document.getElementById("country").disabled = true;
			document.getElementById("country").className='textFieldNormal';
		}

		if (myAddress.address['addressTypeFlag'] == ADDRESSTYPEINTERNATIONAL) {
			//If last Address was a US or Military address, store the state
			if (lLastSelectedAddressType == ADDRESSTYPEUS) {
				sLastUSState = document.getElementById('state').value;
				if (this.trimString(document.getElementById('zip').value).length == 5 && this.trimString(document.getElementById('zip1').value).length == 4)
					sLastUSZip = document.getElementById('zip').value + document.getElementById('zip1').value;
				else
					sLastUSZip = document.getElementById('zip').value;
			}
			if (lLastSelectedAddressType == ADDRESSTYPEMILITARY) {
				sLastMILITARYState = document.getElementById('state').value;
				sLastMILITARYZip = document.getElementById('zip').value;
			}

			//Restore the last selected INTERNATIONAL State
			myAddress.address['state'] = sLastINTERNATIONALState;

			//Restore the last selected INTERNATIONAL State
			myAddress.address['zip'] = sLastINTERNATIONALZip;

			//Restore the last selected INTERNATIONAL Country
			myAddress.address['country'] = sLastINTERNATIONALCountry;

			//Store the new Selected Address Type as the old one for the next change
			lLastSelectedAddressType = ADDRESSTYPEINTERNATIONAL;

			//Set up the Address Type Field
			document.getElementById('addressTypeUSFlag').checked = false;
			document.getElementById('addressTypeInternationalFlag').checked = true;
			document.getElementById('addressTypeMilitaryFlag').checked = false;

			//Set up the State Field
			document.getElementById("dvStateDropDownLabel").innerHTML = '';
			document.getElementById("dvStateDropDown").innerHTML = '';
			document.getElementById("dvStateTextLabel").innerHTML = sStateTextLabelHTML;
			document.getElementById("dvStateText").innerHTML = sStateTextHTML;
			
			//Set up the Zip Field
			document.getElementById("dvZipSingleLabel").innerHTML = sZipSingleLabelHTML;
			document.getElementById("dvZipSingle").innerHTML = sZipSingleHTML;
			document.getElementById("dvZipDoubleLabel").innerHTML = '';
			document.getElementById("dvZipDouble").innerHTML = '';
			
			//Set up the County Field
			document.getElementById("country").selectedIndex = -1;	//this is only for non-IE browsers, otherwise it won't clear
			document.getElementById("country").disabled = false;
			document.getElementById("country").className='textFieldNormal';
		}

		if (myAddress.address['addressTypeFlag'] == ADDRESSTYPEMILITARY) {
			//If last Address was a US or International address, store the state
			if (lLastSelectedAddressType == ADDRESSTYPEUS) {
				sLastUSState = document.getElementById('state').value;
				if (this.trimString(document.getElementById('zip').value).length == 5 && this.trimString(document.getElementById('zip1').value).length == 4)
					sLastUSZip = document.getElementById('zip').value + document.getElementById('zip1').value;
				else
					sLastUSZip = document.getElementById('zip').value;
			}
			if (lLastSelectedAddressType == ADDRESSTYPEINTERNATIONAL) {
				sLastINTERNATIONALState = document.getElementById('state').value;
				sLastINTERNATIONALZip = document.getElementById('zip').value;
				sLastINTERNATIONALCountry = document.getElementById('country').value;
			}

			//Restore the last selected MILITARY State
			myAddress.address['state'] = sLastMILITARYState;

			//Restore the last selected MILITARY Zip
			myAddress.address['zip'] = sLastMILITARYZip;
				
			//Store the new Selected Address Type as the old one for the next change
			lLastSelectedAddressType = ADDRESSTYPEMILITARY;

			//Set up the Address Type Field
			document.getElementById('addressTypeUSFlag').checked = false;
			document.getElementById('addressTypeInternationalFlag').checked = false;
			document.getElementById('addressTypeMilitaryFlag').checked = true;

			//Set up the State Field
			document.getElementById("dvStateDropDownLabel").innerHTML = '';
			document.getElementById("dvStateDropDown").innerHTML = '';
			document.getElementById("dvStateTextLabel").innerHTML = sStateTextLabelHTML;
			document.getElementById("dvStateText").innerHTML = sStateTextHTML;
			
			//Set up the Zip Field
			document.getElementById("dvZipSingleLabel").innerHTML = sZipSingleLabelHTML;
			document.getElementById("dvZipSingle").innerHTML = sZipSingleHTML;
			document.getElementById("dvZipDoubleLabel").innerHTML = '';
			document.getElementById("dvZipDouble").innerHTML = '';
			
			//Set up the County Field
			myAddress.address['country'] = 'USA';
			document.getElementById("country").disabled = true;
			document.getElementById("country").className='textFieldNormal';
		}
		
		this.displayValues();
	}
	
	this.setNameProperties = function(bIndividual) {
		if (bIndividual) {
			document.getElementById("businessFlag").checked = false;			
			document.getElementById("businessName").disabled = true;
			document.getElementById("businessName").className = 'textFieldNormal';
			document.getElementById("businessName").value = '';

			document.getElementById("firstName").disabled = false;
			document.getElementById("middleName").disabled = false;
			document.getElementById("lastName").disabled = false;
			document.getElementById("firstName").select();
		} else {
			document.getElementById("individualFlag").checked = false;
			document.getElementById("firstName").disabled = true;
			document.getElementById("firstName").className = 'textFieldNormal';
			document.getElementById("firstName").value = '';
			document.getElementById("middleName").disabled = true;
			document.getElementById("middleName").value = '';
			document.getElementById("lastName").disabled = true;
			document.getElementById("lastName").className = 'textFieldNormal';
			document.getElementById("lastName").value = '';

			document.getElementById("businessName").disabled = false;
			document.getElementById("businessName").select();
		}	
	}

	this.validateAdditional = function(strType) {
		var elBusinessFlag = document.getElementById("AdditionalBusinessFlag");
		if (elBusinessFlag.checked) {
			var elBusinessName = document.getElementById("AdditionalBusinessName");
			if (this.trimString(elBusinessName.value).length == 0) {
				alert('You must enter a Business Name to ' + strType + ' the Additional Buyer');
				elBusinessName.className = 'textFieldError';
				elBusinessName.select();
				return false;
			}		
		} else {
			var elFirstName = document.getElementById("AdditionalFirstName");
			var elLastName = document.getElementById("AdditionalLastName");
			if (this.trimString(elFirstName.value).length == 0) {
				alert('You must enter a First Name to ' + strType + ' the Additional Buyer');
				elFirstName.className = 'textFieldError';
				elFirstName.select();
				return false;
			}
			if (this.trimString(elLastName.value).length == 0) {
				alert('You must enter a Last Name to ' + strType + ' the Additional Buyer');
				elLastName.className = 'textFieldError';
				elLastName.select();
				return false;
			}
		}
	
		return true;
	}

	
	this.addAddtional = function() {
		if (this.validateAdditional('Add')) {
			var anActor = new actor();
			var elBusinessFlag = document.getElementById("AdditionalBusinessFlag");

			/*
			 * First Determine if it is a business or individual and set properties accordingly
			 */
			if (elBusinessFlag.checked) {
				var elBusinessName = document.getElementById("AdditionalBusinessName");

				anActor.name.businessFlag = true;
				anActor.name.businessName = elBusinessName.value;
			} else {
				var elFirstName = document.getElementById("AdditionalFirstName");
				var elMiddleName = document.getElementById("AdditionalMiddleName");
				var elLastName = document.getElementById("AdditionalLastName");

				anActor.name.businessFlag = false;
				anActor.name.firstName = elFirstName.value;
				anActor.name.middleName = elMiddleName.value;
				anActor.name.lastName = elLastName.value;
			}
			myAdditionalActors.push(anActor);
					
			/*
			 * Now add the additional actor to the listbox
			 */
			var e = document.getElementById("AdditionalNames");
			var sName = myAdditionalActors.returnListBoxText(myAdditionalActors.count()-1);
			e.options[e.options.length] = new Option(sName);

			/*
			 * Reset the additional fields
			 */
			this.clearAdditional();
		}
	}
	

	this.deleteAdditional = function() {
		var e = document.getElementById("AdditionalNames");
		if (e.selectedIndex < 0) {
			alert('Please select an item in the list to the left');
		} else {
			// Delete the item from the Additional Actors List Box
			myAdditionalActors.deleteAt(e.selectedIndex);

			// Delete the item from the listbox
			e.options[e.selectedIndex] = null;											
		}
	}

	
	this.updateAdditional = function() {
		if (this.additionalListID < 0 || this.additionalListID == undefined) {
			alert('Please select a person or business to modify from the list below,\nand click the "Modify Selected" button');
		} else {
			if (this.validateAdditional('Update')) {
				var e = document.getElementById("AdditionalNames");
				if (this.additionalListID != e.selectedIndex) {
					var msg;
					msg = 'The person/buisness you are attempting to modify\n';
					msg += 'is NOT the same person/business selected in the list below.\n\n';
					msg += 'Do you wish to modify the person/business selected below?\n';
					msg += 'Click OK to modify the person/business selected below,\n';
					msg += 'click CANCEL to modify the orginally selected person/business.';
					if (confirm(msg)) {
						this.additionalListID = e.selectedIndex;
					}
				}
						
				// Update the actor
				var anActor = new actor();
				var elBusinessFlag = document.getElementById("AdditionalBusinessFlag");

				/*
				 * First Determine if it is a business or individual and set properties accordingly
				 */
				if (elBusinessFlag.checked) {
					var elBusinessName = document.getElementById("AdditionalBusinessName");

					anActor.name.businessFlag = true;
					anActor.name.businessName = elBusinessName.value;
				} else {
					var elFirstName = document.getElementById("AdditionalFirstName");
					var elMiddleName = document.getElementById("AdditionalMiddleName");
					var elLastName = document.getElementById("AdditionalLastName");

					anActor.name.businessFlag = false;
					anActor.name.firstName = elFirstName.value;
					anActor.name.middleName = elMiddleName.value;
					anActor.name.lastName = elLastName.value;
				}
				myAdditionalActors.updateAt(this.additionalListID, anActor);

				//update the list box with new info				
				e = document.getElementById("AdditionalNames");
				var sName = myAdditionalActors.returnListBoxText(this.additionalListID);
				e.options[this.additionalListID] = new Option(sName);

				this.clearAdditional();
				this.additionalListID = -1;
			}
		}
	}

	
	this.modifyAdditional = function() {
		var e = document.getElementById("AdditionalNames");
		if (e.selectedIndex < 0) {
			alert('Please select a person or business in the list to the left');
		} else {
			var anActor = myAdditionalActors.getAt(e.selectedIndex);
			if (anActor.name.businessFlag) {
				this.clearAdditional();
				this.setAdditionalProperties(false);
				document.getElementById("AdditionalBusinessFlag").checked = true;
				document.getElementById("AdditionalBusinessName").value = anActor.name.businessName;
				document.getElementById("AdditionalBusinessName").select();
			} else {
				this.clearAdditional();
				this.setAdditionalProperties(true);
				document.getElementById("AdditionalIndividualFlag").checked = true;
				document.getElementById("AdditionalFirstName").value = anActor.name.firstName;
				document.getElementById("AdditionalMiddleName").value = anActor.name.middleName;
				document.getElementById("AdditionalLastName").value = anActor.name.lastName;
				document.getElementById("AdditionalFirstName").select();
			}

			this.additionalListID = e.selectedIndex;
		}
	}


	this.clearAdditional = function() {
		document.getElementById("AdditionalFirstName").value = "";
		document.getElementById("AdditionalMiddleName").value = "";
		document.getElementById("AdditionalLastName").value = "";
		document.getElementById("AdditionalBusinessName").value = "";
		document.getElementById("AdditionalBusinessFlag").checked = false;
		document.getElementById("AdditionalIndividualFlag").checked = true;

		this.setAdditionalProperties(true);
	}

	
	this.setAdditionalProperties = function(bIndividualFlag) {
		if (bIndividualFlag) {
			document.getElementById("AdditionalBusinessFlag").checked = false;			
			document.getElementById("AdditionalBusinessName").disabled = true;
			document.getElementById("AdditionalBusinessName").className = 'textFieldNormal';
			document.getElementById("AdditionalBusinessName").value = '';

			document.getElementById("AdditionalFirstName").disabled = false;
			document.getElementById("AdditionalMiddleName").disabled = false;
			document.getElementById("AdditionalLastName").disabled = false;
			document.getElementById("AdditionalFirstName").select();
		} else {
			document.getElementById("AdditionalIndividualFlag").checked = false;
			document.getElementById("AdditionalFirstName").disabled = true;
			document.getElementById("AdditionalFirstName").className = 'textFieldNormal';
			document.getElementById("AdditionalFirstName").value = '';
			document.getElementById("AdditionalMiddleName").disabled = true;
			document.getElementById("AdditionalMiddleName").value = '';
			document.getElementById("AdditionalLastName").disabled = true;
			document.getElementById("AdditionalLastName").className = 'textFieldNormal';
			document.getElementById("AdditionalLastName").value = '';

			document.getElementById("AdditionalBusinessName").disabled = false;
			document.getElementById("AdditionalBusinessName").select();
		}
	}


	this.isValid = function(bShow) {
		if (bShow==undefined)
			bShow = true;

		if (bShow) 
			this.setData();

		/*
		 * Before we do anything, check to see if there are any additional names
		 * that need adding or updating
		 */
		var elBusinessFlag = document.getElementById("AdditionalBusinessFlag");
		var bNeedsAction = false;

		if (elBusinessFlag) {
			/*
			 * First Determine if it is a business or individual
			 */
			if (elBusinessFlag.checked) {
				var elBusinessName = document.getElementById("AdditionalBusinessName");
				if (this.trimString(elBusinessName.value).length > 0) {
					bNeedsAction = true;
				}
			} else {
				var elFirstName = document.getElementById("AdditionalFirstName");
				var elMiddleName = document.getElementById("AdditionalMiddleName");
				var elLastName = document.getElementById("AdditionalLastName");
				if (this.trimString(elFirstName.value).length > 0 || this.trimString(elMiddleName.value).length > 0 || this.trimString(elLastName.value).length > 0) {
					bNeedsAction = true;
				}
			}
		}		 

		if (bNeedsAction) {
			var sMsg = 'You have not added or updated the additional buyer.\n\n';
			sMsg += 'Click OK to Add or Update an Additional Name.\n';
			sMsg += 'Please click either "Add to Additional Names"\n or "Update Additional Name".\n\n';
			sMsg += 'Click CANCEL to not enter the Additional Name\n and ignore it.\n\n';
			sMsg += 'If you are unsure which one to click, click the\n question mark next to ';
			sMsg += 'the buttons for\n information about what each does.';
			if (confirm(sMsg)) 		
				return false;
		}
		if (!myAddress.isValid(bShow)) {
			if (bShow) 
				this.displayErrors();

			return false;
		} else
			return true;
	}

	
	this.displayErrors = function() {
		var msgPop;

		msgPop = 'The following information is missing or incorrect:\n\n';
		for (var i in myAddress.name.errors) {
			msgPop += '\t' + myAddress.name.errors[i].description + '\n';
		}
		for (var i in myAddress.address.errors) {
			msgPop += '\t' + myAddress.address.errors[i].description + '\n';
		}

		msgPop += '\nand will be highlighted on the form.';
		alert(msgPop);

		for (var i in myAddress.name.errors) {
			document.getElementById(myAddress.name.errors[i].element).className = 'textFieldError';
		}
		for (var i in myAddress.address.errors) {
			document.getElementById(myAddress.address.errors[i].element).className = 'textFieldError';
		}

		if (myAddress.name.errors.length > 0)
			document.getElementById(myAddress.name.errors[0].element).select();
		else {
			if(myAddress.address.errors[0].element == 'state')
				document.getElementById(myAddress.address.errors[0].element).focus();
			else
				document.getElementById(myAddress.address.errors[0].element).select();
		}
	}
	
	
	this.toXml = function() {
		var p = myAddress.toXml();
		
		if (myAdditionalActors.count() > 0) 
			p.appendChild(myAdditionalActors.toXml());

		return p;
	}


	/* 
	 * Trim String
	 *
	 * Does a VB Trim on a String
	 */
	this.trimString = function(str) {
	   return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	
	/*
	 * loadActor
	 *
	 * Initializes object to saved values from database
	 */
	this.loadActor = function(businessFlag, fName, mName, lName, addressType, address1, address2, city, state, zip, country) {
		if (businessFlag == 0) {
			myAddress.name.businessFlag = false;
			myAddress.name.firstName = fName;
			
			if (this.trimString(mName).length > 0)
				myAddress.name.middleName = mName;
				
			myAddress.name.lastName = lName;
		} else {
			myAddress.name.businessFlag = true;
			myAddress.name.businessName = lName;
		}
		
		if (addressType == ADDRESSTYPEUS)
			myAddress.address['addressTypeFlag'] = ADDRESSTYPEUS;
		else if (addressType == ADDRESSTYPEINTERNATIONAL)
			myAddress.address['addressTypeFlag'] = ADDRESSTYPEINTERNATIONAL;
		else if (addressType == ADDRESSTYPEMILITARY)
			myAddress.address['addressTypeFlag'] = ADDRESSTYPEMILITARY;
			
		myAddress.address.street1 = address1;
		
		if (this.trimString(address2).length > 0)
			myAddress.address.street2 = address2;

		myAddress.address.city = city;

		if (this.trimString(state).length > 0)
			myAddress.address.state = state;

		myAddress.address.zip = zip;

		myAddress.address.country = country;
	}
	
	/*
	 * loadAdditionalActor
	 *
	 * Initializes the additional actors
	 */
	this.loadAdditionalActor = function(businessFlag, fName, mName, lName) {
		var anActor = new actor();
		if (businessFlag == 0) {


			anActor.name.businessFlag = false;
			anActor.name.firstName = fName;
			
			if (this.trimString(mName).length > 0)
				anActor.name.middleName = mName;
				
			anActor.name.lastName = lName;
		} else {
			anActor.name.businessFlag = true;
			anActor.name.businessName = lName;
		}	

		myAdditionalActors.push(anActor);
	}
}
