function AddAddress(
	arAddresses,
	strAddressId,
	strCountryNameId,
	strState,
	strCounty,
	strCity,
	strZipCode,
	strAddress,
	strPhone,
	strDayPhone,
	strFax,
	strEMail)
{
	var obAddress = new Array(
		strAddressId,
		strCountryNameId,
		strState,
		strCounty,
		strCity,
		strZipCode,
		strAddress,
		strPhone,
		strDayPhone,
		strFax,
		strEMail);
	intLength = arAddresses.length;
	arAddresses[intLength] = obAddress;
}


function SelectAddress(
	arAddresses,
	strAddressId,
	strAddressControl)
{
	intLength = arAddresses.length;
	var obAddress = null;
	for(i = 0; i < intLength; i++)
	{
		if (strAddressId == arAddresses[i][0])
		{
			obAddress = arAddresses[i];
			i = intLength;
		}
	}

	if (null != obAddress)	
	{
		var strCountryNameId = obAddress[1];
		var strState = obAddress[2];
		var strCounty = obAddress[3];
		var strCity = obAddress[4];
		var strZipCode = obAddress[5];
		var strAddress = obAddress[6];
		var strPhone = obAddress[7];
		var strDayPhone = obAddress[8];
		var strFax = obAddress[9];
		var strEMail = obAddress[10];	
				
		var obCountryNameId = document.getElementById(strAddressControl + "CountryName");
		var obState = document.getElementById(strAddressControl + "State");
		var obCounty = document.getElementById(strAddressControl + "County");
		var obCity = document.getElementById(strAddressControl + "City");
		var obZipCode = document.getElementById(strAddressControl + "ZipCode");
		var obAddress = document.getElementById(strAddressControl + "Address");
		var obPhone = document.getElementById(strAddressControl + "Phone");
		var obDayPhone = document.getElementById(strAddressControl + "DayPhone");
		var obFax = document.getElementById(strAddressControl + "Fax");
		var obEMail = document.getElementById(strAddressControl + "EMail");		

		obCountryNameId.value = strCountryNameId;
		obState.value = strState;
		obCounty.value = strCounty;
		obCity.value = strCity;
		obZipCode.value = strZipCode;
		obAddress.value = strAddress;
		obPhone.value = strPhone;
		obDayPhone.value = strDayPhone;
		obFax.value = strFax;
		if( obEMail != null  )
			obEMail.value = strEMail;
	}
}


function DuplicateAddressControl(
	strAddressControlFrom,
	strAddressControlTo)
{
	var obFromCountryNameId = document.getElementById(strAddressControlFrom + "CountryName");
	var obFromState = document.getElementById(strAddressControlFrom + "State");
	var obFromCounty = document.getElementById(strAddressControlFrom + "County");
	var obFromCity = document.getElementById(strAddressControlFrom + "City");
	var obFromZipCode = document.getElementById(strAddressControlFrom + "ZipCode");
	var obFromAddress = document.getElementById(strAddressControlFrom + "Address");
	var obFromPhone = document.getElementById(strAddressControlFrom + "Phone");
	var obFromDayPhone = document.getElementById(strAddressControlFrom + "DayPhone");
	var obFromFax = document.getElementById(strAddressControlFrom + "Fax");
	var obFromEMail = document.getElementById(strAddressControlFrom + "EMail");

	var obToCountryNameId = document.getElementById(strAddressControlTo + "CountryName");
	var obToState = document.getElementById(strAddressControlTo + "State");
	var obToCounty = document.getElementById(strAddressControlTo + "County");
	var obToCity = document.getElementById(strAddressControlTo + "City");
	var obToZipCode = document.getElementById(strAddressControlTo + "ZipCode");
	var obToAddress = document.getElementById(strAddressControlTo + "Address");
	var obToPhone = document.getElementById(strAddressControlTo + "Phone");
	var obToDayPhone = document.getElementById(strAddressControlTo + "DayPhone");
	var obToFax = document.getElementById(strAddressControlTo + "Fax");
	var obToEMail = document.getElementById(strAddressControlTo + "EMail");
	
	obToCountryNameId.value = obFromCountryNameId.value;
	obToState.value = obFromState.value;
	obToCounty.value = obFromCounty.value;
	obToCity.value = obFromCity.value;
	obToZipCode.value = obFromZipCode.value;
	obToAddress.value = obFromAddress.value;
	obToPhone.value = obFromPhone.value;
	obToDayPhone.value = obFromDayPhone.value;
	obToFax.value = obFromFax.value;

	if( obToEMail != null && obFromEMail != null )
		obToEMail.value = obFromEMail.value;
}




function EnableAddressCore(
	strAddressControl,
	bEnabled)
{
	var obCountryNameId = document.getElementById(strAddressControl + "CountryName");
	var obState = document.getElementById(strAddressControl + "State");
	var obCounty = document.getElementById(strAddressControl + "County");
	var obCity = document.getElementById(strAddressControl + "City");
	var obZipCode = document.getElementById(strAddressControl + "ZipCode");
	var obAddress = document.getElementById(strAddressControl + "Address");
	var obPhone = document.getElementById(strAddressControl + "Phone");
	var obDayPhone = document.getElementById(strAddressControl + "DayPhone");
	var obFax = document.getElementById(strAddressControl + "Fax");
	var obEMail = document.getElementById(strAddressControl + "EMail");
	
	var bDisabled = !bEnabled;
	obCountryNameId.disabled = bDisabled;
	obState.disabled = bDisabled;
	obCounty.disabled = bDisabled;
	obCity.disabled = bDisabled;
	obZipCode.disabled = bDisabled;
	obAddress.disabled = bDisabled;
	obPhone.disabled = bDisabled;
	obDayPhone.disabled = bDisabled;
	obFax.disabled = bDisabled;
	if( obEMail != null )
		obEMail.disabled = bDisabled;
	
	document.getElementById( strAddressControl ).disabled = bDisabled;
}


function EnableAddress(strAddressControl)
{
	EnableAddressCore(strAddressControl, true);
}

function DisableAddress(strAddressControl)
{
	EnableAddressCore(strAddressControl, false);
}

function addressRefreshZipFormat(strAddressControlId, intCountryId)
{	
	var obLbl = document.getElementById(strAddressControlId + "ZipCodeLbl");
	var strLbl = document.getElementById(strAddressControlId + "ZipLabelBase").value;	
	var strFormats = document.getElementById(strAddressControlId + "CountryZipFormats").value;
	strLbl = strLbl.substr(0, strLbl.length - 1);
	if ("0" != intCountryId)
	{
		strLbl += " ('";
		var arFormats = strFormats.split('*');
		for (i = 0; i < arFormats.length; i += 2)
		{
			if (arFormats[i] == intCountryId)
			{
				strLbl += arFormats[i+1];
				break;
			}
		}
		
		strLbl += "')";		
	}
	obLbl.innerText = strLbl + ":";
}

