// Ajax functions
// Check for a blank field.
function isBlank(data)
{
	// Remove all cases of "<br>" and "&nbsp;"
	data = data.replace(/\r|\n|\<br>|\&nbsp;/g, "");
	// Remove all spaces
	data = data.replace(/\s/g, "");	

	if (data == '')
		return true;
	else
		return false;	
}

function limitText(limitField, limitNum)
{
	if (limitField.value.length > limitNum)
	{
		limitField.value = limitField.value.substring(0, limitNum);
	}
	else 
	{
		document.getElementById("charsLeft").innerHTML= (limitNum - limitField.value.length);
	}
}

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);
}

/*
function changeShippingRates(form,boxChecked)
{
		if (form.x_ship_to_country.value == "US")
		{	
			if (boxChecked == "threeDaySelect")
			{
				form.overnight.checked = false;
				form.twoDaySelect.checked = false;
			}
			else if(boxChecked == "twoDaySelect")
			{
				form.threeDaySelect.checked = false;
				form.overnight.checked = false;
			}
			else if(boxChecked == "overnight")
			{
				form.threeDaySelect.checked = false;
				form.twoDaySelect.checked = false;
			}

			document.getElementById("insuranceBox").innerHTML="";
			if (document.getElementById("twoDaySelectBox").innerHTML=="")
			{			
				document.getElementById("overnightBox").innerHTML="<div id=\"overnightBox\"><input type=\"checkbox\" name=\"overnight\" onclick=\"changeShippingRates(customerForm,'overnight');\"> Overnight shipping - $30.00 first item, $16.00 for each additional item <b>(Domestic U.S. Accounts ONLY)</b></div>";
				document.getElementById("threeDaySelectBox").innerHTML="<div id=\"threeDaySelectBox\"><input type=\"checkbox\" name=\"threeDaySelect\" onclick=\"changeShippingRates(customerForm,'threeDaySelect');\">  3 day select - $18.50 first item, $7.25 for each additional item <b>(Domestic U.S. Accounts ONLY)</b></div>";
				document.getElementById("twoDaySelectBox").innerHTML="<div id=\"twoDaySelectBox\"><input type=\"checkbox\" name=\"twoDaySelect\" onclick=\"changeShippingRates(customerForm,'twoDaySelect');\">  2 day select - $22.00 first item, $7.25 for each additional item <b>(Domestic U.S. Accounts ONLY)</b></div>";
				if ((form.totalItems.value - 1) > 4)
					form.shipping.value=18.00;
				else
					form.shipping.value = (6.00 + ((form.totalItems.value - 1) * 3.00));
				//form.shipping.value = (9.50 + ((form.totalItems.value - 1) * 7.25));
			}
			else if(form.overnight.checked) 
			{
				form.shipping.value = (30.00 + ((form.totalItems.value - 1) * 16.00));
			}
			else if(form.twoDaySelect.checked) 
			{
				form.shipping.value = (22.00 + ((form.totalItems.value - 1) * 7.25));
			}
			else if(form.threeDaySelect.checked) 
			{
				form.shipping.value = (18.50 + ((form.totalItems.value - 1) * 7.25));
			}

			else
			{
				if ((form.totalItems.value - 1) > 4)
					form.shipping.value=18.00;
				else
					form.shipping.value = (6.00 + ((form.totalItems.value - 1) * 3.00));
				//form.shipping.value = (9.50 + ((form.totalItems.value - 1) * 7.25));
			}
		}
		else if (form.x_ship_to_country.value == "CA")
		{
			//if (boxChecked == "threeDaySelect")
			//{
			//	form.overnight.checked = false;
			//}
			//else 
			//if(boxChecked == "overnight")
			//{
			//	form.threeDaySelect.checked = false;			
			//}

			if (document.getElementById("twoDaySelectBox").innerHTML!="" || document.getElementById("insuranceBox").innerHTML!="" || document.getElementById("overnightBox").innerHTML=="")
			{			

				document.getElementById("overnightBox").innerHTML="<div id=\"overnightBox\"><input type=\"checkbox\" name=\"overnight\" onclick=\"changeShippingRates(customerForm,'overnight');\"> Express shipping (3-5 days) - $35.00 first item, $14.00 each additional item <b>(Canada Accounts ONLY)</b></div>";
				//document.getElementById("threeDaySelectBox").innerHTML="<div id=\"threeDaySelectBox\"><br><input type=\"checkbox\" name=\"threeDaySelect\" onclick=\"changeShippingRates(customerForm,'threeDaySelect');\">  3 day select - $22.00 first item, $10.00 for each additional item <b>(Canada Accounts ONLY)</b></div>";
				document.getElementById("threeDaySelectBox").innerHTML="<div id=\"threeDaySelectBox\"></div>";
				form.shipping.value = (21.00 + ((form.totalItems.value - 1) * 8.25));
			}
			
			if(document.getElementById("overnightBox").innerHTML!="" && form.overnight.checked)
			{

				form.shipping.value = (35.00 + ((form.totalItems.value - 1) * 14.00));
			}
			//else if(document.getElementById("threeDaySelect").innerHTML!="" && form.threeDaySelect.checked) 
			//{
			//	form.shipping.value = (22.00 + ((form.totalItems.value - 1) * 10.00));
			//}
			else
			{
				form.shipping.value = (21.00 + ((form.totalItems.value - 1) * 8.25));
			}
			document.getElementById("insuranceBox").innerHTML="";
			document.getElementById("twoDaySelectBox").innerHTML="";
		}
		else
		{
			var	insurance = 0;
			if (document.getElementById("insuranceBox").innerHTML == "")
			{
				document.getElementById("insuranceBox").innerHTML="<div id=\"insuranceBox\"><input type=\"checkbox\" name=\"overseasInsurance\" onclick=\"changeShippingRates(customerForm,'insurance');\"> Overseas shipping insurance - add $5.00</div>";
			}
			else if (form.overseasInsurance.checked)
			{
				insurance = 5;
			}

			form.shipping.value = (30.00 + ((form.totalItems.value - 1) * 16.00) + (insurance * 1));
			document.getElementById("overnightBox").innerHTML="";
			document.getElementById("twoDaySelectBox").innerHTML="";
			document.getElementById("threeDaySelectBox").innerHTML="";
		}

		var newTotal = (form.price.value * 1)+ (form.shipping.value * 1) - form.discount.value;

		document.getElementById("shippingDisplayPrice").innerHTML = "<b>$"+formatCurrency(form.shipping.value)+"</b>";
		document.getElementById("totalPrice").innerHTML = "<b>$"+formatCurrency(newTotal)+"</b>";
}

function copyBillingInfoToShippingInfo(form)
{
	if (form.shippingSame.checked)
	{		
		form.x_ship_to_first_name.value=form.fname.value;
		form.x_ship_to_middle_name.value=form.mname.value;
		form.x_ship_to_last_name.value=form.lname.value;
		form.x_ship_to_address.value=form.cc_addr.value;
		form.x_ship_to_city.value=form.cc_city.value;
		form.x_ship_to_state.selectedIndex=form.cc_state.selectedIndex;
		form.x_ship_to_zip.value=form.cc_zip.value;
		form.x_ship_to_country.value=form.cc_country.value;
		form.x_ship_to_country.selectedIndex=form.cc_country.selectedIndex;

		changeShippingRates(form);	
	}
}
*/
function changeShippingRates(form,boxChecked,discountType)
{
		var numItems = form.totalItems.value*1;

		form.valentinesRoses.value = formatCurrency(0.00);
		if (document.getElementById("valentinesRoses")!=null)
		{
			if (document.getElementById("valentinesRoses").checked)
			{
				form.valentinesRoses.value = formatCurrency(16.99);
				numItems = numItems + 1;		
			}
			else
			{
				form.valentinesRoses.value = formatCurrency(0.00);
			}
		}

		form.valentinesBasket.value = formatCurrency(0.00);
		if (document.getElementById("valentinesBasket")!=null)
		{
			if (document.getElementById("valentinesBasket").checked)
			{
				form.valentinesBasket.value = formatCurrency(17.95);
				numItems = numItems + 1;
			}
			else
			{
				form.valentinesBasket.value = formatCurrency(0.00);
			}


		}


		/*if (document.getElementById("freeSlippers")!=null)
		{
			if (document.getElementById("freeSlippers").checked)
			{
				numItems = numItems + 1;
			}
		}
		*/

		if (form.x_ship_to_country.value == "US")
		{	
			if (boxChecked == "threeDaySelect")
			{
				//form.overnight.checked = false;
				//form.twoDaySelect.checked = false;
			}
			else if(boxChecked == "twoDaySelect")
			{
				//form.threeDaySelect.checked = false;
				//form.overnight.checked = false;
			}
			else if(boxChecked == "overnight")
			{
				//alert('overnight');
				//form.overnight.checked = true;
				//form.threeDaySelect.checked = false;
				//form.twoDaySelect.checked = false;
			}

			/*else if(form.twoDaySelect.checked) 
			{
				form.shipping.value = (22.00 + ((numItems - 1) * 7.25));
			}
			else if(form.threeDaySelect.checked) 
			{
				form.shipping.value = (18.50 + ((numItems - 1) * 7.25));
			}*/



			document.getElementById("insuranceBox").innerHTML="";document.getElementById("insuranceBox").style.display='none';
			//if (document.getElementById("twoDaySelectBox").innerHTML=="")
			if (document.getElementById("twoDaySelectBox").innerHTML=="" && boxChecked != "overnight")
			{			
				document.getElementById("overnightBox").innerHTML="<input type=\"checkbox\" name=\"overnight\" id=\"overnight\" onclick=\"changeShippingRates(customerForm,'overnight','"+discountType+"');\"> Overnight shipping - $30.00 first item, $16.00 for each additional item <b>(Domestic U.S. Accounts ONLY)</b>";document.getElementById("overnightBox").style.display='';
				//document.getElementById("threeDaySelectBox").innerHTML="<input type=\"checkbox\" name=\"threeDaySelect\" id=\"threeDaySelect\" onclick=\"changeShippingRates(customerForm,'threeDaySelect',"+discountType+");\">  3 day select - $18.50 first item, $7.25 for each additional item <b>(Domestic U.S. Accounts ONLY)</b>";document.getElementById("threeDaySelectBox").style.display='';
				//document.getElementById("twoDaySelectBox").innerHTML="<input type=\"checkbox\" name=\"twoDaySelect\" id=\"twoDaySelect\" onclick=\"changeShippingRates(customerForm,'twoDaySelect',"+discountType+");\">  2 day select - $22.00 first item, $7.25 for each additional item <b>(Domestic U.S. Accounts ONLY)</b>";document.getElementById("twoDaySelectBox").style.display='';
				document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
				document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';				

				if ((numItems - 1) > 4)
					form.shipping.value=27.50;
				else
					form.shipping.value = (9.00 + ((numItems - 1) * 5.00));				
				//form.shipping.value = (9.50 + ((numItems - 1) * 7.25));
			}
			else if(form.overnight.checked) 
			{
				form.shipping.value = (30.00 + ((numItems - 1) * 16.00));
			}
			else
			{

				if ((numItems - 1) > 4)
					form.shipping.value=27.50;
				else
					form.shipping.value = (9.00 + ((numItems - 1) * 5.00));
				//form.shipping.value = (9.50 + ((numItems - 1) * 7.25));
				boxChecked="";
			}
		
			if (numItems == 0)
			{
				form.shipping.value=0;
			}

			if (discountType == 3)
			{

				threeDay = 0;
				/*if (document.getElementById("threeDaySelect")!=null)
				{
					if (document.getElementById("threeDaySelect").checked)
					{threeDay = 1;}
				}
				*/
				
				twoDay = 0;
				/*if (document.getElementById("twoDaySelect")!=null)
				{
					if (document.getElementById("twoDaySelect").checked)
					{twoDay = 1;}
				}
				*/
				onight = 0;
				if (document.getElementById("overnight")!=null)
				{
					if (document.getElementById("overnight").checked)
					{onight = 1;}
				}

				//if (boxChecked != "threeDaySelect" && boxChecked != "twoDaySelect" && boxChecked != "overnight")
				if (threeDay == 0 && twoDay == 0 && onight == 0 && boxChecked=='')
				{

					document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(form.shipping.value);
					form.discount.value = formatCurrency(form.shipping.value);
				}
				else
				{				
					document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(0.0);
					form.discount.value = formatCurrency(0.0);
				}				
			}		
		}
		else if (form.x_ship_to_country.value == "CA")
		{
			if (discountType == 3)
			{								
				document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(0.0);
				form.discount.value = formatCurrency(0.0);								
			}		
			
			//if (document.getElementById("twoDaySelectBox").innerHTML!="" || document.getElementById("insuranceBox").innerHTML!="" || document.getElementById("overnightBox").innerHTML=="")
			if (boxChecked == '')
			{
				document.getElementById("overnightBox").innerHTML="<input type=\"checkbox\" name=\"overnight\" id=\"overnight\" onclick=\"changeShippingRates(customerForm,'overnight','"+discountType+"');\"> Express shipping (3-5 days) - $35.00 first item, $14.00 each additional item <b>(Canada Accounts ONLY)</b>";document.getElementById("overnightBox").style.display='';
				//document.getElementById("threeDaySelectBox").innerHTML="<div id=\"threeDaySelectBox\"><br><input type=\"checkbox\" name=\"threeDaySelect\" onclick=\"changeShippingRates(customerForm,'threeDaySelect');\">  3 day select - $22.00 first item, $10.00 for each additional item <b>(Canada Accounts ONLY)</b></div>";
				document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';
				form.shipping.value = (26.99 + ((numItems - 1) * 14.99));
			}
			
			if(document.getElementById("overnightBox").innerHTML!="" && form.overnight.checked)
			{

				form.shipping.value = (35.00 + ((numItems - 1) * 14.99));
			}
			else
			{
				form.shipping.value = (26.99 + ((numItems - 1) * 14.99));
			}

			if (numItems == 0)
			{
				form.shipping.value=0;
			}
			
			document.getElementById("insuranceBox").innerHTML="";document.getElementById("insuranceBox").style.display='none';
			document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
		}
		else
		{
			if (discountType == 3)
			{								
				document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(0.0);
				form.discount.value = formatCurrency(0.0);								
			}		

			var	insurance = 0;
			if (document.getElementById("insuranceBox").innerHTML == "")
			{
				document.getElementById("insuranceBox").innerHTML="<input type=\"checkbox\" name=\"overseasInsurance\" id=\"overseasInsurance\" onclick=\"changeShippingRates(customerForm,'insurance','"+discountType+"');\"> Overseas shipping insurance - add $5.00";document.getElementById("insuranceBox").style.display='';
			}
			else if (form.overseasInsurance.checked)
			{
				insurance = 5;
			}

			form.shipping.value = (30.00 + ((numItems - 1) * 16.00) + (insurance * 1));

			if (numItems == 0)
			{
				form.shipping.value=0;
			}


			document.getElementById("overnightBox").innerHTML="";document.getElementById("overnightBox").style.display='none';
			document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
			document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';


		}


		form.giftWrapPrice.value = 0.0;
		if (document.getElementById("giftWrap")!=null)
		{
			if (document.getElementById("giftWrap").checked)
			{
				//document.getElementById("giftCardMessage").checked = false;
				form.giftWrapPrice.value = formatCurrency(10.00 + (form.totalItems.value - 1) * 5.00);
				document.getElementById("giftWrapDisplayPrice").innerHTML = "<b>$"+form.giftWrapPrice.value+"</b>";;
			}
			else
			{
				document.getElementById("giftWrapDisplayPrice").innerHTML = "<b>$0.00</b>";
				form.giftWrapPrice.value = formatCurrency(0.00);
			}
		}

		form.giftCardMessagePrice.value = 0.0;
		if (document.getElementById("giftCardMessage")!=null)
		{
			if (document.getElementById("giftCardMessage").checked)
			{
				form.giftCardMessagePrice.value = formatCurrency(2.00);
				document.getElementById("giftCardMessageDisplayPrice").innerHTML = "<b>$"+form.giftCardMessagePrice.value+"</b>";;
			}
			else
			{
				document.getElementById("giftCardMessageDisplayPrice").innerHTML = "<b>$0.00</b>";
				form.giftCardMessagePrice.value = formatCurrency(0.00);
			}
		}

//		else
//			document.getElementById("giftWrapDisplayPrice").innerHTML = "<b>$0.00</b>";;


		tax_rate=0.0;
		switch(form.x_ship_to_state.value){
			case "AZ": tax_rate=0.082; break;
		}
		form.tax.value = formatCurrency(((form.price.value*1) + (form.valentinesRoses.value*1)+(form.valentinesBasket.value*1)+(form.giftWrapPrice.value * 1) + (form.giftCardMessagePrice.value*1)) * tax_rate);

		//var newTotal = (form.price.value * 1)+ (form.shipping.value * 1) - form.discount.value;
		var newTotal = (form.valentinesRoses.value*1)+(form.valentinesBasket.value*1)+(form.giftWrapPrice.value * 1) + (form.giftCardMessagePrice.value * 1) + (form.price.value * 1) + (form.shipping.value * 1) + (form.tax.value * 1) - form.discount.value;
		var newSubTotal = (form.valentinesRoses.value*1)+(form.valentinesBasket.value*1) + (form.price.value * 1);

		document.getElementById("tax").innerHTML = "<b>$"+formatCurrency(form.tax.value)+"</b>";
		document.getElementById("subtotal").innerHTML = "<b>$"+formatCurrency(newSubTotal)+"</b>";
		document.getElementById("shippingDisplayPrice").innerHTML = "<b>$"+formatCurrency(form.shipping.value)+"</b>";
		document.getElementById("totalPrice").innerHTML = "<b>$"+formatCurrency(newTotal)+"</b>";
}

