﻿//modify by netkoala 2008-03-09
var currQuestion = 1;
var totalQuestion = 10;
var result;
function prevQuestion() {
	var cq = document.getElementById('q' + currQuestion);
	var pq = document.getElementById('q' + (currQuestion - 1));
	cq.style.display = 'none';
	pq.style.display = 'block';
	currQuestion--;
	//play sound
	//alert(IsOff);
	if(IsOff==0){
		var SoundFileName = "a_"+ (currQuestion) +".swf";
		PlaySound(SoundFileName);}
	//end play sound
	var nb = document.getElementById('nextBtn');
	var pb = document.getElementById('prevBtn');
	var sb = document.getElementById('submitBtn');
	var eb = document.getElementById('img_empty');
	nb.style.display = 'inline';
	sb.style.display = 'none';
	if(currQuestion <= 1) {
		pb.style.display = 'none';
		eb.style.display = 'inline';
	}
	else {
		pb.style.display = 'inline';
		eb.style.display = 'none';
	}
}

function nextQuestion() {
	if(!checkAns()) {
		alert('請勾選一個選項。');
		return false;
	}
	//play sound
	if(IsOff==0){
		var SoundFileName = "a_"+ (currQuestion + 1) +".swf";
		PlaySound(SoundFileName);}
	//end play sound
	
	var cq = document.getElementById('q' + currQuestion);
	var nq = document.getElementById('q' + (currQuestion + 1));
	cq.style.display = 'none';
	nq.style.display = 'block';
	currQuestion++;
	var nb = document.getElementById('nextBtn');
	var pb = document.getElementById('prevBtn');
	var sb = document.getElementById('submitBtn');
	var eb = document.getElementById('img_empty');
	pb.style.display = 'inline';
	eb.style.display = 'none';
	if(currQuestion >= totalQuestion) {
		nb.style.display = 'none';
		sb.style.display = 'inline';
	}
	else {
		nb.style.display = 'inline';
	}
}

function checkAns() {
	// Check answer
	var ansFlag = false;
	var f = document.frmPPT;
	for(var i = 0; i < f.elements['q' + currQuestion].length; i++) {
		if(f.elements['q' + currQuestion][i].checked) {
			ansFlag = true;
			break;
		}
	}
	if(ansFlag == false) {
		return false;
	}
	return true;
}

function processPPTForm(f) {
	if(!checkAns()) {
		alert('請勾選一個選項。');
		return false;
	}
	var qa = "";
	var client = "";
	var scoreMap = new Array();
	scoreMap.push('');
	scoreMap.push(new Array(1, 4, 13, 17, 17));
	scoreMap.push(new Array(0, 1, 2, 3));
	scoreMap.push(new Array(1, 2, 3, 4));
	scoreMap.push(new Array(4, 3, 2, 1));
	scoreMap.push(new Array(4, 3, 2, 1));
	scoreMap.push(new Array(1, 2, 3, 4));
	scoreMap.push(new Array(1, 2, 3, 4));
	scoreMap.push(new Array(4, 3, 2, 1));
	scoreMap.push(new Array(4, 3, 2, 1));
	scoreMap.push(new Array(4, 3, 2, 1));
	scoreMap.push(new Array(0, 0));
	var scores = new Array();

	for(var i = 1; i <= totalQuestion; i++) {
		for(var j = 0; j < f.elements['q' + i].length; j++) {
			if(f.elements['q' + i][j].checked) {
				scores.push(scoreMap[i][j]);
				//prepare question array
				if (i < 9)
				{
					qa = qa + (i+8) + ":" + f.elements['q' + i][j].value + ":" + (scoreMap[i][j] * 0.41) + "|";
				} else {
					qa = qa + (i+8) + ":" + f.elements['q' + i][j].value + ":" + (scoreMap[i][j] * 0.18) + "|";
				}//if
				if (i==11)
				{
					if ((f.elements['q' + i][j].value) == "2")
					{
						client = "NO";
					} else {
						client = "RC";
					}// if
				}//if
				continue;
			}
		} // for
	} // for
	qa = qa.substring(0, qa.length - 1);
	var s1 = 0.41*(scores[0] + scores[1]);
	var s2 = 0.41*(scores[2] + scores[3] + scores[4] + scores[5] + scores[6]);
	var s3 = 0.18*(scores[7] + scores[8] + scores[9]);
	var score = s1 + s2 + s3;
	if(score <= 6.89) {
		result = 'conservative';
                            f.action = "result_conservative.htm?qa="+qa+"&tot="+score+"&client="+client;
	}
	else if(score <= 10.78) {
		result = 'balanced';
                             f.action = "result_balanced.htm?qa="+qa+"&tot="+score+"&client="+client;   
	}
	else if(score <= 14.67) {
		result = 'growth';
                             f.action = "result_growth.htm?qa="+qa+"&tot="+score+"&client="+client;
	}
	else {
		result = 'aggressive';
                             f.action = "result_aggressive.htm?qa="+qa+"&tot="+score+"&client="+client;                            
	} 
	f.r.value = result;
	f.i.value = location.href.indexOf('intermediary') == -1 ? 'n' : 'y';
	f.score.value = score;
	f.tot.value = score;
	f.qa.value = qa;
	f.client.value = client;
	//f.action = "ppt.htm?qa="+qa+"&tot="+score+"&client="+client;
	return confirm('確定要送出結果嗎？');
}

//added-A440456
 function getUrl(f){
   var score="";
   var qa ="";
   var client="";
   var url_string = unescape(String(document.location));
   var url_array1 = url_string.split('?');
   if(url_array1[1]){
     var e_array = url_array1[1].split('&');
     for(i=0;i<=(e_array.length);i++){
      if(e_array[i]){
       var useVal = e_array[i].split('=');
          //alert(useVal[0]+" == "+useVal[1]);
       if(useVal[0]== "qa"){
          qa = useVal[1];
        }
       if(useVal[0]== "tot"){
         score = useVal[1];
       }
      if(useVal[0]== "client"){
        client = useVal[1];
       }
     } 
   }
  }
  //document.forms[0].action = "ppt1.htm?qa="+qa+"&tot="+score+"&client="+client;
  //document.forms[0].submit();

} 