function setLoading(divId) {
    $(divId)
        .html(
            '<div class="loading"><img src="' + GC_JS_WEBROOT + '/css/loading.gif" alt="Loading..." alt="Loading..." title="Loading..." /></div>');
    $(divId).show();
}

function setWait(divId) {
    $(divId)
        .html(
            '<div class="loading"><img src="' + GC_JS_WEBROOT + '/css/bar_loader.gif" alt="Wait..." alt="Wait..." title="Wait..." /></div>');
    $(divId).show();
}

function handleExpandBoxClick(element, id) {
    if ($('#' + id).is(':visible')) {
        //$('#' + id).slideUp('medium');
        $('#' + id).hide();
        $('#expandBox_menuLeft_' + id).hide();
        $('#expandBox_menuRight_' + id).hide();
    } else {
        $('#' + id).show();
        $('#expandBox_menuLeft_' + id).show();
        $('#expandBox_menuRight_' + id).show();
    }
    //$('#' + id).slideToggle('medium');
    //$('#expandBox_menuLeft_' + id).toggle();
    //$('#expandBox_menuRight_' + id).toggle();
    $(element).toggleClass('ico1');
    $(element).parent('.grayBox').toggleClass('grayBox1');
    return false;
}

function handleExpandBoxClicked(element) {
    $(element).parents('.info-block').toggleClass('block-collapsed');
    $(element).parents('.info-block').toggleClass('block-expanded');
    return false;
}

function getData(id, data) {
    var tempAJAX = $.ajax; // save the original $.ajax
    $.ajax = function(s) {
        // wrap the old $.ajax so set cache to true...
        s.cache = true;
        tempAJAX(s); // call old $.ajax
    }
    $(id).html(data); // insert the HTML and download the <script>s
    $(id).show();
    $.ajax = tempAJAX; // reset $.ajax to the original.
}

function updateContent(selector, content) {
    $(selector).html(content); // Insert the HTML and download the <script>s
    $(selector).show(); // Make it Visible if not.
}

function replaceContent(selector, content) {
    $(selector).replaceWith(content); // Insert the HTML and download the <script>s
    $(selector).show(); // Make it Visible if not.
}

function updateWholeInfoBlock(selector, content) {
    $(selector).parents('.info-block').replaceWith(content); // Update the Whole Info Block
}

function updatePageContent(content) {
    $('#pagewrapper').html(content); // Update the Content within pagewrapper.
    $('#pagewrapper').show(); // Make it Visible if not.
}

function getContent(url, containerId) {
    jQuery.ajax({
        'type'  : 'GET',
        'url'   : url,
        'cache' : false,
        'data'  : '',
        'success' : function(html) {
            jQuery('#' + containerId).html(html);
        }
    });
}

function destroyAllDialogs() {
    $('.ui-dialog').empty();
    $('.ui-dialog').remove();
}

function destroyDialogs(aDialogContainerIds) {
    for (var i = 0; i < aDialogContainerIds.length; i++) {
        dialogContainerId = aDialogContainerIds[i];
        if ($('#' + dialogContainerId)) {
            $('div#' + dialogContainerId + '.ui-dialog-content').dialog('destroy');
            $('#' + dialogContainerId).empty();
            $('#' + dialogContainerId).remove();
        }
    }
}

// check for valid numeric strings
function isNumeric(strString) {
    return /^-?(0|[1-9]\d*|(?=\.))(\.\d+)?$/.test(strString);
}

function isInteger(newString) {
    return (newString.toString().search(/^[0-9]+$/) == 0);
}

function createJsDateObjectFromMysqlString(timestamp)
{
//   if (typeof mysql_string === 'string') {
//      var t = mysql_string.split(/[- :]/);
//
//      // when t[3], t[4] and t[5] are missing they default to zero
//      // alert(t[0]);
//      // alert(t[1]);
//      // alert(t[2]);
//      return new Date(t[0], t[1], t[2], 0, 0, 0, 0);
//   }
//
//   return null;
    // function parses mysql datetime string and returns javascript Date object
    // input has to be in this format: 2007-06-05 15:26:02
//    alert(timestamp);
//    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
//    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
//    return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])$/;
    var parts=timestamp.replace(regex,"$1 $2 $3").split(' ');
    return new Date(parts[0],parts[1]-1,parts[2]);
}

