function am_openBrowserWindow(theURL,winName,features) {
  popup = window.open(theURL, winName, features); 
  popup.focus();
  return false;
}

function toggleBlind (id) {
  if ((elem = document.getElementById(id))) {
  	if (elem.style.display == "none") 
  		Effect.BlindDown('felgenoptionen');
  	else 
  		Effect.BlindUp('felgenoptionen');
  }
}

function toggleDisplay (id) {
  if ((elem = document.getElementById(id))) {
  	if (elem.style.display == "none") 
  		elem.style.display = "inline";
  	else 
  		elem.style.display = "none";
  }
}

function toggleImage (id,from,to) {
  if ((elem = document.getElementById(id))) {
	if (elem.src.indexOf(to) > -1) {
		elem.src = from;
	} else {
		elem.src = to;
	}
  }
}

function ajaxGet(action,params) {
	new Ajax.Request(action, { method: 'post',
							   postBody: params,
							   onSuccess: function (t) { },
							   onFailure: function (t) { }
	  }
    )
}

function disableFile(source, dest) {
  if (   source[1].checked == true 
      || source[2].checked == true) {
	  dest.disabled=true;
	  //document.getElementById('b_marke').value='01';
   } else 
    dest.disabled=false;
	}

function jaNeinLink(link,text) {
  var antwort = false;
  antwort = confirm(text);
  if (antwort) {
    self.location.href = link;
  }
}

function my_submit ( submit_to, targ ) {
  document.msgform.action = submit_to;
  document.msgform.target = targ; 
  document.msgform.onSubmit = '';
  document.msgform.submit();
}

function my_submit_popup ( submit_to, targ ) {
  document.msgform.action = submit_to;
  document.msgform.target = targ;
  document.msgform.onSubmit = MM_openBrWindow('','formtarget','width=400,height=200');
  document.msgform.submit();
}

function contact_submit_popup ( submit_to, targ ) {
  document.contactform.action = submit_to;
  document.contactform.target = targ;
  document.contactform.onSubmit = MM_openBrWindow('','formtarget','width=400,height=200');
  document.contactform.submit();
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function fillLeadingZeroes (myString,count) {
  myString=myString.toString();
  while (myString.length < count)
    myString = "0"+myString;
  return myString;
}

function mm_getLabel (theobject) {  //v1.0
  if (theobject.getAttribute('label'))
    return theobject.getAttribute('label');
  return theobject.name;
}

function createUserName(kundennummer) {
  return 'k'+fillLeadingZeroes(kundennummer,6);
}

//modified with multilanguage functionality
function MM_validateForm() { //v4.0
  var i,p,q,nm_label,nm_name,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
  	test=args[i+2]; 
  	val=MM_findObj(args[i]);
    if (val) { 
    nm_label=mm_getLabel(val); 
    nm_name=val.name; 
    if (document.getElementById(nm_name))
      document.getElementById(nm_name).style.backgroundColor = 'white';
    if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) {
          errors+='- '+nm_label+' '+emailMeldung+'.\n';
          if (document.getElementById(nm_name))
            document.getElementById(nm_name).style.backgroundColor = 'red';
        }
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) {
          errors+='- '+nm_label+' '+nummerMeldung+'.\n';
       	  if (document.getElementById(nm_name))
       	    document.getElementById(nm_name).style.backgroundColor = 'red';
        }
        if (test.indexOf('inRange') != -1) { 
          p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) {
          	errors+='- '+nm_label+' '+nummerZwischenMeldung+' '+min+' '+und+' '+max+'.\n';
          	if (document.getElementById(nm_name))
          	  document.getElementById(nm_name).style.backgroundColor = 'red';
          }
    } } } else if (test.charAt(0) == 'R') {
    	    errors += '- '+nm_label+' '+benoetigtMeldung+'.\n'; 
    	    if (document.getElementById(nm_name))
    	      document.getElementById(nm_name).style.backgroundColor = 'red';
          }
    }
  } if (errors) alert(fehlerMeldung+':\n'+errors);
  document.MM_returnValue = (errors == '');
}
