// formcheck2.js


var defaultEmptyOK = false;
var whitespace = " \t\n\r";

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;

    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isInteger (s)
{   var i;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }
    return true;
}

function isSignedInteger (s)
{   var startPos = 0;
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length)))
}

function isPositiveInteger (s)
{  return (isSignedInteger(s) && (parseInt (s) > 0) );
}

function notchecked2 (s) {
    if (s[0].checked || s[1].checked)
		return false;
    else
		return true;
}
function notchecked3 (s) {
    if (s[0].checked || s[1].checked || s[2].checked)
		return false;
    else
		return true;
}
function notchecked4 (s) {
    if (s[0].checked || s[1].checked || s[2].checked || s[3].checked)
		return false;
    else
		return true;
}
function notchecked6 (s) {
    if (s[0].checked || s[1].checked || s[2].checked || s[3].checked || s[4].checked || s[5].checked)
		return false;
    else
		return true;
}

function validFitPlan (handle) {
    var msg = "";
    var emptyRadios = "";
           	
    if (isWhitespace(handle.age.value)) {
    	msg += "\nA value must be entered in the following field(s):\n";
		msg += "\n\t" + "Age:";
    } else if (!isPositiveInteger(handle.age.value))  {  
    	msg += "\n\"" + handle.age.value + "\"" ;
    	msg += "is not a valid entry for " + "\"Age:\"\n";
    }
    
    if (notchecked4(handle.coverage)) {
        emptyRadios += "\n\tType of Coverage";
    }
    if (notchecked3(handle.online_tools)) {
        emptyRadios += "\n\tI (would) use online tools ...";
    }
    if (notchecked3(handle.pay_more)) {
        emptyRadios += "\n\tI don\'t mind paying more ...";
    }
    if (notchecked3(handle.preventative)) {
        emptyRadios += "\n\tI take advantage of routine ...";
    }
    if (notchecked3(handle.wellness)) {
        emptyRadios += "\n\tI am interested in wellness ...";
    }
    if (notchecked3(handle.better_cov)) {
        emptyRadios += "\n\tI am willing to pay more of the premium ...";
    }
    if (notchecked3(handle.involvement)) {
        emptyRadios += "\n\tI take an active role in managing ...";
    }
    if (notchecked3(handle.new_approach)) {
        emptyRadios += "\n\tI am interested in trying new approaches ...";
    }
    if (notchecked3(handle.referrals)) {
        emptyRadios += "\n\tI don\'t mind getting referrals ...";
    }
    if (notchecked3(handle.low_cost)) {
        emptyRadios += "\n\tI choose the health coverage with the lowest cost ...";
    }
    if (notchecked3(handle.large_ntwk)) {
        emptyRadios += "\n\tI am willing to pay more for a larger choice ...";
    }
    if (notchecked6(handle.curr_cov)) {
        emptyRadios += "\n\tWhat type of health insurance ...";
    }
    if (notchecked3(handle.usage)) {
        emptyRadios += "\n\tDo you believe your usage ...";
    }
    
    if (msg == "" && emptyRadios == "") {
    	return true;
    } else {
		if (emptyRadios != "" ) {
		    msg += "\n\nA selection must be checked in the following field(s):\n";
	    	msg += emptyRadios + "\n";
		}	
    	alert(msg);
    	return false;
    }
}

function validPortfolio (handle) {
	var msg = "";
    var emptyRadios = "";
     
    if (notchecked4(handle.plan)) {
        msg += "\nPlease select at least one plan from \"PPO, POS, HMO, or CDHP\"";
    }
    if (notchecked2(handle.cust)) {
        emptyRadios += "\n\tAre you Currently a Customer?";
    }
    if (notchecked3(handle.sav)) {
        emptyRadios += "\n\tHow much are you looking to save ...";
    }
    if (notchecked3(handle.prod)) {
        emptyRadios += "\n\tWhat products are you currently looking for?";
    }
    
    if (msg == "" && emptyRadios == "") {
    	return true;
    } else {
		if (emptyRadios != "" ) {
		    msg += "\n\nA selection must be checked in the following field(s):\n";
	    	msg += emptyRadios + "\n";
		}	
    	alert(msg);
    	return false;
    }
}

