function updateCart(health_premium,health,8tp,8tpdna,chlandgon,chl,gon,hepb,hepc,herpes,hivanti,hivdna,syp) {
  //$("#spinnerdiv").html('<img src="{{ MEDIA_URL }}i/spinner.gif" id="spinner" alt="Wait" />');
 $.ajax({
   type: "GET",
   url: "/updatecart/",
   data: {'health_premium':health_premium, 'health':health, '8tp':8tp, '8tpdna':8tpdna, 'chlandgon':chlandgon, 'chl':chl, 'gon':gon, 'hepb':hepb, 'hepc':hepc, 'herpes':herpes, 'hivanti':hivanti, 'hivdna':hivdna, 'syp':syp },
   success: function(msg){
     $('#order_details_text').empty().append(msg);
   }
 });
}

function grayAll() {
	$(".testname").addClass("gray");
	$("#gray_message").show();
}

function unGrayAll() {
	$(".testname").removeClass("gray");
	$("#gray_message").hide();
}

function grayOne(id) {
	selector = "#" + id;
	$(selector).addClass("gray");
}

function unGrayOne(id) {
	selector = "#" + id;
	$(selector).removeClass("gray");
}

function fixForm() {
    if ($("#id_ReliefPack").attr("checked") == true) {
		$("#id_ChlandGonPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisBBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisCBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HerpesBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVElisaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVDNABox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_SyphilisBox").attr({'checked': false, 'disabled':'disabled'});
		grayAll();
	} else if ($("#id_PremiumPack").attr("checked") == true) {
		$("#id_ReliefPack").attr({'checked': true, 'disabled':''});
		$("#id_ChlandGonPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisBBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisCBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HerpesBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVElisaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVDNABox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_SyphilisBox").attr({'checked': false, 'disabled':'disabled'});
		grayAll();	
	} else if ($("#id_ChlandGonPack").attr("checked") == true) {
		$("#id_ReliefPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisBBox").attr({'disabled':''});
		$("#id_HepatitisCBox").attr({'disabled':''});		
		$("#id_HerpesBox").attr({'disabled':''});
		$("#id_HIVElisaBox").attr({'disabled':''});
		$("#id_HIVDNABox").attr({'disabled':''});
		$("#id_SyphilisBox").attr({'disabled':''});
		grayOne("chl");
		grayOne("gon");
	}
	
	if ($("#id_HIVElisaBox").attr("checked") == true) {
		$("#id_HIVDNABox").attr({'disabled':'disabled'});
	} else if ($("#id_HIVDNABox").attr("checked") == true) {
		$("#id_HIVElisaBox").attr({'disabled':'disabled'});
	}
}