function copyBillingInfoToShippingInfo(form,discountType)
{
	if (form.shippingSame.checked)
	{		
		form.x_ship_to_first_name.value=form.fname.value;
		form.x_ship_to_middle_name.value=form.mname.value;
		form.x_ship_to_last_name.value=form.lname.value;
		form.x_ship_to_address.value=form.cc_addr.value;
		form.x_ship_to_city.value=form.cc_city.value;
		form.x_ship_to_state.selectedIndex=form.cc_state.selectedIndex;
		form.x_ship_to_zip.value=form.cc_zip.value;
		form.x_ship_to_country.value=form.cc_country.value;
		form.x_ship_to_country.selectedIndex=form.cc_country.selectedIndex;

		changeShippingRates(form,'',discountType);	
	}
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


////////////
function changeShippingRates2(form,boxChecked,discountType)
{	
		//alert(customerForm.product.length);
		//alert(document.getElementById("product").length); // wont work id's have to be different, names can be one name for the radio group however

		var productValue = getCheckedValue(document.customerForm.product);
		if (productValue != "")
		{
			var theQuantity = document.getElementById("quantity_" + productValue).value;
			var size = document.getElementById("size_" + productValue).value;

			//var numItems = form.totalItems.value*1;
			var numItems = theQuantity;
		}
		else
			var numItems = 0;


/*
		form.valentinesRoses.value = formatCurrency(0.00);
		if (document.getElementById("valentinesRoses")!=null)
		{
			if (document.getElementById("valentinesRoses").checked)
			{
				form.valentinesRoses.value = formatCurrency(16.99);
				numItems = numItems + 1;		
			}
			else
			{
				form.valentinesRoses.value = formatCurrency(0.00);
			}
		}

		form.valentinesBasket.value = formatCurrency(0.00);
		if (document.getElementById("valentinesBasket")!=null)
		{
			if (document.getElementById("valentinesBasket").checked)
			{
				form.valentinesBasket.value = formatCurrency(17.95);
				numItems = numItems + 1;
			}
			else
			{
				form.valentinesBasket.value = formatCurrency(0.00);
			}


		}


		if (document.getElementById("freeSlippers")!=null)
		{
			if (document.getElementById("freeSlippers").checked)
			{
				numItems = numItems + 1;
			}
		}
*/


		// Global checkbox handling.
		if(document.getElementById('overnight') != null && document.getElementById('overnight').checked)
		{
			boxChecked = "overnight";
			//document.getElementById('overnight').checked = true;
		}

		if (form.x_ship_to_country.value == "US")
		{	
			if (boxChecked == "threeDaySelect")
			{
				//form.overnight.checked = false;
				//form.twoDaySelect.checked = false;
			}
			else if(boxChecked == "twoDaySelect")
			{
				//form.threeDaySelect.checked = false;
				//form.overnight.checked = false;
			}
			else if(boxChecked == "overnight")
			{
				//alert('overnight');
				//form.overnight.checked = true;
				//form.threeDaySelect.checked = false;
				//form.twoDaySelect.checked = false;
			}



			/*else if(form.twoDaySelect.checked) 
			{
				form.shipping.value = (22.00 + ((numItems - 1) * 7.25));
			}
			else if(form.threeDaySelect.checked) 
			{
				form.shipping.value = (18.50 + ((numItems - 1) * 7.25));
			}*/



			document.getElementById("insuranceBox").innerHTML="";document.getElementById("insuranceBox").style.display='none';
			//if (document.getElementById("twoDaySelectBox").innerHTML=="")
			if (document.getElementById("twoDaySelectBox").innerHTML=="" && boxChecked != "overnight")
			{			
				document.getElementById("overnightBox").innerHTML="<input type=\"checkbox\" name=\"overnight\" id=\"overnight\" onclick=\"changeShippingRates2(customerForm,'overnight','"+discountType+"');\"> Overnight shipping - $30.00 first item, $16.00 for each additional item <b>(Domestic U.S. Accounts ONLY)</b>";document.getElementById("overnightBox").style.display='';
				//document.getElementById("threeDaySelectBox").innerHTML="<input type=\"checkbox\" name=\"threeDaySelect\" id=\"threeDaySelect\" onclick=\"changeShippingRates2(customerForm,'threeDaySelect',"+discountType+");\">  3 day select - $18.50 first item, $7.25 for each additional item <b>(Domestic U.S. Accounts ONLY)</b>";document.getElementById("threeDaySelectBox").style.display='';
				//document.getElementById("twoDaySelectBox").innerHTML="<input type=\"checkbox\" name=\"twoDaySelect\" id=\"twoDaySelect\" onclick=\"changeShippingRates2(customerForm,'twoDaySelect',"+discountType+");\">  2 day select - $22.00 first item, $7.25 for each additional item <b>(Domestic U.S. Accounts ONLY)</b>";document.getElementById("twoDaySelectBox").style.display='';
				document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
				document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';				

				if ((numItems - 1) > 4)
					form.shipping.value=27.50;
				else
					form.shipping.value = (8.00 + ((numItems - 1) * 5.00));				
				//form.shipping.value = (9.50 + ((numItems - 1) * 7.25));
			}
			else if(document.getElementById('overnight').checked) 
			{
				form.shipping.value = (30.00 + ((numItems - 1) * 16.00));
			}
			else
			{

				if ((numItems - 1) > 4)
					form.shipping.value=27.50;
				else
					form.shipping.value = (8.00 + ((numItems - 1) * 5.00));
				//form.shipping.value = (9.50 + ((numItems - 1) * 7.25));
				//boxChecked="";
			}
		
			if (numItems == 0)
			{
				form.shipping.value=0;
			}

			if (discountType == 3)
			{

				threeDay = 0;
				/*if (document.getElementById("threeDaySelect")!=null)
				{
					if (document.getElementById("threeDaySelect").checked)
					{threeDay = 1;}
				}
				*/
				
				twoDay = 0;
				/*if (document.getElementById("twoDaySelect")!=null)
				{
					if (document.getElementById("twoDaySelect").checked)
					{twoDay = 1;}
				}
				*/
				onight = 0;
				if (document.getElementById("overnight")!=null)
				{
					if (document.getElementById("overnight").checked)
					{onight = 1;}
				}

				//if (boxChecked != "threeDaySelect" && boxChecked != "twoDaySelect" && boxChecked != "overnight")
				if (threeDay == 0 && twoDay == 0 && onight == 0 && boxChecked=='')
				{

					document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(form.shipping.value);
					form.discount.value = formatCurrency(form.shipping.value);
				}
				else
				{				
					document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(0.0);
					form.discount.value = formatCurrency(0.0);
				}				
			}		
		}
		else if (form.x_ship_to_country.value == "CA")
		{
			if (discountType == 3)
			{								
				document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(0.0);
				form.discount.value = formatCurrency(0.0);								
			}		
			
			//if (document.getElementById("twoDaySelectBox").innerHTML!="" || document.getElementById("insuranceBox").innerHTML!="" || document.getElementById("overnightBox").innerHTML=="")
			if (boxChecked == '')
			{
				document.getElementById("overnightBox").innerHTML="<input type=\"checkbox\" name=\"overnight\" id=\"overnight\" onclick=\"changeShippingRates2(customerForm,'overnight','"+discountType+"');\"> Express shipping (3-5 days) - $35.00 first item, $14.99 each additional item <b>(Canada Accounts ONLY)</b>";document.getElementById("overnightBox").style.display='';
				//document.getElementById("threeDaySelectBox").innerHTML="<div id=\"threeDaySelectBox\"><br><input type=\"checkbox\" name=\"threeDaySelect\" onclick=\"changeShippingRates2(customerForm,'threeDaySelect');\">  3 day select - $22.00 first item, $10.00 for each additional item <b>(Canada Accounts ONLY)</b></div>";
				document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';
				form.shipping.value = (24.99 + ((numItems - 1) * 14.99));
			}
			
			if(document.getElementById("overnightBox").innerHTML!="" && document.getElementById('overnight').checked)
			{

				form.shipping.value = (35.00 + ((numItems - 1) * 14.99));
			}
			else
			{
				form.shipping.value = (24.99 + ((numItems - 1) * 14.99));
			}

			if (numItems == 0)
			{
				form.shipping.value=0;
			}
			
			document.getElementById("insuranceBox").innerHTML="";document.getElementById("insuranceBox").style.display='none';
			document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
		}
		else if (form.x_ship_to_country.value == "")
		{
			form.shipping.value=0;
			document.getElementById("overnightBox").innerHTML="";document.getElementById("overnightBox").style.display='none';
			document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
			document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';
			document.getElementById("insuranceBox").innerHTML="";document.getElementById("insuranceBox").style.display='none';
		}
		else
		{
			if (discountType == 3)
			{								
				document.getElementById("discountDisplayPrice").innerHTML = '-' + '$' + formatCurrency(0.0);
				form.discount.value = formatCurrency(0.0);								
			}		

			var	insurance = 0;
			if (document.getElementById("insuranceBox").innerHTML == "")
			{
				document.getElementById("insuranceBox").innerHTML="<input type=\"checkbox\" name=\"overseasInsurance\" id=\"overseasInsurance\" onclick=\"changeShippingRates2(customerForm,'insurance','"+discountType+"');\"> Overseas shipping insurance - add $5.00";document.getElementById("insuranceBox").style.display='';
			}
			else if (document.getElementById('overseasInsurance').checked)
			{
				insurance = 5;
			}

			form.shipping.value = (30.00 + ((numItems - 1) * 16.00) + (insurance * 1));

			if (numItems == 0)
			{
				form.shipping.value=0;
			}


			document.getElementById("overnightBox").innerHTML="";document.getElementById("overnightBox").style.display='none';
			document.getElementById("twoDaySelectBox").innerHTML="";document.getElementById("twoDaySelectBox").style.display='none';
			document.getElementById("threeDaySelectBox").innerHTML="";document.getElementById("threeDaySelectBox").style.display='none';


		}


		form.giftWrapPrice.value = 0.0;
		if (document.getElementById("giftWrap")!=null)
		{
			if (document.getElementById("giftWrap").checked)
			{
				//document.getElementById("giftCardMessage").checked = false;
				form.giftWrapPrice.value = formatCurrency(10.00 + (form.totalItems.value - 1) * 5.00);
				document.getElementById("giftWrapDisplayPrice").innerHTML = "<b>$"+form.giftWrapPrice.value+"</b>";;
			}
			else
			{
				document.getElementById("giftWrapDisplayPrice").innerHTML = "<b>$0.00</b>";
				form.giftWrapPrice.value = formatCurrency(0.00);
			}
		}

		form.giftCardMessagePrice.value = 0.0;
		if (document.getElementById("giftCardMessage")!=null)
		{
			if (document.getElementById("giftCardMessage").checked)
			{
				form.giftCardMessagePrice.value = formatCurrency(2.00);
				document.getElementById("giftCardMessageDisplayPrice").innerHTML = "<b>$"+form.giftCardMessagePrice.value+"</b>";;
			}
			else
			{
				document.getElementById("giftCardMessageDisplayPrice").innerHTML = "<b>$0.00</b>";
				form.giftCardMessagePrice.value = formatCurrency(0.00);
			}
		}

//		else
//			document.getElementById("giftWrapDisplayPrice").innerHTML = "<b>$0.00</b>";;


		tax_rate=0.0;
		switch(form.x_ship_to_state.value){
			case "AZ": tax_rate=0.082; break;
		}
		//form.tax.value = formatCurrency(((form.price.value*1) + (form.valentinesRoses.value*1)+(form.valentinesBasket.value*1)+(form.giftWrapPrice.value * 1) + (form.giftCardMessagePrice.value*1)) * tax_rate);
		form.price.value = formatCurrency(theQuantity * 59.99);
		form.tax.value = formatCurrency(((form.price.value*1) + (form.giftCardMessagePrice.value*1)) * tax_rate);


		////var newTotal = (form.price.value * 1)+ (form.shipping.value * 1) - form.discount.value;
		//var newTotal = (form.valentinesRoses.value*1)+(form.valentinesBasket.value*1)+(form.giftWrapPrice.value * 1) + (form.giftCardMessagePrice.value * 1) + (form.price.value * 1) + (form.shipping.value * 1) + (form.tax.value * 1) - form.discount.value;
		//var newSubTotal = (form.valentinesRoses.value*1)+(form.valentinesBasket.value*1) + (form.price.value * 1);

		var newTotal = (form.giftCardMessagePrice.value * 1) + (form.price.value * 1) + (form.shipping.value * 1) + (form.tax.value * 1) - form.discount.value;
		var newSubTotal = (form.price.value * 1);

		document.getElementById("tax").innerHTML = "<b>$"+formatCurrency(form.tax.value)+"</b>";
		document.getElementById("subtotal").innerHTML = "<b>$"+formatCurrency(newSubTotal)+"</b>";
		document.getElementById("shippingDisplayPrice").innerHTML = "<b>$"+formatCurrency(form.shipping.value)+"</b>";
		document.getElementById("totalPrice").innerHTML = "<b>$"+formatCurrency(newTotal)+"</b>";
}

function copyBillingInfoToShippingInfo_landing(form,discountType)
{
	if (form.shippingSame.checked)
	{		
		form.x_ship_to_first_name.value=form.fname.value;
		form.x_ship_to_middle_name.value=form.mname.value;
		form.x_ship_to_last_name.value=form.lname.value;
		form.x_ship_to_address.value=form.cc_addr.value;
		form.x_ship_to_city.value=form.cc_city.value;
		form.x_ship_to_state.selectedIndex=form.cc_state.selectedIndex;
		form.x_ship_to_zip.value=form.cc_zip.value;
		form.x_ship_to_country.value=form.cc_country.value;
		form.x_ship_to_country.selectedIndex=form.cc_country.selectedIndex;

		changeShippingRates2(form,'',discountType);	
	}
}

///////////



/*function validateCustomerForm(form)
{			
	var errorString='';

	if (isBlank(form.fname.value))
	{		
		errorString = errorString + "- Billing First Name\n";
	}
	if (isBlank(form.lname.value))
	{		
		errorString = errorString + "- Billing Last Name\n";
	}
	if (isBlank(form.phone.value))
	{		
		errorString = errorString + "- Billing Phone\n";
	}
	if (isBlank(form.cc_addr.value))
	{		
		errorString = errorString + "- Billing Address\n";
	}
	if (isBlank(form.cc_city.value))
	{		
		errorString = errorString + "- Billing City\n";
	}
	if (isBlank(form.cc_state.value))
	{		
		errorString = errorString + "- Billing State\n";
	}
	if (isBlank(form.cc_zip.value))
	{		
		errorString = errorString + "- Billing Zip Code\n";
	}
	if (isBlank(form.cc_country.value))
	{		
		errorString = errorString + "- Billing Country\n";
	}
	if (isBlank(form.email.value))
	{		
		errorString = errorString + "- Email Address\n";
	}
	if (isBlank(form.x_ship_to_first_name.value))
	{		
		errorString = errorString + "- Shipping First Name\n";
	}
	if (isBlank(form.x_ship_to_last_name.value))
	{		
		errorString = errorString + "- Shipping Last Name\n";
	}
	if (isBlank(form.x_ship_to_address.value))
	{		
		errorString = errorString + "- Shipping Address\n";
	}
	if (isBlank(form.x_ship_to_city.value))
	{		
		errorString = errorString + "- Shipping City\n";
	}
	if (isBlank(form.x_ship_to_state.value))
	{		
		errorString = errorString + "- Shipping State\n";
	}
	if (isBlank(form.x_ship_to_zip.value))
	{		
		errorString = errorString + "- Shipping Zip\n";
	}
	if (isBlank(form.x_ship_to_country.value))
	{		
		errorString = errorString + "- Shipping Country\n";
	}
	if (isBlank(form.cc_num.value))
	{		
		errorString = errorString + "- Credit Card Number\n";
	}
	if (isBlank(form.cc_cid.value))
	{		
		errorString = errorString + "- Credit Card CVV Code\n";
	}

	if (isBlank(form.cc_exp.value))
	{		
		errorString = errorString + "- Credit Card Expiration Date\n";
	}


	if (errorString!='')
	{
		alert("The following information is required:\n" + errorString);
		return false;
	}
	else
	{
		return true;
	}
}
*/

function validateCustomerForm(form)
{			
	var errorString='';

	if (isBlank(form.fname.value))
	{		
		errorString = errorString + "- Billing First Name\n";
	}
	if (isBlank(form.lname.value))
	{		
		errorString = errorString + "- Billing Last Name\n";
	}
	if (isBlank(form.phone.value))
	{		
		errorString = errorString + "- Billing Phone\n";
	}
	if (isBlank(form.cc_addr.value))
	{		
		errorString = errorString + "- Billing Address\n";
	}
	if (isBlank(form.cc_city.value))
	{		
		errorString = errorString + "- Billing City\n";
	}
	if (isBlank(form.cc_state.value))
	{		
		errorString = errorString + "- Billing State\n";
	}
	if (isBlank(form.cc_zip.value))
	{		
		errorString = errorString + "- Billing Zip Code\n";
	}
	if (isBlank(form.cc_country.value) || form.cc_country.value=="--")
	{		
		errorString = errorString + "- Billing Country\n";
	}
	if (isBlank(form.email.value))
	{		
		errorString = errorString + "- Email Address\n";
	}
	if (isBlank(form.x_ship_to_first_name.value))
	{		
		errorString = errorString + "- Shipping First Name\n";
	}
	if (isBlank(form.x_ship_to_last_name.value))
	{		
		errorString = errorString + "- Shipping Last Name\n";
	}
	if (isBlank(form.x_ship_to_address.value))
	{		
		errorString = errorString + "- Shipping Address\n";
	}
	if (isBlank(form.x_ship_to_city.value))
	{		
		errorString = errorString + "- Shipping City\n";
	}
	if (isBlank(form.x_ship_to_state.value))
	{		
		errorString = errorString + "- Shipping State\n";
	}
	if (isBlank(form.x_ship_to_zip.value))
	{		
		errorString = errorString + "- Shipping Zip\n";
	}
	if (isBlank(form.x_ship_to_country.value) || form.x_ship_to_country.value=="--")
	{		
		errorString = errorString + "- Shipping Country\n";
	}

	var choice = "credit_card";
	inputs = document.getElementsByName('paymentMethod');
//	inputs = document.getElementsByTagName('input');
	for(var i=0; i < inputs.length; i++)
	{
		if(inputs[i].getAttribute('type') == 'radio' && inputs[i].checked)
		{
			choice = inputs[i].value;
		}

	}

    if (choice == "credit_card")
	{
		if (isBlank(form.cc_num.value))
		{		
			errorString = errorString + "- Credit Card Number\n";
		}
		if (isBlank(form.cc_cid.value))
		{		
			errorString = errorString + "- Credit Card CVV Code\n";
		}
	}

	
	if (customerForm.terms_conditions.checked == 0)
	{		
		errorString = errorString + "- You must agree to the Terms and Conditions\n";
	}
		
		

//	if (isBlank(form.cc_exp.value))
//	{		
//		errorString = errorString + "- Credit Card Expiration Date\n";
//	}


	if (errorString!='')
	{
		alert("The following information is required:\n" + errorString);
		document.getElementById('submit').style.display='';
		document.getElementById('showme').style.display='none';
		return false;
	}
	else
	{
		return true;
	}
}

function getXMLHttpObject()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
		
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}

