/**
 * 客户端浏览器
 */
var clientBrowser = function(){
	/**
	 * 得到客户端浏览器宽度
	 */
	this.getBwidth = function(){
		if ($.browser.msie && $.browser.version < 7) {
			var scrollWidth = Math.max(
				document.documentElement.scrollWidth,
				document.body.scrollWidth
			);
			var offsetWidth = Math.max(
				document.documentElement.offsetWidth,
				document.body.offsetWidth
			);
			
			if (scrollWidth < offsetWidth) {
				return $(window).width();
			} else {
				return scrollWidth;
			}
		} else {
			return $(document).width();
		}
	};
	
	/**
	 * 得到客户端浏览器高度
	 */
	this.getBheight = function(){
		if ($.browser.msie && $.browser.version < 7) {
			var scrollHeight = Math.max(
				document.documentElement.scrollHeight,
				document.body.scrollHeight
			);
			var offsetHeight = Math.max(
				document.documentElement.offsetHeight,
				document.body.offsetHeight
			);
			
			if (scrollHeight < offsetHeight) {
				return $(window).height();
			} else {
				return scrollHeight;
			}
		} else {
			return $(document).height();
		}
	};
};

/**
 * 弹出层特效
 */
function isblank(str) {
	var i;
	var len = str.length;
	for (i = 0; i < len; ++i) {
		if (str.charAt(i) != " ") {
			return false;
		}
	}
	return true;
}
/**
 * @author 巍巍 
 * 获取页面高度，窗口高度
 * 遗留问题：因获取不同浏览器客户端数据不一致，考虑对蒙版高度和宽度控制进行追加。保持一致，后期开发更改。
 * 过期，暂不用
 */
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else {
		if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {  // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
		}
	}
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll + 50;
	}
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll + 20;
	}
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

function getClientPageSize(){
	var windowWidth, windowHeight;
	if ($.browser.msie && $.browser.version < 7) {
		var scrollWidth = Math.max(
			document.documentElement.scrollWidth,
			document.body.scrollWidth
		);
		var offsetWidth = Math.max(
			document.documentElement.offsetWidth,
			document.body.offsetWidth
		);
		var scrollHeight = Math.max(
			document.documentElement.scrollHeight,
			document.body.scrollHeight
		);
		var offsetHeight = Math.max(
			document.documentElement.offsetHeight,
			document.body.offsetHeight
		);
		if (scrollWidth < offsetWidth) {
			windowWidth = $(window).width();
			windowHeight =  $(window).height();
		} else {
			windowWidth = scrollWidth;
			windowHeight =  scrollHeight;
		}
	} else {
		windowWidth = $(document).width();
		windowHeight = $(document).height();
	}
	arrayPageSize = new Array(windowWidth, windowHeight);
	return arrayPageSize;
}
	/**
	 * 得到客户端浏览器宽度
	 */
	function getBwidth(){
		if ($.browser.msie && $.browser.version < 7) {
			var scrollWidth = Math.max(
				document.documentElement.scrollWidth,
				document.body.scrollWidth
			);
			var offsetWidth = Math.max(
				document.documentElement.offsetWidth,
				document.body.offsetWidth
			);
			if (scrollWidth < offsetWidth) {
				return $(window).width();
			} else {
				return scrollWidth;
			}
		} else {
			return $(document).width();
		}
	}
	
/**
 * 得到客户端浏览器高度
 */
function getBheight(){
	if ($.browser.msie && $.browser.version < 7) {
		var scrollHeight = Math.max(
			document.documentElement.scrollHeight,
			document.body.scrollHeight
		);
		var offsetHeight = Math.max(
			document.documentElement.offsetHeight,
			document.body.offsetHeight
		);
		
		if (scrollHeight < offsetHeight) {
			return $(window).height();
		} else {
			return scrollHeight;
		}
	} else {
		return $(document).height();
	}
}


var BackGroudFont = new function(){
	this.pageWidth = function(){
		return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
	};
	this.pageHeight = function(){
		return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
	};
	this.topPositon = function(){
		return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
	};
	this.leftPositon = function(){
		return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
	};
	this.availWidth = function(){
		return window.screen.availWidth;
	};
	this.availHeight = function(){
		return window.screen.availHeight;
	};
	this.srcollHeight = function(){
		return document.body.scrollHeight;
	};
	this.srcollWidth = function(){
		return document.body.scrollWidth;
	};
	
	this.backGroudFontHieght = function(){
		return Math.max(window.screen.availHeight,document.body.scrollHeight);
	};
	this.backGroudFontWidth = function(){
		return Math.max(window.screen.availHeight,document.body.scrollWidth);
	};
};

