



 document.write('<script type="text/javascript" src="/components/form/fix_e.js"></script>');
 document.write('<script type="text/javascript" src="/components/form/event_attacher.js"></script>');
 document.write('<script type="text/javascript" src="/components/form/class_magic.js"></script>');

//messages (aj pre ine JS subory)

//ac.js
var ajaxErrorMessage ="Hodnotu v tomto poli si musíte vybrať z ponúknutého zoznamu, nie je možné zadať ľubovoľnú hodnotu.";


var domLT = (document.getElementsByTagName) ? true : false;
var ie5LT = (document.getElementsByTagName && document.all) ? true : false;

function highlighthis(obj)
{
  if (ie5LT || domLT)
  {
    if (obj.className.indexOf("highlight") != -1)
      obj.className = obj.className.replace(new RegExp(" highlight\\b"), "");
    else
    	obj.className += " highlight";
  }
}

function thisMove()
{
  var args = arguments;
  return (location.href = args[0]);
}

/* copyValues() - prekopiruje hodnoty z elementu-ov do elementu-ov
 *
 * parametre:
 *
 * 1. mode - single, multi [povinny];
 * single - jedna hodnota do 1 a viac elementov
 * multi - skupina hodnot do skupin hodnot
 *
 * 2. mySource - zdroj hodnot(y) [povinny]
 *
 * 3, 4... dalsie parametre za tym = ID/object ciela, tag(ov) [povinny aspon jeden]
 *
 * foo neprepisuje poliam ich povodny obsah
 *
 */

