﻿function getElement(which){
	try{
		if(typeof(which)=="object"){
			return which;
		}else if(document.getElementById(which)){
			return document.getElementById(which);
		}else if(document.getElementByName(which)){
			return document.getElementByName(which);
		}else if(document.all.which){
			return document.all.which;
		}else if(document.which){
			return document.which;
		}else{
			return null;
		}
	}catch(e){}
}

function ChkAll(form){
	var i=0;
	for(i; i<form.elements.length; i++){
		var e=form.elements[i];
		if(e.name!="chkall"){
			e.checked=form.chkall.checked;
		}
	}
}

function getFocus(which){
	getElement(which).select();
}

function changeImg(which,w,h){
	var thisImage=getElement(which);
	if(thisImage){
		if(thisImage.width>w){
			thisImage.width=w;
		}
		if(thisImage.height>h){
			thisImage.height=h;
		}
	}
}

function openWindow(Link,w,h){
	if(w&&h){
		window.open(Link,"","width="+w+",height="+h);
	}else{
		window.open(Link,"");
	}
}

function disableItem(itm){
	getElement(itm).disabled="disabled";
}

/*===显示编辑器手动分页内容===*/
function getNewsContent(cbound,bound){
	if(isNaN(parseInt(cbound))) return;
	if(isNaN(parseInt(bound))) return;
	
	var ContentA=getElement("contentTextA" + cbound);
	if(ContentA){
		getElement("contentHtml").innerHTML=ContentA.innerHTML;
	}
	
	for(var i=0;i<=bound;i++){
		getElement("pageArg" + i).className="";
	}
	getElement("pageArg" + cbound).className="red_text";
}

function checkRegister(isModify){
	if(isModify!=2){
		if(getElement("UserName").value.length<3||getElement("UserName").value.length>16){
			alert("未填写用户名或格式不正确，长度限制为3-16位");
			getFocus("UserName");
			return false;
		}
	}
	if(isModify==1||isModify==2){
		if(getElement("Password").value.length>0){
			if(getElement("Password").value.length<6||getElement("Password").value.length>16){
				alert("未填写密码或格式不正确，长度限制为6-16位");
				getFocus("Password");
				return false;
			}
			if(getElement("Password2").value!=getElement("Password").value){
				alert("您两次输入的密码不一致，请重新输入");
				getElement("Password").value="";
				getElement("Password2").value="";
				getFocus("Password");
				return false;
			}
		}
	}else{
		if(getElement("Password").value.length<6||getElement("Password").value.length>16){
			alert("未填写密码或格式不正确，长度限制为6-16位");
			getFocus("Password");
			return false;
		}
		if(getElement("Password2").value!=getElement("Password").value){
			alert("您两次输入的密码不一致，请重新输入");
			getElement("Password").value="";
			getElement("Password2").value="";
			getFocus("Password");
			return false;
		}
	}
	/*
	if(getElement("TrueName").value.length<2||getElement("TrueName").value.length>30){
		alert("未填写真实姓名或格式不正确，长度限制为2-30位");
		getFocus("TrueName");
		return false;
	}
	*/
	if(getElement("Question").value.length<3||getElement("Question").value.length>20){
		alert("未填写提示问题或格式不正确，长度限制为3-20位");
		getFocus("Question");
		return false;
	}
	if(getElement("Answer").value.length<3||getElement("Answer").value.length>20){
		alert("未填写提示答案或格式不正确，长度限制为3-20位");
		getFocus("Answer");
		return false;
	}
	if(getElement("Email").value.length==0||getElement("Email").value.indexOf("@")<1||getElement("Email").value.indexOf("@")==getElement("Email").value.length-1||getElement("Email").value.indexOf(".")<1||getElement("Email").value.indexOf(".")==getElement("Email").value.length-1){
		alert("未填写电子邮件或格式不正确");
		getFocus("Email");
		return false;
	}
	/*
	if(getElement("Addr").value.length<2||getElement("Addr").value.length>150){
		alert("未填写联系地址或格式不正确");
		getFocus("Addr");
		return false;
	}
	if(getElement("Phone").value.length<7||getElement("Phone").value.length>16||(isNaN(getElement("Phone").value.replace(/\-/g,"")))){
		alert("未填写联系电话或格式不正确，长度限制为7-16位");
		getFocus("Phone");
		return false;
	}
	*/
	if(getElement("CertType").value==""){
		alert("请选择证件类型");
		return false;
	}
	if(getElement("CertNumber").value.length<3||getElement("CertNumber").value.length>40){
		alert("未填写证件号码或格式不正确，长度限制为3-40位");
		getFocus("CertNumber");
		return false;
	}
}

function showmesage(id){
	try{
		var obj = document.getElementById("gpanel"+id);
		var objImg = document.getElementById("gimg"+id);
		for(var i=0; i<=20; i++){
			var iMenu = document.getElementById("gpanel"+i);
			var iImg = document.getElementById("gimg"+i);
			if(id != i && iMenu){
				iMenu.style.display = "none";
				if(iImg) iImg.src = "images/opensort.gif";
			}
		}
		
		if(obj.style.display == ""){
			obj.style.display = "none";
			objImg.src = "images/opensort.gif";
		}else{
			obj.style.display = "";
			objImg.src = "images/closesort.gif";
		}
	}catch(e){}
}