LoadLib("DVDCreatorDLL.dll");
var dvdcreator = new DVDCreator();
ExportObj(dvdcreator,"g_dvdcreator");

var targetsel = -1;
var targetstr = "";
var targettype = "";

var dcmain_disksize = 4700;

InitFunction();

LoadScript("PackagePub.js");
LoadSkin("standard");
__RefreshLanguage("English");

var logstr = "";
ExportObj(logstr, "g_logstr");

function dcwait_devchange(args)
{
	var eventtype=args[2];
	var dwdata=args[3];
  
  	g_dvdcreator.WaitDiscDeviceChange(eventtype, dwdata);
}

function InitFunction()
{
	var hMainWnd = dcmain.GetHandle();
//	var hFileListWnd = dcmain.panelfilelist.GetHandle();
	var hFileListWnd = dcmain.staticmenupreview.GetHandle();
	var hMenuViewWnd = dcmain.staticmenupreview.GetHandle();
	var hVideoViewWnd = dcmain.staticvideopreview.GetHandle();
	
	dcmain.progresscontent.SetProgressShow(false);
	
	var dcmain_ret = g_dvdcreator.InitDVD("OnMessage",hMainWnd,hFileListWnd,hMenuViewWnd,hVideoViewWnd);
	if(dcmain_ret == false || dcmain_ret == "false")
	{
		Msg(LanguageStr("_msg_programfail"));
		return 0;
	} 
	
	var strDrivers = g_dvdcreator.GetDVDDrivers();
	if (strDrivers.length > 0)
	{
		if (strDrivers.indexOf("[XXX]") != -1)
		{ 
			var nNum = 0;
			var array = strDrivers.split("[XXX]");
			if(array.length > 2)
			{
				targetsel = 0;
				targetstr = "";
				targettype = array[0];
			}
			
			for (var i=0; i<array.length; i++) 
			{
				dcmain.combodestination.AddString(array[i]);
				++nNum;
			}
			
			if (nNum > 2) 
			{
				dcmain.combodestination.SetCurSel(0);
			} 
			else 
			{
				dcmain.combodestination.SetCurSel(-1);
				dcmain.combodestination.SetText("");
			}
		}
		else 
		{
			dcmain.combodestination.SetCurSel(-1);
			dcmain.combodestination.SetText("");
		}
	}
	else 
	{
		dcmain.combodestination.SetCurSel(-1);
		dcmain.combodestination.SetText("");
	}
	g_dvdcreator.SetTarget(targettype, "");
	
	var strdisk = "";
	if(targetsel == 0)
	{
		strdisk = g_dvdcreator.GetDiskType(targettype);
	}
	
	if(strdisk=="9" || strdisk=="D9" || strdisk=="d9")
	{
		dcmain_disksize = 8500;
	}
	else 	//if(strdisk=="5")
	{
		dcmain_disksize = 4700;
	}
	
	if(dcmain_disksize == 8500)
	{
		dcmain.progresscontent.SetDecorateImage(80, "8500.png");
	}
	else
	{
		dcmain_disksize = 4700;
		dcmain.progresscontent.SetDecorateImage(80, "4700.png");
	}
	g_dvdcreator.SetDiscType(dcmain_disksize);

	dcmain.progresscontent.SetPos(0);
	dcmain.combodisktype.SetCurSelByData(dcmain_disksize);
	
	g_dvdcreator.SetFinishedAction("none");
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithnone.SetCheck(true);
	
	dcmain.slidervideotime.setfrommid(5);
	dcmain.slidervideotime.SetRange(0, 100);
	dcmain.slidervideotime.reset();
	dcmain.slidervideotime.SetMidText("00:00:00");
	dcmain.slidervideotime.SetPos(0);

	dcmain.progresscontent.SetForeImage2(80, 100, "capacity_over.png");

	dcmain.menubar.menuopedit.menuopeditedit.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditup.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditdown.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditdel.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditclear.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditselall.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditselreverse.SetEnable(false);	

	dcmain.buttonedit.SetEnable(false);
	dcmain.buttondel.SetEnable(false);
	dcmain.buttonclear.SetEnable(false);
	dcmain.buttonup.SetEnable(false);
	dcmain.buttondown.SetEnable(false);
	
	dcmain.buttonctrlplay.SetEnable(false);
	dcmain.buttonctrlstop.SetEnable(false);
	dcmain.buttonctrlgobeg.SetEnable(false);
	dcmain.buttonctrlgoend.SetEnable(false);
	
}

function dcmain_destroy()
{
	dcmain_dvdstop();
	
	g_dvdcreator.UnInitDVD();
	
	dcmain.Close();
}

