//Save type : À¯´ÏÄÚµå

var AppMinorVersion = navigator.AppMinorVersion;
var appVersion      = navigator.appVersion;
var platform        = navigator.platform;
var appname         = navigator.appName;
var issupport       = false;
var useragent       = navigator.userAgent;

var szLicenseKey	= ""; // string
var nLicenseType	= -1; // long
var szExpiration	= ""; // stringunin

var nDefendSubClassing = 1; // BOOL
var nDefendBHO         = 0; // BOOL
var nProtectionLevel   = 1; // long

var nPopupDialogProtection = 0; // BOOL
var nDRM                   = 0; // BOOL
var nWarningAlertBox       = 0; // BOOL

var nWarningNotifier	= 1; // 0 - Use Dialog, 1 - Use ToolTip, 2 - None

var szLogoImageURL   = "http://www.epost.go.kr/comm/easykeytec/epost_logo.html"; // string
var nLogoImageWidth  = 134; // long
var nLogoImageHeight = 48;  // long
var nLogoDisplaySec  = 0; // long
var nDisableLogo     = 1; // BOOL

var szTrayIconURL = ""; // string
var szWebKey  = ""; // string  protect target : szLogoImageURL, szTrayIconURL

var nEnableE2E         = 0; // long
var nCapturingSecurity = 0; // long

var szActiveXVersion = "2009,12,1,1";
var szMozillaVersion = "2009,6,3,1";
// ActiveX CAB ÆÄÀÏ °æ·Î
var szCabUrl        = "http://www.epost.go.kr/comm/easykeytec/easykeytec.cab";
//var szCabUrl        = "http://update.spaceinter.com/easykeytec/bin/easykeytec.cab";

// ActiveX ¼³Ä¡ ÈÄ ¸®ÅÏ ÆäÀÌÁö °æ·Î ¼³Á¤
var szCabInstallUrl = "http://update.spaceinter.com/easykeytec/bin/easykeytec_install_ie.html?rdir=";// »ç¿ë¾ÈµÊ
//var szCabInstallUrl = "http://dwww.epost.go.kr/comm/easykeytec/easykeytec_install_ie.html?rdir=";//ÀÚÃ¼¼­¹ö


// Mozilla XPI ÆÄÀÏ °æ·Î
//var szXpiUrl        = "http://update.spaceinter.com/easykeytec/bin/easykeytec.xpi"; // »ç¿ë¾ÈµÊ
var szXpiUrl        = "http://www.epost.go.kr/comm/easykeytec/easykeytec.xpi"; // ÀÚÃ¼¼­¹ö

// XPI ¼³Ä¡ ÈÄ ¸®ÅÏ ÆäÀÌÁö °æ·Î ¼³Á¤
//var szMZInstallUrl  = "http://update.spaceinter.com/easykeytec/bin/easykeytec_install_mz_manual.html"; // Mozilla ¼öµ¿¼³Ä¡ À¥ ÆäÀÌÁö ÁÖ¼Ò
var szMZInstallUrl  = "http://www.epost.go.kr/comm/easykeytec/easykeytec_install_mz_manual.html"; // Mozilla ¼öµ¿¼³Ä¡ À¥ ÆäÀÌÁö ÀÚÃ¼¼­¹ö
var szMZInstallType = "once"; //default = ¼³Ä¡ÆäÀÌÁö·Î °è¼Ó ÀÌµ¿ once = ¼³Ä¡ ¿©ºÎ »ç¿ëÀÚ È®ÀÎ


szWebKey  = "90F221818F3A02A2DB932FD41FA6D8B0D561D16C803707D13AD95BDCD69B45E0";

