function changeDiv(the_div,the_change) {
	var the_style = getStyleObject(the_div);
	if (the_style != false) {
		the_style.display = the_change;
	}
}

// function switchDiv()
//  this function takes the id of a div
//  and calls the other functions required
//  to show that div
//
function switchDiv(div_id) {
	var style_sheet = getStyleObject(div_id);
	if (style_sheet) {
		hideAll();
		changeObjectVisibility(div_id,"visible");
	} else  {
		alert("Sie bebötigen einen Browser, der dynamisches HTML beherrscht");
	}
}

function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {  
		return document.all(objectId).style;
   	} else if (document.layers && document.layers[objectId]) { 
		return document.layers[objectId];
   	} else {
		return false;
   	}
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if (styleObject) {
		styleObject.visibility = newVisibility;
		return true;
    } else {
		// we couldn't find the object, so we can't change its visibility
		return false;
    }
}

function changeObjectDisplay(objectId, newDisplay) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if (styleObject) {
		styleObject.display = newDisplay;
		return true;
    } else {
		// we couldn't find the object, so we can't change its display value
		return false;
    }
}

function switchIfDone(the_form, this_div, next_div) {
	var complete = true;
  	for (var loop=0; loop < the_form.elements.length; loop++) {
		if (the_form.elements[loop].value == "") {
	  	  	complete = false;
	      	alert(the_form.elements[loop].name);
	    }
	}
	
	if ((complete == true) && (next_div == "finished")) {
    	submitTheInfo();
  	} else if (complete == true) {
    	switchDiv(this_div, next_div);
  	} else {
    	//alert('Bitte füllen Sie alle benötigten Felder aus.');
    	switchDiv(this_div, next_div);
  	}
}

function submitAllForms(the_form) {
	if (checkPublish(the_form)) {
    	submitTheInfo();
  	} else {
    	alert('Bitte tragen Sie Ihre Veröffentlichungsoption für diesen Bericht ein.');
  	}
}

function checkPublish(the_form) {
  	var publishRadio = the_form.SQL_publish;
  
	for (var i = 0; i < publishRadio.length; i++) {
		if(publishRadio[i].checked) {
			return true;
		}
	}
	
	return false;
}

function checkSQLQuery(the_form) {
  	var errortype = the_form.errortype;
  	var severity = the_form.severity;
  	var ICPC = the_form.ICPC;
  	var ATC = the_form.ATC;
  
	if(errortype.value != "all" || severity.value != "all" || ICPC.value != "all" || ATC.value != "all") {
		return true; 
	} else {
	  	alert('Bitte wählen Sie mindestens eine Kategorie zur Suche aus.');
	  	return false;
	}
}

/*
function switch12(the_form) {
	for (var loop=0; loop < the_form.elements.length; loop++) {
    	if (the_form.elements[loop].name == "date") {
      		if (the_form.elements[loop].value == "") {
      			alert("Bitte tragen Sie das Datum ein!");
      			the_form.elements[loop].focus();
      		} else {
      			switchDiv('part1', 'part2');
     		}
    	}
  	}	
}
*/

function switchDiv(this_div, next_div) {
	if (getStyleObject(this_div) && getStyleObject(next_div)) {
    	//changeObjectVisibility(this_div, "hidden");
    	//changeObjectVisibility(next_div, "visible");
    	
		changeObjectDisplay(this_div, "none");
    	changeObjectDisplay(next_div, "inline");    	
    	
    	changeObjectBackgroundColor(this_div + "nav", "white");
    	changeObjectBackgroundColor(next_div + "nav", "#FFFFD9");
    	changeObjectBorder(this_div + "nav", false);
    	changeObjectBorder(next_div + "nav", true);
    	window.scrollTo(0, 0);
  	}
}

function changeObjectBackgroundColor(objectId, newColor) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if (styleObject) {
		styleObject.background = newColor;
		return true;
    } else {
		// we couldn't find the object, so we can't change its visibility
		return false;
    }
}

function changeObjectBorder(objectId, setBorder) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if (styleObject) {		
    	if (setBorder) {
			styleObject.border = "1px solid black";
		} else {
			styleObject.border = "1px none black";
		}
		return true;
    } else {
		// we couldn't find the object, so we can't change its visibility
		return false;
    }
}

function submitTheInfo() {
	var submission_string = "";
  	var radionames = "";  	
  	//var debug_string="\nDebug: \n";
  	
  	for (var form_loop = 0; form_loop < document.forms.length; form_loop++) {
    	var currentForm = document.forms[form_loop];
    	
		for (var elmt = 0; elmt < currentForm.length; elmt++) {
			var elements = currentForm.elements;
			var element = elements[elmt];

			// Alle zu berücksichtigenden Felder müssen mit SQL_ beginnen
			name:      			
			if ((element.name).indexOf("SQL_") == 0) {
				// *** radio ***
				if (element.type == "radio") {
					// one radiobutten is enough for group
					if (radionames.indexOf(element.name) > -1) {
						//alert(element.name);
						break name;
					}

					radionames += element.name;
					var radiogroup = elements[element.name]; // get the whole set of radio buttons.

					radios:
					for(var j = 0 ; j < radiogroup.length ; j++) {
						if (radiogroup[j].checked) {	       						
							submission_string += element.name + "=" + radiogroup[j].value + "³";
							break radios;
						}
					}
				// *** checkbox ***
				} else if (element.type == "checkbox") {
					if (element.checked) {
						var theValue = element.value;
						// Wert "on" als 1 speichern
						if (theValue == "on") {
							theValue = 1;
						}
						submission_string += element.name + "=" + theValue + "³";
					}
				// *** textarea, text, usw. ***
				} else {        			
					if (element.value != "") {
						value = element.value.replace(/³/gi, "^3");
						submission_string += element.name + "=" + element.value + "³";
					}
				}
			}
		}
  	}
  
  	document.hiddenform.reportContent.value = submission_string;
  	// DEBUG: alert(submission_string);
  	// the next two lines are written for debugging - 
  	// to put the script into action
  	// comment out the changeObjectVisibility() line
  	// and uncomment the document.hidden.form.submit() line  	
  	//changeObjectVisibility("hiddenstuff","visible");
  	document.hiddenform.submit(); 
}

