function SceneChatMsgSend(options) {
	this.options = options;
    
    this.ChatMsgSendView=null;
	this.ChatMsgSendDim=null;
    
    this.TitleBar = null;    
    
    this.TextInputBox = null;
	this.MsgLengthLabel = null;
    
    this.flagPWD = false;
    this.initText ="";
    this.maxStringLenght = 60;
    this.callerObj = null;
    
    this.isSendEnable = false;
	
	this.backupString = "";
	this.useBackupString = false;
	
	this.IMEObj = null;
	this.TextInputTimer = false;
}

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

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

	this.TextInputBox.initKeySet();
	
	if(this.useBackupString==false)
	{
		this.TextInputBox.initInputBox( this.flagPWD, this.initText, this.maxStringLenght,  this.callerObj );	
	}
	else
	{
		this.TextInputBox.initInputBox( this.flagPWD, this.backupString, this.maxStringLenght,  this.callerObj );
		this.useBackupString = false;
	}  
	
	this.startTimer();  
}

SceneChatMsgSend.prototype.handleHide = function () {
	alert("SceneChatMsgSend.handleHide()");
	// this function will be called when the scene manager hide this scene  
	this.backupString = this.TextInputBox.GetText(); 
	
	this.ChatMsgSendDim.hide();
	
	var obj = this.ChatMsgSendView.getCurrentHighlight();
	if(obj != null)
	{
		obj.imeHide();	
	}

	_g_ime.pluginRecog_use_YN = true;
	
	this.MsgLengthLabel.SetText("");
	
	if(this.TextInputTimer==true)
	{
		this.stopTimer();
	}
}

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

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

}

SceneChatMsgSend.prototype.handleKeyDown = function (keyCode) {
	alert("SceneChatMsgSend.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) {
		case sf.key.LEFT:
		case sf.key.RIGHT:

			break;
		case sf.key.UP:

			break;
		case sf.key.DOWN:

			break;
	
		case sf.key.ENTER:
			this.processEnterKey();
			break;
            
        case sf.key.RETURN:
            this.processReturnKey();
			sf.key.preventDefault();
			break;
            
         case sf.key.EXIT:
            //this.processExitKey();
			sf.key.preventDefault();
			break;
            
        case 147:  //infolink
        case 261:  //contents
        case 115:  //wiselink
            sf.key.block(event);
			break;
	}
}

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

SceneChatMsgSend.prototype.create = function(){
    alert("SceneChatMsgSend.create()");
    this.ChatMsgSendView = new View("ChatMsgSend");
    this.ChatMsgSendView.SetBgImage(WndMgr.Bg_ChatMsg.src);
	
	this.ChatMsgSendDim = new DimBg("ChatMsgSendDim", "ChatMsgSend");
    
    this.TitleBar = new Label(null,"chat_msg_send_title");
    this.TitleBar.SetTextStyle("chat_msg_send_title_style");
    this.TitleBar.SetText(TV_SID_SEND_MESSAGE);
    
    this.TextInputBox= new InputBox();
	this.TextInputBox.SetButtonObjId("chat_msg_send_input_box");
    this.TextInputBox.SetButtonTextObjId("chat_msg_send_input_box_text");
	this.TextInputBox.SetInputBoxObjId("chat_msg_send_input_box_editor");
	this.TextInputBox.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_INPUT_BOX_NORMAL);
	this.TextInputBox.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_INPUT_BOX_NORMALFOCUS);	
	this.TextInputBox.setKeypadPos(675,100);
    this.TextInputBox.setWordBoxPos(236,50);
    
	this.MsgLengthLabel = new Label(null,"chat_msg_send_msg_length");
    this.MsgLengthLabel.SetTextStyle("chat_msg_send_msg_length_style");
    this.MsgLengthLabel.SetText("");
	
}

SceneChatMsgSend.prototype.setUseBackupSting=function(flagUse)
{
	this.useBackupString = flagUse;
}

SceneChatMsgSend.prototype.highlight=function(obj)
{
    this.ChatMsgSendView.setCurrenHighlight(obj);
   
   if(obj != null)
   {
   	   var scene = sf.scene.get("ChatMsgSend");
    	
    if(ProcMgr.GetIsInCall())
    {
    	_g_ime.pluginRecog_use_YN = false;
    }	
    
    var ime = new IMEShell(obj.IMEObjInfo.id, scene.imeReady, 'en' /*, 'en' ,  "2_35_259"*/); 
   }
   else
   {
   	 this.TextInputBox.imeHide();
   }
}

