/* new function for mootools 1.2.4 */

function ajaxPageSearch(divcont, ajax_request, url_param)
{
    var url_request = "";

    if (url_param == null)
        url_request = MY_DOWNLOADS_URL + '/ajax_functions.php';
    else
        url_request = url_param;

    var myRequest = new Request({
        url: url_request,
        method: 'post',
        onRequest: function()
        {
            showPageSearchLoading(divcont);
        },
        onSuccess: function(responseText)
        {
            $$(divcont).set({html: responseText});
            evalLiveScript(responseText);
            removePageSearchLoading(divcont);
        },
        onFailure: function()
        {
            alert("An unexpected error has occured. Please try again.");
            removePageSearchLoading(divcont);
        }
    });
    myRequest.send(ajax_request);
}

function showPageSearchLoading(divcont)
{
    var divLoader = new Element('div', {'id' : 'payment_loader', 'class' : 'page_search_loading'});
    var imageLoader = new Element('img', {'src' : 'https://media01.gameloft.com/layout/default/web/sitenew/images_site/my_account/ajax-loader.gif'});

    mvalues = $$(divcont).getParent().getCoordinates();
    window.scrollTo(mvalues["top"],mvalues["left"]);
    imageLoader.inject(divLoader);
    $$(divcont).grab(divLoader,'bottom');
    $$(divcont).getFirst().set({style: 'display: none;'});
    //$$(divcont).getParent().set({style: 'overflow: hidden'});
}

function removePageSearchLoading(divcont)
{
    //$$('#payment_loader').dispose();
    $$(divcont).getLast().dispose();
    $$(divcont).getFirst().set({style: 'display: visible;'});
    //$$(divcont).getParent().set({style: 'overflow: hidden'});
}
/* end mootools function 1.2.4 */


function ajaxPageSearchRequest(divcont, request_name , addtl_param, url_param)
{
    var proceed = true;
    var the_request = "";

    switch (request_name)
    {
        case 'openPageSearch':
            the_request = "ajax=1&ajax_process=openPageSearch&" + addtl_param;
            break;
        case 'openMyDownloads':
            the_request = "ajax=1&ajax_process=openMyDownloads&page=" + addtl_param + "&email=" + document.getElementById('my_downloads_email').value + "&phone=" + document.getElementById('my_downloads_phone').value;
            break;
        case 'redownloads':
            the_request = "ajax=1&ajax_process=redownloads&pid=" + addtl_param + "&email=" + document.getElementById('my_downloads_email').value + "&phone=" + document.getElementById('my_downloads_phone').value;
            break;
        case 'redownloadsnophone':
            the_request = "ajax=1&ajax_process=redownloads&pid=" + addtl_param + "&email=" + document.getElementById('my_downloads_email').value + "&phone=" + document.getElementById('my_downloads_phone2').value + "&country=" + document.getElementById('country_idv2').value;
            break;
        default:
            proceed = false;
    }

    if (proceed)
        ajaxPageSearch(divcont, the_request, url_param);
}

