var debug = true; //get errors as alert

function doContact(frm){	
	//check required fields, rule, search in field captions for * as last char !
	var elem;
	var errors = 0;
	for (var i=0;i<frm.elements.length;i++){
		elem = frm.elements[i];
		errors+=markRequired(elem);
		if (elem.name == 'email' && elem.value.length>0){
			if (!emailOK(elem.value)){
				errors++;
				markCaption(null,elem.name);			
			}else{
				demarkCaption(null,elem.name);
			}
		}
	}

	if (errors>0){
		alert(frm.errormsg.value);
		return false;
	}else
		return true;
}

 //-------------
 function markRequired(el){
	 var o = getObjectCaption(null,el.name);
	 var txt = "";
	 var i = 0;
	 if (o){
			txt = o.innerHTML; 
				
			 if ((txt.length>0 && txt.indexOf("*")==txt.length-1) && isEmpty(el.value)){
				
				markCaption(o);
				i++;
			 }else{
				demarkCaption(o);  
			 }	 
			
	 }	 
	 return i;
 }

 //-------------
 function markCaption(ob, el_name){
	 var o = getObjectCaption(ob,el_name);
	 if (o){
		o.style.color = 'red';	 		 
	 }
 }
  //-------------
 function demarkCaption(ob, el_name){
	 var o = getObjectCaption(ob,el_name);	 
	 if (o){
		o.style.color = '';	 	 
	 }
 }
 //--------------
 
 function getObjectCaption(o,nm){
	 if (o) return o;
	 var obj = document.getElementById(nm + "_label");
	 return obj;
 }
 
 //-------------
 function do_kontakt(frm){
	 if (!emailOK(frm.email.value)) {alert('Bitte überprüfen Sie Email!'); return;}
	 if (isEmpty(frm.nachname.value)) {alert('Bitte Nachname eingeben!');return;}
	 if (isEmpty(frm.nachricht.value)) {alert('Sie haben keine Nachricht eingegeben!');return;}
	 frm.submit();
 }
 //-------------
function isEmpty(str){
  var s = new String(str);
  s=s.replace(" ","");
  return (s.length==0)
}
 //-------------
function emailOK(str){
	var s = new String(str);
	var ok = false;
	els = s.split("@");
	if (els.length>1){
		els2 = els[1].split(".");
		if (els2.length>1){
			if (els2[0].length>0){
				if (els2[1].length>1){
					if (els[0].length>0) ok=true;
				}
			}
		}
	}
	
	return ok;
}

//------------------ DHTML loading combo
	function fillCombo(strId,comboId){
		try{
			var sal = document.getElementById(comboId);
			var salStr = document.getElementById(strId).value;
			var els = salStr.split(',');
			var option_elem;
			deleteOptions(sal);
			for (var i=0;i<els.length;i++){
				option_elem = new Option(els[i],els[i],false,true); 
				sal.options[sal.options.length] = option_elem;
				//option = document.createElement("OPTION");
				//option.innerText = els[i];
				//option.value = els[i];
				//sal.options.add(option);				
			}
		}catch(e){
			if (debug) alert(e.description);
		}	
	}
	
	function deleteOptions(el){
		try{
			if (el){
				if (el.options){
					while(el.options.length>0){
						el.remove(0);
					}
				}
			}
		}catch(e){
			if (debug) alert(e.description);
		}
	}
//--------------