SceneChatMsgSend.prototype.processReturnKey = function(){
    alert("SceneChatMsgSend.processReturnKey() ");
	this.highlight(null);
    StateMgr.Stop_Chat_Msg_Send_State(true);
			sf.key.preventDefault();
}

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

    var send_msg = this.TextInputBox.GetText();

    if(this.isSendEnable ==true)
    {	
		this.highlight(null);
        ProcMgr.SendMessage(send_msg);
    }
}

SceneChatMsgSend.prototype.imeReady = function(imeObject){
    alert("SceneChatMsgSend.imeReady() ");

	var scene = sf.scene.get("ChatMsgSend");
	var obj = scene.ChatMsgSendView.getCurrentHighlight();
	
	obj.imeShow(imeObject);
	
    obj.setKeyFunc(88,  function(keyCode){scene.processReturnKey();  return false;}); // return key
    obj.setKeyFunc(45,  function(keyCode){scene.processReturnKey(); sf.key.preventDefault(); return false;}); // exit key
	obj.setKeyFunc(108,  function(keyCode){scene.DeleteAllText();  return false;}); // red key
    obj.setKeyFunc(222,  function(keyCode){sf.key.preventDefault();  return false;}); // source
    
	obj.setKeyFunc(147,  function(keyCode){sf.key.preventDefault();  return false;}); // infolink
	obj.setKeyFunc(261,  function(keyCode){sf.key.preventDefault();  return false;}); // contents
	obj.setKeyFunc(115,  function(keyCode){sf.key.preventDefault();  return false;}); // wiselink
    
    obj.setOnCompleteFunc(function(keyCode){scene.updateMsgLength(); scene.checkSendEnable(); scene.resetTimer(); return false;})
    obj.setAnyKeyFunc(function(keyCode){scene.resetTimer();  return false;});
    obj.setEnterFunc( function(keyCode){scene.processEnterKey();  return false;});
    
    obj.setKeySetFunc("qwerty");
    
	obj.setReady();
	
	scene.updateMsgLength();
	scene.checkSendEnable();
}

SceneChatMsgSend.prototype.updateMsgLength = function()
{
	alert("SceneChatMsgSend.updateMsgLength() ");
    var obj = this.ChatMsgSendView.getCurrentHighlight();
    var input_string = obj.getString();
	
	obj.SetText(input_string);
	this.MsgLengthLabel.SetText(String(input_string.length) +"/" +String(this.maxStringLenght));  	
}


SceneChatMsgSend.prototype.GetInputText = function()
{
    var obj = this.ChatMsgSendView.getCurrentHighlight();
    return obj.getString();
}

SceneChatMsgSend.prototype.DeleteAllText = function()
{
	this.resetTimer();
    var obj = this.ChatMsgSendView.getCurrentHighlight();
    obj. setString("");
    
	this.updateMsgLength();
    this.checkSendEnable();
}


SceneChatMsgSend.prototype.checkSendEnable = function()
{
    var input_text = this.TextInputBox.GetText();
    
    if(input_text.length ==0)
    {
        this.isSendEnable = false;
    }
    else
    {
        var a=0;
        for(a=0; a<input_text.length; a++)
        {
            this.isSendEnable = false;
             var ch = input_text.substring(a,  a+1);
             if(ch !=" ")
             {
                 this.isSendEnable = true;
                 break;
}
        }
    }
    
    alert("SceneChatMsgSend.checkSendEnable()  :  " +this.isSendEnable);
}

SceneChatMsgSend.prototype.startTimer = function()
{
    alert("SceneChatMsgSend.startTimer() ");
	
	this.TextInputTimer = true;
	PluginAPIMgr.StartOSDTimer("60000" , function() { sf.scene.get('ChatMsgSend').popupTimerCallback();}, ENUM_TIMER_TYPE.TEXT_INPUT);
}

SceneChatMsgSend.prototype.resetTimer = function()
{
    alert("SceneChatMsgSend.resetTimer() ");

	if(this.TextInputTimer == true)
	{
		PluginAPIMgr.RestartOSDTimer("60000" ,ENUM_TIMER_TYPE.TEXT_INPUT);
	}
}

SceneChatMsgSend.prototype.stopTimer = function()
{
    alert("SceneChatMsgSend.stopTimer() ");
	
	this.TextInputTimer = false;
	PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.TEXT_INPUT);
}

SceneChatMsgSend.prototype.popupTimerCallback = function()
{
   alert("SceneChatMsgSend.popupTimerCallback() ");
   	if(this.TextInputTimer == false)
	{
		return;
	}	
	
	this.TextInputTimer = false;
	
	this.highlight(null);
    StateMgr.Stop_Chat_Msg_Send_State(true);
}




