var whitespace = " \t\n\r";

function isEmpty(s)
{   
    return ((s == null) || (s.length == 0));
}

function isWhitespace(s)
{
    var i;

    if (isEmpty(s)) 
        return true;
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) 
            return false;
    }
    return true;
}

function isDigit (c)
{   
    return ((c >= "0") && (c <= "9"));
}

function isInteger (s)
{   
    var i;

    if (isEmpty(s)) {
        if (isInteger.arguments.length == 1) {
            return defaultEmptyOK;
        } else {
            return (isInteger.arguments[1] == true);
        }
    }
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (!isDigit(c)) {
            return false;
        }
    }
    return true;
}

function isEmail(s)
{   
    if (isEmpty(s))  {
        if (isEmail.arguments.length == 1) {
            return false;
        } else {
            return (isEmail.arguments[1] == true);
        }
    }
            
    if (isWhitespace(s)) return false;

    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@")) { 
        i++;
    }

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

    while ((i < sLength) && (s.charAt(i) != ".")) {
        i++;
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
        return false;
    else 
        return true;
}

var IE4 = (document.all ? 1 : 0)


function check_form_anonymous(form)
{
    if (isEmpty(addform.Title.value)) {
        addform.Title.focus();
        alert("Please, fill in the Title of the link");
    } else if (isEmpty(addform.Description.value)) {
        addform.Description.focus();
        alert("Please fill in the Description of the link");
    } else if (isEmpty(addform.Contact_Name.value)) {
        addform.Contact_Name.focus();
        alert("Please fill in Contact Name");
    } else if (!isEmail(addform.Contact_Email.value)) {
        addform.Contact_Email.focus();
        alert("Please fill in Contact Email");
    } else if (isEmpty(addform.back_url.value)) {
        addform.back_url.focus();
        alert("Please fill in The URL where you linked to us");
    } else {
        return true;
    }
    return false;
}
