//Constant value defined for the whitespace
var whitespace = " \t\n\r";

//The function sets the cookie with name as name , value as value and 
//expiry time as expire (Defined by the user)
function setCookie(name, value, expire) {
    document.cookie = name + "=" + escape(value) + ";expires=" + expire.toGMTString();
}

//Gets the value of the specified cookie.
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//The function reads the cookies set in aganst the name and value
//entered
function readCookie() {
    // valid if cookie 'iefc-registration' has value 'tempcookie'
    if (getCookie('iefc-registration') == 'tempcookie') {
        return true;
    }

    return false;
}

//The function checks the structure validity of the email ID's
function isEmail(val) {
    if (isEmpty(val)) 
        if (isEmail.arguments.length == 1) 
            return defaultEmptyOK;
        else 
            return (isEmail.arguments[1] == true);
    //Is val whitespace?
    if(isWhitespace(val))
        return false;
    //There must be >= 1 character before @, so we start looking at 
    //character position 1 (i.e. second character)
    var i = 1;
    var sLength = val.length;

    //Look for @
    while ((i < sLength) && (val.charAt(i) != "@")) {
        i++
    }

    if ((i >= sLength) || (val.charAt(i) != "@")) 
        return false;
    else
        i += 2;

    //Look for .
    while ((i < sLength) && (val.charAt(i) != ".")) {
        i++
    }

    //There must be at least one character after the .
    if ((i >= sLength - 1) || (val.charAt(i) != ".")) 
        return false;
    else 
        return true;
}

//This function checks if the value is a space
function isWhitespace(val) {
    var i;
    //Is val empty?
    if (isEmpty(val)) 
        return true;
    //Search through string's characters one by one until we find a 
    //non-whitespace character. When we do, return false; if we don't,
    //return true.
    for (i = 0; i < val.length; i++) {   
        //Check that current character isn't whitespace.
        var c = val.charAt(i);
        if (whitespace.indexOf(c) == -1) 
            return false;
    }
    //All characters are whitespace.
    return true;
}

//This fucntion checks if the value is empty
function isEmpty(val) { 
    return ((val == null) || (val.length == 0))
}