/*********************************************************
	THIS SCRIPT AND ALL ITS CONTENTS ARE PROPRERTY OF
	SMITHKJAER.DK
	
		Copyright(c) 2004 smithKjaer.dk

*********************************************************/

var packtxt1 ="1 x Fotopakke 1E i ";
var packtxt2 ="1 x Fotopakke 2E i ";
var packtxt3 ="1 x Fotopakke 3E i ";
var packtxt4 ="1 x Fotopakke 1B i ";
var packtxt5 ="1 x Fotopakke 2B i ";
var packtxt6 ="1 x Fotopakke 3B i ";
var packtxt7 ="1 x Fotopakke 4B i ";
var packtxt8 ="1 x Fotopakke 1G i ";
var packtxt9 ="1 x Fotopakke 2G i ";
var packtxt10 ="1 x Fotopakke 3G i ";

var Forsendelsesomkostniger=30.00;
Pris = new Array(299.00,249.00,199.00,299.00,249.00,199.00,199.00,299.00,249.00,199.00);
checkboxSelected = new Array(false,false,false,false,false,false,false,false,false,false);
var methodStatus = new Array(1);
var rect = new Array(4);

function checkBoxValidate(){
	// document.myForm
}

function buildOrderForm(){
	var tmp = "";
	var udtone = "";
	tmp = document.forms[0].Pack1.value;
	if(document.forms[0].antal0.value != 0) {
		if(document.forms[0].udtone0.checked = true) udtone =" + UDTONING";
		document.forms[0].Pack1.value = document.forms[0].antal0.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris0.value + " = " + document.forms[0].pris0.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack2.value;
	if(document.forms[0].antal1.value != 0) {
		if(document.forms[0].udtone1.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack2.value = document.forms[0].antal1.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris1.value + " = " + document.forms[0].pris1.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack3.value;
	if(document.forms[0].antal2.value != 0) {
		if(document.forms[0].udtone2.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack3.value = document.forms[0].antal2.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris2.value + " = " + document.forms[0].pris2.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack4.value;
	if(document.forms[0].antal3.value != 0) {
		if(document.forms[0].udtone3.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack4.value = document.forms[0].antal3.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris3.value + " = " + document.forms[0].pris3.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack5.value;
	if(document.forms[0].antal4.value != 0) {
		if(document.forms[0].udtone4.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack5.value = document.forms[0].antal4.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris4.value + " = " + document.forms[0].pris4.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack6.value;
	if(document.forms[0].antal5.value != 0) {
		if(document.forms[0].udtone5.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack6.value = document.forms[0].antal5.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris5.value + " = " + document.forms[0].pris5.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack7.value;
	if(document.forms[0].antal6.value != 0) {
		if(document.forms[0].udtone6.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack7.value = document.forms[0].antal6.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris6.value + " = " + document.forms[0].pris6.value + " kr " + udtone;
		udtone = "";
	}
	tmp = document.forms[0].Pack8.value;
	if(document.forms[0].antal7.value != 0) {
		if(document.forms[0].udtone7.checked == true) udtone =" + UDTONING";
		document.forms[0].Pack8.value = document.forms[0].antal7.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris7.value + " = " + document.forms[0].pris7.value + " kr " + udtone;
	}
	// added not sure if this should be added
	//tmp = document.forms[0].Pack9.value;
	//if(document.forms[0].antal8.value != 0) {
	//	if(document.forms[0].udtone8.checked == true) udtone =" + UDTONING";
	//	document.forms[0].Pack9.value = document.forms[0].antal8.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris8.value + " = " + document.forms[0].pris8.value + " kr " + udtone;
	//}
	// added not sure if this should be added
	//tmp = document.forms[0].Pack10.value;
	//if(document.forms[0].antal9.value != 0) {
	//	if(document.forms[0].udtone9.checked == true) udtone =" + UDTONING";
	//	document.forms[0].Pack10.value = document.forms[0].antal9.value + " stk af " + "(" + tmp + ") at " + document.forms[0].stkpris9.value + " = " + document.forms[0].pris9.value + " kr " + udtone;
	//}
	
	
	document.forms[0].FMFromName.value = document.forms[0].email.value;
	document.forms[0].Forsendelseomkostninger.value = document.forms[0].postage.value + " kr";
	document.forms[0].Ialt.value = document.forms[0].total.value + " kr";
	
}

function subt(id){
	if(checkboxSelected[id]){
	   var j=0;
	   var p = 0;
	   var newPris = 0.0;
	   var res = 0.0;
	   var aVal=0; 
	   var aPris=0; 
	   var cObj = "";
	   var cTotalPris = "";
	   var cStkPris = "";
	   var tmpObj = "";
	   cObj = "document.forms[0].antal" + id;// "fotopack1E";
	   cTotalPris = eval("document.forms[0].pris" + id);//
	   cStkPris = "document.forms[0].stkpris" + id;//
	   var aVal = eval(cObj + ".value");
	   var aPris  = eval(cStkPris + ".value");
	   j = parseFloat(aVal) - 1;
	   if (j<=0) {
		   j = 0.0;
	   	   res = "0.00";	
	   } else {
	   	p = parseFloat(aPris);
	   	newPris = (j * p);
	   	res = roundToPennies(newPris);
	   }
	   eval(cObj + ".value = " + j);
	   cTotalPris.value = res; 
	   recalcStkTotal();
	} else alert("Sæt først kryds i F eller S/H");
}
// Calculate a new price
function add(id){
   if(checkboxSelected[id]){
      var j=0;
	   var p = 0;
	   var newPris = 0.0;
	   var aVal=0; 
	   var aPris=0; 
	   var cObj = "";
	   var cTotalPris = "";
	   var cStkPris = "";
	   var tmpObj = "";
	   cObj = "document.forms[0].antal" + id;// "fotopack1E";
	   cTotalPris = eval("document.forms[0].pris" + id);//
	   cStkPris = "document.forms[0].stkpris" + id;//
	   var aVal = eval(cObj + ".value");
	   var aPris  = eval(cStkPris + ".value");
	   j = parseFloat(aVal) + 1;
	   p = parseFloat(aPris);
	   newPris = (j * p); 
	   res = roundToPennies(newPris);
	   eval(cObj + ".value = " + j);
	   cTotalPris.value = res;
	   recalcStkTotal();
   } else alert("Sæt først kryds i F eller S/H");
}

function formatForm(){
	// packtxt1
	var i=0;
	FormTemplate = "name,address,postno,by,FMFromName,Payment,customerNo,Order";
	
	while(i<=6)
   	{ 
      	var test = cObj +i; 
      	if (eval(test+".name") != name){
	  	  // deactivate all other checkboxes which are enabled
		  (eval(test+".checked = false"));
		} else {
			if (id !="method"){
				document.myForm.Payment.value = eval(test+".value");
				eval("document.forms[0]." + id + 3 + ".value =" + 30); 
				//alert(cObj + 3);
			} else document.myForm.Payment.value = eval(test+".value");
		}
		i++; 
	}
	document.myForm.FMSortFields.value = FormTemplate;
//	<input type="hidden" name="FMSortFields" value="name,address,postno,by,FMFromName,Payment,customerNo,Order,Pack1,Pack2,Pack3,Pack4,Pack5,Pack6,Pack7,Pack8,Pack9,Pack10,IP,Dato">
}

function doPostPak() {

	if(checkPakForm()){	
		document.myForm.action="http://www.uniquefoto.dk/formmail.asp";
		document.myForm.submit();
	}

}
function checkStkForm()
{
   var error = true;
   var errorTxt = "";
   list=0;
   txtMsg = "disse felter";
   if (document.forms[0].navn.value==""){
      	errorTxt = errorTxt + "- Barnets navn \n"; 
      	list++;
		error = false;
   }
   if (document.forms[0].adresse.value==""){
      	errorTxt = errorTxt + "- Adresse\n"; 
      	list++;
		error = false;
   }
   if (document.forms[0].postno.value==""){
		errorTxt = errorTxt + "- Post nr.\n"; 
		list++;
		error = false;
   }
	if (document.forms[0].by.value==""){
	    errorTxt = errorTxt + "- By\n"; 
    	list++;
		error = false;
   }
   if (document.forms[0].customerNo.value==""){
	    errorTxt = errorTxt + "- Kunde nr.\n"; 
    	list++;
		error = false;
   }
      if (document.forms[0].email.value==""){
	    errorTxt = errorTxt + "- Email\n"; 
    	list++;
		error = false;
	  }
	  if (document.forms[0].total.value=="0.00"){
	    errorTxt = errorTxt + "- Du har ikke valgt en efterbestilling\n"; 
    	list++;
		error = false;
	  }
	   if (document.forms[0].Payment.value==""){
	    errorTxt = errorTxt + "- Du skal angive indbetalingsmåde\n"; 
    	list++;
		error = false;
	  }
		  	
	if(list==1) txtMsg = "dette felt"; 
	if (false == error) alert("Du mangler at udfylde " + txtMsg + ": \n" + errorTxt);
	return error;
	
}
function checkPakForm()
{
   var error = true;
   var errorTxt = "";
   list=0;
   txtMsg = "disse felter";
   if (document.forms[0].navn.value==""){
      	errorTxt = errorTxt + "- Barnets navn \n"; 
      	list++;
		error = false;
   }
   if (document.forms[0].adresse.value==""){
      	errorTxt = errorTxt + "- Adresse\n"; 
      	list++;
		error = false;
   }
   if (document.forms[0].postno.value==""){
		errorTxt = errorTxt + "- Post nr.\n"; 
		list++;
		error = false;
   }
	if (document.forms[0].by.value==""){
	    errorTxt = errorTxt + "- By\n"; 
    	list++;
		error = false;
   }
   if (document.forms[0].KunderNr.value==""){
	    errorTxt = errorTxt + "- Kunde nr.\n"; 
    	list++;
		error = false;
   }
      if (document.forms[0].emailaddr.value==""){
	    errorTxt = errorTxt + "- Email\n"; 
    	list++;
		error = false;
	  }
	  if (document.forms[0].total.value=="0.00"){
	    errorTxt = errorTxt + "- Du har ikke valgt en fotopakke\n"; 
    	list++;
		error = false;
	  }
	   if (document.forms[0].Payment.value==""){
	    errorTxt = errorTxt + "- Du skal angive indbetalingsmåde\n"; 
    	list++;
		error = false;
	  }
	
	if(list==1) txtMsg = "dette felt"; 
	if (false == error) alert("Du mangler at udfylde " + txtMsg + ": \n" + errorTxt);
	return error;
	
}

function checkKontaktForm()
{
   var error = true;
   var errorTxt = "";
   list=0;
   txtMsg = "disse felter";
   if (document.forms[0].Skole.value==""){
      	errorTxt = errorTxt + "- Skole\n"; 
      	list++;
		error = false;
   }
   if (document.forms[0].Adresse.value==""){
      	errorTxt = errorTxt + "- Adresse\n"; 
      	list++;
		error = false;
   }
   if (document.forms[0].Postnr.value==""){
		errorTxt = errorTxt + "- Postnr\n"; 
		list++;
		error = false;
   }
	if (document.forms[0].By.value==""){
	    errorTxt = errorTxt + "- By\n"; 
    	list++;
		error = false;
   }
   if (document.forms[0].Tel.value==""){
	    errorTxt = errorTxt + "- Telefon\n"; 
    	list++;
		error = false;
   }
      if (document.forms[0].FMFromName.value==""){
	    errorTxt = errorTxt + "- e-mail\n"; 
    	list++;
		error = false;
   }
       if (document.forms[0].kontaktperson.value==""){
	    errorTxt = errorTxt + "- Kontaktperson\n"; 
    	list++;
		error = false;
   }
	if(list==1) txtMsg = "dette felt"; 
	if (false == error) alert("Du mangler at udfylde " + txtMsg + ": \n" + errorTxt);
	return error;
// ||(document.forms[0].Adresse.value=="")||(document.forms[0].Postnr.value==""))

}
//////////////////////////////////////////////////////////////////////////////////////
//  Send Kontakt information
//////////////////////////////////////////////////////////////////////////////////////
function doPostKontackt() {
	// checkForm();
	//formatForm();
	if(checkKontaktForm()){	
		//buildOrderForm(); // This is only for single item orders
		document.myForm.action="http://www.uniquefoto.dk/formmail.asp";
		document.myForm.submit();
	}
}

function doPost() {
	if(checkStkForm()){	
		buildOrderForm(); // This is only for single item orders
		document.myForm.action="http://www.uniquefoto.dk/formmail.asp";
		document.myForm.submit();
	}
}

function warningMsg(){
	alert("You can only select F or S/H but not both at the same time");
}

function roundToPennies(n)
{
 pennies = n * 100;

 pennies = Math.round(pennies);

 strPennies = "" + pennies;
 len = strPennies.length;

 return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}

/***********************************************************************
	 make a group of checkboxes work like a goup of radio button
***********************************************************************/
function validateMethod(name,id,count,packno){
   var j=0;
   var i=1; 
   var numberofcheckboxes=count; 
   var cObj = "";
   var tmpObj = "";
   var zeroPris = "0.00";
   //var cPris = "document.forms[0].pris";
   // cObj = "document.forms[0].method"; 
   cObj = "document.forms[0]." + id;// "fotopack1E";
   
   
   //alert(CommaFormatted(17000)); // Test
   // pakkerPris = new Array(29500,24900,19900,29900,24900,19900);
   // pakkerSubTotal = new Array(0,0,0,0,0,0);
   
   while(i<=numberofcheckboxes)
   { 
      	var aValue="";
		var test = cObj +i; 
      	if (eval(test+".name") != name){
	  	  // deactivate all other checkboxes which are enabled
		  (eval(test+".checked = false"));
		} else {
			if (id !="method"){ 
				// Checkbox enabled
				document.myForm.Payment.value = eval(test+".value");
				// Set price
				// eval("document.forms[0]." + id + 3 + ".value =" + 30);  // update pris may not be the correct amount
				aPris = eval(Pris[packno-1]);
				res = roundToPennies(aPris);
				aTmpObj = (eval("document.forms[0]." + id + 3));  // update pris may not be the correct amount
				aTmpObj.value = res;
				// Set description
				textdes = (eval("document.forms[0]." + name + ".value"));
				update = "document.forms[0].Pack" + packno;
				// alert(update);
				tmpObj = eval(update);
				tmpObj.value = textdes;
				
			} else {
				document.myForm.Payment.value = eval(test +".value");
			}
		}
		i++; 
	}
	
	// if clicked checkbox "name" is disabled reset pris to zero
	if(id!="method"){
		if(eval("document.forms[0]." + name + ".checked") == false) {
			tmpObj1 = eval("document.forms[0]." + id + 3);
			tmpObj1.value = zeroPris; // Reset values to zero because checkbox is disabled
			
			tmpObj = eval("document.forms[0].Pack" + packno);
			tmpObj.value = "";
		} 
	} else {
		if((eval("document.forms[0].method[0].checked") == false) && (eval("document.forms[0].method[1].checked") == false) && (eval("document.forms[0].method[2].checked") == false)) { // Reset payment method
			document.forms[0].Payment.value ="";
		}
	}

	recalcTotal();
}

/***********************************************************************
	 make a group of checkboxes work like a goup of radio button
***********************************************************************/
function validateMethod2(name,id,count,packno){
   var j=0;
   var i=1; 
   var numberofcheckboxes=count; 
   var cObj = "";
   var tmpObj = "";
   var zeroPris = "0.00";
   //var cPris = "document.forms[0].pris";
   // cObj = "document.forms[0].method"; 
   cObj = "document.forms[0]." + id;// "fotopack1E";
   
   while(i<=numberofcheckboxes)
   { 
      	
		var test = cObj +i; 
      	if (eval(test+".name") != name){
	  	  // deactivate all other checkboxes which are enabled
		  (eval(test+".checked = false"));
		} else {
			if (id !="method"){ 
				// Checkbox is enabled
				checkboxSelected[packno-1] = true;
				// Set description
				textdes = (eval("document.forms[0]." + name + ".value"));
				update = "document.forms[0].Pack" + packno;
				tmpObj = eval(update);
				tmpObj.value = textdes;
			} else {
				document.myForm.Payment.value = eval(test +".value");
			}
		}
		i++; 
	}
	
	// if clicked checkbox "name" is disabled reset pris to zero
	
	if(id!="method"){
		if(eval("document.forms[0]." + name + ".checked") == false) {
			tmpObj1 = eval("document.forms[0]." + id + 3); // Reset values to zero because checkbox is disabled
			tmpObj1.value = zeroPris;
			
			tmpObj = eval("document.forms[0].Pack" + packno);
			tmpObj.value = "";
			
			// Reset amount to zero
			eval("document.forms[0].antal" + (packno-1) + ".value =" + 0);
			checkboxSelected[packno-1] = false;
			//recalcStkTotal();
		}
	} else {
		if((eval("document.forms[0].method[0].checked") == false) && (eval("document.forms[0].method[1].checked") == false) && (eval("document.forms[0].method[2].checked") == false)) { // Reset payment method
			document.forms[0].Payment.value ="";
		}
	}
	recalcStkTotal();
	// recalcStkTotal();
}

function recalcStkTotal(){
	// alert("recalulated order");
	var postage = "0.00";
	var i=0;
	var aVal = 0;
	totalval = 0;
	while(i<=7){
		if (eval("document.forms[0].pris" + i + ".value")==0){
			// alert("yes"); // This needs to be updated
		}
		aVal = eval("document.forms[0].pris" + i + ".value"); 
		totalval = parseFloat(totalval) + parseFloat(aVal);
		i++; 
	}
	
	if (totalval != "0.00") {
		tmp = parseFloat(Forsendelsesomkostniger);
		val = parseFloat(totalval) + tmp;
		totalval = roundToPennies(val);
		postage = roundToPennies(tmp);
	}
	objPost = eval("document.forms[0].postage");
	objPost.value = postage;
	objTotal = eval("document.forms[0].total");
	if(totalval == 0) totalval = "0.00";
	objTotal.value = totalval;
}

function recalcTotal(){
	// alert("recalulated order");
	var postage = "0.00";
	var i=0;
	var aVal = 0;
	var totalval = "0.00";
	while(i<=8){
		if (eval("document.forms[0].pris" + i + ".value")==0){
			// alert("yes"); // This needs to be updated
		}
		aVal = eval("document.forms[0].pris" + i + ".value"); 
		totalval = parseFloat(totalval) + parseFloat(aVal);
		// alert(totalval);
		i++; 
	} 
	
	if (totalval != "0.00") {
		tmp = parseFloat(Forsendelsesomkostniger);
		val = parseFloat(totalval) + tmp;
		totalval = roundToPennies(val);
		postage = roundToPennies(tmp);
	} 
	objPost = eval("document.forms[0].postage");
	objPost.value = postage;
	
	objTotal = eval("document.forms[0].total");
	if(totalval <= 0) totalval = "0.00";
	objTotal.value = totalval;
	//alert(totalval);
}

function popUp(url,wintitle,width, height){
	var centerX=(screen.width-width)/2; //Need to subtract the window width/height so that it appears centered. If you didn't, the top left corner of the window would be centered. 
	var centerY=(screen.height-height)/2; 
	//window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+ width +",height=" + height + ",left =" + rect[0] +",top =" + rect[1] +"');");
	window.open(url, wintitle, 'width='+width+',height='+height+',left='+centerX+',top='+centerY); 
}

function availHeight(){
	
}

function colourDepth(){
	alert(Math.pow(2,screen.colorDepth));
}

// Using decimals

isMoneyFormatAmount = 0.00;
isMoneyFormatString = "0.00";

function isMoneyFormat(str,eur) {
   isMoneyFormatAmount = 0.00;
   isMoneyFormatString = "0.00";
   if(!str) return false;
   str = "" + str; // force string
   for (var i=0; i<str.length;i++) {
      var ch = str.charAt(i);
      if (!isNum(ch) && ch!='.' && ch != ',' && ch !='-') return false
   }

   var sign = 1;
   var signChar = '';
   isMoneyFormatAmount = 0.00;
   isMoneyFormatString = "0.00";

   if (str.length > 1) {
      signChar = str.substring(0,1);
      if (signChar == '-' || signChar == '+' ) {
         if (signChar == '-') sign = -1;         
         str = str.substring(1);
      }
      else signChar = '';
   }
   var decimalPoint = '.';
   var thDelim = ',';
   if (eur) { 
      decimalPoint = ','
      thDelim = '.';
   }
   test1 = str.split(decimalPoint);
   if (test1.length == 2) { // Decimals found
      if (test1[1].length > 2) return false; // more than 2 decimals
      if (isNum(test1[1])) {
         if (test1[1] < 9 && test1[1].charAt(0) > 0) test1[1] = new String(test1[1]+"0");
      }
      else return false; 
   }
   else test1[1] = "00"; // force decimals
   if (test1[0] == '') test1[0] = 0;
   if (test1[0] && test1[0].indexOf(thDelim) != -1) {
      test2 = test1[0].split(thDelim);  
      if (test2.length >= 2) { // thousands found
         var thError = false;
         for (var i=0;i<test2.length;i++) {
            if (test2[i].length < 3 && i != 0) { thError = true; break; } // all thousands exept the first.
            if (!isNum(test2[i])) { thError = true; break; } // all numbers
         }
         if (thError) return false;
         test1[0] = test2.join('')
      }
   }
   isMoneyFormatAmount = (parseInt(test1[0]) + parseFloat('.'+test1[1]))*sign;
   isMoneyFormatString = new String(""+signChar+""+parseInt(test1[0])) +'.'+test1[1];
   return true;
} 

function isNum(str) {
  if(!str) return false;
  for(var i=0; i<str.length; i++){
    var ch=str.charAt(i);
    if ("0123456789".indexOf(ch) ==-1) return false;
  }
  return true;
} 


//////////////////////////////////////////////////////////
// toolbox - Number of deciaml places
//////////////////////////////////////////////////////////
// toFixxed() :
function(f) {
  f = parseInt(f/1 || 0)
  if (f<0 || f>20) // next line was throw ...
    alert("The number of fractional digits is out of range")
  if (isNaN(this)) return "NaN"
  var s = this<0 ? "-" : "", x = Math.abs(this)
  if (x>Math.pow(10,21)) return s + x.toString()
  var m = Math.round(x*Math.pow(10,f)).toString()
  if (!f) return s + m
  while (m.length<=f) m = "0" + m
  return s + m.substring(0,m.length-f)+"."+m.substring(m.length-f)
  }

function DA2(X, M) {
  return (new Number(X)).toFixxed(M) }

// Convert to pence
function BadStrOfPence(X) { var S, T
  return (S=new String(Math.round(X*100))).substr(0,
    T=(S.length-2)) + '.' + S.substr(T, 2) }

// Convert to string
function OKStrOfPenny(X) { var T, S=new String(Math.round(X*100))
  while (S.length<3) S='0'+S
  return S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2) }



function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
	var nn = n.substr(n.length-3);
	a.unshift(nn);
	n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}



