dojo.provide("memory.ImagePreloader");
dojo.require("dojo.lang.declare");
dojo.declare("memory.ImagePreloader",null,function(_1,_2,_3){
if(arguments.length==0){
return;
}
this.imgUrlBase=_1;
this.callback=_3;
this.nLoaded=0;
this.nProcessed=0;
this.aImages=new Array;
this.nImages=_2.length;
for(var f=0;f<this.nImages;f++){
this.preload(_2[f]);
}
},{preload:function(_5){
var _6=new Image;
this.aImages.push(_6);
_6.onload=dojo.lang.hitch(this,"onload");
_6.onerror=dojo.lang.hitch(this,"onerror");
_6.onabort=dojo.lang.hitch(this,"onabort");
_6.src=this.imgUrlBase+_5;
},onComplete:function(){
this.nProcessed++;
if(this.nProcessed==this.nImages){
this.callback(this.aImages,this.nLoaded);
}
},onload:function(){
this.nLoaded++;
this.onComplete();
},onerror:function(){
this.onComplete();
},onabort:function(){
this.onComplete();
}});

dojo.provide("memory.widget.ImageViewer");
dojo.require("memory.ImagePreloader");
dojo.require("dojo.lang.common");
dojo.require("dojo.lang.func");
dojo.require("dojo.widget.*");
dojo.require("dojo.lfx.*");
dojo.widget.defineWidget("memory.widget.ImageViewer",dojo.widget.HtmlWidget,function(){
this.endSlide=false;
this.callback=null;
this.isLoading=false;
},{templatePath:dojo.uri.moduleUri("memory.widget","templates/ImageViewer.html"),templateCssPath:dojo.uri.moduleUri("memory.widget","templates/ImageViewer.css"),preloadSize:5,imgUrls:[],imgUrlBase:"",transitionInterval:2000,imgWidth:800,imgHeight:600,stopped:false,_cIdx:0,cacheUrls:[],_urlsIdx:0,_dspIdx:0,_dir:"n",img:null,fadeAnim:null,postMixInProperties:function(){
this.width=this.imgWidth+"px";
this.height=this.imgHeight+"px";
},fillInTemplate:function(){
dojo.html.setOpacity(this.img,0.9999);
},start:function(){
this.stopped=false;
this.endSlide=false;
this._urlsIdx=0;
this._dspIdx=0;
this._cIdx=0;
this.img.src=this.imgUrlBase+"blank.jpg";
this.preLoad("_start");
},_start:function(_1,_2){
this._addToCache(_1);
this.isLoading=false;
this.next();
},_addToCache:function(_3){
if(!_3||_3.length==0){
return;
}
for(var f=0;f<_3.length;f++){
this.cacheUrls[this._cIdx++]=_3[f].src;
}
},stop:function(){
this.stopped=true;
this.img.src=this.imgUrlBase+"blank.jpg";
},setDelay:function(){
},setImages:function(_5){
if(dojo.lang.isString(_5)){
_5=_5.split(";");
}
this.imgUrls=_5;
},setPhotoCallback:function(_6){
if(_6){
this.callback=_6;
}
},preLoad:function(_7){
if(this._urlsIdx>=this.imgUrls.length){
return;
}
var _8=[];
for(var f=0;f<this.preloadSize;f++){
if(this._urlsIdx>this.imgUrls.length-1){
break;
}
_8.push(this.imgUrls[this._urlsIdx++]);
}
if(_8&&_8.length>0){
this.isLoading=true;
this.preload=new memory.ImagePreloader(this.imgUrlBase,_8,dojo.lang.hitch(this,_7));
}
},_preloadComp:function(_a,_b){
this._addToCache(_a);
this.isLoading=false;
},_displayImage:function(){
if(this.fadeAnim){
this.fadeAnim.stop();
}
this.fadeAnim=dojo.lfx.fadeOut(this.img,this.transitionInterval,null);
dojo.event.connect(this.fadeAnim,"onEnd",this,"_endAnim");
this.fadeAnim.play();
},_endAnim:function(){
var _c=0;
if(this._dir=="n"){
_c=this._dspIdx-1;
}else{
if(this._dir=="p"){
_c=--this._dspIdx;
this._dspIdx-=1;
}
}
this.img.src=this.cacheUrls[this._dspIdx];
this.fadeAnim=dojo.lfx.fadeIn(this.img,this.transitionInterval,null);
this.fadeAnim.play();
this._fireCallback("nextSlide",_c,this._dspIdx++);
},next:function(){
if(this.stopped||this.loadTimer){
return;
}
this._dir="n";
if(this._dspIdx>=this.imgUrls.length){
this.endSlide=true;
this._fireCallback("nextSlide",this._dspIdx-1,-1);
this.stop();
this._fireCallback("endSlide",-1,-1);
return;
}
if(this._dspIdx<this._cIdx){
this._displayImage();
}
if(this.isLoading){
this.loadTimer=dj_global.setInterval(dojo.lang.hitch(this,"timerHandler"),2000);
}else{
if(this._urlsIdx<this.imgUrls.length){
this.preLoad("_preloadComp");
}else{
this._displayImage();
}
}
},timerHandler:function(){
if(this.isLoading){
return;
}
dj_global.clearInterval(this.loadTimer);
this.next();
},previous:function(){
if(this.stopped||this.loadTimer){
return;
}
if((this._dspIdx-1)<=0){
alert("At beginning of images");
return;
}
this._dir="p";
this._displayImage();
},_fireCallback:function(_d,_e,_f){
if(this.callback&&dojo.lang.isFunction(this.callback[_d])){
this.callback[_d](_e,_f);
}
}});

