/*********************************************/
/*       ALL MEAL PLANNER FUNCTIONS          */
/*********************************************/

// append globals //
gPaths.images_mp = gPaths.base + "media/images/";

// ******************************************** //
// EXEC A BODY CONTENT LINK   
// p_id = string
// can redirect or call openNewWindow();
// ******************************************** //
function PMG_writeLegend(p){
	
	// Default is both legend items //
	if(!p){
		p = {exchange:true,acid:true}
	}
	
	var lItems = {};
	lItems.exchange = 'Exchange Items';
	lItems.acid = 'Possible Acid Reflux Trigger';
	
	var s = '';
	s += '<div id="legend_div">';
	s += '<table cellpadding="0" cellspacing="0" border="0"><tr>';
	for(var prop in p){
		if(p[prop]){
			s += '<td><div id="'+ prop + '_square"></div><td class="legend_item">' + lItems[prop] + '</td>';
		}
	}
	
	s += '</tr></table>';
	s += '</div>'

	document.write(s);
	
}

// ******************************************** //
// EXEC A BODY CONTENT LINK   
// p_id = string
// can redirect or call openNewWindow();
// ******************************************** //
function PMG_clickLink(_location){
	
	var pLoc = null;

	switch(_location){
		case "register":
			pLoc = "landing_page.aspx#registration_top";
			break;
		case "azprivacystatement":
			PMG_newWindow({loc:"http://www.azprivacystatement.com",name:"az"});
			break;
		case "adobe_reader":
			PMG_newWindow({loc:"http://www.adobe.com",name:"adobe"});
			//openNewWindow({loc:"http://www.adobe.com/products/acrobat/readstep2.html",name:"adobe"});
			break;
		case "calorie_level":
			var p = {};
			p.loc = "calorie_level.aspx";
			p.nochrome = true;
			p.chrome = {};
			p.chrome.scrollbars = "yes";
			PMG_newWindow(p);
			break;
		default:
			if(_location != ""){
				pLoc = _location;
				 if(pLoc.indexOf(".asp") == -1){
				 	pLoc += ".aspx";
				 }
			}else{
				alert("href not passed to PMG_clickLink() in functions_mp.js");
			}
			break;
	}

	
	if(pLoc != null){
		location.href = pLoc;
	}
	
}

function writePurpleHeader_mp(p){

	if(typeof(p) != "object"){
		p = {text:"Title not passed to writePurpleHeader_mp()"}
	}
	
	var s = '';
	s += '<div class="purple_header_mp">';
	s += '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	s += '<tr>';
	s += '<td class="purple_header_mp" height="26">' + p.text + '</td>';
	s += '</tr>';
	s += '</table>';
	s += '</div>';
	
	if(p.inline){
		return s;
	}else{
		document.write(s);
	}
	return true;

}

function clickForAlternatives(pAnchor){
	p = {};
	p.loc = "subslistPF.aspx#" + pAnchor;
	p.nochrome = true;
	p.chrome = {}
	p.chrome.scrollbars = "yes";
	p.w = 850;
	PMG_newWindow(p);
}


function mp_advancedSearch(){
	p = {};
	p.loc = "mpsearch.aspx";
	p.nochrome = true;
	p.chrome = {};
	p.chrome.scrollbars = "yes";
	p.chrome.resizable = "yes";
	p.w = 900;
	p.h = 500;
	PMG_newWindow(p);
}

// ******************************************** //
// CLOSE A POPUP WINDOW   
// p = {}
// p.id = opener new location?
// p.frame = the frame to redirect (parent,top)
// closes a popup and can redirect the opener
// ******************************************** //
function closeThisWindow(p){

	var pLocation = false;
	if(p){
		switch(p.id){
			case "register":
				pLocation = "registration.aspx";
				break;
			default:
				alert("p.id = " + p.id + "\nID not passed to closeThisWindow()");
				break;
		}
	}
	
	if(pLocation){
		if(p.frame){
			/* Break out of the frame? */
			window.opener[p.frame].location.href = pLocation;
		}else{
			window.opener.location.href = pLocation;
		}
	}
	
	window.close();

}

// ***************************************************************************** //
// OPEN A PDF In A POPUP WINDOW
// pLoc = page location
// Assumes form PDFLauncher exists in page (required to get dynamically
// generated PDFs to display.
// ***************************************************************************** //
function openPDFWindow(pLoc){

	newWindow = PMG_newWindow({loc:pLoc,name:'printpdf',nochrome:true,w:800,h:600});
	
	document.PDFLauncher.target = "printpdf";
	document.PDFLauncher.action = pLoc;
	document.PDFLauncher.submit();
	
}

/*********************************************/
/*            WRITE FLASH OBJECT             */
/*********************************************/

function writeFlash_mp(pFlashVars){

	ws = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="660" height="140" id="tabs7" align="middle" VIEWASTEXT>';
	ws += '<param name=movie value="media/flash/tabs_mp.swf">';
	ws += '<param name="allowScriptAccess" value="sameDomain">';
	ws += '<param name=quality value=high>';
	ws += '<param name="wmode" value="transparent">';
	ws += '<param name="menu" value="false">';
	ws += '<param name=FlashVars value="' + pFlashVars + '">';
	ws += '<embed src="media/flash/tabs_mp.swf" FlashVars="' + pFlashVars + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="660" height="140" name="tabs7" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	ws += '</object>'

	document.write(ws);
}
