/*var counter = 0;
winLoad = window.onload;
window.onload = function() {
					if(counter == 0) {
						if(typeof winLoad == "function") winLoad();
						searchClassInv();
						counter++;
					}
				}
*/				
/*
THE FOLLOWING CODE HANDLES THE GRAPHICAL CHANGES FOR RADIO BUTTONS AND CHECKBOXES
*/
//global variables that can be used by ALL the function son this page. 
var inputs; 
var imgCheckboxFalse = '/wps/themes/html/Hermes-Standard/img/chbox_deaktiv_enable.gif'; 
var imgCheckboxTrue = '/wps/themes/html/Hermes-Standard/img/chbox_aktiv_enable.gif'; 
var imgCheckboxFalseDisabled = '/wps/themes/html/Hermes-Standard/img/chbox_deaktiv_disable.gif'; 
var imgCheckboxTrueDisabled = '/wps/themes/html/Hermes-Standard/img/chbox_aktiv_disable.gif'; 
var imgRadioFalse = '/wps/themes/html/Hermes-Standard/img/inp_radio_false.gif'; 
var imgRadioTrue = '/wps/themes/html/Hermes-Standard/img/inp_radio_true.gif'; 
var imgRadioFalseDisabled = '/wps/themes/html/Hermes-Standard/img/inp_radio_false_disabled.gif'; 
var imgRadioTrueDisabled = '/wps/themes/html/Hermes-Standard/img/inp_radio_true_disabled.gif'; 

//this function runs when the page is loaded, put all your other onload stuff in here too. 
function init() { 
	if (HermesGlobalData.get( "PropsNewsTicker"))	{
		ProPSNewsTickerWindowOnload();
	}
    replaceChecks(); 
    replaceRadios();

   	if ( typeof callWalkAround_FF_pw_autocomplete == "function" ) {
   		callWalkAround_FF_pw_autocomplete();
   	}

} 

function replaceChecks() { 

    //get all the input fields on the page 
    inputs = document.getElementsByTagName('input'); 

    //cycle trough the input fields 
    for(var i=0; i < inputs.length; i++) { 

	//check if the input is a checkbox 
	if(inputs[i].getAttribute('type') == 'checkbox') { 
		
		// Do not create Image, if alt-Attribut of checkbox set to 'noImageReplacement'
		if (inputs[i].alt != 'noImageReplacement') {
		
		    //create a new image 
		    var img = document.createElement('img'); 
	
		    //check if the checkbox is checked 
		    if(inputs[i].checked) { 
					if(inputs[i].disabled)
					{
						img.src = imgCheckboxTrueDisabled; 
					} else {
						img.src = imgCheckboxTrue; 
					}
		    } else { 
				if(inputs[i].disabled)
						{
							img.src = imgCheckboxFalseDisabled; 
						} else {
							img.src = imgCheckboxFalse; 
						}
			    } 
		
			    //set image ID and onclick action 
			    img.id = 'checkImage'+i; 
			    //set image 
			    if(!inputs[i].disabled) img.onclick = new Function('checkChange('+i+')'); 
			    //place image in front of the checkbox 
			    inputs[i].parentNode.insertBefore(img, inputs[i]); 
		
			    //hide the checkbox 
			    inputs[i].style.display='none'; 
			} 
		}
    } 
} 

function replaceRadios() { 

    //get all the input fields on the page 
    inputs = document.getElementsByTagName('input'); 

    //cycle trough the input fields 
    for(var i=0; i < inputs.length; i++) { 
	
	//check if the input is a radiobutton
	if(inputs[i].getAttribute('type') == 'radio') { 

		// Do not create Image, if alt-Attribut of radiobutton set to 'noImageReplacement'
		if (inputs[i].alt != 'noImageReplacement') {
		
		    //create a new image 
		    var img = document.createElement('img'); 
	
		    //check if the checkbox is checked 
		    if(inputs[i].checked) { 
				if(inputs[i].disabled)
					{
						img.src = imgRadioTrueDisabled; 
					} else {
						img.src = imgRadioTrue; 
					}
		    } else { 
				if(inputs[i].disabled)
					{
						img.src = imgRadioFalseDisabled; 
					} else {
						img.src = imgRadioFalse; 
					}
			    } 
		
			    //set image ID and onclick action 
			    img.id = 'radioImage'+inputs[i].id; 
		
			    //set image click event if button not disabled
			    if(!inputs[i].disabled) img.onclick = new Function('radioChange('+i+')'); 
			    
			    /*
			    if (inputs[i].previousSibling.id == img.id) {
			    	inputs[i].parentNode.removeChild(inputs[i].previousSibling);
			    }
			    */
			    
			    //place image in front of the checkbox 
			    inputs[i].parentNode.insertBefore(img, inputs[i]); 
		
			    //hide the checkbox 
			    inputs[i].style.display='none'; 
			} 
		}
    } 
} 

