$(document).ready(function(){
});

// helper functions

/*
 *  Returns a string based on the length of the object's value. If it is
 *  greater than _length, then reduce to _length
 *
 *  Author:     Vincent Kwan
 *  Copyright:  2011-02-11
 *
 *  Param:      _obj - html object
 *  Param:      _length - length to reduce to
 *
 *  Return:     _obj's value reduced to the _length (if applicable)
 */
function reduceLength( _obj, _length )
{
  return ( $(_obj).val().length > _length ) ? $(_obj).val().substr(0, _length) : $(_obj).val();
} // reduceLength

/*
 *  Checks if the value entered in the _obj is a number of decimal
 *
 *  Author:     Vincent Kwan
 *  Copyright:  2011-02-11
 *
 *  Param:      _obj - html object
 *
 *  Return:     _obj's sanitized value
 */
function checkFloat( _obj )
{
  var str = $(_obj).val();
  
  return ( str.match(/^[0-9]*\.?[0-9]*$/ig) == null ) ? str.substring(0, str.length-1) : str;
} // checkFloat

/*
 *  Checks if the value entered in the _obj is a positive number
 *
 *  Author:     Vincent Kwan
 *  Copyright:  2011-02-21
 *
 *  Param:      _obj - html object
 *
 *  Return:     _obj's sanitized value
 */
function checkInteger( _obj )
{
  var str = $(_obj).val();
  
  return ( str.match(/^[0-9]*$/ig) == null ) ? str.substring(0, str.length-1) : str;
} // checkInteger

/*
 *	This will create the price value to Canadian format
 *
 *	@author		Vincent Kwan
 *	@copyright	2011-02-23
 *
 *	@param		$_number		number to make into a price
 *
 *	@return		$###,###.##, ex: $987,654.32
*/  
function formatPrice( _number )
{
  var m_numPrice = (_number.length == 0) ? 0.00 : parseFloat(_number);

  if( m_numPrice >= 0 ) // create the pricing for this
  {
    m_numPrice = Math.round( m_numPrice * 100 ) / 100;
    m_arrPrice = m_numPrice.toString().split('.');
    
    var m_strTmp = m_arrPrice[0];
    var m_strPrice = '';
    
    while( m_strTmp.length>3 ) // add a separater for thousands
    {
      m_strPrice = ',' . m_strTmp.substring( m_strTmp.length-3, 3 ) + m_strPrice;
      m_strTmp = $m_strTmp.substring(0, $m_strTmp.length-3);
    } // while
    
    m_strDecimal = ( m_arrPrice.length == 1 ) ? '00' : MakeTwoDigits(m_arrPrice[1]);
    
    m_numPrice = '$' + m_strTmp + m_strPrice + '.' + m_strDecimal;
  }
  else // send "Ask for Price"
  {
    m_numPrice = 'Ask For Price';
  } // if
  
  return m_numPrice;
} // formatPrice

/*
 *	This will make the string 2 digits
 *
 *	@author		Vincent Kwan
 *	@copyright	2010 12 27
 *
 *	@param		_number		number to make into 6 digits
 *
 *	@return		A two digit number
*/      
function MakeTwoDigits( _number )
{
    m_Return = 0;
    
    if( _number.length == 0 )
      m_Return = '00';
    else if( _number.length == 1 )
      m_Return = _number + '0';
    else
      m_Return = _number;
    
    return m_Return;
} // MakeTwoDigits