function copyValues () // mode, mySource, targetIDs/targetObjects..
{
  var args = arguments;

  // pracovne premenne
  var tmp = "";
  var tmp2 = "";
  var tmp3 = "";
  var tmp4 = "";
  var tmp5 = "";
  var tmp6 = "";
  var trueFalse = false;

  if (args[0] == "single")
  {

    if (typeof(args[1]) == "object") // ziskanie mySource hodnoty
    {
      tmp = args[1].value;
    }
    else
    {
      tmp = document.getElementById('args[1]').value;
    }

    for (var i=2; i < args.length; i++) // ziskaj a napln ciele
    {

      if (typeof(args[i] == "string")) // ziskaj ciel
      {
        tmp2 = document.getElementById(args[i]);
      }
      else // if (typeof(args[i] == "object"))
      {
        tmp2 = args[i];
      }

/* tmp sa moze dalej kontrolovat na typ a potom robit innerHTML alebo value */
// momentalne je to iba value

      if (!tmp2.value.length > 0) // napln ciel
      {
        tmp2.value = tmp;
      }

    }

  }
  else if (args[0] == "multi")
  {

    if (typeof(args[1]) == "object") // ziskanie mySource hodnoty
    {
      tmp = args[1];
    }
    else
    {
      tmp = document.getElementById(args[1]+'Set');
    }

    tmp3 = tmp.id.split("Set"); // ziskaj klucove slovo mySource poli
    tmp3 = tmp3[0]; // ok
    // alert(tmp3);

/* ciele (skupiny) by sa mohli ponuknut na vyber, ze ktore */
// momentalne zoberie vsetky co su v parametroch

    tmp = tmp.childNodes; // mySource skupina a jeho iteracia

    for (var x=0; x < tmp.length; x++) // docasny fix
    {
      if (typeof(tmp[x].tagName) != "undefined")
      {
        //alert(tmp[y].tagName + " " + tmp[y].childNodes.length);
        // alert(tmp[y].childNodes.length);

        for (var xx=0; xx < tmp[x].childNodes.length; xx++)
        {
          if (typeof(tmp[x].childNodes[xx].tagName) != "undefined")
          {
            //alert(tmp[y].childNodes[z].tagName + " " + tmp[y].childNodes[z].childNodes.length);

            //alert(tmp[y].childNodes[z].childNodes);
            //tmp6.appendChild(tmp[y].childNodes[z]);
            tmp6 = tmp6  + "tmp[" + x + "]." + "childNodes[" + xx + "], ";

          }
        }
        tmp6 = tmp6  + "tmp[" + x + "], ";
      }
    }

    //tmp6 = { 0:tmp[0],1:tmp[1],2:tmp[2] }
    tmp6 = tmp6.replace(/,\s$/,"");
    tmp6 = "tmp6 = new Array(" + tmp6 + ");";
    tmp6 = eval(tmp6);
    tmp = tmp6;
    
    //alert (tmp[4].childNodes.length);
    for (var y=0; y < tmp.length; y++)
    {
//      if (typeof(tmp[y].tagName) != "undefined")
//      {

        if (tmp[y].tagName.toUpperCase() == "LEGEND")
        {
          if (confirm ("Prebrat' hodnoty z bloku \"" + tmp[y].innerHTML.replace(/\s{2,}/gi, "") + "\"?"))
            trueFalse = true;
          else
            trueFalse = false;

          break;
        }

//      }
    }

if (trueFalse)
{ 
    for (var y=0; y < tmp.length; y++)
    {
/*      if (typeof(tmp[y].tagName) != "undefined")
      {
        if (tmp[y].tagName.toUpperCase() == "INPUT")
        {*/
          if (/*tmp[y].name != "undefined" && */tmp[y].type == "text") // filter na iba text fieldy
          {

            for (var i=2; i < args.length; i++) // pocet cielovych skupin - parametrov
            {

              if (typeof(args[i]) == "object") // ziskanie cielovej skupiny
              {
                tmp2 = args[i];
              }
              else
              {
                tmp2 = document.getElementById(args[i]+'Set');
              }
              tmp4 = tmp2.id.split("Set"); // ziskaj klucove slovo cielovej skupiny
              tmp4 = tmp4[0]; // ok

              tmp2 = tmp2.childNodes; // cielova skupina a jeho iteracia

              tmp6 = "";
              // docasny fix
              for (var x=0; x < tmp2.length; x++)
              {
                if (typeof(tmp2[x].tagName) != "undefined")
                {
                  //alert(tmp[y].tagName + " " + tmp[y].childNodes.length);
                  // alert(tmp[y].childNodes.length);

                  for (var xx=0; xx < tmp2[x].childNodes.length; xx++)
                  {
                    if (typeof(tmp2[x].childNodes[xx].tagName) != "undefined")
                    {
                      //alert(tmp[y].childNodes[z].tagName + " " + tmp[y].childNodes[z].childNodes.length);

                      //alert(tmp[y].childNodes[z].childNodes);
                      //tmp6.appendChild(tmp[y].childNodes[z]);
                      tmp6 = tmp6  + "tmp2[" + x + "]." + "childNodes[" + xx + "], ";

                    }
                  }
                  tmp6 = tmp6  + "tmp2[" + x + "], ";
                }
              }

              //tmp6 = { 0:tmp[0],1:tmp[1],2:tmp[2] }
              tmp6 = tmp6.replace(/,\s$/,"");
              tmp6 = "tmp6 = new Array(" + tmp6 + ");";
              //alert(tmp6);
              tmp6 = eval(tmp6);
              tmp2 = tmp6;


              for (var z=0; z < tmp2.length; z++)
              {

                if (tmp2[z].name != "undefined" && tmp2[z].type == "text") // filter na iba text fieldy
                {
                  tmp5 = tmp[y].name.split(tmp3); // ziskaj priponu zdroja
                  tmp5 = tmp5[1];
                  //alert(tmp5);
                  tmp6 = tmp2[z].name.split(tmp4);  // ziskaj priponu ciela
                  tmp6 = tmp6[1];
                  //alert(tmp6);

                  if (tmp5 == tmp6)
                  {
                    tmp2[z].value = tmp[y].value;
                    if (checkForm) checkForm.checkField(tmp2[z]);
                  }
                }

              }

            }

/*          }
        }*/
      }
 //   }

    }
}
  }
  else
  {
    // noop
  }

}

/* common compliance */
function printPage()
{
  var options = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=460;"
  url = top.location.href;
  if (url.indexOf("#")>0) url = url.substring(0, url.indexOf("#"));
  if (url.indexOf("?")>0) url = url + "&print=yes";
  else url = url + "?print=yes";
  printWindow=window.open(url,"_blank",options);
}

function printPageEn()
{
  var options = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=460;"
  url = top.location.href;
  if (url.indexOf("#")>0) url = url.substring(0, url.indexOf("#"));
  if (url.indexOf("?")>0) url = url + "&print=yes&eng=yes";
  else url = url + "?print=yes&eng=yes";
  printWindow=window.open(url,"_blank",options);
}

