//Not use
var ASSIGNED_LABEL_TYPE = {      
	    NONE		:   0,
	    MOBILE		:   1, 
		OFFICE		:	2,
		HOME		:	3,
		OTHER		:	4
}


function SceneAddAssignedPhoneNumber(options) {
	this.options = options;
    
    this.AddPhoneNumberView	=null;
	this.AddPhoneNumberViewBg = null;
	this.AddPhoneNumberDim	=null;
    
    this.TitleBar = null;    
    
    this.MsgLabel		= null;
  
    this.PhoneNumberInputBox		= null;

    //About country code
    this.CountryCodeBtn		= null;
   	this.CountryPrefixLabel	= null;
    this.CountryNameLabel	= null;
    this.CountryCode		= "";
    this.CountryPrefix		= "";
    	    
    //Button
    this.AddBtn			= null;    
    this.CancelBtn		= null;       

    //Check
		
	this.TargetIdentity 	= null;	
	this.PrevPhoneNumber	= null;

	this.AssignedIndex		= 0;
	this.Type				= null;			//Add , mobile, office, home
	this.AddMode			= true;

	//label button & list
    this.LabelBtn		= null;
//    this.LabelList		= null;    

    //flag of Sublist     
	this.ShownFlagList	= false;
	
	//timer
    this.TextInputTimer = false;
	
}

SceneAddAssignedPhoneNumber.prototype.initialize = function () {
	alert("SceneAddAssignedPhoneNumber.initialize()");

   this.create();
}

SceneAddAssignedPhoneNumber.prototype.handleShow = function () {
	alert("SceneAddAssignedPhoneNumber.handleShow()");

    this.AddPhoneNumberDim.show();
 
	this.initData();   

	//check
	var this_ = sf.scene.get("AddAssignedPhoneNumber");
	//2013 modify by minseok : because of defect w0000097935
	sf.scene.get("CountryFlagList").Init(FLAG_LIST_TYPE.LIST_MAIN_CALL,'AddAssignedPhoneNumber',this_.SetCountryFlag,null);	// this_.HideCountryHelpbar

  	var callbackFunction =  function(){
  		sf.scene.get('AddAssignedPhoneNumber').processReturnKey();
  	};
  	
	WndMgr.startPopupHideTimer(60000,callbackFunction);

}

SceneAddAssignedPhoneNumber.prototype.handleHide = function () {
	alert("SceneAddAssignedPhoneNumber.handleHide()");
	
	WndMgr.stopPopupHideTimer();

	//hide flag list
	if(this.ShownFlagList == true)
	{
		sf.scene.hide('CountryFlagList');
		this.ShownFlagList = false;
	}

	if(this.ShownLabelList == true)
	{
		sf.scene.hide('AddAssignedPhoneLabelSeletor');
		this.ShownLabelList = false;
	}
		
	//this.HelpBar.hiddenObj();
	
	//this.resetData(); 
	this.AddPhoneNumberDim.hide();
	
	//reset g_data
	g_Data.SetAssignedPhoneNumberInfo(null,-1,-1,null,false);
}

SceneAddAssignedPhoneNumber.prototype.handleFocus = function () {
	alert("SceneAddAssignedPhoneNumber.handleFocus()");
 
    var currentHighlight = this.AddPhoneNumberView.getCurrentHighlight();
    if(currentHighlight == null)
    {
		this.highlight(this.PhoneNumberInputBox);
    }
    else
    {
        this.highlight(currentHighlight);
    }
	
	//TEMPCODE:
	this.ShownFlagList = false;
	this.ShownLabelList	= false;
}

SceneAddAssignedPhoneNumber.prototype.handleBlur = function () {
	alert("SceneAddAssignedPhoneNumber.handleBlur()");
	
     var currentHighlight =  this.AddPhoneNumberView.getCurrentHighlight();
     
	 if(currentHighlight != null)     
	 {
	 	currentHighlight.blur();
	 }
	 
}

SceneAddAssignedPhoneNumber.prototype.handleKeyDown = function (keyCode) {
	alert("SceneAddAssignedPhoneNumber.handleKeyDown(" + keyCode + ")");
PluginAPIMgr.PlayAudio(keyCode);
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();
			sf.key.preventDefault();
			break;

         case 147:  //infolink
            ProcMgr.processInfolinkKey(); 
			break;
	}
}

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

