/********************************************************************************************
 * Basic Functions 
 *
 * Made by Max , June 2010.
 *
 *
 * 1. Variables
 *		- isIE : ie or not
 *
 * 2. Functions
 * 	- Browser
 * 		createBookmark ( [url, title] ) : Create bookmark specified by url and title
 *																The url, title is current domain and author by default.
 *		- String function
 *			getBytes(string) : Returns the byte(s) of the given string.
 *
 *		- Layer
 *			getDistance(object, layer id) : Returns the distance from object to given layer.
 *			getPos(object) : Returns the positions from given object to left top of document.
 *
 *		- Event
 *			addOnLoadEvent(callback function) : Set onload function with keep existing onload.
 * 										
 ********************************************************************************************/

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var today = new Date();

function createBookmark(){		// make bookmark current domain and author
	var url;
	var title;
	
	if(arguments.length==2){
		url = arguments[0];
		title = arguments[1];
	} else {	
		url = 'http://'+document.location.host.replace(/^([a-z0-9]+\.)?([\w]+\.[a-z]{2,4}(?:\.[a-z]{2})?)$/, "www.$2");
		var res = document.getElementsByTagName("meta");
		title = document.title;
		for(i=0;i<res.length;i++){
			if(res[i].name.toLowerCase()=="author"){ title=res[i].content; break; }
		}
	}
	if(isIE) window.external.AddFavorite(url, title);
	else	alert('Áñ°ÜÃ£±â¸¦ µî·ÏÇÏ½Ã·Á¸é Ctrl + D Å°¸¦ ´­·¯ÁÖ¼¼¿ä.');
}

function getBytes(str){
	var len = str.length;
	var bytes = 0;
	for(i=0; i< len; i++){
		var c = str.charAt(i);
		if(escape(c).length > 4) bytes += 2; // Two byte character
		else bytes++;
	}
	return bytes;
}

function getDistance(obj, id) {
	var r = { x: obj.offsetLeft, y: obj.offsetTop };
	while(obj.offsetParent){
		obj = obj.offsetParent;
		if(obj.id){
			if(obj.id==id) break;
		}
		r.x += obj.offsetLeft;
		r.y += obj.offsetTop;
	}
	return r;
}

