var xmlHttp13;

function loadSponsors(){
	xmlHttp13 = GetXmlHttpObject();
	if(xmlHttp13 == null)
 	{
 		alert ("Browser does not support HTTP Request");
 	}
	 	
	var url = "ofphp/sponsorlist.php";
	url += "?sid=" + Math.random();
			
	xmlHttp13.open("GET", url, true);
	xmlHttp13.onreadystatechange = stateChanged13;
	xmlHttp13.send("");		
}

function stateChanged13(){ 
	if(xmlHttp13.readyState==4 || xmlHttp13.readyState=="complete"){
		var sponsorArray = xmlHttp13.responseText.split("~~~"); 
		var level1Array = new Array(); //600+
		var level2Array = new Array();
		var level3Array = new Array();
		var level4Array = new Array();
		
		
		for(var i = 0; i < sponsorArray.length - 1; i++){
			var sponsorItem = sponsorArray[i].split("***");
			
//create the container
/*
image_file
url
contribution
title
subtitle
description
*/		

			var sponsContainer = "<table border=0 cellspacing=0 cellpadding=0>"
			sponsContainer += "<tr><td>";
			sponsContainer += "<a href='" + sponsorItem[1] + "'><img src='sponsors/" + sponsorItem[0] + "' /></a>"; //image and link 
			sponsContainer += "</td><td style='left:160px; width:260px; font-size: 11px; border-left: 1px solid #fe7115; padding:10px'>";
			sponsContainer += "<h1>" + sponsorItem[3] + "</h1>";//title
			if(sponsorItem[4] != "")
				sponsContainer += "<br><span style='font-weight:bold; text-align: center'>" + sponsorItem[4] + "</span>";//subtitle
			sponsContainer += "<br>" + unescape(sponsorItem[5]);//description
			sponsContainer += "</div>";
			sponsContainer += "</td></tr></table>";
			
//add the container to one of four elements
			if(parseInt(sponsorItem[2]) >= 600) //champion level
				level1Array.push(sponsContainer);				
			else if((parseInt(sponsorItem[2]) >= 300) && (parseInt(sponsorItem[2]) <= 599)) //touchdown
				level2Array.push(sponsContainer);				
			else if((parseInt(sponsorItem[2]) >= 100) && (parseInt(sponsorItem[2]) <= 299))//first and goal //extra point
				level3Array.push(sponsContainer);				
			else if((parseInt(sponsorItem[2]) >= 50) && (parseInt(sponsorItem[2]) <= 99))//first and goal //extra point
				level4Array.push(sponsContainer);
		}		

		for(var i = 0; i < level1Array.length; i++) {
//create a row
			var tbl = document.getElementById("level1");
			var lastRow = tbl.rows.length;
			var row = tbl.insertRow(lastRow);
//first cell
			var cellLeft = row.insertCell(0);
			cellLeft.style.backgroundColor = "#ffffff";
			cellLeft.style.border = "1px solid #fe7115";
			cellLeft.innerHTML = level1Array[i];

//second cell			
			if(i < level1Array.length - 1) {
				var cellRight = row.insertCell(1);
				cellRight.style.backgroundColor = "#ffffff";
				cellRight.style.border = "1px solid #fe7115";
				i++;
				cellRight.innerHTML = level1Array[i];
			}
		}
		for(var i = 0; i < level2Array.length; i++) {
//create a row
			var tbl = document.getElementById("level2");
			var lastRow = tbl.rows.length;
			var row = tbl.insertRow(lastRow);
//first cell
			var cellLeft = row.insertCell(0);
			cellLeft.style.backgroundColor = "#ffffff";
			cellLeft.style.border = "1px solid #fe7115";
			cellLeft.innerHTML = level2Array[i];

//second cell			
			if(i < level2Array.length - 1) {
				var cellRight = row.insertCell(1);
				cellRight.style.backgroundColor = "#ffffff";
				cellRight.style.border = "1px solid #fe7115";
				i++;
				cellRight.innerHTML = level2Array[i];
			}
		}
		for(var i = 0; i < level3Array.length; i++) {
//create a row
			var tbl = document.getElementById("level3");
			var lastRow = tbl.rows.length;
			var row = tbl.insertRow(lastRow);
//first cell
			var cellLeft = row.insertCell(0);
			cellLeft.style.backgroundColor = "#ffffff";
			cellLeft.style.border = "1px solid #fe7115";
			cellLeft.innerHTML = level3Array[i];

//second cell			
			if(i < level3Array.length - 1) {
				var cellRight = row.insertCell(1);
				cellRight.style.backgroundColor = "#ffffff";
				cellRight.style.border = "1px solid #fe7115";
				i++;
				cellRight.innerHTML = level3Array[i];
			}
		}
		for(var i = 0; i < level4Array.length; i++) {
//create a row
			var tbl = document.getElementById("level4");
			var lastRow = tbl.rows.length;
			var row = tbl.insertRow(lastRow);
//first cell
			var cellLeft = row.insertCell(0);
			cellLeft.style.backgroundColor = "#ffffff";
			cellLeft.style.border = "1px solid #fe7115";
			cellLeft.innerHTML = level4Array[i];

//second cell			
			if(i < level4Array.length - 1) {
				var cellRight = row.insertCell(1);
				cellRight.style.backgroundColor = "#ffffff";
				cellRight.style.border = "1px solid #fe7115";
				i++;
				cellRight.innerHTML = level4Array[i];
			}
		}
	}	
}
