
function SceneSignupSuggestion(options) {
	this.options = options;
    
    this.SignupSuggestionView=null;
    
    this.SignupTitleLabel = null;
     
    this.MsgTopLabel = null;
    this.MsgMiddleLabel = null;
    this.MsgBottomLabel = null;

    this.SkypeNameBtn = null;
    this.SkypeNameInfoMsgLabel = null;
    
    this.CreateAccountBtn = null;
    
	this.SuggestionList = null;
	
	this.FlagSkypeNameCheck= false;
    
    this.DefaultHelpBar =null;
    this.InputHelpBar =null;
    
}

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

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

SceneSignupSuggestion.prototype.handleHide = function () {
	alert("SceneSignupSuggestion.handleHide()");
	this.SuggestionList.ResetHighlight();	
	// this function will be called when the scene manager hide this scene  
    
    //sf.scene.hide(this.SubSceneId[this.iCurrentSubScene]);

}

SceneSignupSuggestion.prototype.handleFocus = function () {
	alert("SceneSignupSuggestion.handleFocus()");
	// this function will be called when the scene manager focus this scene
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    if(currentHighlight ==null)
    {
        this.highlight(this.SkypeNameBtn);
    }
    else
    {
         this.highlight(currentHighlight);
		 if(currentHighlight == this.SuggestionList){
		 	this.DefaultHelpBar.visibleObj();
		 }
    }
  

}

SceneSignupSuggestion.prototype.handleBlur = function () {
	alert("SceneSignupSuggestion.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    currentHighlight.blur();
	
	if(currentHighlight == this.SuggestionList){
		this.DefaultHelpBar.hiddenObj();
	}

}

SceneSignupSuggestion.prototype.handleKeyDown = function (keyCode) {
	alert("SceneSignupSuggestion.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:
            this.processLeftKey();
			break;
		case sf.key.RIGHT:
            this.processRightKey();
			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;
	}
}

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

SceneSignupSuggestion.prototype.create = function(){
    alert("SceneSignupSuggestion.create()");
    this.SignupSuggestionView = new View("SignupSuggestion");
    this.SignupSuggestionView.SetBgImage(g_Image.IMAGE_SIGNUP_BG);
    
    this.SignupTitleLabel = new Label(null,"signup_suggestion_title");
    this.SignupTitleLabel.SetTextStyle("signup_suggestion_title_style");
    this.SignupTitleLabel.SetText(TV_SID_CREATE_A_NEW_SKYPE_ACCOUNT);   

    this.MsgTopLabel = new Label(null,"signup_suggestion_message_top");
    this.MsgTopLabel.SetTextStyle("signup_suggestion_message_top_style");
    this.MsgTopLabel.SetText(TV_SID_SKYPE_NAME_NOT_AVAILABLE);   

    this.MsgMiddleLabel = new Label(null,"signup_suggestion_message_middle");
    this.MsgMiddleLabel.SetTextStyle("signup_suggestion_message_middle_style");
    this.MsgMiddleLabel.SetText(g_String.IDWS_MOIP_LOGIN_FAIL_SKYPENAME_TAKEN);   
    
    this.MsgBottomLabel = new Label(null,"signup_suggestion_message_bottom");
    this.MsgBottomLabel.SetTextStyle("signup_suggestion_message_bottom_style");
    this.MsgBottomLabel.SetText(g_String.IDWS_MOIP_SELECT_FROM_THE_FOLLOWING_SUGGESTION);   

    this.SkypeNameInfoMsgLabel = new Label(null,"signup_suggestion_skype_name_info_msg");
    this.SkypeNameInfoMsgLabel.SetTextStyle("signup_suggestion_info_msg_style");
    //this.SkypeNameInfoMsgLabel.SetText(TV_SID_6_32_CHARACTERS_NEEDED);
    this.SkypeNameInfoMsgLabel.SetText("");
    
    var this_ = sf.scene.get("SignupSuggestion");
    var clickCF =  function(obj){this_.processClickEvent(obj);};

    this.SkypeNameBtn= new Button();
    this.SkypeNameBtn.SetImageObjId("signup_suggestion_skype_name_btn");
    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("signup_suggestion_skype_name_btn_text");
    this.SkypeNameBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"signup_suggestion_btn_style");
    this.SkypeNameBtn.SetMaxStringLength(32);
    this.SkypeNameBtn.SetMinStringLength(6);
    this.SkypeNameBtn.SetFlagBlockSpace(true);
	this.SkypeNameBtn.SetFlagIdType(true);
    //this.SkypeNameBtn.SetText("Skype Name");
    this.SkypeNameBtn.SetOnTextChangeFunc(function(){ this_.invalidSkypeName();});
    // this.SkypeNameBtn.SetHelpText(IDWS_MOIP_PRESS_ENTER, "signup_suggestion_btn_help_style");
    this.SkypeNameBtn.SetTextEditorInfo(TV_SID_CREATE_SKYPE_NAME, TV_SID_6_32_CHARACTERS_NEEDED);
    this.SkypeNameBtn.SetOnClickCallbackFunc(clickCF);
    
    this.CreateAccountBtn= new Button();
    this.CreateAccountBtn.SetImageObjId("signup_suggestion_create_account_btn");
    this.CreateAccountBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_SIGNUP_BTN_NORMAL);
    this.CreateAccountBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_SIGNUP_BTN_NORMALFOCUS);
    this.CreateAccountBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_SIGNUP_BTN_DIM);
    this.CreateAccountBtn.SetTextObjId("signup_suggestion_create_account_btn_text");
    this.CreateAccountBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"common_btn_text_f19_normal_style");
	this.CreateAccountBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"common_btn_text_f19_highlight_style");
    this.CreateAccountBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"common_btn_text_f19_dim_style");
    this.CreateAccountBtn.SetText(SID_CREATE_ACCOUNT);
    this.CreateAccountBtn.SetOnClickCallbackFunc(clickCF);
    
	this.SuggestionList = new ScrollList();
	this.SuggestionList.CreateBG("SuggestionList");
	this.SuggestionList.SetBGImage(g_Image.IMAGE_SIGNUP_SUGGESTION_LIST_BG);	
	this.SuggestionList.SetNumOfVisibleItem(5);
	this.SuggestionList.SetStartDataIndex(0);		
	this.SuggestionList.SetItemBgImage(ITEM_STATE.NORMAL," ");
	this.SuggestionList.SetItemBgImage(ITEM_STATE.HIGHLIGHT,g_Image.IMAGE_SIGNUP_SUGGESTION_LIST_ITEM_HIGHLIGHT);
	this.SuggestionList.SetItemDefualtTextStyle(ITEM_STATE.NORMAL,"SuggestionListItem_Text_Normal_style");
	this.SuggestionList.SetItemDefualtTextStyle(ITEM_STATE.HIGHLIGHT,"SuggestionListItem_Text_Highlight_style");
	this.SuggestionList.SetDataType(ITEM_DATA_TYPE.TEXT_ONLY);
	
