var price = { 
				'register' : 0,
				're_register' : 0,
				'edit' : 0,
				'register_1' : 4500,
				'register_2' : 1500,
				'register_3' : 9000,
				're_register_1' : 1350,
				're_register_2' : 3700,
				'edit_1' : 945,
				'oferta' : 0
			};
var toPay;

$().ready( function() {
	var seans =  new Date();
	$("#seans").val(seans.getTime());
	
	var options = 	{
						success:	showWindow   
					};
	
	var a, b;
	
	$("form input[type=radio]").click( function() { 
	/*	if (a) {
			a.attr("href","#");
		}*/
		var id = $(this).attr("id");
		var container = $("div#"+id+"_dop");
		var now = $("div#calculate div:visible");
		if (now.attr("id")!=container.attr("id")) {
			if (now.length==0) {
				$("form#form").append(container);
				container.fadeIn(300);
			} else {
				$("form#form").append(container);
				now.fadeOut(300, function() {
					container.fadeIn(300);
				});
				$("body").append(now);
			}
		};
		toPay = price[id]; 
		$("h3#toPay > span").text(toPay);
		$("#cena").val("");
		$("#itogo").val("");
		var seans =  new Date();
		$("#seans").val(seans.getTime());
	});
	
	$("input[type=checkbox]").click( function() {
		/*if (a) {
			a.attr("href","#");
		}*/
		var id = $(this).attr("id");
		if ($(this).attr("checked")) {
			toPay += price[id]; 
		} else {
			toPay -= price[id];
		}
		$("h3#toPay > span").text(toPay);
		var seans =  new Date();
		$("#seans").val(seans.getTime());
	});
	
	$("a.print").click( function() {
		b = $(this);
		$('form#form').attr("action","print.php")
		var dop = [];
		$("form#form input:checked").each( function() { 
			dop.push(price[$(this).attr("id")]);
		});
		dop = dop.join(";");
		$("#cena").val(dop)
		$("#itogo").val(toPay);
		$('form#form').ajaxForm(options);
		$('form#form').submit();
		$("#seans").val("");
		return false;
	});
	/*
	$("a.download").click( function() {
		if ($(this).attr("href")=="#") { 
			var dop = [];
			$("form#form input:checked").each( function() { 
				dop.push(price[$(this).attr("id")]);
			});
			dop = dop.join(";");
			$("#cena").val(dop)
			$("#itogo").val(toPay);
			$('form#form').attr("action","download.php")
			$('form#form').ajaxForm({	
							success:	showResponse      
						}); 
			$('form#form').submit();
			$("#seans").val("");
			a = $(this);
			return false;
		} else {
			return true;
		}
	});
*/
	function showWindow(responseText, statusText)  {
		myWin = open("", "displayWindow", "width=700,height=700,status=yes,toolbar=yes,menubar=yes,scrollbars=yes");
		myWin.document.open();
		myWin.document.write(responseText);
		myWin.self.print();
		myWin.document.close();
		link = myWin.document.getElementById("num");
		link = $(link).text();
		b.next("a").attr("href",link+".zip");
	};
	/*
	function showResponse(responseText, statusText)  { 
		if (responseText!=-1) {
			document.location.href = responseText;
			a.attr("href",responseText);
		} else {
			document.location.href = a.attr("href");
		}
	} 
	*/
});