﻿//功能：根据传入的参数弹出常规窗口，如果弹出多个则会一次展开显示，而不会重叠到一起

//作者：葛绍飞

//日期：2008-6-20
/*
参数：

url：弹出窗口的页面地址
width：弹出窗口的宽度
heigth：弹出窗口的高度
*/
var strTop = 0;
var left = 0;
function OpenWindow(url, width, heigth) {
    window.open(url, "_blank", "height=" + heigth + ",width=" + width + ",status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,top=" + strTop + ",left=" + left);
    strTop = strTop + 20;
    left = left + 20;
    if (strTop > window.screen.height) {
        strTop = 0;
        left = 0;
    }
}

function OpenCenterWindow(url, width, height) {
    if (width == null)
        width = 500;
    if (height == null)
        height = 400;

    var topPos = (window.screen.availHeight - height) / 2;
    var leftPos = (window.screen.availWidth - width) / 2;
    window.open(url, "_blank", "height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,top=" + topPos + ",left=" + leftPos);
}

//功能：根据传入的参数弹出模态窗口

//作者：葛绍飞

//日期：2008-6-20
/*
参数：

url：弹出窗口的页面地址
width：弹出窗口的宽度
heigth：弹出窗口的高度
*/
function ShowModalDialog(url, width, height) {
    return window.showModalDialog(url, window, 'dialogHeight =' + height + 'px; dialogWidth=' + width + 'px;status:no;help:no;location:no;scroll=yes;resizable:yes;')
}

/*
作者：葛绍飞
功能：根据传入的Url地址，自动生成一个包含各个参数的对象
Url：要解析的地址串，如：Url为
ShowInfo.aspx?year=2008&month=8&date=1
的链接串返回对象将包含如下的属性：
var urlStr = "ShowInfo.aspx?year=2008&month=8&date=1";
var obj = ParamParser(urlStr);
alert(obj.year+"年"+obj.month+"月"+obj.date+"日");
显示结果为：
2008年8月1日

注意如果不传入URL，将会自动解析当前页面的地址
*/
function ParamParser(url) {
    if (!url)
        url = window.location.href;
    var qPos = url.indexOf("?");
    if (qPos == -1)
        return;
    else {
        var paramStr = url.substr(qPos + 1); //截取?后面的参数集合字符串
        var paramArr = paramStr.split("&"); //把截取到的参数字符串以&隔开
        for (var i in paramArr) {                   //把每一个"参数名=参数值"与键值对的形式存储起来
            var tempArr = paramArr[i].split("=");
            this[tempArr[0]] = tempArr[1];
        }
    }
    return this;
}


function linkMouseOver(curLink,color)
{
    if(color == undefined)
        color="#FF6600";
    curLink.style.color=color;
    curLink.style.textDecoration="underline";
}
function linkMouseOut(curLink,color)
{
    if(color == undefined)
        color="#2C2C2C";
    curLink.style.color=color;
    curLink.style.textDecoration="none";
}


/*以下两个方法是用来使FireFox下可以使用innerText*/
function  isIE(){  //ie? 
      if  (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1) 
        return  true; 
      else 
        return  false; 
} 

if(!isIE()){  //firefox  innerText  define 
      HTMLElement.prototype.__defineGetter__("innerText", 
        function(){ 
          var  anyString  =  ""; 
          var  childS  =  this.childNodes; 
          for(var  i=0;  i <childS.length;  i++)  { 
            if(childS[i].nodeType==1) 
              anyString  +=  childS[i].tagName=="BR"  ?  '\n'  :  childS[i].innerText; 
            else  if(childS[i].nodeType==3) 
              anyString  +=  childS[i].nodeValue; 
          } 
          return  anyString; 
        } 
      ); 
      HTMLElement.prototype.__defineSetter__("innerText", 
        function(sText){ 
          this.textContent=sText; 
        } 
      ); 
}

