function ValidLoginFrm(thisform)
{
	if (thisform.email.value=="")
	{
		alert("請 輸 入 電 郵 地 址");
//		document.thisform.email.focus();
		return false;
	}

	if (thisform.email.value.length<6 || thisform.email.value.length>100 ) {		
		alert("電郵地址不正確，請重新輸入");
		return false;
	}

	if (thisform.password.value.length<6 || thisform.password.value.length>50) {		
		alert("密碼不正確，請重新輸入");
		return false;
	}	
	return true;
}
	
function Validform(theform, type){

	error = "";
	is_number=true;
	
	if (type == 1) { 
		if (theform.email.value.length<6 || theform.email.value.length>100 ) {		
			error = "電郵必須超過6個位，但不可超過100個位<br>";
		}
		if (!isWord(theform.email.value)) {		
			error += "電郵只可由英文字母及/或數字組成<br>";
		}
		if (theform.password.value.length<6 || theform.password.value.length>10) {		
			error += "密碼必須超過6個位，但不可超過10個位<br>";
		}	
	} else {
		if (theform.password.value.length != 0 && theform.oldpassword.value.length == 0 ) {
			error += "請輸入舊密碼<br>";
    }
		if (theform.oldpassword.value.length != 0 && theform.password.value.length == 0) {
			error += "請輸入新密碼<br>";
		}		
		if (theform.password.value.length != 0 && (theform.password.value.length<6 || theform.password.value.length>10)) {		
			error += "密碼必須超過6個位，但不可超過10個位<br>";
		}
/*
        	if (theform.oldpassword.value.length == 0 ) {
			error += "請輸入舊密碼<br>";
        	}
		if (theform.password.value.length == 0) {
			error += "請輸入新密碼<br>";
		}
		if (theform.password2.value.length == 0) {
			error += "請輸入確認密碼<br>";
		}		
		if (theform.password.value.length != 0 && (theform.password.value.length<6 || theform.password.value.length>10)) {		
			error += "密碼必須超過6個位，但不可超過10個位<br>";
		}	     
*/
	}

	if (!isWord(theform.password.value)) {		
		error += "密碼只可由英文字母及/或數字組成<br>";
	}

	if (theform.password.value!=theform.password2.value) {		
		error += "請重新輸入確認密碼<br>";
	}
	
	if (!isChecked(theform.title)) {		
		error += "請選擇稱號<br>";
	}
	
	if (isblank(theform.firstname.value)) {		
		error += "請輸入名字<br>";
	}
	
	if (isblank(theform.lastname.value)) {		
		error += "請輸入姓氏<br>";
	}

	if (!isChecked(theform.gender)) {		
		error += "請選擇性別<br>";
	}
		
	if (!isDateValid(theform.b_yy.value, theform.b_mm.value, theform.b_dd.value)) {		
		error += "出生日期的"+ theform.b_mm.value + "月份只有" + getDateByMonth(theform.b_yy.value, theform.b_mm.value) + "日<br>";
	}	
		
	if (isblank(theform.phone_home.value) && isblank(theform.phone_mobile.value) && isblank(theform.phone_office.value)){
		error += "請填寫數字於聯絡電話<br>";
	}
	if (!isblank(theform.phone_home.value)) {
		if (isNaN(theform.phone_home.value)) {
			error += "請填寫數字於住宅聯絡電話<br>";
		}
	}
	if (!isblank(theform.phone_mobile.value)) {
		if (isNaN(theform.phone_mobile.value)) {
			error += "請填寫數字於流動電話聯絡電話<br>";
		}
	}
	if (!isblank(theform.phone_office.value)) {
		if (isNaN(theform.phone_office.value)) {
			error += "請填寫數字於辦公室聯絡電話<br>";
		}
	}		
		
	if (isblank(theform.email.value)) {		
		error += "請輸入電郵<br>";
	}
	if (!isblank(theform.email.value)) {
		str = theform.email.value;
		pos = str.indexOf(".") 
		if (pos <= 0) {
			error += "請輸入正確的電郵<br>";
		}
	}
			
	if (isblank(theform.address.value)) {		
		error += "請輸入地址<br>";
	}			

	if (theform.edu_level[0].selected) {		
		error += "請選擇教育程度<br>";
	}
			
	if (theform.work_exp[0].selected) {		
		error += "請選擇工作經驗<br>";
	}
	
	if (theform.isParent.checked == true) {
		if (theform.child_birth_dt_yy.value =='' || theform.child_birth_dt_mm.value =='' || theform.child_birth_dt_dd.value == '') {
			error += "孩子一的預產期或出生日期不正確<br>";
		//} else if (!isDateValid(theform.child_birth_dt_yy.value, theform.child_birth_dt_mm.value, theform.child_birth_dt_dd.value)) {		
			//error += "孩子一的預產期或出生日期的"+ theform.child_birth_dt_mm.value + "月份只有" + getDateByMonth(theform.child_birth_dt_yy.value, theform.child_birth_dt_mm.value) + "日<br>";
		}
	}
	if (theform.isParent.checked == true) {
		if (theform.child_birth_dt_yy2.value =='' || theform.child_birth_dt_mm2.value =='' || theform.child_birth_dt_dd2.value == '') {
			error += "孩子二的預產期或出生日期不正確<br>";
		//} else if (!isDateValid(theform.child_birth_dt_yy.value, theform.child_birth_dt_mm.value, theform.child_birth_dt_dd.value)) {		
			//error += "孩子二的預產期或出生日期的"+ theform.child_birth_dt_mm.value + "月份只有" + getDateByMonth(theform.child_birth_dt_yy.value, theform.child_birth_dt_mm.value) + "日<br>";
		}
	}
	if (theform.isParent.checked == true) {
		if (theform.child_birth_dt_yy3.value =='' || theform.child_birth_dt_mm3.value =='' || theform.child_birth_dt_dd3.value == '') {
			error += "孩子三的預產期或出生日期不正確<br>";
		//} else if (!isDateValid(theform.child_birth_dt_yy.value, theform.child_birth_dt_mm.value, theform.child_birth_dt_dd.value)) {		
			//error += "孩子三的預產期或出生日期的"+ theform.child_birth_dt_mm.value + "月份只有" + getDateByMonth(theform.child_birth_dt_yy.value, theform.child_birth_dt_mm.value) + "日<br>";
		}
	}
	/*
	if (theform.couple_email.value.length<6 || theform.couple_email.value.length>100 ) {		
			error = "你的另一半的電郵必須超過6個位，但不可超過100個位<br>";
	}
	*/
	/*
	if (!isblank(theform.couple_email.value)) {
		str = theform.couple_email.value;
		pos = str.indexOf(".") 
		if (pos <= 0) {
			error += "請輸入你的另一半的正確的電郵<br>";
		}
		if (theform.couple_email.value.length<6 || theform.couple_email.value.length>100 ) {		
			error += "你的另一半的電郵必須超過6個位，但不可超過100個位<br>";
		}
	}
	*/
	if (isblank(theform.alias.value)) {		
		error += "請填寫別名<br>";
	}
	if (!isblank(theform.alias.value)) {	
		if (theform.alias.value.length>15) {	
			error += "別名不可超過15個位<br>";
		}
	}			
//	if (theform.industry[0].selected) {		
//		error += "請選擇工作行業<br>";
//	}
			
	if (!isChecked(theform.course_promote)) {		
		error += "請選擇'登記「精選課程速遞」免費電郵服務'<br>";
	}

	var isEduChecked = false;
	for (checked_req_edu = 0; checked_req_edu < theform.require_edu_level.length; checked_req_edu++){
		if (theform.require_edu_level[checked_req_edu].checked) {
			isEduChecked = true;
			break;
		}
	}

	var isIntChecked = false;
	for (checked_int_course = 0; checked_int_course < theform.interest_course.length; checked_int_course++){
		if (theform.interest_course[checked_int_course].checked) {
			isIntChecked = true;
			break;
		}
	}

	//if ((!isEduChecked && !isIntChecked))  {				
	if (!isEduChecked && !isIntChecked && theform.course_promote[0].checked)  {
		error += "請選擇您感興趣的課程<br>";
	}

	if (type == 1) { 
		if (!isChecked(theform.is_jm_member)) {		
			error += "請選擇是否JobMarket會員";
		}	

		if (theform.is_jm_member[0].checked && isblank(theform.jm_login.value)) {		
			error += "請填寫閣下之JobMarket電郵<br>";
		}	

		if (theform.is_jm_member[0].checked && isblank(theform.jm_password.value)) {		
			error += "請填寫閣下之JobMarket登入密碼<br>";
		}	
		
		if (theform.join_jm.checked && theform.is_jm_member[0].checked) {
			error += "你已經登記成為JobMarket會員了，請不用選擇 '同時登記成為《求職廣場》會員' ";
		}
	}
	
	if (error) {        
		outError  = '<table width="500" border="0" align="center">';
		outError += '<tr>';
		outError += '<td class="errfont">';
		outError += '<font color="#FF0000">' + error + '</font>';
		outError += '</td>';
		outError += '</tr>';
		outError += '</table>';
		document.getElementById('ermsg').innerHTML = outError;
		document.location = "#err";
		return false;               
	}	else {	
		document.getElementById('submit_blk').innerHTML = 'Submission in process, please wait...';	// prevent button double click
		return true;
  }
}

