/**********************************************************************
ÀÛ¼ºÀÚ     :¿À¼¼Çü
ÀÛ¼ºÀÏ     :2009.01.16
ÃÖÁ¾¼öÁ¤ÀÏ :2009.01.21
**********************************************************************/
var SECURITY       = new CSecurity();
var CHECK          = new CCheck();
var COOKIE         = new CCookie();
var AOS            = new CAOS();
var mkd_usb_detect = 1;
var disable        = false; // true : »ç¿ëÁßÁö / false : »ç¿ë
var isInstalled    = null;
function CAOS() {
	this.keycrypt = _keycrypt;
	this.firewall = _firewall;
	this.decrypt  = _decrypt;

	function _setClassId() {
		aos_set_subclsid("40","59B0298B-A7B5-4045-A34E-377EDF7BCB8E");
	}
	function _aos() {
		aos_set_authinfo( "aosmgr_dnf.html" );
		aos_set_option( "uimode", true );
		aos_set_option( "asyncmode", false );
	}
	function _write_object() {
		if( !aos_loaded() ) {
			_setPosition();
			_setObjStyle()
			aos_write_object();
		}
	}
	function _setPosition() {
		aos_set_option("obj_position","beforeEnd");
	}
	function _setProtectLevel() {
		aos_set_option( "mkd_protect_level", "default" ); //default, low
	}
	function _start(arg) {
		aos_start(arg);
	}
	
	function _keycrypt() {
		if(!disable) {
			_setClassId();
			//_aos();
			_aos_ak();
			_write_object();
			_setProtectLevel();
			_start('40');
		} else {
			//
		}
	}
	function _firewall() {
		if(!disable) {
			_aos();
			_write_object();
			_start('e5');
			document.getElementById('firewall_check').checked = true;
		} else {
			//
		}
	}
	function _decrypt( formName ) {
		if(!disable) {
			aos_copy_to_form(formName);
		} else {
			//
		}
	}
	function _aos_ak() {
		aos_set_authinfo( "aosmgr_dnf_ak.html" );
		aos_set_option( "uimode", true );
		aos_set_option( "asyncmode", false );
	}
	function _start_ex() {
		aos_start_ex(); // AOS Anti-Keylogger+Firewall ½ÇÇà
	}
	// AOS Anti-Keylogger+Firewall ½ÇÇàµÇ´Â °æ¿ì
	function _keycrypt_and_firewall() {
		if(!disable) {
			_setClassId();
			_aos();
			_write_object();
			_start_ex();
			document.getElementById('firewall_check').checked = true;
		} else {
			//
		}
	}
	function _setObjStyle() {
		aos_set_option("obj_style","hideout");
	}
}

function CSecurity() {
	this.onKeyCrypt    = _keycrypt;
	this.onFireWall    = _firewall;
	this.onAOSDownload = _AOSDownload;

	function _AOSDownload() {
		DISPLAY.hideLayerKeypro();
		document.location = "http://d-fighter.nefficient.co.kr/samsungdnf/neople/installer/InstAosmgr.exe";
	}
	function _keycrypt() {
		if ( getUserAgentType() ) {
			DISPLAY.hideLayerKeypro();
			AOS.keycrypt();
		}
	}
	function _firewall() {
		DISPLAY.hideLayerKeypro();
		AOS.firewall();
	}
}

function CCheck() {
	this.isInstalledFireWall = _isInstalledFirewall;
	this.isInstalledKeyCrypt = _isInstalledKeyCrypt;
	this.isRunningFireWall   = _isRunningFireWall;
	this.isRunningKeyCrypt   = _isRunningKeyCrypt;

	function _isInstalledFirewall() {
		/*
		if( !aos_loaded() ) { 
			aos_write_object();
			AOS.firewall();
		}
		*/

		if( !aos_loaded() ) aos_write_object();
		var checkupdate = _aos_checkupdate("e5");
		if(checkupdate == 'undefined' || checkupdate == 1) {
			return false;
		} else {
			return true;
		}

		//return aos_isinstalled("e5");
		//return aos_isrunning("e5");
		//return _isInstalledActiveX("aosmgr.aosmgrCtrl.1");
	}
	function _isInstalledKeyCrypt() {
		if( !aos_loaded() ) { 
			aos_write_object();
			AOS.keycrypt();
		}
		/*
		if(_aos_checkupdate("40") == 'undefined' || _aos_checkupdate("40") == 1) {
			return false;
		} else {
			return true;
		}
		*/
		/*
		if(isInstalled == null) {
			isInstalled = _aos_checkupdate("40");
		}
		if(isInstalled == 'undefined' || isInstalled == 1) {
			return false;
		} else {
			return true;
		}
		*/
		//return aos_isinstalled("40");
		return aos_isrunning("40");
		//return _isInstalledActiveX("mkd25aos.mkd25aosCtrl.1");
	}
	function _isRunningFireWall() {
		return aos_isrunning("e5");
	}
	function _isRunningKeyCrypt() {
		return aos_isrunning("40");
	}
	function _isInstalledActiveX(objName) {
		var isInstalled = false;
		try {
			var obj = new ActiveXObject(objName);
			
			if(obj) {
				isInstalled = true;
			} else {
				isInstalled = false;
			}
		} catch(e) {
			isInstalled = false;
		}
		//isInstalled = false;
		return isInstalled;
	}
}