/*
	var scene = sf.scene.get("SignupSuggestion");
	this.SuggestionList.SetEventOnReturnFunc(scene.ProcessKeyReturn);
	this.SuggestionList.SetItemPressedEventCallback(scene.ProcessKeyEnter);
*/
		
	this.SetSuggestionListData();
	
	this.SuggestionList.CreateScrBar("SuggestionScrollBar");
	this.SuggestionList.SetScrBarImage(g_Image.IMAGE_SIGNUP_SUGGESTION_SCROLLBAR_BG,
		g_Image.IMAGE_SIGNUP_SUGGESTION_SCROLLBAR_TOP,
		g_Image.IMAGE_SIGNUP_SUGGESTION_SCROLLBAR_CENTER,
		g_Image.IMAGE_SIGNUP_SUGGESTION_SCROLLBAR_BOTTOM);	
	this.SuggestionList.SetScrBarPosition(210,0,5);

	this.SuggestionList.SetOnClickCallbackFunc(0,this.onClickEventFunc1);
	this.SuggestionList.SetOnClickCallbackFunc(1,this.onClickEventFunc2);
	this.SuggestionList.SetOnClickCallbackFunc(2,this.onClickEventFunc3);
	this.SuggestionList.SetOnClickCallbackFunc(3,this.onClickEventFunc4);
	this.SuggestionList.SetOnClickCallbackFunc(4,this.onClickEventFunc5);

	this.SuggestionList.SetClickEventAvailable(WndMgr.MouseClickEnable);

	
	this.SuggestionList.Show();

}

SceneSignupSuggestion.prototype.SetSuggestionListData = function(){
	
	if(this.SuggestionList.GetMaxNumOfData() > 0){
		
		this.SuggestionList.DeleteDataAll();
	}
		
	var strSuggestionList = PluginAPIMgr.GetSuggestedSkypeNameList();
	alert("strSuggestionList = " + strSuggestionList );
																
	if (strSuggestionList) {
		
		var STX = String.fromCharCode(2);
		var ETX = String.fromCharCode(3);
		var splitter = ETX + STX;
		
		var SuggestionArray = strSuggestionList.split(splitter);
		var NumOfSuggestion = SuggestionArray.length - 1;
		//this.SearchNumberResultArray = new Array(this.PhoneNumberArray.length);
		
		var tempData = new Array(NumOfSuggestion);
				
		for (var i=0; i < NumOfSuggestion; i++) {
													
			tempData[i] = [ SuggestionArray[i] ,null];							
			this.SuggestionList.AddData(tempData[i]);											
		}

		//check!!!!
		
		
		this.SuggestionList.ShowItem();			
	}
	else{
		alert("SuggestionList is null ");
	}	
	
}