//change the checkbox status and the replacement image 
function checkChange(i) { 

    if(inputs[i].checked) { 
	inputs[i].checked = ''; 
	document.getElementById('checkImage'+i).src=imgCheckboxFalse; 
    } else { 
	inputs[i].checked = 'checked'; 
	document.getElementById('checkImage'+i).src=imgCheckboxTrue; 
    } 
    //onclick funktion vom nicht anklickbarem checkbox ausführen
    if (inputs[i].onclick!=null)
    	new inputs[i].onclick; 
} 

//change the checkbox status and the replacement image of checked and all in same group
function radioChange(i) { 
	var radios=new Array();
	var tmpradios;

	// load all the inputs into tmp array
	tmpradios = document.getElementsByTagName('input'); 

	for(var j=0; j < tmpradios.length; j++) { 
		// Add only the radios in this group to the array
		if(tmpradios[j].getAttribute('name') == inputs[i].getAttribute('name'))
		{
			radios.push(tmpradios[j]);
		}
	}

    if(inputs[i].checked) { 
		// already checked so do nothing as radio does not uncheck like a checkbox
    } else { 
		// make all other group items unchecked
	for(var j=0; j < radios.length; j++) { 
			document.getElementById('radioImage'+radios[j].id).src=imgRadioFalse; 
			document.getElementById('radioImage'+radios[j].id).checked=''; 
		}
		// make the selected item checked
	inputs[i].checked = 'checked'; 
	document.getElementById('radioImage'+inputs[i].id).src = imgRadioTrue;       
    } 
    
    //onclick funktion vom nicht anklickbarem checkbox ausführen
    if (inputs[i].onclick!=null)
    	new inputs[i].onclick;     
}

/* Function switches the images and check status of radio elements, that have an replaced/inserted Hermes image
 * radioId - id of the clicked radio element
 * radioName - name of the radio Group
 */
function onClickOfReplacedRadio (radioId, radioName) {
	var radios = document.getElementsByName(radioName);
	var radioElem = $(radioId);

	// Make all radio items unchecked and the clicked checked
    if(!radioElem.checked) { // if already checked, nothing to change	
		for(var j=0; j < radios.length; j++) { 
				document.getElementById('radioImage'+radios[j].id).src=imgRadioFalse; 
				document.getElementById('radioImage'+radios[j].id).checked=''; 
		}
	   radioElem.checked = 'checked'; // make the selected item checked
	   document.getElementById('radioImage'+radioElem.id).src = imgRadioTrue;       
    }
}

function checkChangeNr(hasId) {
	for(i=0; i < inputs.length; i++){
		if(inputs[i].id == hasId) {
			checkChange(i);
		}		
	}
}

function radioChangeNr(hasId) {
	for(i=0; i < inputs.length; i++){
		if(inputs[i].id == hasId) {
			radioChange(i);
		}		
	}
}

function chgtolabel(){
	lbl = document.getElementsByTagName('label');
	for(i=0; i < lbl.length; i++){
		hasId = lbl[i].htmlFor;
		if(document.getElementById(hasId).getAttribute('type') == 'checkBox') {
			lbl[i].setAttribute("onclick", "checkChangeNr('" + hasId + "')");
		}		
	}
}

// window.onload = init;
if (HCU) {
		HCU.WindowOnloadListe.append( {func:init, thisObj:this, argArray:[]} );
}

/*
END OF RADIO BUTTON /CHECKBOX CODE
*/