// lib.js rev.2SO.212401

function newwindow(w, h, src, name)
{
	w=window.open(src,name,'width='+ w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0');
	w.focus();
}


// so_ver02 iR
function newwindow02(w, h, src, name)
{
	w=window.open(src,name,'width='+ w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
	w.focus();
}

function newwindow03(w, h, src, name)
{
	w=window.open(src,name,'width='+ w + ',height=' + h  + ',toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
	w.focus();
}

//  end so_ver02 iR


var nowsel;
var tree = new Array();

function menu_cat_sel(sel)
{
	uls = document.getElementsByTagName("ul");
	sel = sel + 1;
	
	for ( i=0; i<uls.length; i++ )
	{
		id = uls[i].id;
		if ( id.match(/cat_/) )
		{
			id = id.substr(4, id.length);
			
			if ( id == sel )
			{
				disp = "block";
			}
			
			else
			{
				disp = "none";
			}
			target = "cat_"+id;
			ulObj = document.getElementById(target);
			ulObj.style.display = disp;
		}
	}
}


function fit_mc_height()
{
	marginH    = 20;
	
	parentH    = document.getElementById("parent").offsetHeight;
	topbarH    = document.getElementById("top_bar").offsetHeight;
	anchorH    = document.getElementById("anc").offsetHeight;
	topicpathH = document.getElementById("topic_path").offsetHeight;
	
	mcObj      = document.getElementById("maincontent");
	mcObj.style.margin = "0px 0px 0px 3px";
	
	topOffset  = topbarH + anchorH + topicpathH + marginH;
	mcObj.style.top = topOffset + "px";
	mcObj.style.height = parentH - topOffset + "px";
}


function anchors_prefetch()
{
	// PageTopAnchor
	document.getElementById("maincontent").innerHTML = "<a name=\"p0\"></a>" + document.getElementById("maincontent").innerHTML;
	
	var divObjs = document.getElementsByTagName("div");
	num = 0;
	
	if ( divObjs.length > 0)
	{
		for(i=0; i < divObjs.length; i++)
		{
			divObj = divObjs[i];
			if ( (divObj.getAttribute("class")||divObj.getAttribute("className")) == "anchorid" )
			{
				if ( num == 0 )
				{
					if (document.documentElement.getAttribute("style") == document.documentElement.style)
					{
						divObj.style.cssText = "height:0px;font-size:1px;";
					}
					else
					{
						divObj.setAttribute("style","height:0px;font-size:1px;");
					}
				}
				
				if ( num != 0 )
				{
					divObj.innerHTML = "<a name=\"p" + num + "\"></a>" + divObj.innerHTML;
				}
				
				num++;
			}
		}
		
		if ( num == 0 )
		{
			return false;
		}
		
		else
		{
			return num-1;
		}
	}
	
	else
	{
		return false;
	}
}

function ol_number()
{
	olObjs = document.getElementsByTagName("ol");
	if ( olObjs.length > 0 )
	{
		for ( i=0; i < olObjs.length; i++)
		{
			olObjs[i].setAttribute("start", i+1);
			olObjs[i].firstChild.setAttribute("value", i+1);
		}
	}
}


function anchors(start)
{
	ancMode = anchors_prefetch();
	
	ancObj = document.getElementById('anchor');
	
	// AnchorMode New(ir)
	if ( ancMode != false )
	{
		anc = ancMode;
		tags = "";
		j = (start > 0) ? start : 1;
	}
	
	else  // Old anchor mode
	{
		aTags = document.getElementsByTagName("a");
		tags = "";
		
		j = (start > 0) ? start : 1;
		
		
		var anc = 0;
		
		for (i = 0; i < aTags.length; i++)
		{
			id = aTags[i].id;
			if ( id.match(/p[0-9]+/) )
			{
				anc++;
			}
		}
	}
	
	if ( anc == 0 )
	{
		tags = "";
	}
	
	else
	{
		anc++;
		if ( anc>10 && j != 1 )
		{
			prev = (j-10 < 0) ? 1 : j-10;
			tags += '<a href="javascript:anchors('+prev+');">&lt;</a>&nbsp;';
		}
		for ( i=0; i<10; i++ )
		{
			tags += '<a href="#p' + j + '">' + j + '</a>&nbsp';
			j++;
			if ( j > anc-1 ) { break; }
		}
		
		if ( anc>10 && j < anc )
		{
			tags += '<a href="javascript:anchors('+j+');">&gt;</a>&nbsp;';
		}
	}
	ancObj.innerHTML = tags;
	
	fit_mc_height();
}



function jump_to_anchor ( ID )
{
	anc = document.getElementById(ID);
	document.body.scrollTop = anc.offsetTop;
	document.documentElement.scrollTop = anc.offsetTop;
}


function mouse_in( id )
{
	id.style.background = "#ffcccc";
}


function mouse_out( id )
{
	id.style.background = "#ffffff";
}

function mouse_in_2( id )
{
	id.style.background = "#ff9999";
}


function mouse_out_2( id )
{
	id.style.background = "transparent";
}


function menu_tree_toggle( id, btn )
{
	target = document.getElementById( id );
	if ( tree[id] == "close")
	{
		target.style.display = "none";
		tree[id] = "open";
	}
	
	else
	{
		target.style.display = "block";
		tree[id] = "close";
	}
	
}


function jump_page( path )
{
	window.self.location = path;
}


function beta_alert_on()
{
	altdiv = document.getElementById("alt");
	altdiv.style.display = "block";
}

function beta_alert_off()
{
	altdiv = document.getElementById("alt");
	altdiv.style.display = "none";
}


function openresult() {
	
	w=window.open( '../../search/result.html',"CResult", "toolbar=no,location=no,status=no,menubar=no,width=570,height=350");
	w.focus();
}


function openresult_from_menu() {
	w=window.open( '../search/result.html',"CResult", "toolbar=no,location=no,status=no,menubar=no,width=570,height=350" );
	w.focus();
}

function openresult_from_home() {
	w=window.open( './search/result.html',"CResult", "toolbar=no,location=no,status=no,menubar=no,width=570,height=350" );
	w.focus();
}

// so_ver02 iR
function openresult02() {
	w=window.open( '../../subwindow/result.html',"CResult", "toolbar=no,location=no,status=no,menubar=no,width=570,height=350,resizable=yes,scrollbars=yes");
	w.focus();
}


function openresult_from_menu02() {
	w=window.open( '../subwindow/result.html',"CResult", "toolbar=no,location=no,status=no,menubar=no,width=570,height=350,resizable=yes,scrollbars=yes" );
	w.focus();
}

function openresult_from_home02() {
	w=window.open( './subwindow/result.html',"CResult", "toolbar=no,location=no,status=no,menubar=no,width=570,height=350,resizable=yes,scrollbars=yes" );
	w.focus();
}
// end so_ver02 iR


function topmenu_printbtn()
{
	print_sel = document.topprint.print.value;
	if ( print_sel != "" )
	{
		print_window("./contents/" + print_sel);
	}
}

function print_window(path)
{
	pwin=window.open(path);
	pwin.focus();
}