function popup(url, width, height)
{
  var options = "toolbar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+";"
  popupWindow=window.open(url,"_blank",options);
}

function wjPopup(url, width, height)
{
  var options = "toolbar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+";"
  popupWindow=window.open(url,"_blank",options);
}

// Scott Andrew's event attacher
function ckmAddEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function ckmFixE(e) {
	if (!e && window.event) e = window.event;
	if (!e.target) e.target = e.srcElement;
	return e;
}

function getPageElement(name)
{
   var el = null;
   if (document.getElementById)
   {
      el = document.getElementById(name);
   }
   return(el);
}
function setFieldValue(elementId, value)
{
   var el = getPageElement(elementId);
   if (el!=null)
	{	   
		el.value=value;
		if (checkForm) checkForm.checkField(el);		
	}
}

var dateLastFocusElement = null;

function checkDate(vstup)
{ 
   return(checkDate(vstup, false));
}

function checkDate(vstup, allowBack)
{   
  if (vstup && vstup.value && vstup.value.length > 0)
  {
   test_date = vstup.value;   
   test_date = test_date.replace(",", ".");
   test_date = test_date.replace(" ", ".");
   test_date = test_date.replace(":", ".");
   test_date = test_date.replace("-", ".");
   test_date = test_date.replace("/", ".");
   vstup.value = test_date;

   test_date = vstup.value;
   test_date = test_date.replace(",", ".");
   test_date = test_date.replace(" ", ".");
   test_date = test_date.replace(":", ".");
   test_date = test_date.replace("-", ".");
   test_date = test_date.replace("/", ".");
   vstup.value = test_date;
   
   //replace nazvov
   test_date = vstup.value.toUpperCase();
   test_date = test_date.replace("JAN", ".01.");
   test_date = test_date.replace("FEB", ".02.");
   test_date = test_date.replace("MAR", ".03.");
   test_date = test_date.replace("APR", ".04.");
   test_date = test_date.replace("MAJ", ".05.");
   test_date = test_date.replace("MAY", ".05.");
   test_date = test_date.replace("JUN", ".06.");
   test_date = test_date.replace("JUL", ".07.");
   test_date = test_date.replace("AUG", ".08.");
   test_date = test_date.replace("SEP", ".09.");
   test_date = test_date.replace("OKT", ".10.");
   test_date = test_date.replace("OCT", ".10.");
   test_date = test_date.replace("NOV", ".11.");
   test_date = test_date.replace("DEC", ".12.");
   vstup.value = test_date;
   
   if (test_date.length == 8 && test_date.indexOf(".")==-1)
   {
      test_date = test_date.substring(0,2)+"."+test_date.substring(2,4)+"."+test_date.substring(4);
      vstup.value = test_date;
   }

   var text
   var index
   var tecka
   var den
   var mesic
   var rok
   var ch
   text=""

   den=""
   mesic=""
   rok=""
   tecka=0

   for (index = 0; index < vstup.value.length; index++)
   {
      ch = vstup.value.charAt(index);
      if (ch != "0" && ch != "1" && ch != "2" && ch != "3" && ch != "4" && ch != "5" && ch != "6" && ch != "7" && ch != "8" && ch != "9" && ch != ".")
         {text="Dátum musí byť vo formáte DD.MM.RRRR (DD=deň, MM=mesiac, RRRR=rok).\r"}
      if ((ch == "0" || ch == "1" || ch == "2" || ch == "3" || ch == "4" || ch == "5" || ch == "6" || ch == "7" || ch == "8" || ch == "9") && (text ==""))
      {
         if (tecka == 0)
            {den=den + ch}
         if (tecka == 1)
            {mesic=mesic + ch}
         if (tecka == 2)
            {rok=rok + ch}
      }
      if (ch == "." && text == "")
      {
         if (tecka == 1)
            {tecka=2}
         if (tecka == 0)
            {tecka=1}

      }
   }
   
   den = Number(den);
   mesic = Number(mesic);
   
   if (!rok || rok == "")
   {
   	var dNow = new Date();
      if (mesic < (dNow.getMonth()+1))
      {
         rok = dNow.getYear()+1;
      }
      else if (mesic == (dNow.getMonth()+1) && den < dNow.getDate())
      {
         rok = dNow.getYear()+1;
      }
      else
      {
         rok = dNow.getYear();
      }
   }
   
   rok = Number(rok);
   
   //window.alert("den="+den);

   if ((den<1 || den >31) && (text == ""))
      {text=text + "Počet dní v mesiaci nesmie byť menej ako 1 alebo viac ako 31.\r"}
   if ((mesic<1 || mesic>12) && (text == ""))
      {text=text + "Mesiac nemôže byť menší ako 1 alebo väčší ako 12.\r"}
   if (rok<100 && tecka == 2 && text == "" && rok != "")
   {
      rok = 2000 + rok;
   }
   else if (rok<1900 && tecka == 2 && text == "" && rok != "")
   {
      text=text + "Rok nemôže byť menší ako 1900.\r"      
   }
   if ((tecka == 2 && rok == "") || (tecka > 2))
      {text=text+ "Dátum musí byť vo formáte DD.MM alebo DD.MM.RRRR (DD=deň, MM=mesiac, RRRR=rok).\r"}
   if (mesic == 2)
   {
      if (rok != "")
         {
         if (rok % 4 == 0)
            {
            if (den>29)
               {text=text + "Vo februári roku " + rok + " je iba 29 dní.\r"}
            }
         else
            {
            if (den>28)
               {text=text + "Vo februári roku " + rok + " je iba 28 dní.\r"}
            }
         }
      else
         {
         if (den>29)
            {text=text + "Vo februári je 29 dní.\r"}
         }
   }

   if ((mesic == 4 || mesic == 6 || mesic == 9 || mesic == 11) && (den>30))
      {text=text + "Počet dní vo vybranom mesiaci nesmie byť menej ako 1 alebo viac ako 30.\r"}

   if (text!="")
   {   	
      window.alert(text);           
      if (dateLastFocusElement==null || dateLastFocusElement!=vstup)
   	{
   		vstup.focus();
      	vstup.select(); 
      	dateLastFocusElement = vstup;
      }
      return(vstup);
   }
   else
   {
      //zostav formatovany datum
      var myDatum = ""+den;
      if (den < 10) myDatum = "0"+den;
      if (mesic < 10) myDatum += ".0"+mesic;
      else myDatum += "."+mesic;
      myDatum += "."+rok;
      vstup.value = myDatum;
      
      if (allowBack==false)
      {
	      //skontroluj, ci nie je v minulosti
			var myDate = getDate(vstup.value);
			
			var nowDate = getDate("11.04.2026");
			if (myDate < nowDate)
			{
				text = text + "Dátum musí byť väčší alebo rovný ako 11.04.2026";
				window.alert(text);           
		      if (dateLastFocusElement==null || dateLastFocusElement!=vstup)
		   	{
		   		vstup.focus();
		      	vstup.select(); 
		      	dateLastFocusElement = vstup;
		      }
		      return(vstup);
			}
		}
      
      return(null);
   }   
 }
 return(null)
}

