/* Javascript file for shopping*/


function updateSalesTax()
{
	var cost;
	var STP="";
	cost = parseFloat(document.shipping.taxable_total.value);
	num_deliverable = parseInt(document.shipping.num_deliverable.value);
	sub_total = parseFloat(document.shipping.sub_total.value);
	//alert("Taxable total is "+cost+" and # deliverable is "+num_deliverable);
	if (num_deliverable > 1) { 
    num_deliverable = 1; 
  } else if (num_deliverable == 1) {
    num_deliverable = 1;
  } else {
    num_deliverable = 0;
  }
	  shipping_location = document.shipping.shipping_location.value;
	  
	 
		if(shipping_location== "california")
		{
	   	 
  		 tax_total = 0.0875 * cost;
	   	 shipping_total = 5.50 * num_deliverable;
		   STP = "Sales Tax 8.75 %";
    }
  
	
		if(shipping_location=="usa")
		{
		  tax_total = 0;
		  shipping_total = 5.50 * num_deliverable;
		  STP = 'Sales Tax (0 %)';
    }
		
		if(shipping_location=="other")
		{
		  tax_total = 0;
		  shipping_total = 9.50 * num_deliverable;
		  STP = 'Sales Tax (0 %)';
		}
		
		
	grand_total    = sub_total + shipping_total + tax_total;
	fixed_shipping = shipping_total.toFixed(2);
	fixed_tax      = tax_total.toFixed(2);
	fixed_grand    = grand_total.toFixed(2);


	document.getElementById('shipping_total').value = fixed_shipping;
	document.getElementById('tax_total').value = fixed_tax;
	document.getElementById('grand_total').value = fixed_grand;
			 
	document.getElementById('sales_tax_percent').innerHTML = STP;
	document.getElementById('sales_tax').innerHTML = '$'+fixed_tax;
	document.getElementById('delivery_cost').innerHTML = '$'+fixed_shipping;
	document.getElementById('grand_total_cost').innerHTML = '$'+fixed_grand;
	
	document.getElementById('please_select').innerHTML = '';
	document.getElementById('submit_button').disabled = false;
	document.getElementById('shipping_location').value = shipping_location;
	
	
	//document.update.shipping_location.value = document.shipping.shipping_location.value;
	
	
	
}


function fixFloat(num)
{
  return parseFloat(num).toFixed(2);
}

function updateShipping(form2)
{
	form2.submit();
}

function checkShipping(details)
{
	value = document.uShipping.shipping.options[document.uShipping.shipping.options.selectedIndex].value;
	document.co.action="https://secure.freetimers.com/flowerdiarydirect/order.php"+details;
	//document.co.action="https/order.php"+details;

	if (value == -1)
	{
		alert ("Please select your shipping location");
	}
	else
	{
		document.co.submit();
	}
}

function doSubmit(form2,action)
{
  var myForm = eval("document." + form2);

	myForm.form_action.value = action;
	myForm.submit();
}

function removeItem(form2, val, product_id)
{
    var myForm = eval("document." + form2);
    //alert ('hello:' + form2);
    myForm.remove_index.value = val;
    myForm.products_id.value = product_id;
  	myForm.form_action.value = 'remove';
    myForm.submit();
}

function updateItems(form2)
{
    var myForm = eval("document." + form2);
   	document.update.form_action.value = 'update';
   	//alert ('updating:' + form2 + '|' + document.update.action.value);
    document.update.submit();
}


function goShopping()
{
	document.co.action="index.php";
	document.co.submit();
}

//function to show and hide our div tag with options
function showHide(idname, linkName)
{
	if(idname.style.display == "inline")
	{
		idname.style.display = "none";
		linkName.innerHTML="(more info...)";
	}

	else
	{
		idname.style.display = "inline";
		linkName.innerHTML="(less info...)";
	}
}
