var scripts = document.getElementsByTagName("script");
var lastScript = scripts[scripts.length-1].src;
var thispath = lastScript.substring( 0, lastScript.lastIndexOf("/")+1 );

function urlthis( str )
{
		return "url(" + thispath + str +")"
}

var g_post_pd = null;

function aos_start_e8( with_pd, post_pd )
{
	window.setTimeout( function() { _aos_start_e8_onload(with_pd, post_pd); }, 100 ); 
}


function _aos_start_e8_onload( with_pd, post_pd )
{
	if( _aos_loaded() )
	{
		try
		{
			if( document.getElementById("AOSMGR").GetBuildNumber( "00" ) >= 432 )
			{
				_aos_start_e8( with_pd, post_pd );
				return ;
			}
		}
		catch( e )
		{
		}
		
		if( with_pd && post_pd )
		{
			aos_start_ex2( with_pd, post_pd );
		}
		else if( with_pd && post_pd==null )
		{
			// µ¿±â start
			aos_start( with_pd );
		}
		else if( with_pd==null && post_pd )
		{
			// ºñµ¿±â start
			aos_set_option( "asyncmode", true );
			aos_set_option( "uimode", false );				
			aos_start( post_pd );
		}
	}
	else
	{
		window.setTimeout( function() { _aos_start_e8_onload(with_pd, post_pd); }, 100 ); 
	}
}

var g_infectedcount = -1;
var g_cleancount = 0;
var g_failcount = 0;
var g_rebootrequired = 0;
var g_progress = 0;
var g_progressMax = 90;
var interval_id;


function progress_interval()
{
	g_progress += 1;
	if( g_progress > g_progressMax ) g_progress = g_progressMax;
	
	aos_set_width( "progress_bar", 276 * g_progress / 100 + "px" );
	aos_set_innerHTML( "progress_text", g_progress + "%" );

}

function _aos_start_e8( with_pd, post_pd )
{
	var pluginuimode = false;
	
	if( document.getElementById("AOSMGR").GetBuildNumber( "00" ) >= 448 )
	{
		pluginuimode = true;
	}
	
	aos_loadstring();
	
	if( pluginuimode == true )
	{
		if( aos_get_option("DllScan_UI") == "" )
		{
			aos_set_option( "DllScan_UI", "http://ahnlabdownload.nefficient.co.kr/aos/plugin/dllscan.html" );
		}
	}
	else
	{
		aos_write_layer( null, aos_modal_layer );						
		
		var logoUrl = aos_get_option("DllScan_LogoUrl");
		if( logoUrl )
		{
			document.getElementById("neo_about_bi").style.backgroundImage="url(" + logoUrl + ")";
		}
		else
		{
			document.getElementById("po_by_ahnlab").style.display='none';
		}
		
		
		aos_show_layer( "aos_modal" );
		aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_01_MSG01 );
	}

	aos_set_option( "DllScan_CloseConfirmMsg", 2 );
	aos_set_option( "DllScan_RebootMsg", 2 );	
	
	if( navigator.appName.indexOf("Internet Explorer") > 0 )
	{
		aos_set_option( "threadmode", false );
	}
	else
	{
		aos_set_option( "threadmode", true );
	}
		
	aos_set_option( "asyncmode", false );
	aos_set_option( "uimode", false );				
	aos_set_option( "aos_event_handler", on_aosmgr_event );		
	aos_set_option( "pluginuimode", pluginuimode );		

	if( with_pd == "40" )
	{
		aos_set_subclsid( "40", "59B0298B-A7B5-4045-A34E-377EDF7BCB8E" );
		aos_set_submimetype( "40", "application/ahnlab/asp/npmkd25aos" );
		aos_set_submimetype( "40", "application/ahnlab/asp/npmkd25sp" );
	}

	
	aos_set_option( "startinfo", with_pd );
	
	var start_pd = "e8";
	
	if( with_pd )
	{
		start_pd = start_pd + "|" + with_pd;
	}

	g_post_pd = post_pd;
	aos_start( start_pd );
	
	if( pluginuimode == false )
	{
		interval_id = setInterval( progress_interval, 500 );
	}
}

function start_postpd()
{
	aos_hide_layer( "aos_modal" );
	
	if( g_post_pd )
	{
		aos_set_option( "asyncmode", true );
		aos_set_option( "startinfo", g_post_pd );
		aos_start( g_post_pd );
	}
}





