function SceneAccountConnection(options) {
	this.options = options;

	this.MainView = null;
	this.MainViewBG = null;
	this.MainViewDim = null;

	this.TitleBar = null;
	this.MsgLabel = null;

	this.SkypeNameLabel = null;
	this.SkypeNameInputBox = null;

	this.PasswordLabel = null;
	this.PasswordInputBox = null;

	this.SigninBtn = null;
	this.CancelBtn = null;
	//this.CreateBtn = null;

	this.DefaultHelpBar = null;
	this.InputHelpBar = null;

	this.InitFlag = true;
	this.CloseTimer = false;
}

SceneAccountConnection.prototype.initialize = function() {
	alert("SceneAccountConnection.initialize()");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here
	// scene HTML and CSS will be loaded before this function is called

	this.create();
}

SceneAccountConnection.prototype.handleShow = function() {
	alert("SceneAccountConnection.handleShow()");
	// this function will be called when the scene manager show this scene

	this.MainViewDim.show();
	if(this.InitFlag == true) {
		this.initAccountConnection();
	}
	var callbackFunction = function() {
		sf.scene.get('AccountConnection').popupTimerCallback();
	};

	WndMgr.startPopupHideTimer(60000, callbackFunction);
}

SceneAccountConnection.prototype.handleHide = function() {
	alert("SceneAccountConnection.handleHide()");
	// this function will be called when the scene manager hide this scene

	this.MainViewDim.hide();
	this.PasswordBtn.SetText("");		//initialize

	WndMgr.stopPopupHideTimer();
}

SceneAccountConnection.prototype.handleFocus = function() {
	alert("SceneAccountConnection.handleFocus()");
	// this function will be called when the scene manager focus this scene

	var callbackFunction = function() {
		sf.scene.get('AccountConnection').popupTimerCallback();
	};

	WndMgr.startPopupHideTimer(60000, callbackFunction);

	var currentHighlight = this.MainView.getCurrentHighlight();

	if(currentHighlight == null) {
		this.highlight(this.SkypeNameBtn);
	} else {
		this.highlight(currentHighlight);
	}
}

