		
function radioButtonChecker(f, name) {
	var radio_choice = false;
	for (counter = 0; counter < f[name].length; counter++) {
		if (f[name][counter].checked) radio_choice = true;
	}
	if (!radio_choice) {
		return (false);
	}
	return (true);
}

var currentProgress=1;

document.getElementById("progressdone")

function progress1(){
	currentProgress+=3;
	if(currentProgress<150){
		//$("#progressdone").css("padding","0 "+currentProgress+"px");
		document.getElementById("progressdone").style.padding = "0px "+currentProgress+"px";
		setTimeout("progress1();",30);
	}
	else{
		loadAnalysis();
	}
}

function validateQuiz() {
	var f = document.form1;
	var qmax = parseInt(f.QuestionCount.value) + 1;
	var state = f.state.value;
	if (state == 'NA'){
		alert("Please select a state for question 1.");
		return;
	}
	for (i=2; i < qmax; i++) {    
		if(f["question" + i]) {
			if(!radioButtonChecker(f,"question" + i)) {
			    alert("Please select an answer for question "+i+".");
				return;
		    }
		}
	}
	switchid('progressdiv');
	//document.bgColor='#FFFFFF';
	setTimeout("progress1();",30);
	return;
}

function loadAnalysis() {
	switchid('summarydiv');
	//document.bgColor='#DDDDDD';
	document.form1.attr("onsubmit","javascript:return true;");
}

//here you place the ids of every element you want.
var ids=new Array('surveydiv','progressdiv','summarydiv');

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// Deep Email Validation
function emailCheck (emailStr) 
    {
        var emailPat=/^(.+)@(.+)$/
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
        var validChars="\[^\\s" + specialChars + "\]"
        var quotedUser="(\"[^\"]*\")"
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
        var atom=validChars + '+'
        var word="(" + atom + "|" + quotedUser + ")"
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
        var matchArray=emailStr.match(emailPat)
        
        if (matchArray==null)
            {
                alert("The email address you provided is not valid! \n \n Check if you provided '@' & '.' symbol.")
                return false
            }
        var user=matchArray[1]
        var domain=matchArray[2]
        
        if (user.match(userPat)==null) 
            {
                alert("The email address you provided is not valid! \n \n It's username seems invalid.")
                return false
            }
            
        var IPArray=domain.match(ipDomainPat)
        if (IPArray!=null) 
            {
                // this is an IP address
                for (var i=1;i<=4;i++) 
                    {
                        if (IPArray[i]>255) 
                            {
                                alert("Destination IP address is invalid!")
                                return false
                            }
                    }
                return true
            }
            
        var domainArray=domain.match(domainPat)
        
        if (domainArray==null) 
            {
                alert("The email address you provided is not valid! \n \n It's domain name seems invalid.")
                return false
            }
            
        var atomPat=new RegExp(atom,"g")
        var domArr=domain.match(atomPat)
        var len=domArr.length
        if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
            {
                alert("The email address you provided is not valid! \n \n The address must end in a three-letter domain, or two letter country.")
                return false
            }
        if (len<2) 
            {
                var errStr="The email address you provided is not valid! \n \n This address is missing a hostname!"
                alert(errStr)
            return false
            }
        return true;
    }

function checkform(f){
	if(f.txtFirstName.value==""){
		alert("Please enter your first name.");
		f.txtFirstName.focus();
		return (false);
	}
        // Validate Email
    if (f.txtEmail.value==''){
		alert("Please enter your email address.");
		f.txtEmail.focus();
		return (false);
	}
	if (!emailCheck (f.txtEmail.value) ){
		f.txtEmail.focus();
		return (false);
	}
	return (true);
}