SceneAddAssignedPhoneNumber.prototype.create = function(){
    alert("SceneAddAssignedPhoneNumber.create()");
    
	this.AddPhoneNumberView = new View("AddAssignedPhoneNumber");

    this.AddPhoneNumberViewBg = new View("AddAssignedPhoneNumberBg");
    this.AddPhoneNumberViewBg.CreatePopupBG(0,"AddAssignedPhoneNumberBg");
	this.AddPhoneNumberViewBg.SetTitleTextofPopupBG(IDWS_MOIP_SKYPE_ADD_A_PHONE_NUMBER);
//	this.AddPhoneNumberViewBg.CreateInnerBox("AddAssignedPhoneNumberBg_innerbox");
    
	this.AddPhoneNumberDim = new DimBg("AddAssignedPhoneNumberDim", "AddAssignedPhoneNumber"); 

	this.MsgLabel = new Label(null,"AddAssignedPhoneNumber_msg");
    this.MsgLabel.SetTextStyle("AddAssignedPhoneNumber_msg_style");

    this.LabelBtn = new Button();
    this.LabelBtn.SetImageObjId("AddAssignedPhoneNumber_Label_Button", 20);
    this.LabelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.LabelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.LabelBtn.SetBgImage(BtnImgIndex.BTN_SELECTED_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.LabelBtn.SetIconObjId("AddAssignedPhoneNumber_Label_icon");
    this.LabelBtn.SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_ADD_CONTACT_ARROW_ICON);
    this.LabelBtn.SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_ADD_CONTACT_ARROW_ICON);
	this.LabelBtn.SetBgIcon(BtnIconIndex.BTN_SELECTED_ICON, g_Image.IMAGE_ADD_CONTACT_ARROW_ICON);
    this.LabelBtn.SetTextObjId("AddAssignedPhoneNumber_Label_text");
	this.LabelBtn.SetOnClickCallbackFunc(this.ClickLabelBtn);


	this.CountryCodeBtn = new Button();
	this.CountryCodeBtn.SetImageObjId("AddAssignedPhoneNumber_code_btn", 20);
	this.CountryCodeBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.CountryCodeBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
    this.CountryCodeBtn.SetIconObjId("AddAssignedPhoneNumber_code_icon");
    this.CountryCodeBtn.SetBgIcon(BtnIconIndex.BTN_NORMAL_ICON, g_Image.IMAGE_ADD_CONTACT_ARROW_ICON);
    this.CountryCodeBtn.SetBgIcon(BtnIconIndex.BTN_NORMAL_FOCUS_ICON, g_Image.IMAGE_ADD_CONTACT_ARROW_ICON);
	this.CountryCodeBtn.SetBgIcon(BtnIconIndex.BTN_SELECTED_ICON, g_Image.IMAGE_ADD_CONTACT_ARROW_ICON);
