lockUITimer                 = null;
flagDisableUI 				= true;

function Anthem_PreCallBack_LockUI()
{
    $('#lockui').addClass("lock_on");
}

function Anthem_PreCallBack()
{
    var arrayPageSize = $.fn.lightbox.getPageSize();
    $("#lockui").css({width: '100%', height: arrayPageSize[1]+'px'}).fadeIn();
    
    if ( lockUITimer )
    {
        window.clearTimeout(this.lockUITimer);
        lockUITimer = null;
    }
    lockUITimer = window.setTimeout("Anthem_PreCallBack_LockUI()", 100);
}

function Anthem_PostCallBack()
{
    $('#lockui').removeClass("lock_on");
	
	if ( lockUITimer )
    {
        window.clearTimeout(this.lockUITimer);
        lockUITimer = null;
    }
	$('#lockui').css('display', 'none');
}

function UpdateQty(e, element)
{
    var input = $(element).parent().find("input").eq(0);
    if ( /^[-+]?[0-9]+$/.test($(input).val()) || $(input).val() == '')
    {
        if ( $(input).val() != '' && parseInt($(input).attr('r_mult')) != 0 && (parseInt($(input).val()) % parseInt($(input).attr('r_mult'))) != 0 )
        {
            alert("La quantità deve essere multiplo di " + $(input).attr('r_mult'));
            $(input).addClass('err');
            return;
        }    
        
        if ( parseInt($(input).val()) <= 0 )
        {
            alert("La quantità deve essere maggiore di zero.");
            $(input).addClass('err');
            return;
        }
        
        $(input).removeClass('err');
        Anthem_InvokePageMethod(
            'Add', 
            new Array($(input).attr('r_id'), ($(input).val() == '' ? '0' : $(input).val())), 
            function(result) 
            {
            }
            , null);
            
        var basket = $(element).parent().find("span.cbkt").eq(0);
        basket.parents("div:first").eq(0).show();
        basket.html( parseInt(jQuery.trim(basket.html())==''?'0':basket.html()) + parseInt($(input).val()));
        $(input).val('');
    }
    else
    {
        alert("La quantità non è valida, inserire solo valori numerici interi (es. 1, 10).");
        $(input).addClass('err');
    }
    e.stopPropagation();
}
  
function BindQuantityEvents()
{
    jQuery('.quantity').keydown(
    function(e)
    {
        if (e.keyCode == 13) 
        {
            UpdateQty(e,this);
            return false;
        }
    });         
    $(".basket_add").bind
    (
      "click",
      function(e)
      {
        UpdateQty(e,this);
      }
    );
}
    
function Info(url)
{
    var w = 500;
    var h = 430;
    var l = Math.floor((screen.width-w)/2);
    var t = Math.floor((screen.height-h)/2);
    window.open(url, '', 'menubar=false,scrollbars=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l,'');
}
