
/**** Only 7bit ANSII character space ****/

function containsSpecialChars(input) {
	var intCharcode;
	for (charIndex = 0; charIndex < input.length ; charIndex++) {
		/*
		Charcodes allowed
		0-9 => 48-57
		A-Z => 65-90
		a-z => 97-122
		*/
		intCharcode = input.charCodeAt(charIndex)
		if (!(
				(intCharcode >= 48 && intCharcode <= 57) ||
				(intCharcode >= 65 && intCharcode <= 90) ||
				(intCharcode >= 97 && intCharcode <= 122) ||
				(intCharcode == 95)
		)) {
			return true;
		}
	}
	return false;
}


/**** E-mail validation ****
Validate the e-mail address (returns true if all ok, else possibly the character that is not allowed or simply false)
*/
function validateEmail(email)
{
	invalidChars = "/:,;£$€{[]}|´!\"#¤%&()=?`½§\\*+'<>^"

	for (i=0; i < invalidChars.length; i++) {
		checkChar = invalidChars.charAt(i)
		if (email.indexOf(checkChar, 0) > - 1) {
			return checkChar;
		}
	}

	onPos = email.indexOf("@", 1);
	if (onPos == -1) {
		return false;
	}

	if (email.indexOf("@", onPos+1) != -1)	{
		return false;
	}	

	dotPos = email.indexOf(".", onPos);
	if (dotPos == -1) {
		return false;
	}

	if (dotPos+3 > email.length) {
		return false;
	}

	return true;
}

/***** textareas have no maxlength property *****/
function limitLength(inputObj, maxsize) {
	if (inputObj.value.length > maxsize) {
		inputObj.value = inputObj.value.substring(0, maxsize);
	}
}
