function confirm_del(id) {
	var del = confirm("Are you sure you to delete?", "Yes", "No");

	if (del) {
		window.location = "index.php?id=" + id;
	}
}

function ChangeRowColor(tableRow, highLight) {
	if (highLight)
	{
		tableRow.style.backgroundColor = '#3CB371';
	}
	else {
		tableRow.style.backgroundColor = '#FFF';
	}
}

/* Dom Ready */
$(function () {
	var submit = false;

	$("#playBt").click(function () {
		$("#playLink").fancybox({
			'onStart': $("#submitFrm").css("display", "block"),
			'onClosed': $("#thanks").css("display", "none"),
			'padding': 0,
			'hideOnOverlayClick': false,
			'centerOnScroll': true
		});

		$("#playLink").trigger("click");
	});

	$("#awardBt").click(function () {
		$.fancybox("<div style='height: 604px; width: 402px; overflow: hidden;'><img src='images/08.jpg' width='402px' height='604px' /></div>", {
			'padding': 0,
			'centerOnScroll': true,
			'title': 'ร่ม และ กระบอกน้ำ Chill89fm'
		});
	});

	$("#submitFrm").validate({
		rules: {
			name: "required",
			nick: "required",
			age: {required: true, digits: true},
			tel: {required: true, digits: true},
			occ: "required",
			email: {required: true, email: true},
			movie: "required",
			reason: "required"
		},
		messages: {
			name: "*",
			nick: "*",
			age: {required: "*", digits: "*"},
			tel: {required: "*", digits: "*"},
			occ: "*",
			email: {required: "*", email: "*"},
			movie: "*",
			reason: "*"
		},
		meta: "validate",
		submitHandler: function() {
			submit = true;
		}
	});

    $("#submitFrm").bind("submit", function() {
		if (submit) {
			$.ajax({
				type		: "POST",
				cache	: false,
				url			: "submit.php",
				data		: $(this).serialize(),
				success	: function(data) {
					if (data == 1) {
						$("#submitFrm").css("display", "none");
						$("#thanks").css("display", "block");
						$("#resetBt").trigger("click");
					}
					else {
						alert("บันทึกข้อมุลล้มเหลว");
					}
				}
			});
			submit = false;
		}
		return false;
    });

	$("#sendBt").click(function () {
		$("#submitFrm").submit();
	});
});
