﻿var self = this;
var postResponse;
var Queue = 0;
function xmlhttpPost(strURL, callback) {
    var xmlHttpReq = false;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function () {
        if ((self.xmlHttpReq.readyState == 4)) {
            if (callback)
                callback(self.xmlHttpReq.responseText);
            else if (updatepage)
                updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send();
}

function Send(action, controller, data, callback, errorCallback) {
    Queue++;
    //show loading screen
    try { $('#loader').show(); } catch (ex) { }
    $.ajax({
        type: "POST",
        url: "/" + controller + "/" + action,
        data: data,
        dataType: "json",
        error: errorCallback,
        success: callback
    });
}



//==============================================
//  CHANGE RESULT NUMBER
//==============================================
var resultAmount = {};
var initialFontSize = '';

$(document).ready(function () {

    //cache result span element, and initial font-size
    resultAmount = $('#ti_counter span');
    initialFontSize = resultAmount.css('font-size');
    if (initialFontSize != undefined)
        initialFontSize = initialFontSize.substr(0, initialFontSize.length - 2);

});

function changeResultNumber(newResultAmount){
    
    //animate number of results out, then back in with new number
    resultAmount.animate({opacity:0, fontSize:(initialFontSize/2) + 'px'}, 500, function(){
        resultAmount.text(newResultAmount);
        resultAmount.animate({opacity:1,fontSize:initialFontSize + 'px'}, 500);
    });
}
