function carLogin()
{
    var car = $("#car").val();
    var password = $("#password").val();
	
    if(car == "" || password=="")
    {
        alert("Please enter login!");
        return;
    }
	
    $.post("login.php",
        "car="+car+"&password="+password,
        function(data){
            if(data=="ERROR")
            {
                alert("Login incorrect");
                return;
            }
            $('#content').text('');
            $('#content').load('page_challenge.php',"id=online",function (responseText, textStatus, XMLHttpRequest) {
                $(this).removeClass('ajax-loading');
                if(responseText.substring(0,3)=="ERR")
                    $('#content').text('');
            }).addClass('ajax-loading');
        },
        "text"
        );
}

function logout()
{
    $.post("logout.php",
        "",
        function(data){
            if(data=="ERROR")
            {
                alert("Error");
                return;
            }
            $('#content').text('');
            $('#content').load('page_challenge.php',"id=online",function (responseText, textStatus, XMLHttpRequest) {
                $(this).removeClass('ajax-loading');
                if(responseText.substring(0,3)=="ERR")
                    $('#content').text('');
            }).addClass('ajax-loading');
        },
        "text"
        );
}

function gotoPage(page)
{
    $('#content').text('');
    $('#content').load('page_challenge.php',"page="+parseInt(page,10),function (responseText, textStatus, XMLHttpRequest) {
        $(this).removeClass('ajax-loading');
        if(responseText.substring(0,3)=="ERR")
            $('#content').text('');
    }).addClass('ajax-loading');
}

function reducePoints() {
    var page = $("#page").val();
    $action = "reducePoints";
    $.post("answer.php",
        "page="+page+"&action="+$action,
        function(data){
            if(data=="ERROR")
            {
                alert("Error!");
                return;
            }
            $('#content').text('');
            $('#content').load('page_challenge.php',"page="+(parseInt(page,10)+1),function (responseText, textStatus, XMLHttpRequest) {
                $(this).removeClass('ajax-loading');
                if(responseText.substring(0,3)=="ERR")
                    $('#content').text('');
            }).addClass('ajax-loading');
        },
        "text"
        );
}

function submitAnswer()
{
    var page = $("#page").val();
    var answer = $("#answer").val();
    $action = "submitAnswer";
	
    if(answer == "")
    {
        alert("Please enter your answer!");
        return;
    }
	
    $.post("answer.php",
        "page="+page+"&answer="+answer+"&action="+$action,
        function(data){
            if(data=="ERROR")
            {
                alert("Error!");
                return;
            }
            if(data=="WRONG") {
                alert("Wrong answer!");
                return;
            }
            $('#content').text('');
            $('#content').load('page_challenge.php',"page="+(parseInt(page,10)+1),function (responseText, textStatus, XMLHttpRequest) {
                $(this).removeClass('ajax-loading');
                if(responseText.substring(0,3)=="ERR")
                    $('#content').text('');
            }).addClass('ajax-loading');
        },
        "text"
        );
}
