initmenuedit();

function initmenuedit(args)
{
	var hMainWnd = dcmenuedit.GetHandle();
	var hPreviewWnd = dcmenuedit.staticmenupreview.GetHandle();
//	var hTemplateWnd = dcmenuedit.imageviewtmpl.GetHandle();
	var hTemplateWnd = dcmenuedit.staticmenupreview.GetHandle();
	var bkmusicfile = "";
	var bkimagefile = "";
	var dftColor = "RGB(0,255,255)";
	g_dvdcreator.InitMenuEditClass(	hMainWnd, 
					hPreviewWnd, 
					hTemplateWnd,
					bkmusicfile,
					bkimagefile,
					dftColor);
	var tmplpath = g_dvdcreator.GetMenuTmplDir();
	dcmenuedit.imageviewtmpl.SetDir(tmplpath);
	
}

var tmptmplshow = "Skin\\NoneMenu.jpg";
var tmptmplname = "000_nonemenu";
var tmpfontcolor = "RGB(0,255,255)";

var cfgtmplshow = "Skin\\NoneMenu.jpg";
var cfgtmplname = "000_nonemenu";
var cfgcolor = "RGB(0,255,255)";

var cfgtitle = "";
var chkmusic = "";
var cfgmusic = "";
var chkimage = "";
var cfgimage = "";
//var cfgfont = "";

function dcmenuedit_choosemenustyle(args)
{
	var str = args[2];
	
	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];
				}
			}
		}
	}
	
/*	
	g_dvdcreator.SetMenuTmplName(tmp);
	
	var tmpchk = dcmenuedit.checkboxbgdimage.GetCheck();
	var tmppic = dcmenuedit.editimagefile.GetText();
	if(tmpchk == true && tmppic.length > 0)
	{
		g_dvdcreator.MenuImageChange(tmppic);
		str = "Data\\menuSelf\\menuself.png";
	}

	dcmenuedit.staticmenupreview.SetImage(str);
	tmptmplshow = str;
	tmptmplname = tmp;
*/	

	tmptmplshow = str;
	tmptmplname = tmp;
	dcmenuedit_preview();
	
	return 1;
}

function dcmenuedit_musicchk(args)
{
	var val = dcmenuedit.checkboxbgdmusic.GetCheck();
	
	dcmenuedit.editmusicfile.SetEnable(val);
	dcmenuedit.buttonmusicchoose.SetEnable(val);
}

function dcmenuedit_choosebkmusic(args)
{
	var tmpstr = dcmenuedit.editmusicfile.GetText();
	
	var str = g_dvdcreator.ChooseFile("music", tmpstr);
	if(str.length <= 0)
	{
		dcmenuedit.editmusicfile.SetText(tmpstr);
		return 1;
	}
	
	var ret = g_dvdcreator.IsFileType("music", str);
	if(ret == false)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_openfilefail"), 1, LanguageStr("_btn_ok"));
		dcmenuedit.editmusicfile.SetText(tmpstr);
		return 1;
	}
	
	dcmenuedit.editmusicfile.SetText(str);
//	g_dvdcreator.MenuMusicChange(str);
	
	return 1;
}

function dcmenuedit_imagechk(args)
{
	var val = dcmenuedit.checkboxbgdimage.GetCheck();
	
	dcmenuedit.editimagefile.SetEnable(val);
	dcmenuedit.buttonimagechoose.SetEnable(val);
}

function dcmenuedit_choosebkimage(args)
{
	var tmpstr = dcmenuedit.editimagefile.GetText();

	var str = g_dvdcreator.ChooseFile("image", tmpstr);
	if(str.length <= 0)
	{
		dcmenuedit.editimagefile.SetText(tmpstr);
		return 1;
	}
	
	var ret = g_dvdcreator.IsFileType("image", str);
	if(ret == false)
	{
		ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_openfilefail"), 1, LanguageStr("_btn_ok"));
		dcmenuedit.editimagefile.SetText(tmpstr);
		return 1;
	}

	dcmenuedit.editimagefile.SetText(str);
//	g_dvdcreator.MenuImageChange(str);
	
	return 1;
}

/*
function dcmenuedit_choosefont(args)
{
	var str = g_dvdcreator.ChooseFont();
	dcmenuedit.editfontstyle.SetText(str);
}
*/

function dcmenuedit_choosefontcolor(args)
{
	var str = g_dvdcreator.ChooseFontColor(tmpfontcolor);
	if(str.length <= 0)
	{
		return 1;
	}
	
	tmpfontcolor = str;
}

function dcmenuedit_preview()
{
	var tmpchkmusic = dcmenuedit.checkboxbgdmusic.GetCheck();
	var tmpmusic = dcmenuedit.editmusicfile.GetText();
	var tmpchkimage = dcmenuedit.checkboxbgdimage.GetCheck();
	var tmpimage = dcmenuedit.editimagefile.GetText();
	if(tmpchkimage == false)
	{
		tmpimage = "";
	}
	var tmptitle = dcmenuedit.editfontstyle.GetText();
	
	if(tmptmplname != "000_nonemenu")
	{
		var str = "";
		str = g_dvdcreator.MenuEditPreview(	tmptmplname,
							tmptitle,
							tmpfontcolor,
							tmpchkimage,
							tmpimage);
		if(str.length > 0)
		{
			tmptmplshow = str;
		}
	}
	
	dcmenuedit.staticmenupreview.SetImage(tmptmplshow);
	
	return 1;
}

