ctad_included("persist.js");ctad_require("functions.js");function ctad_init(module_name,activity_type,is_summary){if(MT(module_name)){ctad_error("ctad_init needs to supply a module name");return;}
document.ctad=new Root();document.ctad.persist_init();if(typeof document.ctad.Modules=="undefined"){document.ctad.add_collection("Modules");}
if(typeof document.ctad.Modules[module_name]=="undefined"){var obj=new Module();document.ctad.Modules.add_member(obj,module_name);}
document.ctad["current_module"]=document.ctad.Modules[module_name];document.ctad.set_property("latest_module",module_name);document.ctad.set_bookmark(window.location.href,activity_type,is_summary);document.ctad["question_attempts"]=0;}
function ctadinitload(module_name,module_total_activitys){if(!document.ctad.Modules){ctad_error("ctadinitload could not find the values installed by ctad_init");return;}
if(!module_name||!module_total_activitys){ctad_error("ctadinitload should be called with a module name and total Activitys in module");return;}
var mod=document.ctad.Modules[module_name];mod.start(module_total_activitys);if(!getAPIHandle()){document.ctad.set_property("vle","false");return;}
document.ctad.set_property("vle","true");if(LMSIsInitialized()){return;}
var result=LMSInitialize();if(result=="false"){ctad_error("Problem initializing LMS");return;}
var new_date=new Date();document.ctad.set_property("vle_initialized",new_date.getTime());var ctad_children=LMSGetValue("cmi.core._children");if(!ctad_children){ctad_error("Problem finding LMS supported values");return;}
var ar_children=ctad_children.split(/\s*,\s*/);if(ar_children.contains("lesson_status")&&LMSGetValue("cmi.core.lesson_status")=="not attempted"){document.ctad.save_to_vle("cmi.core.lesson_status","incomplete");}
if(ar_children.contains("exit")){document.ctad.save_to_vle("cmi.core.exit","suspend");}
if(ar_children.contains("lesson_location")){var location=LMSGetValue("cmi.core.lesson_location");if(location.slice(0,5)!="http:"){document.ctad.save_to_vle("cmi.core.lesson_location","");location="";}
if(location&&location!=window.location.href){if(confirm("Would you like to continue from where you left off? Select OK or Cancel")){window.location.href=location;}}}
mod.get_vle_attempts();}
function loadAllQuestions(this_form){persist_questions_init(this_form);}
function persist_questions_init(this_form){if(typeof(document.ctad)=="undefined"){ctad_error("document.ctad not set. ctad_init may not have been called");return;}
var current_activity=document.ctad.current_module.get_child("Activitys",this_form.name);var obj_questions=new Object();for(var i=0;i<this_form.length;i++){var el=this_form.elements[i];var ar_match=el.name.match(/^q(\d*)/i);if(!ar_match){continue;}
el.question=current_activity.get_child("Questions",ar_match[1]);obj_questions[ar_match[1]]=true;if(el.type=="checkbox"||el.type=="radio"){el.onclick=persist_question_save;el.onchange="";}else{el.onchange=persist_question_save;el.onclick="";}}
for(var qname in obj_questions){current_activity.Questions[qname].get_question_type();current_activity.Questions[qname].load_user_data();}
if(current_activity.Questions){document.ctad.last_question=current_activity.Questions[qname];}}
function persist_question_save(){if(typeof(this.question)=="undefined"){ctad_error("element "+this.name+" has no question object attached. persist_questions_init may not have been called correctly");return;}
this.question.save_user_data();}
function Persist(store_mechanism){this.$delimiter="|";this.$store_mechanism=store_mechanism;if(this.$store_mechanism=="cookie"){this.load_from_cookie();}}
Persist.prototype.store=function(){if(this.$store_mechanism=="cookie"){this.set_cookie();}else if(this.$store_mechanism=="parent"){parent.persist=this;}else{ctad_error("Variables could not be saved.\nNo persistence mechanism available");}};Persist.prototype.load_from_cookie=function(){var c=new Cookie(document,"persist");c.load();for(var prop in c){if((prop.charAt(0)!='$')&&((typeof c[prop])!='function')){this[prop]=c[prop];}}};Persist.prototype.set_cookie=function(){var c=new Cookie(document,"persist",null,"/");for(var prop in this){if((typeof this[prop])!='function'){c[prop]=this[prop];}}
c.store();};Persist.prototype.dump=function(){var html="";for(var prop in this){if(prop.charAt(0)!='$'&&(typeof this[prop])!='function'){html+=("\n<p>"+prop+":"+this[prop]);}}
return(html);};Persist.prototype.save=function(name,value){this.tree_populate(name,value);this[name]=value;this.store();};Persist.prototype.save_object=function(obj,recurse){if(recurse){var children=obj.get_children();for(var c in children){this.save_object(children[c],true);}}
var properties=obj.get_properties();for(var p in properties){var property_name=this.property_name(obj,p);this[property_name]=properties[p];}
this.store();};Persist.prototype.save_property=function(obj,property_name){var persist_property_name=this.property_name(obj,property_name);this[persist_property_name]=obj[property_name];this.store();};Persist.prototype.property_name=function(obj,property_name){var var_name=this.var_name(obj);var_name+=this.$delimiter+property_name;return(var_name);};Persist.prototype.var_name=function(obj){var var_name="";var delim="";while(obj.$parent){var parent=obj.$parent;if(parent.get_class_name()=="Root"){break;}else{if(parent.$collection_name){var_name=parent.$collection_name+this.$delimiter+obj.$name+delim+var_name;delim=this.$delimiter;}}
obj=parent;}
return(var_name);};Persist.prototype.tree_populate=function(name,value,var_current){var ar_tokens=name.split(this.$delimiter);var prop=ar_tokens.pop();var var_name=ar_tokens.join(this.$delimiter);if(var_name){var new_var=this.tree_create(var_name,var_current);}else{var new_var=var_current;}
new_var[prop]=value;};Persist.prototype.tree_create=function(name,var_current){var var_name="";var var_type="";var var_collection="";var var_current;var new_current;var property_name="";if(!var_current){var_current=document.ctad;}
var ar_tokens=name.split(this.$delimiter);for(var i=0;i<ar_tokens.length;i+=2){var_collection=ar_tokens[i];var_name=ar_tokens[i+1];this.collection_create(var_collection,var_current);new_current=this.node_create(var_collection,var_name,var_current);if(!new_current){ctad_error('__Persist_tree_create:Still not created the var');}else{var_current=new_current;}}
return(var_current);};Persist.prototype.collection_create=function(collection,current){if(current[collection]){return;}
current[collection]=new Collection(collection,current);};Persist.prototype.node_create=function(collection,name,current){if(current[collection][name]){return(current[collection][name]);}
var type=collection.substring(0,collection.length-1);if(!type){ctad_error("__Persist_node_create:Tried to make object without type");return;}
var obj=eval("new "+type+"()");if(!obj){ctad_error("__Persist_node_create:Failed to make object with type "+type);return;}
current[collection][name]=obj;obj.$parent=current[collection];obj.$name=name;return(obj);};function Ctad(){}
Ctad.prototype.get_class_name=function(){var re=/function\s(.+)\s*\(/;var result=re.exec(this.constructor);if(typeof result[1]=="undefined"){return("unknown");}
return(result[1]);};Ctad.prototype.get_children_count=function(){var children=this.get_children();var i=0;for(c in children){i++;}
return(i);};Ctad.prototype.get_children=function(){var ar_children=new Object();for(c in this){if((typeof this[c])=='object'&&c.charAt(0)!='$'){ar_children[c]=this[c];}}
return(ar_children);};Ctad.prototype.get_properties=function(){var ar_properties=new Object();for(c in this){if((typeof this[c])!='object'&&(typeof this[c])!='function'&&c.charAt(0)!='$'){ar_properties[c]=this[c];}}
return(ar_properties);};Ctad.prototype.set_property=function(property_name,value){if(property_name.indexOf(document.persist.$delimiter)!=-1){ctad_error("Cannot persist property with name:"+property_name+". Character '"+document.persist.$delimiter+"' is used as a delimiter");return;}
this[property_name]=value;document.persist.save_property(this,property_name);};Ctad.prototype.add_collection=function(collection_name){this[collection_name]=new Collection(collection_name,this);document.persist.save_object(this[collection_name]);};Ctad.prototype.child_exists=function(){var goodvar=this;for(var i=0;i<arguments.length;i++){if(typeof goodvar[arguments[i]]=="undefined"){return(false);}else{goodvar=goodvar[arguments[i]];}}
return(true);};Ctad.prototype.get_child=function(){if(!arguments.length){return;}
var path="";var ar_args=Array();for(var i=0;i<arguments.length;i++){ar_args[i]=arguments[i];}
var path=ar_args.join(document.persist.$delimiter);return(document.persist.tree_create(path,this));};Ctad.prototype.clear_object=function(clear_self){var children=this.get_children();for(var c in children){if(children[c].clear_object){children[c].clear_object(true);}}
var properties=this.get_properties();for(var p in properties){var property_name=document.persist.property_name(this,p);delete(document.persist[property_name]);}
document.persist.store();if(clear_self){delete(this);}};function Collection(collection_name,parent_object){inherit_object(this,new Ctad());this.$collection_name=collection_name;this.$parent=parent_object;}
Collection.prototype.add_member=function(obj,member_name){this[member_name]=obj;obj.$parent=this;obj.$name=member_name;document.persist.save_object(obj);};function Root(){inherit_object(this,new Ctad());}
Root.prototype.persist_init=function(){if(cookies_use()){document.persist=new Persist("cookie");}else{if(parent.frames.length){if(!parent.persist){parent.persist=new Persist("parent");}
document.persist=new Persist("parent");for(var p in parent.persist){if(typeof(parent.persist[p])!="function"){document.persist[p]=parent.persist[p];}}}else{ctad_error("Cookies are not available and there is no frameset\nTherefore values you enter will not be saved");}}
this.tree_restore(document.persist);}
Root.prototype.tree_restore=function(persist_var){for(var prop in persist_var){if((typeof persist_var[prop])!='function'){persist_var.tree_populate(prop,persist_var[prop],this);}}};Root.prototype.save_to_vle=function(key,value){value=String(value);LMSSetValue(key,value);var iErrorNumber=LMSGetLastError();if(iErrorNumber!="0"){ctad_error("LMS error:"+LMSGetErrorString(iErrorNumber));return(false);}
else{LMSCommit();return(true);}};Root.prototype.shutdown_vle=function(){if(this.vle_present()&&LMSIsInitialized()){LMSFinish();}};Root.prototype.set_bookmark=function(href,activity_type,is_summary){if(this.bookmark){this.set_property("last_bookmark",this.bookmark);}
if((typeof href)=="undefined"){return;}
href=href.replace(/\#.*$/i,"");this.set_property("bookmark",href);if(!this.vle_present()){return;}
if(!LMSIsInitialized()){return;}
var bmk=this.bookmark;if(activity_type=="t"){if(is_summary=="a"){bmk="";}else{var ar_bmk=bmk.split("/");ar_bmk.pop();bmk=ar_bmk.join("/")+"/body01.htm";}}
this.save_to_vle("cmi.core.lesson_location",bmk);}
Root.prototype.get_activity_status=function(activity_name){if((typeof this.current_module)=="undefined"){return;}
if(this.current_module.child_exists("Activitys",activity_name)){return(this.current_module["Activitys"][activity_name].status);}else{return("none");}};Root.prototype.info_start=function(info_name){if(typeof(this.current_module)=="undefined"){return;}
var mod=this.current_module;var info=mod.get_child("Activitys",info_name);info.start();};Root.prototype.info_complete=function(info_name){if(typeof this.current_module=="undefined"){return;}
var mod=this.current_module;var info=mod.get_child("Activitys",info_name);info.complete();};Root.prototype.test_complete=function(test_name){if(typeof this.current_module=="undefined"){return;}
var mod=this.current_module;var test=mod.get_child("Activitys",test_name);test.complete(true);};Root.prototype.practice_complete=function(practice_name){if(typeof this.current_module=="undefined"){return;}
var mod=this.current_module;var practice=mod.get_child("Activitys",practice_name);practice.complete();};Root.prototype.get_activity=function(activity_name){if(typeof this.current_module=="undefined"){return;}
var mod=this.current_module;var act=mod.get_child("Activitys",activity_name);return(act);};Root.prototype.vle_present=function(){return((this.vle=="true"));};function Module(){inherit_object(this,new Ctad());}
Module.prototype.start=function(total_activitys){this.set_property("total_activitys",total_activitys);this.set_property("status","started");};Module.prototype.activity_complete=function(act){var total_activitys=0;if(this.Activitys){for(var i in this.Activitys.get_children()){if(this.Activitys[i].status=="completed"){total_activitys++;}}}
if(this.total_activitys==total_activitys){this.set_property("status","completed");}
this.set_property("latest_activity",act.$name);if(!document.ctad.vle_present()){return;}
this.set_vle_attempts();this.set_timer();if(this.status=="completed"){document.ctad.save_to_vle("cmi.core.lesson_status","completed");}};Module.prototype.attempt_added=function(attempt){if(!document.ctad.vle_present()){return;}
if(!LMSIsInitialized()){return;}
var score=0;var max_score=0;for(var i in this.Activitys.get_children()){if(this.Activitys[i].Attempts){score+=parseInt(this.Activitys[i].Attempts[0].score);max_score+=parseInt(this.Activitys[i].max_score);}}
document.ctad.save_to_vle("cmi.core.score.raw",score);document.ctad.save_to_vle("cmi.core.score.min","0");document.ctad.save_to_vle("cmi.core.score.max",max_score);};Module.prototype.set_timer=function(){if(!document.ctad.vle_present()){return;}
if(!LMSIsInitialized()){return;}
if(!this.$parent.$parent.vle_initialized){return;}
var new_date=new Date();var elapsed_time=(new_date.getTime()-this.$parent.$parent.vle_initialized)/1000;var hours=("0000"+Math.floor(elapsed_time/(60*60))).slice(-4);var minutes=("00"+Math.floor((elapsed_time-hours*60*60)/60)).slice(-2);var seconds=("00"+Math.floor(elapsed_time-hours*60*60-minutes*60)).slice(-2);document.ctad.save_to_vle("cmi.core.session_time",hours+":"+minutes+":"+seconds);};Module.prototype.set_vle_attempts=function(){var ar_tests=new Array();var j=0;var activitys=this.Activitys.get_children();for(var act in activitys){if(!activitys[act].Attempts){continue;}
var attempts=activitys[act].Attempts.get_children();var ar_attempts=new Array();var i=0;for(var attempt in attempts){ar_attempts[i++]=activitys[act].Attempts[attempt].score+","+activitys[act].Attempts[attempt].date;}
ar_tests[j++]=act+":"+ar_attempts.join(",");}
if(!ar_tests.length){return;}
var attempts=ar_tests.join("|");document.ctad.save_to_vle("cmi.suspend_data",attempts);};Module.prototype.get_vle_attempts=function(){var attempts=LMSGetValue("cmi.suspend_data");if(!attempts){return;}
var ar_tests=attempts.split("|");for(var i=0;i<ar_tests.length;i++){var ar_pair=ar_tests[i].split(":");if(!ar_pair||ar_pair.length!=2){continue;}
var test_name=ar_pair[0];var ar_attempts=ar_pair[1].split(",");for(var j=0;j<ar_attempts.length;j+=2){var attempt=this.get_child("Activitys",test_name,"Attempts",j/2);attempt.set_score(ar_attempts[j],ar_attempts[j+1]);document.persist.save_object(attempt);}}};Module.prototype.activity_started=function(act){this.set_property("latest_activity",act.$name);};function Activity(){inherit_object(this,new Ctad());}
Activity.prototype.complete=function(is_test){if(this.status!="started"){return;}
this.set_property("status","completed");if(is_test){this.set_max_score();this.mark();this.add_attempt();}
this.$parent.$parent.activity_complete(this);};Activity.prototype.add_attempt=function(){if(!this.Attempts){this.add_collection("Attempts");}
var attempts_number=this.Attempts.get_children_count();var new_attempt=new Attempt();new_attempt.set_score(this.score);this.Attempts.add_member(new_attempt,attempts_number);this.$parent.$parent.attempt_added(new_attempt);};Activity.prototype.set_max_score=function(){if(typeof(theanswers.length)=="undefined"){ctad_error("Could not set max score for this test. no theanswers array found");return;}
var max_score=0;for(var i=0;i<theanswers.length;i++){if(typeof(theanswers[i])!="undefined"){max_score++;}}
this.set_property("max_score",max_score);};Activity.prototype.mark=function(){if(typeof(this.Questions)=="undefined"){this.set_property("score",0);return;}
var questions=this.Questions.get_children();var score=0;var incomplete=false;for(var q in questions){var mark=questions[q].mark();if(mark=="c"){score++;}else if(mark=="s"){incomplete=true;}}
this.set_property("score",score);};Activity.prototype.start=function(){if(this.status=="started"){return;}
this.set_property("status","started");this.$parent.$parent.activity_started(this);};function Question(){inherit_object(this,new Ctad());this.$answer_delimiter="^";}
Question.prototype.get_form_name=function(){return(this.$parent.$parent.$name);};Question.prototype.get_question_type=function(){if(!this.elements){this.get_elements();}
this.question_type=this.elements[0].type.replace("-","_");if(this.elements[0].type=="hidden"){if(this.elements[0].ctad){this.question_type="ctad";if(this.elements[0].ctad.match_answers){this.match_answers=true;}}}
this.set_property("question_type",this.question_type);}
Question.prototype.get_question_answer=function(){if(typeof(theanswers)=="undefined"){ctad_error("no theanswers array in qdata.js");return;}
if(typeof(theanswers[this.$name])=="undefined"){ctad_error("no answer specified for this question:"+this.$name);return;}
this.answer=theanswers[this.$name];};Question.prototype.get_elements=function(){var form_name=this.get_form_name();this.elements=new Array();var j=0;var re=new RegExp("^q"+this.$name+".*$");for(var i=0;i<document.forms[form_name].length;i++){if(re.test(document.forms[form_name][i].name)){this.elements[j++]=document.forms[form_name][i];}}};Question.prototype.load_user_data=function(){if(this.user_data){this.restore_state(this.user_data);}};Question.prototype.load_answer_data=function(){if(!this.answer){this.get_question_answer();}
this.restore_state(this.answer);};Question.prototype.restore_state=function(value){this.values=value.split(this.$answer_delimiter);if(this["restore_"+this.question_type]){this["restore_"+this.question_type](value);}else{ctad_error("no restore function for question type:"+this.question_type);}};Question.prototype.restore_default=function(){for(var i=0;i<this.values.length;i++){if(this.values[i]==null){this.elements[i].value=""
}else{this.elements[i].value=this.values[i];}}};Question.prototype.restore_text=function(){this.restore_default();};Question.prototype.restore_textarea=function(){this.restore_default();};Question.prototype.restore_hidden=function(){this.restore_default();};Question.prototype.restore_checkbox=function(){for(var i=0;i<this.elements.length;i++){this.elements[i].checked=this.values.contains(this.elements[i].value);}};Question.prototype.restore_radio=function(){for(var i=0;i<this.elements.length;i++){this.elements[i].checked=(this.values[0]==this.elements[i].value);}};Question.prototype.restore_select_one=function(){for(var i=0;i<this.elements.length;i++){var select=this.elements[i];for(var j=0;j<select.options.length;j++){select.options[j].selected=(this.values[i]==select.options[j].value);}}};Question.prototype.restore_ctad=function(){this.elements[0].ctad.restore_data(this.values);}
Question.prototype.save_user_data=function(){this.$parent.$parent.start();this.get_question_type();if(this["save_"+this.question_type]){this["save_"+this.question_type]();}else{ctad_error("no save function for question type:"+this.question_type);}
this.set_property("user_data",this.user_data);};Question.prototype.save_default=function(){var ar_user_data=new Array();this.incomplete=false;for(var i=0;i<this.elements.length;i++){if(this.elements[i].value){ar_user_data[i]=this.elements[i].value;}else{this.incomplete=true;}}
this.user_data=ar_user_data.join(this.$answer_delimiter);};Question.prototype.save_text=function(){this.save_default();};Question.prototype.save_textarea=function(){this.save_default();};Question.prototype.save_hidden=function(){this.save_default();};Question.prototype.save_ctad=function(){this.user_data=this.elements[0].value;if(this.match_answers){this.get_question_answer();var answer_parts=this.answer.split(this.$answer_delimiter).length;var data_parts=this.user_data.split(this.$answer_delimiter).length;this.incomplete=(answer_parts!=data_parts);}}
Question.prototype.save_checkbox=function(){var ar_checked=new Array();for(var i=0;i<this.elements.length;i++){if(this.elements[i].checked){ar_checked[ar_checked.length]=this.elements[i].value;}}
this.user_data=ar_checked.join(this.$answer_delimiter);if(!this.user_data){this.incomplete=true;}else{this.incomplete=false;}};Question.prototype.save_radio=function(){for(var i=0;i<this.elements.length;i++){if(this.elements[i].checked){this.user_data=this.elements[i].value;}}
if(!this.user_data){this.incomplete=true;}else{this.incomplete=false;}};Question.prototype.save_select_one=function(){var ar_user_data=new Array();var missing_select=false;for(var i=0;i<this.elements.length;i++){ar_user_data[i]=this.elements[i].options[this.elements[i].selectedIndex].value;if(!ar_user_data[i]||ar_user_data[i]=="_blank"){missing_select=true;}}
this.incomplete=missing_select;this.user_data=ar_user_data.join(this.$answer_delimiter);};Question.prototype.mark=function(){if(typeof(this.answer)=="undefined"){this.get_question_answer();}
if(!this.user_data){return("n");}
if(this.incomplete){return("n");}
if(!this.question_type){this.get_question_type();}
if(this["mark_"+this.question_type]){return(this["mark_"+this.question_type]());}else{if(this.user_data==this.answer){return("c");}else{return("i");}}};Question.prototype.mark_textarea=function(){return(this.mark_text());};Question.prototype.mark_text=function(){var val=new Validate(this.$answer_delimiter);var return_value=val.validate_text(this.user_data,this.answer);if(return_value){return("c");}else{if(val.answers_array){for(var i in val.answers_array){if(!val.answers_array[i]){this.elements[i].value="";}}}
return("i");}};function Attempt(){inherit_object(this,new Ctad());}
Attempt.prototype.set_score=function(score,attempt_date){this.score=score;if(!attempt_date){var attempt_date=new Date();this.date=attempt_date.getTime();}else{this.date=attempt_date;}};function Validate(delimiter){if(delimiter){this.$delimiter=delimiter;}else{this.$delimiter="^";}}
Validate.prototype.validate_text=function(value,valid_values){if(!valid_values){ctad_error("validate called without valid values");return(false);}
if(valid_values.toString().indexOf(this.$delimiter)!=-1){if(value.toString().indexOf(this.$delimiter)!=-1){return this.validate_multiple(value.split(this.$delimiter),valid_values.split(this.$delimiter));}else{return this.validate_single(value,valid_values.split(this.$delimiter));}}else{var ar_values=new Array;ar_values[0]=valid_values;return this.validate_single(value,ar_values);}
for(var i=0;i<ar_values.length;i++){if(ar_values[i].match(/^\s*$/)){continue;}
var re=new RegExp("^\s*"+ar_values[i]+"\s*$","i");if(re.test(value)){return(true);}else{if(!isNaN(ar_values[i])){if(this.validate_number(value,ar_values[i])){return(true);}}}}
return(false);};Validate.prototype.validate_multiple=function(ar_values,ar_valid_values){if(ar_values.length!=ar_valid_values.length){ctad_error("number of answers does not match number of questions");return false;}
this.answers_array=new Array();var all_right=true;for(var i=0;i<ar_values.length;i++){var ar_valid_value=new Array();ar_valid_value[0]=ar_valid_values[i];this.answers_array[i]=this.validate_single(ar_values[i],ar_valid_value);if(!this.answers_array[i]){all_right=false;}}
return all_right;};Validate.prototype.validate_single=function(value,ar_valid_values){for(var i=0;i<ar_valid_values.length;i++){if(ar_valid_values[i].match(/^\s*$/)){continue;}
var re=new RegExp("^\s*"+ar_valid_values[i]+"\s*$","i");if(re.test(value)){return(true);}else{if(!isNaN(ar_valid_values[i])){if(this.validate_number(value,ar_valid_values[i])){return(true);}}}}
return(false);};Validate.prototype.validate_number=function(value,valid_number){var re=new RegExp("^\\s*"+valid_number+"\\s*$","i");if(re.test(value)){return(true);}
if(!isNaN(parseFloat(value))&&!isNaN(parseFloat(valid_number))){return(parseFloat(value)==parseFloat(valid_number));}
var number_as_words=this.number_to_words(valid_number);var re=new RegExp("^\\s*"+number_as_words+"\\s*$","i");if(re.test(value)){return(true);}
number_as_words=number_as_words.replace(/-/," ");var re=new RegExp("^\\s*"+number_as_words+"\\s*$","i");if(re.test(value)){return(true);}
return(false);};Validate.prototype.number_to_words=function(number){var ar_small=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"];var obj_large=new Object();obj_large[1000000]="million";obj_large[1000]="thousand";obj_large[100]="hundred";var result="";if(ar_small[number]){return(ar_small[number]);}
for(var val in obj_large){if(parseInt(number)>parseInt(val)){var larges=Math.floor(number/val);var remainder=number-(larges*val);return(this.number_to_words(larges)+" "+obj_large[val]+" "+this.number_to_words(remainder));}}
if(number>=20){var tens=Math.floor(number/10);result=ar_small[tens]+"ty";if(number-(tens*10)){result+="-"+ar_small[number-(tens*10)];}}else{result=ar_small[number-10]+"teen";}
result=result.replace(/twoty/,"twenty");result=result.replace(/threet/,"thirt");result=result.replace(/fourty/,"forty");result=result.replace(/fivet/,"fift");result=result.replace(/eightt/,"eight");return(result);};
