/* file for js functions that can be used on multiple tire pages */
function submitBuyForm2(wantRHP, shipquote, isWishList, formName) {
 currentForm = eval("document." + formName);
 currentForm.target = "";
 currentForm.shipquote.value = "N";
 currentForm.wishlist.value = "false";
 if(currentForm.WantRHP != null) { //set
	currentForm.WantRHP.value = wantRHP;
 } else if(currentForm.i1_WantRHP != null) { //single
	currentForm.i1_WantRHP.value = wantRHP;
 }
 if(wantRHP.indexOf("Y") > -1) { //wants RHP
	var intQty = 0;
	var qty = 0;

	// frontTire (i1)
	if(currentForm.i1_Qty != null) {
	  if(currentForm.i1_Qty.options != null) {
	  	qty = currentForm.i1_Qty.options[currentForm.i1_Qty.selectedIndex].value;
	  } else if(currentForm.i1_Qty.value != null) {
		qty = currentForm.i1_Qty.value;
	  }
	 if(qty != null && qty>0) {
		intQty += parseInt(qty);
	  }
	}

	// frontLeftTire (i2)
	if(currentForm.i2_Qty != null) {
	  if(currentForm.i2_Qty.options != null) {
	  	qty = currentForm.i2_Qty.options[currentForm.i2_Qty.selectedIndex].value;
	  } else if(currentForm.i2_Qty.value != null) {
		qty = currentForm.i2_Qty.value;
 	  }
	  if(qty != null && qty>0) {
		intQty += parseInt(qty);
	  }
	}

	// rearTire (i3)
	if(currentForm.i3_Qty != null) {
	  if(currentForm.i3_Qty.options != null) {
	  	qty = currentForm.i3_Qty.options[currentForm.i3_Qty.selectedIndex].value;
	  } else if(currentForm.i3_Qty.value != null) {
		qty = currentForm.i3_Qty.value;
	  }
	  if(qty != null && qty>0) {
		intQty += parseInt(qty);
	  }
	}

	// rearLeftTire (i4)
	if(currentForm.i4_Qty != null) {
	  if(currentForm.i4_Qty.options != null) {
	  	qty = currentForm.i4_Qty.options[currentForm.i4_Qty.selectedIndex].value;
	  } else if(currentForm.i4_Qty.value != null) {
		qty = currentForm.i4_Qty.value;
	  }
	  if(qty != null && qty>0) {
		intQty += parseInt(qty);
	  }
	}

	/*if(intQty < 4) { //wants RHP, but has < 4 tires
		alert("REMINDER: You must purchase four (4) or more tires in a set to be eligible for Tire Rack's Road Hazard Program.");
	} else { */
		//RHP is the only action that needs to submit the form
		//the others are using the onClick method and will submit
		//submit the form through an image input tag
		currentForm.submit();
//}
 } else if(shipquote.indexOf("Y") > -1) { //doing a shipping quote
	currentForm.shipquote.value = "Y";
	var newwindow = window.open('','ShipWindow','width=500,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
	currentForm.target = "ShipWindow";
 } else if (shipquote.indexOf("M") > -1) { //showing MAP
 	if(shipquote.indexOf("MRHP") > -1){
		if(currentForm.WantRHP != null) { //set
			currentForm.WantRHP.value = wantRHP;
		} else if(currentForm.i1_WantRHP != null) { //single
			currentForm.i1_WantRHP.value = wantRHP;
		}
	}
	currentForm.shipquote.value = "M";
	newwindow = window.open('','ShipWindow','width=620,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
	currentForm.target = "ShipWindow";
 	// MNS (Map no submit) is used for javascript that doesn't submit the form
	if (shipquote.indexOf("MNS") > -1 || shipquote.indexOf("MRHP") > -1) {
		currentForm.submit();
	}
 } else if(isWishList.indexOf("Y") > -1) { //adding to wishlist
	currentForm.wishlist.value = "true";
 }
}
