//handle ini file,produce g_Config object
var ini = new JSIniFile("dvdcreator_cfg.ini");
if(!ini.ReadFile())
{
	ini.WriteFile();
}
ExportObj(ini,"g_Config");
initmessage();

function initmessage(args)
{
	ReadConfig();
	
	dcsetting_setparams();
}

var dcsetting_oldqa = 0;
var dcsetting_newqa = 0;

function SaveConfig(args)
{
	var langindex = dcsetting.tabbasic.combolanguage.GetCurSel();
	var langstr = dcsetting.tabbasic.combolanguage.GetData(langindex);
	Product.SetString("language",langstr);
	
	var skin = dcsetting.tabbasic.comboshow.GetCurSel();
	var skinstr = dcsetting.tabbasic.comboshow.GetData(skin);
	var speed = dcsetting.tabbasic.combospeed.GetCurSel();
	var speedstr = dcsetting.tabbasic.combospeed.GetData(speed);
	var tempdir = dcsetting.tabbasic.editlocation.GetText();
	if(tempdir.length <= 0)
	{
		tempdir = g_dvdcreator.GetTempDirDft();
	}
	var deltemp = dcsetting.tabbasic.checkboxdeltempfile.GetCheck();
	var tvsetting = dcsetting.tabbasic.combotvsetting.GetCurSel();
	var tvsettingstr = dcsetting.tabbasic.combotvsetting.GetString(tvsetting);
	var filmscale = dcsetting.tabbasic.combofilmscale.GetCurSel();
	var filmscalestr = dcsetting.tabbasic.combofilmscale.GetString(filmscale);
	var zoommode = dcsetting.tabbasic.combozoommode.GetCurSel();
	var zoommodestr = dcsetting.tabbasic.combozoommode.GetString(zoommode);
//	var filmlevel = dcsetting.tabbasic.combofilmlevel.GetCurSel();
	var filmlevel = 0;
//	var filmlevelstr = dcsetting.tabbasic.combofilmlevel.GetString(filmlevel);
	var filmlevelstr = "R";
	var quality = dcsetting.tabbasic.groupquality.GetCheck();
	var straightplay = dcsetting.tabbasic.checkboxplay.GetCheck();
	var autochapter = dcsetting.tabbasic.checkboxchapter.GetCheck();
	var chaptertime = dcsetting.tabbasic.editspintime.GetValue();
	if(autochapter == true && chaptertime <= 0)
		chaptertime = 15;
	var usebreviary = dcsetting.tabbasic.checkboxbreviary.GetCheck();
	var breviarytime = dcsetting.tabbasic.editspinlength.GetValue();
	if(usebreviary == true && breviarytime <= 0)
		breviarytime = 5;
		
//	g_Config.SetValue("basic","langindex",langindex);
//	g_Config.SetValue("basic","langstr",langstr);
	g_Config.SetValue("basic","skin",skin);
	g_Config.SetValue("basic","skinstr",skinstr);
	g_Config.SetValue("basic","speed",speed);
	g_Config.SetValue("basic","speedstr",speedstr);
	g_Config.SetValue("basic","tempdir",tempdir);
	g_Config.SetValue("basic","deltemp",deltemp);
	g_Config.SetValue("basic","tvsetting",tvsetting);
	g_Config.SetValue("basic","tvsettingstr",tvsettingstr);
	g_Config.SetValue("basic","filmscale",filmscale);
	g_Config.SetValue("basic","filmscalestr",filmscalestr);
	g_Config.SetValue("basic","zoommode",zoommode);
	g_Config.SetValue("basic","zoommodestr",zoommodestr);
	g_Config.SetValue("basic","filmlevel",filmlevel);
	g_Config.SetValue("basic","filmlevelstr",filmlevelstr);
	g_Config.SetValue("basic","quality",quality);
	g_Config.SetValue("basic","straightplay",straightplay);
	g_Config.SetValue("basic","autochapter",autochapter);
	g_Config.SetValue("basic","chaptertime",chaptertime);
	g_Config.SetValue("basic","usebreviary",usebreviary);
	g_Config.SetValue("basic","breviarytime",breviarytime);
	
	g_Config.WriteFile();
	
	dcsetting_setparams();
	
	dcsetting_newqa = g_Config.GetValue("basic","quality",0);
	dcsetting_newqa = dcsetting_newqa * 1;
	if(dcsetting_oldqa != dcsetting_newqa)
	{
		if(dcsetting_oldqa == 0)
		{
			dcmain.progresscontent.curdisksize = dcmain.progresscontent.curdisksize / 1;
		}
		else if(dcsetting_oldqa == 1)
		{
			dcmain.progresscontent.curdisksize = dcmain.progresscontent.curdisksize / 0.75;
		}
		else
		{
			dcmain.progresscontent.curdisksize = dcmain.progresscontent.curdisksize / 0.67;
		}
		
		if(dcsetting_newqa == 0)
		{
			dcmain.progresscontent.curdisksize = dcmain.progresscontent.curdisksize * 1;
		}
		else if(dcsetting_newqa == 1)
		{
			dcmain.progresscontent.curdisksize = dcmain.progresscontent.curdisksize * 0.75;
		}
		else
		{
			dcmain.progresscontent.curdisksize = dcmain.progresscontent.curdisksize * 0.67;
		}
		
		updateprogress(dcmain.progresscontent.curdisksize);
	}
	
	dcsetting.Close();
	
	return 1;
}

