/**
 *	@mainpage	´º½º¼½¼Ç °øÅë ½ºÅ©¸³Æ®
 *
 *	@brief		´º½º¼½¼Ç °øÅë ½ºÅ©¸³Æ®
 *
 *
 *	@author		(ÁÖ)´Ù³ª¿Í °³¹ßÆÀ ³²¹Ì°æ
 *	@date		2008³â 07¿ù 01ÀÏ (È­)
 *	@file		news_common.js
 *
 *	@section	maintenance		¼öÁ¤ ³»¿ª
 *	2010³â 07¿ù 14ÀÏ (¼ö¿äÀÏ)
 *	 - ´º½º ºä ÆäÀÌÁö ·Îµù ¼Óµµ °³¼±À» À§ÇÑ ÀÛ¾÷ jQuery (ÀÌ½Â¿¬)
 *
 */
document.domain	='danawa.com';
var domain_img	= "http://img.danawa.com";
var domain_bbs	= "http://bbs.danawa.com";
var domain_blog = "http://blog.danawa.com";
var gPvspSubmit = false;	//Áßº¹ ¼­ºê¹Ô ¹æÁö

// ¿¡·¯ Ãâ·Â
function rpError() {
	alert("Á¤»óÀûÀ¸·Î Ã³¸®µÇÁö ¾Ê¾Ò½À´Ï´Ù.");
}//end function rpError()

// ÆäÀÌÁö ÀüÈ¯
function setNewsGoLink(cUrl) {
	top.location.href=cUrl;
}//end function setNewsGoLink(nUrl)

// ÆË¾÷Ã¢ ¶ç¿ì±â
function setNewsGoPopupLink(nWidth,nHeight,nPosx,nPosy,cScroll,cUrl) {
	nPosition = "width="+nWidth+",height="+nHeight+",scrollbars="+cScroll+",resizable=no,top="+nPosx+",left="+nPosy;
	window.open(cUrl,'GoPopupLink',nPosition);
}//end function setNewsGoPopupLink(nWidth,nHeight,nPosx,nPosy,cScroll,cUrl)

// ÀÌ¹ÌÁö ¾øÀ»½Ã noimg °¡Á®¿À±â
function setNewsNoImage(img,size) {
	var args = setNewsNoImage.arguments;

	switch (size) {
		case 50 : var altImg = domain_img + '/new/dalgi/common/noimg_50.gif'; break;
		case 75 : var altImg = domain_img + '/new/dalgi/common/noimg_75.gif'; break;
		case 80 : var altImg = domain_img + '/new/dalgi/common/noimg_80.gif'; break;
	}//end switch

	if (args[0].src == altImg) {
		args[0].onerror = null;
	} else {
		var imgWidth = args[1] ? args[1] : size;
		var imgHeight = args[2] ? args[2] : size;
		args[0].src = altImg;
		args[0].width = imgWidth;
		args[0].height = imgHeight;
	}//end if
}//end function setNewsNoImage(img,size)

// ¼¼ºÎ Ä«Å×°í¸® º¸±â
function setNewsCateList(nDpLayer, nDpLayer2, nCnt) {

	var obj		= document.getElementById(nDpLayer+nCnt);
	var objClass= document.getElementById(nDpLayer2+nCnt);
	if(obj.style.display == "none") {
		obj.style.display	= "block";
		objClass.className	= "cate1_on";
	}else{
		obj.style.display	= "none";
		objClass.className	= "cate1";
	}//end if
}//end function setNewsCateList(nDpLayer, nDpLayer2, nCnt)

// ¹®È­.»ýÈ°.ÆÐ¼Ç Ä«Å×°í¸® ³ëÃâ
function setNewsCateList_10(nDpLayer) {
	var obj	= document.getElementById(nDpLayer);
	obj.className = "cate1_on";
}//end function setNewsCateList_10(nModeC, nCate1, nDpLayer)

// °ü·Ã »óÇ° º¸±â(ºä ÆäÀÌÁö)
function getNewsViewProdList(nSeq, nSize, nType, nMultiC, nDpLayer) {
	var url		= "/News_List_RelProd_ajax.php";
	var pars	= "nSeq="+nSeq+"&nSize="+nSize+"&nType="+nType+"&nMultiC="+nMultiC+"&nProtoType=Y";

	var myAjax = new Ajax.Updater(
				{success: nDpLayer},
				url,
				{
					method: 'post',
					parameters: pars,
					onFailure: function() {
						alert("°ü·Ã»óÇ°À» ºÒ·¯¿ÀÁö ¸øÇß½À´Ï´Ù.");
					}//end function
				});
}//end function getNewsViewProdList(nSeq, nSize, nType, nMultiC, nDpLayer)

