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 Check_login(name) {
	var cookies = document.cookie;
	var value  = "";
	if(cookies.indexOf(name) != -1) {
		var start = cookies.indexOf(name) + name.length + 1;
		var end   = cookies.indexOf(";",start);

		if(end == -1) {
			end = cookies.length;
		}

		value = cookies.substring(start,end);
		value = unescape(value);
	}

	return value;
}

var winobj;
var winModalWindow;
var AppID = "99995613";

function TryItNow() {
	//checkCookie
	CheckCookie();

	// Test #1: Launch with no email variable value causing the user to have to select another user to interact with.
	CheckMessenger();

	//setCookie
	SetCookieArticle();

	LaunchApp(AppID, "");
}

function LaunchApp(AppID, emailID) {
	if (winobj != null) {
		winobj.LaunchApp(AppID, emailID);
	}
}

function CheckMessenger() {
	eval ('try {winobj = new ActiveXObject("MSNMessenger.P4QuickLaunch"); } catch (e) {winobj = null;}');
	var strErrorPage = "http://www.donga.com/news/liveMessenger/prt_error.html"
}

function CheckCookie() {
	var cookieName = "checkCookie";
	document.cookie = cookieName + "=1;path=/"+((location.host.toLowerCase().indexOf("donga.com")>=0)?";domain=donga.com":"");
	var value = getCookie(cookieName);
	if (value == null || value == "") {
		//if (isVista())
		//	alert ("¸Þ½ÅÀúº¸³»±â ±â´ÉÀº À¥ ºê¶ó¿ìÀú¿¡¼­ 'ÄíÅ°Çã¿ë' ÈÄ »ç¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.");
		alert ("ÄíÅ°¼³Á¤ÀÌ ¾ÈµÇ¾î ÀÖ´Â °æ¿ì ´Ù¸¥±â»ç°¡ Àü¼ÛµÉ ¼ö ÀÖ½À´Ï´Ù. \n\nÀÎÅÍ³Ý¿É¼Ç¿¡¼­ ÄíÅ°Çã¿ëÀ» È®ÀÎÇØ ÁÖ¼¼¿ä.");
	}

	document.cookie = cookieName + "=;path=/;expires=Fri, 31 Dec 1900 23:59:59 GMT"+((location.host.toLowerCase().indexOf("donga.com")>=0)?";domain=donga.com":"");
}

function IgnoreEvents(e) {
	return false;
}

//Display error message if the MSN Messenger client 6.2 is not installed or the browser is not Internet Explorer
function ShowWindow(strError, width, height) {
	if (window.showModalDialog) {

		window.showModalDialog(strError,null, "dialogWidth="+width+"px;dialogHeight="+height+"px;help=no;dialogLeft=160");
	} else {
		var ah = screen.availHeight;

		var y = (ah - height) / 2;

		window.top.captureEvents (Event.CLICK|Event.FOCUS)
		window.top.onfocus=HandleFocus
		winModalWindow = window.open (strError,"ModalChild", "dependent=yes,width="+width+",height="+height+",top="+y+",left=160,screenX=160,screenY="+y)
		winModalWindow.focus()
	}
}

function HandleFocus() {
	if (winModalWindow) {
		if (!winModalWindow.closed) {
			winModalWindow.focus()
		} else {
			window.top.releaseEvents (Event.CLICK|Event.FOCUS)
		}
	}
	return false
}

function SetCookieArticle() {
	var dongaUrl = location.href;
	var sExpires = new Date();
	sExpires.setDate(sExpires.getDate()+1);
	sExpires.setHours(0,0,0,0);

	document.cookie="dongaUrl="+escape(dongaUrl)+";expires="+(sExpires.toGMTString())+";path=/"+((location.host.toLowerCase().indexOf("donga.com")>=0)?";domain=donga.com":"");
}

//ºñ½ºÅ¸ Ã¼Å© ÀÚ¹Ù½ºÅ©¸³Æ® ºñ½ºÅ¸ÀÎ°æ¿ì true ¸®ÅÏ
function isVista() {
	var re = new RegExp("Windows NT ([0-9]).([0-9])" ,"g");
	var m = re.exec(navigator.userAgent);
	return (m[1] >= 6);
}