/**
 * 全屏层
 * 每次创建层对象，用来加载loading对象层。
 * 可加异常控制，只创建一次全屏层
 */
function ShowAllSreenDiv() {
	if (document.getElementById("opbgDiv") != null) {
		var opbgObj = document.getElementById("opbgDiv");
		var opshowObj = document.getElementById("opshowDiv");
		document.body.removeChild(opbgObj);
		//document.body.removeChild( opshowObj );
	}
	var sWidth, sHeight;
	var array1 = getClientPageSize();
	sWidth = array1[0];
	//sHeight = array1[1];
	//使用新的函数
	sHeight = BackGroudFont.backGroudFontHieght();
	//sWidth = BackGroudFont.backGroudFontWidth();
	//生成全屏的DIV层
	var op_bgObj = document.createElement("div");
	op_bgObj.setAttribute("id", "opbgDiv");
	op_bgObj.style.position = "absolute";
	op_bgObj.style.top = 0+"px";
	op_bgObj.style.background = "#000";
	op_bgObj.style.filter = "alpha(opacity=20);-moz-opacity:0.2;opacity: 0.2;";
	op_bgObj.style.opacity = "0.6";
	op_bgObj.style.left = 0+"px";
	op_bgObj.style.width = sWidth + "px";
	op_bgObj.style.height = sHeight + "px";
	op_bgObj.style.zIndex = "1";
	var iframe = document.createElement("iframe");
	iframe.frameBoder="no";
	iframe.setAttribute("id", "markIframeId");
	iframe.style.padding=op_bgObj.style.padding;
	iframe.style.margin=op_bgObj.style.margin;
	iframe.style.top=op_bgObj.style.top;
	iframe.style.left=op_bgObj.style.left;
	iframe.style.background = "transparent";
	iframe.style.allowTransparency="true";
	iframe.style.position = "absolute";
	iframe.style.display = "block";
 	iframe.style.filter = op_bgObj.style.filter;
	iframe.style.opacity = op_bgObj.style.opacity;
	if(browser().agent=="firefox"){
		iframe.style.width= (sWidth-5)+"px";
		iframe.style.height=(sHeight-5)+"px";
	}else{
		iframe.style.width= op_bgObj.style.width;
		iframe.style.height=op_bgObj.style.height;
	}	iframe.style.zIndex =op_bgObj.style.zIndex - 1;
	document.body.appendChild(iframe);
	document.body.appendChild(op_bgObj);
}

/**
 * 默认显示层提示在客户端距中位置，添加top控制据上高度。
 */
function showdiv2(divname, widths, heights, top) {
	ShowAllSreenDiv();//显示全屏DIV
	var fdiv = document.getElementById(divname);
	var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	var clientBounds = getClientBounds();
    var xCoord = (parseInt(clientBounds.width)-parseInt(widths))/2;
    var yCoord = (parseInt(clientBounds.height)-parseInt(heights))/2;   
	if(browser().agent=="ie"){
		yCoord=parseInt(yCoord)-parseInt(top);
	}
	if(browser().agent=="firefox"){
		yCoord=parseInt(yCoord)-parseInt(top);
	}
	if(browser().agent=="opera"){
		yCoord=parseInt(yCoord)-parseInt(top);
	}
	fdiv.style.position = "absolute";
	fdiv.style.left =( parseInt(scrollLeft) + parseInt(xCoord)) + "px";
	fdiv.style.width = widths +"px";
	fdiv.style.height = heights+"px" ;
	fdiv.style.top = (parseInt(scrollTop) + parseInt(yCoord)) + "px";
//	fdiv.style.backgroundColor = "#fff";
	fdiv.style.zIndex = "100";
	fdiv.style.display = "";
}
function getClientBounds(){
  var clientWidth;
  var clientHeight;
  switch(browser().agent) {
      case "ie":
          clientWidth = document.documentElement.clientWidth;
          clientHeight = document.documentElement.clientHeight;
          if(clientWidth == 0)
          	clientWidth = document.body.clientWidth;
          if(clientHeight == 0)
          	clientHeight = document.body.clientHeight;
          break;
      case "firefox":
          clientWidth = window.innerWidth;
          clientHeight = window.innerHeight;
          break;
      case "opera":
          clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
          clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
          break;
      default:
          clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
          clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
          break;
  }
   return{
            width:clientWidth,
            height:clientHeight
        }
}
function browser(){
        var agent,version;
        if (navigator.userAgent.indexOf(' MSIE ') > -1) {
            agent = "ie";
            version = parseFloat(navigator.userAgent.match(/MSIE (\d+\.\d+)/)[1].toString());
        }
        else if (navigator.userAgent.indexOf(' Firefox/') > -1) {
            agent = "firefox";
            version = parseFloat(navigator.userAgent.match(/ Firefox\/(\d+\.\d+)/)[1].toString());
        }
        else if (navigator.userAgent.indexOf(' Safari/') > -1) {
            agent = "safari";
            version = parseFloat(navigator.userAgent.match(/ Safari\/(\d+\.\d+)/)[1].toString());
        }
        else if (navigator.userAgent.indexOf('Opera/') > -1) {
            agent = "opera";
        }
        return{
            agent : agent,
            version : version
        }
    }
 //显示DIV