SceneSignupSuggestion.prototype.initSignupSuggestion = function()
{
    this.SkypeNameBtn.SetText("");

    this.highlight(null);
    
    this.CreateAccountBtn.SetFlagDim(true);
	
	this.SetSuggestionListData();
}

SceneSignupSuggestion.prototype.startTextInput = function(){
    alert("SceneCreateAccountStep1.startTextInput() ");
    
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.SkypeNameBtn:
             WndMgr.StartTextEditor(this.SkypeNameBtn, "SignupSuggestion", null);
            break;                    
    }    
}


SceneSignupSuggestion.prototype.highlight=function(obj)
{
	alert("SceneSignupSuggestion.highlight()");
	
    this.SignupSuggestionView.setCurrenHighlight(obj);
}

SceneSignupSuggestion.prototype.select=function(obj)
{
     this.SignupSuggestionView.setCurrentSelect(obj);
}


SceneSignupSuggestion.prototype.processRightKey = function(){
    alert("SceneSignupSuggestion.processRightKey() ");
    
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.SkypeNameBtn:
        case this.CreateAccountBtn:
			this.moveToSuggestion();
        break;
    }
    
}


SceneSignupSuggestion.prototype.processLeftKey = function(){
    alert("SceneSignupSuggestion.processLeftRightKey() ");
    
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    
	if(currentHighlight == this.SuggestionList){
		this.DefaultHelpBar.hiddenObj();
		this.highlight(this.SkypeNameBtn);
	}
    
}

SceneSignupSuggestion.prototype.processUpKey = function(){
    alert("SceneSignupSuggestion.processUpKey() ");
    
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();

    
    switch(currentHighlight)
    {
        case this.SkypeNameBtn:
             if( this.CreateAccountBtn.GetFlagDim() == false)
            {
               this.highlight(this.CreateAccountBtn);
            }

        break;
        case this.CreateAccountBtn:
            this.highlight(this.SkypeNameBtn);
        break;
        case this.SuggestionList:
            this.SuggestionList.Previous();

    }
    
}


SceneSignupSuggestion.prototype.processDownKey = function(){
    alert("SceneSignupSuggestion.processDownKey() ");
        
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.SkypeNameBtn:
                 if( this.CreateAccountBtn.GetFlagDim() == false)
                {
                   this.highlight(this.CreateAccountBtn);
                }
                
			break;
        case this.CreateAccountBtn:
            this.highlight(this.SkypeNameBtn);
        break;
        case this.SuggestionList:
            this.SuggestionList.Next();

    }
    
}

SceneSignupSuggestion.prototype.processEnterKey = function(){
    alert("SceneSignupSuggestion.processEnterKey() ");
    
    var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    
    this.select(currentHighlight);
    
     switch(currentHighlight)
    {
        case this.SkypeNameBtn:
            this.startTextInput();
        break;
        
        case this.CreateAccountBtn:
			ProcMgr.CreateAccountWithNewSkypeName(this.SkypeNameBtn.GetText());
        break;
		
        case this.SuggestionList:
			var Index = this.SuggestionList.GetCurrentItem();
			var Text = this.SuggestionList.ItemArray[Index].GetDataText();
			this.SkypeNameBtn.SetText(Text);
			this.DefaultHelpBar.hiddenObj();
			this.highlight(this.SkypeNameBtn);
        	break;						
    }
    
}

SceneSignupSuggestion.prototype.processReturnKey = function(){
    alert("SceneSignupSuggestion.processReturnKey() ");
    
    //WndMgr.BackStepSignup();
	WndMgr.BackStepCreateAccount();
}

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

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

