//===============================================================================================
// About image (common)
//===============================================================================================
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//===============================================================================================
// Browser Check (IE or not IE)
//===============================================================================================
var isIE = (document.all)?true:false;

//===============================================================================================
// document.all / document.getElementById => return object
//===============================================================================================
function getObj(oName){
	return isIE?document.all(oName):document.getElementById(oName);
}

function addObj(sTagName, obj){
	if(sTagName == "TR"){
		if(isIE) obj.insertRow();
		else { 
			var oTR = document.createElement(sTagName)
			obj.appendChild(oTR);
		}
	}
	else if(sTagName == "TD"){
		if(isIE) obj.insertCell();
		else {
			var oTD = document.createElement(sTagName)
			obj.appendChild(oTD);
		}
	}
}

//===============================================================================================
// Send mail (Copyright click)
//===============================================================================================
function goMailSend(){
	location.href = "mailto:rankey@rankey.com";
	return;
}

//===============================================================================================
// Show message (ready)
//===============================================================================================
function readyMsg(){
	alert("此服务尚未开通，敬请期待!");
	return;
}

//===============================================================================================
// Set left menu
//===============================================================================================
function setMenuImg(img){
	var obj = getObj(img);	
	if(!obj) return;
	//if(obj.src.indexOf("_on") < 0) obj.src = obj.src.substring(0, obj.src.length-4) + "_on" + ".gif";
	obj.src = obj.src.substring(0, obj.src.length-10) + "on" + obj.src.substring(obj.src.length-7, obj.src.length);	
	
	return;
}

//===============================================================================================
// Auth check
//===============================================================================================
function reqLogin(){
	if(lynx){		// member free : false
		alert('注册会员后可以使用此服务！');
	}
	else {
		if(arguments.length>0) arg = arguments[0]; 
		else arg = 0;

		if(arg == 1)
			alert('注册会员后可以使用此服务！');
		else
			alert('注册会员后可以使用此服务！');

		if(document.loginFrm){
			document.loginFrm.id.style.backgroundColor = "#FFFFCC";
			document.loginFrm.passwd.style.backgroundColor = "#FFFFCC";
    		document.loginFrm.id.focus();
    		return;
		}
	}
}

//=========================================================================================
// ID/PW Find
//=========================================================================================
function goSearchID(){
	var pWin = window.open("/member/search_id_pop.php", "pWin", "width=440, height=325");
	pWin.focus();
}

//===============================================================================================
// Blank check
//===============================================================================================
function isBlank(obj, msg){
	var str = obj.value.replace(/(^\s*|\s*$|\n)/g,"");

	if(str == ""){
		//alert(msg + "Please input ");
		alert(msg);
		obj.value = "";
		obj.focus();
		return true;
	}
	else {
		obj.value = str;
		return false;
	}
}

function Cn_blank_check(obj, msg){
	var str = obj.value.replace(/(^\s*|\s*$|\n)/g,"");

	if(str == ""){
		alert(msg);
		obj.value = "";
		obj.focus();
		return true;
	}
	else {
		obj.value = str;
		return false;
	}
}

//===============================================================================================
// Cut blank
//===============================================================================================
function trim(str){
	return str.replace(/(^\s*|\s*$|\n)/g,"");
}

//===============================================================================================
// Replace string
//===============================================================================================
function replaceString(oldS,newS,fullS) {
	// Replaces oldS with newS in the string fullS   
	for (var i=0; i<fullS.length; i++) {      
		if (fullS.substring(i,i+oldS.length) == oldS) {    
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
		}  
	}
	return fullS
}

//===============================================================================================
// Family site gogo
//===============================================================================================
function goFamilySite(obj){
	var nIdx = obj.options.selectedIndex;
	var sUrl = obj.value;

	if(sUrl != "") window.open(sUrl, "_blank", "");
}

//===============================================================================================
// Login check (Top)
//===============================================================================================
function loginCheck(){
	var frm = document.loginFrm;

	if(isBlank(frm.id,"id")) return;
	if(isBlank(frm.passwd,"password")) return;

	frm.action = "/member/login.php";
	frm.submit();
}

