﻿function $(objectId) 
{
    if(document.getElementById && document.getElementById(objectId)) 
    {
        // W3C DOM
        return document.getElementById(objectId);
    } 
    else if (document.all && document.all(objectId)) 
    {
        // MSIE 4 DOM
        return document.all(objectId);
    } 
    else if (document.layers && document.layers[objectId]) 
    {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    } 
    else 
    {
        return false;
    }
}


//为Date对象添加一个Format方法
Date.prototype.Format = function(format)
{
    var o = 
    {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) 
        format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}

//获取鼠标所在的位置
function getPosXY(a,offset)
{
    var p=offset?offset.slice(0):[0,0],tn;
    while(a)
    {
        tn=a.tagName.toUpperCase();
        p[0]+=a.offsetLeft-(tn=="DIV"&&a.scrollLeft?a.scrollLeft:0);
        p[1]+=a.offsetTop-(tn=="DIV"&&a.scrollTop?a.scrollTop:0);
        if(tn=="BODY")break;
        a=a.offsetParent;
    }
    return p;
}
//获取窗体大小
function getWinSize(w)
{
    if(!w)w=window;
    if(w.document.compatMode=='CSS1Compat')
    with(w.document.documentElement)return[clientWidth,clientHeight,scrollLeft,scrollTop];
    else
    with(w.document.body)return[clientWidth,clientHeight,scrollLeft,scrollTop];
}
//获取URL传递的参数
function GetUrlValue(key)
{
    var reg = new RegExp("(^|\\?|&)"+ key +"=([^&]*)(\\s|&|$)", "i");
    if (reg.test(window.location.href)) return RegExp.$2; return "";
}
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; 
    } 
   ); 
}

//页面中构造DIV块
//返回DIV对象
function creatediv(divID)
{
	if(document.getElementById(divID))
		return;
		
	var newDiv = document.createElement("div");
	newDiv.id = divID;
	document.body.appendChild(newDiv);
	return newDiv;
}