$(function(){
	$('.inactive_buying').click(function(){
		alert('แพคเก็จนี้ถูกยกเลิกชั่วคราว');
	});
	$("#signup_btn input").click(function(){
		window.location.href = '/company/signup'
	});
	$('.del_pck a').click(function(event){
		event.preventDefault();
		var tmp_obj = $(this);
		if(confirm('ต้องการลบใช่ไหม?')){
			$.ajax({
			type: "GET",
			url: ''+$(this).attr('href'),
			data: "rand="+Math.random(),
			beforeSend: function(){tmp_obj.empty().html('<img src=\"/images/reload.gif\" border=0 />'); },
			success: function(msg){ 
				if(msg.substring(0, 2)=='DU'){
					tmp_obj.parents('div.show_content').remove();
					var sz = $(".show_content:last",$(".pck")).css({"margin-bottom":0, "border-bottom-style":"solid"}).size();
					if(sz==0) window.location.reload();
				} }
			});
		}
	});
	$('.buy_pck').click(function(event){
		event.preventDefault();
		var pid = $(this).attr('name');
		var uid = $('#employer_container').attr('name');
		var tmp_url = '/orders/buy/';
		if($.trim(pid)!='' && $.trim(uid)!=''){
			tmp_url =  '/orders/buy/'+uid+'/'+pid;
		}
		$.ajax({
		type: "GET",
		url: tmp_url,
		data: "rand="+Math.random(),
		beforeSend: function(){
			$('a:[name="'+pid+'"]').hide().before('<img src="/images/reload.gif" width="16" height="16" />');
		},
		success: function(msg){
				if(msg.substring(0, 2)=='OK'){
					window.location.href='/orders/view/'+uid;
				}else if(msg.substring(0, 2)=='DU'){
					alert('ท่านเคยสั่งซื้อแพคเก็จนี้แล้ว\nตอนนี้กำลังรอการชำระเงินค่ะ');
					$('img', $('a:[name="'+pid+'"]').show().parent('span')).remove();
				}else{
					alert('กรุณาเข้าระบบเป็นผู้ประกอบการ');
					$('img:[src*=reload.gif]', $('a:[name="'+pid+'"]').show().parent('span')).remove();
				}
			}
		});
	});
	$(".show_content:last",$(".bank_payment")).css({"margin-bottom":0, "border-bottom-style":"solid"});
	$(".pck_det:last",$(".pck")).css({"margin-bottom":0, "border-bottom-style":"solid"});
	$(".pck_det:last",$(".banner_det")).css({"margin-bottom":0, "border-bottom-style":"solid"});
	$(".show_content:last",$(".pck")).css({"margin-bottom":0, "border-bottom-style":"solid"});
	
	if($('#flashMessage').size()>0){
		$('#flashMessage').hide();
		$(".show_content:first",$(".pck")).css({"background-color":"#FFD7D7", "padding-top":"7px"});
		$(".pck .content_panel_bar").css({"margin-bottom":0});
		alert('สั่งซื้อแพคเก็จเสร็จเรียบร้อยแล้ว\nกรุณาชำระเงินด้วยค่ะ');
	}
});
