//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Author (0-multiple authors)

function citeBook()
{
	
	var authorsLastName = new Array();
	var authorsFirstName = new Array();
	var authorsMiddleName = new Array();
	var nbOfAuthors = 0;
	for( var i = 0; i < 6; ++i )
	{
		authorsLastName[i] = document.getElementById("bookauthorLastName" + String(i + 1)).value;
		authorsFirstName[i] = document.getElementById("bookauthorFirstName" + String(i + 1)).value.toUpperCase();
		authorsMiddleName[i] = document.getElementById("bookauthorMiddleName" + String(i + 1)).value.toUpperCase();
		if("" != authorsLastName[i])
		{
			++nbOfAuthors;
		}
		else
		{
			break;
		}
	}
	
	var moreThan6Authors = false;
	if( (6 == nbOfAuthors) && (document.getElementById("checkboxAuthors").checked) )
	{
		moreThan6Authors = true;
	}
	
	var authors = "";
	for( var i = 0; i < nbOfAuthors; ++i )
	{
		authors += authorsLastName[i] + ", " + authorsFirstName[i] + ".";
		
		if( "" != authorsMiddleName[i] )
			 authors += " " + authorsMiddleName[i] + ".";
		
		if( i == (nbOfAuthors - 1) ) // the last author
		{
			if( moreThan6Authors )
				authors +=  ", et al."
		}
		else if( (i == (nbOfAuthors - 2)) && (!moreThan6Authors) )
		{
			authors += ", & ";
		}		
		else
			authors += ", ";
	}
	
	var bookYear = document.getElementById("bookYear").value;
	if (bookYear != "")
	{
		bookYear = " (" + bookYear + "). ";
	}	
	var bookTitle = document.getElementById("bookTitle").value;
	if (bookTitle == ""){bookTitle = "";}
		else
		{
    if (bookTitle.match(/\.$|\?$|!$/))
      {
      bookTitle = "<i>" + bookTitle + "</i>" + " ";
      }
      else
      {
      bookTitle = "<i>" + bookTitle + "</i>" + ". ";
      }
    }
    
	var bookState = document.getElementById("bookState").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var bookCity = document.getElementById("bookCity").value;
	if (bookCity != "")
	{
		bookCity += bookState + ": ";
	}

	
	var bookPublisher = document.getElementById("bookPublisher").value;
	if (bookPublisher != "")
	{
		bookPublisher = bookPublisher + ".";
	}
	
	if( 0 == nbOfAuthors )
	{
		citationText = bookTitle + bookYear + bookCity + bookPublisher;
	}
	else
	{
		citationText = authors + " " +
		bookYear + bookTitle + bookCity + bookPublisher;
	}

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if ((0 == nbOfAuthors) && !bookYear && !bookTitle)
	{
		alert("There is not enough information to create a citation.");
	}
	else
	{
		 citationArray[lengthOfArray] = citationText;
		 write();
	}	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Editor (0-multiple editors)

function citeBookEd()
{
	
	var editorsLastName = new Array();
	var editorsFirstName = new Array();
	var editorsMiddleName = new Array();
	var nbOfEditors = 0;
	for( var i = 0; i < 6; ++i )
	{
		editorsLastName[i] = document.getElementById("bookeditorLastName" + String(i + 1)).value;
		editorsFirstName[i] = document.getElementById("bookeditorFirstName" + String(i + 1)).value.toUpperCase();
		editorsMiddleName[i] = document.getElementById("bookeditorMiddleName" + String(i + 1)).value.toUpperCase();
		if("" != editorsLastName[i])
		{
			++nbOfEditors;
		}
		else
		{
			break;
		}
	}
	
	var moreThan6Editors = false;
	if( (6 == nbOfEditors) && (document.getElementById("checkboxEditors").checked) )
	{
		moreThan6Editors = true;
	}
	
	var editors = "";
	for( var i = 0; i < nbOfEditors; ++i )
	{
		editors += editorsLastName[i] + ", " + editorsFirstName[i] + ".";
		
		if( "" != editorsMiddleName[i] )
			 editors += " " + editorsMiddleName[i] + ".";
		
		if( i == (nbOfEditors - 1) ) // the last editor
		{
			if( moreThan6Editors )
				editors +=  ", et al."
		}
		else if( (i == (nbOfEditors - 2)) && (!moreThan6Editors) )
		{
			editors += ", & ";
		}		
		else
			editors += ", ";
	}
	
	if( nbOfEditors > 1 )
	{
		editors += " (Eds.).";
	}
	else if( 1 == nbOfEditors )
	{
		editors += " (Ed.).";
	}
	
	var bookYear = document.getElementById("bookYearEd").value;
	if (bookYear != "")
	{
		bookYear = " (" + bookYear + "). ";
	}	
	var bookTitle = document.getElementById("bookTitleEd").value;
	if (bookTitle != "")
	{
		bookTitle = "<i>" + bookTitle + "</i>" + " ";
	}

	var bookEdition = document.getElementById("bookEditionEd").value;
	if( bookEdition != "" )
	{
		bookEdition = "(" + bookEdition + " ed.). ";
	}
	
	var bookState = document.getElementById("bookStateEd").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var bookCity = document.getElementById("bookCityEd").value;
	if (bookCity != "")
	{
		bookCity += bookState + ": ";
	}
	
	var bookPublisher = document.getElementById("bookPublisherEd").value;
	if (bookPublisher != "")
	{
		bookPublisher = bookPublisher + ".";
	}
	
	if( 0 == nbOfEditors )
	{
		citationText = bookTitle + bookYear + bookCity + bookPublisher;
	}
	else
	{
		citationText = editors + " " +
		bookYear + bookTitle + bookEdition + bookCity + bookPublisher;
	}

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if ((0 == nbOfEditors) && !bookYear && !bookTitle)
	{
		alert("There is not enough information to create a citation.");
	}
	else
	{
		 citationArray[lengthOfArray] = citationText;
		 write();
	}	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Author and Editor of 1 title

function citePrintAE()
{	

	var lastName = document.getElementById("printAEauthorLastName").value;
		lastName = capitalizeFirstLetter("printAEauthorLastName");
		if (lastName == ""){lastName = "";}
		else{lastName = lastName + ", ";}		
	var firstName = document.getElementById("printAEauthorFirstName").value.toUpperCase();
		if (firstName == ""){firstName = "";}
		else {firstName = firstName + ".";}
	var middleName = document.getElementById("printAEauthorMiddleName").value.toUpperCase();
		if (middleName == ""){middleName = "";}
		else {middleName = middleName + ".";}

// Function below tests to see if there are values for the other author/editor names.
// If there are values then a comma will be placed after the first author/editor.
// And an ampersand will be placed before the last name.

	var nameExists
		if (lastName || firstName || middleName){nameExists=true;}

//////////////////////////////
	

	var elastName = document.getElementById("printAEeditorLastName").value;
		elastName = capitalizeFirstLetter("printAEeditorLastName");
		if (elastName == ""){elastName = "";}
		else{elastName = " " + elastName + "";}		
	var efirstName = document.getElementById("printAEeditorFirstName").value.toUpperCase();
		if (efirstName == ""){efirstName = "";}
		else {efirstName = efirstName + ".";}
	var emiddleName = document.getElementById("printAEeditorMiddleName").value.toUpperCase();
		if (emiddleName == ""){emiddleName = "";}
		else {emiddleName = emiddleName + ".";}

// Function below tests to see if there are values for the other author/editor names.
// If there are values then a comma will be placed after the first author/editor.
// And an ampersand will be placed before the last name.

	var enameExists
		if (elastName || efirstName || emiddleName){enameExists=true;}

//////////////////////////////

	var printAEYear = document.getElementById("printAEYear").value;
		if (printAEYear == ""){printAEYear = "";}
		else {printAEYear = " (" + printAEYear + "). ";}
	var printOriginalAETitle = document.getElementById("printOriginalAETitle").value;
		if (printOriginalAETitle == ""){printOriginalAETitle = "";}
		else {printOriginalAETitle = printOriginalAETitle;}
		
	var bookState = document.getElementById("printAEState").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var printAECity = document.getElementById("printAECity").value;
	if (printAECity != "")
	{
		printAECity += bookState + ": ";
	}
		
	var printAEPublisher = document.getElementById("printAEPublisher").value;
		if (printAEPublisher == ""){printAEPublisher = "";}
		else {printAEPublisher = printAEPublisher + ".";}

	var edPluralizer = ", Ed.";

	citationText = lastName + firstName + middleName + 
		printAEYear + "<i>" + printOriginalAETitle + "</i>" +  		
		" (" + efirstName + emiddleName + elastName + edPluralizer + "). " + printAECity + printAEPublisher;

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if (!nameExists && !enameExists && !printAEYear && !printOriginalAETitle){
		alert("There is not enough information to create a citation.");
		}
	else{
		 if(lengthOfArray == 0){
		  citationArray[0] = citationText;
		 }
		 else{
		 var longString = lengthOfArray;
		 citationArray[longString] = citationText;
		 }
		 write();
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Anthology/Story Collection

function citePrintAnthology()
{	

	var lastName = document.getElementById("printAnthologyAuthorLastName").value;
		lastName = capitalizeFirstLetter("printAnthologyAuthorLastName");
		if (lastName == ""){lastName = "";}
		else{lastName = lastName + ", ";}		
	var firstName = document.getElementById("printAnthologyAuthorFirstName").value.toUpperCase();
		if (firstName == ""){firstName = "";}
		else {firstName = firstName + ".";}
	var middleName = document.getElementById("printAnthologyAuthorMiddleName").value.toUpperCase();
		if (middleName == ""){middleName = "";}
		else {middleName = middleName + ".";}

// Function below tests to see if there are values for the other author/editor names.
// If there are values then a comma will be placed after the first author/editor.
// And an ampersand will be placed before the last name.

	var nameExists
		if (lastName || firstName || middleName){nameExists=true;}

//////////////////////////////
	

	var elastName = document.getElementById("printAnthologyEditorLastName").value;
		elastName = capitalizeFirstLetter("printAnthologyEditorLastName");
		if (elastName == ""){elastName = "";}
		else{elastName = " " + elastName + "";}		
	var efirstName = document.getElementById("printAnthologyEditorFirstName").value.toUpperCase();
		if (efirstName == ""){efirstName = "";}
		else {efirstName = efirstName + ".";}
	var emiddleName = document.getElementById("printAnthologyEditorMiddleName").value.toUpperCase();
		if (emiddleName == ""){emiddleName = "";}
		else {emiddleName = " " + emiddleName + ".";}

// Function below tests to see if there are values for the other author/editor names.
// If there are values then a comma will be placed after the first author/editor.
// And an ampersand will be placed before the last name.

	var enameExists
		if (elastName || efirstName || emiddleName){enameExists=true;}

//////////////////////////////

	var printAEYear = document.getElementById("printAnthologyYear").value;
		if (printAEYear == ""){printAEYear = "";}
		else {printAEYear = " (" + printAEYear + "). ";}
	var articleTitle = document.getElementById("printAnthologyArticleTitle").value;
	if (articleTitle == ""){articleTitle = "";}
		else
		{
    if (articleTitle.match(/\.$|\?$|!$/))
      {
      articleTitle = articleTitle ;
      }
      else
      {
      articleTitle = articleTitle + ".";
      }
    }
    
	var printOriginalAETitle = document.getElementById("printAnthologyTitle").value;
		if (printOriginalAETitle == ""){printOriginalAETitle = "";}
		else {printOriginalAETitle = printOriginalAETitle;}
	var pages = document.getElementById("printAnthologyPages").value;
	if("" != pages)
	{
		pages = " (pp. " + pages + ")";
	}

	var bookState = document.getElementById("printAnthologyState").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var printAECity = document.getElementById("printAnthologyCity").value;
	if (printAECity != "")
	{
		printAECity += bookState + ": ";
	}
				
	var printAEPublisher = document.getElementById("printAnthologyPublisher").value;
		if (printAEPublisher == ""){printAEPublisher = "";}
		else {printAEPublisher = printAEPublisher + ".";}

	citationText = lastName + firstName + " " + middleName + 
		printAEYear + articleTitle + " In " + efirstName + emiddleName + elastName + " (Ed.), " +
		"<i>" + printOriginalAETitle + "</i>" + pages + ". " + 		
		printAECity + printAEPublisher;

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if (!nameExists && !enameExists && !printAEYear && !printOriginalAETitle){
		alert("There is not enough information to create a citation.");
		}
	else{
		 if(lengthOfArray == 0){
		  citationArray[0] = citationText;
		 }
		 else{
		 var longString = lengthOfArray;
		 citationArray[longString] = citationText;
		 }
		 write();
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Previously published book in a collection

function citeRepublication()
{	
	var lastName = document.getElementById("printRepubauthorLastName").value;
	lastName = capitalizeFirstLetter("printRepubauthorLastName");
	if(lastName != "")
	{
		lastName = lastName + ", ";
	}		
	var firstName = document.getElementById("printRepubauthorFirstName").value.toUpperCase();
	if(firstName != "")
	{
		firstName = firstName + ".";
	}
	var middleName = document.getElementById("printRepubauthorMiddleName").value.toUpperCase();
	if(middleName != "")
	{
		middleName = " " + middleName + ".";
	}

	var nameExists = false;
	if (lastName || firstName || middleName)
	{nameExists=true;}
	
	var editorLastName = document.getElementById("printRepubEditorLastName").value;
	var editorFirstInitial = document.getElementById("printRepubEditorFirstName").value;	
	var editorMiddleInitial = document.getElementById("printRepubEditorMiddleName").value;
	if( "" != editorMiddleInitial )
	{
		editorMiddleInitial = editorMiddleInitial + ". ";
	}
		

//////////////////////////////
	var articleTitle = document.getElementById("repubArticleTitle").value;	
  if (articleTitle == ""){articleTitle = "";}
		else
		{
    if (articleTitle.match(/\.$|\?$|!$/))
      {
      articleTitle = articleTitle;
      }
      else
      {
      articleTitle = articleTitle + ".";
      }
    }

	var repubTitle = document.getElementById("republishedTitle").value;
	if (repubTitle != "")
	{
		repubTitle = "<i>" + repubTitle + "</i>";
	}
	var repubVolume = document.getElementById("republishedVolume").value;
	if(repubVolume != "")
	{
		repubVolume = "Vol. " + repubVolume + ", ";
	}
	var repubPages = document.getElementById("republishedPages").value;
	var repubYear = document.getElementById("republishedYear").value;
	if(repubYear != "")
	{
		repubYear = " (" + repubYear + ").";
	}
	
	var repState = document.getElementById("republishedState").value;
	if (repState != "")
	{
		repState = ", " + repState;
	}
	var repubCity = document.getElementById("republishedCity").value;
	if (repubCity != "")
	{
		repubCity += repState + ": ";
	}
		
		
	var repubPublisher = document.getElementById("republishedPublisher").value;

	var originalTitle = document.getElementById("repubOriginalTitle").value;
	var originalVol = document.getElementById("repubOriginalVolume").value;
	var originalPages = document.getElementById("repubOriginalPages").value;
	var originalYear = document.getElementById("repubOriginalYear").value;
	
	var bookState = document.getElementById("repubOriginalState").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var originalCity = document.getElementById("repubOriginalCity").value;
	if (originalCity != "")
	{
		originalCity += bookState + ": ";
	}

	
	var originalPub = document.getElementById("repubOriginalPublisher").value;

	citationText = lastName + firstName + middleName + 
		repubYear + " " +
		articleTitle + " In " + editorFirstInitial + ". " + editorMiddleInitial  + editorLastName + " (Ed.), " +
		repubTitle + " (" + repubVolume + "pp. " + repubPages + "). " + 
		repubCity + repubPublisher + ". (Reprinted from <i>" + originalTitle + "</i>" + 
		", " + originalVol + ", " +  originalPages;
	if( "" != originalYear )
	{
		citationText += ", (" + originalYear + ") " + originalCity + originalPub;
	}
	citationText += ")";

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if (!nameExists && !repubYear && !repubTitle){
		alert("There is not enough information to create a citation.");
		}
	else{
		 if(lengthOfArray == 0){
		  citationArray[0] = citationText;
		 }
		 else{
		 var longString = lengthOfArray;
		 citationArray[longString] = citationText;
		 }
		 write();
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Previously published journal in a collection

function citeRepublicationJournal()
{	
	var lastName = document.getElementById("printRepubauthorLastNameJournal").value;
	lastName = capitalizeFirstLetter("printRepubauthorLastNameJournal");
	if(lastName != "")
	{
		lastName = lastName + ", ";
	}		
	var firstName = document.getElementById("printRepubauthorFirstNameJournal").value.toUpperCase();
	if(firstName != "")
	{
		firstName = firstName + ".";
	}
	var middleName = document.getElementById("printRepubauthorMiddleNameJournal").value.toUpperCase();
	if(middleName != "")
	{
		middleName = " " + middleName + ".";
	}

	var nameExists = false;
	if (lastName || firstName || middleName)
	{nameExists=true;}
	
	var editorLastName = document.getElementById("printRepubEditorLastNameJournal").value;
	var editorFirstInitial = document.getElementById("printRepubEditorFirstNameJournal").value;	
	var editorMiddleInitial = document.getElementById("printRepubEditorMiddleNameJournal").value;
	if( "" != editorMiddleInitial )
	{
		editorMiddleInitial = editorMiddleInitial + ". ";
	}
		

//////////////////////////////
  var articleTitle = document.getElementById("repubArticleTitleJournal").value;
  if (articleTitle == ""){articleTitle = "";}
		else
		{
    if (articleTitle.match(/\.$|\?$|!$/))
      {
      articleTitle = articleTitle + " In " ;
      }
      else
      {
      articleTitle = articleTitle + ". In ";
      }
    }

	var repubTitle = document.getElementById("republishedTitleJournal").value;
	if (repubTitle != "")
	{
		repubTitle = "<i>" + repubTitle + "</i>";
	}

	var repubVolume = document.getElementById("republishedVolumeJournal").value;
	if(repubVolume != "")
	{
		repubVolume = "Vol. " + repubVolume + ", ";
	}
	var repubPages = document.getElementById("republishedPagesJournal").value;
	var repubYear = document.getElementById("republishedYearJournal").value;
	if(repubYear != "")
	{
		repubYear = " (" + repubYear + ").";
	}
	
	var repState = document.getElementById("republishedStateJournal").value;
	if (repState != "")
	{
		repState = ", " + repState;
	}
	var repubCity = document.getElementById("republishedCityJournal").value;
	if (repubCity != "")
	{
		repubCity += repState + ": ";
	}
		
		
	var repubPublisher = document.getElementById("republishedPublisherJournal").value;

	var originalTitle = document.getElementById("repubOriginalTitleJournal").value;
	var originalVol = document.getElementById("repubOriginalVolumeJournal").value;
	var originalPages = document.getElementById("repubOriginalPagesJournal").value;
	var originalYear = document.getElementById("repubOriginalYearJournal").value;
	
	var bookState = document.getElementById("repubOriginalStateJournal").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var originalCity = document.getElementById("repubOriginalCityJournal").value;
	if (originalCity != "")
	{
		originalCity += bookState + ": ";
	}

	
	var originalPub = document.getElementById("repubOriginalPublisherJournal").value;

	citationText = lastName + firstName + middleName + 
		repubYear + " " +
		articleTitle + editorFirstInitial + ". " + editorMiddleInitial  + editorLastName + " (Ed.), " +
		repubTitle + " (" + repubVolume + "pp. " + repubPages + "). " + 
		repubCity + repubPublisher + ". (Reprinted from <i>" + originalTitle + "</i>" + 
		", " + originalVol + ", " +  originalPages;
	if( "" != originalYear )
	{
		citationText += ", (" + originalYear + ") " + originalCity + originalPub;
	}
	citationText += ")";

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if (!nameExists && !repubYear && !repubTitle){
		alert("There is not enough information to create a citation.");
		}
	else{
		 if(lengthOfArray == 0){
		  citationArray[0] = citationText;
		 }
		 else{
		 var longString = lengthOfArray;
		 citationArray[longString] = citationText;
		 }
		 write();
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Encyclopedia Article

function citePrintEncy()
{
	
	var authorsLastName = new Array();
	var authorsFirstName = new Array();
	var authorsMiddleName = new Array();
	var nbOfAuthors = 0;
	for( var i = 0; i < 1; ++i )
	{
		authorsLastName[i] = document.getElementById("encyauthorLastName" + String(i + 1)).value;
		authorsFirstName[i] = document.getElementById("encyauthorFirstName" + String(i + 1)).value.toUpperCase();
		authorsMiddleName[i] = document.getElementById("encyauthorMiddleName" + String(i + 1)).value.toUpperCase();
		if("" != authorsLastName[i])
		{
			++nbOfAuthors;
		}
		else
		{
			break;
		}
	}
	
	var moreThan6Authors = false;
	
	var authors = "";
	for( var i = 0; i < nbOfAuthors; ++i )
	{
		authors += authorsLastName[i] + ", " + authorsFirstName[i] + ".";
		
		if( "" != authorsMiddleName[i] )
			 authors += " " + authorsMiddleName[i] + ".";
		
		if( i == (nbOfAuthors - 1) ) // the last author
		{
			if( moreThan6Authors )
				authors +=  ", et al."
		}
		else if( (i == (nbOfAuthors - 2)) && (!moreThan6Authors) )
		{
			authors += ", & ";
		}		
		else
			authors += ", ";
	}
	
	var bookYear = document.getElementById("encyYear").value;
	if (bookYear != "")
	{
		bookYear = " (" + bookYear + "). ";
	}	
	var articleTitle = document.getElementById("encyArticleTitle").value;
	if( "" != articleTitle )
  {
    if (articleTitle.match(/\.$|\?$|!$/))
    {
    articleTitle += " ";
    }
    else
    {
    articleTitle += ". ";
    }
  }
	var bookTitle = document.getElementById("encyTitle").value;
	if (bookTitle != "")
	{
		bookTitle = "In <i>" + bookTitle + "</i> ";
	}
	var vol = document.getElementById("encyVol").value;
	if( "" != vol )
	{
		vol = "Vol. " + vol + ", ";
	}
	var pages = document.getElementById("encyPages").value;
	
	var bookState = document.getElementById("encyState").value;
	if (bookState != "")
	{
		bookState = ", " + bookState;
	}
	var bookCity = document.getElementById("encyCity").value;
	if (bookCity != "")
	{
		bookCity += bookState + ": ";
	}

	var bookPublisher = document.getElementById("encyPublisher").value;
	if (bookPublisher != "")
	{
		bookPublisher = bookPublisher + ".";
	}
	
	if( 0 == nbOfAuthors )
	{
		citationText = bookTitle + bookYear + bookCity + bookPublisher;
	}
	else
	{
		citationText = authors + " " +
		bookYear + articleTitle + bookTitle + "(" + vol + "pp. " + pages + "). " + bookCity + bookPublisher;
	}

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if ((0 == nbOfAuthors) && !bookYear && !bookTitle)
	{
		alert("There is not enough information to create a citation.");
	}
	else
	{
		 citationArray[lengthOfArray] = citationText;
		 write();
	}	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Magazine or Scholarly Journal Article

function citePrintMagazine()
{	
	var lastName4 = document.getElementById("printMagazineAuthorLastName4").value;
		lastName4 = capitalizeFirstLetter("printMagazineAuthorLastName4");
		if (lastName4 == ""){lastName4 = "";}
		else{lastName4 = lastName4 + ", ";}		
	var firstName4 = document.getElementById("printMagazineAuthorFirstName4").value.toUpperCase();
		if (firstName4 == ""){firstName4 = "";}
		else {firstName4 = firstName4 + ".";}
	var middleName4 = document.getElementById("printMagazineAuthorMiddleName4").value.toUpperCase();
		if (middleName4 == ""){middleName4 = "";}
		else {middleName4 = " " + middleName4 + ".";}

	var lastName3 = document.getElementById("printMagazineAuthorLastName3").value;
		lastName3 = capitalizeFirstLetter("printMagazineAuthorLastName3");
		if (lastName3 == ""){lastName3 = "";}
		else{lastName3 = lastName3 + ", ";}		
	var firstName3 = document.getElementById("printMagazineAuthorFirstName3").value.toUpperCase();
		if (firstName3 == ""){firstName3 = "";}
		else {firstName3 = firstName3 + ".";}
	var middleName3 = document.getElementById("printMagazineAuthorMiddleName3").value.toUpperCase();
		if (middleName3 == ""){middleName3 = "";}
		else {middleName3 = " " + middleName3 + ".";}

	var lastName2 = document.getElementById("printMagazineAuthorLastName2").value;
		lastName2 = capitalizeFirstLetter("printMagazineAuthorLastName2");
		if (lastName2 == ""){lastName2 = "";}
		else{lastName2 = lastName2 + ", ";}		
	var firstName2 = document.getElementById("printMagazineAuthorFirstName2").value.toUpperCase();
		if (firstName2 == ""){firstName2 = "";}
		else {firstName2 = firstName2 + ".";}
	var middleName2 = document.getElementById("printMagazineAuthorMiddleName2").value.toUpperCase();
		if (middleName2 == ""){middleName2 = "";}
		else {middleName2 = " " + middleName2 + ".";}

	var lastName = document.getElementById("printMagazineAuthorLastName").value;
		lastName = capitalizeFirstLetter("printMagazineAuthorLastName");
		if (lastName == ""){lastName = "";}
		else{lastName = lastName + ", ";}		
	var firstName = document.getElementById("printMagazineAuthorFirstName").value.toUpperCase();
		if (firstName == ""){firstName = "";}
		else {firstName = firstName + ".";}
	var middleName = document.getElementById("printMagazineAuthorMiddleName").value.toUpperCase();
		if (middleName == ""){middleName = "";}
		else {middleName = " " + middleName + ".";}	

// Function below tests to see if there are values for the other author/editor names.
// If there are values then a comma will be placed after the first author/editor.
// And an ampersand will be placed before the last name.

	var nameExists
		if (lastName || firstName || middleName){nameExists=true;}
	var nameExists2
		if (lastName2 || firstName2 || middleName2){nameExists2=true;}
	var nameExists3
		if (lastName3 || firstName3 || middleName3){nameExists3=true;}
	var nameExists4
		if (lastName4 || firstName4 || middleName4){nameExists4=true;}

	var comma = ", ";
		if (!nameExists2){comma = "";}
	var comma2 = ", ";
		if (!nameExists3){comma2 = "";}
	var comma3 = ", ";
		if (!nameExists4){comma3 = "";}

	var ampersand = "";
	var ampersand2 = "";
	var ampersand3 = "";
		if (nameExists4){ampersand3 = "& ";}
		else if (nameExists3){ampersand2 = "& ";}
		else if (nameExists2){ampersand = "& ";}

//////////////////////////////

	var printMagazineYear = document.getElementById("printMagazineYear").value;
		if (printMagazineYear == ""){printMagazineYear = "";}
		else {printMagazineYear = printMagazineYear + ", ";}	
	var printMagazineMonth = document.getElementById("printMagazineMonth").value;
		if (printMagazineMonth == ""){printMagazineMonth = "";}
		else {printMagazineMonth = printMagazineMonth;}	
	var printMagazineDay = document.getElementById("printMagazineDay").value;
		if (printMagazineDay == ""){printMagazineDay = "";}
		else {printMagazineDay = " " + printMagazineDay;}		
	
	var printMagazineArticleTitle = document.getElementById("printMagazineArticleTitle").value;
		if (printMagazineArticleTitle == ""){printMagazineArticleTitle = "";}
		else
    {
      if (printMagazineArticleTitle.match(/\.$|\?$|!$/))
      {
      printMagazineArticleTitle += " ";
      }
      else
      {
      printMagazineArticleTitle += ". ";
      }
    }
  
	var printMagazineTitle = document.getElementById("printMagazineTitle").value;
		if (printMagazineTitle == ""){printMagazineTitle = "";}
		else {printMagazineTitle = "<i>" + printMagazineTitle + "</i>" + ", ";}

	var printMagazineIssue = document.getElementById("printMagazineIssue").value;
		if (printMagazineIssue == ""){printMagazineIssue = "";}
		else {printMagazineIssue = "<i>" + printMagazineIssue + "</i>, ";}
	var printMagazinePages = document.getElementById("printMagazinePages").value;
		if (printMagazinePages == ""){printMagazinePages = "";}
		else {printMagazinePages = printMagazinePages + ".";}

	if(!nameExists)
	{
		citationText = printMagazineArticleTitle + 
		" (" + printMagazineYear + printMagazineMonth + printMagazineDay  + "). " +
		printMagazineTitle + printMagazineIssue + printMagazinePages;
	}
	else
	{
		citationText = lastName + firstName + middleName + comma + ampersand +
		lastName2 + firstName2 + middleName2 + comma2 + ampersand2 +
		lastName3 + firstName3 + middleName3 + comma3 + ampersand3 +
		lastName4 + firstName4 + middleName4 + 
		" (" + printMagazineYear + printMagazineMonth + printMagazineDay  + "). " +
		printMagazineArticleTitle + printMagazineTitle + printMagazineIssue + printMagazinePages;
	}

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if (!nameExists && !printMagazineYear && !printMagazineTitle){
		alert("There is not enough information to create a citation.");
		}
	else{
		 if(lengthOfArray == 0){
		  citationArray[0] = citationText;
		 }
		 else{
		 var longString = lengthOfArray;
		 citationArray[longString] = citationText;
		 }
		 write();
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Print Book: Newspaper Article

function citePrintNewspaper()
{	
	var lastName4 = document.getElementById("printNewspaperAuthorLastName4").value;
		lastName4 = capitalizeFirstLetter("printNewspaperAuthorLastName4");
		if (lastName4 == ""){lastName4 = "";}
		else{lastName4 = lastName4 + ", ";}		
	var firstName4 = document.getElementById("printNewspaperAuthorFirstName4").value.toUpperCase();
		if (firstName4 == ""){firstName4 = "";}
		else {firstName4 = firstName4 + ".";}
	var middleName4 = document.getElementById("printNewspaperAuthorMiddleName4").value.toUpperCase();
		if (middleName4 == ""){middleName4 = "";}
		else {middleName4 = " " + middleName4 + ".";}

	var lastName3 = document.getElementById("printNewspaperAuthorLastName3").value;
		lastName3 = capitalizeFirstLetter("printNewspaperAuthorLastName3");
		if (lastName3 == ""){lastName3 = "";}
		else{lastName3 = lastName3 + ", ";}		
	var firstName3 = document.getElementById("printNewspaperAuthorFirstName3").value.toUpperCase();
		if (firstName3 == ""){firstName3 = "";}
		else {firstName3 = firstName3 + ".";}
	var middleName3 = document.getElementById("printNewspaperAuthorMiddleName3").value.toUpperCase();
		if (middleName3 == ""){middleName3 = "";}
		else {middleName3 = " " + middleName3 + ".";}

	var lastName2 = document.getElementById("printNewspaperAuthorLastName2").value;
		lastName2 = capitalizeFirstLetter("printNewspaperAuthorLastName2");
		if (lastName2 == ""){lastName2 = "";}
		else{lastName2 = lastName2 + ", ";}		
	var firstName2 = document.getElementById("printNewspaperAuthorFirstName2").value.toUpperCase();
		if (firstName2 == ""){firstName2 = "";}
		else {firstName2 = firstName2 + ".";}
	var middleName2 = document.getElementById("printNewspaperAuthorMiddleName2").value.toUpperCase();
		if (middleName2 == ""){middleName2 = "";}
		else {middleName2 = " " + middleName2 + ".";}

	var lastName = document.getElementById("printNewspaperAuthorLastName").value;
		lastName = capitalizeFirstLetter("printNewspaperAuthorLastName");
		if (lastName == ""){lastName = "";}
		else{lastName = lastName + ", ";}		
	var firstName = document.getElementById("printNewspaperAuthorFirstName").value.toUpperCase();
		if (firstName == ""){firstName = "";}
		else {firstName = firstName + ".";}
	var middleName = document.getElementById("printNewspaperAuthorMiddleName").value.toUpperCase();
		if (middleName == ""){middleName = "";}
		else {middleName = " " + middleName + ".";}	

// Function below tests to see if there are values for the other author/editor names.
// If there are values then a comma will be placed after the first author/editor.
// And an ampersand will be placed before the last name.

	var nameExists
		if (lastName || firstName || middleName){nameExists=true;}
	var nameExists2
		if (lastName2 || firstName2 || middleName2){nameExists2=true;}
	var nameExists3
		if (lastName3 || firstName3 || middleName3){nameExists3=true;}
	var nameExists4
		if (lastName4 || firstName4 || middleName4){nameExists4=true;}

	var comma = ", ";
		if (!nameExists2){comma = "";}
	var comma2 = ", ";
		if (!nameExists3){comma2 = "";}
	var comma3 = ", ";
		if (!nameExists4){comma3 = "";}

	var ampersand = "";
	var ampersand2 = "";
	var ampersand3 = "";
		if (nameExists4){ampersand3 = "& ";}
		else if (nameExists3){ampersand2 = "& ";}
		else if (nameExists2){ampersand = "& ";}

//////////////////////////////

	var printNewspaperYear = document.getElementById("printNewspaperYear").value;
		if (printNewspaperYear == ""){printNewspaperYear = "";}
		else {printNewspaperYear = " (" + printNewspaperYear + ", ";}	
	var printNewspaperMonth = document.getElementById("printNewspaperMonth").value;
		if (printNewspaperMonth == ""){printNewspaperMonth = "";}
		else {printNewspaperMonth = printNewspaperMonth + " ";}	
	var printNewspaperDay = document.getElementById("printNewspaperDay").value;
		if (printNewspaperDay == ""){printNewspaperDay = "";}
		else {printNewspaperDay = printNewspaperDay + "). ";}		
	
	var printNewspaperArticleTitle = document.getElementById("printNewspaperArticleTitle").value;
		if (printNewspaperArticleTitle == ""){printNewspaperArticleTitle = "";}
		else
    {
      if (printNewspaperArticleTitle.match(/\.$|\?$|!$/))
      {
      printNewspaperArticleTitle += " ";
      }
      else
      {
      printNewspaperArticleTitle += ". ";
      }
    }

	var letterToEditor = "";
	if(document.getElementById("printcheckboxLetterEditor").checked)
	{
		letterToEditor = " [Letter to The Editor]. "
	}

	var printNewspaperTitle = document.getElementById("printNewspaperTitle").value;
		if (printNewspaperTitle == ""){printNewspaperTitle = "";}
		else {printNewspaperTitle = "<i>" + printNewspaperTitle + "</i>" + ", ";}
	var printNewspaperPages = document.getElementById("printNewspaperPages").value;
		if (printNewspaperPages == ""){printNewspaperPages = "";}
		else {printNewspaperPages = "pp. " + printNewspaperPages + ".";}


	citationText = lastName + firstName + middleName + comma + ampersand +
		lastName2 + firstName2 + middleName2 + comma2 + ampersand2 +
		lastName3 + firstName3 + middleName3 + comma3 + ampersand3 +
		lastName4 + firstName4 + middleName4 + 
		printNewspaperYear + printNewspaperMonth + printNewspaperDay +		
		printNewspaperArticleTitle + letterToEditor + printNewspaperTitle + printNewspaperPages;

	// Add citationText to citationArray	
	var lengthOfArray = citationArray.length;
	var longString;
	
	if (!nameExists && !printNewspaperYear && !printNewspaperTitle){
		alert("There is not enough information to create a citation.");
		}
	else{
		 if(lengthOfArray == 0){
		  citationArray[0] = citationText;
		 }
		 else{
		 var longString = lengthOfArray;
		 citationArray[longString] = citationText;
		 }
		 write();
	}
}
