
/**
 * @author Samsung
 */

 var CBoxImgIndex = { CB_NORMAL_IMG:0, CB_NORMAL_FOCUS_IMG:1, CB_SELECTED_IMG:2, CB_SELECTED_FOCUS_IMG:3, CB_DIM_IMG:4};

function CheckBox(imageId, textId) {

    this.objType ="CHECKBOX";

    this.image_layer =null;
    this.text_layer =null;
   
    
    if(imageId)
    {
       this.SetImageObjId(imageId);
    }
    
    if(textId)
    {
        this.SetTextObjId(imageId);
    }
   
    this.CBImg = new Array(5);
    this.initImg = 0;
    
    this.flag_highlight = false;
    this.flag_selected = false;
    this.flag_dim = false;
    
    this.helpBar =null;
	this.flag_visible_helpbar = false;

	this.text_normal_style ="";
	this.text_dim_style ="";
	
	this.onClickCallbackFunc = null;
	this.onMouseOutCallbackFunc= null;
	this.flagClickEnable = false;
	this.flagMouseOverEnable = false;

}

CheckBox.prototype.SetImageObjId= function(id){

    if(id)
    {
        this.image_layer = new ImageLayer(id);
    }
    else
    {
        this.image_layer= null;
    }

}

CheckBox.prototype.SetTextObjId= function(id){

    if(id)
    {
        this.text_layer = new TextLayer(id);
    }
    else
    {
        this.text_layer= null;
    }

}

CheckBox.prototype.SetBgImage = function(imgIndex, bgImage){
    
    this.CBImg[imgIndex] = bgImage;
    
    if(this.initImg ==0 && imgIndex==0)
    {
        this.initImg=1;
        this.image_layer.SetBgImage(bgImage);
    }
}


CheckBox.prototype.SetText = function(string){
	if(this.text_layer !=null)
	{
	    this.text_layer.SetText(string);
	}

}

CheckBox.prototype.SetTextStyle = function(style)
{
    this.text_layer.SetTextStyle(style);
	this.text_normal_style = style;
}

CheckBox.prototype.SetTextDimStyle = function(style)
{
    this.text_dim_style = style;
}

CheckBox.prototype.highlight = function(){

    this.flag_highlight = true;
    
    if(this.flag_selected)
    {
        if(this.CBImg[CBoxImgIndex.CB_SELECTED_FOCUS_IMG])
        {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_SELECTED_FOCUS_IMG] );
        }
        else
        {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_FOCUS_IMG] );
            this.image_layer.visibleFgObj();
        }
    }
    else
    {
        this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_FOCUS_IMG] );
        this.image_layer.hiddenFgObj();
    }
    /*
     if( this.helpBar)
    {
         this.helpBar.visibleObj();
    }*/
	
	this.visibleHelpBar();

}

CheckBox.prototype.blur = function(){

    this.flag_highlight = false;
    
    if(this.flag_selected)
    {
        if(this.CBImg[CBoxImgIndex.CB_SELECTED_IMG])
        {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_SELECTED_IMG] );
        }
        else
        {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_IMG] );
            this.image_layer.visibleFgObj();
        }
       
    }
    else
    {
        this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_IMG] );
        this.image_layer.hiddenFgObj();
    }
    /*
     if( this.helpBar)
    {
         this.helpBar.hiddenObj();
    }*/
	
	this.hiddenHelpBar();

}

CheckBox.prototype.flagHighlight = function(){

    return this.flag_highlight;
}

CheckBox.prototype.toggleSelect = function(){
    if(this.flag_selected)
    {
        this.flag_selected = false;
    }
    else
    {
         this.flag_selected = true;
    }
    
    this.select(this.flag_selected);
}

CheckBox.prototype.select = function(){

    if(this.flag_selected==true)
    {
        this.flag_selected = false;
        this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_FOCUS_IMG] );
         this.image_layer.hiddenFgObj();
    }
    else
    {
        this.flag_selected = true;
       if(this.CBImg[CBoxImgIndex.CB_SELECTED_FOCUS_IMG])
       {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_SELECTED_FOCUS_IMG] );
       }
        this.image_layer.visibleFgObj();
    }
}


CheckBox.prototype.SetFlagSelect = function(flagSelect){

    if(flagSelect==false)
    {
        if(this.flag_highlight)
        {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_FOCUS_IMG] );
        }
        else
        {
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_IMG] );
        }
         this.image_layer.hiddenFgObj();
    }
    else
    {
        if(this.flag_highlight)
        {
           if(this.CBImg[CBoxImgIndex.CB_SELECTED_FOCUS_IMG])
           {
                this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_SELECTED_FOCUS_IMG] );
           }
           else
           {
                this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_FOCUS_IMG] );
                this.image_layer.visibleFgObj();
           }
       }
       else
       {
           if(this.CBImg[CBoxImgIndex.CB_SELECTED_IMG])
           {
                this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_SELECTED_IMG] );
           }
           else
           {
                this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_IMG] );
                this.image_layer.visibleFgObj();
           }
       }
    }
    
    if(this.flag_selected !==flagSelect)
    {
        this.flag_selected = flagSelect;
    }
}

CheckBox.prototype.GetFlagSelect = function(){
    return this.flag_selected;
}

CheckBox.prototype.AppendFgImage = function(id,h_space, v_space, w, h, img_src)
{
    this.image_layer.AppendFgImage(id,h_space, v_space, w, h, img_src);
}

