function Validate()
{
	this.msg="";		//儲存錯誤訊息
	this.counter=0;		//儲存錯誤總數
	
	this.validatePositiveInteger = Validate_validatePositiveInteger;
	this.validateCommom = Validate_validateCommom;
	this.equalTo = Validate_equalTo;
	this.validateSelect = Validate_validateSelect;
	this.denySQ = Validate_denySQ;
	this.required = Validate_required;
	this.addMsg = Validate_addMsg;
}

//驗證只能接受英文字母、數字及底線
function Validate_validateCommom(value, fieldName, required)
{
	var msg = "";

	if(required)
	{
		re = /^\w+$/g;
		msg = "[必要欄位]";
	}
	else
		re = /^\w*$/g;
	
	if(!re.test(value))
	{
		this.counter++;
		this.msg += this.counter + "." + msg + fieldName + "只能輸入英文字母、數字、底線" + "\n\n";
	}

}

//驗證是否相等
function Validate_equalTo(source, desti, sfieldName, dfieldName)
{
	if(source != desti)
	{
		this.counter++;
		this.msg += this.counter + "." + sfieldName + "欄位必須等於" + dfieldName + "欄位\n\n";
	}
}

//驗證是否有選取select標籤
function Validate_validateSelect(obj_source,obj_name,exception)
{
	var flag=true;
	//var obj=obj_source.value;
    var obj_len=obj_source.length;

	for(i=0;i < obj_len;i++)
	{
		if(obj_source.options[i].selected)
		{
			if(obj_source.options[i].value==exception)
			{
				flag = false;
				break;
			}
		}
	}

	if(!flag)
	{
		this.counter++;
		this.msg += this.counter + ". 請選取" + obj_name + "資料欄位" + "\n\n";
	}
}

//驗證拒絕單引號
function Validate_denySQ(value, fieldName, required)
{
	if(required)
		this.required(value,fieldName);

	re = /\'{1,}/gi;

	if(re.test(value))
	{
		this.counter++;
		this.msg += this.counter + "." + fieldName + "請勿輸入單引號" + "\n\n";
	}
}

//驗證必須輸入資料
function Validate_required(value,fieldName)
{
	re = /\s/g;
	var newValue = value.replace(re, "");
	if(newValue.length==0)
	{
		this.counter++;
		this.msg += this.counter + "." + fieldName + "必須輸入資料" + "\n\n";
	}
}

//驗證正整數
function Validate_validatePositiveInteger(value, required, fieldName)
{
	var msg = "";

	if(required)
	{
		re = /^\d+$/g;
		msg = "[必要欄位]";
	}
	else
		re = /^\d*$/g;
	
	if(!re.test(value))
	{
		this.counter++;
		this.msg += this.counter + "." + msg + fieldName + "只能輸入正整數" + "\n\n";
	}	
}

//加入物件訊息
function Validate_addMsg(msg)
{
	this.counter++;
	this.msg += this.counter + "." + msg + "\n\n";	
}