/*INISEAL:[trjiyJX5wZ5aJOsHOk1hKKcho3A%3D%0A]*/
/**
 * @author Administrator
 */
var vp_Version = "2,0,0,4";



/* Constant */
var VP_USE_COOKIE	=	"Veraport20Use";
var VP_DEBUG_COOKIE	=	"Veraport20Debug";
var VP_TYPE_SIMPLE	=	"simple";
var VP_TYPE_MINI	=	"mini";
var VP_TYPE_NORMAL	=	"normal";
var VP_TYPE_FULL	=	"full";
var VP_TYPE_MANAGE	=	"manage";


var VP_CONF_AXINFOURL 		= "axinfourl";
var VP_CONF_TYPE 			= "type";
var VP_CONF_LOGOURL 		= "logourl";
var VP_CONF_MSGURL 			= "msgurl";
var VP_CONF_WEBINFOURL 		= "webinfourl";
var VP_CONF_INFOPAGEURL 	= "infopageurl";
var VP_CONF_LANGUAGE 		= "language";
var VP_CONF_CISENDURL 		= "clientinfosendurl";
var VP_CONF_ILSENDURL 		= "installlogsendurl";
var VP_CONF_SILENCE 		= "silence";
var VP_CONF_SENDVPINFO		= "sendvpinfo";
var VP_CONF_INSTALLGUIDE	= "installguide";



/* hanabank */
//var VP_RECV_BASE_URL		= "http://" + document.location.host + "/ibk/action/";
//var VP_DOWN_BASE_URL		= "http://" + document.location.host + "/resource/download/veraport/";
//var VP_DIST_BASE_URL		= "http://" + document.location.host + "/resource/download/veraport/dist/";

/* Wizvera */
var VP_RECV_BASE_URL		= "http://" + document.location.host + "/shttp/install/veraport/";
var VP_DOWN_BASE_URL		= "http://" + document.location.host + "/shttp/install/veraport/";
var VP_DIST_BASE_URL		= "http://" + document.location.host + "/shttp/install/veraport/";
var VP_UPDATE_URL				= "http://update.wizvera.com/veraport20/real/scfirstbank/updateinfo.xml";


/* Variable */

var vp_AxInfoUrl      		= VP_DIST_BASE_URL + "down/dist/axinfo.dist";

var vp_ClientInfoSendUrl	= VP_RECV_BASE_URL + "recvClientInfo.jsp";
var vp_LogSendUrl        	= VP_RECV_BASE_URL + "recvInstallLog.jsp";

var vp_CabUrl				= VP_DOWN_BASE_URL + "down/veraport20.cab";
var vp_ExeUrl				= VP_DOWN_BASE_URL + "down/veraport20.exe";

var vp_InstallPage			= VP_DOWN_BASE_URL + "install.html";
var vp_LogoS				= VP_DOWN_BASE_URL + "down/html/logo_small.gif";
var vp_LogoL				= "";// VP_DOWN_BASE_URL + "down/hanabank/logo_large.gif";
var vp_MsgS					= "";// VP_DOWN_BASE_URL + "down/hanabank/msg_small.gif";
var vp_MsgL					= VP_DOWN_BASE_URL + "down/html/msg_large.gif";
var vp_Html					= VP_DOWN_BASE_URL + "down/html/msg.html";


/* Initialize */
try { 
	//VP_notUse();
	//vp_setDebug();
	vp_checkBrowser();
	vp_createObject();
	vp_init();
} catch(err) {
	alert("vp_Main\n[" + err.description  + "]");
}	

