
/*
Validate email
*/
function EmailValid(mailfield) {
   var emailPat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
   var matchArray = mailfield.match(emailPat);

   if (matchArray == null) {
   	  return 0;
		}
   else {
        return 1;
        }
    }
	
/*
function: CheckEmailValue
Purpose: Validate emailaddress
*/
function CheckEmailValue(stringVal, allowEmpty, MaxLen, fieldName) {
	if ( (allowEmpty!=false) && (allowEmpty!=true) ) { allowEmpty = true; }
	
	if (stringVal.length==0) {
		if (!allowEmpty) { 
			return "\nPlease fill in a value for '" + fieldName + "'"; }
		else {
			return '';
			}
		}
	else {
		if ((!isNaN(MaxLen)) && (MaxLen!=0) && (stringVal.length > MaxLen)) {
			return "\nThe text for '" +fieldName + "' is to long."
			}
		if (!EmailValid(stringVal)) {
			return "\n'" + stringVal+ "'is not a valid emailaddress.";;
			}
		}
	return '';
	}

/*
function: CheckStringValue
Purpose: Validate string
*/
function CheckStringValue(stringVal, allowEmpty, MaxLen, fieldName, testDoubleQuote) {
	if ( (allowEmpty!=false) && (allowEmpty!=true) ) { allowEmpty = true; }
	if (testDoubleQuote=="") {testDoubleQuote = false; }

	if (stringVal.length==0) {
		if (!allowEmpty) { 
			return "\nPlease fill in a value for '" + fieldName + "'"; }
		else {
			return '';
			}
		}
	else {
		if ((testDoubleQuote) && (stringVal.indexOf("\"")!=-1)) {
			return "\nPlease don't use a double quote (\") in '" +fieldName + "'."
			}
		if ((!isNaN(MaxLen))	&& (MaxLen!=0) && (stringVal.length > MaxLen)) {
			return "\nThe text for '" +fieldName + "' is to long."
			}
		}
		
	return '';
	}

	
/*
function: CheckintegerValue
Purpose: Validate integer value
*/
function CheckIntegerValue( integerVal, allowEmpty, MinVal, MaxVal, fieldName) {
	if ( (allowEmpty!=false) && (allowEmpty!=true) ) { allowEmpty = true; }

	if (integerVal.length==0) {
		if (!allowEmpty) { 
			return "\nPlease fill in a value for '" + fieldName + "'"; }
		else {
			return '';
			}
		}
	else {
		if (!isNaN(MinVal)) {
			if (parseInt(integerVal) < parseInt(MinVal)) {
				return "\nThe value for '" +fieldName + "' is below the minimum of "+ MinVal +".\nPlease try again.";
				}
			}
		if (!isNaN(MaxVal)) {
			if (parseInt(integerVal) > parseInt(MaxVal)) {
				return "\nThe value for '" +fieldName + "' is above the maximum of "+ MaxVal +".\nPlease try again.";
				}
			}
		}
		
	return '';
	}


	
/*
function: CheckintegerValue
Purpose: Validate integer value
*/
function CheckSelectbox(integerVal,fieldName) {

	if ((integerVal.length==0) || (integerVal==0)) {
		return "\nPlease select an option for '" + fieldName + "'"; 
		}

	return '';
	}


