var numFormat = /^\d*$/;
var num2Format = /^\d{2}$/;
var num10Format = /^\d{10}$/;
var num13Format = /^\d{13}$/;
var doubleFormat = /^\d*\.?\d{0,2}$/;
var trimFormat = /(^\s*)|(\s*$)/gi;
var arrDateFormat = [	/^\d{1,2}\/\d{1,2}\/\d{2,4}$/i, /^\d{1,2}-\d{1,2}-\d{2,4}$/i];

function lpad(s,n,c)
{
	var str = new String(s);
	var len = str.length;
	if (len == n) return str;
	else if (len > n) return str.substr(0, n);
	var result = "";
	for (var index = 0; index < n - len; ++index) result += c;
	return result + str;
}
function trim(value)
{
	return value.replace(trimFormat,"");
}
function LeapYear(year)
{
    var iYear = parseInt(year);
    var result = !Boolean(iYear % 400);
    if (!result)
    {
        result = Boolean(iYear % 100);
        if (result) result = !Boolean(iYear % 4);
    }
    return result;
}
function isValidDateFormat(strDate)
{
	if ((-1 == strDate.search(arrDateFormat[0])) &&
        (-1 == strDate.search(arrDateFormat[1])))
        return false;
    else return true;
}
function isValidDateInput(strDate)
{
    var arrDatesOfMonths = [31/*January*/,
                            28/*February*/,
                            31/*March*/,
                            30/*April*/,
                            31/*May*/,
                            30/*June*/,
                            31/*July*/,
                            31/*August*/,
                            30/*September*/,
                            31/*October*/,
                            30/*November*/,
                            31/*December*/];
    if (!isValidDateFormat(strDate)) return false;
    var arrDate;
    if (-1 < strDate.search(arrDateFormat[0]))
        arrDate = strDate.split("/");
    else if (-1 < strDate.search(arrDateFormat[1]))
        arrDate = strDate.split("-");
    var year = parseInt(arrDate[2/*year*/]);
    //if (year < 100) year += (year >= 50 ? 1900 : 2000);
    if (year < 100) year = 2500 + year - 543;
    else year = year - 543;
    if (year < 0) return false;
    var month = Number(arrDate[1/*month*/]);
    if (month < 1 || month > 12) return false;
    var date = Number(arrDate[0/*date*/]);
    if (date < 1 || date > 31) return false;
    if (month == 2/*February*/)
    {
        if (LeapYear(year))
        {
            if (date > 29) return false;
        }
        else if (date < 1 || date > arrDatesOfMonths[month - 1])
        {
            return false;
        }
    }
    else if (date < 1 || date > arrDatesOfMonths[month - 1])
        return false;
    return true;
}
function focusNext(me)
{
	return;
    switch (event.keyCode)
    {
        case 13:  // carriage return
            if (null == me) return;
            if (null == me.form) return;
            event.returnValue = false;
//            if (("button" == me.type) || ("submit" == me.type) || ("reset" == me.type))
			if (("submit" == me.type) || ("reset" == me.type))
            {
                me.click();
                return;
            }
            var len = me.form.length;
            var focusable = null;
            var passedOver = false;
            for (var index = 0; index < len; ++index)
            {
                if ((index >= len - 1) && passedOver && (null != focusable))
                {
                    if ("text" == focusable.type || "checkbox" == focusable.type) focusable.select();
					//alert(focusable.type);
                    focusable.focus();
                    return;
                }
                var el = me.form.elements[index];
                if (me == el)
                {
                    if (("hidden" != el.type) && (!el.disabled))
                    {
                        var tmp = me.form.elements[index + 1];
                        if (null == tmp) continue;
                        if (("hidden" != tmp.type) && (!tmp.disabled))
                        {
                            if (null == tmp) continue;
                            if ("text" == tmp.type || "checkbox" == tmp.type) tmp.select();
							//alert(tmp.type);
                            tmp.focus();
                            return;
                        }
                    }
                    passedOver = true;
                }
                else if (passedOver)
                {
                    if (("hidden" != el.type) && (!el.disabled))
                    {
                        if ("text" == el.type || "checkbox" == el.type) el.select();
						//alert(el.type);
                        el.focus();
                        return;
                    }
                }
                if (("hidden" != el.type) && (!el.disabled) && (null == focusable))
                    focusable = el;
            }
            if (null != focusable) 
			{
				if ("text" == focusable.type || "checkbox" == focusable.type) focusable.select();
				//alert(focusable.type);
				focusable.focus();
			}
            break;
        default: break;
    }
}
/*function convertEscapeChars(src)
{
	alert(src);
	if (src == "") return "";
	src = new String(src);
	if (src.length == 0) return src;
	var found = false;
	var result = "";
	for (var index = 0; index < src.length; ++index)
	{
		var currChar = src.charAt(index);
		if ('\r' == currChar)
		{
			result += "\\r";
			continue;
		}
		else if ('\n' == currChar)
		{
			result += "\\n";
			continue;
		}
		else if ('\f' == currChar)
		{
			result += "\\f";
			continue;
		}
		else if ('\t' == currChar)
		{
			result += "\\t";
			continue;
		}
		else if ('"' == currChar)
		{
			result += "\\\"";
			continue;
		}
		else if ('\\' == currChar)
		{
			result += "\\\\";
			continue;
		}
		else result += currChar;
	}
	return result;
}*/
