// JavaScript Document

function getCatalog(){

var dept = document.getElementById('dept').value;
var url = "https://www.arrl.org/forms/recruiting/scripts/catalogTable.php?dept="+dept;

 xmlHttp = GetXmlHttpObject(); // create instance of xmlHttp object
 xmlHttp.onreadystatechange= function(){
   if(xmlHttp.readyState==4) { 
  
   document.getElementById('catalogTable').innerHTML = xmlHttp.responseText;
   
   }
 }
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}


function updateCart(itemID){
  var selQty = document.getElementById("item_"+itemID+"_quantity");
  var QtyIndex = selQty.selectedIndex;
   var quant = selQty.options[QtyIndex].value;
   var url = "updateCart.php?item="+itemID+"&quant="+quant;

 xmlHttp = GetXmlHttpObject(); // create instance of xmlHttp object
 xmlHttp.onreadystatechange= function(){
   if(xmlHttp.readyState==4) { 
   
   var parts = xmlHttp.responseText.split("|");
   var total_quantity = parts[0];
   var total_cost = parts[1];
   var total_weight = parts[2];
    if(total_quantity > 0){
	document.getElementById('cartSummary').style.display = "block";
	document.getElementById('cartQuantity').innerHTML = total_quantity;
  //document.getElementById('cartSubTotal').innerHTML = "$" + parseFloat(total_cost).toFixed(2);
	}else{
	document.getElementById('cartSummary').style.display = "none";
	}
   
   }
 }
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}//end "updateCart" function


//function to validate form and submit
function checkForm(){
 
  //later, put some validation code here to make sure quantity is > 0
  //alert("You have selected a quantity of ZERO (0).  Please enter a quantity before continuing");
    
	//if user has javascript, then values have already been set in session so just forward them to the form;
	//if they don't have javascript, this wont work and the form will POST the data and process on the next page.
    window.location = 'https://www.arrl.org/forms/recruiting/checkout.html';
	return false;
}// end "checkForm" function


//function to create xmlHttp object
var xmlHttp; //declare variable to be used in this function
function GetXmlHttpObject()
{
  var xmlHttp=null;
  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;
}// end of function to create ajax object