﻿
function validateForm(theform)
{

	pass = 1; //assume everything is ok
	msg = "在提交表單時，發現以下問題﹕\n\n";
		

     if( theform.fm_school_name.value == '' ){
			msg = msg + "- 學校名稱欄不能空置\n\n";
			pass = 0;
		}


	 if( theform.fm_student_name.value == ""){
			msg = msg + "- 學生姓名欄不能空置\n\n";
			pass = 0;	
		}

	 if( theform.fm_class.value == ""){
			msg = msg + "- 班別 不能空置\n\n";
			pass = 0;	
		}

	 if( theform.fm_class_number.value == ""){
			msg = msg + "- 學號 不能空置\n\n";
			pass = 0;	
		}

	 if( theform.fm_reason_element.value == ""){
			msg = msg + "- 題目 1 未作問\n\n";
			pass = 0;	
		}

		
	 if( theform.fm_what_how.value == ""){
			msg = msg + "- 題目 2 未作問\n\n";
			pass = 0;	
		}		


	if (pass == 1)
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

// validators ------------------------------------------------------------------
	
function isEmpty (s) {
	var p = /\S+/;
	return !p.test(s);
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphaNum(string) {
    if (string.search(/^[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isIDformat(string) {
    if (string.search(/^[a-z0-9_]+$/) != -1)
	{
        if(string.search(/^_|_$/) != -1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
    else
        return false;
}

/*function isNum(string) {
    if (string.search(/^[0-9]+$/) != -1)
        return false;
    else
        return true;
}
*/

function isNum(string) {
    if (string.match(/^[0-9]+$/) !=null)
        return true;
    else
        return false;
}


function isBinary(string) {
    if (string.search(/^[0-1]+$/) != -1)
        return false;
    else
        return true;
}

function isExecutable (s) {
	var p = /\.(bat|com|dll|exe|vbs)$/i;
	return p.test(s);
}

function isImage (s) {
	var p = /\.(gif|jpg)$/i;
	return p.test(s);
}

function isUrl (s) {
	var p = /^(http|https|ftp):\/\/\S+\.[^\.\s]{2,4}(\/\S*)?$/i;
	return p.test(s);
}

function isSame(str1, str2){
	if (str1 == str2)
		return false;
	else
		return true;
}

//-->
