var sheets;
var columnsDone = 0;
//appends a loading image to any element passed
function loadingImage(element,colour) {
    var image = document.createElement("img");
    image.setAttribute("src",ajaxLoader);
    $(element).appendChild(image);
}
//Toggle a divs visibility
function toggleDiv(id) {
	var div = $(id);
	(div.hasClassName("collapsed")) ? div.removeClassName("collapsed") : div.addClassName("collapsed");
}
//These functions handle popups and convert standard links to popups
function processLinks(div) {
	if(document.getElementById(div)) {
		var div = document.getElementById(div);
		var as = div.getElementsByTagName("a");
		for (var i = 0; i < as.length; i++) {
			var a = as[i];
			attachLinkEvent(a);
		}
	}
}
function attachLinkEvent(a) {
	var url = a.getAttribute("href");
	a.setAttribute("target","_blank");
	/*a.onclick = function() {
		popup(url);
		return false;
	}*/
}
function popup(url) {
	if (screen.height > 600) {
		var height = screen.height * 0.8;
	}
	else {
		var height = 580;
	}
	if (screen.width > 800) {
		var width = screen.width * 0.8;
	}
	else {
		var width = 780;
	}
	var p = window.open(url,"popup","height=" + height + ", width=" + width + ", location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, toolbar=yes, left=15, top=15");
	p.focus();
}
function noneAbove(element) {
	if (element.value == "NONE") {
		$("question1_additional_help").style.display = "block";
		$("question1_help").style.display = "none";
		$("STD1HELP").style.display = "block";
		element.parentNode.className = "highlight";
	}
}
function show_help(element,id) {
    if (id == "STD1HELP") {
        $("question1_additional_help").style.display = "none";
        $("question1_help").style.display = "block";
    }
    var p = element.parentNode;
    p = p.parentNode;
    if (p.className == "highlight") {
        p.className = "";
    }
    else {
        p.className = "highlight";    
    }
    var help_div = $(id);
    if (help_div.style.display == "block") {
        help_div.style.display = "none";
    }
    else {
        help_div.style.display = "block";
    }
}
//for RSH
/*
window.dhtmlHistory.create({
        toJSON: function(o) {
                return Object.toJSON(o);
        }
        , fromJSON: function(s) {
                return s.evalJSON();
        }
});

var yourListener = function(newLocation, historyData) {
        if (location.href.indexOf("#a_") != -1) {
			var url = location.href.split("#a_")[1];
		}
		else {
			var url = "#a_step_1";	
		}
		//alert(url);
		//loadState(url);
}
window.onload = function() {
        dhtmlHistory.initialize();
        dhtmlHistory.addListener(yourListener);
};*/
var myModuleBookmarkedState = YAHOO.util.History.getBookmarkedState("vw");
// If there is no bookmarked state, assign the default state: 
var myModuleInitialState = myModuleBookmarkedState || "#a_intro";
YAHOO.util.History.register("vw", myModuleInitialState, function (state) {		  
	var currentState = YAHOO.util.History.getCurrentState("vw"); 
	//alert(currentState);
	loadState(currentState);
});
window.onload = function() {
	try { 
	YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe"); 
	}  catch (e) {
	loadState("#a_intro");	
	} 
	var url = window.location.toString();
		if (url.indexOf("#") != -1) {
			window.location = url.split("#")[0];
		}
};
//Define page layout based on the step the user is at
function loadState(state) {
	if (state == "#a_intro") {
		//Hide steps 2 and 3
		$("vw_container").style.display = "none";
		$("intro_container").style.display = "block";
		//goToAnchor('#a_step_1');
	}
	else if (state == "#a_step_1") {
		//Hide steps 2 and 3
		$("vw_container").style.display = "block";
		$("step_2").style.display = "none";
		$("step_3").style.display = "none";
		$("intro_container").style.display = "none";
		//Change heading
		$("step_1_heading").style.backgroundPosition = "0px 0px";
		//remove A list from step_1 div
		//remove Q & A lists from step_1 and step_2 divs
		if ($("step_1_container").firstChild.nodeName == "UL") {
			$("step_1_container").removeChild($("step_1_container").firstChild);
		}
		if ($("step_2_container").firstChild.nodeName == "UL") {
			$("step_2_container").removeChild($("step_2_container").firstChild);
		}
		//remove additional questions from step_2 and step_3 divs
		$("additionalQuestions").innerHTML = "";
		$("additionalQuestions2").innerHTML = "";
		//display step_1 div and find visas button
		$("step_1_question_container").style.display = "block";
		$("changeAnswers1").style.display = "none";
		$("findVisas").style.display = "inline";
		$("results_container").style.display = "none";
		//goToAnchor('#a_step_1');
	}
	else if (state == "#a_step_2") {
		//Show step 2 and 3
		$("step_2").style.display = "block";
		$("step_3").style.display = "none";
		//Hide buttons and divs in step_1 div
		$("findVisas").style.display = "none";
		$("step_1_question_container").style.display = "none";
		//Show buttons
		$("findVisas2").style.display = "inline";
		$("changeAnswers1").style.display = "inline";
		$("changeAnswers2").style.display = "none";
		//Change heading
		$("step_1_heading").style.backgroundPosition = "0px -117px";
		$("step_2_heading").style.backgroundPosition = "0px -60px";
		//remove Q & A lists from step_1 div
		if ($("step_2_container").firstChild.nodeName == "UL") {
			$("step_2_container").removeChild($("step_2_container").firstChild);
		}
		if ($("step_1_container").firstChild.nodeName != "UL") {
			showAnswers("step_1_question_list","step_1_container");	
		}
		if ($("additionalQuestions").innerHTML == "") {
			step1();
		}
		$("ajax_loader").style.display = "none";
		$("step_2_question_container").style.display = "block";
		//remove additional questions from step_2 and step_3 divs
		$("additionalQuestions2").innerHTML = "";
		$("results_container").style.display = "none";
		//goToAnchor('#a_step_2');
	}
	else if (state == "#a_step_3") {
		//Show step 3
		$("step_2").style.display = "block";
		$("step_3").style.display = "block";
		//Hide buttons and divs in step_2 div
		$("findVisas2").style.display = "none";
		$("step_2_question_container").style.display = "none";
		$("vw_container").style.display = "block";
		//Show buttons
		$("changeAnswers2").style.display = "block";
		//Change heading
		$("step_2_heading").style.backgroundPosition = "0px -209px";
		$("results_container").style.display = "none";
		if ($("additionalQuestions2").innerHTML == "") {
			step1();
		}
		$("ajax_loader").style.display = "none";
		showAnswers("step_2_question_list","step_2_container");
		//goToAnchor('#a_step_3');
	}
	else if (state == "#a_results") {
		//hide the vw and show the results div
		$("vw_container").style.display = "none";
		$("results_container").style.display = "block";
		$("resultsubheading").style.display = "block";
		$("infoMessages").style.display = "none";
		$("resultsTable").style.display = "block";
		$("ajax_loader").style.display = "none";
		goToTop();
		//goToAnchor('#a_results');
	}
	else if (state == "#a_info") {
		//hide the vw and show the results div
		$("vw_container").style.display = "none";
		$("results_container").style.display = "block";
		$("resultsubheading").style.display = "none";
		$("resultsTable").style.display = "none";
		$("previous_answers").style.display = "none";
		$("backtoquestions").style.display = "block";
		$("ajax_loader").style.display = "none";
		goToTop();
		//goToAnchor('#a_info');
	}
	else if (state == "#a_error") {
		//hide the vw and show the results div
		$("vw_container").style.display = "none";
		$("results_container").style.display = "block";
		$("resultsubheading").style.display = "none";
		$("resultsTable").style.display = "none";
		$("previous_answers").style.display = "none";
		$("backtoquestions").style.display = "block";
		$("ajax_loader").style.display = "none";
		goToTop();
		//goToAnchor('#a_error');
	}
	else if (state == "#a_return_to_questions") {
		//hide the vw and show the results div
		$("vw_container").style.display = "block";
		$("results_container").style.display = "none";
		//goToTop();
		//goToAnchor('#a_step_1');
	}
}
function goToAnchor(name) {

	var url;
	if (location.href.indexOf("#") != -1) {
		url = location.href.split("#")[0];		
	}
	else {
		url = location.href
	}
	//alert("moved to: " + name);
	//location.href = url + name;
	try {
		YAHOO.util.History.navigate("vw", name); 
	}  catch (e) {
		loadState(name);
	}
}

