//
// Included by a classified page gate.
//
// Expects:
//
// . msgBlankCode - message when code is blank.
// . msgInvalidCode = message for invalid code.
// . codeCookieName = name of cookie storing the code.
// . codeVal = input code value
// . baseName = classified file base name. full name is: <code><base name>.html
//

function GoToClassifiedPage(fileLib)
{
    codeVal = document.getElementById('code').value;

    if (codeVal == '')
    {
        document.getElementById('msg').innerHTML = msgBlankCode;
        document.getElementById('msg').style.display = 'inline';
        t = setTimeout("document.getElementById('msg').style.display = 'none'", 2.5 * 1000);
    }
    
    else
    {
        //document.getElementById('button').style.display = 'none';
        //document.getElementById('iconServer').style.display = 'inline';
        //SimpleAjax("ChkClassifyCode", fileLib+codeVal);
        createCookie(codeCookieName, codeVal, 365); // 365 days.
        location.href = codeVal+baseName+'.htm';
    }
}


//
// Checks classified page code.
//
function CheckClassifyCode()
{    
    var f = document.forms['FormClsPage'];
    var code = f.code.value;

    //
    // Case error - blank input code.
    //
    if (code == '')
    {
        $('#msg').html(msgBlankCode);
        $('#msg').show();
        return;
    }

    //
    // Switch button.
    //
    Hide('button');
    ShowInline('iconServer');
    
    //
    // Call ajax.
    //
    $.ajax(
    {
        type: "GET",
        dataType: "script",
        url: 'http://isether.com/ips/mod/site/ajax.php',
        data: 'action=ChkClassifyCode&catId='+catId+'&code='+code+'&sid='+siteId,
        
        success: function(msg)
        {
            msg;
        },
        
        error: function (XMLHttpRequest, textStatus, errorThrown) 
        {
            alert('ajax failed');
        }

    });
    
    //
    // Return false.
    //
    return false;

}

function FinishCheckClassifyCode(isCodeOk, code)
{    
    ShowInline('button');
    Hide('iconServer');
    
    if (isCodeOk)
    {
        createCookie(codeCookieName, code, 365); // 365 days.
        location.href = code + baseName + '.htm';
    }

    else
    {
        $('#msg').html(msgInvalidCode);
        $('#msg').show();
    }
}