function resetForm(form) {
	alert(form.length);
  	for (i = 0; i < form.length; i++) {
  		var tempobj = form.elements[i];
    	if (tempobj.type == "text") {
      		eval(tempobj.value = "")
    	} else if (tempobj.type == "checkbox") {
      		eval(tempobj.checked = 0)
      	} else if (tempobj.col != "") {
      		eval(tempobj.value = "")
    	}
  	}
}

function resetCat() {
	//alert(form);
  	for (i = 0; i < form.length; i++) {
  		var tempobj = form.elements[i]
    	if (tempobj.type == "text") {
      		eval(tempobj.value = "")
    	} else if (tempobj.type == "checkbox") {
      		eval(tempobj.checked = 0)
    	} else if (tempobj.col != "") {
      		eval(tempobj.value = "")
    	}
  	}
}

function showAndFocus(div_id, field_to_focus) {
  	var the_div = getStyleObject(div_id);
  	if (the_div != false) {
    	changeObjectVisibility(div_id, "visible");
    	field_to_focus.focus();
  	}
}

function fillInDate() {
  var month_select = document.date_form.month;
  var month = month_select.options[month_select.selectedIndex].value;
  var day_select = document.date_form.day;
  var day = day_select.options[day_select.selectedIndex].value;
  var year_select = document.date_form.year;
  var year = year_select.options[year_select.selectedIndex].value;
  document.part1.date.value = day + "." + month + "." + year;
  changeObjectVisibility("dateDiv","hidden");
}

function explain(msg) {
  	explainBounds('width=350,height=300,left=300,top=300', msg);
}

function explainBounds(bounds, msg) {
  	newwin = window.open('','',bounds + ',resizable=yes');
  	if (!newwin.opener) {
  		newwin.opener = self;
  	}
  	with (newwin.document) {
    	open();
    	write('<html><head><LINK href="theme/master.css" rel="stylesheet" type="text/css"><head>');
		write('<body>' + msg + '<br>');
		write('<p><input type=button value="Fenster schließen." onClick=window.close()>');
		write('</body></html>');
		close();
   	}
}

function explainBoundsURL(bounds, name) {
  	//newwin = window.open('../../help/' + name,'HilfeFenster',bounds + ',resizable=yes');
  	newwin = window.open(name,'HilfeFenster',bounds + ',resizable=yes');
  	if (!newwin.opener) {
  		newwin.opener = self;
  	} 
}

function alertCheckResponsibility() {
	alert("Das Team von jeder-fehler-zaehlt.de gibt in keinem Fall Informationen an Dritte weiter.\nBitte prüfen Sie daher, ob Sie eine professionelle Körperschaft oder die Justiz über\ndiesen Vorgang informieren sollten.");
}

function validateMailForm() {
	return true;
}

var newwindow;
function customwindow(url) {
	newwindow=window.open(url,'name','width=500,height=300,left=100,top=100');
	if (window.focus) {
		newwindow.focus();
	}
}
   
function openReport(repID) { 
	var url = '/public/report/displaySingleReport.jsp?repID=' + repID;
	window.open(url, 'Bericht' + repID, 'width=640,height=600,left=200,top=100,resizable=yes,scrollbars=yes'); 
} 
   
function openEnquiry(repID, enquiryKey) { 
	var url = '/public/enquiry/enquiryShow.jsp?repID=' + repID + '&enquiryKey=' + enquiryKey;
	window.open(url, 'Rückfrage' + repID, 'width=640,height=600,left=200,top=100,resizable=yes,scrollbars=yes'); 
} 
   
function openReportWithAnker(repID, theAnker) { 
	var url = '/public/report/displaySingleReport.jsp?repID=' + repID + '#id' + theAnker;
	window.open(url, 'Bericht' + repID, 'width=640,height=600,left=200,top=100,resizable=yes,scrollbars=yes'); 
} 
   
function openDiscussion(topic) { 
	var url = '/public/discussion/discussionSingle.jsp?topic=' + topic;
	window.open(url, 'Diskussion', 'width=640,height=600,left=200,top=100,resizable=yes,scrollbars=yes'); 
} 
   
function openPrevention(part) { 
	window.open('/public/prevention/preventionSingle.jsp?part=' + part, 'TippsZurFehlervermeidung', 'width=640,height=600,left=200,top=100,resizable=yes,scrollbars=yes'); 
} 
 
var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial() {
	if (document.getElementById != null) {
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null) {
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0) {
				html += headTags[0].innerHTML;
			}
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null) {
			html += printReadyElem.innerHTML;
		} else {
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint) {
			printWin.print();
		}
	} else {
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}