// Provide the XMLHttpRequest class for IE 5.x-6.x:
// Other browsers (including IE 7.x-8.x) ignore this when XMLHttpRequest is predefined
if (typeof XMLHttpRequest == "undefined")
	XMLHttpRequest = function()
	{
		try {return new ActiveXObject("Msxml2.XMLHTTP.6.0");} catch(err) {}
		try {return new ActiveXObject("Msxml2.XMLHTTP.3.0");} catch(err) {}
		try {return new ActiveXObject("Msxml2.XMLHTTP");} catch(err) {}
		try {return new ActiveXObject("Microsoft.XMLHTTP");} catch(err) {}
		throw new Error("Your browser does not support XMLHttpRequest used by this page.");
	};

// use global variables
var ajaxRequest, ajaxDivName;

// update efront
function updateEfront(divname, login, active)
{
	if (active)
		ajaxUpdate(divname, "update_efront.php?login_activate=" + login);
	else
		ajaxUpdate(divname, "update_efront.php?login_deactivate=" + login);
}

function updateUserType(divname, agentID, UserType)
{
	ajaxUpdate(divname, "update_usertype.php?arguments=" + UserType + " " + agentID);
}

function updateCoach(divname, CoachID , AgentID )
{
	ajaxUpdate(divname, "update_membercoach.php?arguments=" + CoachID + " " + AgentID);
}

// update member newsletter subscription status
function updateNewsLetterMember(divname, agentID, subscription)
{
	ajaxUpdate(divname, "update_newslettermember.php?arguments=" + subscription + " " + agentID);
}

// update member purchase products status
function updatePurchaseProducts(divname, agentID, subscription)
{
	ajaxUpdate(divname, "update_purchaseproducts.php?arguments=" + subscription + " " + agentID);
}

// update member photo upload status
function updatePhotoUpload(divname, agentID, subscription)
{
	ajaxUpdate(divname, "update_photoupload.php?arguments=" + subscription + " " + agentID);
}

// update member newsletter subscription status
function updateNewsLetterCoach(divname, agentID, subscription)
{
	ajaxUpdate(divname, "update_newslettercoach.php?arguments=" + subscription + " " + agentID);
}

// update member subscription status
function updateMember(divname, agentID, subscription)
{
	ajaxUpdate(divname, "update_member.php?arguments=" + subscription + " " + agentID);
}

// update coach/member status
//function updateCoach_old(divname, agentID, coach)
//{
	//if (coach)
		//ajaxUpdate(divname, "update_coach.php?val_id=1 " + agentID);
	//else
		//ajaxUpdate(divname, "update_coach.php?val_id=0 " + agentID);
//}






// use this function to setup the ajax update
function ajaxUpdate(divName, getString)
{
	try {ajaxRequest = new XMLHttpRequest();} catch (err) {throw err;}

	ajaxRequest.open("GET", getString, true);
	ajaxDivName = divName;
	ajaxRequest.onreadystatechange = ajaxProcessRequest;
	ajaxRequest.send(null);
}

// processes the successful http request
function ajaxProcessRequest()
{	
	if (ajaxRequest.readyState == 4) 	// completed
	{
		if (ajaxRequest.status == 200)	// HTTP OK
			document.getElementById(ajaxDivName).innerHTML = ajaxRequest.responseText;					
		else
			throw new Error("There has been an error retrieving the Ajax HTTP request: " + ajaxRequest.statusText);
	}
}		
