﻿/*!
* WebChanix Common Javascript File
* Version 1.0
* requires various other supporting file,
* jQuery http://jquery.com
* blockUI http://malsup.com/jquery/block/
* jGrowl http://growl.info
* Copyright (c) 2007-2008 WebChanix
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Thanks to all the folks that created the tools that this file accesses!
*/

//jquery default for ajax requests
//$.ajaxSetup({
//    type: "POST",
//    contentType: "application/json; charset=utf-8",
//    data: "{}",
//    dataFilter: function (data)
//    {
//        var msg;

//        if (typeof (JSON) !== 'undefined' &&
//        typeof (JSON.parse) === 'function')
//            msg = JSON.parse(data);
//        else
//            msg = eval('(' + data + ')');

//        if (msg.hasOwnProperty('d'))
//            return msg.d;
//        else
//            return msg;
//    }
//});

$.ajaxSetup({ cache: false });

var __notifClosingIn = 0;
var __notifCallback = null;

function Redirect(u) { location.href = u; }
function Refresh() { location.reload(true); }
function PopUp(u) {window.open(u); }
function BlockUi(text)
{
    $.blockUI({ message: $("#Blocker").html(text) });
}
function UnBlockUi(elementId)
{
    if (elementId == null)
    {
        $.unblockUI();
    }
    else
    {
        $("#" + elementId).unblock();
    }
}
function UnBlockUiIn(delay)
{
    setTimeout(UnBlockUi, delay);
}
function BlockUiWithContent(elementId)
{
    $.blockUI({ message: $("#" + elementId) });
}
function BlockUiElementWithContent(elementIdToBlock, elementIdToUse)
{
    $("#" + elementIdToBlock).block({ message: $("#" + elementIdToUse) });

}
function BlockUiElement(elementId, text)
{
    $("#" + elementId).block({ message: text });
}
function CheckNotification()
{
    var msg = $("#notifMsg").val();
    if (msg.length > 0)
    {
        var parts = msg = msg.split('|');
        ShowNotification(parts[0], parts[1], parts[2]);
    }
}
function ShowNotification(title, message, timeout)
{
    $("#notifTitle").html(title);
    $("#notifMessage").html(message);
    $("#notifHolder").effect("slide", { direction: "up" }, 500);
    $("#notifHolder").effect("highlight", { color: "#3d66cd" }, 700);
    if (timeout > 0)
    {
        __notifClosingIn = timeout;
        NotificationCountDown();
    }
}
function NotificationCountDown()
{
    __notifClosingIn--;
    if (__notifClosingIn == 0)
    {
        NotificationClose();
        return;
    }

    $("#notifCountDown").html("Closing in " + __notifClosingIn);
    setTimeout(NotificationCountDown, 1000);
}
function NotificationClose()
{
    __notifClosingIn = null;
    $("#notifCountDown").html("");
    $("#notifHolder").slideUp(200, function ()
    {
        $("#notifContent").html("");
        $("#notifHeader").html("");
    });
}

//jquery highlight effect, use this to ensure consistency
function Highlight(elementId)
{
    $("#" + elementId).effect("highlight", 3000);

}

function SlideToggle(elementId)
{
    $("#" + elementId).slideToggle();
}

///these functions scripts are data access

//return the MVC AJAX result as an actual object
//we do this here to avoid having to type that same string everywhere. If a better method is found we can change it here
//GetMvcAjaxObject
function GMAO(r)
{
    if (r != null && r != "undefined" && r != "")
    {
        return r.get_response().get_object(); 
    }
    
    return "";
}

function IsIphoneIpod()
{
    return ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1));
}