// °ü·Ã »óÇ° º¸±â(ºä ÆäÀÌÁö)
function getNewsViewProdListJQuery(nSeq, nSize, nType, nMultiC, nDpLayer) {
	$.post(
		"/News_List_RelProd_ajax.php",
		{"nSeq":nSeq, "nSize":nSize, "nType":nType, "nMultiC":nMultiC},
		function(data) {
			$("#"+nDpLayer).html(data);
		}
	);
}//end function getNewsViewProdList(nSeq, nSize, nType, nMultiC, nDpLayer)

// °ü·Ã ºê·£µå ºí·Î±×(ºä ÆäÀÌÁö)
function getNewsViewBrandBlog(nSeq,nBoardSeq,nSize,nDpLayer) {
	$.ajax({
		type: "POST",
		url : "/News_List_Brand_ajax.php",
		error : function () { alert("°ü·Ãºê·£µå ºí·Î±×¸¦ ºÒ·¯¿ÀÁö ¸øÇß½À´Ï´Ù.") } ,
		data : "nSeq="+nSeq+"&nBoardSeq="+nBoardSeq+"&nSize="+nSize,
		success : function (data) {$("#" + nDpLayer).html(data);}
	});
}//end function getNewsViewBrandBlog(nSeq, nSize, nDpLayer)

// ´ë°á¸ÂÂ¯ º¸±â(ºä ÆäÀÌÁö)
function getNewsViewPvspList(nSeq, nPvspSeq, nSize, nDpLayer) {
	$.ajax({
		type: "POST",
		url : "/News_List_Pvsp_ajax.php",
		data : "nSeq="+nSeq+"&nPvspSeq="+nPvspSeq+"&nSize="+nSize ,
		error : function () { alert("´ë°á¸ÂÂ¯À» ºÒ·¯¿ÀÁö ¸øÇß½À´Ï´Ù.") },
		success : function (data) {$("#" + nDpLayer).html(data);}
	});
}//end function getNewsViewPvspList(nSeq, nPvspSeq, nSize, nDpLayer)

// ´ë°á¸ÂÂ¯ ÅõÇ¥Ã³¸®
function getNewsPvsp(nFrm,nFld,nPvspSeq) {
	if(gPvspSubmit == true) {
		alert("ÅõÇ¥ ¿äÃ»ÀÌ ÁøÇàÁßÀÔ´Ï´Ù Àá½Ã ±â´Ù·Á ÁÖ¼¼¿ä!");
	}else{
		var nDescCode	= "" ;
		var obj			= eval("document.forms['"+nFrm+"']."+nFld);
	//	var objDesc		= document.getElementById('sComment');
	//	var nDescM		= encodeURIComponent(objDesc.value);

		for(var i=0; i<obj.length; i++) {
			if(obj[i].checked == true) {
				nDescCode = obj[i].value;
			}//end if
		}//end for

		// Á¦ÇÑ Ã³¸®
		if(!nDescCode) {
			alert('ÅõÇ¥Ç×¸ñÀ» ¼±ÅÃÇÏ¼¼¿ä');
			return;
		}//end if

		gPvspSubmit = true;

		$.ajax({
			type: "POST",
			url : "/News_List_PvspVote_ajax.php",
			data : "nPvspSeq="+nPvspSeq+"&nDescCode="+nDescCode,
			dataType : "text",
			error : function () { alert('ÅõÇ¥¿¡ ½ÇÆÐÇß½À´Ï´Ù.'); },
			success : function (data) { setMovePoll(data);}
		});
	}//end if
}//end function getNewsPvsp(nFrm,nFld,nPvspSeq)