if ( CompareDomain( "epost.go.kr", document.domain ) != -1 )
{
	// µµ¸ÞÀÎ ¶óÀÌ¼¾½º Å°
	szLicenseKey = "A198DC8CA3468AF54BD31FCBFBCEB4CB111ABCF0E6158413984B68C8FCE16702";
	// ¶óÀÌ¼¾½º Å° Å¸ÀÔ
	nLicenseType = 773;
	
}
else if ( CompareDomain( "epost.kr", document.domain ) != -1 )
{
	// µµ¸ÞÀÎ ¶óÀÌ¼¾½º Å°
	szLicenseKey = "4C98610B396A0F60A664406CB77D3594753A30768FE860A9A8F8A8D4E7A21CCB";
	// ¶óÀÌ¼¾½º Å° Å¸ÀÔ
	nLicenseType = 517;

}
else if ( CompareDomain( "kstamp.go.kr", document.domain ) != -1 )
{
	// µµ¸ÞÀÎ ¶óÀÌ¼¾½º Å°
	szLicenseKey = "3FD1DF885AAAB0DB76321254573D49421E3926EBCAA5ABCFEA070F84FF13F4B8";
	// ¶óÀÌ¼¾½º Å° Å¸ÀÔ
	nLicenseType = 773;

}
else if ( CompareDomain( "koreastamp.go.kr", document.domain ) != -1 )
{
	// µµ¸ÞÀÎ ¶óÀÌ¼¾½º Å°
	szLicenseKey = "8AE1C7DF634F6CBDA10E2333E25E4BCA949D0F211EA5D71E354CC8C4273E5EDD";
	// ¶óÀÌ¼¾½º Å° Å¸ÀÔ
	nLicenseType = 773;

}
else if ( CompareDomain( "kstamp.net", document.domain ) != -1 )
{
    // µµ¸ÞÀÎ ¶óÀÌ¼¾½º Å°
    szLicenseKey = "CDA40F191E5B4A09C75EFF69F51992DBF25143A4D4E085CD564C91C7E19CB30A";
    // ¶óÀÌ¼¾½º Å° Å¸ÀÔ
    nLicenseType = 517;
}

if (platform == "Win32")
{
	if (appname == "Microsoft Internet Explorer")
	{
		appname = "IE";
		issupport = true;
	}
	else if (useragent.lastIndexOf( "Chrome" ) != -1) 
		appname = "Chrome";
	else if (useragent.lastIndexOf( "Safari" ) != -1)
	{
		appname = "Safari";
		issupport = true;
	}
	else if (useragent.lastIndexOf( "Opera" ) != -1)
	{
		appname = "Opera";
		issupport = true;
	}
	else if (appname == "Netscape") 
	{
		appname = "FireFox";
		issupport = true;
	}
}

if ( issupport == true )
{

	if (appname == "IE")
	{
		document.write('<OBJECT ID="EZKeytec" CLASSID="CLSID:2DCB00FB-3485-486B-BD41-C49AD605264D" CODEBASE="' + szCabUrl + '#version=' + szActiveXVersion + '" width="0" height="0">');
	}
	else
	{
		if ( szMZInstallType == "once" )
		{
			easykeytec_update_mz_once();
		}
		else
		{
			easykeytec_update_mz();
		}

		document.write('<OBJECT ID="EZKeytec" type="application/spaceinter/EasyKeytec" width="0" height="0" title="EasyKeytec Web">');
	}

	document.write('<PARAM NAME="szSerialKey"           VALUE="' + szLicenseKey 		+ '" />');
	document.write('<PARAM NAME="LicenseType"           VALUE="' + nLicenseType 		+ '" />');
	document.write('<PARAM NAME="Expiration"            VALUE="' + szExpiration 		+ '" />');
	document.write('<PARAM NAME="DefendSubClassing"     VALUE="' + nDefendSubClassing 	+ '" />');
	document.write('<PARAM NAME="DefendBHO"             VALUE="' + nDefendBHO         	+ '" />');
	document.write('<PARAM NAME="PopupDialogProtection" VALUE="' + nPopupDialogProtection 	+ '" />');
	document.write('<PARAM NAME="ProtectionLevel"       VALUE="' + nProtectionLevel   	+ '" />');
	document.write('<PARAM NAME="DRM"                   VALUE="' + nDRM               	+ '" />');
	document.write('<PARAM NAME="WarningAlertBox"       VALUE="' + nWarningAlertBox   	+ '" />');
	document.write('<PARAM NAME="LogoDisplaySec"        VALUE="' + nLogoDisplaySec    	+ '" />');
	document.write('<PARAM NAME="DisableLogo"           VALUE="' + nDisableLogo       	+ '" />');
	document.write('<PARAM NAME="LogoImageWidth"        VALUE="' + nLogoImageWidth    	+ '" />');
	document.write('<PARAM NAME="LogoImageHeight"       VALUE="' + nLogoImageHeight   	+ '" />');
	document.write('<PARAM NAME="LogoImageURL"          VALUE="' + szLogoImageURL     	+ '" />');
	document.write('<PARAM NAME="TrayIconURL"           VALUE="' + szTrayIconURL      	+ '" />');
	document.write('<PARAM NAME="CapturingSecurity"     VALUE="' + nCapturingSecurity 	+ '" />');
	document.write('<PARAM NAME="EnableE2E"             VALUE="' + nEnableE2E         	+ '" />');
	document.write('<PARAM NAME="WarningNotifier"	    VALUE="' + nWarningNotifier    	+ '" />');
	document.write('<PARAM NAME="WebKey"			    VALUE="' + szWebKey			  	+ '" />');
	document.write('</OBJECT>');

	if (appname == "IE")
	{
		//easykeytec_update_ie();
	}
}

