var toggle = false;
var pop_caster_p_Html;
var htmlAdTicketUrl;
var baseAdTicketUrl; 

var showCasterinfo = function showCasterinfo(castdate, casturl,donation,totaldonateamount,donationclick, pageX, pageY) {
	$("#pop_caster").hide();
	leftCordi = pageX-30 + "px";
	if(pageX-30>660){
		leftCordi =660 + "px";
	}
	topCordi = pageY+8 + "px";
	
	if (castdate == "게재 대기중") {
		$("#pop_caster").attr("class","do_pop");
		$("#pop_caster").html("<p>게재 대기중</p>");
	} else if (castdate == "ADticket 게재 가능 시간 종료") {
		$("#pop_caster").attr("class","pop_caster2");
		$("#pop_caster").html("<p>ADticket 게재 가능 시간 종료</p>");
	} else {
		$("#pop_caster").attr("class","do_pop");
		$("#pop_caster").html(pop_caster_p_Html);
		$("#castdate").html(castdate);
		$("#casturl").html(casturl);
		$("#casturlhref").attr("href",casturl);
		$("#donation").html(donation);
		$("#totaldonateamount").html(totaldonateamount);
		$("#donationclick").html(donationclick);
		}
	$("#pop_caster").css({'cursor':'',	
				          'position':'absolute',
				          'left':leftCordi,
				          'top':topCordi});
	$("#pop_caster").show(); 
};

var toggleCasterDiv = function() {
	$("#pop_caster").hide();
	if (toggle == false) {
		$("#btn").attr("src","../img/adtickepost/btn_close.gif");
		$("#caster").slideDown("normal");
		toggle = true;
	} else {
		$("#btn").attr("src","../img/adtickepost/btn_open.gif");
		$("#caster").slideUp("normal");
		toggle = false;
	}
};

$(function() {
	$("#pop_caster").bind("click", function hideCasterinfo() {
		var html = $("#pop_caster").html();
		if (html == "<P>게재 대기중</P>" || html == "<P>ADticket 게재 가능 시간 종료</P>"
			|| html == "<p>게재 대기중</p>" || html == "<p>ADticket 게재 가능 시간 종료</p>")
			$("#pop_caster").hide();
	});
});

var hidePopCaster = function() {
	$("#pop_caster").hide();
};

$(function() {
	$("span[title=adcaster]").css({'cursor':'pointer'});
	$("span[title=adcaster]").bind("click", function (event) {
		pageX = event.pageX;
		pageY = event.pageY;
		var castdate = eval("document.frm." + this.id + "_castdate");
		var casturl = eval("document.frm." + this.id + "_casturl");
		var donation = eval("document.frm." + this.id + "_donation");
		var totaldonateamount = eval("document.frm." + this.id + "_totaldonateamount");
		var donationclick =eval("document.frm." + this.id + "_donationclick");
	
		showCasterinfo(castdate.value, casturl.value, donation.value, totaldonateamount.value, donationclick.value, pageX, pageY);
		
	});
});

$(function() {
	window.onunload = function() {
		$.get("./update_refseq.enz",
				{
					"refstarttime":$("#refstarttime").val(),
					"ticketseq":$("#ticketseq").val()
				});
	};
});

$(function() {
	$("#btn_01").css({"cursor":"pointer"}).click(function() {
		$("#s_popup").hide();
	});
	pop_caster_p_Html = $("#pop_caster").html();
});

$(function() {
	$("#btn_subok").css({"cursor":"pointer"});
	$("#btn_subok").click(function() {
		$("#pop_subok").hide();
	});
});

var getTicketurl = function() {
	$.get("../adticket/getadticketurl.enz",
			{
				"ticketseq" : $("#ticketseq").val()
			}, showTicketUrl,"json");
};

var showTicketUrl = function(data) {
	htmlAdTicketUrl = data.htmlcastpage;
	baseAdTicketUrl = data.basecastpage;
	$("#adticketsource").val(htmlAdTicketUrl);
	$("#s_popup").hide();
	$("#pop_subok").show();
};

var showTicketHowto = function() {
	var width = 533;
	var height = 600;
	var winleft = (screen.width - width) / 2;
	var wintop = (screen.height - height) / 2;
	var option = "width="+width+",";
	option += "height="+height+",top="+wintop+",left="+winleft+",scrollbars=yes";
	window.open("./show_tickethowto.enz", "pointpopup", option);
};

var showTicketingHowto = function() {
	var width = 533;
	var height = 600;
	var winleft = (screen.width - width);
	var wintop = (screen.height - height) / 2;
	var option = "width="+width+",";
	option += "height="+height+",top="+wintop+",left="+winleft+",scrollbars=yes";
	window.open("../adticket/show_ticketinghowto.enz", "ticketinghowtopopup", option);
	showTicketinghowtoFlag = true;
};

var showTicketMoney = function(ticketseq) {
	var width = 503;
	var height = 620;
	var winleft = (screen.width - width) / 2;
	var wintop = (screen.height - height) / 2;
	var option = "width="+width+",";
	option += "height="+height+",top="+wintop+",left="+winleft+",scrollbars=no";
	window.open("../adticket/show_ticketmoney.enz?ticketseq="+ticketseq, "ticketmoneypopup", option);
	showTicketinghowtoFlag = true;
};	

var showClickMoney = function(ticketseq) {
	var width = 503;
	var height = 620;
	var winleft = (screen.width - width) / 2;
	var wintop = (screen.height - height) / 2;
	var option = "width="+width+",";
	option += "height="+height+",top="+wintop+",left="+winleft+",scrollbars=no";
	window.open("../adticket/show_clickmoney.enz?ticketseq="+ticketseq, "ticketmoneypopup", option);
	showTicketinghowtoFlag = true;
};	

$(function() {
	$("#adbanner_html").css({"cursor":"pointer"}).click(function() {
		$("#adbanner_html").attr("src","../img/adtickepost/pop_btn_mix_on.gif");
		$("#adbanner_base").attr("src","../img/adtickepost/pop_btn_img_off.gif");
		$("#adticketsource").val(htmlAdTicketUrl);
	});
	$("#adbanner_base").css({"cursor":"pointer"}).click(function() {
		$("#adbanner_html").attr("src","../img/adtickepost/pop_btn_mix_off.gif");
		$("#adbanner_base").attr("src","../img/adtickepost/pop_btn_img_on.gif");
		$("#adticketsource").val(baseAdTicketUrl);
	});
});

