/*
function to validate minimum and maximum length of a string
example: validateMinMaxLength('test', 4, 12)
would return true
validateMinMaxLength('a', 2,3)
would return false
@author chandan
*/
function validateMinMaxLength(/*String*/ txt, /*int*/ minLen, /*int*/ maxLen) {
	if (txt.length < minLen || txt.length >maxLen) {
		return false;
	}
	return true;
}
/*
function to validate if given word has text
example: validateHasSpace ('chandan kumar')
would return true
validateHasSpace ('noSpace')
would return false
@author chandan
*/
function validateHasSpace(/*String*/ txt) {
	re = new RegExp(" ");
	return re.test(txt);
}
/*
function which validates if given GiiWord is valid or not
'errorMessage' reference should be in global type if you would
like reference to error message
@author chandan
*/
function isValidGiiWord(txt) {
	valid = validateMinMaxLength(txt, 4, 12);
	if (!valid) {
		errorMessage = "Enter word length between 4 to 12 chars";
	} else if (!isAlphaNumeric(txt)){
		errorMessage = "GiiWords should contain only numbers and letters";
		return false;
	} else if (validateHasSpace(txt)){
		errorMessage = "GiiWords should not have blank spaces";
		return false;
	}
	return valid;
}
/*
function which validates if given GiiWord is valid or not
'errorMessage' reference should be in global type if you would
like reference to error message
@author chandan
*/
function isValidSimpleGogii(txt) {
	valid = validateMinMaxLength(txt, 3, 12);
	if (!valid) {
		errorMessage = "Enter word length between 4 to 12 chars";
	} else if (!isAlphaNumeric(txt)){
		errorMessage = "GiiWords should contain only numbers and letters";
		return false;
	} else if (validateHasSpace(txt)){
		errorMessage = "GiiWord should not have blank space";
		return false;
	}
	return valid;
}
/*
NOTE: Introducing this function as change request states
Giiwords can be of infinite length
function which validates if given GiiWord is valid or not
'errorMessage' reference should be in global type if you would
like reference to error message
@author chandan
*/
function isValidGiiWord2(txt) {
	valid = validateMinMaxLength(txt, 4, 30);
	if (!valid) {
		errorMessage = "Enter a word length between 4 to 30 characters";
	} else if (!isAlphaNumeric(txt)){
		errorMessage = "GiiWords should contain only numbers and letters";
		return false;
	} else if (validateHasSpace(txt)){
		errorMessage = "GiiWord should not have blank space";
		return false;
	}
	return valid;
}
function isAlphaNumeric(txt) {
	re = /^[0-9A-Za-z]+$/; //^[a-zA-z]+$/;
	return re.test(txt);
}
function isValidZip(txt) {
	re=/[0-9][0-9][0-9][0-9][0-9]/;
	return re.test(txt);
}