var dcmain_bonmessage = false;
function OnMessage(args)
{
	dcmain_bonmessage = true;
	
	var message = args[2];
	
	if(message == 2006001)
	{		
		var npos = args[3];
	}
	else if(message == 2006002)
	{
		dcmain_dvdstop();
	}
	else if(message == 2006003)
	{
		dcmain_dvdstop();
	}
	else if(message == 2006004)
	{
		var str = args[3];
		var timedisp = "00:00:00";
		var timepos = 0;		
		
		if (str.indexOf("[???]") != -1)
		{ 
			var nNum = 0;
			var strarray = str.split("[???]");
			if(strarray.length < 2)
			{
				timedisp = "00:00:00";
				timepos = 0;		
			}
			else
			{
				timedisp = strarray[0];
				timepos = strarray[1];
			}
		}
		else
		{
			timedisp = "00:00:00";
			timepos = 0;		
		}
		
		timepos = timepos*1;
		dcmain.slidervideotime.SetMidText(timedisp);
		dcmain.slidervideotime.SetPos(timepos);
	}
	else if(message == 2006101)
	{
		dcoutput_running = 1;
		dcoutput.buttonagain.SetEnable(false);
		dcoutput.buttoncancel.SetText("_btn_abort");
		dcoutput.buttoncancel.SetTipText("_btn_abort");
	}
	else if(message == 2006102)
	{
		dcoutput_running = 0;
		if(targettype == "DVD Folder" || targettype == "ISO")
		{
			dcoutput.buttonagain.SetEnable(false);
		}
		else
		{
			dcoutput.buttonagain.SetEnable(true);
		}
		dcoutput.buttoncancel.SetText("_btn_finish");
		dcoutput.buttoncancel.SetTipText("_btn_finish");
	}
	else if(message == 2006103)
	{
		var str = args[3];
		dcoutput.staticstatus.SetText(str);
	}
	else if(message == 2006104)
	{
		var str = args[3];
		dcoutput.statictimeuse.SetText(str);
	}
	else if(message == 2006105)
	{
		var str = args[3];
	}
	else if(message == 2006106)
	{
		var npos = args[3];
		dcoutput.progressdetail.SetPos(npos);
	}
	else if(message == 2006107)
	{
		var npos = args[3];
		dcoutput.progresstotal.SetPos(npos);
	}
	else if(message == 2006108)
	{
		dcoutput.ShowModal();
	}
	else if(message == 2006109)
	{
		dcoutput_reloadclose();
	}
	else if(message == 2006110)
	{
		var str = args[3];
		dcoutput.staticdetail.SetText(str);
	}
	else if(message == 2006111)
	{
		var str = args[3];
		dcoutput.statictotal.SetText(str);
	}
	else if(message == 2006112)
	{
		var str = args[3];
		dcoutput_execresult(str);
	}
	else if(message == 2006113)
	{
		dcoutput_dealabort();
	}
	else if(message == 2006114)
	{
		dcmain_inputlicense();
	}
	else if(message == 2006115)
	{
		dcmain_destroy();
	}
	else if(message == 2006116)
	{
		dcmain.combodestination.ClearString();
		targetsel = -1;
		targetstr = "";
		targettype = "";
		var strDrivers = args[3];
		if (strDrivers.length > 0)
		{
			if (strDrivers.indexOf("[XXX]") != -1)
			{ 
				var nNum = 0;
				var array = strDrivers.split("[XXX]");
				if(array.length > 2)
				{
					targetsel = 0;
					targetstr = "";
					targettype = array[0];
				}
				
				for (var i=0; i<array.length; i++) 
				{
					dcmain.combodestination.AddString(array[i]);
					++nNum;
				}
				
				if (nNum > 2) 
				{
					dcmain.combodestination.SetCurSel(0);
				} 
				else 
				{
					dcmain.combodestination.SetCurSel(-1);
					dcmain.combodestination.SetText("");
				}
			}
			else 
			{
				dcmain.combodestination.SetCurSel(-1);
				dcmain.combodestination.SetText("");
			}
		}
		else 
		{
			dcmain.combodestination.SetCurSel(-1);
			dcmain.combodestination.SetText("");
		}
		g_dvdcreator.SetTarget(targettype, "");
	}
	else if(message == 2006201)
	{
/*
		var str = args[3];
		currmenupic = str;
		dcmenuedit.staticmenupreview.SetImage(str);
		tmptmplshow = str;
*/		
	}
	else if(message == 2006301)
	{
		dcvideoedit_stop();
	}
	else if(message == 2006302)
	{
		var str = args[3];
		var timedisp = "00:00:00";
		var timepos = 0;		
		
		if (str.indexOf("[???]") != -1)
		{ 
			var nNum = 0;
			var strarray = str.split("[???]");
			if(strarray.length < 2)
			{
				timedisp = "00:00:00";
				timepos = 0;		
			}
			else
			{
				timedisp = strarray[0];
				timepos = strarray[1];
			}
		}
		else
		{
			timedisp = "00:00:00";
			timepos = 0;		
		}
		
		timepos = timepos*1;
		dcvideoedit.slidervideotime.SetMidText(timedisp);
		dcvideoedit.slidervideotime.SetPos(timepos);
	}
	else if(message == 2006401)//OK
	{ 
		ShowMsg(LanguageStr("_product_name"), args[3], 1, LanguageStr("_btn_ok"));
		return g_msgvalue;
	}
	else if(message == 2006402)//YES OR NO
	{ 
		ShowMsg(LanguageStr("_product_name"), args[3], 2, LanguageStr("_btn_yes"), LanguageStr("_btn_no"));
		return g_msgvalue;
	}
	else if(message == 2006403)//RETRY OR CANCEL
	{ 
		ShowMsg(LanguageStr("_product_name"), args[3], 2, LanguageStr("_btn_retry"), LanguageStr("_btn_cancel"));
		return g_msgvalue;
	}
	else if(message == 2006501)
	{ 
		dcalert.message1.SetText(args[3]);
		dcalert.ShowModal();
	}
	else if(message == 2006502)
	{ 
		dcalert.message2.SetText(args[3]);
	}
	else if(message == 2006601)
	{ 
		dcwait.ShowModal();
	}
	else if(message == 2006602)
	{ 
		dcwait.Close();
	}
	else if(message == 2006603)
	{ 
		dcwait.statichint1.SetText(args[3]);
	}
	else if(message == 2006604)
	{ 
		dcwait.statichint2.SetText(args[3]);
	}
	else if(message == 2006605)
	{ 
		dcwait.staticdiscneed.SetText(args[3]);
	}
	else if(message == 2006606)
	{ 
		dcwait.staticdischave.SetText(args[3]);
	}
	else if(message == 2006607)
	{ 
		dcwait.staticspaceneed.SetText(args[3]);
	}
	else if(message == 2006608)
	{ 
		dcwait.staticspacehave.SetText(args[3]);
	}
	else if(message == 2006609)
	{ 
		dcwait.title001.SetText(args[3]);
	}
	else if(message == 2006610)
	{
		if(args[3] == "true") 
		{
			dcwait.statichint2.SetVisible(true);
			dcwait.buttonignore.SetVisible(true);
		}
		else
		{
			dcwait.statichint2.SetVisible(false);
			dcwait.buttonignore.SetVisible(false);
		}
	}
	else
	{
	}

	dcmain_bonmessage = false;
}

function dcmain_menuedit(args)
{
	dcmain_dvdstop();
	
	dcmenuedit_preview();
	dcmenuedit.ShowModal();
	
	return 1;
}

function dcmain_setting(args)
{
	dcmain_dvdstop();
	
	dcsetting_oldqa = g_Config.GetValue("basic","quality",0);
	dcsetting_oldqa = dcsetting_oldqa * 1;

	dcsetting.ShowModal();
	
	return 1;
}

