function ValidateRequiredFields(frm, arr)
{
	for (i = 0; i < arr.length; i++)
	{
		var e = frm.elements[arr[i]];
		if (e.value.length <= 0)
		{
		    return false;
		}
	}	
	return true;
}

function ValidateRegular(source, reg)
{
	if (source.length == 0)
	{
	    return false;
	}
	var rx = new RegExp(reg);
	var matches = rx.exec(source);
    return (matches != null && source == matches[0]);
}

function ValidateUserID(source)
{
	if(!ValidateRegular(source, "\\w+([-.]\\w+)*"))
	{
		return false;
	}
	return true;
}

function ValidateEmail(source)
{
	if  (!ValidateRegular(source, "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))
	{
		return false;
	}
	return true;
}

function ValidatePhone(source)
{
	if (!ValidateRegular(source, "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}"))
	{
		return false;
	}
	return true;
}

function ValidateURL(source)
{
	
	if (!ValidateRegular(source, "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"))
	{
		return false;
	}
	return true;
}

function CheckLength(source,start,end)
{
    var len = source.length;
	if(len<start || len>end)
	{
	    return false;   
	}
	return true;   
}

function IsInteger(source)
{
	if (!ValidateRegular(source, "\\d*"))
	{
		return false;
	}
	return true;
}

function isNum(argvalue) 
{
	argvalue = argvalue.toString();

	if (argvalue.length == 0)
	return false;

	for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
			return false;
	return true;
}


function checkFileType(objControl,strMessage,strFileType )
{
	if(objControl.value == "")
	{
		return "";
	}
	else
	{
		if(checkFile(objControl.value, strFileType))
		{
			return "";
		}
		else
		{
			objControl.select();
			objControl.focus();
			return strMessage;
		}
	}
}

function checkFile(strValue, strFileType)
{
    var strExtension = strValue.substr((strValue.lastIndexOf(".") + 1), strValue.length);
    var arrExtension = strFileType.split(",");
    var bFound = false;
    for(var i = 0; i < arrExtension.length;i++)
    {
	    if(strExtension == arrExtension[i])
	    {
		    return true;
	    }
    }
    return false;
}

