
	function checkAmount(field, minAmount,pageId)
	{
		var chdig = 0;
		var dec = 0;
		var leadzero = 0;
		var newfield = "";
  		var errorText = "";
  	
		// Check to see if a value was passed	
  		if (field.length == 0)
		{
			if (pageId == "cost")
			{
				errorText = "I would like to borrow is a required field \n";
			}
			else
			{
				errorText = "Amount that I can afford to pay per month is a required field \n";
			}
			return errorText;
		}	
  		
		// Check to see if we have valid characters entered in the field	
    	// Loop over all the characters in the field
    	for( var i = 0 ; i < field.length ; i++ ) 
		{
			var chr = field.charAt(i);
			// Checks each character in the field to see if it's a decimal
			// point or not, increments 'dec' if it is.
			if ( chr == "." ) 
			{
				dec++;
			}
			// If the character is greater than 9 (i.e. non numeric) and
			// is not a decimal point, then set 'chdig' to 1
			if ( ((chr > "9")  || (chr < "0")) &&  ((chr != ".") && (chr != ",")) ) 
			{
				chdig = 1;
			}
			
			if (leadzero == 0)
			{
				if (chr != 0)
				{
					newfield = newfield + field.charAt(i);
					leadzero = 1;
				}
			}
			else
			{
				newfield = newfield + field.charAt(i);
			}
		}
		
		// Store the validated value back in our original variable
		field = newfield;
		
		// If there was a non numeric character or more than 1 decimal
		// point, alert the user to invalid input
		if (chdig == 1 || dec > 1) 
		{
			if (pageId == "cost")
			{
				errorText = "I would like to borrow must be a number \n";
			}
			else
			{
				errorText = "Amount that I can afford to pay per month must be a number \n";
			}		

			return errorText;
		}
		else 
		{
			// Check for amounts below the minimum allowed value and spurious data
			var oldstring = field;
			var newstring = "";
		
			// Remove all unecessary formatting from the field (retain just numerics and decimal point)
			for (j = 0 ; j <= oldstring.length ; j++) 
			{
				if (oldstring.charAt(j) != ",") 
				{
					newstring = newstring + oldstring.charAt(j);
				}
			}
			
			var errorFound = false;
			
			// Field is now empty (only a comma was entered)
			if (newstring == "") 
			{
				errorFound = true;
			}
				
			// Field is now a decimal point (no numerics were entered)	
			if (newstring == ".") 
			{
				errorFound = true;
			}
			
			// Field is below the minimum allowed value
			if (parseInt(newstring) < minAmount) 
			{
				errorFound = true;	
			}
			
			if (errorFound)
			{
				if (pageId == "cost")
				{
					errorText = "I would like to borrow has a mimimum value of GBP " + minAmount + "\n";
				}
				else
				{
					errorText = "How much could I borrow based on how much I can afford has a mimimum value of GBP " + minAmount + "\n";
				}	
				return errorText;
			}
			
		}	
		// No errors return an empty string
		return errorText;
	}
	
	function checkRepaymentTerm(field)
	{	
	    var chdig = 0;
		var errorText = "";
	
		// Check for an empty field, return an error if it is
		if (field.length == 0)
		{
			errorText = "Repayment term in years is a required field \n";
			return errorText;
		}
		
		// Check we have only digits entered
	    for(var i = 0 ; i < field.length ; i++ ) 
		{
			var chr = field.charAt(i);
			
			if ((chr > "9")  || (chr < "0")) 
			{
				chdig = 1;
			}
		}
	
		// Check Characters other than digits entered, return an error if there are
		if (chdig == 1) 
		{
			errorText = "Repayment term in years must be a number \n";
			return errorText;
		}
	
		// Check for a value greater than the maximum term, return an error if it is
		if (field > 35) 
		{
			errorText = "The maximum repayment term is 35 years \n";
			return errorText;
		}
		// Check for a value less than the minimum term, return an error if it is
		else if ((field < 3) && (field.length != 0)) 
		{
			return errorText = "The minimum repayment term is 3 years \n";
		}
		else
		{ 
			// No errors, return an empty string
			return errorText;
		}
	}

	function checkMortgageType(field)
	{
		var errorText = "";
		
		// Check for a value being selected from the drop down
		if (field == "") 
		{
			errorText="How do you want to pay back your mortgage is a required field \n";
			return errorText;
		}
		else
		{
			// no errors, return an empty string
			return errorText;
		}
	}	
	
	function checkMortgageRate(ratesSelected)
	{
		var errorText = "";
	
		// Check for one or more values being selected 
		if (ratesSelected == "")
		{
			errorText = "With a rate that is: at least one value must be selected \n"
			return errorText;
		}
		// no errors, return an empty string
		return errorText;
	}
	
	function checkMortgageSelected(ratesSelected)
	{
		var errorText = "";
	
		// Check for one or more values being selected 
		if (ratesSelected == "")
		{
			errorText = "At least one rate must be selected \n"
			return errorText;
		}
		// no errors, return an empty string
		return errorText;
	}
	