//===============================================================================================
// Search (Top)
//===============================================================================================
function goSearch(){
	var frm = document.searchFrm;

	if(isBlank(frm.search_word, "search word")) return;

	frm.action = "/search/rankey_search.php";
	frm.submit();
}

//===============================================================================================
// Site vs Site (Top flash common)
//===============================================================================================
function goFlashSiteComp(){
	var oFlash = getObj("topmenu080916");
	var nLoopCnt = arguments.length;
	var nSiteCnt = 0;
	var sParam = "";
	var bFlag = false;

	for(var i=0; i<nLoopCnt; i++){
		var tmpStr = trim(arguments[i]);

		//"www" start
		if(tmpStr.indexOf("www.") == 0){
			bFlag = true;
		}

		//Exception process
		if(tmpStr != "" && tmpStr.length > 4 && tmpStr.indexOf('.') > 0 && tmpStr != "co.cn"){
			nSiteCnt++;
			sParam+= "&site" + (i+1) + "=" + tmpStr;
		}
		else {
			oFlash.setVariable("site" + (i+1), "");
		}
	}

	if(nSiteCnt < 2) {
		alert("请输入2个以上网站域名进行比较！");
		oFlash.SetVariable("tmpVal", "1");
	}
	else if(bFlag) {
		alert("输入网址时请去掉www");
	}
	else {
		sParam = "site_cnt=" + nSiteCnt + sParam;
		location.href = "/rank/rank_site2site.php?" + sParam;
	}
}

function goTopSiteComp(nBoxCnt){
	var nSiteCnt = 0;
	var sParam = "";

	for(var i=0; i<nBoxCnt; i++){
		var obj = getObj("csite" + (i+1));
		var tmpStr = trim(obj.value);

		//"www" start
		if(tmpStr.indexOf("www.") == 0){
			alert("输入网址时请去掉www");
			obj.select();
			obj.focus();
			return;
		}

		//Exception process
		if(tmpStr != "" && tmpStr.length > 4 && tmpStr.indexOf('.') > 0 && tmpStr != "co.cn"){
			nSiteCnt++;
			sParam+= "&site" + (i+1) + "=" + tmpStr;
		}
		else obj.value = "";
	}

	if(nSiteCnt < 2){
		alert("请输入2个以上网站域名进行比较！");
		getObj("csite1").focus();
		return;
	}
	else { 
		sParam = "site_cnt=" + nSiteCnt + sParam;
		location.href = "/rank/rank_site2site.php?" + sParam;
	}
}

function goTopReset(){
	for(var i=0; i<5; i++){
		var obj = getObj("csite" + (i+1));
		obj.value = "";
	}

	getObj("csite1").focus();
}

//===============================================================================================
// Ajax Request
//===============================================================================================
var req = "";

