function resetem() {
	document.getElementsByName("module[1]")[0].checked = false ;
	document.getElementsByName("module[1]")[1].checked = false ;
	document.getElementsByName("module[2]")[0].checked = false ;
	document.getElementsByName("module[2]")[1].checked = false ;
	
	document.getElementById('clients').value = 1 ;
	document.getElementById('months').value = 54 ;
	
	for(var i=0;i<=3;i++) {
		document.getElementById('e' + i).style.display = 'none' ;
	}
	
	document.getElementById('button_disabled').style.display = 'block' ;
	document.getElementById('button_enabled').style.display = 'none' ;
	
}

function ajd_c(param) {
	var clients = document.getElementById('clients').value ;
	if (param == '+' && clients < 9999) {
		clients++ ;
	}
	if (param == '-' && clients > 1) {
		clients-- ;
	}
	document.getElementById('clients').value = clients ;
}

function showModule() {
	var choice = document.getElementById('product').value ;
	resetem() ;
	if (choice=='0') {
		document.getElementById('OLmods').style.display = 'none' ;
		document.getElementById('CLmods').style.display = 'none' ;
		document.getElementById('mask').style.display = 'none' ;
	} else {
		if (choice<='2') {
			document.getElementById('CLmods').style.display = 'block' ;
			document.getElementById('OLmods').style.display = 'none' ;
		} else {
			document.getElementById('OLmods').style.display = 'block' ;
			document.getElementById('CLmods').style.display = 'none' ;
		}
	} 
}

function resetall() {
	
	resetem() ;
	document.getElementById('CLmods').style.display = 'block' ;
	document.getElementById('OLmods').style.display = 'none' ;
	
	document.getElementById('result').style.display = 'none' ;
	document.getElementById('calculator').style.display = 'block' ;
	document.getElementById('product').value = 1 ;
	
}

function cf() {
	if (document.getElementsByName("module[1]")[0].checked == true ||
		document.getElementsByName("module[1]")[1].checked == true ||
		document.getElementsByName("module[2]")[0].checked == true ||
		document.getElementsByName("module[2]")[1].checked == true) {
		document.getElementById('button_disabled').style.display = 'none' ;
		document.getElementById('button_enabled').style.display = 'block' ;
	} else {
		document.getElementById('button_disabled').style.display = 'block' ;
		document.getElementById('button_enabled').style.display = 'none' ;
	}
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
    return sa ? s : s[0];
}

function roundit(x, n) {
	  if (n < 1 || n > 14) return false;
	  var e = Math.pow(10, n);
	  var k = (Math.round(x * e) / e).toString();
	  if (k.indexOf('.') == -1) k += '.';
	  k += e.toString().substring(1);
	  return str_replace('.', ',', (k.substring(0, k.indexOf('.') + n+1)));
}

