// JavaScript Document
<!-- //hide from older browsers.

//mnj displays enlarged photo of product
function PopImage( path, file, w, h, name ) { 
	thewindow = window.open(path + file, name, config='height=' + h + ',width=' + w + ',toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no'); 

} 

function GetPrice ( unique_cart_id, qty ) { 

	switch (unique_cart_id) {
		
		case 1: { // Pain Spray	
		
			if (qty == 1) 											{return 9.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 8.95; }
			else if ((qty >= 6) && (qty <= 11)) {return 8.45; }
			else if ((qty >= 12) && (qty <= 23)){return 7.95; }
			else if (qty > 23) 									{return 5.56; }
			break; 
		}
		
    case 2: { // Mite-NIX Allergy Relief
		
		  if (qty == 1) 											{return 11.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 10.95; }
			else if ((qty >= 6) && (qty <= 11)) {return 9.95; }
			else if ((qty >= 12) && (qty <= 23)){return 8.59; }
			else if (qty > 23)									{return 5.90; }
			break; 
		}
		
		case 3: { // Mite-NIX Pet Shampoo
		
		  if (qty == 1) 											{return 9.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 8.95; }
			else if ((qty >= 6) && (qty <= 11)) {return 8.45; }
			else if ((qty >= 12) && (qty <= 23)){return 7.95; }
			else if (qty > 23)									{return 5.85; }
			break; 
		}
		
		
		case 4: { // Pain Spray 1 oz. Travel Size
		
		  return 0.01; 
			break; 
		}
		
		case 5: { // Mite-NIX Laundry Rinse
		
		  if (qty == 1) 											{return 11.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 10.95; }
			else if ((qty >= 6) && (qty <= 11)) {return 9.95; }
			else if ((qty >= 12) && (qty <= 23)){return 8.59; }
			else if (qty > 23) 									{return 5.90; }
			break; 
		}

		case 6: { //  Mite-NIX Mold & Mildew Cleaner
			// mnj 01/22/08 inacative price
			//if (qty == 1) 											{return 7.95; }
			//else if ((qty >= 2) && (qty <= 5)) 	{return 6.95; }
			//else if ((qty >= 6) && (qty <= 11)) {return 6.45; }
			//else if ((qty >= 12) && (qty <= 23)){return 5.95; }
			//else if (qty > 23) 									{return 3.90; }
		
			//break;
			
			if (qty == 1) 											{return 11.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 10.95; }
			else if ((qty >= 6) && (qty <= 11)) {return 9.95; }
			else if ((qty >= 12) && (qty <= 23)){return 8.59; }
			else if (qty > 23) 									{return 5.90; }
			break; 

		}

		case 7: { //  Mite-NIX Value Pack

			// mnj 01/22/08 inacative price
			//if (qty >= 1) 											{return 27.85; }
			
			if (qty >= 1) 											{return 32.95; }

			break; 
		}

		case 8: { // Creme De La Femme
		
			if ((qty >= 1) && (qty <= 2)) 			{return 14.95; }
			else if ((qty >= 3) && (qty <= 5)) 	{return 11.00; }
			else if (qty > 5) 									{return 10.00; }
			break; 
		}

		case 9: { // Mite-NIX Allergy Relief Economy Quart Refill

			if (qty == 1) 											{return 19.95; }
			else if ((qty >= 2) && (qty <= 3)) 	{return 18.95; }
			else if (qty >= 4) 									{return 14.95; }
			break; 
		}

		case 10: { // Mite-NIX Allergy Relief Economy Gallon Refill
		
		 	if (qty == 1) 											{return 59.95; }
			else if (qty >= 2) 									{return 54.95; }
			break; 
		}

		case 11: { // Mite-NIX Laundry Rinse Economy Quart Refill

			if (qty == 1) 											{return 19.95; }
			else if ((qty >= 2) && (qty <= 3)) 	{return 18.95; }
			else if (qty >= 4) 									{return 14.95; }
			break; 
		}

		case 12: { // Mite-NIX Laundry Rinse Economy Gallon Refill 
		
		 	if (qty == 1) 											{return 59.95; }
			else if (qty >= 2) 									{return 54.95; }
			break; 
		}

		case 13: { // Plant Rescue
		
			if (qty == 1)									 			{return 14.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 13.95; }
			else if ((qty >= 6) && (qty <= 23))	{return 11.95; }
			else if (qty > 23) 									{return 9.95; }
			break; 
		}

		case 14: { //  Headache Re-leaf
			if ((qty >= 1) && (qty <= 2))				{return 7.95; }
			else if ((qty >= 3) && (qty <= 5)) 	{return 7.00; }
			else if ((qty >= 6) && (qty <= 23))	{return 6.00; }
			else if (qty > 23) 									{return 4.00; }
		
			break; 
		}
		
		case 15:  // Aroma Works Pocket Inhalers (all scents)
		case 16:  // Aroma Works Pocket Inhalers (all scents)
		case 17:  // Aroma Works Pocket Inhalers (all scents)
		case 18:  // Aroma Works Pocket Inhalers (all scents)
		case 19:  // Aroma Works Pocket Inhalers (all scents)
		case 20: { // Aroma Works Pocket Inhalers (all scents)
			if (qty == 1) 											{return 8.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 7.95; }
			else if ((qty >= 6) && (qty <= 11)) {return 6.95; }
			else if ((qty >= 12) && (qty <= 23)){return 6.45; }
			else if (qty > 23) 									{return 5.45; }
		
			break; 
		}
		
		case 21: { //  Mite-NIX Value Pack

			if (qty >= 1) 											{return 24.95; }

			break; 
		}

		case 22: { // Prostate Health Cocktail
		
			if (qty == 1)									 			{return 59.95; }
			else if ((qty >= 2) && (qty <= 5)) 	{return 49.95; }
			else if ((qty >= 6) && (qty <= 23))	{return 44.95; }
			else if (qty > 23) 									{return 38.88; }
			break; 
		}
		
		case 24: { // Creme Travel Size

			if (qty >= 1) 											{return 3.95; }
			break; 
		}

		
		case 29: { // Prostate Health Cocktail (Buy 1 Get 2nd Half Off)
		
			return 59.95;
			break; 
			
		}
		

		case 30: { // Pain Spray 1 oz. Travel Size
		
			if (qty >= 1) 											{return 3.95; }
			break; 
		}


		default: return 0.00;
	}
 } 
 

