function view_webzine(idx) {
	if(idx || idx == 0) {
		window.open('../enewspaper/mainview.php?mvid=' + idx ,'','left=100,top=50,marginwidth=0,marginheight=0,scrollbars=yes,menubar=0,top=0, left=0,resizable=yes');
	}
	else {
		window.open('../enewspaper/mainview.php?mvid=' + allpastnewsletter.hosu.value ,'','left=100,top=50,marginwidth=0,marginheight=0,scrollbars=yes,menubar=0,top=0, left=0,resizable=yes');
	}
}

function article_print_view(p_aid) {
  var popwin;
  popwin = window.open("../enewspaper/subarticle/pre_print_article.php?paid=" + p_aid, "", "width=800,height=600,scrollbars=no,resizeable=yes,statusbar=0,alwaysRaised=yes,top=100, left=127");
  popwin.focus();
}

function select_sgroup(sgroup) {
	sgid = sgroup.options[sgroup.selectedIndex].value;

	sid = document.getElementById("select_section_list");

	for(i=0; i<sid.length; i++) {
    sid.options.remove(0);
  }

  var section_option = document.createElement('option');

	for(i=0; i<section_groups[sgid].length; i++) {
		section_option.value = section_groups[sgid][i][0];
		section_option.text  = section_groups[sgid][i][1];
		alert(section_groups[sgid][i]);
		alert(section_groups[sgid][i][0]);
		alert(section_groups[sgid][i][1]);

		sid.options.add(section_option);
	}
}

function comment_writeing() {
	if(article_comment.article_comment_name.value == '') {
		alert('ÀÌ¸§À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä');
		article_comment.article_comment_name.focus();
		return;
	}

	if(article_comment.article_comment_pass.value == '') {
		alert('¾ÏÈ£À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä');
		article_comment.article_comment_pass.focus();
		return;
	}

	if(article_comment.article_comment_title.value == '') {
		alert('³»¿ëÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä');
		article_comment.article_comment_title.focus();
		return;
	}

	if(article_comment.article_comment_title.value.length > 200) {
		alert('³»¿ëÀ» 200ÀÚÀÌÇÏ·Î ÀÔ·ÂÇØ ÁÖ¼¼¿ä');
		article_comment.article_comment_title.focus();
		return;
	}
	article_comment.submit();
}

function comment_delete(del_cid) {
	var popwin;
	popwin = window.open('./sub_comment/comment_delete.php?del_cid=' + del_cid + '&aid=18&mvid=&ssid=&comment_all=&eda=&sda=&sid=&stext=&mtnkey=articleview&mkey=scatelist&mkey2=4&bpage=&#comment', '', 'width=195,height=120,scrollbars=no,resizeable=no,statusbar=0,alwaysRaised=yes,top=100, left=127');
	popwin.focus();
}

function cal_pre(){	
	var tmpStr;

	tmpStr = article_comment.article_comment_title.value;
	cal_byte(tmpStr);
}

function cal_byte(aquery) {
	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;

	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for (k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);
		if (escape(onechar) =='%0D') { } else if (escape(onechar).length > 4) { tcount += 2; } else { tcount++; }
	}

	article_comment.cbyte.value = tcount;
	if(tcount>200) {
		reserve = tcount-200;
		alert('¸Þ½ÃÁö ³»¿ëÀº 200¹ÙÀÌÆ® ÀÌ»óÀº Àü¼ÛÇÏ½Ç¼ö ¾ø½À´Ï´Ù. ¾²½Å ¸Þ¼¼Áö´Â '+reserve+'¹ÙÀÌÆ®°¡ ÃÊ°úµÇ¾ú½À´Ï´Ù. ÃÊ°úµÈ ºÎºÐÀº ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.'); 
		cutText();
		return;
	}
}

function cutText() {
	nets_check(article_comment.article_comment_title.value);
}