SceneSignupSuggestion.prototype.invalidSkypeName = function(){
    alert("SceneSignupSuggestion.invalidSkypeName() ");
	
    if(this.InitFlag ==true)
    {
        return;
    }
    
    var SkypeNameinputText = this.SkypeNameBtn.GetText();
   
    this.FlagSkypeNameCheck= false;
	
    if(SkypeNameinputText.length ==0)
    {
        this.SkypeNameInfoMsgLabel.SetText(TV_SID_6_32_CHARACTERS_NEEDED);
    }
    else
	{
		var normalize_result = PluginAPIMgr.NormalizeIdentityForNewAccount(SkypeNameinputText);
		var STX = String.fromCharCode(2);
		var ETX = String.fromCharCode(3);
		var splitter = ETX + STX;
		
		var Result = normalize_result.split(splitter);
		
		if(parseInt(Result[0]) == ENUM_NORMALIZERESULT.IDENTITY_OK)
		{
		 	var result = PluginAPIMgr.ValidatePasswd(SkypeNameinputText,g_Data.DATA_CREATE_ACCOUNT_INPUT_INFO.pwd);
			if(result == ENUM_PWD_VALIDATERESULT.SAME_AS_USERNAME)
		    {
		        this.SkypeNameInfoMsgLabel.SetText(TV_SID_PASSWORD_IS_TOO_SIMILAR_TO_SKYPE_NAME);
		    }
			else
			{
				this.SkypeNameInfoMsgLabel.SetText("");
		        this.FlagSkypeNameCheck= true;        
			}
		}
		else if(parseInt(Result[0]) == ENUM_NORMALIZERESULT.IDENTITY_EMPTY)
	    {
	        this.SkypeNameInfoMsgLabel.SetText(TV_SID_6_32_CHARACTERS_NEEDED);
	    }
		else if(parseInt(Result[0]) == ENUM_NORMALIZERESULT.SKYPENAME_SHORTER_THAN_6_CHARS)
	    {
	        this.SkypeNameInfoMsgLabel.SetText(TV_SID_TOO_SHORT_6_CHARACTERS_MIN);
	    }
		else if(parseInt(Result[0]) == ENUM_NORMALIZERESULT.IDENTITY_TOO_LONG)
	    {
	        this.SkypeNameInfoMsgLabel.SetText(TV_SID_6_32_CHARACTERS_NEEDED);
	    }
		else if(parseInt(Result[0]) == ENUM_NORMALIZERESULT.SKYPENAME_STARTS_WITH_NONALPHA)
	    {
	        this.SkypeNameInfoMsgLabel.SetText(TV_SKYPE_USERNAME_START_ALPHABETIC_MSG);
	    }
		else if(parseInt(Result[0]) == ENUM_NORMALIZERESULT.IDENTITY_CONTAINS_INVALID_CHAR)
		{
			this.SkypeNameInfoMsgLabel.SetText(TV_THE_SKYPE_USERNAME_HAS_INVALID_CHARACTERS);
		}
	    else
	    {
			this.SkypeNameInfoMsgLabel.SetText(IDWS_MOIP_LOGIN_FAIL_INVALID_SKYPENAME);
	    }
	} 
	
	if(this.FlagSkypeNameCheck== false)
	{
		if(this.CreateAccountBtn != null)
        {
            this.CreateAccountBtn.SetFlagDim(true);
        }
	}
	else
	{
		if(this.CreateAccountBtn != null)
        {
            this.CreateAccountBtn.SetFlagDim(false);
            this.highlight(this.CreateAccountBtn);
        }
	}   
	
}

SceneSignupSuggestion.prototype.moveToSuggestion = function(){

	if(this.SuggestionList.GetMaxNumOfData() > 0){

        this.highlight(this.SuggestionList);
		this.DefaultHelpBar.visibleObj();		
	}
	
}

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

SceneSignupSuggestion.prototype.processClickEvent = function(obj){
	alert("SceneSignupSuggestion.processClickEvent() ");
	
	var currentHighlight =  this.SignupSuggestionView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	this.processEnterKey();
}

SceneSignupSuggestion.prototype.processListClick = function(ItemIndex)
{
	alert("SceneSignupSuggestion.processListClick() -- " + ItemIndex);
	
	var Text = this.SuggestionList.ItemArray[ItemIndex].GetDataText();
	this.SkypeNameBtn.SetText(Text);
	this.DefaultHelpBar.hiddenObj();
	this.highlight(this.SkypeNameBtn);

}

SceneSignupSuggestion.prototype.onClickEventFunc1 = function()
{
	var This_ = sf.scene.get("SignupSuggestion");	
	This_.processListClick(0);
}

SceneSignupSuggestion.prototype.onClickEventFunc2 = function()
{
	var This_ = sf.scene.get("SignupSuggestion");	
	This_.processListClick(1);
}

SceneSignupSuggestion.prototype.onClickEventFunc3 = function()
{
	var This_ = sf.scene.get("SignupSuggestion");	
	This_.processListClick(2);
}

SceneSignupSuggestion.prototype.onClickEventFunc4 = function()
{
	var This_ = sf.scene.get("SignupSuggestion");	
	This_.processListClick(3);
}

SceneSignupSuggestion.prototype.onClickEventFunc5 = function()
{
	var This_ = sf.scene.get("SignupSuggestion");	
	This_.processListClick(4);
}


