
//==================================================================================================//
// Internet Explorer PlugIn
//==================================================================================================//

var TEFW_CLSID="clsid:27640517-0513-4d81-A61E-228DC51680F8";	

var TEFW_CODEBASE="http://dn.softsecurity.co.kr/TouchEnfirewall/ebs/TEFW.cab";	

var TEFW_VERSION="version=2,1,1,13";

var USING_TEFW = "1";

var Multi_InstallBinary = "";


// Å°º¸µåº¸¾È ¼³Ä¡ÆäÀÌÁö ±¸ºÐ
var isInstallPage = false;
var cURL = document.location.href;

if(cURL.indexOf("ck_install") != -1) {
		isInstallPage = true;
	} else {
		isInstallPage = false;
}



var Base = {
	ua		: navigator.userAgent.toLowerCase(),
  ie		: navigator.appName == 'Microsoft Internet Explorer',
  ns		: navigator.appName == 'Netscape',
  ff		: navigator.userAgent.match('Firefox') == 'Firefox',
  sf		: navigator.userAgent.match('Safari') == 'Safari',
  op		: navigator.userAgent.match('Opera') == 'Opera',
  cr		: navigator.userAgent.match('Chrome') == 'Chrome',
  win		: navigator.platform == 'Win32',
  mac		: navigator.userAgent.match('Mac') == 'Mac',
  lnx		: navigator.userAgent.match('Linux') == 'Linux'
}

var getPluginType = {
	cCKFFMIME		: ((Base.win) && (Base.ff ||Base.op)),
	cCKSFMIME		: ((Base.win) && (Base.sf ||Base.cr)),
	cACTIVEX		: ((Base.win) && (Base.ie)),
	cNPRUNTIME	: (Base.win && ((Base.ff || Base.sf || Base.cr) || Base.op)),
	cOtherNP		: (Base.win && (Base.cr || Base.op))
}

// ºê¶ó¿ìÀúº° ¼³Ä¡ÆäÀÌÁö ºÐ±â
if (getPluginType.cACTIVEX) {	
	Multi_InstallPage = "";
} else if ((getPluginType.cNPRUNTIME) && (Base.ff)) {
	Multi_InstallPage = "";
} else if ((getPluginType.cNPRUNTIME) && (Base.sf) && (!Base.cr)) {
	Multi_InstallPage = "";
} else if (getPluginType.cOtherNP) {
	Multi_InstallPage = "";
}

// ºê¶ó¿ìÀú MimeType Ã¼Å©
function checkFWMime() {
	var result = "";
	
	if (getPluginType.cCKFFMIME) {
		var CKmType = navigator.mimeTypes['application/ckfw-plugin'];
		
		if (CKmType == undefined) {
			return false;
		} else {
			return true;
		}
	} else if (getPluginType.cCKSFMIME) {
		var CKmType = navigator.mimeTypes['application/ckfw-plugin'];
		//alert("CKmType2 = " + CKmType);
		if (CKmType == undefined) {
			return false;
		} else {
			return true;
		}
	}
}


