/*function DIALOG.message(argTitle, argText, argFocus, argRedirect) {

    // Enter text to dialog box
    $('#ui-dialog').html(argText);
    // Add button properties to dialog box
    $('#ui-dialog').dialog({
        title: argTitle,
        buttons : {

            "Ok": function() {
                $(this).dialog("close");
                if(argFocus) argFocus.focus();
                if(argRedirect) window.location.href = argRedirect;
            }
        }
    });
    // Open the dialog box
    $('#ui-dialog').dialog('open');
}
*/
var DIALOG = new clsDIALOG();
function clsDIALOG() {

    function confirm(argTitle, argText, argFunc) {

        // Enter text to dialog box
        $('#ui-dialog').html(argText);
        // Add button properties to dialog box
        $('#ui-dialog').dialog({
            title: argTitle,
            buttons : {

                "Cancel": function() {
                    $(this).dialog("close");                    
                },
                
                "Yes": function() {
                    $(this).dialog("close");
                    if(argFunc) eval(argFunc +";");

                }
            }
        });
        // Open the dialog box
        $('#ui-dialog').dialog('open');
    }

    function message(argTitle, argText, argFocus, argRedirect, argFunc) {

        // Enter text to dialog box
        $('#ui-dialog').html(argText);
        // Add button properties to dialog box
        $('#ui-dialog').dialog({
            title: argTitle,
            buttons : {

                "Ok": function() {
                    $(this).dialog("close");
                    if(argFocus) argFocus.focus();
                    if(argRedirect) window.location.href = argRedirect;
                    if(argFunc) eval(argFunc +";");
                }
            }
        });
        // Open the dialog box
        $('#ui-dialog').dialog('open');
    }

    this.confirm = confirm;
    this.message = message;
}

$(function() {

    /*if($("#btn-default")) {
        
        $("#btn-default").attr('class', 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only');
        $("#btn-default").mouseover(function() { $(this).addClass('ui-state-hover'); });
        $("#btn-default").mouseout(function() { $(this).removeClass('ui-state-hover'); });
        $("#btn-default").css('height', '25px');
    }*/

    /*if($("#btn-upl")) {

        $("#btn-upl").attr('class', 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only');
        $("#btn-upl").mouseover(function() { $(this).addClass('ui-state-hover'); });
        $("#btn-upl").mouseout(function() { $(this).removeClass('ui-state-hover'); });
        $("#btn-upl").css('height', '25px');
    }*/

    if($('#ui-dialog')) {
        
        $('#ui-dialog').dialog({
            autoOpen   : false,
            modal      : true,
            width      : 400,
            resizable  : false
        });
    }

    var so = new SWFObject(DOCROOT +"media/swf/vgamerz_468X60_flash.swf", "myswf", "468", "60", "9");
    so.write("swf");
});

function numOnly(e) {
    var key;
    var keychar;

    if(window.event) { key = window.event.keyCode; }
    else
    if(e) { key = e.which; }
    else { return true; }

    keychar = String.fromCharCode(key);

    // control keys
    if((key == null) ||
       (key == 0) ||
       (key == 8) ||
       (key == 9) ||
       (key == 13) ||
       (key == 27)) {
       return true;
    }
    else
    if((("0123456789").indexOf(keychar) > -1)) { return true; }
    else { return false; }
}

function count_chars(obj, disp, max) {

    if(obj.val().length > max){
        obj.val(obj.val().substr(0, max));
    }

    disp.html((max - obj.val().length));
}


var GBL = new clsGBL();

function clsGBL() {

    this.find = function find(argToFind) {

        var subject = $("#search_"+ argToFind).val().replace(/^\s+/, '').replace(/\s+$/, ''); // Trim it Baby ...

        if(subject == "" || subject.length < 3) {

            if(subject == "") DIALOG.message('OOOPS !!! BLANK', "You must enter something to <b>search</b>.", $("#search_"+ argToFind));
            else if(subject.length < 3) DIALOG.message("OOOPS !!! TOO SHORT", "The <b>"+ argToFind +"</b> is too short, it should have been better if it was 3 characters or more than that.", $("#search_"+ argToFind));

            return;
        }

        $("#loader_"+ argToFind).html('<img src="blank.gif" class="i_loader" />');
        $.post('?m=gbl&async=find', {'find' : argToFind, search : subject}, function(argResponse){

            var output = [];
            output.push('<option value="0">[none]</option>');
            $("#"+ argToFind).html('');

            if(argResponse) {

                argResponse = eval(argResponse);
                if(argResponse.length > 0) {

                    for(var i=0; i<argResponse.length; i++) {
                        output.push('<option value="'+ argResponse[i].id +'">'+ argResponse[i].name +'</option>');
                    }
                } else {

                    DIALOG.message("OOOPS !!! NONE", "Sorry, but we <b>can't find</b> the place named <b>"+ subject + "</b>!");
                }
            }
            $("#"+ argToFind).html(output.join(''));
            $("#loader_"+ argToFind).html('');

        }, 'json');
    }

    this.btnbehavior = function btnbehavior(argLoad) {

        if(argLoad) {

            $("#btnmain").attr("disabled", true);
            $("#td_btnmain").html('<img src="blank.gif" class="i_loader" /> <b>processing ...</b> <u>please</u> <b>wait ...</b>');
        } else {

            $("#btnmain").attr("disabled", false);
            $("#td_btnmain").html('');
        }
    }

    this.menutoggle = function menutoggle(obj, cls) {

        obj.attr('class', cls);
    }
}
