
var questions = [
	{text:"1. In ten years' time, I see myself ...",id:"E26AED7C569CAB5F0298E3EE1251BB80",
	answers:[ 
		{text:"Having vastly more responsibility than I do now, with a salary to match" , id:"392BCAD88F9AA6250813FD1202DE48B4", color:"Blue"},
		
		{text:"Enjoying a better work-life balance than I have now" , id:"88F49F5349A3E7A0FAEAAD2D46CD5CFE", color:"Green"},
		
		{text:"Flourishing as a self-employed specialist" , id:"04821718FF004DF196CAA0A1A2E2BBAD", color:"Orange"}
	]},
	
	{text:"2. Other than salary, the most important work benefit for me would be ...",id:"D946A3467646EA160DC8BA3290F24574",
	answers:[
		{text:"Performance-based cash bonuses" , id:"85AD2C1187E8A668DABCD71A515584F7", color:"Blue"},
		
		{text:"Paid academic training and development" , id:"D93E03966DA5C105320BA57A424CAA59", color:"Blue"},
		
		{text:"Flexible working arrangements" , id:"7A0DCFC61D2AF35C56BAE11FAF39491B", color:"Orange"},
		
		{text:"Paid time off to do charity or social/humanitarian work" , id:"5177DB18D56E2B7A0AAFCD7818552AE4", color:"Green"},
		
		{text:"A good company pension plan" , id:"26CE29710F0E697B8ED6D136FCF035E9", color:"Green"},
		
		{text:"Exposure to advanced networking/social activities" , id:"E651AA8760B1964E22F38D5F633A2CF2", color:"Orange"}
	]},

	{text:"3. Ideally, my career path leads to ...",id:"E783F4B549DF2152F80407228E822F4F",
	answers:[
		{text:"Working for a variety of employers and on a wide range of projects" , id:"8E476AC7F74065B2A2C5BBD63623BFCC", color:"Orange"},
		
		{text:"A mutually beneficial, long-term relationship with a major corporation, in which I acquire valuable experience across a variety of roles" , id:"545608852B62456C12359B25CB61576F", color:"Blue"},
		
		{text:"Staying with an organisation that has earned my loyalty and respect" , id:"6B895789029BBE2BE07E0711675784DA", color:"Green"}
	]},
	
	{text:"4. In the future, I picture myself working in ...",id:"91A5FBA01CCC1F795BCCF82A79FF1784",
	answers:[
		{text:"A virtual place where employees log in from any location" , id:"38A30698983D4BBFE6F517AE52F88576", color:"Orange"},
		
		{text:"A centralised hub in a major city" , id:"395215909E4F296E0684151173E8EAE2", color:"Blue"},
		
		{text:"An energy-efficient building outside of a major city" , id:"C58CF0A3AA1F18FBCEB5323A6074B798", color:"Green"}
	]},
	
	{text:"5. My ideal employer is ...",id:"1B2DB7C99339891A038880A67A0DB0FF",
	answers:[
		{text:"A company whose values match my own" , id:"BF82CF4CF381DBE22C63D4197C60ADD0", color:"Green"},
		
		{text:"An elite company that employs only the best" , id:"EB40AC3EA299C79458085F2A7F270805", color:"Blue"},
		
		{text:"Myself, enjoying the freedom and flexibility to choose which companies I work with, and under what conditions" , id:"F09024F59EEF4B0530FBAF1F9998549F", color:"Orange"}
	]},
	
	{text:"6. In tomorrow’s world, it will be important for companies to …",id:"0F945EE537FB9571DD832D488C8FED24",
	answers:[
		{text:"Embrace technology and the power of social networking" , id:" 114D885BE73DDB7A065D6A1B7B35967B", color:"Orange"},
		
		{text:"Understand the importance of emerging markets" , id:"4AA184D7EC04C1F4D101161480630070", color:"Blue"},
		
		{text:"Have a powerful social conscience intrinsic to the brand and a “green” sense of responsibility" , id:"C4D90B8FDE56958FB895C990F37F8940", color:"Green"}
	]},
	
	{text:"7. What I most want to gain from my work experience is ...",id:"2C78432EE684A0CFB12391C4DF259DE8",
		answers:[
			{text:"Quality relationships and a strong network" , id:"3C188EC7908A419F04D98EA56715AD75", color:"Orange"},
			
			{text:"The knowledge that I am making a difference in the world" , id:"2FB1B794B777406E13B4C5134F45A2FC", color:"Green"},
			
			{text:"As high a professional profile as possible &mdash; as quickly as possible" , id:"0C26EFC7A70753775B165AF893615AE8", color:"Blue"}
		]}
];