function ReadConfig(args)
{
//	var langindex = g_Config.GetValue("basic","langindex",0);
	var langstr = Product.GetString("language","","");
	if(langstr == "")
	{
		langstr = Product.GetDefaultLanguage();
	}
	if(langstr == "Chinese")
	{
		var country = Product.GetCountry();
		if((country == "Taiwan")||(country == "Hong Kong S.A.R."))
			langstr = "Chinese(Simplified)";	//"Chinese(Traditional)";
		else
			langstr = "Chinese(Simplified)";
	}

	var skin = g_Config.GetValue("basic","skin",0);
	var speed = g_Config.GetValue("basic","speed",0);
	var tempdir = g_Config.GetValue("basic","tempdir","");
	if(tempdir.length <= 0)
	{
		tempdir = g_dvdcreator.GetTempDirDft();
		g_Config.SetValue("basic","tempdir",tempdir);
	}
	var deltemp = g_Config.GetValue("basic","deltemp",true);
	var tvsetting = g_Config.GetValue("basic","tvsetting",0);
	var filmscale = g_Config.GetValue("basic","filmscale",0);
	var zoommode = g_Config.GetValue("basic","zoommode",0);
	var filmlevel = g_Config.GetValue("basic","filmlevel",0);
	var quality = g_Config.GetValue("basic","quality",0);
	var straightplay = g_Config.GetValue("basic","straightplay",false);
	var autochapter = g_Config.GetValue("basic","autochapter",true);
	var chaptertime = g_Config.GetValue("basic","chaptertime",15);
	var usebreviary = g_Config.GetValue("basic","usebreviary",true);
	var breviarytime = g_Config.GetValue("basic","breviarytime",5);

	dcsetting.tabbasic.combolanguage.SetCurSelByData(langstr);
	if(langstr == "English")
	{
		dcmain.menubar.menuoptool.menuoptoollang.menulangenglish.SetCheck(true);
		dcmain.menubar.menuoptool.menuoptoollang.menulangchinese.SetCheck(false);
	}
	else if(langstr == "Chinese(Simplified)")
	{
		dcmain.menubar.menuoptool.menuoptoollang.menulangenglish.SetCheck(false);
		dcmain.menubar.menuoptool.menuoptoollang.menulangchinese.SetCheck(true);
	}
	__RefreshLanguage(langstr);
	
	dcsetting.tabbasic.comboshow.SetCurSel(skin);
	var skinstr = dcsetting.tabbasic.comboshow.GetData(skin);
	if(skinstr == "standard")
	{
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinstandard.SetCheck(true);
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinspecial.SetCheck(false);
	}
	else if(skinstr == "special")
	{
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinstandard.SetCheck(false);
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinspecial.SetCheck(true);
	}
	LoadSkin(skinstr);
	
	dcsetting.tabbasic.combospeed.SetCurSel(speed);
	dcsetting.tabbasic.editlocation.SetText(tempdir);
	dcsetting.tabbasic.checkboxdeltempfile.SetCheck(deltemp);
	dcsetting.tabbasic.combotvsetting.SetCurSel(tvsetting);
	dcsetting.tabbasic.combofilmscale.SetCurSel(filmscale);
	dcsetting.tabbasic.combozoommode.SetCurSel(zoommode);
//	dcsetting.tabbasic.combofilmlevel.SetCurSel(filmlevel);
	dcsetting.tabbasic.groupquality.SetCheck(quality);
	dcsetting.tabbasic.checkboxplay.SetCheck(straightplay);
	dcsetting.tabbasic.checkboxchapter.SetCheck(autochapter);
	dcsetting.tabbasic.editspintime.SetEnable(autochapter);
	dcsetting.tabbasic.editspintime.SetValue(chaptertime);
	dcsetting.tabbasic.checkboxbreviary.SetCheck(usebreviary);
	dcsetting.tabbasic.editspinlength.SetEnable(usebreviary);
	dcsetting.tabbasic.editspinlength.SetValue(breviarytime);
	
}

