function berechneProvision(frm, dezimaltrennzeichen, tausendertrennzeichen) {

	// die 'variablen' felder
	var vFelder = new Array("preis","prozentprovision_satz","festprovision");
	// die 'fixen' felder, die der user nicht ändern kann.
	var fFelder = new Array('prozentprovision_betrag','provision_betrag_netto');
	// zwischenspeicher, um aus den string-werten float-werte zu machen.
	var vWerte = new Array(vFelder.length);
	var fWerte = new Array(fFelder.length);

	// konvertierung aller felder in float-werte
	for(i = 0; i < vFelder.length; i++) {
		vWerte[i] = stringToNumber(frm.elements[vFelder[i]].value, "0_erzwingen", dezimaltrennzeichen, tausendertrennzeichen);
	}
	for(i = 0; i < fFelder.length; i++) {
		fWerte[i] = stringToNumber(frm.elements[fFelder[i]].value, "0_erzwingen", dezimaltrennzeichen, tausendertrennzeichen);
	}

	// berechnen:
	// prozentprovision_betrag = preis * (prozentprovision_satz * 0.01)
	fWerte[0] = vWerte[0] * (vWerte[1] * 0.01);
	// provision_betrag_netto = prozentprovision_betrag + festprovision
	fWerte[1] = fWerte[0] + vWerte[2];

	// wieder zurückschreiben:
	for(i=0;i<vFelder.length;i++) {
		frm.elements[vFelder[i]].value = numberToString(vWerte[i], dezimaltrennzeichen);
	}
	for(i=0;i<fFelder.length;i++) {
		frm.elements[fFelder[i]].value = numberToString(fWerte[i], dezimaltrennzeichen);
	}

}

function stringToNumber(string, modus, dezimaltrennzeichen, tausendertrennzeichen) {

    var out = "";

    for(var i=0; i < string.length; i++) {

    	if(string.charAt(i) == tausendertrennzeichen) {
    		continue;
    	}

    	if(string.charAt(i) == dezimaltrennzeichen || string.charAt(i) == ".") {
    		out = out + ".";
    		continue;
    	}

    	if(string.charAt(i) == " ") {
    		continue;
    	}

     	if(string.charAt(i) == "-") {
    		out = out + "-";
    		continue;
    	}

		if(isNaN(string.charAt(i)) == false) {
        	out = out + string.charAt(i);
    	}

    }

    if(out == "") {

    	if(modus == "0_erzwingen") {
    		return 0;
    	}
    	else {
    		return "";
    	}

    }
	else {
    	return parseFloat(out);
	}

}

function numberToString(number, dezimaltrennzeichen) {
	var tmp;
	tmp = String(number);
	tmp = tmp.replace(/[.]/,dezimaltrennzeichen);
	return tmp;
}

function pslOeffneInternet(fieldValue) {
	var url;
	url = fieldValue;
	re = /^(file|http|https|ftp):\/\/\S/i
	if(!re.test(url)) {
		url = 'http://' + url;
	}
	window.open(url,'_blank','');
	return;
}

function show_htmleditor(form, feld, modus) {
	f1 = window.open('./htmleditor.php?form='+form+'&feld='+feld+'&modus='+modus+'', 'htmleditor', 'width=910,height=600,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function partnerdetails(partnerid) {
	f1 = window.open('./partnerdaten.php?aktion=details&partnerid='+partnerid+'', 'partnerdetails', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function partnerpicker(form, feld) {
	var partnerid;
	partnerid = document[form][feld].value;
	f1 = window.open('./partnerpicker.php?formular='+form+'&feld='+feld+'&partnerid_start='+partnerid+'', 'partnerpicker', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function subpicker(form, feld_subid, modus, partnerid_input) {
	var subid;
	var partnerid;
	if(modus == "feld") {
		partnerid = document[form][partnerid_input].value;
	}
	else {
		partnerid = partnerid_input;
	}
	subid = document[form][feld_subid].value;
	f1 = window.open('./subpicker.php?partnerid='+partnerid+'&formular='+form+'&feld='+feld_subid+'&subid_start='+subid+'', 'subpicker', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function bannerpicker(form, feld) {
	var bannerid;
	bannerid = document[form][feld].value;
	f1 = window.open('./bannerpicker.php?formular='+form+'&feld='+feld+'&bannerid_start='+bannerid+'', 'bannerpicker', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function benutzerpicker(form, feld) {
	var id;
	id = document[form][feld].value;
	f1 = window.open('./benutzerpicker.php?formular='+form+'&feld='+feld+'&id_start='+id+'', 'benutzerpicker', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function bildgroesse(form, feld_breite, feld_hoehe, feld_bild) {
	f1 = window.open('./bildgroesse.php?formular='+form+'&feld_breite='+feld_breite+'&feld_hoehe='+feld_hoehe+'&aktuelle_datei='+feld_bild+'', 'bildgroesse', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function farbauswahl(form, feld) {
	f1 = window.open('./design.php?aktion=farbauswahl&formular='+form+'&feld='+feld+'', 'farbauswahl', 'width=400,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function fenstergroesse(form, feld_breite, feld_hoehe, feld_bild) {
	f1 = window.open('./bildgroesse.php?formular='+form+'&feld_breite='+feld_breite+'&feld_hoehe='+feld_hoehe+'&aktuelle_datei='+feld_bild+'', 'fenstergroesse', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function zeitraumauswahl(form, feld) {
	var time;
	time = document[form][feld].value;
	f1 = window.open('./zeitraumauswahl.php?formular='+form+'&feld='+feld+'&timestamp='+time+'', 'zeitraumauswahl', 'width=650,height=300,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function bannerauswahl(form, feld, typ) {
	var bildurl;
	bildurl = document[form][feld].value;
	f1 = window.open('./bannerauswahl.php?formular='+form+'&feld='+feld+'&typ='+typ+'&aktuelle_datei='+bildurl+'', 'bannerauswahl', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function admin_einzelmail(partnerid) {
	f1 = window.open('./kontakt.php?aktion=admin_einzelmail&partnerid='+partnerid+'', 'admin_einzelmail', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function benutzer_einzelmail(id) {
	f1 = window.open('./benutzer.php?aktion=einzelmail&id='+id+'', 'benutzer_einzelmail', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function provisionspicker(form, feld, typ, partnerid_input) {
	var partnerid;
	partnerid = document[form][partnerid_input].value;
	f1 = window.open('./provisionspicker.php?formular='+form+'&feld='+feld+'&partnerid='+partnerid+'&typ='+typ+'', 'provisionspicker', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function template_variablen(typ) {
	f1 = window.open('./templates.php?aktion=variablen_'+typ+'', 'template_variablen', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function template_grafik() {
	f1 = window.open('./templates.php?aktion=grafik', 'template_grafik', 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes');
	f1.focus();
}

function open_popup(url, name, menubar) {
	f1 = window.open(url, name, 'width=650,height=550,left=0,top=0,resizable=yes,scrollbars=yes,menubar='+menubar+'');
	f1.focus();
}
