
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;
	}
}

// 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 : " + field.id;
	}
}

// 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 : " + field.id;
	}
}

function IsValidDate(date)
{
	var obj_myDate		= new Date();
	var obj_dateArray	= date.split("/");
	var str_year		= obj_dateArray[2];
	var int_month		= -1;
	var int_monthTemp	= 0;
	var str_day			= obj_dateArray[0];
	
	// javascript months start at 0 (0-11 instead of 1-12)
	try
	{
		int_month = parseInt(obj_dateArray[1], 10);
		int_month--;
	}
	catch(e){}

	// setFullYear(yyyy, mm, dd);
	obj_myDate.setFullYear(str_year, int_month ,str_day);
	
	try
	{
		int_monthTemp = obj_myDate.getMonth();
	}
	catch(e){}	

	//alert(str_day);
	//alert(obj_myDate.getDate());
	//alert(int_month);
	//alert(int_monthTemp);
	//alert(str_year);
	//alert( obj_myDate.getFullYear());
	
	return ((str_day == obj_myDate.getDate()) && (int_month == int_monthTemp) && (str_year == obj_myDate.getFullYear()));
}

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();
		}
	}
}
