// ----------------------------------------------------------------------------
// Check fax.
// ----------------------------------------------------------------------------
function CheckFax(strForm, strFaxAreaCode, strFax)
{
	var form = eval("document." + strForm + ";");
	var varFaxAreaCode = eval("form." + strFaxAreaCode + ".value;");
	var varFax = eval("form." + strFax + ".value;");
	if ((varFaxAreaCode != "") && (varFax == ""))
		return false;
	else
		return true;
}

// ----------------------------------------------------------------------------
// Check selection.
// ----------------------------------------------------------------------------
function CheckSelection(strForm, strSelectionValue, strOperator, strValue)
{
	var form = eval("document." + strForm + ";");
	var varSelectedValue = eval("form." + strSelectionValue + ".options[form." + strSelectionValue + ".selectedIndex].value;");
	var blnResult = eval("varSelectedValue " + strOperator + " strValue;");
	return blnResult;
}

// ----------------------------------------------------------------------------
// Get file extension from input file type.
// ----------------------------------------------------------------------------
function GetFileExtension(strForm, strFileControl)
{
	var objFileInput = eval("document." + strForm + "." + strFileControl);

	var strFullPathFilename = new String(objFileInput.value);
	var arrTemp = new Array;
	arrTemp = strFullPathFilename.split("\\");

	var strFilename = arrTemp[arrTemp.length - 1];
	var strFilenameTemp = new String(strFilename);
	var arrFile = new Array;
	arrFile = strFilenameTemp.split(".");
	
	return arrFile[arrFile.length - 1];
}

// ----------------------------------------------------------------------------
// Compare file against list of banned extensions.
// ----------------------------------------------------------------------------
function CheckExtension(strForm, strFileControl)
{
	var strBannedExtension = new String("bat,exe,dll,asp,cfm,vbs,ini,sys,cab,asa");
	var arrBannedExtension = new Array;
	arrBannedExtension = strBannedExtension.split(",");

	var strFileExtension = GetFileExtension(strForm, strFileControl);
	var blnResult = true;

	for (var i = 0; i < arrBannedExtension.length; ++i)
	{
		if (strFileExtension == arrBannedExtension[i])
		{
			alert("Cannot upload file with extension (" + arrBannedExtension[i] + ").");
			blnResult = false;
			break;
		}
	}
	return blnResult;
}

// ----------------------------------------------------------------------------
// Check credit card number.
// ----------------------------------------------------------------------------
function CheckCreditCard(strForm, strCreditCard)
{
	var objForm = eval("document." + strForm);
	var strCreditCardValue = eval("objForm." + strCreditCard + ".value");
	var white_space = " -";
	var creditcard_string="";
	var check_char;

	if (strCreditCardValue.length == 0)
		return true;

	// squish out the white space
	for (var i = 0; i < strCreditCardValue.length; i++)
	{
		check_char = white_space.indexOf(strCreditCardValue.charAt(i))
		if (check_char < 0)
			creditcard_string += strCreditCardValue.substring(i, (i + 1));
	}

	// if all white space return error
	if (creditcard_string.length == 0)
		return false;

	// make sure number is a valid integer
	if (creditcard_string.charAt(0) == "+")
		return false;

	if (!_IsInteger(creditcard_string))
		return false;

	// now check mod10
	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i))

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
			{
				checkdigit++;
			}

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}       
	return (checkdigit % 10) == 0 ? true : false;
}

// ----------------------------------------------------------------------------
// Open a pop up window for displaying messages.
// ----------------------------------------------------------------------------
function OpenWindow(strPage)
{
	window.open(strPage, '', 'status=no,resizable=yes,width=400,height=300,menubar=no,toolbar=no,scrollbars=yes,alwaysRaised=yes');
}