/*
Copyright © Tribal Education Ltd. 

This file has been compressed to make the page loading faster. For working version of this file, please contact Tribal's Digital Learning Studio at digitallearningsupport@tribalgroup.com.
*/
ctad_included("wordclick.js");ctad_require("functions.js");function word_click_init(form_name,question_name,format,style_attribute,style_value){var hidden_field=document.forms[form_name][question_name];var container=document.getElementById("wordclick_"+question_name);var wck=new Wordclick(container,hidden_field,format);if(style_attribute){wck.selected_style_attribute=style_attribute;}
if(style_value){wck.selected_style_value=style_value;}
wck.init();}
function word_click(obj,no_unselect){if(obj.selected){if(!no_unselect){obj.creator.unselect(obj);}}else{if(obj.creator.$format=="multi"){obj.creator.select(obj);}else{obj.creator.unselect_all()
obj.creator.select(obj);}}
obj.creator.update_data();};function Wordclick(container,hidden_field,format){this.$container=container;this.$sentence=this.$container.innerHTML;this.$hidden_field=hidden_field;this.$format=format;this.delimiter="^";this.selected_style_attribute="backgroundColor";this.selected_style_value="red";}
Wordclick.prototype.init=function(){var str=this.$sentence.replace(/([\w|\']+)/g,"<a onclick=\"word_click(this)\">$1</a>");this.$container.innerHTML=str;this.get_spans();var d=new Date();var big_number=d.getTime().toString().slice(-2)*100;var set_color=(!style_in_stylesheet(".null_anchor","color")&&!style_in_stylesheet("a.null_anchor","color"));for(var i=0;i<this.spans.length;i++){this.spans[i].ordinal=i;this.spans[i].creator=this;this.spans[i].href="javascript:;";this.spans[i].style.textDecoration="none";if(set_color){this.spans[i].style.color="black";}
this.spans[i].className="null_anchor";}
if(this.$hidden_field){this.$hidden_field.ctad=this;}};Wordclick.prototype.get_spans=function(){if(this.$container.getElementsByTagName){this.spans=this.$container.getElementsByTagName("a");}else if(this.$container.all){this.spans=this.$container.all;}else{return;}};Wordclick.prototype.update_data=function(){var ar_data=new Array();for(var i=0;i<this.spans.length;i++){if(this.spans[i].selected){ar_data[ar_data.length]=this.spans[i].ordinal;}}
this.data=ar_data.join(this.delimiter);if(this.$hidden_field){this.$hidden_field.value=this.data;if(typeof(this.$hidden_field["onchange"])=="function"){this.$hidden_field.onchange();}}};Wordclick.prototype.restore_data=function(ar_data){this.get_spans();this.unselect_all();for(var j=0;j<ar_data.length;j++){for(var i=0;i<this.spans.length;i++){if(this.spans[i].ordinal==ar_data[j]){word_click(this.spans[i],true);}}}};Wordclick.prototype.select=function(obj){obj.selected=true;obj.old_style_value=obj.style[this.selected_style_attribute];obj.style[this.selected_style_attribute]=this.selected_style_value;};Wordclick.prototype.unselect=function(obj){obj.selected=false;this.unset_style(obj);};Wordclick.prototype.unselect_all=function(){for(var i=0;i<this.spans.length;i++){this.spans[i].selected=false;this.unset_style(this.spans[i]);}};Wordclick.prototype.unset_style=function(obj){var initial_style=obj.style[this.selected_style_attribute];if(typeof(obj.old_style_value)!="undefined"){obj.style[this.selected_style_attribute]=obj.old_style_value;}
if(initial_style!=""&&initial_style==obj.style[this.selected_style_attribute]){obj.style[this.selected_style_attribute]="none";}};

