                                       
									   /*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

var thepromocode="0";

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

/* shipping option function */
        function calculateTotal(inputItem) {
		with (inputItem.form) {
			// process each of the different input types in the form.
			if (inputItem.type == "radio") { // process radio buttons
				// subtract the previously selected radio button value from the total
				calculatedTotal.value = eval(calculatedTotal.value) - eval(previouslySelectedRadioButton.value);
				// save the current radio selection value
				previouslySelectedRadioButton.value = eval(inputItem.value);
				// add the current radio button selection value to the total
				calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);	
			} else { // process text boxes
				if (inputItem.type == "textBox") { // item was uncheck. subtract item value from total
				    calculatedTotal.value =  eval(calculatedTotal.value) - eval(inputItem.value);
				} else { // item was checked. add the item value to the total
				    calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value); 
				}
			}


			// total value should never be less than 0
			if (calculatedTotal.value < 0) {
				InitForm();
			}

			// return total value
			return(formatCurrency(calculatedTotal.value));
		}
	}

	// format a value as currency. 
	function formatCurrency(num) {
		num = num.toString().replace(/\$|\,/g,'');
		
		if(isNaN(num))
		   num = "0";
		   
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/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 (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	
	/*  promo  calcuation */
	function calculate2() {
	
	if ( document.frmCheckout.promo.value != "") {
	
   if ( document.frmCheckout.promo.value == "CC1" || document.frmCheckout.promo.value == "cc1" || document.frmCheckout.promo.value == "MM1"
	 || document.frmCheckout.promo.value == "mm1" || document.frmCheckout.promo.value == "YC1" || document.frmCheckout.promo.value == "yc1" ||
	 document.frmCheckout.promo.value == "NN1" || document.frmCheckout.promo.value == "nn1" || document.frmCheckout.promo.value == "CV1" || document.frmCheckout.promo.value == "cv1")  
   { 
   
   
        		if(thepromocode == "1")
      {   
           alert("You already Entered a Code!");
      }
       else
      { 
			                     
						A = document.frmCheckout.subtotal.value
						if(A >= Number("99.8"))
						{
						      var thenumber = A/24.95;
						      if(thenumber = 4 || thenumber == 5 || thenumber == 6 ||thenumber == 7)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 8 || thenumber == 9 || thenumber == 10 ||thenumber == 11)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*2)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 12 || thenumber == 13 || thenumber == 14 ||thenumber == 15)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*3)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 16 || thenumber == 17 || thenumber == 18 ||thenumber == 19)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*4)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 20 || thenumber == 21 || thenumber == 22 ||thenumber == 23)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*5)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 24 || thenumber == 25 || thenumber == 26 ||thenumber == 27)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*6)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 28 || thenumber == 29 || thenumber == 30 ||thenumber == 31)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*7)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 32 || thenumber == 33 || thenumber == 34 ||thenumber == 35)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*8)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 36 || thenumber == 37 || thenumber == 38 ||thenumber == 39)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*9)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
									if(thenumber == 40 || thenumber == 41 || thenumber == 42 ||thenumber == 43)
									{						
						  	  		document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (28.69*10)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
									}
						}
						
						else
						{
								/*document.frmCheckout.subtotal.value = formatCurrency(A)
								B = document.frmCheckout.discount.value
								A = Number(A)
								B = Number(B)
								C = (A * B)
								document.frmCheckout.discountAmount.value = formatCurrency(C)
								C = Number(C)
								D = (A - C)
								document.frmCheckout.newSubTotal.value = formatCurrency(D)
								E = document.frmCheckout.shippingCost.value
								D = Number(D)
								E = Number(E)
								document.frmCheckout.shippingCost.value = formatCurrency(E)
								F = (D + E)
								document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";*/
								//alert('You need at least 4 Items in your cart to use this promo code');
						}
      }
   
   
   
   
   
   
   
   
   
			
    	} 
		else if(document.frmCheckout.promo.value == "asdddff")
		{
		
		
			if(thepromocode == "1")
      		{   
           		alert("You already Entered a Code!");
      		}
       		else
      	    { 
			                     
						A = document.frmCheckout.subtotal.value
						if(A >= Number("49.9"))
						{
						      var thenumber = A/24.95;
						      
							  
							  if(thenumber == 2 || thenumber == 3)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (24.95)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 4 || thenumber == 5)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (49.90)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 6 || thenumber == 7)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (74.85)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 8 || thenumber == 9)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (99.80)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 10 || thenumber == 11)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (124.75)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 12 || thenumber == 13)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (49.90)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  
							 }
							 if(thenumber == 14 || thenumber == 15)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (49.90)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 16 || thenumber == 17)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (49.90)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 18 || thenumber == 19)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (49.90)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							  if(thenumber == 20 || thenumber == 21)
							  {						
						  	  				document.frmCheckout.subtotal.value = formatCurrency(A);
											B = document.frmCheckout.discount.value
											A = Number(A)
											B = Number(B)
											C = (49.90)
											document.frmCheckout.discountAmount.value = formatCurrency(C)
											C = Number(C)
											D = (A - C)
											document.frmCheckout.newSubTotal.value = formatCurrency(D)
											E = document.frmCheckout.shippingCost.value
											D = Number(D)
											E = Number(E)
											document.frmCheckout.shippingCost.value = formatCurrency(E)
											F = (D + E)
											document.frmCheckout.hidTotal.value = formatCurrency(F)
            								thepromocode="1";
							  }
							 
							  
									
						}
						else
						{
						 /*
								document.frmCheckout.subtotal.value = formatCurrency(A)
								B = document.frmCheckout.discount.value
								A = Number(A)
								B = Number(B)
								C = (A * B)
								document.frmCheckout.discountAmount.value = formatCurrency(C)
								C = Number(C)
								D = (A - C)
								document.frmCheckout.newSubTotal.value = formatCurrency(D)
								E = document.frmCheckout.shippingCost.value
								D = Number(D)
								E = Number(E)
								document.frmCheckout.shippingCost.value = formatCurrency(E)
								F = (D + E)
								document.frmCheckout.hidTotal.value = formatCurrency(F)
            					thepromocode="1";
						 */
								//alert('You need at least 4 Items in your cart to use this promo code');
						}
             }
		
		}
		else {
        alert ("The coupon code is not valid."); 
        document.frmCheckout.promo.focus ( ); 
        return false; 
      } 
	}
  
}
