// MyFantasyAlert.com

dojo.provide("fantasy.client");



dojo.require("dojo.lfx.*");

dojo.require("dojo.event.*");

dojo.require("dojo.lfx.extras");

dojo.require("dojo.widget.Checkbox");


	

fantasy.client.is_minimized = 0;

fantasy.client.current_scrollview = [];

fantasy.client.current_scrollview.topic = 1;

fantasy.client.current_scrollview.questions = 1;

fantasy.client.current_scrollview.overview = 1;

			

fantasy.client.questions_container_height = 332;//box.height;//372;//dojo.html.getMarginBox(dojo.byId('topic_sroll_container')).height;//372;

fantasy.client.questions_container_width = 332;//box.height;//372;//dojo.html.getMarginBox(dojo.byId('topic_sroll_container')).height;//372;

			

fantasy.client.topics_container_height = 402;//box.height;	

fantasy.client.topics_container_width = 228;//box.height;			

fantasy.client.questionsoverview_container_height = 372;			

fantasy.client.questionsoverview_container_width = 332;		

fantasy.client.max_elements = 13;

fantasy.client.headers_cnt = 0;

fantasy.client.element_height = Math.floor(fantasy.client.topics_container_height/fantasy.client.max_elements);

fantasy.client.current_level = 0;

fantasy.client.current_nodeId = null;

fantasy.client.current_nodeName = null;

fantasy.client.activeTopics = [];

fantasy.client.cache = [];

fantasy.client.topics = null;

fantasy.client.questions = null;

fantasy.client.questionNodes = [];

fantasy.client.currentCategory = null;

fantasy.client.renderedTopics = [];

fantasy.client.selectedMatches = [];

fantasy.client.questionCounter = 0;

			

// Result rendering

fantasy.client.results = [];

			

fantasy.client.minimizeSelect = function(maximize_detail){		
	

	if (fantasy.client.is_minimized == '0') {

		if (maximize_detail == '1') {

			dojo.byId("square_one_mini").style.backgroundColor = '#ad2c31';

		}

		if (maximize_detail == '4') {

			dojo.byId("square_two_mini").style.backgroundColor = '#ad2c31';

		}

		if (maximize_detail == '2') {

			dojo.byId("square_three_mini").style.backgroundColor = '#ad2c31';

		}

		if (maximize_detail == '3') {

			dojo.byId("square_four_mini").style.backgroundColor = '#ad2c31';

		}

			

		fantasy.client.loadSurveyData(maximize_detail);

					

		fantasy.client.is_minimized = 1;

		dojo.byId("content").style.zIndex = 100;

								

		dojo.lfx.combine(

			dojo.lfx.implode(dojo.byId("square_one"), dojo.byId("square_one_mini"), 350),

			dojo.lfx.implode(dojo.byId("square_two"), dojo.byId("square_two_mini"), 350),

			dojo.lfx.implode(dojo.byId("square_three"), dojo.byId("square_three_mini"), 350),

			dojo.lfx.implode(dojo.byId("square_four"), dojo.byId("square_four_mini"), 350),

			dojo.lfx.html.fadeShow(dojo.byId('content'), 650),

			dojo.lfx.html.fadeShow(dojo.byId('container_mini'), 850)						

		).play(100);

	}

};

			

fantasy.client.maximizeSelect = function(maximize_detail){

	if (fantasy.client.is_minimized == 1) {

		fantasy.client.is_minimized = 0;	

					

		dojo.byId("square_one_mini").style.backgroundColor = '#490202';

		dojo.byId("square_two_mini").style.backgroundColor = '#490202';

		dojo.byId("square_three_mini").style.backgroundColor = '#490202';

		dojo.byId("square_four_mini").style.backgroundColor = '#490202';						

					

		dojo.lfx.combine(

			dojo.lfx.html.fadeHide(dojo.byId("content"), 20, null, function(evt) { 

				dojo.byId("content").style.zIndex = -5;

			}),					

			dojo.lfx.explode(dojo.byId("square_one_mini"), dojo.byId("square_one"), 350),

			dojo.lfx.explode(dojo.byId("square_two_mini"), dojo.byId("square_two"), 350),

			dojo.lfx.explode(dojo.byId("square_three_mini"), dojo.byId("square_three"), 350),

			dojo.lfx.explode(dojo.byId("square_four_mini"), dojo.byId("square_four"), 350),



			dojo.lfx.html.fadeHide(dojo.byId('container_mini'), 250)

						

		).play(100);

	}

};		



fantasy.client.initWelcome = function() {

	// check if we want special screen

	url = window.location.href;

	array_url = url.split('#');

	if (array_url[1]) {

		if (array_url[1] == 'join') {

			token = gup('email');

			dojo.byId('join_email').value = token;

			fantasy.client.toggleSurveyJoin('join');

		}

		else if (array_url[1] == 'result') {

			token = gup('token');

			dojo.byId('result_token').value = token;

			token = gup('email');

			dojo.byId('result_email').value = token;

			fantasy.client.toggleSurveyJoin('result');

		}

		else {

			fantasy.client.toggleSurveyJoin('new');

		}

	}

	else {

		fantasy.client.toggleSurveyJoin('new');

	}

	

	error = gup('error');

	

	if (error == 'noaccess') {

		dojo.byId('error_msg').innerHTML = 'Somehow you don\'t have access to a survey. Please check whether you entered the correct email and password combination.';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error == 'insurvey') {

		dojo.byId('error_msg').innerHTML = 'You still have to close another survey before you can start a new one.';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error == 'partnerinsurvey') {

		dojo.byId('error_msg').innerHTML = 'Your partner still has to close a survey.';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error == 'form') {

		dojo.byId('error_msg').innerHTML = 'There was an error in your data and somehow you passed the validation. ouch';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error == 'unknownsurvey') {

		dojo.byId('error_msg').innerHTML = 'We can\'t seem to find the survey. Maybe you provided a wrong survey token? Please check your email and make sure all data are filled in correctly.';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error == 'notuniquekey') {

		dojo.byId('error_msg').innerHTML = 'You have used this password already for another survey. Please choose a different one.';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error == 'notuniquekeypartner') {

		dojo.byId('error_msg').innerHTML = 'Your partner has used this password already in a different survey. Please choose a different one.';

		dojo.byId('alert_error').style.display = '';

	}

	else if (error.length > 0) {

		dojo.byId('error_msg').innerHTML = 'We don\'t exactly know why an error happened. Please just try again or send us a message if it happens more often.';

		dojo.byId('alert_error').style.display = '';

	}

	

	// see if member has an open survey

	var bindArgs = {

		url: '/FANTASY/Alert/Has/',

		method: 'POST',

		type: 'text/json',

		load: function(type, evaldObj) 

		{ 

			eval("var decoded_data = "+evaldObj);

			if (decoded_data.RESPONSE_TYPE == 'SUCCESS') {	

				survey_id = decoded_data.RESPONSE.ID;

				survey_token = decoded_data.RESPONSE.TOKEN;

				survey_closed = decoded_data.RESPONSE.CLOSED;

				

				fantasy.client.toggleSurveyStatus(survey_id, survey_token, survey_closed);

			}

		}			

	};						

	// Trying to create survey

	dojo.io.bind(bindArgs);	



	fantasy.client.howToInit();

};



fantasy.client.initSurvey = function() {

	dojo.lfx.html.fadeHide(dojo.byId('container_mini'), 0, 0, function() { 
		dojo.html.removeClass(dojo.byId('container_mini'), 'hidden');
	}).play();

	dojo.lfx.html.fadeHide(dojo.byId('content'), 0, 0, function() { 
		dojo.html.removeClass(dojo.byId('content'), 'hidden');
	}).play();

	dojo.event.connect(dojo.byId('square_one'), "onclick", function(evt) {

		fantasy.client.minimizeSelect('1');

	});

	dojo.event.connect(dojo.byId('square_two'), "onclick", function(evt) {

		fantasy.client.minimizeSelect('4');

	});

	dojo.event.connect(dojo.byId('square_three'), "onclick", function(evt) {

		fantasy.client.minimizeSelect('2');

	});

	dojo.event.connect(dojo.byId('square_four'), "onclick", function(evt) {

		fantasy.client.minimizeSelect('3');

	});

				

	dojo.event.connect(dojo.byId('square_one_mini'), "onclick", function(evt) {

		fantasy.client.maximizeSelect('1');

	});

	dojo.event.connect(dojo.byId('square_two_mini'), "onclick", function(evt) {

		fantasy.client.maximizeSelect('4');

	});

	dojo.event.connect(dojo.byId('square_three_mini'), "onclick", function(evt) {

		fantasy.client.maximizeSelect('2');

	});

	dojo.event.connect(dojo.byId('square_four_mini'), "onclick", function(evt) {

		fantasy.client.maximizeSelect('3');

	});	

				

	dojo.event.connect(dojo.byId("topic_scroller_button_up"), "onclick", function() { fantasy.client.scrollerScrollUp("topic"); });

	dojo.event.connect(dojo.byId("topic_scroller_button_down"), "onclick", function() { fantasy.client.scrollerScrollDown("topic"); });	

	

	dojo.event.connect(dojo.byId("questions_scroller_button_up"), "onclick", function() { fantasy.client.scrollerScrollUp("questions"); });

	dojo.event.connect(dojo.byId("questions_scroller_button_down"), "onclick", function() { fantasy.client.scrollerScrollDown("questions"); });		

	

	dojo.event.connect(dojo.byId("overview_scroller_button_up"), "onclick", function() { fantasy.client.scrollerScrollUp("overview"); });

	dojo.event.connect(dojo.byId("overview_scroller_button_down"), "onclick", function() { fantasy.client.scrollerScrollDown("overview"); });	

};