// pvsp/js_pvsp.js
function setMovePoll(nRequest) {
	gPvspSubmit = false;

	var nState = nRequest.split("|");

	switch(nState[0]) {
		case "noLogin":
			alert("·Î±×ÀÎÈÄ Âü¿©ÇÏ¼¼¿ä.");
		break;

		case "inPvsp":
			alert("ÀÌ¹Ì Âü¿© ÇÏ¼Ì½À´Ï´Ù.");
		break;

		case "notTerm":
			alert("Âü¿© ±â°£ÀÌ ¾Æ´Õ´Ï´Ù.");
		break;

	/*	case "notCom":
			alert("¼­¹ö ¹®Á¦·Î ÀÎÇÏ¿© ÀúÀå µÇÁö ¾Ê¾Ò½À´Ï´Ù.");
		break;
	*/
		case "ok":
			location.href = nState[1];
		break;

		case "serverRepaire":
		case "serverError":
			alert("½Ã½ºÅÛ Á¡°ËÁßÀÔ´Ï´Ù.");
		break;

		default :
			alert("Á¤»óÀûÀÎ Âü¿© ¹æ¹ýÀÌ ¾Æ´Õ´Ï´Ù.");
		break;
	}//end switch
}//end function setMovePoll(nRequest)

/**
 *	ÅÂ±×°¡ µé¾î ÀÖ´ÂÁö È®ÀÎÇÏ±â
 *	@param	sDirtyHtml Ã¼Å©ÇÒ ¹®ÀÚ¿­
 *	@return int °á°ú°ª (-1:¾øÀ½,0ÀÌ»ó:Á¸Àç)
 */
function getExistTag(sDirtyHtml) {
	return sDirtyHtml.search(/<[^>]+>/g);
}

