// Copyright (C) Minyoo Network, InC.
var MinyooDomain = "192.168.0.16";
var needReplaceMinyooDomain = false;
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf("opera") != -1 && opera.version();
var is_moz = (navigator.product == "Gecko") && userAgent.substr(userAgent.indexOf("firefox") + 8, 3);
var is_ie = (userAgent.indexOf("msie") != -1 && !is_opera) && userAgent.substr(userAgent.indexOf("msie") + 5, 3);
var XMLHttpReq;
var cookiePath = "/";
var cookieTime = 3600 * 24;
function isUndefined(variable) {
	return typeof variable == "undefined" ? true : false;
}

if (needReplaceMinyooDomain) {
	replaceMinyooDomain();
}

// select begin date
function selectBeginDate(ctrlobj) {
	var the_url = location.href;
	var str1 = the_url.split("//");
	var str2 = str1[1];
	var str3 = str2.split("/");
	var folder = str3[1];
	retval = window.showModalDialog("/CalendarDlg.html", "", "dialogWidth:260px; dialogHeight:210px; dialogLeft:300px; dialogTop:150px; status:no; directories:yes;scrollbars:no;Resizable=no;");
	if (retval != null) {
		retval = retval.substring(0, 10);
		ctrlobj.value = retval;
	}
}

// select end date
function selectEndDate(ctrlobj) {
	var the_url = location.href;
	var str1 = the_url.split("//");
	var str2 = str1[1];
	var str3 = str2.split("/");
	var folder = str3[1];
	retval = window.showModalDialog("/CalendarDlg.html", "", "dialogWidth:260px; dialogHeight:210px; dialogLeft:300px; dialogTop:150px; status:no; directories:yes;scrollbars:no;Resizable=no;");
	if (retval != null) {
		retval = retval.substring(0, 10);
		ctrlobj.value = retval;
	}
}

// hidden big image
function hiddenBigImage() {
	var x, y, layer;
	mlayer = document.getElementById("MinyooLayer");
	if (mlayer) {
		mlayer.innerHTML = "";
		mlayer.style.display = "none";
	}
}

// show big image
function showBigImage(id) {
	var imgsrc = "/image.jsp?id=" + id;
	var x, y, mlayer;
	x = event.clientX;
	y = event.clientY;
	mlayer = document.getElementById("MinyooLayer");
	if (mlayer) {
		mlayer.style.left = x;
		mlayer.style.top = y;
		mlayer.innerHTML = "<img onerror='doHidden(this)' src=\"" + imgsrc + "\">";
		mlayer.style.display = "block";
	}
}

// hidden article content
function hiddenArtContent() {
	var x, y, layer;
	mlayer = document.getElementById("MinyooLayer");
	if (mlayer) {
		mlayer.innerHTML = "";
		mlayer.style.display = "none";
	}
}

// show article Link for Column
function showArtLink(webid, colid, bid, currentPage, showCount) {
	var mlayer = document.getElementById("MinyooPageLoader");
	if (mlayer == null || colid == null || colid.length == 0 || bid == null || bid.length == 0|| currentPage == null || currentPage.length == 0) {
		return;
	}
	var url = "/block.jsp?webid="+webid+"&colid="+colid+"&bid="+bid+"&currentPage="+currentPage+"&showCount="+showCount;
	createXMLHttpRequest();
	XMLHttpReq.onreadystatechange = checkBackArtLink;
	XMLHttpReq.open("GET", url, true);
	XMLHttpReq.send(null);
}

function checkBackArtLink(){
	if (XMLHttpReq.readyState == 4) {
		if (XMLHttpReq.status == 200) {
			document.getElementById("MinyooPageLoader").innerHTML = XMLHttpReq.responseText;
		} else {
			alert("\u5f53\u524d\u7f51\u7edc\u72b6\u51b5\u4e0d\u597d\uff0c\u8bf7\u91cd\u8bd5\uff01");
		}
	};
}

// show article content
function showArtContent(artid) {
	var contdiv = eval("document.all.artdiv_" + artid);
	var mlayer = document.getElementById("MinyooLayer");
	if (mlayer == null || artid == null || artid.length == 0 || contdiv.innerHTML.length == 0) {
		return;
	}
	var x = event.clientX;
	var y = event.clientY;
	mlayer.style.cssText = "filter:alpha(opacity=90); border:5px solid #ffffff; BORDER-TOP: 3px outset; BORDER-BOTTOM: 3px outset; BORDER-LEFT: 3px outset; BORDER-RIGHT: 3px outset; width: 520; height: 70%; position: absolute; background-color: #3366FF; color:#FFFFFF; font-size:12px; vertical-align: middle; text-align: left; z-index:5; position: absolute;white-space:normal; width:510;";
	mlayer.style.left = x;
	mlayer.style.top = y;
	mlayer.innerHTML = "<table width='100%'><tr><td>" + contdiv.innerHTML + "</td></tr></table>";
	mlayer.style.display = "block";
}