function getAjaxRequest(sUrl, sParam){

	if(isIE) req = new ActiveXObject("Msxml2.XMLHTTP");
	else req = new XMLHttpRequest();

	if(req){
		req.onreadystatechange = setAjaxResponse;
		req.open("POST", sUrl, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(sParam);
	}
}

//===============================================================================================
// List page
//===============================================================================================
function setListPage(page){
	var nStartPage = 1;
	var nEndPage = 1;
	var sBarImage = "<img src='../images/biz/dot_pageline.gif' align='absmiddle'>";
	var sPageStr = "";
	var i = 0;

	if(page == "" || page < 1 || page > gnTotalPage) page = 1;

	//if(gnTotalPage == 0 || gnPageSize == 0) return;
	if(gnTotalPage == 0 || gnPageSize == 0) page = 0;

	nStartPage = 1 + parseInt((page-1)/gnPageSize)*gnPageSize;
	nEndPage = nStartPage + gnPageSize;
	i = nStartPage;

	if(nStartPage > 1)
		sPageStr += "<a href='javascript:goList(1);'><img src='../images/biz/icon_pre.gif' align='absmiddle' border=0></a>&nbsp;";
	else
		sPageStr += "<img src='../images/biz/icon_pre.gif' align='absmiddle'>&nbsp;";

	if(i > gnPageSize)
		sPageStr += "<a href='javascript:goList(" + (nStartPage-1) + ");'><img src='../images/biz/icon_pre01.gif' hspace='12' align='absmiddle' border=0></a>&nbsp;";
	else
		sPageStr += "<img src='../images/biz/icon_pre01.gif' hspace='12' align='absmiddle'>&nbsp;";

	while(i <= gnTotalPage){
		if(i == nStartPage){
			if(i == page)
				sPageStr += "<font class='b_slist'><b>" + i + "</b></font>";
			else
				sPageStr += "<a href='javascript:goList(" + i + ");'>" + i + "</a>";
		}
		else {
			if(i == page)
				sPageStr += sBarImage + "<font class='b_slist'><b>" + i + "</b></font>";
			else
				sPageStr += sBarImage + "<a href='javascript:goList(" + i + ");' class='slist'>" + i + "</a>";
		}

		i++;
		if(i == nEndPage) break;
	}

	if(nStartPage+gnPageSize <= gnTotalPage)
		sPageStr += "&nbsp;<a href='javascript:goList(" + eval(nStartPage+gnPageSize) + ")'><img src='../images/biz/icon_next01.gif' hspace='12' align='absmiddle' border=0></a>";
	else
		sPageStr += "&nbsp;<img src='../images/biz/icon_next01.gif' hspace='12' align='absmiddle'>";

	if(nEndPage <= gnTotalPage)
		sPageStr += "&nbsp;<a href='javascript:goList(" + gnTotalPage + ")'><img src='../images/biz/icon_next.gif' align='absmiddle' border=0></a>";
	else
		sPageStr += "&nbsp;<img src='../images/biz/icon_next.gif' align='absmiddle'>";
	
	//alert(sPageStr);
	if(getObj("oPage")){
		getObj("oPage").rows[0].cells[1].innerHTML = sPageStr;
		getObj("oPageCnt").innerHTML = gnTotalPage;
		getObj("oCount").innerHTML = gnTotalRec;
		getObj("nPage").value = page;
	}
}

//===============================================================================================
// Show / Hide graph
//===============================================================================================
var gbGraphShow = true;

function goDivShow(nValue){
	var oTable = getObj("oTable");
	if(oTable){
		var nLength = oTable.rows.length;
		if(nLength < 3){		//no graph
			alert("没有该图表！");
			return;
		}
	}

	var obj = getObj("oGraph");
	if(nValue == 1){
		obj.style.display = "";
		gbGraphShow = true;
		setCookie("oGraphView", "", 1);
	}
	else {
		obj.style.display= "none";
		gbGraphShow = false;
		setCookie("oGraphView", "none", 1);
	}
}

//===============================================================================================
// Compare graph
//===============================================================================================
function checkGraphAction(sGraphType){
	var obj = getObj("sel_period");
	var obj2 = getObj("sel_graph2");

	if(gsGraphType == sGraphType && gsGraphType.indexOf("c_in") < 0) return false;

	if(obj2 != null && obj2.selectedIndex != 0){
		if(gsGraphType.indexOf("c_in") < 0){
			gsGraphType = gsGraphType.substring(0, gsGraphType.indexOf("_")) + "c_in";
		}
		else {
			if(sGraphType != "") gsGraphType = sGraphType.substring(0, sGraphType.indexOf("_")) + "c_in";
		}
	}
	else {
		if(sGraphType != "") gsGraphType = sGraphType;
		else {
			if(gsGraphType.indexOf("c_in") > 0) gsGraphType = gsGraphType.substring(0, gsGraphType.indexOf("c_")) + "_in";
		}
	}

	if(obj != null && obj2 != null) {
		if(obj.selectedIndex == obj2.selectedIndex-1){
			alert("时间重复，请重新选择时段！");
			obj2.selectedIndex = 0;
			return false;
		}
	}

	return true;
}

//===============================================================================================
// Print graph
//===============================================================================================
function setGraphSrc(sGraphSrc, obj_nm_cnt){

	if(sGraphSrc != ""){
		var obj = getObj("oGraphSrc");
		if(obj_nm_cnt != null) obj = getObj("oGraphSrc" + obj_nm_cnt);
		if(obj) obj.innerHTML = sGraphSrc;
		if(gbGraphShow) {
			if(obj_nm_cnt == null) getObj("oGraph").style.display = "";
			if(obj_nm_cnt != null) getObj("oGraph" + obj_nm_cnt).style.display = "";
			obj.style.display = "";
		}
	}
	else {
		//alert("No graph data!");
		getObj("oGraph").style.display = "none";
	}
}

//===============================================================================================
// List order
//===============================================================================================
function setOrderText(nFieldIndex, nExCnt){
	var oTr = "";

	if(getObj("oList2")){
		var oSelKind = getObj("sel_kind");
		if(obj.selectedIndex == 0) oTr = getObj("oList");
		else oTr = getObj("oList2");
	}
	else oTr = getObj("oList");

	var oSort = oTr.cells[nFieldIndex-1].childNodes(0);
	var nLen = oTr.cells.length;
	var sText = oSort.innerHTML;

	for(var i=0; i<nLen-nExCnt; i++){
		oTr.cells[i].childNodes(0).className = "bbs_title";
	}

	if(gsOrderType == "asc") sText = sText.replace('▼', '▲');
	else sText = sText.replace('▲', '▼');

	oSort.className = "orange";
	oSort.innerHTML = sText;
}

//===============================================================================================
// Move page (Ranking zone)
//===============================================================================================
function goRankPage(){
	var arg = arguments[0];
	var nTarget = arguments[1];
	var oPeriod = getObj("sel_period");
	var oCate1 = getObj("sel_cate1");
	var oCate2 = getObj("sel_cate2");
	var oCate3 = getObj("sel_cate3");
	var sPeriod = "";
	var sCat1_ID = "";
	var sCat2_ID = "";
	var sCat3_ID = "";

	if(oPeriod) sPeriod = oPeriod.value;
	if(oCate1) sCat1_ID = oCate1.value;
	if(oCate2) sCat2_ID = oCate2.value;
	if(oCate3) sCat3_ID = oCate3.value;

	switch(arg){
		case 0:
			if(nTarget == 1){
				location.href = "./rank_cate3_info.php?cat1_id=" + arguments[2] + "&cat2_id=" + arguments[3];
			}
			else if(nTarget == 2){
				location.href = "./rank_site_cate.php?cat1_id=" + arguments[2] + "&cat2_id=" + arguments[3];
			}
			break;

		case 1:
			if(nTarget == 1){
				location.href = "./rank_cate1_trend.php?cat1_id=" + arguments[2];
			}
			if(nTarget == 2){
				location.href = "./rank_cate2_info.php?cat1_id=" + arguments[2];
			}
			else if(nTarget == 3){
				location.href = "./rank_cate1_info.php";
			}
			else if(nTarget == 4){
				location.href = "./rank_cate2_info.php?cat1_id=" + sCat1_ID + "&sel_period=" + arguments[2];
			}
			break;

		case 2:	
			if(nTarget == 1){
				location.href = "./rank_cate1_trend.php?cat1_id=" + sCat1_ID;
			}
			else if(nTarget == 2){
				location.href = "./rank_cate3_info.php?cat1_id=" + sCat1_ID + "&cat2_id=" + arguments[2];
			}
			else if(nTarget == 3){
				location.href = "./rank_cate2_trend.php?cat1_id=" + sCat1_ID + "&cat2_id=" + arguments[2];
			}
			else if(nTarget == 4){
				location.href = "./rank_cate2_info.php?cat1_id=" + sCat1_ID + "&sel_period=" + arguments[2];
			}
			else if(nTarget == 5){
				location.href = "./rank_cate3_info.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID + "&sel_period="+arguments[2];
			}
			else if(nTarget == 6){
				location.href = "./rank_site_cate.php?cat1_id=" + sCat1_ID + "&cat2_id=" + arguments[2];
			}
			else if(nTarget == 7){
				location.href = "./rank_site_cate.php?cat1_id=" + sCat1_ID;
			}
			break;

		case 3:
			if(nTarget == 1){
				location.href = "./rank_cate2_trend.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID;
			}
			else if(nTarget == 2){
				location.href = "./rank_cate3_trend.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID + "&cat3_id=" + arguments[2];
			}
			else if(nTarget == 3){
				location.href = "./rank_site_cate.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID + "&cat3_id=" + arguments[2];
			}
			else if(nTarget == 4){
				location.href = "./rank_cate3_info.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID;
			}
			else if(nTarget == 5){
				if(sCat3_ID == ""){
					alert("请选择小分类！");
					return;
				}
				location.href = "./rank_site_cate.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID + "&cat3_id=" + sCat3_ID + "&sel_period=" + arguments[2];
			}
			else if(nTarget == 6){
				location.href = "./rank_site_cate.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID;
			}
			break;

		case 4:
			var oSponsor = getObj("oSponsor");
			var oRankFrom = getObj("rank_from");
			var oRankTo = getObj("rank_to");
			var oPeriod = getObj("sel_period");
			var sParam = "";

			if(oRankFrom)
				sParam = "&rank_from="+oRankFrom.value+"&rank_to="+oRankTo.value+"&where=1&period="+oPeriod.value+"&page="+gnPage;
			else if(oSponsor)
				sParam = "&where=2&period="+sPeriod+"&page="+gnPage;

			//location.href = "./rank_site_detail.php?grp_id=" + arguments[1] + "&cat_id=" + arguments[2] + sParam;
			window.open("./rank_site_detail.php?grp_id=" + arguments[1] + "&cat_id=" + arguments[2] + sParam);
			return;
			break;

		case 5:
			if(nTarget == 1){
				location.href = "./rank_cate3_info.php?cat1_id=" + sCat1_ID + "&cat2_id=" + sCat2_ID;
			}
			else if(nTarget == 2){
				location.href = "./rank_site_cate.php?cat1_id=" + arguments[2] + "&cat2_id=" + arguments[3] + "&cat3_id=" + arguments[4];
			}
			break;

		case 6:
			if(nTarget == 1){
				location.href = "./rank_cate2_trend.php?cat1_id=" + arguments[2] + "&cat2_id=" + arguments[3];
			}
			else if(nTarget == 2){
				location.href = "./rank_cate3_trend.php?cat1_id=" + arguments[2] + "&cat2_id=" + arguments[3] + "&cat3_id=" + arguments[4];
			}
			break;


		default: break;
	}

	goWaiting(1);
}

//===============================================================================================
// Ajax processing bar show/hide (modified by yjpark in 20081111)
//===============================================================================================
function goWaiting(arg){
	var oIng = getObj("oProgress");
	var nLen = arguments.length;

	if(arg == 2){
		oIng.style.visibility = "hidden";
		return;
	}

	if(nLen > 1){
		var sName = arguments[1];
		if(sName != "Mouse"){
			var obj = getObj(arguments[1]);
			oIng.style.left = getXPos(obj) + 250 + "px";
			oIng.style.top = getYPos(obj) - 30 + "px";
		}
		else {
			oIng.style.left = isIE?event.clientX:e.pageX + document.documentElement.scrollLeft - 70 + "px";
			oIng.style.top = isIE?event.clientY:e.pageY + document.documentElement.scrollTop + 20 + "px";
		}
	}
	else {
		var obj = getObj("oMsg");

		oIng.style.left = getXPos(obj) + 250 + "px";
		oIng.style.top = getYPos(obj) - 25 + "px";
	}

	oIng.style.visibility = "visible";
}

function getXPos(obj){
	if(obj.offsetParent == document.body) return obj.offsetLeft;
	else return obj.offsetLeft + getXPos(obj.offsetParent);
}

function getYPos(obj){
	if(obj.offsetParent == document.body) return obj.offsetTop;
	else return obj.offsetTop + getYPos(obj.offsetParent);
}

//===============================================================================================
// Show rank up/down (Layer - added by yjpark in 2008.11.19)
//===============================================================================================
function showRankUd() {
	var event = arguments[0] || window.event;
	var arg = arguments[1];
	var obj = getObj("oRankUd");
	var obj2 = getObj("oRankVal");
	var xPos = event.clientX || event.pageX;
	var yPos = event.clientY || event.pageY;

	obj.style.left = xPos + document.documentElement.scrollLeft - 25 + "px";
	obj.style.top = yPos + document.documentElement.scrollTop - 30 + "px";

	if(arg == 0){
		obj2.innerHTML = "";
		obj.style.visibility = "hidden";
	}
	else if(arg == 1){
		//obj2.className = "tablered2";
		obj2.innerHTML = "<img src='/images/common/bul_05.gif' align=absmiddle> " + arguments[2];
		obj.style.visibility = "visible";
	}
	else if(arg == 2){
		//obj2.className = "tableblue2";
		obj2.innerHTML = "<img src='/images/common/bul_06.gif' align=absmiddle> " + arguments[2];
		obj.style.visibility = "visible";
	}
}

//===============================================================================================
// Set select tag
//===============================================================================================
function setSelData(){			//arg => 1: Rank(M3/M/W), 2~4: Category
	var arg = parseInt(arguments[0]);

	if(arg == 1){
		var arrData = arguments[1];
		var obj = getObj("sel_period");
		var obj2 = getObj("sel_graph2");
		var nIdx = getObj("sel_rank").options.selectedIndex;
		var sPeriod = obj.options[obj.selectedIndex].value;
		obj.length = 0;
		if(obj2) obj2.length = 1;
		if(getObj("sel_rank").length == 2) nIdx++;
		if(sPeriod.length == 6) sPeriod = sPeriod + "01";

		if(nIdx == 0){			//M3 rank
			for(var i=0; i<arrData.length; i++){
				obj.length++;
				obj.options[i].text = arrData[i].ymd;
				obj.options[i].value = arrData[i].week;
	
				if(obj2){
					obj2.length++;
					obj2.options[i+1].text = obj.options[i].text;
					obj2.options[i+1].value = obj.options[i].value;
				}

				if(sPeriod == arrData[i].week) obj.selectedIndex = i;
			}
		}
		else if(nIdx == 1){		//Weekly rank
			for(var i=0; i<arrData.length; i++){
				obj.length++;
				sWeek=arrData[i].week.substring(0,4)+"年"+arrData[i].week.substring(4,6)+"月" +arrData[i].week.substring(6)+"周";
				obj.options[i].text = sWeek + "(" + arrData[i].date_from + "~" + arrData[i].date_to + ")";
				obj.options[i].value = arrData[i].week;

				if(obj2){
					obj2.length++;
					obj2.options[i+1].text = obj.options[i].text;
					obj2.options[i+1].value = obj.options[i].value;
				}

				if(sPeriod == arrData[i].week) obj.selectedIndex = i;
			}
		}
		else if(nIdx == 2){		//Monthly rank
			for(var i=0; i<arrData.length; i++){
				obj.length++;
				obj.options[i].text = arrData[i].year + "年 " + arrData[i].month +"月";
				obj.options[i].value = arrData[i].year + arrData[i].month;
	
				if(obj2){
					obj2.length++;
					obj2.options[i+1].text = obj.options[i].text;
					obj2.options[i+1].value = obj.options[i].value;
				}

				if(sPeriod.substring(0, 6) == obj.options[i].value) obj.selectedIndex = i;
			}
		}

		goList(gnPage);
	}
	else if(arg == 2){
		var arrCate2 = arguments[1];
		var obj = getObj("sel_cate2");
		obj.length = 1;

		//2nd Category
		for(var i=1; i<arrCate2.length+1; i++){
			obj.length++;
			obj.options[i].text = arrCate2[i-1].cat_name;
			obj.options[i].value = arrCate2[i-1].cat_id;
		}
	}
	else if(arg == 3){
		var arrCate2 = arguments[1];
		var arrCate3 = arguments[2];
		var obj2 = getObj("sel_cate2");
		var obj3 = getObj("sel_cate3");

		//2nd Category
		if(arrCate2 != ""){
			obj2.length = 0;

			for(var i=0; i<arrCate2.length; i++){
				obj2.length++;
				obj2.options[i].text = arrCate2[i].cat_name;
				obj2.options[i].value = arrCate2[i].cat_id;
			}
		}

		//3rd Category
		if(arrCate3 != ""){
			obj3.length = 1;

			for(var i=1; i<arrCate3.length+1; i++){
				obj3.length++;
				obj3.options[i].text = arrCate3[i-1].cat_name;
				obj3.options[i].value = arrCate3[i-1].cat_id;
			}
		}
	}
	else if(arg == 4){
		var arrCate2 = arguments[1];
		var arrCate3 = arguments[2];
		var obj = getObj("sel_cate1");
		var obj2 = getObj("sel_cate2");
		var obj3 = getObj("sel_cate3");

		//2nd Category
		if(arrCate2 != ""){
			obj2.length = 1;

			for(var i=1; i<arrCate2.length+1; i++){
				obj2.length++;
				obj2.options[i].text = arrCate2[i-1].cat_name;
				obj2.options[i].value = arrCate2[i-1].cat_id;
			}
		}

		//3rd Category
		if(obj2.value != "" && arrCate3 != ""){
			obj3.length = 1;

			for(var i=1; i<arrCate3.length+1; i++){
				obj3.length++;
				obj3.options[i].text = arrCate3[i-1].cat_name;
				obj3.options[i].value = arrCate3[i-1].cat_id;

				if(arrCate3[i-1].cat_id == gsCat3_ID){
					obj3.options.selectedIndex = i;
				}
			}
		}
		else obj3.length = 1;

		if(getObj("sel_graph1")) goList(gnPage);
	}
	else if(arg == 5){
		var arrCate2 = arguments[1];
		var arrCate3 = arguments[2];
		var obj = getObj("sel_cate1");
		var obj2 = getObj("sel_cate2");
		var obj3 = getObj("sel_cate3");

		//2nd Category
		if(arrCate2 != ""){
			obj2.length = 1;

			for(var i=1; i<arrCate2.length+1; i++){
				obj2.length++;
				obj2.options[i].text = arrCate2[i-1].cat_name;
				obj2.options[i].value = arrCate2[i-1].cat_id;
			}
		}

		//3rd Category
		if(obj2.value != ""){
			obj3.length = 0;

			for(var i=0; i<arrCate3.length; i++){
				obj3.length++;
				obj3.options[i].text = arrCate3[i].cat_name;
				obj3.options[i].value = arrCate3[i].cat_id;
			}
		}
	}
}

//===============================================================================================
// Dynamic message & title display
//===============================================================================================
function showMsg(){
	var oPeriod = getObj("sel_period");
	var oRank = getObj("sel_rank");
    var oCate1 = getObj("sel_cate1");
	var oCate2 = getObj("sel_cate2");
	var oCate3 = getObj("sel_cate3");
	var oCateName = getObj("oCateName");
	var oMsg = getObj("oMsg");
	var sCat1_ID = "";
	var sCat2_ID = "";
	var sCat3_ID = "";
	var sPeriod = "";
	var sRank = "";

	if(oPeriod) oMsg.innerHTML = oPeriod.options[oPeriod.selectedIndex].text + " " + oRank.options[oRank.selectedIndex].text;
	else oMsg.innerHTML = oRank.options[oRank.selectedIndex].text;

	//Set title (Category)
	if(oCate1 && oCateName){
		sCat1_ID = oCate1.value;

		if(oCate2) sCat2_ID = oCate2.value;
		if(oCate3) sCat3_ID = oCate3.value;

		if(sCat3_ID != "") oCateName.innerHTML = oCate3.options[oCate3.options.selectedIndex].text;
		else if(sCat2_ID != "") oCateName.innerHTML = oCate2.options[oCate2.options.selectedIndex].text;
		else oCateName.innerHTML = oCate1.options[oCate1.options.selectedIndex].text;
	}

	//Set image
	if(gbGraphOnly){
		if(gsGraphType == "line2"){           //Line Graph
			getObj("img_line").src = "/images/common/icon_graph01on.gif";
			getObj("img_vbar").src = "/images/common/icon_graph02.gif";
			getObj("img_hbar").src = "/images/common/icon_graph03.gif";
		}
		else if(gsGraphType == "vbar2"){      //Vertical Graph
			getObj("img_line").src = "/images/common/icon_graph01.gif";
			getObj("img_vbar").src = "/images/common/icon_graph02on.gif";
			getObj("img_hbar").src = "/images/common/icon_graph03.gif";
		}
		else if(gsGraphType == "hbar2"){      //Horizontal Graph
			getObj("img_line").src = "/images/common/icon_graph01.gif";
			getObj("img_vbar").src = "/images/common/icon_graph02.gif";
			getObj("img_hbar").src = "/images/common/icon_graph03on.gif";
		}
	}

	self.focus();
}

//===============================================================================================
// Print data (Excel, Email, Print - Ranking zone)
//===============================================================================================
function getDataOutput(arg, sParam, sUrl){
	var obj1 = getObj("sel_cate1");
	var obj2 = getObj("sel_cate2");
	var obj3 = getObj("sel_cate3");

	if(sUrl != "rank_focus_top5.php"){
		if(obj1) sParam+= "&bcat_nm=" + encodeURIComponent(obj1.options[obj1.options.selectedIndex].text);
		if(obj2) sParam+= "&mcat_nm=" + encodeURIComponent(obj2.options[obj2.options.selectedIndex].text);
		if(obj3) sParam+= "&cat_nm=" + encodeURIComponent(obj3.options[obj3.options.selectedIndex].text);
	}

	if(arg == 1){
		//pWin1 = window.open("/rank/excel/excel_" + sUrl + "?" + sParam, "pWin1", "width=700, height=800, scrollbars=1");
		location.href = "./excel/excel_" + sUrl + "?" + sParam;
	}
	else if(arg == 2){
		sParam+= "&url=" + sUrl;
		pWin2 = window.open("./mail/mail_rank_send_form.php?"+sParam, "pWin2", "width=462, height=356, left=30, top=5");
	}
	else if(arg == 3){
		pWin3 = window.open("./print/print_" + sUrl + "?" + sParam, "pWin3", "width=700, height=800, scrollbars=1");
	}
}

//===============================================================================================
// Window status (delete)
//===============================================================================================
function dStatus(){
	window.status = "";
	return true;
}

//===============================================================================================
// Keyboard Input Check
//===============================================================================================
function keyCheck(e, arg){
	var event = e || window.event;
	var iKey = event.keyCode;

	if(arg == 1){
		if( (47 < iKey && iKey < 58) || (95 < iKey && iKey < 106) || iKey == 8 || iKey == 9 
						|| iKey == 37 || iKey == 39 || iKey == 46)
			event.returnValue = true;
		else {
			if(isIE) event.returnValue = false;
			else event.preventDefault();
		}
	}
	else if(arg == 2){
		if( (47 < iKey && iKey < 58) || (95 < iKey && iKey < 106) || iKey == 8 || iKey == 9 
						|| iKey == 37 || iKey == 39 || iKey == 46 || iKey == 190)
			event.returnValue = true;
		else
			event.returnValue = false;
	}
	else if(arg == 3){
		if( (47 < iKey && iKey < 58) || (95 < iKey && iKey < 106) || iKey == 8 || iKey == 9 
						|| iKey == 37 || iKey == 39 || iKey == 46 || iKey == 189)
			event.returnValue = true;
		else
			event.returnValue = false;
	}
}

//===============================================================================================
// Cookie Setting
//===============================================================================================
function setCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}


//===============================================================================================
// Data Zone - Help View
//===============================================================================================
function view_title(obj, view_type) {
	var obj = getObj(obj);
	if(obj){
		if(obj.style.height.indexOf("px") > 0)
			nDivHeight = obj.style.height.substring(0, obj.style.height.indexOf("px"));
		else
			nDivHeight = 130;

		obj.style.left = event.clientX + document.documentElement.scrollLeft;
		obj.style.top = event.clientY + document.documentElement.scrollTop - (nDivHeight-50);
		obj.style.display = view_type;
	}
}
