/*
File:egis Setting js file
Vesion:1.0
Auth: Bill
*/
var mySetting = new EgisSettings();
////////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////////
function load()
{
	System.Gadget.onSettingsClosing = settingsClosing;
	////System.Debug.outputString("Setting Start");
	
	mySetting.load();
	
	CBLayout[1].checked = mySetting.dec_able;
	CBLayout[2].checked = mySetting.psd_able;
	CBLayout[0].checked = mySetting.enc_able;
}
////////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////////
function saveSettings()
{
	////System.Debug.outputString("saveSettings");
	////System.Debug.outputString( CBLayout[0].checked );
	////System.Debug.outputString( CBLayout[1].checked );
	////System.Debug.outputString( CBLayout[2].checked );
	if((false == CBLayout[0].checked) && (false == CBLayout[1].checked) && (false == CBLayout[2].checked))
	{
		////System.Debug.outputString("saveSettings failed");
		return false;
	}
	mySetting.enc_able = CBLayout[0].checked;
	mySetting.dec_able = CBLayout[1].checked;
	mySetting.psd_able = CBLayout[2].checked;
	mySetting.save();
	return true;
}

////////////////////////////////////////////////////////////////////////////////
//
// settings event closing
//
////////////////////////////////////////////////////////////////////////////////
function settingsClosing(event)
{
    if (event.closeAction == event.Action.commit)
    {
		activex1.TrackUIClick2(0x120507);		//Option-Ok 12.5.7
        if( false == saveSettings() )
		{
			////System.Debug.outputString("settingsClosing saveSettings failed");
			//show error message-you must choose one option at least;
			//activex1.ShowErrMsg(18,0);
			//change warning text color;
			warningTxt.setAttribute("className","warning_text_x");
			event.cancel = true;
		}else
		{
			event.cancel = false;
		}
    }else if (event.closeAction == event.Action.cancel)
    {
		activex1.TrackUIClick2(0x120508);		//Option-Cancel 12.5.8
    }
}

//////////////////////////////////my setting class///////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////////
function EgisSettings()
{   
    this.save = saveSettingToDisk;
    this.load = loadSettingFromDisk;
    //init layout
    this.enc_able = true;
    this.dec_able = true;
    this.psd_able = true;
}
////////////////////////////////////////////////////////////////////////////////
//
// load the information from disk
//
////////////////////////////////////////////////////////////////////////////////
function loadSettingFromDisk()
{
	////System.Debug.outputString("loadSettingFromDisk");
    if(System.Gadget.Settings.read("SettingsExist"))
    {
		////System.Debug.outputString("SettingsExist is true");
        this.enc_able = System.Gadget.Settings.read("egisEnc");
        this.dec_able = System.Gadget.Settings.read("egisDec");
        this.psd_able = System.Gadget.Settings.read("egisPsd");
    }
}
////////////////////////////////////////////////////////////////////////////////
//
// save information to disk
//
////////////////////////////////////////////////////////////////////////////////
function saveSettingToDisk()
{
    System.Gadget.Settings.write("SettingsExist", true);
    System.Gadget.Settings.write("egisEnc", this.enc_able);
    System.Gadget.Settings.write("egisDec", this.dec_able);
    System.Gadget.Settings.write("egisPsd", this.psd_able);
}