﻿var wc_loading_big = "<img src='/images/x/loading_big.gif' alt='loading' />";

///显示panel在鼠标的位置
///target 需要显示的对象
///effectstring 显示效果 jquery show 参数
function mouseShow(target, effectstring){
        var scrollYPos, windowWidth, windowHeight; 
        scrollYPos = getScrollTop();
        if (typeof window.pageYOffset != 'undefined') { 
           windowWidth =  window.innerWidth;
           windowHeight =  window.innerHeight;
        } 
        else if (typeof document.compatMode != 'undefined' && 
           document.compatMode != 'BackCompat') { 
           windowWidth = document.documentElement.clientWidth;
           windowHeight =  document.documentElement.clientHeight;
        } 
        else if (typeof document.body != 'undefined') { 
           windowWidth = document.body.clientWidth;      
           windowHeight =  document.body.clientHeight;     
        } 
        targetWidth = parseInt(target.width());
        targetHeight = parseInt(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);
        
}

/// 获取滚动条上部位置
function getScrollTop(){
        if (typeof window.pageYOffset != 'undefined') { 
           return window.pageYOffset;
        } 
        else if (typeof document.compatMode != 'undefined' && 
           document.compatMode != 'BackCompat') { 
           return document.documentElement.scrollTop; 
        } 
        else if (typeof document.body != 'undefined') { 
           return document.body.scrollTop; 
        } 
}

/// 获取滚动条左边位置
function getScrollLeft(){
        if (typeof window.pageYOffset != 'undefined') { 
           return window.pageXOffset;
        } 
        else if (typeof document.compatMode != 'undefined' && 
           document.compatMode != 'BackCompat') { 
           return document.documentElement.scrollLeft; 
        } 
        else if (typeof document.body != 'undefined') { 
           return document.body.scrollLeft; 
        } 
}

var xoffsetTop=0, xoffsetLeft=0;

///将一个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();
}

/// 获取对象上部位置
function getTopPix(obj){
    xoffsetTop += obj.offsetTop;
    xoffsetLeft += obj.offsetLeft;
    if (obj.offsetParent){        
        getTopPix(obj.offsetParent);
    }
}

//将提示信息显示在参考控件的下方
//msg 提示信息
//refObj 参考对象
//className cssclass  
function tipDown(msg, refObj, className){
    xID = new Date();
    xID=xID*1;
    tipAdd =  $("<div id='" + xID + "'>" + 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");
}


//获取但前窗口的显示高度 兼容各浏览器
function getWindowHeight(){
   var windowHeight=0;
   if (typeof(window.innerHeight)=='number')
	            windowHeight = window.innerHeight;          
	else 
	{
	    if (document.documentElement && document.documentElement.clientHeight)
	         windowHeight = document.documentElement.clientHeight;
	    else
	    {
	        if (document.body && document.body.clientHeight)
	            windowHeight = document.body.clientHeight;
	    }            
    }            
    return windowHeight;
}

//获取当前窗口的显示宽度
function getWindowWidth(){
   var windowHeight=0;
   if (typeof(window.innerWidth)=='number')
	            windowWidth = window.innerWidth;          
	else 
	{
	    if (document.documentElement && document.documentElement.clientWidth)
	         windowWidth = document.documentElement.clientWidth;
	    else
	    {
	        if (document.body && document.body.clientWidth)
	            windowWidth = document.body.clientWidth;
	    }            
    }            
    return windowWidth;
}

// 无title打开DialogBox
// obj 需要打开的对象 
// hand 如果启用 draggable 时使用的 handle
// lockPage 是否锁住页面 true or false
function openDialogBox(obj,hand,lockPage){
    var topPosition = (getWindowHeight() - $(obj).height())/2;
    var leftPosition =(getWindowWidth() - $(obj).width())/2;
    $(obj).css({"position":"fixed","z-index":"999999","top":topPosition+"px","left":leftPosition+"px"});
    
    if(hand) {
       $(hand,$(obj)).css({ cursor: "pointer" });
       $(obj).draggable({handle:hand});
    }
    if(lockPage)
       $(obj).after("<div class='dialogBoxBackup' style='position:fixed;z-index:999998;top:0;left:0;right:0;bottom:0;background:#CCC;color:white;filter:Alpha(opacity=30);opacity:0.3'></div>");
    $(obj).show();
}

// 关闭 DialogBox
function closeDialogBox(obj){
    $(obj).hide();
    var boxBackup =  $("+.dialogBoxBackup",$(obj));
    if(boxBackup!= null)
       boxBackup.remove();
}