function calc() {
	
	var error = 0 ;
	
	/**
	* List of all main products
	*/
	var series = new Array ;
	series[1] = 'Classic Line Standard' ;
	series[2] = 'Classic Line Professional' ;
	series[3] = 'Office Line Basic' ;
	series[4] = 'Office Line Business' ;
	
	/**
	* Series to Module Price Relation
	*/
	var price = new Array ;
	for(var i=1;i<=4;i++) {
		price[i] = new Array ;
	}
	/* CL Std */
	price[1][0] = 795 ;
	price[1][1] = 795 ;
	price[1][2] = 595 ;
	/* CL Pro */  
	price[2][0] = 1795 ;
	price[2][1] = 1795 ;
	price[2][2] = 595 ;
	/* OL Std */  
	price[3][0] = 890 ;
	price[3][1] = 890 ;
	price[3][2] = 690 ;
	/* OL Pro */  
	price[4][0] = 1990 ;
	price[4][1] = 1990 ;
	price[4][2] = 1290 ;
	
	var modules = new Array ;
	for(var i=1;i<=4;i++) {
		modules[i] = new Array ;
	}
	
	modules[1][1] = 'Auftragsbearbeitung' ;
	modules[1][2] = 'Finanzbuchhaltung' ;
	modules[1][3] = 'Auftragsbearbeitung, Finanzbuchhaltung' ;

	modules[2][1] = 'Auftragsbearbeitung' ;
	modules[2][2] = 'Finanzbuchhaltung' ;
	modules[2][3] = 'Auftragsbearbeitung, Finanzbuchhaltung' ;
	
	modules[3][1] = 'Warenwirtschaft' ;
	modules[3][2] = 'Rechnungswesen' ;
	modules[3][3] = 'Warenwirtschaft, Rechnungswesen' ;
	
	modules[4][1] = 'Warenwirtschaft' ;
	modules[4][2] = 'Rechnungswesen' ;
	modules[4][3] = 'Warenwirtschaft, Rechnungswesen' ;

	var input = new Array ;
	var output = new Array ;
	var licence = 0 ;
	var clients = 0 ;
	var total = 0 ;
	var monthly = 0 ;
	
	input['Months'] = document.getElementById('months').value ;
	input['Series'] = document.getElementById('product').value ;
	input['Clients'] = document.getElementById('clients').value ;
	input['Modules'] = 0 ;
		
	output['monthly_clients'] = 0 ;
	output['Price'] = 0 ;
	
	if (input['Series'] <= 2) {
		
		for(var i=0;i<=1;i++) {
			if (document.getElementsByName("module[1]")[i].checked == true) {
				
				output['Price'] = parseFloat(output['Price'])+parseFloat(price[input['Series']][i]) ;
				output['monthly_clients'] = parseFloat(price[input['Series']][2]) ;
				var j = i+1 ;
				input['Modules'] = parseFloat(input['Modules'])+parseFloat(j) ;
			}
		}
	} else {
		for(var i=0;i<=1;i++) {
			if (document.getElementsByName("module[2]")[i].checked == true) {
				output['Price'] = parseFloat(output['Price'])+parseFloat(price[input['Series']][i]) ;
				output['monthly_clients'] = parseFloat(price[input['Series']][2]) ;
				var j = i+1 ;
				input['Modules'] = parseFloat(input['Modules'])+parseFloat(j) ;
			}
		}
	}
	
	output['licence'] = parseFloat(output['Price'])+(parseFloat(output['monthly_clients'])*parseFloat(input['Clients'])) ;
	monthly = parseFloat(output['licence'])/parseFloat(input['Months']) ;
	per_client = parseFloat(monthly)/parseFloat(input['Clients']) ;
	
	if (output['licence']<=3000) {
		error = 4 ;
	}
	
	document.getElementById('result').style.display = 'block' ;
	document.getElementById('calculator').style.display = 'none' ;
	
	for(var i=0;i<=3;i++) {
		document.getElementById('e' + i).style.display = 'none' ;
	}
	
		
	if (hp == 'ol') {
		hp = 'Office Line' ;
	} else if (hp == 'cl') {
		hp = 'Classic Line' ;
	} else {
		hp = series[input['Series']] ;
	}
	
	if (error == 6) {
		document.getElementById('e6').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	} else if (error == 5) {
		document.getElementById('e5').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	} else if (error == 4) {
		document.getElementById('e4').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	} else if (error == 3) {
		document.getElementById('e3').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	} else if (error == 2) {
		document.getElementById('e2').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	} else if (error == 1) {
		document.getElementById('e1').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	} else {
	
		if (input['Clients'] == 1) {
			document.getElementById('i_clients').innerHTML = input['Clients'] + ' Arbeitsplatz' ;
		} else {
			document.getElementById('i_clients').innerHTML = input['Clients'] + ' Arbeitspl&auml;tze' ;
		}
		
		document.getElementById('i_months').innerHTML = input['Months'] ;
		document.getElementById('i_modules').innerHTML = modules[input['Series']][input['Modules']] ;
		document.getElementById('r_total').innerHTML = roundit(output['licence'],2) ;
		document.getElementById('r_cliently').innerHTML = roundit(per_client,2) ;
		document.getElementById('e0').style.display = 'block' ;
		document.getElementById('contact').href = '/smb/kontakt/kontaktformular.asp?Thema=Null-Leasing&bestProduct=' + hp + ' - ' + modules[input['Series']][input['Modules']] + ': ' + input['Clients'] + ' Clients, ' + input['Months'] + ' Monate, ' + roundit(output['licence'],2) + ' Eur Lizenzpreis' ;
	}
}
