﻿// ============================ Start :: Cookie 관련 함수 =============================
function delCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function setCookie (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1) endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
// ============================ End :: Cookie 관련 함수 =============================

// ============================ Start :: Font 관련 함수 =============================
var article_fontSize = parseInt(getCookie("article_fontSize"));		 

function initFont() { 
	if ( (article_fontSize < 10) || (article_fontSize > 18) || (isNaN(article_fontSize) == true)) {
		article_fontSize = 10;	  
	}						
	setFont(article_fontSize);
}

function setFont(article_fontSize) {		 
	document.getElementById("newsContent").style.fontSize = article_fontSize+"pt";  

	setFontCookie(article_fontSize);
}	

function setFontCookie(article_fontSize) {
	var expiry = new Date();
	var path = "/";
	var domain = ".einmong.com";  // 다음 스크립트를 사용할 도메인에 맞게 사용해야 합니다.
	var secure = "";

	expiry.setTime(expiry.getTime() + 90 * (24 * 60 * 60 * 1000));
	setCookie("article_fontSize",article_fontSize,expiry,path,domain,secure);
}	

function fontPlus() {		
	if (article_fontSize < 17) {  
		article_fontSize = article_fontSize + 1; 
		setFont(article_fontSize); 
	}
}

function fontMinus() {
	if (article_fontSize > 10) { 
		article_fontSize = article_fontSize - 1; 
		setFont(article_fontSize); 
	}
}	
// ============================ End :: Font 관련 함수 =============================

function resizeImage() { 
	var content = document.getElementById("newsContent"); 

	// content 아이디 내의 모든 이미지 크기가 maxsize 보다 크면 maxsize로 리사이즈. 
	var maxsize = content.offsetWidth - 20;
	
	if (!content) return;

	var img = content.getElementsByTagName("img"); 
	for(i=0; i<img.length; i++) { 
		if ( eval('img[' + i + '].width > maxsize') ) { 
			var img_height = parseInt((maxsize * eval('img[' + i + '].height')) / eval('img[' + i + '].width'));
	
			eval('img[' + i + '].width = maxsize') ; 
			eval('img[' + i + '].height = ' + img_height) ; 
		} 
	} 
}