//	this.CountryCodeBtn.AppendFgImage("AddAssignedPhoneNumber_code_btn_icon");
	this.CountryCodeBtn.AppendFgImage("AddAssignedPhoneNumber_code_btn_icon", "18px", "13px", "42px", "26px");
	this.CountryCodeBtn.SetOnClickCallbackFunc(this.ClickCountryCodeBtn);
	
	this.CountryPrefixLabel = new Label(null,"AddAssignedPhoneNumber_prefix");
    this.CountryPrefixLabel.SetTextStyle("AddAssignedPhoneNumber_prefix_style");
    this.CountryPrefixLabel.SetReverseDisable(true);
	
    this.CountryNameLabel = new Label(null,"AddAssignedPhoneNumber_country_name");
    this.CountryNameLabel.SetTextStyle("AddAssignedPhoneNumber_country_name_style");
	
	this.PhoneNumberInputBox = new NumberInputBox();
	this.PhoneNumberInputBox.SetButtonObjId("AddAssignedPhoneNumber_input_box", 30);
    this.PhoneNumberInputBox.SetButtonTextObjId("AddAssignedPhoneNumber_input_box_text");
	this.PhoneNumberInputBox.SetInputBoxObjId("AddAssignedPhoneNumber_input_box_editor");
	this.PhoneNumberInputBox.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_INPUT_BOX_NORMAL);
	this.PhoneNumberInputBox.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_INPUT_BOX_NORMALFOCUS);	
	
	var scene = sf.scene.get("AddAssignedPhoneNumber");
    this.PhoneNumberInputBox.setPrevEventOnLeftFunc(	function(){scene.processLeftKey();	WndMgr.resetPopupHideTimer();	});
    this.PhoneNumberInputBox.setPrevEventOnRightFunc(	function(){scene.processRightKey();	WndMgr.resetPopupHideTimer();	});    
    this.PhoneNumberInputBox.setPrevEventOnDownFunc(	function(){scene.processDownKey();	WndMgr.resetPopupHideTimer();	});
    this.PhoneNumberInputBox.setPrevEventOnUpFunc(		function(){scene.processUpKey();	WndMgr.resetPopupHideTimer();	});
    this.PhoneNumberInputBox.setPrevEventOnReturnFunc(	function(){scene.processReturnKey();					});
    this.PhoneNumberInputBox.setPrevEventOnExitFunc(function(){scene.processReturnKey();						});
    this.PhoneNumberInputBox.setEnterFunc(				function(){scene.processEnterKey();	WndMgr.restartPopupHideTimer();					});
    this.PhoneNumberInputBox.setAnyKeyFunc(				function(keyCode){scene.callbackPhoneNumberInput(keyCode)});
    
    this.PhoneNumberInputBox.SetHelpbarChangeEnable("AddAssignedPhoneNumber");
    this.PhoneNumberInputBox.SetOnClickCallbackFunc(this.ClickPhoneNumberInputBox);
    this.PhoneNumberInputBox.SetReverseDisable(true);

	this.AddBtn = new Button();
	this.AddBtn.SetImageObjId("AddAssignedPhoneNumber_Add_Button", 20);
	this.AddBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.AddBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);
	this.AddBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
	this.AddBtn.SetTextObjId("AddAssignedPhoneNumber_Add_Button_Text");
	this.AddBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "cPopup_btn_text");
	this.AddBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "cPopup_btn_text_dim");
    this.AddBtn.SetText(SID_OK);    
 	this.AddBtn.SetOnClickCallbackFunc(this.ClickAddBtn);

	this.CancelBtn = new Button();
	this.CancelBtn.SetImageObjId("AddAssignedPhoneNumber_Cencel_Button", 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.SetTextObjId("AddAssignedPhoneNumber_Cencel_Button_text");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "cPopup_btn_text");
    this.CancelBtn.SetText(SID_CANCEL);
 	this.CancelBtn.SetOnClickCallbackFunc(this.ClickCancelBtn);
   
	this.LabelBtn.SetOnMouseOverCallbackFunc(function(obj) {scene.processMouseOver(obj);});
	this.CountryCodeBtn.SetOnMouseOverCallbackFunc(function(obj) {scene.processMouseOver(obj);});
	this.PhoneNumberInputBox.SetOnMouseOverCallbackFunc(function(obj) {scene.processMouseOver(obj);});
	this.AddBtn.SetOnMouseOverCallbackFunc(function(obj) {scene.processMouseOver(obj);});
	this.CancelBtn.SetOnMouseOverCallbackFunc(function(obj) {scene.processMouseOver(obj);});
}

SceneAddAssignedPhoneNumber.prototype.Init = function(Identity)
{
	this.TargetIdentity = Identity;
}

SceneAddAssignedPhoneNumber.prototype.GetAssignedIndex = function()
{

	alert("SceneAddAssignedPhoneNumber.GetAssignedIndex()");	
			
	var bUseFirstIndex = false;
	var bUseSecondIndex = false;
	var bUseThirdIndex = false;
	
	var AssignedLabel1		= PluginAPIMgr.GetAssignedPhoneNumberWithName(this.TargetIdentity,2);
	var AssignedLabel2		= PluginAPIMgr.GetAssignedPhoneNumberWithName(this.TargetIdentity,4);
	var AssignedLabel3		= PluginAPIMgr.GetAssignedPhoneNumberWithName(this.TargetIdentity,6);

	//2. Mobile
	if(AssignedLabel1 == "mobile")
	{
		bUseFirstIndex = true;
	}
	if(AssignedLabel2 == "mobile")
	{
		bUseSecondIndex = true;
	}
	if(AssignedLabel3 == "mobile")
	{
		bUseThirdIndex = true;
	}
		
	//3. Office
	if(AssignedLabel1 == "office")
	{
		bUseFirstIndex = true;
	}
	if(AssignedLabel2 == "office")
	{
		bUseSecondIndex = true;
	}
	if(AssignedLabel3 == "office")
	{
		bUseThirdIndex = true;
	}
	
	//3. Home
	if(AssignedLabel1 == "home")
	{
		bUseFirstIndex = true;
	}
	if(AssignedLabel2 == "home")
	{
		bUseSecondIndex = true;
	}
	if(AssignedLabel3 == "home")
	{
		bUseThirdIndex = true;
	}
	
	//4. other
	if(AssignedLabel1 == "other")
	{
		bUseFirstIndex = true;
	}
	if(AssignedLabel2 == "other")
	{
		bUseSecondIndex = true;
	}
	if(AssignedLabel3 == "other")
	{
		bUseThirdIndex = true;
	}
	
	if(bUseFirstIndex == false)
	{
		this.AssignedIndex = 1;
	}
	else if(bUseFirstIndex == true && bUseSecondIndex == false)
	{
		this.AssignedIndex = 2;
	}
	else if(bUseFirstIndex == true && bUseSecondIndex == true && bUseThirdIndex == false)
	{
		this.AssignedIndex = 3;
	}
	else 
	{
		this.AssignedIndex = 4;
	}
	
	alert("AssignedIndex = " + this.AssignedIndex);	
}

