$(function(){
	$('#entry_sweet').click(function(){
		var event_id = GET('event_id');
		var button = this;
		
		if(event_id == '') alert('請選擇要報名的活動');
		else{
			$.ajax({
				type: "POST",
				url: 'ajax/ajax_entry_sweet.php',
				data: 'event_id='+event_id,
				dataType: 'json',
				async: false,
				beforeSend: function(){
					$(button).hide().after('<div>處理中請稍後...</div>');
				},
				success: function(data){
					if(data.success == false){
						alert(data.msg);
						if(data.todo == 'login'){
							location.href = 'http://www.cwcentral.com/?form='+data.form;
						}
					}
					else if(data.success == true){
						alert(data.msg);
						location.reload();
					}
					$(button).show().next().remove();
				}
			});
		}
	});
});

function GET(k){
	var href = location.href.split('?');
	if(href.length >= 2){
		var	href2 = href[1].split('&');
		var v = '';
		for(var idx in href2){
			var href3 = href2[idx].split('=');
			if(href3[0]==k) var v=href3[1];
		}
		if(v != '') return v;
		else return false;
	}
	else return false;
}