function totalPlusTax(unique_cart_id, ele)
{
	//alert('lol');
	/* User's desired quantity. */
	var qty = ele.value;
	/* check for invalid input. */
	if ( isNaN(qty) || ((qty == '') || (qty < 0) || (qty % 1 > 0)))  
	{
		alert('You must enter a numeric value between 0 and 999');
		qty = 0;
		ele.value = 0;
		ele.focus();
	} 
		/* A straight price of 59.95 all the time as of 10/23/09. */
		var price = GetPrice(unique_cart_id,qty);
		var subTotal1 = price * qty;
		/* Current CA tax is 9.25% as of 10/23/09. Subject to change. */
		var taxMultiple = 9.25 / 100;
		var subTotal2 = subTotal1 + (subTotal1 * taxMultiple);
		/* Note: shipping is provided FREE as of 10/23/09. Subject to change upon client's request. */
		/* Set the shown quantities to equal what the user entered */
		for(var c = 0; c < 1; c++)
		{
			/* Get the div that shows quantity. */
			var element = document.getElementById("showQuantity" + c);
			element.innerHTML = ("" + qty);
		}
		/* Set the shown subTotal without tax. */
		var e = document.getElementById("showSubTotal1");
		e.innerHTML = formatCurrency(subTotal1);
		/* Set the shown subTotal with tax. */
		e = document.getElementById("showSubTotal2");
		e.innerHTML = formatCurrency(subTotal2);
		/* Set the hidden field "prodsubtotal" so that the cart will know what the subtotal is. */
		
		/* mnj OLD e = document.cartform.prodsubtotal;*/
		e = document["cartform"+unique_cart_id].prodsubtotal;
		
		e.value = subTotal2;
}
 
// mnj this has threshold at 6+ for pricing every bottle the same