function dcmain_addvideofile(args)
{
	g_logstr = "";
	
	dcmain_dvdstop();
	
	var str = g_dvdcreator.ChooseFile("video", "");
	
	if(str.length <= 0)
	{
		return 1;
	}
	//add by chengang 07-01-24
	dcmain.Refresh();
	var nNum = 0;
	var currtmp = "";
	var bret = -1;
	if (str.indexOf("[???]") != -1)
	{ 
		var array = str.split("[???]");
		for (var i=0; i<array.length; i++) 
		{
			//add file to list
			currtmp = array[i];
			bret = listinsertitem(currtmp);
			bret = bret * 1;
			if(bret == -1)
			{
				return 1;
			}
			++nNum;
		}
	}
	else 
	{
		//add file to list
		currtmp = str;
		bret = listinsertitem(currtmp);
		bret = bret * 1;
		if(bret == -1)
		{
			return 1;
		}
		nNum = 1;
	}
	
	if(g_logstr.length > 0)
	{
		dclog.staticlog.SetText(g_logstr);
		dclog.ShowModal();
	}

	dcmain_updatebutton();
	
	return 1;
}

var dcmain_videofolder = "";
function dcmain_addvideofolder(args)
{
	g_logstr = "";

	dcmain_dvdstop();
	
	var str = g_dvdcreator.ChooseVideoFolder(dcmain_videofolder);
	if(str.length <= 0)
	{
		return 1;
	}

	var nNum = 0;
	var currtmp = "";
	var bret = -1;
	if (str.indexOf("[???]") != -1)
	{ 
		var array = str.split("[???]");
		for (var i=0; i<array.length; i++) 
		{
			//add file to list
			currtmp = array[i];
			bret = listinsertitem(currtmp);
			bret = bret * 1;
			if(bret == -1)
			{
				return 1;
			}
			++nNum;
		}
	}
	else 
	{
		//add file to list
		currtmp = str;
		bret = listinsertitem(currtmp);
		bret = bret * 1;
		if(bret == -1)
		{
			return 1;
		}
		nNum = 1;
	}

	dcmain_videofolder = g_dvdcreator.GetMainPath(currtmp);
	
	if(g_logstr.length > 0)
	{
		dclog.staticlog.SetText(g_logstr);
		dclog.ShowModal();
	}
	
	dcmain_updatebutton();
	
	return 1;
}

function dcmain_ondropfile(args)
{
	g_logstr = "";

	dcmain_dvdstop();

	var dropstr = args[2];
	if(dropstr.length <= 0)
	{
		return 1;
	}
	
	var str = g_dvdcreator.ParseFileFromPath(dropstr);

	if(str.length <= 0)
	{
		return 1;
	}

	var nNum = 0;
	var currtmp = "";
	var bret = -1;
	if (str.indexOf("[???]") != -1)
	{ 
		var array = str.split("[???]");
		for (var i=0; i<array.length; i++) 
		{
			//add file to list
			currtmp = array[i];
			bret = listinsertitem(currtmp);
			bret = bret * 1;
			if(bret == -1)
			{
				return 1;
			}
			++nNum;
		}
	}
	else 
	{
		//add file to list
		currtmp = str;
		bret = listinsertitem(currtmp);
		bret = bret * 1;
		if(bret == -1)
		{
			return 1;
		}
		nNum = 1;
	}
	
	if(g_logstr.length > 0)
	{
		dclog.staticlog.SetText(g_logstr);
		dclog.ShowModal();
	}

	dcmain_updatebutton();
	
	return 1;	
}

function dcmain_capturedv(args)
{
	dcdvcapture.ShowModal();
	
	return 1;
}

var dcmain_dvdplaystatus = 0;
function dcmain_dvdplay(args)
{
/*
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		return 1;
	}
	var itemtmp = dcmain.listctrlfiles.GetItem(item[1]);
	var itemval = itemtmp[6];
	if(itemval.length <= 0)
	{
		return 1;
	}
*/	

	if(dcmain_dvdplaystatus==0)
	{
		var str = g_dvdcreator.GetCurrVideo();
		if(str.length <= 0)
		{
			return 1;
		}
		
		dcmain.buttonctrlplay.SetImage("pause.png");
		dcmain.buttonctrlplay.SetTipText("_btn_pause");
		dcmain_dvdplaystatus=1;
		
		g_dvdcreator.VideoPlay();
	}
	else
	{
		dcmain.buttonctrlplay.SetImage("play.png");
		dcmain.buttonctrlplay.SetTipText("_btn_play");
		dcmain_dvdplaystatus=0;

		g_dvdcreator.VideoPause();
	}
	
	dcmain.buttonctrlstop.SetEnable(true);
	dcmain_updateplay();
	
	return 1;
}

function dcmain_dvdstop(args)
{
	g_dvdcreator.VideoStop();
	
	dcmain_dvdplaystatus=0;
	
	dcmain.staticvideopreview.SetImage("Skin\black.png");
	dcmain.buttonctrlplay.SetImage("play.png");
	dcmain.buttonctrlplay.SetTipText("_btn_play");
	
	dcmain.slidervideotime.SetMidText("00:00:00");
	dcmain.slidervideotime.SetPos(0);
	
	dcmain.buttonctrlstop.SetEnable(false);
	dcmain.buttonctrlgobeg.SetEnable(false);
	dcmain.buttonctrlgoend.SetEnable(false);
	
	return 1;
}

function dcmain_dvdprevious(args)
{
//	g_dvdcreator.VideoPrevious();

	var nmax = dcmain.listctrlfiles.GetItemCount();
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		return 1;
	}
	
	if(item[1] <= 0)
	{
		return 1;
	}

	dcmain_dvdstop();
	
	dcmain.listctrlfiles.UnSelItem(item[1]);
	dcmain.listctrlfiles.SetCurSel(item[1]-1);
	var itemtmp = dcmain.listctrlfiles.GetItem(item[1]-1);
	var itemval = itemtmp[6];
	if(itemval.length > 0)
	{
		g_dvdcreator.SetCurrVideo(itemval);
		
		var time = g_dvdcreator.GetVideoTime(itemval);
		
		dcmain.slidervideotime.SetRange(0, time);
		dcmain.slidervideotime.SetMidText("00:00:00");
		dcmain.slidervideotime.SetPos(0);
		
		dcvideoedit.slidervideotime.SetRange(0, time);
		dcvideoedit.slidervideotime.SetMidText("00:00:00");
		dcvideoedit.slidervideotime.SetPos(0);
	}

	dcmain_dvdplay();

	dcmain_updatebutton();
	
	dcmain.buttonctrlstop.SetEnable(true);
	dcmain_updateplay();

}

