/*function update_attributes(doc){
			var tank_choice = doc.forms.userdata.kindoftank;
			var tank_div = doc.getElementById("tank_attributes");
			while (tank_div.hasChildNodes()){
				tank_div.removeChild(tank_div.firstChild);
			}
		
			if ((tank_choice.options[tank_choice.selectedIndex].value == "Erdtank / Hochtank") ||
				(tank_choice.options[tank_choice.selectedIndex].value == "Kellergeschweisster Tank")){
			//Label
				var labelnode = doc.createElement("label");
				var labeltext = doc.createTextNode("Tankgr??e (Ltr.): *");
				labelnode.appendChild(labeltext);
				doc.getElementById("tank_attributes").appendChild(labelnode);
			//Input
				var inputnode = doc.createElement("input");
			//	var attribute = doc.createAttribute("type");
				inputnode.setAttribute("type","text");
				inputnode.setAttribute("name","ctanksize");
				inputnode.setAttribute("value","<element name="ctanksize">");
				inputnode.setAttribute("maxlength","100");
				inputnode.setAttribute("class","big<if name="ctanksize_err"> error</if>");
				doc.getElementById("tank_attributes").appendChild(inputnode);
			}else if (tank_choice.options[tank_choice.selectedIndex].value == "Batterietanks"){
			//Labels
				var labelnode1 = doc.createElement("label");
				var labeltext1 = doc.createTextNode("Anzahl der Tanks: *");
				labelnode1.appendChild(labeltext1);
				var labelnode2 = doc.createElement("label");
				var labeltext2 = doc.createTextNode("Einzeltank Gr??e (Ltr.): *");
				labelnode2.appendChild(labeltext2);
				var labelnode3 = doc.createElement("label");
				var labeltext3 = doc.createTextNode("Beschaffenheit des Tanks: *");
				labelnode3.appendChild(labeltext3);
			//Inputs
				var inputnode1 = doc.createElement("input");
				inputnode1.setAttribute("type","text");
				inputnode1.setAttribute("name","cnotanks");
				inputnode1.setAttribute("value","<element name="csingletanksize">");
				inputnode1.setAttribute("maxlength","100");
				inputnode1.setAttribute("class","big<if name="csingletanksize_err"> error</if>");
				var inputnode2 = doc.createElement("input");
				inputnode2.setAttribute("type","text");
				inputnode2.setAttribute("name","csingletanksize");
				inputnode2.setAttribute("value","<element name="csingletanksize">");
				inputnode2.setAttribute("maxlength","100");
				inputnode2.setAttribute("class","big<if name="csingletanksize_err"> error</if>");
			//Select
				var selectnode = doc.createElement("select");
				selectnode.setAttribute("name","ctankmaterial");
				selectnode.setAttribute("size","1");
				selectnode.setAttribute("class","<if name="ctankmaterial_err"> error</if>");
				selectnode.setAttribute("font-weight","bold");
				selectnode.options[0] = new Option("Wei? nicht");
				selectnode.options[0].selected = true;
				selectnode.options[1] = new Option("Plastik / Gfk");
				selectnode.options[2] = new Option("Stahl");
		
				doc.getElementById("tank_attributes").appendChild(labelnode1);
				doc.getElementById("tank_attributes").appendChild(inputnode1);
				doc.getElementById("tank_attributes").appendChild(labelnode2);
				doc.getElementById("tank_attributes").appendChild(inputnode2);
				doc.getElementById("tank_attributes").appendChild(labelnode3);
				doc.getElementById("tank_attributes").appendChild(selectnode);
			}
}
*/

function changeInputValue(doc,objForm, strNameElement, src) {
	/* check if objects exist */
	var firstnameLabelNode = doc.getElementById("firstnamelabel");
	var surnameLabelNode = doc.getElementById("surnamelabel");
	if (typeof(objForm) != 'undefined') {
		if (typeof(objForm.elements) != 'undefined') {
			if (typeof(objForm.elements[strNameElement]) != 'undefined') {
				if (typeof(objForm.elements[strNameElement].value) != 'undefined') {
					if (src == "c") {//Firma
						if (objForm.elements[strNameElement].value.length == 0){
							objForm.elements[strNameElement].value = String('Firma');
						}
						firstnameLabelNode.firstChild.nodeValue = "";
						surnameLabelNode.firstChild.nodeValue = "Firmenname: *";
					} else if ((src == "m")||(src == "f")) {//Herr/Frau
						if (objForm.elements[strNameElement].value == 'Firma'){
							objForm.elements[strNameElement].value = '';
						}
						firstnameLabelNode.firstChild.nodeValue = "Vorname: *";
						surnameLabelNode.firstChild.nodeValue = "Nachname: *";
					}
				}
			}
		}
	}
}

