// Constants for Series
var LeNo = "Lecture Notes in Computer Science".link("http://www.springer.de/comp/lncs");
var ElNo = "Electronic Notes in Theoretical Computer Science".link("http://www.elsevier.com/locate/entcs");

// Constants for publishers
var SpVe = "Springer Verlag".link("http://www.springer.de");
var ElSc = "Elsevier Science".link("http://www.elsevier.com");
var CoSo = "IEEE Computer Society".link("http://www.computer.org");
var AcPr = "Academic Press".link("http://www.academicpress.com");
var WoSc = "World Scientific".link("http://www.wspc.com");
var FrGe = "Fraunhofer Gesellschaft ISST".link("http://www.isst.fhg.de/index_e.html");
var CaUn = "Cambridge University Press".link("http://www.cup.org/");

// Constants for Journals
var InCo = "Information and Computation".link("http://www.academicpress.com/i&c");
var ThCo = "Theoretical Computer Science".link("http://www.elsevier.com/locate/tcs");
var MaSt = "Mathematical Structures in Computer Science".link("http://uk.cambridge.org/journals/msc");

// Constants for Institutes
var UnPi = "Computer Science Department".link("http://www.di.unipi.it")+", "+"University of Pisa".link("http://www.unipi.it");
var StRe = "SRI International".link("http://www.csl.sri.com");
var UnVe = "Computer Science Department".link("http://www.dsi.unive.it/")+", "+"University Ca' Foscari of Venice".link("http://www.unive.it");
var UnRo = "Computer Science Department".link("http://www.dsi.uniroma1.it/")+", "+"University La Sapienza of Rome".link("http://www.uniroma1.it");

function Article
    (authors,    // list of FirstName FamilyName
     title,	 // complete title
     year,	 // four digits year
     pages,	 // pages xx-yy | xx pages
     psFile,	 // link to .ps.gz
     pdfFile,	 // link to .pdf.gz
     bibTex,	 // bibtex entry
     abstr,	 // full abstract
     confAcro,   // acronym of the conference
     confBook,   // full description of the conference | booktitle
     confLink,   // link to conference page
     place,	 // conference location
     editors,	 // list of FirstName FamilyName, Editor(s)
     series,     // series (LNCS | ENTCS)
     volume,	 // volume
     publisher,  // SV | ES | IEEE | AP | WS | ISST | CUP
     journal,    // journal name (IC | TCS | MSCS)
     techRep,    // type and number
     phdThesis,  // type and number 
     institute,  // institution (UP | SRI)
     draft,      // Submitted | To Appear | Unpublished
     note,	 // annotations
     icon,	 // name of gif icon
     copyHold,	 // copyright holder
     kWords      // keywords
    )
{
    this.authors    = (authors    == null ? "" : authors);
    this.title      = (title      == null ? "" : title);
    this.year       = (year       == null ? "" : year);
    this.pages      = (pages      == null ? "" : pages);
    this.psFile     = (psFile     == null ? "" : psFile);
    this.pdfFile    = (pdfFile    == null ? "" : pdfFile);
    this.bibTex     = (bibTex     == null ? "" : bibTex);
    this.abstr      = (abstr      == null ? "" : abstr);
    this.confAcro   = (confAcro   == null ? "" : confAcro);
    this.confBook   = (confBook   == null ? "" : confBook);
    this.confLink   = (confLink   == null ? "" : confLink);
    this.place      = (place      == null ? "" : place);
    this.editors    = (editors    == null ? "" : editors);
    this.series     = (series     == null ? "" : series);
    this.volume     = (volume     == null ? "" : volume);
    this.publisher  = (publisher  == null ? "" : publisher);
    this.journal    = (journal    == null ? "" : journal);
    this.phdThesis  = (phdThesis  == null ? "" : phdThesis);
    this.techRep    = (techRep    == null ? "" : techRep);
    this.institute  = (institute  == null ? "" : institute);
    this.draft      = (draft      == null ? "" : draft);
    this.note       = (note       == null ? "" : note);
    this.icon       = (icon       == null ? "" : icon);
    this.copyHold   = (copyHold   == null ? "" : copyHold);
    this.kWords     = (kWords     == null ? "" : kWords);

    this.getBibtex = article_getBibtex;
    this.toHtml     = article_toHtml;
    this.toHtmlAbs = article_toHtmlAbs;
}

