// JavaScript Document
function isEmailAddr(email){
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0){
	var pindex = theStr.indexOf(".",index);
	if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function isRegist() {
	if ((document.the_form.membername.value == "") || (document.the_form.membername.value.length < 4) || (document.the_form.membername.value.length > 20)) {
		alert("请输入一个长度在4-20位的会员名称。");
		document.the_form.membername.focus();
		return false;
	} 
	if (!isEmailAddr(document.the_form.email.value)) {
		alert("请输入常用的电子邮箱地址。");
		document.the_form.email.focus();
		return false;
	} 
	if ((document.the_form.password.value == "") || (document.the_form.password.value.length < 6)) {
		alert("请输入一个长度超过6位的密码");
		document.the_form.password.focus();
		return false;
	} 
	if (document.the_form.password.value != document.the_form.password_cfm.value) {
		alert("两次输入的密码不一致");
		document.the_form.password.value="";
		document.the_form.password_cfm.value="";
		document.the_form.password.focus();
		return false;
	} 
	if ((document.the_form.truename.value == "")) {
		alert("请输入真实姓名。");
		document.the_form.truename.focus();
		return false;
	} 
	if ((document.the_form.gender.value == "")) {
		alert("请选择您的称谓。");
		document.the_form.gender.focus();
		return false;
	} 
	if ((document.the_form.country.value == 0)) {
		alert("请选择您的居住地。");
		document.the_form.country.focus();
		return false;
	} 
	if (document.the_form.jobposition.value=="") {
		alert("请输入您的职位.");
		document.the_form.jobposition.focus();
		return false;
	} 
	document.the_form.submit();
	return true;
}
function isModify() {
	
	if (!isEmailAddr(document.the_form.email.value)) {
		alert("请输入您常用的电子邮件地址！");
		document.the_form.email.focus();
		return false;
	} 
	if ((document.the_form.truename.value == "")) {
		alert("请输入真实姓名。");
		document.the_form.truename.focus();
		return false;
	} 
	if ((document.the_form.gender.value == "")) {
		alert("请选择您的称谓。");
		document.the_form.gender.focus();
		return false;
	} 
	if ((document.the_form.country.value == 0)) {
		alert("请选择您的居住地。");
		document.the_form.country.focus();
		return false;
	} 
	if (document.the_form.jobposition.value=="") {
		alert("请输入您的职位.");
		document.the_form.jobposition.focus();
		return false;
	} 
	document.the_form.submit();
	return true;
}

function popUp(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, 'infoPage', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left = 100,top = 0');");
}
function isNumComma(input) {
    var chars = ",0123456789";
    return containsCharsOnly(input,chars);
}
function containsCharsOnly(input,chars) {
    for (var inx = 0; inx < input.length; inx++) {
       if (chars.indexOf(input.charAt(inx)) == -1)
           return false;
    }
    return true;
}
 
function validate(column,value){
	if(!document.getElementById(column).value){
		alert("请填写正确的信息");
		document.getElementById(column).focus();
		return false;
	}
	xmlHttp=GetXmlHttpObject();
	var url='ajax_validate.php';
	url=url+'?column='+column+'&col_value='+value;
	xmlHttp.onreadystatechange=changed_validate; 
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);			
}
function changed_validate() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){
		 var gettext=xmlHttp.responseText.split('@@');
		document.getElementById(gettext[0]).innerHTML=gettext[1];
	}	 
} 
//国家/地区 - 省市选择
function populateCountry(inForm, selected){
	if (selected == 1){
		inForm.province.disabled = false;
		inForm.country.disabled = false;
	}else{
		inForm.province.disabled = true;
	}
}

//设定初始的selected选项
function chgSelect(value,selname){
 var opt = document.getElementById(selname).innerHTML.toString();
 var re = new RegExp(value,"g");
 opt = opt.replace(/<OPTION|<\/OPTION>| selected|value/g,"").match(/=.*?>/g).toString().replace(/=|>/g,"").replace(re,"┢").replace(/[^,┢]/g,"").indexOf("┢");
 document.getElementById(selname).getElementsByTagName("option")[opt].selected = true;
}
