function getElementsByName_iefix(tag, name) {     // workaround fuer ie7 - getElementsByName funktioniert nicht
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function theOpenCloser(theName, docroot) {
	//cookie zum lesen, ob das element offen ist oder nicht
	nameElements = getElementsByName_iefix("tr",theName);
	plusminus = document.getElementById(theName+"Hdr");
	iconPath = docroot + 'templates/gastrolove/img/';
		
	if(readCookieContent()) {
		sectionsString = readCookieContent();
	}
	else {
		sectionsString = "";
	}
	
	if(nameElements[0].style.display == '') { 	// zuklappen
		newState = 'none';
		plusminus.src = iconPath + 'plus.gif';
		
		// name ans cookie anhängen
		sectionsString += theName + ',';				
	}
	else {								// aufklappen
		newState = '';
		plusminus.src = iconPath + 'minus.gif';
		
		// name aus cookie entfernen
		sectionsString = sectionsString.replace(theName+",","");
	}
	
	setCookie(sectionsString);

	for(i=0; i<nameElements.length; i++) {
		nameElements[i].style.display = newState;
	}
}

function cookieCloser(theName, docroot) {
	nameElements = getElementsByName_iefix("tr",theName);
	plusminus = document.getElementById(theName+"Hdr");
	
	iconPath = docroot + 'templates/gastrolove/img/';
		
	// zuklappen
	newState = 'none';
	plusminus.src = iconPath + 'plus.gif';	
		
	for(i=0; i<nameElements.length; i++) {
		nameElements[i].style.display = newState;	
	}
}

function readCookieContent() {
	if(document.cookie && (document.cookie.indexOf("closedSections=")>-1)) {
		var Wertstart = document.cookie.indexOf("closedSections=") + 15;
		var Wertende = document.cookie.indexOf('_END');	
		if (Wertende == -1) {
			Wertende = document.cookie.length;
		}
		content = document.cookie.substring(Wertstart, Wertende);
			
		return(content);
	}
}

function killCookie() {
	document.cookie = "prodNotes=; expires=Thu, 01-Jan-70 00:00:01 GMT;";
}

function setCookie(theName) {
	theClosedSections = theName;    	
	
	var jetzt = new Date();
	var Auszeit = new Date(jetzt.getTime() + 86400000);
	document.cookie = "closedSections=" + theClosedSections + "_END; expires=" + Auszeit.toGMTString() + ";";
}

function openCloseSections(docroot) { // wird body onload aufgerufen
	if(readCookieContent()) {		
		sectionsString = readCookieContent();
	}
	else {
		sectionsString = "";	
	}
	
	contentArray = splitCookieContent(sectionsString);
	
	for(k=0; k<contentArray.length; k++) {
		//öffnen & schließen gemäß cookie		
		if(contentArray[k]) {
			cookieCloser(contentArray[k],docroot);
		}
		
	}
	
}

function splitCookieContent(content) {
	contentArray = content.split(",");
	return(contentArray);
}