SceneAddAssignedPhoneNumber.prototype.initData = function()
{
    alert("SceneAddAssignedPhoneNumber.initData()"); 

	//Set Data
//	this.AssignedIndex		= g_Data.GetAssignedPhoneNumberIndex();	
	this.GetAssignedIndex();
	this.Type				= g_Data.GetAssignedPhoneNumberType();
	this.PrevPhoneNumber	= g_Data.GetAssignedPhoneNumberPhonenumber();
//	this.TargetIdentity		= g_Data.GetAssignedPhoneNumberName();

	alert("AssignedIndex = " + this.AssignedIndex); 	
	alert("Type = " + this.Type); 	
	alert("PrevPhoneNumber = " + this.PrevPhoneNumber); 
	alert("TargetIdentity = " + this.TargetIdentity); 
	//Set UI & Text
		
	//1.Set Display Name
	var DisplayName = PluginAPIMgr.GetContactPropWithName(this.TargetIdentity, ENUM_CONTACT_PROPERTY.P_DISPLAYNAME );
	this.MsgLabel.SetText(DisplayName);
		
	this.ShownPhoneNumberList = false;

	/*Set button
	if(this.Type > 0)
	{
		alert("Change/Delete Mode...."); 
		this.AddMode = false;
		
		//2. Set Label SubList
	    this.SetLabelButtonText(this.Type - 1);

		
		//Set Country Code 				
		this.CountryCode = PluginAPIMgr.FindCountryCodeByNumber(this.PrevPhoneNumber);		


		//Set Country Btn Image
		if(this.CountryCode.length >0)
		{
			this.CountryCodeBtn.SetFgImage(g_Image.base_flag_image_path + this.CountryCode.toUpperCase() + ".png");
		}
		else
		{
			this.CountryCodeBtn.SetFgImage("");
		}
		
		//Set Country Name
		var CountryName = PluginAPIMgr.GetISOCountryName(this.CountryCode);
     	this.CountryNameLabel.SetText(CountryName);
     	
     	//set Country prefix
		this.CountryPrefix	= PluginAPIMgr.GetISOCountryPrefix(this.CountryCode);
		this.CountryPrefixLabel.SetText(this.CountryPrefix);
		
	 	//set PhoneNumber InputBox text
	 	var LocalCode = PluginAPIMgr.GetLocalNumber(this.PrevPhoneNumber);
		this.PhoneNumberInputBox.setInitString(LocalCode);		
				
		//4. Set Button
	    this.OkBtn.blur();  		
	    this.OkBtn.Show();    
	    this.Cancel2Btn.Show();       
	    this.DeleteBtn.Show(); 
	    
	    this.AddBtn.Hide();
	    this.CancelBtn.Hide(); 

	}
	else */
	{
		alert("Add Mode...."); 
		this.AddMode = true;
		
		//2. Set Label SubList
		this.SetLabelButtonText(0);
		
		//3. Set Country Code 
		this.CountryCode = PluginAPIMgr.GetMyCountryCode();
		
		//Set Country Btn Image
		this.CountryCodeBtn.SetFgImage(PluginAPIMgr.GetMyCountryFlag());
		
		//Set Country Name
		this.CountryNameLabel.SetText(PluginAPIMgr.GetMyCountryName());
		
		//set Country prefix
		this.CountryPrefix = PluginAPIMgr.GetMyCountryPrefix();
	 
		if(this.CountryPrefix.length > 0 && this.CountryPrefix != "0" )
		{
			this.CountryPrefixLabel.SetText("+" + this.CountryPrefix);
		}
		else
		{
			this.CountryPrefixLabel.SetText("");
		}	 
		
	 	//set PhoneNumber InputBox text
		this.PhoneNumberInputBox.setInitString("");

		//4. Set Button
		this.AddBtn.SetFlagDim(true);
	}	
}

