
function isIE() {
	if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1) {
		return true;
	} 
	else {
		return false;
	}
}
if (!isIE()) {
	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].innerText;
			} 
			else {
				if (childS[i].nodeType == 3) {
					anyString += childS[i].nodeValue;
				}
			}
		}
		return anyString;
	});
	HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
		this.textContent = sText;
	});
}
function getMsgWidth(msgC) {
	var msgSize = getCharLength(msgC);
	var msgWidth = msgSize * 9;
	if (msgWidth < 200) {
		msgWidth = 200;
	}
	if (msgWidth > 600) {
		msgWidth = 600;
	}
	return msgWidth;
}
function diyAlert(msgC, msgL) {
	customAlert(msgC, 100, getMsgWidth(msgC), "&nbsp;\u7cfb\u7edf\u63d0\u793a", "1", msgL);
}
function diyConfirm(msgC, msgL) {
	customAlert(msgC, 100, getMsgWidth(msgC), "&nbsp;\u7cfb\u7edf\u63d0\u793a", "2", msgL);
}
function diyLoading() {
	var msgW = 200;
	var msgH = 100;
	_loadingNone();
	/* 居中显示 */
	var l = (_document().body.clientWidth - msgW) / 2;
	var t = (_document().body.scrollHeight - msgH) / 2;
	var container = _document().createElement("div");
	container.id = "fatherLoadingDiv";
	var items = _document().createElement("div");
	items.style.cssText = "z-index:5001;cursor:pointer;top:" + t + "px;left:" + l + "px;width:" + msgW + "px;height:" + msgH + "px;font-size:12px;font-family:\u5b8b\u4f53;position:absolute;";
	var message = _document().createElement("div");
	message.style.cssText = "padding:10px;margin:0;line-height:130%;color:black;text-align:center;";
	message.innerHTML = "<center><img src='/js/pageCAlert/loading.gif'/></center>";
	items.appendChild(message);
	container.appendChild(items);
	var bgDiv = _document().createElement("div");
	bgDiv.innerHTML = "<iframe scrolling='no' frameborder='0' style='background-color: white;z-index:-1;position:absolute;width:100%;height:" + _document().body.scrollHeight + "px;'></iframe>";
	bgDiv.id = "childLoadingDiv";
	bgDiv.style.cssText = "z-index:5000;filter:alpha(opacity=50);left:0px;width:100%;position:absolute;top:0px;height:" + _document().body.scrollHeight + "px;background-color:#BCBCBC;moz-opacity:0.5;opacity:0.5";
	bgDiv.onmouseup = function () {
		return false;
	};
	bgDiv.onmousemove = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.ondblclick = function () {
		return false;
	};
	bgDiv.onclick = function () {
		return false;
	};
	bgDiv.oncontextmenu = function () {
		return false;
	};
	bgDiv.onselectstart = function () {
		return false;
	};
	_document().body.appendChild(container);
	_document().body.appendChild(bgDiv);
}
/*  
	msgC: 消息框的内容 string
    msgH: 消息框的高度 int
    msgW: 消息框的宽度 int
    msgT: 消息框的标题 string
    msgB: 消息框的按钮 string
    msgL: 确定后执行的函数 object
*/
function customAlert(msgC, msgH, msgW, msgT, msgB, msgL) {
	if (msgC == null) {
		return;
	}
	var butFatherDiv = _document().createElement("div");
	butFatherDiv.style.cssText = "margin-top: 10px";
	if (msgB == "1") {
		var button_ok = _addButton("\u786e  \u5b9a");
		button_ok.onclick = _butok;
		button_ok.id = "_button_ok";
		butFatherDiv.appendChild(button_ok);
	}
	if (msgB == "2") {
		var button_ok = _addButton("\u786e  \u5b9a");
		button_ok.onclick = _butok;
		button_ok.id = "_button_ok";
		butFatherDiv.appendChild(button_ok);
		var button_no = _addButton("\u53d6  \u6d88");
		button_no.onclick = _butno;
		butFatherDiv.appendChild(button_no);
	}
	_document().documentElement.scrollTop = 0;
	/* 居中显示 */
	var l = (_document().body.clientWidth - msgW) / 2;
	var t = (_document().documentElement.clientHeight - msgH) / 2;
	if (t > 220) {
		t = 220;
	}
	var container = _document().createElement("div");
	container.id = "fatherDiv";
	var items = _document().createElement("div");
	items.style.cssText = "z-index:5004;padding:0;margin:0;top:" + t + "px;left:" + l + "px;width:" + msgW + "px;height:" + msgH + "px;font-size:12px;font-family:\u5b8b\u4f53;position:absolute;";
	var title = _document().createElement("div");
	title.style.cssText = "width:100%;height:29px;line-height:29px;";
	var title_left = _document().createElement("div");
	title_left.className = "alert_title";
	title_left.style.cssText = "cursor:pointer;height: 29px;float:left;width:" + (msgW - 30) + "px;";
	title_left.onmousedown = mousedown;
	if (msgT != null && msgT.length > 0) {
		title_left.innerHTML = "<div class='alert_text'>" + msgT + "</div>";
	} 
	else {
		title_left.innerHTML = "<div class='alert_text'>\u7cfb\u7edf\u6d88\u606f</div>";
	}
	var title_right = _document().createElement("div");
	title_right.className = "alert_titleright";
	title_right.style.cssText = "float:left; margin-right:0;font-weight:bold;font-size:16px;text-align:center;width:30px;cursor: pointer;";
	title_right.onclick = _butno;
	title_right.innerHTML = "\xd7";
	var message = _document().createElement("div");
	message.className = "alert_box";
	message.innerHTML = "  " + msgC;
	message.appendChild(butFatherDiv);
	title.appendChild(title_left);
	title.appendChild(title_right);
	items.appendChild(title);
	items.appendChild(message);
	container.appendChild(items);
	var bgDiv = _document().createElement("div");
	bgDiv.innerHTML = "<iframe scrolling='no' frameborder='0' style='background-color: white;z-index:-1;position:absolute;width:100%;height:" + _document().body.scrollHeight + "px;'></iframe>";
	bgDiv.id = "childDiv";
	bgDiv.style.cssText = "z-index:5003;filter:alpha(opacity=50);left:0px;width:100%;position:absolute;top:0px;height:" + _document().body.scrollHeight + "px;background-color:#BCBCBC;moz-opacity:0.5;opacity:0.5";
	bgDiv.onmouseup = function () {
		return false;
	};
	bgDiv.onmousemove = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.ondblclick = function () {
		return false;
	};
	bgDiv.onclick = function () {
		return false;
	};
	bgDiv.oncontextmenu = function () {
		return false;
	};
	bgDiv.onselectstart = function () {
		return false;
	};
	_document().body.appendChild(container);
	_document().body.appendChild(bgDiv);
	var x, y, dragObj, oEvent;
	function mousedown() {
		try {
			oEvent = window.parent.event;
			var obj = oEvent.srcElement.parentNode.parentNode.parentNode;
			dragObj = obj;
			dragObj.onmousemove = mousemove;
			dragObj.onmouseup = mouseup;
			dragObj.setCapture();
			x = oEvent.clientX;
			y = oEvent.clientY;
		}
		catch (e) {
		}
	}
	function mousemove() {
		try {
			oEvent = window.parent.event;
			var _top = oEvent.clientY - y + parseInt(dragObj.style.top);
			var _left = oEvent.clientX - x + parseInt(dragObj.style.left);
			if (_left < 1) {
				_left = 1;
			}
			if (_top < 1) {
				_top = 1;
			}
			var sw = _document().body.scrollWidth - dragObj.offsetWidth - 1;
			var sh = _document().body.clientHeight - dragObj.offsetHeight - 1;
			if (_left > sw) {
				_left = sw;
			}
			if (_top > sh) {
				_top = sh;
			}
			try {
				dragObj.style.top = _top + "px";
				dragObj.style.left = _left + "px";
			}
			catch (e) {
			}
			x = oEvent.clientX;
			y = oEvent.clientY;
		}
		catch (e) {
		}
	}
	function mouseup() {
		dragObj.onmousemove = null;
		dragObj.onmouseup = null;
		dragObj.releaseCapture();
		dragObj = null;
	}
	title.focus();
	function _butno() {
		if (msgL != null) {
			msgL(false);
		}
		//container.style.display = "none";
		//bgDiv.style.display = "none";
		_alertNone();
	}
	function _butok() {
		if (msgL != null) {
			msgL(true);
		}
		//container.style.display = "none";
		//bgDiv.style.display = "none";
		_alertNone();
	}
}
/*  
	msgC: 消息框的内容 string
    msgH: 消息框的高度 int
    msgW: 消息框的宽度 int
    msgT: 消息框的标题 string
    msgB: 消息框的按钮 string
    msgL: 确定后执行的函数 object
*/
function openWindows(msgC, msgH, msgW, msgT, msgB, msgL) {
	if (msgC == null) {
		return;
	}
	var butFatherDiv = document.createElement("div");
	butFatherDiv.style.cssText = "margin-top: 10px";
	if (msgB == "1") {
		var button_ok = _addButton("\u786e  \u5b9a",2);
		button_ok.onclick = _butok;
		button_ok.id = "_button_ok";
		butFatherDiv.appendChild(button_ok);
	}
	if (msgB == "2") {
		var button_ok = _addButton("\u786e  \u5b9a",2);
		button_ok.onclick = _butok;
		button_ok.id = "_button_ok";
		butFatherDiv.appendChild(button_ok);
		var button_no = _addButton("\u53d6  \u6d88",2);
		button_no.onclick = _butno;
		butFatherDiv.appendChild(button_no);
	}
	document.documentElement.scrollTop = 0;
	/* 居中显示 */
	var l = (document.body.clientWidth - msgW) / 2;
	var t = (document.documentElement.clientHeight - msgH) / 2;
	if (t > 100) {
		t = t-t/2;
	}
	var container = document.createElement("div");
	container.id = "fatherDiv";
	var items = document.createElement("div");
	items.style.cssText = "z-index:5004;padding:0;margin:0;top:" + t + "px;left:" + l + "px;width:" + msgW + "px;height:" + msgH + "px;font-size:12px;font-family:\u5b8b\u4f53;position:absolute;";
	var title = document.createElement("div");
	title.style.cssText = "width:100%;height:29px;line-height:29px;";
	var title_left = document.createElement("div");
	title_left.className = "alert_title";
	title_left.style.cssText = "cursor:pointer;height: 29px;background-color:#fff;float:left;font-weight:bold;line-height:29px;width:" + (msgW - 30) + "px;";
	if (msgT != null && msgT.length > 0) {
		title_left.innerHTML = "<div class='alert_text'>" + msgT + "</div>";
	} 
	else {
		title_left.innerHTML = "<div class='alert_text'>\u7cfb\u7edf\u6d88\u606f</div>";
	}
	var title_right = document.createElement("div");
	title_right.className = "alert_titleright";
	title_right.style.cssText = "float:left; margin-right:0;font-family:\u5fae\u8f6f\u96c5\u9ed1,\u9ed1\u4f53,\u5b8b\u4f53;font-weight:bold;font-size:16px;text-align:center;width:30px;cursor: pointer;";
	title_right.onclick = _butno;
	title_right.innerHTML = "\xd7";
	var message = document.createElement("div");
	message.className = "alert_box";
	message.innerHTML = "  " + msgC;
	message.appendChild(butFatherDiv);
	title.appendChild(title_left);
	title.appendChild(title_right);
	items.appendChild(title);
	items.appendChild(message);
	container.appendChild(items);
	var bgDiv = document.createElement("div");
	bgDiv.innerHTML = "<iframe scrolling='no' frameborder='0' style='background-color: white;z-index:-1;position:absolute;width:100%;height:" + document.body.scrollHeight + "px;'></iframe>";
	bgDiv.id = "childDiv";
	bgDiv.style.cssText = "z-index:5003;filter:alpha(opacity=50);left:0px;width:100%;position:absolute;top:0px;height:" + document.body.scrollHeight + "px;background-color:#BCBCBC;moz-opacity:0.5;opacity:0.5";
	bgDiv.onmouseup = function () {
		return false;
	};
	bgDiv.onmousemove = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.ondblclick = function () {
		return false;
	};
	bgDiv.onclick = function () {
		return false;
	};
	bgDiv.oncontextmenu = function () {
		return false;
	};
	bgDiv.onselectstart = function () {
		return false;
	};
	document.body.appendChild(container);
	document.body.appendChild(bgDiv);
	title.focus();
	function _butno() {
		if (msgL != null) {
			msgL(false);
		}
		//container.style.display = "none";
		//bgDiv.style.display = "none";
		_alertNone();
	}
	function _butok() {
		if (msgL != null) {
			msgL(true);
		}
		//container.style.display = "none";
		//bgDiv.style.display = "none";
		_alertNone();
	}
}
function _document() {
	if (window.parent != null) {
		return window.parent.document;
	} 
	else {
		return window.document;
	}
}
function _alertNone() {
	try {
		var fatherDiv = _document().getElementById("fatherDiv");
		if (fatherDiv != null) {
			fatherDiv.parentNode.removeChild(fatherDiv);
		}
		if (fatherDiv == null) {
			fatherDiv = document.getElementById("fatherDiv");
			if (fatherDiv != null) {
				fatherDiv.parentNode.removeChild(fatherDiv);
			}
		}
		var childDiv = _document().getElementById("childDiv");
		if (childDiv != null) {
			childDiv.parentNode.removeChild(childDiv);
		}
		if (childDiv == null) {
			childDiv = document.getElementById("childDiv");
			if (childDiv != null) {
				childDiv.parentNode.removeChild(childDiv);
			}
		}
	}
	catch (e) {
	}
}
function _loadingNone() {
	try {
		var fatherDiv = _document().getElementById("fatherLoadingDiv");
		if (fatherDiv != null) {
			fatherDiv.parentNode.removeChild(fatherDiv);
		}
		var childDiv = _document().getElementById("childLoadingDiv");
		if (childDiv != null) {
			childDiv.parentNode.removeChild(childDiv);
		}
	}
	catch (e) {
	}
}
function _addButton(val,task) {
	var new_button;
	if(task == 2){
		new_button = document.createElement("INPUT");
	}
	else{
		new_button = _document().createElement("INPUT");
	}	
	new_button.type = "button";
	new_button.className = "botton3";
	new_button.value = val;
	new_button.onmouseover = function () {
		new_button.className = "botton1";
	};
	new_button.onmouseout = function () {
		new_button.className = "botton3";
	};
	return new_button;
}
function getCharLength(s) {
	var realLength = 0, len = s.length, charCode = -1;
	for (var i = 0; i < len; i++) {
		charCode = s.charCodeAt(i);
		if (charCode >= 0 && charCode <= 128) {
			realLength += 1;
		} 
		else {
			realLength += 2;
		}
	}
	return realLength;
}
function _location(url) {
	return function () {
		window.location.href = url;
	};
}
