/* 
 *Validation for the savings tool in the global left nav, and homepage
 */
function validate() {
	
	var phone_a = document.toolform.phone_a.value;
	var phone_b = document.toolform.phone_b.value;
	var phone_c = document.toolform.phone_c.value;

	var isA_ok = phone_a.length == 3 && isInteger(phone_a);
	var isB_ok = phone_b.length == 3 && isInteger(phone_b);
	var isC_ok = phone_c.length == 4 && isInteger(phone_c);
	
	if (isA_ok && isB_ok && isC_ok) {
		return true;
	}
	
	alert("Please enter your full telephone number");
	return false;
}


function isInteger (s) {
	for (i = 0; i < s.length; i++) {   
    	var c = s.charAt(i);
        if (! isDigit(c)) return false;
    }
	return true;
}


function isDigit (c) {   
	return ((c >= "0") && (c <= "9"))
}


function isMoney (s) {
	var dotcount = 0;
	for (i = 0; i < s.length; i++) {   
    	var c = s.charAt(i);
        if (! isDigit(c) && c != '.') return false;
        if (c == '.')  {
        	dotcount++;
        	var cents = s.split(".")[1];
        	if (cents.length > 2) return false;
        }
    }
    
    if (dotcount > 1) return false;
    
	return true;
}


function autoTab(obj, evt, maxlen, next) {
	if (document.all) {
		formlen = obj.value.length;
	} else {
		formlen = evt.target.value.length;
	}

	if (formlen >= maxlen) {
		document.toolform.elements[next].focus();
		//document.toolform.elements[next].select();
	}
}