fantasy.client.initResults = function() {

	bindArgs = {

		url: '/FANTASY/Alert/Result/'+dojo.byId('result_token').value,

		method: 'POST',

		type: 'text/json',

		load: function(type, evaldObj) 

		{ 

			eval("var decoded_data = "+evaldObj);	

			if (decoded_data.RESPONSE_TYPE == 'SUCCESS') {	

				fantasy.client.results = decoded_data.RESPONSE;

				

				fantasy.client.fillResult(fantasy.client.results);

				

				fantasy.client.loadResultAdvice('');

	

			}

			else if (decoded_data.RESPONSE_TYPE == 'ERROR') {

				alert('Acess denied!');

			}

		}			

	};			

	bindArgs.content = { password: dojo.byId('result_password').value, email: dojo.byId('result_email').value};



	// Trying to create survey

	dojo.io.bind(bindArgs);	

};



fantasy.client.initDirectory = function() {

	
};

			

fantasy.client.renderScrollStatus = function(name) {

	fantasy.client.current_scrollview.topic = 1;

	fantasy.client.current_scrollview.questions = 1;

	fantasy.client.current_scrollview.overview = 1;

		

	while(dojo.byId(name+"_scroller_status").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId(name+"_scroller_status").firstChild); }



	count = dojo.byId(name+"_scroll_container").childNodes.length;

			

	if (count == 1) {

		dojo.html.setDisplay(dojo.byId(name+'_scroller_status_container'), 'none');

		dojo.html.setDisplay(dojo.byId(name+'_scroller_button_up'), 'none');

		dojo.html.setDisplay(dojo.byId(name+'_scroller_button_down'), 'none');

					

		return;

	}

				

	dojo.html.setDisplay(dojo.byId(name+'_scroller_status_container'), '');

	dojo.html.setDisplay(dojo.byId(name+'_scroller_button_up'), '');

	dojo.html.setDisplay(dojo.byId(name+'_scroller_button_down'), '');

				

	height = (422/2)-((count*11)/2);

	dojo.byId(name+"_scroller_status").style.top = height+'px';

		

	for (var i=1;i<=count;i++) {

		if (i == 1) {

			color = '#ad2c31';

		} 

		else {

			color = '#490202';

		}

		statusElement = document.createElement('div');

		statusElement.innerHTML = '';

		

		dojo.html.setStyle(statusElement,'position', 'relative');

		dojo.html.setStyle(statusElement,'top','-50%');

		dojo.html.setStyle(statusElement,'width','10px');

		dojo.html.setStyle(statusElement,'height','9px');

		dojo.html.setStyle(statusElement,'background-color',color);

		dojo.html.setStyle(statusElement,'margin-bottom','2px');

		dojo.html.setStyle(statusElement,'font-size','1px');

		

		statusElement.setAttribute('id', name+"_scroller_status_"+i);

		dojo.byId(name+"_scroller_status").appendChild(statusElement);

		

		dojo.byId(name+"_scroller_status_"+i).i = i;

		dojo.event.connect(dojo.byId(name+"_scroller_status_"+i), 'onclick', dojo.lang.hitch(dojo.byId(name+"_scroller_status_"+i),function(e){fantasy.client.skipScroller(this.i, name);}));

	}

};

			

fantasy.client.skipScroller = function(moveTo, name) {

	if (fantasy.client.current_scrollview[name] < moveTo) {

		for (i=fantasy.client.current_scrollview[name]; i<moveTo; i++) {

			fantasy.client.scrollerScrollDown(name);

		}

	}

	else if (fantasy.client.current_scrollview[name] > moveTo) {

		for (i=fantasy.client.current_scrollview[name]; i>moveTo; i--) {

			fantasy.client.scrollerScrollUp(name);

		}				

	}

};

			

fantasy.client.updateScrollview = function(name) {

	count = dojo.byId(name+"_scroll_container").childNodes.length;

				

	for (var i=1;i<=count;i++) {

		if (i == fantasy.client.current_scrollview[name]) {

			color = '#ad2c31';

		} 

		else {

			color = '#490202';

		}

		dojo.byId(name+"_scroller_status_"+i).style.backgroundColor = color;

	}

};

			

fantasy.client.scrollerScrollUp = function(name) {

	fantasy.client.scrollerView = fantasy.client.current_scrollview[name];

				

	if (fantasy.client.current_scrollview[name] == 1) {

		fantasy.client.current_scrollview[name] = dojo.byId(name+"_scroll_container").childNodes.length;

		fantasy.client.nextView = fantasy.client.current_scrollview[name];

	}

	else {

		fantasy.client.current_scrollview[name]--;

		fantasy.client.nextView = fantasy.client.current_scrollview[name];

	}

				

	for (var i=1; i<=dojo.byId(name+"_scroll_container").childNodes.length; i++) {

		if (i != fantasy.client.nextView && i != fantasy.client.scrollerView) {

			dojo.byId(name+'_view_'+i).style.visibility = 'hidden';

		}

		

		dojo.byId(name+'_view_'+fantasy.client.nextView).style.top = -fantasy.client.topics_container_height+'px';

		dojo.byId(name+'_view_'+fantasy.client.nextView).style.visibility = '';

		dojo.byId(name+'_view_'+fantasy.client.scrollerView).style.top = 0+'px';

		dojo.byId(name+'_view_'+fantasy.client.scrollerView).style.visibility = '';

	}				

				

	dojo.lfx.combine(

		dojo.lfx.html.slideBy(dojo.byId(name+'_view_'+fantasy.client.nextView), { top: fantasy.client.topics_container_height, left: 0 } , 200, 200),

		dojo.lfx.html.slideBy(dojo.byId(name+'_view_'+fantasy.client.scrollerView), { top: fantasy.client.topics_container_height, left: 0 } , 200, 200)

	).play(10);	

				

	fantasy.client.updateScrollview(name);	

};

			

fantasy.client.scrollerScrollDown = function(name) {	

	fantasy.client.scrollerView = fantasy.client.current_scrollview[name];

				

	if (fantasy.client.current_scrollview[name] == dojo.byId(name+"_scroll_container").childNodes.length) {

		fantasy.client.current_scrollview[name] = 1;

		fantasy.client.nextView = fantasy.client.current_scrollview[name];

	}

	else {

		fantasy.client.current_scrollview[name]++;

		fantasy.client.nextView = fantasy.client.current_scrollview[name];

	

	}	

				

	for (var i=1; i<=dojo.byId(name+"_scroll_container").childNodes.length; i++) {

		if (i != fantasy.client.nextView && i != fantasy.client.scrollerView) {

			dojo.byId(name+'_view_'+i).style.visibility = 'hidden';

		}

		dojo.byId(name+'_view_'+fantasy.client.nextView).style.top = fantasy.client.topics_container_height+'px';

		dojo.byId(name+'_view_'+fantasy.client.nextView).style.visibility = '';

		dojo.byId(name+'_view_'+fantasy.client.scrollerView).style.top = 0+'px';

		dojo.byId(name+'_view_'+fantasy.client.scrollerView).style.visibility = '';

	}

				

	dojo.lfx.combine(

		dojo.lfx.html.slideBy(dojo.byId(name+'_view_'+fantasy.client.nextView), { top: -fantasy.client.topics_container_height, left: 0 } , 200, 200),

		dojo.lfx.html.slideBy(dojo.byId(name+'_view_'+fantasy.client.scrollerView), { top: -fantasy.client.topics_container_height, left: 0 } , 200, 200)

	).play(10);		

				

				

	fantasy.client.updateScrollview(name);	

};



