/**
 * DUE FOR REDESIGN
 * Convert to JSP
 */
// mirror the markup order
var groups = new Array('age','employment','future','retire','dependents','gross','networth','equityassets','knowledge','needmoney','mainobjective','withdrawperiod','next5years','view','eroding','declinesagree','botheragree','likelypurchase','hypothetical','react');
var exceptions = new Array();
// group name, selection index, question, answer
exceptions[0] = new Array('future',3,'3) How certain are you that your various income sources will continue into the future?','Extremely uncertain');
exceptions[1] = new Array('needmoney',0,'10) Over what period of time are you investing in this plan?','Less than 5 years');
exceptions[2] = new Array('mainobjective',0,'11) What is your main objective for this investment?','Large purchase within five years');
exceptions[3] = new Array('mainobjective',1,'11) What is your main objective for this investment?','Vacation or new car purchase within 5 years');
exceptions[4] = new Array('mainobjective',2,'11) What is your main objective for this investment?','Down payment for a home purchase within five years');
exceptions[5] = new Array('next5years',3,'13) What percentage of this money might you spend in the next 5 years?','Over 70%');

function initProfile(){

	var answers = null;
	var a1 = lib.getUrlNamedValue('a');
	var a2 = lib.readCookie('efganswers');
	a1 ? answers = a1 : a2 ? answers = a2 : null;
	if(answers)
	{
		var userExceptions = new Array();
		for(i=0;i<answers.length;i++){

			for(j=0;j < exceptions.length;j++)
			{
				if(exceptions[j][0] == groups[i] &&
					exceptions[j][1] == parseInt(answers.charAt(i)))
				{
					userExceptions[userExceptions.length] = j;
				}
			}

		}

		if(userExceptions.length > 0)
		{
			var plural = '';
			if(userExceptions.length > 1) plural = 's';

			var exceptHTML = '<p>Your Risk Tolerance has been calculated to be zero because of your answer'+plural+' to the following question'+plural+':<\/p>';
			exceptHTML += '<dl>';
			for(i=0;i<userExceptions.length;i++)
			{
				exceptHTML += '<dt>' + exceptions[userExceptions[i]][2] + '<\/dt>'
				exceptHTML += '<dd>' + exceptions[userExceptions[i]][3] + '<\/dd>'
			}
			exceptHTML += '<\/dl>';

			document.getElementById('EXCEPTIONS').innerHTML = exceptHTML;
			document.getElementById('EXCEPTIONS').style.display = 'block';
		}
	}

	var tolerance = null;
	var t1 = lib.getUrlNamedValue('t');
	var t2 = lib.readCookie('efgtolerance');
	t1 ? tolerance = t1 : t2 ? tolerance = t2 : null;
	if(tolerance)
	{
		var profile = 0;
		if(tolerance<=0){
			profile=0;
		}
		else if(tolerance<=130){
			profile=1;
		}
		else if(tolerance<=160){
			profile=2;
		}
		else if(tolerance<=190){
			profile=3;
		}
		else if(tolerance<=230){
			profile=4;
		}
		else if(tolerance<=260){
			profile=5;
		}
		else if(tolerance>260){
			profile=6;
		}

		document.getElementById('YOURSCORE').innerHTML=tolerance;
		document.getElementById('PROFILERANGES').style.display='block';
		document.getElementById('ROW'+profile).className='yourProfile';

		showProfile(profile);

		document.getElementById('NOTESCONTROL').innerHTML = '<p><a class="button" id="PERSONALCONTROL" href="javascript:showHideInfo();">Add contact information<\/a><\/p>';

	}
	else{
		document.getElementById('TESTPROMPT').style.display='block';
	}
}

function showProfile(profile){
	for(i=0;i<7;i++){// hide profiles and select current
		document.getElementById('PROFILE'+i).style.display='none';
	}
	document.getElementById('PROFILE'+profile).style.display='block';
	
	for(i=0;i<7;i++){// clear the currently selected cell
		document.getElementById('LINK'+i).className='jsLink';
	}
	profileLink=document.getElementById('LINK'+profile);

	if(profileLink.parentNode.className!='yourProfile'){
		profileLink.className='currentProfile';
	}
}

function showHideInfo()
{
	theButn = document.getElementById('PERSONALCONTROL');
	theFields = document.getElementById('PERSONALINFO');
	if(theButn.innerHTML.indexOf('Add') > -1)
	{
		theButn.innerHTML='Hide contact information';
		theFields.style.display='block';
	}
	else
	{
		theButn.innerHTML='Add contact information';
		theFields.style.display='none';
	}
	theButn.blur();
}

function updateNotes()
{
	document.getElementById('PERSONALNAME').innerHTML = document.getElementById('PERSONALNAMEINPUT').value;
	document.getElementById('PERSONALADDRESS1').innerHTML = document.getElementById('PERSONALADDRESS1INPUT').value;
	document.getElementById('PERSONALADDRESS2').innerHTML = document.getElementById('PERSONALADDRESS2INPUT').value;
	document.getElementById('PERSONALPHONE').innerHTML = document.getElementById('PERSONALPHONEINPUT').value;
	document.getElementById('PERSONALINFOFORM').style.display='none';
	document.getElementById('PERSONALINFODISPLAY').style.display='block';
}

function editNotes()
{
	document.getElementById('PERSONALINFOFORM').style.display='block';
	document.getElementById('PERSONALINFODISPLAY').style.display='none';
}