function on_aosmgr_event( event_name, event_param1, event_param2 )
{
	try
	{
		var aosmgr = document.getElementById("AOSMGR");
		var param1 = event_param1 ? event_param1.toString() : "";
		var param2 = event_param2 ? event_param2.toString() : "";
		
		if( event_name == "update_error" )
		{
			param1 = event_param1.toString(16);
		}
		
		aosmgr.SendEvent( event_name, param1, param2 );
	}
	catch( e )
	{
	}

	g_progress += 5;
	if( g_progress > g_progressMax ) g_progress = g_progressMax;
	aos_set_width( "progress_bar", 276 * g_progress / 100 + "px" );
	aos_set_innerHTML( "progress_text", g_progress + "%" );
	
	if( event_name == "scanfinished" )
	{	
		g_progressMax = 100;
		g_progress = 100;
		clearInterval( interval_id );
		aos_set_width( "progress_bar", 276 * g_progress / 100 + "px" );
		aos_set_innerHTML( "progress_text", g_progress + "%" );
	}
	else if( event_name == "update_error" )
	{	
		g_progressMax = 100;
		g_progress = 100;
		clearInterval( interval_id );
		aos_set_width( "progress_bar", 276 * g_progress / 100 + "px" );
		aos_set_innerHTML( "progress_text", g_progress + "%" );
		var lang = (aos_get_option("DllScan_Lang") == "en-us") ? "en_us" : "ko_kr";
		var errorcode = event_param1.toString(16);
		aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_00_ERROR + "<a target='new' href='http://ahnlabdownload.nefficient.co.kr/aos/faq/" + lang + "/faq.htm?ErrCode=" + errorcode + "'>(" + errorcode + ")</a>" );
		
		var callback = aos_get_option("DllScan_Callback");
		if( callback )
		{
			callback( event_name, event_param1, event_param2 );
		}
	}
	else if( event_name == "update_event_begin" )
	{
		aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_01_MSG02 );
		aos_set_backgroundImage( "icon_arrow_01", urlthis("icon_arrow_on.jpg") );
		aos_set_backgroundImage( "aos_loading_icon_02", urlthis("icon_02_on.jpg") );
	}
	else if( event_name == "service_start" )
	{
		if( event_param1 == 0xe8 )
		{
			aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_01_MSG03 );
			aos_set_backgroundImage( "icon_arrow_02", urlthis("icon_arrow_on.jpg") );
			aos_set_backgroundImage( "aos_loading_icon_03", urlthis("icon_03_on.jpg") );
		}
	}
	else if( event_name == "service_exit" )
	{
		if( event_param1 == 0xe8 )
		{
			g_progressMax = 100;
			g_progress = 100;
			clearInterval( interval_id );
			
			aos_set_width( "progress_bar", 276 * g_progress / 100 + "px" );
			aos_set_innerHTML( "progress_text", g_progress + "%" );
		}
	}
	else if( event_name == "reportstart"
			|| event_name == "infectedcount"
			|| event_name == "cleancount"
			|| event_name == "failcount"
			|| event_name == "liststart"
			|| event_name == "scanresult"
			|| event_name == "listend"
			|| event_name == "reportend"
			|| event_name == "rebootrequired" )
	{
		if( event_name == "infectedcount" )
		{
			g_infectedcount = event_param1;
		}
		else if( event_name == "cleancount" )
		{
			g_cleancount = event_param1;
		}
		else if( event_name == "failcount" )
		{
			g_failcount = event_param1;
		}
		else if( event_name == "rebootrequired" )
		{
			g_rebootrequired = event_param1;
		}

		var callback = aos_get_option("DllScan_Callback");
		if( callback )
		{
			callback( event_name, event_param1, event_param2 );
		}
	}
	else if( event_name == "update_complete" )
	{
		if( true == _aos_isfindlist(event_param1 ,"e8") )
		{
			if( g_infectedcount == -1 )
			{
				// scan error
				aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_00_ERROR );
			}
			else if( g_infectedcount == 0 )
			{
				aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_01_MSG04 );
				window.setTimeout( start_postpd, 1000 );
			}
			else if( g_infectedcount == g_cleancount )
			{
				if( g_rebootrequired == 0 )
				{
					aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_02_MSG01 );
					window.setTimeout( start_postpd, 1000 );
				}
				else
				{
					aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_02_MSG02 );
				}
			}
			else
			{
				if( g_failcount > 0 )
				{
					aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_02_MSG03 );
				}
				else
				{
					aos_set_innerHTML( "aos_modal_msg", NEOP_ALER_02_MSG04 );
				}
			}
		}
	}
	
	
}