fantasy.client.loadSurveyData = function(category, is_header) {

	// Break down the widgets

	var i=0;

	

	while(dojo.byId('questions_scroll_container').hasChildNodes()){ 

		if (!fantasy.client.questionNodes[fantasy.client.currentCategory]) {

			fantasy.client.questionNodes[fantasy.client.currentCategory] = [];

		}

		fantasy.client.questionNodes[fantasy.client.currentCategory][i] = dojo.byId('questions_scroll_container').removeChild(dojo.byId('questions_scroll_container').firstChild);

		i++;

	}			

	fantasy.client.currentCategory = category;

	if (fantasy.client.cache[category] && fantasy.client.topics) {

		fantasy.client.topics = fantasy.client.cache[category].categories;

		fantasy.client.questions = fantasy.client.cache[category].questions;

		fantasy.client.currentLevel = fantasy.client.topics.level;

							

		if (!fantasy.client.activeTopics[fantasy.client.currentLevel]) {

			fantasy.client.activeTopics[fantasy.client.currentLevel] = [];

		}

		fantasy.client.activeTopics[fantasy.client.currentLevel].name = fantasy.client.topics.detail.name;

		fantasy.client.activeTopics[fantasy.client.currentLevel].id = fantasy.client.topics.detail.id; 

							

		if (fantasy.client.topics.children.length > 0) {

			fantasy.client.renderedTopics = [];

			fantasy.client.renderTopics();

			fantasy.client.renderScrollStatus("topic");					

		}		

		else {

			if (is_header !== true) {

				fantasy.client.updateActive(category);

			}						

		}

		fantasy.client.renderQuestions();		

		fantasy.client.renderScrollStatus("questions");		

	}

	else {			

		fantasy.client.cache[category] = [];

					

		bindArgs = {

			url: '/FANTASY/AjaxData/Get/?type=Questions&category='+category,

			method: 'POST',

			type: 'text/json',

			load: function(type, evaldObj) 

			{ 

				eval("var decoded_data = "+evaldObj);

				fantasy.client.cache[category].questions = decoded_data;

				fantasy.client.questions = fantasy.client.cache[category].questions;

					

				fantasy.client.renderQuestions();		

				fantasy.client.renderScrollStatus("questions");

			}			

		};

					

		dojo.io.bind(bindArgs);		

					

		bindArgs = {

			url: '/FANTASY/AjaxData/Get/?type=Categories&mode=js&node='+category,

			method: 'POST',

			type: 'text/json',

			load: function(type, evaldObj) 

			{ 

				eval("var decoded_data = "+evaldObj);

				fantasy.client.cache[category].categories = decoded_data;

							

				fantasy.client.topics = decoded_data;

				fantasy.client.currentLevel = fantasy.client.topics.level;

							

				if (!fantasy.client.activeTopics[fantasy.client.currentLevel]) {

					fantasy.client.activeTopics[fantasy.client.currentLevel] = [];

				}

				fantasy.client.activeTopics[fantasy.client.currentLevel].name = fantasy.client.topics.detail.name;

				fantasy.client.activeTopics[fantasy.client.currentLevel].id = fantasy.client.topics.detail.id; 

							

				if (fantasy.client.topics.children.length > 0) {

					fantasy.client.renderedTopics = [];

					fantasy.client.renderTopics();

					fantasy.client.renderScrollStatus("topic");		

				}	

				else {

					if (is_header !== true) {

						fantasy.client.updateActive(category);

					}

				}									

			}			

		};

					

		dojo.io.bind(bindArgs);		

	}							

};		

			

fantasy.client.renderQuestions = function() {

	super_container = dojo.byId('questions_scroll_container');



	if (fantasy.client.questionNodes[fantasy.client.currentCategory] && fantasy.client.questionNodes[fantasy.client.currentCategory].length > 0) {

		for (i=0; i < fantasy.client.questionNodes[fantasy.client.currentCategory].length; i++) {

			super_container.appendChild(fantasy.client.questionNodes[fantasy.client.currentCategory][i]);

		}

		return;

	}

			

	question_height = 0;

				

	view = 1;

	element_container = document.createElement('div');

	

	//dojo.widget.createWidget("ContentPane", {id: 'questions_view_'+fantasy.client.currentCategory+view}, element_container); 									

	element_container.style.height = fantasy.client.questions_container_height+'px';

	element_container.style.width = fantasy.client.questions_container_width+'px';

	element_container.setAttribute('id','questions_view_'+view);	

	dojo.html.setClass(element_container, 'scroller_view');	

	super_container.appendChild(element_container);		

		

	if (fantasy.client.questions.length == 0) {

		question_container = contentContainer = fantasy.client.createRounded('rounded_medium', 'no_questions');

		element_container.appendChild(question_container);

		

		dojo.byId('no_questions').innerHTML = "Click on the buttons to the left to see the questions related to each topic. <p>If you want to go back to the four main topics 'Fetish, S&M, Role Play and Sexual Behaviour', click on the little squares above or on the 'Overview' button below.</p>"; 

	}

	else {

		for (var i in fantasy.client.questions) {

			q_one = null;

			q_two = null;

			q_three = null;

			height = 0;

			question_container = null;

			

			if (fantasy.client.questions[i].question_one_id !== null) {

				q_one = document.createElement('tr');

				dojo.html.setClass(q_one, 'question_content');

						

				contentCol = document.createElement('td');

				dojo.html.setClass(contentCol, 'question_content_text');

				contentCol.innerHTML = fantasy.client.questions[i].question_one;

							

				checkbox_container = document.createElement('td');

				checkbox_container.setAttribute('valign', 'top');

				dojo.html.setClass(checkbox_container, 'question_content_checkbox');

				var checkbox = dojo.widget.createWidget("Checkbox", {id: 'question_one_'+i, value: 'question_one_'+i, templateCssString: null, templateCssPath: '/css/Checkbox.css'}); 							

					

				callback = fantasy.client.setMatch( 'question_one_'+i );

				//dojo.event.connect(checkbox, 'onclick', callback);

				checkbox.onClick = callback;						

							

				checkbox_container.appendChild(checkbox.domNode);

								

				q_one.appendChild(checkbox_container);

				q_one.appendChild(contentCol);		

			}

			if (fantasy.client.questions[i].question_two_id !== null) {

				q_two = document.createElement('tr');

				dojo.html.setClass(q_two, 'question_content');

							

				contentCol = document.createElement('td');

				dojo.html.setClass(contentCol, 'question_content_text');

				contentCol.innerHTML = fantasy.client.questions[i].question_two;

							

				checkbox_container = document.createElement('td');

				checkbox_container.setAttribute('valign', 'top');

				dojo.html.setClass(checkbox_container, 'question_content_checkbox');

				var checkbox = dojo.widget.createWidget("Checkbox", {id: 'question_two_'+i, value: 'question_two_'+i, templateCssString: null, templateCssPath: '/css/Checkbox.css'}); 							

							

				callback = fantasy.client.setMatch( 'question_two_'+i );

				checkbox.onClick = callback;						

							

				checkbox_container.appendChild(checkbox.domNode);

						

				q_two.appendChild(checkbox_container);

				q_two.appendChild(contentCol);

			}

			if (fantasy.client.questions[i].question_three_id !== null) {

				q_three = document.createElement('tr');

				dojo.html.setClass(q_three, 'question_content');

							

				contentCol = document.createElement('td');

				dojo.html.setClass(contentCol, 'question_content_text');

				contentCol.innerHTML = fantasy.client.questions[i].question_three;

							

				checkbox_container = document.createElement('td');

				checkbox_container.setAttribute('valign', 'top');

				dojo.html.setClass(checkbox_container, 'question_content_checkbox');

				var checkbox = dojo.widget.createWidget("Checkbox", {id: 'question_three_'+i, value: 'question_three_'+i, templateCssString: null, templateCssPath: '/css/Checkbox.css'}); 							

							

				callback = fantasy.client.setMatch( 'question_three_'+i );

				checkbox.onClick = callback;						

							

				checkbox_container.appendChild(checkbox.domNode);

							

				q_three.appendChild(checkbox_container);

				q_three.appendChild(contentCol);

			}

					

			if (q_one || q_two || q_three) {

				

				top_border = document.createElement('div');

				dojo.html.setClass(top_border, 'question_border_top');

							

				question_table = document.createElement('table');

				

				tablebody = document.createElement('tbody');

				tablehead = document.createElement('thead');

				tablefoot = document.createElement('tfoot');

						

				if (q_one) {

					tablebody.appendChild(q_one);

				}

				if (q_two) {

					tablebody.appendChild(q_two);

				}

				if (q_three) {

					tablebody.appendChild(q_three);

				}

				

				question_table.appendChild(tablehead);

				question_table.appendChild(tablefoot);

				question_table.appendChild(tablebody);

				

				question_container = document.createElement('div');

				

				dojo.html.setClass(question_container, 'question_container');

				question_container.appendChild(top_border);

				

				question_container.appendChild(question_table);

				bottom_border = document.createElement('div');

				dojo.html.setClass(bottom_border, 'question_border_bottom');

						

				question_container.appendChild(bottom_border);

			}

			if (question_container) {

				tmp_container = question_container.cloneNode(true);

					

				dojo.byId('get_height').style.width = fantasy.client.questions_container_width+'px';

				dojo.byId('get_height').appendChild(tmp_container);

							

				obj_height = dojo.html.getMarginBox(dojo.byId('get_height'));

				while(dojo.byId("get_height").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId("get_height").firstChild); }

							

				height = obj_height.height;

				question_height = question_height + height;

				if (question_height <= fantasy.client.questions_container_height) {

					element_container.appendChild(question_container);

				}

				else {

					question_height = height;

					view++;

										

					element_container = document.createElement('div');

					//dojo.widget.createWidget("ContentPane", {id: 'questions_view_'+fantasy.client.currentCategory+view}, element_container); 									

					element_container.style.height = fantasy.client.questions_container_height+'px';									

					element_container.style.visibility = 'hidden';

					element_container.style.height = fantasy.client.questions_container_height+'px';

					element_container.style.width = fantasy.client.questions_container_width+'px';	

					element_container.setAttribute('id','questions_view_'+view);

					dojo.html.setClass(element_container, 'scroller_view');	

					super_container.appendChild(element_container);					

								

					element_container.appendChild(question_container);

				}

			}

		}

	}

};

			

fantasy.client.setMatch = function(id) {

	return function() {

		if (fantasy.client.selectedMatches[id]) {

			fantasy.client.questionCounter--;

			delete fantasy.client.selectedMatches[id];

		}

		else {

			fantasy.client.questionCounter++;

			array = id.split('_');

			arr_id = array[2];

			key = array[0]+'_'+array[1];					

			fantasy.client.selectedMatches[id] = fantasy.client.questions[arr_id][key];

		}

	};

};

			

fantasy.client.updateActive = function(topic) {

	for (var i in fantasy.client.renderedTopics) {

		topicId = i;

					

		if (topic == topicId) {

			dojo.html.setClass(dojo.byId('topic_link_'+topicId), 'topic_act');

		}

		else {

			dojo.html.setClass(dojo.byId('topic_link_'+topicId), 'topic_inact');

		}

	}

};

			