function dcmain_dvdnext(args)
{
//	g_dvdcreator.VideoNext();

	var nmax = dcmain.listctrlfiles.GetItemCount();
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		return 1;
	}
	
	if(item[1] >= nmax-1)
	{
		return 1;
	}

	dcmain_dvdstop();
	
	dcmain.listctrlfiles.UnSelItem(item[1]);
	dcmain.listctrlfiles.SetCurSel(item[1]+1);
	var itemtmp = dcmain.listctrlfiles.GetItem(item[1]+1);
	var itemval = itemtmp[6];
	if(itemval.length > 0)
	{
		g_dvdcreator.SetCurrVideo(itemval);
		
		var time = g_dvdcreator.GetVideoTime(itemval);
		
		dcmain.slidervideotime.SetRange(0, time);
		dcmain.slidervideotime.SetMidText("00:00:00");
		dcmain.slidervideotime.SetPos(0);
		
		dcvideoedit.slidervideotime.SetRange(0, time);
		dcvideoedit.slidervideotime.SetMidText("00:00:00");
		dcvideoedit.slidervideotime.SetPos(0);
	}

	dcmain_dvdplay();

	dcmain_updatebutton();
	
	dcmain.buttonctrlstop.SetEnable(true);
	dcmain_updateplay();
}

function dcmain_sliderchange(args)
{

	var pos = dcmain.slidervideotime.GetPos();
	
	g_dvdcreator.VideoSeek(pos);
	
}

function dcmain_sliderbegdrap(args)
{
/*	
	var pos = dcmain.slidervideotime.GetPos();
	
	g_dvdcreator.VideoSeek(pos);
*/	
}

function dcmain_menutmpl(args)
{
	dcmain_dvdstop();
	dcmain.buttonmenutmpl.PopWindow(dcmenutmpl);
}

function dcmain_onmove(args)
{
	g_dvdcreator.WinMove();
}

function dcmain_targetchange(args)
{
	var targetlocation = "";
	
	var tmpstr = "";
	var tmpindex = dcmain.combodestination.GetCurSel();
	var strseldest = dcmain.combodestination.GetString(tmpindex);
	
	var nIndex = strseldest.indexOf("...",0);
	if (nIndex != -1) 
	{
		nIndex = strseldest.indexOf("iso",0);
		if (nIndex != -1) 
		{
			tmpstr = "ISO";
		}
		else
		{
			tmpstr = "DVD Folder";
		}
	}
	else
	{
		tmpstr = strseldest;
	}
	
	var dvdname = dcmain.editdvdname.GetText();
	var str = "";
	if(tmpstr == "DVD Folder")
	{
		var tmpdir = targetstr;
		if(tmpdir.length <= 0)
		{
			tmpdir = "";
		}
		str = g_dvdcreator.ChooseDVDFolder(tmpdir, dvdname);
		if(str.length > 0)
		{
			if(g_dvdcreator.IsRWPath(str,false) == true)
			{
				targetsel = -1;
				targetstr = str;
				targettype = tmpstr;
			}
			else
			{
				if(g_dvdcreator.IsFAT32(str) == false)
				{
					ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_errorreadonly"), 1, LanguageStr("_btn_ok"));
					str = targetstr;
				}
				else
				{
					targetsel = -1;
					targetstr = str;
					targettype = tmpstr;
				}
			
			}
		}
		else
		{
			str = targetstr;
		}
	}
	else if(tmpstr == "ISO")
	{
		str = g_dvdcreator.ChooseISOFile(dvdname);
		if(str.length > 0)
		{
			if(g_dvdcreator.IsRWPath(str,true) == true)
			{
				targetsel = -1;
				targetstr = str;
				targettype = tmpstr;
			}
			else
			{
				if(g_dvdcreator.IsFAT32(str) == false)
				{
					ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_errorreadonly"), 1, LanguageStr("_btn_ok"));
					str = targetstr;
				}
				else
				{
					targetsel = -1;
					targetstr = str;
					targettype = tmpstr;
				}
			}
		}
		else
		{
			str = targetstr;
		}
	}
	else
	{
		str = "";
		
		targetsel = tmpindex;
		targetstr = str;
		targettype = tmpstr;
	}
	
	dcmain.combodestination.SetCurSel(targetsel);
	dcmain.combodestination.SetText(targetstr);
	
	targetlocation = str;

	g_dvdcreator.SetTarget(targettype, targetlocation);
		
	return 1;
}

function dcmain_menuskinstandard(args)
{
	dcmain.menubar.menuoptool.menuoptoolskin.menuskinstandard.SetCheck(true);
	dcmain.menubar.menuoptool.menuoptoolskin.menuskinspecial.SetCheck(false);
	dcsetting.tabbasic.comboshow.SetCurSelByData("standard");
	LoadSkin("standard");
	SaveConfig();
}

function dcmain_menuskinspecial(args)
{
	dcmain.menubar.menuoptool.menuoptoolskin.menuskinstandard.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolskin.menuskinspecial.SetCheck(true);
	dcsetting.tabbasic.comboshow.SetCurSelByData("special");
	LoadSkin("special");
	SaveConfig();
}

function dcmain_menulanenglish(args)
{
	dcmain.menubar.menuoptool.menuoptoollang.menulangenglish.SetCheck(true);
	dcmain.menubar.menuoptool.menuoptoollang.menulangchinese.SetCheck(false);
	dcsetting.tabbasic.combolanguage.SetCurSelByData("English");
	__RefreshLanguage("English");
	SaveConfig();
}

function dcmain_menulangchinese(args)
{
	dcmain.menubar.menuoptool.menuoptoollang.menulangenglish.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoollang.menulangchinese.SetCheck(true);
	dcsetting.tabbasic.combolanguage.SetCurSelByData("Chinese(Simplified)");
	__RefreshLanguage("Chinese(Simplified)");
	SaveConfig();
}