function nets_check(aquery) {

	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;

	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for(k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);

		if(escape(onechar).length > 4) {
			tcount += 2;
		} else {
			// ¿£ÅÍ°ªÀÌ µé¾î¿ÔÀ»¶§ °ª()ÀÌ µÎ¹ø½ÇÇàµÇ´Âµ¥ Ã¹¹øÂ° °ª()ÀÌ µé¾î¿ÔÀ»¶§ tcount¸¦ Áõ°¡½ÃÅ°Áö ¾Ê´Â´Ù.
			if(escape(onechar)=='%0A') {
			} else {
				tcount++;
			}
		}

		if(tcount>200) {
			tmpStr = tmpStr.substring(0,k);
			break;
		}

	}
	article_comment.article_comment_title.value = tmpStr;
	cal_byte(tmpStr);

}

function subscription(sskey) {
	var popwin;
	popwin = window.open("/newshome/subscription/subscription.php?sskey="+sskey, "subscription", "width=628,height=700,scrollbars=yes,resizeable=no,statusbar=0,alwaysRaised=yes,top=10, left=10");
	popwin.focus();
}

function real_name() {
	var pop=window.open('/components/real_name/input.php', 'real_name', 'width=270, height=191, top=100, left=100, statusbar=0');
	pop.focus();
}

function forced_select(idx)
{
	idx = idx-1;
	dsearch_frm2.search_kind[idx].checked = "true";
}

function filedownload(filename){
	document.all["blindiframe"].src='http://news.pajuro.net/enewspaper/file_download.php?filename='+filename;
}










function OnLoad_Function() {
	if(document.getElementById("main_layout")) {
		hidden_menu();
		text_dot();
		tab_news_init('tab1', 'tab01', 'tab_list_1');
		image_hidden();
		scatelist_hidden();
		align_pagelist();
		article_view_center();
	}
	else {
		setTimeout(OnLoad_Function, 1);
	}
}





function view_menu(menu_id, view) {
	hidden_menu();
	if(view) {
		this_obj = eval("document.all.smenu_"+menu_id);
		this_obj.style.display = "";
	}
}

function hidden_menu() {
	var bmenu_obj = document.getElementById("menu").childNodes[0];
	
	for(bmenu_cnt=0; bmenu_cnt<bmenu_obj.childNodes.length; bmenu_cnt++) {
		smenu_obj = bmenu_obj.childNodes[bmenu_cnt];

		for(smenu_cnt=0; smenu_cnt<smenu_obj.childNodes.length; smenu_cnt++) {
			if(smenu_obj.childNodes[smenu_cnt].nodeName == "UL") {
				smenu_obj.childNodes[smenu_cnt].style.display = "none";
			}
		}
	}
}

function tab_news_init(obj_id, obj_img, obj_div) {
	if(document.getElementById(obj_id)) {
		//ÇØ´ç °³Ã¼ Ã£¾Æ³»±â
		target_obj = document.getElementById(obj_id);

		while(target_obj.tagName) {
			if(target_obj.tagName == "UL") {
				break;
			}
			target_obj = target_obj.childNodes[0];
		}

		var image_list = new Array();
		var div_list = new Array();
		var margin = 0;

		for(i=0; i<target_obj.childNodes.length; i++) {
			target_obj_li = target_obj.childNodes[i];

			img_id = target_obj_li.childNodes[0].childNodes[0].id;
			div_id = target_obj_li.childNodes[1].id;

			image_list[img_id] =  target_obj_li.childNodes[0].childNodes[0];
			div_list[div_id]   =  target_obj_li.childNodes[1];

			//ÀÌ¹ÌÁö Á¤¸®
			image_list[img_id]["out"]  = "/images/newshome/" + img_id + ".gif";
			image_list[img_id]["over"] = "/images/newshome/" + img_id + "_over.gif";


			//ÃÊ±âÈ­
			image_list[img_id].src = image_list[img_id]["out"];
			div_list[div_id].style.display = "none";

			margin = margin + 1;
			div_list[div_id].style.margin = "0px 0px 0px -" + margin + "px";
			margin = margin + image_list[img_id].offsetWidth;

			//alert(div_list[div_id].style.margin);
		}
		
		image_list[obj_img].src = image_list[obj_img]["over"];
		div_list[obj_div].style.display = "";
	}
}

