// JavaScript Document
function stripAlphaChars(pstrSource) 
{ 
	var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, ''); 

    return m_strOut; 
}


function doCalc() {
	
	// Strip any non alphas
	document.getElementById("storagereq").value = stripAlphaChars(document.getElementById("storagereq").value);
	document.getElementById("nummailboxes").value = stripAlphaChars(document.getElementById("nummailboxes").value);	
	document.getElementById("numusers").value = stripAlphaChars(document.getElementById("numusers").value);		
	if (document.getElementById("storagereq").value.length < 1) document.getElementById("storagereq").value = "0";	
	if (document.getElementById("nummailboxes").value.length < 1) document.getElementById("nummailboxes").value = "0";	
	if (document.getElementById("numusers").value.length < 1) document.getElementById("numusers").value = "0";
	

	var sr = Math.round(document.getElementById("storagereq").value);		document.getElementById("storagereq").value = sr;
	var ecnm = Math.round(document.getElementById("nummailboxes").value);	document.getElementById("nummailboxes").value = ecnm;
	var hostednm = Math.round(document.getElementById("numusers").value); document.getElementById("numusers").value = hostednm;

	if (sr > 0) {
	    var icost = 0;
	    var irrp = 0;

	    if ((sr >= 0) && (sr <= 5)) { icost = 5; irrp = 10; }
	    if ((sr >= 6) && (sr <= 10)) { icost = 10; irrp = 20; }
	    if ((sr >= 11) && (sr <= 15)) { icost = 15; irrp = 25; }
	    if ((sr >= 16) && (sr <= 20)) { icost = 20; irrp = 30; }		
	    if ((sr >= 21) && (sr <= 25)) { icost = 25; irrp = 38; }		
	    if ((sr >= 26) && (sr <= 30)) { icost = 30; irrp = 45; }
	    if ((sr >= 31) && (sr <= 40)) { icost = 36; irrp = 54; }
	    if ((sr >= 41) && (sr <= 50)) { icost = 40; irrp = 60; }
	    if ((sr >= 51) && (sr <= 60)) { icost = 48; irrp = 72; }
	    if ((sr >= 61) && (sr <= 70)) { icost = 56; irrp = 84; }
	    if ((sr >= 71) && (sr <= 80)) { icost = 60; irrp = 90; }
	    if ((sr >= 81) && (sr <= 90)) { icost = 66; irrp = 101; }
	    if ((sr >= 91) && (sr <= 100)) { icost = 71; irrp = 105; }
	    if ((sr >= 101) && (sr <= 110)) { icost = 76; irrp = 114; }
	    if ((sr >= 111) && (sr <= 120)) { icost = 82; irrp = 123; }
	    if ((sr >= 121) && (sr <= 130)) { icost = 87; irrp = 131; }
	    if ((sr >= 131) && (sr <= 140)) { icost = 92; irrp = 139; }
	    if ((sr >= 141) && (sr <= 150)) { icost = 98; irrp = 147; }
	    if ((sr >= 151) && (sr <= 160)) { icost = 101; irrp = 155; }
	    if ((sr >= 161) && (sr <= 170)) { icost = 105; irrp = 162; }
	    if ((sr >= 171) && (sr <= 180)) { icost = 110; irrp = 169; }
	    if ((sr >= 181) && (sr <= 190)) { icost = 114; irrp = 176; }
	    if ((sr >= 191) && (sr <= 200)) { icost = 118; irrp = 169; }
	    if ((sr >= 201) && (sr <= 210)) { icost = 122; irrp = 168; }
	    if ((sr >= 211) && (sr <= 220)) { icost = 128; irrp = 173; }
	    if ((sr >= 221) && (sr <= 230)) { icost = 133; irrp = 178; }
	    if ((sr >= 231) && (sr <= 240)) { icost = 139; irrp = 183; }
	    if (sr >= 241) {
	        icost = Math.round(0.55 * sr);
	        irrp = Math.round(0.75 * sr);
	    }
	    document.getElementById("costtoyou1").value = Math.round(icost);
	    document.getElementById("revenue1").value = Math.round(irrp);
	}
	else {
	    document.getElementById("costtoyou1").value = 0;
	    document.getElementById("revenue1").value = 0;
	}

	if (ecnm > 0) {
	    var icost = 0;
	    var irrp = 0;
	    if ((ecnm >= 0) && (ecnm <= 5)) { icost = 10; irrp = 20; }
	    if ((ecnm >= 6) && (ecnm <= 10)) { icost = 20; irrp = 40; }
	    if ((ecnm >= 11) && (ecnm <= 15)) { icost = 30; irrp = 45; }
	    if ((ecnm >= 16) && (ecnm <= 20)) { icost = 40; irrp = 50; }
	    if ((ecnm >= 21) && (ecnm <= 25)) { icost = 38; irrp = 55; }
	    if ((ecnm >= 26) && (ecnm <= 30)) { icost = 45; irrp = 60; }
	    if ((ecnm >= 31) && (ecnm <= 35)) { icost = 47.5; irrp = 65; }
	    if ((ecnm >= 36) && (ecnm <= 40)) { icost = 50; irrp = 70; }
	    if ((ecnm >= 41) && (ecnm <= 45)) { icost = 55; irrp = 75; }
	    if ((ecnm >= 46) && (ecnm <= 50)) { icost = 60; irrp = 80; }
	    if ((ecnm >= 51) && (ecnm <= 55)) { icost = 65; irrp = 85; }
	    if ((ecnm >= 56) && (ecnm <= 60)) { icost = 70; irrp = 90; }
	    if ((ecnm >= 61) && (ecnm <= 70)) { icost = 73; irrp = 100; }
	    if ((ecnm >= 71) && (ecnm <= 80)) { icost = 76; irrp = 110; }
	    if ((ecnm >= 81) && (ecnm <= 90)) { icost = 80; irrp = 120; }

	    if (ecnm >= 100) {
	        icost = Math.round(0.75 * ecnm);
	        irrp = Math.round(1 * ecnm);
	    }

	    document.getElementById("costtoyou2").value = Math.round(icost);
	    document.getElementById("revenue2").value = Math.round(irrp);
	} else {
	    document.getElementById("costtoyou2").value = 0;
	    document.getElementById("revenue2").value = 0;
	}

	if (hostednm > 0) {
	
		var icost = 35, irrp = 55;
	
		icost = Math.round(icost * hostednm);
		irrp = Math.round(irrp * hostednm);
	    if(document.getElementById("sqlrqd").checked){
			icost=Math.round(icost)+100;
			irrp=Math.round(irrp)+150;
		}else{
			icost=Math.round(icost);
			irrp=Math.round(irrp);
		}
		
		document.getElementById("costtoyou3").value = icost;
	    document.getElementById("revenue3").value = irrp;
	} else {
	    document.getElementById("costtoyou3").value = 0;
	    document.getElementById("revenue3").value = 0;
	}
	
	/*if ((hostednm > 0) && (ecnm > 0) && (hostednm == ecnm)) {
		var icost = 0;
		var irrp = 0;		
		if (hostednm <= 50) {
			icost = (1.25 * hostednm);
			irrp = (icost * 1.2);
		} else if (hostednm <= 200) {
			icost = (1 * hostednm);
			irrp = (icost * 1.2);			
		} else {
			icost = (0.75 * hostednm);
			irrp = (icost * 1.2);

        }
        document.getElementById("costtoyou3").value = Math.round(icost);
		document.getElementById("revenue3").value = Math.round(irrp);		
		document.getElementById("costtoyou2").value = Math.round(icost);
		document.getElementById("revenue2").value = Math.round(irrp);		
		
	}*/
	
	document.getElementById("totalmonthlycosts").value = Math.round(document.getElementById("costtoyou3").value) + Math.round(document.getElementById("costtoyou2").value) + Math.round(document.getElementById("costtoyou1").value);
	document.getElementById("totalmonthlyincome").value = Math.round(document.getElementById("revenue3").value) + Math.round(document.getElementById("revenue2").value) + Math.round(document.getElementById("revenue1").value);	
	document.getElementById("annualgrossprofit").value = 12 * (Math.round(document.getElementById("totalmonthlyincome").value)  - Math.round(document.getElementById("totalmonthlycosts").value)); 
}
