var xmlHttp = createXmlHttpRequestObject();

function getNextGiveUpYear1(ownerID)  {
	if (document.tradeform.giveupdraft1year.options[document.tradeform.giveupdraft1year.selectedIndex].value == "x")  {
		clearSelectGiveUpYear1();
	} else {
		processGiveUpYear1(ownerID);
	}
}

function getNextGiveUpYear2(ownerID)  {
	if (document.tradeform.giveupdraft1round.options[document.tradeform.giveupdraft1round.selectedIndex].value != "x")  {
		if (document.tradeform.giveupdraft2year.options[document.tradeform.giveupdraft2year.selectedIndex].value == "x")  {
			clearSelectGiveUpYear2();
		} else {
			processGiveUpYear2(ownerID);
		}
	}
}


function getNextGiveUpYear3(ownerID)  {
	if (document.tradeform.giveupdraft1round.options[document.tradeform.giveupdraft1round.selectedIndex].value != "x")  {
		if (document.tradeform.giveupdraft2round.options[document.tradeform.giveupdraft2round.selectedIndex].value != "x")  {
			if (document.tradeform.giveupdraft3year.options[document.tradeform.giveupdraft3year.selectedIndex].value == "x")  {
				clearSelectGiveUpYear3();
			} else {
				processGiveUpYear3(ownerID);
			}
		}
	}
}


function processGiveUpYear3(ownerID)  {
	if (xmlHttp)  {
		try  {
			var year1 = document.tradeform.giveupdraft1year.options[document.tradeform.giveupdraft1year.selectedIndex].value;
			var round1 = document.tradeform.giveupdraft1round.options[document.tradeform.giveupdraft1round.selectedIndex].value;
			var year2 = document.tradeform.giveupdraft2year.options[document.tradeform.giveupdraft2year.selectedIndex].value;
			var round2 = document.tradeform.giveupdraft2round.options[document.tradeform.giveupdraft2round.selectedIndex].value;
			var year3 = document.tradeform.giveupdraft3year.options[document.tradeform.giveupdraft3year.selectedIndex].value;
			xmlHttp.open("GET","getTradeDraftList.php?ownerID="+ownerID+"&year1="+year1+"&year2="+year2+"&year3="+year3+"&round1="+round1+"&round2="+round2,true);
			xmlHttp.onreadystatechange = handleRequestStateChangeGiveUpYears3;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}


function processGiveUpYear2(ownerID)  {
	if (xmlHttp)  {
		try  {
			var year1 = document.tradeform.giveupdraft1year.options[document.tradeform.giveupdraft1year.selectedIndex].value;
			var round1 = document.tradeform.giveupdraft1round.options[document.tradeform.giveupdraft1round.selectedIndex].value;
			var year2 = document.tradeform.giveupdraft2year.options[document.tradeform.giveupdraft2year.selectedIndex].value;
			xmlHttp.open("GET","getTradeDraftList.php?ownerID="+ownerID+"&year1="+year1+"&year2="+year2+"&year3=&round1="+round1+"&round2=",true);
			xmlHttp.onreadystatechange = handleRequestStateChangeGiveUpYears2;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}

function processGiveUpYear1(ownerID)  {
	if (xmlHttp)  {
		try  {
			var year1 = document.tradeform.giveupdraft1year.options[document.tradeform.giveupdraft1year.selectedIndex].value;
			xmlHttp.open("GET","getTradeDraftList.php?ownerID="+ownerID+"&year1="+year1+"&year2=&year3=&round1=&round2=",true);
			xmlHttp.onreadystatechange = handleRequestStateChangeGiveUpYear1;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}

function handleRequestStateChangeGiveUpYear1()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseGiveUpYear1();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}

function handleRequestStateChangeGiveUpYears2()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseGiveUpYear2();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}


function handleRequestStateChangeGiveUpYears3()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseGiveUpYear3();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}


function handleServerResponseGiveUpYear1()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	var html = "";
	clearSelectGiveUpYear1();
	for (var x=0;x<valueArray.length;x++)  {
		var thisOption=new Array();
		thisOption["round"] = valueArray.item(x).firstChild.data+":"+valueArray.item(x+1).firstChild.data;
		x++;
		x++;
		thisOption["id"] = valueArray.item(x).firstChild.data;
		document.getElementById("giveupdraft1round").options[document.getElementById("giveupdraft1round").options.length] = new Option(thisOption["id"],thisOption["round"]);
	}
	<!--populateNextYear2();-->
}

function handleServerResponseGiveUpYear2()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	var html = "";
	clearSelectGiveUpYear2();
	for (var x=0;x<valueArray.length;x++)  {
		var thisOption=new Array();
		thisOption["round"] = valueArray.item(x).firstChild.data+":"+valueArray.item(x+1).firstChild.data;
		x++;
		x++;
		thisOption["id"] = valueArray.item(x).firstChild.data;
		document.getElementById("giveupdraft2round").options[document.getElementById("giveupdraft2round").options.length] = new Option(thisOption["id"],thisOption["round"]);
	}
}


function handleServerResponseGiveUpYear3()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	var html = "";
	clearSelectGiveUpYear3();
	for (var x=0;x<valueArray.length;x++)  {
		var thisOption=new Array();
		thisOption["round"] = valueArray.item(x).firstChild.data+":"+valueArray.item(x+1).firstChild.data;
		x++;
		x++;
		thisOption["id"] = valueArray.item(x).firstChild.data;
		document.getElementById("giveupdraft3round").options[document.getElementById("giveupdraft3round").options.length] = new Option(thisOption["id"],thisOption["round"]);
	}
}


