var notice_html = {'notice' : '', 'event' : ''};
var customer_index_html = { 
	'faq' : {'1' : '', '2' : '', '3' : '', '4' : '', '685' : '', '702' : ''}, 
	'manual' : {'webhosting' : '', 'webmail_hosting' : '', 'flvhosting' : '', 'imagehosting' : '', 'gabiafreemall' : ''} 
};

// body onload
$(function() {
	$("#dialog").dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		height: 'auto',
		width: 698,
		modal: true
	});

	// faq Ä«Å×°í¸®
	getCategorySelect ('category1', '');
	// ³ªÀÇ »ó´ã ³»¿ª / My Gabia
	getUserInfo ();
	// °øÁö»çÇ×
	chgNotice ('notice');
	// ¸¹ÀÌ º¸´Â Áú¹®
	getCustomerIndex ('faq', '2');
	// ¸¹ÀÌ º¸´Â ¸Þ´º¾ó
	getCustomerIndex ('manual', 'domain');
});

// ¸¹ÀÌ Ã£´Â º¸´Â ´Ü¾î
function clickSearchKeyword (keyword)
{
	$('#keyword').val(keyword);
	$('#frmFaqSearch').submit();
}

// FAQ °Ë»ö
function chkFaqSearch (form)
{
	if (!$.trim(form.keyword.value))
	{
		form.keyword.focus();
		alert ('°Ë»ö¾î¸¦ ÀÔ·ÂÇÏ¼¼¿ä.');
		return false;
	}
}

// ³ªÀÇ »ó´ã ³»¿ª / My °¡ºñ¾Æ
function getUserInfo ()
{
	$.ajax({
		type: 'POST',
		url: '/include/index_data.php',
		data: 'action=getUserInfo',
		dataType: 'json',
		success: function(json_data) {
			var myvoc, mygabia;
			if (json_data.login)
			{
				myvoc   = '<a href="/1to1/my_list.php" class="IN01">¤ýÁ¢¼ö <b><font color="#303030">'+json_data.counsel_request+'</font></b>°Ç</a><br><a href="/1to1/my_list.php" class="IN01">¤ýÃ³¸® <b><font color="#303030">'+json_data.counsel_complete+'</font></b>°Ç</a><br>';
				mygabia = '<a href="http://domain.gabia.com/mydomain/mydomain_list.php" class="IN01">¤ýµµ¸ÞÀÎ <b><font color="#303030">'+json_data.domain_service+'</font></b>°Ç</a><br><a href="http://hosting.gabia.com/myhg/mylist/" class="IN01">¤ýÈ£½ºÆÃ <b><font color="#303030">'+json_data.hosting_service+'</font></b>°Ç</a><br>';
			}
			else
			{
				var s = location.href;
				myvoc   = '<a href="https://www.gabia.com/login/login_form.php?origin_site='+s+'" class="IN01">·Î±×ÀÎ ½Ã<br>Á¶È¸ °¡´É</a>';
				mygabia = '<a href="https://www.gabia.com/login/login_form.php?origin_site='+s+'" class="IN01">·Î±×ÀÎ ½Ã<br>Á¶È¸ °¡´É</a>';
			}

			$('#myvoc').html(myvoc);
			$('#mygabia').html(mygabia);
		}
	});
}

// °øÁö»çÇ× / ÀÌº¥Æ® 
function chgNotice (type)
{
	$('#btn_notice').attr('src', '/images/index/2009/0826_16.gif');
	$('#btn_event').attr('src', '/images/index/2009/0826_17.gif');

	//
	if (type == 'notice')
	{
		$('#btn_notice').attr('src', '/images/index/2009/0826_16_1.gif');
		$('#notice_more').attr('href', 'http://www.gabia.com/gabia_notice/list.php');
	}
	else if (type == 'event')
	{
		$('#btn_event').attr('src', '/images/index/2009/0826_17_1.gif');
		$('#notice_more').attr('href', 'http://www.gabia.com/gabia_notice/event_list.php');
	}

	//
	if (!notice_html[type])
	{
		$.ajax({
			type: 'POST',
			url: '/include/index_data.php',
			data: 'action=getNotice&notice_type='+type,
			dataType: 'html',
			success: function(html_data) {
				notice_html[type] = html_data;
				$('#notice_view').html(html_data);
			}
		});
	}
	else
	{
		$('#notice_view').html(notice_html[type]);
	}
}

// ¸¹ÀÌ º¸´Â Áú¹® / ¸Þ´º¾ó
function getCustomerIndex (type, gubun)
{
	if (!customer_index_html[type][gubun])
	{
		$.ajax({
			type: 'POST',
			url: '/include/index_data.php',
			data: 'action=getCustomerIndex&type='+type+'&gubun='+gubun,
			dataType: 'html',
			success: function(html_data) {
				customer_index_html[type][gubun] = html_data;
				$('#'+type+'_view').html(html_data);
			}
		});
	}
	else
	{
		$('#'+type+'_view').html(customer_index_html[type][gubun]);
	}
}

// ¸¹ÀÌº¸´Â Áú¹® / ¸Þ´º¾ó »ó¼¼º¸±â
function viewContents (type, gubun, seqno)
{
	var url;
	var data;

	if (type == "faq")
	{
		url = '/include/faq_data.php';
		data = 'action=getFaqInfo&seqno='+seqno;
	}
	else if (type == "manual")
	{
		url = '/include/manuals_data.php';
		data = 'action=getManualInfo&seqno='+seqno;
	}

	//
	$.ajax({
		type: 'POST',
		url: url,
		data: data,
		dataType: 'xml',
		error: function (XMLHttpRequest, textStatus, errorThrown) { alert ("Åë½Å Áß ¿¡·¯°¡ ¹ß»ýÇß½À´Ï´Ù.");},
		success: function (xml_data) {
			$(xml_data).find("data").each(function() {
				$('#dialog_subject').html($(this).find("subject").text());
				$('#dialog_category').html($(this).find("category").text());
				$('#dialog_contents').html($(this).find("contents").text());

				var attach_files = $(this).find("attach_files");
				$('#dialog_attach_files').html('');
				if (attach_files.find('file').length == 0) 
				{
					$('#dialog_attach_files').append('Ã·ºÎÆÄÀÏ ¾øÀ½.');
				}
				else
				{
					$(attach_files).find("file").each(function() {
						$('#dialog_attach_files').append('<a href="/voc/file_viewer.php?s=' + $(this).attr("seqno") + '&gubun=D">' + $(this).text() + '</a> &nbsp; ');
					});
				}

				$('#dialog').dialog('open');
			});
		}
	});
}