dojo.provide("memory.widget.SlideShow");
dojo.require("dojo.widget.SlideShow");
dojo.require("dojo.lang.common");
dojo.require("dojo.lang.func");
dojo.require("dojo.widget.*");
dojo.widget.defineWidget("memory.widget.SlideShow",dojo.widget.SlideShow,function(){
this.endSlide=false;
this.callback=null;
this.prevImage=-1;
this.nextImage=-1;
},{templatePath:dojo.uri.moduleUri("memory.widget","templates/SlideShow.html"),start:function(){
this.stopped=false;
this.endSlide=false;
this.prevImage=-1;
this.nextImage=-1;
this._urlsIdx=0;
this._background="img2";
this._foreground="img1";
this.img2.src=this.imgUrlBase+this.imgUrls[this._urlsIdx++]+this._getUrlSuffix();
if(this.imgUrls.length<2){
this.endSlide=true;
}
this._endTransition();
},stop:function(){
this.stopped=true;
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onerror"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onerror"));
},setImages:function(_1){
if(dojo.lang.isString(_1)){
_1=_1.split(";");
}
this.imgUrls=_1;
this.imgUrls.push("blank.jpg");
},setPhotoCallback:function(_2){
if(_2){
this.callback=_2;
}
},_getEventObj:function(_3,_4){
return {srcObj:_3,srcFunc:_4,adviceObj:this,adviceFunc:"_backgroundImageLoaded",once:true,delay:this.delay};
},setDelay:function(_5){
if(_5>0){
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onerror"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onerror"));
this.delay=_5*1000;
}
},_loadNextImage:function(){
if(this.endSlide){
this._fireCallback("nextSlide",this.nextImage,-1);
this.stop();
this._fireCallback("endSlide",-1,-1);
return;
}else{
this.prevImage=this.nextImage;
this.nextImage=this._urlsIdx-1;
this._fireCallback("nextSlide",this.prevImage,this.nextImage);
}
dojo.event.kwConnect(this._getEventObj(this[this._background],"onload"));
dojo.event.kwConnect(this._getEventObj(this[this._background],"onerror"));
dojo.html.setOpacity(this[this._background],1);
this[this._background].src=this.imgUrlBase+this.imgUrls[this._urlsIdx++];
if(this._urlsIdx>(this.imgUrls.length-1)){
this.endSlide=true;
}
},_fireCallback:function(_6,_7,_8){
if(this.callback&&dojo.lang.isFunction(this.callback[_6])){
this.callback[_6](_7,_8);
}
}});