function dcmenuedit_titlechange()
{
/*	
	tmpmenutitle = dcmenuedit.editfontstyle.GetText();
	
	if(tmpmenutitle.length > 32)
	{
		tmpmenutitle = cfgtitle;
		ShowMsg("DVD Creator", "text length more than 32 characters !", 1, "OK");
		return 1;
	}

	g_dvdcreator.MenuTitleChange(tmpmenutitle);
*/	
}

function dcmenuedit_confirm(args)
{
	cfgtmplname = tmptmplname;
	cfgtmplshow = tmptmplshow;
	cfgcolor = tmpfontcolor;
	
	chkmusic = dcmenuedit.checkboxbgdmusic.GetCheck();
	cfgmusic = dcmenuedit.editmusicfile.GetText();
	if(cfgmusic.length <= 0)
	{
		chkmusic = false;
		dcmenuedit.checkboxbgdmusic.SetCheck(chkmusic);
	}
	chkimage = dcmenuedit.checkboxbgdimage.GetCheck();
	cfgimage = dcmenuedit.editimagefile.GetText();
	if(cfgimage.length <= 0)
	{
		chkimage = false;
		dcmenuedit.checkboxbgdimage.SetCheck(chkimage);
	}
	cfgtitle = dcmenuedit.editfontstyle.GetText();
	
	var menuname = cfgtmplname;
	dcmain.staticmenuname.SetText(LanguageStr(menuname));

	dcmenuedit.editmusicfile.SetEnable(chkmusic);
	dcmenuedit.buttonmusicchoose.SetEnable(chkmusic);
	
	dcmenuedit.editimagefile.SetEnable(chkimage);
	dcmenuedit.buttonimagechoose.SetEnable(chkimage);
	
	g_dvdcreator.UpdateMenuEdit(	cfgtmplname,
					cfgtitle,
					cfgcolor,
					chkimage,
					cfgimage,
					chkmusic,
					cfgmusic);
				
	dcmenuedit_preview();
					
	dcmenuedit.staticmenupreview.SetImage(cfgtmplshow);
	dcmain.staticmenupreview.SetImage(cfgtmplshow);
	
	dcmenuedit.Close();
}

function dcmenuedit_cancel(args)
{
	tmptmplname = cfgtmplname;
	tmptmplshow = cfgtmplshow;
	tmpfontcolor =cfgcolor;
	
	dcmenuedit.checkboxbgdmusic.SetCheck(chkmusic);
	dcmenuedit.editmusicfile.SetText(cfgmusic);
	dcmenuedit.checkboxbgdimage.SetCheck(chkimage);
	dcmenuedit.editimagefile.SetText(cfgimage);

	dcmenuedit.editfontstyle.SetText(cfgtitle);
	
	var menuname = cfgtmplname;
	dcmain.staticmenuname.SetText(LanguageStr(menuname));
	
	dcmenuedit.editmusicfile.SetEnable(chkmusic);
	dcmenuedit.buttonmusicchoose.SetEnable(chkmusic);
	
	dcmenuedit.editimagefile.SetEnable(chkimage);
	dcmenuedit.buttonimagechoose.SetEnable(chkimage);
	
	g_dvdcreator.UpdateMenuEdit(	cfgtmplname,
					cfgtitle,
					cfgcolor,
					chkimage,
					cfgimage,
					chkmusic,
					cfgmusic);
				
	dcmenuedit_preview();
	
	dcmenuedit.staticmenupreview.SetImage(cfgtmplshow);
	dcmain.staticmenupreview.SetImage(cfgtmplshow);
					
	dcmenuedit.Close();
}

function dcmenutmpl_choosemenustyle(args)
{
	var str = args[2];
	
	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];
				}
			}
		}
	}
//	g_dvdcreator.SetMenuTmplName(tmp);
	
	tmptmplname = tmp;
	tmptmplshow = str;
	tmpfontcolor = "RGB(0,255,255)";
	
	dcmenuedit.checkboxbgdmusic.SetCheck("false");
	dcmenuedit.editmusicfile.SetText("");
	dcmenuedit.checkboxbgdimage.SetCheck("false");
	dcmenuedit.editimagefile.SetText("");
	
	chkmusic = dcmenuedit.checkboxbgdmusic.GetCheck();
	cfgmusic = dcmenuedit.editmusicfile.GetText();
	chkimage = dcmenuedit.checkboxbgdimage.GetCheck();
	cfgimage = dcmenuedit.editimagefile.GetText();
	
	cfgtmplname = tmptmplname;
	cfgtmplshow = tmptmplshow;
	cfgcolor = tmpfontcolor;
	
	cfgtitle = "";
	
	var menuname = cfgtmplname;
	dcmain.staticmenuname.SetText(LanguageStr(menuname));

	dcmenuedit.editmusicfile.SetEnable(chkmusic);
	dcmenuedit.buttonmusicchoose.SetEnable(chkmusic);
	
	dcmenuedit.editimagefile.SetEnable(chkimage);
	dcmenuedit.buttonimagechoose.SetEnable(chkimage);
	
	g_dvdcreator.UpdateMenuEdit(	cfgtmplname,
					cfgtitle,
					cfgcolor,
					chkimage,
					cfgimage,
					chkmusic,
					cfgmusic);
				
//	dcmenuedit_preview();
					
	dcmenuedit.staticmenupreview.SetImage(cfgtmplshow);
	dcmain.staticmenupreview.SetImage(cfgtmplshow);
	
	dcmenutmpl.Close();
	
	return 1;
}