// hidden object
function doHidden(obj) {
	if (obj) {
		obj.style.display = "none";
	}
}

// link a url
function linkURL(uobj, fobj) {
	var uo = eval("document.all." + uobj);
	var fo = eval("document.all." + fobj);
	if (uo && fo && fo.value) {
		window.open(uo.value + fo.value);
	}
}

// check file type (eg: checkFileType(this, ',jpg,jpeg,gif,png,bmp,ico,pcx,JPG,JPEG,GIF,PNG,BMP,ICO,PCX,'))
function checkFileType(obj, regex) {
	if (obj && obj.value && regex) {
		var type = obj.value.substring(obj.value.lastIndexOf(".") + 1, obj.value.length);
		if (regex.indexOf("," + type + ",") == -1) {
			alert("\u8bf7\u9009\u62e9\u6307\u5b9a\u7684\u6587\u4ef6\u7c7b\u578b\uff01");
			obj.select();
			document.execCommand("Delete");
			obj.focus();
		}
	}
}

// check url
function checkURL(url) {
	var oReq = new ActiveXObject("Microsoft.XMLHTTP");
	oReq.open("Get", url, false);
	oReq.send();
	if (oReq.status == 404) {
		return false;
	} else {
		return true;
	}
}

//old article content page 
function gotoContPage(page) {
	var pageCount = document.all.cont_page_count;
	if (!pageCount || page > pageCount.value * 1) {
		return;
	}
	var c = pageCount.value * 1;
	for (i = 1; i <= c; i++) {
		var cpo = eval("document.all.cont_page_" + i);
		var cpb = eval("document.all.page_bar_" + i);
		if (!cpo) {
			continue;
		}
		cpo.style.display = "none";
		cpb.style.background = "";
	}
	var po = eval("document.all.cont_page_" + page);
	var pb = eval("document.all.page_bar_" + page);
	if (po && pb) {
		po.style.display = "";
		pb.style.background = "#3399FF";
	}
	window.location.hash = "ArticleContent";
}

// new article content page 
function gotoContentPage(page) {
	var pageCount = document.getElementById("cont_page_count");
	if (!pageCount || page * 1 < 1 || page * 1 > pageCount.value * 1) {
		return;
	}
	var currentObj = document.getElementById("cont_page_current");
	if (!currentObj) {
		return;
	}
	currentObj.value = page;
	var c = pageCount.value * 1;
	for (i = 1; i <= c; i++) {
		var cpo = eval("document.all.cont_page_" + i);
		var cpb = eval("document.all.page_span_" + i);
		if (!cpo) {
			continue;
		}
		cpo.style.display = "none";
		cpb.className = "pc";
	}
	var po = eval("document.all.cont_page_" + page);
	var pb = eval("document.all.page_span_" + page);
	if (po && pb) {
		po.style.display = "";
		pb.className = "ps";
	}
	window.location.hash = "ArticleContent";
}

function showAllContentPage() {
	var pageCount = document.getElementById("cont_page_count");
	if (!pageCount || pageCount.value * 1 < 2) {
		return;
	}
	var c = pageCount.value * 1;
	for (i = 1; i <= c; i++) {
		var cpo = eval("document.all.cont_page_" + i);
		if (!cpo) {
			continue;
		}
		cpo.style.display = "";
	}
	window.location.hash = "ArticleContent";
}

function keydownRightOrLeft(e) {
	var pageCountObj = document.getElementById("cont_page_count");
	var currentObj = document.getElementById("cont_page_current");
	if (!pageCountObj || !currentObj) {
		return;
	}
	var nowPage = currentObj.value * 1;
	var pageCount = pageCountObj.value * 1;
    e = (e) ? e : event;
    var code = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));
   if (nowPage < pageCount) {
        if (code == 39) {
        	gotoContentPage(currentObj.value*1+1);
        }
    }
    if (nowPage > 1) {
        if (code == 37) {
        	gotoContentPage(currentObj.value*1-1);
        }
    }
}

if (typeof document.addEventListener != "undefined") {
    document.addEventListener("keydown", keydownRightOrLeft, false);
} else {
    document.attachEvent("onkeydown", keydownRightOrLeft);
}

