// JavaScript Document
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
  // alert(retValue);
   return retValue; // Return the trimmed string back to the user
}
var cnt = 0;
var arr_uebung_01 = new Array(
"Warum","hat","Stefan","Heine","nur","sehr","wenig","Geld?",
"Stefan","Heine","hat","nur","sehr","wenig","Geld,","weil","er","schon","seit","3","Jahren","arbeitslos","ist.",
"Warum","liegt","Marko","Plötz","im","Krankenhaus?",
"Marko","Plötz","liegt","im","Krankenhaus,","weil","er","einen","Arbeitsunfall","hatte.",
"Warum","braucht","Heinrich","Hinkelstein","heute","nicht","zu","arbeiten?",
"Heinrich","Hinkelstein","braucht","heute","nicht","zu","arbeiten,","weil","heute","Sonntag","ist.",
"Warum","muss","Torsten","morgen","sehr","früh","aufstehen?",
"Torsten","muss","morgen","sehr","früh","aufstehen,","weil","sein","Zug","schon","um","5:15","Uhr","abfährt.",
"Warum","sucht","Elfriede","ihre","Lesebrille?",
"Elfriede","sucht","ihre","Lesebrille,","weil","sie","das","Kleingedruckte","nicht","lesen","kann."
                             );

function Ergebnis_uebung_01(){
	cnt = 0;
	//alert(cnt +arr_uebung_01.length );
	for(i = 0,cnt=1;i<arr_uebung_01.length;i++){
		 var txtVal = document.getElementById(cnt).value;
		 var txtTrimedString = trim(txtVal);
		// alert(arr_uebung_01[i] + txtTrimedString)
		 if(arr_uebung_01[i] == txtTrimedString)
		   document.getElementById(cnt).style.backgroundColor = "#66FF33";
		 else
		   document.getElementById(cnt).style.backgroundColor = "#ff0033";
		   cnt = cnt + 1;
	}
	
}
function Loesung_uebung_01(){
	
	for(i = 0,cnt=1;i<arr_uebung_01.length;i++){
		//alert('i :- '+i+'\ncnt :- '+cnt);
		if((document.getElementById(cnt).style.backgroundColor == 'rgb(255, 0, 51)'||document.getElementById(cnt).style.backgroundColor == '')||document.getElementById(cnt).style.backgroundColor == '#ff0033'||document.getElementById(cnt).style.backgroundColor == '' ){
  			 document.getElementById(cnt).value = arr_uebung_01[i];
			 document.getElementById(cnt).style.backgroundColor = "#CCCCCC";
		}
		 cnt = cnt + 1;
	}
	cnt = 0;
}
var arr_uebung_02 = new Array(
"Rüdiger","ist","sehr","glücklich,","weil","er","2.000","Euro","gewonnen","hat.",
"Da","Rüdiger","2.000","Euro","gewonnen","hat,","ist","er","sehr","glücklich.",
"Gudrun","ist","sehr","traurig,","weil","ihr","Hund","nach","langer","Krankheit","verstorben","ist.",
"Da","Gudruns","Hund","nach","langer","Krankheit","verstorben","ist,","ist","sie","sehr","traurig.",
"Das","Knie","der","kleinen","Hannelore","blutet,","weil","sie","mit","ihrem","Dreirad","gestürzt","ist.",
"Da","die","kleine","Hannelore","mit","ihrem","Dreirad","gestürzt","ist,","blutet","ihr","Knie.",
"Bruno","hat","keine","Zeit","Fußball","zu","spielen,","weil","er","sich","auf","einen","Test","vorbereiten","muss.",
"Da","Bruno","sich","auf","einen","Test","vorbereiten","muss,","hat","er","keine","Zeit","Fußball","zu","spielen.",
"Helmut","hat","Übergewicht,","weil","er","sich","falsch","ernährt.",
"Da","Helmut","sich","falsch","ernährt,","hat","er","Übergewicht."
                              );

function Ergebnis_uebung_02(){
	cnt = 0;
	for(i = 0,cnt=96;i<arr_uebung_02.length;i++){
		 var txtVal = document.getElementById(cnt).value;
		 
		 var txtTrimedString = trim(txtVal);
		// alert(arr_uebung_02[i] + txtTrimedString)
		 if(arr_uebung_02[i] == txtTrimedString)
		   document.getElementById(cnt).style.backgroundColor = "#66FF33";
		 else
		   document.getElementById(cnt).style.backgroundColor = "#ff0033";
		   cnt = cnt + 1;
	}
}
function Loesung_uebung_02(){
	
	cnt = 0;
	
	for(i = 0,cnt=96;i<arr_uebung_02.length;i++){
		//alert(document.getElementById(cnt).style.backgroundColor);
         if((document.getElementById(cnt).style.backgroundColor == 'rgb(255, 0, 51)'||document.getElementById(cnt).style.backgroundColor == '')||document.getElementById(cnt).style.backgroundColor == '#ff0033'||document.getElementById(cnt).style.backgroundColor == '' ){
  		     document.getElementById(cnt).value = arr_uebung_02[i];
			 document.getElementById(cnt).style.backgroundColor = "#CCCCCC";
		 }
		 cnt = cnt + 1;
	}
}