function show_star(num) {
	if (num == 1) {
		outMsg = "* ";
	}else {
		outMsg = "&nbsp;";
	}
       document.getElementById('msg').innerHTML = outMsg;
}

function isblank(s)
{
	for(var i =0; i<s.length;i++)
	{
		var c = s.charAt(i);
		if((c!=' ') && (c!='\n') && (c!='\t')) return false;
	}
	return true;
}

function isNumber(myString){
	var regExp = /^[0-9]+$/;
	var valid = regExp.test(myString);
	return valid;
}

function checkIsNumber(myString){
	var regExp =/^[0-9\-]/;
	var valid = regExp.test(myString);
	return valid;
}

function getDateByMonth(Year, Month)
{
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0))
	{
		monthDays[1] = 29;
	}
	return monthDays[parseInt(Month)-1];
}

function isDateValid(Year, Month, Day)
{
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0))
	{
		monthDays[1] = 29;
	}

	if (!isNumber(Year))
	{
		return false;
	}
	else if (!isNumber(Month))
	{
		return false;
	}
	else if (!isNumber(Day))
	{
		return false;
	}


	if (parseInt(Month) > 12 || parseInt(Month) < 1)
	{
		return false;
	}

	if (parseInt(Day) > monthDays[parseInt(Month)-1])
	{
		return false;
	}
	else 
	{
		return true;
	}

}

function isWord(myString){
	var regExp = /^[0-9a-zA-Z_\.]*$/;
	var valid = regExp.test(myString);
	return valid;
}

function isChecked (obj)
{
	for (i=0; i < obj.length; i++)
	{
		if (obj[i].checked)
			return true;
	}
	return false;
}


function errorMessage(show, errorMsg)
{
	if (show)
	{
		return errorMsg;
	}
	else
	{
		return ""
	}
}

function selectAll(checkbox)
{
	if(checkbox != null)
	{
		for(i=0; i < checkbox.length;i++)
		{
			checkbox[i].checked = true;
		}
	}
}

function deleteViewCourseEventConfirm(theform)
{
	check = false;
	if(theform.course_id != null)
	{
		for(i=0; i < theform.course_id.length;i++)
		{
			if(theform.course_id[i].checked)
			{
				check = true;
				break;
			}
		}
	}
	else
	{
		alert("沒有任何紀錄可刪除.");
		return false;
	}
	
	if(check)
	{
		if(confirm("是否要刪除此紀錄?"))
			return true;
		else
			return false;
	}
	else
	{
		alert("請選取刪除紀錄.");
		return false;
	}
}
