function SceneKeypad(options) {
	this.options = options;
    
    this.MainView=null;
   
   	this.SubView1=null;
   	this.SubView2=null; 
   
    this.Number1Btn=null;
    this.Number2Btn=null;
    this.Number3Btn=null;
    this.Number4Btn=null;
    this.Number5Btn=null;
    this.Number6Btn=null;
    this.Number7Btn=null;
    this.Number8Btn=null;
    this.Number9Btn=null;
    this.Number0Btn=null;
    this.StarBtn=null;
    this.SharpBtn=null;
    this.LeftBtn=null;
    this.EnterBtn=null;
    this.RightBtn=null;
    
    this.NumBtnList = new Array(15);
    this.SelectTimer = null;
    
    this.CallerObj = null;
    this.CallerSceneId ="";
    
    this.CloseTimer = false;
}

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

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

SceneKeypad.prototype.handleHide = function () {
	alert("SceneKeypad.handleHide()");
	// this function will be called when the scene manager hide this scene  
	
	if(this.CloseTimer==true)
	{
		this.stopTimer();
	}
	clearTimeout(this.SelectTimer);
}

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

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

}

SceneKeypad.prototype.handleKeyDown = function (keyCode) {
	alert("SceneKeypad.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
			
	switch (keyCode) {
		case sf.key.LEFT:
        
			break;
		case sf.key.RIGHT:

			break;
		case sf.key.UP:

			break;
		case sf.key.DOWN:

			break;

		case sf.key.ENTER:

			break;
            
        case sf.key.RETURN:

			break;
            
        case sf.key.RED:

			break;
            
        case sf.key.EXIT:

			break;
            
         case 147:  //infolink
         case 261:  //contents
         case 115:  //wiselink

			break;
            
        default:

            break;  
	}
}

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

SceneKeypad.prototype.create = function(){
    alert("SceneKeypad.create()");
    this.MainView = new View("KeyPad");
    
    this.SubView1 = new View("keypad_bg");
    this.SubView1.SetBgImage(g_Image.IMAGE_KEYPAD_BG);
    this.SubView2 = new View("keypad_alpha_bg");
    this.SubView2.SetBgImage(g_Image.IMAGE_KEYPAD_ALPHA_BG);
    
///// number key pad //////////////////////////////////////////////////////////////////////////////////////////////////////

    this.Number1Btn = new Label("keypad_number_1_btn", null);
    this.Number2Btn = new Label("keypad_number_2_btn", null);
    this.Number3Btn = new Label("keypad_number_3_btn", null);
    this.Number4Btn = new Label("keypad_number_4_btn", null);
    this.Number5Btn = new Label("keypad_number_5_btn", null);
    this.Number6Btn = new Label("keypad_number_6_btn", null);
    this.Number7Btn = new Label("keypad_number_7_btn", null);
    this.Number8Btn = new Label("keypad_number_8_btn", null);
    this.Number9Btn = new Label("keypad_number_9_btn", null);
    this.StarBtn = new Label("keypad_star_btn", null);
    this.Number0Btn = new Label("keypad_number_0_btn", null);
    this.SharpBtn = new Label("keypad_sharp_btn", null);
  	this.LeftBtn = new Label("keypad_left_btn", null);
    this.EnterBtn = new Label("keypad_enter_btn", null);
    this.RightBtn = new Label("keypad_right_btn", null);
    
    var a=0;
     for(a=0; a<this.NumBtnList.length; a++)
     {
         this.NumBtnList[a]=new Object();
     }
     
     this.NumBtnList[0].obj =  this.Number1Btn;
     this.NumBtnList[1].obj =  this.Number2Btn;
     this.NumBtnList[2].obj =  this.Number3Btn;
     this.NumBtnList[3].obj =  this.Number4Btn;
     this.NumBtnList[4].obj =  this.Number5Btn;
     this.NumBtnList[5].obj =  this.Number6Btn;
     this.NumBtnList[6].obj =  this.Number7Btn;
     this.NumBtnList[7].obj =  this.Number8Btn;
     this.NumBtnList[8].obj =  this.Number9Btn;
     this.NumBtnList[9].obj =  this.StarBtn;
     this.NumBtnList[10].obj = this.Number0Btn;
     this.NumBtnList[11].obj = this.SharpBtn;
  	 this.NumBtnList[12].obj =  this.LeftBtn;
     this.NumBtnList[13].obj = this.EnterBtn;
     this.NumBtnList[14].obj = this.RightBtn;
     
    this.NumBtnList[0].norImage = g_Image.IMAGE_KEYPAD_NUMBER_1;
    this.NumBtnList[1].norImage = g_Image.IMAGE_KEYPAD_NUMBER_2;
    this.NumBtnList[2].norImage = g_Image.IMAGE_KEYPAD_NUMBER_3;
    this.NumBtnList[3].norImage = g_Image.IMAGE_KEYPAD_NUMBER_4;
    this.NumBtnList[4].norImage = g_Image.IMAGE_KEYPAD_NUMBER_5;
    this.NumBtnList[5].norImage = g_Image.IMAGE_KEYPAD_NUMBER_6;
    this.NumBtnList[6].norImage = g_Image.IMAGE_KEYPAD_NUMBER_7;
    this.NumBtnList[7].norImage = g_Image.IMAGE_KEYPAD_NUMBER_8;
    this.NumBtnList[8].norImage = g_Image.IMAGE_KEYPAD_NUMBER_9;
    this.NumBtnList[9].norImage = g_Image.IMAGE_KEYPAD_NUMBER_HYPHEN;
    this.NumBtnList[10].norImage = g_Image.IMAGE_KEYPAD_NUMBER_0;
    this.NumBtnList[11].norImage = g_Image.IMAGE_KEYPAD_NUMBER_PRECH;
  	this.NumBtnList[12].norImage = g_Image.IMAGE_KEYPAD_NUMBER_LEFT;
    this.NumBtnList[13].norImage = g_Image.IMAGE_KEYPAD_NUMBER_ENTER;
    this.NumBtnList[14].norImage = g_Image.IMAGE_KEYPAD_NUMBER_RIGHT;
    
    this.NumBtnList[0].selImage = g_Image.IMAGE_KEYPAD_NUMBER_1_PRESS;
    this.NumBtnList[1].selImage = g_Image.IMAGE_KEYPAD_NUMBER_2_PRESS;
    this.NumBtnList[2].selImage = g_Image.IMAGE_KEYPAD_NUMBER_3_PRESS;
    this.NumBtnList[3].selImage = g_Image.IMAGE_KEYPAD_NUMBER_4_PRESS;
    this.NumBtnList[4].selImage = g_Image.IMAGE_KEYPAD_NUMBER_5_PRESS;
    this.NumBtnList[5].selImage = g_Image.IMAGE_KEYPAD_NUMBER_6_PRESS;
    this.NumBtnList[6].selImage = g_Image.IMAGE_KEYPAD_NUMBER_7_PRESS;
    this.NumBtnList[7].selImage = g_Image.IMAGE_KEYPAD_NUMBER_8_PRESS;
    this.NumBtnList[8].selImage = g_Image.IMAGE_KEYPAD_NUMBER_9_PRESS;
    this.NumBtnList[9].selImage = g_Image.IMAGE_KEYPAD_NUMBER_HYPHEN_PRESS;
    this.NumBtnList[10].selImage = g_Image.IMAGE_KEYPAD_NUMBER_0_PRESS;
    this.NumBtnList[11].selImage = g_Image.IMAGE_KEYPAD_NUMBER_PRECH_PRESS;
  	this.NumBtnList[12].selImage = g_Image.IMAGE_KEYPAD_NUMBER_LEFT_PRESS;
    this.NumBtnList[13].selImage = g_Image.IMAGE_KEYPAD_NUMBER_ENTER_PRESS;
    this.NumBtnList[14].selImage = g_Image.IMAGE_KEYPAD_NUMBER_RIGHT_PRESS;
    
     for(a=0; a<this.NumBtnList.length; a++)
     {
        this.NumBtnList[a].obj.AppendFgImage(this.NumBtnList[a].obj.GetImageObjId()+"_icon","4px", "4px", "52px", "52px");
     	this.NumBtnList[a].obj.SetFgImage(this.NumBtnList[a].norImage);
     	this.NumBtnList[a].obj.isSelected = false;
     }	 
      
 // for processing mouse click event    
	this.NumBtnList[0].key =  sf.key.N1;
	this.NumBtnList[1].key =  sf.key.N2;
	this.NumBtnList[2].key =  sf.key.N3;
	this.NumBtnList[3].key =  sf.key.N4;
	this.NumBtnList[4].key =  sf.key.N5;
	this.NumBtnList[5].key =  sf.key.N6;
	this.NumBtnList[6].key =  sf.key.N7;
	this.NumBtnList[7].key =  sf.key.N8;
	this.NumBtnList[8].key =  sf.key.N9;
	if(ProcMgr.isTTXMIX == false)
	{
		this.NumBtnList[9].key =  35;  //plus100
	}
	else
	{
		this.NumBtnList[9].key =  650; // TTXMIX
	}	
	this.NumBtnList[10].key = sf.key.N0;
	this.NumBtnList[11].key = 259; // Pre-ch
	this.NumBtnList[12].key = sf.key.LEFT;
    this.NumBtnList[13].key = sf.key.ENTER;
    this.NumBtnList[14].key = sf.key.RIGHT;
	var this_ = sf.scene.get('Keypad');
	var keypadClickCF = function(obj){this_.processKeyPadClickEvent(obj);};
	
    for(a=0; a<this.NumBtnList.length; a++)
    {
        this.NumBtnList[a].obj.SetOnClickCallbackFunc(keypadClickCF);
    }
}

SceneKeypad.prototype.initData = function(KeypadCallerObj, KeypadCallerSceneId)
{
    alert("SceneKeypad.initData()"); 
    
    this.CallerObj = KeypadCallerObj;
    this.CallerSceneId = KeypadCallerSceneId;
}

SceneKeypad.prototype.initKeypad = function()
{
    alert("SceneKeypad.initKeypad()"); 
   
    var init_index = 4;
   	this.NumBtnList[init_index].obj.SetBgImage(g_Image.IMAGE_KEYPAD_NUMBER_HIGHLIGHT);
 	//this.NumBtnList[init_index].obj.SetFgImage(this.NumBtnList[init_index].selImage);
	this.NumBtnList[init_index].isSelected=true;    
}

SceneKeypad.prototype.processKeyPadClickEvent = function(obj){
	alert("SceneKeypad.processKeyPadClickEvent() ");
	
	var index=15;
   	for(a=0; a<this.NumBtnList.length; a++)
    {
        if(this.NumBtnList[a].obj==obj)
        {
        	index = a;
        	break;
        }
    }
    
    if(index<0 || index>=15)
    {
    	return;
    }
    
    this.resetTimer();
    this.selectKeypad(index);
	
	if(index==11)
	{
		this.CallerObj.processPreChKey();
	}
	else if(index==12)
	{
		this.CallerObj.moveLeft();
	}
	else if(index==13)
	{
		WndMgr.StopKeypad(); 
	}
	else if(index==14)
	{
		this.CallerObj.moveRight();
	}
	else
	{
		this.CallerObj.processNumberKey(this.NumBtnList[index].key)
	}
}

SceneKeypad.prototype.selectTimerCallback= function()
{
     alert("SceneKeypad.selectTimerCallback() ");
     
     for(a=0; a<this.NumBtnList.length; a++)
     {     
		if(this.NumBtnList[a].isSelected== true)
		{
			this.NumBtnList[a].obj.SetBgImage("");
     		//this.NumBtnList[a].obj.SetFgImage(this.NumBtnList[a].norImage);
     		this.NumBtnList[a].obj.isSelected = false;
		}
     } 
}

SceneKeypad.prototype.selectKeypad = function(index)
{
    alert("SceneKeypad.selectKeypad() ");

     for(a=0; a<this.NumBtnList.length; a++)
     {     
	 	if(this.NumBtnList[a].isSelected== true)
		{
		 	this.NumBtnList[a].obj.SetBgImage("");
		 	//this.NumBtnList[a].obj.SetFgImage(this.NumBtnList[a].norImage);
			this.NumBtnList[a].isSelected=false;
		}
     } 
     
	this.NumBtnList[index].obj.SetBgImage(g_Image.IMAGE_KEYPAD_NUMBER_HIGHLIGHT);
 	//this.NumBtnList[index].obj.SetFgImage(this.NumBtnList[index].selImage);
	this.NumBtnList[index].isSelected=true;
	
    this.SelectTimer=setTimeout("timerCF()", 300);
    timerCF = function() { sf.scene.get("Keypad").selectTimerCallback();}
}

SceneKeypad.prototype.startTimer = function()
{
    alert("SceneKeypad.startTimer() ");
	
	this.CloseTimer = true;
	PluginAPIMgr.StartOSDTimer("60000" , function() { sf.scene.get('Keypad').popupTimerCallback();}, ENUM_TIMER_TYPE.OTHER);
}

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

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

SceneKeypad.prototype.stopTimer = function()
{
    alert("SceneKeypad.stopTimer() ");
	
	this.CloseTimer = false;
	PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.OTHER);
}

SceneKeypad.prototype.popupTimerCallback = function()
{
	alert("SceneKeypad.popupTimerCallback() ");
	if(this.CloseTimer==false)
   	{
   		return;
   	}
   this.CloseTimer = false;

   WndMgr.StopKeypad();
}

SceneKeypad.prototype.pressKey = function(keycode)
{
	alert("SceneKeypad.pressKey() ");
	
	var index=15;
   	for(a=0; a<this.NumBtnList.length; a++)
    {
        if(this.NumBtnList[a].key==keycode)
        {
        	index = a;
        	break;
        }
    }
    
    if(index<0 || index>=15)
    {
    	return;
    }
    
    //this.resetTimer();
    this.selectKeypad(index);
}