function article_getBibtex()
{
    if (this.bibTex != "") {
        return this.bibTex+"\n"
    } else {
        var createdKey = this.title.substring(0,10);
        createdKey = createdKey.spaceToUscore();
        var bibEntry = "@";
        if (this.journal != "") {
            bibEntry += "article\{"+createdKey+":"+this.year+",\n";
            bibEntry += "    author = \{"+this.authors+"\},\n";
            bibEntry += "    title = \{"+this.title+"\},\n";
            bibEntry += "    journal = \{"+this.journal+"\},\n";
            bibEntry += "    volume = \{"+this.volume+"\},\n";
            bibEntry += "    editor = \{"+this.editors+"\},\n";
            bibEntry += "    publisher = \{"+this.publisher+"\},\n";
            bibEntry += "    pages = \{"+this.pages+"\},\n";
        } else if (this.confAcro != "") {
            bibEntry += "inproceedings\{"+createdKey+":"+this.year+",\n";
            bibEntry += "    author = \{"+this.authors+"\},\n";
            bibEntry += "    title = \{"+this.title+"\},\n";
            bibEntry += "    booktitle = \{Proceedings of "+this.confAcro+", "+this.confBook+"\},\n";
            bibEntry += "    series = \{"+this.series+"\},\n";
            bibEntry += "    volume = \{"+this.volume+"\},\n";
            bibEntry += "    editor = \{"+this.editors+"\},\n";
            bibEntry += "    publisher = \{"+this.publisher+"\},\n";
            bibEntry += "    pages = \{"+this.pages+"\},\n";
        } else if (this.confBook != "") {
            bibEntry += "incollection\{"+createdKey+":"+this.year+",\n";
            bibEntry += "    author = \{"+this.authors+"\},\n";
            bibEntry += "    title = \{"+this.title+"\},\n";
            bibEntry += "    booktitle = \{"+this.confBook+"\},\n";
            bibEntry += "    series = \{"+this.series+"\},\n";
            bibEntry += "    volume = \{"+this.volume+"\},\n";
            bibEntry += "    editor = \{"+this.editors+"\},\n";
            bibEntry += "    publisher = \{"+this.publisher+"\},\n";
            bibEntry += "    pages = \{"+this.pages+"\},\n";
        } else if (this.phdThesis != "") {
            bibEntry += "phdthesis\{"+createdKey+":"+this.year+",\n";
            bibEntry += "    author = \{"+this.authors+"\},\n";
            bibEntry += "    title = \{"+this.title+"\},\n";
            bibEntry += "    school = \{"+this.institute+"\},\n";
            bibEntry += "    type = \{"+this.phdThesis+"\},\n";
        } else if (this.techRep != "") {
            bibEntry += "techreport\{"+createdKey+":"+this.year+",\n";
            bibEntry += "    author = \{"+this.authors+"\},\n";
            bibEntry += "    title = \{"+this.title+"\},\n";
            bibEntry += "    institution = \{"+this.institute+"\},\n";
            bibEntry += "    number = \{"+this.phdThesis+"\},\n";
        } else {
            bibEntry += "misc\{"+createdKey+":"+this.year+",\n";
            bibEntry += "    author = \{"+this.authors+"\},\n";
            bibEntry += "    title = \{"+this.title+"\},\n";
        }
        bibEntry += "    year = \{"+this.year+"\},\n";
        if (this.note+this.draft != "") {
            bibEntry += "    note = \{"+this.note+((this.note != "") ?  ((this.draft != "") ? " "+this.draft+"." : "") : this.draft+".")+"\},\n";
        }
        bibEntry += "\}\n";
        return bibEntry;
    }
}