if (typeof $ === "undefined") {
	$ = function (id) {
		return document.getElementById(id);
	};
}

/*
function $(id) {
	return document.getElementById(id);
}

Array.prototype.push = function(value) {
	this[this.length] = value;
	return this.length;
}
*/

if (typeof Array.prototype.push === "undefined") {
	Array.prototype.push = function (value) {
		this[this.length] = value;
		return this.length;
	};
}
function getCookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? "" : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
function setCookie(cookieName, cookieValue, seconds, path, domain, secure) {
	seconds = seconds ? seconds : cookieTime;
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + "=" + escape(cookieValue) + (expires ? "; expires=" + expires.toGMTString() : "") + (path ? "; path=" + path : cookiePath) + (domain ? "; domain=" + domain : "") + (secure ? "; secure" : "");
}
function attachEvent(obj, evt, func) {
	if (obj.addEventListener) {
		obj.addEventListener(evt, func, false);
	} else {
		if (obj.attachEvent) {
			obj.attachEvent("on" + evt, func);
		}
	}
}
function cancelBubble(e, returnValue) {
	if (!e) {
		return;
	}
	if (is_ie) {
		if (!returnValue) {
			e.returnValue = false;
		}
		e.cancelBubble = true;
	} else {
		e.stopPropagation();
		if (!returnValue) {
			e.preventDefault();
		}
	}
}
function checkAll(name) {
	var e = is_ie ? event : checkAll.caller.arguments[0];
	obj = is_ie ? e.srcElement : e.target;
	var arr = document.getElementsByName(name);
	var k = arr.length;
	for (var i = 0; i < k; i++) {
		arr[i].checked = obj.checked;
	}
}
function getPosition(obj) {
	var r = new Array();
	r["x"] = obj.offsetLeft;
	r["y"] = obj.offsetTop;
	while (obj = obj.offsetParent) {
		r["x"] += obj.offsetLeft;
		r["y"] += obj.offsetTop;
	}
	return r;
}
function addMouseEvent(obj) {
	var checkbox, atr, ath, i;
	atr = obj.getElementsByTagName("tr");
	for (i = 0; i < atr.length; i++) {
		atr[i].onclick = function () {
			ath = this.getElementsByTagName("th");
			checkbox = this.getElementsByTagName("input")[0];
			if (!ath.length && checkbox.getAttribute("type") == "checkbox") {
				if (this.className != "currenttr") {
					this.className = "currenttr";
					checkbox.checked = true;
				} else {
					this.className = "";
					checkbox.checked = false;
				}
			}
		};
	}
}
if (is_ie) {
	document.documentElement.addBehavior("#default#userdata");
}
function setData(key, value) {
	if (is_ie) {
		document.documentElement.load(key);
		document.documentElement.setAttribute("value", value);
		document.documentElement.save(key);
		return document.documentElement.getAttribute("value");
	} else {
		sessionStorage.setItem(key, value);
	}
}
function getData(key) {
	if (is_ie) {
		document.documentElement.load(key);
		return document.documentElement.getAttribute("value");
	} else {
		return sessionStorage.getItem(key) && sessionStorage.getItem(key).toString().length == 0 ? "" : (sessionStorage.getItem(key) == null ? "" : sessionStorage.getItem(key));
	}
}
function selectFormOption(obj, value) {
	for (var i = 0; i < obj.options.length; i++) {
		if (obj.options[i].value == value) {
			obj.options[i].selected = true;
		}
	}
}
function show(id, display) {
	if (!$(id)) {
		return false;
	}
	if (display == null || display == "auto") {
		$(id).style.display = $(id).style.display == "" ? "none" : "";
	} else {
		$(id).style.display = display;
	}
}
function trim(str) {
	return (str + "").replace(/(\s+)$/g, "").replace(/^\s+/g, "");
}
function loginOk() {
	var ok = false;
	var minyoo_uid = getCookie(minyoo_uid);
	minyoo_uid = minyoo_uid == "" ? 0 : minyoo_uid;
	if (minyoo_uid * 1 > 0 && getCookie("login_status")) {
		ok = true;
	}
	return ok;
}
function setLoginStatus(action, minyoo_uid, minyoo_user) {
	if (action == null || action == "logout" || minyoo_uid * 1 <= 0) {
		setCookie("login_status", 0);
		setCookie("minyoo_uid", 0);
		setCookie("minyoo_user", "");
	} else {
		if (action == "login") {
			setCookie("login_status", 1);
			setCookie("minyoo_uid", minyoo_uid);
			setCookie("minyoo_user", minyoo_user);
		} else {
			setCookie("login_status", 0);
			setCookie("minyoo_uid", 0);
			setCookie("minyoo_user", "");
		}
	}
}
function setValue(obj, value) {
	var obj = $(obj);
	if (obj) {
		obj.value = value;
	}
}
function isEmail(obj) {
	var ret = false;
	var obj = $(obj);
	if (obj == null || obj.value.length == 0) {
		return ret;
	} else {
		if (obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
			ret = true;
		} else {
			obj.value = "";
			obj.focus();
		}
	}
	return ret;
}

