function openWin(url, size) {
	window.open(url, "", "resizable=1,scrollbars=1,status=no,toolbar=no,location=no,menu=no,left=200,top=150," + size);
}

function openWindow(url, winName, width, height) {

	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 )) {
	
		xposition = (screen.width - width) / 2;
		
		yposition = (screen.height - height) / 2;
	
	}
	
	theproperty = "width=" + width + "," 
	
			+ "height=" + height + "," 
			
			+ "location=0," 
			
			+ "menubar=0,"
			
			+ "resizable=0,"
			
			+ "scrollbars=1,"
			
			+ "status=0," 
			
			+ "titlebar=0,"
			
			+ "toolbar=0,"
			
			+ "hotkeys=0,"
			
			+ "screenx=" + xposition + "," //仅适用于Netscape
			
			+ "screeny=" + yposition + "," //仅适用于Netscape
			
			+ "left=" + xposition + "," //IE
			
			+ "top=" + yposition; //IE 
	
	window.open(url, winName, theproperty);
}

/**
	by milaneuo,这个函数有误?
*/			
function getSelectBoxValue(selName) {
	var arrSel = document.getElementsByName(selName);
	var len = arrSel.length;
	
	// alert("len === " + len);
	for (var i = 0; i < len; ++i) {
		if (arrSel[i].checked) {
			return arrSel[i].value;
		}
	}
	
	return "";
}

function getRadioBoxValue(selName) {
	var arrSel = document.getElementsByName(selName);
	var len = arrSel.length;
	for (var i = 0; i < len; ++i) {
		if (arrSel[i].checked) {
			return arrSel[i].value;
		}
	}
	
	return "";
}

function getCheckBoxValue(selName) {
	var result = "";
	var arrSel = document.getElementsByName(selName);
	var len = arrSel.length;
	for (var i = 0; i < len; ++i) {
		if (arrSel[i].checked) {
			result += arrSel[i].value + ",";
		}
	}
	
	var strLen = result.length;
	if (strLen > 0) {		//需要去掉最后一个逗号
		result = result.substr(0, strLen - 1);
	}
	
	return result;
}

function showHiddenType(sid, hidsid) {
	if (document.getElementById(sid).value == '-1') {
		//document.getElementById(hidsid).style.display = 'block';
		document.getElementById(hidsid).style.display = 'block';
		//document.getElementById(hidsid).style.visibility = 'visible';
	} else {
		//document.getElementById(hidsid).style.height = 1;
		//alert(document.getElementById(hidsid).style.height);
		//document.getElementById(hidsid).style.display = 'none';
		//document.getElementById(hidsid).style.visibility = "";
		document.getElementById(hidsid).style.display = "none";
	}
	//document.getElementById
}

function selectAll(eid) {
	var eArray = document.getElementsByName(eid);
	for (i = 0; i < eArray.length; ++i) {
		eArray[i].checked = true;
	}
}

function unSelectAll(eid) {
	var eArray = document.getElementsByName(eid);
	for (i = 0; i < eArray.length; ++i) {
		eArray[i].checked = false;
	}
}

function strLen(str) {
	var l = str.length;
	var n = l;
	for (var i = 0; i < l; ++i) {
		if (str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255) ++n;
	}
	return n;
}

function inStr(strObj, strSub, separator) { 	//校验的字符串只能是ascii字符
	var strSubTemp = strSub.toString(); //为了转化数字
	if (strObj == strSubTemp) return 0;
	
	var tmpStr = strSubTemp + separator;
	if (strObj.indexOf(tmpStr) == 0) return 0;
	
	var tempStr = "," + strSub;
	
	var index = strObj.indexOf(tempStr);
	var lenObj = strObj.length;
	var lenSub = strSubTemp.length;
	
	if (index == -1) { /*alert("index == -1");*/ return -1; }
	
	//alert("index === " + index);
	//alert("strSubTemp.length === " + strSubTemp.length);
	//alert(index + strSubTemp.length + 1);
	//alert(lenObj);
	if (index + lenSub + 1 == lenObj) { /*alert("index + strSub.length + 1");*/ return index; }
	
	//alert(strObj.charAt(index + lenSub + 1));
	if (strObj.charAt(index + lenSub + 1) == separator) { /*alert("trObj.charAt(index + 1)");*/ return index; }
	
	//alert("at the end");
	return -1;
}