function article_toHtml()
{
    var paperBlock = "<hr />\n";
    paperBlock += "<dl>\n";
    paperBlock += "<dt>";

    if (this.icon != "") {
        paperBlock += "<img src='";
        paperBlock += this.icon+"' ";
        paperBlock += "align='top' width='35' /> ";
    }

    if (this.copyHold != "") {
        paperBlock += "&copy; "+this.copyHold;
    }

    paperBlock += "</dt>\n";
    paperBlock += "<dd>\n";

    paperBlock += ('"'+this.title+'"').bold()+",<br />";
    paperBlock += this.authors+",<br />";

    if (this.confBook != "" || this.confAcro != "") {
        var descr;
	if (this.confAcro != "") {
	    if (this.confLink != "") {
	        descr = this.confAcro.link(this.confLink);
	    } else {
	        descr = this.confAcro;
	    }
	    if (this.confBook != "") {
	        descr += ", "+this.confBook;
	    }
	} else {
	    if (this.confLink != "") {
	        descr = this.confBook.link(this.confLink);
	    } else {
	        descr = this.confBook;
	    }
	}
        paperBlock += "in "+("Proceedings of "+descr).italics();

	paperBlock += ",<br />";

	if (this.editors != "" || this.place != "") {
	    if (this.editors != "") {
	        paperBlock += "("+this.editors+")";
		if (this.place != "") {
		    paperBlock += ", "+this.place;
		}
	    } else {
	    	if (this.place != "") {
		    paperBlock += this.place;
		}
	    }
	    paperBlock += ",<br />";
	}

        if (this.series != "") {
            if (this.series == "LNCS") {
		paperBlock += LeNo;
	    } else {
	        if (this.series == "ENTCS") {
		    paperBlock += ElNo;
		} else {
		    paperBlock += this.series;
		}
	    }
            if (this.volume != "") {
	        paperBlock += " "+this.volume.bold()
	    }
	    paperBlock += ", ";
	}

	if (this.pages != "") {
	    paperBlock += this.pages+", ";
	}
    }

    if (this.journal != "")
    {
        if (this.journal == "IC") {
            paperBlock += InCo.italics();
        } else {
            if (this.journal == "TCS") {
		paperBlock += ThCo.italics();
	    } else {
	        if (this.journal == "MSCS") {
		    paperBlock += MaSt.italics();
		} else {
		    paperBlock += this.journal.italics();
		}
	    }
        }

        if (this.volume != "") {
            paperBlock += " "+this.volume.bold();
            if (this.pages != "") {
                paperBlock += ":"+this.pages;
            } 
        } else {
            if (this.pages != "") {
                paperBlock += ", "+this.pages;
            }
        }

        paperBlock += ", ";
    }

    if (this.publisher != "") {
        if (this.publisher == "SV") {
            paperBlock += SpVe;
        } else {
            if (this.publisher == "ES") {
	        paperBlock += ElSc;
	    } else {
	        if (this.publisher == "IEEE") {
		    paperBlock += CoSo;
		} else {
		    if (this.publisher == "AP") {
		        paperBlock += AcPr;
		    } else {
		        if (this.publisher == "WS") {
			    paperBlock += WoSc;
	                } else {
			    if (this.publisher == "ISST") {
			        paperBlock += FrGe;
			    } else {
			        if (this.publisher == "CUP") {
			            paperBlock += CaUn;
			        } else {
			            paperBlock += this.publisher;
				}
			    }
			}
		    }
		}
	    }
	}
	paperBlock += ", ";
    }

    if (this.techRep != "")
    {
        paperBlock += "Technical Report "+this.techRep+", ";
    }

    if (this.phdThesis != "")
    {
        paperBlock += "Ph.D. Thesis "+this.phdThesis+", ";
    }

    if (this.institute != "") {
        if (this.institute == "UP") {
            paperBlock += UnPi+", ";
        } else {
            if (this.institute == "SRI") {
                paperBlock += StRe+", ";
            } else {
            	if (this.institute == "VE") {
                    paperBlock += UnVe+", ";
            	} else {
            	    if (this.institute == "RM") {
                        paperBlock += UnRo+", ";
            	    } else {
                        paperBlock += this.institute+", ";
		    }
		}
            }
        }
    }

    if (this.draft != "") {
        paperBlock += this.draft+", ";
    }

    if (this.year != "") {
	paperBlock += this.year+". ";
    }

    paperBlock += "<br />";

    if (this.note != "") {
        paperBlock += this.note+"<br />";
    }

    if (this.kWords != "") {
        paperBlock += "<p>"+"Keywords: ".fontcolor("green").italics()+this.kWords+"</p>";
    }

    if (this.psFile != "") {
        paperBlock += "(" + "Postscript".link(this.psFile)+") ";
    }

    if (this.pdfFile != "") {
        paperBlock += "(" + "PDF".link(this.pdfFile) + ") ";
    }

    if (this.pdfFile+this.psFile != "") {
        paperBlock += "<br />\n";
    }

    paperBlock += "</dd></dl>";

    return paperBlock;
}

function article_toHtmlAbs()
{
    var paperBlock = this.toHtml();
    var pbLength = paperBlock.length;

    if (this.abstr != "") {
        paperBlock = paperBlock.substring(0,pbLength-10);
        paperBlock += "<p>"+"Abstract".fontcolor("red").bold()+"<br />"+this.abstr+"</p>";
        paperBlock += "</dd></dl>";
    }

   return paperBlock;
}

String.prototype.spaceToUscore = spaceToUscore;
function spaceToUscore() {
    var retValue = "";
    for (var i=0 ; i<this.length ; i++) {
        if (this.charAt(i) == " " || 
            this.charAt(i) == "\t" || 
            this.charAt(i) == "\n") {
           retValue += "_";
        } else {
           retValue += this.charAt(i);
        }
    }
    return retValue;
}