//////////////////////////////////////////////////////////////////////
// Numerical Checking Support (internal use)

function IsNumber(Value, AllowPoint, DigitsAfter, DigitsBefore)
// Returns true if the given Value is a number that parseInt/Float will read correctly
// Returns false is the given Value contains junk which parseInt/Float would ignore
// Additionally, can limit number of digits before and after point
{
   // If AllowPoint is not set, assume it is false ie check for an integer
   if (IsNumber.arguments.length < 2)
      AllowPoint = false;

   if (!(AllowPoint))
   {  DigitsBefore = -1;
      DigitsAfter = -1;
   }

   // Flags for float/integer validation
   DigitsStarted = false;
   DigitsStopped = false;
   PointPosition = -1;
   SignPosition = -1;
   CountBefore = 0;
   CountAfter = 0;
   ValidNumber = false;

   // Check its a valid number
   for (I = 0; I < Value.length; I++)
   {  // "-" is allowable once, immediately before digits and/or point only
      if (Value.charAt(I) == "-")
      {  if ((DigitsStarted) || (SignPosition > -1) || PointPosition > -1)
         {  ValidNumber = false;
            break;
         }
         else
            SignPosition = I;
      }

      // "." is allowed once and must be immediately before or after a digit
      else if (Value.charAt(I) == ".")
      {  if ((PointPosition > -1) || (DigitsStopped) || (!(AllowPoint)))
         {  ValidNumber = false;
            break;
         }
         else
            PointPosition = I;
      }

      // " " is allowable when leading or trailing only
      else if (Value.charAt(I) == " ")
         DigitsStopped = DigitsStarted;

      // numbers are allowable when in one lump
      // any sign or point must be immediately previous if this is the first digit
      else if ((Value.charAt(I) >= "0") &&
               (Value.charAt(I) <= "9"))
      {  ValidNumber = true;
         if ( (((SignPosition > -1) && (SignPosition != I-1) && (SignPosition != PointPosition-1)) && (!(DigitsStarted)))
              ||
              (((PointPosition > -1) && (PointPosition != I-1)) && (!(DigitsStarted)))
              ||
              (DigitsStopped)
            )
         {  ValidNumber = false; alert(I + " " + SignPosition + " " + PointPosition + " " + DigitsStarted);
            break;
         }

         DigitsStarted = true;
         if (PointPosition > -1)
            CountAfter++;
         else
            CountBefore++;

         if (((DigitsBefore > -1) && (CountBefore > DigitsBefore)) ||
             ((DigitsAfter > -1) && (CountAfter > DigitsAfter)))
         {  ValidNumber = false;
            break;
         }
      }

      // nothing else is allowed
      else
      {  ValidNumber = false;
         break;
      }
   }

   return ValidNumber;
}