function contactRequestDetails(myForm, elementToChange, eventID, adminID, hideshow)
{
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/admin/ajax_php/contact_request_details.php";
	url=url+"?id="+eventID;
	url=url+"&admin_id="+adminID;
	url=url+"&hideshow="+hideshow;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;}
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.send(null);
}

function eventDetails(myForm, elementToChange, eventID, hideshow)
{
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/admin/ajax_php/event_details.php";
	url=url+"?id="+eventID;
	url=url+"&hideshow="+hideshow;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{
			document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
		}
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.send(null);
}

function testPrint()
{
	alert('hi');
}

function showPreview(elementToChange)
{	

	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/admin_page_preview.php";
	
//	var poststr = "billing_address=" + encodeURI( document.getElementById("billing_address").value ) +
//		  		  "&billing_city=" + encodeURI( document.getElementById("billing_city").value ) +
//		  		  "&cc_zip=" + encodeURI( document.getElementById("cc_zip").value );
	

	var poststr = "thecontent=" +  encodeURI(document.getElementById("page_content").value);

	var t;

	xmlHttp.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
					//alert(xmlHttp.responseText);
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.setRequestHeader("Content-length", poststr.length);
   xmlHttp.setRequestHeader("Connection", "close");
   xmlHttp.send(poststr);
 
//   orderOK();
 //  alert("t is " + xmlHttp.responseText);
}