function image_hidden() {
	total_img_cnt = document.images.length;

	for(i=0; i<total_img_cnt; i++) {
		cur_img = document.images[i];

		if(cur_img.parentNode.id == "image" && cur_img.style.display == "none") {
			cur_img.parentNode.style.display = "none";
		}
	}
}

function scatelist_hidden() {
	total_a_cnt = document.anchors.length;

	for(i=0; i<total_a_cnt; i++) {
		cur_a = document.anchors[i];

		if(cur_a.parentNode.nodeName == "LI" && cur_a.style.display == "none") {
			cur_a.parentNode.style.display = "none";
			document.anchors[i-1].parentNode.style.border = "0px";
		}
	}
}

function align_pagelist() {
	if(document.getElementById("pagelist")) {
		page_item     = document.getElementById("pagelist");
		page_item_cnt = page_item.childNodes.length;
		tot_width     = 0;

		for(i=0; i<page_item_cnt; i++) {
			tot_width += page_item.childNodes[i].offsetWidth;
		}

		page_item.style.width = tot_width+15;
	}
}

function article_view_center() {
	if(document.getElementById("article_view")) {
		a = document.getElementById("article_view");
		
		for(i=0; i<a.childNodes.length; i++) {
			if(a.childNodes[i].id == "article") {
				a = a.childNodes[i];
				break;
			}
		}
		
		for(i=0; i<a.childNodes.length; i++) {
			if(a.childNodes[i].id == "content") {
				a = a.childNodes[i];
				break;
			}
		}

		if(a.childNodes[0].offsetWidth < 650) {
			a.style.width = a.childNodes[0].offsetWidth + 20;
		}
		else {
			a.style.width = 670;
		}
	}
}

