/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}


/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* approve an applicant */
function add_to_portfolio(mod_id){

	http.open('get', 'ajax_add_to_portfolio.php?action=add&mod_id='+mod_id);
	// alert("Hello");
	http.onreadystatechange  = function() { handle_add(mod_id) }
	http.send(null);
}


function handle_add(mod_id){

	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		var element = mod_id;
		// alert(app_id);
		document.getElementById('inner_module_controls_holder_'+mod_id).innerHTML = response;
	}
}

function get_page_contents(p_id,mod_id,u_id){

	http.open('get', 'ajax_get_page_contents.php?p_id='+p_id+'&mod_id='+mod_id+'&u_id='+u_id);
	// alert("Hello");
	http.onreadystatechange  = function() { handle_get_page_contents(p_id,mod_id,u_id) }
	http.send(null);

}
function handle_get_page_contents(p_id,mod_id,u_id){

	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		var control = '<a href=javascript:close_content('+p_id+','+mod_id+','+u_id+');>Close</a>';
		var element = p_id;
		// alert(app_id);
		document.getElementById('holder_'+p_id).innerHTML = response;
		document.getElementById('control'+p_id).innerHTML = control;
	}
}

//

function get_page_control(p_id,mod_id,u_id){

	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		var element = p_id;
		// alert(app_id);
		document.getElementById('holder_'+p_id).innerHTML = response;
	}
}


function close_content(p_id,mod_id,u_id){

	var control = '<a href=javascript:get_page_contents('+p_id+','+mod_id+','+u_id+');>View Content</a>';
	document.getElementById('holder_'+p_id).innerHTML = "";
	document.getElementById('control'+p_id).innerHTML = control;
}

function mha_apply(u_id){

	http.open('get', 'ajax_mha_application.php?u_id='+u_id);
	// alert("Hello");
	http.onreadystatechange  = function() { handle_mha_apply(u_id) }
	http.send(null);

}
function handle_mha_apply(u_id){

	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		var element = u_id;
		// alert(app_id);
		document.getElementById('mha_application').innerHTML = response;
	} else if (http.readyState>0 && http.readyState<4) {
		document.getElementById('mha_application').innerHTML = "Processing... Please Wait";	
	}
}
