var gvstrScore20 = "It's time to get started, you have a lot to experience yet."
var gvstrScore40 = "You are on your way, but need to focus on planning these experiences into your year."
var gvstrScore60 = "You are becoming much more focused on creating a wonderful life for yourself."
var gvstrScore80 = "You are becoming a Master at enjoying your life, maybe you can make a contribution to the list?"
var gvstrScore100 = "Congratulations, you have mastered life so far, but now it's time to expand the list and start the next one hundred?"

function calculateNumOfThings(){
	//alert("box clicked")
	var x, lvintTotal, lvstrThings, lvstrResult
	lvintTotal = 0	
	for (x=1;x<101;x++){			
		if (eval("document.main.activity" + x + ".checked")){
			lvintTotal++
		}
	}
	if(lvintTotal==1){
		lvstrThings = " thing"			
	}
	else{
		lvstrThings = " things"
	}
	//alert(lvintTotal+" boxes checked")
	if(lvintTotal<=20){
		lvstrResult = gvstrScore20
	}
	else if(lvintTotal<=40){
		lvstrResult = gvstrScore40
	}
	else if(lvintTotal<=60){
		lvstrResult = gvstrScore60
	}
	else if(lvintTotal<=80){
		lvstrResult = gvstrScore80
	}
	else{
		lvstrResult = gvstrScore100
	}
	document.getElementById("numOfThings").innerHTML = lvintTotal.toString() + lvstrThings + "<br>" + lvstrResult
}

function validateThingToDo(){
	with (document.thingtodo){
		var problem = 0
		var message = ""
		if (name.value==""){
			problem++
			message+="\nYour name is required."
		}				
		if (!verifyEmail(email.value)){
			problem++
			message+="\nA valid email address is required."
		}		
		if (problem > 0){
			alert(message);
			return false;
		}
		else{
			return true;
		}
	}
}

function validateContact(){
	with (document.thingtodo){
		var problem = 0
		var message = ""
		if (name.value==""){
			problem++
			message+="\nYour name is required."
		}				
		if (!verifyEmail(email.value)){
			problem++
			message+="\nA valid email address is required."
		}		
		if (problem > 0){
			alert(message);
			return false;
		}
		else{
			return true;
		}
	}
}

function verifyEmail(addr) { 
    var atPos = addr.indexOf('@'); 
    var dotPos = addr.lastIndexOf('.') 
    if (atPos>0 && dotPos>atPos+1) return true; 
    else
    	return false;
} 

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