//fill body text of email
var states = new Array('ERROR!','Select Your State','Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia','Wisconsin','Wyoming');
function email(){
	var f1 = document.form1;
	var f2 = document.form1;
	var mail = f2.mail_body;
	var text = "";
	if(!checkform(f1)){return;}
//Intro
	text = "Hi "+f2.txtFirstName.value+",\n\nHere's your customized analysis based on the answers you gave to our online quiz.\n\n\n";
//Question 1
	text += "Question 1.) Where do you live?\n\nYou selected "+states[(f1.state.selectedIndex+1)]+"\n\n"+states[(f1.state.selectedIndex+1)]+" has a probate exemption amount of $"+f1.state.value+". This is important to know because a will does not have to go through the probate process if your entire estate is less than the probate exemption amount.\n\n\n";
//Question 2
//	var answer = getCheckedValue(f1.question2);
//	mail.value += "Question 2.) Do you have...?\n\nYour answer: "+answer+"\n\n";
//	if(answer=="A will"){
//		mail.value += "Did you know that a will has to go through a process called probate in order to be effective? However, a will does not have to go through the probate process if your entire estate is less than the probate exemption amount.\n\n\n";
//	}
//	else if(answer=="A living trust"){
//		mail.value += "A properly funded living trust avoids probate altogether. Having a properly funded living trust means that all of your assets have been transferred to and re-titled in the name of your trust. Make sure your trust is properly funded.\n\n\n";
//	}
//	else{
//		mail.value += "If you have not done any estate planning, then upon your death your estate is entirely dependent upon the courts.  The courts will decide what to do with your estate according to the will written by the state legislature.";
//	}
//Question 3
//	var answer = getCheckedValue(f1.question3);
//	mail.value += "Question 3.) Do you...\n\nYour answer: "+answer+"\n\n";
//	if(answer=="Own a home / condo / apartment"){
//		mail.value += "If you own any real estate, the title must be transferred to your heirs upon your death.  This is done through the probate process.  If you wish to avoid probate, you should have a living trust.\n\n\n";
//	}
//	else if(answer=="Rent a home / condo / apartment"){
//		mail.value += "If you rent, your rental property is not considered a part of your estate. Unless all the other assets in your estate add up to more than the probate exemption amount, no probate will be required.\n\n\n";
//	}
//	else{
//		mail.value += "Unless all the other assets in your estate add up to more than the probate exemption amount, no probate will be required.\n\n\n";
//	}
//Question 4
//	var answer = getCheckedValue(f1.question4);
//	mail.value += "Question 4.) Who do you want to leave your estate to?\n\nYour answer: "+answer+"\n\n";
//	if(answer=="I don’t care"){
//		mail.value += "If you don’t care who you want your estate left to then it doesn’t really matter what type of estate planning you do or don’t do.\n\n";
//	}
//	mail.value += "If you want to specify who you want your estate left to or even if you want to choose when they will receive it, you will want to prepare a revocable living trust.\n\n";
//	mail.value += "To show you how specific you can be with your living trust, here is an example: You can leave a specific percentage (let’s say 33%) to your son or daughter that will be distributed to him or her only when they have completed college or until they turn 25. Then when they reach 35, another 33% is distributed. And the final 34% is distributed when they reach age 45.\n\n\n";
//Question 5
//	var answer = getCheckedValue(f1.question5);
//	mail.value += "Question 5.) How long would you like your estate tied up in probate court?\n\nYour answer: "+answer+"\n\n";
//	if(answer=="I don’t want it to be tied up at all"){
//		mail.value += "If the value of your estate is more than the probate exemption amount, you will need a living trust to prevent your estate from being tied up in probate.\n\n";
//	}
//	mail.value += "Four to eight months is the shortest period of time that your estate will be tied up in probate court for a simple uncontested probate. One to two years, is the average time for probate. Three to five years is how long it would take if there were some trouble with your probate case. For example, it would take longer to solve will disputes, contested creditor claims or liquidating assets.\n\n";
//	mail.value += "When Howard Hughes died, it was estimated that his estate was worth between two and five billion dollars. He owned real estate in Texas, Nevada and California. Twenty-nine wills were produced to the court and none of them was found to be valid. There were also many people claiming that they were heirs to part of his estate. All of these complications, made his three probates – one for each state – last more than 11 years. This shows you how important good estate planning can be.\n\n\n";
//Question 6
//	var answer = getCheckedValue(f1.question6);
//	mail.value += "Question 6.) If something were to happen to you, who would you like to take care of your minor children?\n\nYour answer: "+answer+"\n\n";
//	mail.value += "If you have any minor children, it is very important that you have a living trust.  If you do not have a living trust, the court appointed guardian of your child will have to appear in court at least once a year until your child is 18 to disclose any and all financial activities. They will also have to provide an accounting report to the court.\n\n\n";
//Question 7
//	var answer = getCheckedValue(f1.question7);
//	mail.value += "Question 7.) \n\nYour answer: "+answer+"\n\n";
//	mail.value += "If you do own real estate in multiple states, upon your death a probate will be required in each of those states. The best way to avoid multiple probates, or any probate at all, is to have a revocable living trust.\n\n\n";
//Question 8
//	var answer = getCheckedValue(f1.question8);
//	mail.value += "Question 8.) \n\nYour answer: "+answer+"\n\n";
//	mail.value += "Believe it or not, business planning is a critical part of estate planning – and estate planning is an essential component of business planning! If you own a business such as a limited liability company, subchapter-S corporation or C-corporation, you must remain on guard.  Each business entity must be properly included in your overall estate plan. Link your business entities with your living trust for maximum protection. Your living trust is the foundation of your estate plan, and everything else will be a building block on your trust.\n\n\n";
//	alert("4");
	mail.value = text;
	document.form1.submit();
	return true;
}