SceneAddAssignedPhoneNumber.prototype.highlight=function(obj)
{
	if(obj == this.AddBtn) {
		this.checkAddBtnEnable();
		if(this.AddBtn.GetFlagDim())
			return;
	}
	
    this.AddPhoneNumberView.setCurrenHighlight(obj);
    
    if(obj == this.PhoneNumberInputBox) {
   		this.ChangeHelpbar(2);
    } else {
    	this.ChangeHelpbar(0);
    }
   
}

SceneAddAssignedPhoneNumber.prototype.processReturnKey = function(){
    alert("SceneAssignedPhoneNumber.processReturnKey() ");
	
	this.highlight(null);	
	this.AddBtn.SetFlagDim(false);
	StateMgr.Stop_Add_Phone_Number_State(true);
	
	//Check....
	/*
	var scene = sf.scene.get(WndMgr.GetMainSubSceneID());	
		scene.Activation();	*/
	

}

SceneAddAssignedPhoneNumber.prototype.initInputBox = function(flagPWD, initText, maxLen, callerObj)
{
    alert("SceneAssignedPhoneNumber.initInputBox()");
    this.flagPWD = flagPWD;
    this.initText = initText;
    this.maxStringLenght = maxLen;
    this.callerObj = callerObj;
}


SceneAddAssignedPhoneNumber.prototype.DeleteAllText = function()
{	
	WndMgr.resetPopupHideTimer();
    this.PhoneNumberInputBox.setString("");
	
}

SceneAddAssignedPhoneNumber.prototype.processEnterKey = function(){
    alert("SceneAssignedPhoneNumber.processEnterKey() ");

    var currentHighlight =  this.AddPhoneNumberView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.CountryCodeBtn:
			this.showFlagList();
			break;
			
        case this.AddBtn: 	
			this.IputPhoneNumber();
			break;
			
        case this.CancelBtn: 	
			this.processReturnKey();
			break;			

        case this.LabelBtn:
			this.ShowLabelList();
			break;			      
    }
}


SceneAddAssignedPhoneNumber.prototype.processLeftKey = function()
{
    alert("SceneAddAssignedPhoneNumber.processLeftKey() ");

    var currentHighlight =  this.AddPhoneNumberView.getCurrentHighlight();

    switch(currentHighlight)
    {
        case this.PhoneNumberInputBox:    		
			this.highlight(this.CountryCodeBtn);	
			break;
        case this.CountryCodeBtn:    		
			this.highlight(this.PhoneNumberInputBox);	
			break;			
        case this.AddBtn:    		
			this.highlight(this.CancelBtn);	
			break;
        case this.CancelBtn:            
			this.highlight(this.AddBtn);
			break;
    }
}

SceneAddAssignedPhoneNumber.prototype.processRightKey = function()
{
    alert("SceneAddAssignedPhoneNumber.processRightKey() ");

    var currentHighlight = this.AddPhoneNumberView.getCurrentHighlight();
	
	switch(currentHighlight)
    {
        case this.CountryCodeBtn:    		
			this.highlight(this.PhoneNumberInputBox);	
			break;
        case this.PhoneNumberInputBox:    		
			this.highlight(this.CountryCodeBtn);
			break;			
        case this.AddBtn:    		
			this.highlight(this.CancelBtn);	
			break;
        case this.CancelBtn:    		
				this.highlight(this.AddBtn);
			
			break;
    }

}

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

    var currentHighlight =  this.AddPhoneNumberView.getCurrentHighlight();

	switch(currentHighlight)
    {
        case this.AddBtn:    		
        case this.CancelBtn:    		
			this.highlight(this.PhoneNumberInputBox);
			break;

        case this.CountryCodeBtn:    		
        case this.PhoneNumberInputBox:    		
			this.highlight(this.LabelBtn);	
			break;
    }
}

SceneAddAssignedPhoneNumber.prototype.processDownKey = function()
{

    var currentHighlight =  this.AddPhoneNumberView.getCurrentHighlight();

	switch(currentHighlight)
    {
        case this.LabelBtn:    		
			this.highlight(this.PhoneNumberInputBox);
			break;

        case this.CountryCodeBtn:    		
        case this.PhoneNumberInputBox:    		
			if(!this.AddBtn.GetFlagDim()) {
				this.highlight(this.AddBtn);
			} else {
				this.highlight(this.CancelBtn);
			}
			break;
    }
}


