
function checkInteger( strVal ) {
  var re  = /(^-?\d\d*$)/;

  //check for integer characters
  return re.test(strValue);
}

function trimBoth(strVal) {

	var re = /^(\s*)([\W\w]*)(\b\s*$)/;

	// check for leading & trailing spaces

	if (re.test(strVal)) {
		strVal = strVal.replace(re, '$2');
	}
	return strVal;
}

function isEmpty(inputStr) {

	inputStr = trimBoth(inputStr);
	if (inputStr==null || inputStr=="") {
		return true;
	}
	return false;
}

function checkPoBox( strVal ) {
	var re = /(^P|^p)(\.?)(\s)?(O|o)(\.?)(\s)?(BOX|box|Box|BOx|BoX|bOX|boX|bOx)/
	varAddr = trimBoth(strVal);
	if (re.test(varAddr.value)) {
		alert("PO Box addresses are not acceptable due to a high incidence of associated fraud.");
		varAddr.focus();
		return false;
	}
	return true;
}

function checkName(varName) {

	var re = /^(([a-zA-Z]){1,}\s)+([a-zA-Z]){2,}$/;
	if (isEmpty(varName.value) == true ) {
		alert("Name : Your name is missing");
		varName.focus();
		return false;
	}
	else if (!re.test(varName.value)) {
		alert("Name : This is not Name format");
		varName.focus();
		return false;
	}
	return true;
}

function checkEmail(varEmail) {
	var re  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]){2,4}$/;
//	var re=/^.+@.+\..{2,4}$/
	
	if (isEmpty(varEmail.value) ==  true){
		alert("Email : E-Mail address is missing.");
		varEmail.focus();
		return false;
	} else if (!re.test(varEmail.value)) {
		alert("Email : Please input a complete and valid email address.\n");
		varEmail.focus();
		return false;	
	}
	return true
}

function checkPhone(varPhone, tObject) {
	var re = /\(?\d{3}\)?\d{3}-\d{4}/;

	varPhone = trimBoth(varPhone);
	if (!re.test(varPhone)) {
		alert("Phone : Please input a valid phone number");
		tObject.focus();
		return false;	
	}
	return true;
}

function checkZip(varZip) {

	var re = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	
	if (!re.test(varZip.value)) {
		alert("ZIP : Please input a valid zip code");
		varZip.focus();
		return false;
	}
	return true;
}

function checkCredit(varCredit) {
	var re = /\d{15}/;

	if (!re.test(varCredit.value)) {
		alert("CreditCard : Please input a valid creditcard number");
		varCredit.focus();
		return false;
	}
	return true;
}