this.style = "notChosen";
this.type= "notChosen";
this.citation = new Array(20);
this.authorNum = "0";
this.hasChangedAuthor = false;
var citationNum = 0;
this.numberRows = 0;
this.authorRows =0;
var myalert=0;
var medium="";
var total="";
var mytotal="";

function updateBox(which){
//document.form3.textarea1.rows=48;	
//document.getElementById('textarea1').rows=48
//alert(document.getElementById('textarea1').rows);
//alert(document.getElementById('textarea1').className)
//document.getElementById('textarea1').className= 'show';
//alert(document.getElementById('textarea1').className)
var inst = tinyMCE.getInstanceById(which);


if(inst)
{
    //inst.focus()
	
	//alert( inst.getBody().innerHTML);
}
tinyMCE.activeEditor.setContent(''); value="Clear";

citation.sort();

wholeThing = "";i=0;
while(citation[i]!=null){
wholeThing = wholeThing + citation[i];
i++; 
}
tinyMCE.activeEditor.setContent(total  + wholeThing );
var content= tinyMCE.activeEditor.getContent();

}
function refresh(){
	
	myalert=0;
	dateString="";
	changeAuthor(0);

	document.getElementById('Step4').className="";
document.getElementById('dformat').className="hide";
	document.getElementById('authorlabel').className="hide";
	document.getElementById('mycitation').className="hide";
document.getElementById('publabel').className="hide";
		document.getElementById("myButton").disabled= "disabled";
  document.getElementById('temp').className="show";
	  document.getElementById('temp2').className="show";
if (style==="MLA")
{document.getElementById('myone2').selected = true;
}
else{
		document.getElementById('myone').selected = true;
		
	} 
	


deleteInfoRow(numberRows);
hasChangedAuthor = false;
for (i=1;i<=5 ;i++ )
{
document.getElementById('radiobutton'+i).checked = false;
}
citation[citationNum] = total;
citationNum++;
mytotal=mytotal+total;
;
mytotal="<p style =\"padding-left: 20px; text-indent: -20px\" >Sssss.  </p><br />"
mytotal="<p style =\"padding-left: 20px; text-indent: -20px\" >added rest</p>";
document.getElementById("export").value = mytotal;
total = "";

updateBox();
type="notChosen";

if(style != "notChosen" && type== "notChosen"){//makes 2 bold
 var btn = document.getElementById("myButton"); btn.disabled = 'disabled';
 document.getElementById('temp').className="show";
   document.getElementById('temp2').className="show";
}
}
function refreshStyle(){
	for (i=1;i<=5 ;i++ )
{
document.getElementById('radiobutton'+i).checked = false;
//document.getElementById('radiobutton'+i).disabled = "disabled";
}
	for (i = 1; i <= 3; i++) {
		//alert(document.getElementById('radiobutton'+i).checked)
		document.getElementById('style'+i).checked = false;
	}
	//document.getElementById('numauthors1').disabled = "disabled";
//document.getElementById('numauthors2').disabled = "disabled";
document.getElementById('myone').selected = "selected";
document.getElementById('myone2').selected = "selected";
document.getElementById('Print').checked = true;
}

