
function SceneCreateAccountStep2(options) {
	this.options = options;
	
	this.InitFlag = true;
	this.destroyFlag = true;
	
	this.MainView=null;
	
	this.TitleLabel = null;
	
	
	//2013 add by minseok
	this.Nevi_icon1 = null;
	this.Nevi_icon2 = null;
	this.Nevi_icon3 = null;
	this.Nevi_icon4 = null;
	
	this.FullNameLabel = null;
	this.EmailLabel = null;
	
	this.FullNameInfoLabel = null;
	this.EmailInfoLabel = null;
	
	this.FullNameBtn = null;
	this.EmailBtn = null;
	
	this.EmailVerifyLabel = null;
	
	this.FlagEmailCheck= false;
	
//2013 add by minseok
	this.SendEmailCheckBox = null;
	
	this.PreviousBtn = null;
	this.NextBtn = null;
	
	this.DefaultHelpBar =null;
	this.InputHelpBar =null; 
}

SceneCreateAccountStep2.prototype.initialize = function () {
	alert("SceneCreateAccountStep2.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();
}

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

	if(this.InitFlag == true){
	
	    this.initCreateAccount();
	}
        
}

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

}

SceneCreateAccountStep2.prototype.handleFocus = function () {
	alert("SceneCreateAccountStep2.handleFocus()");
	// this function will be called when the scene manager focus this scene
    var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight ==null)
    {
        this.highlight(this.FullNameBtn);
    }
    else
    {
         this.highlight(currentHighlight);
    }
  
	var this_ = sf.scene.get("CreateAccountStep2");
  	var returnCF =  function(){this_.processReturnKey();};
    WndMgr.SetReturnIconClickCallback(returnCF);
}