function getPos(obj) {
	var r = { x: obj.offsetLeft, y: obj.offsetTop };
	if (obj.offsetParent) {
		var tmp = getPos(obj.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}


function addOnLoadEvent(func){
	if(typeof window.onload != 'function'){
		window.onload = func;
	} else {
		var oldonload = window.onload;
		window.onload = function(){
			oldonload();
			if(typeof func != 'function') eval(func);
			else func();
		}
	}
}

function getCookie(name){
    var nameOfCookie = name + "=";
    var x = 0;
    while ( x <= document.cookie.length ){
    	var y = (x+nameOfCookie.length);
		if( document.cookie.substring( x, y ) == nameOfCookie ){
				if((endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
					endOfCookie = document.cookie.length;
				return unescape( document.cookie.substring( y, endOfCookie ) );
			}
		x = document.cookie.indexOf( " ", x ) + 1;
		if( x == 0 ) break;
	}
   return "";
}

function setCookieTime(name, value, mSecond) {
		var today  = new Date();
		var expire = new Date(today.getTime() + mSecond);
		window.document.cookie = name + "=" + escape(value) + ((expire) ? ";path=/; expires=" + expire.toGMTString() : "");
}

function setCookie(name, value, min){
	setCookieTime(name, value, min*1000*60); /* ºÐ */ 
}


function openflash(width,height,src,id,str,wmode,ver){ 
   var html = '';
	var ver = (ver) ? ver : 8;
	if(isIE && isWin && !isOpera){
		var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+',0,0,0" width="'+width+'" height="'+height+'" ';
		if(id) html += 'id="'+id+'" name="'+id+'" ';
		html += 'align="middle">';
		html += '<param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" />';
		html += '<param name="movie" value="'+src+'" /><param name="quality" value="high" />';
		if(str) html += '<param name="FlashVars" value="'+str+'" />';
		if(!wmode) html += '<param name="wmode" value="transparent" />';
		html += '</object>';
	} else {
		html += '<embed src="'+src+'" quality="high" ';
		if(str) html += 'FlashVars="'+str+'" ';
		if(id) html += 'name="'+id+'" ';
		if(!wmode) html += 'wmode="transparent" ';
		html += 'width="'+width+'" height="'+height+'" align="middle" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
  }
  return html;
} 

function writeflash(src){ 
    document.write(src); 
}

function writeFlashMovie(){	
	document.write(openflash(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]));
}

function fo(){
	window.focus();
}

function closediv(DIV){
	document.getElementById(DIV).style.display='none';
}

function closeFlashWindow1(ID,TIME){
	closeWin(ID,TIME);
}

function pop(CID)
	{
        if(getCookie( CID ) != "done" )
			{
			    document.getElementById(CID).style.display = 'block';
		    }
	}

function closeWin(CID,MIN)
	{
		setCookie( CID, "done" , MIN); 
		document.getElementById(CID).style.display = 'none' ;
	}
	
function closeToday(cid){
	var today  = new Date();
	var expire = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 24, 00);
	window.document.cookie = cid + "=1" + ((expire) ? ";path=/; expires=" + expire.toGMTString() : "");
	document.getElementById(cid).style.display = 'none' ;
}

function closeWin2(CID,MIN)
	{
		setCookie( CID, "done" , MIN);
	}

function Position_change (div,left, top,otherdiv){
	if (screen.width==800 ) { float_left1 = left; }
	else if (screen.width==1024 ) { float_left1 = left; }
	else if (screen.width==1152 ) { float_left1 = left+64; }
	else if (screen.width==1280 ) { float_left1 = left+128; }
	else if (screen.width==1360 ) { float_left1 = left+168; }
	else if (screen.width==1400 ) { float_left1 = left+188; }
	else if (screen.width==1600 ) { float_left1 = left+288; }
	else if (screen.width==1680 ) { float_left1 = left+328; }
	else if (screen.width==1920 ) { float_left1 = left+448; }
	else if (screen.width==2048 ) { float_left1 = left+512; }

document.getElementById( div ).style.left = float_left1;

			if(otherdiv!="" ){
				if(document.getElementById(otherdiv)!=null){
					if(getCookie( otherdiv ) != "done" ){      
						var plustop = document.getElementById( otherdiv ).clientHeight ;
						document.getElementById( div ).style.top = top+plustop;
					}
				}
			}
}

function Position_test (div,left, top,otherdiv)
	{
	var sizes = getPageSize ();
	alert(sizes[0]+' '+sizes[1]+' '+sizes[2]+' '+sizes[3]);
	document.getElementById( div ).style.left = -83;
	if (sizes[0]<1003)
	{	document.getElementById( div ).style.left = -93;
	}
	if(getCookie( otherdiv ) != "done" )   
		{
	var plustop = document.getElementById( otherdiv ).clientHeight ;
	document.getElementById( div ).style.top = top+plustop;
		}
	}

if(typeof jkMouseTracking == 'undefined') jkMouseTracking = function(){}

function ad_view(){
	var adStatistics = new Image();
	var url = "http://common.jkn.co.kr/ad"+arguments[0]+"/view.php";
	url=url+"?ad_id="+arguments[1]+"&time="+today.valueOf();
	adStatistics.src = url; 
}

function ad_click(){
	var adStatistics = new Image();
	var url = "http://common.jkn.co.kr/ad"+arguments[0]+"/click.php";
	url=url+"?ad_id="+arguments[1]+"&n_url="+document.location.href+"&s_url="+document.referrer+"&time="+today.valueOf();
	adStatistics.src = url; 
}

function ad_event_click(){
	var adStatistics = new Image();
	var url = "http://event.jkn.co.kr/click/click.php";
	url=url+"?ad_id="+arguments[0]+"&time="+today.valueOf();
	adStatistics.src = url; 
}

var favoriteurl="http://www.jkn.co.kr/";
var favoritetitle="Financial and Economic News";
function addfavorites(){
	if (document.all)window.external.AddFavorite(favoriteurl,favoritetitle);
}

function setPng24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,''); 
	obj.style.filter =
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='about:blank;';
	return '';
}


/************************************************************************************************
 *
 * Preload Image Function (November. 24, 2008)
 *
 *	Copyright (C) 2008  JKNews Co,. Ltd.		Programmed by Maxwell, Shim( msshim@jknews.co.kr )
 ************************************************************************************************/
var Preload = {
		motion:false,
		loaded:false,
		onComplete:{},
		imgComplete: 0,
		loadingImage:'loadingImage',
		arg: 0,
		checkOnLoad: function(){
			Preload.imgComplete++;
			if(Preload.imgComplete == Preload.arg){
				if(Preload.motion){
					if(Preload.loadingImage!='') document.getElmentById(Preload.loadingImage).style.display='none';
					Preload.onComplete();
				} else Preload.loaded = true;
			}
		},
		load: function(){
			Preload.motion = Preload.loaded = false;
			Preload.imgComplete = 0;
			Preload.arg = arguments.length;
			var img = new Array();
			for(i=0; i<Preload.arg; i++){
				img[i] = new Image();
				img[i].src = arguments[i];
				if(img[i].complete) Preload.checkOnLoad();
				else img[i].onload = function(){ Preload.checkOnLoad(); }
			}
		}
	}