function PrintTEFWActiveXTag() {
		
	if (USING_TEFW == "1" && navigator.appName.indexOf("Microsoft")!=-1 && (navigator.platform == "Win32" || navigator.platform == "Win64")) 
	{
			var Str="";	
			Str+= '<object classid="' + TEFW_CLSID + '"';
			Str+= '\n\t codebase="' + TEFW_CODEBASE + '#' + TEFW_VERSION + '"';
			Str+= '\n\tvspace="0" hspace="0" width="0" id="TEFW" style="display:none;">';
			Str+= '\n\t<param name="SecurityLevel" value="medium">';	//SecurityLevel - medium/high/low
			Str+= '\n\t<param name="Priority" value="user">';					//Priority - user/site
			Str+= '\n\t<PARAM NAME="AV" VALUE="on">';									//whether use AntiVirus or not - on/off
		
			//===== < Site Interface > ================================================================//		
			Str+= '\n\t<PARAM NAME="AVScanWhenStart" VALUE="on">';		// whether use real-scan when first loading - on/off
			Str+= '\n\t<param name="ProgressBarPolicy" value="3">';		//1 : Ç×»ó ¾÷µ¥ÀÌÆ®¹Ù ÆË¾÷
																																//2 : ¾÷µ¥ÀÌÆ® ÇÒ°ÍÀÌ ÀÖÀ»°æ¿ì¸¸ ÆË¾÷ (default)
																																//3 : Ç×»ó ¾÷µ¥ÀÌÆ®Ã¢ ÆË¾÷ ¾ÈÇÔ
			Str+= '\n\t<param name="ProgressBarPosType" value="rightbottom">';	// progressbar popup location - center/rightbottom
			//=========================================================================================//
		
			Str+= '\n\t<PARAM NAME="RegParam" VALUE="1">';
			//Str+= '\n\t<PARAM NAME="RegIpPortLst" VALUE="1,5004,5004,0,0,1,SAMPLE,1">';
			//Str+= '\n\t<PARAM NAME="RegIpPortLst" VALUE="1,23,23,0,0,1,SAMPLE,1">';
			//Str+= '\n\t<PARAM NAME="RegIpPortLst" VALUE="1,5000,5010,192.168.0.1,192.168.0.2,1,SAMPLE,1">';
			//Str+= '\n\t<param name="RegProcLst" value="1,C:\\Program Files\\QFile\\QFile.exe">';
			//Str+= '\n\t<param name="RegProcLst" value="1,C:\\Program Files\\Nanum Technologies\\SmartFlow OSE2\\messenger\\SmartMessenger.exe">';
			//Str+= '\n\t<param name="RegProcLst" value="1,C:\\Program Files\\NATEON\\BIN\\NateOnMain.exe">';
			Str+= '\n</object>';
			document.write(Str);	
	}
}

function PrintFWEmbedTag() {
	
	
		if (USING_TEFW == "1") {
				var Str="";
				Str+= '<EMBED id="TEFW" type="application/ckfw-plugin" width=0 height=0 hidden="true" ';				
				Str+= 'SecurityLevel="medium" ';		// SecurityLevel - medium/high/low
				Str+= 'Priority="user" ';						// Priority - user/site
				Str+= 'AV="on" ';										// whether use AntiVirus or not - on/off
			
				//===== < Site Interface > ================================================================//		
				Str+= 'multi_version="1.0.0.3 ';		// multi browser version
				Str+= 'AVScanWhenStart="on" ';			// whether use real-scan when first loading - on/off
				Str+= 'progressbarpolicy="3" ';			// 1 : always show UpdateBar
																						// 2 : show UpdateBar when there is some update files (default)
																						// 3 : always doesn't show UpdateBar
				Str+= 'ProgressBarPosType="rightbottom" ';	// progressbar popup location - center/rightbottom
				//=========================================================================================//		

				//Str+= 'RegParam="1" ';
				//Str+= 'RegIpPortLst="1,5004,5004,0,0,1,SAMPLE,1"';
				//Str+= 'RegIpPortLst="1,5000,5010,192.168.0.1,192.168.0.2,1,SAMPLE,1"';
				//Str+= 'RegProcLst="1,C:\\Program Files\\QFile\\QFile.exe"';
				Str+= '>';
				Str+= '</EMBED>';
				Str+= '\n<NOEMBED>no TouchEn Firewall</NOEMBED>';
			
		
			
				document.write(Str);
			}
			
}



function CK_PrintFWTag()
{

	if (getPluginType.cACTIVEX){
		PrintTEFWActiveXTag();
	} else if (getPluginType.cNPRUNTIME){
		
		var mTypeRet = checkFWMime();
		
		if (mTypeRet) {
			PrintFWEmbedTag();
		} else {
			if (!isInstallPage) {
				
			}
		}
	}
}



