﻿function addEvent(obj,evtType,func,cap){
    cap=cap||false;
 	if(obj.addEventListener){
    	obj.addEventListener(evtType,func,cap);
  		return true;
 	}
	else if(obj.attachEvent){
    	if(cap){
			obj.setCapture();
         	return true;
     	}
		else
		    return obj.attachEvent("on" + evtType,func); 
 	}
	else 
  		return false; 
}

/*
GetPageScroll函数能够给出滚动条的位置。执行这个函数会得到一个包含滚动条水平位置和滚动条垂直位置的对象
通过一个有3个分支的if...else语句实现。第1个分支针对Mozilla家族的浏览器例如Firefox；第2个分支针对Strict模式的IE 6.0 浏览器；第3个分支针对普通IE和其他浏览器。
*/
function getPageScroll(){
    var xScroll,yScroll;
 	if (self.pageXOffset) 
  		xScroll = self.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft) 
  		xScroll = document.documentElement.scrollLeft;
    else if (document.body)  
  		xScroll = document.body.scrollLeft;
	  
 	if (self.pageYOffset) 
  		yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) 
  		yScroll = document.documentElement.scrollTop;
    else if (document.body) 
  		yScroll = document.body.scrollTop;
	 
 	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

/*
GetPageSize能够获得页面大小和窗口大小。执行这个函数会得到一个包含页面宽度、页面高度、窗口宽度、窗口高度的对象。
第一部分是获得页面的实际大小，通过一个有3个分支的if...else语句实现。第1个分支针对Mozilla家族的浏览器例如Firefox；第2个分支针对普通IE浏览器；第3个分支针对IE Mac浏览器。
第二部分是获得窗口的实际大小，通过一个有3个分支的if...else语句实现。第1个分支针对Mozilla家族的浏览器例如Firefox；第2个分支针对Strict模式的IE 6.0 浏览器；第3个分支针对普通IE和其他浏览器。
第三个部分是在页面高度或者宽度少于窗口高度或者宽度的情况下，调整页面大小的数值。因为即使页面大小不足窗口大小，我们看到的仍然是窗口大小，所以调整后的数值更加符合实际需要。
*/
function GetPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {  // Mozilla
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } 
	else if (document.body.scrollHeight > document.body.offsetHeight){ // IE Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } 
	else { // other
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } 
	else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } 
	else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    } 
    if(yScroll < windowHeight) 
        pageHeight = windowHeight;
    else 
        pageHeight = yScroll; 
    if(xScroll < windowWidth) 
        pageWidth = windowWidth;
    else 
        pageWidth = xScroll; 
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}
function isNullOrEmpty(obj){
	if (typeof(obj) == "undefined")
	  return true; 
	if (obj == undefined)
	  return true; 
	if (obj == null)
	  return true; 
	if( obj == "")
	  return true;
	return false;
}
