var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE

function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}

	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length; 
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {

		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}

	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;

	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	}
	return (xhrsend);
}

function fcn(url, mediaID, divID) {

	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', url, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			//alert(xhr[xhri].responseText)
		document.getElementById(divID).innerHTML=xhr[xhri].responseText
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}

// show portfolio by mediaID
function getPortfolioByMID(MediaID, IsEducation) {
	// CALL A FUNCTION THAT USES xmlHttp MULTIPLE TIMES
	if (IsEducation == 0) {
		fcn('../files/includes/getportfolio.asp?MediaID='+MediaID+'&sid='+Math.random(),MediaID,'foliobodycontent');
		fcn('../files/includes/getportfolioimages.asp?MediaID='+MediaID+'&sid='+Math.random(),MediaID,'swatchbodycontent');
	} else {
		fcn('../files/includes/getedportfolio.asp?MediaID='+MediaID+'&sid='+Math.random(),MediaID,'foliobodycontent');
		fcn('../files/includes/getedportfolioimages.asp?MediaID='+MediaID+'&sid='+Math.random(),MediaID,'swatchbodycontent');
	}
}

// show portfolio by portfolioID
function getPortfolioByPID(PortfolioID, IsEducation){
	// CALL A FUNCTION THAT USES xmlHttp MULTIPLE TIMES
	if (IsEducation == 0) {
		fcn('../files/includes/getportfolio.asp?PortfolioID='+PortfolioID+'&sid='+Math.random(),PortfolioID,'foliobodycontent');
	} else {
		fcn('../files/includes/getedportfolio.asp?PortfolioID='+PortfolioID+'&sid='+Math.random(),PortfolioID,'foliobodycontent');
	}
}

// show portfolio by portfolioID
function getMediaProfile(MediaID){
	document.getElementById('MediaID').value=MediaID;
	fcn('../files/includes/getmediaprofile.asp?MediaID='+MediaID+'&sid='+Math.random(),MediaID,'mediaprofilecontent');
}

// show case study by portfolioID
//function getCaseStudyByPID(PortfolioID){
	//fcn('../files/includes/getcasestudy.asp?PortfolioID='+PortfolioID+'&sid='+Math.random(),PortfolioID,'casestudybodycontent');
//}

// show case study by portfolioID
function getCaseStudyByPID(PortfolioID, IsEducation){
	if (IsEducation == 0) {
		fcn('../files/includes/getcasestudy.asp?PortfolioID='+PortfolioID+'&sid='+Math.random(),PortfolioID,'casestudybodycontent');
	} else {
		fcn('../files/includes/getedcasestudy.asp?PortfolioID='+PortfolioID+'&sid='+Math.random(),PortfolioID,'casestudybodycontent');
	}
}

// show newsletter by NewsletterID
function getNewsletterByNID(NewsletterID){
	fcn('../files/includes/getnewsletter.asp?NewsletterID='+NewsletterID+'&sid='+Math.random(),NewsletterID,'newsbodycontent');
}



//window.onload = loadMulti();

