jQuery(document).ready(function() {
	jQuery('#applicantHostingMileage').click(function() {
		if (jQuery(this).attr('href') != '#') {
			return;
		}
		if (!isHostingMileageApplicant) {
			alert('Àû¸³±Ý ÀÀ¸ð¸¦ À§ÇÑ È£½ºÆÃ Àû¸³±ÝÀÌ ¾ø°Å³ª ºÎÁ·ÇÕ´Ï´Ù.');
			return false;
		}
		var msg = 'È£½ºÆÃ Àû¸³±Ý '+ varHostingMileage +'¿øÀÌ Â÷°¨µË´Ï´Ù.\nÀÀ¸ðÇÏ½Ã°Ú½À´Ï±î?';
		if (!window.confirm(msg)) {
			return false;
		}
		var f = getParentForm(jQuery(this).get(0));
		f.use_hosting_mileage.value = 'Y';
		f.submit();
		return false;
	});
});
function submitEventPoint(f) {
	if (f.event_code.value.trim() == "") {
		alert("ÀÌº¥Æ® ÄÚµå°¡ ÇÊ¿äÇÕ´Ï´Ù.");
		return false;
	}
}
function submitEventComment(f) {
	if (f.event_code.value.trim() == "") {
		alert("ÀÌº¥Æ® ÄÚµå°¡ ÇÊ¿äÇÕ´Ï´Ù.");
		return false;
	} else if (f.comment_memo.value.trim() == "") {
		alert("´ñ±ÛÀ» ÀÔ·ÂÇÏ¿©¾ß ÇÕ´Ï´Ù.");
		elFocus(f.comment_memo);
		return false;
	}
}

function removeEventComment(el, comment_idx) {
	if (!window.confirm("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) return;
	var f = getParentForm(el);
	f.comment_idx.value = comment_idx;
	f.exec_mode.value = "comment_remove";
	f.submit();
}

var popupSNS = null;
function postupSNS(pElement) {
	var link_path = 'http://'+ window.location.host + window.location.pathname;
	link_path += '?p='+ getQueryString('p');
	link_path += '&event_code='+ getQueryString('event_code');

	var f = getParentForm(pElement);
	var varMedia = pElement.alt;
	var varMovieTitle = f.movie_title.value;
	var varEventType = f.event_type.value;
	// SNS ±Û ³»¿ë Á¶ÇÕ
	var snsTitle = '¾¾³×ÅäÅ©¿Í ÇÔ²²ÇÏ´Â ['+ varMovieTitle +'] ';
	switch (varEventType) {
		case 'ticket'     : snsTitle += '¿¹¸Å±Ç'; break;
		case 'invitation' : snsTitle += 'ÃÊ´ë±Ç'; break;
		case 'sisa'       : snsTitle += '½Ã»çÈ¸'; break;
	}
	snsTitle += ' ÀÌº¥Æ®';

	var encodeTitle = encodeURIComponent(snsTitle);
	var encodeURL   = encodeURIComponent(link_path);

	var varOpt = '';
	var varOpenURL = new Array();
	switch (varMedia) {
		case "twitter" :
			varOpenURL.push("http://twitter.com/intent/tweet");
			varOpenURL.push("?text=" + encodeTitle);
			varOpenURL.push("&url="+ encodeURL);
			varOpt = 'width=800, height=500';
			break;
		case "me2day" :
			varOpenURL.push("http://me2day.net/posts/new");
			varOpenURL.push("?new_post[body]=" + encodeTitle);
			varOpenURL.push(" "+ encodeURL);
			varOpenURL.push("&new_post[tags]=");
			break;
		case "yozm" :
			varOpenURL.push("http://yozm.daum.net/api/popup/prePost");
			varOpenURL.push("?link=" + encodeURL);
			varOpenURL.push("&prefix=" + encodeTitle);
			varOpenURL.push("&parameter=" + encodeTitle);
			break;
		case "facebook" :
			varOpenURL.push("http://www.facebook.com/sharer.php");
			varOpenURL.push("?t=" + encodeTitle);
			varOpenURL.push("&u=" + encodeURL);
			break;
		case "cyworld" :
			thumbnail = ('http://'+ window.location.host + f.img_src.value);
			var varSummary = new Array();
			varOpenURL.push("http://csp.cyworld.com/bi/bi_recommend_pop.php");
			varOpenURL.push("?url=" + encodeURL);
		//	varOpenURL.push("?url=" + link_path);
			varOpenURL.push("&title_nobase64=" + encodeTitle);
			varOpenURL.push("&thumbnail="+ thumbnail);
		//	varOpenURL.push("&summary_nobase64="+ encodeURIComponent(varSummary.join('<br />')));
			varOpenURL.push("&writer=cinetalk");
			varOpt = 'width=400, height=340';
			break;
	}
	if (varOpt == '') {
		window.open(varOpenURL.join(''));
	} else {
		if (popupSNS != null) popupSNS.close();
		popupSNS = window.open(varOpenURL.join(''), "popupSNS", varOpt);
		popupSNS.focus();
	}
}

function getQueryString(pKey) {
	var strQueryString = window.location.search.slice(1);
	var splitQueryString = strQueryString.split('&');
	var arrQueryString = new Array;
	for (var i=0, max=splitQueryString.length; i<max; i++) {
		querystring = splitQueryString[i];
		point = querystring.indexOf('=');
		sKey = querystring.substr(0, point);
		sVal = querystring.substr(point+1);
		arrQueryString[sKey] = sVal;
	}
	if (pKey == undefined) return arrQueryString;
	if (arrQueryString[pKey] == undefined) return '';
	return arrQueryString[pKey];
}