fantasy.client.renderTopics = function() {

	super_container = dojo.byId('topic_scroll_container');

	while(dojo.byId("topic_scroll_container").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId("topic_scroll_container").firstChild); }

	while(dojo.byId("topic_scroll_header").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId("topic_scroll_header").firstChild); }

				

	// get the actual container height

	element_space = fantasy.client.max_elements-fantasy.client.currentLevel;

				

	for (var i=0; i<fantasy.client.currentLevel; i++) {

		j=i+1;

		field = document.createElement('div');

		field.style.height = fantasy.client.element_height+'px';

		field.style.backgroundColor = '';

		

		contentLink = document.createElement('a');

		

		contentLink.innerHTML = fantasy.client.activeTopics[j].name;

		dojo.html.setClass(contentLink, 'header_text');

		dojo.html.addClass(contentLink, 'topic_header');

						

		field.appendChild(contentLink);	

					

					

		field.setAttribute('onclick','fantasy.client.loadSurveyData('+fantasy.client.activeTopics[j].id+', true)');			

					

		field.setAttribute('id','header_'+fantasy.client.activeTopics[j].id);

			

		dojo.byId('topic_scroll_header').appendChild(field);			

	}

				

	view = 1;

	element_container = document.createElement('div');

	element_container.style.height = fantasy.client.topics_container_height+'px';

	element_container.style.width = fantasy.client.topics_container_width+'px';

	element_container.setAttribute('id','topic_view_'+view);

	dojo.html.setClass(element_container, 'scroller_view');	

	super_container.appendChild(element_container);

				

	// render initial empty fields as placeholders for headers

	for (var x=0; x<fantasy.client.currentLevel; x++) {

		field = document.createElement('div');

		field.style.height = fantasy.client.element_height+'px';

					

		element_container.appendChild(field);				

	}				

	

	for (i=1; i<=fantasy.client.topics.children.length; i++) {

		j = i-1;

		topicId = fantasy.client.topics.children[j].id;

				

		fantasy.client.renderedTopics[topicId] = true;

					

		field = document.createElement('div');

		field.style.height = fantasy.client.element_height+'px';

		//field.style.backgroundColor = '';

					

		contentLink = document.createElement('a');

		contentLink.innerHTML = fantasy.client.topics.children[j].name;

		contentLink.setAttribute('id','topic_link_'+topicId);

		dojo.html.setClass(contentLink, 'topic_text');

					

		field.appendChild(contentLink);

					

		field.setAttribute('id','topic_'+topicId);

		

		var callbackFunc = fantasy.client.setTopic(topicId);

		dojo.event.connect(field, "onclick", callbackFunc);

		dojo.html.setClass(field, 'topic_inact');

					

		element_container.appendChild(field); 

					

		if (i%element_space === 0) {		

			view++;

			element_container = document.createElement('div');

			element_container.style.height = fantasy.client.topics_container_height+'px';

			element_container.setAttribute('id','topic_view_'+view);								

			element_container.style.visibility = 'hidden';

			element_container.style.height = fantasy.client.topics_container_height+'px';

			element_container.style.width = fantasy.client.topics_container_width+'px';

			dojo.html.setClass(element_container, 'scroller_view');		

			super_container.appendChild(element_container);

						

			// render initial empty fields as placeholders for headers

			for (x=0; x<fantasy.client.currentLevel; x++) {

				field = document.createElement('div');

				field.style.height = fantasy.client.element_height+'px';

						

				element_container.appendChild(field);				

			}											

		}

	}

	if (fantasy.client.topics.length%element_space !== 0) {

		super_container.appendChild(element_container);

	}

};



fantasy.client.setTopic = function(topicId) {

	return function(evt) {

		fantasy.client.loadSurveyData(topicId, false);

	};

};

			

renderTopicHeaders = function() {

			

};

fantasy.client.startCurrentPage = 'new_one';