function checkTime(Field)
// Checks the contents of a given TEXT/TEXTAREA is a valid time hh:mm
{
   // Allow blank times
   if (!Field || !Field.value || Field.value.length == 0) { return null; }

   test_time = Field.value;   
   test_time = test_time.replace(",", ":");
   test_time = test_time.replace(" ", ":");
   test_time = test_time.replace("\.", ":");
   test_time = test_time.replace("-", ":");

   if (test_time.length == 4 && test_time.indexOf(":")==-1)
   {
      test_time = test_time.substring(0,2)+":"+test_time.substring(2);
   }

   dvojbodka = test_time.indexOf(":");

   // Check it
   if ( (test_time.length > 5)                   // its too long
        ||
        (dvojbodka < 1)              // its not got a : in the middle
        ||
        (!(IsNumber(test_time.substring(0,dvojbodka))))   // its hours isnt a number
        ||
        (!(IsNumber(test_time.substring(dvojbodka+1,test_time.length))))   // its minutes isnt a number
        ||
        (test_time.indexOf(" ") > -1)             // its got spaces in it
        ||
        (test_time.indexOf("-") > -1)             // its got negatives in it
        ||
        (parseInt(test_time.substring(0,2)) > 23) // its got too many hours
        ||
        (parseInt(test_time.substring(3,5)) > 59) // its got too many minutes
      )
   {
      window.alert("Zadaný čas nie je korektný");
      if (dateLastFocusElement==null || dateLastFocusElement!=Field)
      {
      	Field.select();
      	Field.focus();
      	dateLastFocusElement = Field;
      }
      return Field;
   }
   else
   {
      Field.value = test_time;
      return null;
   }
}

function getDate(dateString)
{
   var values = dateString.split(".");
   var date = new Date(values[2], values[1]-1, values[0]);
   //window.alert(date);
   return(date);
}

function checkEndDate(fieldStart, fieldEnd, b_isEnd)
{
   if (b_isEnd == false && checkDate(fieldStart)!=null)
   {
      return false;
   }
   if (checkDate(fieldEnd)!=null)
   {
      //fieldEnd.focus();
      //window.alert("Nesprávne zadaný koncový dátum.");
      return false;
   }

   if (fieldStart.value.length < 10)
   {
      //return;
   }
   
   var dateStart = getDate(fieldStart.value);
	var dateEnd = getDate(fieldEnd.value);

	//window.status = dateStart + " end=" + dateEnd;
	var diff = dateEnd - dateStart;
	//window.alert(diff);
   if (dateEnd < dateStart)
   {
   	if (b_isEnd == true) window.alert("Koncový dátum nemôže byt skôr ako začiatočný.");
   	if (dateLastFocusElement==null || dateLastFocusElement!=fieldEnd)
   	{
   		fieldEnd.value = "";
      	fieldEnd.focus();  
      	fieldEnd.select();    
      	dateLastFocusElement = fieldEnd;
      }
      return;
   }
}

