﻿// Highlight the Selected Node
var ColorHeitecRed = '#d13735'


$(document).ready(function() {
    var retval = $('.CustomRadioButtonDivs').length;
    if(retval==1)
    {
        $('.CustomRadioButtonDivs >input').parent().css('backgroundColor','#d13735');   
        $('.CustomRadioButtonDivs >input').parent().find('label').css('color','white'); 	 
        $('.CustomRadioButtonDivs >input').attr("checked", "checked")
    }
    if( !!retval == true )
    {
            $('.CustomRadioButtonDivs >input:checked').parent().css('backgroundColor','#d13735');
            $('div >div').filter('input').css('color','#000000');
            $('.CustomRadioButtonDivs >input:checked').parent().find('label').css('color','white'); 	 
            var retval = $('input:checked').length;
            if(!!retval == true)
            { 
                //var redId = $('input:checked').parent().get(0).id;
                //var redId = $('.CustomRadioButtonDivs >input:checked').parent().get(0).id;
                if(!!$('.CustomRadioButtonDivs >input:checked').length == true )
                {
                    var redId = $('.CustomRadioButtonDivs >input:checked').parent().get(0).id;
                                $("input[name$='m_CRBL_Hidden']").val(redId);
                }else
                {
                    $("input[name$='m_CRBL_Hidden']").val('');    
                }
            }
            
    }
});


function dkconfig_RadioButtonListKeyUp(oButtonlist, oSubmit, oEvent)
{
  if(oEvent != null)
  {
    var iKeyCode = -1;
    
    iKeyCode = oEvent.which != null ? oEvent.which : (oEvent.keyCode != null ? oEvent.keyCode : -1);       

    dkconfig_RadioButtonListKeyPress(oButtonlist, oSubmit, iKeyCode);
  }
}

function dkconfig_RadioButtonListKeyPress(oListBox, oSubmit, iKeyCode)
{
  if(oSubmit != null)
  {
    if(iKeyCode == 13)
    {
      oSubmit.click();
    }
  }
}


function Highlight(contdiv){   
  if( contdiv.firstChild.checked == true)
	 {
	    contdiv.style.backgroundColor = ColorHeitecRed;
	    var InputLabel = contdiv.lastChild;
	    InputLabel.style.color = 'white';
	    //wildcard Select auf m_hidden
	    var last = $("input[name$='m_CRBL_Hidden']").get(0).value;
	    
	    if(last != '' ) 
	    {	    
	        if( document.getElementById(last) != null ) 
	        {
	            var IdToReset = document.getElementById(last);
	            var InputLabelToReset = IdToReset.lastChild;
	            IdToReset.style.backgroundColor= '#cccccc';
	            InputLabelToReset.style.color = '#000000';
	        }
	    }
	    //wildcard Select auf m_hidden
	    $("input[name$='m_CRBL_Hidden']").val(contdiv.id);	    
	 } 
}


function getParent(element, parent)
{
    if(typeof element=="string")
    {
        element=document.getElementById(element);
    };
    if(!element)
    {
        return null;
    };
    var elements=[];
    if(typeof parent!="string")
    {/*no parent: gets all parents till #document*/
	    while(element.parentNode)
	    {
	        element=element.parentNode;
	        elements.unshift(element);
		    if(element==parent)
		    {
    		    return elements;
	    	};
	    }
    }
    else
    {/*string, presumes you want to locate the first parent node that is such TAG*/
        parent=parent.toUpperCase();
	    while(element.parentNode)
	    {
	        element=element.parentNode;
	        elements.unshift(element);
		    if(element.nodeName && element.nodeName.toUpperCase()==parent)
		    {
		        return elements;
		    };
	    }
    };
return elements;
}