SceneCreateAccountStep2.prototype.handleBlur = function () {
	alert("SceneCreateAccountStep2.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();

	WndMgr.SetReturnIconClickCallback(null);
}

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

		case sf.key.ENTER:
            this.processEnterKey();
			break;
            
        case sf.key.RETURN:
            this.processReturnKey();
            //2013 modify by minseok
            sf.key.preventDefault();
            //sf.key.block(event);
			break;
            
        case sf.key.EXIT:
            this.processExitKey();
            //2013 modify by minseok
            sf.key.preventDefault();
            //sf.key.block(event);
			break;
            
        case 147:  //infolink
        case 261:  //contents
        case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
        
		default:
            ProcMgr.processBlockKey(keyCode);
            break;

	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneCreateAccountStep2.prototype.create = function(){
    alert("SceneCreateAccountStep2.create()");
	
    this.MainView = new View("CreateAccountStep2");
    // this.MainView.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_BG);
	
	/*this.ProgressBarBgLabel= new Label("create_account_step2_progress_bar_bg", null);
    this.ProgressBarBgLabel.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_PROGRESS_BAR_BG);
	
	this.ProgressBarPreviousLabel= new Label("create_account_step2_progress_bar_previous", null);
    this.ProgressBarPreviousLabel.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_PROGRESS_BAR_PREVIOUS_BG);
	
	this.ProgressBarCurrentLabel= new Label("create_account_step2_progress_bar_current", null);
    this.ProgressBarCurrentLabel.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_PROGRESS_BAR_CURRENT_BG);
    */
   	this.Nevi_icon1 = new Label("create_account_step2_nevi1",null);
	this.Nevi_icon1.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_NEVI_NORMAL);
	this.Nevi_icon2 = new Label("create_account_step2_nevi2",null);
	this.Nevi_icon2.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_NEVI_HIGHLIGHT);
	this.Nevi_icon3 = new Label("create_account_step2_nevi3",null);
	this.Nevi_icon3.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_NEVI_NORMAL);
	this.Nevi_icon4 = new Label("create_account_step2_nevi4",null);
	this.Nevi_icon4.SetBgImage(g_Image.IMAGE_CREATE_ACCOUNT_NEVI_NORMAL);
	
   
    this.TitleLabel = new Label(null,"create_account_step2_title");
    this.TitleLabel.SetTextStyle("create_account_title_style");
    this.TitleLabel.SetText(TV_SID_CREATE_AN_ACCOUNT);

    this.FullNameLabel = new Label(null,"create_account_step2_full_name");
    this.FullNameLabel.SetTextStyle("create_account_text_style");
    this.FullNameLabel.SetText(IDWS_MOIP_FULL_NAME);

    this.EmailLabel = new Label(null,"create_account_step2_email");
    this.EmailLabel.SetTextStyle("create_account_text_style");
    this.EmailLabel.SetText(IDWS_MOIP_E_MAIL);

    var this_ = sf.scene.get("CreateAccountStep2");
    var clickCF =  function(obj){this_.processClickEvent(obj);};
    var overCF =  function(obj){this_.processMouseOverEvent(obj);};
	
    this.FullNameBtn= new Button();
    this.FullNameBtn.SetImageObjId("create_account_step2_full_name_btn", 30);
    this.FullNameBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CREATE_ACCOUNT_BTN_NORMAL);
    this.FullNameBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CREATE_ACCOUNT_BTN_NORMALFOCUS);
    this.FullNameBtn.SetTextObjId("create_account_step2_full_name_btn_text");
    this.FullNameBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"create_account_input_btn_style");
    this.FullNameBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"create_account_input_btn_select_style");
    this.FullNameBtn.SetMaxStringLength(50);
    this.FullNameBtn.SetIsPlainText(true);
    this.FullNameBtn.SetOnTextChangeFunc(function(){ this_.invalidFullName();});
    //this.FullNameBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "create_account_input_btn_help_style");
    this.FullNameBtn.SetTextEditorInfo(IDWS_MOIP_FULL_NAME, IDWS_MOIP_INPUT_YOUR_FULL_NAME);
    this.FullNameBtn.SetOnClickCallbackFunc(clickCF);
    this.FullNameBtn.SetOnMouseOverCallbackFunc(overCF);

    this.EmailBtn= new Button();
    this.EmailBtn.SetImageObjId("create_account_step2_email_btn",30);
    this.EmailBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CREATE_ACCOUNT_BTN_NORMAL);
    this.EmailBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CREATE_ACCOUNT_BTN_NORMALFOCUS);
    this.EmailBtn.SetTextObjId("create_account_step2_email_btn_text");
    this.EmailBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"create_account_input_btn_style");
    this.EmailBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"create_account_input_btn_select_style");
    this.EmailBtn.SetMaxStringLength(50);
    this.EmailBtn.SetIsPlainText(true);
    this.EmailBtn.SetFlagBlockSpace(true);
	this.EmailBtn.SetFlagIdType(true);
    this.EmailBtn.SetOnTextChangeFunc(function(){ this_.invalidEmail();});
    //this.EmailBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "create_account_input_btn_help_style");
    this.EmailBtn.SetTextEditorInfo(IDWS_MOIP_E_MAIL, IDWS_MOIP_OPTIONS_USER_PROFILE_KEYPAD_HELP_ENTER_EMAIL);
	this.EmailBtn.SetOnClickCallbackFunc(clickCF);
	this.EmailBtn.SetOnMouseOverCallbackFunc(overCF);
	
    this.EmailVerifyLabel = new Label(null,"create_account_step2_email_verify_msg");
    this.EmailVerifyLabel.SetTextStyle("create_account_verify_msg_style");
    this.EmailVerifyLabel.SetText(IDWS_MOIP_LOGIN_FAIL_INVALID_EMAIL);


	this.SendEmailCheckBox = new CheckBox();
	this.SendEmailCheckBox.SetImageObjId("create_account_step2_send_email_check_box");
    this.SendEmailCheckBox.SetBgImage(CBoxImgIndex.CB_NORMAL_IMG,  g_Image.IMAGE_CREATE_ACCOUNT_CHECK_BOX_NORMAL);
    this.SendEmailCheckBox.SetBgImage(CBoxImgIndex.CB_NORMAL_FOCUS_IMG,  g_Image.IMAGE_CREATE_ACCOUNT_CHECK_BOX_NORMALFOCUS);
    this.SendEmailCheckBox.SetTextObjId("create_account_step2_send_email_check_box_text");
    this.SendEmailCheckBox.SetText(TV_SID_SPECIAL_OFFERS_AND_FUN_STUFF_FROM_SKYPE);
    this.SendEmailCheckBox.SetTextStyle("create_account_check_box_style");
    this.SendEmailCheckBox.AppendFgImage("create_account_step2_send_email_check_box_selected_icon","0px","0px","29px","29px");
    this.SendEmailCheckBox.SetFgImage(g_Image.IMAGE_CREATE_ACCOUNT_CHECK_BOX_SELECTED); 
    this.SendEmailCheckBox.SetFlagSelect(false);
    this.SendEmailCheckBox.SetOnClickCallbackFunc(clickCF);
    this.SendEmailCheckBox.SetOnMouseOverCallbackFunc(overCF);
    
    

    this.PreviousBtn= new Button();
    this.PreviousBtn.SetImageObjId("create_account_step2_previous_btn",30);
    this.PreviousBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CREATE_ACCOUNT_PREVIOUS_BTN_NORMAL);
    this.PreviousBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CREATE_ACCOUNT_PREVIOUS_BTN_NORMALFOCUS);
    this.PreviousBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_CREATE_ACCOUNT_PREVIOUS_BTN_NORMAL);
    this.PreviousBtn.SetTextObjId("create_account_step2_previous_btn_text");
    this.PreviousBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"create_account_btn_normal_style");
	this.PreviousBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"create_account_btn_select_style");
    this.PreviousBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"create_account_btn_dim_style");
    this.PreviousBtn.SetText(SID_BACK_KR_PREV);
    this.PreviousBtn.SetOnClickCallbackFunc(clickCF);
    this.PreviousBtn.SetOnMouseOverCallbackFunc(overCF);
	
	this.NextBtn= new Button();
    this.NextBtn.SetImageObjId("create_account_step2_next_btn",30);
    this.NextBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_CREATE_ACCOUNT_NEXT_BTN_NORMAL);
    this.NextBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_CREATE_ACCOUNT_NEXT_BTN_NORMALFOCUS);
    this.NextBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_CREATE_ACCOUNT_NEXT_BTN_DIM);
    this.NextBtn.SetTextObjId("create_account_step2_next_btn_text");
    this.NextBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"create_account_btn_normal_style");
	this.NextBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"create_account_btn_select_style");
    this.NextBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"create_account_btn_dim_style");
    this.NextBtn.SetText(SID_NEXT);
    this.NextBtn.SetOnClickCallbackFunc(clickCF);
    this.NextBtn.SetOnMouseOverCallbackFunc(overCF);
    
}

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

