// **** DYNAMIC UPDATES **** //
// **** DYNAMIC UPDATES **** //
// **** DYNAMIC UPDATES **** //

var gUpdates = {};
gUpdates.event = {};
gUpdates.event.type = "event";
gUpdates.event.title = ["Featured","news:"];
gUpdates.event.article = "event_20090413";
gUpdates.event.content = {file:gUpdates.event.article,div:"featured_event_content"};
gUpdates.event.script = "featuredEvent";
gUpdates.event.init = dynamicUpdates;
gUpdates.event.done = updatesDone;
gUpdates.event.links = [];
gUpdates.event.links.push(PMG_writeLink({id:gUpdates.event.type,text:"Find out more",clas:"arrow_links",inline:true,style:"margin:5px 0px 0px 0px;",script:"featuredEvent"}))

//var gUpdates = {};
//gUpdates.event = {};
//gUpdates.event.type = "event";
//gUpdates.event.title = ["Featured","news:"];
//gUpdates.event.article = "event_20080813";
//gUpdates.event.content = {file:gUpdates.event.article,div:"featured_event_content"};
//gUpdates.event.script = "featuredEvent";
//gUpdates.event.init = dynamicUpdates;
//gUpdates.event.done = updatesDone;
//gUpdates.event.links = [];
//gUpdates.event.links.push(PMG_writeLink({id:gUpdates.event.type,text:"Find out more",clas:"arrow_links",inline:true,style:"margin:5px 0px 0px 0px;",script:"featuredEvent"}))
//gUpdates.event.links.push(PMG_writeLink({id:gUpdates.event.type,text:"Download PDF of Lynn's presentation ",clas:"pdf_links",inline:true,style:"margin:5px 0px 0px 0px;",script:"downloadPDF"}))

// FEATURE //
gUpdates.program = {};
gUpdates.program.type = "program";
gUpdates.program.title = ["Featured","event:"];
gUpdates.program.article = "event_20080915";
gUpdates.program.content = {file:gUpdates.program.article,div:"featured_program_content"};
gUpdates.program.script = "featuredPopup";
gUpdates.program.init = dynamicUpdates;
gUpdates.program.done = updatesDone;
gUpdates.program.links = [];
gUpdates.program.links.push(PMG_writeLink({id:gUpdates.program.type,text:"Find out more",clas:"arrow_links",inline:true,style:"margin:5px 0px 0px 0px;",script:"featuredPopup"}))
//gUpdates.program.links.push(PMG_writeLink({id:gUpdates.program.type,text:"See the program",clas:"arrow_links",inline:true,style:"margin:5px 0px 0px 0px;",script:"featuredPopup"}))


function dynamicUpdates(p){
	var x = gUpdates[p];
	var url = gPaths.dynamic_updates + x.content.file + ".txt";
	var target = x.content.div;
	
	document.getElementById(target).innerHTML = 'Loading...';
	if (window.XMLHttpRequest){
		x.req = new XMLHttpRequest();
	}else{
		if(window.ActiveXObject){
			x.req = new ActiveXObject("Microsoft.XMLHTTP");
			
		}
	}
	if(x.req != undefined){
		x.req.onreadystatechange = function(){x.done(url, target, x.req, p);};
		x.req.open("GET", url, true);
		x.req.send("");
	}
}  

function updatesDone(url, target, p_x, p_name) {
	if(p_x.readyState == 4){ // only if p_x is "loaded"
		if(p_x.status == 200){ // only if "OK"
			var w = '';
			var i = gUpdates[p_name].links
			if(i){
				for(var x = 0; x<gUpdates[p_name].links.length; x++){
					w += '<div class="' + p_name + '_link_div">' + i[x] + '</div>';
				}
			}
			// Allows you to place the button within the content //
			var lContent = p_x.responseText + w;
			var lSplit = p_x.responseText.split("~button_goes_here~");
			if(lSplit.length == 2){
				lContent = lSplit[0] + w + lSplit[1]; 
			}
			document.getElementById(target).innerHTML = lContent + '<p>&nbsp;</p>';
		}else{
			document.getElementById(target).innerHTML=" dynamicUpdates() Error:\n" + p_x.status + "\n" + p_x.statusText;
		}
	}
}


function featuredEvent(obj){
	location.href = "news.html?news=newsletters";
}

function downloadPDF(){
	//alert("I need this PDF file please.")
	PMG_downloadPDF('medadnews_conference_9_25_07');
}

function featuredPopup(obj){
	/*
	var p = {};
	p.w = 1024;
	p.h = 768;
	//p.chrome = {} contains all chrome settings ({toolbar:'yes',status:'yes'})
	p.loc = "http://www.purplepill.com";
	PMG_newWindow(p);
	*/
	location.href = "news.html?news=080915";
}

// DYNAMIC UPDATES //
// DYNAMIC UPDATES //
// DYNAMIC UPDATES //

function writeFeaturedBox(p){
	var w = '';
	
	w += '<div id="featured_' + p.type + '" class="featured_div">';	
	w += '<table class="featured_tables" width="100%" cellpadding="0" cellspacing="0" border="0">';
	w += '<tr>';
	w += '<td id="icon_' + p.type + '" class="featured_icons"></td>';
	w += '<td id="header_' + p.type + '" class="featured_headers">';
	w += '<span class="featured_title_blue">' + p.title[0] + '</span> <span class="featured_title_grey">' + p.title[1] + '</span>';
	w += '<div id="featured_' + p.type + '_line" class="featured_lines"></div>';
	w += '<div id="featured_' + p.type + '_content" class="featured_content"></div>';
	//w += '<div class="featured_link_div">' + PMG_writeLink({id:"featured_" + p.type,text:"Find out more",clas:"arrow_links",inline:true}) + '</div>'
	w += '</td>';
	w += '</tr>';
	w += '</table>';
	
	w += '</div>';
	
	document.write(w);
}