function checkEndTime(fieldStart, fieldEnd, b_isEnd)
{
   if (checkTime(fieldStart)!=null)
   {
      return;
   }
   if (checkTime(fieldEnd)!=null)
   {
      return;
   }

   startTime = fieldStart.value;
   endTime = fieldEnd.value;

   if (endTime.length < 3 || endTime.indexOf(":") < 1)
   {
      fieldEnd.value = "";
      return;
   }
   if (startTime.length < 3 || startTime.indexOf(":") < 1)
   {
      startTime = "08:30"
      fieldStart.value = startTime;
   }

   minutesStart = (startTime.substring(0,startTime.indexOf(':'))-0) * 60 +
                  (startTime.substring(startTime.indexOf(':')+1,startTime.length)-0);
   minutesEnd = (endTime.substring(0,endTime.indexOf(':'))-0) * 60 +
                (endTime.substring(endTime.indexOf(':')+1,endTime.length)-0);

   if (b_isEnd == false && lastTimeDif > 0)
   {
      minutesEnd = minutesStart + lastTimeDif;
      hours = Math.floor(minutesEnd / 60);
      if (hours < 10) hours = "0"+hours;
      minutes = (minutesEnd - (hours * 60));
      if (minutes < 10) minutes = "0"+minutes;
      fieldEnd.value = hours + ':' + minutes;
      endTime = fieldEnd.value;
   }
   else
   {
      if (minutesEnd < minutesStart)
      {
         fieldEnd.value = "";
         window.alert("Koncový cas nemôže byt skôr ako začiatočný.");
         return;
      }
   }
   lastTimeDif = minutesEnd - minutesStart;
   //window.alert("min start="+minutesStart+" end="+minutesEnd);

}

function confirmDelete(text)
{
   if (window.confirm(text))
	{
	   return true;
	}
	return false;
}

function escapeParameter(param)
{
   param = param.replace(/ĺ/gi, "%C4%BA");
   param = param.replace(/ľ/gi, "%C4%BE");
   param = param.replace(/š/gi, "%C5%A1");
   param = param.replace(/č/gi, "%C4%8D");
   param = param.replace(/ť/gi, "%C5%A5");
   param = param.replace(/ž/gi, "%C5%BE");
   param = param.replace(/ý/gi, "%C3%BD");
   param = param.replace(/á/gi, "%C3%A1");
   param = param.replace(/í/gi, "%C3%AD");
   param = param.replace(/é/gi, "%C3%A9");
   param = param.replace(/ú/gi, "%C3%BA");
   param = param.replace(/ä/gi, "%C3%A4");
   param = param.replace(/ô/gi, "%C3%B4");
   param = param.replace(/ó/gi, "%C3%B3");
   param = param.replace(/ň/gi, "%C5%88");
   param = param.replace(/ď/gi, "%C4%8F");
   param = param.replace(/ö/gi, "%C3%B6");
   param = param.replace(/ő/gi, "%C5%91");
   param = param.replace(/ü/gi, "%C3%BC");
   param = param.replace(/ű/gi, "%C5%B1");
   return(param);
}
function formatCurrency( num )
{
  var isNegative = false;
  num = num.toString().replace(/\$|\\,/g,'');
  if( isNaN( num ) )
  {
    num = "0";
  }
  if ( num < 0 )
  {
    num = Math.abs( num );
    isNegative = true;
  }
  cents = Math.floor( ( num * 100 + 0.5 ) % 100 );
  num = Math.floor( ( num * 100 + 0.5 ) / 100 ).toString();
  if ( cents < 10 )
  {
    cents = "0" + cents;
  }
  for ( i = 0; i < Math.floor( ( num.length - ( 1 + i ) ) / 3 ); i++)
  {
    num = num.substring( 0 ,num.length - ( 4 * i + 3 ) ) + ' ' + num.substring( num.length - ( 4 * i + 3 ) );
  }

  var result = num + ',' + cents;
  if ( isNegative )
  {
    result = "-" + result;
  }
  return result;
}