function ClearAllInputFields(ThisForm) {
	for (i = 0; i < ThisForm.elements.length; i++) {
		if (ThisForm.elements[i].type == "text" || ThisForm.elements[i].type == "file" || ThisForm.elements[i].type == "password") {
			ThisForm.elements[i].value = "";
		}
	}
}

function TrimAllTextFields(ThisForm) {
	for (i = 0; i < ThisForm.elements.length; i++) {
		if (ThisForm.elements[i].type == "text" || ThisForm.elements[i].type == "file") {
			ThisForm.elements[i].value = trim(ThisForm.elements[i].value);
		}
	}
}

function trim(str) {
	// We don't want to trim JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	var i, j;

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		i = s.length - 1;		 // Get length of string
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		s = s.substring(0, i+1);
	}

	j = s.length;

	if (j > 1 && whitespace.indexOf(s.charAt(0)) != -1) {
		i = 0;		 // Get length of string
		while (i < j && whitespace.indexOf(s.charAt(i)) != -1)
			i++;
		s = s.substring(i, j);
	}

	return s;
}

//var emailPattern = /^\w+((-\w+)|(\.\w+)|(\/\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,12}$/
var emailPattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
//var emailListPattern = /^\w+((-\w+)|(\.\w+)|(\/\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,12}+([,.]\w+((-\w+)|(\.\w+)|(\/\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,12}+)*$/
var emailListPattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$/

function checkPattern(value, pattern) {
	if ( value.search(pattern) != -1 )
		return true;
	else
		return false;
}

function checkEmail(value) {
	return checkPattern(value, emailPattern);
}

function checkEmailList(value) {
	return checkPattern(value, emailListPattern);
}

function beautifyEmailList(value) {
	var temp = value;
	temp = trim(temp);
	temp = temp.replace(/\s+/g, " ")
	temp = temp.replace(/\s*;\s*/g, ";")
	temp = temp.replace(/\s+/g, ";")
	return temp;
}