
function printWindow() 
{
	if( window.print) window.print();
}

function disableButton(frm)
{
  // disable submit button
  if (document.all || document.getElementById)
  {
    frm.btnProcess.disabled = true;
  }	
  
  return true;
}

function showProgress()
{
	if (document.getElementById)
	{
		var ibodyHeight = ( 
			document.body.scrollHeight > document.body.offsetHeight ? 
			document.body.scrollHeight : document.body.offsetHeight );

		var iclientWidth = document.body.clientWidth;

		var divGrayOut = document.getElementById("divGrayOut");
		divGrayOut.style.visibility = 'visible';

		divGrayOut.style.width = iclientWidth;
		divGrayOut.style.height = ibodyHeight;

		var divProgress = document.getElementById("progressBar");
		divProgress.style.visibility = 'visible';

		var IpopLeft = (iclientWidth - divProgress.offsetWidth) / 2;
		var IpopTop = (document.body.clientHeight - divProgress.offsetHeight) / 2;

		divProgress.style.left= IpopLeft + document.body.scrollLeft;
		divProgress.style.top= IpopTop + document.body.scrollTop;
	}
}

function hideLayers(names)
{
	var i = 0;
	var oElement = null;
	var arrNames = names.split(",");
	for( i = 0; i < arrNames.length; i++ )
	{
		oElement = document.getElementById(arrNames[i]);
		if( oElement ) oElement.style.display = "none";
	}
}

function showLayers(names)
{
	var i = 0;
	var oElement = null;
	var arrNames = names.split(",");
	for( i = 0; i < arrNames.length; i++ )
	{
		oElement = document.getElementById(arrNames[i]);
		if( oElement ) oElement.style.display = "";
	}
}

function toggleLayers(names)
{
	var i = 0;
	var oElement = null;
	var arrNames = names.split(",");
	for( i = 0; i < arrNames.length; i++ )
	{
		oElement = document.getElementById(arrNames[i]);
		if( oElement ) oElement.style.display = (oElement.style.display !='none'?'none':'');
	}
}

function DisableAddressForm()
{
	DisableFields("first|last|company|email|country|street1|street2|city|state|zip|dayphone|evephone");
}

function EnableAddressForm()
{
	DisableFields("first|last|company|email|country|street1|street2|city|state|zip|dayphone|evephone",false);
}

// Receives replies from server
function ServerReply(sReply, sContext)
{
	var lblAlert = null;
	var arrValues = null;
	var sLabelName = "";
	var sKey = "";
	var sValue = "";
	
	// Parse reply, check key, find label to alert in
	if( sReply.length > 0 )
	{
		arrValues = sReply.split("=");
		if( arrValues.length == 2 )
		{
			sKey = arrValues[0];
			sValue = arrValues[1];

			if( sKey == "sitename" )
			{
				lblAlert = document.getElementById('lblSitenameAlert' );
			}
			else if( sKey == "username" )
			{
				lblAlert = document.getElementById('lblUsernameAlert' );
			}
			else if( sKey == "customerno" )
			{
				lblAlert = document.getElementById('lblCustomerNoAlert' );
			}
		}
	}

	if( sKey == "customerno" 
		&& sValue.length > 0
		&& sValue.indexOf("okfill") == 0 )
	{
		FillInForm(sValue);
	}
	else if( sKey == "customerno" 
		&& sValue == "ok" )
	{
		//DisableAddressForm();
	}
	else if( sKey == "customerno" 
		&& sValue != "ok" )
	{
		//EnableAddressForm();
		SetAlertText(lblAlert,sValue);
	}
	else if( sValue.length > 0 )
	{
		SetAlertText(lblAlert,sValue);
	}
	else
	{
		SetAlertText(lblAlert,"");
	}
}

// Disables fields specified in string
// field1|field2 ...
var _arrDisabled = new Array();
function DisableFields(sValueString,bDisable)
{
	var arrValues = null;
	var oField = "";
	var sFieldName = "";

	if(bDisable == null ) 
	{
		bDisable = true;
	}

	// fieldid|fieldid ...
	if( sValueString.length > 0 )
	{
		arrValues = sValueString.split("|");
	}
	else if( (!bDisable) && _arrDisabled.length > 0 )
	{
		arrValues = _arrDisabled;
	}

	if( arrValues.length > 0 )
	{
		for( iIndex = 0; iIndex < arrValues.length; iIndex++ )
		{
			sFieldName = arrValues[iIndex];
			oField =  document.getElementById(sFieldName);
			if( oField )
			{
				oField.disabled = bDisable;
				_arrDisabled[_arrDisabled.length] = sFieldName;
			}
		}
	}
}

// fills in form fields with values in string
// fieldid:value|fieldid:value ...
function FillInForm(sValueString)
{
	var arrValues = null;
	var oField = "";
	var sFieldName = "";
	var sValue = "";
	var iSeparator = 0;

	if( sValueString.length > 0 )
	{
		arrValues = sValueString.split("|");
		for( iIndex = 0; iIndex < arrValues.length; iIndex++ )
		{
			sValue = arrValues[iIndex];

			iSeparator = sValue.indexOf(":");
			if( iSeparator > 0 )
			{
				sFieldName = sValue.substring(0,iSeparator);
				sValue = sValue.substring(iSeparator+1);
			}

			oField =  document.getElementById(sFieldName);

			if( oField )
			{
				if( oField.type == "text" )
				{
					oField.value = sValue;
				}
				else if( oField.type == "select" 
					|| oField.type == "select-one" 
					|| oField.type == "select-multiple" )
				{
					for(iSelIndex = 0; iSelIndex < oField.options.length; iSelIndex++)
					{
						if( oField.options[iSelIndex].value == sValue )
						{
							oField.selectedIndex = iSelIndex;
						}
					}
				}
			}
		}
	}
}

function SetAlertText(lblAlert, sReply)
{
	if( lblAlert) lblAlert.innerHTML = sReply;
}

function ServerError(message)
{
   //alert('An error occurred on the server:\n' + message);
}