// Non-ajax functions - used for two lists manipulations (one is a main list, and the other is the new list)
function uncheckAll(obj) {
	for (var loop=0; loop < obj.options.length; loop++) {
	obj.options[loop].selected = false;
	}
}
function selectAll(listID)
{
	var newList = document.getElementById(listID);

	for (i = newList.length - 1; i>=0; i--)
	{
		newList.options[i].selected = true;
	}
}
function addSelectedClientsToList(mList, nList)
{
	var elSel = document.getElementById(mList);
	var newList = document.getElementById(nList);

	var i;
	for (i = elSel.length - 1; i>=0; i--)
	{
		if (elSel.options[i].selected)
		{
			//alert(elSel.options[i].text + ' ' + elSel.options[i].value);
			addClientsToList(elSel.options[i].value, elSel.options[i].text, newList);
		}
	}

	uncheckAll(document.getElementById(mList));
}

function addClientsToList(optionValue, optionText, newList)
{
	var found = 0;

	for (i = newList.length - 1; i>=0; i--) {
		if (newList.options[i].value ==optionValue) {
		 found = 1;
		}
	}

	if (found == 0)
	{
		var elOptNew = document.createElement('option');
		elOptNew.text = optionText;
		elOptNew.value = optionValue;

		try {
		newList.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		newList.add(elOptNew); // IE only
		}
	}

}