SceneCreateAccountStep2.prototype.setDestroyFlag= function(destroy_flag){
     this.destroyFlag = destroy_flag;
}


SceneCreateAccountStep2.prototype.initCreateAccount = function()
{
	this.FullNameBtn.SetText("");
	this.EmailBtn.SetText("");
	
	this.FlagEmailCheck= false;
	
	this.EmailVerifyLabel.SetText("");
	
	this.highlight(null);
	this.InitFlag = false;
	
	if(this.destroyFlag == true)
	{
	this.destroyFlag= false;
	}
	//test_modify by minseok
	this.NextBtn.SetFlagDim(true);
	// this.FullNameBtn.SetText("haha");
	// this.EmailBtn.SetText("haha@samsung.com");
	
}

SceneCreateAccountStep2.prototype.startTextInput = function(){
    alert("SceneCreateAccountStep2.startTextInput() ");
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.FullNameBtn:
        case this.EmailBtn:
        
             WndMgr.StartTextEditor(currentHighlight, "CreateAccountStep2", null);
            break;          
    }    
}

SceneCreateAccountStep2.prototype.goNextStep = function(){
    alert("SceneCreateAccountStep2.goNextStep() ");
	g_Data.SetCreateAccountStep2InputInfo(this.EmailBtn.GetText(), this.FullNameBtn.GetText());
	WndMgr.NextStepCreateAccount();
}


SceneCreateAccountStep2.prototype.highlight=function(obj)
{
	alert("SceneCreateAccountStep2.highlight()");
	
    this.MainView.setCurrenHighlight(obj);
}

SceneCreateAccountStep2.prototype.select=function(obj)
{
	alert("SceneCreateAccountStep2.select()");
	
     this.MainView.setCurrentSelect(obj);
}


SceneCreateAccountStep2.prototype.processDownKey = function(){
    alert("SceneCreateAccountStep2.processDownKey() ");
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
	switch(currentHighlight)
	{
		case this.FullNameBtn:
			 this.highlight(this.EmailBtn);
			break;
		
		case this.EmailBtn:
			this.highlight(this.SendEmailCheckBox);
			break;
		case this.SendEmailCheckBox:
			if(this.NextBtn.GetFlagDim()==false)
			{
				this.highlight(this.NextBtn);
			}
			else
			{
				this.highlight(this.PreviousBtn);
			}
			 
			break;
			
		case this.PreviousBtn:	
		case this.NextBtn:
			 //this.highlight(this.FullNameBtn);
			break;
	}

}