function sendToBottom(){
	//authorOneLast = "";authorOneFirst = "";authorTwoLast = "";authorTwoFirst = "";authorThreeLast = "";authorThreeFirst = "";authorFourFirst = "";authorFourLast = "";authorFiveLast = "";authorFiveFirst = "";authorSixLast = "";authorSixFirst = "";
	var authorLast = new Array(6);
	var authorFirst = new Array(6);
	var MI = new Array(6);
	//does the authors
	
	for (var w = 1; w < 7; w++) {
		authorLast[w] = "";
		authorFirst[w] = "";
		MI[w] = "";
	}
	try {
		authorLast[1] = document.getElementById("authorLast1").value;
		authorFirst[1] = document.getElementById("authorFirst1").value;
		MI[1] = document.getElementById("MI1").value;
		
	} 
	catch (err) {
	}
	try {
		authorLast[2] = document.getElementById("authorLast2").value;
		authorFirst[2] = document.getElementById("authorFirst2").value;
		MI[2] = document.getElementById("MI2").value;
		
	} 
	catch (err) {
	}
	try {
		authorLast[3] = document.getElementById("authorLast3").value;
		authorFirst[3] = document.getElementById("authorFirst3").value;
		MI[3] = document.getElementById("MI3").value;
		
	} 
	catch (err) {
	}
	try {
		authorLast[4] = document.getElementById("authorLast4").value;
		authorFirst[4] = document.getElementById("authorFirst4").value;
		MI[4] = document.getElementById("MI4").value;
		
	} 
	catch (err) {
	}
	try {
		authorLast[5] = document.getElementById("authorLast5").value;
		authorFirst[5] = document.getElementById("authorFirst5").value;
		MI[5] = document.getElementById("MI5").value;
		
	} 
	catch (err) {
	}
	try {
		authorLast[6] = document.getElementById("authorLast6").value;
		authorFirst[6] = document.getElementById("authorFirst6").value;
		MI[6] = document.getElementById("MI6").value;
		
	} 
	catch (err) {
	}
	
	for (var k = 1; k < 7; k++) {
		for (var i = 1; i < 6; i++) {
			if (authorLast[i] === "" && authorFirst[i] === "") {
			
				authorLast[i] = authorLast[i + 1];
				authorLast[i + 1] = "";
				authorFirst[i] = authorFirst[i + 1];
				authorFirst[i + 1] = "";
				MI[i] = MI[i + 1];
				MI[i + 1] = "";
			}
		}
	}//end for
	authorString = author(authorLast[1], authorFirst[1], MI[1], authorLast[2], authorFirst[2], MI[2], authorLast[3], authorFirst[3], MI[3], authorLast[4], authorFirst[4], MI[4], authorLast[5], authorFirst[5], MI[5], authorLast[6], authorFirst[6], MI[6]);
	document.getElementById("myButton").disabled = false;
	//document.getElementById("instructions4").value = "Step 5 Add a new citation";
	this.total = "";
	
	/*******  GET INFORMATION FROM OTHER FIELDS  ***/
	
	try {
		var ATitle = document.getElementById("ATitle").value;
	} 
	catch (err) {
		ATitle = "";
	}
	
	try {
		var MedTitle = document.getElementById("MedTitle").value;
	} 
	catch (err) {
		MedTitle = "";
	}
	try {
		var City = document.getElementById("City").value;
	} 
	catch (err) {
		City = "";
	}
	
	try {
		var Publisher = document.getElementById("Publisher").value;
	} 
	catch (err) {
		Publisher = "";
	}
	
	try {
		var Volume = document.getElementById("Volume").value;
	} 
	catch (err) {
		Volume = "";
	}
	
	try {
		var Issue = document.getElementById("Issue").value;
	} 
	catch (err) {
		Issue = "";
	}
	
	
	try {
		var Edition = document.getElementById("Edition").value;
	} 
	catch (err) {
		Edition = "";
	}
	
	try {
		var Page = document.getElementById("Page").value;
	} 
	catch (err) {
		Page = "";
	}
	try {
		var URL = document.getElementById("URL").value;
	} 
	catch (err) {
		URL = "";
	}
	try {
		var Day = document.getElementById("Day").value;
		if (Day=="dd")Day="";
		
	} 
	catch (err) {
		Day = "";
	}
	try {
		var Month = document.getElementById("Month").value;
		if (Month == "Month") {
			Month = "";
		}
		} 
	catch (err) {
		Month = "";
		
	}
	
	try {
		var Year = document.getElementById("Year").value;
		if (Year == "yyyy") {
			Year = "";
		}
	} 
	catch (err) {
		Year = "";
	}
	
	try {
		var Day2 = document.getElementById("Day2").value;
		if (Day2 == "dd") {
			Day2 = "";
		}
	} 
	catch (err) {
		Day2 = "";
	}
	try {
		var Month2 = document.getElementById("Month2").value;
		if (Month2 == "Month") {
			Month2 = "";
		}
		} 
	catch (err) {
		Month2 = "";
	}
	try {
		
		var Year2 = document.getElementById("Year2").value;
		if (Year2 == "yyyy") {
			Year2 = "";
		}
		
	} 
	catch (err) {
		Year2 = "";
	}
	
	/********* FORMAT FIELDS ***********/
	if (Edition !== "") {
	
		switch (Edition) {
			case "1":
				Edition = "1st ed.";
				break;
			case "2":
				Edition = "2nd ed.";
				break;
			case "3":
				Edition = "3rd ed.";
				break;
			default:
				Edition = Edition + "th ed.";
		}
	}
	if (Year2 !== "") {
		Year2Period = Year2 + ". ";
		Year2Comma = Year2 + ", ";
	}
	else {
		Year2Period = "";
		Year2Comma = "";
	}
	if (Year !== "") {
		var YearColon = Year + ": ";
		var YearPeriod = Year + ". ";
		var YearBracketColon = "    (" + Year + "): ";
		var YearComma = Year + ", ";
		if (Month === "" && Day === "") {
			 YearComma = Year;
		} else {YearComma =  Year + ", ";}
	}
	else {
		YearColon = "";
		YearPeriod = "";
		YearComma = "";
		YearBracketColon = "";
			}
	
	if (Day !== "") {
		SpaceDay = " "+ Day;
		DayComma = Day + ", ";
	}
	else {
		SpaceDay = "";
		DayComma = "";
	}
	if (Day2 !== "") {
		Day2Comma = Day2 + ", ";
	}
	else {
		Day2Comma = "";
	}
	if (Volume !== "") {
		VolumeComma = Volume + ", ";
	}
	else {
		VolumeComma = "";
	}
	if (Issue !== "") {
		IssueNo = "no. " + Issue;
	}
	else {
		IssueNo = "";
	}

	if (Year !== ""){ 
		 YearColon = Year + ": ";
}
else {YearColon="";}
if (Publisher!==""){PublisherComma= Publisher +  ", "; }
else {PublisherComma= "";}

if (URL!==""&&URL!=="http://"){myURL= " &lt;"+URL +   "&gt;."; }else{myURL="";}

switch (style)
{
case "MLA":
if (ATitle !== "") {
	ATitle = " \"" + ATitle + ".\" ";
}
if (MedTitle!=="") {MedTitle=  " <u>" +MedTitle+  "</u>. "; }
if (City!=="") {City=  City +  ": ";} 
if (Publisher!=="") {Publisher=  Publisher +  ", "; }
if (Issue!=="" && Volume !== ""){Issue= "."+ Issue ;} 
if (Page !== "")  {Page = Page + ". ";}
if (Month!=="") {Month=Month + " ";}
if (Day2!=="" ||Month2!==""||Year2!==""){dateString2=" "+ Day2 +" "+ Month2 + " "+ Year2Period ;}	
else{dateString2="";}

break;

case "APA":
if (Edition !=""){Edition =" (" + Edition + "). ";}
if (ATitle !== "") {
	ATitle = " "+ATitle + ". ";
}
if (type === "Journal") {
	if (MedTitle !== "") {
		MedTitle = " <i>" + MedTitle + "</i>, ";
	}
}else {if (MedTitle !== "") {
		MedTitle = " <i>" + MedTitle + "</i>. ";
	}}
if (City!=="") {City=  City +  ": "; }
if (Publisher !== ""||(URL !==""&&URL !=="http://")) {var From=" from  ";}
	else{From=" ";}


if (Publisher !== "") {
	Publisher = Publisher + ". ";
	
}

if (Volume!==""&& Issue===""){Volume=Volume + ", ";}
if (Issue!==""){Issue= "("+ Issue+"), " ; }
if (Day!=="" ||Month!==""||Year!==""){dateString=" ("+ YearComma + Month + SpaceDay + ").";}	
else{dateString="";}
if (Day2!=="" ||Month2!==""||Year2!==""){dateString2=" "+ Month2 +" "+ Day2Comma + " "+ Year2Comma ;}	
else{dateString2="";}

if (dateString2!==""||(URL !==""&&URL !=="http://")) {Retrieved=" Retrieved  ";}
else {Retrieved="";}
if (Page !== "") {
	 Page = Page + ". ";
	 var NPage = "p." + Page;
}
else {
	 NPage = "";
}
//if (URL!="")var myURL= "Web site: "+URL;
break;

case "Chicago":
if (ATitle !== "") {
	ATitle = " \"" + ATitle + ".\" ";
}
if (MedTitle !== "") {
	MedTitle = " <i>" + MedTitle + "</i>. ";
}
if (City !== "") {
	City = City + ": ";
}
if (Publisher !== "") {
	Publisher = Publisher + ".";
}
	
if (Issue !== "") {
	Issue = "(" + Issue + ") ";
}
if (Day2!==""){Day2=" " + Day2;}

if (Day2!=="" ||Month2!==""||Year2!==""){dateString2="(accessed "+ Month2 +  Day2 + ", " + Year2+ ").";}	
else{dateString2="";}

if (Page !== "") {
	 Page = " "+Page + ". ";
	NPage = " p." + Page;
}
else {
	 NPage = "";
}
break;
}
if (URL !=="" && URL !=="http://")
{fromURL = " from " + URL;
} else {
	fromURL ="";
}
if (authorNum === 0) {
	authorString = "";
}



//******* MLA MAGAZINE ONLINE**************//
if (style==="MLA"&& type==="Magazine"){
total=authorString + ATitle + MedTitle  + Day +  " " + Month + YearColon + Page +  dateString2 +myURL;
}//end if

//******* MLA BOOK **************//

if (style=="MLA"&& type=="Book"){

total = authorString + MedTitle + Edition +" " + City + Publisher + YearPeriod;
}//end if

//******* MLA JOURNAL ONLINE **************//
if (style=="MLA"&& type=="Journal"){
total = authorString +ATitle + MedTitle + Volume + Issue + YearBracketColon + Page +  dateString2 +myURL;

}//end if


//******* MLA Newspaper ONLINE **************//
if (style == "MLA" && type == "Newspaper") {
	total = authorString + ATitle + MedTitle + Day + " " + Month + " " + YearPeriod + " " + Page  +  dateString2+ myURL;
}

//******* MLA MEDIA **************//

if (style==="MLA"&& type==="Media"){
if (title !=="") {title = " <i>" + title + ".</i>";}//adds on quotations
if (specificTitle !== "")  {specificTitle = " " + specificTitle+ ",";}//adds on space
if (date !== "") {date = " "+ date + ".";}//adds on space
total = authorString + title + specificTitle + date ;

}//end if
//******* MLA Database **************//

if (style=="MLA"&& type=="Database"){
total = authorString +ATitle + MedTitle  +  Day + " " + Month +  " " + YearPeriod +  " " + dateString2 +  " "  +myURL ;
}
//******* MLA WEBSITE **************//

if (style=="MLA"&& type=="Website"){
total = authorString +ATitle + MedTitle  +  Day + " " + Month +  " " + YearPeriod +  " " + dateString2 +  " "  +myURL ;
}


//******* APA MAGAZINE **************//

if (style=="APA"&& type=="Magazine"){
	
total=authorString + dateString + ATitle + MedTitle + Volume +  Page + Retrieved + dateString2 +  fromURL;

}//end if
//******* APA BOOK **************//

if (style=="APA"&& type=="Book"){

total = authorString+ dateString + " "+ MedTitle +" " + Edition + City + Publisher ;

}//end if

//******* APA JOURNAL **************//

if (style=="APA"&& type=="Journal"){
total = authorString + dateString + ATitle + MedTitle + Volume + Issue + Page + Retrieved + dateString2 +  fromURL;

}//end if


//******* APA NEWSPAPER WEB**************//

if (style=="APA"&& type=="Newspaper"){
total = authorString + dateString + ATitle +" " + MedTitle + Volume + Issue + Page + Retrieved + dateString2  + fromURL;
}//end if

//******* APA WEBSITE **************//

if (style=="APA"&& type=="Website"){
total = authorString + dateString + ATitle + " " + MedTitle + Retrieved + dateString2  + fromURL ;
}

//******* CHICAGO BOOK **************//

if (style=="Chicago"&& type=="Book"){

total = authorString + MedTitle + Edition +" " + City + PublisherComma + YearPeriod;
}//end if



//******* CHICAGO MAGAZINE WEB**************//

if (style=="Chicago"&& type=="Magazine"){
total=authorString +  ATitle + MedTitle + Month +" "+ DayComma +  YearPeriod +   dateString2;
}//end if



//******* CHICAGO ONLINE JOURNAL **************//

if (style=="Chicago"&& type=="Journal"){
total = authorString  + ATitle + MedTitle + VolumeComma + IssueNo + YearBracketColon + Page + " " + myURL + dateString2;
}//end if


//******* CHICAGO NEWSPAPER**************//

if (style=="Chicago"&& type=="Newspaper"){
total = authorString + ATitle + MedTitle + Volume + Issue +   Month +" " +  DayComma +" "+ YearPeriod + myURL +" " + dateString2;
}//end if

//******* CHICAGO MEDIA **************//

if (style=="Chicago"&& type=="Media"){
total = authorString  + ATitle + MedTitle + VolumeComma + IssueNo + YearBracketColon + Page;
}//end if

//******* CHICAGO WEBSITE **************//

if (style=="Chicago"&& type=="Website"){
total = authorString + ATitle + Publisher  +" "+ myURL  +" "+ dateString2 ;
}

total = '<p style ="padding-left: 20px; text-indent: -20px" >' + total + '</p>';

updateBox();
//tinyMCE.activeEditor.setContent(''); value="Clear";
//tinyMCE.activeEditor.setContent(total);

		
	
	
} //end function
function getfields(){
	try {
		var shorttitle = document.getElementById("shorttitle").value;
	} 
	catch (err) {
		shorttitle = "";

	}
	try {
		var runninghead = document.getElementById("runninghead").value;
	} 
	catch (err) {
		runninghead = "";

	}
	try {
		var mytitle = document.getElementById("mytitle").value;
	} 
	catch (err) {
		mytitle = "";

	}
	try {
		var myname = document.getElementById("myname").value;
	} 
	catch (err) {
		myname = "";	
	}
	try {
		var institution = document.getElementById("institution").value;
	} 
	catch (err) {
		institution = "";	
	}
	try {
		var section = document.getElementById("section").value;
	} 
	catch (err) {
		section = "";	
	}
	try {
		var instructor = document.getElementById("instructor").value;
			} 
	catch (err) {
		instructor = "";	
	}
	try {
		var mydate = document.getElementById("mydate").value;
	} 
	catch (err) {
		mydate = "";	
	}
	try {
		var course = document.getElementById("course").value;
	} 
	catch (err) {
		course = "";	
	}
	
	if (shorttitle!=="") {shorttitle="<div style='text-align: right'> "+shorttitle+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1";}
	if (runninghead!==""){runninghead="Running head: " + runninghead.toUpperCase() + "<br /><br /><br />";}
	total=shorttitle + "</div><div style='font-size:15px;'> " + runninghead + "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></div><div style='text-align: center'>"+ mytitle + "<br/><br /><br/><br /><br/><br /><br/><br /><br/><br /><br/><br /><br/><br />" + myname + "<br /><br />" + instructor+ "<br /><br />" + course + " " + section+ "<br /><br />" + institution + "<br /><br />"+ mydate + "</div>";
		
		updateBox();
		
}

function focus(which){
	var inst = tinyMCE.getInstanceById(which);
if(inst)
{
    inst.focus();
	//alert( inst.getBody().innerHTML);
}
}

