// JavaScript Document
<!-- Begin
function addBookMark() { 
  var url="http://www.cosmicmarketing.com";
  var title="Internet Marketing Information from CosmicMarketing.com";
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(url, title);
  }
  else {
    if (window.sidebar&&window.sidebar.addPanel)
    //configure two parameters below to your own (title, url of content to store)
      window.sidebar.addPanel(title,url,"");
    else 
      alert("Your need to Bookmark using (CTRL-D)")
  }
}

var newWin;
function openHlp(hlpurl,hlpheight,hlpwidth)
{
   if (newWin != null && !newWin.closed) newWin.close();
   newWin = null;

   var height = parseInt( screen.height * 0.7 );
   var width = parseInt( screen.width * 0.7 );
   if (hlpheight) height = hlpheight;
   if (hlpwidth) width = hlpwidth;
   var left = parseInt( ( screen.width - width ) /2 );
   var top = parseInt( ( screen.height - height ) /2 );
   newWin = open(hlpurl,"help","scrollbars=yes,resizable=yes,status=no,height=" +
            height + ",width=" + width + ",left=" + left + ",top=" + top);
}

// End -->


function RunCalculation() {
  // CopyRight, All Rights Reserved. Lyle Hopkins Cosmic Networks Ltd
  // Split name, setup and month by _
  var array;
  var name;
  var setup;
  var monthly;
  var checkservice;
  var checksolution;
  var setuptotal = 0;
  var monthlytotal = 0;
  var qty = 0;
  var currency = "$";
  var numservices = 0;
  var numsolutions = 0;
  var numoptions = 0;
  var includemonthly = 0;
  var includeoptqty = 0;
  if (document.calcform.service) {
    numservices = document.calcform.service.length;
  } // End if
  if (document.calcform.solution) {
    numsolutions = document.calcform.solution.length;
  } // End if
  if (document.calcform.option) {
    numoptions = document.calcform.option.length;
  } // End if
  if (document.calcform.totalmonthly) {
    includemonthly = 1;
  } // End if
  if (document.calcform.optionqty) {
    includeoptqty = 1;
  } // End if
  
  // Service calc
if (numservices) {
  array = "";
  name = "None";
  setup = 0;
  monthly = 0;
  for (var count=0; count<numservices; count++) {
    if (document.calcform.service[count].checked) {
      array = document.calcform.service[count].value.split("_");
      name = array[0];
      setup = array[1];
      monthly = array[2];
    } // End if
  } // End loop
  setuptotal = eval (setuptotal + "+" + setup);
  monthlytotal = eval (monthlytotal + "+" + monthly);
  document.calcform.servicecost.value = name;
} // End if

  // Solution calc
if (numsolutions) {
  array = "";
  name = "None";
  setup = 0;
  monthly = 0;
  for (var count=0; count<numsolutions; count++) {
    if (document.calcform.solution[count].checked) {
      array = document.calcform.solution[count].value.split("_");
      name = array[0];
      setup = array[1];
      monthly = array[2];
    } // End if
  } // End loop
  setuptotal = eval (setuptotal + "+" + setup);
  monthlytotal = eval (monthlytotal + "+" + monthly);
  document.calcform.solutioncost.value = name;
} // End if

  // Options calc
if (numoptions) {
  document.calcform.optionscost.value = "";
  for (var count=0; count<numoptions; count++) {
    if (document.calcform.option[count].checked) {
      array = document.calcform.option[count].value.split("_");
	  name = array[0];
      setup = array[1];
      monthly = array[2];
	  qty = 1;
	  if (includeoptqty) {
	    qty = document.calcform.optionqty[count].value;
	  } // End if
      setuptotal = eval (setuptotal + "+" + setup + " * " + qty);
      monthlytotal = eval (monthlytotal + "+ (" + monthly + " * " + qty + ")");
	  document.calcform.optionscost.value += ", ";
	  if (includeoptqty) {
	    document.calcform.optionscost.value += qty + " x ";
	  } // End if
      document.calcform.optionscost.value += name;
    } // End if
  } // End loop
  document.calcform.optionscost.value = document.calcform.optionscost.value.replace(/, /i,"");
} // End if

  document.calcform.totalsetup.value = currency + Format(setuptotal,2);
if (includemonthly) {
  document.calcform.totalmonthly.value = currency + Format(monthlytotal,2);
} // End if
  document.calcform.backpackages.focus()
  //document.calcform.service.value;
} 

function Format(total,decimals)
 {
      var num = parseFloat(total);
      // First section sets non-number value to zero
          if (!(num = parseFloat(num)))
               num = "0.00";
      // Second section sets two decimal place format
          var Pad = "";
          num = "" + Math.floor(num * Math.pow(10,decimals + 1) + 5);
          // Pad if less than 0.10
          if(num.length < decimals+1)
          {
               for(Count = num.length; Count <= decimals; Count++)
                    Pad += "0";
          }
          num = Pad + num;
     // Parse into final string
          num = num.substring(0,num.length - decimals - 1) +
               "." + num.substring(num.length - decimals -1, num.length -1);
     // If less than 1 then add 0 to the left of the decimal
          if((num == "") || (parseFloat(num) < 1))
               num = "0" + num;
     // Final section returns formatted number
          return num;
}

