// JavaScript Document
var dopopup		= true;
var alertmsg	= null;

$(function() {
	// get default plan and configure risk reversal if it exists
	// TODO?
	
	// update prices and checkout link
	$('.set-price').focus( function() {
		var id = $(this).attr('id');
		var planStr = $(this).val();
		var plan = planStr.split('|');
		
		var price = Number( $('#p'+id).val() );
		$('.monthly-payment').html( price.toFixed(2) );

		var newCheckout = "products/order/step1.php?buy="+plan[0]+"&amp;CheckOutOption=3&amp;PPL="+plan[1];
		$('.checkout').attr({ href: newCheckout });
	});
	
	// SHOULD TO CHECK IF exit div exist
	$("#exit").css("background","none");
	$("#exit").css("padding-top","0");
	
	alertmsg = $("#alertmsg").html();
	
	window.onbeforeunload = exitPopup; // COMMENT OUT TO DISABLE EXIT POPUP

	$("a").click( function(event) {
		dopopup = false;
	});
	
	$("form").submit( function(event) {
		dopopup = false;
	});
	
});

function exitPopup() {
	if(dopopup) {
		dopopup = false;
		
		//$("#exit").show();
		//$("div#main").hide();
		$("div#main").html($("#exit").html());
		var alertmsg = '';
		return "\n\n\n*****************************************************\n\nATTENDEZ NE PARTEZ PAS SANS VOS CADEAUX!\n\n"+alertmsg+"Cliquez sur le menu 'GRATUIT' en haut de la page \n\net vous recevrez 2 cadeaux pour vous remercier de votre visite\n\n\Marcel BELIVEAU\n\n\n*****************************************************\n\n\n";
	}
}