// JavaScript Document
function upqty(a)
{
	var sess= document.getElementById('mysid').value;	
	var shipregion = document.getElementById('shipregion').value;		
	window.location = "update_cart.php?id="+a.name+"&qty="+a.value+"&mysid="+sess+"&shreg="+shipregion;
}

function upshiiping(c)
{
	if(c.value!="")
	{
		document.getElementById("shipping").value ="0.00";
		var bigtotal;
		var shipping = parseFloat(document.getElementById("shipping").value);
		var tax = parseFloat(document.getElementById("tax").value);
		var subtotal = parseFloat(document.getElementById("subtotal").value);		
		
		bigtotal = shipping + tax + subtotal;	
		document.getElementById("txttotal").value = roundit(bigtotal,2);
	}else
	{
		var bigtotal;
		//alert(document.getElementById("radio").value);
		var shipping1 = getCheckedValue();
		var shipping =parseFloat(shipping1);
		document.getElementById("shipping").value =shipping;
		
		var tax = parseFloat(document.getElementById("tax").value);
		var subtotal = parseFloat(document.getElementById("subtotal").value);		
		
		bigtotal = shipping + tax + subtotal;	
		document.getElementById("txttotal").value = roundit(bigtotal,2);
	}
	
	//---------------------------------------------
	var ajaxRequest;  // The variable that makes Ajax possible!		
	try
	{		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{	
		
		}
	}
	var shp_no=c.value;	
	ajaxRequest.open("GET", "update_shp.php?shp="+shp_no, true);
	ajaxRequest.send(null);
	//---------------------------------------------
}
function getCheckedValue() {
	for(var i = 0; i < document.frmcart.shp.length; i++) {
		if(document.frmcart.shp[i].checked) {
			return document.frmcart.shp[i].value;
		}
	}
	return "0.00";	
}

function addship(b,z)
{
if(document.getElementById("txtaccount2").value=="")
	{
	document.getElementById("shipping").value = b+'.00';
	}else
	{
	document.getElementById("shipping").value ="0.00";
	}
	var bigtotal;
	var shipping = parseFloat(document.getElementById("shipping").value);
	var tax = parseFloat(document.getElementById("tax").value);
	var subtotal = parseFloat(document.getElementById("subtotal").value);
	
		
	bigtotal = shipping + tax + subtotal;
	
	document.getElementById("txttotal").value = roundit(bigtotal,2);
	document.getElementById("hidshp").value=z;
}

function addtax(c)
{

	var subtotal = document.getElementById("subtotal").value;
	var bigtotal;
	if(c.checked==true)
	{
		if(document.getElementById("resale").checked==false)
		{
			var tax = (parseFloat(subtotal) * 8.75) / 100;
			tax=roundit(tax,2);
			document.getElementById("tax").value = tax;
			bigtotal = parseFloat(subtotal) + parseFloat(tax);
		}
					
	}
	else
	{
		document.getElementById("tax").value = "0.00";
		
	}
	
	var shipping = parseFloat(document.getElementById("shipping").value);
	
	
	if(shipping!="")
	{
		bigtotal = parseFloat(subtotal) + parseFloat(document.getElementById("tax").value) + parseFloat(document.getElementById("shipping").value);
	}
	else
	{
		
		bigtotal = parseFloat(subtotal) + parseFloat(document.getElementById("tax").value);
		
	}
	document.getElementById("txttotal").value = roundit(bigtotal,2);
	
	//---------------------------------------------
	var ajaxCalRes;  // The variable that makes Ajax possible!		
	try
	{		// Opera 8.0+, Firefox, Safari
		ajaxCalRes = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxCalRes = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try
			{
				ajaxCalRes = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxCalRes.onreadystatechange = function()
	{
		if(ajaxCalRes.readyState == 4)
		{	
		
		}
	}
	if(c.checked==true)
	{ var cal_res ='1';
	}else
	{ var cal_res ='0';}
	ajaxCalRes.open("GET", "update_calRes.php?cal_res="+cal_res, true);
	ajaxCalRes.send(null);	
}

function removetax(c)
{
	var subtotal = document.getElementById("subtotal").value;
	var bigtotal;
	var tax = document.getElementById("tax").value;
	if(c.checked==true)
	{
		
		var tax = 0;		
		document.getElementById("tax").value = "0.00";
		bigtotal = parseFloat(subtotal) + parseFloat(tax);
				
	}else
	{
		if(document.getElementById("bills").checked==true)
		{
			var tax = (parseFloat(subtotal) * 8.75) / 100;
			tax=roundit(tax,2);
			document.getElementById("tax").value = tax;
			bigtotal = parseFloat(subtotal) + parseFloat(tax);
		}
	}
	
	
	var shipping = parseFloat(document.getElementById("shipping").value);
	
	
	if(shipping!="")
	{
		bigtotal = parseFloat(subtotal) + parseFloat(document.getElementById("tax").value) + parseFloat(document.getElementById("shipping").value);
	}
	else
	{
		
		bigtotal = parseFloat(subtotal) + parseFloat(document.getElementById("tax").value);
		
	}
	document.getElementById("txttotal").value = roundit(bigtotal,2);
	
	//---------------------------------------------
	var ajaxReseller;  // The variable that makes Ajax possible!		
	try
	{		// Opera 8.0+, Firefox, Safari
		ajaxReseller = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxReseller = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try
			{
				ajaxReseller = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxReseller.onreadystatechange = function()
	{
		if(ajaxReseller.readyState == 4)
		{	
		}
	}
	if(c.checked==true)
	{ var reseller ='1';
	}else
	{ var reseller ='0';}
	ajaxReseller.open("GET", "update_reseller.php?reseller="+reseller, true);
	ajaxReseller.send(null);
}

function roundit(Num, Places) {
   if (Places > 0) {
      if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
         var Rounder = Math.pow(10, Places);
         return Math.round(Num * Rounder) / Rounder;
      }
      else return Num;
   }
   else return Math.round(Num);
}

function chkshipp()
{
	 var btn = valButton(frmcart.shp);
	if (btn == null) 
	{ 
		alert("Please select your shipping method");
		return false;
	}
	
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function chkTax()
{
	var cal = document.getElementById('bills');
	var  res = document.getElementById('resale');
	removetax(res);
	addtax(cal);
}

function updtShRegion()
{
var x= document.getElementById('shipregion').value;
var y = document.getElementById('xquantity').value;

	
	
	
		bigtotal = parseFloat(document.getElementById("txttotal").value) - parseFloat(document.getElementById("shipping").value);
	
	document.getElementById("txttotal").value = roundit(bigtotal,2);
	document.getElementById("shipping").value="0.00";
	//---------------------------------------------
	var ajaxRequest;  // The variable that makes Ajax possible!		
	try
	{		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{	
			var get_str=ajaxRequest.responseText;
			<!--alert(get_str);-->
			document.getElementById('shipptd').innerHTML=get_str;
			
		}
	}
	
	ajaxRequest.open("GET", "update_shpregion.php?shp="+x+"&qty="+y, true);
	ajaxRequest.send(null);
	//---------------------------------------------
	
	
	
}