
/* SIMPLE TUITION widget */

function stusnLTS(prod){
	var id;
	if(prod.value == "parent")id = "p";
	if(prod.value == "undergraduate")id = "u";
	if(prod.value == "graduate")id = "g";
	document.getElementById("p_lts").style.display = "none";
	document.getElementById("u_lts").style.display = "none";
	document.getElementById("g_lts").style.display = "none";
	document.getElementById(id+"_lts").style.display = "";
	stusnClearLTS();
}

var stusnCoOn = false;

function stusnUGPVT(lt){
	if(lt.checked){
		document.getElementById("cos").style.display = "";
		stusnCoOn = true;
	}else{
		document.getElementById("cos").style.display = "none";
		stusnCoOn = false;
	}
}

function stusnClearLTS(){
	var frm = document.stusn_form;
	for(i = 0; i < frm.loanType.length; ++i){
		frm.loanType[i].checked = false;
	}
}

function stusnValidateAmt(amt){

	//if(amt == null)return false;
	//var tmp = amt.replace(/s*/g, "").replace(/$*/g, "").replace(/,/g, "");
	//if(tmp == "" || isNaN(tmp) || tmp <= 0)return false;
	return true;
}

function stusnValidate(){
	try{
		var msg = "";
		var frm = document.stusn_form;
		var ok = true;

		var amt = frm.amt.value;
		if(!stusnValidateAmt(amt)){
			msg += "Please enter a valid amount.";
			ok = false;
		}
		var prod = frm.product.value;
		if(prod == null || prod == ""){
			msg += "Please select a borrower type.";
			ok = false;
		}else{
			var lts = frm.loanType;
			var ltCnt = 0;
			for(i = 0; i < lts.length; ++i){
				if(lts[i].checked)++ltCnt;
			}
			if(ltCnt == 0){
				msg += "Please select at least one loan type.";
				stusnLTS(frm.product);
				ok = false;
			}
			if(prod == "undergraduate" && stusnCoOn){
				var cos = false;
				for(i = 0; i < 2; ++i){
					if(frm.cosigner[i].checked)cos = true;
				}
				if(!cos){
					msg += "Please indicate whether you have a co-signer. ";
					ok = false;
				}
			}
		}
		if(!frm.tac.checked){
			msg += "U.S. News & World Report and SimpleTuition have partnered to offer user-friendly student loan comparisons to U. S. News readers.  We wish to inform all U. S. News readers that any information submitted on the co-branded site will be subject to the privacy policy of SimpleTution, a third-party web site. ";
			ok = false;
		}

		if(!ok)alert(msg);
		return ok;
	}catch(er){
		alert("WTF:"+er);
		return true;
	}
}