function deviantChangeInputValue(doc,objForm, strNameElement, src) {
	/* check if objects exist */
	var firstnameLabelNode = doc.getElementById("d_firstnamelabel");
	var surnameLabelNode = doc.getElementById("d_surnamelabel");
	if (typeof(objForm) != 'undefined') {
		if (typeof(objForm.elements) != 'undefined') {
			if (typeof(objForm.elements[strNameElement]) != 'undefined') {
				if (typeof(objForm.elements[strNameElement].value) != 'undefined') {
					if (src == "c") {//Firma
						if (objForm.elements[strNameElement].value.length == 0){
							objForm.elements[strNameElement].value = String('Firma');
						}
						firstnameLabelNode.firstChild.nodeValue = "";
						surnameLabelNode.firstChild.nodeValue = "Firmenname: *";
					} else if ((src == "m")||(src == "f")) {//Herr/Frau
						if (objForm.elements[strNameElement].value == 'Firma'){
							objForm.elements[strNameElement].value = '';
						}
						firstnameLabelNode.firstChild.nodeValue = "Vorname: *";
						surnameLabelNode.firstChild.nodeValue = "Nachname: *";
					}
				}
			}
		}
	}
}

function checkText(doc, defaultText, elementIdText, radioName,radioValue){
	var firstNameText = doc.getElementById(elementIdText);
	var radiobtn = findNodeViaNodeNameValue(doc,'input',radioName,radioValue);
	if ((firstNameText.value.length==0)&&(radiobtn.checked)){//&&(radiobtn.checked)
		firstNameText.value = defaultText;
	}		
}


//finds a node in combination with its tagname and the nodename 
function findNodeViaNodeName(doc,nodeTagName,nodeName){
	var tagNodes = doc.getElementsByTagName(nodeTagName);
	var node=null;
	var i=0;
	var length=tagNodes.length;
	while((node==null)&&(i<length)){
		if (tagNodes[i].getAttribute("name")==nodeName){
			node=tagNodes[i];
		}
		i++;
	}
	return node;
}

//finds a node in combination with its tagname, nodename and its value 
function findNodeViaNodeNameValue(doc,nodeTagName,nodeName,nodeValue){
	var tagNodes = doc.getElementsByTagName(nodeTagName);
	var node=null;
	var i=0;
	var length=tagNodes.length;
	while((node==null)&&(i<length)){
		if ((tagNodes[i].getAttribute("name")==nodeName)&&
		    (tagNodes[i].getAttribute("value")==nodeValue)){
			node=tagNodes[i];
		}
		i++;
	}
	return node;
}

//Functions to join informations of the register-form and the updateuser-information form	
function joinBirthday(doc,birthdayFieldName){
	//alert("JOIN da fam");
	var d=findNodeViaNodeName(doc,"input","b_day").value;
	var m=findNodeViaNodeName(doc,"input","b_month").value;
	var y=findNodeViaNodeName(doc,"input","b_year").value;
	var birthdayNode=findNodeViaNodeName(doc,"input",birthdayFieldName);
	if ((d!="")&&(m!="")&&(y!="")){
		birthdayNode.value=d+"."+m+"."+y;
		foo = birthdayNode.value;
	} else {
		birthdayNode.value="";
	}
}	


function joinInfos(doc,inf1_name,division,inf2_name,targetTagName,targetNodeName){
	var val1=findNodeViaNodeName(doc,'input',inf1_name).value;
	var val2=findNodeViaNodeName(doc,"input",inf2_name).value;
	var targetNode=findNodeViaNodeName(doc,targetTagName,targetNodeName);
	if((val1!="")&&(val2!="")){
		if (inf2_name=='cstreetnr'){	//We don't want to have blanks in our housenumber!
			val2=val2.replace(/ /,'');
		}
		targetNode.value=val1+division+val2;
	}else{
		targetNode.value="";		
	}		
}