var color_lookup = {
	"392BCAD88F9AA6250813FD1202DE48B4":"Blue",
	"88F49F5349A3E7A0FAEAAD2D46CD5CFE":"Green",
	"04821718FF004DF196CAA0A1A2E2BBAD":"Orange",
	"85AD2C1187E8A668DABCD71A515584F7":"Blue",
	"D93E03966DA5C105320BA57A424CAA59":"Blue",
	"7A0DCFC61D2AF35C56BAE11FAF39491B":"Orange",
	"5177DB18D56E2B7A0AAFCD7818552AE4":"Green",
	"26CE29710F0E697B8ED6D136FCF035E9":"Green",
	"E651AA8760B1964E22F38D5F633A2CF2":"Orange",
	"8E476AC7F74065B2A2C5BBD63623BFCC":"Orange",
	"545608852B62456C12359B25CB61576F":"Blue",
	"6B895789029BBE2BE07E0711675784DA":"Green",
	"38A30698983D4BBFE6F517AE52F88576":"Orange",
	"395215909E4F296E0684151173E8EAE2":"Blue",
	"C58CF0A3AA1F18FBCEB5323A6074B798":"Green",
	"BF82CF4CF381DBE22C63D4197C60ADD0":"Green",
	"EB40AC3EA299C79458085F2A7F270805":"Blue",
	"F09024F59EEF4B0530FBAF1F9998549F":"Orange",
	"3C188EC7908A419F04D98EA56715AD75":"Orange",
	"2FB1B794B777406E13B4C5134F45A2FC":"Green",
	"0C26EFC7A70753775B165AF893615AE8":"Blue",	
	"114D885BE73DDB7A065D6A1B7B35967B":"Orange",
	"4AA184D7EC04C1F4D101161480630070":"Blue",
	"C4D90B8FDE56958FB895C990F37F8940":"Green"
};

var myAnswers=new Array();
var ets_id;
var sid = '21BB8F00D';

function get_ets_id(){
	var url = "http://survey.elegantthought.com/etsid.php?";
	$.getJSON(url + "&jsoncallback=?", function(resp){
		ets_id = resp.etsurveyor_id;
	});
}
	
function get_myAnswers(){
	var url = "http://survey.elegantthought.com/mtp/mtp.php?";
	$.getJSON(url + "&jsoncallback=?", function(resp){
		myAnswers = resp;
		
		changeQuestion(myAnswers.length);
	});
}


$(function(){
	
	//initialize
	get_myAnswers();
	$("#quiz_modal").jqm();
	$("#questions img.next").hide();

	$('#privacy').jqmAddTrigger('#footer-wrapper #footerlinks ul li:first a');

	/*if(!$.browser.msie){ //sifr for non-ie
		$("#quiz_modal").jqmShow().css('z-index','-1000');		
		$('.jqmOverlay').css('z-index','-1000');
		
		$("#questions").addClass('showMe');
		$("#first_page").addClass('showMe');
		$("#last_question").addClass('showMe');
		$("#quiz_result_modal").addClass('showMe');
		
		$('.question').addClass('showMe');	
		$('.question').find('div.que').sifr({path:'/en_GX/gx/assets/flash/',font:'arialbd'}).end().find('div.que_num').sifr({path:'/en_GX/gx/assets/flash/',font:'arialbd'});
		$('.question').removeClass('showMe');
		
		$("#questions").removeClass('showMe');
		$("#first_page").removeClass('showMe');
		$("#last_question").removeClass('showMe');
		$("#quiz_result_modal").removeClass('showMe');
		
		$("#quiz_modal").jqmHide();	
	}*/
	
	$("img.take_quiz").click(function(){
		$("#quiz_modal").jqmShow();

		/*if(myAnswers.length != 7){
			$("#quiz_modal").jqmShow();			
		}
		else{
			$("#last_question").jqmShow();
		}*/
	});
	
	$("#first_page img.home_background").click(function(){
		$('#first_page').hide();
		$('#questions').show();
	});
	
	$(".last_que").click(function(){
		$("#last_question").show();
	});
	
	$("img.next").click(function(){
		submitAnswer();	
		changeQuestion(myAnswers.length);
		$("#questions img.next").hide();
	});	


	$('input:checkbox').click(function(){
		$('.answers input:checked').attr('checked',false);
		$(this).attr('checked',true);
		$("#questions img.next").show();
	});
	
	if($('#last_question').find(':selected, :checked').length > 2){
		$("#last_question img.submit").show();	
	}


	$('#last_question').click(function(){	
		if($('#last_question').find(':selected, :checked').length > 3 && $("#country_combobox option:selected").text()!="Select a country"){
			$("#last_question img.submit").show();
			$("#country_combobox option:first").attr("disable","true");
		}
	});
	$("#country_combobox").change(function () {
		 if($("#country_combobox option:selected").text()=="Select a country"){
			$("#last_question img.submit").hide();
		 }
	 }).change(); 
	$('#last_question img.submit').click(function(){
		submitInfo();
		showResults();
		
	});
	
	/*$('#have_your_say a..facebook').confirm({
		msg: 'October 23, 2009\nThis group on Facebook in no way is endorsed or directly related to PricewaterhouseCoopers Business Trust or affiliates thereof. It is simply a forum for discussions for those who participated in the MTP Quiz.',
		buttons:{
			ok:'Proceed to Facebook',
			cancel:'Cancel',
			seperator:' '
		}
	});*/
	
	
	$('#have_your_say a..facebook').click(function(){
		$(this).removeAttr('href');
		confirmToFacebook();
	});
	
});

