$(function(){

	$("#tavoritName,#tavoritDay,#tavoritMonth,#tavoritYear,#tavoritTelPref,#tavoritTel").focus(function() {
		$("#buttonTavorit").val("שלח");
	});

	$("#buttonTavorit").click(function(event){
		event.preventDefault();
		var name = $("#tavoritName").val().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		var day = $("#tavoritDay :selected").val();
		var month = $("#tavoritMonth :selected").val();
		var year = $("#tavoritYear :selected").val();
		var telpref = $("#tavoritTelPref :selected").val();
		var tel = $("#tavoritTel").val().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		if(name != "" && day != "0" && month != "0" && year != "0" && telpref != "0" && tel != ""){
			$.ajax({
				url: "BannerRequestForm.aspx",
				data: { 
					"base": "article", 
					"name": name,
					"day": day,
					"month": month, 
					"year": year, 
					"telpref": telpref,
					"tel": tel
				},
				type: "POST",
				statusCode: {
					404: function () {
						$("#buttonTavorit").val("התרחשה שגיאה");
					},
					200: function (msg) {
						if(msg == "-1")
							$("#buttonTavorit").val("פנייתך כבר נשלחה בעבר");
						else if(msg == "-2")
							$("#buttonTavorit").val("תאריך לידה משוער חל בעבר");
						else
							$("#buttonTavorit").val("פנייתך התקבלה");
					}
				}
			});
		}
		else
			$("#buttonTavorit").val("יש למלא את כל השדות");
		
	});
})