SceneAddAssignedPhoneNumber.prototype.comebackCallScene= function()
{
	alert("SceneAddAssignedPhoneNumber.comebackCallScene() ");
	
}

SceneAddAssignedPhoneNumber.prototype.showFlagList = function()
{
	alert("SceneAddAssignedPhoneNumber.showFlagList() ");

	var This_ = sf.scene.get("AddAssignedPhoneNumber");

	alert("CountryCode = " + This_.CountryCode);
	
	var Index = g_Data.GetCountryIndexWithCode(This_.CountryCode);	
	alert("Index = " + Index);

	sf.scene.get("CountryFlagList").SetCurIndex(Index);
	sf.scene.show("CountryFlagList");
	sf.scene.focus("CountryFlagList");
	
	this.ShownFlagList = true;	
}


SceneAddAssignedPhoneNumber.prototype.SetCountryFlag = function()
{
    alert("SceneAddAssignedPhoneNumber.SetCountryFlag() ");
	
	var Scene = sf.scene.get("CountryFlagList");	
	
	var FlagImage = Scene.GetCountryFlag();
	var CountryCode = Scene.GetCountryCode();
	var Prefix = Scene.GetPrefix();
	var CountryName = Scene.GetCountryName();
		
		
	var This_ = sf.scene.get("AddAssignedPhoneNumber");	
	This_.SetCountryData(CountryCode,Prefix,CountryName,FlagImage);
	
}

SceneAddAssignedPhoneNumber.prototype.SetCountryData = function(code,prefix,name,flagImage)
{
	this.CountryCode = code;	
	this.CountryPrefix = prefix;	
	//Set UI
	this.CountryCodeBtn.SetFgImage(flagImage);	
	this.CountryPrefixLabel.SetText("+"+prefix);
 	this.CountryNameLabel.SetText(name);	
	
}

SceneAddAssignedPhoneNumber.prototype.ShowLabelList = function(){

    alert("SceneAddAssignedPhoneNumber.ShowLabelList() ");

	//only 0,1,2,3
	var LabelType = this.Type;
	
	var this_ = sf.scene.get("AddAssignedPhoneNumber");
		
	sf.scene.get('AddAssignedPhoneLabelSeletor').Init(LabelType,this_.SetLabelButtonText);
	sf.scene.show('AddAssignedPhoneLabelSeletor');
	sf.scene.focus('AddAssignedPhoneLabelSeletor');
	
	this.ShownLabelList = true;
		
}


SceneAddAssignedPhoneNumber.prototype.SetLabelButtonText = function(LabelIndex)
{
    alert("SceneAddAssignedPhoneNumber.SetLabelButtonText(" + LabelIndex + ")");
    
    var LabelText = null;
        
    switch(LabelIndex)
    {
    	case 0:
    		LabelText = IDWS_MOIP_MOBILE;
    		break;    	
    	case 1:
    		LabelText = IDWS_MOIP_OFFICE;    	
    		break;
    	case 2:
    		LabelText = SID_HOME_KR_HOMEPHONE;
    		break;
    	case 3:
    		LabelText = SID_COUNTRY_OTHER;
    		break;    		
    }
    
    var this_ = sf.scene.get("AddAssignedPhoneNumber");
    
    this_.LabelBtn.SetText(LabelText);
	this_.Type = LabelIndex;
}


//LabelText is only engilsh text.. it is code!!
//Sync SceneListMainContactPhoneNumberList.SetPhoneNumberArray
//mobile
//office
//home
//other

SceneAddAssignedPhoneNumber.prototype.IputPhoneNumber = function()
{
	alert("SceneAddAssignedPhoneNumber.IputPhoneNumber()");
	
	var normalized_phone_number = null;
	var phone_number = this.GetPhoneNumber();
	    	     
	if(phone_number)
		normalized_phone_number = PluginAPIMgr.NormalizeIdentity(phone_number);	
	if(normalized_phone_number != null &&  normalized_phone_number.length > 0)
	{
		alert("SkypeName = " + this.TargetIdentity);
		alert("AssignedIndex = " + this.AssignedIndex);		
		alert("PhoneNumber = " + normalized_phone_number);
		
		var LabelText = null;
		
	    switch(this.Type)
	    {
	    	case 0:
	    		LabelText = "mobile";
	    		break;    	
	    	case 1:
	    		LabelText = "office";    	
	    		break;
	    	case 2:
	    		LabelText = "home";
	    		break;
	    	case 3:
	    		LabelText = "other";
	    		break;
	    		
	    }		
		alert("LabelText = " + LabelText);
		
	alert("SceneAddAssignedPhoneNumber.IputPhoneNumber("+normalized_phone_number+")");
	    PluginAPIMgr.SetAssignedPhoneNumber(this.TargetIdentity,this.AssignedIndex,LabelText,normalized_phone_number);	    		
	}
	else
	{
		alert("NormalizeIdentity Error!!!" );
	}
			
	this.processReturnKey();
	//added 10.5
	var scene = sf.scene.get(WndMgr.GetMainSubSceneID());	
		scene.Activation();
}


