
/*****************************************************************************
Partnerseller Version 3.1.7
Copyright (c) 2002-2011 kohnlesoft.de
*****************************************************************************/

/***************************************
psl_berechne_provision
***************************************/

function psl_berechne_provision(frm, dezimaltrennzeichen, tausendertrennzeichen) {

	var vFelder = new Array("preis","prozentprovision_satz","festprovision");
	var fFelder = new Array('prozentprovision_betrag','provision_betrag_netto');
	var vWerte = new Array(vFelder.length);
	var fWerte = new Array(fFelder.length);

	for(i = 0; i < vFelder.length; i++) {
		vWerte[i] = psl_string2number(frm.elements[vFelder[i]].value, "0_erzwingen", dezimaltrennzeichen, tausendertrennzeichen);
	}
	for(i = 0; i < fFelder.length; i++) {
		fWerte[i] = psl_string2number(frm.elements[fFelder[i]].value, "0_erzwingen", dezimaltrennzeichen, tausendertrennzeichen);
	}

	fWerte[0] = vWerte[0] * (vWerte[1] * 0.01);
	fWerte[1] = fWerte[0] + vWerte[2];

	for(i=0;i<vFelder.length;i++) {
		frm.elements[vFelder[i]].value = psl_number2string(vWerte[i], dezimaltrennzeichen);
	}
	for(i=0;i<fFelder.length;i++) {
		frm.elements[fFelder[i]].value = psl_number2string(fWerte[i], dezimaltrennzeichen);
	}

}

/***************************************
psl_string2number
***************************************/

function psl_string2number(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);
	}

}

/***************************************
psl_number2string
***************************************/

function psl_number2string(number, dezimaltrennzeichen) {

	var tmp;
	tmp = String(number);
	tmp = tmp.replace(/[.]/,dezimaltrennzeichen);
	return tmp;

}

/***************************************
psl_oeffne_internet
***************************************/

function psl_oeffne_internet(url, height, width) {

	var fw = ((screen.width - width) / 2);
	var fh = ((screen.height - height) / 2);

	if(url != "") {
		window.open(url, '_blank', 'width='+width+' , height='+height+', left='+fw+', top='+fh+', location=yes, menubar=yes, status=yes, resizable=yes, scrollbars=yes');
	}
	else {
		window.open('', '_blank', 'width='+width+' , height='+height+', left='+fw+', top='+fh+', location=yes, menubar=yes, status=yes, resizable=yes, scrollbars=yes');
	}

	return false;

}

/***************************************
psl_popup_subpicker
***************************************/

function psl_popup_subpicker(form, feld_subid, modus, partnerid_input, height, width, title) {

	var subid;
	var partnerid;

	subid = document[form][feld_subid].value;

	if(modus == "feld") {
		partnerid = document[form][partnerid_input].value;
	}
	else {
		partnerid = partnerid_input;
	}

	psl_popup_open('./subpicker.php?partnerid='+partnerid+'&formular='+form+'&feld='+feld_subid+'&subid_start='+subid, height, width, 'popup_subpicker', title);
	return false;

}

/***************************************
psl_popup_open
***************************************/

function psl_popup_open(url, height, width, id, title) {

	$("body").append('<div id="'+id+'" />');

	$("#"+id).dialog({
		autoOpen: false,
		modal: true,
		height: height,
		width: width,
		title: title
	});

	$("#"+id).html('<iframe id="iframe_'+id+'" name="iframe_'+id+'" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />').dialog("open");
	$("#iframe_"+id).attr("src", url);
	return false;

}

/***************************************
psl_popup_close
***************************************/

function psl_popup_close(id) {

	$("#"+id).dialog('close');
	return false;

}

/***************************************
psl_popup_close_and_go
***************************************/

function psl_popup_close_and_go(id, url) {

	$("#"+id).dialog('close');
	window.location.href = url;
	return false;

}

/***************************************
psl_popup_close_and_open
***************************************/

function psl_popup_close_and_open(id, url, height, width) {

	$("#"+id).dialog('close');

	var fw = ((screen.width - width) / 2);
	var fh = ((screen.height - height) / 2);

	window.open(url, '', 'width='+width+' , height='+height+', left='+fw+', top='+fh+', location=yes, menubar=yes, status=yes, resizable=yes, scrollbars=yes');
	return false;

}