SceneAccountConnection.prototype.handleBlur = function() {
	alert("SceneAccountConnection.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene

	var currentHighlight = this.MainView.getCurrentHighlight();
	currentHighlight.blur();
}

SceneAccountConnection.prototype.handleKeyDown = function(keyCode) {
	alert("SceneAccountConnection.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) {
		case sf.key.LEFT:
			WndMgr.resetPopupHideTimer();
			this.processLeftKey();
			break;
		case sf.key.RIGHT:
			WndMgr.resetPopupHideTimer();
			this.processRightKey();
			break;
		case sf.key.UP:
			WndMgr.resetPopupHideTimer();
			this.processUpKey();
			break;
		case sf.key.DOWN:
			WndMgr.resetPopupHideTimer();
			this.processDownKey();
			break;

		case sf.key.ENTER:
			this.processEnterKey();
			break;

		case sf.key.RETURN:
		case sf.key.EXIT:
			this.processReturnKey();
			//2013 modify by minseok
			sf.key.preventDefault();
			break;

		case 147:
		//infolink
		case 261:
		//contents
		case 115:
			//wiselink
			ProcMgr.processInfolinkKey();
			break;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneAccountConnection.prototype.create = function() {
	alert("SceneAccountConnection.create()");
	this.MainView = new View("AccountConnection");
	this.MainViewDim = new DimBg("AccountConnectionDim", "AccountConnection");
	this.MainViewBG = new View("AccountConnectionBG");
	this.MainViewBG.CreatePopupBG(0, "AccountConnection_popup_BG");
	this.MainViewBG.SetTitleTextofPopupBG(TV_LINK_ACCOUNT);

	var CurLangID = ResMgr.GetCurLanguage();

	this.SkypeNameLabel = new Label(null, "account_connection_skype_name_text");
	this.SkypeNameLabel.SetTextStyle("account_connection_text_style");
	this.SkypeNameLabel.SetText(IDWS_MOIP_SKYPE_NAME);

	this.PasswordLabel = new Label(null, "account_connection_password_text");
	this.PasswordLabel.SetTextStyle("account_connection_text_style");
	this.PasswordLabel.SetText(SID_PASSWORD);

	/*if(CurLangID == ENUM_TV_LANGUAGE.GRE) {
		$("#account_connection_password_text").css('width', "126px");
	}*/

	var this_ = sf.scene.get("AccountConnection");
	var clickCF = function(obj) {
		this_.processClickEvent(obj);
	};

	this.SkypeNameBtn = new Button();
	this.SkypeNameBtn.SetImageObjId("account_connection_skype_name_input_box", 30);
	this.SkypeNameBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_INPUT_BOX_NORMAL);
	this.SkypeNameBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_INPUT_BOX_NORMALFOCUS);
	this.SkypeNameBtn.SetTextObjId("account_connection_skype_name_input_box_text");
	this.SkypeNameBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "account_connection_input_btn_style");
	this.SkypeNameBtn.SetMaxStringLength(32);
	this.SkypeNameBtn.SetMinStringLength(6);
	this.SkypeNameBtn.SetIsPlainText(true);
	this.SkypeNameBtn.SetFlagBlockSpace(true);
	this.SkypeNameBtn.SetFlagIdType(true);
	this.SkypeNameBtn.SetOnTextChangeFunc(function() {
		this_.invalidSkypeName();
	});
	/*if(CurLangID == ENUM_TV_LANGUAGE.HEB) {
		this.SkypeNameBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "account_connection_input_btn_help_large_style");
	} else {
		this.SkypeNameBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "account_connection_input_btn_help_style");
	}*/
	this.SkypeNameBtn.SetTextEditorInfo(IDWS_MOIP_SKYPE_NAME, SIGN_IN_KEYPAD_HELP_ENTER_SKYPE_NAME);
	this.SkypeNameBtn.SetOnClickCallbackFunc(clickCF);

	this.PasswordBtn = new Button();
	this.PasswordBtn.SetImageObjId("account_connection_password_input_box", 30);
	this.PasswordBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_INPUT_BOX_NORMAL);
	this.PasswordBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_INPUT_BOX_NORMALFOCUS);
	this.PasswordBtn.SetTextObjId("account_connection_password_input_box_text", true);
	this.PasswordBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "account_connection_input_btn_style");
	this.PasswordBtn.SetMaxStringLength(20);
	this.PasswordBtn.SetMinStringLength(6);
	this.PasswordBtn.SetIsPlainText(true);
	this.PasswordBtn.SetOnTextChangeFunc(function() {
		this_.invalidPassword();
	});
	/*if(CurLangID == ENUM_TV_LANGUAGE.HEB) {
		this.PasswordBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "account_connection_input_btn_help_large_style");
	} else {
		this.PasswordBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "account_connection_input_btn_help_style");
	}*/
	this.PasswordBtn.SetTextEditorInfo(SID_PASSWORD, SIGN_IN_KEYPAD_HELP_ENTER_PASSWORD);
	this.PasswordBtn.SetOnClickCallbackFunc(clickCF);

	this.SigninBtn = new Button();
	this.SigninBtn.SetImageObjId("account_connection_ok_btn", 20);
	this.SigninBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.SigninBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.SigninBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
	this.SigninBtn.SetTextObjId("account_connection_ok_btn_text");
	this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "cPopup_btn_text");
	this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "cPopup_btn_text_high");
	this.SigninBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "cPopup_btn_text_dim");
	this.SigninBtn.SetText(SID_OK);
	this.SigninBtn.SetOnClickCallbackFunc(clickCF);

	this.CancelBtn = new Button();
	this.CancelBtn.SetImageObjId("account_connection_cancel_btn", 20);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
	this.CancelBtn.SetTextObjId("account_connection_cancel_btn_text");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "cPopup_btn_text");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "cPopup_btn_text_high");
	this.CancelBtn.SetText(SID_CANCEL);
	this.CancelBtn.SetOnClickCallbackFunc(clickCF);

	/*this.CreateBtn = new Button();
	this.CreateBtn.SetImageObjId("account_connection_create_btn", 20);
	this.CreateBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.CreateBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.CreateBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
	this.CreateBtn.SetTextObjId("account_connection_create_btn_text");
	this.CreateBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "cPopup_btn_text");
	this.CreateBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "cPopup_btn_text_high");
	this.CreateBtn.SetText(SID_CREATE_ACCOUNT);
	this.CreateBtn.SetOnClickCallbackFunc(clickCF);*/


}

SceneAccountConnection.prototype.setInitFlag = function(init_flag) {
	this.InitFlag = init_flag;
}

SceneAccountConnection.prototype.initAccountConnection = function() {
	alert("SceneAccountConnection.initAccountConnection() ");

	this.SkypeNameBtn.SetText("");
	this.PasswordBtn.SetText("");

	this.highlight(null);
	this.InitFlag = false;

	this.SigninBtn.SetFlagDim(true);
}

SceneAccountConnection.prototype.highlight = function(obj) {
	this.MainView.setCurrenHighlight(obj);

}

SceneAccountConnection.prototype.startTextInput = function() {
	alert("SceneAccountConnection.startTextInput() ");

	var currentHighlight = this.MainView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.SkypeNameBtn:
		case this.PasswordBtn:

			WndMgr.stopPopupHideTimer();
			WndMgr.StartTextEditor(currentHighlight, "AccountConnection", this.MainViewDim);
			break;
	}
}

SceneAccountConnection.prototype.processLeftKey = function() {
	alert("SceneAccountConnection.processLeftKey() ");
	var currentHighlight = this.MainView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.SigninBtn:
			//this.highlight(this.CreateBtn);
			break;

		case this.CancelBtn:
			if(this.SigninBtn.GetFlagDim() == false) {
				this.highlight(this.SigninBtn);
			} else {
				//this.highlight(this.CreateBtn);
			}

			break;
	}

}
SceneAccountConnection.prototype.processRightKey = function() {
	alert("SceneAccountConnection.processRightKey() ");
	var currentHighlight = this.MainView.getCurrentHighlight();

	switch(currentHighlight) {
		/*case this.CreateBtn:
			if(this.SigninBtn.GetFlagDim() == false) {
				this.highlight(this.SigninBtn);
			} else {
				this.highlight(this.CancelBtn);
			}
			break;*/
		case this.SigninBtn:
			this.highlight(this.CancelBtn);
			break;

	}
}