function text_dot() {
	image_margin = 8;
	image_padding = 6;
	image_border = 2;
	title_font_size = 12;
	title_font_height = 160;
	content_font_size = 12;
	content_font_height = 140;

	var title_obj, content_obj, image_obj;

	tot_length = document.anchors.length;

	for(i=0; i<tot_length; i++) {
		anchor_width = document.anchors[i].offsetWidth;

		child_cnt = document.anchors[i].childNodes.length;

		title_obj = content_obj = image_obj = null;

		for(j=0; j<child_cnt; j++) {
			if(document.anchors[i].childNodes[j].id == "title") {
				title_obj = document.anchors[i].childNodes[j];
				title_obj_width = title_obj.offsetWidth;
				title_obj_margin = title_obj.style.marginLeft + title_obj.style.marginRight;
				title_obj_idx = j;
			}

			if(document.anchors[i].childNodes[j].id == "content") {
				content_obj = document.anchors[i].childNodes[j];
				content_obj_width = content_obj.offsetWidth;
				content_obj_margin = content_obj.style.marginLeft + content_obj.style.marginRight;
				content_obj_idx = j;
			}

			if(document.anchors[i].childNodes[j].id == "image") {
				image_obj = document.anchors[i].childNodes[j];
				image_obj_width = image_obj.style.width;
				image_obj_margin = image_obj.style.marginLeft + image_obj.style.marginRight;
				image_obj_idx = j;
			}
		}

		if(image_obj && (content_obj_width > 0)) {
			if(title_obj_idx < image_obj_idx) {
				max_width = anchor_width;
			}
			else {
				max_width = parseInt((anchor_width - image_obj_width - image_margin - image_padding - image_border) * 0.9);
			}
		}
		else {
			max_width = anchor_width;
		}

		if(title_obj) {
			if(title_obj.style.fontSize) {
				font_size = title_obj.style.fontSize;

				if(font_size.indexOf("px")) {
					font_size = font_size.replace("px", "");
				}
				else if(font_size.indexOf("%")) {
					font_size = font_size.substring("%", "");
				}
				else {
					font_size = font_size;
				}
			}
			else {
				font_size = title_font_size;
			}
			
			if(title_obj.style.lineHeight) {
				line_height = title_obj.style.lineHeight;
			}
			else {
				line_height = title_font_height;
			}

			fwidth = font_size;
			fheight = font_size * ( line_height / 100 );

			max_cols = parseInt(max_width/fwidth);

			if(title_obj.offsetHeight > fheight) {
				max_rows = parseInt(title_obj.offsetHeight/fheight);
			}
			else {
				max_rows = 1;
			}

			innerhtml = title_obj.innerHTML;
			/*
			alert("innerhtml = " + innerhtml + "\r\n\r\n"
					+ "anchor_width = " + anchor_width + "\r\n\r\n"
			    + "image_obj_width = " + image_obj_width + "\r\n\r\n"
					+ "image_margin = " + image_margin + "\r\n\r\n"
					+ "image_padding = " + image_padding + "\r\n\r\n"
					+ "image_border = " + image_border + "\r\n\r\n"
					+ "parseInt((anchor_width - image_obj_width - image_margin - image_padding - image_border) * 0.9) = " + parseInt((anchor_width - image_obj_width - image_margin - image_padding - image_border) * 0.9) + "\r\n\r\n"
					+ "max_width = " + max_width + "\r\n\r\n"
					+ "font_size = " + font_size + "\r\n\r\n"
					+ "line_height = " + line_height + "\r\n\r\n"
					+ "fwidth = " + fwidth + "\r\n\r\n"
					+ "fheight = " + fheight + "\r\n\r\n"
					+ "max_cols = " + max_cols + "\r\n\r\n"
					+ "max_rows = " + max_rows + "\r\n\r\n"
					+ "innerhtml.length = " + innerhtml.length + "\r\n\r\n"
					+ "parseInt(max_cols*max_rows * 1.05) = " + parseInt(max_cols*max_rows * 1.05) + "\r\n\r\n"
			);
			*/
			if(innerhtml.length > parseInt(max_cols*max_rows * 1.05)) {
				if(Browser.Version() < 7) {
					innerhtml = innerhtml.substring(0, parseInt(max_cols*max_rows * 1))+'...';
				}
				else {
					innerhtml = innerhtml.substring(0, parseInt(max_cols*max_rows * 1))+'...';
				}
			}

			title_obj.innerHTML = innerhtml;
		}

		if(content_obj) {
			if(content_obj.style.fontSize) {
				font_size = content_obj.style.fontSize;
			}
			else {
				font_size = content_font_size;
			}
			
			if(content_obj.style.lineHeight) {
				line_height = content_obj.style.lineHeight;
			}
			else {
				line_height = content_font_height;
			}

			fwidth = font_size;
			fheight = font_size * ( line_height / 100 );

			max_cols = parseInt(content_obj.offsetWidth/fwidth);
			max_rows = parseInt(content_obj.offsetHeight/fheight);

			innerhtml = content_obj.innerHTML;

			if(innerhtml.length > parseInt(max_cols*max_rows)) {
				innerhtml = innerhtml.substring(0, parseInt(max_cols*max_rows) * 1.1)+'...';
			}

			content_obj.innerHTML = innerhtml;
		}
	}
}	


//¹öÀüÃ¼Å©
var Browser = {
	Version: function() {
		var version = 999; // we assume a sane browser
		if (navigator.appVersion.indexOf("MSIE") != -1)      // bah, IE again, lets downgrade version number
			version = parseFloat(navigator.appVersion.split("MSIE")[1]);    
		return version;  
	}
}