var URL_PATTERN   = "^(http\\:\\/\\/)?([a-z0-9]+([-a-z0-9+]+[0-9a-z])?\\\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobile)(\\/?|\\/.*)$";
var EMAIL_PATTERN = "^[-a-z_][-0-9a-z_\.]*@([a-z0-9]+(\-+[a-z0-9]+)?\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobile)$";


function b(obj, flag)
{
    if (!obj) return;

    if (flag) 
        obj.style.fontSize = '18px';
    else 
        obj.style.fontSize = '14px';
}

function do_click(link_id)
{
    var req = new JsHttpRequest();
    
    req.open('GET', 'go.php', false);
    req.send( { id:link_id} );

    return true;
}


function setStyle(id, type1, e)
{
    if (e)
        if (type1)
            document.getElementById(id).className = 'correct_field';
        else
            document.getElementById(id).className = 'correct_field_2';
    else
        if (type1)
            document.getElementById(id).className = 'error_field';
        else
            document.getElementById(id).className = 'error_field_2';

}

function checkUrl(id, type1)
{
    var v = new FormValidator();
    var e = v.MatchRegexp([id, URL_PATTERN, "i"]);

    setStyle(id, type1, e)

    return e;
}

function checkNotEmpty(id, type1)
{
    var v = new FormValidator();
    var e = v.NotEmptyField([id]);

    setStyle(id, type1, e)

    return e;
}

function checkEmail(id, type1)
{
    var v = new FormValidator();
    var e = v.MatchRegexp([id, EMAIL_PATTERN, "i"]);

    setStyle(id, type1, e)

    return e;
}


function checkCp(id, type1)
{
    if (!document.getElementById(id)) false;
  
    var req = new JsHttpRequest();
    var ACp = document.getElementById(id).value;

    req.onreadystatechange = function()
    {
        if (4 == req.readyState)
        {
            setStyle(id, type1, 'OK' == req.responseJS.status);
        }
    }

    document.getElementById(id).className = 'loading_field';
    req.open('GET', 'cp.php', true);
    req.send( {cp:ACp} );
}

function checkPwL(id, type1)
{
    var v = new FormValidator();
    var e = v.NotEmptyField([id]);

    setStyle(id, type1, e);

    return e;
}

function checkPwR(id, type1)
{
    var v = new FormValidator();
    var e = v.LongerOrEqual([id, MIN_PASSWORD_LEN]);

    setStyle(id, type1, e);

    return e;
}

function checkEq(id1, id2, type1)
{
    var v = new FormValidator();
    var e = checkPwR(id2, type1) && v.IsEqual([id1, id2]);

    setStyle(id1, type1, e);

    return e;
}