function showdiv(divname, widths, heights) {
	showdiv2(divname, widths, heights, 200);
}


 //关闭DIV
function closediv(divname) {
	//document.getElementById(divname).innerHTML = "";
	if(document.getElementById(divname)==null)return;
	document.getElementById(divname).style.display = "none";//关闭当前div
	var ifram = document.getElementById("markIframeId");
	if(ifram!=null) document.body.removeChild(ifram);
	var opbgObj = document.getElementById("opbgDiv");
	if(opbgObj!=null) document.body.removeChild(opbgObj);//关闭全屏div
}

 //关闭DIV 刷新页面
function closediv2(divname) {
	//document.getElementById(divname).innerHTML = "";
	if(document.getElementById(divname)==null)return;
	document.getElementById(divname).style.display = "none";//关闭当前div
	var opbgObj = document.getElementById("opbgDiv");
	if(opbgObj!=null){
		document.body.removeChild(opbgObj);//关闭全屏div
	}
	window.location.reload();
}


/**
 * 新加测试弹出层。
 * 
 */
function sAlert(){
	var obj = document.getElementById("bgMsmDiv")
	try       //对象存在,就只要显示,因为不能同时创建两个相同的DOM
	{
	   var str=obj.toString();
	   if( str.indexOf('object') != -1 )
	   {
		  obj.style.display = '';
		  return;
	   }
	}
	catch ( e ) //对象不存在
	{
		var sWidth,sHeight;
		sWidth=document.body.offsetWidth;
		sHeight=document.body.offsetHeight;
	
		var bgObj=document.createElement("div");
		bgObj.setAttribute('id','bgMsmDiv');
		bgObj.style.position="absolute";
		bgObj.style.top="0" + "px";
		bgObj.style.left="0" + "px";
		bgObj.style.background="#000";
		bgObj.style.filter="alpha(opacity=10)";
		bgObj.style.opacity="0.1";
		bgObj.style.width=sWidth + "px";
		bgObj.style.height=sHeight + "px";
		document.body.appendChild(bgObj);
	}
}

function closeAlert(){
	$1('bgMsmDiv').style.display='none';	
}


/**
 * @author 巍巍
 * 移动层脚本
 * 通过各浏览器测试
 */
function moveStart(e, _sId){
	function fixE(e) {
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
	function getX(e){ return fixE(e).clientX; };
	function getY(e){	return fixE(e).clientY; };
	function drag(e){
		v = document.getElementById(_sId);
		var nX = getX(e);
		var nY = getY(e);
		var ll = v.rL + nX - v.oX;
		var tt = v.rT + nY - v.oY;
		v.style.left = ll + 'px';
		v.style.top  = tt + 'px';
		//$1('openwin').style.left = ll + 6 +'px';
		//$1('openwin').style.top = tt + 6 + 'px';
		//$1('openwin').style.left = ll + 'px';
		//$1('openwin').style.top = tt + 'px';
		return false;
	}
	function end() {
		document.onmousemove	= null;
		document.onmouseup		= null;
	}
	v = $1(_sId);
	v.oX = getX(e);
	v.oY = getY(e);
	v.rL = parseInt(v.style.left ? v.style.left : 0);
	v.rT = parseInt(v.style.top  ? v.style.top  : 0);
	document.onmousemove = drag;
	document.onmouseup	 = end;
	return false;
}
function $1(s){return document.getElementById(s);}
