﻿

//初始化火狐的按
if (check_browser() == "firefox") {
	document.captureEvents(Event.KEYDOWN)
}

//判断浏览器类型
function check_browser() {
	var Sys = {};
	var ua = navigator.userAgent.toLowerCase();
	if (window.ActiveXObject) {
		Sys.ie = ua.match(/msie ([\d.]+)/)[1];
	}
	else if (document.getBoxObjectFor) {
		Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1];
	}
	else if (window.MessageEvent && !document.getBoxObjectFor) {
		Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1];
	}
	else if (window.opera) {
		Sys.opera = ua.match(/opera.([\d.]+)/)[1];
	}
	else if (window.openDatabase) {
		Sys.safari = ua.match(/version\/([\d.]+)/)[1];
	}

	//以下进行测试 
	if (Sys.ie) {
		return "ie";
	}
	if (Sys.firefox) {
		return "firefox";
	}
	if (Sys.chrome) {
		return "chrome";
	}
	if (Sys.opera) {
		return "opera";
	}
	if (Sys.safari) {
		return "safari";
	}
}


//判断键盘事件，返回按键代码
function GetKeyCode(e) {
	if (check_browser() == "firefox") {
		return e.which;
	}
	if (check_browser() == "ie") {
		return event.keyCode;
	}
	if (check_browser() == "chrome") {
		return event.keyCode;
	}
	return 0;
}


function GetDocumentHW() //函数：获取尺寸
{
	var winWidth = 0;
	var winHeight = 0;
	//获取窗口宽度  
	if (window.innerWidth) {
		winWidth = window.innerWidth;
	}
	else if ((document.body) && (document.body.clientWidth)) {
		winWidth = document.body.clientWidth;  //获取窗口高度  
	}
	if (window.innerHeight) {
		winHeight = window.innerHeight;
	}
	else if ((document.body) && (document.body.clientHeight)) {
		winHeight = document.body.clientHeight;  //通过深入Document内部对body进行检测，获取窗口大小 
	}
	if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
		winHeight = document.documentElement.clientHeight;
		winWidth = document.documentElement.clientWidth;
	}
	return { height: winHeight, width: winWidth };
}



//获取当前鼠标的坐标
function GetMouseXY(ev) {
	var xy = new Array();
	ev = ev || window.event;
	return mouseCoords(ev);
}

function mouseCoords(ev) {
	if (ev.pageX || ev.pageY) { return { x: ev.pageX, y: ev.pageY }; }
	return { x: ev.clientX + document.documentElement.scrollLeft, y: ev.clientY + document.documentElement.scrollTop }
}


function ShowBackGroundBox(width, height, html) {
	__createBackGroundBoxDiv(width, height);
	document.getElementById("back_ground_box_context").innerHTML = html;
}
function SetBackGroundBox(html) {
    document.getElementById("back_ground_box_context").innerHTML = html;
}

function HideBackGroundBox() {
	var bg = document.getElementById("back_ground_div");
	bg.style.display = "none";
	var box = document.getElementById("back_ground_box");
	box.style.display = "none";
}

function __createBackGroundBoxDiv(width, height) {
	var screen = GetDocumentHW();
	if (!document.getElementById("back_ground_div")) {
		var bg = document.createElement("DIV");
		bg.id = "back_ground_div";
		bg.style.filter = "alpha(opacity=60)";
		bg.style.opacity = "0.6";
		bg.style.position = "absolute";
		bg.style.backgroundColor = "#000";
		bg.style.zIndex = "60000";
		bg.style.left = "0px";
		bg.style.top = "0px";
		bg.style.height = screen.height + "px";
		bg.style.width = screen.width + "px";
		document.body.appendChild(bg);

		var box = document.createElement("DIV");
		box.id = "back_ground_box";
		box.style.position = "absolute";
		box.style.backgroundColor = "#ffffff";
		box.style.zIndex = "60001";
		box.style.left = ((screen.width - width) / 2) + "px";
		box.style.top = ((screen.height - height - 16) / 2) + "px";
		box.style.height = (height + 16) + "px";
		box.style.width = width + "px";
		box.style.border = "4px solid #e4e4e4";
		var baseHtml = "<DIV style=\"TEXT-ALIGN: right\"><INPUT id=dialogBoxClose onmouseover=\"this.style.backgroundPosition='-16px 0'\" title=关闭 style=\"BORDER-RIGHT: 0px; PADDING-RIGHT: 0px; BORDER-TOP: 0px; DISPLAY: block; PADDING-LEFT: 0px; BACKGROUND: url(/templets/images/popclose.gif) no-repeat 0px 0px; FLOAT: right; PADDING-BOTTOM: 0px; MARGIN: 0px; BORDER-LEFT: 0px; WIDTH: 16px; PADDING-TOP: 0px; BORDER-BOTTOM: 0px; HEIGHT: 16px\" onclick=\"HideBackGroundBox();return false\" onmouseout=\"this.style.backgroundPosition='0 0'\" type=button><DIV style=\"CLEAR: both\"></DIV></DIV>";
		baseHtml += "<div id=\"back_ground_box_context\" style=\"height:" + height + "\"><\/div>";
		box.innerHTML = baseHtml;
		document.body.appendChild(box);
	}
	else {
		var bg = document.getElementById("back_ground_div");
		bg.style.display = "";
		var box = document.getElementById("back_ground_box");
		box.style.display = "";
		box.style.left = ((screen.width - width) / 2) + "px";
		box.style.top = ((screen.height - height) / 2) + "px";
		box.style.height = height + "px";
		box.style.width = width + "px";
	}
}




function Ajax(url, params, success, failure) {
	var xmlhttp;
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				if (success != undefined) {
					success(xmlhttp.responseText);
				}
			} else {
				if (failure != undefined) {
					failure();
				}
			}
		}
	}
	xmlhttp.open("post", url, true);
	xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

	var paramString = "";
	if (params != undefined) {
		for (var one in params) {
			if (paramString != "") {
				paramString += "&";
			}
			paramString += one + "=" + escape(params[one]);
		}
	}

	xmlhttp.send(paramString);

}

function _(elementId)
{
	return document.getElementById(elementId);
}