
var gbl_NEW_LINE = "\n\r";

function ValidateFocus(field)
{
	var str_originalValue = "";
	
	if(field)
	{
		with(field)
		{
			str_originalValue = value;
			value = "";
			focus();
			value = str_originalValue;
		}
	}
}

function ValidateTrim(str)
{
    var str_match = str.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (str_match == null) ? "" : str_match[1];
}

// Validate Required Field.
function ValidateREQ(field)
{
	var bln_valid		= true;
	var obj_validator	= document.getElementById(field.id + "REQ");

	if(obj_validator && field)
	{
		with(field)
		{
			if(value == null || (ValidateTrim(value)).length == 0)
				bln_valid = false;
			
			obj_validator.style.display = bln_valid ? "none" : "block";
			return bln_valid ? "" : (obj_validator.innerHTML + gbl_NEW_LINE);
		}
	}
	else
	{
		return "Invalid Validator REQ FIELD : " + field.id;
	}
}

function ValidateDDLREQ(field)
{
	var bln_valid		= true;
	var obj_validator	= document.getElementById(field.id + "REQ");

	if(obj_validator)
	{		
		if(field.options[field.selectedIndex].value == "0")
			bln_valid = false;
		
		obj_validator.style.display = bln_valid ? "none" : "block";
		return bln_valid ? "" : (obj_validator.innerHTML + gbl_NEW_LINE);
		
	}
	else
	{
		return "Invalid Validator REQ FIELD : " + field.id;
	}
}

// Validate Length.
function ValidateLEN(field, param)
{
	var bln_valid		= true;
	var obj_validator	= document.getElementById(field.id + "LEN");

	if(obj_validator && field)
	{	
		with(field)
		{
			if(value == null || (ValidateTrim(value)).length > param)
				bln_valid = false;
			
			obj_validator.style.display = bln_valid ? "none" : "block";
			return bln_valid ? "" : (obj_validator.innerHTML + gbl_NEW_LINE);
		}
	}
	else
	{
		return "Invalid Validator LENGTH";
	}
}

// Validate Regular Expression.
function ValidateREG(field, param)
{
	var bln_valid		= true;
	var obj_validator	= document.getElementById(field.id + "REG");
	var str_match		= "";

	if(obj_validator && field)
	{	
		with(field)
		{
			if(value == null || !param.test((ValidateTrim(value))))
				bln_valid = false;
			
			obj_validator.style.display = bln_valid ? "none" : "block";
			return bln_valid ? "" : (obj_validator.innerHTML + gbl_NEW_LINE);
		}
	}
	else
	{
		return "Invalid Validator REG EXP";
	}
}

function ShowOther(obj_source, item_id)
{
	var obj_item	= document.getElementById(item_id);
	
	if(obj_item && obj_source)
		obj_item.style.display = obj_source.options[obj_source.selectedIndex].value == "other" ? "block" : "none";
}

function CaptchaCheck(obj_Form)
{
	// TODO: Captcha
	return true;
}

function LoadingBar(bln_Show, obj_button)
{
	if(pg && obj_button)
	{
		if(bln_Show)
		{
			obj_button.disabled = true;
			pg.show()
		}
		else
		{
			obj_button.disabled = false;
			pg.hide();
		}
	}
}