function selectFirstOption(selID) {
	var selObj = document.getElementById(selID);
	for (i = 0; i < selObj.length; ++i) {
		if (selObj[i].value != "") {
			selObj[i].selected = true;
			
			return;
		}
	}
}
function initSelectBox(selID, selValue) {
	var selObj = document.getElementById(selID);
	for (i = 0; i < selObj.length; ++i) {
		if (selObj[i].value == selValue) selObj[i].selected = true;
	}
}

function initCheckBox(chkBoxName, chkBoxValue) {
	var chkBox = document.getElementsByName(chkBoxName);
	for (i = 0; i < chkBox.length; ++i) {
		//alert(chkBox[i].value);
		if (inStr(chkBoxValue, chkBox[i].value, ",") != -1) {
			chkBox[i].checked = "checked";
		}
	}
}

function initRadioBox(radioBoxName, radioBoxValue) {
	var radioBox = document.getElementsByName(radioBoxName);
	for (i = 0; i < radioBox.length; ++i) {
		//alert(chkBox[i].value);
		if (inStr(radioBoxValue, radioBox[i].value, ",") != -1) {
			radioBox[i].checked = "checked";
		}
	}
}


function hideObj(oid) {
	document.getElementById(oid).style.display = 'none';
}

function faQControl() {
	var statusObj = document.getElementById('viewFaQControlStatus');
	var imgObj = document.getElementById('viewFaQControl');
	var status = statusObj.value;
	//alert("status === " + status);
	if (status == 'close' || status == '') {
		xajax_ajaxGetFamiliarQuestion(xajax.getFormValues("frmQ"));
		statusObj.value = 'open';
		imgObj.src = "admin/img/close_same.gif";
	} else if (status == 'open') {
		hideObj("familiarQuestion");
		statusObj.value = 'close';
		imgObj.src = "admin/img/view_same.gif";
	}
}

function refreshCaptcha() {
	document.getElementById("captchaImg").src = webRoot + "lib/cap/securimage/securimage_show.php?test=" + Math.random();
}

function parseParameter() {
  	url = document.location.href;  
	get = url.split("?")[1];  
	para = null;
	if (get!=null && get.length>0) {  
		para = get.split("&");
	}  
	
	var aID = "";
	for (i = 0; para!=null && i<para.length; ++i) {
		vars = para[i].split("=");  
		eval("var " + vars[0] + "='" + vars[1] + "'");
		var hidObj = document.getElementById(vars[0]);
		if (typeof(hidObj) != "undefined") {
			//alert(vars[1])
			hidObj.value = vars[1];
		}
	}
}

function selectAtLeastOne(selName) {
	var selValue = getCheckBoxValue(selName);
	
	if (selValue == "") {
		alert('请至少选择一条记录');
		return false;
	}
	
	return true;
}

function getBrowserType() {
	if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
		return "IE";
	} else {
		return "FF";
	}
}

function showTrElement(eleID) {
	var isIE = (getBrowserType() == "IE");
	var tElement = document.getElementById(eleID);
	
	if (isIE) {
		tElement.style.display = "block";
	} else {
		tElement.style.visibility = "visible";
		tElement.style.display = "table-row";
	}
}

function hideTrElement(eleID) {
	var isIE = (getBrowserType() == "IE");
	var tElement = document.getElementById(eleID);
	
	if (isIE) {
		tElement.style.display = "none";
		//area.style.visibility = "hidden";
	} else {
		tElement.style.visibility = "hidden";
		tElement.style.display = "none";
	}
}

function updateUserLoginInfo() {
	
	var isIE = (getBrowserType() == "IE");
	
	if (isIE && (document.readyState != 'complete')) {
		
		if (document.attachEvent) {
			document.attachEvent("onreadystatechange", function() {
				((document.readyState == "complete") && xajax_ajaxUpdateLoginInfo())
			});
		}
	} else {
		xajax_ajaxUpdateLoginInfo();
	}
}

function updateCommentInfo(moduleName, id) {
	var isIE = (getBrowserType() == "IE");
	
	if (isIE && (document.readyState != 'complete')) {
		
		if (document.attachEvent) {
			document.attachEvent("onreadystatechange", function() {
				((document.readyState == "complete") && xajax_ajaxUpdateCommentInfo(moduleName, id))
			});
		}
	} else {
		xajax_ajaxUpdateCommentInfo(moduleName, id);
	}
}