//**********************************************************************
//                             StaticCart                              *
// JavaScript MoneyFormat Module                    Copyright 2004-06  *
//                                                                     *
//**********************************************************************
//                                                                     *
// None of this script may be redistributed or sold without the        *
// authors express consent. Violations of this copyright will be       *
// prosecuted.  If you would like to use StaticCart, email us at       *
// carl@staticcart.com or visit http://www.staticcart.com              *
//                                                                     *
//**********************************************************************

//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount                                ||
//---------------------------------------------------------------------||

function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;

//---------------------------------------------------------------------||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to ####.## format                 ||
//---------------------------------------------------------------------||
   
if ( MonetaryFormat == "default") {

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
// dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return(dollars + "." + cents);
}
}
//---------------------------------------------------------------------||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #'###.###,## format         ||
//---------------------------------------------------------------------||

if ( MonetaryFormat == "dk") {
var cents = "" + Math.round(input * 100); 
cents = cents.substring(cents.length-2, cents.length) 
//dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0; 

if ( cents == "0" ) 
cents = "00"; 

dolstring = new String(dollars); 

if (dolstring.length>6) { 
hundreds=dolstring.slice(dolstring.length-3); 
thousands=dolstring.slice(-6,dolstring.length-3); 
million=dolstring.slice(0,dolstring.length-6); 
dolstring=million+"'"+thousands+"."+hundreds; 

} 

else { 
if (dolstring.length>3) { 
hundreds=dolstring.slice(dolstring.length-3); 
thousands=dolstring.slice(0,dolstring.length-3); 
dolstring=thousands+"."+hundreds; 
} 


} 


return(dolstring + "," + cents); 

} 
}


//=====================================================================||
//                        END MoneyFormat Module                       ||
//=====================================================================||