function HaveControl_CK() {
	if(getPluginType.cACTIVEX) {
		if(document.TEFW==null || typeof(document.TEFW) == "undefined" || document.TEFW.object == null)
			return false;
		else
			return true;
	} else {
		if(document.getElementById('tefw')==null)
			return false;
		else
			return true;
	}
}




function CK_MimeExist()
{
	var CKInstalled = false;
	var objCKKeyProMimeType = navigator.mimeTypes['application/ClientKeeperKeyPro'];
	if (objCKKeyProMimeType) {	

		if (objCKKeyProMimeType.description) {
			CKInstalled = true;
		    return true;
		}
	}
	
	if (CKInstalled == false) {
   location.replace(Multi_InstallPage);
   return false;
	}
}

function CK_CheckPlugInVersion() {
	if (navigator.cookieEnabled) {
		var useCKKeyProCookie = getCookie("KeyProCookie_TEST");
		if (useCKKeyProCookie) {
		} else {
			if(!getPluginType.cNPRUNTIME) {
				HaveControl_CK();
			} else {
			 	try{
			 		
			 		var isNeedUpdate = document.getElementById('TEFW').isUpdate();
					//IsNeedUpdate = document.getElementById('CKFW').NeedUpdate(Multi_Version);	
					if (isNeedUpdate==false){
					} else {
						//alert("¹æÈ­º®ÀÌ ¼³Ä¡µÇÁö ¾Ê¾Ò½À´Ï´Ù.\n\n ¾ÈÀüÇÑ »çÀÌÆ® ÀÌ¿ëÀ» À§ÇØ ¼³Ä¡ ÈÄ ÁøÇàÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.");
						  //window.location=Multi_InstallPage;
						 
		   window.open('./TEFW_Installer.exe','TEFW','resizable=no scrollbars=no width=100 height=100 left=50 top=50 ');
		}
				}	catch(e){
							//alert("exception : " +e);
						  //window.location=Multi_InstallPage;
						
		   window.open('./TEFW_Installer.exe','TEFW','resizable=no scrollbars=no width=100 height=100 left=50 top=50 ');
		}
			}
		}
	} else {
		alert("»ç¿ëÇÏ½Ã´Â ºê¶ó¿ìÀúÀÇ ÄíÅ°±â´ÉÀÌ ºñÈ°¼ºÈ­ µÇ¾î ÀÖ½À´Ï´Ù.\n\nÄíÅ°±â´ÉÀÌ È°¼ºÈ­µÇ¾î¾ß Å°º¸µåº¸¾È ÇÁ·Î±×·¥À» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.");
	}
}

function CK_CheckInstalled() {
	if (navigator.cookieEnabled) {
		var useCKKeyProCookie = getCookie("KeyProCookie_TEST");
		if (useCKKeyProCookie) {
		} else {
			if(!getPluginType.cNPRUNTIME) {
				if(document.TEFW==null || typeof(document.TEFW) == "undefined" || document.TEFW.object == null) {
					return true;
				} else {
				
					window.open('./TEFW_Installer.exe','TEFW','resizable=no scrollbars=no width=100 height=100 left=50 top=50 ');
				}
			} else {
				IsNeedUpdate = document.getElementById('TEFW').NeedUpdate(Multi_Version);
				if (IsNeedUpdate==false){
				
					window.open('./TEFW_Installer.exe','TEFW','resizable=no scrollbars=no width=100 height=100 left=50 top=50 ');
				} else {
				
					location.href = Multi_InstallBinary;
				}
			}
		}
	}
}

//ÄíÅ°¸¦ ÀÐ¾î¿À´Â ÇÔ¼ö
function getCookie(name) {
      allCookies=document.cookie.split('; ');
      for(i=0;i<allCookies.length;i++){
             cookieArray=allCookies[i].split('=');
             if (name==cookieArray[0]) return unescape(cookieArray[1]);
      }
      return "";
}
PrintTEFWActiveXTag();
/*
CK_PrintFWTag();
if (!isInstallPage) {

		CK_CheckPlugInVersion();
} else {
				CK_CheckInstalled();
	}			
*/
