// JavaScript Document

function checkReferrals(slideNumber) {
	var minRequired = 5;
	var countOK = 0;
	
	document.getElementById('referralError1').style.display = "none";
	document.getElementById('referralError2').style.display = "none";
	
	if (document.getElementById('friendValid1').value == 'true') { countOK++; }
	if (document.getElementById('friendValid2').value == 'true') { countOK++; }
	if (document.getElementById('friendValid3').value == 'true') { countOK++; }
	if (document.getElementById('friendValid4').value == 'true') { countOK++; }
	if (document.getElementById('friendValid5').value == 'true') { countOK++; }

	
	if (countOK != minRequired) {
		//Can't continue, not enough referrals
		triggerStat('5', 'Required Valid Referrals', '<5');
		dojo.fx.wipeIn({
			node: referralError1,
			duration: 300
		}).play();

	} else {
		triggerStat('5', 'Required Valid Referrals', '>=5');
		
		var countbad = 0;
		if (checkOptionalReferal('6') == false) { countbad++; }
		if (checkOptionalReferal('7') == false) { countbad++; }
		if (checkOptionalReferal('8') == false) { countbad++; }
		if (checkOptionalReferal('9') == false) { countbad++; }
		if (checkOptionalReferal('10') == false) { countbad++; }
		
		if (countbad>0) {
			//Cant continue one of the optional one's isn't valid
			triggerStat('5', 'Optional Valid Referrals', 'Invalid');
			dojo.fx.wipeIn({
				node: referralError2,
				duration: 300
			}).play();
		} else {
			triggerStat('5', 'Optional Valid Referrals', 'Valid');
			saveReferrals();
			triggerStat('5', 'Referrals', 'Saved');
			moveNextSlide(slideNumber);
		}
	}
}

function checkOptionalReferal(num) {
	if (document.getElementById('friendName' + num).value.length > 0 || document.getElementById('friendEmail' + num).value.length > 0) {
			if (document.getElementById('friendValid'+ num).value != 'true') {
				return false;
			} else {
				return true;
			}
	} else {
		return true;
	}
}