function checkSignup(f) {
		$('btnSignup').disabled = true;
		if(f.inputEmail.value.length < 7) {
			alert('กรุณากรอกข้อมูลด้วยค่ะ.');
			f.inputEmail.focus();
			checkBtn();
			return false;
		}
		if(!isEmail(f.inputEmail.value)) {
			alert('รูปแบบ E-mail ไม่ถูกต้องค่ะ.');
			f.inputEmail.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputPassword1.value.length < 6 || f.inputPassword1.value.length > 12) {
			alert('ความยาวของรหัสผ่านไม่ถูกต้องค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputPassword2.value.length < 6 || f.inputPassword2.value.length > 12) {
			alert('ความยาวของรหัสผ่านไม่ถูกต้องค่ะ.');
			f.inputPassword2.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputPassword1.value != f.inputPassword2.value) {
			alert('รหัสผ่านไม่ตรงกันค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputUsername.value.length < 4 || f.inputPassword2.value.length > 15) {
			alert('ความยาวของ ScreenName ไม่ถูกต้องค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		check_email(f.inputEmail.value,1);
		return false;
	
	}
function checkSignup_cap(f) {
		$('btnSignup').disabled = true;
		if(f.inputEmail.value.length < 7) {
			alert('กรุณากรอกข้อมูลด้วยค่ะ.');
			f.inputEmail.focus();
			checkBtn();
			return false;
		}
		if(!isEmail(f.inputEmail.value)) {
			alert('รูปแบบ E-mail ไม่ถูกต้องค่ะ.');
			f.inputEmail.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputPassword1.value.length < 6 || f.inputPassword1.value.length > 12) {
			alert('ความยาวของรหัสผ่านไม่ถูกต้องค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputPassword2.value.length < 6 || f.inputPassword2.value.length > 12) {
			alert('ความยาวของรหัสผ่านไม่ถูกต้องค่ะ.');
			f.inputPassword2.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputPassword1.value != f.inputPassword2.value) {
			alert('รหัสผ่านไม่ตรงกันค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		
		if(f.inputUsername.value.length < 4 || f.inputPassword2.value.length > 15) {
			alert('ความยาวของ ScreenName ไม่ถูกต้องค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		if(f.inputCaptchar.value.length != 5) {
			alert('ข้อความรหัสรับไม่ถูกต้องค่ะ.');
			f.inputPassword1.focus();
			checkBtn();
			return false;
		}
		check_email(f.inputEmail.value,1);
		return false;
	
	}
	function isEmail(str) {

      var supported = 0;

      if (window.RegExp) {

        var tempStr = "a";

        var tempReg = new RegExp(tempStr);

        if (tempReg.test(tempStr)) supported = 1;

      }

      if (!supported) 

      return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

      var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");

      var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

      return (!r1.test(str) && r2.test(str));

}
function checkBtn() {
	//if($('chkSignup').checked==true)  $('btnSignup').disabled = false;
	//else
	$('btnSignup').disabled = false;
	return false;
}

function keyScreenname(v) {
	var mes = 'yourname';
	if(v.length > 0) {
		$('label_onair').innerHTML = v;
		$('label_id').innerHTML = v;
		$('label_show').innerHTML = v;
	} else {
		$('label_onair').innerHTML = mes;
		$('label_id').innerHTML = mes;
		$('label_show').innerHTML = mes;
	}
	return false;
}

function check_user(username,type) {	
	var url = 'check_user_ajax.php?name='+username;
// notice the use of a proxy to circumvent the Same Origin Policy.

	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		var notice = $('name_response');
		var response = transport.responseText;
		if (response=='ok') {
			notice.update('ใช้งานได้ครับ').setStyle({ background: '#33FF66' });
			if(type == 1) { $('btnSignup').disabled = false; $('formSignup').submit();  } 
		} else if (response=='invalid_name') {
		  notice.update('ชื่อ ScreenName ไม่ถูกต้อง').setStyle({ background: '#fdd' });
		  checkBtn();
		} else if (response=='username') {
		  notice.update('ชื่อ ScreenName นี้มีผู้ใช้งานแล้วค่ะ').setStyle({ background: '#fdd' });
		  checkBtn();
		} else if (response=='username2') {
		  notice.update('ชื่อ ScreenName นี้มีผู้ใช้งานแล้วค่ะ').setStyle({ background: '#fdd' });
		  checkBtn();
		}
	  } ,
	  onFailure: function(transport) {
		  alert('ไม่พบ File ค่ะ');
		  checkBtn();
	  }
	  ,
	  onLoading : function(transport) {
		 //var notice = $('name_response');
		 //notice.update('<img src="images/icon_throbber.gif" style="border:0px;" />');
	  }
	  
	});
}
function check_email(username,type) {	
	var url = 'check_email_ajax.php?email='+username;
// notice the use of a proxy to circumvent the Same Origin Policy.

	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		var notice = $('email_response');
		var response = transport.responseText;
		if (response=='ok') {
			notice.update('ใช้งานได้ครับ').setStyle({ background: '#33FF66' });
			if(type == 1) { check_user($('inputUsername').value,1);   } 
		} else if (response=='invalid_email') {
		  notice.update('E-mail ไม่ถูกต้อง').setStyle({ background: '#fdd' });
		  checkBtn();
		} else if (response=='email') {
		  notice.update('E-mail นี้มีผู้ใช้งานแล้วค่ะ').setStyle({ background: '#fdd' });
		  checkBtn();
		}
	  } ,
	  onFailure: function(transport) {
		  alert('ไม่พบ File ค่ะ');
		  checkBtn();
	  }
	  ,
	  onLoading : function(transport) {
		 //var notice = $('email_response');
		 //notice.update('<img src="images/icon_throbber.gif" style="border:0px;" />');
	  }
	  
	});
}
function changProvince(s) {

	province = document.getElementById('inputProvince');

	if(s.value != 210) {

		province.disabled = true;

	} else {

		province.disabled = false;

	}

}

function div_switch(id,active,total) {

for(i=1;i<=total;i++) {

document.getElementById(id+i).style.display = 'none';
document.getElementById('td'+id+i).className = 'green_link1';
}

document.getElementById(id+active).style.display = '';
document.getElementById('td'+id+active).className = 'greenb_text2';
}

function confirm_box(msg){
	if(confirm(msg)==true) {
		return true;
	}
	return false;
}