function dcmain_disksizechange()
{
	var ii = dcmain.combodisktype.GetCurSel();
	dcmain_disksize = dcmain.combodisktype.GetData(ii);
	
	if(dcmain_disksize == 8500)
	{
		dcmain.progresscontent.SetDecorateImage(80, "8500.png");
	}
	else
	{
		dcmain_disksize = 4700;
		dcmain.progresscontent.SetDecorateImage(80, "4700.png");
	}
	g_dvdcreator.SetDiscType(dcmain_disksize);
	
	//add by chengang
	var dblsize = dcmain.progresscontent.curdisksize/1000;
	pos = dblsize/dcmain_disksize*80;
	pos = Math.round(pos);
	dcmain.progresscontent.SetPos(pos);

}

//add by chengang
dcmain.progresscontent.curdisksize = 0;
function getfilesize(szfile)
{
	var nsize = g_dvdcreator.GetFileSize(szfile);

	return nsize;	
}

function updateprogress(nsize)
{
	var dblsize = nsize/1000;
	var dispsize = Math.round(dblsize);
	var currstr = "        ";
	currstr += dispsize;
	currstr += " MB";
	dcmain.progresscontent.SetText(currstr);
	
	pos = dblsize/dcmain_disksize*80;
	pos = Math.round(pos);
	dcmain.progresscontent.SetPos(pos);
}

function newitem(value1,value2,value3,value4,value5,value6,value7)
{
	var items = dcmain.listctrlfiles.listitems;
	
	var itemtmp = items.NewItem();
	var itemvalue1 = itemtmp.NewValue();
	itemvalue1.value = value1;
	var itemvalue2 = itemtmp.NewValue();
	itemvalue2.value = value2;
	var itemvalue3 = itemtmp.NewValue();
	itemvalue3.value = value3;
	var itemvalue4 = itemtmp.NewValue();
	itemvalue4.value = value4;
	var itemvalue5 = itemtmp.NewValue();
	itemvalue5.value = value5;
	var itemvalue6 = itemtmp.NewValue();
	itemvalue6.value = value6;
	var itemvalue7 = itemtmp.NewValue();
	itemvalue7.value = value7;
	
	return itemtmp;
}

function listinsertitem(str)
{
	var nmax = dcmain.listctrlfiles.GetItemCount();
	if(nmax >= 99)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_filenumtoomuch"), 1, LanguageStr("_btn_ok"));
		return -1;
	}
	
	var ret = g_dvdcreator.IsFileType("video", str);
	if(ret == false || ret == "false")
	{
		g_logstr += str;
		g_logstr += "\r\n";

		return 1;		
	}
	
	var tmp = "";
	if (str.length > 0) 
	{
		if(str.indexOf("\\") != -1) 
		{ 
			var arraystr1 = str.split("\\");
			var tmp1 = arraystr1[arraystr1.length-1];
			if(tmp1.indexOf(".") != -1) 
			{ 
				var arraystr2 = tmp1.split(".");
				tmp = "";
				for(var tt=0; tt<arraystr2.length-1; tt++)
				{
					if(tmp.length > 0)
					{
						tmp += ".";
					}
					tmp += arraystr2[tt];
				}
			}
		}
	}
	
	var zoommode = dcsetting.tabbasic.combozoommode.GetCurSel();
	var zoommodestr = dcsetting.tabbasic.combozoommode.GetString(zoommode);
	

	var bitmap = "";
	var pixel = "";
	var time = "";
	
	var info = g_dvdcreator.GetVideoInfo(str);
	if(info.length <= 0)
	{
		g_logstr += str;
		g_logstr += "\r\n";
		
		return 1;
	}
	
	var array = info.split("[???]");
	bitmap = array[0];
	pixel = array[1];
	time = array[2];

	var timestr = g_dvdcreator.ConvertTimeToString(time);
	
	var itemtmp = new Array();
	itemtmp[0] = "";
	itemtmp[1] = bitmap;
	itemtmp[2] = tmp;
	itemtmp[3] = pixel;
	itemtmp[4] = zoommodestr;
	itemtmp[5] = timestr;
	itemtmp[6] = str;
	
	var itemcnt = dcmain.listctrlfiles.GetItemCount();
	dcmain.listctrlfiles.InsertItem(itemcnt, itemtmp);
	
	arrayvideorange[itemcnt] = [0];
	arraybreviarypos[itemcnt] = -1;
	
	var dblsize = getfilesize(str);
	dblsize = dblsize * 1;
	dcmain.progresscontent.curdisksize += dblsize;
	updateprogress(dcmain.progresscontent.curdisksize);

	dcmain_updatebutton();
}

function dcmain_listrclick()
{
	var nmax = dcmain.listctrlfiles.GetItemCount();
	if(nmax <= 0)
	{
		dcmain_dvdstop();
		g_dvdcreator.SetCurrVideo("");
		dcmain_updatebutton();
		return 1;
	}

	dcmenupopup.menupopupbar.menupopupedit.menupopupeditvideo.SetEnable(true);
	dcmenupopup.menupopupbar.menupopupedit.menupopupeditup.SetEnable(true);
	dcmenupopup.menupopupbar.menupopupedit.menupopupeditdown.SetEnable(true);
	dcmenupopup.menupopupbar.menupopupedit.menupopupeditdel.SetEnable(true);
	dcmenupopup.menupopupbar.menupopupedit.menupopupeditclear.SetEnable(true);
	dcmenupopup.menupopupbar.menupopupedit.menuopeditselall.SetEnable(true);
	dcmenupopup.menupopupbar.menupopupedit.menuopeditselreverse.SetEnable(true);
	
	var nmax = dcmain.listctrlfiles.GetItemCount();
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		dcmenupopup.menupopupbar.menupopupedit.menupopupeditvideo.SetEnable(false);
		dcmenupopup.menupopupbar.menupopupedit.menupopupeditup.SetEnable(false);
		dcmenupopup.menupopupbar.menupopupedit.menupopupeditdown.SetEnable(false);
		dcmenupopup.menupopupbar.menupopupedit.menupopupeditdel.SetEnable(false);
		dcmain_dvdstop();
	}
	else
	{
		if(item[1] <= 0)
		{
			dcmenupopup.menupopupbar.menupopupedit.menupopupeditup.SetEnable(false);
		}
	
		if(item[item[0]] >= nmax-1)
		{
			dcmenupopup.menupopupbar.menupopupedit.menupopupeditdown.SetEnable(false);
		}
		
		var tmpfile = g_dvdcreator.GetCurrVideo();
		var itemtmp = dcmain.listctrlfiles.GetItem(item[1]);
		var itemval = itemtmp[6];
	
		if(tmpfile != itemval)
		{
			dcmain_dvdstop();
		}
		
		if(itemval.length > 0)
		{
			g_dvdcreator.SetCurrVideo(itemval);

			var time = g_dvdcreator.GetVideoTime(itemval);
			
			dcmain.slidervideotime.SetRange(0, time);
			dcmain.slidervideotime.SetMidText("00:00:00");
			dcmain.slidervideotime.SetPos(0);
			
			dcvideoedit.slidervideotime.SetRange(0, time);
			dcvideoedit.slidervideotime.SetMidText("00:00:00");
			dcvideoedit.slidervideotime.SetPos(0);
		}	
	}
	
	dcmain_updatebutton();

	dcmenupopup.menupopupbar.menupopupedit.Popup();
}

