
	function setColor(el, bg)
		{
			if (el.style) el.style.backgroundColor = bg;
		}

	function Submitone()
{		
		var bgBad = "red";
  		var bgGood = "white";
		var valid = true;

			if (document.mailform1a.mval.value == "")
		{
			valid = false;
			setColor(document.mailform1a.mval, bgBad);
		}
			else {setColor(document.mailform1a.mval, bgGood);
		}
			if (!valid) {alert("Please enter the full mortgage amount required");
  			return false;		
		}		
			if (document.mailform1a.pval.value == "")
		{
			valid = false;
			setColor(document.mailform1a.pval, bgBad);
		}
			else {setColor(document.mailform1a.pval, bgGood);
		}
			if (!valid) {alert("Please enter the approximate value of property");
  			return false;		
		}		
			 if (document.mailform1a.purpose.value == "- - -")
		{
			valid = false;
			setColor(document.mailform1a.purpose, bgBad);
		}
			else {setColor(document.mailform1a.purpose, bgGood);
		}
			if (!valid) {alert("Please select purpose of remortgage");
  			return false;		
		}
			if (document.mailform1a.moval.value == "")
		{
			valid = false;
			setColor(document.mailform1a.moval, bgBad);
		}
			else {setColor(document.mailform1a.moval, bgGood);
		}
			if (!valid) {alert("Please enter approximate value of outstanding mortgage");
  			return false;		
		}		

}

// Validates a currency value field
// adding commas to clarify the value
// and ensuring only numbers, with a
// maximum of 2 decimal places are
// added.
function ValidateValue(objTextBox)
{
    var strText = objTextBox.value;

    var blnDecimalFound = false;
    var blnIsValid = true;
    var intDecimalCount = 0;
    
    var strCharCode = 0;
    var strNewNum = '';
    
    var strCommaNum = '';
    var intCurrentPos = 0;
    
    // remove all non numeric characters, with
    // the exception of a single decimal point
    // and a maximum of 2 decimal places.
    for (var i=0; i < strText.length; i++)
    {
        intCharCode = strText.charCodeAt(i);

        if ((48 <= intCharCode) && (intCharCode <= 57))
        {
            if (blnDecimalFound == true)
            {
                if (intDecimalCount > 1)
                {
                    alert('only 2 decimal places are permitted.');
                    break;
                }
                else
                {
                    strNewNum = strNewNum.concat(strText.charAt(i));
                    intDecimalCount++;
                }
            }
            else
            {
                strNewNum = strNewNum.concat(strText.charAt(i));
            }
        }
        else if ((intCharCode == 46) && (blnDecimalFound == false))
        {
            strNewNum = strNewNum.concat(strText.charAt(i));
            blnDecimalFound = true;
        }
    }

    //Go through and add the commas
    intCurrentPos = strNewNum.indexOf('.');
    if (intCurrentPos == -1)
    {
        intCurrentPos = strNewNum.length;
    }
    else
    {
        strCommaNum = strNewNum.substring(strNewNum.indexOf('.'));
    }
    for (var i = intCurrentPos; i > 0; i = i - 3)
    {
        if (i > 3)
        {
            strCommaNum = ',' + strNewNum.substring(i-3,i) + strCommaNum;
        }
        else
        {
            strCommaNum = strNewNum.substring(0,i) + strCommaNum;
        }
    }
    //then copy the new value into the textbox
    objTextBox.value = strCommaNum;
}
