//Javascript for Paratext brief and full displays.
//  Needs outside variables temp (temporary file name), total (total hits),
//      and maxlines (maximum display lines)  to be set.

                var newwindow;
                function popwindow(url)
                {
                    newwindow=window.open(url,'name','height=400,width=800,left=100,top=200,scrollbars=yes,resizable=yes');
                            if (window.focus) {newwindow.focus()}
                }


                function calc_page(pageformname)
                {
                 var form = eval( 'document.' + pageformname);
                 var docid = form.pagebox.value;
                 if ( (docid < 1) || (docid > total))
                   {
                        alert ( docid + " is an invalid item number." );
                        return false;
                    }
                    docid = docid-1;
                    var url = '/cgi-bin/member/search/d?' + temp + '@' +  docid + ',' + maxlines;
                    top.location.href = url;
                    return false;
                 }

                function saveChecked()
                {
                 var k = 0;
                 var j;
                 for (j=0; j < document.anchors.length; j++)
                 {
                   if (document.anchors[j].name == 'saveBtn')
                      break;
                 }
                 for (var i=0; i < document.mainform1.item.length; i++)
                 {
                   if (document.mainform1.item[i].checked)
                   {
                        document.anchors[j].href += i + '+';
                        k++;
                    }
                 }
                 if (k == 0)
                {
                 alert('No items were checked'); return false;
                }
                 return true;
                }

                var aEmailWin;
                function openEmailWin( title )
                {
                aPopUp = window.open('', 'Email', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,menubar=no,width=600,height=550');
                ndoc= aPopUp.document;
                astr = '<html><head><title>Email</title>';
                astr += '</head><body  BGCOLOR="ffffff" >';
                astr += '<FORM ACTION="/cgi-bin/member/search" NAME="emailform" METHOD=POST TARGET="_self" onSubmit="setTimeout(\'window.close()\',30000)" onBlur="javascript:void()">';


                astr += '  <center><i><b><font COLOR="6666cc" size="+2">' + title + '</font></i></b>';
                astr += '  <p>';
                astr += '  <center><b>Email Search Results</b>';
                astr += '  <p>';
                astr += '  <table>';
                astr += '  <tr>';
                astr += '  <td>';
                astr += '  <b>To:</b>';
                astr += '  </td><td>';
                astr += '  <input type="text" name="to" size="40"><br>';
                astr += '  </td></tr>';
                astr += '  <tr><td>';
                astr += '  <b>CopyTo:</b>';
                astr += '  </td><td>';
                astr += '  <input type="text" name="copyto" size="40"><br>';
                astr += '  </td></tr><tr><td>';
                astr += '  <b>From:</b>';
                astr += '  </td><td>';
                astr += '  <input type="text" name="from" size="40"><br>';
                astr += '  </td></tr><tr><td>';
                astr += '  <b>Subject:</b>';
                astr += '  </td><td>';
                astr += '  <input type="text" name="subject" size="40"><br>';
                astr += '  </td></tr>';
                astr += '  </table>';
                astr += '  <textarea name=text wrap=physical cols=40 rows=10>';
                astr += '  </textarea>';
                astr += '  <p>';
                astr += '<input type="hidden" name="TempFile" value="' + temp + '">';
                astr += '  <input type="submit" name="Send" value="Send Mail">';


                astr += '</FORM>';
                astr += '</BODY>';
                astr += '</HTML>';
                ndoc.write(astr);
                ndoc.close();
                self.aEmailWin = aPopUp;
                self.aEmailWin.focus();
                }

//Sort and Download expansions

                $(document).ready(function(){
                        $("#sort").click(function(){
                          $("#sortLayer").show("fast")
                          });

                        $("#closeSort,div > button").click(function() {
                                $("#sortLayer").hide("fast")
                          });

                        $("#download").click(function() {
                                $("#downloadLayer").show("fast")
                          });

                        $("#closeDownload,div > button").click(function() {
                                $("#downloadLayer").hide("fast")
                          });

                        $("#searchOptions").click(function() {
                                $("#searchOptionsLayer").toggle();
                                if ($("#searchOptions").text() == "Show more search options") {
                                   ($("#searchOptions").text("Hide search options"))
                                }
                                else {
                                   ($("#searchOptions").text("Show more search options"))
                                }
                                document.optionsForm.Stemming[0].checked=true;
                                document.optionsForm.and[0].checked=true;
                          });


                     });