//XMLHttpRequest         
function createXMLHttpRequest() {
	if (window.XMLHttpRequest) { // Mozilla
		XMLHttpReq = new XMLHttpRequest();
		if (XMLHttpReq.overrideMimeType) {
			XMLHttpReq.overrideMimeType("text/xml");
		}
	} else {
		if (window.ActiveXObject) { // ie
			var versions = ["Microsoft.XMLHTTP", "MSXML.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP"];
			for (var i = 0; i < versions.length; i++) {
				try {
					XMLHttpReq = new ActiveXObject(versions[i]);
					if (XMLHttpReq) {
						break;
					}
				}
				catch (e) {
					/*alert(e.message);*/
				}
			}
		}
	}
}   

function sendLoginRequest() {
	if (!$("userName").value || !$("password").value) {
		alert("\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\xfb\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ub8e1");
		return false;
	}
	show("loadImg", "");
	createXMLHttpRequest();
	var url = "/passport.jsp?action=login&u=" + $("userName").value + "&p=" + $("password").value;
	XMLHttpReq.open("GET", url, true);
	XMLHttpReq.onreadystatechange = processLoginResponse;
	XMLHttpReq.send(null);
}   

function sendLogoutRequest() {
	show("loadImg", "none");
	createXMLHttpRequest();
	var url = "/passport.jsp?action=logout";
	XMLHttpReq.open("GET", url, true);
	XMLHttpReq.onreadystatechange = processLoginResponse;
	XMLHttpReq.send(null);
}   

function processLoginResponse() {
	if (XMLHttpReq.readyState == 4) {
		if (XMLHttpReq.status == 200) {
			displayLoginInfo();
		} else {
			window.alert("\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u04b3\ufffd\ufffd\ufffd\ufffd\ufffd\ucce3\ufffd\ufffd");
		}
	}
}

function displayLoginInfo() {
	if (XMLHttpReq) {
		var uid = trim(XMLHttpReq.responseText);
		if (uid * 1 > 0) {
			showLogoutWapper(uid, $("userName").value);
		} else {
			if (uid * 1 == 0) {
				showLoginWapper();
			} else {
				showFailedWapper();
			}
		}
	}
}

function showLoginWapper() {
	setLoginStatus("logout", "", "");
	show("loginForm", "");
	show("loginOK", "none");
	show("loadImg", "none");
	$("loginOK").innerHTML = "";
}

function showLogoutWapper(uid, userName) {
	setLoginStatus("login", uid, userName);
	show("loginForm", "none");
	show("loginOK", "");
	$("loginOK").innerHTML = "\ufffd\ufffd\xe3\ufffd" + userName + " \ufffd\ufffd\u04ed\ufffd\ufffd4\ufffd\ufffd&nbsp;<input type=\"button\" value=\"\u05e2  \ufffd\ufffd\" style=\"font:12px\" name=\"logoutButton\" onClick=\"sendLogoutRequest()\">";
}

function showFailedWapper() {
	show("loadImg", "none");
	setValue("password", "");
	alert("\ufffd\xfb\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u06bb\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0523\ufffd");
}

function initLoginForm() {
	var login_status = getCookie("login_status");
	var minyoo_uid = getCookie("minyoo_uid");
	var minyoo_user = getCookie("minyoo_user");
	login_status = (login_status != null && login_status.length == 1) ? login_status : "0";
	minyoo_uid = (minyoo_uid != null && minyoo_uid.length > 0) ? minyoo_uid : "0";
	minyoo_user = (minyoo_uid != null && minyoo_user.length > 0) ? minyoo_user : "";
	if (login_status * 1 > 0 && minyoo_uid * 1 > 0 && trim(minyoo_user).length > 0) {
		showLogoutWapper(minyoo_uid, minyoo_user);
	} else {
		showLoginWapper();
	}
}

