<!--
//Copyright © 2002 - 2010 PracticeWEB Ltd
/* Checks that the value entered is within set criteria (digits), also that if nothing is entered (and is within criteria) move on, else bounce to error msg*/ 

function masterChecker(number){

	var digits="0123456789.£";
 	
	if (number=="£") {return false;}
	if (number.length==0) {return false;}
 	
	for (var i=0; i<number.length; i++){
		if (digits.indexOf(number.substring(i,i+1))==-1 && number.substring(i,i+1)!="."){return false;}
	}
		if (number<0) {return false;}
		return true;
}

/**********************/

/* Checks if there is a decimalPos, makes sure only 2 characters, if there is not a decimal returns (zerostring) which is .00. the result of this is passed into function masterChecker*/
                    
function formatCurrency(number){

	var number = Math.round(number*100)/100;
	var string = number.toString();
	var zerostring = "";
	var decimalPos = string.indexOf(".");

		if (decimalPos != -1) {
		if (string.charAt(decimalPos+2) == "") {
			zerostring = "0";
		}
		} 
		else {
			zerostring = ".00";
		}
		
		return("£" + number + zerostring);
		
		}

/*********************/          

function calculateStartUp(){

/* loads the values from form into variables */

	var form=document.StartUpCalc;
	
	var a=form.advertising.value;
	var b=form.business_plan.value;
	var c=form.communications.value;
	var d=form.cost_of_financing.value;
	var e=form.fixtures.value;
	var f=form.insurance.value;
	var g=form.office_supplies.value;
	var h=form.redecoration.value;
	var i=form.prof_fees.value;
	var j=form.prod_devel.value;
	var k=form.randd.value;
	var l=form.transport.value; 
	var m=form.website.value;
	var n=form.other_costs.value;
	var o=form.unexpected.value;
	var p=form.less.value;

//initialise those variables for calculation

var x=0;
                                  	
// takes information added into form fields and passes function(masterChecker) criteria in 

var errorMessage="";

	if (!masterChecker(a)) {errorMessage+="Advertising, marketing and promotion";}
	if (!masterChecker(b)) {errorMessage+="Business plan";}
	if (!masterChecker(c)) {errorMessage+="Communications infrastructure";}
	if (!masterChecker(d)) {errorMessage+="Cost of financing";}
	if (!masterChecker(e)) {errorMessage+="Fixtures and equipment";}
	if (!masterChecker(f)) {errorMessage+="Insurance";}
	if (!masterChecker(g)) {errorMessage+="Office supplies";}
	if (!masterChecker(h)) {errorMessage+="Premises redecoration and remodelling";}		
	if (!masterChecker(i)) {errorMessage+="Professional fees";}
	if (!masterChecker(j)) {errorMessage+="Product development and initial stock";}
	if (!masterChecker(k)) {errorMessage+="Research and development";}
	if (!masterChecker(l)) {errorMessage+="Transport";}
	if (!masterChecker(m)) {errorMessage+="Website development";}		
	if (!masterChecker(n)) {errorMessage+="Other costs not covered above";}
	if (!masterChecker(o)) {errorMessage+="Unexpected costs";}
	if (!masterChecker(p)) {errorMessage+="Less: Available capital";}	
	
	if (errorMessage.length!=0) {alert("You have added incorrect data in to:\n"+errorMessage+"\nPlease try again.");return false;}

// Checks to see if user has inputted a £ sign in which case it will start counting at position 1

	if (a.substring(0,1)=="£") {a=a.substring(1);}
	if (b.substring(0,1)=="£") {b=b.substring(1);}
	if (c.substring(0,1)=="£") {c=c.substring(1);}
	if (d.substring(0,1)=="£") {d=d.substring(1);}
	if (e.substring(0,1)=="£") {e=e.substring(1);}
	if (f.substring(0,1)=="£") {f=f.substring(1);}
	if (g.substring(0,1)=="£") {g=g.substring(1);}
	if (h.substring(0,1)=="£") {h=h.substring(1);}
	if (i.substring(0,1)=="£") {i=i.substring(1);}
	if (j.substring(0,1)=="£") {j=j.substring(1);}
	if (k.substring(0,1)=="£") {k=k.substring(1);}
	if (l.substring(0,1)=="£") {l=l.substring(1);}
	if (m.substring(0,1)=="£") {m=m.substring(1);}
	if (n.substring(0,1)=="£") {n=n.substring(1);}
	if (o.substring(0,1)=="£") {o=o.substring(1);}

// Returns string to an Integer

	a = parseInt(a * 100) / 100;
	b = parseInt(b * 100) / 100;
	c = parseInt(c * 100) / 100;
	d = parseInt(d * 100) / 100;
	e = parseInt(e * 100) / 100;
	f = parseInt(f * 100) / 100;
	g = parseInt(g * 100) / 100;
	h = parseInt(h * 100) / 100;
	i = parseInt(i * 100) / 100;
	j = parseInt(j * 100) / 100;
	k = parseInt(k * 100) / 100;
	l = parseInt(l * 100) / 100;
	m = parseInt(m * 100) / 100;
	n = parseInt(n * 100) / 100;
	o = parseInt(o * 100) / 100;
	p = parseInt(p * 100) / 100;
	
// do the calculations

x = (a+b+c+d+e+f+g+h+i+j+k+l+m+n+o-p);                  

//load text boxes with results

form.funding_req.value=formatCurrency(x);
            	
return false;
}
//-->

