		
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;
	for (i=1; 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
function email(){
	var f1 = document.form1;
	var mail = f1.mail_body;
	var text = "";
	if(!checkform(f1)){return;}
	text = "Hi "+f1.txtFirstName.value+",<br /><br />Here is your customized analysis based on the answers you gave to our online quiz.";
	mail.value = text;
	document.form1.submit();
	return true;
}
