/// <reference path="jquery-1.4.2.min-vsdoc.js" />

$(function() {
	$("#results .controls").hide();
	$("#output").hide();

	$("#btnClear").click(function() {
		$("#output").fadeOut();
		$("#results .controls").fadeOut();
	});

	$("#btnSubmit").click(function() {
		
		$("#results .controls").fadeOut();
		
		$("#output").load("proxy.aspx table", 
				{
					eid_ekl_ar: $("input#Number").val(),
					Eponymo: $("input#lName").val(),
					Onoma: $("input#fName").val(),
					on_pat: $("input#pName").val(),
					on_mht: $("input#mName").val(),
					etos_gen: $("input#year").val(),
				}, function(response, status, xhr) {
					
					var rtext = xhr.responseText;
					var problem = false;
					
					if (status != "error") {
						$("#output").fadeIn();
						$("#output table").attr("style", "").attr("width", "");
					}
					
					if(rtext.match("Πρέπει να συμπληρώσετε")) {
						$("#output").html(xhr.responseText);
						problem = true;
					} 

					if(rtext.match("ΑΝΕΠΙΤΥΧΗΣ ΑΝΑΖΗΤΗΣΗ")) {
						$("#output").html("Δε βρέθηκε εγγραφή με τα στοιχεία που δώσατε.");
						problem = true;
					}					
					
					if(!problem) {
						$("#results .controls").fadeIn();
					}
					
				});
			
		return false;
	});
	
	$("#print").click(function() {
		window.print();
	});
	
});