function removeOptionSelected(listID)
{
  var elSel = document.getElementById(listID);
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
	if (elSel.options[i].selected) {
	  elSel.remove(i);
	}
  }
}

function changeJammerzOutfit(pID, elementToChange)
{
//	alert(countryID);

	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/admin/ajax_php/changeJammerzOutfit.php";
	url=url+"?id="+pID;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{
			document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
			//document.getElementById('cityDropDown').innerHTML="";
			//window.open("document.writeln('" + xmlHttp.responseText + "');", 'OFFSCREEN','scrollbars=no,resizable=no,width=1024,height=768');
		}
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.send(null);   
}

function changeJammerzDropDown(pID, elementToChange)
{
	//alert(pID);

	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/admin/ajax_php/changeJammerzDropDown.php";
	url=url+"?id="+pID;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{
			document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
		}
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.send(null);   
}

function processResponse(form, responseID, elementToChange, adminID)
{
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/processResponse.php";
	url=url+"?cr_id="+responseID;
	url=url+"&admin_id="+adminID;
	url=url+"&cr_response_"+responseID+"="+encodeURIComponent(encodeURI(document.getElementById("cr_response_"+responseID).value));
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{
			document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
		}
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.send(null);
}

function order_email_response(elementToChange, responseElement, customerEmailAddress, orderID, adminID)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/order_email_response.php";
	var poststr =	"customer_email=" + encodeURI(customerEmailAddress) +					
					"&orderID=" + encodeURI(orderID) + 
					"&adminID=" + encodeURI(adminID)+
					"&response=" + encodeURI(document.getElementById(responseElement).value)
					+"&sid="+Math.random();


	xmlHttp.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
					//alert(xmlHttp.responseText);
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.setRequestHeader("Content-length", poststr.length);
   xmlHttp.setRequestHeader("Connection", "close");
   xmlHttp.send(poststr);

}

