
function selectAllPublications()
{
    for (var i=0 ; i<RB_papers.length ; i++)
        { document.myForm.titleSelect.options[i].selected=true; }
    document.myForm.totSel.value = RB_papers.length;
}

function deselectAllPublications()
{
    for (var i=0 ; i<RB_papers.length ; i++)
        { document.myForm.titleSelect.options[i].selected=false; }
    document.myForm.totSel.value = 0;
}

function coSelectPublications()
{
    for (var i=0 ; i<RB_papers.length ; i++)
        { document.myForm.titleSelect.options[i].selected = !document.myForm.titleSelect.options[i].selected; }
    document.myForm.totSel.value = RB_papers.length - document.myForm.totSel.value;
}

function selectPubByYear()
{
    var tot=0;
    var selectedYear=document.myForm.yearSelect.options[document.myForm.yearSelect.selectedIndex].text;
    for (var i=0 ; i<RB_papers.length ; i++) { 
        if (RB_papers[i].year+"" == selectedYear+"") {
	    document.myForm.titleSelect.options[i].selected = true;
            tot++;
        } else if (document.myForm.titleSelect.options[i].selected) {
	    tot++;
        }
    }
    document.myForm.totSel.value = tot;
}

function selectPubByType()
{
    var tot=0;
    var selectedType=document.myForm.typeSelect.options[document.myForm.typeSelect.selectedIndex].text;

    if (selectedType == "Journal") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            if (RB_papers[i].journal != "") {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }

    if (selectedType == "Collection/Proceedings") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            if (RB_papers[i].confBook != "") {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }

    if (selectedType == "Technical Report") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            if (RB_papers[i].techRep != "") {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }

    if (selectedType == "Thesis") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            if (RB_papers[i].phdThesis != "") {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }

    if (selectedType == "Abstract") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            var titleOfPub = (RB_papers[i].title).toLowerCase();
            var notesOfPub = (RB_papers[i].note).toLowerCase();
            if (titleOfPub.indexOf("(abstract)") != -1 || notesOfPub.indexOf("extended abstract") != -1) {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }
 
    if (selectedType == "To Appear") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            var notesOfPub = (RB_papers[i].draft+" "+RB_papers[i].note).toLowerCase();
            if (notesOfPub.indexOf("to appear") != -1) {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }
 
    if (selectedType == "Draft") {
        for (var i=0 ; i<RB_papers.length ; i++) { 
            if (RB_papers[i].draft != "") {
	        document.myForm.titleSelect.options[i].selected = true;
                tot++;
            } else if (document.myForm.titleSelect.options[i].selected) {
	        tot++;
            }
        }
    }

    document.myForm.totSel.value = tot;
}

function selectPubByKeyword()
{
    var tot = 0;
    var selectedKeyword = document.myForm.keywordSelect.options[document.myForm.keywordSelect.selectedIndex].text;
    selectedKeyword = selectedKeyword.toLowerCase();

    for (var i=0 ; i<RB_papers.length ; i++) { 
        var notesOfPub = RB_papers[i].kWords.toLowerCase();
        if (notesOfPub.indexOf(selectedKeyword) != -1) {
	    document.myForm.titleSelect.options[i].selected = true;
            tot++;
        } else if (document.myForm.titleSelect.options[i].selected) {
	    tot++;
        }
    }
 
    document.myForm.totSel.value = tot;
}

function selectPubBySearch()
{
    var tot = 0;
    var selectedString = document.myForm.searchString.value;
    selectedString = selectedString.toLowerCase();

    for (var i=0 ; i<RB_papers.length ; i++) { 
        var infoPub = RB_papers[i].toHtmlAbs();
        infoPub = infoPub.toLowerCase();
       if (infoPub.indexOf(selectedString) != -1) {
	    document.myForm.titleSelect.options[i].selected = true;
            tot++
        } else {
	    document.myForm.titleSelect.options[i].selected = false;
        }
    }
 
    document.myForm.totSel.value = tot;
}

function countPub()
{
    var tot=0;
    for (var i=0 ; i<RB_papers.length ; i++)
        { if (document.myForm.titleSelect.options[i].selected)
	     { tot++ }
	}
    document.myForm.totSel.value = tot;
}