function RestoreConfig(args)
{
	ReadConfig();
	dcsetting.Close();
}

function dcsetting_setparams()
{
	var langstr = Product.GetString("language","","");
	var skinstr = g_Config.GetValue("basic","skinstr","standard");
	var speedstr = g_Config.GetValue("basic","speedstr","most fast");
	var tempdir = g_Config.GetValue("basic","tempdir","");
	if(tempdir.length <= 0)
	{
		tempdir = g_dvdcreator.GetTempDirDft();
		g_Config.SetValue("basic","tempdir",tempdir);
	}
	var deltemp = g_Config.GetValue("basic","deltemp",true);
	var tvsettingstr = g_Config.GetValue("basic","tvsettingstr","NTSC");
	var filmscalestr = g_Config.GetValue("basic","filmscalestr","4:3");
	var zoommodestr = g_Config.GetValue("basic","zoommodestr","Letterbox");
	var filmlevelstr = g_Config.GetValue("basic","filmlevelstr","G");
	var quality = g_Config.GetValue("basic","quality",0);
	var straightplay = g_Config.GetValue("basic","straightplay",false);
	var autochapter = g_Config.GetValue("basic","autochapter",true);
	var chaptertime = g_Config.GetValue("basic","chaptertime",15);
	var usebreviary = g_Config.GetValue("basic","usebreviary",true);
	var breviarytime = g_Config.GetValue("basic","breviarytime",5);
	
	g_dvdcreator.SetParameters(	langstr,
					skinstr,
					speedstr,
					tempdir,
					deltemp,
					tvsettingstr,
					filmscalestr,
					zoommodestr,
					filmlevelstr,
					quality,
					straightplay,
					autochapter,
					chaptertime,
					usebreviary,
					breviarytime);
}

function dcsetting_choosetempdir(args)
{
	var tmpstr = dcsetting.tabbasic.editlocation.GetText();
	
	var str = g_dvdcreator.ChooseFolder(tmpstr);
	if(str.length <= 0)
	{
		str = tmpstr;
	}
	if(g_dvdcreator.IsRWPath(str,false) == false)
	{
		if(g_dvdcreator.IsFAT32(str) == false)
		{
			ShowMsg(LanguageStr("_product_name"), LanguageStr("_msg_errorreadonly"), 1, LanguageStr("_btn_ok"));
			str = tmpstr;
		}
	}
	
	dcsetting.tabbasic.editlocation.SetText(str);
	
	return 1;
}

function dcsetting_skin(args)
{
	var skin = dcsetting.tabbasic.comboshow.GetCurSel();
	var skinstr = dcsetting.tabbasic.comboshow.GetData(skin);

	if(skinstr == "standard")
	{
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinstandard.SetCheck(true);
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinspecial.SetCheck(false);
	}
	else if(skinstr == "special")
	{
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinstandard.SetCheck(false);
		dcmain.menubar.menuoptool.menuoptoolskin.menuskinspecial.SetCheck(true);
	}
	
	LoadSkin(skinstr);
}

function dcsetting_lang(args)
{
	var langindex = dcsetting.tabbasic.combolanguage.GetCurSel();
	var langstr = dcsetting.tabbasic.combolanguage.GetData(langindex);
	
	if(langstr == "English")
	{
		dcmain.menubar.menuoptool.menuoptoollang.menulangenglish.SetCheck(true);
		dcmain.menubar.menuoptool.menuoptoollang.menulangchinese.SetCheck(false);
	}
	else if(langstr == "Chinese(Simplified)")
	{
		dcmain.menubar.menuoptool.menuoptoollang.menulangenglish.SetCheck(false);
		dcmain.menubar.menuoptool.menuoptoollang.menulangchinese.SetCheck(true);
	}
	
	__RefreshLanguage(langstr);
}

function dcsetting_chkchapter(args)
{
	var val = dcsetting.tabbasic.checkboxchapter.GetCheck();
	
	dcsetting.tabbasic.editspintime.SetEnable(val);
}

function dcsetting_chkbreviary(args)
{
	var val = dcsetting.tabbasic.checkboxbreviary.GetCheck();
	
	dcsetting.tabbasic.editspinlength.SetEnable(val);
}