function prtotal(unique_cart_id, ele){
  var qty=0,ttlqty=0,fee,ttlprice=0;
  var i;
  var tqty;
  var count;
  var ttlcounter;
  var arrayLength;
  
  if (isNaN(ele.value))  {
   alert('You must enter a numeric value between 0 and 999');
   ele.value = 0;
   ele.focus();
  } else {
   if (ele.value==''||ele.value<0||ele.value%1>0) {
    alert('You must enter a numeric value between 0 and 999');
    ele.value=0;
    ele.focus();
   }
 	}
  
  //mnj orig var oProds = document.cartform.quantity;
	var oProds = document["cartform"+unique_cart_id].quantity;
	//var oProds = eval( "document.cartform" + unique_cart_id + ".quantity" );
  if (!oProds.length) arrayLength = 1;
  else arrayLength = oProds.length;

  /* Calculate Matrix Variables */
  ttlqty = TotalCount( arrayLength, document["cartform"+unique_cart_id] );
  var ttlPricePerBottle = GetPrice( unique_cart_id, ttlqty );
  var ttlPriceForFirstBottle =  GetPrice( unique_cart_id, 1 );
  
  /* Index the current product..  First bottle is always 5.95 */
  if (ttlqty >= 6) { ttlcounter = 1; }
  else { ttlcounter = 0; }
 
  /* Receipt Description */
  var description = "";
    
  for (i=0; i<arrayLength; i++ ) {
      /* Get the QTY from the Array */
      if (arrayLength > 1) qty = parseInt(document["cartform"+unique_cart_id].quantity[i].value);
      if (arrayLength == 1) qty = parseInt(document["cartform"+unique_cart_id].quantity.value);
   
   /* Add the subtotals and grand */
   if ((ttlcounter == 0) && (qty > 0)) {
    /* Local Sub Total Calc */
    price = ttlPriceForFirstBottle + ((qty - 1) * ttlPricePerBottle)
 
    /* Add it to the total */    
    ttlprice += price;
    
    /* Okay.  No more of this. */
    ttlcounter = 1;
   } else {
    /* Local Sub Total Calc */
    price = (qty * ttlPricePerBottle);
   
    /* Add to total */
    ttlprice += price;
   }
    
   if ((document["cartform"+unique_cart_id].isMac.value == "True")||(document["cartform"+unique_cart_id].isNetscape6.value == "True")||(document["cartform"+unique_cart_id].isIE.value == "False")) { 
      if (arrayLength > 1) document["cartform"+unique_cart_id].prodsubtotal[i].value = formatCurrency(price);
      if (arrayLength == 1) document["cartform"+unique_cart_id].prodsubtotal.value = formatCurrency(price);
   } else {
      UpdateDivContent('divSubtotal'+ i,  '<span class=blk11>' + formatCurrency(price) + '</span>');
   } 
  }
  
}