function reliefPack() {
	if ($("#id_ReliefPack").attr("checked") == true) {
		$("#id_PremiumPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlandGonPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisBBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisCBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HerpesBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVElisaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVDNABox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_SyphilisBox").attr({'checked': false, 'disabled':'disabled'});
		grayAll();
		getSummary();
	} else {
		$("#id_PremiumPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':''});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':''});
		$("#id_HepatitisBBox").attr({'checked': false, 'disabled':''});
		$("#id_HepatitisCBox").attr({'checked': false, 'disabled':''});
		$("#id_HerpesBox").attr({'checked': false, 'disabled':''});
		$("#id_HIVElisaBox").attr({'checked': false, 'disabled':''});
		$("#id_HIVDNABox").attr({'checked': false, 'disabled':''});
		$("#id_SyphilisBox").attr({'checked': false, 'disabled':''});
		unGrayAll();
		getSummary();
	}
}

function premiumPack() {
	if ($("#id_PremiumPack").attr("checked") == true) {
		$("#id_ReliefPack").attr({'checked': true, 'disabled':''});
		$("#id_ChlandGonPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisBBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HepatitisCBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HerpesBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVElisaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_HIVDNABox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_SyphilisBox").attr({'checked': false, 'disabled':'disabled'});
		grayAll();
		getSummary();
	} else {
		getSummary();
	}
}

function chlandGonPack() {
	if ($("#id_ChlandGonPack").attr("checked") == true) {
		unGrayAll();
		$("#id_ReliefPack").attr({'checked': false, 'disabled':''});
		$("#id_PremiumPack").attr({'checked': false, 'disabled':''});
		$("#id_ChlamydiaBox").attr({'checked': false, 'disabled':'disabled'});
		$("#id_GonorrheaBox").attr({'checked': false, 'disabled':'disabled'});
		grayOne("chl");
		grayOne("gon");
		$("#id_HepatitisBBox").attr({'disabled':''});
		$("#id_HepatitisCBox").attr({'disabled':''});

		if ($("#id_HIVDNABox").attr("checked") == true) {
			$("#id_HIVElisaBox").attr({'disabled':'disabled'});
			grayOne("hivanti");
		} else {
			$("#id_HIVElisaBox").attr({'disabled':''});
			unGrayOne("hivanti");
		}

		if ($("#id_HIVElisaBox").attr("checked") == true) {
			$("#id_HIVDNABox").attr({'disabled':'disabled'});
			grayOne("hivdna");
		} else {
			$("#id_HIVDNABox").attr({'disabled':''});
			unGrayOne("hivdna");
		}

		$("#id_HerpesBox").attr({'disabled':''});
		$("#id_SyphilisBox").attr({'disabled':''});
		
		getSummary();
	} else {
		$("#id_ChlamydiaBox").attr({'disabled':''});
		$("#id_GonorrheaBox").attr({'disabled':''});
		getSummary();
		unGrayOne("chl");
		unGrayOne("gon");
		$("#gray_message").hide();
	}
}

function hivdna() {
	if ($("#id_HIVDNABox").attr("checked") == true) {
		$("#id_HIVElisaBox").attr({'disabled':'disabled'});
		grayOne("hivanti");
	} else {
		$("#id_HIVElisaBox").attr({'disabled':''});
		unGrayOne("hivanti");
	}
	getSummary();	
} 

function hivELISA() {
	if ($("#id_HIVElisaBox").attr("checked") == true) {
		$("#id_HIVDNABox").attr({'disabled':'disabled'});
		grayOne("hivdna");
	} else {
		$("#id_HIVDNABox").attr({'disabled':''});
		unGrayOne("hivdna");
	}
	getSummary();	
} 

function getSummary() {
	//str = $(":input[@name='productbundle']:checked").val(); 
	
	updateCart(false,
	           false,
			   $("#id_ReliefPack").attr("checked"),
	           $("#id_PremiumPack").attr("checked"),
	           $("#id_ChlandGonPack").attr("checked"), 
	           $("#id_ChlamydiaBox").attr("checked"),
	           $("#id_GonorrheaBox").attr("checked"),
	           $("#id_HepatitisBBox").attr("checked"),
	           $("#id_HepatitisCBox").attr("checked"),
	           $("#id_HerpesBox").attr("checked"),
	           $("#id_HIVElisaBox").attr("checked"),
	           $("#id_HIVDNABox").attr("checked"),
	           $("#id_SyphilisBox").attr("checked"));
}

$(document).ready(function(){
	$("#gray_message").hide();
	fixForm();
	$("form").submit(function() { $(".submit").attr("disabled","true").attr("value", "Please Wait..."); });
	$("#id_ReliefPack").click(function() { reliefPack(); });
	$("#id_PremiumPack").click(function() { premiumPack(); });
	$("#id_ChlandGonPack").click(function() { chlandGonPack(); });
	$("#id_ChlamydiaBox").click(function() { getSummary(); });
	$("#id_GonorrheaBox").click(function() { getSummary(); });
	$("#id_HepatitisBBox").click(function() { getSummary(); });
	$("#id_HepatitisCBox").click(function() { getSummary(); });
	$("#id_HerpesBox").click(function() { getSummary(); });
	$("#id_HIVElisaBox").click(function() { hivELISA(); });
	$("#id_SyphilisBox").click(function() { getSummary(); });
	$("#id_HIVDNABox").click(function() { hivdna(); });
	
	$('#spinnerdiv')
    	.hide()  // hide it initially
    	.ajaxStart(function() {
        	$('#order_details_text').empty();
        	$(this).show();
    	})
    	.ajaxStop(function() {
        	$(this).hide();
    	});

	$('span.test_details').hide();

	// Toggle More Info/Less Info
	$("a.info").click(function(){
	  $(this).next('span.test_details').slideToggle(5);
	  $(this).toggleClass("active");
	  
	  return false;
	  
	  //text = $(this).html();
	  
	  //if (text == "More Info") {
	  //	$(this).html("Less Info");
	  //} else {
	  //	$(this).html("More Info");
	  //}
	});
});