function CompareDomain( targetDomain, CurDomain )
{
	return CurDomain.lastIndexOf( targetDomain, CurDomain );
}

function IsInstalled_mz()
{
	var result = 0;
	var index = detect_plugin_mz("EasyKeytec-plugin");
	if (index == -1) return false;

	var desc = navigator.plugins[index].description;

	index = desc.indexOf('v', 0);
	if (index < 0) return false;

	var verstring = desc.substring(index+1, desc.length);

	var arrayCurVersion = verstring.split('.');
	var arrayNewVersion = szMozillaVersion.split(',');

	for( var i=0; i<4; i++ )
	{
		if ( arrayCurVersion[i] > arrayNewVersion[i] ) return true;
		else if ( arrayCurVersion[i] < arrayNewVersion[i] ) return false;
	}

	return true;
}

function detect_plugin_mz( szTarget )
{
	var results = -1;
	for ( var j = 0; j < navigator.plugins.length; j++ )
	{
		results = CompareDomain( szTarget, navigator.plugins[j].name );
		if ( results != -1 ) return j;
	}

	return ( -1 );
}

function easykeytec_update_ie()
{
	if (EZKeytec.object == null) document.location.href = szCabInstallUrl + document.location.href + "&LicenseKey=" + szLicenseKey +  "&LicenseType=" + nLicenseType +  "&szCabUrl=" + szCabUrl +  "&szActiveXVersion=" + szActiveXVersion;
}

function ezty_getcookie( str )
{
  var key = str + "=";
  var i = 0;
  while ( i <= document.cookie.length ){
    var j = i + key.length;
    if ( document.cookie.substring( i, j ) == key ){
		var cookie_end = document.cookie.indexOf( ";", j );
		if ( cookie_end == -1 )
			cookie_end = document.cookie.length;
		return unescape( document.cookie.substring( j, cookie_end ) );
    }
    i = document.cookie.indexOf( " ", i ) + 1;
    if ( i == 0 )  break;
  }
  return "";
}

function ezty_setcookie( key, value, term )
{
	if ( term >= 0){
		var expire = new Date();  
		expire.setDate( expire.getDate() + term );
		document.cookie = key + "=" + escape( value ) + "; path=/; expires=" + expire.toGMTString() + ";";
		return;
	}
	document.cookie = key + "=" + escape( value ) + "; path=/;";
}


function easykeytec_update_mz()
{
	if ( !IsInstalled_mz() ) document.location.href = szMZInstallUrl;
}

function easykeytec_update_mz_once()
{
	if( ezty_getcookie("ezty")=="off" )
		return false; // objectÅÂ±×¸¦ ¾È¾²µµ·Ï ÇÑ´Ù.
	
	if ( !IsInstalled_mz() )
	{			
		var msg = "EasyKeytec-Web1.5 For Plugin(Å°º¸µåº¸¾È)À» ¼³Ä¡ ÇÏ½Ã°Ú½À´Ï±î?\n\n";
		msg = msg + "\"¿¹\"¸¦ ´©¸£½Ã¸é Å°º¸µåº¸¾È ¼³Ä¡ÆäÀÌÁö·Î ÀÌµ¿ÇÕ´Ï´Ù.\n";
		msg = msg + "\"Ãë¼Ò\"¸¦ ´©¸£½Ã¸é Å°º¸µåº¸¾ÈÀ» ¼³Ä¡ÇÏÁö ¾Ê°í º» »çÀÌÆ®¸¦ ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.\n"
 		msg = msg + "\"Ãë¼Ò\"¸¦ ´­·¶À» °æ¿ì ÃßÈÄ Å°º¸µåº¸¾ÈÀ» ´Ù½Ã ¼³Ä¡ÇÏ½Ã·Á¸é \"°³ÀÎ Á¤º¸ ÃÊ±âÈ­\" ¸Þ´º¸¦ ÀÌ¿ëÇÏ¿© \n\"ÄíÅ°\"¸¦ ÃÊ±âÈ­ÇØ¾ß ÇÕ´Ï´Ù";
		
		if (confirm( msg ))
		{
			if ( appname == "FireFox" )
			{					
				//window.top.document.location.href = szMZInstallUrl;
				document.location.href = szMZInstallUrl;
			}
			else
			{
				//document.parentWindow.top.document.location.href = szMZInstallUrl;
				document.location.href = szMZInstallUrl;
			}
		}
		else
		{
			ezty_setcookie("ezty", "off", 365);
			return false;
		}
	}
	return true;
} 