SceneAccountConnection.prototype.processUpKey = function() {
	alert("SceneAccountConnection.processUpKey() ");

	var currentHighlight = this.MainView.getCurrentHighlight();

	switch(currentHighlight) {

		case this.PasswordBtn:
			this.highlight(this.SkypeNameBtn);
			break;

		case this.SigninBtn:
		case this.CancelBtn:
			this.highlight(this.PasswordBtn);
			break;

	}
}

SceneAccountConnection.prototype.processDownKey = function() {
	alert("SceneAccountConnection.processDownKey() ");

	var currentHighlight = this.MainView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.SkypeNameBtn:
			this.highlight(this.PasswordBtn);
			break;

		case this.PasswordBtn:
			if(this.SigninBtn.GetFlagDim() == false) {
				this.highlight(this.SigninBtn);
			} else {
				this.highlight(this.CancelBtn);
			}
			break;

	}
}

SceneAccountConnection.prototype.processEnterKey = function() {
	alert("SceneAccountConnection.processEnterKey() ");

	var currentHighlight = this.MainView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.SkypeNameBtn:
		case this.PasswordBtn:
			this.startTextInput();
			break;

		case this.SigninBtn:
			this.requestSignin();
			break;

		case this.CancelBtn:
			this.setInitFlag(true);
			WndMgr.BackStepFaceRecogSignin();
			break;
			
		/*case this.CreateBtn:
			StateMgr.Start_Create_Account_State(); 
			break;*/
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneAccountConnection.prototype.requestSignin = function() {
	alert("SceneAccountConnection.requestSignin() ");
	if(this.invalidEmainID()==true){
	ProcMgr.RequestFaceRegistrationAfterSignin(this.SkypeNameBtn.GetText(), this.PasswordBtn.GetText());
	}else{
		//prevent msa login
    	//StateMgr.Start_Guide_Page_State(GUIDEPAGE_TYPE.SIGNIN_WITH_EMAIL);
    	this.setInitFlag(true);
    	WndMgr.ShowGuidePageFaceRecogSignin(); 
	}
}
SceneAccountConnection.prototype.invalidEmainID = function(){
	alert("SceneAccountConnection.invalidEmainID() ");
	var skypeName = this.SkypeNameBtn.GetText();
	if(PluginAPIMgr.IsValidEmail(skypeName)==true){
		return false;
	}else{
		return true;
	}
}

SceneAccountConnection.prototype.InputPWDAgain = function() {
	alert("SceneAccountConnection.InputPWDAgain() ");

	this.highlight(this.PasswordBtn);
	this.PasswordBtn.SetText("");
	sf.scene.focus('AccountConnection');
}

SceneAccountConnection.prototype.invalidSkypeName = function() {
	alert("SceneAccountConnection.invalidSkypeName() ");
	if(this.InitFlag == true) {
		return;
	}

	this.checkSigninBtnEnable();

	var inputText = this.SkypeNameBtn.GetText();

	if(inputText.length > 0) {
		this.highlight(this.PasswordBtn);
	}

}

SceneAccountConnection.prototype.invalidPassword = function() {
	alert("SceneAccountConnection.invalidPassword() ");
	if(this.InitFlag == true) {
		return;
	}

	this.checkSigninBtnEnable();

	var PWDInputText = this.PasswordBtn.GetText();

	if(PWDInputText.length > 0) {
		var inputText = this.SkypeNameBtn.GetText();
		if(inputText.length > 0) {
			this.highlight(this.SigninBtn);
		} else {
			this.highlight(this.SkypeNameBtn);
		}
	}
}

SceneAccountConnection.prototype.checkSigninBtnEnable = function() {
	var SkypeNameInputText = this.SkypeNameBtn.GetText();
	var PWDInputText = this.PasswordBtn.GetText();

	if(SkypeNameInputText.length > 0 && PWDInputText.length > 0) {
		alert("SceneAccountConnection.checkSigninBtnEnable()  : false");
		this.SigninBtn.SetFlagDim(false);
	} else {
		alert("SceneAccountConnection.checkSigninBtnEnable()  : true");
		this.SigninBtn.SetFlagDim(true);

	}
}

SceneAccountConnection.prototype.processReturnKey = function() {
	alert("SceneAccountConnection.processReturnKey() ");
	this.setInitFlag(true);
	WndMgr.BackStepFaceRecogSignin();
}

SceneAccountConnection.prototype.popupTimerCallback = function() {
	alert("SceneAccountConnection.popupTimerCallback() ");

	this.setInitFlag(true);
	WndMgr.BackStepFaceRecogSignin();
}

SceneAccountConnection.prototype.processClickEvent = function(obj) {
	alert("SceneAccountConnection.processClickEvent() ");

	var currentHighlight = this.MainView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}

	this.processEnterKey();
}