function sendRegisterRequest() {
	if (!$("userName").value) {
		alert("\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\xfb\ufffd\ufffd\ufffd");
		return false;
	}
	if (!$("password").value) {
		alert("\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ub8e1");
		return false;
	}
	if (!isEmail("email")) {
		alert("\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0237\ufffd\ufffdEmail\ufffd\ufffd");
		return false;
	}
	show("loadImg", "");
	createXMLHttpRequest();
	var url = "/passport.jsp?action=register&u=" + $("userName").value + "&p=" + $("password").value + "&e=" + $("email").value;
	XMLHttpReq.open("GET", url, true);
	XMLHttpReq.onreadystatechange = processRegisterResponse;
	XMLHttpReq.send(null);
}   

function processRegisterResponse() {
	if (XMLHttpReq.readyState == 4) {
		if (XMLHttpReq.status == 200) {
			displayRegisterInfo();
		} else {
			window.alert("\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u04b3\ufffd\ufffd\ufffd\ufffd\ufffd\ucce3\ufffd\ufffd");
		}
	}
}

function displayRegisterInfo() {
	if (XMLHttpReq) {
		var uid = trim(XMLHttpReq.responseText);
		show("loadImg", "none");
		if (uid * 1 > 0) {
			showLogoutWapper2(uid, $("userName").value);
		} else {
			if (uid == -1) {
				alert("\ufffd\xfb\ufffd\ufffd\ufffd\ufffd\u03f7\ufffd\ufffd\ufffd");
			} else {
				if (uid == -2) {
					alert("\ufffd\ufffd\u04aa\ufffd\ufffd\ufffd\ufffd\u05e2\ufffd\ufffd\u0134\ufffd\ufffd\uf8e1");
				} else {
					if (uid == -3) {
						alert("\ufffd\xfb\ufffd\ufffd\ufffd\ufffd\u047e\ufffd\ufffd\ufffd\ufffd\u06a3\ufffd");
					} else {
						if (uid == -4) {
							alert("Email\ufffd\ufffd\u02bd\ufffd\ufffd\ufffd\ufffd");
						} else {
							if (uid == -5) {
								alert("Email\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u05e2\ufffd\u18e1");
							} else {
								if (uid == -6) {
									alert("Email\ufffd\u047e\ufffd\ufffd\ufffd\u05e2\ufffd\u18e1");
								} else {
									alert("\u03b4\ufffd\ufffd\ufffd\ufffd\u0134\ufffd\ufffd\ufffd");
								}
							}
						}
					}
				}
			}
		}
	}
}

function showLogoutWapper2(uid, userName) {
	setLoginStatus("login", uid, userName);
	show("registerForm", "none");
	show("loginOK", "");
	$("loginOK").innerHTML = "\ufffd\ufffd\u03f2\ufffd\ufffd\u05e2\ufffd\ufffd\u0279\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u05e1\ufffd\ufffd\ufffd\ufffd\xfb\ufffd\ufffd\ufffd[" + userName + "] \ufffd\ufffd&nbsp;<input type=\"button\" value=\"\u05e2  \ufffd\ufffd\" style=\"font:12px\" name=\"logoutButton\" onClick=\"sendLogoutRequest()\">&nbsp;<input type=\"button\" value=\"\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u04b3\" style=\"font:12px\" name=\"homeButton\" onClick=\"window.location = '/';\">";
	//window.location = "/";
}

function isChinese_(str){
	var lst = /[u4E00-u9FA5|,|.|*|?|!|'|"|\[|\]|\{|\}|+|-|\/|:|;| ]/g;
	return !lst.test(str);  
}

function limitWord_(node, num) {
	var o = document.getElementById(node);
	if (o) {
		o.innerHTML = getLimitString_(o.innerHTML, num)
	}
}

function getLimitString_(str, num) {
	var strlength = 0;
	for (var i=0; i<str.length; i++){
		if(strlength <= num){
			if (isChinese_(str.charAt(i))==true) {
				strlength = strlength + 2;
			    num++;
			} else {
				strlength = strlength + 1;
			}
		}else{
			str = str.substring(0,i);
			break;
		}
	}	
	return str + ((strlength>num)?"...":"");
}

function enterPressSubmit(e, key){
	var e = e || window.event; 
	if(e.keyCode == 13){ 
		document.getElementById(key).click(); 
	} 
}

function getMinyooDomain() {
	return document.location.href.replace("http://", "").replace("https://", "").split("/")[0];
}

function replaceMinyooDomain() {
	//document.body.innerHTML = document.body.innerHTML.replace(MinyooDomain, getMinyooDomain());
	var minyooVideoLayer001 = document.all.MinyooVideoLayer001;
	if (minyooVideoLayer001) {
		minyooVideoLayer001.src = minyooVideoLayer001.src.replace(MinyooDomain, getMinyooDomain());
	}
}