//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// DateUtil

/**
 * Utility methods related to dates.
 * @constructor
 * @private 
 */
function DateUtil(strRaw)
{
	throw new Error("DateUtil is a static class. Do not instantiate.");
}

/**
 * Converts common acceptable L/N Date formats into a standard mm/dd/yyyy format
 *
 *  Valid Formats
 *    * 01/01/1999
 *    * 01/01/99
 *    * 1/1/1999
 *    * 1/1/99
 *    * Jan. 1, 1999
 *    * jan. 1, 1999
 *    * Jan. 1, 99
 *    * Jan 1, 1999
 *    * jan 1, 1999
 *    * Jan 1, 99
 *    * January 1, 1999
 *    * january 1, 1999
 *    * January 1, 99
 */
DateUtil.parse = function(strRaw)
{
  var m = strRaw.match(/^([01]?\d|\w+)(\/|\.?\s+)([0123]?\d)(\/|,\s+)(\d{4}|\d{2})$/i);
  if (m !== null)
  {
    return DateUtil.parseMonth(m[1]) + "/" + DateUtil.parseNumericDay(m[3]) + "/" +  DateUtil.parseYear(m[5]); 
  }
  return;
};

/**
 * Converts numeric days into two digit absolute numbers.
 * For instance "1" returns "01"
 */
DateUtil.parseNumericDay = function(strRaw)
{
  if (strRaw.search(/^\d\d$/) != -1) return strRaw;
  return "0" + strRaw;
};

/**
 *
 */
DateUtil.parseYear = function(strRaw)
{
  // If it is a four digit year, just return ut
  if (strRaw.toString().search(/\d{4}/) != -1)
  {
    return strRaw;
  }
  var intValue = parseInt(strRaw, 10);
  if (intValue < 20)
  {
    return "20" + strRaw;
  }
  else
  {
    return "19" + strRaw;
  }
};

/**
 *
 */
DateUtil.parseMonth = function(strRaw)
{
  // Make sure that it is a string
  var str = strRaw.toString();
  str = str.toLowerCase();
  
  switch(str)
  {
    case("jan"):
    case("january"):
    case("1"):
    case("01"):
      return "01";
      break;
    case("feb"):
    case("february"):
    case("2"):
    case("02"):
      return "02";
      break;
    case("mar"):
    case("march"):
    case("3"):
    case("03"):
      return "03";
      break;
    case("apr"):
    case("april"):
    case("4"):
    case("04"):
      return "04";
      break;
    case("may"):
    case("5"):
    case("05"):
      return "05";
      break;
    case("jun"):
    case("june"):
    case("6"):
    case("06"):
      return "06";
      break;
    case("jul"):
    case("july"):
    case("7"):
    case("07"):
      return "07";
      break;
    case("aug"):
    case("august"):
    case("8"):
    case("08"):
      return "08";
      break;
    case("sep"):
    case("september"):
    case("9"):
    case("09"):
      return "09";
      break;
    case("oct"):
    case("october"):
    case("10"):
      return "10";
      break;
    case("nov"):
    case("november"):
    case("11"):
      return "11";
      break;
    case("dec"):
    case("december"):
    case("12"):
      return "12";
      break;
    default:
      return;      
  }
  return;
};

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// FormUtil

/**
 * @constructor
 * @private
 */
function FormUtil()
{
	throw new Error("FormUtil is a static class. Do not instantiate.");
}

FormUtil.getHiddenFieldVal = function(fieldName, val)
{
	if (!Truth.isTrue(val)) 
	{
		return "";
	}
    while (val.indexOf("'") > -1)
    {
        val = val.replace("'", "&#39;");
    }
   	return "<input type='hidden' name='" + fieldName + "' value='" + val + "' />";
};

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// QueryUtil

/**
 * @constructor
 * @private
 */
function QueryUtil()
{
	throw new Error("QueryUtil is a static class. Do not instantiate.");
}

QueryUtil.segment = function(strSeg) 
{
	return "(" + strSeg + ")"
};


//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// Truth

/**
 * @constructor
 * @private
 */
function Truth()
{
 
}

/** 
 * Static method to test truth from a Perl perspective
 */
Truth.isTrue = function(o) 
{
	if (o)
	{
		if (o === "") { return false; }
		return true;
	}
	return false;
};

/**
 * @private
 */
function escapeQuote(str)
{
	var re = new RegExp("'" , "g");
	return str.replace(re, "\'");

}


/**
 * Trim whitespace from the beginning and ending of a value.
 *
 * @param {String} The string to be trimmed
 * @return The string minus leading and trailing white space
 * @type String
 * @private
 */
function trimAll(sString)
{
	if (sString)
	{
		return sString.replace(/^\s*|\s*$/g,'');
	} 
	else
	{
		return sString;
	}
}