// ¸®½ºÆ® °Ë»ö
function searchNewsList(nUrl) {
	var sSearchUrl	= nUrl;
	var sLikeKey	= document.frmNewsSearch.sLikeKey.options[document.frmNewsSearch.sLikeKey.selectedIndex].value;
	var sLikeValue	= document.frmNewsSearch.sLikeValue.value;

	if (getExistTag(sLikeValue) != -1) {
		alert('ÅÂ±×¸¦ Á¦¿ÜÇÑ °Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä!');
		document.frmNewsSearch.sLikeValue.value='';
		document.frmNewsSearch.sLikeValue.focus();
		return false;
	} else if(sLikeValue=='') {
		alert('°Ë»ö¾î¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		document.frmNewsSearch.sLikeValue.value='';
		document.frmNewsSearch.sLikeValue.focus();
		return false;
	}//end if

	document.frmNewsSearch.submit();
}//end function searchNewsList(nUrl)

// TV ¸®½ºÆ® °Ë»ö
function searchNewsTvList(nUrl) {
	var sSearchUrl	= nUrl;
	var sLikeKey	= document.frmNewsSearch.sLikeKey.options[document.frmNewsSearch.sLikeKey.selectedIndex].value;
	var sLikeValue	= document.frmNewsSearch.sLikeValue.value;

	if(sLikeValue=='') {
		alert('°Ë»ö¾î¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		document.frmNewsSearch.sLikeValue.value='';
		document.frmNewsSearch.sLikeValue.focus();
		return false;
	}else{
		if(sLikeValue.length < 3) {
			alert('3ÀÚ ÀÌ»ó ÀÔ·Â ÇÏ¼¼¿ä');
			return false;
		}
	}//end if

	sSearchUrl = sSearchUrl + '&sLikeKey=' + sLikeKey;
	sSearchUrl = sSearchUrl + '&sLikeValue=' + sLikeValue;
	document.location.href = sSearchUrl;
}//end function searchNewsTvList(nUrl)

// ÀÌ¹ÌÁö ÆË¾÷Ã¢
function open_Img(src) {
	var imgContents = document.getElementsByName('image_content');

	for (i = 0; i < imgContents.length; i++) {
		var img = new Image();
		img.src = imgContents[i].src

		if(imgContents[i].src == src && img.width>660) {
			window.open(src);
		}//end if
	}//end for
}//end function open_Img(src)

// ³» ºí·Î±×¿¡ ´ã±â
function MyBlog_Scrap(LoginCk,nMemSeq,nScrap,nSeq,nBlogCateSeq1) {
	if(nScrap == "Y") {
		if(LoginCk > 0)	{
				if(nMemSeq == LoginCk) {
					alert("º»ÀÎÀÌ ÀÛ¼ºÇÑ ±ÛÀº ½ºÅ©·¦ ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
				} else {
					window.open(domain_blog+'/archive/form_scrap.php?nListSeq='+nSeq+'&nBlogCateSeq1='+nBlogCateSeq1+'&nScrapSeq='+nSeq,'scrap_pop','width=400, height=350');
				} //end if
		} else {
			alert("½ºÅ©·¦À» ÇÏ·Á¸é ¸ÕÀú ·Î±×ÀÎ ÇÏ¼Å¾ß ÇÕ´Ï´Ù.");
		}//end if
	} else {
		alert("½ºÅ©·¦ÀÌ Çã¿ëµÇÁö ¾ÊÀº ±Û ÀÔ´Ï´Ù.");
	}//end if
}//end function MyBlog_Scrap(LoginCk,nMemSeq,nScrap,nSeq,nGroup,nBlogCateSeq1)

// ±â»ç ÆÛ°¡±â
function getTvListCopy(nListSeq) {
	 document.getElementById('ListDescCopy').src = domain_bbs+'/view_ajax.php?nSeq=' +nListSeq;
}//end function getListCopy(nSeq)

// °³ÀÎ Á¤º¸Ã¢
function ViewUserInfo(sid,nNick,nMemSeq) {
	var width	= 300;
	var height	= 200;
	var posx	= 100;
	var posy	= 100;
	position = "width="+width+",height="+height+",scrollbars=no,resizable=no,top="+posy+",left="+posx;
    window.open(domain_bbs + '/pop_user_info.php?sId='+sid+'&sNickname='+nNick+'&nMebSeq='+nMemSeq,'pop_link', position);
}//end function ViewUserInfo(sid,nNick,nMemSeq)

// Ã¼Å© ¹Ú½º (¸®½ºÆ® ÆäÀÌÁö)
function getCheckSubMenu(nUrl) {
	var xi=0;
	var objChkBox	= document.frmCheckSubMenu.elements['aCheck[]'];
	var nChkBoxCnt	= objChkBox.length;
	var sCheck		= "";

	for(nLoop=0; nLoop < nChkBoxCnt; nLoop++) {
		if(objChkBox[nLoop].checked == true) {
			if(xi == 0) {
				sCheck = objChkBox[nLoop].value;
			} else {
				sCheck = sCheck + "_" + objChkBox[nLoop].value;
			}//end if

			xi++;
		}//end if
	}//end if
	if (sCheck != "") {
		document.location.href = nUrl + '&sCheck=' + sCheck;
	} else {
		document.location.href = nUrl;
	}//end if
}//end function getCheckSubMenu(nUrl)

// ¾Æ¹ÙÅ¸ ÀÌ¹ÌÁö Ãà¼Ò
function getAvatarImg() {
	var imgsAvatar = document.getElementsByName('image_sAvatar');
	for (i = 0; i < imgsAvatar.length; i++) {
			var img = new Image();
			img.src = imgsAvatar[i].src

			if(img.width > 45) {
				imgsAvatar[i].height = parseInt((img.height*45)/img.width); imgsAvatar[i].width=45;
			}else if(img.height > 45) {
				imgsAvatar[i].width = parseInt((img.width*45)/img.height); imgsAvatar[i].height=45;
			}//end if
	}//end for
}//end function setAvatarImg()

// ´º½º ¼½¼Ç ³»¿ë º¸±â (Å¸ÀÌÆ²¿¡ µû¸¥ ³»¿ë º¯°æ)
function newsViewContents(nPage, nTotalPage, sDivId) {
	var oContents;
	var nBottomDivNum;
	var aNewsTitleTab;

	for (var i=0; i < (nTotalPage*2) ; i++) {
		aNewsTitleTab = document.getElementById(sDivId+i);

		if (window.attachEvent) { // IE
			aNewsTitleSpan = aNewsTitleTab.children.tags('SPAN');
		} else { // FF
			aNewsTitleSpan = aNewsTitleTab.children;
		}//end if

		if (i == nPage || (i%nTotalPage) == nPage) {
			aNewsTitleTab.className = aNewsTitleTab.className.replace("tabout" , "tabon");
		} else {
			aNewsTitleTab.className = aNewsTitleTab.className.replace("tabon" , "tabout");
		}//end if

		for(var j=0; j < aNewsTitleSpan.length; j++) {
			if (i == nPage || (i%nTotalPage) == nPage) {
				aNewsTitleSpan[j].className = aNewsTitleSpan[j].className.replace("tabout" , "tabon");
			} else {
				aNewsTitleSpan[j].className = aNewsTitleSpan[j].className.replace("tabon" , "tabout");
			}//end if
		}//end if
	}//end for

	for (var i = 0; i < nTotalPage; i++) {
		oContents = document.getElementById('divArticleContents' + (i+1));
		if (nPage != i) {
			oContents.style.display = 'none';
		} else {
			oContents.style.display = 'block';
		}//end if
	}//end for
}//end function