SceneAddAssignedPhoneNumber.prototype.GetPhoneNumber = function()
{
	
	alert("SceneAddAssignedPhoneNumber.GetPhoneNumber()");

	var input_phone_number = this.PhoneNumberInputBox.GetText();   
	var temp_phone_number = null;

	if(input_phone_number != null && input_phone_number.length > 0 ) {
	    if(input_phone_number.indexOf("+") == 0)
	    {
//	        return input_phone_number;
	    }
	    else if(input_phone_number.indexOf("00") == 0 )
	    {
//	        return input_phone_number;
	    }
	    else if(input_phone_number.indexOf("011") == 0)
	    {
//	        return input_phone_number;
	    }
	    else
	    {
			if(this.CountryPrefix != "0")
			{
				temp_phone_number = "+" + this.CountryPrefix + input_phone_number;
				input_phone_number = temp_phone_number;
			}
			else
			{
//				return  input_phone_number;
			}       
	    }   
	}else {
		input_phone_number = null;
	}

	alert("SceneAddAssignedPhoneNumber.GetPhoneNumber( "+input_phone_number+" )");
	return input_phone_number;
}

SceneAddAssignedPhoneNumber.prototype.DeletePhoneNumber = function()
{
	alert("SceneAddAssignedPhoneNumber.DeletePhoneNumber()");
	
	alert("SkypeName = " + this.TargetIdentity);
	alert("AssignedIndex = " + this.AssignedIndex);		
	alert("PhoneNumber = null");
	alert("LabelText = none");
			
	PluginAPIMgr.SetAssignedPhoneNumber(this.TargetIdentity,this.AssignedIndex,null,null);	    		

	this.processReturnKey();
}

SceneAddAssignedPhoneNumber.prototype.callbackPhoneNumberInput = function(keyCode)
{
    this.checkCallBtnEnable();
}

SceneAddAssignedPhoneNumber.prototype.checkCallBtnEnable = function()
{
    alert("SceneAddAssignedPhoneNumber.checkCallBtnEnable() ");
    
	var phone_number = this.GetPhoneNumber();
	    	     
	if(phone_number != null && phone_number.length > 0 && phone_number.length != 0) {
		
		var normalized_phone_number = PluginAPIMgr.NormalizeIdentity(phone_number);	

    alert("SceneAddAssignedPhoneNumber.normalized_phone_number("+normalized_phone_number+") ");
		if(normalized_phone_number != null && normalized_phone_number.length > 0 && normalized_phone_number.length != 0)
		{
	   		this.setAddOkBtnEnable(true);
		}
		else{
			this.setAddOkBtnEnable(false);
		}
	} else{
		this.setAddOkBtnEnable(false);
	}
}

SceneAddAssignedPhoneNumber.prototype.setAddOkBtnEnable= function(flag_enable)
{
	alert("SceneAddAssignedPhoneNumber.setAddOkBtnEnable() : " + flag_enable);
	
    if(flag_enable == true) {
			this.AddBtn.SetFlagDim(false);
    } else {
			this.AddBtn.SetFlagDim(true);
    }
}

SceneAddAssignedPhoneNumber.prototype.checkAddBtnEnable = function() {
	alert("SceneChangePhoneNumber.checkAddBtnEnable() ");
	
	var input_phone_number = this.PhoneNumberInputBox.GetText();

	if(input_phone_number.length > 0) {

		var add_prefix_phone_number = this.addCountryPrefix(input_phone_number);

		alert("add_prefix_phone_number : " + add_prefix_phone_number);

		this.NormalizedPhoneNumber = PluginAPIMgr.NormalizeIdentity(add_prefix_phone_number);

		if(this.NormalizedPhoneNumber.length > 0) {

			var is_emergency_call = PluginAPIMgr.IsEmergencyCall(this.NormalizedPhoneNumber);

			if(is_emergency_call == 1) {
				this.AddBtn.SetFlagDim(true);
			} else {
				this.AddBtn.SetFlagDim(false);
			}
		} else {
			this.AddBtn.SetFlagDim(true);
		}
	} else {
		this.AddBtn.SetFlagDim(true);
	}
}

