function bValidAddressInfo(frm)
{
	var n;
	var sCountry;
	var sStateCode;

	if(frm.Prefix.selectedIndex == -1)
	{
		alert("Please select the prefix.");
		frm.Prefix.focus();
		return false;
	}
	if(bIsBlank(frm.FirstName.value))
	{
		alert("Please enter your first name.");
		frm.FirstName.focus();
		return false;
	}

	if(bIsBlank(frm.LastName.value))
	{
		alert("Please enter your last name.");
		frm.LastName.focus();
		return false;
	}


	if(bIsBlank(frm.Title.value))
	{
		alert("Please enter your title.");
		frm.Title.focus();
		return false;
	}

	if(bIsBlank(frm.Company.value))
	{
		alert("Please enter your company name.");
		frm.Company.focus();
		return false;
	}


	if(bIsBlank(frm.Address1.value))
	{
		alert("Please enter your address.");
		frm.Address1.focus();
		return false;
	}

	if(bIsBlank(frm.City.value))
	{
		alert("Please enter the city.");
		frm.City.focus();
		return false;
	}

	n = frm.Country.selectedIndex;
	if(n == -1)
	{
		alert("Please enter the Country.");
		frm.Country.focus();
		return false;
	}
	else sCountry = frm.Country.options[n].text;

// alert('state');
	if(bIsBlank(frm.State.value) && (sCountry == "United States" || sCountry == "Canada"))
	{
		alert("Please enter the State/Province.");
		frm.State.focus();
		return false;
	}

// alert('postal');

	if(bIsBlank(frm.PostalCode.value) && (sCountry == "United States" || sCountry == "Canada"))
	{
		alert("Please enter the Postal/Zip code.");
		frm.PostalCode.focus();
		return false;
	}

	if(bIsBlank(frm.Phone.value))
	{
		alert("Please enter your telephone number.");
		frm.Phone.focus();
		return false;
	}
	else
	{
		if(frm.Phone.value.length < 10)
		{
			alert("Please enter your complete telephone number with the area code.");
			frm.Phone.focus();
			return false;
		}
	}

	if(!bValidEmailAddress(frm.Email.value))
	{
		alert("Please enter a valid e-mail address for yourself.");
		frm.Email.focus();
		return false;
	}

	if(!bValidEmailAddress(frm.Email2.value))
	{
		alert("Please confirm you e-mail address by entering it again.");
		frm.Email2.focus();
		return false;
	}

	if(frm.Email.value != frm.Email2.value)
	{
		alert("Your e-mail addresses do not match.");
		frm.Email.focus();
		return false;
	}

	return true;
}


function bValidCreditCardInfo(frm)
{
	var sCountry;
	var sStateCode;

	if(frm.CreditCard.selectedIndex == -1)
	{
		alert("Please select a credit card.");
		frm.CreditCard.focus();
		return false;
	}

	if(frm.ExpirationMonth.selectedIndex == -1)
	{
		alert("Please select the expiration month.");
		frm.ExpirationMonth.focus();
		return false;
	}


	if(frm.ExpirationYear.selectedIndex == -1)
	{
		alert("Please select the expiration year.");
		frm.ExpirationYear.focus();
		return false;
	}

	if(bIsBlank(frm.Name.value))
	{
		alert("Please enter the name on the credit card.");
		frm.Name.focus();
		return false;
	}

	if(bIsBlank(frm.CCNumber.value))
	{
		alert("Please enter a valid credit card number.");
		frm.CCNumber.focus();
		return false;
	}

	if(bIsBlank(frm.BillingAddress.value))
	{
		alert("Please enter your billing address.");
		frm.BillingAddress.focus();
		return false;
	}


	if(bIsBlank(frm.BillingCity.value))
	{
		alert("Please enter your billing city.");
		frm.BillingCity.focus();
		return false;
	}

	if(frm.BillingState.selectedIndex == -1)
	{
		alert("Please select your billing state/province.");
		frm.BillingState.focus();
		return false;
	}

	sCountry = frm.BillingCountry.options[frm.BillingCountry.selectedIndex].text;
	sStateCode = frm.BillingState.options[frm.BillingState.selectedIndex].value;

	if((sCountry == "United States" || sCountry == "Canada") && sStateCode == "ZZ")
	{
		alert("Please select the correct billing state/province.");
		frm.BillingState.focus();
		return false;
	}

	if(bIsBlank(frm.BillingZipCode.value) && (sCountry == "United States" || sCountry == "Canada"))
	{
		alert("Please enter your billing Postal/Zip Code.");
		frm.BillingZipCode.focus();
		return false;
	}

	return true;
}

