fix genefamily search.pl compilation error
[sgn.git] / documents / inc / secretary.js
blob9f6d1209d0aee106426940288994128ccaa59371
1 /*** Third-party Javascript Code **************************************************************************
2 **********************************************************************************************************
3 */
5 /** NOTICE: This code has been modified for ease of use.  Please download the original from
6 http://www.jaaulde.com/test_bed/cookieLib/ for the original (and latest) versions
7 /*
8 Copyright (c) 2005, James Auldridge
9 All rights reserved.
10 Code licensed under the BSD License:
11   http://www.jaaulde.com/license.txt
12 Version 1.2
14 var Cookie = window.Cookie || {};
15 Cookie = {
16         get: function(cookieName) {
17                 var cookieNameStart,valueStart,valueEnd,value;
18                 cookieNameStart = document.cookie.indexOf(cookieName+'=');
19                 if (cookieNameStart < 0) {return null;}
20                 valueStart = document.cookie.indexOf(cookieName+'=') + cookieName.length + 1;
21                 valueEnd = document.cookie.indexOf(";",valueStart);
22                 if (valueEnd == -1){valueEnd = document.cookie.length;}
23                 value = document.cookie.substring(valueStart,valueEnd );
24                 value = unescape(value);
25                 if (value == "") {return null;}
26                 return value;
27         },
28         set: function(cookieName,value,hoursToLive,path,domain,secure) {
29                 var domainRegEx = /[^.]+\.[^.]+$/;
30                 domain = window.location.hostname.match(domainRegEx);
31                 if(domain == 'cornell.edu') domain = 'sgn.cornell.edu';
32                 var expireString,timerObj,expireAt,pathString,domainString,secureString,setCookieString;
33                 if (!hoursToLive || typeof hoursToLive != 'number' || parseInt(hoursToLive)=='NaN'){
34                         expireString = "";
35                 }
36                 else {
37                         timerObj = new Date();
38                         timerObj.setTime(timerObj.getTime()+(parseInt(hoursToLive)*60*60*1000));
39                         expireAt = timerObj.toGMTString();
40                         expireString = "; expires="+expireAt;
41                 }
42                 pathString = "; path=";
43                 (!path || path=="") ? pathString += "/" : pathString += path;
44                 domainString = "; domain=";
45                 (!domain || domain=="") ? domainString += window.location.hostname : domainString += domain;
46                 (secure === true) ? secureString = "; secure" : secureString = "";
47                 value = escape(value);
48                 setCookieString = cookieName+"="+value+expireString+pathString+domainString;
49                 document.cookie = setCookieString;
50         },
51         del: function(cookieName,path,domain){
52           (!path || !path.length) ? path="" : path=path;
53           (!domain || !domain.length) ? domain="" : domain=domain;
54                 Cookie.utils.cookies.set(cookieName,"",-8760,path,domain);
55         },
56         test: function(){
57                 Cookie.utils.cookies.set('cT','acc');
58                 var runTest = Cookie.utils.cookies.get('cT');
59                 if (runTest == 'acc'){
60                         Cookie.utils.cookies.del('cT');
61                         testStatus = true;
62                 }
63                 else {
64                         testStatus = false;
65                 }
66                 return testStatus;
67         }
72 /** Javascript Code written by C. Carpita and ******* ***************************************************
73 *********************************************************************************************************
74 *********************************************************************************************************
79 /**
80 ************** Misc Secretary Functions ***********************************HEADER************************
81 **/
83 function getSel() {
84         var txt = '';
85         var foundIn = '';
86         document.getElementById('selectedblastp').innerHTML = "";
87         document.getElementById('selectedblastnfull').innerHTML = "";
88         document.getElementById('selectedblastncds').innerHTML = "";
89         
90         if (window.getSelection)
91         {
92                 txt = window.getSelection();
93                 foundIn = 'window.getSelection()';
94         }
95         else if (document.getSelection)
96         {
97                 txt = document.getSelection();
98                 foundIn = 'document.getSelection()';
99         }
100         else if (document.selection)
101         {
102                 txt = document.selection.createRange().text;
103                 foundIn = 'document.selection.createRange()';
104         }
105         else return false;
106         //fixtxt = txt.replace(/<br>/ig, "");
107         var fixtxt = new String(txt);
109         fixtxt = fixtxt.replace(/\W/ig, "");
110         if (fixtxt.match(/^[A-Z]+$/)) {
111                 return fixtxt;
112         }
113         else return false;
116 function selectedblastp(selection){
117       HTML = "<a class='external' href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Put&QUERY=" + selection + "&DATABASE=nr&PROGRAM=blastp&FILTER=L&HITLIST_SZE=500'>Perform BLASTP on Selection (" + selection.length + " aa)</a>";
118       document.getElementById('selectedblastp').innerHTML = HTML;
122 function selectedblastnfull(selection){
123       HTML = "<a class='external' href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Put&QUERY=" + selection + "&DATABASE=nr&PROGRAM=blastn&FILTER=L&HITLIST_SZE=500'>Perform BLASTN on Selection (" + selection.length + " bp)</a>";
124       document.getElementById('selectedblastnfull').innerHTML = HTML;
127 function selectedblastncds(selection){
128       HTML = "<a class='external' href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Put&QUERY=" + selection + "&DATABASE=nr&PROGRAM=blastn&FILTER=L&HITLIST_SZE=500'>Perform BLASTN on Selection (" + selection.length + " bp)</a>";
129       document.getElementById('selectedblastncds').innerHTML = HTML;
133 function closebox(boxID) {
134         document.getElementById(boxID).style.display="none";
135         return false;
138 /** Only works on <span> tags for a given class name, currently alters the following properties:
139 ***** color, backgroundColor, border, fontWeight  **/
140 function classAlter(className, styleProperty, styleValue) {
141         for (i=0;i<document.getElementsByTagName("span").length; i++) {
142                 if (document.getElementsByTagName("span").item(i).className == className){
143                         if(styleProperty == "color"){
144                                 document.getElementsByTagName("span").item(i).style.color = styleValue;
145                         }
146                         else if(styleProperty == "backgroundColor"){
147                                 document.getElementsByTagName("span").item(i).style.backgroundColor = styleValue;
148                         }
149                         else if(styleProperty == "border"){
150                                 document.getElementsByTagName("span").item(i).style.border = styleValue;
151                         }
152                         else if(styleProperty == "fontWeight"){
153                                 document.getElementsByTagName("span").item(i).style.fontWeight = styleValue;
154                         }
155                 }       
156         }
159 /* Must match value in class highlightColor of the css file
161 var searchHighlightColor = "#c9c9ff";
162 var searchHighlight = 0;
164 //Ensures that cookie object is instantiated, as well as Highlight Toggle-dependent functions
165 function prepareSearchHighlight(){
166         if(Cookie){
167                 if(UserPrefs.get('searchHighlight')){
168                         searchHighlight = UserPrefs.get('searchHighlight');
169                 }
170         }
171         //Ok, this may look weird.  What we are doing is priming browser cache by calling the toggle function, which calls the classAlter function
172         // and iterates through all of the <span> tags.  Therefore, the switches occur more quickly when the user first clicks the button.
173         if (searchHighlight == 1){ 
174                 searchHighlight = 0; 
175                 toggleSearchHighlight();  //this will set searchHighlight back to 1, don't worry ;) 
176         }
177         else{
178                 searchHighlight = 1;
179                 toggleSearchHighlight();
180         }
183 function toggleSearchHighlight(nocookieset){
184         if(searchHighlight){
185                 classAlter("searchHighlight", "backgroundColor", "white");
186                 document.getElementById("highlightSelector").style.display = "inline";
187                 document.getElementById("unhighlightSelector").style.display = "none";
188                 searchHighlight = 0;
189                 UserPrefs.set('searchHighlight', 0);
190                 if(!nocookieset) UserPrefs.setCookie();
191         }
192         else {
193                 classAlter("searchHighlight", "backgroundColor", searchHighlightColor);
194                 document.getElementById("highlightSelector").style.display = "none";
195                 document.getElementById("unhighlightSelector").style.display = "inline";
196                 searchHighlight = 1;
197                 UserPrefs.set('searchHighlight', 1);
198                 if(!nocookieset) UserPrefs.setCookie();
199         }
203 ************** Secretary Database Query Functions *********************HEADER*****************************
207 var selectTextColorBg = "#771111"; //background color of active text
208 var selectTextColor = "#332277";  //color of unselected checkbox text
210 var joiners = new Array();
212 for(var i=0; i<10; i++) joiners.push("AND");
214 function selectModify(num, type){
216         if(type=='rem'){
217                 document.getElementById("condcontainer" + num).style.display = "none";
218                 document.getElementById("selrem" + num).style.display = "none";
219                 if(num<10) document.getElementById("seladd" + num).style.display = "none";
220                 document.getElementById("seladd" + (num-1)).style.display = "inline";
221                 if (num > 1) document.getElementById("selrem" + (num-1)).style.display = "inline";
222                 document.getElementById("condvar"+num).value="";
223                 document.getElementById("condop"+num).value="=";
224                 document.getElementById("condoperand"+num).value="";
225         }
226         if(type=='add'){
227                 if(num<10) document.getElementById("condcontainer" + (num+1)).style.display="inline";
228                 if(num<10) document.getElementById("selrem" + (num+1)).style.display="inline";
229                 if(num<9) document.getElementById("seladd" + (num+1)).style.display="inline";
230                 document.getElementById("seladd" + num).style.display="none";
231                 if(num>0) document.getElementById("selrem" + num).style.display="none"
232         }
235 function selectSwitch(value, item){
236         box = document.getElementById("cb." + value);
237         text = document.getElementById("text." + value);
238         
239         if(item){
240                 box = document.getElementById("cb." + value + "." + item);
241                 text = document.getElementById("text." + value + "." + item);
242         }
243         if(box.checked) {
244                 box.checked = false;
245                 text.style.backgroundColor = "white";
246                 text.style.color = selectTextColor;
247                 text.style.fontWeight = "normal";
248         }
249         else {
250                 box.checked = true;
251                 text.style.backgroundColor = selectTextColorBg; 
252                 text.style.color = "white";
253                 text.style.fontWeight = "bold";
255                 if(value != "COUNT"){
256                                 document.getElementById("cb.COUNT").checked = false;
257                                 text = document.getElementById("text.COUNT");
258                                 text.style.color = "#332277"
259                                 text.style.backgroundColor = "white";
260                                 text.style.fontWeight = "normal";
261                 }
262         }
267 function cbColorSwitch(value, item){
268         
269         box = document.getElementById("cb." + value);
270         text = document.getElementById("text." + value);
271         
272         if(item){
273                 box = document.getElementById("cb." + value + "." + item);
274                 text = document.getElementById("text." + value + "." + item);
275         }
278         if(!box.checked) {
279                 text.style.backgroundColor = "white";
280                 text.style.color = selectTextColor;
281                 text.style.fontWeight = "normal";
282         }
283         else {
284                 text.style.backgroundColor = selectTextColorBg;
285                 text.style.color = "white";
286                 text.style.fontWeight = "bold";
287         }
291 function switchJoin(id){
292         joinercontent = document.getElementById("joinercontent"+id);
293         formjoiner = document.getElementById("formjoiner" + id);
294         if (joinercontent.innerHTML=="AND"){
295                 joinercontent.innerHTML="OR";
296                 joiners[id-1] = "OR";
297                 formjoiner.value = "OR";
298         }
299         else{
300                 joinercontent.innerHTML="AND";
301                 joiners[id-1] = "AND";
302                 formjoiner.value = "AND";
303         }
306 function switchParen(id){
307         formparen = document.getElementById("formparen"+id);
308         parencontent = document.getElementById("parencontent"+id);
309         jointop = document.getElementById("jointop"+id);
310         joinbottom = document.getElementById("joinbottom"+id);
312         if(formparen.value=='0'){
313                 formparen.value=1;
314                 parencontent.innerHTML = "<span style='color:#442277'>(Unjoin)</span>";
315                 jointop.innerHTML="";
316                 joinbottom.innerHTML="";
317         }
318         else{
319                 formparen.value=0;
320                 parencontent.innerHTML = "(Join)";
321                 jointop.innerHTML="<br>";
322                 joinbottom.innerHTML="<br>";
323         }
327 function variableChange(id){
328         variable = document.getElementById("condvar" + id);
329         operator = document.getElementById("condop" + id);
330         type = variable.value.charAt(0);
331         if(type=="f" || type=="i") operator.value = ">";
332         else if(type=="r") operator.value = "REGEXP";
333         else if(type=="t") operator.value = "FULLTEXT";
336 function chartTypeChange(){
337         ctype = document.getElementById("charttype");
338         pie_opt = document.getElementById("pie_options");
339         bar_opt = document.getElementById("bar_options");
340         if(ctype.value==''){
341                 pie_opt.style.display = "none";
342                 bar_opt.style.display = "none";
343         }
344         else if(ctype.value=="pie"){
345                 pie_opt.style.display = "block";
346                 bar_opt.style.display = "none";
347         }
348         else{
349                 pie_opt.style.display = "none";
350                 bar_opt.style.display = "block";
351         }
354 var num=0;
355 var live=1;
356 var last=3;
358 function killAnimateDots(){
359         live = 0;
362 function animateDots(){
363         num = num+1;
364         if(num>3) num = 0;
365         last = num - 1;
366         if(last<0) last = 3;
367         
368         document.getElementById("dots"+last).style.display="none";
369         document.getElementById("dots"+num).style.display="inline";
370         
371         if(live) setTimeout("animateDots()", 500); 
375 function closeBox(name){
376         document.getElementById(name+"_hide").style.display="none";     
377         document.getElementById(name+"_show").style.display="inline";
378         document.getElementById(name+"_table").style.display="none";
379         document.getElementById(name+"_box").style.borderColor="#555555";
380         document.getElementById(name+"_header").style.backgroundColor="#555555";
383 function openBox(name){
384         document.getElementById(name+"_hide").style.display="inline";   
385         document.getElementById(name+"_show").style.display="none";
386         document.getElementById(name+"_table").style.display="inline";
388         var activeColor = "";
389         if(name=="chart") activeColor = "#444499";
390         else if(name=="select") activeColor = "#770000";
391         else if(name=="cond") activeColor = "#551155";
393         document.getElementById(name+"_box").style.borderColor = activeColor;
394         document.getElementById(name+"_header").style.backgroundColor = activeColor;
399 *************** Hotlist Functions ***************************HEADER****************************************
402 //var user_pref_string is used (global already set in header))
403 //Used to set user_pref_string variables for the current user.
404 var UserPrefs = {
405         _preferences: new Object,
406         init: function() {
408                 //the string is initially set server-side, so if we don't get
409                 //anything, we try the client-side cookie
410                 if(!user_pref_string.length) UserPrefs.loadCookie();
411         
412                 if(user_pref_string.length && user_pref_string.indexOf('=') && user_pref_string.indexOf(":")) {
413                         var pref_array = user_pref_string.split(":");
414                         for(var n = 0; n < pref_array.length; n++) {
415                                 var key_val = pref_array[n].split("=");
416                                 if(key_val[0].length>0 && key_val[1].length>0){
417                                         UserPrefs._preferences[key_val[0]] = key_val[1];
418                                 }
419                         }
420                 }
421                 UserPrefs.setCookie();
422         },      
423         setCookie: function() {
424                 var thisDate = new Date();
425                 var base = new Date(0);
426                 var skew = base.getTime(); 
427                 var unix_epoch_time = thisDate.getTime();
428         if (skew > 0)  unix_epoch_time -= skew;  //Steve Jobs is a prick!
429                 UserPrefs._preferences.timestamp = unix_epoch_time;
430                 UserPrefs._preferences.sp_person_id = user_id;
431                 UserPrefs._buildString();
432                 Cookie.set('user_prefs', user_pref_string, 1000);
433         },
434         //sendPrefs will make an AJAX request to the server, writing the cookie string to the database.  neat-o!
435         //ONLY use this when you anticipate that the user will set a preference and not load another page.  The page-loading process will update the user_prefs string in the database from the user's cookie.
436         send: function() {
437                 var req = new Request();                
438                 if(req.isValid()){
440                         var parameters = "?sp_person_id=" + user_id + "&user_prefs=" + encodeURIComponent(user_pref_string); 
441                         req.sendRequest("/scraps/set_user_prefs.pl", parameters);
442                         return true;
443                 }
444                 return false;
445         },
446         loadCookie: function() {
447                 user_pref_string = Cookie.get('user_prefs');
448         },
449         _buildString: function() {
450                 var new_string = '';
451                 var i = 0;
452                 for(var name in UserPrefs._preferences){
453                         if(i>0) new_string += ":";
454                         new_string += name + "=" + UserPrefs._preferences[name];
455                         i++;
456                 }
457                 user_pref_string = new_string;
458         },
459         set: function(name, value) {
460                 UserPrefs._preferences[name] = value;
461         },
462         get: function(name) {
463                 return UserPrefs._preferences[name];
464         }
466 UserPrefs.init();
469 //Encapsulates all of our visual effects on Secretary
470 var Effects = {
472         switchHotlistButton: function(buttonId, switchTo, content, clearOnClick){
473                 var button = document.getElementById(buttonId);
474                 var imgAdd = document.getElementById(buttonId + ":imgAdd");
475                 var imgRemove = document.getElementById(buttonId + ":imgRemove");
476         
477                 var optionalText = "All AGIs on this Page ";
478                 if(!content.match(/:/)) optionalText = "";
479                 if(switchTo == 'remove'){  
480                         imgAdd.style.display = "none";
481                         imgRemove.style.display = "inline";
482                         button.firstChild.nodeValue = "Remove " + optionalText + "from Hotlist";
483                         if(clearOnClick){
484                                 button.setAttribute("onClick", "alert('some')");
485                         }
486                         else {
487                                 button.setAttribute("onClick", "Hotlist.remove('" + buttonId + "', '" + content + "'); return false;");
488                         }
489                 }
490                 else if (switchTo == 'add'){ 
491                         imgAdd.style.display = "inline";
492                         imgRemove.style.display = "none";
493                         button.firstChild.nodeValue = "Add " + optionalText + "to Hotlist";
494                         if(clearOnClick){
495                                 button.setAttribute("onClick", "alert('some')");
496                         }
497                         else {
498                                 button.setAttribute("onClick", "Hotlist.add('" + buttonId + "', '" + content + "'); return false;");
499                         }
500                 }
501                 else { alert("You sent a bad switchTo variable to switchHotlistButton"); }
502         },
503         showElement: function(elementId, displayMethod) {
504                 var element = document.getElementById(elementId);
505                 var dispMethod;
506                 if(displayMethod) {
507                         dispMethod = displayMethod;
508                 }
509                 else { dispMethod = "inline" }
510                 element.style.display = dispMethod;
511         },
512         hideElement: function(elementId, displayMethod) {
513                 var element = document.getElementById(elementId);
514                 var dispMethod = "";
515                 if(displayMethod) {
516                         dispMethod = displayMethod
517                 }
518                 else { dispMethod = "none"; } //alternative is "hidden", which causes it to continue occupying space on the page
519                 element.style.display = dispMethod;
520         },
521         swapElements: function(elementIdFrom, elementIdTo, displayMethod){
522                 try {   
523                         var dispMethod = displayMethod || "inline";
524                         var elementFrom = document.getElementById(elementIdFrom);
525                         var elementTo = document.getElementById(elementIdTo);
526                         elementFrom.style.display = "none";
527                         elementTo.style.display = dispMethod;
528                 }
529                 catch(e) { alert(e) }
530         }
535 function RequestWaitIndicator(waitElementId) {
536                 
537         RequestWaitIndicator.numWaits += 1;
538         this.id = "RWI:" + RequestWaitIndicator.numWaits;
539         RequestWaitIndicator.waitHash[this.id] = 1;     
540         this.waitElementId = waitElementId;     
541         setTimeout("RequestWaitIndicator.displayElement('" + this.id + "', '" + this.waitElementId + "')", 1000);
542         
543         this.stopWait = function () {
544                 RequestWaitIndicator.waitHash[this.id] = 0;
545                 Effects.hideElement(waitElementId);
546         }
548 RequestWaitIndicator.numWaits = 0;
549 RequestWaitIndicator.waitHash = {};
550 RequestWaitIndicator.displayElement = function (waitId, elementId) {
551         if (RequestWaitIndicator.waitHash[waitId]){
552                 Effects.showElement(elementId);
553         }
558 //Request Object
559 //The returned XML file should contain all information needed to cause a page effect,
560 //rather than creating a custom response for each request, which is not possible due
561 //to the security issues that prevent the creation of instances of XMLHttpRequest() 
562 //with unique properties
563 function Request() {
564         
565         var request = null;
566         var valid = false;
567         var loader = this;
568         
569         if(window.XMLHttpRequest) {
570                 request = new XMLHttpRequest();
571         }
572         else if (window.ActiveXObject) {
573                 try { request = new ActiveXObject("Msxml2.XMLHTTP");}
574                 catch(e) {
575                         try { request = new ActiveXObject ("Microsoft.XMLHTTP");}
576                         catch (e) {}
577                 }
578         }
579         
580         if(request) { 
581                 valid = true;
582                 request.onreadystatechange = function() { loader.onReadyState.call() }
583         }
584         
586         this.isValid= function () { return valid }
587         this.onReadyState= function() { //override this function in a subclass!!
588                 if(request.readyState==4){
589                         if(request.responseText.indexOf('E:')==0) alert(request.responseText);
590                         XMLroute(request.responseXML);  
591                 }
592         }       
593         this.sendRequest= function(url, parameters, method) {
594                 if(!method) { method = "GET" }
595                 request.open(method, url + parameters, true);
596                 request.send(null);
597         }
600 //finds the calling object name in the XML response and directs the document to the appropriate handler
601 function XMLroute (response) {
602         var doc = response;
603         var caller = doc.getElementsByTagName("caller")[0].firstChild.nodeValue;
604         if(caller=="Hotlist") {
605                         Hotlist._response(doc);
606         }
607         else {
608                 // insert 'if' statements to route to other handlers
609         }
613 //Hotlist is defined as a single object instead of a class. We can't have more than one!
614 var Hotlist = window.Hotlist || {};
615 Hotlist = { //buttonId: id of the clicked button, for changing the button
616         add: function(buttonId, content) {
617                 if(!buttonId) { alert("buttonId not sent!"); }
618                 var waitIndicator;// = new RequestWaitIndicator("hotlistWait:" + content);              
619                 var request = new Request();
620                 if(request.isValid()) {
621                         Effects.switchHotlistButton(buttonId, 'remove', content, 1);  //last argument clears onClick to prevent user interaction
622                         var parameters = "?owner=" + user_id + "&button_id=" + buttonId + "&cookie_string=" + cookie_string + "&action=add&content=" + content;
623                         request.sendRequest("/scraps/hotlist.pl", parameters);
624                 }
625                 else { alert('invalid request') }
626         },
627         remove: function (buttonId, content) {
628                 if(!buttonId) { alert("buttonId not sent!"); }
629                 var waitIndicator;// = new RequestWaitIndicator("hotlistWait:" + content);              
630                 var request = new Request();
631                 if(request.isValid()) {
632                         Effects.switchHotlistButton(buttonId, 'add', content, 1);
633                         var parameters = "?owner=" + user_id + "&button_id=" + buttonId + "&cookie_string=" + cookie_string + "&action=remove&content=" + content;
634                         request.sendRequest("/scraps/hotlist.pl", parameters);
635                 }
636         },
637         _response: function(doc) {
638                 var newsize = doc.getElementsByTagName("newsize")[0].firstChild.nodeValue;
639                 var oldsize = doc.getElementsByTagName("oldsize")[0].firstChild.nodeValue;
640                 var content = doc.getElementsByTagName("content")[0].firstChild.nodeValue;
641                 var action = doc.getElementsByTagName("action")[0].firstChild.nodeValue;
642                 var buttonId = doc.getElementsByTagName("buttonId")[0].firstChild.nodeValue;
643                 if(newsize > oldsize){
644                         Hotlist._addResponse(buttonId, content, newsize);
645                 }
646                 else if(newsize < oldsize) {
647                         Hotlist._removeResponse(buttonId, content, newsize);
648                 }
649                 else {
650                         Hotlist._nullResponse(buttonId, content, action);
651                         alert(doc);  //temporary
652                 }
653         },
654         _addResponse: function(buttonId, content, newsize){
655                 Effects.switchHotlistButton(buttonId, 'remove', content); //will restore onClick attribute
656                 document.getElementById('hlsize').firstChild.nodeValue = newsize;
657         },
658         _removeResponse: function(buttonId, content, newsize){
659                 Effects.switchHotlistButton(buttonId, 'add', content);
660                 document.getElementById('hlsize').firstChild.nodeValue = newsize;
661         },
662         _nullResponse: function(buttonId, content, action) {
663                 if(action == "add") {
664                         Effects.switchHotlistButton(buttonId, 'add', content); //change back
665                 }
666                 if(action == "remove") {
667                         Effects.switchHotlistButton(buttonId, 'add', content); //change back
668                 }
669         } 
673 ********* User account related functions ****************HEADER************************************************
678 var http_request = false;
680 function makeRequest(url, parameters, type) {
682       http_request = false;
684       if (window.XMLHttpRequest) { // Mozilla, Safari,...
685          http_request = new XMLHttpRequest();
686          if (http_request.overrideMimeType) {
687             http_request.overrideMimeType('text/xml');
688          }
689       } else if (window.ActiveXObject) { // IE
690          try {
691             http_request = new ActiveXObject("Msxml2.XMLHTTP");
692          } catch (e) {
693             try {
694                http_request = new ActiveXObject("Microsoft.XMLHTTP");
695             } catch (e) {}
696          }
697       }
698         if (!http_request) {
699              //print("<!--Async XML Request Failed-->");
700          return false;
701       }
702       if (type=='username') http_request.onreadystatechange = alertContentsName;
703       http_request.open('GET', url + parameters, true);
704       http_request.send(null);
705           return true;
708 function alertContentsName() {
709       if (http_request.readyState == 4) {
710          if (http_request.status == 200) {
711             check_name_response(http_request.responseText);
712                 return true;
713          }
714           else return true;
715       }
716       else return false;
717    }
720 function check_password(password){
721         if(password==""){
722                 document.getElementById('quickwarning').innerHTML = "&nbsp;";
723                 document.getElementById('choosepw').style.color= "black"; 
724     }
725         else if(password.length < 7){
726                 document.getElementById('quickwarning').innerHTML = "Password must be at least 7 characters long";
727                 document.getElementById('choosepw').style.color= "#dd4444"; 
728         }
729         else {
730                 document.getElementById('quickwarning').innerHTML = "&nbsp;";
731                 document.getElementById('choosepw').style.color = "black";
732         }
735 function check_password_match(passwordrep){
736         password = document.cf.password.value;
737         if(passwordrep=="" || password.length==0){
738                 document.getElementById('quickwarning').innerHTML = "&nbsp;"
739                 document.getElementById('confirmpw').style.color = "black";
740         }
741         else if(passwordrep != password){
742                 document.getElementById('quickwarning').innerHTML = "Repeated password doesn't match";
743                 document.getElementById('confirmpw').style.color = "#dd4444";
744         }
745         else{
746                 document.getElementById('quickwarning').innerHTML = "&nbsp;";
747                 document.getElementById('confirmpw').style.color = "black";
748         }
753 function check_name(username){
754   if(username==""){
755         document.getElementById('quickwarning').innerHTML = "&nbsp;";         
756         document.getElementById('chooseuname').style.color = "black";
757         document.getElementById('uname_available').style.display = "none";
758         document.getElementById('uname_taken').style.display = "none";
759   }
760   else if(username.length < 7){
761         document.getElementById('quickwarning').firstChild.nodeValue = "Username must be at least 7 characters long";
762         document.getElementById('chooseuname').style.color = "#dd4444";
763         document.getElementById('uname_available').style.display = "none";
764         document.getElementById('uname_taken').style.display = "none";
765   }
766   else  {
767         document.getElementById('quickwarning').innerHTML = "&nbsp;";
768         document.getElementById('chooseuname').style.color = "black";
769         makeRequest('scraps/check_name_avail.pl', '?username=' + username, 'username');
770   }
773 function check_email(email){
775   var ereg = /^[^@]+@[^@]+$/; 
776   if(email==""){
777         document.getElementById('quickwarning').innerHTML = "&nbsp;";         
778         document.getElementById('chooseemail').style.color = "black";
779   }
780   else if(!email.match(ereg)){
781         document.getElementById('quickwarning').innerHTML = "E-mail not of the form: name@address";
782         document.getElementById('chooseemail').style.color = "#dd4444";
783   
784   }
785   else  {
786         document.getElementById('quickwarning').innerHTML = "&nbsp;";
787         document.getElementById('chooseemail').style.color = "black";
788   }
791 function check_name_response(response){
792         if (response=='1') {
793                 document.getElementById('uname_available').style.display = "inline";
794                 document.getElementById('uname_taken').style.display = "none";
795         }
796         else if(response=='0') {
797                 document.getElementById('uname_available').style.display = "none";
798                 document.getElementById('uname_taken').style.display = "inline";
799         }
800         else {
801                 document.getElementById('uname_available').style.display = "none";
802                 document.getElementById('uname_taken').style.display = "none";
803         }
807 function hide_warning(){
808         document.getElementById('login_warning').style.display="none";
811 function new_user(){
812         document.getElementById('login_box').style.display="none";
813         document.getElementById('createaccount_box').style.display="block";
814         document.getElementById('newuname').focus();
815         return false;
818 function hide_create(){
819         document.getElementById("createaccount_box").style.display="none";
820         document.getElementById("userbar_container").style.display="block"; 
821         document.getElementById("login_warning").style.display="none";
822         return false;
825 function hide_login(){
826         document.getElementById("login_box").style.display="none"; 
827         document.getElementById("userbar_container").style.display="block"; 
828         document.getElementById("login_warning").style.display="none";
829         return false;
832 function show_login(){
833         document.getElementById("login_box").style.display="block"; 
834         document.getElementById("userbar_container").style.display="none"; 
835         document.getElementById("uname").focus(); 
836         document.getElementById("login_warning").style.display="none";
837         return false;
842 /** 
843 **** List Functions ****************************HEADER**********************************************************
845 var http_request_mylistpage = false;
846 var workinglist = "";
848 var lastAction = "";
849 var lastList = "";
850 var lastNewList = "";
853 function makeRequestMylist(url, parameters, type, list) {
855           workinglist = list;
856       http_request_mylistpage = false;
858       if (window.XMLHttpRequest) { // Mozilla, Safari,...
859          http_request_mylistpage = new XMLHttpRequest();
860          if (http_request_mylistpage.overrideMimeType) {
861             http_request_mylistpage.overrideMimeType('text/xml');
862          }
863       } else if (window.ActiveXObject) { // IE
864          try {
865             http_request_mylistpage = new ActiveXObject("Msxml2.XMLHTTP");
866          } catch (e) {
867             try {
868                http_request_mylistpage = new ActiveXObject("Microsoft.XMLHTTP");
869             } catch (e) {}
870          }
871       }
872       if (!http_request_mylistpage) {
873                  return false;
874       }
875       if (type=='alterlist') http_request_mylistpage.onreadystatechange = alertContentsList;
876       if (type=='FASTA') http_request_mylistpage.onreadystatechange = alertContentsFASTA;
877       http_request_mylistpage.open('GET', url + parameters, true);
878       http_request_mylistpage.send(null);
879           return true;
883 function alertContentsList() {
884       if (http_request_mylistpage.readyState == 4) {
885          if (http_request_mylistpage.status == 200) {
886             mylist_response(http_request_mylistpage.responseText);
887             return true;
888          }
889          else return true;
890       }
891       else return false;
892    }
894 function alertContentsFASTA(list){
895       if (http_request_mylistpage.readyState == 4) {
896          if (http_request_mylistpage.status == 200) {
897             fasta_response(http_request_mylistpage.responseText);
898             return true;
899          }
900          else return true;
901       }
902       else return false;
903    }
906 function createFASTA(type, list) {
907         document.getElementById(list+'_fetch').style.display='inline';
908         document.getElementById(list+'_cleartool').style.display="none";
909         document.getElementById(list+'_createfastalinks').style.display="none";
910         if(type!="full" && type!="cds" && type!="prot" && type!="cdna") type="full";
912         var RequestURL = "fastacreate.php?user=<?php echo $username?>&type=" + type + "&list="+list; 
913         makeRequestMylist(RequestURL, "", "FASTA", list);               
917 function fasta_response(output) {
918         var list = workinglist;
919         document.getElementById(list+"_FASTAbox").value = output;               
920         document.getElementById(list+"_FASTAholder").style.display="block";
921         document.getElementById(list+"_fetch").style.display='none';
922         document.getElementById(list+"_cleartool").style.display="inline";
923         document.getElementById(list+"_createfastalinks").style.display = "inline";
926 function undoLast(){
927         var action;
928         if(lastAction=="add") action = "remove";
929         else if(lastAction=="remove") action = "add";
931         alterList()
936 function alterList(newlist, action, list){      
937         
938         lastAction = action;
939         lastList = list;
940         lastNewList = newlist;
942         var RequestURL = "alterlist.php?user=<?php echo $username?>&md5pass=<?php echo $password?>";
943         RequestURL += "&list="+list+"&newlist=" + newlist + "&action=" + action;
944         makeRequestMylist(RequestURL, "", "alterlist", list);   
947 var clear_reload = 0;
948 function clearList(list){
949         
950         RequestURL = "alterlist.php?user=<?php echo $username?>&md5pass=<?php echo $password?>";
951         RequestURL += "&list="+list+"&clear=1";
952         makeRequestMylist(RequestURL, "", "alterlist", list);
953         clear_reload = 1;
956 function alterLink(id, action, list){
957         
958         if(action=="add") HTML = "<a href='#' onclick='alterList(\"" + id + "\", \"add\", \""+list+"\"); alterLink(\"" + id + "\", \"remove\", \""+list+"\"); return false;' style='text-decoration:none'>[ <img src='/img/hotlist_add.png' border=0 align='absmiddle'> Re-Add ]</a>";
959         else if (action=="remove") HTML = "<a href='#' onclick='alterList(\"" + id + "\", \"remove\", \""+list+"\"); alterLink(\"" + id + "\", \"add\", \""+list+"\"); return false;' style='text-decoration:none'>[ <img src='/img/hotlist_remove.png' border=0 align='absmiddle'> Remove ]</a>";
960         document.getElementById(list + "_" + id).innerHTML = HTML;
964 function mylist_response(output){
966         var list = workinglist;
967         output = output.toString();
968         
969         if (output.charAt(0) == 'q'){
971         output = output.substring(1);
972         listsize = output * 1;
973         if(list=="hotlist") document.getElementById('hlsize').firstChild.nodeValue = listsize;
974     document.getElementById(list+"_headercount").innerHTML = listsize + " Genes";       
975         if(listsize==0 && clear_reload==1) window.location.reload();
976         clear_reload = 0;
977         }
978         
979