function deleteInfoRow(num){
	for (var i = 0; i < num ; i++){
		document.getElementById('myTable2').deleteRow(0);
		}
	
	try {
		for (var i = 0; i < 2; i++) {
			document.getElementById('myTable3').deleteRow(0);
		}
	} 
	catch (e) {
	}
numberRows=0;
	}//end function
	
function buildTable(mylist,mylist2,mytable){
	for (var i = mylist.length - 1; i >= 0; i--) {
	if (mytable == "reg") {
		var x = document.getElementById('myTable2').insertRow(0);
	}else{var x = document.getElementById('myTable3').insertRow(0)}
			
			var y = x.insertCell(0);
			var z = x.insertCell(1);
			
			
			pubLabel = document.createElement("input");
			textField = document.createElement("input");
			pubLabel.tabIndex = "-1";
			pubLabel.value = mylist[i];
			pubLabel.style.border = '0px';
			pubLabel.className = 'mybackground';
			pubLabel.size = "13";
			//var a=document.getElementById('myTable2').rows[0].cells
			
			textField.type = "text";
			textField.id = mylist2[i];
			
			textField.onkeyup = function(){
				sendToBottom();
			};
			textField.size = "46";
			//x.id = "id" + i;
			if (textField.id === "Year" || textField.id === "Issue" || textField.id === "Volume" || textField.id === "Edition") {
				textField.size = "4";
			}
			if (textField.id == "Page") {
				textField.size = "8";
			}
			if (textField.id == "URL") {
				textField.value = "http://";
				/*y.width = "120";*/
				if(type!="Website"){x.id="online";}
							}
		if (mylist[i] == "Date accessed" && type != "Website") {
		
			//x.id = "online2";
			//x.className = "online2";
			
		}
		
			y.appendChild(pubLabel);
			z.appendChild(textField);
			
			/***  VOLUME ISSUE BOX */
			if (mylist2[i] === "Volume") {
			
				textField2 = document.createElement("INPUT");
				textField3 = document.createElement("INPUT");
				
				textField2.type = "text";
				textField3.type = "text";
				textField.style.marginRight = '5px';
				textField2.style.marginRight = '5px';
				
				textField.size = "2";
				textField2.size = "10";
				
				textField3.size = "6";
				
				textField.id = "Volume";
				textField2.value = "Issue";
				textField2.style.border = '0px';
				textField2.tabIndex = -1;
				textField3.id = "Issue";
				textField2.className = 'mybackground';
				textField2.size = "4";
				textField2.readonly = "true";
				
				textField2.onkeyup = function(){
					sendToBottom();
				};
				
			}
			
			if (mylist2[i] === "myDate" || mylist2[i] === "myDate2") {
			
				textField2 = document.createElement("select");
				textField3 = document.createElement("input");
				
				if (mylist2[i] == "myDate2") {
						var until= 13;
					}else{ until=29;}
				
				for (x = 0; x < until; x++) {
					if (style === "MLA") {
						myarray = ["", "Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec." ,"Jan.-Feb.", "Feb.-Mar.", "Mar.-Apr.", "Apr.-May", "May-June", "June-July", "July-Aug.", "Aug.-Sept.", "Sept.-Oct.", "Oct.-Nov.", "Nov.-Dec.", "Dec.-Jan.","Spring","Summer","Fall","Winter"];
					}
					else {
						myarray = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December",  "January/February", "February/March", "March/April", "April/May", "May/June", "June/July", "July/August", "August/September", "September/October", "October/November", "November/December", "December/January","Spring","Summer","Fall","Winter"];
					}
					textField32 = document.createElement("option");
					
					textField32.appendChild(document.createTextNode(myarray[x]));
					textField32.setAttribute("value", myarray[x]);
					textField2.appendChild(textField32);
					j = 1;
					textField.maxLength = "2";
					textField3.maxLength = "4";
					
				}
				
				
				//textField2.type = "text";
				textField3.type = "text";
				textField.style.marginRight = '5px';
				textField2.style.marginRight = '5px';
				
				textField.size = "2";
				
				
				textField3.size = "4";
				switch (mylist2[i]) {
					case "Volume":
						textField.id = "Volume";
						textField2.value = "Issue";
						textField2.style.border = '0px';
						textField2.tabIndex = -1;
						textField3.id = "Issue";
						textField2.className = 'mybackground';
						textField2.size = "4";
						textField2.readonly = "true";
						break;
					case "myDate":
								
						textField.id = "Day";
						textField2.id = "Month";
						textField3.id = "Year";
						
						break;
					case "myDate2":
						
						textField.id = "Day2";
						textField2.id = "Month2";
						textField3.id = "Year2";
			
						break;
				}
				if (mylist2[i]=="myDate2"|| mylist2[i]=="myDate"){
								
						textField.value="dd";
						textField.style.color='#ccc';
						textField.defaultValue="dd";
						textField.onfocus = function(){
					clearDefault(this);
	};
				
		textField3.value="yyyy";
						textField3.style.color='#ccc';
						textField3.defaultValue="yyyy";
						textField3.onfocus = function(){
					clearDefault(this);
	};		}
				
				textField2.onchange = function(){
					sendToBottom();
				};
				
				
			}
			if (mylist2[i] == "myDate" || mylist2[i] == "myDate2" || mylist2[i] == "Volume") {
				textField.onkeyup = function(){
					sendToBottom();
				};
				textField3.onkeyup = function(){
					sendToBottom();
				};
				z.appendChild(textField2);
				
				z.appendChild(textField3);
			}
			//numberRows++;
			if (j === 1 && (type!="Journal")&&!(style==="Chicago"&&type==="Website")) {
				document.getElementById('dformat').className = "show";
			}
			
			if (style === "MLA") {
				document.getElementById('mymonth').className = "shortMonth";
			}
			else {
				document.getElementById('mymonth').className = "longerMonth";
			}
	
}
}//end for
function gettype(mymedium){
	medium=mymedium	
		try {
		
		if (medium == 'Print') {
		
			document.getElementById('myTable3').className = "hide";
			//document.getElementById('online').className = "hide";
			if (style == "MLA") {
				//document.getElementById('mymonth').className = "shortMonth";
			}
			else {
				//document.getElementById('mymonth').className = "longerMonth";
			}
		}
		else {
		
			
			
			document.getElementById('myTable3').className = "show";
			document.getElementById('dformat12').className = "show";
			alert(document.getElementById('dformat12').className)
			//document.getElementById('online').className = "show";
			
			if (type == "Journal") {
				document.getElementById('dformat2').className = "show";
			}
		if (style == "MLA") {
				//document.getElementById('mymonth').className = "shorterMonth";
			}
			else {
				//document.getElementById('mymonth').className = "longMonth";
			}
		}
	}
	catch(e){}
}
function showInfo(text){
	
	type = text;
	if (style!=="notChosen"){
	if (document.getElementById("myButton").disabled === false&& myalert===0) {
		myalert=1;
		answer = confirm("Do you want to proceed without saving your citation? \nIf you do not save it will be overwritten by the next citation");
		if (answer===false){var proceed="no";}
	}
	if (proceed == "no") {
		switch (type){
		case "Magazine":
		rb=	'radiobutton1';
		break;
		case "Book":
		rb=	'radiobutton2';
		break;
		case "Journal":
		rb=	'radiobutton3';
		break;
		case "Newspaper":
		rb=	'radiobutton4';
		break;
		case "Website":
		rb=	'radiobutton5';
		break;
		
		}
		
		document.getElementById(rb).checked = true;
		proceed = "yes";
	}
	else {
		myimage = text;
		
		
		switch (text) {
			case "NewspaperWeb":
				mytext = "an Online Newspaper";
				myimage = "Newspaper";
				break;
			case "JournalWeb":
				mytext = "an Online Journal";
				myimage = "Journal";
				break;
			case "MagazineWeb":
				myimage = "Magazine";
				break;
			default:
				mytext = "a " + text;
				document.getElementById('Print').checked = true;
				
		}
		
		document.getElementById('mycitation').innerHTML = "<img class='floatLeft' src='images/" + myimage + ".gif'>&nbsp;  <strong> " + style + " Citation for " + mytext + " </strong>";
		document.getElementById('citationlabel').innerHTML = " <span class='smallFont'> <strong>Author(s)</strong> First Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MI &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last Name</span>";
		document.getElementById('Step4').className = "mybackground";
		
			if (authorNum !== 0) {
				document.getElementById('authorlabel').className = "show";
			}
		
		document.getElementById('publabel').className = "show";
		if (type == "Website" || type == "Book") {
			document.getElementById('medium').className = "hide";
		}
		else {
			document.getElementById('medium').className = "show";
		}
		document.getElementById('dformat').className = "hide";
		//document.getElementById('publabel').className = "show";
		
		if (typeof numberRows !== "undefined") {
			deleteInfoRow(numberRows);
		}
		//document.getElementById("myButton").style.disabled= "false";
		
		if (hasChangedAuthor === false) {
			changeAuthor(1);
			hasChangedAuthor = true;
		}
		
		var mylist;
		document.getElementById('numauthors1').disabled = false;
		document.getElementById('numauthors2').disabled = false;
		document.getElementById('numauthors1').className = "show";
		
		if (style == "MLA") {
			
			document.getElementById('MLAnote').className = "show";
			document.getElementById('numauthors1').className = "hide";
			document.getElementById('numauthors2').className = "show";
			document.getElementById('APAnote').className = "hide";
			
			switch (text) {
				
				case "Magazine":
					mylist = ["Article title", "Magazine title", "Page(s)", "Date published" ];
					mylist2 = ["ATitle", "MedTitle", "Page", "myDate"];
					break;
					
				case "Book":
					mylist = ["Title", "Edition", "Publishing City", "Publisher", "Year"];
					mylist2 = ["MedTitle", "Edition", "City", "Publisher", "Year"];
					break;
					case "Journal":
					mylist = ["Article title", "Journal Title", "Volume", "Year published", "Pages"];
					mylist2 = ["ATitle", "MedTitle", "Volume", "Year", "Page"];
					break;
				case "Newspaper":
					mylist = ["Article title", "Newspaper title","Pages", "Date Published"];
					mylist2 = ["ATitle", "MedTitle", "Page", "myDate"];
					break;
				case "Media":
					mylist = ["Title", "More Specific Title", "Date"];
					mylist2 = ["ATitle", "City", "Volume", "myDate"];
					break;
				case "Database":
					mylist = ["Article Title", "Database", "Date published", "Date accessed"];
					mylist2 = ["ATitle", "MedTitle", "myDate", "myDate2"];
					break;
					
				case "Website":
					mylist = ["Article title", "Website title", "Date published"];
					mylist2 = ["ATitle", "MedTitle","myDate"];
					break;
					
			}
		}
		if (style == "APA") {
			document.getElementById('MLAnote').className = "hide";
			document.getElementById('numauthors1').className = "show";
			document.getElementById('numauthors2').className = "hide";
			document.getElementById('APAnote').className = "show";
			switch (text) {
				case "Magazine":
					mylist = ["Article title", "Magazine title", "Pages", "Date published"];
					mylist2 = ["ATitle", "MedTitle", "Page", "myDate", "URL"];
					break;
				case "Book":
					mylist = ["Title", "Edition", "Publishing City", "Publisher", "Year"];
					mylist2 = ["MedTitle", "Edition", "City", "Publisher", "Year"];
					break;
				case "Journal":
					mylist = ["Article title", "Journal Title", "Year published", "Volume","Pages"];
					mylist2 = ["ATitle", "MedTitle", "Year", "Volume", "Page"];
					break;
				case "Newspaper":
					mylist = ["Article title", "Newspaper title",  "Pages","Date published"];
					mylist2 = ["ATitle", "MedTitle","Page", "myDate","URL"];
					break;
				case "Media":
					mylist = ["Title", "More Specific Title", "Date"];
					mylist2 = ["ATitle", "City", "Volume", "myDate"];
					break;
				case "Website":
					mylist = ["Article title", "Website title", "Date published"];
					mylist2 = ["ATitle", "MedTitle", "myDate"];
					break;
			}
		}
		
		if (style == "Chicago") {
			document.getElementById('MLAnote').className = "hide";
			document.getElementById('numauthors1').className = "show";
			document.getElementById('numauthors2').className = "hide";
			document.getElementById('APAnote').className = "hide";
			
			switch (text) {
				case "Magazine":
					mylist = ["Article title", "Magazine title", "Date published"];
					mylist2 = ["ATitle", "MedTitle", "myDate"];
					break;
				case "Book":
					mylist = ["Title", "Edition", "Publishing City", "Publisher", "Year"];
					mylist2 = ["MedTitle", "Edition", "City", "Publisher", "Year"];
					break;
				case "Journal":
					mylist = ["Article title", "Journal Title", "Year published", "Volume","Pages"];
					mylist2 = ["ATitle", "MedTitle", "Year", "Volume", "Page"];
					break;
				
				case "Newspaper":
					mylist = ["Article title", "Newspaper title", "Date published"];
					mylist2 = ["ATitle", "MedTitle", "myDate"];
					break;
				case "Media":
					mylist = ["Title", "More Specific Title", "Date"];
					mylist2 = ["ATitle", "City", "Volume", "myDate"];
					break;
				case "Website":
					mylist = ["Article title", "Website title"];
					mylist2 = ["ATitle", "Publisher"];
					break;
			}
		}
		numberRows=mylist.length;
		
				j = 0;
				
		
			//first name
		onlinelist = [ "URL",  "Date accessed"];
				
					onlinelist2 = ["URL",  "myDate2"];	
		if (type != "Book" ) {
			buildTable(onlinelist, onlinelist2,"online");
		}
		buildTable(mylist,mylist2,"reg")
		
		
	try{
		if (type !== "Website") {
			document.getElementById('myTable3').className = "hide";
		}else{document.getElementById('myTable3').className = "show";}
				
				}	
				catch(e){}
	}
	
	}//end function show info
}



function changeStyle(txt){
focus("textarea1");	
		if (citationNum === 0 && document.getElementById('textarea1').value!="Citations will appear in this box as your are typing.") {
		
		tinyMCE.activeEditor.setContent('');
	}
style=txt;	
deleteInfoRow(numberRows);
	//changeAuthor(0);
//gives instructions

//for (i=1;i<=5 ; i++)
//{
//document.getElementById('radiobutton'+i).disabled=false;
//}

//if(txt=='Magazine'||txt=='Book' || txt=='Media' || txt=='Website' || txt=='Journal' || txt=='Newspaper'){
//document.getElementById('numauthors1').disabled=false;
//document.getElementById('numauthors2').disabled=false;
// }

if(type!= "notChosen" && style!== "notChosen"){//makes 3 and 4 bold
	
	document.getElementById("myButton").style.disabled= "false";

	if(hasChangedAuthor === false){ changeAuthor(1); hasChangedAuthor = true;}
showInfo(type);
}
	
	

}
function setStyle(style){
	if (style=="APA"){
	//document.getElementById("myrunninghead").className="show";
	document.getElementById("keyword").className="show";		
	}else{//document.getElementById("runninghead").className="hide";
	document.getElementById("keyword").className="hide";	}
}