SceneAddAssignedPhoneNumber.prototype.addCountryPrefix = function(input_phone_number) {
	alert("SceneAddContactPhoneNumber.addCountryPrefix() --> this.CountryPrefix : " + this.CountryPrefix);

	if(input_phone_number.indexOf("+") == 0) {
		return input_phone_number;
	} else if(input_phone_number.indexOf("00") == 0) {
		return input_phone_number;
	} else if(input_phone_number.indexOf("011") == 0) {
		return input_phone_number;
	} else {
		if(this.CountryPrefix != "0") {
			return "+" + this.CountryPrefix + input_phone_number;
		} else {
			return input_phone_number;
		}
	}
}

SceneAddAssignedPhoneNumber.prototype.processMouseOver = function(obj) {
	alert("SceneAddAssignedPhoneNumber.processMouseOver");	

	var currentHighlight = this.AddPhoneNumberView.getCurrentHighlight();
	//add : smartcontrol highlight issue(130926)
	if(PluginAPIMgr.FlagSmartControlNumber()==1){
		return;
	}
	if(currentHighlight != obj) {
		this.highlight(obj);
		WndMgr.resetPopupHideTimer();
	}
}

SceneAddAssignedPhoneNumber.prototype.ClickLabelBtn = function(){
	alert("SceneAddAssignedPhoneNumber.ClickLabelBtn");	

	var This_ = sf.scene.get('AddAssignedPhoneNumber');
	This_.highlight(This_.LabelBtn);
	This_.ShowLabelList();
}

SceneAddAssignedPhoneNumber.prototype.ClickCountryCodeBtn = function(){
	alert("SceneAddAssignedPhoneNumber.ClickCountryCodeBtn");	

	var This_ = sf.scene.get('AddAssignedPhoneNumber');
	This_.highlight(This_.CountryCodeBtn);
	This_.showFlagList();
}

SceneAddAssignedPhoneNumber.prototype.ClickAddBtn = function(){
	alert("SceneAddAssignedPhoneNumber.ClickAddBtn");	

	var This_ = sf.scene.get('AddAssignedPhoneNumber');
	This_.IputPhoneNumber();
}

SceneAddAssignedPhoneNumber.prototype.ClickCancelBtn = function(){
	alert("SceneAddAssignedPhoneNumber.ClickCancelBtn");	

	var This_ = sf.scene.get('AddAssignedPhoneNumber');
	This_.processReturnKey();
}

SceneAddAssignedPhoneNumber.prototype.ClickPhoneNumberInputBox = function(){
	alert("SceneAddAssignedPhoneNumber.ClickPhoneNumberInputBox");	

	var This_ = sf.scene.get('AddAssignedPhoneNumber');
	This_.highlight(This_.PhoneNumberInputBox);
}

SceneAddAssignedPhoneNumber.prototype.startKeypad = function(){
    alert("SceneAddAssignedPhoneNumber.startKeypad() ");
    		
	WndMgr.stopPopupHideTimer();

    var TimerCallbackFunc = function(){WndMgr.restartPopupHideTimer();};

    WndMgr.StartKeypad(this.PhoneNumberInputBox, "AddAssignedPhoneNumber", TimerCallbackFunc);
         
}

SceneAddAssignedPhoneNumber.prototype.inputDelete = function(){
    alert("SceneAddAssignedPhoneNumber.inputDelete() ");

	WndMgr.resetPopupHideTimer();
			        
    this.PhoneNumberInputBox.processPreChKey();

}

SceneAddAssignedPhoneNumber.prototype.ChangeHelpbar = function(type,str) {
	var dataInfo="";
	if(str){
		dataInfo = str;
	}else{
		switch(type){
			case 0:
				dataInfo = {
					'return' : SID_RETURN
				};
				break;
			case 1:
				dataInfo = {
			'ff' : SID_NUMBER,
					'play' : SID_DELETE, //not support
			'return' : SID_RETURN
		};
				break;
			case 2:
				dataInfo = {
			'ff' : SID_NUMBER,
					'stop' : "+",
			'return' : SID_RETURN
		};
				break;
			case 3:
				dataInfo = {
					'ff' : SID_NUMBER,
			'return' : SID_RETURN
		};
				break;
		}
	}
	if(dataInfo.length!=0)
		this.AddPhoneNumberViewBg.SetHelpbarContentsOfPopupBG(dataInfo);
		
}