/* functions */
function vp_update() {
	var obj = vp_getObject();
	if(obj == null) return "null";
	return obj.Update(VP_UPDATE_URL);
}
function vp_checkVp20Install(goInstallPage) {
	if (!vp_isUse()) return false;
	try {
		if( ((typeof(this.document.Vp20Ctl) == "undefined") || (this.document.Vp20Ctl == "undefined")
			||(this.document.Vp20Ctl == null) || (this.document.Vp20Ctl.object == null) )) {
			if (goInstallPage) vp_goVp20InstallPage();
			return false;
		}
	}
	catch(err) {
		alert("VeraPort20InstallCheck\n[" + err.description + "]");
	}
	return true;
}
function vp_checkBrowser() {
	try	{
		
		var brower_ver = "";
		if (navigator.appName == 'Netscape') {
			s = navigator.userAgent.indexOf("/");
			e = navigator.userAgent.indexOf(" ");
			brower_ver = navigator.userAgent.substring(s+1, s+4);
			vp_notUse();
		} 
		else if(navigator.cpuClass.toLowerCase() == "x64") {
			vp_notUse();
		}
		else {
			s = navigator.userAgent.indexOf("MSIE ");
			if (s < 0) vp_unsetVeraPortUse();
			tmp = navigator.userAgent.substring(s+5);
			e = tmp.indexOf(";");
			brower_ver = tmp.substring(0, 3);
			if (brower_ver<5.0) vp_notUse();
		}

		if (!vp_isUse()) {
			var msg = "Version Information[";
				msg += brower_ver + "]";
				msg += "\n\nNavigator Information\n";
				msg += "navigator.appName \t[" + navigator.appName + "]\n";
				msg += "navigator.userAgent \t[" + navigator.userAgent + "]\n";
				msg += "navigator.appCodeName \t[" + navigator.appCodeName + "]\n";
				msg += "navigator.appVersion \t[" + navigator.appVersion + "]\n";
				msg += "navigator.systemLanguage \t[" + navigator.systemLanguage + "]\n";
				msg += "navigator.javaEnabled() \t[" + navigator.javaEnabled() + "]\n";
				msg += "navigator.systemLanguage \t[" + navigator.systemLanguage + "]\n";
				msg += "navigator.language \t\t[" + navigator.language + "]\n";
				msg += "navigator.platform \t\t[" + navigator.platform + "]\n";

			vp_alert(msg);
		}

	} 
	catch(err) {
		alert("vp_CheckBrowser\n[" + err.description + "]");
	}	
}
function vp_goVp20InstallPage() {
	if (window.location.href != vp_InstallPage)
		window.location.href = vp_InstallPage;
}

function vp_getCookie( name ) {
	try {
		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;
		}
	} 
	catch(err) {
		alert("vp_getCookie\n[" + err.description + "]");
	}	
	return "";
}

function vp_isUse() {
	if (vp_getCookie("Veraport20Use") == "N") return false;
	return true;
}
function vp_setUse() {
	document.cookie=VP_USE_COOKIE+"=Y; path=/;";
}
function vp_notUse() {
	document.cookie=VP_USE_COOKIE+"=N; path=/;";
}
function vp_setDebug() {
	document.cookie=VP_DEBUG_COOKIE+"=Y; path=/;";
}
function vp_notDebug() {
	document.cookie=VP_DEBUG_COOKIE+"=N; path=/;";
}
function vp_notUseDays(days) {
	var today = new Date();
  	var expiry = new Date(today.getTime() + days * 24 * 60 * 60 * 1000); 
	document.cookie=VP_USE_COOKIE+"=N; path=/; expires=" + expiry.toGMTString();
}
function vp_isDebug() {
	if (vp_getCookie(VP_DEBUG_COOKIE) == "Y") return true;
	return false;
}

function vp_alert(msg) {
	if (vp_isDebug()) alert(msg);
}
function vp_createObject() {
	var vp_CLSID	= "CLSID:477D5B9A-6479-44F8-9718-9340119B0308";

	var objstr = "";
	objstr += '<object id="Vp20Ctl" width="1" height="1" classid="';
	objstr += vp_CLSID;
	objstr += '" codebase="';
	objstr += vp_CabUrl;
	objstr += '#version=';
	objstr += vp_Version;
	objstr += '"></object>';

	if (!vp_isUse()) return;  
	document.write(objstr);
}
function vp_getObject() {
	if(!vp_checkVp20Install(false)) return null;
	return document.getElementById("Vp20Ctl");
}
function vp_getLastError() {
	var obj = vp_getObject();
	if(obj == null) return "null";
	return obj.GetLastErrorMsg();
}
function vp_getConfigureAll() {
	var obj = vp_getObject();
	if(obj == null) return "null";
	return obj.GetConfigureAll();
}
function vp_getConfigureJson() {
	var obj = vp_getObject();
	if(obj == null) return "null";
	return obj.GetConfigureJson();
}
function vp_init() {
	vp_setAxInfoUrl(vp_AxInfoUrl);
	vp_setLogo(vp_LogoL);
	vp_setMsg(vp_MsgL);
	vp_setWebInfo(vp_Html);	
	vp_setType(VP_TYPE_MANAGE);
	vp_setLogSendUrl(vp_LogSendUrl);
	vp_setClientInfoSendUrl(vp_ClientInfoSendUrl);	

}
function vp_showVeraport(type) {
	vp_setAxInfoUrl(vp_AxInfoUrl);
	vp_setLogSendUrl(vp_LogSendUrl);
	vp_setClientInfoSendUrl(vp_ClientInfoSendUrl);

	var flag = 1;
	if(type ==  VP_TYPE_MANAGE || type ==  VP_TYPE_FULL) {
			vp_setLogo(vp_LogoL);
			vp_setMsg(vp_MsgL);
			vp_setWebInfo(vp_Html);
			if(type ==  VP_TYPE_MANAGE) {
				flag = 0;
			}
		}
	else {
		vp_setLogo(vp_LogoS);
		vp_setMsg(vp_MsgS);

	}
	vp_setConfigure("type",type);
	vp_show(flag);
}
function vp_setWebInfo(url) {
	vp_setConfigure(VP_CONF_WEBINFOURL,url);
}
function vp_setMsg(url) {
	vp_setConfigure(VP_CONF_MSGURL,url);	
}
function vp_setLogo(url) {
	vp_setConfigure(VP_CONF_LOGOURL,url);
}
function vp_setClientInfoSendUrl(url) {
	vp_setConfigure(VP_CONF_CISENDURL,url);
}
function vp_setLogSendUrl(url) {
	vp_setConfigure(VP_CONF_ILSENDURL,url);
}
function vp_setAxInfoUrl(url){
	vp_AxInfoUrl = url;
	vp_setConfigure(VP_CONF_AXINFOURL, url);
}
function vp_setType(type) {
	vp_setConfigure(VP_CONF_TYPE,type);
}
function vp_setInstallGuide(url) {
	vp_setConfigure(VP_CONF_INSTALLGUIDE,url);
}
function vp_show(flag) {
	var obj = vp_getObject();
	if(obj == null) return "null";
	vp_loadInfo();		
	obj.ShowType(flag);	
}
function vp_setConfigure(key,value) {
	var obj = vp_getObject();
	if(obj == null) return "null";
	obj.SetConfigure(key,value);		
}
function vp_uninstallAll() {
	var obj = vp_getObject();
	if(obj == null) return "null";
	obj.UninstallAll();
}
function vp_loadInfo() {
    var obj = vp_getObject();
	if(obj == null) return "null";
    var ret = obj.LoadInfo("");
	return ret;
}
function vp_SetSendVpInfo(flag) {
	vp_setConfigure(VP_CONF_SENDVPINFO,flag);	
	}

	


