function GetCookieValue(cookieName) {
    thisCookie = document.cookie.split("; ")
    for (i = 0; i < thisCookie.length; i++) {
        if (cookieName == thisCookie[i].split("=")[0]) {
		if(thisCookie[i].indexOf("=")>0)
	            return thisCookie[i].split("=")[1];
		else
			return 0;
        }
    }
    return 0;
}

var errorFound = false;

function error(elem, text)
{
	if(errorFound) return;

	window.alert(text);
	elem.focus();
	errorFound = true;
}

function CheckField(){
	errorFound = false;
	var message = CheckEmailAddress(document.jobalert.EMAIL.value);	
	if(message.indexOf("Invalid")>=0)
		error(document.jobalert.EMAIL, message);
	return !errorFound;
}

function CheckEmailAddress(address){
	// The Field Shouldn't be Empty
	address = trim(address);
	if (address == "") {
		return "Invalid email address: empty address";
	}

	// Check For Bad Chars
	badchar = " ()<>\/[]{}+*|;,"
	for (i=0;i<address.length;i++) {
		for (j=0;j<badchar.length;j++) {
			if (address.charAt(i) == badchar.charAt(j)) {
				return "Invalid email address '" + address + "': there is an invalid character or a space in the email address";
			}
		}
	}

	// There Should Be a dot (.) Symbol
	if (address.indexOf(".") == -1) {
		return "Invalid email address '" + address + "': does not have any dot(.) symbol";
	}

	// There Should Be an @ Symbol
	if (address.indexOf("@") == -1) {
		return "Invalid email address '" + address + "': does not have any @ symbol";
	}
	else {
	// Only one @ symbol should be found
		symbolfound = 0
		for (i=0;i<address.length;i++) {
			if (address.charAt(i) == "@") {
				symbolfound++
			}
			else {
				continue
			}
		}
		if (symbolfound != 1) {
			return "Invalid email address '" + address + "': more than one @ symbol";
		}
	}

	// Check For Syntax Errors Such as .@  or   @.  or  ..
	if (address.indexOf("@.") != -1 || address.indexOf(".@") != -1 || address.indexOf("..") != -1) {
		return "Invalid email address '" + address + "': two symbol side by side";
	}

	// The first character shouldn't be @ or .
	if (address.charAt(0) == "@" || address.charAt(0) == ".") {
		return "Invalid email address '" + address + "': first character seem is . or @";
	}

	// The last character shouldn't be @ or .
	if (address.charAt(address.length-1) == "@" || address.charAt(address.length-1) == ".") {
		return "Invalid email address '" + address + "': last character is . or @";
	}

	return "OK";
}

function trim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function PageLoad(){

}