function dcmain_listitemclick(args)
{
	var tmpfile = g_dvdcreator.GetCurrVideo();

	var nmax = dcmain.listctrlfiles.GetItemCount();
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		dcmain_dvdstop();
		g_dvdcreator.SetCurrVideo("");
		dcmain_updatebutton();
		return 1;
	}

	var itemtmp = dcmain.listctrlfiles.GetItem(item[1]);
	var itemval = itemtmp[6];

	if(tmpfile == itemval)
	{
		return 1;
	}
	
	dcmain_dvdstop();
	
	if(itemval.length > 0)
	{
		g_dvdcreator.SetCurrVideo(itemval);
		
		var time = g_dvdcreator.GetVideoTime(itemval);
		
		dcmain.slidervideotime.SetRange(0, time);
		dcmain.slidervideotime.SetMidText("00:00:00");
		dcmain.slidervideotime.SetPos(0);
		
		dcvideoedit.slidervideotime.SetRange(0, time);
		dcvideoedit.slidervideotime.SetMidText("00:00:00");
		dcvideoedit.slidervideotime.SetPos(0);
	}

	dcmain_updatebutton();
}

function dcmain_listmoveup()
{
	var nmax = dcmain.listctrlfiles.GetItemCount();
	if(nmax <= 1)
	{
		return 1;
	}
	
	var ii = 0;
	for(ii=1; ii<nmax; ii++)
	{
		var flagcurr = dcmain.listctrlfiles.IsSel(ii);
		var flagtmp = dcmain.listctrlfiles.IsSel(ii-1);
		if(flagtmp==false && flagcurr==true)
		{
			dcmain.listctrlfiles.MoveItem(ii, ii-1);

			var tmprange = arrayvideorange[ii];
			var tmppos = arraybreviarypos[ii];
			arrayvideorange[ii] = arrayvideorange[ii-1];
			arraybreviarypos[ii] = arraybreviarypos[ii-1];
			arrayvideorange[ii-1] = tmprange;
			arraybreviarypos[ii-1] = tmppos;
			
		}
	}

	dcmain_updatebutton();	

	dcmain_updateplay();
}

function dcmain_listmovedown()
{
	var nmax = dcmain.listctrlfiles.GetItemCount();
	if(nmax <= 1)
	{
		return 1;
	}
	
	var ii = 0;
	for(ii=nmax-2; ii>=0; ii--)
	{
		var flagcurr = dcmain.listctrlfiles.IsSel(ii);
		var flagtmp = dcmain.listctrlfiles.IsSel(ii+1);
		if(flagtmp==false && flagcurr==true)
		{
			dcmain.listctrlfiles.MoveItem(ii, ii+1);
			
			var tmprange = arrayvideorange[ii];
			var tmppos = arraybreviarypos[ii];
			arrayvideorange[ii] = arrayvideorange[ii+1];
			arraybreviarypos[ii] = arraybreviarypos[ii+1];
			arrayvideorange[ii+1] = tmprange;
			arraybreviarypos[ii+1] = tmppos;
		}
	}
	
	dcmain_updatebutton();	

	dcmain_updateplay();
}

function dcmain_videodel(args)
{
	dcmain_dvdstop();
	
	g_dvdcreator.SetCurrVideo("");
	
	var nmax = dcmain.listctrlfiles.GetItemCount();
	if(nmax <= 0)
	{
		g_dvdcreator.ClearMemory();
	}
	
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		return 1;
	}

	var tt = 0;
	for(tt=item[0]; tt>=1; tt--)
	{
		var itemtmp = dcmain.listctrlfiles.GetItem(item[tt]);
		var itemval = itemtmp[6];

		dcvideoedit.slidervideotime.reset();
		if(arrayvideorange[item[tt]][0] == 0)
		{
			dcvideoedit.slidervideotime.SetSelectRange();
		}
		else
		{
			dcvideoedit.slidervideotime.SetSelectRange(arrayvideorange[item[tt]]);
		}
		var tmpsize = getlengthfromrange(itemval);
		dcvideoedit.slidervideotime.reset();
		tmpsize = tmpsize * 1;
		dcmain.progresscontent.curdisksize -= tmpsize;
		if(dcmain.progresscontent.curdisksize <= 0)
		{
			dcmain.progresscontent.curdisksize = 0;
		}

		dcmain.listctrlfiles.DeleteItem(item[tt]);
	
		var ii = 0;
		for(ii=item[tt]; ii<nmax-1; ii++)
		{
			arrayvideorange[ii] = arrayvideorange[ii+1];
			arraybreviarypos[ii] = arraybreviarypos[ii+1];
		}
	}
	
	updateprogress(dcmain.progresscontent.curdisksize);

	dcmain_updatebutton();
	
	dcmain.buttonctrlplay.SetEnable(false);
	dcmain.buttonctrlstop.SetEnable(false);
	dcmain.buttonctrlgobeg.SetEnable(false);
	dcmain.buttonctrlgoend.SetEnable(false);
}