/* Previous version compatibility*/
function SetAxInfoName(dist_name) {
	vp_AxInfoUrl = VP_DIST_BASE_URL + dist_name;
	vp_setAxInfoUrl(vp_AxInfoUrl);
}
function VeraportShowAndInstall() {
	vp_showVeraport(VP_TYPE_MINI);
}
function VeraPortShowAndInstall() {
	vp_showVeraport(VP_TYPE_MINI);
}
function VeraportShow() {
	vp_showVeraport(VP_TYPE_MINI);
}
function VeraPortShow() {
	vp_showVeraport(VP_TYPE_MINI);
}












function GetTD(value) {
	var td = document.createElement("TD");
	td.innerText = value;
	return td;
}
function UpdateDistributeInfo(target) {
	var parent = document.getElementById(target);
	if(parent == null)
		return ;
	var obj = vp_getObject();
	if(obj == null) return "null";
	
	try {
		var distinfo = eval(obj.GetDistributeInfo());
		var info = "";
		var version = (distinfo[0].version == 0) ? "V10" : "V20";
		
		info = info + "Versoin : ";
		info = info + version;
		info = info +  " , CreateDate : " + distinfo[0].createdate;

		parent.innerText = info;
	}
	catch(e) {
	}
	
}
function UpdateInstallState(target) {

	var parent = document.getElementById(target);
	if(parent == null)
		return ;
		
	while(parent.rows != null && parent.rows.length > 0)
		parent.deleteRow(0);



	var obj = vp_getObject();
	if(obj == null) return "null";
	
	//vp_setAxInfoUrl(vp_AxInfoUrl);
	vp_loadInfo();
		
	var axinfo = eval(obj.GetAxInfo());
	var state = "";
	var type = "";
	
	try {
		for(var i=0;i<axinfo.length;i++) {
	
				
			var tr = document.createElement("TR");
			
			tr.appendChild(GetTD(axinfo[i].objectname));
			tr.appendChild(GetTD(axinfo[i].displayname));
			tr.appendChild(GetTD(axinfo[i].systemtype));
			tr.appendChild(GetTD((axinfo[i].version == 1) ? "V10" : "V20"));
			tr.appendChild(GetTD(axinfo[i].objectversion));
			
			var td;
			td 	= GetTD((axinfo[i].installstate == 0) ? "not install" : "installed");
			td.className = (axinfo[i].installstate == 0) ? "ninstall" : "install";
			tr.appendChild(td);
			
			td = GetTD((axinfo[i].objecttype == 0) ? "must" : "option");
			td.className = (axinfo[i].objecttype == 0) ? "must" : "opt";
			tr.appendChild(td);
			
			parent.appendChild(tr);
		}
	}
	catch(e) {
	}


}

