function InitAjax()
{
　var ajax=false;
　try {
　　ajax = new ActiveXObject("Msxml2.XMLHTTP");
　} catch (e) {
　　try {
　　　ajax = new ActiveXObject("Microsoft.XMLHTTP");
　　} catch (E) {
　　　ajax = false;
　　}
　}
　if (!ajax && typeof XMLHttpRequest!='undefined') {
　　ajax = new XMLHttpRequest();
　}
　return ajax;
}

function checkusername(url,div)
{
　var show = document.getElementById(div);

　var ajax = InitAjax();

　ajax.open("GET", url, true);

　ajax.onreadystatechange = function() {
　　if (ajax.readyState == 4 && ajax.status == 200) {
　　　show.innerHTML = ajax.responseText;
　　}
　}
　ajax.send(null);
　
var unlen = document.creator.username.value.replace(/[^\x00-\xff]/g, "**").length;
if(unlen < 3) {
document.getElementById("show_user2").style.display = '';
document.getElementById("show_user2").innerHTML = '<br><font color=red>您輸入的用戶名小於3個字符, 請輸入一個較長的用戶名。</font>';
return;
}
if(unlen >= 3) {
document.getElementById("show_user2").style.display = 'none';
return;
}
}

function checkemail2(url,div)
{
　var show = document.getElementById(div);

　var ajax = InitAjax();

　ajax.open("GET", url, true);

　ajax.onreadystatechange = function() {
　　if (ajax.readyState == 4 && ajax.status == 200) {
　　　show.innerHTML = ajax.responseText;
　　}
　}
　ajax.send(null);
}

function checkpassword() {
var unlen = document.creator.password.value.replace(/[^\x00-\xff]/g, "**").length;
if(unlen < 8) {
document.getElementById("checkpassword").style.display = '';
document.getElementById("checkpassword").innerHTML = '<font color=red>您輸入的密碼小於8個字符, 請輸入一個較長的密碼。</font>';
}
if(unlen >= 8) {
document.getElementById("checkpassword").style.display = 'none';
}
//if (document.creator.password.value != document.creator.repassword.value){
//document.getElementById("checkpassword2").style.display = '';
//document.getElementById("checkpassword2").innerHTML = '<font color=red>兩次輸入的密碼不一致，請檢查後重試。</font>';
//} else {
//document.getElementById("checkpassword2").style.display = 'none';
//}
}

function checkpassword2() {
if (document.creator.password.value != document.creator.repassword.value){
document.getElementById("checkpassword2").style.display = '';
document.getElementById("checkpassword2").innerHTML = '<font color=red>兩次輸入的密碼不一致，請檢查後重試。</font>';
} else {
document.getElementById("checkpassword2").style.display = 'none';
}
}

function checkemail() {
if(document.creator.email.value.length!=0)
{
if (document.creator.email.value.charAt(0)=="." ||
document.creator.email.value.charAt(0)=="@"||
document.creator.email.value.indexOf('@', 0) == -1 ||
document.creator.email.value.indexOf('.', 0) == -1 ||
document.creator.email.value.lastIndexOf("@")==document.creator.email.value.length-1 ||
document.creator.email.value.lastIndexOf(".")==document.creator.email.value.length-1)
{
document.getElementById("checkemail").style.display = '';
document.getElementById("checkemail").innerHTML = '<font color=red>E-Mail 格式不正確，請檢查後重試。</font>';
return false;
}
else
{
document.getElementById("checkemail").style.display = 'none';
}
}
else
{
document.getElementById("checkemail").style.display = '';
document.getElementById("checkemail").innerHTML = '<font color=red>對不起，您的 E-Mail 尚未填寫。</font>';
return false;
}
return false;
}

var checkerror = '<img src=/images/check_error.gif width=13 height=13 align=absmiddle> <font color=red>尚未填寫</font>';
function checkLogin(easychannel) {
  	document.getElementById('show_user').style.display = 'none';
  	document.getElementById('show_email').style.display = 'none';
  	document.getElementById('checkemail').style.display = 'none';
  	document.getElementById('show_mobile').innerHTML = '';
  	document.getElementById('show_birth').innerHTML = '';
  	document.getElementById('show_occupation').innerHTML = '';
  	document.getElementById('show_buhist').innerHTML = '';
	var unlen = document.creator.username.value.replace(/[^\x00-\xff]/g, "**").length;
    if((unlen<3)) {
       document.getElementById('show_user2').innerHTML = '<br><font color=red>您輸入的用戶名小於3個字符, 請輸入一個較長的用戶名。</font>';
	   return false;
	} 
	else
	var unlen = document.creator.password.value.replace(/[^\x00-\xff]/g, "**").length;
	if((unlen<8)) {
       document.getElementById('checkpassword').innerHTML = '<font color=red>您輸入的密碼小於8個字符, 請輸入一個較長的密碼。</font>';
	   return false;
	}
	else
	if((easychannel.email.value.length==0)) {
		document.getElementById('show_email').style.display = 'block';
       document.getElementById('show_email').innerHTML = '<font color=red>對不起，您的 E-Mail 尚未填寫。</font>';
	   return false;
	}
	else
	if((easychannel.mobile.value.length==0)) {
       document.getElementById('show_mobile').innerHTML = checkerror;
	   return false;
	}
	else
	if((easychannel.year.value.length==0)) {
       document.getElementById('show_birth').innerHTML = checkerror;
	   return false;
	}
	else
	if((easychannel.month.value.length==0)) {
       document.getElementById('show_birth').innerHTML = checkerror;
	   return false;
	}
	else
	if((easychannel.day.value.length==0)) {
       document.getElementById('show_birth').innerHTML = checkerror;
	   return false;
	}
	else
	if((easychannel.buhist.value.length==0)) {
       document.getElementById('show_buhist').innerHTML = checkerror;
	   return false;
	}
	else
	if((easychannel.occupation.value.length==0)) {
       document.getElementById('show_occupation').innerHTML = checkerror;
	   return false;
	}
	else
	if((easychannel.interest.value.length==0)) {
       document.getElementById('show_interest').innerHTML = checkerror;
	   return false;
	} else {
		//easychannel.submit.disabled=true;
       return true;
	}
}

function updateseccode() {
	document.getElementById("seccode").innerHTML = '<img id="seccode" onclick="updateseccode()" src="/seccode.php?update=' + Math.random() + '" class="absmiddle" alt="如果看不清驗證碼，請點圖片刷新" />';
}
