function Trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,'');
}

function IsPhone(strPhone)
{
    var phonePattern = /^\(?\d{3}\)?-?\s*?\d{3}-?\s*?\d{4}$/;
    return phonePattern.test(strPhone);
}

function IsUSPostalCode(strPostalCode)
{
    var zipPattern = /^\d{5}([\-]\d{4})?$/;
    return zipPattern.test(strPostalCode);
}

function IsEMail(strEMail)
{
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(strEMail);
}

function IsUrl(strUrl)
{
    var url = /\b(https?:\/\/[^\s+\"\<\>]+)/igm;
    return url.test(strUrl);
}

function RemoveMoneySymbols(strToChange)
{
    var ret = trim(strToChange);
    ret = ret.replace(/[^\d\.]/g,'');
    return Number(ret);
}

function IsDate(strDate) {

    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = strDate.match(datePat); // is the format ok?

    if (matchArray == null) return false;

    month = Number(matchArray[1]); // p@rse date into variables
    day = Number(matchArray[3]);
    year = Number(matchArray[5]);

    try
    {
        var dt = new Date();
        dt.setFullYear(year,month,day);
        return (dt != null);
    }
    catch (err)
    {
        return false;
    }
}


function StringToDate(strDate)
{
    var dt = new Date();
    var datePat = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    var matchArray = strDate.match(datePat); // is the format ok?

    if (matchArray == null) return null;

    month = Number(matchArray[1]); // p@rse date into variables
    day = Number(matchArray[2]);
    year = Number(matchArray[3]);

    try
    {
        dt.setFullYear(year,month,day);
        return dt;
    }
    catch (err)
    {
        return null;
    }
    
}

function IsDefined(o) {
	return (typeof(o)!="undefined");
};

function onSelect(calendar, date) {
  calendar.sel.value = date;
  if (calendar.dateClicked) {
    calendar.callCloseHandler(); // this calls "onClose" (see above)
  }
}
function onClose(calendar) {
  calendar.hide();
  // or calendar.destroy();
}
// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(el) {
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(0, null, onSelect, onClose);
    cal.weekNumbers = false;
    cal.showsTime = false;
    cal.showsOtherMonths = true;
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    //cal.activeDiv.zIndex = 200000;
    cal.create();
  }
  _dynarch_popupCalendar.element.style.zIndex = 200000;
  _dynarch_popupCalendar.setDateFormat("%m/%d/%Y");    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.
  _dynarch_popupCalendar.showAtElement(el, "Br");        // show the calendar

  return false;
}

function WriteYear() {

  today=new Date(); // Initialize Date in raw form
  year=today.getFullYear(); // Get the year
  document.write (year);
}

function GetQueryString()
{
    var qs = location.search;

    if (qs && qs != null && qs != 'undefined')
    {
        var pairs = qs.substring(1).split('&');
        var retPairs = new Array(pairs.length);
        var splitPair;

        for (var i = 0; i < pairs.length; i++)
        {
            splitPair = pairs[i].split("=");
            retPairs[i] = new Array(splitPair[0],splitPair[1]);
        }
        
        return retPairs;
    }
    return null;
}