function isNumeric(value)
{
	var checkOK = "0123456789";
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	}
	return allValid;
}

function Get_Radio_Value(r) 
{
        for (var i=0; i<r.length; i++) 
        {
                if (!r[i].checked) continue;
                else return r[i].value;
        }
        return null;
}

function Copy_Billing_To_Shipping()
{
	if (document.form.copy.checked)
	{
        	document.form.o_name.value = document.form.cc_name.value;
        	document.form.o_street.value = document.form.cc_street.value;
        	document.form.o_city.value = document.form.cc_city.value;
        	document.form.o_state.value = document.form.cc_state.value;
        	document.form.o_zip.value = document.form.cc_zip.value;
	}
	else
	{
        	document.form.o_name.value = "";
        	document.form.o_street.value = "";
        	document.form.o_city.value = "";
        	document.form.o_state.value = "";
        	document.form.o_zip.value = "";
	}
}

function Process2()
{
	var strPrice = Get_Radio_Value (document.form.price1);
	if (strPrice == "149.00" || strPrice == "79.00" || strPrice == "77.00")
	{
		if (document.form.promo.value.toLowerCase() == "ct79") 
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "79.00";
		}
		else if (document.form.promo.value.toLowerCase() == "ct89"
				|| document.form.promo.value.toLowerCase() == "jh89") 
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "89.00";
		}
		else if (document.form.promo.value.toLowerCase() == "show49")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "49.00";
		}
		else if (document.form.promo.value.toLowerCase() == "feb01" 
				|| document.form.promo.value.toLowerCase() == "cs12"
				|| document.form.promo.value.toLowerCase() == "g99"
				|| document.form.promo.value.toLowerCase() == "fc99"
				|| document.form.promo.value.toLowerCase() == "jh99"
				|| document.form.promo.value.toLowerCase() == "justin")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "99.00";
		}
		else if (document.form.promo.value.toLowerCase() == "jh109"
			|| document.form.promo.value.toLowerCase() == "st109")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "109.00";
		}
		else if (document.form.promo.value.toLowerCase() == "cs119"
			|| document.form.promo.value.toLowerCase() == "jh119"
			|| document.form.promo.value.toLowerCase() == "g01"
			|| document.form.promo.value.toLowerCase() == "g119"
			|| document.form.promo.value.toLowerCase() == "fc119"
			|| document.form.promo.value.toLowerCase() == "fc01"
			|| document.form.promo.value.toLowerCase() == "cs119+0"
			|| document.form.promo.value.toLowerCase() == "m119+295"
			|| document.form.promo.value.toLowerCase() == "m119+395"
			|| document.form.promo.value.toLowerCase() == "nt119")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "119.00";
		}
		else if (document.form.promo.value.toLowerCase() == "cs129" 
				|| document.form.promo.value.toLowerCase() == "jh129"
				|| document.form.promo.value.toLowerCase() == "uv129"
				|| document.form.promo.value.toLowerCase() == "etth")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "129.00";
			
		}
		else if (document.form.promo.value.toLowerCase() == "cs134")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "134.00";
		}
		else if (document.form.promo.value.toLowerCase() == "cs139"
				|| document.form.promo.value.toLowerCase() == "jh139")
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "139.00";
		}
		else if (document.form.promo.value.toLowerCase() == "jh149") 
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
			document.process.price.value = "149.00";
		}
		else
		{
			document.process.description.value = document.form.description.value;
			document.process.price.value = Get_Radio_Value (document.form.price1);
		}
		
		document.process.quantity.value = document.form.quantity.value > 0 ? document.form.quantity.value : 1;
		if (document.form.o_notes.value != '' && document.form.o_notes.value != null)
		{
			document.process.o_notes.value = "Device ID: " + document.form.o_notes.value;
		}

		if (document.form.promo.value != '')
		{
			document.process.description.value = "Promo [" + document.form.promo.value+"] - " + document.form.description.value;
		}
		
		if (strPrice == "79.00")
		{
			//alert(document.form.o_notes.value);
			//alert(document.form.reactivateEmail.value);

            if(document.form.o_notes.value.length == 0)
			{
				alert("Please enter Device ID");
				document.form.o_notes.focus();
				return false;
			}

			if(document.form.o_notes.value.length < 8) 
			{
				alert("Please enter valid Device ID");
				document.form.o_notes.focus();
				return false;
			}
			else if (!isNumeric(document.form.o_notes.value))
			{
				alert("Please enter valid Device ID");
				document.form.o_notes.focus();
				return false;
			}

			var str = document.form.reactivateEmail.value;
			if ((str.indexOf(".") > 2) && (str.indexOf("@") > 0) && (str.indexOf(".") > str.indexOf("@")))
			{
			}
			else
			{
				alert("Please enter Email in valid format.");
				document.form.reactivateEmail.focus();
				return false;
			}
			//alert("jignesh");
			document.process.price.value = strPrice;
			//alert("1 " + document.process.description.value);
			document.process.description.value = "Reactivation Charges";
			//alert("2 " + document.process.description.value);
			document.process.need_to_ship.value = "no";
			document.process.s_h_amount.value = "0.00";
			document.process.need_to_tax.value = "no";
			//alert("jignesh");
		}
		if (strPrice == "77.00")
		{
			document.process.price.value = "79.00";
			if (document.form.promo1.value.toLowerCase() == "m77") 
			{
				document.process.description.value = "Promo ["+document.form.promo1.value+"] - Prepaid Reactivation Charges";
				document.process.price.value = "77.00";
			}
			else if (document.form.promo1.value.toLowerCase() == "m75") 
			{
				document.process.description.value = "Promo ["+document.form.promo1.value+"] - Prepaid Reactivation Charges";
				document.process.price.value = "75.00";
			}
			else if (document.form.promo1.value.toLowerCase() == "m74") 
			{
				document.process.description.value = "Promo ["+document.form.promo1.value+"] - Prepaid Reactivation Charges";
				document.process.price.value = "74.00";
			}
			else if (document.form.promo1.value.toLowerCase() == "m73") 
			{
				document.process.description.value = "Promo ["+document.form.promo1.value+"] - Prepaid Reactivation Charges";
				document.process.price.value = "73.00";
			}
			else if (document.form.promo1.value.toLowerCase() == "m71") 
			{
				document.process.description.value = "Promo ["+document.form.promo1.value+"] - Prepaid Reactivation Charges";
				document.process.price.value = "71.00";
			}
			var intNumOfReact = 0;
			intNumOfReact = document.form.numOfReact.value > 0 ? document.form.numOfReact.value : 1;

			if (document.form.promo1.value.toLowerCase() == "eap" || document.form.promo1.value.toLowerCase() == "well" | document.form.promo1.value.toLowerCase() == "g119")
			{
				document.process.description.value = "Promo ["+document.form.promo1.value+"] - Prepaid Reactivation Charges";
				if (!isNaN(intNumOfReact) && intNumOfReact >= 1 && intNumOfReact <= 23)
				{
					document.process.price.value = "79.00";
				}
				else if (!isNaN(intNumOfReact) && intNumOfReact >= 24 && intNumOfReact <= 47)
				{
					document.process.price.value = "77.00";
				}
				else if (!isNaN(intNumOfReact) && intNumOfReact >= 48 && intNumOfReact <= 71)
				{
					document.process.price.value = "75.00";
				}
				else if (!isNaN(intNumOfReact) && intNumOfReact >= 72 && intNumOfReact <= 95)
				{
					document.process.price.value = "73.00";
				}
				else if (!isNaN(intNumOfReact) && intNumOfReact >= 96 && intNumOfReact <= 119)
				{
					document.process.price.value = "71.00";
				}
				else if (!isNaN(intNumOfReact) && intNumOfReact >= 120)
				{
					document.process.price.value = "69.00";
				}
			}

			document.process.quantity.value = intNumOfReact;
			document.process.need_to_ship.value = "no";
			document.process.s_h_amount.value = "0.00";
			document.process.need_to_tax.value = "no";
		}
        
		if (strPrice == "149.00")
		{
			// No shipping, only tax
			if (document.form.promo.value.toLowerCase() == "cs119+0")
			{
				document.process.need_to_ship.value = "no";
				document.process.s_h_amount.value = "0.00";
				document.process.need_to_tax.value = "yes";
			}
			// No tax, no shipping
			else if (document.form.promo.value.toLowerCase() == "jh89"
					|| document.form.promo.value.toLowerCase() == "jh99"
					|| document.form.promo.value.toLowerCase() == "jh109"
					|| document.form.promo.value.toLowerCase() == "jh119"
					|| document.form.promo.value.toLowerCase() == "jh129"
					|| document.form.promo.value.toLowerCase() == "jh139"
					|| document.form.promo.value.toLowerCase() == "jh149")
			{
				document.process.need_to_tax.value = "no";
				document.process.need_to_ship.value = "no";
				document.process.s_h_amount.value = "0.00";
			}
			// No tax, Only shipping
			else if (document.form.promo.value.toLowerCase() == "nt119")
			{
			//alert("Comes in No Tax, ONly Shipping");
				document.process.need_to_tax.value = "no";
				document.process.need_to_ship.value = "yes";
				document.process.s_h_amount.value = "9.95";
				var intQty = parseInt(document.process.quantity.value);
				var shipping = 9.95;
				
				if (!isNaN(intQty) && intQty == 1 )
				{
					shipping = 9.95;
				}
				else if (!isNaN(intQty) && intQty >= 2 && intQty <= 9)
				{
					shipping = 8.95;
				}
				else if (!isNaN(intQty) && intQty >= 10 && intQty <= 23)
				{
					shipping = 7.95;
				}
				else if (!isNaN(intQty) && intQty >= 24 && intQty <= 47)
				{
					shipping = 6.95;
				}
				else if (!isNaN(intQty) && intQty >= 48)
				{
					shipping = 5.95;
				}
				/*
				if (!isNaN(intQty))
				{
					var shippingValue = "" + parseFloat(shipping * intQty);

					if (shippingValue.indexOf(".") > 0)
					{
						if (shippingValue.substring(shippingValue.indexOf(".") + 1).length == 1)
						{
							shippingValue = shippingValue + "0";
						}
						if (shippingValue.substring(shippingValue.indexOf(".") + 1).length > 2)
						{
							shippingValue = shippingValue.substring(0, shippingValue.indexOf(".") + 3);
						}
					}
					else
					{
						shippingValue = shippingValue + ".00";
					}
					document.process.s_h_amount.value = shippingValue;
				}
				else
				{
					document.process.quantity.value = 1;
				}
				*/

				if (isNaN(intQty))
					document.process.quantity.value = 1;

				document.process.s_h_amount.value = shipping;
			}
			// Both tax and shipping
			else
			{
			
				document.process.need_to_tax.value = "yes";
				document.process.need_to_ship.value = "yes";
				document.process.s_h_amount.value = "9.95";
				var intQty = parseInt(document.process.quantity.value);

				if (isNaN(intQty))
				{
					intQty = 1;
					document.process.quantity.value = 1;
				}

				var shipping = 9.95;

				//if (document.form.promo.value.toLowerCase() == "m119+395")
				//	shipping = 3.95
				//else if (document.form.promo.value.toLowerCase() == "m119+295")
				//	shipping = 2.95

				if (document.form.promo.value.toLowerCase() == "eap")
				{
					if (!isNaN(intQty) && intQty >= 1 && intQty <= 2)
					{
						document.process.price.value = "119.00";
					}
					else if (!isNaN(intQty) && intQty >= 3 && intQty <= 6)
					{
						document.process.price.value = "109.00";
					}
					else if (!isNaN(intQty) && intQty >= 7 && intQty <= 23)
					{
						document.process.price.value = "104.00";
					}
					else if (!isNaN(intQty) && intQty >= 24 && intQty <= 95)
					{
						document.process.price.value = "99.00";
					}
					else if (!isNaN(intQty) && intQty >= 96 && intQty <= 480)
					{
						document.process.price.value = "94.00";
					}
					else if (!isNaN(intQty) && intQty >= 481)
					{
						document.process.price.value = "89.00";
					}
				}
				else if (document.form.promo.value.toLowerCase() == "well")
				{
					if (!isNaN(intQty) && intQty >= 1 && intQty <= 2)
					{
						document.process.price.value = "149.00";
					}
					else if (!isNaN(intQty) && intQty >= 3 && intQty <= 6)
					{
						document.process.price.value = "139.00";
					}
					else if (!isNaN(intQty) && intQty >= 7 && intQty <= 23)
					{
						document.process.price.value = "134.00";
					}
					else if (!isNaN(intQty) && intQty >= 24 && intQty <= 95)
					{
						document.process.price.value = "129.00";
					}
					else if (!isNaN(intQty) && intQty >= 96 && intQty <= 480)
					{
						document.process.price.value = "119.00";
					}
					else if (!isNaN(intQty) && intQty >= 481)
					{
						document.process.price.value = "99.00";
					}
				}

				//if (!isNaN(intQty) && (document.form.promo.value.toLowerCase() == "eap" || document.form.promo.value.toLowerCase() == "well"))
				//{
					if (!isNaN(intQty) && intQty == 1 )
					{
						shipping = 9.95;
					}
					else if (!isNaN(intQty) && intQty >= 2 && intQty <= 9)
					{
						shipping = 8.95;
					}
					else if (!isNaN(intQty) && intQty >= 10 && intQty <= 23)
					{
						shipping = 7.95;
					}
					else if (!isNaN(intQty) && intQty >= 24 && intQty <= 47)
					{
						shipping = 6.95;
					}
					else if (!isNaN(intQty) && intQty >= 48)
					{
						shipping = 5.95;
					}
				//}

		/*		if (!isNaN(intQty) && document.form.promo.value.toLowerCase() == "g119")
				{
					if (!isNaN(intQty) && intQty == 1)
					{
						shipping = 5.95;
					}
					else if (!isNaN(intQty) && intQty > 1 && intQty <= 11)
					{
						shipping = 3.95;
					}
					else if (!isNaN(intQty) && intQty >= 12)
					{
						shipping = 2.95;
					}
				}
		*/
				/*
				if (!isNaN(intQty))
				{
					var shippingValue = "" + parseFloat(shipping * intQty);

					if (shippingValue.indexOf(".") > 0)
					{
						if (shippingValue.substring(shippingValue.indexOf(".")+1).length == 1)
						{
							shippingValue = shippingValue + "0";
						}
						if (shippingValue.substring(shippingValue.indexOf(".")+1).length > 2)
						{
							shippingValue = shippingValue.substring(0, shippingValue.indexOf(".")+3);
						}
					}
					else
					{
						shippingValue = shippingValue + ".00";
					}
					document.process.s_h_amount.value = shippingValue;
				}
				else
				{
					document.process.quantity.value = 1;
				}
				*/
				document.process.s_h_amount.value = shipping;
			}
		}
	}
	else if (strPrice == "15.00")
	{
		document.process.description.value = "Continuation of Service";
		document.process.price.value = strPrice;
		document.process.quantity.value = document.form.months.value > 0 ? document.form.months.value : 1;
		if (document.form.o_notes1.value != '' && document.form.o_notes1.value != null)
		{
			document.process.o_notes.value = "Device ID: " + document.form.o_notes1.value;
		}
		document.process.need_to_ship.value = "no";
		document.process.s_h_amount.value = "0.00";
		document.process.need_to_tax.value = "no";
		//document.process.tax_amount.value = "0.00";
	}
	else if (strPrice == "199.00")
	{
		var price = strPrice;
		document.process.description.value = "MEDSignals Device";
		document.process.need_to_ship.value = "yes";
		document.process.need_to_tax.value = "yes";
		document.process.s_h_amount.value = "6.95";
		var intQty = parseInt(document.form.quantityMED.value);
		var shipping = 6.95;

		if (!isNaN(intQty))
		{
			if (intQty >= 1 && intQty <= 10)
			{
				price = "199.00"
			}
			else if (intQty >= 11 && intQty <= 20)
			{
				price = "179.00"
			}
			else if (intQty >= 21 && intQty <= 50)
			{
				price = "169.00"
			}
			else if (intQty >= 51 && intQty <= 100)
			{
				price = "159.00"
			}
			else if (intQty >= 101 && intQty <= 300)
			{
				price = "139.00"
			}
			else if (intQty >= 301 && intQty <= 800)
			{
				price = "119.00"
			}


			/*
			var shippingValue = "" + parseFloat(shipping * intQty);

			if (shippingValue.indexOf(".") > 0)
			{
				// PayJunction takes shipping value in the format #.00
				if (shippingValue.substring(shippingValue.indexOf(".")+1).length == 1)
				{
					shippingValue = shippingValue + "0";
				}
				if (shippingValue.substring(shippingValue.indexOf(".")+1).length > 2)
				{
					shippingValue = shippingValue.substring(0, shippingValue.indexOf(".")+3);
				}
			}
			else
			{
				shippingValue = shippingValue + ".00";
			}
			*/
			document.process.s_h_amount.value = shipping;
			document.process.quantity.value = intQty;
		}
		else
		{
			document.process.quantity.value = 1;
		}
		document.process.price.value = price;
	}

	document.process.zPromoCode.value = document.form.promo.value;
	document.process.zQuantity.value = document.form.quantity.value;
	document.process.zDeviceIdForReactivation.value = document.form.o_notes.value;
	document.process.zReactivationEmail.value = document.form.reactivateEmail.value;
	document.process.zMonths.value = document.form.months.value;
	document.process.zDeviceIdForContinuation.value = document.form.o_notes1.value;
	document.process.zDescription.value = document.process.description.value;
	document.form.description.value = document.process.description.value;
	document.form.need_to_ship.value = document.process.need_to_ship.value;
	document.form.s_h_amount.value = document.process.s_h_amount.value;
	document.form.need_to_tax.value = document.process.need_to_tax.value;
	document.form.price.value = document.process.price.value;
	
	
	document.form.zPromoCode.value = document.form.promo.value;
	document.form.zQuantity.value = document.form.quantity.value;
	document.form.zDeviceIdForReactivation.value = document.form.o_notes.value;
	document.form.zReactivationEmail.value = document.form.reactivateEmail.value;
	document.form.zMonths.value = document.form.months.value;
	document.form.zDeviceIdForContinuation.value = document.form.o_notes1.value;
	document.form.zDescription.value = document.process.description.value;
	
	//document.process.zQuantityMED.value = document.form.quantityMED.value;
	document.process.echo.value = 'echoed';
	document.process.submit();
//	document.form.submit();
	return true;
}
