var arrAddressFields = new Array(
	"PersonAddress1",
	"PersonAddress2",
	"PersonAddress3",
	"PersonAddress4",
	"PersonAddress4_typein",
	"PersonPostalCode",
	"PersonCountry",
	"PersonPhoneNumber",
	"PersonMobileNumber",
	"PersonFaxNumber",
	"PersonEmail",
	"PersonTitle",
	"PersonSalutation",
	"PersonFirstName",
	"PersonLastName",
	"PersonCompany"
	);

function HideInvoice()
	{
	// Check to see if seperate address we checked before and if so show address and check box
	var chkBox = document.getElementById('InvoiceShowHide');

	if (chkBox == null)
		{
		bSeparateAddresses = false;
		}
	else
		{
		chkBox.checked = AddressesDiffer() ? true : false;
		bSeparateAddresses = chkBox.checked;
		}

	if (bSeparateAddresses)
		{
		document.getElementById('DeliveryAddressLegend').innerHTML = "Deliver To:";
		document.getElementById('InvoiceAddress').style.display ='block';
		}
	else
		{
		document.getElementById('DeliveryAddressLegend').innerHTML = "Invoice/Deliver To:";
		document.getElementById('InvoiceAddress').style.display ='none';
		}
	}

function ShowHideInvoice()
	{
	// Check to see if seperate address we checked before and if so show address and check box
	var chkBox = document.getElementById('InvoiceShowHide');

	if (chkBox.checked)
		{
		document.getElementById('DeliveryAddressLegend').innerHTML = "Deliver To:";
		document.getElementById('InvoiceAddress').style.display ='block';
		}
	else
		{
		document.getElementById('DeliveryAddressLegend').innerHTML = "Invoice/Deliver To:";
		document.getElementById('InvoiceAddress').style.display ='none';
		}
	}

function AddressesDiffer()
	{
	var nField;
	for (nField in arrAddressFields)
		{
		var sField = arrAddressFields[nField];
		if (document.getElementById("Invoice_" + sField) == null)
			{
			alert("No id defined for 'Invoice_" + sField + "'");
			}
		if (document.getElementById("Delivery_" + sField) == null)
			{
			alert("No id defined for 'Delivery_" + sField + "'");
			}
		if (document.getElementById("Invoice_" + sField).value !=
			document.getElementById("Delivery_" + sField).value)
			{
			return(true);
			}
		}
	return(false);
	}

function CopyAddress(sFrom, sTo)
	{
	chkBox = document.getElementById('InvoiceShowHide');
	if (chkBox != null && chkBox.checked)
		{
		return;
		}

	var nField;
	for (nField in arrAddressFields)
		{
		var sField = arrAddressFields[nField];
		document.getElementById(sTo + '_' + sField).value =
			document.getElementById(sFrom + '_' + sField).value;
		}
	}

//addLoadEvent("HideInvoice();");

/***********************************************************************
*
* SwapImage			-	swaps an image to the alternative
*
* Input:	sName		-	name of the image
*
*			sAltImage	-	filename of the alternative image
*
************************************************************************/

function SwapImage(sName, sAltImage)
	{
	var nCount = 0;
	document.aSource = new Array;						// array for images
	if (document[sName] != null)						// if image name exists
		{
		document.aSource[nCount++] = document[sName];	// store image
		if(null == document[sName].sOldSrc)
			{
			document[sName].sOldSrc = document[sName].src;	// store image source
			}
		document[sName].src = sAltImage;				// change image source to alternative
		}
	}

/***********************************************************************
*
* RestoreImage		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function RestoreImage()
	{
	var nCount, aSource = document.aSource;
	if (aSource != null)									// if array of images exists
		{
		for(nCount=0; nCount < aSource.length; nCount++)	// restore all images
			{
			if ((aSource[nCount] != null) &&
				(aSource[nCount].sOldSrc != null))	// if we stored something for this image
				{
				aSource[nCount].src = aSource[nCount].sOldSrc;	// restore the original image
				}
			}
		}
	}

/***********************************************************************
*
* PreloadImages		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
*
************************************************************************/

function PreloadImages()
	{
	bPageIsLoaded = true;
	if(document.images)
		{
		if(!document.Preloaded)							// preload array defined?
			{
			document.Preloaded = new Array();		// no, define it
			}
		var nCounter , nLen = document.Preloaded.length, saArguments = PreloadImages.arguments;
		for(nCounter = 0; nCounter < saArguments.length; nCounter++)	// iterate through arguments
			{
			document.Preloaded[nLen] = new Image;
			document.Preloaded[nLen++].src = saArguments[nCounter];
			}
   	}
	}