// General functions for post processing of forms

function PostCheckNumber(number,target){

	// assume number is valid

	valid = true;

	number = String(number);



	// make sure it only contains numbers

	for(i = 0 ; i < number.length ; i++){

		c = number.charCodeAt(i);

		if(c < 48 || c > 57) valid = false;

	}



	//return result

    return(valid);

}



function PostCheckText(txt,target){

	// assume text is valid

	valid = true;

	txt = String(txt);

	txt = txt.toUpperCase();



	// make sure it only contains text

	for(i = 0 ; i < txt.length ; i++){

		c = txt.charCodeAt(i);

		if(c != 32 && c != 46 && c != 45 && (c < 65 || c > 90) && (c < 97 || c > 122)) valid = false;

	}



	//return result

    return(valid);

}



function PostCheckEmailaddress(ea){

	// assume address is valid

	valid = true;

	ea = ea.toLowerCase();



	// check email address syntax

	if(ea == null) valid = false;

	else if(ea.indexOf("@") < 2) valid = false;

	else if(ea.indexOf("@") != ea.lastIndexOf("@")) valid = false;

	else if(ea.length - ea.lastIndexOf(".") < 3) valid = false;

	else if(ea.substr(ea.indexOf("@")+1,ea.length-1).indexOf(".") < 2) valid = false;



	// make sure the last set set of chars only contain alpha chars

	s = ea.substr(ea.lastIndexOf(".")+1,ea.length-1);

	for(i = 0 ; i < s.length ; i++){

		if(s.charCodeAt(i) < 97 || s.charCodeAt(i) > 122) valid = false;

	}



	// make sure the chars before the @ are valid (charCodes 33-57,65-90,95,97-122)

	s = ea.substr(0,ea.indexOf("@"));

	for(i = 0 ; i < s.length ; i++){

		c = s.charCodeAt(i);

		if(c == 95 || (c >= 33 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)) ;

		else {

			valid = false;

			break;

		}

	}



	//return result

    return(valid);

}



function PostCheckPostalNumber(number, target){

	// assume number is valid

	valid = true;

	number = String(number);



	// make sure it only contains numbers

	for(i = 0 ; i < number.length ; i++){

		c = number.charCodeAt(i);

		if(c < 48 || c > 57) valid = false;

	}



	//return result

    return(valid);

}



function PostCheckPostalDigit(txt,target){

	// assume digit is valid

	valid = true;

	txt = String(txt);

	txt = txt.toUpperCase();



	// make sure it only contains text

	for(i = 0 ; i < txt.length ; i++){

		c = txt.charCodeAt(i);

		if(c != 32 && (c < 58 || c > 90) &&(c < 33 || c > 46 )) valid = false;

	}



	//return result

    return(valid);

}
