﻿
$(function() {

    $.superbox.settings = {
        boxId: "superbox", // Id attribute of the "superbox" element
        boxClasses: "", // Class of the "superbox" element
        overlayOpacity: .8, // Background opaqueness
        boxWidth: "600", // Default width of the box
        boxHeight: "400", // Default height of the box
        loadTxt: "Loading...", // Loading text
        closeTxt: "Close", // "Close" button text
        prevTxt: "Previous", // "Previous" button text
        nextTxt: "Next" // "Next" button text
    };

    $.superbox();

    $('.txt-echo-listen').keypress(function(event) {
        if ($(this).attr('echoID') != null) {
            $('#' + $(this).attr('echoID')).val($(this).val());
        }
    });

    $('.txt-echo-listen').change(function(event) {
        if ($(this).attr('echoID') != null) {
            $('#' + $(this).attr('echoID')).val($(this).val());
        }
    });

    $('.button-trigger').click(function(event) {
        $(this).children('input').click();
    });

    $('.button-trigger').children('input').click(function(event) {
        event.stopPropagation();
    });

    $('.txt-default-listen').focus(function() {
        $(this).removeClass('txt-default');
        if ($(this).val() == $(this).attr('alt')) {
            $(this).val('');
        } else {
            this.select();
        }
    });

    $('.txt-default-listen').blur(function() {
        if ($(this).val() == '') {
            $(this).val($(this).attr('alt'));
            $(this).addClass('txt-default');
        }
    });

    $('.form-quantitybox-increment').click(function() {
        var quantity = $(this).parent().children('input').val();
        if (parseInt(quantity)) {
            $(this).parent().children('input').val(parseInt(quantity) + 1);
        } else {
            $(this).parent().children('input').val(1);
        }
        if ($(this).parent().children('input').attr('triggergroupquantity') == 'true') {
            handleGroupQuantity(this);
        }
    });

    $('.form-quantitybox-decrement').click(function() {
        var quantity = $(this).parent().children('input').val();
        if (parseInt(quantity)) {
            if (parseInt(quantity) > 0) {
                $(this).parent().children('input').val(parseInt(quantity) - 1);
            }
        }
        if ($(this).parent().children('input').attr('triggergroupquantity') == 'true') {
            handleGroupQuantity();
        }
    });

    $('.form-quantitybox-input').change(function() {
        if (/^[0-9]+$/.test($(this).val()) == false) {
            $(this).val('0')
        }
        if ($(this).attr('triggergroupquantity') == 'true') {
            handleGroupQuantity();
        }
    });

    $('.form-quantitybox-input').focus(function() {
        $(this).select();
    });

});

function handleAutoButton(sender, event, trigger) {
    if (event.which == 13) {
        if ($('#hdnAutoButtonAction'))
            $('#hdnAutoButtonAction').val(trigger);
        $(trigger).click();
        return false;
    }
}

function handleAutoButtonOverride(trigger) {
    if ($('#hdnAutoButtonAction'))
        $('#hdnAutoButtonAction').val(trigger);
}

function handleSignInModalSetup() {
    $('.divSignInForm').show();
    $('.divPasswordRecoverForm').hide();
    $('.divPasswordRecoverFormConfirmation').hide();
}

function handleSignInModalPasswordRecovery() {
    $('.divSignInForm').show();
    $('.divSignInForm').hide();
    $('.divPasswordRecoverForm').show();
}

function cleanInputNumeric(input) {
    var result = new String(input);
    result = result.replace(/[^0-9]/g, '');
    return result;
}