function dcmain_videoclear(args)
{
	dcmain_dvdstop();
	
	g_dvdcreator.SetCurrVideo("");	

	dcmain.listctrlfiles.ClearItem();
	
	for(var ii=0; ii<arraybreviarypos.length; ii++)
	{
		arrayvideorange[ii][0] = 0;
		arraybreviarypos[ii] = -1;
	}

	g_dvdcreator.ClearMemory();
	
	dcmain.progresscontent.curdisksize = 0;
	updateprogress(dcmain.progresscontent.curdisksize);
	
	dcmain_updatebutton();	
	
	dcmain.buttonctrlplay.SetEnable(false);
	dcmain.buttonctrlstop.SetEnable(false);
	dcmain.buttonctrlgobeg.SetEnable(false);
	dcmain.buttonctrlgoend.SetEnable(false);
}

function dcmain_videoall(args)
{
	dcmain_dvdstop();

	dcmain.listctrlfiles.SelectAll();
}

function dcmain_videoreverse(args)
{
	dcmain_dvdstop();
	
	dcmain.listctrlfiles.InvertSelect();
}

function ClearVideoList()
{
	dcmain_dvdstop();
	
	g_dvdcreator.ClearVideoPara();	
}
	
function AddVideoList()
{
	var bhavedisc = false;
	
	var nmax = dcmain.listctrlfiles.GetItemCount();
	
	for(var ii=0; ii<nmax; ii++)
	{
		var item1 = dcmain.listctrlfiles.GetItem(ii);
		var val0 = item1[6];
		var val1 = item1[2];
		var val2 = item1[3];
		var val3 = item1[4];
		var val4 = arrayvideorange[ii];
		var val5 = arraybreviarypos[ii];
		
		g_dvdcreator.AddVideoPara(val0, val1, val2, val3, val4, val5);
		
		if(bhavedisc == false)
		{
			if(g_dvdcreator.IsRWPath(val0,true) == false)
			{
				if(g_dvdcreator.IsFAT32(val0) == false)
				{
					bhavedisc = true;
				}
			}
		}
	}

	return bhavedisc;	
}

function dcmain_dvdoutput(args)
{
	dcmain_dvdstop();
	
	var dvdname = dcmain.editdvdname.GetText();
	
	if(dvdname.length <= 0)
	{
//		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_needdvdname"), 1, LanguageStr("_btn_ok"));
//		return 1;
		dvdname = "";
	}
	g_dvdcreator.SetDVDName(dvdname);
	
	var itemcnt = dcmain.listctrlfiles.GetItemCount();
	if(itemcnt <= 0)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_listempty"), 1, LanguageStr("_btn_ok"));
		return 1;
	}
	
	var diff = dcmain.progresscontent.curdisksize - dcmain_disksize*1000;
	if(diff >= 0)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_unfitsize"), 2, LanguageStr("_btn_yes"), LanguageStr("_btn_no"));
		if(g_msgvalue != 1)
		{
			return 1;
		}
	}
	
	g_dvdcreator.SetVideoSize(dcmain.progresscontent.curdisksize);

	if(targetsel==-1 && targettype.length<=0)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_nodevice"), 1, LanguageStr("_btn_ok"));
		return 1;
	}	

	ClearVideoList();
	var bhavedisc = AddVideoList();
	
	if(bhavedisc == true)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_havesourcefromdisc"), 2, LanguageStr("_btn_yes"), LanguageStr("_btn_no"));
		if(g_msgvalue != 1)
		{
			return 1;
		}
	}
	
	var skinstr = g_Config.GetValue("basic","skinstr","standard");
	var gifname = "skin\\" + skinstr + "\\copynow.gif";
	
	var ret = g_dvdcreator.StartBurn();
	if(ret == "false" || ret == false)
	{
		dcoutput_running = 0;
		dcoutput.progressdetail.SetPos(0);
		dcoutput.progresstotal.SetPos(0);
		dcoutput.buttonagain.SetEnable("false");
		dcoutput.buttoncancel.SetText("_btn_abort");
		dcoutput.buttoncancel.SetTipText("_btn_abort");
		dcoutput.statictimeuse.SetText("00:00:00");
		dcoutput.staticphoto.Stop();

		dcoutput.staticphoto.LoadGif(gifname);
		
		return 1;
	}

	dcoutput_running = 1;
	dcoutput.progressdetail.SetPos(0);
	dcoutput.progresstotal.SetPos(0);
	dcoutput.buttonagain.SetEnable("false");
	dcoutput.buttoncancel.SetText("_btn_abort");
	dcoutput.buttoncancel.SetTipText("_btn_abort");
	dcoutput.statictimeuse.SetText("00:00:00");
	dcoutput.staticphoto.Stop();

	dcoutput.staticphoto.LoadGif(gifname);
	
	dcoutput.staticphoto.Start();
	dcoutput.ShowModal();

	return 1;
}

function getlengthfromrange(str)
{
	var fullsize = getfilesize(str);
	fullsize = fullsize * 1;
	if(fullsize <= 0)
	{
		return fullsize;
	}
	
	var tmplen = dcvideoedit.slidervideotime.geteditlen();
	tmplen = tmplen * 1;
	if(tmplen <= 0)
	{
		return fullsize;
	}
	
	var info = g_dvdcreator.GetVideoInfo(str);
	if(info.length <= 0)
	{
		return fullsize;
	}
	
	var array = info.split("[???]");
	time = array[2];
	time = time * 1;
	
	var editsize = fullsize * tmplen / time;

	return editsize;
}

function dcmain_videoedit(args)
{
	dcmain_dvdstop();
	
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		return 1;
	}
	var itemtmp = dcmain.listctrlfiles.GetItem(item[1]);
	var itemval = itemtmp[6];
	if(itemval.length <= 0)
	{
		return 1;
	}
	
	var titlestr = itemtmp[2];
	dcvideoedit.title002.SetText(titlestr);

	dcvideoedit.slidervideotime.SetMidText("00:00:00");
	dcvideoedit.slidervideotime.SetPos(0);
	
	g_dvdcreator.InitVideoEditPara();
	dcvideoedit_curritem = item[1];
	dcvideoedit.slidervideotime.reset();
	if(arrayvideorange[dcvideoedit_curritem][0] == 0)
	{
		dcvideoedit.slidervideotime.SetSelectRange();
	}
	else
	{
		dcvideoedit.slidervideotime.SetSelectRange(arrayvideorange[dcvideoedit_curritem]);
	}
	tmpbreviarypos = arraybreviarypos[dcvideoedit_curritem];
	
	dcvideoedit_oldsize = getlengthfromrange(itemval);
	
	dcvideoedit.buttonctrlplay.SetEnable(true);
	dcvideoedit.buttonctrlstop.SetEnable(false);
	dcvideoedit.buttonctrlgobeg.SetEnable(false);
	dcvideoedit.buttonctrlgoend.SetEnable(false);
	
	dcvideoedit.ShowModal();
	
	return 1;
}

