/*-------------------------------------------------------------------------------------------------------------------
 Script Name: functions.js
 Author: Tony Wei (魏志國)  tonywei123_at_gmail.com
 Description: JavaScript 共用函式庫
 Revision History:
   1.0: original version 2010/1/11
-------------------------------------------------------------------------------------------------------------------*/



// -------------------------------------------------------------------------------------------------------------------------------------------
// 附加於 windows.onload 函式
// -------------------------------------------------------------------------------------------------------------------------------------------
var _qs = new Querystring();
var _fn = "";
if ( _qs.get("fn") != null ) {
	_fn = _qs.get("fn");
}
switch( _fn ) {

	case "resume_register_1":
		if ( window.attachEvent ) window.attachEvent( "onload", resume_register_1_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", resume_register_1_winload, false );	 // Mozilla
		break;

	case "resume_register_2":
		if ( window.attachEvent ) window.attachEvent( "onload", resume_register_2_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", resume_register_2_winload, false );	 // Mozilla
		break;

	case "resume_register_3":
		if ( window.attachEvent ) window.attachEvent( "onload", resume_register_3_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", resume_register_3_winload, false );	 // Mozilla
		break;

	case "resume_register_4":
		if ( window.attachEvent ) window.attachEvent( "onload", resume_register_4_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", resume_register_4_winload, false );	 // Mozilla
		break;

	case "resume_register_5":
		if ( window.attachEvent ) window.attachEvent( "onload", resume_register_5_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", resume_register_5_winload, false );	 // Mozilla
		break;

	case "resume_edit_4":
		if ( window.attachEvent ) window.attachEvent( "onload", resume_edit_4_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", resume_edit_4_winload, false );	 // Mozilla
		break;

	case "job_list":
		if ( window.attachEvent ) window.attachEvent( "onload", job_list_winload );	// IE
		if ( window.addEventListener ) document.addEventListener( "DOMContentLoaded", job_list_winload, false );	 // Mozilla
		break;

}

// 清除 cookie
if ( location.href.indexOf( "&l=1" ) > -1 ) {
	setCookie( "sCookieChain1", "", 0 );
	setCookie( "sCookieChain2", "", 0 );
	setCookie( "sCookieChain3", "", 0 );
	setCookie( "sCookieChain4", "", 0 );
}

// 履歷登錄 -- Step1
function resume_register_1_winload()
{
	if ( getCookie( "sCookieChain1" ) != "" ) {

		var sCookieChain = getCookie( "sCookieChain1" );
		var sArray = sCookieChain.split( "`" );
		document.getElementById( "MI_Name" ).value			= sArray[ 0 ];
		document.getElementById( "MI_ID" ).value				= sArray[ 1 ];
		document.getElementById( "MI_Birthday" ).value	= sArray[ 2 ];
		document.getElementById( "MI_High" ).value			= sArray[ 3 ];
		document.getElementById( "MI_Weight" ).value		= sArray[ 4 ];

		document.getElementById( "MI_Sex"					+ getCookie( "MI_Sex" ) ).checked = true;
		document.getElementById( "MI_Marriage"		+ getCookie( "MI_Marriage" ) ).checked = true;
		document.getElementById( "MI_Identity"			+ getCookie( "MI_Identity" ) ).checked = true;
		document.getElementById( "MI_CarLicence"		+ getCookie( "MI_CarLicence" ) ).checked = true;
		document.getElementById( "MI_Car"					+ getCookie( "MI_Car" ) ).checked = true;
		if ( document.getElementById( "MI_Sex0" ).checked ) {
			do_sex(0);
		} else {
			document.getElementById( "MI_Military"			+ getCookie( "MI_Military" ) ).checked = true;
		}
	}
}

// 履歷登錄 -- Step2
function resume_register_2_winload()
{
	if ( getCookie( "sCookieChain2" ) != "" ) {

		var sCookieChain = getCookie( "sCookieChain2" );
		var sArray = sCookieChain.split( "`" );
		document.getElementById( "MI_Email" ).value			= sArray[ 0 ];
		document.getElementById( "MI_TelZone" ).value		= sArray[ 1 ];
		document.getElementById( "MI_Tel" ).value				= sArray[ 2 ];
		document.getElementById( "MI_Mobile" ).value		= sArray[ 3 ];
		document.getElementById( "MI_Address" ).value		= sArray[ 4 ];

		document.getElementById( "city" ).selectedIndex			= parseInt( getCookie( "city" ) );
		change_city();
		document.getElementById( "cityarea" ).selectedIndex	= parseInt( getCookie( "cityarea" ) );
	}
}

// 履歷登錄 -- Step3
function resume_register_3_winload()
{
	if ( getCookie( "sCookieChain3" ) != "" ) {

		var sCookieChain = getCookie( "sCookieChain3" );
		var sArray = sCookieChain.split( "`" );
		document.getElementById( "MI_Experience" ).value			= sArray[ 0 ];
		document.getElementById( "MI_School" ).value					= sArray[ 1 ];
		document.getElementById( "MI_Department" ).value			= sArray[ 2 ];
		document.getElementById( "MI_Pay" ).value							= sArray[ 3 ];
		document.getElementById( "MI_Location" ).value				= sArray[ 4 ];
		document.getElementById( "MI_StartDate" ).value				= sArray[ 5 ];
		document.getElementById( "MI_OtherContact" ).value		= sArray[ 6 ];
		document.getElementById( "MI_Am" ).value							= sArray[ 7 ];
		document.getElementById( "MI_Pm" ).value							= sArray[ 8 ];
		document.getElementById( "MI_SalesExperience" ).value	= sArray[ 9 ];

		document.getElementById( "MI_Status"					+ getCookie( "MI_Status" ) ).checked = true;
		document.getElementById( "MI_IsSales"		+ getCookie( "MI_IsSales" ) ).checked = true;

		var sCookieChain = getCookie( "MI_Contact" );
		var sArray = sCookieChain.split( "`" );
		document.getElementById( "MI_Contact1" ).checked = ( sArray[ 0 ] == "1" );
		document.getElementById( "MI_Contact2" ).checked = ( sArray[ 1 ] == "1" );
		document.getElementById( "MI_Contact3" ).checked = ( sArray[ 2 ] == "1" );
		document.getElementById( "MI_Contact4" ).checked = ( sArray[ 3 ] == "1" );

		document.getElementById( "MI_Education" ).selectedIndex = parseInt( getCookie( "MI_Education" ) );
	}
}

// 履歷登錄 -- Step4
function resume_register_4_winload()
{
	if ( getCookie( "sCookieChain4" ) != "" ) {

		var sCookieChain = getCookie( "sCookieChain4" );
		var sArray = sCookieChain.split( "`" );
		document.getElementById( "MI_OtherLanguage" ).value		= sArray[ 0 ];
		document.getElementById( "MI_Skill1" ).value							= sArray[ 1 ];
		document.getElementById( "MI_Skill2" ).value							= sArray[ 2 ];
		document.getElementById( "MI_Skill3" ).value							= sArray[ 3 ];
	
		var sCookieChain = getCookie( "MI_Language" );
		var sArray = sCookieChain.split( "`" );
		document.getElementById( "MI_Language1" ).checked = ( sArray[ 0 ] == "1" );
		document.getElementById( "MI_Language2" ).checked = ( sArray[ 1 ] == "1" );
		document.getElementById( "MI_Language3" ).checked = ( sArray[ 2 ] == "1" );
		document.getElementById( "MI_Language4" ).checked = ( sArray[ 3 ] == "1" );
		document.getElementById( "MI_Language5" ).checked = ( sArray[ 4 ] == "1" );

		check_other_language();
	}
}

// 履歷登錄 -- Step5
function resume_register_5_winload()
{
	if ( getCookie( "MI_Autobiography" ) != "" ) {
		document.getElementById( "MI_Autobiography" ).value = getCookie( "MI_Autobiography" );
	}
}

// 履歷修改 -- Step4
function resume_edit_4_winload()
{
		check_other_language();
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 職缺搜尋
var oldCity	= "";
var oldArea	= "";
var oldStore	= "";
var oldJob		= "";
function job_list_winload()
{

	if ( oldCity != "" ) {
		for ( var i=0 ; i < document.getElementById( "city" ).options.length ; i++ )
		{
			if ( document.getElementById( "city" ).options[ i ].value == oldCity ) {
				document.getElementById( "city" ).selectedIndex = i;
			}
		}
		x_change_city();
	}

	if ( oldArea != "" ) {
		for ( var i=0 ; i < document.getElementById( "area" ).options.length ; i++ )
		{
			if ( document.getElementById( "area" ).options[ i ].value == oldArea ) {
				document.getElementById( "area" ).selectedIndex = i;
			}
		}
		x_change_area();
	}

	if ( oldStore != "" ) {
		for ( var i=0 ; i < document.getElementById( "store" ).options.length ; i++ )
		{
			if ( document.getElementById( "store" ).options[ i ].value == oldStore ) {
				document.getElementById( "store" ).selectedIndex = i;
			}
		}
	}

	if ( oldJob != "" ) {
		for ( var i=0 ; i < document.getElementById( "jno" ).options.length ; i++ )
		{
			if ( document.getElementById( "jno" ).options[ i ].value == oldJob ) {
				document.getElementById( "jno" ).selectedIndex = i;
			}
		}
	}

}

// -------------------------------------------------------------------------------------------------------------------------------------------







// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷登錄 -- Step1
function check_resume_register_1( fm )
{
	if ( ! check_required( 'MI_Name', '姓名' ) ) return false;
	if ( document.getElementById( "MI_ID" ).value.toUpperCase() == "A123456789" ) {
		alert( "此為無效的身份證字號!" );
		fm.MI_ID.focus();
		return false;
	}
	if ( ! check_required( 'MI_ID', '身分證字號' ) ) return false;
	var firstChar = fm.MI_ID.value.substr( 0, 1 ).toUpperCase();
	if ( firstChar >= "A" && firstChar <= "Z" ) {
		if ( fm.MI_ID.value.length != 10 ) {
			alert( "身份證字號必須是 10 個字!" );
			fm.MI_ID.focus();
			return false;
		}
	}
	if ( ! check_member_account() ) {
		return false;
	}
	if ( ! check_required( 'MI_Password', '密碼' ) ) return false;
	if ( fm.MI_Password.value.length < 4 ) {
		alert( "密碼至少須為 4 個字以上!" );
		fm.MI_Password.value = "";
		fm.MI_Password2.value = "";
		fm.MI_Password.focus();
		return false;
	}
	if ( ! check_required( 'MI_Password2', '密碼確認' )   ) return false;
	if ( fm.MI_Password.value != fm.MI_Password2.value ) {
		alert( "密碼與密碼確認須一致!" );
		fm.MI_Password.value = "";
		fm.MI_Password2.value = "";
		fm.MI_Password.focus();
		return false;
	}
	if ( ! check_required( 'MI_High', '身高' ) ) return false;
	if ( ! check_numeric( 'MI_High', '身高' ) ) return false;
	if ( ! check_range( "MI_High", 100, 220, "身高" ) ) return false;
	if ( ! check_required( 'MI_Weight', '體重' ) ) return false;
	if ( ! check_numeric( 'MI_Weight', '體重' ) ) return false;
	if ( ! check_range( "MI_Weight", 40, 150, "體重" ) ) return false;
	if ( fm.MI_Sex1.checked ) {
		if ( ! ( fm.MI_Military1.checked || fm.MI_Military2.checked || fm.MI_Military3.checked || fm.MI_Military4.checked || fm.MI_Military5.checked ) ) {
			alert( "請點選兵役狀況!" );
			fm.MI_Military1.focus();
			return false;
		}
		if ( fm.MI_ID.value.substr( 1, 1 ) != "1" ) {
			alert( "您輸入的身分證字號與性別不符!" );
			return false;
		}
	} else {
		if ( fm.MI_ID.value.substr( 1, 1 ) != "2" ) {
			alert( "您輸入的身分證字號與性別不符!" );
			return false;
		}
	}
	if ( fm.MI_Picture.value != "" ) {
		if ( ! checkExt( fm.MI_Picture.value ) ) return false;
	}

	// 解決 IE6 Cookie 數量限制的問題
	var sCookieChain = "";
	sCookieChain += document.getElementById( "MI_Name" ).value + "`";
	sCookieChain += document.getElementById( "MI_ID" ).value + "`";
	sCookieChain += document.getElementById( "MI_Birthday" ).value + "`";
	sCookieChain += document.getElementById( "MI_High" ).value + "`";
	sCookieChain += document.getElementById( "MI_Weight" ).value;
	setCookie( "sCookieChain1", sCookieChain, 0.01 );

	setCookie( "MI_Sex", ( fm.MI_Sex1.checked ? "1" : "0" ), 0.01 );
	setCookie( "MI_Marriage", ( fm.MI_Marriage1.checked ? "1" : "2" ), 0.01 );

	for ( var i=1 ; i <= 5 ; i++ ) {   if ( document.getElementById( "MI_Military" + i ).checked ) {   setCookie( "MI_Military", i, 0.01 );   }   }
	for ( var i=1 ; i <= 3 ; i++ ) {   if ( document.getElementById( "MI_Identity" + i ).checked ) {   setCookie( "MI_Identity", i, 0.01 );   }   }
	for ( var i=1 ; i <= 4 ; i++ ) {   if ( document.getElementById( "MI_CarLicence" + i ).checked ) {   setCookie( "MI_CarLicence", i, 0.01 );   }   }
	for ( var i=1 ; i <= 4 ; i++ ) {   if ( document.getElementById( "MI_Car" + i ).checked ) {   setCookie( "MI_Car", i, 0.01 );   }   }

}

// 照片上傳
var exts = "jpg";

function checkExt( value )
{
	if(value=="")return true;
	var re = new RegExp("^.+\.("+exts+")$","i");
	if(!re.test(value))
	{
	alert( "照片請上傳 JPG 檔案!" );
	return false;
	}
	return true;
}

// 切換性別
function do_sex( iSex )
{
	for ( var i=1 ; i <= 5 ; i++ )
	{
		document.getElementById( "MI_Military" + i ).disabled = ( iSex == 1 ) ? false : true;
		if ( iSex == 0 ) {
			document.getElementById( "MI_Military" + i ).checked = false;
		}
	}
}

// 履歷查詢 -- 重新填寫
function reset_resume_register_1()
{
	document.getElementById( "uid2" ).value = "";
	document.getElementById( "pwd2" ).value = "";
}

// 履歷查詢 -- 送出查詢
function go_resume_register_1()
{
	if ( ! check_required( 'uid2', '帳號' ) ) return;
	if ( ! check_required( 'pwd2', '密碼' ) ) return;
	document.getElementById( "uid" ).value = document.getElementById( "uid2" ).value;
	document.getElementById( "pwd" ).value = document.getElementById( "pwd2" ).value;
	document.login_form.submit();
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷登錄 -- Step2
function check_resume_register_2( fm )
{
	if ( ! check_required( 'MI_Email', '電子信箱' ) ) return false;
	if ( ! check_email( 'MI_Email' ) ) return false;
	if ( fm.MI_Tel.value != "" ) {
		if ( ! check_required( 'MI_TelZone', '區碼' ) ) return false;
		if ( ! check_numeric2( 'MI_TelZone', '區碼' )     ) return false;
		if ( ! check_numeric2( 'MI_Tel', '聯絡電話' ) ) return false;
	} else {
		if ( ! check_required( 'MI_Mobile', '手機' ) ) return false;
		if ( ! check_numeric2( 'MI_Mobile', '手機' )     ) return false;
		if ( fm.MI_Mobile.value.substr( 0, 2 ) != "09" ) {
			alert( "手機號碼必須是 09 開頭!" );
			fm.MI_Mobile.focus();
			return false;
		}
		if ( fm.MI_Mobile.value.length != 10 ) {
			alert( "手機號碼必須是 10 個阿拉伯數字!" );
			fm.MI_Mobile.focus();
			return false;
		}
	}
	if ( fm.cityarea.selectedIndex < 1 ) {
		alert( "請選擇縣市鄉鎮!" );
		fm.cityarea.focus();
		return false;
	}
	if ( ! check_required( 'MI_Address', '通訊地址' ) ) return false;
	
	// 解決 IE6 Cookie 數量限制的問題
	var sCookieChain = "";
	sCookieChain += document.getElementById( "MI_Email" ).value + "`";
	sCookieChain += document.getElementById( "MI_TelZone" ).value + "`";
	sCookieChain += document.getElementById( "MI_Tel" ).value + "`";
	sCookieChain += document.getElementById( "MI_Mobile" ).value + "`";
	sCookieChain += document.getElementById( "MI_Address" ).value;
	setCookie( "sCookieChain2", sCookieChain, 0.01 );

	setCookie( "city",			fm.city.selectedIndex, 0.01 );
	setCookie( "cityarea",	fm.cityarea.selectedIndex, 0.01 );
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷登錄 -- Step3
function check_resume_register_3( fm )
{
	if ( fm.MI_Education.selectedIndex < 1 ) {
			alert( "請選取您的最高學歷!" );
			fm.MI_Education.focus();
			return false;
	}
	if ( ! check_required( 'MI_Experience', '工作經歷' ) ) return false;
	if ( ! check_required( 'MI_Pay', '希望待遇' ) ) return false;
	if ( ! check_required( 'MI_Location', '希望工作地點' ) ) return false;
	if ( ! ( fm.MI_Contact1.checked || fm.MI_Contact2.checked || fm.MI_Contact3.checked || fm.MI_Contact4.checked ) ) {
		alert( "請點選聯絡方式!" );
		fm.MI_Contact1.focus();
		return false;
	}
	if ( fm.MI_Contact4.checked ) {
		if ( ! check_required( 'MI_OtherContact', '其他聯絡方式' ) ) return false;
	}
	if ( ! check_required( 'MI_Am', '聯絡時間(am)' ) ) return false;
	if ( ! check_required( 'MI_Pm', '聯絡時間(pm)' ) ) return false;
	if ( fm.MI_IsSales1.checked ) {
		if ( fm.MI_SalesExperience.value == "請填寫之前的公司名稱及任職年資" ) {
			fm.MI_SalesExperience.value = "";
		}
		if ( ! check_required( 'MI_SalesExperience', '之前的公司名稱及任職年資' ) ) return false;
	}
	
	// 解決 IE6 Cookie 數量限制的問題
	var sCookieChain = "";
	sCookieChain += document.getElementById( "MI_Experience" ).value + "`";
	sCookieChain += document.getElementById( "MI_School" ).value + "`";
	sCookieChain += document.getElementById( "MI_Department" ).value + "`";
	sCookieChain += document.getElementById( "MI_Pay" ).value + "`";
	sCookieChain += document.getElementById( "MI_Location" ).value + "`";
	sCookieChain += document.getElementById( "MI_StartDate" ).value + "`";
	sCookieChain += document.getElementById( "MI_OtherContact" ).value + "`";
	sCookieChain += document.getElementById( "MI_Am" ).value + "`";
	sCookieChain += document.getElementById( "MI_Pm" ).value + "`";
	sCookieChain += document.getElementById( "MI_SalesExperience" ).value;
	setCookie( "sCookieChain3", sCookieChain, 0.01 );

	setCookie( "MI_Status", ( fm.MI_Status1.checked ? "1" : "2" ), 0.01 );
	setCookie( "MI_IsSales", ( fm.MI_IsSales1.checked ? "1" : "0" ), 0.01 );

	setCookie( "MI_Contact", ( fm.MI_Contact1.checked ? "1" : "0" ) + "`" + ( fm.MI_Contact2.checked ? "1" : "0" ) + "`" + ( fm.MI_Contact3.checked ? "1" : "0" ) + "`" + ( fm.MI_Contact4.checked ? "1" : "0" ), 0.01 );
	
	setCookie( "MI_Education", fm.MI_Education.selectedIndex, 0.01 );
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷登錄 -- Step4
function check_resume_register_4( fm )
{
	if ( ! ( fm.MI_Language1.checked || fm.MI_Language2.checked || fm.MI_Language3.checked || fm.MI_Language4.checked || fm.MI_Language5.checked ) ) {
		alert( "請點選語文能力!" );
		fm.MI_Language1.focus();
		return false;
	}
	if ( fm.MI_Language5.checked ) {
		if ( ! check_required( 'MI_OtherLanguage', '其他語言能力' ) ) return false;
	}
	
	// 解決 IE6 Cookie 數量限制的問題
	var sCookieChain = "";
	sCookieChain += document.getElementById( "MI_OtherLanguage" ).value + "`";
	sCookieChain += document.getElementById( "MI_Skill1" ).value + "`";
	sCookieChain += document.getElementById( "MI_Skill2" ).value + "`";
	sCookieChain += document.getElementById( "MI_Skill3" ).value;
	setCookie( "sCookieChain4", sCookieChain, 0.01 );

	setCookie( "MI_Language", ( fm.MI_Language1.checked ? "1" : "0" ) + "`" + ( fm.MI_Language2.checked ? "1" : "0" ) + "`" + ( fm.MI_Language3.checked ? "1" : "0" ) + "`" + ( fm.MI_Language4.checked ? "1" : "0" ) + "`" + ( fm.MI_Language5.checked ? "1" : "0" ), 0.01 );
}

function check_other_language()
{
	if ( document.getElementById( "MI_Language5" ).checked ) {
		document.getElementById( "span_other" ).style.visibility = "";
	} else {
		document.getElementById( "span_other" ).style.visibility = "hidden";
		document.getElementById( "MI_OtherLanguage" ).value = "";
	}
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷登錄 -- Step5
function check_resume_register_5( fm )
{
	if ( ! check_required( 'MI_Autobiography', '自傳' ) ) return false;
	setCookie( "MI_Autobiography", document.getElementById( "MI_Autobiography" ).value, 0.01 );
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷修改 -- Step1
function check_resume_edit_1( fm )
{
	if ( ! check_required( 'MI_Name', '姓名' ) ) return false;
	if ( fm.MI_Password.value != "" ) {
		if ( fm.MI_Password.value.length < 4 ) {
			alert( "密碼至少須為 4 個字以上!" );
			fm.MI_Password.value = "";
			fm.MI_Password2.value = "";
			fm.MI_Password.focus();
			return false;
		}
		if ( ! check_required( 'MI_Password2', '密碼確認' )   ) return false;
		if ( fm.MI_Password.value != fm.MI_Password2.value ) {
			alert( "密碼與密碼確認須一致!" );
			fm.MI_Password.value = "";
			fm.MI_Password2.value = "";
			fm.MI_Password.focus();
			return false;
		}
	}
	if ( ! check_required( 'MI_High', '身高' ) ) return false;
	if ( ! check_numeric( 'MI_High', '身高' ) ) return false;
	if ( ! check_range( "MI_High", 100, 220, "身高" ) ) return false;
	if ( ! check_required( 'MI_Weight', '體重' ) ) return false;
	if ( ! check_numeric( 'MI_Weight', '體重' ) ) return false;
	if ( ! check_range( "MI_Weight", 40, 150, "體重" ) ) return false;
	if ( fm.MI_Sex1.checked ) {
		if ( ! ( fm.MI_Military1.checked || fm.MI_Military2.checked || fm.MI_Military3.checked || fm.MI_Military4.checked || fm.MI_Military5.checked ) ) {
			alert( "請點選兵役狀況!" );
			fm.MI_Military1.focus();
			return false;
		}
	}
	if ( fm.MI_Picture.value != "" ) {
		if ( ! checkExt( fm.MI_Picture.value ) ) return false;
	}
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷修改 -- Step2
function check_resume_edit_2( fm )
{
	if ( ! check_required( 'MI_Email', '電子信箱' ) ) return false;
	if ( ! check_email( 'MI_Email' ) ) return false;
	if ( fm.MI_Tel.value != "" ) {
		if ( ! check_required( 'MI_TelZone', '區碼' ) ) return false;
		if ( ! check_numeric2( 'MI_TelZone', '區碼' )     ) return false;
		if ( ! check_numeric2( 'MI_Tel', '聯絡電話' ) ) return false;
	} else {
		if ( ! check_required( 'MI_Mobile', '手機' ) ) return false;
		if ( ! check_numeric2( 'MI_Mobile', '手機' )     ) return false;
		if ( fm.MI_Mobile.value.substr( 0, 2 ) != "09" ) {
			alert( "手機號碼必須是 09 開頭!" );
			fm.MI_Mobile.focus();
			return false;
		}
		if ( fm.MI_Mobile.value.length != 10 ) {
			alert( "手機號碼必須是 10 個阿拉伯數字!" );
			fm.MI_Mobile.focus();
			return false;
		}
	}
	if ( fm.cityarea.selectedIndex < 1 ) {
		alert( "請選擇縣市鄉鎮!" );
		fm.cityarea.focus();
		return false;
	}
	if ( ! check_required( 'MI_Address', '通訊地址' ) ) return false;
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷修改 -- Step3
function check_resume_edit_3( fm )
{
	if ( fm.MI_Education.selectedIndex < 1 ) {
			alert( "請選取您的最高學歷!" );
			fm.MI_Education.focus();
			return false;
	}
	if ( ! check_required( 'MI_Experience', '工作經歷' ) ) return false;
	if ( ! check_required( 'MI_Pay', '希望待遇' ) ) return false;
	if ( ! check_required( 'MI_Location', '希望工作地點' ) ) return false;
	if ( ! ( fm.MI_Contact1.checked || fm.MI_Contact2.checked || fm.MI_Contact3.checked || fm.MI_Contact4.checked ) ) {
		alert( "請點選聯絡方式!" );
		fm.MI_Contact1.focus();
		return false;
	}
	if ( fm.MI_Contact4.checked ) {
		if ( ! check_required( 'MI_OtherContact', '其他聯絡方式' ) ) return false;
	}
	if ( ! check_required( 'MI_Am', '聯絡時間(am)' ) ) return false;
	if ( ! check_required( 'MI_Pm', '聯絡時間(pm)' ) ) return false;
	if ( fm.MI_IsSales1.checked ) {
		if ( fm.MI_SalesExperience.value == "請填寫之前的公司名稱及任職年資" ) {
			fm.MI_SalesExperience.value = "";
		}
		if ( ! check_required( 'MI_SalesExperience', '之前的公司名稱及任職年資' ) ) return false;
	}
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷修改 -- Step4
function check_resume_edit_4( fm )
{
	if ( ! ( fm.MI_Language1.checked || fm.MI_Language2.checked || fm.MI_Language3.checked || fm.MI_Language4.checked || fm.MI_Language5.checked ) ) {
		alert( "請點選語文能力!" );
		fm.MI_Language1.focus();
		return false;
	}
	if ( fm.MI_Language5.checked ) {
		if ( ! check_required( 'MI_OtherLanguage', '其他語言能力' ) ) return false;
	}
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 履歷修改 -- Step5
function check_resume_edit_5( fm )
{
	if ( ! check_required( 'MI_Autobiography', '自傳' ) ) return false;
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 忘記密碼
function check_forget_password()
{
	if ( ! check_required( 'uid2', '身分證字號' ) ) return false;
	if ( ! check_required( 'cname', '姓名' ) ) return false;
}

// 會員當入
function check_login()
{
	if ( ! check_required( 'uid', '帳號' ) ) return false;
	if ( ! check_required( 'pwd', '密碼' ) ) return false;
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 職缺搜尋
function x_change_city()
{
	var city = document.getElementById( "city" );
	var cityIndex = city.options[ city.selectedIndex ].value;
	document.getElementById( "area1" ).innerHTML = "<select name='area' class='inputtext_4' id='area' onchange='x_change_area()'>" + area_array[ cityIndex ] + "</select>";
	x_change_area();
}

function x_change_area()
{
	var area = document.getElementById( "area" );
	var areaIndex = area.options[ area.selectedIndex ].value;
	document.getElementById( "store1" ).innerHTML = "<select name='store' class='inputtext_2' id='store'>" + store_array[ areaIndex ] + "</select>";
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 我要應徵
function check_job_apply()
{
	if ( ! check_required( 'AR_Text', '自我推薦' ) ) return false;
	if ( document.getElementById( "AR_Text" ).value.length > 150 ) {
		alert( "限輸入150字以內!" );
		document.getElementById( "AR_Text" ).focus();
		return false;
	}
}

// 應徵範本
function apply_template( no )
{
	document.getElementById( "AR_Text" ).value = document.getElementById( "template" + no ).value;
}

// 轉寄好友
function check_job_mailto()
{
	if ( ! check_required( 'email1', '朋友Email' ) ) return false;
	for ( var i=1 ; i <= 5 ; i++ )
	{
		if ( document.getElementById( "email" + i ).value != "" ) {
			if ( ! check_email( "email" + i ) ) return false;
		}
	}
	if ( ! check_required( 'cname', '你的姓名' ) ) return false;
	if ( ! check_required( 'sender', '你的email' ) ) return false;
	if ( ! check_email( 'sender' ) ) return false;
	if ( ! check_required( 'message', '給朋友的留言' ) ) return false;
	if ( document.getElementById( "message" ).value.length > 100 ) {
		alert( "限輸入100字以內!" );
		document.getElementById( "message" ).focus();
		return false;
	}
	if ( ! check_required( 'code', '驗證碼' ) ) return false;
	if ( ! check_numeric2( 'code', '驗證碼' )     ) return false;
	if ( ! check_code() ) return false;
}

// 預先檢查驗證碼
function check_code()
{
	var url = "index.aspx?fn=check_code&rand=" + Math.random() + "&code=" + document.getElementById( "code" ).value;
	var objTag = ccioo_ajax_getXmlData( url ).getElementsByTagName("item");
	var sReturn = objTag[0].firstChild.nodeValue;
	if ( parseInt( sReturn ) > 0 ) {
		alert( "請輸入正確的驗證碼!" );
		return false;
	}
	return true;
}

// 顯示更多朋友 Email 輸入框
function show_tr( no )
{
	document.getElementById( "tr" + no ).style.display = "";
	document.getElementById( "add" + no ).style.display = "none";
}

// 刷新驗證碼
function refresh_code( no )
{
	ccioo_ajax_setData( "index.aspx?fn=job_mailto&no=" + no + "&rand=" + Math.random() );
	document.getElementById( "code_pic" ).src = "ccioo/Image/random_image.aspx?rand=" + Math.random();
}

// -------------------------------------------------------------------------------------------------------------------------------------------
// 問與答搜尋
function check_qa_list( fm )
{
	//if ( ! check_required( 'k', '關鍵字' ) ) return false;
}


/*-------------------------------------------------------------------------------------------------------------------
 Function: check_member_account()
 Description: 檢查會員帳號是否已經有人使用
 Input: N/A
 Output: true or false
 Example: 
	check_member_account()
 Revision History:
   1.0: original version 2008/1/11
   1.1: 加入亂數，避免快取 2008/1/17
-------------------------------------------------------------------------------------------------------------------*/
function check_member_account()
{
	if ( ! check_required( 'MI_ID', '登入帳號' ) ) return false;
	var url = "index.aspx?fn=member_check&rand=" + Math.random() + "&MI_ID=" + document.getElementById("MI_ID").value;
	var objTag = ccioo_ajax_getXmlData( url ).getElementsByTagName("item");
	var sReturn = objTag[0].firstChild.nodeValue;
	if ( parseInt( sReturn ) > 0 ) {
		alert( "此帳號已經有人使用，請您換一個帳號!" );
		document.getElementById("MI_ID").focus();
		return false;
	}
	return true;
}

/*-------------------------------------------------------------------------------------------------------------------
 Function: check_date()
 Description: 檢查日期格式是否正確
 Input: 年, 月, 日
 Output: 是否驗證通過 true or false
 Example: 
	check_date( 2008, 1, 29 );
Revision History:
   1.0: original version 2008/3/7
-------------------------------------------------------------------------------------------------------------------*/
function check_date( yyyy, mm, dd )
{
	mm = parseInt( mm ) - 1;
	var day = ( new Date( yyyy, mm, dd ) ).getDate();
	if ( day != dd ) {
		if ( mm == 1 && dd == 29 ) {
			alert( yyyy + " 年不是閏年，2 月沒有 29 天喔!" );
		} else {
			alert( ( mm + 1 ) + " 月沒有 " + dd + " 天喔!" );
		}
		return false;
	}
	return true;
}

/*-------------------------------------------------------------------------------------------------------------------
 Function: check_required()
 Description: 檢查表單欄位是否有填寫
 Input: 物件ID, 訊息
 Output: 是否驗證通過 true or false
 Example: 
	check_required( "username", "姓名" );
Revision History:
   1.0: original version 2007/1/5
-------------------------------------------------------------------------------------------------------------------*/
function check_required( objID, sMessage )
{
	var objField = document.getElementById( objID );
	if ( objField.value.replace( /\s/g, "" ).length == 0 ) {
		alert( "請填寫" + sMessage + "!" );
		objField.focus();
		return false;
	}
	return true;
}

 /*-------------------------------------------------------------------------------------------------------------------
 Function: check_numeric()
 Description: 檢查表單欄位是否是數字
 Input: 物件ID, 訊息
 Output: 是否驗證通過 true or false
 Example: 
	check_numeric( "amount", "數量" );
Revision History:
   1.0: original version 2007/1/8
-------------------------------------------------------------------------------------------------------------------*/
function check_numeric( objID, sMessage )
{
	var objField = document.getElementById( objID );
	if ( isNaN( parseInt( objField.value ) ) || parseInt( objField.value ) != objField.value ) {
		alert( sMessage + "必須是數字!" );
		objField.select();
		objField.focus();
		return false;
	}
	return true;
}

 /*-------------------------------------------------------------------------------------------------------------------
 Function: check_numeric2()
 Description: 檢查表單欄位是否是數字
 Input: 物件ID, 訊息
 Output: 是否驗證通過 true or false
 Example: 
	check_numeric2( 'mobile', '手機或聯絡電話' );
Revision History:
   1.0: original version 2007/1/8
-------------------------------------------------------------------------------------------------------------------*/
function check_numeric2( objID, sMessage )
{
	var objField = document.getElementById( objID );
	var filter= /^([0-9\-\(\)#]+)$/i;
	if ( ! filter.test( objField.value ) ) {
		alert( sMessage + "必須是數字!" );
		objField.select();
		objField.focus();
		return false;
	}
	return true;
}

 /*-------------------------------------------------------------------------------------------------------------------
 Function: check_range()
 Description: 檢查表單欄位值是否介於最小值與最大值之間, 並轉換為整數
 Input: 物件ID, 最小值, 最大值, 訊息
 Output: 是否驗證通過 true or false
 Example: 
	check_range( "amount", 1, 100, "數量" );
Revision History:
   1.0: original version 2007/1/8
-------------------------------------------------------------------------------------------------------------------*/
function check_range( objID, iMin, iMax, sMessage )
{
	var objField = document.getElementById( objID );
	objField.value = parseInt( objField.value );
	iMin  = parseInt( iMin );
	iMax = parseInt( iMax );
	if ( objField.value < iMin || objField.value > iMax ) {
		alert( sMessage + "必須介於 " + iMin + " 與 " + iMax + " 之間!" );
		objField.select();
		objField.focus();
		return false;
	}
	return true;
}

 /*-------------------------------------------------------------------------------------------------------------------
 Function: check_email()
 Description: 檢查表單欄位是否是合法 Email 帳號
 Input: 物件ID, 訊息
 Output: 是否驗證通過 true or false
 Example: 
	check_email( "email" );
Revision History:
   1.0: original version 2007/1/8
-------------------------------------------------------------------------------------------------------------------*/
function check_email( objID, sMessage )
{
	var objField = document.getElementById( objID );
	var filter= /^([\w-]+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if ( ! filter.test( objField.value ) ) {
		alert( "請填寫正確的Email信箱!" );
		objField.select();
		objField.focus();
		return false;
	}
	return true;
}

/*-------------------------------------------------------------------------------------------------------------------
 Function: change_select_index()
 Description: 更改 <SELECT> 下拉選單的選取項目
 Input: 物件ID, 被選取值
 Output: N/A
 Example: 
	change_select_index( "education", "{education}" );
Revision History:
   1.0: original version 2007/1/5
-------------------------------------------------------------------------------------------------------------------*/
function change_select_index( objID, sValue )
{
	var coll = document.getElementById( objID );
	for ( i=0; i< coll.options.length ; i++ ) {
		if ( coll.options(i).value == sValue ) {
			coll.selectedIndex = i;
		}
	}
}

/*-------------------------------------------------------------------------------------------------------------------
 Function: jump_form()
 Description: 換頁, 使用 POST
 Input: 新頁碼
 Output: N/A
 Example: 
	jump_form(2);
Revision History:
   1.0: original version 2007/1/8
-------------------------------------------------------------------------------------------------------------------*/
function jump_form(p) {
	document.form1.page.value = p;
	document.form1.submit();
}

/*-------------------------------------------------------------------------------------------------------------------
 Function: jump_get()
 Description: 換頁, 使用 GET
 Input: 新頁碼
 Output: N/A
 Example: 
	jump_get(2);
Revision History:
   1.0: original version 2007/1/10
   2.0: fn 參數版 2007/6/23
   3.0: c21 專用 2010/1/13
-------------------------------------------------------------------------------------------------------------------*/
function jump_get( p, sortNumber ) {
	var qs = new Querystring();
	var tail = "";
	if ( qs.get("city") != null ) {
		tail += "&city=" + qs.get("city");
	}
	if ( qs.get("area") != null ) {
		tail += "&area=" + qs.get("area");
	}
	if ( qs.get("store") != null ) {
		tail += "&store=" + qs.get("store");
	}
	if ( qs.get("jno") != null ) {
		tail += "&jno=" + qs.get("jno");
	}
	if ( qs.get("k") != null ) {
		tail += "&k=" + encodeURI( document.getElementById('k').value );
	}
	if ( sortNumber != 0 ) {
		tail += "&sort=" + sortNumber;
	} else {
		if ( qs.get("sort") != null ) {
			tail += "&sort=" + qs.get("sort");
		}
	}
	location.href = "index.aspx?fn=" + qs.get("fn") + "&no=" + qs.get("no") + "&page=" + p + tail + "#anchor";
}

/*-------------------------------------------------------------------------------------------------------------------
 cookie Functions
 lifetype\js\cookie\cookie.js
 1.0 加入 encodeURI 編碼來儲存，以解決 Mozilla 儲存中文會導致 Cookie 資料損毀的問題 Tony in 2008/2/27
-------------------------------------------------------------------------------------------------------------------*/
function setCookie( name, value, days )
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+ encodeURI( value ) +expires+"; path=/";
}

function getCookie( name )
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return decodeURI( c.substring(nameEQ.length,c.length) );
	}
	return "";
}

function delCookie( name )
{
	setCookie(name,"",-1);
}