function get_order_list(elementToChange, field_search, field_search_text, orderStatus, trackingType, 
fromTimeHour, 
fromTimeMinute,
fromTimeAMPM,
toTimeHour, 
toTimeMinute,
toTimeAMPM,
fromDateMonth,
fromDateDay,
fromDateYear,
toDateMonth,
toDateDay,
toDateYear)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/orderList.php";
	var poststr =	"field_search=" + encodeURI(field_search) +					
					"&field_search_text=" + encodeURI(field_search_text) + 
					"&orderStatus=" + encodeURI(orderStatus)+					
					"&trackingType=" + encodeURI(trackingType)+
					"&fromTimeHour=" + encodeURI(fromTimeHour)+
					"&fromTimeMinute=" + encodeURI(fromTimeMinute)+
					"&fromTimeAMPM=" + encodeURI(fromTimeAMPM)+
					"&toTimeHour=" + encodeURI(toTimeHour)+
					"&toTimeMinute=" + encodeURI(toTimeMinute)+
					"&toTimeAMPM=" + encodeURI(toTimeAMPM)+
					"&fromDateMonth=" + encodeURI(fromDateMonth)+
					"&fromDateDay=" + encodeURI(fromDateDay)+
					"&fromDateYear=" + encodeURI(fromDateYear)+
					"&toDateMonth=" + encodeURI(toDateMonth)+
					"&toDateDay=" + encodeURI(toDateDay)+
					"&toDateYear=" + encodeURI(toDateYear)+
					"&sid="+Math.random();