function dcmain_help(args)
{
	var urlstr = "dvdcreator.chm";
	if(urlstr.length <= 0)
	{
		return 1;
	}
	
	GotoUrl(urlstr);
}

function dcmain_buy(args)
{
	var urlstr = Product.GetBuyUrl();
	if(urlstr.length <= 0)
	{
		return 1;
	}

	GotoUrl(urlstr);
}

function dcmain_inputlicense(args)
{
	var reginfo = Product.GetRegInfo();
	dcregister.regname.SetText(reginfo[0]);
	dcregister.regcode.SetText("");
	dcregister.regok.SetEnable(false);
	
	dcregister.ShowModal();
}

function dcmain_support(args)
{
	var urlstr = Product.GetSupportUrl();
	if(urlstr.length <= 0)
	{
		return 1;
	}

	GotoUrl(urlstr);
}

function dcmain_menuwithnone(args)
{
	g_dvdcreator.SetFinishedAction("none");
	
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithnone.SetCheck(true);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithpoweroff.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithsleep.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithwait.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithquit.SetCheck(false);
}

function dcmain_menuwithpoweroff(args)
{
	g_dvdcreator.SetFinishedAction("poweroff");
	
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithnone.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithpoweroff.SetCheck(true);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithsleep.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithwait.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithquit.SetCheck(false);
}

function dcmain_menuwithsleep(args)
{
	g_dvdcreator.SetFinishedAction("sleep");
	
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithnone.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithpoweroff.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithsleep.SetCheck(true);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithwait.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithquit.SetCheck(false);
}

function dcmain_menuwithwait(args)
{
	g_dvdcreator.SetFinishedAction("wait");
	
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithnone.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithpoweroff.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithsleep.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithwait.SetCheck(true);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithquit.SetCheck(false);
}

function dcmain_menuwithquit(args)
{
	g_dvdcreator.SetFinishedAction("quit");
	
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithnone.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithpoweroff.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithsleep.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithwait.SetCheck(false);
	dcmain.menubar.menuoptool.menuoptoolfinished.menuwithquit.SetCheck(true);
}

function dcmain_about(args)
{
	dcabout.ShowModal();
}

function dcmain_listviewnormal(args)
{
	dcmain.listctrlfiles.SetItemHeight(36);
	dcmain.listctrlfiles.SetColumnWidth(1,54);
	
	dcmain.buttonview001.SetImage("normalview1.png");
	dcmain.buttonview002.SetImage("fileview.png");

}

function dcmain_listviewfile(args)
{
	dcmain.listctrlfiles.SetItemHeight(24);
	dcmain.listctrlfiles.SetColumnWidth(1,0);

	dcmain.buttonview001.SetImage("normalview.png");
	dcmain.buttonview002.SetImage("fileview1.png");

}

function dcmain_updatebutton()
{
	dcmain.menubar.menuopedit.menuopeditedit.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditup.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditdown.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditdel.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditclear.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditselall.SetEnable(false);	
	dcmain.menubar.menuopedit.menuopeditselreverse.SetEnable(false);	

	dcmain.buttonedit.SetEnable(false);
	dcmain.buttondel.SetEnable(false);
	dcmain.buttonclear.SetEnable(false);
	dcmain.buttonup.SetEnable(false);
	dcmain.buttondown.SetEnable(false);
	
	dcmain.buttonctrlplay.SetEnable(false);
//play control change status when play button down	
/*	
	dcmain.buttonctrlstop.SetEnable(false);
	dcmain.buttonctrlgobeg.SetEnable(false);
	dcmain.buttonctrlgoend.SetEnable(false);
*/

	var nmax = dcmain.listctrlfiles.GetItemCount();
	if(nmax >= 1)
	{
		dcmain.menubar.menuopedit.menuopeditclear.SetEnable(true);	
		dcmain.menubar.menuopedit.menuopeditselall.SetEnable(true);	
		dcmain.menubar.menuopedit.menuopeditselreverse.SetEnable(true);	
		
		dcmain.buttonclear.SetEnable(true);
	}
	
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		g_dvdcreator.SetCurrVideo("");
		return 1;
	}
	else
	{
		dcmain.menubar.menuopedit.menuopeditedit.SetEnable(true);	
		dcmain.menubar.menuopedit.menuopeditdel.SetEnable(true);	
		
		dcmain.buttonedit.SetEnable(true);
		dcmain.buttondel.SetEnable(true);

		dcmain.buttonctrlplay.SetEnable(true);
	}
	
	if(item[1] > 0)
	{
		dcmain.menubar.menuopedit.menuopeditup.SetEnable(true);	
		
		dcmain.buttonup.SetEnable(true);
	}

	if(item[1] < nmax-1)
	{
		dcmain.menubar.menuopedit.menuopeditdown.SetEnable(true);	
	
		dcmain.buttondown.SetEnable(true);
	}
	
	return 1;
}

function dcmain_updateplay()
{
	var nmax = dcmain.listctrlfiles.GetItemCount();
	
	var item = dcmain.listctrlfiles.GetCurSel();
	if(item[0] <= 0)
	{
		g_dvdcreator.SetCurrVideo("");
		return 1;
	}
	
	if(item[1] > 0)
	{
		dcmain.buttonctrlgobeg.SetEnable(true);
	}
	else
	{
		dcmain.buttonctrlgobeg.SetEnable(false);
	}

	if(item[1] < nmax-1)
	{
		dcmain.buttonctrlgoend.SetEnable(true);
	}
	else
	{
		dcmain.buttonctrlgoend.SetEnable(false);
	}
	
	return 1;
}

function dcmain_devchange(args)
{
	if(dcoutput_running == 1)
	{
		return;
	}
	
	var eventtype=args[2];
	var dwdata=args[3];
  
  	g_dvdcreator.DeviceChange(eventtype, dwdata);
}