//function like prtotal, except for every two bottles, 1 is half off. Written by Benjamin D. Beasley on 09/12/09.
function prtotal5halfoff(unique_cart_id, ele)
{
	//alert("lol!");
	
  	var qty=0,ttlqty=0,fee,ttlprice=0;
  	var i;
  	var tqty;
  	var count;
  	var ttlcounter;
  	var arrayLength;
	var tf = true;
  	//alert("value: " + ele.value);
	if (isNaN(ele.value))  
	{
   		document.getElementById("message").innerHTML = 'You must enter a numeric value between 0 and 999';
		ele.value = 0;
   		ele.focus();
		tf = false;
  	} 
	else 
	{
   		if (ele.value==''||ele.value<0||ele.value%1>0)
		{
    		document.getElementById("message").innerHTML = 'You must enter a numeric value between 0 and 999';
    		ele.value=0;
    		ele.focus();
			tf = false;
   		}
 	}
	
  	/* Note, first bottle price is always at a big discount price. */
  	ttlqty = ele.value;
  	var ttlPricePerBottle = GetPrice( unique_cart_id, ttlqty );
		var qty = ttlqty;
		var qty_halfoff = 0;
		var qty_normal = 0;
		var amt_saved = 0;
		//Half will be @ half price, and half will be @ normal price.
		if(qty % 2 == 0)
		{
			//alert("lol6    qty: "  + qty);
			if(qty != 0)
			{
				//alert("lol7");
				qty_halfoff = qty / 2;
				qty_normal = qty / 2;
			}
		}
		else if (qty != 1)
		{
			//alert("lol8");
			qty_halfoff = ((qty - 1) / 2);
			qty_normal = ((qty - 1) / 2) + 1;
		}
		else
		{
			qty_halfoff = 0;
			qty_normal = 1;
		}
    	 /* calc the price of regular product plus the half-off prices of every other bottle.*/
		var price_halfoff = (ttlPricePerBottle / 2)  - 0.005;
    	price = (qty_normal * ttlPricePerBottle) + (qty_halfoff * price_halfoff);
 		amt_saved = (qty_halfoff) * ((ttlPricePerBottle / 2) + 0.005);
  		/* Receipt Description */
  		var description = "";
		//alert("lol3");
		if ((document.cartform.isMac.value == "True") || (document.cartform.isNetscape6.value == "True") || (document.cartform.isIE.value == "False")) 
   		{ 
			//alert("lol2");
		  	document.cartform.prodsubtotal.value = formatCurrency(price);
   		} 
   		else 
   		{
			//alert("lol4");
      		UpdateDivContent('divSubtotal'+ i,  '<span class=blk11>' + formatCurrency(price) + '</span>');
   		} 
		
		//MR. BEASLEY, EDIT THESE TO CHANGE WHAT IS SAID WHEN quantity entered is greater than  or equal to 2,  equal to one, or is equal to 0.
		if(tf)
		{
			if(qty % 2 != 0)
			{
				if(qty == 1)
				{
					document.getElementById("message").innerHTML = "Buy 2, and get the second bottle half off.";
				}
				else
				{
					var num_shouldbuy = parseInt(qty,0) + 1;
					var temp1 = (parseInt(qty,0) +1) / 2;
					var save = (temp1) * ((ttlPricePerBottle / 2) + 0.005);
					var newprice = (temp1 * price_halfoff) + (temp1 * (ttlPricePerBottle));
					//alert("lol1");
					document.getElementById("message").innerHTML = "Buy " + num_shouldbuy + " bottles for " + formatCurrency(newprice) +  " and save " + formatCurrency(save) +".";
					//alert("lol2");
				}
			}
			else 
			{
				if(qty >= 2)
				{
					document.getElementById("message").innerHTML = "You save " + formatCurrency(amt_saved);
				}
				else
				{
					document.getElementById("message").innerHTML = "Buy one, get one half off.";
				}
			}
		}
}

// mnj duplicate of prtotal except this has threshold at 4+ (for Mite-Nix) for pricing every bottle the same

function prtotal4Threshold(unique_cart_id, ele){
  var qty=0,ttlqty=0,fee,ttlprice=0;
  var i;
  var tqty;
  var count;
  var ttlcounter;
  var arrayLength;
  
  if (isNaN(ele.value))  {
   alert('You must enter a numeric value between 0 and 999');
   ele.value = 0;
   ele.focus();
  } else {
   if (ele.value==''||ele.value<0||ele.value%1>0) {
    alert('You must enter a numeric value between 0 and 999');
    ele.value=0;
    ele.focus();
   }
 	}
  
  var oProds = document["cartform"+unique_cart_id].quantity;
  
  if (!oProds.length) arrayLength = 1;
  else arrayLength = oProds.length;

  /* Calculate Matrix Variables */
  ttlqty = TotalCount( arrayLength, document["cartform"+unique_cart_id] );
  var ttlPricePerBottle = GetPrice( unique_cart_id, ttlqty );
  var ttlPriceForFirstBottle =  GetPrice( unique_cart_id, 1 );
  
  /* Index the current product. */
  if (ttlqty >= 4) { ttlcounter = 1; }
  else { ttlcounter = 0; }
 
  /* Receipt Description */
  var description = "";
    
  for (i=0; i<arrayLength; i++ ) {
      /* Get the QTY from the Array */
      if (arrayLength > 1) qty = parseInt(document["cartform"+unique_cart_id].quantity[i].value);
      if (arrayLength == 1) qty = parseInt(document["cartform"+unique_cart_id].quantity.value);
   
   /* Add the subtotals and grand */
   if ((ttlcounter == 0) && (qty > 0)) {
    /* Local Sub Total Calc */
    price = ttlPriceForFirstBottle + ((qty - 1) * ttlPricePerBottle)
 
    /* Add it to the total */    
    ttlprice += price;
    
    /* Okay.  No more of this. */
    ttlcounter = 1;
   } else {
    /* Local Sub Total Calc */
    price = (qty * ttlPricePerBottle);
   
    /* Add to total */
    ttlprice += price;
   }
    
   if ((document["cartform"+unique_cart_id].isMac.value == "True")||(document["cartform"+unique_cart_id].isNetscape6.value == "True")||(document["cartform"+unique_cart_id].isIE.value == "False")) { 
      if (arrayLength > 1) document["cartform"+unique_cart_id].prodsubtotal[i].value = formatCurrency(price);
      if (arrayLength == 1) document["cartform"+unique_cart_id].prodsubtotal.value = formatCurrency(price);
   } else {
      UpdateDivContent('divSubtotal'+ i,  '<span class=blk11>' + formatCurrency(price) + '</span>');
   } 
  }
  
}

