
/*
//==================================================================
    checkbox class
    -------------------
    this class scans the page once it has been loaded
    finds all checkboxes and 'hides' them
    adding in 'checkbox' like images which are cliackable
    
    
//==================================================================
*/

function Checks()
{
    //--------------------------------------------------------------
    // variables
    //--------------------------------------------------------------
    this.checks    = {
        on: contextPathVal+"/images/en/app/boxCC.gif",
        off:contextPathVal+"/images/en/app/boxUC.gif",
		disabledOn:contextPathVal+"/images/en/app/boxUDC.gif",
		disabledOff:contextPathVal+"/images/en/app/boxU.gif"
    }
    
    this.radios    = {
        on:contextPathVal+"/images/en/app/rdCC.gif",
        off:contextPathVal+"/images/en/app/rdUC.gif",
		disabledOn:contextPathVal+"/images/en/app/rdC.gif",
		disabledOff:contextPathVal+"/images/en/app/rdU.gif"
    }

    //--------------------------------------------------------------
    // methods
    //--------------------------------------------------------------
    
    //    init
    this.init = function()
    {
        this.checkbox = $(":checkbox");
        this.radiobox = $(":radio");
        
        $(this.checkbox).hide();
        $(this.radiobox).hide();
		var disabledState;
		var checkedState;
                
        for(var n = 0; n < this.checkbox.length; n++)
        {
        	disabledState = ($(this.checkbox[n]).attr("disabled") == true) ? ($(this.checkbox[n]).attr("checked") == true ? this.checks.disabledOn : this.checks.disabledOff) : false;		
        	checkedState = $(this.checkbox[n]).attr("checked") == true ? this.checks.on : this.checks.off;
			
			if(disabledState){
            	img    = "<img src='" + disabledState + "' />";
				$(this.checkbox[n]).parent().addClass('disabledText');
			} else {
				img    = "<img src='" + checkedState + "'  class='checkbox' />";
				$(this.checkbox[n]).parent('.disabledText').removeClass('disabledText');
			}
            $(this.checkbox[n]).parent().prepend(img);
        }
        
        for(var n = 0; n < this.radiobox.length; n++)
        {
			disabledState = ($(this.radiobox[n]).attr("disabled") == true) ? ($(this.radiobox[n]).attr("checked") == true ? this.radios.disabledOn : this.radios.disabledOff) : false;		
        	checkedState = $(this.radiobox[n]).attr("checked") == true ? this.radios.on : this.radios.off;
           
		  	if(disabledState){
			   img    = "<img src='" + disabledState + "' />";
			   $(this.radiobox[n]).parent().addClass('disabledText');
		  	} else {
			  img    = "<img src='" + checkedState + "' class=\"radio\" />";
			  $(this.radiobox[n]).parent('.disabledText').removeClass('disabledText');
		  	}
            $(this.radiobox[n]).parent().prepend(img);
        }
        
        this.functionality();
    }
    
    // check box functiyonality
    this.functionality    = function()
    {
        $("img[@class='checkbox']").bind(
            'click',
            function()
            {
                this.src = this.src.indexOf(cb.checks.off) != -1 ? cb.checks.on : cb.checks.off ;
                $(this).parent().children()[1].checked = this.src.indexOf(cb.checks.off) != -1 ? false : true;
                var check = $(this).parent().children()[1];
                $(check).trigger('change');
            }
        )
        
        $("img[@class='radio']").bind(
            'click',
            function()
            {
            	var linkedInput = $(this).parent().children()[1];
            	var groupInputs = linkedInput.name != "" ? $("input[@name='"+linkedInput.name+"']") : false;
				var disabledState;
            	
    	        for(var n = 0; n < groupInputs.length; n++)
		        {
					disabledState = ($(groupInputs[n]).parent().children()[1].disabled == true) ? ($(groupInputs[n]).parent().children()[1].checked == true ? cb.radios.disabledOn : cb.radios.disabledOff) : false;	
					if(! disabledState){
						$(groupInputs[n]).parent().children()[0].src = cb.radios.off;
						$(groupInputs[n]).checked = false;
					}
		        }
            		
                this.src = this.src.indexOf(cb.radios.off) != -1 ? cb.radios.on : cb.radios.off ;
                linkedInput.checked = this.src.indexOf(cb.radios.off) != -1 ? false : true;
            }
        )
    }

    this.init();
}


//==================================================================
// on page load
//==================================================================
$('document').ready(
	function()
	{   
		//DISABLED STYLED INPUTS UNTIL WE CAN PROPERLY SETUP - Dan Van Brunt
		cb = new Checks(); 
	}
);