//Functions to divide those informations for the forms again

function divideBirthday(doc){
	var birthday=findNodeViaNodeName(doc,"input","birthday").value;
	var birthdata=birthday.split(".");
	var birthdatalength=birthdata.length;
	var d_node=findNodeViaNodeName(doc,"input","b_day");
	if(birthdatalength>0){
		d_node.value=birthdata[0];
	} else {
		d_node.value="";
	}
	var m_node=findNodeViaNodeName(doc,"input","b_month");
	if(birthdatalength>1){
		m_node.value=birthdata[1];
	} else {
		m_node.value="";
	}
	var y_node=findNodeViaNodeName(doc,"input","b_year");
	if(birthdatalength>2){
		y_node.value=birthdata[2];
	} else {
		y_node.value="";
	}	
}

function divideInfos(doc,src,target1,target2,division){
	if (src.indexOf('default')==0){
		var srcInfo=findNodeViaNodeName(doc,"input",src.slice(7,src.length-7)).defaultValue;
	}else{
		var srcInfo=findNodeViaNodeName(doc,"input",src).value;
	}
	var srcSplit=srcInfo.split(division);
	var srcSplitLength=srcSplit.length;
	var target1Node=findNodeViaNodeName(doc,"input",target1);
	if (division=="-"){
			target1Node.value=srcSplit[0];
			target1Node.defaultValue=srcSplit[0];//default, to have the right value onreset
	}else if (division==" "){
		var j=0;
		target1Node.value="";
		target1Node.defaultValue="";//default, to have the right value onreset
		while (j<srcSplitLength-1){
			target1Node.value+=srcSplit[j]+" ";
			target1Node.defaultValue+=srcSplit[j]+" ";//default, to have the right value onreset
			j++;
		
		}
	}
	var target2Node=findNodeViaNodeName(doc,"input",target2);
	if (division==" "){
		target2Node.value=srcSplit[srcSplitLength-1];
		target2Node.defaultValue=srcSplit[srcSplitLength-1];//default, to have the right value onreset
	}else if (division=="-"){
				target2Node.value="";
				target2Node.defaultValue="";//default, to have the right value onreset
				var i=1;
				while (i<srcSplitLength){
					target2Node.value+=srcSplit[i];
					target2Node.defaultValue+=srcSplit[i];//default, to have the right value onreset
					i++;
				}
	}
}

function checkForError(){
	if(document.getElementById('form_error').value==1)
		return false;
	else
		return true;
	
}

//?berpr?fen der Schlauchl?nge
function checkChose(doc,value){
	var detect = navigator.userAgent.toLowerCase();
	var style;
	
	if (detect.indexOf('msie') + 1)	{// internet explorer
		style = 'className';
	} else {// mozilla etc.
		style = 'class';
	}	
	var errorNode=null;
	if (value>60 || isNaN(value)){//insert an errormassage when value bigger 60
		if (findNodeViaNodeName(doc,'p','errorChose')!=null){//if errormsg was stated - it'll be deleted
			doc.getElementById("tankdata").removeChild(findNodeViaNodeName(doc,'p','errorChose'));
		}
		var divTankdata=doc.getElementById("tankdata");
		var brNode=findNodeViaNodeName(doc,'input','chose').nextSibling;
		errorNode=doc.createElement("p");
		errorNode.setAttribute(style,"error");
		errorNode.setAttribute("name","errorChose");
		if(value>60){
			var errormsg=doc.createTextNode("Leider können wir Sie auf Grund der Schlauchlänge von über 60m nicht beliefern.");
		}else{
			errorNode.appendChild(doc.createElement("br"));
			errorNode.appendChild(doc.createElement("br"));
			var errormsg = doc.createTextNode("Bitte geben Sie eine Zahl zwischen 0 und 60 ein.");
		}
		doc.getElementById('form_error').setAttribute("value",1);
		errorNode.appendChild(errormsg);
		doc.getElementById("tankdata").insertBefore(errorNode,brNode);
	}else if (findNodeViaNodeName(doc,'p','errorChose')!=null){//if errormsg was stated - it'll be deleted
		doc.getElementById('form_error').setAttribute("value",0);
		doc.getElementById("tankdata").removeChild(findNodeViaNodeName(doc,'p','errorChose'));
	}
}