SceneCreateAccountStep2.prototype.processUpKey = function(){
    alert("SceneCreateAccountStep2.processUpKey() ");
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
	switch(currentHighlight)
	{
		case this.FullNameBtn:
			break;
		case this.EmailBtn:
			 this.highlight(this.FullNameBtn);
			break;
		case this.SendEmailCheckBox:
			this.highlight(this.EmailBtn);
			break;
		case this.PreviousBtn:	
		case this.NextBtn:
			 this.highlight(this.SendEmailCheckBox);
			break;
	}
}

SceneCreateAccountStep2.prototype.processLeftRightKey = function(keyCode){
    alert("SceneCreateAccountStep2.processLeftRightKey() ");
    
    var currentHighlight =  this.MainView.getCurrentHighlight();
    
	switch(currentHighlight)
	{		
		case this.PreviousBtn:	
			if(keyCode==sf.key.RIGHT && this.NextBtn.GetFlagDim()==false)
			{
				this.highlight(this.NextBtn);
			}
			break;
			
		case this.NextBtn:
			if (keyCode==sf.key.LEFT) {
				this.highlight(this.PreviousBtn);	
			}
			break;
	}
}

SceneCreateAccountStep2.prototype.processEnterKey = function(){
    alert("SceneCreateAccountStep2.processEnterKey() ");
    
    var currentHighlight = this.MainView.getCurrentHighlight();
    
    this.select(currentHighlight);
	
		switch(currentHighlight)
	{
		case this.FullNameBtn:
		case this.EmailBtn:
			 this.startTextInput();
			break;
			
		case this.PreviousBtn:	
			 this.processReturnKey();
			break;
			
		case this.NextBtn:
			this.goNextStep();
			break;
	}
}

SceneCreateAccountStep2.prototype.processReturnKey = function(){
    alert("SceneCreateAccountStep2.processReturnKey() ");
    var currentHighlight = this.MainView.getCurrentHighlight();
    if(currentHighlight==this.PreviousBtn){
    	WndMgr.BackStepCreateAccount();	
    }else{
    	StateMgr.Start_Welcome_State();
    }
    
}

SceneCreateAccountStep2.prototype.processExitKey = function(){
    alert("SceneCreateAccountStep2.processExitKey() ");
   
   ProcMgr.ExitWithSignIn();
}

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

    var inputText = this.FullNameBtn.GetText();
    
    if(inputText.length > 0)
    {
        this.highlight(this.EmailBtn);
    }
}

SceneCreateAccountStep2.prototype.invalidEmail = function(){
    alert("SceneCreateAccountStep2.invalidEmail() ");
     if(this.InitFlag ==true)
    {
        return;
    }
     
    var inputText = this.EmailBtn.GetText();

    this.FlagEmailCheck= false;
    
    if(inputText.length > 0 && !(PluginAPIMgr.IsValidEmail(inputText)) )
    {
         this.EmailVerifyLabel.SetText(IDWS_MOIP_LOGIN_FAIL_INVALID_EMAIL);
		 
		 this.checkNextBtnEnable();
    }
    else
    {
        this.EmailVerifyLabel.SetText("");
        
        if(inputText.length > 0 )
        {
              this.FlagEmailCheck= true;
              
			  this.checkNextBtnEnable();
              this.highlight(this.NextBtn);
        }
		else
		{
			this.checkNextBtnEnable();
		}
    } 
}

SceneCreateAccountStep2.prototype.checkNextBtnEnable = function(){

    if(this.FlagEmailCheck==true )
    {
         alert("SceneCreateAccountStep2.checkNextBtnEnable()  : false");
        this.NextBtn.SetFlagDim(false);
    }
    else
    {
        alert("SceneCreateAccountStep2.checkNextBtnEnable()  : true");
        this.NextBtn.SetFlagDim(true);       
    }
}

///////// Processing Click evnet  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneCreateAccountStep2.prototype.processClickEvent = function(obj){
	alert("SceneCreateAccountStep2.processClickEvent() ");
	
	
	this.processEnterKey();
}
SceneCreateAccountStep2.prototype.processMouseOverEvent = function(obj){
	alert("SceneCreateAccountStep2.processMouseOverEvent() ");
	
	var currentHighlight =  this.MainView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	//this.processEnterKey();
}