// mnj duplicate of prtotal except this has threshold at 3+ (for creme de la femme) for pricing every bottle the same

function prtotal3Threshold(unique_cart_id, ele){
  var qty=0,ttlqty=0,fee,ttlprice=0;
  var i;
  var tqty;
  var count;
  var ttlcounter;
  var arrayLength;
  
  if (isNaN(ele.value))  {
   alert('You must enter a numeric value between 0 and 999');
   ele.value = 0;
   ele.focus();
  } else {
   if (ele.value==''||ele.value<0||ele.value%1>0) {
    alert('You must enter a numeric value between 0 and 999');
    ele.value=0;
    ele.focus();
   }
 	}
  
  var oProds = document["cartform"+unique_cart_id].quantity;
  
  if (!oProds.length) arrayLength = 1;
  else arrayLength = oProds.length;

  /* Calculate Matrix Variables */
  ttlqty = TotalCount( arrayLength, document["cartform"+unique_cart_id] );
  var ttlPricePerBottle = GetPrice( unique_cart_id, ttlqty );
  var ttlPriceForFirstBottle =  GetPrice( unique_cart_id, 1 );
  
  /* Index the current product. */
  if (ttlqty >= 3) { ttlcounter = 1; }
  else { ttlcounter = 0; }
 
  /* Receipt Description */
  var description = "";
    
  for (i=0; i<arrayLength; i++ ) {
      /* Get the QTY from the Array */
      if (arrayLength > 1) qty = parseInt(document["cartform"+unique_cart_id].quantity[i].value);
      if (arrayLength == 1) qty = parseInt(document["cartform"+unique_cart_id].quantity.value);
   
   /* Add the subtotals and grand */
   if ((ttlcounter == 0) && (qty > 0)) {
    /* Local Sub Total Calc */
    price = ttlPriceForFirstBottle + ((qty - 1) * ttlPricePerBottle)
 
    /* Add it to the total */    
    ttlprice += price;
    
    /* Okay.  No more of this. */
    ttlcounter = 1;
   } else {
    /* Local Sub Total Calc */
    price = (qty * ttlPricePerBottle);
   
    /* Add to total */
    ttlprice += price;
   }
    
   if ((document["cartform"+unique_cart_id].isMac.value == "True")||(document["cartform"+unique_cart_id].isNetscape6.value == "True")||(document["cartform"+unique_cart_id].isIE.value == "False")) { 
      if (arrayLength > 1) document["cartform"+unique_cart_id].prodsubtotal[i].value = formatCurrency(price);
      if (arrayLength == 1) document["cartform"+unique_cart_id].prodsubtotal.value = formatCurrency(price);
   } else {
      UpdateDivContent('divSubtotal'+ i,  '<span class=blk11>' + formatCurrency(price) + '</span>');
   } 
  }
  
}
 

 
 function TotalCount( totalproducts, cartingform ) {
  var l=0;
  var total=0;
  var val=0;
  
  /* Loop through all text boxes and  */
  for (l = 0; l < totalproducts; l++ ) {
      if (totalproducts > 1) val = cartingform.quantity[l].value;
      if (totalproducts == 1) val = cartingform.quantity.value; 

      total += parseInt( val );
  }
  
  return total;   
 }
 
 function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if (isNaN(num)) num = "0";
  cents = Math.floor((num*100+0.5)%100);
  num = Math.floor((num*100+0.5)/100).toString();
  if (cents < 10) cents = "0" + cents;
  for (var 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));
  return ('$' + num + '.' + cents);
 }
 
 
 function UpdateDivContent(divid, newcontent) {
    
  if (document.layers){ //ns4+
    with (document.layers[divid].document) {
      write(newcontent);
      close();
    }
   }
  
 }
 
// -->