CheckBox.prototype.SetFgImage = function(img_src){

    this.image_layer.SetFgImage(img_src);
    this.image_layer.hiddenFgObj();
    
}

CheckBox.prototype.registHelpBar= function(obj){
    if(obj)
    {
           this.helpBar = obj;
    }
}

CheckBox.prototype.SetFlagDim = function(b_dim){

    if(this.flag_dim==b_dim  ||  this.flag_highlight ==true)
    {
        return;
    }
    
    this.flag_dim = b_dim;
    
    if(this.flag_dim == true)
    {
         if(this.flag_selected==true)
        {
            this.flag_selected = false;
            this.image_layer.hiddenFgObj();
        }
        
            this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_DIM_IMG] );
		
		if(this.text_dim_style.length >0)
		{
			this.text_layer.SetTextStyle(this.text_dim_style);
		}
		
		this.DisableOnClick();
		this.DisableOnMouseOver();
    }
    else
    {
        this.image_layer.SetBgImage( this.CBImg[CBoxImgIndex.CB_NORMAL_IMG] );
		this.text_layer.SetTextStyle(this.text_normal_style);
		
		this.EnableOnClick();
		this.EnableOnMouseOver();
    }
}

CheckBox.prototype.GetFlagDim= function(){
    return this.flag_dim;
}

CheckBox.prototype.visibleHelpBar= function(){
	
	if(this.flag_visible_helpbar == true)
	{
		return;
	}
	else
	{
		this.flag_visible_helpbar = true;
		if( this.helpBar)
	    {
	         this.helpBar.visibleObj();
	    }
	}
}

CheckBox.prototype.hiddenHelpBar= function(){
	
	if(this.flag_visible_helpbar == false)
	{
		return;
	}
	else
	{
		this.flag_visible_helpbar = false;
		if( this.helpBar)
	    {
	         this.helpBar.hiddenObj();
	    }
	}
}

CheckBox.prototype.changeHelpBar= function(obj){
	//alert("CheckBox.prototype.hiddenObj()");
    if(this.helpBar == obj)
    {
        return;
    }
    
    if(this.helpBar != null)
    {
       	this.helpBar.hiddenObj();
    }
    
     if(obj)
    {
       this.helpBar = obj;
       //if(this.flag_highlight ==true)
	   if(this.flag_visible_helpbar== true)
       {
            this.helpBar.visibleObj();
       }
    } 
}

CheckBox.prototype.SetOnClickCallbackFunc = function(func)
{
	if(WndMgr.MouseClickEnable==false)
	{
		return;	
	}
	
	if(this.image_layer != null)
	{
		alert("CheckBox.SetOnClickCallbackFunc() set on image_layer");
		
		var object = this.image_layer.GetObjectId();
		this.onClickCallbackFunc = func;
		this.EnableOnClick();			
	}
}

CheckBox.prototype.EnableOnClick = function()
{
	if(this.flagClickEnable == false && this.flag_dim== false)
	{
		var object = this.image_layer.GetObjectId();
		var this_ = this;
		document.getElementById(object).onclick = function(){this_.onClickCallbackFunc(this_);};
		this.flagClickEnable = true;
		$("#"+this.image_layer.GetObjectId()).css({'cursor' : 'pointer'});	
	}
}

CheckBox.prototype.DisableOnClick = function()
{
	if(this.flagClickEnable == true)
	{
		var object = this.image_layer.GetObjectId();
		document.getElementById(object).onclick = null;
		this.flagClickEnable = false;
		$("#"+this.image_layer.GetObjectId()).css({'cursor' : ''});	 
	}
}

CheckBox.prototype.SetOnMouseOverCallbackFunc = function(func){
	if(WndMgr.MouseClickEnable==false)
	{
		return;	
	}
	if(this.image_layer.GetObjectId()!= null)
	{
		alert("CheckBox.SetOnMouseOverCallbackFunc() set on image_layer");
		
		this.onMouseOverCallbackFunc = func;
		this.EnableOnMouseOver();			
	}
}
CheckBox.prototype.EnableOnMouseOver = function(){
	var object = this.image_layer.GetObjectId();
	var this_ = this;
	if(this.flagMouseOverEnable == false && this.flag_dim == false) {
	document.getElementById(object).onmouseover = function(){this_.onMouseOverCallbackFunc(this_);};
		this.flagMouseOverEnable=true;
	}
}
CheckBox.prototype.SetOnMouseOutCallbackFunc = function(func)
{
	if(WndMgr.MouseClickEnable==false)
	{
		return;	
	}
	var id = this.image_layer.GetObjectId();
	if(id != null)
	{
		alert("CheckBox.SetOnMouseOutCallbackFunc() set on image_layer");
		
		this.onMouseOutCallbackFunc = func;
		this.EnableOnMouseOver();			
	}
}
CheckBox.prototype.DisableOnMouseOver = function(){
	var object = this.image_layer.GetObjectId();
	if(this.flagMouseOverEnable == true) {
		document.getElementById(object).onmouseover = null;
		this.flagMouseOverEnable = false;
	}
}
CheckBox.prototype.EnableOnMouseOut = function(){
	var object = this.image_layer.GetObjectId();
	var this_ = this;
	document.getElementById(object).onmouseout = function(){this_.onMouseOutCallbackFunc(this_);};
}