fantasy.client.enterQuestionnaire = function(type, form) {

	if (type == 'new_init') {
		dojo.byId('start_init').style.display='';
		dojo.byId('start_partner').style.display='none';
		
		fantasy.client.startCurrentPage = 'new_one';
	}
	
	else if (type == 'new_one' || fantasy.client.startCurrentPage == 'new_one') {

		if (dojo.byId('name').value.length === 0) {

			position = dojo.html.getAbsolutePosition(dojo.byId('name'),true);

			box = dojo.html.getBorderBox(dojo.byId('name'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;
			
			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please enter a name. <br /><br />Use a name your partner knows so when he/her gets the invitation email it is clear who you are.';

			dojo.byId('helping_dialog').style.display = '';

			return false;

		}

		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(dojo.byId('email').value)) {

			position = dojo.html.getAbsolutePosition(dojo.byId('email'),true);

			box = dojo.html.getBorderBox(dojo.byId('email'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please enter an email<br /><br />We don\'t give your data away to third parties! The email is required so only you can access the fantasy survey.<br />If you are worried that we save your data just use one of the public free email services.';

			dojo.byId('helping_dialog').style.display = '';

			return;

		}
		
		dojo.byId('start_init').style.display='none';
		dojo.byId('start_partner').style.display='';
		dojo.byId('name_partner').focus();
		dojo.byId('start_password').style.display='none';
		
		fantasy.client.startCurrentPage = 'new_two';
		
	}
	else if (type == 'new_two' || fantasy.client.startCurrentPage == 'new_two') {
		
		dojo.byId('start_partner').style.display='';
		dojo.byId('start_password').style.display='none';	
	

		if (dojo.byId('name_partner').value.length === 0) {

			position = dojo.html.getAbsolutePosition(dojo.byId('name_partner'),true);

			box = dojo.html.getBorderBox(dojo.byId('name_partner'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please enter your partners name. <br />';

			dojo.byId('helping_dialog').style.display = '';

			return;

		}

		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(dojo.byId('email_partner').value)) {

			position = dojo.html.getAbsolutePosition(dojo.byId('email_partner'),true);

			box = dojo.html.getBorderBox(dojo.byId('email_partner'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please enter an email<br /><br />We don\'t give your data away to third parties! The email is required so only you can access the fantasy survey.<br />If you are worried that we save your data just use one of the public free email services.';

			dojo.byId('helping_dialog').style.display = '';

			return;

		}	
		
		if (dojo.byId('email_partner').value == dojo.byId('email').value) {

			position = dojo.html.getAbsolutePosition(dojo.byId('email_partner'),true);

			box = dojo.html.getBorderBox(dojo.byId('email_partner'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please enter a different email<br /><br />Your partners email can\'t be the same as your email.';

			dojo.byId('helping_dialog').style.display = '';

			return;

		}
		
		dojo.byId('start_partner').style.display='none';
		dojo.byId('start_password').style.display='';
		
		dojo.byId('password').focus();
		fantasy.client.startCurrentPage = 'new_three';
	}
	else if (type == 'new_three' || fantasy.client.startCurrentPage == 'new_three') {

		if (dojo.byId('password').value.length === 0){

			position = dojo.html.getAbsolutePosition(dojo.byId('password'),true);

			box = dojo.html.getBorderBox(dojo.byId('password'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please provide a password.';

			dojo.byId('helping_dialog').style.display = '';	

			return (true);

		}
		

		dojo.byId('helping_dialog').style.display = 'none';	

			
		
		form.submit();
		
		dojo.byId('start_password').style.display = 'none';
	
		dojo.byId('alert_loading').style.display = '';			
	}

	
	dojo.byId('helping_dialog').style.display = 'none';
};

fantasy.client.joinQuestionnaire = function(form) {

	dojo.byId('helping_dialog').style.display = 'none';
	
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(dojo.byId('join_email').value)) {

			position = dojo.html.getAbsolutePosition(dojo.byId('join_email'),true);

			box = dojo.html.getBorderBox(dojo.byId('join_email'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please enter your email.';

			dojo.byId('helping_dialog').style.display = '';

			return;

		}	

		if (dojo.byId('join_password').value.length === 0) {

			position = dojo.html.getAbsolutePosition(dojo.byId('join_password'),true);

			box = dojo.html.getBorderBox(dojo.byId('join_password'));

			

			xPos = position.left + box.width+15;

			yPos = position.top-5;

			dojo.byId('helping_dialog').style.top = yPos+'px';

			dojo.byId('helping_dialog').style.left = xPos+'px';

			dojo.byId('notice_content').innerHTML = 'Please the survey passsword';

			dojo.byId('helping_dialog').style.display = '';

			return;

		}

							
		
		form.submit();
		
		dojo.byId('alert_existing').style.display = 'none';
	
		dojo.byId('alert_loading').style.display = '';	
	
	
	dojo.byId('helping_dialog').style.display = 'none';
};





fantasy.client.toggleSurveyJoin = function(type) {

	dojo.byId('helping_dialog').style.display = 'none';

	dojo.byId('alert_start').style.display = '';

	dojo.byId('alert_loading').style.display = 'none';

	dojo.html.setClass(dojo.byId('survey-link-start'), 'rounded-tab-li');
	dojo.html.setClass(dojo.byId('survey-link-join'), 'rounded-tab-li');
	dojo.html.setClass(dojo.byId('survey-link-result'), 'rounded-tab-li');		
	
	if (type == 'new') {

		dojo.html.addClass(dojo.byId('survey-link-start'), 'tab-act');
		dojo.html.addClass(dojo.byId('survey-link-join'), 'tab-inact');
		dojo.html.addClass(dojo.byId('survey-link-result'), 'tab-inact');
		
		dojo.byId('alert_existing').style.display = 'none';

		dojo.byId('alert_new').style.display = '';

		dojo.byId('alert_result').style.display = 'none';

	}

	else if (type == 'result' ) {
		
		dojo.html.addClass(dojo.byId('survey-link-start'), 'tab-inact');
		dojo.html.addClass(dojo.byId('survey-link-join'), 'tab-inact');
		dojo.html.addClass(dojo.byId('survey-link-result'), 'tab-act');
		
		dojo.byId('alert_existing').style.display = 'none';

		dojo.byId('alert_new').style.display = 'none';

		dojo.byId('alert_result').style.display = '';

	}

	else {

		dojo.html.addClass(dojo.byId('survey-link-start'), 'tab-inact');
		dojo.html.addClass(dojo.byId('survey-link-join'), 'tab-act');
		dojo.html.addClass(dojo.byId('survey-link-result'), 'tab-inact');

		dojo.byId('alert_existing').style.display = '';

		dojo.byId('alert_new').style.display = 'none';

		dojo.byId('alert_result').style.display = 'none';

	}

};



fantasy.client.menuContent = [];

fantasy.client.menuContent['content_about'] = 1;

fantasy.client.menuContent['content_home'] = 1;

fantasy.client.menuContent['content_privacy'] = 1;

fantasy.client.menuContent['content_howitworks'] = 1;

fantasy.client.triggerContent = function(type) {

	dojo.byId('helping_dialog').style.display = 'none';

	for (key in fantasy.client.menuContent) {
		
		dojo.html.setClass(dojo.byId('li-'+key), 'rounded-tab-li');
		if (key == type) {

			dojo.html.addClass(dojo.byId('li-'+key), 'tab-act');

			dojo.byId(key).style.display = '';

		}

		else {

			dojo.html.addClass(dojo.byId('li-'+key), 'tab-inact');

			dojo.byId(key).style.display = 'none';

		}

	}

};



// Form emailing

fantasy.client.sending = 0;

fantasy.client.contactForm = function() {

	if (fantasy.client.sending == 0) {

		fantasy.client.sending = 1;

	}

	else {

		alert('Still sending emails!');

		return;

	}

	

	sender_email = dojo.byId('sender_email').value;	

	sender = dojo.byId('sender').value;

	message = dojo.byId('friend_message').value;	

	

	if (sender_email.length == 0 || sender.length == 0 || message.length == 0) {

		alert('Please fill in all the fields!');

		fantasy.client.sending = 0;

		return;

	}

	

	var bindArgs = {

		url: '/FANTASY/Messenger/Send/',

		method: 'POST',

		type: 'text/json',

		load: function(type, evaldObj) 

		{ 

			eval("var decoded_data = "+evaldObj);	

			fantasy.client.sending = 0;

			

			alert('Thank you for contacting us!');

			

			dojo.byId('sender').value = '';

			dojo.byId('sender_email').value = '';

			dojo.byId('friend_message').value = '';		

		},

		content: {message: message, sender: sender, sender_email: sender_email}	

	};			



	// Trying to create survey

	dojo.io.bind(bindArgs);		

};	

// Form emailing

fantasy.client.sending = 0;

fantasy.client.suggestSite = function() {

	if (fantasy.client.sending == 0) {

		fantasy.client.sending = 1;

	}

	else {

		alert('Still sending emails!');

		return;

	}

	

	sender_email = dojo.byId('sender_email').value;	

	sender = dojo.byId('sender').value;
	site_title = dojo.byId('sender_sitetitle').value;
	site_url = dojo.byId('sender_siteurl').value;
	site_bannerurl = dojo.byId('sender_bannerurl').value;
	site_recurl = dojo.byId('sender_recurl').value;

	message = dojo.byId('friend_message').value;	

	var message_str = 'NEW WEBSITE: '+site_title+"\nSENDER: "+sender+"\nSENDER EMAIL: "+sender_email+"\nURL: "+site_url+"\nBANNER: "+site_bannerurl+"\nRECIPROCAL LINK: "+site_recurl+"\nMESSAGE:\n"+message;

	if (sender_email.length == 0 || sender.length == 0 || message.length == 0
		|| site_title.length == 0 || site_url.length == 0) {

		alert('Please fill in all the fields!');

		fantasy.client.sending = 0;

		return;

	}

	

	var bindArgs = {

		url: '/FANTASY/Messenger/Send/',

		method: 'POST',

		type: 'text/json',

		load: function(type, evaldObj) 

		{ 

			eval("var decoded_data = "+evaldObj);	

			fantasy.client.sending = 0;

			

			alert('Thank you for submitting your website! After we have reviewed your website we will contact you.');

			

			dojo.byId('sender').value = '';

			dojo.byId('sender_email').value = '';

			dojo.byId('friend_message').value = '';	
			dojo.byId('sender_sitetitle').value = '';
			dojo.byId('sender_siteurl').value = '';
			dojo.byId('sender_bannerurl').value = '';
			dojo.byId('sender_recurl').value = '';	

		},

		content: {message: message_str, sender: sender, sender_email: sender_email}	

	};			



	// Trying to create survey

	dojo.io.bind(bindArgs);		

};	

	

fantasy.client.toggleSurveyStatus = function(survey_id, token, closed) {

	dojo.byId('helping_dialog').style.display = 'none';

	

	if (closed == '0') {

		fantasy.client.toggleInOpenSurvey(survey_id, token);

	}

	else {

		fantasy.client.toggleInClosedSurvey();

	}

};



fantasy.client.toggleInOpenSurvey = function(id, token) {
	dojo.byId('close_error').style.display = 'none';
	
	dojo.byId('error_msg').innerHTML = 'You started a survey but didn\'t close it. Please close it first to continue!<br /><br /><a href="/Fantasy/Survey/Join/" class="notice_txt"  >Click here to continue the alert</a>';						

	dojo.byId('alert_error').style.display = '';

};



fantasy.client.toggleInClosedSurvey = function() {	
	dojo.byId('close_error').style.display = 'none';			

	dojo.byId('error_msg').innerHTML = 'You are currently in a survey and this survey has to be filled in by your partner first.<br /><br /><a href="javascript: void(0);" onclick="fantasy.client.toggleSurveyJoin(\'join\');" class="notice_txt">Click here to continue an open survey</a>';						

	dojo.byId('alert_error').style.display = '';					

};



fantasy.client.startAlert = function() {

	dojo.byId('notice_content').innerHTML = '';

	dojo.byId('helping_dialog').style.display = 'none';

	

	dojo.byId('fantasy_questions').style.display = '';

	dojo.byId('fantasy_questions_overview').style.display = 'none';

};



fantasy.client.togglePage = function(page) {

	dojo.byId('helping_dialog').style.display = 'none';

	if (page == 'result') {

		dojo.byId('fantasy_questions').style.display = 'none';

		dojo.byId('fantasy_questions_overview').style.display = 'none';

		dojo.byId('fantasy_questions_final').style.display = 'none';	

	}

	else if (page == 'alert_overview') {

		if (fantasy.client.questionCounter < 5) {

			alert('Please select at least 5 fantasies you can imagine sharing with your partner. Otherwise the chance for a match will be extremely low.');

			return;	

		}

		fantasy.client.renderQuestionOverview();

		fantasy.client.renderScrollStatus("overview");

		dojo.byId('fantasy_questions').style.display = 'none';

		dojo.byId('fantasy_questions_overview').style.display = '';

		dojo.byId('fantasy_questions_final').style.display = 'none';	

	

	}

	else if (page == 'alert_final') {

		dojo.byId('fantasy_questions').style.display = 'none';

		dojo.byId('fantasy_questions_overview').style.display = 'none';

		dojo.byId('fantasy_questions_final').style.display = '';	

	}

};



fantasy.client.renderQuestionOverview = function() {

	super_container = dojo.byId('overview_scroll_container');

	

	while (super_container.hasChildNodes()) {

		dojo.dom.destroyNode(super_container.firstChild);

	}

				

	question_height = 0;



	view = 1;

	element_container = document.createElement('div');

	if (dojo.widget.byId('overview_overview_'+view)) { dojo.widget.byId('overview_overview_'+view).destroy(); }

	element_container.style.height = fantasy.client.questionsoverview_container_height+'px';

	element_container.style.width = fantasy.client.questionsoverview_container_width+'px';

	element_container.setAttribute('id','overview_view_'+view);	

	dojo.html.setClass(element_container, 'scroller_view');	

	super_container.appendChild(element_container);		

				

	for (var i in fantasy.client.selectedMatches) {

		array = i.split('_');

		id = array[2];

		key = array[0]+'_'+array[1];

					

		result = document.createElement('tr');

		dojo.html.setClass(result, 'question_content');

							

		contentCol = document.createElement('td');

		dojo.html.setClass(contentCol, 'questionoverview_content_text');

		contentCol.innerHTML = fantasy.client.selectedMatches[i];

												

		result.appendChild(contentCol);

						

		question_container = document.createElement('div');

		dojo.html.setClass(question_container, 'question_container');

		top_border = document.createElement('div');

		dojo.html.setClass(top_border, 'question_border_top');

							

		question_table = document.createElement('table');

		

		

		tablebody = document.createElement('tbody');

		tablehead = document.createElement('thead');

		tablefoot = document.createElement('tfoot');

					

		tablebody.appendChild(result);

		

		question_table.appendChild(tablehead);

		question_table.appendChild(tablefoot);

		question_table.appendChild(tablebody);

						

		question_container.appendChild(top_border);

												

		question_container.appendChild(question_table);

							

		bottom_border = document.createElement('div');

		dojo.html.setClass(bottom_border, 'question_border_bottom');

							

		question_container.appendChild(bottom_border);

						

		question_clone = question_container.cloneNode(true);

		

		dojo.byId('get_height').style.width = fantasy.client.questionsoverview_container_width+'px';

		dojo.byId('get_height').appendChild(question_clone);				

		obj_height = dojo.html.getMarginBox(dojo.byId('get_height'));

		while(dojo.byId("get_height").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId("get_height").firstChild); }

							

		height = obj_height.height;

		

		question_height = question_height + height;

		

		if (question_height <= fantasy.client.questionsoverview_container_height) {

			element_container.appendChild(question_container);

		}

		else {

			question_height = height;

			view++;

										

			element_container = document.createElement('div');

			if (dojo.widget.byId('overview_overview_'+view)) { dojo.widget.byId('overview_overview_'+view).destroy(); }

			element_container.style.height = fantasy.client.questionsoverview_container_height+'px';									

			element_container.style.visibility = 'hidden';

			element_container.style.height = fantasy.client.questionsoverview_container_height+'px';

			element_container.style.width = fantasy.client.questionsoverview_container_width+'px';

			element_container.setAttribute('id','overview_view_'+view);

			dojo.html.setClass(element_container, 'scroller_view');	

			super_container.appendChild(element_container);					

							

			element_container.appendChild(question_container);

		}

	}	

};


fantasy.client.isSendingAlert = 0;


fantasy.client.submitAlert = function() {
	if (fantasy.client.isSendingAlert == 1) {
		alert('You are still submitting the current alert! Please be patient.');
		return;
	}

	if (fantasy.client.questionCounter < 5) {

		alert('Please select at least 5 fantasies you can imagine sharing with your partner. Otherwise the chance for a match will be extremely low.');

		return;	

	}

	// generate post values

	contentMatches = [];

	for (var i in fantasy.client.selectedMatches) {

		contentMatches[i] = 'checked';

	}

	fantasy.client.isSendingAlert = 1;

	var bindArgs = {

		url: '/FANTASY/Alert/Submit/',

		method: 'POST',

		type: 'text/json',

		load: function(type, evaldObj) 

		{ 

			eval("var decoded_data = "+evaldObj);	

			fantasy.client.isSendingAlert = 0;	

			if (decoded_data.RESPONSE_TYPE == 'SUCCESS') {	

				fantasy.client.togglePage('alert_final');

			}

			else if (decoded_data.RESPONSE_TYPE == 'ERROR') {

				alert('Oooops! There was an error!');

			}

		}			

	};			

	bindArgs.content = contentMatches;



	// Trying to create survey

	dojo.io.bind(bindArgs);		

};



fantasy.client.viewResult = function(form) {

	dojo.byId('helping_dialog').style.display = 'none';

	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(dojo.byId('result_email').value)) {

		position = dojo.html.getAbsolutePosition(dojo.byId('result_email'),true);

		box = dojo.html.getBorderBox(dojo.byId('result_email'));

			

		xPos = position.left + box.width+15;

		yPos = position.top-5;

		dojo.byId('helping_dialog').style.top = yPos+'px';

		dojo.byId('helping_dialog').style.left = xPos+'px';

		dojo.byId('notice_content').innerHTML = 'Please enter your email.';

		dojo.byId('helping_dialog').style.display = '';

		return;

	}	

	if (dojo.byId('result_password').value.length === 0) {

		position = dojo.html.getAbsolutePosition(dojo.byId('result_password'),true);

		box = dojo.html.getBorderBox(dojo.byId('result_password'));

		

		xPos = position.left + box.width+15;

		yPos = position.top-5;

		dojo.byId('helping_dialog').style.top = yPos+'px';

		dojo.byId('helping_dialog').style.left = xPos+'px';

		dojo.byId('notice_content').innerHTML = 'Please the survey passsword';

		dojo.byId('helping_dialog').style.display = '';

		return;

	}	

	if (dojo.byId('result_token').value.length === 0) {

		position = dojo.html.getAbsolutePosition(dojo.byId('result_token'),true);

		box = dojo.html.getBorderBox(dojo.byId('result_token'));

			

		xPos = position.left + box.width+15;

		yPos = position.top-5;

		dojo.byId('helping_dialog').style.top = yPos+'px';

		dojo.byId('helping_dialog').style.left = xPos+'px';

		dojo.byId('notice_content').innerHTML = 'Please enter the survey token';

		dojo.byId('helping_dialog').style.display = '';

		return;

	}

	dojo.byId('alert_result').style.display = 'none';
	
	dojo.byId('alert_loading').style.display = '';	

	form.submit();	

};



fantasy.client.fillResult = function(response) {

	var i =1;

	for (member in response.members) {

		dojo.byId('user_'+i).innerHTML = response.members[member];

		i++;

	}

	

	if (response.percentage[1]) {

		dojo.byId('square_one_result_content').innerHTML = response.percentage[1]+'%';

	}

	if (response.percentage[2]) {

		dojo.byId('square_three_result_content').innerHTML = response.percentage[2]+'%';

	}

	if (response.percentage[3]) {

		dojo.byId('square_four_result_content').innerHTML = response.percentage[3]+'%';

	}

	if (response.percentage[4]) {

		dojo.byId('square_two_result_content').innerHTML = response.percentage[4]+'%';

	}

};



fantasy.client.createRounded = function(css_class, content_id) {

	roundedContainer = document.createElement('div');

	

	dojo.html.setClass(roundedContainer, css_class);

	

	contentRounded = document.createElement('div');

	dojo.html.setClass(contentRounded, 'content');

	dojo.html.addClass(contentRounded, 'p');

	

	topBorder = document.createElement('div');

	dojo.html.setClass(topBorder, 't');

	

	contentRounded.appendChild(topBorder);

	content_container = document.createElement('div');

	content_container.setAttribute('id', content_id);

	contentRounded.appendChild(content_container);

	

	

	//div = document.createElement('div');

	//dojo.html.setClass(div, 'clearfix');

			

	//contentRounded.appendChild(div);

	

	bottomBorder = document.createElement('div');

	dojo.html.setClass(bottomBorder, 'b');

	

	bottom_container = document.createElement('div');

	bottomBorder.appendChild(bottom_container);

	

	roundedContainer.appendChild(contentRounded);

	roundedContainer.appendChild(bottomBorder);

	

	return roundedContainer;

};



fantasy.client.createResultAdvice = function(id, result, image) {

	if (result.length == 0) {

		return;

	}

	adviceContainer = document.createElement('div');

	

	header = document.createElement('h3');

	img = document.createElement('img');

	img.src = image;

	header.appendChild(img);

	adviceContainer.appendChild(header);

	

	rounded = fantasy.client.createRounded('rounded_medium', id);

	adviceContainer.appendChild(rounded);

	

	dojo.byId('result_right_advice').appendChild(adviceContainer);

	

	p_spacer = document.createElement('p');

	

	dojo.byId('result_right_advice').appendChild(p_spacer);

	

	for (var i=0; i<result.length; i++) {

		contentContainer = fantasy.client.createRounded('rounded_dark', id+'_'+i);

		dojo.html.setStyle(contentContainer, 'margin-top', '5px');

		dojo.byId(id).appendChild(contentContainer);

			

		if (result[i].Name.length > 0) {

			header = '<h4>'+result[i].Name+'</h4>';

		}

		contentContainer = header + result[i].Content;

		if (result[i].Link && result[i].Link.length > 0) {

			readmore_link = '<p><a href="/Fantasy/Links/Go/'+result[i].Id+'" target="_blank" >read more...</a></p>';

				

			contentContainer = contentContainer + readmore_link;

		}

		dojo.byId(id+'_'+i).innerHTML = contentContainer;

		div = document.createElement('div');

		//dojo.html.setClass(div, 'clearfix');

					

		dojo.byId(id).appendChild(div);

	}

	p_spacer = document.createElement('p');

	dojo.byId(id).appendChild(p_spacer);

};



// Scroller



var arr_Elements = [];

var time, pos;

var dir;



function Scroll_DN(layer) {

	if (!arr_Elements[layer])

 	{

 		arr_Elements[layer] = [];

		arr_Elements[layer].pos = 0;	

	}

	arr_Elements[layer].pos = arr_Elements[layer].pos-3;



	pos = arr_Elements[layer].pos;

	elementHeight = dojo.html.getMarginBox(dojo.byId(layer)).height;

	viewportHeight = dojo.html.getPaddingBox(dojo.byId(layer+'_visible')).height;

	

	scrollheight = elementHeight-viewportHeight;

	if (pos > -scrollheight) {

		document.getElementById(layer).style.top=pos+"px";

		time = setTimeout("Scroll_DN('"+layer+"')", 50);

	}

}



function Scroll_Stop() {

	if (time) { clearTimeout(time) };

}



function Scroll_UP(layer) {

	if (!arr_Elements[layer]) {

 		arr_Elements[layer] = [];

 		arr_Elements[layer].pos = 0;

 	}

 	arr_Elements[layer].pos = arr_Elements[layer].pos+3;



 	pos = arr_Elements[layer].pos;



 	if (pos <= 0) {

 		document.getElementById(layer).style.top=pos+"px";

		

		if (pos < 2000) {

 			time = setTimeout("Scroll_UP('"+layer+"')", 50);

 		}

 	}

}



fantasy.client.loadResults = function(id, parent) {
	matches = fantasy.client.results.questions;

	almost = matches.almost;

	activemember = fantasy.client.results.active_member;

	current_matches = [];
	almost_matches = [];

	if (matches && matches[activemember] && matches[activemember][parent]) {

		current_matches = matches[activemember][parent];

	}

	if (almost && almost[parent]) {

		almost_matches = almost[parent];

	}

	// Delete old overview and categopries
	while(dojo.byId("results_container").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId("results_container").firstChild); }
	while(dojo.byId("directory-subtopics-list").hasChildNodes()){ dojo.dom.destroyNode(dojo.byId("directory-subtopics-list").firstChild); }

	cat_container = [];

	// now we either have questions within the parent category or other categories
	cnt = 0;

	total_cnt = 0;
	
	arr_topics = [];
	arr_results = [];
	
	for (i in current_matches) {
		for (j=0; j<current_matches[i].length; j++) {	
			if (i == id) {
				arr_results[arr_results.length] = current_matches[i][j];
			}
			
			if (!arr_topics[current_matches[i][j].cat_id]) {
				arr_topics[current_matches[i][j].cat_id] = current_matches[i][j].cat_name;
			}
		}
	}
	
	for (i in arr_results) {
		total_cnt++;
		if (cnt === 0) {

			headerElement = document.createElement('h3');

			headerElement.innerHTML = 'Your exact matches';

			dojo.byId('results_container').appendChild(headerElement);

				

			cnt ++;

		}
		
		headerContainer = fantasy.client.createRounded('rounded_light', 'result_cat_'+arr_results[i].question_id);
		dojo.byId('results_container').appendChild(headerContainer);
		
		question_table = document.createElement('table');
		
		tablebody = document.createElement('tbody');
		
		table_t = document.createElement('tr');
		table_td_1 = document.createElement('td');
		table_td_1.setAttribute('valign', 'middle');
		dojo.html.setClass(table_td_1, 'directory-question');
		table_td_1.innerHTML = arr_results[i]['q_text'];
		
		table_td_2 = document.createElement('td');
		container_div = document.createElement('div');
		container_div.setAttribute('id', 'question-content-icons-'+arr_results[i].question_id);
		dojo.html.setClass(container_div, 'question-content-links');
		table_td_2.appendChild(container_div);
		
		table_t.appendChild(table_td_1);
		table_t.appendChild(table_td_2);

		tablebody.appendChild(table_t);
		
		tablehead = document.createElement('thead');

		tablefoot = document.createElement('tfoot');

		
		question_table.appendChild(tablehead);

		question_table.appendChild(tablefoot);

		question_table.appendChild(tablebody);

		dojo.byId('result_cat_'+arr_results[i].question_id).appendChild(question_table);
		
		ressource_div = document.createElement('div');
		ressource_div.setAttribute('id', 'ressources_'+arr_results[i].question_id);

		dojo.byId('result_cat_'+arr_results[i].question_id).appendChild(ressource_div);	
		
		fantasy.client.loadResultRessources(arr_results[i].question_id);	
	}
	
	cnt = 0;
	
	arr_results = [];
	
	for (i in almost_matches) {
		for (j=0; j<almost_matches[i].length; j++) {	
			if (i == id) {
				arr_results[arr_results.length] = almost_matches[i][j];
			}
			
			if (!arr_topics[almost_matches[i][j].cat_id]) {
				arr_topics[almost_matches[i][j].cat_id] = almost_matches[i][j].cat_name;
			}
		}
	}

	catalmost_container = [];

	cnt = 0;
	
	for (i in arr_results) {
		total_cnt++;

		if (cnt === 0) {

			headerElement = document.createElement('h3');

			headerElement.innerHTML = '<br />Close Match! This shows that your partner may have a similar interest.<br /> Just not precisely what you chose.';

			dojo.byId('results_container').appendChild(headerElement);
			
			cnt ++;
		}
		
		headerContainer = fantasy.client.createRounded('rounded_light', 'result_cat_'+arr_results[i].question_id);
		dojo.byId('results_container').appendChild(headerContainer);
			
		question_table = document.createElement('table');
			
		tablebody = document.createElement('tbody');
			
		table_t = document.createElement('tr');
		table_td_1 = document.createElement('td');
		table_td_1.setAttribute('valign', 'middle');
		dojo.html.setClass(table_td_1, 'directory-question');
		table_td_1.innerHTML = arr_results[i]['name'];
			
		table_td_2 = document.createElement('td');
		container_div = document.createElement('div');
		container_div.setAttribute('id', 'question-content-icons-'+arr_results[i].question_id)
		dojo.html.setClass(container_div, 'question-content-links');
		table_td_2.appendChild(container_div);
			
		table_t.appendChild(table_td_1);
		table_t.appendChild(table_td_2);

		tablebody.appendChild(table_t);
			
		tablehead = document.createElement('thead');
	
		tablefoot = document.createElement('tfoot');
		
		question_table.appendChild(tablehead);
	
		question_table.appendChild(tablefoot);
	
		question_table.appendChild(tablebody);
	
		dojo.byId('result_cat_'+arr_results[i].question_id).appendChild(question_table);
			
		ressource_div = document.createElement('div');
		ressource_div.setAttribute('id', 'ressources_'+arr_results[i].question_id);
	
		dojo.byId('result_cat_'+arr_results[i].question_id).appendChild(ressource_div);	
			
		fantasy.client.loadResultRessources(arr_results[i].question_id);	
	}	
	
	// Render topics
	for (topic in arr_topics) {
		li_t = document.createElement('li');
		div_rl = document.createElement('div');
		dojo.html.setClass(div_rl, 'topic-rounded-l');
		div_rl.innerHTML = '&nbsp;';
		div_rr = document.createElement('div');
		dojo.html.setClass(div_rr, 'topic-rounded-r');
		div_rr.innerHTML = '&nbsp;';
		
		link_c = document.createElement('a');
		link_c.setAttribute('href', 'javascript: fantasy.client.loadResults('+topic+','+parent+');');
		//link_c.setAttribute('onclick', 'fantasy.client.loadResults('+topic+','+parent+'); return false');
		span_c = document.createElement('span');
		dojo.html.setClass(span_c, 'directory-topic');
		if (id == topic) {
			span_c.innerHTML = '<strong class="p_std">'+arr_topics[topic]+'</strong>';
			
			dojo.byId('current_topic'). innerHTML = 'Results for: '+arr_topics[topic];
		}
		else {
			span_c.innerHTML = arr_topics[topic];
		}
		link_c.appendChild(span_c);
		
		li_t.appendChild(div_rl);
		li_t.appendChild(link_c);
		li_t.appendChild(div_rr);
		
		dojo.byId('directory-subtopics-list').appendChild(li_t);
	}

	if (total_cnt === 0) {

		headerElement = document.createElement('h3');

		headerElement.innerHTML = 'Please click on the sub-categories above to see the fantasies matches you have with your partner.';

		dojo.byId('results_container').appendChild(headerElement);

	}

};

fantasy.client.resultCache = [];

fantasy.client.loadResultRessources = function(cat) {

	// destroy previous content

	if (!cat) {

		cat = '';

	}

	if (fantasy.client.resultCache[cat]) {
		if (fantasy.client.resultCache[cat]['FANTASY_ICONS']) {
			dojo.byId('question-content-icons-'+cat).innerHTML = fantasy.client.resultCache[cat]['FANTASY_ICONS'];
		}
		if (fantasy.client.resultCache[cat]['RESSOURCES']) {
			dojo.byId('ressources_'+cat).innerHTML = fantasy.client.resultCache[cat]['RESSOURCES'];
		}
	}
	else {

		var bindArgs = {
	
			url: '/FANTASY/AjaxData/Get/?type=Ressources&by=cat&cat='+cat,
	
			method: 'POST',
	
			type: 'text/json',
	
			load: function(type, evaldObj) 
	
			{ 
	
				eval("var decoded_data = "+evaldObj);	
	
				fantasy.client.resultCache[cat] = decoded_data;
				
				if (decoded_data['FANTASY_ICONS']) {
					dojo.byId('question-content-icons-'+cat).innerHTML = decoded_data['FANTASY_ICONS'];
				}
				if (decoded_data['RESSOURCES']) {
					dojo.byId('ressources_'+cat).innerHTML = decoded_data['RESSOURCES'];
				}
			}			
	
		};			
	
	
	
		// Trying to create survey
	
		dojo.io.bind(bindArgs);	
	}
};



// Emailing

fantasy.client.sending = 0;

fantasy.client.inviteFriends = function() {

	if (fantasy.client.sending == 0) {

		fantasy.client.sending = 1;

	}

	else {

		alert('Still sending emails!');

		return;

	}

	

	email_1 = dojo.byId('friend_email_1').value;

	email_2 = dojo.byId('friend_email_2').value;

	email_3 = dojo.byId('friend_email_3').value;

	email_4 = dojo.byId('friend_email_4').value;

	

	sender_email = dojo.byId('sender_email').value;	

	sender = dojo.byId('sender').value;

	message = dojo.byId('friend_message').value;	

	

	var bindArgs = {

		url: '/FANTASY/Messenger/Send/',

		method: 'POST',

		type: 'text/json',

		load: function(type, evaldObj) 

		{ 

			eval("var decoded_data = "+evaldObj);	

			fantasy.client.sending = 0;

			

			dojo.byId('friend_email_1').value = '';

			dojo.byId('friend_email_2').value = '';

			dojo.byId('friend_email_3').value = '';

			dojo.byId('friend_email_4').value = '';	

			alert('Thank you! Of course you can keep inviting friends by entering more email addresses.');

		},

		content: {email_1: email_1,email_2: email_2,email_3: email_3,email_4: email_4,message: message, sender: sender, sender_email: sender_email}	

	};			



	// Trying to create survey

	dojo.io.bind(bindArgs);		

};



fantasy.client.callbackResultMatch = function(id) {

	return function() {

		fantasy.client.loadResultAdvice(id);

	}

};



// Howto



fantasy.client.howtoContent = [];

fantasy.client.howtoContent[0] = [];

fantasy.client.howtoContent[0]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[0]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/surveystart_tn.png';

fantasy.client.howtoContent[0]['TITLE'] = 'Step 1';

fantasy.client.howtoContent[0]['CONTENT'] = 'You start a FantasyAlert by providing your and your partners email and name. Also choose a password to make sure only you can access the FantasyAlert. <br />You can have several FantasyAlerts but remember that for each of them you have to set a different password. The password and your email acts as an identifier for a survey.<br /><br />Once you click \'Enter\' you can start the FantasyAlert and we will invite your partner to join (Step 5.)';

fantasy.client.howtoContent[1] = [];

fantasy.client.howtoContent[1]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[1]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/surveyselector_tn.png';

fantasy.client.howtoContent[1]['TITLE'] = 'Step 2';

fantasy.client.howtoContent[1]['CONTENT'] = 'On the following screen you will see the four main categories: Fetish, S&M, Roleplay and Sexual Behaviour. These topics are the entry points to all questions. <br /><br />Click on one of the topics to see the questions and click on the button \'Overview\' to go back to this screen.';

fantasy.client.howtoContent[2] = [];

fantasy.client.howtoContent[2]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[2]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/surveyquestions_tn.png';

fantasy.client.howtoContent[2]['TITLE'] = 'Step 3';

fantasy.client.howtoContent[2]['CONTENT'] = 'After clicking on the topic you will be presented with all the questions available. Simply check the checkbox for topics you like. <br /><br />Remember, Your partner will only see the topics you both have choosen, so you can be as honest as you like.<br /><br />If you want to go back to the topic screen simply click on the \'Overview\' button.';

fantasy.client.howtoContent[3] = [];

fantasy.client.howtoContent[3]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[3]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/surveyoverview_tn.png';

fantasy.client.howtoContent[3]['TITLE'] = 'Step 4';

fantasy.client.howtoContent[3]['CONTENT'] = 'On this page you will get an overview of all topics for confirmation. If everything is right, click on the \'Submit\' button to submit your FantasyAlert.';

fantasy.client.howtoContent[4] = [];

fantasy.client.howtoContent[4]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[4]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/surveyjoin_tn.png';

fantasy.client.howtoContent[4]['TITLE'] = 'Step 5';

fantasy.client.howtoContent[4]['CONTENT'] = 'After your partner received an invitation, he/she will get directed to this screen to enter the email and password of the FantasyAlert. Step 2. - 4. are exactly the same.';

fantasy.client.howtoContent[5] = [];

fantasy.client.howtoContent[5]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[5]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/surveyclosed_tn.png';

fantasy.client.howtoContent[5]['TITLE'] = 'Step 6';

fantasy.client.howtoContent[5]['CONTENT'] = 'After you and your partner have completed the FantasyAlert we will present you with the \'FantasyAlert Completed\' screen. Then we will create the FantasyMatch and send you an email with the link to your personalized results page. <br /><br />Feel free to tell your friends about the site. ';

fantasy.client.howtoContent[6] = [];

fantasy.client.howtoContent[6]['IMG'] = new Image(180, 143);

fantasy.client.howtoContent[6]['IMG'].src = 'http://www.myfantasyalert.com/images/slides/result_tn.png';

fantasy.client.howtoContent[6]['TITLE'] = 'Step 7';

fantasy.client.howtoContent[6]['CONTENT'] = 'On your personalized results page you will see which fantasies match exactly to your partners results. We present you with a selection of links, articles and other interesting content in regards to the fantasies you selected.';



fantasy.client.currentHowTo = 0;



fantasy.client.howToInit = function() {

	dojo.byId('howto_step').innerHTML = fantasy.client.howtoContent[fantasy.client.currentHowTo]['TITLE'];

	howto_img = fantasy.client.howtoContent[fantasy.client.currentHowTo]['IMG'];

	howto_img.setAttribute('id', 'howto_image');

	dojo.dom.replaceNode(dojo.byId('howto_image'), howto_img);

	dojo.byId('howto_content').innerHTML = fantasy.client.howtoContent[fantasy.client.currentHowTo]['CONTENT'];

}



fantasy.client.howToNext = function() {

	fantasy.client.currentHowTo++;

	if (fantasy.client.howtoContent[fantasy.client.currentHowTo]) {

		dojo.byId('howto_step').innerHTML = fantasy.client.howtoContent[fantasy.client.currentHowTo]['TITLE'];

		howto_img = new Image(180,143);

		howto_img = fantasy.client.howtoContent[fantasy.client.currentHowTo]['IMG'];

		howto_img.setAttribute('id', 'howto_image');

		dojo.dom.replaceNode(dojo.byId('howto_image'), howto_img);

		dojo.byId('howto_content').innerHTML = fantasy.client.howtoContent[fantasy.client.currentHowTo]['CONTENT'];

	}

	else {

		fantasy.client.currentHowTo--;

	}

	if (fantasy.client.howtoContent.length == fantasy.client.currentHowTo+1) {

		dojo.byId('howto_next').innerHTML = '[Next]';

	}

	else {

		dojo.byId('howto_next').innerHTML = '[<a href="javascript: void(0);" onclick="fantasy.client.howToNext();">Next</a>]';

	}

	dojo.byId('howto_previous').innerHTML = '[<a href="javascript: void(0);" onclick="fantasy.client.howToPrevious();">Previous</a>]';

};



fantasy.client.howToPrevious = function() {

	fantasy.client.currentHowTo--;

	if (fantasy.client.howtoContent[fantasy.client.currentHowTo]) {

		dojo.byId('howto_step').innerHTML = fantasy.client.howtoContent[fantasy.client.currentHowTo]['TITLE'];

		howto_img = fantasy.client.howtoContent[fantasy.client.currentHowTo]['IMG'];

		howto_img.setAttribute('id', 'howto_image');

		dojo.dom.replaceNode(dojo.byId('howto_image'), howto_img);dojo.byId('howto_content').innerHTML = fantasy.client.howtoContent[fantasy.client.currentHowTo]['CONTENT'];

	}

	else {

		fantasy.client.currentHowTo++;

	}

	if (fantasy.client.currentHowTo == 0) {

		dojo.byId('howto_previous').innerHTML = '[Previous]';

	}

	else {

		dojo.byId('howto_previous').innerHTML = '[<a href="javascript: void(0);" onclick="fantasy.client.howToPrevious();">Previous</a>]';

	}

	dojo.byId('howto_next').innerHTML = '[<a href="javascript: void(0);" onclick="fantasy.client.howToNext();">Next</a>]';

};

fantasy.client.openDirectoryRessources = [];
fantasy.client.showDirectoryRessources = function(element) {
	for (open_element in fantasy.client.openDirectoryRessources) {
		if (element != open_element) {
			//dojo.lfx.html.wipeOut(dojo.byId(open_element), 300).play();
			if (dojo.byId(open_element)) {
				dojo.byId(open_element).style.display = 'none';
			}
			
			delete fantasy.client.openDirectoryRessources[open_element];
		}
	}
	
	if (!fantasy.client.openDirectoryRessources[element]) {
		dojo.html.setClass(dojo.byId(element), '');
		//dojo.lfx.html.wipeIn(dojo.byId(element), 300).play();
		dojo.byId(element).style.display = '';
	}
	fantasy.client.openDirectoryRessources[element] = 1;
	
};

fantasy.client.hideDirectoryRessources = function() {
	for (open_element in fantasy.client.openDirectoryRessources) {
		dojo.lfx.html.wipeOut(dojo.byId(open_element), 300).play();
			delete fantasy.client.openDirectoryRessources[open_element];
	}
};

function dump(arr,level) {

var dumped_text = "";

if(!level) {

	level = 0;

}



//The padding given at the beginning of the line.

var level_padding = "";

for(var j=0;j<level+1;j++) {

	level_padding += "    ";

}



if(typeof(arr) == 'object') { //Array/Hashes/Objects

 for(var item in arr) {

  value = arr[item];

 

  if(typeof(value) == 'object') { //If it is an array,

   dumped_text += level_padding + "'" + item + "' ...\n";

   dumped_text += dump(value,level+1);

  } else {

   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";

  }

 }

} else { //Stings/Chars/Numbers etc.

 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";

}

return dumped_text;

} 



function gup( name )

{

  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regexS = "[\\?&]"+name+"=([^&#]*)";

  var regex = new RegExp( regexS );

  var results = regex.exec( window.location.href );

  if( results == null )

    return "";

  else

    return results[1];

}