function goToTop() {
	window.scrollTo(0,0);
}

//Age calculator
var one_day=1000*60*60*24;
var one_month=1000*60*60*24*30;
var one_year=1000*60*60*24*30*12;
function displayage(yr, mon, day, unit, decimal, round){
	today=new Date();
	var pastdate=new Date(yr, mon-1, day);
	var countunit=unit;
	var decimals=decimal;
	var rounding=round;
	finalunit=(countunit=="days") ? one_day : (countunit=="months")? one_month : one_year;
	decimals=(decimals<=0)? 1 : decimals*10;

	if (unit!="years"){
		if (rounding=="rounddown") {
			var age = Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals;
			return age;
		}
		else {
			var age = Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals;
			return age;
		}
	}
	else{
		yearspast=today.getFullYear()-yr-1;
		tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0;
		pastdate.setFullYear(today.getFullYear());
		pastdate2=new Date(today.getFullYear()-1, mon-1, day);
		tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals;
		var age = yearspast+tail;
		return age;
	}
}
//validate the form and submit the query string to Rules Burst via Ajax.request. If passed a variable will mean user is at step 2
function step1() {
	$("ajax_loader").style.display = "block";
	var proceed = true;
	errorColumns = "";
	var string;
	($("Q1").value != "") ? string = "Q1=" + $("Q1").value : proceed = false;
	($("Q2").value != "") ? string += "&Q2=" + $("Q2").value : proceed = false;
	//this bit calculates the users age
	if ($("Q3c").value != "" && $("Q3b").value != "" && $("Q3a").value != "") {
		var year = $("Q3c").value;
		var month = $("Q3b").value;
		var day = $("Q3a").value;
		var age = displayage(year, month, day, "years", 0, "rounddown");
		//alert(age);
		string += "&Q3=" + age;
	}
	else {
		proceed = false;
	}
	($("Q4").value != "") ? string += "&Q4=" + $("Q4").value : proceed = false;
	($("Q5").value != "") ? string += "&Q5=" + $("Q5").value : proceed = false;
	//if additional questions exist get their id and value and append to the query string
	if ($("additionalQuestions").getElementsByTagName("select")) {
		var s = $("additionalQuestions").getElementsByTagName("select");
		for (var i = 0; i < s.length; i++) {
			var id = s[i].getAttribute("id");
			var v = s[i].value;
			if (v != "") {
				string += "&" + id + "=" + v;
			}
			else {
				proceed = false;
			}
		}
	}
	//if second set of additional questions exist get their id and value and append to the query string
	if ($("additionalQuestions2").getElementsByTagName("select")) {
		var s = $("additionalQuestions2").getElementsByTagName("select");
		for (var i = 0; i < s.length; i++) {
			var id = s[i].getAttribute("id");
			var v = s[i].value;
			if (v != "") {
				string += "&" + id + "=" + v;
			}
			else {
				proceed = false;
			}
		}
	}
	//highlight any select boxes that have an empty value, and unhighlight them if they've been corrected
	var proceed;
	var qs = $$('#questions select');
	qs.each(function(q) {
			if (q.value == "") {
				q.addClassName("highlight_error");
				proceed = false;
			}
			else if (q.hasClassName("highlight_error")){
				q.removeClassName("highlight_error");
			}
		}
	);
	if (proceed == false) {
		$("ajax_loader").style.display = "none";
		alert("Please answer all of the questions");
	}
	else {
		//submit the query string to ruleburst visa soap handler
		var url = domain + soapHandler + string;
		//alert("String submitted to Ruleburst: " + string);
		try {
			new Ajax.Request(url, {method:'get',onComplete:function(transport) { step2(transport.responseText); }});
		}
		catch (e) {
			alert("Sorry, the system is currently unavailable. Please contact us for more information.");	
		}
	}
	return false;
}
//Process the returned string from ruleburst. the variable r is the response text from ruleburst
function step2(r) {
	var exitFunction = false;
	//alert("Response from ruleburst: " + r);
	var response = r.split(",");
	//if we have an error
	if (response[0] == "e") {
		var page = response[1].toUpperCase();
		var url = domain + messagePath + page; 
		new Ajax.Request(url,{method:'get', on404:function() {alert(url + " could not be found");}, onSuccess:function(transport) { loadErrorMessage(transport.responseText); goToAnchor("#a_error"); }});
	}
	//if we have additional questions
	else if (response[0] == "q") {
		state = 2;
		loadAdditionalQuestions(r);
	}
	//else if we have summary sheets
	else if (response[0] == "p") {
		var s = r.split(",");
		//splice the string to remove the p, and leave just the summary sheet id's
		s.splice(0,1);
		//Check for an INF file
		for (var i = 0; i < s.length; i++) {
			var value = s[i];
			if (value.indexOf("INF0") != -1) {
				value = value.split("INF");
				var url = domain + "/visawizard/summary/INF" + value[1]; 
				new Ajax.Request(url,{method:'get', on404:function() {alert(url + " could not be found");}, onSuccess:function(transport) { goToAnchor("#a_info"); loadInfoMessage(transport.responseText); }});
			exitFunction = true;
			}
		}
		if (exitFunction == true) { return; }
		var url = domain + summaryPath; 
		//Lets build the table based on how many summary sheets we have been given from ruleburst. We'll also hide any extra columns
		sheets = s.length;
		if (s.length == 1) {
			new Ajax.Request(url + s[0],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 1;}, onComplete:function(transport) { loadSummaries(transport.responseText,1); goToAnchor('#a_results');/*loadState('results');*/}});
		}
		if (s.length == 2) {
			new Ajax.Request(url + s[0],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 1;}, onComplete:function(transport) { loadSummaries(transport.responseText,1); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[1],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 2;}, onComplete:function(transport) { loadSummaries(transport.responseText,2); goToAnchor('#a_results');/*loadState('results');*/}});
		}
		if (s.length == 3) {
			new Ajax.Request(url + s[0],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 1;}, onComplete:function(transport) { loadSummaries(transport.responseText,1); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[1],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 2;}, onComplete:function(transport) { loadSummaries(transport.responseText,2); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[2],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 3;}, onComplete:function(transport) { loadSummaries(transport.responseText,3); goToAnchor('#a_results');/*loadState('results');*/}});
		}
		if (s.length == 4) {
			new Ajax.Request(url + s[0],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 1;}, onSuccess:function(transport) { loadSummaries(transport.responseText,1); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[1],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 2;}, onSuccess:function(transport) { loadSummaries(transport.responseText,2); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[2],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 3;}, onSuccess:function(transport) { loadSummaries(transport.responseText,3); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[3],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 4;}, onSuccess:function(transport) { loadSummaries(transport.responseText,4); goToAnchor('#a_results');/*loadState('results');*/}});
		}
		if (s.length == 5) {
			new Ajax.Request(url + s[0],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 1;}, onSuccess:function(transport) { loadSummaries(transport.responseText,1); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[1],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 2;}, onSuccess:function(transport) { loadSummaries(transport.responseText,2); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[2],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 3;}, onSuccess:function(transport) { loadSummaries(transport.responseText,3); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[3],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 4;}, onSuccess:function(transport) { loadSummaries(transport.responseText,4); goToAnchor('#a_results');/*loadState('results');*/}});
			new Ajax.Request(url + s[4],{method:'get', on404:function() {loadErrorMessage(r), loadState('error'); errorColumns = 5;}, onSuccess:function(transport) { loadSummaries(transport.responseText,5); goToAnchor('#a_results');/*loadState('results');*/}});
		}
	}
}
// if additional questions are returned from ruleburst, load them into the additional questions div
function loadAdditionalQuestions(text) {
	var r = text.split(",");
	if (r.length > 2) {
		var page = r[2].toLowerCase();
		div = "additionalQuestions2";
		//loadingImage(div,"white");
		new Ajax.Updater(div, domain + questionPath + page, {method:'get', onComplete:function() { goToAnchor('#a_step_3');/*loadState("step_3");*/}});
	}
	else {
		var page = r[1].toLowerCase();
		div = "additionalQuestions";
		//loadingImage(div,"white");
		new Ajax.Updater(div, domain + questionPath + page, {method:'get', onComplete:function() {goToAnchor('#a_step_2');/*loadState("step_2");*/}});
	}
	return false;
}
function showAnswers(listId,divId,append) {
	var div = $(divId);
	if (div.getElementsByTagName("ul").length > 0) {
		var uls = div.getElementsByTagName("ul");
		var ulsLen = uls.length;
		for (var u = 0; u < ulsLen; u++) {
			if (uls[u].className == "answers" && !append) {
				return;
			}
		}
	}
	var ul = document.createElement("ul");
	ul.className = "answers";
	if ($(listId)) {
		var li = $(listId).childElements();
		var liLen = li.length;
		for (var i = 0; i < liLen; i++) {
			var qText = document.createTextNode(li[i].getElementsByTagName("label").item(0).firstChild.nodeValue);
			if (li[i].getElementsByTagName("select").length > 1) {
				var s = li[i].getElementsByTagName("select");
				var sLen = s.length;
				var text;
				for (var j = 0; j < sLen; j++) {
					if (j == 0) {
						text = " " + s[j].options[s[j].selectedIndex].text;
					}
					else {
						text += " " + s[j].options[s[j].selectedIndex].text;
					}
				}
				var sText = document.createTextNode(text);
			}
			else {
				var s = li[i].getElementsByTagName("select").item(0);
				var sText = document.createTextNode(s.options[s.selectedIndex].text);
			}
			var l = document.createElement("li");
			var br = document.createElement("br");
			l.appendChild(qText);
			l.appendChild(br);
			var div_a = document.createElement("div");
			div_a.appendChild(sText);
			l.appendChild(div_a);
			ul.appendChild(l);
		}
		if (append) {
			div.appendChild(ul);
		}
		else {
			div.insertBefore(ul,div.firstChild);
		}
	}
}
//loads an INFO message
function loadInfoMessage(page) {
	$("infoMessages").style.display = "block";
	$("infoMessages").innerHTML = "";
	$("infoMessages").innerHTML += "<div>" + page + "</div>";
	processLinks("infoMessages");
}
function loadErrorMessage(page) {
	$("infoMessages").style.display = "block";
	$("infoMessages").innerHTML = "";
	$("infoMessages").innerHTML += "<div>" + page + "</div>";
	processLinks("errorMessages");
}
function PHP_Unserialize(input) {
	var result = PHP_Unserialize_(input);
	return result[0];
}
function PHP_Unserialize_(input) {
	var length = 0;
	switch (input.charAt(0)) {
		case 'a':
			length = PHP_Unserialize_GetLength(input);
			input  = input.substr(String(length).length + 4);
			var arr   = new Array();
			var key   = null;
			var value = null;
			for (var i=0; i<length; ++i) {
				key   = PHP_Unserialize_(input);
				input = key[1];

				value = PHP_Unserialize_(input);
				input = value[1];

				arr[key[0]] = value[0];
			}
			input = input.substr(1);
			return [arr, input];
			break;
		case 'O':
			length = PHP_Unserialize_GetLength(input);
			var classname = String(input.substr(String(length).length + 4, length));
			input  = input.substr(String(length).length + 6 + length);
			var numProperties = Number(input.substring(0, input.indexOf(':')));
			input = input.substr(String(numProperties).length + 2);
			var obj      = new Object();
			var property = null;
			var value    = null;
			for (var i=0; i<numProperties; ++i) {
				key   = PHP_Unserialize_(input);
				input = key[1];
				
				// Handle private/protected
				key[0] = key[0].replace(new RegExp('^\x00' + classname + '\x00'), '');
				key[0] = key[0].replace(new RegExp('^\x00\\*\x00'), '');

				value = PHP_Unserialize_(input);
				input = value[1];

				obj[key[0]] = value[0];
			}
			input = input.substr(1);
			return [obj, input];
			break;
		case 's':
			length = PHP_Unserialize_GetLength(input);
			return [String(input.substr(String(length).length + 4, length)), input.substr(String(length).length + 6 + length)];
			break;
		case 'i':
		case 'd':
			var num = Number(input.substring(2, input.indexOf(';')));
			return [num, input.substr(String(num).length + 3)];
			break;
		case 'b':
			var bool = (input.substr(2, 1) == 1);
			return [bool, input.substr(4)];
			break;


		case 'N':
			return [null, input.substr(2)];
			break;
		case 'o':
		case 'r':
		case 'C':
		case 'R':
		case 'U':
			alert('Error: Unsupported PHP data type found!');
		default:
			return [null, null];
			break;
	}
}
function PHP_Unserialize_GetLength(input) {
	input = input.substring(2);
	var length = Number(input.substr(0, input.indexOf(':')));
	return length;
}
function loadSummaries(text,column) {
	switch (sheets) {
		case 1:
			var tdWidth = "90%";
			break;
		case 2:
			var tdWidth = "45%";
			break;
		case 3:
			var tdWidth = "30%";
			break;
		case 4:
			var tdWidth = "22.5%";
			break;
		case 5:
			var tdWidth = "18%";			
			break;
	}
	//unserialize the array return by petes php script
	//(PHP_Unserialize(text)) ? alert("PHP unserialize successful") : alert("PHP unserialize failed");
	var content = PHP_Unserialize(text);
	//alert(content[0]);
	contentLen = content.length;
	//process table header
	var th = $("resultsTable").getElementsByTagName("th");
	var thLen = th.length;
	var d = th[column].getElementsByTagName("div");
	var dLen = d.length;
	for (var j = 0; j < dLen; j++) {
		if (d[j].className == "col_name") {
			d[j].innerHTML = content[0];
			th[column].style.display = "";
		}
	}
	var tr = $("resultsTable").getElementsByTagName("tr");
	var even = false;
	//loop through all the td's and append the new html from the summary sheet and also set the zebra stipes
	for (var i = 1; i < contentLen; i++) {
		if (tr[i]) {
			var td = tr[i].getElementsByTagName("td");
			var tdLen = td.length;
			for (var t = 0; t < tdLen; t++) {
				td[t].style.width = (t == 0) ? "5%" : tdWidth;
			}
			td.item(column).innerHTML = content[i];
			td.item(column).style.display = "";
		}
	}
	columnsDone ++;
	if (columnsDone == sheets) {
		hideCells(columnsDone,"th");
		hideCells(columnsDone,"td");
		processLinks("resultsTable");
		/* This part is to display the users andswers on the results screen */
		$("answers_header").style.display = "none";
		$("answers_content").style.display = "block";
		$("answers_left").innerHTML = "";
		$("answers_right").innerHTML = "";
		$("backtoquestions").style.display = "none";
		$("previous_answers").style.display = "block";
		showAnswers("step_1_question_list","answers_left",true);
		showAnswers("step_2_question_list","answers_right",true);
		showAnswers("step_3_question_list","answers_right",true);
		/*if (location.href.indexOf("?hide_results") != -1) {
			$("answers_header").style.display = "block";
			$("answers_content").style.display = "";
		}
		if (location.href.indexOf("?no_results") != -1) {
			$("previous_answers").style.display = "none";
		}*/
		columnsDone = "";
	}
}
function hideCells(c,tag) {
	var rows = $("resultsTable").getElementsByTagName("tr");
	var rowsLen = rows.length;
	for (var j = 0; j < rowsLen; j++) {
		var cells = rows[j].getElementsByTagName(tag);
		var cellsLen = cells.length;
		for (var i = c+1; i < cellsLen; i++) {
			cells[i].style.display = "none";
		}
	}
}