//function to select the selectoption according to the DB info
function selectoption(doc,selectId,selectOption){
	if ((selectOption!='')&&(selectOption!=null)){
		var selectNode = doc.getElementById(selectId);
		selectNode.options[selectOption].selected=true;
	}
}


function checkObjForValue(doc,obj,defaultValue,fieldname,errFieldId,motherNodeId,classAttr){
	if (doc.getElementById("errorNode")!=null){
		var motherNode=doc.getElementById(motherNodeId);
		var errorfield = doc.getElementById("errorNode").getAttribute('name');
		var classAttrs=findNodeViaNodeName(doc,'input',errorfield).getAttribute('class').split(' ');
		var defAttr=classAttrs[0];
		findNodeViaNodeName(doc,'input',errorfield).setAttribute("class",defAttr);
		motherNode.removeChild(doc.getElementById("errorNode"));		
	}
	if (obj.value.length==0){
		obj.value=defaultValue;
		obj.setAttribute('class',classAttr);
		var errorNode=doc.createElement("p");
		errorNode.setAttribute("id","errorNode");
		errorNode.setAttribute("name",errFieldId);
		errorNode.setAttribute("class","error");
		var errormsg=doc.createTextNode("Das Feld "+fieldname+" muss ausgef?llt werden.");
		errorNode.appendChild(errormsg);
	//	var beforeNode=
		doc.getElementById(motherNodeId).insertBefore(errorNode,doc.getElementById("legend").nextSibling);
	}
}


function setSelectbox(doc,selectBoxName,selectValue){
	var selectBox=findNodeViaNodeName(doc,'select',selectBoxName);
	if (selectBox!='undefined'){
		if ((selectValue==0)||(selectValue=='')){
			selectBox.options[0].selected=true;
		}
		if (selectValue==1){
			selectBox.options[1].selected=true;
		}
		if (selectValue==2){
			selectBox.options[2].selected=true;
		}
	}
}

function setRadioButtonsMFC(doc,RadioButtonName,radioValue){
	if (radioValue!=''){
		findNodeViaNodeNameValue(doc,'input',RadioButtonName,'m').checked = false;
		findNodeViaNodeNameValue(doc,'input',RadioButtonName,'f').checked = false;
		findNodeViaNodeNameValue(doc,'input',RadioButtonName,'c').checked = false;
	}
	
	if (radioValue=='m'){
		findNodeViaNodeNameValue(doc,'input',RadioButtonName,'m').checked = true;
	}
	if (radioValue=='f'){
		findNodeViaNodeNameValue(doc,'input',RadioButtonName,'f').checked = true;
	}
	if (radioValue=='c'){
		findNodeViaNodeNameValue(doc,'input',RadioButtonName,'c').checked = true;
	}
}



function admin_update_attributes(doc){
	var detect = navigator.userAgent.toLowerCase();
	var displaymode;
	
	if (detect.indexOf('msie') + 1)	{// internet explorer
		displaymode = 'block';
	} else {// mozilla etc.
		displaymode = 'table-row';
	}
	
	var tank_choice = doc.forms.userdata.ctanktype;
	if ((tank_choice.options[tank_choice.selectedIndex].value == "0") ||
		(tank_choice.options[tank_choice.selectedIndex].value == "1")){
		doc.getElementById('ctanksize_id').style.display=displaymode;
		
		doc.getElementById('cnotanks_id').style.display="none";
		doc.getElementById('csingletanksize_id').style.display="none";
		doc.getElementById('ctankmaterial_id').style.display="none";
	//setting defaults, if fields don't have a value	
		if (doc.getElementById('notanks').value==''){
			doc.getElementById('notanks').value='---';
		}
		if (doc.getElementById('singletanksize').value==''){
			doc.getElementById('singletanksize').value='---';
		}
	}else if (tank_choice.options[tank_choice.selectedIndex].value == "2"){
		doc.getElementById('ctanksize_id').style.display="none";
		//setting default, if field doesn't have a value
		if (doc.getElementById('tanksize').value==''){
			doc.getElementById('tanksize').value='---';
		}
		doc.getElementById('cnotanks_id').style.display=displaymode;
		doc.getElementById('csingletanksize_id').style.display=displaymode;
		doc.getElementById('ctankmaterial_id').style.display=displaymode;
	}
}