function clearSelectGiveUpYear1()  {
	var selectList1 = document.getElementById("giveupdraft1round");
	if (selectList1.options.length != 0)  {
		while(selectList1.lastChild){
    		selectList1.removeChild(selectList1.lastChild);
		}
	}
	var selectList2 = document.getElementById("giveupdraft2round");
	if (selectList2.options.length != 0)  {
		while(selectList2.lastChild){
    		selectList2.removeChild(selectList2.lastChild);
		}
	}
	var selectList3 = document.getElementById("giveupdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("giveupdraft1round").options[document.getElementById("giveupdraft1round").options.length] = new Option("Draft pick 1...","x");
	document.getElementById("giveupdraft2round").options[document.getElementById("giveupdraft2round").options.length] = new Option("Draft pick 2...","x");
	document.getElementById("giveupdraft3round").options[document.getElementById("giveupdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("giveupdraft2year").selectedIndex=0;
	document.getElementById("giveupdraft3year").selectedIndex=0;
}

function clearSelectGiveUpYear2()  {
	var selectList2 = document.getElementById("giveupdraft2round");
	if (selectList2.options.length != 0)  {
		while(selectList2.lastChild){
    		selectList2.removeChild(selectList2.lastChild);
		}
	}
	var selectList3 = document.getElementById("giveupdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("giveupdraft2round").options[document.getElementById("giveupdraft2round").options.length] = new Option("Draft pick 2...","x");
	document.getElementById("giveupdraft3round").options[document.getElementById("giveupdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("giveupdraft3year").selectedIndex=0;
}


function clearSelectGiveUpYear3()  {
	var selectList3 = document.getElementById("giveupdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("giveupdraft3round").options[document.getElementById("giveupdraft3round").options.length] = new Option("Draft pick 3...","x");
}


function populateNextYear2()  {
	var selectSource=document.getElementById("giveupdraft1year");
	for (x=1;x<selectSource.length;x++)  {
		document.getElementById("giveupdraft2year").options[document.getElementById("giveupdraft2year").options.length] = new Option(selectSource[x].value,selectSource[x].value);
	}
}


function getNextGiveUpRound1()  {
	var selectList2 = document.getElementById("giveupdraft2round");
	if (selectList2.options.length != 0)  {
		while(selectList2.lastChild){
    		selectList2.removeChild(selectList2.lastChild);
		}
	}
	var selectList3 = document.getElementById("giveupdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("giveupdraft2round").options[document.getElementById("giveupdraft2round").options.length] = new Option("Draft pick 2...","x");
	document.getElementById("giveupdraft3round").options[document.getElementById("giveupdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("giveupdraft2year").selectedIndex=0;
	document.getElementById("giveupdraft3year").selectedIndex=0;
}


function getNextGiveUpRound2()  {
	var selectList3 = document.getElementById("giveupdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("giveupdraft3round").options[document.getElementById("giveupdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("giveupdraft3year").selectedIndex=0;
}




var xmlHttp = createXmlHttpRequestObject();

function getNextGettingYear1()  {
	var ownerID=document.tradeform.otherteam.options[document.tradeform.otherteam.selectedIndex].value;
	if (ownerID == "x")  {
		clearSelectGettingYear1();
	} else {
		processGettingYear1(ownerID);
	}
}

function getNextGettingYear2()  {
	var ownerID=document.tradeform.otherteam.options[document.tradeform.otherteam.selectedIndex].value;
	if (document.tradeform.gettingdraft1round.options[document.tradeform.gettingdraft1round.selectedIndex].value != "x")  {
		if (document.tradeform.gettingdraft2year.options[document.tradeform.gettingdraft2year.selectedIndex].value == "x")  {
			clearSelectGettingYear2();
		} else {
			processGettingYear2(ownerID);
		}
	}
}


function getNextGettingYear3()  {
	var ownerID=document.tradeform.otherteam.options[document.tradeform.otherteam.selectedIndex].value;
	if (document.tradeform.gettingdraft1round.options[document.tradeform.gettingdraft1round.selectedIndex].value != "x")  {
		if (document.tradeform.gettingdraft2round.options[document.tradeform.gettingdraft2round.selectedIndex].value != "x")  {
			if (document.tradeform.gettingdraft3year.options[document.tradeform.gettingdraft3year.selectedIndex].value == "x")  {
				clearSelectGettingYear3();
			} else {
				processGettingYear3(ownerID);
			}
		}
	}
}


function processGettingYear3(ownerID)  {
	if (xmlHttp)  {
		try  {
			var year1 = document.tradeform.gettingdraft1year.options[document.tradeform.gettingdraft1year.selectedIndex].value;
			var round1 = document.tradeform.gettingdraft1round.options[document.tradeform.gettingdraft1round.selectedIndex].value;
			var year2 = document.tradeform.gettingdraft2year.options[document.tradeform.gettingdraft2year.selectedIndex].value;
			var round2 = document.tradeform.gettingdraft2round.options[document.tradeform.gettingdraft2round.selectedIndex].value;
			var year3 = document.tradeform.gettingdraft3year.options[document.tradeform.gettingdraft3year.selectedIndex].value;
			xmlHttp.open("GET","getTradeDraftList.php?ownerID="+ownerID+"&year1="+year1+"&year2="+year2+"&year3="+year3+"&round1="+round1+"&round2="+round2,true);
			xmlHttp.onreadystatechange = handleRequestStateChangeGettingYears3;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}


function processGettingYear2(ownerID)  {
	if (xmlHttp)  {
		try  {
			var year1 = document.tradeform.gettingdraft1year.options[document.tradeform.gettingdraft1year.selectedIndex].value;
			var round1 = document.tradeform.gettingdraft1round.options[document.tradeform.gettingdraft1round.selectedIndex].value;
			var year2 = document.tradeform.gettingdraft2year.options[document.tradeform.gettingdraft2year.selectedIndex].value;
			xmlHttp.open("GET","getTradeDraftList.php?ownerID="+ownerID+"&year1="+year1+"&year2="+year2+"&year3=&round1="+round1+"&round2=",true);
			xmlHttp.onreadystatechange = handleRequestStateChangeGettingYears2;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}

function processGettingYear1(ownerID)  {
	if (xmlHttp)  {
		try  {
			var year1 = document.tradeform.gettingdraft1year.options[document.tradeform.gettingdraft1year.selectedIndex].value;
			xmlHttp.open("GET","getTradeDraftList.php?ownerID="+ownerID+"&year1="+year1+"&year2=&year3=&round1=&round2=",true);
			xmlHttp.onreadystatechange = handleRequestStateChangeGettingYear1;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}

function handleRequestStateChangeGettingYear1()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseGettingYear1();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}

function handleRequestStateChangeGettingYears2()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseGettingYear2();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}


function handleRequestStateChangeGettingYears3()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseGettingYear3();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}


function handleServerResponseGettingYear1()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	var html = "";
	clearSelectGettingYear1();
	for (var x=0;x<valueArray.length;x++)  {
		var thisOption=new Array();
		thisOption["round"] = valueArray.item(x).firstChild.data+":"+valueArray.item(x+1).firstChild.data;
		x++;
		x++;
		thisOption["id"] = valueArray.item(x).firstChild.data;
		document.getElementById("gettingdraft1round").options[document.getElementById("gettingdraft1round").options.length] = new Option(thisOption["id"],thisOption["round"]);
	}
	<!--populateNextYear22();-->
}

function handleServerResponseGettingYear2()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	var html = "";
	clearSelectGettingYear2();
	for (var x=0;x<valueArray.length;x++)  {
		var thisOption=new Array();
		thisOption["round"] = valueArray.item(x).firstChild.data+":"+valueArray.item(x+1).firstChild.data;
		x++;
		x++;
		thisOption["id"] = valueArray.item(x).firstChild.data;
		document.getElementById("gettingdraft2round").options[document.getElementById("gettingdraft2round").options.length] = new Option(thisOption["id"],thisOption["round"]);
	}
}


function handleServerResponseGettingYear3()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	var html = "";
	clearSelectGettingYear3();
	for (var x=0;x<valueArray.length;x++)  {
		var thisOption=new Array();
		thisOption["round"] = valueArray.item(x).firstChild.data+":"+valueArray.item(x+1).firstChild.data;
		x++;
		x++;
		thisOption["id"] = valueArray.item(x).firstChild.data;
		document.getElementById("gettingdraft3round").options[document.getElementById("gettingdraft3round").options.length] = new Option(thisOption["id"],thisOption["round"]);
	}
}


function clearSelectGettingYear1()  {
	var selectList1 = document.getElementById("gettingdraft1round");
	if (selectList1.options.length != 0)  {
		while(selectList1.lastChild){
    		selectList1.removeChild(selectList1.lastChild);
		}
	}
	var selectList2 = document.getElementById("gettingdraft2round");
	if (selectList2.options.length != 0)  {
		while(selectList2.lastChild){
    		selectList2.removeChild(selectList2.lastChild);
		}
	}
	var selectList3 = document.getElementById("gettingdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("gettingdraft1round").options[document.getElementById("gettingdraft1round").options.length] = new Option("Draft pick 1...","x");
	document.getElementById("gettingdraft2round").options[document.getElementById("gettingdraft2round").options.length] = new Option("Draft pick 2...","x");
	document.getElementById("gettingdraft3round").options[document.getElementById("gettingdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("gettingdraft2year").selectedIndex=0;
	document.getElementById("gettingdraft3year").selectedIndex=0;
}

function clearSelectGettingYear2()  {
	var selectList2 = document.getElementById("gettingdraft2round");
	if (selectList2.options.length != 0)  {
		while(selectList2.lastChild){
    		selectList2.removeChild(selectList2.lastChild);
		}
	}
	var selectList3 = document.getElementById("gettingdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("gettingdraft2round").options[document.getElementById("gettingdraft2round").options.length] = new Option("Draft pick 2...","x");
	document.getElementById("gettingdraft3round").options[document.getElementById("gettingdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("gettingdraft3year").selectedIndex=0;
}


function clearSelectGettingYear3()  {
	var selectList3 = document.getElementById("gettingdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("gettingdraft3round").options[document.getElementById("gettingdraft3round").options.length] = new Option("Draft pick 3...","x");
}


function populateNextYear22()  {
	var selectSource=document.getElementById("gettingdraft1year");
	for (x=1;x<selectSource.length;x++)  {
		document.getElementById("gettingdraft2year").options[document.getElementById("gettingdraft2year").options.length] = new Option(selectSource[x].value,selectSource[x].value);
	}
}


function getNextGettingRound1()  {
	var selectList2 = document.getElementById("gettingdraft2round");
	if (selectList2.options.length != 0)  {
		while(selectList2.lastChild){
    		selectList2.removeChild(selectList2.lastChild);
		}
	}
	var selectList3 = document.getElementById("gettingdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("gettingdraft2round").options[document.getElementById("gettingdraft2round").options.length] = new Option("Draft pick 2...","x");
	document.getElementById("gettingdraft3round").options[document.getElementById("gettingdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("gettingdraft2year").selectedIndex=0;
	document.getElementById("gettingdraft3year").selectedIndex=0;
}


function getNextGettingRound2()  {
	var selectList3 = document.getElementById("gettingdraft3round");
	if (selectList3.options.length != 0)  {
		while(selectList3.lastChild){
    		selectList3.removeChild(selectList3.lastChild);
		}
	}
	document.getElementById("gettingdraft3round").options[document.getElementById("gettingdraft3round").options.length] = new Option("Draft pick 3...","x");
	document.getElementById("gettingdraft3year").selectedIndex=0;
}
