
 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 //                                                                        
 //  This file was created by rjc from system/js/ii_palette.js%
 //  on 2003/11/11 10:37:26.
 //                                                                        
 //    Copyright 1999-2003 Interactive Information Ltd, All Rights Reserved 
 //    http://information.overlaid.com
 //                                                                        
 //  It is almost certainly a bad idea to edit it.
 //  
 //  ------------------------------------------------------------------------
 //  
 //  Version:	2.3.1 for Grange Scrapbook
 //  Features:	VZERO HSPOPUP DATACOPYRIGHT LABEL LINEAR MAPPING
 //  Scales:	linear
 //  Hotspots:	rect poly circle
 //  Markers:	cross image paintable
 //  
 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
var palette_entries_loaded=false;var palette_entries=[];var palette_entries_n=[];
var palette_type_names=null;var palette_field_names=null;var palette_cached_reslist=null;
var palette_marker_type="cross";var palette_marker_index=null;
var palette_painting_index=null;var palette_selected_types=[];
var palette_modes=[];var palette_relevance=[];var palette_counts=[];
var palette_popup_window='palette_popup';var palette_popup_window_params='width=800,height=500,menubar=yes,scrollbars=yes,resize=yes';
var palette_marker_class="entry";var palette_on_selected=null;
var palette_main_type=3;var palette_timeslot_type=null;var palette_order_function=null;
var palette_type_order=null;var palette_do_subheadings=true;var palette_do_hotspots=false;
var palette_type_separator=",";var palette_load_window=null;var palette_results_window=null;
var palette_labelling_field=null;var palette_labelling_align=1;
var palette_labelling_font=null;var palette_labelling_dx=0;var palette_labelling_dy=0;
function palette_results_frame_is(){var win=palette_results_window;
if(win==null)win=results;}function palette_set_selected(type,val,yesno)
{if(palette_selected_types[type]==null)palette_selected_types[type]=[];
var old=palette_selected_types[type][val]==true;var n=palette_counts[type];
if(n==null)n=0;if(old&&!yesno)n--;if(!old&&yesno)n++;palette_selected_types[type][val]=yesno;
palette_counts[type]=n;palette_cached_reslist=null;if(palette_on_selected!=null)
palette_on_selected(type,val,old,yesno);}function palette_set_mode(type,mode)
{palette_modes[type]=mode;palette_cached_reslist=null;}function palette_set_relevence(type,rel)
{palette_relevance[type]=rel;palette_cached_reslist=null;}function palette_set_all(form,type,val)
{var i;if(palette_selected_types[type]==null){palette_selected_types[type]=[];
palette_counts[type]=0;}for(i=0;i<form.elements.length;i++){var el=form.elements[i];
if(el.type=="checkbox"){var field=el.name;var value=el.value;
if(field==type)palette_set_selected(field,value,el.checked=val);
}else if(el.type.substring(0,6)=="select"){var field=el.name;
if(field==type)for(i in el.options){var op=el.options[i];var value=op.value;
palette_set_selected(field,value,op.selected=val);}}}palette_list_entries(palette_selected_types);
}function palette_update_from_form(form,update){var i;for(i=0;i<form.elements.length;i++)
{var el=form.elements[i];if(el.type=="checkbox")palette_update_from_cb(el,false);
else if(el.type.substring(0,6)=="select")palette_update_from_sel(el,false);
}if(update!=null&&update)palette_list_entries(palette_selected_types);
}function palette_update_from_cb(cb,update){var field=cb.name;
var value=cb.value+"";if(palette_selected_types[field]==null)
{palette_selected_types[field]=[];palette_counts[field]=0;}palette_set_selected(field,value,cb.checked);
if(update==null||update)palette_list_entries(palette_selected_types);
}function palette_update_from_sel(sel,update){var field=sel.name;
if(palette_selected_types[field]==null){palette_selected_types[field]=[];
palette_counts[field]=0;}for(i in sel.options){var op=sel.options[i];
var value=op.value;palette_set_selected(field,value,op.selected);
}if(update==null||update)palette_list_entries(palette_selected_types);
}function palette_set_timeslot(timeslot,val){if(palette_selected_types['timeslot']==null)
{palette_selected_types['timeslot']=[];palette_counts['timeslot']=0;
}if(val!=null&&val==palette_selected_types['timeslot'][timeslot])
return val;if(palette_selected_types['timeslot'][timeslot]==true)
{palette_set_selected('timeslot',timeslot,val=false);}else {palette_set_selected('timeslot',timeslot,val=true);
}return val;}var palette_current_timeslot='';function palette_select_timeslot(timeslot)
{var ret;if(palette_current_timeslot!=timeslot){if(palette_current_timeslot!='')
ret=palette_set_timeslot(palette_current_timeslot,false);palette_current_timeslot=timeslot;
ret=palette_set_timeslot(palette_current_timeslot,true);}palette_cached_reslist=null;
palette_list_entries(palette_selected_types);}function palette_toggle_timeslot(timeslot)
{var ret=palette_set_timeslot(timeslot,null);palette_list_entries(palette_selected_types);
return ret;}function palette_auto_timeslot_select(timeslot){if(cal.show_timeslot(timeslot))
palette_select_timeslot(timeslot);palette_list_entries(palette_selected_types);
}function palette_clear_entry_list(message){palette_entries_loaded=false;
palette_entries=[];palette_entries_n=0;markers_clear();palette_cached_reslist=null;
if(message!=null)palette_write_results_message(message);}function palette_update_results_list()
{palette_list_entries(palette_selected_types);}function palette_start_entry_list(types,fields,message)
{palette_clear_entry_list(message);if(types!=null)palette_type_names=types;
if(fields!=null)palette_field_names=fields;if(palette_load_window==null)
palette_load_window=hidden;hotspot_named[palette_marker_class]=[];
marker_named[palette_marker_class]=[];var i;for(i=0;i<palette_type_names.length;i++)
if(palette_selected_types[palette_type_names[i]]==null){palette_selected_types[palette_type_names[i]]=[];
palette_counts[palette_type_names[i]]=0;}}function palette_record_entry(id,cx,cy)
{if(cx==""||cy=="")return;if(cx-0!=cx||cy-0!=cy)return;palette_record_an_entry(id,cx,cy,null,palette_record_entry.arguments);
}function palette_record_area_entry(id,points){var cx,cy;for(i=0;i<points.length;i+=2)
{cx+=points[i];cy+=points[i+1];}cx /=points.length/2;cy /=points.length/2;
palette_record_an_entry(id,cx,cy,points,palette_record_area_entry.arguments);
}function palette_record_an_entry(id,cx,cy,points,a){var type=a[palette_main_type];
var timeslot=palette_timeslot_type!=null?a[palette_timeslot_type]:"";
var values=[];var types=[];var fields=[];values["id"]=id;values["type"]=type;
values["cx"]=cx;values["cy"]=cy;values["points"]=points;var i,j;
for(i=0,j=3;i<palette_type_names.length;i++,j++)values[palette_type_names[i]]=types[i]=a[j]+"";
for(i=0;i<palette_field_names.length;i++,j++)values[palette_field_names[i]]=fields[i]=a[j];
if(palette_entries[id]==null)palette_entries_n++;if(points==null)
palette_entries[id]=[ id,type,cx,cy,timeslot,types,fields,values ];
else palette_entries[id]=[ id,type,points,null,timeslot,types,fields,values ];
var mkt=palette_marker_index!=null?palette_marker_index[type]:palette_marker_type;
if(mkt==null)mkt=palette_marker_type;var mk=null;var hs=null;
if(points==null)mk=markers_add(id,palette_marker_class,cx,cy,mkt,10,3);
else hs=hotspots_add(id,palette_marker_class,"poly","world",points.join(","));
if(palette_do_hotspots&&hs==null){var rad=Math.floor(5*current_level.xgpp+0.5);
hs=hotspots_add(id,palette_marker_class,"rect","world",(cx-rad)+","+(cy-rad)+","+(rad*2)+","+(rad*2));
if(hs!=null){hotspots_set_status(hs,id);hotspots_enable(hs,true);
}}if(palette_labelling_field!=null){if(mk!=null)markers_set_label(mk,values[palette_labelling_field],
palette_labelling_align,palette_labelling_font,palette_labelling_dx,palette_labelling_dy);
if(hs!=null)hotspots_set_popup(hs,values[palette_labelling_field]);
}var ti;if(palette_painting_index!=null&&mk!=null)for(ti=0;ti<types.length;ti++)
{var tt=types[ti].split(palette_type_separator);var tj;for(tj=0;tj<tt.length;tj++)
{var t=tt[tj];var paintings=palette_painting_index[t];if(paintings!=null)
markers_set_paintings(mk,paintings,true);}}palette_cached_reslist=null;
}function palette_end_entry_list(){palette_entries_loaded=true;
hotspots_activate();palette_update_results_list();}function palette_order_int(e1,e2)
{if(palette_order_function!=null)return palette_order_function(e1[7],e2[7]);
else if(palette_type_order!=null)return palette_type_order[e1[1]]>palette_type_order[e2[1]]?1:-1;
else return e1[1]>e2[1]?1:-1;}var palette_list_entries_inprogress=false;
var palette_list_entries_pending=false;function palette_list_entries(types)
{if(!palette_entries_loaded)return;palette_write_results_message("Preparing Results List");
setTimeout("palette_list_entries_handle();",300);}function palette_display(id)
{var it;if((it=marker_named[palette_marker_class][id])!=null)
markers_display(it);if((it=hotspot_named[palette_marker_class][id])!=null)
{hotspots_set_visible(it,true);hotspots_enable(it,true);}}function palette_undisplay(id)
{var it;if((it=marker_named[palette_marker_class][id])!=null)
markers_undisplay(it);if((it=hotspot_named[palette_marker_class][id])!=null)
{hotspots_set_visible(it,false);hotspots_enable(it,false);}}function palette_list_entries_handle()
{if(the_easel==null)return;palette_list_entries_pending=true;
if(palette_list_entries_inprogress)return;palette_list_entries_inprogress=true;
while(palette_list_entries_pending){palette_list_entries_pending=false;
the_easel.setBatch(1);palette_list_entries_internal(palette_selected_types);
the_easel.setBatch(0);}palette_list_entries_inprogress=false;
}function palette_list_entries_internal(types){if(the_easel==null)return;
var timeslots=palette_selected_types['timeslot'];markers_highlight(null);
easel_get_area();var i;if(palette_cached_reslist==null){i=-1;
palette_cached_reslist=[];for(id in palette_entries){i++;if(palette_list_entries_pending)
return;if((i%100)==20)the_easel.myrepaint();var ap=palette_entries[id];
var type=ap[1];var cx=ap[2];var cy=ap[3];var timeslot=ap[4];var ap_types=ap[5];
var fields=ap[6];if(timeslots!=null&&timeslots[ap[4]]!=true){
palette_undisplay(id);continue;}var t;for(t=0;t<palette_type_names.length;t++)
{var have=ap_types[t].split(palette_type_separator);var want=types[palette_type_names[t]];
var mode=palette_modes[palette_type_names[t]];var rel=palette_relevance[palette_type_names[t]];
if(rel!=null&&rel!=type)continue;var need=1;if(mode=="AND")need=palette_counts[palette_type_names[t]];
else if(mode=="IGNORE")need=0;var hi;var got=0;for(hi=0;hi<have.length;hi++)
{if(want[have[hi]]==true){got++;}}if(got<need){palette_undisplay(id);
t=-1;break;}}if(t<0)continue;palette_display(id);if(palette_do_hotspots)
hotspots_enable(hotspot_named[palette_marker_class][id],true);
palette_cached_reslist[palette_cached_reslist.length]=ap;}}var reslist=[];
for(i=0;i<palette_cached_reslist.length;i++){if(palette_list_entries_pending)
return;var ap=palette_cached_reslist[i];var cx=ap[2];var cy=ap[3];
if(cy==null){var hs=hotspot_named[palette_marker_class][ap[0]];
if(hotspots_overlaps(hs,selected_x,selected_y,selected_w,selected_h))
reslist[reslist.length]=ap;}else {if(selected_x<=cx&&selected_y<=cy &&selected_x+selected_w>=cx&&selected_y+selected_h>=cy)
reslist[reslist.length]=ap;}}the_easel.setBatch(0);if(palette_list_entries_pending)
return;reslist.sort(palette_order_int);var restypes=[];var type='';
for(i=0;i<reslist.length;i++){if(reslist[i][1]!=type)restypes[restypes.length]=type=reslist[i][1];
}var subheads=(palette_do_subheadings==true&&restypes.length>1)|| (restypes.length>palette_do_subheadings);
var currhead='';if(palette_list_entries_pending)return;var win=palette_results_frame_is();
win.document.open("text/html");palette_write_head(win);palette_write_results_top(win,palette_entries_n,reslist.length,restypes);
for(i=0;i<reslist.length;i++){var ap=reslist[i];var id=ap[0];
var type=ap[1];var cx=ap[2];var cy=ap[3];var values=ap[7];if(subheads&&type!=currhead)
{palette_write_subheading(win,type);currhead=type;}palette_write_result(win,id,type,cx,cy,values);
if(palette_list_entries_pending)return;}palette_write_results_bottom(win,palette_entries_n,reslist.length);
palette_write_foot(win);win.document.close();}function palette_popup(link)
{var win=window.open(link.href,palette_popup_window,palette_popup_window_params);
win.focus();return(false);}function palette_show_anchor(win,name)
{var a=win.document.anchors[name];if(a==null){var i;for(i=0;i<win.document.anchors.length;i++)
if(name==win.document.anchors[i].name){a=win.document.anchors[i];
break;}}if(a!=null){if(a.y!=null)win.scrollTo(0,a.y);else if(a.scrollIntoView!=null)
a.scrollIntoView();}}var palette_highlighted_hotspot=null;function palette_highlight_entry(id)
{if(the_easel==null)return;var mk=marker_named[palette_marker_class][id];
if(mk!=null)markers_highlight(mk);else markers_highlight(null);
if(palette_highlighted_hotspot!=null){hotspots_select(palette_highlighted_hotspot,false);
palette_highlighted_hotspot=null;}var hs=hotspot_named[palette_marker_class][id];
if(hs!=null){palette_highlighted_hotspot=hs;hotspots_select(palette_highlighted_hotspot,true);
}}function palette_zoom_to_entry(id){var mk=marker_named[palette_marker_class][id];
if(mk==null)return;markers_zoom_to(mk,1,1);}function palette_write_results_message(m)
{var win=palette_results_frame_is();win.document.close();win.document.open("text/html");
palette_write_head(win);win.document.writeln("<h1 align=center>"+m+"</h1>");
palette_write_foot(win);win.document.close();}
