function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function round2decimal(value) {
  return Math.round(value * 100) / 100
}

function complete2decimal(value) {
  value = round2decimal(value);
  value += '';
  x = value.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? x[1] : '';

  if (x2.length < 1) {
	  value += '.';
  }
  
  for (i = x2.length; i < 2; i++) {
    value += '0';
  }
  return value;
}

function changeRecips(form) {

  form.Recipient[2].checked = true;

}

function clearSLForm()  {
  document.nsform.String.value = "";
  document.nsform.Where.selectedIndex  = "0";
  //document.nsform.Which.selectedIndex  = "0";
  document.nsform.Type.selectedIndex  = "0";
  document.nsform.Category.selectedIndex  = "0";
  document.nsform.Month.selectedIndex  = "0";
  document.nsform.Year.selectedIndex  = "0";
	if (getEl("labelType") != null)
		getEl("labelType").selectedIndex = "0";
	constructParameters();
}

function clearPPForm()  {

  document.nsform.String.value = "";
  document.nsform.Where.selectedIndex  = "0";
  document.nsform.Colour.selectedIndex  = "0";
  document.nsform.Category.selectedIndex  = "0";
  document.nsform.Month.selectedIndex  = "0";
  document.nsform.Year.selectedIndex  = "0";

}

function clearCLForm()  {

  document.nsform.String.value = "";
  document.nsform.Where.selectedIndex  = "0";
  //document.nsform.Which.selectedIndex  = "0";
  document.nsform.Cat.selectedIndex  = "0";
  document.nsform.Month.selectedIndex  = "0";
  document.nsform.Year.selectedIndex  = "0";
}

function ViewImage(imageName, w, h) {
   var imageWin
   if (imageWin) { imageWin.close() }

   var leftPos = 0
   var topPos = 0
    

   imageWin = window.open('showPlantImage.php?type=preview&file_number='+imageName,'imageprev','scrollbars=no,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
   imageWin.focus();

}

function ViewPDF(imageName) {
   var imageWin
   if (imageWin) { imageWin.close() }

   var leftPos = 0
   var topPos = 0

   imageWin = window.open(imageName,'pdfView','scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
   imageWin.focus();
}

function doEcho() {
  if (document.nform.Duplicate_Address.checked) {
     document.nform.Shipping_Address.value=document.nform.Billing_Address.value;
     document.nform.Shipping_Address1.value=document.nform.Billing_Address1.value;
     document.nform.Shipping_State.value=document.nform.Billing_State.value;
     document.nform.Shipping_Suburb.value=document.nform.Billing_Suburb.value;
     document.nform.Shipping_Postcode.value=document.nform.Billing_Postcode.value;
     document.nform.Shipping_Country.value=document.nform.Billing_Country.value;
  }

}

function change_page(form)  {
var tmp;

selecteditem = form.gotopage.selectedIndex;
tmp = form.gotopage.options[selecteditem].value;

change_page_byID(tmp);
}

function change_page_byID(tmp) {
var location;
if (parent.parent.content != null)
  location = parent.parent.content.location;
else
  location = top.location;

if (tmp == '1') location.href = "stocklabels.php";
if (tmp == '2') location.href = "stocklabels.php?show=custom";
if (tmp == '3') location.href = "customlabels.php";
if (tmp == '4') location.href = "orders.php"; // orders.htm -- Jimmy 10:03 AM Thursday, June 01, 2006
if (tmp == '5') location.href = "stocklabels.php?show=cart";
if (tmp == '6') location.href = "customlabels.php?show=custom";
if (tmp == '7') location.href = "customlabels.php?show=cart";
if (tmp == '8') location.href = "descriptives.php?labelType=descriptivesStock";
if (tmp == '9') location.href = "descriptives.php?labelType=descriptivesCustom";
if (tmp == '10') location.href = "descriptives.php?show=custom&labelType=descriptivesStock";
if (tmp == '11') location.href = "descriptives.php?show=custom&labelType=descriptivesCustom";
if (tmp == '12') location.href = "descriptives.php?show=cart&labelType=descriptivesStock";
if (tmp == '13') location.href = "descriptives.php?show=cart&labelType=descriptivesCustom";
}

function alterRC(what,col) {
   try {
	 (what != null)? what.style.background = col : null;
   }
   catch(errorObject) {
	 alert('what is not an obj\t error = ' + errorObject.description);
   }

}

function changeLabel(itm, pr, string, where, type, orderby, srt, ct, mth, yr, pg, shw, op) {
	 parent.ipanel.location = "imagepanel.php?item=" + itm + "&pr=" + pr + "&String=" + string + "&Where=" + where + "&Type=" + type + "&orderby=" + orderby + "&sort=" + srt + "&Category=" + ct + "&Month=" + mth + "&Year=" + yr + "&page=" + pg + "&show=" + shw + "&op=" + op;
}

function changeImage(itm, pr, string, where, clr, orderby, srt, ct, mth, yr, pg, shw, op) {
   parent.ipanel.location = "imagepanel.php?plantpic=1&imageno=" + itm + "&pr=" + pr + "&String=" + string + "&Where=" + where + "&Colour=" + clr + "&orderby=" + orderby + "&sort=" + srt + "&Category=" + ct + "&Month=" + mth + "&Year=" + yr + "&page=" + pg + "&show=" + shw + "&op=" + op;
}

function changeCustom(itm, op) {
   parent.ipanel.location = "customlabelrequest.php?" + itm  + op;
}

//duck 24/01/06
function closePanel()
{
	//clear the panel first (to prevent flickering when it is reopened
	//with a new image
	parent.ipanel.location = "blank.html";

	//then resize to hide it away
	parent.document.body.rows='*,0';
}
