// JavaScript Document
function CheckAction(objItem)
{
	var strUrl = "";
	var objForm = document.forms[0];
	ShowCategory(false);
	switch(objItem.id)
	{
		case "mnActor" :
			ShowCategory(true);
			break;
		case "mnAnnounce" :
			strUrl = "announcelist.php";
			break;
		case "mnLatest" :
			strUrl = "latestlist.php";
			break;
		case "mnBackStage" :
			strUrl = "backstagelist.php";
			break;
		case "mnSignup" :
			strUrl = "signup.php";
			break;
		case "mnContract" :
			strUrl = "contract.php";
			break;
	}
	if (strUrl != "")
		window.location.href = strUrl;
}

function ShowCategory(bShow)
{
	if (bShow)
		itemCategory.style.display = "block";
	else
		itemCategory.style.display = "none";
}

function OnMenuOver(objMenu)
{
	objMenu.className = "menuover";
}

function OnMenuOut(objMenu)
{
	objMenu.className = "menuout";
}

function OnItemOver(objItem)
{
	objItem.style.color = "blue";
}

function OnItemOut(objItem)
{
	objItem.style.color = "#333333";
}

function OnBtnOver(objBtn)
{
	objBtn.style.backgroundColor = "#ffcc00";//f7b977;"#ffcc00";//"#f6ad49";
}

function OnBtnOut(objBtn)
{
	objBtn.style.backgroundColor = "transparent";
}

function IsTelFormat(strValue)
{
	var filter = /^(\d{2,4}-)?\d{5,}(#\d{2,})?$/;
	
	if (filter.test(strValue))
		return true;
	else
		return false;
}

function IsMailFormat(strValue)
{
	var filter = /^[^@\s]+@[^@\.\s]+\.[^@\.\s]+(\.[^@\.\s]+(\.[^@\.\s]+)?)?$/;
	if (filter.test(strValue))
		return true;
	else
		return false;
}

function CheckContract()
{
	with(document.frmContract)
	{
		if (txtName.value == "" || txtTel.value == "" || 
				txtMail.value == "" || txtContent.value == "")
			alert("姓名、聯絡電話、電子信箱及內容為必填項目 !!");
		else if (!IsTelFormat(txtTel.value) && !IsMobile(txtTel.value))
			alert("聯絡電話輸入格式須為 xx-xxxxxxxx 或手機號碼(10位數) !!");
		else if (!IsMailFormat(txtMail.value))
			alert("電子信箱輸入格式不正確 !!");
		else
			submit();
	}
}

function CheckSignUp()
{
	with(document.frmSignup)
	{
		if (cname.value == "" || cbirthdate.value == "" || 
				cheight.value == "" || cweight.value == "" ||
				cphone.value == "" || cemail.value == "" ||
				ctitle.value =="" || cdescription.value == "" ||
				carea.value == "")
			alert("資料填寫不完整 !!");
		else if (file1.value == "" && file2.value == "" && file3.value == "")
			alert("至少須上傳一個附件 !!");
		else if (!IsBirthday(cbirthdate.value))
			alert("生日輸入格式為或範圍不正確(yyyy/mm/dd) !!");
		else if (!IsInteger(cheight.value))
			alert("身高輸入資料型態不正確 !!");
		else if (!IsInteger(cweight.value))
			alert("體重輸入資料型態不正確 !!");
		else if (!IsTelFormat(cphone.value) && !IsMobile(cphone.value))
			alert("聯絡電話輸入格式須為 xx-xxxxxxxx 或手機號碼(10位數) !!");
		else if (!IsMailFormat(cemail.value))
			alert("電子信箱輸入格式不正確 !!");
		else
			submit();
	}
}

function IsBirthday(strValue)
{
	var filter;
	
	filter = /^\d{4}\/(((0?[13578]|1[02])\/(0?[1-9]|[1-2][0-9]|3[01]))|(0?2\/(0?[1-9]|[1-2][0-9]))|((0?[469]|11)\/(0?[1-9]|[1-2][0-9]|30)))$/;	
	
	if (filter.test(strValue))
		return true;
	else
		return false;
}

function IsInteger(strValue)
{
	var filter = /^[\d]{1,3}$/;
	if (filter.test(strValue))
		return true;
	else
		return false;
}

function IsMobile(strValue)
{
	var filter = /^[\d]{10}$/;
	if (filter.test(strValue))
		return true;
	else
		return false;
}

function SwitchPage()
{
	window.location.href = cbxPg.value;
}