		var changedElements = new Array();

                function addChangedElement(name, selectId) {
                    changedElements[name] = selectId;
                }

                function changeDoctor ( totalCount ) {
                    for ( key in changedElements ) {
                        changeFatigue (key, changedElements[key], totalCount);
                    }
                }


		function changeFatigue(name, selectId,totalCount) {
                        addChangedElement(name, selectId);
			element = document.getElementById(name+selectId);
                        nrDoctorsElement = document.getElementById('nrDoctors');
                        if ( nrDoctorsElement != null ) {
                            nrDoctors = nrDoctorsElement.options[nrDoctorsElement.selectedIndex].text;
                        } else {
                            nrDoctors = 0;
                        }
			selectValue = element.options[element.selectedIndex].text; 
			pointsPerQuart = 6;
			pointsLossPerDay = 5 + (nrDoctors*0.5);
			div = document.getElementById("div_"+name+selectId);
			hiddenDiv = document.getElementById("hiddendiv_"+name);		
			points = eval(hiddenDiv.innerHTML);
			
			div.innerHTML = points + (selectValue*pointsPerQuart);
			
			for ( i=1;i<totalCount;++i) {
				divName = "div_"+name+i;
				div = document.getElementById(divName);
				divPrevName = "div_"+name+(i-1);
				//alert ( divName + " " + divPrevName );
				divPrev = document.getElementById(divPrevName);
				prevPoints = eval (divPrev.innerHTML);
				// get current points
				element = document.getElementById(name+i);
				points = eval(element.options[element.selectedIndex].text)*pointsPerQuart;
				// fill the div with the new points
				value = eval (prevPoints) - pointsLossPerDay;
				if ( value < 0 ) {
					value = 0;
				}
				value = eval(points) + value;
				
				
				div.innerHTML = value;
			}
		}
		
		
		function submitForm ( wizardPage, wizardPageAction ) {
			document.forms["main"].wizardPage.value = wizardPage;
			document.forms["main"].wizardPageAction.value = wizardPageAction;
			document.forms["main"].submit();
		}
		
		function checkInt ( input, checkMinMax ) {
			var error = false;
			if (input.value!="") {
				if ( isNaN(input.value) ) {
					alert("Only use integers");
					error = true;
				}
				
				if ( checkMinMax ) {
					if ( input.value > 100 ) {
						alert ("Values larger than 100 not allowed");	
						error = true;
					}
					else if ( input.value < -1 ) {
						alert ("Values smaller than -1 not allowed");	
						error = true;
					}
				}
			}
			if ( error ) {
				input.style.background = "#ffaaaa";
				input.focus();
				input.select();
			}
			else  {
				input.style.background = "#ffffff";
			}
		}
		
		function showDiv(id){
			if (document.layers) {
				if ( document.getElementById(id).style.display == "" ) {
					 document.getElementById(id).style.display = 'none';
				}
				current = (document.layers[id].display == 'none') ? 'block' : 'none';
				document.layers[id].display = current;
			}
			else if (document.all) {
				if ( document.getElementById(id).style.display == "" ) {
					 document.getElementById(id).style.display = 'none';
				}
				current = (document.all[id].style.display == 'none') ? 'block' : 'none';
				document.all[id].style.display = current;
			}
			else if (document.getElementById) {
				if ( document.getElementById(id).style.display == "" ) {
					 document.getElementById(id).style.display = 'none';
				}
				vista = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
	
				document.getElementById(id).style.display = vista;
			}
		} 
		
		function checkElements ( ) {
			var totalPerc = 0;
			for(i=0; i<document.main.elements.length; i++) {
				if ( document.main.elements[i].name.indexOf('Perc') != -1 ) {
					if ( document.main.elements[i].value!="" ) {
						totalPerc = totalPerc + eval(document.main.elements[i].value);
					}
				}
			}
			
			if ( totalPerc > 100 ) {
				document.forms["main"].totalPer.style.background = "#ffaaaa";
			}
			else  {
				document.forms["main"].totalPer.style.background = "#ffffff";
			}
			document.forms["main"].totalPer.value = totalPerc;
		}
		
		

		 	