function showLast(){
	$("#last_question").show();
	$("#last_question .question").addClass("selected");
	$("#questions").hide();
}

function showResults(){
	var myColor = calculateColor();
	$("#questions").hide();
	showColor(myColor);
}

function showColor(myColor){
	var colorCode = {'green':'#8C9600','blue':'#0083BE','orange':'#d78600'};		
	
	$("#"+ myColor).show();
	$('img.arrows').hide();
	$('img.'+myColor+'_arrow').show();
	$('#'+myColor+'_left_inner').show();
	$('#'+myColor+'_right_inner').show().find('a').css('color','black');
	$("#quiz_result_modal .column a").css('color',colorCode[myColor]);
	$("#quiz_result_modal").show();
	$("#last_question").hide();
	
}

function changeQuestion(target){
	if(target > 0){
		$('#first_page').hide();
		$('#questions').show();
	}
	if(target > 6){	//quiz answered
		if(target > 7){	//info is also answered
			showResults();
		}else{	//info not answered
			showLast();
		}

	}
	else{
		$("img.graph_img").attr({
							src:"/en_GX/gx/managing-tomorrows-people/future-of-work/assets/survey_step"+(target+1)+".gif",
							alt:("survey_step"+(target+1))
						});
		//$("img.graph_img").pngFix();
		
		$("div.question").removeClass("selected");
		$("div.question").eq(target).addClass("selected");
		
		$("div.answers").removeClass("selected");
		$("div.answers").eq(target).addClass("selected");

	}
}

function submitInfo(){
	$('#last_question').find(':selected, :checked').each(function(){
		var qid = $(this).attr('name');
		var aid = $(this).attr('value');
		myAnswers.push(aid);
		
		var params ="";
		params += "etsurveyor_id="+ets_id+"&";
		params += "sid="+sid+"&";
		params += "qid="+qid+"&";
		params += "aid[]="+aid+"&";

		var url = "http://survey.elegantthought.com/submit.php?"+params;
		
		$.getJSON(url + "&jsoncallback=?", function(resp){
			ets_id = resp.etsurveyor_id;
		});
		
	});
	
}

function submitAnswer(){
	
	
	var qid = $('.answers.selected input:checked').attr('name');
	var aid = $('.answers.selected input:checked').attr('value');
	myAnswers.push(aid);
	
	var params ="";
	params += "etsurveyor_id="+ets_id+"&";
	params += "sid="+sid+"&";
	params += "qid="+qid+"&";
	params += "aid[]="+aid+"&";

	var url = "http://survey.elegantthought.com/submit.php?"+params;
	
	$.getJSON(url + "&jsoncallback=?", function(resp){
		ets_id = resp.etsurveyor_id;
	});
	
	
}
function calculateColor(){
	var blue=0,orange=0,green=0;
	for(i in myAnswers){
		switch(color_lookup[myAnswers[i]]){
			case "Blue":
				blue++;
				break;
			case "Green":
				green++;
				break;
			case "Orange":
				orange++;
				break;
		}
	}
	if(blue>orange && blue > green){ 
		return 'blue';
	}
	else if(green>orange){		
		return 'green';
	}
	else{
		return 'orange';
	}
}

function confirmToFacebook(){
	var answer = confirm("October 23, 2009\nThis group on Facebook in no way is endorsed or directly related to PricewaterhouseCoopers Business Trust or affiliates thereof." +
			" It is simply a forum for discussions for those who participated in the MTP Quiz." +
			"\n\nPress 'OK' to proceed to Facebook");
	if (answer){
		wrs_trackclick('DCS.dcsuri=http://www.facebook.com/pwcfanpage#/topic.php?uid=5845959276&topic=36102', 'WT.ti=Offsite: http://www.facebook.com/pwcfanpage#/topic.php?uid=5845959276&topic=36102', 'WT.dl=24');
		window.open("http://www.facebook.com/topic.php?topic=36102&uid=5845959276");
	}
}