function bIsBlank(sText)
{
	var i;
	var bStatus;

	bStatus = true;

	for(i = 0; i < sText.length; ++i)
	{
		if(sText.charAt(i) != " ")
		{
			bStatus = false;
			break;
		}
	}

	return bStatus;
}
// @Sun Lee
function IsNumeric(strString)
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	 {
	   strChar = strString.charAt(i);
	   if (strValidChars.indexOf(strChar) == -1)
	   {
	      blnResult = false;
	   }
	}
	return blnResult;
}
// @Sun Lee
function isFloat (s)

{   if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    return reFloat.test(s)
}
function sFixNumber(sText)
{
	var i;
	var sTemp;
	var c;
	var sNumbers;

	sTemp = "";
	sNumbers = "0123456789.";

	for(i = 0; i < sText.length; ++i)
	{
		c = sText.charAt(i);
		if(sNumbers.indexOf(c) >= 0) sTemp = sTemp + c;
	}
	
	if(sTemp == "") sTemp = "0"

	return sTemp;
}


function bValidEmailAddress(sEmail)
{

//	Match one or more non-whitespace characters followed by the @ sign followed by one or more
//	non-whitespace characters followed by a period (.) followed by one or more non-whitespace
//	characters.

	return sEmail.search(/\S+@\S+\.\S+/) != -1;
}

function bValidMoney(sMoney)
{
	return parseFloat(sMoney) >= 1.50;
}

function DisplayCompanies(sWriteBackDoc)
{
	var sDocument;
	var sSearch;

	sSearch = sLTrim(document.RegForm.Company.value);

	if(sSearch == "") alert("Please enter the first part of the company name.");
	else
	{
		sDocument = "http://nrfweb.nrf.com/display.asp?name=" + sURLEncode(sSearch);
		sDocument = sDocument + "&page=" + sWriteBackDoc;

		SearchPopUp(sDocument, 650, 300);
	}
}

function SearchPopUp(sDocument, width, height)
{
	var x, y, win, sFeatures;

	x = (screen.width - width - 22)/2 - 100;
	y = (screen.height - height)/2 - 100;

	sFeatures = "width=" + width + ",height=" + height + ",toolbar=0,menubar=0,scrollbars=0,resizable=0,"
	sFeatures = sFeatures + "location=0,directories=0,status=0,left=" + x + ",top=" + y;
	sFeatures = sFeatures + ",screenX=" + x + ",screenY=" + y;

	win = window.open(sDocument, "PopUp", sFeatures);

	if (!win.opener) win.opener = self;
	win.focus();

	return;
}

function sURLEncode(sString)
{
	var i, n, x, y, sTemp, sHexchars, iBase;

	sTemp = "";
	sHexchars = "0123456789ABCDEF";
	iBase = sHexchars.length;

	for(i = 0; i < sString.length; ++i)
	{
		n = sString.charCodeAt(i);
		x = Math.floor(n / iBase);
		y = n - (x * iBase);

		sTemp = sTemp + "%" + sHexchars.charAt(x) + sHexchars.charAt(y);
	}

	return sTemp;
}

function sLTrim(sString)
{
	var i, sTemp, c, bBlank;

	sTemp = "";
	bBlank = 1;

	for(i = 0; i < sString.length; ++i)
	{
		c = sString.charAt(i);
		if(c != " " || bBlank == 0)
		{
			sTemp = sTemp + c;
			bBlank = 0;
		}
	}

	return sTemp;
}



function sFormatCurrency(x)
{
	var sText;

	sText = '$' + x;
	if(sText.search(/\.\d\d/) == -1)
	{
		if(sText.search(/\.\d/) == -1) sText = sText + '.00';
		else sText = sText + '0';
	}

	return sText;
}

function OpenNewWindow(sFile, sName, width, height, scrollbar)
{
	x = (screen.width - width - 22)/2;
	y = (screen.height - height)/2 - 50;
	x = screen.width - width - 50;
	y = screen.height -height - 100;
  	
	win = window.open(sFile, sName, "width=" + width + ",height=" + height + 
  		", toolbar=0,menubar=0,scrollbars=" + scrollbar + ",resizable=0,location=0,directories=0,status=0,left=" +
		x + ",top=" + y);

	return;
}


function changeImage(image, sDocument)
{
	image.src = sDocument;
	return true;
}
function isInteger(str)
{
	var new_msg = "true"
	inputStr = str.toString()
	for (var i = 0; i < inputStr.length; i++)
		{
			var oneChar = inputStr.charAt(i)			
			if (oneChar >= "0" && oneChar <= "9" )
				;
			else
				return false;
		}
	return true;
}