dojo.provide("memory.controller");
dojo.require("memory.widget.SlideShow");
dojo.require("memory.widget.ImageViewer");
dojo.require("dojo.lang.declare");
dojo.require("dojo.lang.common");
dojo.require("dojo.event.*");
dojo.require("dojo.rpc.JsonService");
dojo.require("dojo.debug");
dojo.require("dojo.uri.*");
dojo.require("dojo.string.Builder");
dojo.declare("memory.controller",null,function(){
this.photoProps=null;
},{init:function(){
this.connectWidgetEvent("start","onClick","startMemorization");
this.connectNodeEvent("allDemoProp","onclick","selDemoProps");
this.connectNodeEvent("clearDemoProp","onclick","clrDemoProps");
this.connectNodeEvent("allPhotoProp","onclick","selPhotoProps");
this.connectNodeEvent("clearPhotoProp","onclick","clrPhotoProps");
this.focusField("num_photos");
this.clrDemoProps();
this.clrPhotoProps();
},connectNodeEvent:function(id,_2,_3){
var _4=dojo.byId(id);
if(_4){
dojo.event.connect(_4,_2,this,_3);
}
},connectWidgetEvent:function(_5,_6,_7){
var _8=dojo.widget.byId("start");
if(_8){
dojo.event.connect(_8,"onClick",this,"startMemorization");
}
},focusField:function(_9){
var n=dojo.byId(_9);
if(n&&n.focus){
n.focus();
}
},validatePhotoProps:function(_b){
if(_b["num_photos"]==""||_b["num_photos"]<=0){
alert("Number of test photos must be greater than zero");
this.focusField("num_photos");
return false;
}
if(_b["test_time"]==""){
_b["test_time"]=0;
}
if(_b["photo_time"]==""){
_b["photo_time"]=0;
}
if(_b["test_time"]==0&&_b["photo_time"]==0){
alert("Either time limit for test or max photo time is required");
this.focusField("test_time");
return false;
}
if(_b["pccfn"]==""){
_b["pccfn"]=0;
}
if(!this.checkNumber(_b["pccfn"],0,100,"Percent common first name")){
this.focusField("pccfn");
return false;
}
if(_b["pccln"]==""){
_b["pccln"]=0;
}
if(!this.checkNumber(_b["pccln"],0,100,"Percent common last name")){
this.focusField("pccln");
return false;
}
return true;
},startMemorization:function(){
this.photoProps=null;
var _c={};
var _d=this.getFormValues("memForm");
if(!this.validatePhotoProps(_d)){
return;
}
_c["photos"]=_d;
var _e=this.getFormValues("demoForm");
_c["demographics"]=_e;
var _f=this.getFormValues("photoForm");
_c["photoProperties"]=_f;
if(dojo.lang.isFunction(memory.photoRpc["getPhotos"])){
this.dialogHandler(true,"Loading please wait...");
memory.photoRpc.getPhotos(_c).addBoth(this,"_startMemorization");
}else{
alert("ERROR: getPhotos() method not found");
}
},getImages:function(){
var _10=[];
if(!this.photoProps){
return _10;
}
for(var f=0;f<this.photoProps.length;f++){
_10.push(this.photoProps[f].filename);
}
return _10;
},_setupSlideShow:function(_12,_13,_14,_15,_16){
var _17=this.getFormValues(_13);
var _18=false;
var tt=parseFloat(_17.test_time);
var pt=parseFloat(_17.photo_time);
if(pt>0){
_18=true;
tt=0;
}else{
tt*=60;
}
var wt="ImageViewer";
if(_18){
wt="SlideShow";
}
var _1c=null;
if(this.slideShow){
_1c=this.slideShow.domNode;
}else{
_1c=dojo.byId("slideShow");
}
var _1d={transitionInterval:700,imgUrlBase:"../images/",imgWidth:400,imgHeight:600};
wt="memory:"+wt;
this.slideShow=dojo.widget.createWidget(wt,_1d,_1c);
this.slideShow.setPhotoCallback(_14);
this.slideShow.setImages(_12);
this.slideShow.setDelay(pt);
var fct=function(){
this[_16](this.slideShow,tt);
};
var cc=dojo.widget.byId("clientContainer");
cc.addOnLoad(dojo.lang.hitch(this,fct));
cc.setUrl(_15);
},_startMemorization:function(_20){
if(_20 instanceof Error){
this.dialogHandler(false);
alert("Error fetching photos for memorization - "+_20.message);
return;
}else{
}
this.dialogHandler(false);
this.photoProps=_20;
var _21=this.getImages();
var _22={"nextSlide":dojo.lang.hitch(this,"nextSlide"),"prevSlide":dojo.lang.hitch(this,"prevSlide"),"endSlide":dojo.lang.hitch(this,"endSlide")};
this._setupSlideShow(_21,"memForm",_22,"memoryEntry.html","_memoryEntryLoaded");
},_memoryEntryLoaded:function(_23,_24){
if(_24>0){
this.memTimer=dj_global.setInterval(dojo.lang.hitch(this,"stopMemorization"),_24*1000);
}
_23.start();
},nextSlide:function(_25,_26){
var _27=this.getFormValues("entryForm");
if(_25>=0){
var pp=this.photoProps[_25];
if(pp!=null){
pp["userProps"]=_27;
}
}
var pp=this.photoProps[_26];
if(pp){
this.displayUserData(pp["userProps"]);
}
this.displayProperties(_26);
},prevSlide:function(_2a,_2b){
this.displayProperties(_2b);
},endSlide:function(){
this.stopMemorization();
},stopMemorization:function(){
if(this.memTimer){
dj_global.clearInterval(this.memTimer);
}
if(this.slideShow){
this.slideShow.stop();
}
this.clearProperties();
var cc=dojo.widget.byId("clientContainer");
cc.addOnLoad(dojo.lang.hitch(this,"_startLoaded"));
cc.setUrl("StartTest.html");
},_startLoaded:function(){
var btn=dojo.widget.byId("startTest");
if(btn){
dojo.event.connect(btn,"onClick",this,"startTest");
}
},startTest:function(){
dojo.widget.byId("nameInfo").hide();
this.fisherYatesShuffle(this.photoProps);
var _2e=this.getImages();
var _2f={"nextSlide":dojo.lang.hitch(this,"testNext"),"prevSlide":dojo.lang.hitch(this,"testPrev"),"endSlide":dojo.lang.hitch(this,"testEnd")};
this._setupSlideShow(_2e,"testForm",_2f,"memoryEntry.html","_testEntryLoaded");
},_testEntryLoaded:function(_30,_31){
if(_31>0){
this.memTimer=dj_global.setInterval(dojo.lang.hitch(this,"testEnd"),_31*1000);
}
_30.start();
},testNext:function(_32,_33){
var _34=this.getFormValues("entryForm");
if(_32>=0){
var pp=this.photoProps[_32];
if(pp!=null){
pp["testProps"]=_34;
}
}
var pp=this.photoProps[_33];
if(pp){
this.displayUserData(pp["testProps"]);
}
},testPrev:function(_37,_38){
},testEnd:function(){
this._stopTest();
},_stopTest:function(){
if(this.memTimer){
dj_global.clearInterval(this.memTimer);
}
if(this.slideShow){
this.slideShow.stop();
}
var cc=dojo.widget.byId("clientContainer");
cc.addOnLoad(dojo.lang.hitch(this,"_displayResults"));
cc.setUrl("TestResults.html");
},_displayResults:function(){
var sb=new dojo.string.Builder("<table style=\"resultTable\"><thead><tr>");
sb.append("<th class=\"tableHdr\">Image</th>").append("<th class=\"tableHdr\">Memorization/Test Comparison</th></tr></thead><tbody>");
for(var f=0;f<this.photoProps.length;f++){
sb.append(this._formatResult(this.photoProps[f]));
}
sb.append("</tbody></table>");
var cp=dojo.widget.byId("testData");
if(cp){
cp.setContent(sb.toString());
}
},_formatResult:function(_3d){
var ded=this._defaultEntryData();
if(!_3d["userProps"]){
_3d["userProps"]=ded;
}
if(!_3d["testProps"]){
_3d["testProps"]=ded;
}
var sb=new dojo.string.Builder("<tr><td><img width=\"80\" height=\"120\" src=\"/memory/images/");
sb.append(_3d.filename).append("\"/></td><td valign=\"top\"><table><tr><th style=\"dataHdr\">Memorization<th style=\"dataHdr\">Test</tr>");
sb.append(this._formatData(_3d["userProps"].facial_feature,_3d["testProps"].facial_feature));
sb.append(this._formatData(_3d["userProps"].same_name,_3d["testProps"].same_name));
sb.append(this._formatData(_3d["userProps"].location,_3d["testProps"].location));
sb.append(this._formatData(_3d["userProps"].first_name,_3d["testProps"].first_name));
sb.append(this._formatData(_3d["userProps"].last_name,_3d["testProps"].last_name));
sb.append(this._formatData(_3d["userProps"].first_name_img,_3d["testProps"].first_name_img));
sb.append(this._formatData(_3d["userProps"].last_name_img,_3d["testProps"].last_name_img));
sb.append("</table></td></tr>");
return sb.toString();
},_formatData:function(_40,_41){
var sb=new dojo.string.Builder("<tr><td style=\"memData\">").append(_40).append("</td><td style=\"testData\">").append(_41).append("</td></tr>");
return sb.toString();
},fisherYatesShuffle:function(_43){
var i=_43.length;
if(i==0){
return false;
}
while(--i){
var j=Math.floor(Math.random()*(i+1));
var _46=_43[i];
var _47=_43[j];
_43[i]=_47;
_43[j]=_46;
}
},_defaultEntryData:function(){
return {facial_feature:"",same_name:"",location:"",first_name:"",last_name:"",first_name_img:"",last_name_img:""};
},displayUserData:function(_48){
if(!_48){
_48=this._defaultEntryData();
}
var _49=dojo.byId("entryForm");
for(var f=0;f<_49.elements.length;f++){
var el=_49.elements[f];
if(el.name==""){
continue;
}
if(_48[el.name]){
el.value=_48[el.name];
}else{
el.value="";
}
}
},dialogHandler:function(_4c,_4d){
if(_4d){
var msg=dojo.byId("statusMsg");
if(msg){
msg.innerHTML=_4d;
}
}
var _4f=dojo.widget.byId("statusDialog");
if(_4c){
_4f.show();
}else{
_4f.hide();
}
},displayProperties:function(_50){
if(this.photoProps==null){
this.clearProperties();
return;
}
this.updateProperties(_50);
},clearProperties:function(){
var ap=dojo.widget.byId("addInfo");
ap.setContent("");
},_fp:function(_52){
return "<div class=\"photoProps\">"+_52+"</div>";
},updateProperties:function(_53){
if(this.photoProps==null){
return;
}
var pp=this.photoProps[_53];
if(!pp){
return;
}
var _55=dojo.byId("photoName");
_55.innerHTML=pp.first_name+" "+pp.last_name;
var sb=new dojo.string.Builder();
if(pp["spouse_name"]){
sb.append(this._fp("Spouse named "+pp["spouse_name"]));
}
if(pp["daughter1"]){
sb.append(this._fp("Daughter named "+pp["daughter1"]));
}
if(pp["son1"]){
sb.append(this._fp("Son named "+pp["son1"]));
}
if(pp["company_name"]){
sb.append(this._fp("Employed by "+pp["company_name"]));
}
if(pp["job_title"]){
sb.append(this._fp("Job function "+pp["job_title"]));
}
if(pp["location"]){
sb.append(this._fp("Resides in "+pp["location"]));
}
if(pp["university"]){
sb.append(this._fp("College degree from "+pp["university"]+" Graduate"));
}
if(pp["hobby"]){
sb.append(this._fp("Favorite hobby is "+pp["hobby"]));
}
var ap=dojo.widget.byId("addInfo");
ap.setContent(sb.toString());
},checkNumber:function(_58,min,max,_5b){
_58=parseFloat(_58);
if(isNaN(_58)||_58<min||_58>max){
alert(_5b+" value is invalid");
return false;
}
return true;
},getFormValues:function(_5c){
var _5d=dojo.byId(_5c);
if(!_5d){
return {};
}
var _5e={};
for(var f=0;f<_5d.elements.length;f++){
var el=_5d.elements[f];
if(el.name==""){
continue;
}
if((el.type!="select-multiple"&&el.type!="checkbox"&&el.type!="radio")||(el.type=="radio"&&el.checked)){
_5e[el.name]=el.value;
}else{
if(el.type=="checkbox"&&el.checked){
if(typeof (_5e[el.name])=="undefined"){
_5e[el.name]=[];
}
_5e[el.name].push(el.value);
}else{
if(el.type=="select-multiple"){
if(typeof (_5e[name])=="undefined"){
_5e[el.name]=[];
}
for(var opt=0,optlen=el.options.length;opt<optlen;opt++){
if(el.options[opt].selected){
_5e[name].push(el.options[opt].value);
}
}
}
}
}
}
return _5e;
},setCheckboxes:function(_62,_63){
var _64=dojo.byId(_62);
if(!_64){
return;
}
for(var f=0;f<_64.elements.length;f++){
if(_64.elements[f].type=="checkbox"){
_64.elements[f].checked=_63;
}
}
},selDemoProps:function(){
this.setCheckboxes("demoForm",true);
return false;
},clrDemoProps:function(){
this.setCheckboxes("demoForm",false);
return false;
},selPhotoProps:function(){
this.setCheckboxes("photoForm",true);
return false;
},clrPhotoProps:function(){
this.setCheckboxes("photoForm",false);
return false;
}});
memory.appController=new memory.controller();
memory.photoRpc=new dojo.rpc.JsonService("../php/memory.smd");

