var formErrorMsg;

function validateNumericMandatory(testValue, fieldName)
{
	if (!NumericTestProc(testValue)) {
		formErrorMsg += "- " + fieldName + " must be a number\n";
		return true;
	}

	return false;

}

function NumericTestProc(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  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;
   }

function validateCCDate(ccexpmonth, ccexpyear, fieldName) {

	var todayDate = new Date();
	var testTodayDate = ('' + todayDate.getFullYear()) + ('' + Right('0' + (todayDate.getMonth() + 1), 2));
	var testInputDate = Right('0000' + ccexpyear, 4) + Right('0' + ccexpmonth, 2);
	
	
	//alert("today = " + testTodayDate + " input = " + testInputDate);
	if(testTodayDate > testInputDate) {
		formErrorMsg += "- " + fieldName + " is not valid.\n";
	}

}
function validateCCType(testString, cardType, fieldName)
{
	//alert(testString.charAt(0) + ' ' + cardType + fieldName)
	if (testString.charAt(0) == '3' && cardType != 'AMEX') {
		formErrorMsg = "- " + fieldName + " is not correct for card type\n";
	}
	if (testString.charAt(0) == '4' && cardType != 'VISA') {
		formErrorMsg = "- " + fieldName + " is not correct for card type\n";
	}
	if (testString.charAt(0) == '5' && cardType != 'MC') {
		formErrorMsg = "- " + fieldName + " is not correct for card type\n";
	}
	if (testString.charAt(0) == '6' && cardType != 'DISC') {
		formErrorMsg = "- " + fieldName + " is not correct for card type\n";
	}

}

function validateCCNumber(testString, fieldName) {


	if (testString == "") {
		formErrorMsg += "- " + fieldName + " must be filled in\n";
	}
	
}
function validateOther(otherString, testString, fieldName)
{
	if (otherString == "Other" && testString == "") {
		formErrorMsg += "- " + fieldName + " must be filled in\n";
		return true;
	}

	return false;

}

function validateFieldNotEmpty(testString, fieldName)
{
	if (testString == "") {
		formErrorMsg += "- " + fieldName + " must be filled in\n";
		return true;
	}

	return false;

}

function validateFileFieldNotEmpty(testString, fieldName)
{
	if (testString == "") {
		formErrorMsg += "- " + fieldName + " must be selected\n";
		return true;
	}

	return false;

}

function validateFileExtension(testString, fieldName, extension) {

	var thisext = testString.substr(testString.lastIndexOf('.'));
	for(var i = 0; i < extension.length; i++) {
		if(thisext == extension[i]) {
			return true;
		}
	}
	formErrorMsg += "- " + fieldName + " must be a filetype "
	for(var i = 0; i < extension.length; i++) {
		formErrorMsg += extension[i] + " "
	}
	formErrorMsg += "\n";
	return false;
}

function validateNumeric(testValue, fieldName)
{
	if (testValue != "") {
		if (!NumericTestProc(testValue)) {
			formErrorMsg += "- " + fieldName + " must be a number\n";
			return true;
		}
	}
	return false;

}

function validateCheckboxChecked(testValue, fieldName)
{
	if (testValue != true) {
		formErrorMsg += "- " + fieldName + " must be checked\n";
		return true;
	}

	return false;

}

function validateCompareFields(testString1, testString2, fieldName)
{
	if (testString1 != testString2) {
		return ("- Both " + fieldName + " fields must match\n");
	} else {
	        return ("");
	}
}

function validateEmailField(testEmail1, testEmail2, fieldName) {

	if (testEmail1 == "") {
		formErrorMsg += '- ' + fieldName + ' must be a valid email address ("yourname@domain.com") \n';
		return true;
	}
		
	if (testEmail1.indexOf(".") > 2 && testEmail1.indexOf("@") > 0) {
	} else {
		formErrorMsg += '- ' + fieldName + ' must be a valid email address ("yourname@domain.com") \n';
		return true;
	}

	if (testEmail1 != testEmail2) {
		formErrorMsg += '- Both Email fields must match \n';
		return true;
	}
	
	return false;
		
}

function validatePasswordField(testPassword1, testPassword2, fieldName) {

	if (testPassword1 == "") {
		formErrorMsg += "- " + fieldName + " must be filled in\n";
		return true;
	}
		
	/*if (testPassword1.indexOf(".") > 2 && testPassword1.indexOf("@") > 0) {
	} else {
		formErrorMsg += "- " + fieldName + " must conain at least 1 number\n";
		return true;
	}*/

	if (testPassword1 != testPassword2) {
		formErrorMsg += '- Both Password fields must match \n';
		return true;
	}
	
	return false;
		
}


