function checkRentalAgreements(){
	var notCheckedAgreements;
	notCheckedAgreements = $("input.rental-agreement-check:not(:checked)");
	if (notCheckedAgreements.length > 0)
	{
		alert("You did not accept the rental terms and conditions.");
		notCheckedAgreements.parent().addClass("error");
		return false;
	}
	return true;
}
function updateTotals(url) {
    document.getElementById("frmCart").action = url;
    document.getElementById("frmCart").submit();
}
var confirmWin;
function rentalAgreementsInit(){
    $("#frmCart").submit(checkRentalAgreements);
    $("#frmCart").append($(".jqmConfirm"));
	//$(".jqmConfirm").jqm({overlay:88, modal:true, trigger:false});
	$(".rental-agreement-check").click(function(){
		if($(this).is(":checked")){
			//return confirm($("#termstext-" + $(this).attr("id").split("_")[1]).text());
			confirm($(this).attr("id").split("_")[1]);
		}
	});
	$(".rental-agreement-print").click(function () {
	    //var confirmWin = window.open("", "rentalAgreement", "location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,width=500,height=250");
	    if (confirmWin != null) {
	        confirmWin.document.body.innerHTML = '';
	    } else {
	        confirmWin = window.open("", "rentalAgreement", "scrollbars=yes,scrollbars=1,location=no,menubar=no,status=no,titlebar=no,toolbar=yes,resizable=yes,width=500,height=250");
	    }
	    var text = "";
	    text += "<html><head><title>Rental Terms and Conditions</title></head>"
	    text += "<body>";
	    text += "<p>Rental Terms and Conditions</p>";
	    text += $("#rental_agreement_text-" + $(this).attr("id").split("-")[1]).html();
	    text += "</body></html>";
	    confirmWin.document.write(text);
	    confirmWin.document.close();
	    confirmWin.focus();
	    confirmWin.print();
	    confirmWin = null;
	});
}
function confirm(lineNum){
	$("#agreement-" + lineNum).openModal();
	$("#agreement-" + lineNum)
	.find("a.button")
		.click(function(){
			if($(this).attr("id") == "accepted"){
				$("#rental-agreement-check_"+lineNum).attr("checked", "checked");
				
			}else{
				$("#rental-agreement-check_"+lineNum).attr("checked", "");
			}
			$("#agreement-" + lineNum).closeModal();
			return false;
		});
	$(".jqmClose").click(function(){
		$("#rental-agreement-check_" + lineNum).attr("checked", "");
		$("#agreement-" + lineNum).closeModal();
		return false;
	});

	$(".close-jqm").click(function () {
		$("#rental-agreement-check_" + lineNum).attr("checked", "");
		$("#agreement-" + lineNum).closeModal();
		return false;
	});

}
function print_agreement(lineNum){

}

$(function () {
	$('.jqmWindow').each(function () {
		$(this).createModal({
			title: "Rental Terms and Conditions",
			width: "500px",
            maxHeight: "400px",
			modal: true,
			closeButton: false
		});
	});
});

