function CheckEmpty(Field, FieldTitle)
{
	if (Field.value == "")
	{
		alert("請在\"" + FieldTitle + "\"一欄中輸入內容.");
		Field.focus();
		return false;
	}

	return true;
}

function CheckInteger(Field, FieldTitle)
{
	if (Field.value != "")
	{
		for (i = 0; i < Field.value.length; i++)
		{
			ch = Field.value.charAt(i);

			if ( (ch < '0' || ch > '9') && ch != '-' ) {
				alert("\"" + FieldTitle + "\"中只能輸入數位.");
				Field.focus();
				return	false;
			}
		}
	}

	return true;
}

function CheckReal(Field, FieldTitle)
{
	if (Field.value != "")
	{
		DotNum = 0;
		for (i = 0; i < Field.value.length;  i++)
		{
			ch = Field.value.charAt(i);

			if ((ch < '0' || ch > '9') && ch != '.')
			{
				alert("\"" + FieldTitle + "\"中只能輸入數位.");
				Field.focus();
				return false;
			}

			if (ch == '.')
			{
				if (DotNum > 0)
				{
					alert("\"" + FieldTitle + "\"中只能輸入一個小數點.");
					Field.focus();
					DotNum++;
					return false;
				}
			}
		}
	}

	return	true;
}

function CheckMaxLength(Field, MaxLength, FieldTitle)
{
	if (Field.value != "")
	{
		if (Field.value.length > MaxLength)
		{
			alert("\"" + FieldTitle + "\"中輸入的字元請不要超過" + MaxLength + "字元.");
			Field.focus();
			return false;
		}
	}

	return true;
}

function CheckMinLength(Field, MinLength, FieldTitle)
{
	if (Field.value != "")
	{
		if (Field.value.length < MinLength)
		{
			alert("\"" + FieldTitle + "\"中輸入的字元請不要少於" + MinLength + "字元.");
			Field.focus();
			return false;
		}
	}

	return true;
}

function CheckOption(Field, FieldTitle)
{
	for (i = 0; i < Field.length; i++)
		if (Field[i].checked)
			return true;

	alert("請選擇\"" + FieldTitle + "\"中的值.");
	return false;
}

function Checkselect(Field, FieldTitle)
{
	if (Field.options[Field.selectedIndex].value=="")
	{
		alert("請選擇\"" + FieldTitle+"\"" );
		Field.focus();
		return false;
	}

	return true;
}

	//此函數用於判斷Email位址是否正確
function CheckEmail(Field)
{
   // there must be >= 1 character before @, so we
   // start looking at character position 1
   // (i.e. second character)
   var i = 1;
   var len = Field.value.length;
	if (len > 50)
	{
		window.alert("email位址長度不能超過50位!");
		return false;
	}
	pos1 = Field.value.indexOf("@");
	pos2 = Field.value.indexOf(".");
	pos3 = Field.value.lastIndexOf("@");
	pos4 = Field.value.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len-1)||(pos2 <= 0)||(pos2 == len-1))
	{
		window.alert("請輸入有效的E-mail位址！");
		Field.focus();
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'
		{
			window.alert("請輸入有效的E-mail位址！");
			return false;
		}
	}
	return true;
}

function CheckMustLength(Field, MustLength, FieldTitle)
{
		if (Field.value.length != MustLength)
		{
			alert("\"" + FieldTitle + "\"中輸入的值必須是" + MustLength + "位.");
			Field.focus();
			return false;
		}
	return true;
}

function CheckIntRange(field,prompt,min,max) {
	if ( ! CheckInteger(field,prompt) )
		return	false;
	ival = parseInt(field.value);
	if ( ival < min || ival > max ) {
		alert(prompt + " 只能為 " + min + " 到 " + max + " 之間的數");
		field.focus();
		return	false;
	}
	return	true;
}


//列表框選擇值
function SelectValue(objSelect,strValue){
	if (strValue=="") return;
	for(i=0;i<objSelect.options.length;i++){
		if(objSelect.options[i].value==strValue){
			objSelect.options[i].selected=true;
			break;
		}
	}
}

//單選框選擇值
function RadioValue(objSelect,strValue){
	if (strValue=="") return;
	for(i=0;i<objSelect.length;i++){
		if(objSelect[i].value==strValue){
			objSelect[i].checked=true;
			break;
		}
	}
}

//核取方塊選擇值
function CheckValue(objSelect,strValue){
	if (strValue=="") return;
	if(objSelect.value==strValue){
		objSelect.checked=true;
	}
}

//核取方塊選擇值
function CheckValues(objSelectList,strValue){
	if (strValue=="") return;
	if (objSelectList.length==null){
		if(strValue.indexOf(objSelectList.value)>=0){
			objSelectList.checked=true;
		}
	}
	else{
		for(i=0;i<objSelectList.length;i++){
			if(strValue.indexOf(objSelectList[i].value)>=0){
				objSelectList[i].checked=true;
			}
		}
	}
}

//核取方塊選擇值
function CheckValue1(objSelect,strValue){
	if (strValue=="") return;
	if(objSelect.value==strValue){
		objSelect.checked=true;
	}
	else{
		objSelect.checked=false;
	}
}