//alert(encodeURI(field_search) +  ", " + encodeURI(field_search_text) +  ", " + encodeURI(trackingType) +  
//	", " + encodeURI(fromTime) +  ", " + encodeURI(toTime) +  ", " + encodeURI(fromDate) +  ", " + encodeURI(toDate) +
//	", " + encodeURI(orderType) +  ", ");
	xmlHttp.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;	
			 }				
		}
	
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.setRequestHeader("Content-length", poststr.length);
   xmlHttp.setRequestHeader("Connection", "close");
   xmlHttp.send(poststr);
}

function get_customer_list(elementToChange, field_search, field_search_text, customerStatus, customerType)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/customerList.php";
	var poststr =	"field_search=" + encodeURI(field_search) +					
					"&field_search_text=" + encodeURI(field_search_text) + 
					"&customerStatus=" + encodeURI(customerStatus)+					
					"&customerType=" + encodeURI(customerType)+
					"&sid="+Math.random();

//alert(encodeURI(field_search) +  ", " + encodeURI(field_search_text) +  ", " + encodeURI(trackingType) +  
//	", " + encodeURI(fromTime) +  ", " + encodeURI(toTime) +  ", " + encodeURI(fromDate) +  ", " + encodeURI(toDate) +
//	", " + encodeURI(orderType) +  ", ");
	xmlHttp.onreadystatechange=bleh;

	function bleh()
	{	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;	
				document.getElementById('loading').innerHTML='Search Complete! Results are shown below:';
			 }				
		}

	}

	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
}

function get_rolodex_list(elementToChange, field_search, field_search_text, customerStatus, customerType)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/rolodexList.php";
	var poststr =	"field_search=" + encodeURI(field_search) +					
					"&field_search_text=" + encodeURI(field_search_text) + 
					"&customerStatus=" + encodeURI(customerStatus)+					
					"&customerType=" + encodeURI(customerType)+
					"&sid="+Math.random();

//alert(encodeURI(field_search) +  ", " + encodeURI(field_search_text) +  ", " + encodeURI(trackingType) +  
//	", " + encodeURI(fromTime) +  ", " + encodeURI(toTime) +  ", " + encodeURI(fromDate) +  ", " + encodeURI(toDate) +
//	", " + encodeURI(orderType) +  ", ");
	xmlHttp.onreadystatechange=bleh;

	function bleh()
	{	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;	
				document.getElementById('loading').innerHTML='Search Complete! Results are shown below:';
			 }				
		}

	}

	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
}


function get_quick_response(elementToChange, quickResponseID)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/getQuickResponse.php";
	var poststr =	"quickResponseID=" + encodeURI(quickResponseID) +					
					"&sid="+Math.random();

	xmlHttp.onreadystatechange=bleh;

	function bleh()
	{	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
				
				document.getElementById(elementToChange).value=xmlHttp.responseText;	
				//alert(document.getElementById(elementToChange).value);	
				//document.getElementById(elementToChange).value="testing";
				//document.getElementById(elementToChange).SetHTML="testing";
				//xmlHttp.responseText
			 }				
		}

	}

	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
}


function get_reminders(elementToChange, adminID, expand)
{	
	// expand: 0 = close, or collapse menu to short list of reminders.
	//         1 = expand reminders, show all reminders.

	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/getReminders.php";
	var poststr =	"aid="+adminID +
					"&expand="+expand +
					"&sid="+Math.random();

	xmlHttp.onreadystatechange=bleh;

	function bleh()
	{	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{				
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;	
			}				
		}

	}

	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
	
}

function get_slipper_sizes(elementToChange, productID, size)
{	
	// expand: 0 = close, or collapse menu to short list of reminders.
	//         1 = expand reminders, show all reminders.

	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="/admin/ajax_php/getSlipperSizes.php";
	var poststr =	"size="+ size +		
					"&productID="+ productID +
					"&sid="+Math.random();

	xmlHttp.onreadystatechange=bleh;

	function bleh()
	{	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{				
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;	
			}				
		}

	}

	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
	
}


function getLotSizeBoxes(elementToChange, pid, lotType)
{
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/admin/ajax_php/getLotSizeBoxes.php";
	url=url+"?pid="+pid;
	url=url+"&lotType="+lotType;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{
			document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
		}
    }

   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
}


function getLotSizeBoxesCreate(elementToChange, lotType)
{
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/admin/ajax_php/getLotSizeBoxesCreate.php";
	url=url+"?lotType="+lotType;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
		{
			document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
		}
    }

   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
}


