function getParameterJS( name ) {
	parseQueryStringJS( );
	return QueryStringJS( name );
}

QueryStringJS.keys = new Array();
QueryStringJS.values = new Array();

function parseQueryStringJS() {
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for ( var i = 0; i < pairs.length; i++ ) {
		var pos = pairs[i].indexOf('=');
		if ( pos >= 0 )	{
			var argname = pairs[i].substring( 0, pos );
			var value = pairs[i].substring(pos+1);
			QueryStringJS.keys[QueryStringJS.keys.length] = argname;
			QueryStringJS.values[QueryStringJS.values.length] = value;
		}
	}
}

function QueryStringJS( key ) {
	var value = "";

	if (QueryStringJS.keys != null) {
		for ( var i = 0; i < QueryStringJS.keys.length; i++ ) {
			if ( QueryStringJS.keys[i] == key ) {
				value = QueryStringJS.values[i];
				break;
			}
		}
	}
	return value;
}

//opener.location.href;
//opener.document.getElementById("artByLine").innerHTML;
//opener.document.getElementById("artTitle").innerHTML;
//http://www.chosun.com/svc/news/www/printArticle.html
function printOpen(url) {
	printWin=window.open(url, 'pbml_win','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=615,height=550');
}

//opener.ArtID
//opener.CatID
//opener.location.href
//opener.document.getElementById("artTitle").innerHTML
//opener.document.getElementById("artSubTitle").innerHTML
//opener.document.getElementById("artContent").innerHTML
//http://www.chosun.com/svc/news/www/sendArticle.html
function mailOpen(url) {
	mailWin=window.open(url, 'pbml_win','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrolling=no,width=480,height=500');
}

/***
function doResize() {
	var win_height = hitframe.document.body.scrollHeight;

	if (getParameterJS("site") == "photo" && win_height < 1400)
		hitframe.height = 1400;
	else if (win_height < 1200) 
		hitframe.height = 1200;
	else 
		hitframe.height = hitlist.document.body.scrollHeight;

	//document.all.hitframe.height = document.all.hitlist.document.body.scrollHeight;
}
***/

if (navigator.appName.charAt(0) == 'N') window.document.onkeydown = protectKeyFF;
else if (navigator.appName.charAt(0) == 'M') window.document.onkeydown = protectKey;
function protectKey() {
	if(event.keyCode == 116) {
		event.keyCode = 0;
		return false;
	}
	else if ((event.keyCode == 82) && (event.ctrlKey == true)) {
		event.keyCode = 0;
		return false;
	}
	else if ((event.keyCode == 78) && (event.ctrlKey == true)) {
		event.keyCode = 0;
		return false;
	}
}
function protectKeyFF(event) {
	if(event.keyCode == 116) return false;
	else if ((event.keyCode == 82) && (event.ctrlKey == true)) return false;
	else if ((event.keyCode == 78) && (event.ctrlKey == true)) return false;
}

document.oncontextmenu = new Function ("return false");
document.ondragstart = new Function ("return false");
document.onselectstart = new Function ("return false");

function chgURL (type) {
	var pg = getParameterJS("pg");
	var site = getParameterJS("site");
	var scode = getParameterJS("scode");
	var date = getParameterJS("date");
	//var newsPlusURL = "index.html";
	var newsPlusURL = "http://" + window.location.host + window.location.pathname;

	if (type == "") { 
		newsPlusURL = newsPlusURL + "?site=" + site + "&scode=" + scode;
	}
	else {
		//newsPlusURL = newsPlusURL + "?site=" + site + "&scode=" + scode + "&pg=" + pg;
		newsPlusURL = newsPlusURL + "?site=" + site + "&scode=" + scode;

		if (type == "last") { 
			if (newsPlusURL.indexOf("bbs") != -1)
				//newsPlus = "index.html?site=index&scode=" + scode + "&pg=" + pg;
				newsPlus = "index.html?site=index&scode=" + scode;

			var today = new Date(new Date().getTime() - 24*60*60*1000);
			var last_date = today.getYear() + (today.getMonth()+1 < 10 ? "0" : "") + (today.getMonth()+1) + (today.getDate() < 10 ? "0" : "") + today.getDate();
			newsPlusURL = newsPlusURL + "&date=" + last_date; 
		}
		else
			newsPlusURL = newsPlusURL + "&date=" + type;
	}
	
	top.location.href = newsPlusURL;	
}

function _getCookies(name) {
	var pcookie = document.cookie.split("; ");

	for (var i=0; i < pcookie.length; i++) {
		var values = pcookie[i].split("=");
		if (name == values[0])
			return unescape(values[1]);
	}
	return null;
}

function _checkLogin()
{
	if(!_getCookies('SMSESSION') || _getCookies('SMSESSION') == "LOGGEDOFF" || !_getCookies('SM_USER') || !_getCookies('dz_info')) {
		return false;
	}
	else {
		return true;
	}
}
