﻿// JScript 文件

//页面加载时自动调整大小
function win_onLoad()
{ 
    var table = document.body.getElementsByTagName("table");
   
    var tb = table[0];
    var width = 752;
    if(tb != null)
    {
        width = tb.width;
    }
 //   alert(tb.offsetHeight);
    var height = tb.offsetHeight;  
   // alert(width);
    width = eval(width * 1 + 30);
    height = eval(height * 1 + 60);
    
    var sWidth  = screen.width;
    var sHeight = screen.height;

    var left = sWidth-((sWidth-width)/2 + width);
    if(left < 0)
    {
        left = 0;
    }
    var top = sHeight-((sHeight-height)/2 + height);
    if(top < 0)
    {
        top = 0;
    }
//alert(width);
    if (width > screen.width-50) 
        width = screen.width-50; 
     
    if (height > screen.height-50) 
        height = screen.height-50; 
 //alert(width);
    window.moveTo(left, top);
    window.resizeTo(width,height);
    
    // Add Ajax Wait
    main_onload();
}

//打开一个自适应窗口

function OpenSizeWin(url)
{
   window.open(url,"url","toolbar=no,resizable=yes,scrollbars=yes,location=no, status=no");
}

//弹出窗口
function WindowShow(obj,w,h)
{
    if(w != null && h != null)
    {
        window.open(obj,"","width=" + w + ",height=" + h + ",toolbar=no,resizable=yes,scrollbars=yes,location=no, status=no");
    }
    else if(w != null && h == null)
    {
        window.open(obj,"","width=770" + ",height=" + w + ",toolbar=no,resizable=yes,scrollbars=yes,location=no, status=no");
    }
    else if(w == null && h == null)
    {
        window.open(obj,"","toolbar=no,resizable=yes,scrollbars=yes,location=no, status=no");
    }
}

function WindowshowModalDialog(obj)
{
    window.showModalDialog(obj,null,"toolbar=no,resizable=no,scrollbars=yes,location=no, status=no");
}

//关闭弹出窗口,刷新主窗口
function ReplaceParent(bool)
{
    if(bool == 1)
    {
        opener.window.location.reload();
    }
    window.close();
}

//隐藏显示div
function divDisplay(obj)
{
    var div = document.getElementById(obj);
    
    if(div.style.display == "none")
    {
        div.style.display = "block";
    }
    else
    {
        div.style.display = "none";
    }
}

function optionDisplay(count,tdname,divname,index)
{
    for(i=1; i<=count; i++)
    {
        var td = document.getElementById(tdname + i);
        var div = document.getElementById(divname + i);
        
        if(i == index)
        {
            td.className = "click";
            div.style.display = "block";
        }
        else
        {
            td.className = "default";
            div.style.display = "none";
        }
    }
}

function menuDisplay(count,menuName,divname,index)
{
    for(i=1; i<=count; i++)
    {
        var menu = document.getElementById(menuName + i);
        var div = document.getElementById(divname + i);
        
        if(i == index)
        {
            menu.src = "images/ecdengluhou_anniu" + i + ".gif";
            div.style.display = "block";
        }
        else
        {
            menu.src = "images/ecdengluhou_anniu0" + i + ".gif";
            div.style.display = "none";
        }
    }
}

//Element Items Borrowed From Prototype. Add by SuChuanyi

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}


var Element = {
  
  toggle: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 
        (element.style.display == 'none' ? '' : 'none');
    }
  },

  hide: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 'none';
    }
  },

  show: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = '';
    }
  },

  remove: function(element) {
    element = $(element);
    element.parentNode.removeChild(element);
  },
   
  getHeight: function(element) {
    element = $(element);
    return element.offsetHeight; 
  }
}

//End Element Items
    
//function alert(message,type)
//{
//    if(type == null || type == 0)
//    {
//        window.showModalDialog("/ADCAdminPortal/Common/Succeed.aspx",message,"dialogHeight:200px;dialogWidth:412px;center:yes;scroll:no;resizable:no;help:no;status:no;directions:no;menubar:no;location:no;toolbar:no;");
//    }
//    else
//    {
//        window.showModalDialog("/ADCAdminPortal/Common/Lost.aspx",message,"dialogHeight:200px;dialogWidth:412px;center:yes;scroll:no;resizable:no;help:no;status:no;directions:no;menubar:no;location:no;toolbar:no;");
//    }
//}


// 2007-01-23 开始添加

/*
const define
*/
var WAIT_DIV = "divWaiting";
/*
var define
*/
var is_posting = false;

// page load
function main_onload(){
  
  // Browser check
  if(navigator.appName != "Microsoft Internet Explorer")
    return;
  
  try {
    // 
    wait_div_create();
  
    document.onclick = ctl_page_post;
  
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(main_EndRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(main_BeginRequestHandler);
  }catch(e){}
  
} // end main_onload

function main_EndRequestHandler() {
  try {
    var div = getobject(WAIT_DIV);
    is_posting = false;
    div.style.display = "none";
  }catch(e){}
} // end main_EndRequestHandler

function main_BeginRequestHandler() {
  try {
    var div = getobject(WAIT_DIV);
    is_posting = true;
    wait_div_setxy();
    div.style.display = "block";
  }catch(e){}
} // end main_BeginRequestHandler

// create wait div
function wait_div_create() {
  
  if(getobject(WAIT_DIV) != null)
    return;
  
  var div = document.createElement("div");
  var txt = document.createTextNode("");
  var img = document.createElement("image");
  img.src = "../images/ajax-loader.gif"
  img.style.height ="41px"; 
  img.style.width ="184px"; 
  img.border = 0;
  div.appendChild(img);
  div.appendChild(txt);

  div.style.display = "none";
  div.style.position = "absolute";
  div.style.color = "white";

  div.style.top = "1px";
  div.style.right = "16px";
  div.style.fontSize = "12px";
  
  div.id = WAIT_DIV;
  div.zIndex = 99;
  document.body.appendChild(div);
} // end wait_div_create

function wait_div_setxy() {
  var div = getobject(WAIT_DIV);
  var posX = 0,posY = 0;
  if (document.documentElement && document.documentElement.scrollTop) {
    posX = document.documentElement.scrollLeft;
    posY = document.documentElement.scrollTop;
  }
  else if (document.body) {
    posX = document.body.scrollLeft;
    posY = document.body.scrollTop;
  }
  div.style.top=(posY+1)+"px";
  div.style.right=(posX+16)+"px";
  
  div.style.left =(document.body.clientWidth-70)/2; 
  div.style.top =(document.body.clientHeight-70)/2;
  div.style.zIndex = 99;
  
} // end wait_div_setxy

function getobject(idno) {
  return ((document.all) ? document.all[idno] : document.getElementById(idno));
} // end getobject

function ctl_page_post() {
  try {
    if(is_posting) {
      wait_div_setxy();
      return false;
    }
  }catch(e){}
} // end ctl_page_post

// 2007-01-23 结束添加