function ajax_change_shipping_rates(elementToChange, shippingCountry, shippingState, value, totalItems2, totalPrice2)
{	

	xmlHttp2 = getXMLHttpObject();
	if (xmlHttp2==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/ajax_php/calculateShipping.php";
	
//	var poststr = "billing_address=" + encodeURI( document.getElementById("billing_address").value ) +
//		  		  "&billing_city=" + encodeURI( document.getElementById("billing_city").value ) +
//		  		  "&cc_zip=" + encodeURI( document.getElementById("cc_zip").value );
	

	var poststr2 = "boxChecked=" +  encodeURI(value) +
		  		  "&totalItems=" + encodeURI(totalItems2) +
		  		  "&totalPrice=" + encodeURI(totalPrice2) +
		  		  "&shippingCountry=" + encodeURI(shippingCountry) + 
		  		  "&shippingState=" + encodeURI(shippingState);

	var t;

	xmlHttp2.onreadystatechange=blah;

	function blah()
    {	
		if(xmlHttp2.readyState==4)
		{
			if(xmlHttp2.status==200)
			{
					//alert(xmlHttp.responseText);
				document.getElementById(elementToChange).innerHTML=xmlHttp2.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp2.open("POST",url,true);
   xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp2.setRequestHeader("Content-length", poststr2.length);
   xmlHttp2.setRequestHeader("Connection", "close");
   xmlHttp2.send(poststr2);
}


function ajax_change_shipping_price(elementToChange, shippingCountry, shippingState, totalItems, shippingType)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/ajax_php/calculateShippingPrice.php";
	
	var poststr = "totalItems=" + encodeURI(totalItems) +
		  		  "&shippingType=" + encodeURI(shippingType) + 
		  		  "&shippingCountry=" + encodeURI(shippingCountry) + 
		  		  "&shippingState=" + encodeURI(shippingState);

	var t;

	xmlHttp.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{		
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.setRequestHeader("Content-length", poststr.length);
   xmlHttp.setRequestHeader("Connection", "close");
   xmlHttp.send(poststr);
}

function ajax_change_total_price(elementToChange, shippingCountry, shippingState, shippingType, totalItems, totalPrice)
{	
	xmlHttp3 = getXMLHttpObject();
	if (xmlHttp3==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/ajax_php/calculateTotalPrice.php";
	
	var poststr3 = "totalItems=" + encodeURI(totalItems) +
		  		  "&shippingType=" + encodeURI(shippingType)+ 
				  "&totalPrice=" + encodeURI(totalPrice) +
				  "&shippingCountry=" + encodeURI(shippingCountry) + 
		  		  "&shippingState=" + encodeURI(shippingState);

	var t;

	xmlHttp3.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp3.readyState==4)
		{
			if(xmlHttp3.status==200)
			{		
				document.getElementById(elementToChange).innerHTML=xmlHttp3.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp3.open("POST",url,true);
   xmlHttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp3.setRequestHeader("Content-length", poststr3.length);
   xmlHttp3.setRequestHeader("Connection", "close");
   xmlHttp3.send(poststr3);
}


function ajax_change_shipping_type(elementToChange, shippingCountry, shippingState, boxChecked, totalItems, totalPrice)
{	
	xmlHttp4 = getXMLHttpObject();
	if (xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/ajax_php/calculateShippingType.php";
	
	var poststr4 = "totalItems=" + encodeURI(totalItems) +
				  "&totalPrice=" + encodeURI(totalPrice) +
				  "&shippingCountry=" + encodeURI(shippingCountry) + 
		  		  "&shippingState=" + encodeURI(shippingState) + 
		  		  "&boxChecked=" + encodeURI(boxChecked);

	var t;

	xmlHttp4.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp4.readyState==4)
		{
			if(xmlHttp4.status==200)
			{		
				document.getElementById(elementToChange).value = xmlHttp4.responseText;
			 }
				
		}
	
    }

   xmlHttp4.open("POST",url,true);
   xmlHttp4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp4.setRequestHeader("Content-length", poststr4.length);
   xmlHttp4.setRequestHeader("Connection", "close");
   xmlHttp4.send(poststr4);
}


function ajax_change_all_shipping_info(ratesElement, priceElement, totalPriceElement, shippingCountry, shippingState, shippingType, boxChecked, totalItems, totalPrice)
{
	/* First check to see if any shipping options are already selected */ 

	/* Do all shipping changes with the following three AJAX functions */
	ajax_change_shipping_rates(ratesElement, shippingCountry, shippingState, boxChecked, totalItems, totalPrice);
	ajax_change_shipping_price(priceElement, shippingCountry, shippingState, totalItems, shippingType);
	ajax_change_total_price(totalPriceElement, shippingCountry, shippingState, shippingType, totalItems, totalPrice);
	ajax_change_shipping_type("shippingType", shippingCountry, shippingState, boxChecked, totalItems, totalPrice);

//	alert(document.getElementById('tests').value);
}

function ajax_lots_change_total_price(elementToChange, shippingCountry, totalPrice, domesticShipping, internationalShipping)
{	
	xmlHttp3 = getXMLHttpObject();
	if (xmlHttp3==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/ajax_php/calculateLotsTotalPrice.php";
	
	var poststr3 = "shippingCountry=" + encodeURI(shippingCountry) +
				  "&totalPrice=" + encodeURI(totalPrice) + 
				  "&domesticShipping=" + encodeURI(domesticShipping) + 
				  "&internationalShipping=" + encodeURI(internationalShipping);

	var t;

	xmlHttp3.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp3.readyState==4)
		{
			if(xmlHttp3.status==200)
			{		
				document.getElementById(elementToChange).innerHTML=xmlHttp3.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp3.open("POST",url,true);
   xmlHttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp3.setRequestHeader("Content-length", poststr3.length);
   xmlHttp3.setRequestHeader("Connection", "close");
   xmlHttp3.send(poststr3);
}

function ajax_lots_change_shipping_price(elementToChange, shippingCountry, domesticShipping, internationalShipping)
{	
	xmlHttp = getXMLHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 


	var url="/admin/ajax_php/calculateLotsShippingPrice.php";
	
	var poststr = "shippingCountry=" + encodeURI(shippingCountry) +
		  		  "&domesticShipping=" + encodeURI(domesticShipping) +
		  		  "&internationalShipping=" + encodeURI(internationalShipping);

	var t;

	xmlHttp.onreadystatechange=bleh;

	function bleh()
    {	
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{		
				document.getElementById(elementToChange).innerHTML=xmlHttp.responseText;
				//window.open("javascript:document.writeln(" + xmlHttp.responseText + ");", 'OFFSCREEN','scrollbars=yes,resizable=yes,width=1024,height=768');
			 }
				
		}
	
    }

   xmlHttp.open("POST",url,true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.setRequestHeader("Content-length", poststr.length);
   xmlHttp.setRequestHeader("Connection", "close");
   xmlHttp.send(poststr);
}


function validateLotsCustomerForm(form)
{			
	var errorString='';

	if (isBlank(form.fname.value))
	{		
		errorString = errorString + "- Billing First Name\n";
	}
	if (isBlank(form.lname.value))
	{		
		errorString = errorString + "- Billing Last Name\n";
	}
	if (isBlank(form.phone.value))
	{		
		errorString = errorString + "- Billing Phone\n";
	}
	if (isBlank(form.cc_addr.value))
	{		
		errorString = errorString + "- Billing Address\n";
	}
	if (isBlank(form.cc_city.value))
	{		
		errorString = errorString + "- Billing City\n";
	}
	if (isBlank(form.cc_state.value))
	{		
		errorString = errorString + "- Billing State\n";
	}
	if (isBlank(form.cc_zip.value))
	{		
		errorString = errorString + "- Billing Zip Code\n";
	}
	if (isBlank(form.cc_country.value))
	{		
		errorString = errorString + "- Billing Country\n";
	}
	if (isBlank(form.email.value))
	{		
		errorString = errorString + "- Email Address\n";
	}
	if (isBlank(form.x_ship_to_first_name.value))
	{		
		errorString = errorString + "- Shipping First Name\n";
	}
	if (isBlank(form.x_ship_to_last_name.value))
	{		
		errorString = errorString + "- Shipping Last Name\n";
	}
	if (isBlank(form.x_ship_to_address.value))
	{		
		errorString = errorString + "- Shipping Address\n";
	}
	if (isBlank(form.x_ship_to_city.value))
	{		
		errorString = errorString + "- Shipping City\n";
	}
	if (isBlank(form.x_ship_to_state.value))
	{		
		errorString = errorString + "- Shipping State\n";
	}
	if (isBlank(form.x_ship_to_zip.value))
	{		
		errorString = errorString + "- Shipping Zip\n";
	}
	if (isBlank(form.x_ship_to_country.value))
	{		
		errorString = errorString + "- Shipping Country\n";
	}

	if (errorString!='')
	{
		alert("The following information is required:\n" + errorString);
		return false;
	}
	else
	{
		return true;
	}
}

// Non-ajax functions - used for two lists manipulations (one is a main list, and the other is the new list)
function uncheckAll(obj) {
	for (var loop=0; loop < obj.options.length; loop++) {
	obj.options[loop].selected = false;
	}
}
function selectAll(listID)
{
	var newList = document.getElementById(listID);

	for (i = newList.length - 1; i>=0; i--)
	{
		newList.options[i].selected = true;
	}
}
function addSelectedToList(mList, nList)
{
	var elSel = document.getElementById(mList);
	var newList = document.getElementById(nList);

	var i;
	for (i = elSel.length - 1; i>=0; i--)
	{
		if (elSel.options[i].selected)
		{
			addClientsToList(elSel.options[i].value, elSel.options[i].text, newList);
		}
	}

	uncheckAll(document.getElementById(mList));
}

function addToList(optionValue, optionText, newList)
{
	var found = 0;

	for (i = newList.length - 1; i>=0; i--) {
		if (newList.options[i].value ==optionValue) {
		 found = 1;
		}
	}

	if (found == 0)
	{
		var elOptNew = document.createElement('option');
		elOptNew.text = optionText;
		elOptNew.value = optionValue;

		try {
		newList.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		newList.add(elOptNew); // IE only
		}
	}

}

function removeOptionSelected(listID)
{
  var elSel = document.getElementById(listID);
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
	if (elSel.options[i].selected) {
	  elSel.remove(i);
	}
  }
}
