﻿var wc_loading_big = "<img src='/images/x/loading_big.gif' alt='loading...' />";
var wc_loading_small = "<img src='/images/x/blue-loading.gif' alt='loading...' />";
var wc_loading_min = "<img src='/images/x/loading.gif' alt='loading...' />";
//ajax提交的时候显示loading...
$(function() {
    var loader = jQuery('<div id="loadingProgress">' + wc_loading_small + '</div>')
    	    .css({ padding: "10px", position: "absolute", top: 0, left: 0, 'z-index': '105' })
    	    .appendTo("body")
    	    .hide();
    jQuery().ajaxStart(function() {
        loader.show();
    }).ajaxStop(function() {
        loader.hide();
    }).ajaxError(function(a, b, e) {
        alert("Ajax Error");
    });
});

// 一下方法由于jQuery已经做了兼容支持，所以都改了；
/// 获取滚动条上部位置
function getScrollTop() {
    return $(window).scrollTop();
}

/// 获取滚动条左边位置
function getScrollLeft() {
    return $(window).scrollLeft();
}

//获取但前窗口的显示高度 
function getWindowHeight() {
    return $(window).height();
}

//获取当前窗口的显示宽度
function getWindowWidth() {
    return $(window).width();
}

///显示panel在鼠标的位置
///target 需要显示的对象
///effectstring 显示效果 jquery show 参数
function mouseShow(target, effectstring) {
    var scrollYPos = $(window).scrollTop();
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var targetWidth = target.width();
    var targetHeight = target.height();

    if (event.y <= windowHeight / 2)
        target.css("top", event.y + scrollYPos);
    else
        target.css("top", event.y + scrollYPos - targetHeight);
    if (parseInt(target.css("top")) < 0) {
        target.css("top", event.y + scrollYPos);
    }

    if (event.x <= windowWidth / 2)
        target.css("left", event.x);
    else
        target.css("left", event.x - targetWidth);
    target.show(effectstring);
}

///将一个panel 显示在另一个panel的附近 此处的object 为dom
///tarObj 需要显示的对象
///refObj 参考对象
function showPanel(tarObj, refObj) {
    xoffsetTop = 0;
    xoffsetLeft = 0;
    getTopPix(refObj);
    windowWidth = document.body.clientWidth;
    showerWidth = tarObj.clientWidth;
    if (xoffsetLeft <= windowWidth / 2) {
        $(tarObj).css("left", xoffsetLeft);
    } else {
        $(tarObj).css("left", xoffsetLeft - showerWidth + refObj.clientWidth);
    }
    $(tarObj).css("top", xoffsetTop + refObj.clientHeight);
    $(tarObj).show();
}

var xoffsetTop = 0, xoffsetLeft = 0;
/// 获取对象上部位置
function getTopPix(obj) {
    xoffsetTop += obj.offsetTop;
    xoffsetLeft += obj.offsetLeft;
    if (obj.offsetParent) {
        getTopPix(obj.offsetParent);
    }
}

//将提示信息显示在参考控件的下方
//msg 提示信息
//refObj 参考对象
//className cssclass  
function tipDown(msg, refObj, className) {
    var xID = new Date();
    xID = xID * 1;
    var tipAdd = $("<div id='" + xID + "' class='msgItem'>" + msg + "</div>").appendTo("body");
    if (className)
        tipAdd.attr("class", className);
    else {
        tipAdd.css("background", "#eee");
        tipAdd.css("padding", "8px");
        tipAdd.css("margin", "5px auto");
        tipAdd.css("border", "1px solid #ccc");
        tipAdd.css("color", "red");
    }
    tipAdd.css("position", "absolute");
    showPanel(tipAdd.get(0), refObj);
    tipAdd.fadeOut(5000);

}

// Create a cookie with the specified name and value.
// The cookie expires at the end of the 21st century.
function setCookie(sName, sValue) {
    date = new Date();
    document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT; path=/";
}

// Get the value of the cookie with the specified name.
function getCookie(sName) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    // a cookie with the requested name does not exist
    return null;
}

// Delete the cookie with the specified name.
// The value of the cookie is unnecessary.
function delCookie(sName) {
    document.cookie = sName + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT; path=/";
}

///弹出框 <div class=cssName><div class=title>title</div><div class=content></div></div>
function xAlert(title, modal, cssName, url) {
    dOverlay = $("<div id='overlay'></div>").appendTo("body");
    //dOverlay.css("visibility","hidden"); 
    dOverlay.css("position", "absolute");
    dOverlay.css("left", "0px");
    dOverlay.css("top", "0px");
    dOverlay.css("width", "100%");
    dOverlay.css("height", "100%");
    dOverlay.css("text-align", "center");
    dOverlay.css("z-index", "1000");
    dOverlay.css("background", "#eee");
    dOverlay.html(title);
    $("#wrapper").attr("disabled", "true");
}


//直接 ajax update
function ajaxPager(url, para, updateID) {
    $.post(url, para, function(res) {
        $(updateID).html(res);
    });
}

// 无title打开DialogBox
// obj 需要打开的对象 
// hand 如果启用 draggable 时使用的 handle
// lockPage 是否锁住页面 true or false
function openDialogBox(obj, hand, lockPage) {
    if (!lockPage) { $(obj).XDialog({ lockPage: false }); } else { $(obj).XDialog({ lockPage: true }); }
    if (hand) { $(obj).draggable({ handle: hand }); }
}

// 关闭 DialogBox
function closeDialogBox(obj) {
    $(obj).XDialog({ isOpen: false });
}

function includeJs(jsFile){
    document.write('<script type="text/javascript" src="' + jsFile + '"></script>'); 
}




//XTabPanel
includeJs("/js/jquery/XTabPanel/XTabPanel_min.js");

//XTreeBox
includeJs("/js/jquery/XTreeBox/XTreeBox_min.js");

//XTreeMenu 插件
includeJs("/js/jquery/XTreeMenu/XTreeMenu_min.js");

//XDialog 插件
includeJs("/js/jquery/XDialog/XDialog_min.js");