function CCookie() {
	this.setCookies = _setCookies;
	this.getCookie  = _getCookie;

	function _setCookies(name, value, days) {
		_setCookieTime(name, value, days * 24 * 60 * 60 * 1000);
	}
	function _getCookie(uName) {
		var strCookie = " " + window.document.cookie;
		var ptrFr = strCookie.indexOf(" " + uName + '=');

		if (ptrFr != -1) {
			ptrFr = ptrFr + uName.length + 2;
			ptrTo = strCookie.indexOf(';', ptrFr);

			if (ptrTo == -1) {
				ptrTo = strCookie.length;
			}
			return unescape(strCookie.substring(ptrFr, ptrTo));
		} else {
			return "";
		}
	}
	function _setCookieTime(name, value, mSecond) {
		var today  = new Date();
		var expire = new Date(today.getTime() + mSecond);

		window.document.cookie = name + "=" + escape(value)
			+ ((expire) ? "; expires=" + expire.toGMTString() : "");
	}
}

var DISPLAY = {
	viewLayer: function(funcType) {
		if(funcType == 'KeyCrypt') {
			onSecurity = function() {
				SECURITY.onKeyCrypt();
				//SECURITY.onAOSDownload()
			}
			secuType01 = "keydefense01";
			secuType02 = "keydefense02";

		} else if(funcType == 'FireWall') {
			onSecurity = function() {
				SECURITY.onFireWall();
				//SECURITY.onAOSDownload()
			}
			secuType01 = "firewall01";
			secuType02 = "firewall02";
		}

		var strHTML = [];

		strHTML.push("<div style='z-index:100;width:100%;height:100%;'>");
		strHTML.push("<table width='434' height='483'  border='0' cellpadding='0' cellspacing='0'>");
		strHTML.push("<tr><td height='291'><img src='http://img.d-fighter.com/img/notice/200901/"+secuType01+".jpg'></td></tr>");
		strHTML.push("<tr><td height='192'><img src='http://img.d-fighter.com/img/notice/200901/"+secuType02+".jpg' border='0' usemap='#Map'></td></tr>");
		strHTML.push("</table>");

		if(funcType == 'KeyCrypt') {
			strHTML.push("<map name='Map'><area shape='rect' coords='93,100,213,131' href='javascript:onSecurity();'>");
			strHTML.push("<area shape='rect' coords='221,100,341,131' href='javascript:DISPLAY.hideLayerKeypro();'>");
			strHTML.push("<area shape='rect' coords='362,154,411,174' href='javascript:DISPLAY.hideLayerKeypro();'></map>");
		} else if(funcType == 'FireWall') {
			strHTML.push("<map name='Map'><area shape='rect' coords='93,68,213,99' href='javascript:onSecurity();'>");
			strHTML.push("<area shape='rect' coords='221,68,341,99' href='javascript:DISPLAY.hideLayerKeypro();'>");
			strHTML.push("<area shape='rect' coords='362,154,411,174' href='javascript:DISPLAY.hideLayerKeypro();'></map>");
		}

		strHTML.push("</div>");

		if(document.all.keypro_layer2) {
			document.all.keypro_layer2.style.visibility = 'visible';
			document.all.keypro_layer2.innerHTML = strHTML;

			strHTML = strHTML.join("");

			keypro_layer2.style.setExpression("left", "document.body.clientWidth/2 - keypro_layer2.offsetWidth/2"); // ·¹ÀÌ¾îÀÇ x Ãà À§Ä¡¸¦ ¼³Á¤ ÇÕ´Ï´Ù
			keypro_layer2.style.setExpression("top", "document.body.clientHeight/2 - keypro_layer2.offsetHeight/2"); // ·¹ÀÌ¾îÀÇ yÃà À§Ä¡¸¦ ¼³Á¤ ÇÕ´Ï´Ù
		}
	},
	hideLayerKeypro: function() {
		if(document.all.keypro_layer2) {
			document.all.keypro_layer2.style.visibility = "hidden";
		}
	}
};

var installKeyCrypt = function() {
	if(CHECK.isInstalledKeyCrypt()) {
		if(!CHECK.isRunningKeyCrypt()) {
			SECURITY.onKeyCrypt();
		}
		return false;
	} else {
		DISPLAY.viewLayer('KeyCrypt');
		focus();
		return false;
	}
};

var installFireWall = function() {
	firewallCheck = document.getElementById('firewall_check').checked;
	COOKIE.setCookies('isUseSecurity', firewallCheck, 365);

	if(firewallCheck) {
		if(CHECK.isInstalledFireWall()) {
			if(!CHECK.isRunningFireWall()) {
				SECURITY.onFireWall();
			} else {
				//
			}
		} else {
			firewallCheck = false;
			DISPLAY.viewLayer('FireWall');
			COOKIE.setCookies('isUseSecurity', false, 365);
			return false;
		}
	}
};

var beforeSubmit = function( formName ) {
	if(CHECK.isInstalledKeyCrypt()) {
		if(CHECK.isRunningKeyCrypt()) {
			AOS.decrypt( formName );
		} else {
			SECURITY.onKeyCrypt();
		}
	} else {
		DISPLAY.viewLayer('KeyCrypt');
		return false;
	}
};

var getUserAgentType = function() {
	if ( new RegExp(/MSIE/).test( navigator.userAgent ) ) {
		return true;
	} else {
		return false;
	}
}