//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;
                 }
                 if (typeof document.mainform1.item.length == 'undefined')
                 {
                    if (document.mainform1.item.checked)
                    {
                           document.anchors[j].href += 0 + '+';
                           k++;
                    }
                 }
                 else
                 {
                    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;
                }

                function saveUpdate( type, buttonName )
                {
                 var k = 0;
                 var j;
                 var message = "The following items will be " + type + " your local holdings:" + '\n' + '\n' ;
                 for (j=0; j < document.anchors.length; j++)
                 {
                   if (document.anchors[j].name == buttonName)
                      break;
                 }
                 if (typeof document.mainform1.item.length == 'undefined')
                 {
                    if (document.mainform1.item.checked)
                    {
                           document.anchors[j].href += 0 + '+';
                           message += document.mainform1.item.value + '\n';
                           k++;
                    }
                 }
                 else
                 {
                    for (var i=0; i < document.mainform1.item.length; i++)
                    {
                      if (document.mainform1.item[i].checked)
                      {
                           document.anchors[j].href += i + '+';
                           message += document.mainform1.item[i].value + '\n';
                           k++;
                       }
                    }
                 }
                 if (k == 0)
                 {
                    alert('No items were checked'); return false;
                 }
                 var r=confirm( message );
                 return r;
                }

                var aEmailWin;
                function openEmailWin( title )
                {
                aPopUp = window.open('', 'Email', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,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")
                          });

                        $("#add").click(function(){
                          $("#addLayer").show("fast",function(){
                                $("#deleteLayer").hide("fast");
                                $("#reportLayer").hide("fast");
                             $("#addLayer #addArea").focus();
                           });
                          });

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

                        $("#delete").click(function(){
                          $("#deleteLayer").show("fast",function(){
                                $("#reportLayer").hide("fast");
                                $("#addLayer").hide("fast");
                             $("#deleteLayer #deleteArea").focus();
                           });
                          });

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

                        $("#report").click(function(){
                          $("#reportLayer").show("fast");
                                $("#addLayer").hide("fast");
                                $("#deleteLayer").hide("fast")
                          });

                        $("#closeReport,div > button").click(function() {
                                $("#reportLayer").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;
                          });


                     });
                function resetitems()
                {
                var count =document.mainform1.item.length;
                   if (count == undefined)
                      document.mainform1.item.checked = false;
                  else
                  for (var i=0; i < count; i++)
                     document.mainform1.item[i].checked =  false;
                }
                function checkallitems()
                {
                var count =document.mainform1.item.length;
                   if (count == undefined)
                      document.mainform1.item.checked = true;
                  else
                  for (var i=0; i < count; i++)
                     document.mainform1.item[i].checked =  true;
                }