function displayBibtex()
{
    document.myForm.dispBT.value = "";
    for (var i=0 ; i<RB_papers.length ; i++) {
        if (document.myForm.titleSelect.options[i].selected) { 
            document.myForm.dispBT.value += RB_papers[i].getBibtex()+"\n";
        }
    }
}

function displayPublications()
{
    myWin[lastWin] = window.open("","openWin"+lastWin,"toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1");
    myWin[lastWin].document.open();
    myWin[lastWin].document.writeln("<html"+"><head"+"><title"+">Publications by Roberto Bruni: Selection n."+(lastWin+1)+"</title"+"></head"+">");
    myWin[lastWin].document.writeln("<style type=\"text/css\"> \n<!"+"--");
    myWin[lastWin].document.writeln("a \{ text-decoration: none; \}");
    myWin[lastWin].document.writeln("--"+">\n</style"+">");
    myWin[lastWin].document.writeln("<body "+"bgcolor=white"+">");
    myWin[lastWin].document.writeln("<h1>Publications by Roberto Bruni</h1>");
    myWin[lastWin].document.writeln("<h2>(selection n."+(lastWin+1)+")</h2>");
    myWin[lastWin].document.writeln("<p><em>As a contributing author of the documents listed in this page, I have made available our work electronically to ensure timely dissemination of scientific and technical contributions on a non-commercial basis.  Nevertheless, copyright and all rights therein are maintained by the authors or by other copyright holders (e.g., the publisher). It is understood that all persons accessing this information will adhere to the appropriate copyright rules. In particular, these works may not be reposted without the explicit permission of the copyright holder.</em></p>");
    myWin[lastWin].document.writeln("<p><b>Note:</b> This page has been generated on-the-fly from a "+"search page".link("http://www.di.unipi.it/~bruni/publications/searchPub.html")+". If you want to access exactly the same information in the future, you better save the page on your local file system.</p>");
    myWin[lastWin].document.write("You have selected the following "+document.myForm.totSel.value+" publications:");


    for (var i=0 ; i<RB_papers.length ; i++)
        { if (document.myForm.titleSelect.options[i].selected)
	     { if (document.myForm.inclAbstract.checked) {
                  myWin[lastWin].document.writeln(RB_papers[i].toHtmlAbs()); 
               } else {
                  myWin[lastWin].document.writeln(RB_papers[i].toHtml()); 
               }
             }
	}

    myWin[lastWin].document.writeln("<hr /><address><table width=\"100%\">");
    myWin[lastWin].document.writeln("<tr><td align=\"left\"><a href=\"mailto:bruni@di.unipi.it\"><img border=\"0\" src=\"emailed.gif\" align=\"bottom\" alt=\"email me\" /></a></td>");
    myWin[lastWin].document.write("<td align=\"center\">created: ");
    var todayDate = new Date();
    myWin[lastWin].document.writeln(todayDate);
    myWin[lastWin].document.writeln("</td>");
    myWin[lastWin].document.writeln("<td align=\"right\"><a href=\"http://www.di.unipi.it/~bruni\"><img border=\"0\" src=\"home3.jpg\" align=\"bottom\" alt=\"Roberto Bruni's Home Page\" /></a></td>");
    myWin[lastWin].document.writeln("</tr></table></address>");


    myWin[lastWin].document.writeln("</body"+">");
    myWin[lastWin].document.close();
    lastWin++;
}

function cleanWin()
{
   for (var i=0 ; i<lastWin ; i++)
        { if (!myWin[i].closed)
             { myWin[i].close(); }
	}
   if (helpWin != null && !helpWin.closed) {
      helpWin.close();
   }
}

function searchInstructions()
{ 
   if (helpWin == null || helpWin.closed) {
       helpWin = window.open("searchHelp.html","helpWin","scrollbars=1");
   } else {
       helpWin.focus();
   }
   document.fileCabinet.src="file_cabnet_squirm_md_wht.gif"; //reload animation
   document.flipPage.src="book_page_flip_md_wht.gif"; //reload animation
   document.emailMe.src="emailed.gif"; //reload animation
}


