function CheckInput(errorMsg) {

	var tagName, tagVal;
	var retval = true;
	var opt, found; 
	var fehlendeOptionaleElemente = 0;
	var reqStr = document.getElementsByName("required")[0].value;
	var optionalEl = document.getElementsByName("optional")[0];
	var optionalStr = "";
	if(optionalEl != null) {
		var optionalStr = optionalEl.value;
	}
		

	for (var i = 0; i < document.forms[0].elements.length; i++) {
		tagName = document.forms[0].elements[i].name;
		
		if((optionalStr.indexOf(tagName)>=0) && (tagName!="")){
			tagVal = document.forms[0].elements[i].value;
			if (tagVal == "") {
			 	fehlendeOptionaleElemente++;
			}
		}
// OBEN TOP
	if ((reqStr.indexOf(tagName) >= 0) && (tagName != "")) {
			
			if (document.forms[0].elements[i].nodeName == "SELECT") {
			 	opt = document.forms[0].elements[i].options[document.forms[0].elements[i].options.selectedIndex];
			 	found = false;
			 	for (var k = 0; k < opt.attributes.length; k++) {
			 
			 		if (opt.attributes[k].name == "value") {
			 			if (!opt.attributes[k].specified) {
			 				tagVal = opt.childNodes[0].data;
			 			}
			 			else {
			 				tagVal = opt.value;
			 			}
			 			found = true;
			 		} //if spec
				}
				//for attr
				if (!found) {
			 		tagVal = opt.childNodes[0].data;
				}
			} //if SELECT
			else {
			 	tagVal = document.forms[0].elements[i].value;
			}   
			
			if (tagVal == "") {
			 	retval = false;
			 	document.forms[0].elements[i].style.backgroundColor = "#FFB3B3";
			}
			else {
			 	document.forms[0].elements[i].style.backgroundColor = "#FFFFFF"; 
			}
		}
		
		//if (reqStr.indexOf(tagName)...
		
	// UNTEN TOP		
	}
	
	if(fehlendeOptionaleElemente==3){
		retval = false;
		for (var i = 0; i < document.forms[0].elements.length; i++) {
			tagName = document.forms[0].elements[i].name;
			if((optionalStr.indexOf(tagName)>=0) && (tagName!="")){
					document.forms[0].elements[i].style.backgroundColor = "#0099FF";
			}
		}
	}

	if (!retval) {
		window.location.href = "#";
		if (document.getElementById("contactwarning") != null) {
			document.getElementById("contactwarning").style.color = "#FF0000";
			document.getElementById("contactwarning").innerHTML = errorMsg;
		}
	}
	
	document.anfrage.Kommentar.value = document.anfrage.Kommentar.value + "\n\n\n Produkt:" + document.URL.split("?product=")[1]; 
	
	return retval;
}


//function setRedirects() {
	//var path = document.URL.substring(0, document.URL.lastIndexOf('/'));
	//document.getElementsByName("redirect")[0].value = path + "/form_suc.html";
//	document.getElementsByName("missing_fields_redirect")[0].value = path + "/form_mis.html";
//}

function setInfoValues() {
	document.getElementsByName("URL")[0].value = document.URL;
	//if (document.getElementById("recipientInfo") != null) 
	//	document.getElementById("recipientInfo").innerHTML = document.getElementById("recipientInfo").innerHTML.replace(/#email#/, document.getElementsByName("recipient")[0].value);

}

function setDebugMode() {
	var recipient = "";
	if (document.URL.indexOf("?debug=") > -1) {
		recipient = document.URL.substring(document.URL.lastIndexOf("=") + 1, document.URL.length);
		document.getElementsByName("recipient")[0].value = recipient + "@storkdesign.de";
	}
}

function checkProduct() {
if (document.URL.indexOf("?product") >= 0) {
document.getElementById("product_name").innerHTML = document.URL.split("?product=")[1];
}
}
/*document.forms[0].Kommentar.value = document.forms[0].Kommentar.value + document.URL.split("?product=")[1]; */
