//var pattern="";
var _ReCheck;

function __PostCheckValue(group, fun, value)
{
	var str_error = "";
	var PanelIndex = 1;
	var checkPanelIndex = 0;
	var AReCheckId = new Array();
	$("ReqExp[group=" + group + "]").each(function()
	{
		var checkValue = "";
		checkValue = $("#" + $(this).attr("checkid")).val();
		checkValue = checkValue.replace(/\r\n|\r|\n/g, '');
		
		//取得正規表示式
		//pattern = $(this).attr("patStr");
		//取得驗證表單
		_ReCheck = $(this);
		//alert(_ReCheckId);
		
		
		/*
		if($(this).attr("check")=="compareTo")
		{			
			var compareValue = $("#" + $(this).attr("compareid")).val();
			compareValue = compareValue.replace(/\r\n|\r|\n/g, '');		
			
			if(checkValue!=compareValue)
				str_error += $(this).attr("error") + "\n";
		}

		else if(eval($(this).attr("check") + "(checkValue)"))
		{
			//alert($(this).attr("error"));
			str_error += $(this).attr("error") + "\n";
		}
		*/
		//$(this).next().text($(this).text());
		
		if(eval($(this).attr("check") + "(checkValue)"))
		{
			//alert($(this).attr("error"));
			
			if(checkPanelIndex == 0)
			{
				PanelIndex = parseInt($(this).attr("TabbedPanel"));
				if(!checkNum(PanelIndex))
				{
					checkPanelIndex = 1;
					PanelIndex = PanelIndex;
				}
			}
			str_error += $(this).attr("error") + "\n";
			AReCheckId.push($(this).attr("checkid"));
			//$("#" + $(this).attr("checkid")).addClass("input_req");
		}
		else
		{
			$("#" + $(this).attr("checkid")).removeClass("input_req");
		}
		
		for(var i = 0; i < AReCheckId.length; i++)
		{
			
			$("#" + AReCheckId[i]).addClass("input_req");
		}
	});
	
	if(str_error != "")
	{
		if(checkPanelIndex == 1)
		{
			changePanelIndex(PanelIndex - 1);
		}
		
		alert(str_error);
		return false;
	}
	
	__doPostBack(fun, value);
}

function __jsCheckValue(group, fun)
{
	var str_error = "";
	var PanelIndex = 1;
	var checkPanelIndex = 0;
	var AReCheckId = new Array();
	$("ReqExp[group=" + group + "]").each(function()
	{
		var checkValue = "";
		checkValue = $("#" + $(this).attr("checkid")).val();
		checkValue = checkValue.replace(/\r\n|\r|\n/g, '');
		
		//取得驗證表單
		_ReCheck = $(this);
		
		if(eval($(this).attr("check") + "(checkValue)"))
		{
			//alert($(this).attr("error"));
			
			if(checkPanelIndex == 0)
			{
				PanelIndex = parseInt($(this).attr("TabbedPanel"));
				if(!checkNum(PanelIndex))
				{
					checkPanelIndex = 1;
					PanelIndex = PanelIndex;
				}
			}
			str_error += $(this).attr("error") + "\n";
			AReCheckId.push($(this).attr("checkid"));
			//$("#" + $(this).attr("checkid")).addClass("input_req");
		}
		else
		{
			$("#" + $(this).attr("checkid")).removeClass("input_req");
		}
		
		for(var i = 0; i < AReCheckId.length; i++)
		{
			
			$("#" + AReCheckId[i]).addClass("input_req");
		}
	});
	
	if(str_error != "")
	{
		if(checkPanelIndex == 1)
		{
			changePanelIndex(PanelIndex - 1);
		}
		
		alert(str_error);
		return false;
	}
	
	eval(fun + "()");
}


function empty(val)
{
	if(val == "")
	{
		return true;
	}

	var regu = "^[ ]+$";
	var re = new RegExp(regu);
	
	return re.test(val);

}

function checkNum(val)
{
	if(val == "")
	{
		return false;
	}
	var regu = "[0-9]";
	var re = new RegExp(regu);
	//alert(re.test(val));
	return !re.test(val);
}

function datetime(val)
{
	if(val == "")
	{
		return false;
	}
	
	return true;
}

function FileImage(val)
{
	
	if(val == "")
	{
		return false;
	}
	var i, j = 1;
        var checkFile = new Array("jpg", "gif", "JPG", "GIF")
        var fileArray = new Array()

        fileArray = val.split(".")

        for (i = 0; i < checkFile.length; i++) {
            if (fileArray[fileArray.length - 1] == checkFile[i])
			{
                j = 0;
				
			}
        }

        if (j == 1)
            return true;
        else
            return false;
}

function FileFlashAndImage(val)
{
	
	if(val == "")
	{
		return false;
	}
	var i, j = 1;
        var checkFile = new Array("jpg", "gif", "JPG", "GIF","swf","SWF")
        var fileArray = new Array()

        fileArray = val.split(".")

        for (i = 0; i < checkFile.length; i++) {
            if (fileArray[fileArray.length - 1] == checkFile[i])
			{
                j = 0;
				
			}
        }

        if (j == 1)
            return true;
        else
            return false;
}

function FileDocAndPdf(val)
{
	
	if(val == "")
	{
		return false;
	}
	var i, j = 1;
        var checkFile = new Array("doc", "docx", "pdf")
        var fileArray = new Array()

        fileArray = val.split(".")

        for (i = 0; i < checkFile.length; i++) {
            if (fileArray[fileArray.length - 1] == checkFile[i])
			{
                j = 0;
				
			}
        }

        if (j == 1)
            return true;
        else
            return false;
}

function checkReg(val)
{
	if(val == "")
	{
		return false;
	}
	/*
	if(pattern == "")
	{
		return false;
	}
	*/

	var regu =  _ReCheck.attr("patStr");

	var re = new RegExp(regu);

	return !re.test(val);
}

function compareTo(val)
{
	var compareValue = $("#" + _ReCheck.attr("compareid")).val();
	compareValue = compareValue.replace(/\r\n|\r|\n/g, '');		
	
	if(val == "" || compareValue == "")
	{
		return false;
	}
	
	if(val!=compareValue)
	{
		return true;
	}
	else
	{
		return false;
	}
	
}

