/*********************************************/
/*              PMG FUNCTIONS                */
/*********************************************/

// ******************************************** //
// WRITE A BODY CONTENT LINK   
// p = {};
// p.arrow = boolean will add the orange arrow
// p.id = passed to doBodyContentClick();
// p.write = boolean write or return string
// can redirect or call openNewWindow();
// ******************************************** //
function PMG_writeLink(p){

	if(typeof(p) != "object"){
		p = {text:"Text not passed to writeBodyLink()"}
	}
	
	if(!p.id){p.id = ""}
	if(!p.clas){p.clas = "bodyLinks"}
	if(!p.script){p.script = "PMG_clickLink"}
	if(!p.style){p.style = ""}

	var ws = '';
	ws += '<a style="' + p.style + '" class="' + p.clas + '" ';
	ws += 'href="javascript:void(0);" ';
	ws += 'onfocus="this.blur();" ';
	ws += 'onclick="' + p.script + '(\'' + p.id + '\');return false;" ';
	ws += '>' + p.text + '</a>';
	
	if(p.p_write){
		document.write(ws);
	}else{
		return ws;
	}
	
	return true;
}

// ***************************************************************************** //
// PMG_img() Writes or returns an <img>
// p = {}
// p.graphic = the graphic name
// p.extension = jpg, png, gif
// p.path = allows for a custom path
// p.w = integer width
// p.h = integer height
// p.id = unique id default is ""
// p.cname = unique class default is ""
// p.title = the title tag default is ""
// p.alt = the alt tag default is ""
// p.write = boolean will write or return value
// ***************************************************************************** //

function PMG_img(p){

	var ws = ''
	var lExt = p.ext || "jpg";
	var lPath = p.path || gPaths.images;
	var lGraphic = (typeof(p.graphic) == "object")? p.graphic[Math.round(Math.random()*(p.graphic.length-1))] : p.graphic;
	var lImage = lPath + lGraphic + '.' + lExt;
	
	// Check for special styles //
	var lID = (p.id)? 'id="' + p.id + '"' : '';
	var lClass = (p.cname)? 'class="' + p.cname + '"' : '';
	var lStyle = (p.style)? 'style="' + p.style + '"' : '';
	var lAlt = (p.alt)? 'alt="' + p.alt + '"' : '';
	var lTitle = (p.title)? 'title="' + p.title + '"' : '';
	
	if((lExt == "png") && (gBrowser.vendor == "IE") && !gBrowser.support_png){
			ws = '<div ' + lID + lClass + ' style="width:' + p.w + 'px; height:' + p.h + 'px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + lImage + '\', sizingMethod=\'image\');"></div>';
	}else{
		var lSize = (p.w)? 'width="' + p.w + '" height= "' + p.h + '"': '';		
		ws = '<img ' + lID + lClass + lTitle + lStyle + ' src="' + lImage + '" ' + lSize + ' vspace="0" hspace="0"  border="0" ' + lAlt + ' />';
	}
	
	if(p.p_write){
		document.write(ws);
	}else{
		return ws;
	}
	
	return false;
}

function PMG_background(p){

	var ws = ''
	var lType = p.ext || "jpg";
	var lPath = p.path || gPaths.images;
	var lImage = lPath + p.graphic + '.' + lType
	var lScale = p.scale || "image";
	//var lProps = p.props || "";

	if((lType == "png") && (gBrowser.vendor == "IE") && !gBrowser.support_png){
		ws += 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + lImage + '\', sizingMethod=\'' + lScale + '\')'
	} else {
		ws += 'background-image: url(\'' + lImage  + '\');';
	}

	return ws;
}

// ********************************* //
//        WRITE BOX			         //
// ********************************* //
function writeTableBox(obj){

	var ws = "";
	var lType = obj.type || "";
	var lName = obj.name || "table_box";
	if(obj.top){
		ws += '<table class="' + lName + lType + '" width="100%" cellpadding="0" cellspacing="0" border="0">';
		ws += '<tr><td class="' + lName + '_top_left' + lType + '"></td><td class="' + lName + '_top' + lType + '"></td><td class="' + lName + '_top_right' + lType + '"></td></tr>';
		ws += '<tr><td class="' + lName + '_left' + lType + '"></td><td class="' + lName + '_back' + lType + '">'
	}else{
		ws += '</td><td class="' + lName + '_right' + lType + '"></td></tr>';
		ws += '<tr><td class="' + lName + '_bottom_left' + lType + '"></td><td class="' + lName + '_bottom' + lType + '"></td><td class="' + lName + '_bottom_right' + lType + '"></td></tr>';
		ws += '</table>';
	}

	if(obj.write){
		document.write(ws);
	}else{
		return ws;
	}
	
	return true;
	
}

function createRoundedBox(p){
	
	// find content to round //
	if(!p || !p.divs){
		alert("Divs not passed to createRoundedBox()\nCalled from " + location.href);
		return false;
	}
	
	if(!p.divs.length){
		alert("Array required for createRoundedBox()\nCalled from " + location.href);
		return false;
	}
	
	for(var x = 0; x<p.divs.length; x++){
		var lID = p.divs[x].id;
		// blue is default //
		var lClass = p.divs[x].className || "blue";
		if(!lID){
			alert("ID is required for createRoundedBox()\nCalled from " + location.href);
			return false;
		}
		// find the div //
		var lDiv = document.getElementById(lID);
		// make sure the div exists //
		if(lDiv){
		
			var lPath = gPaths.images + "boxes/";
			var ws = "";
			ws += '<table id="table_' + lID + '" class="table_round_' + lClass + '" cellpadding="0" cellspacing="0" border="0">';
			var lStyle = PMG_background({ext:"png",graphic:"boxes/top_left"});
			ws += '<tr><td class="top_left_' + lClass + '" style="width:10px; height:10px; ' + lStyle + '" ></td><td class="top_' + lClass + '"></td>';
			var lStyle = PMG_background({ext:"png",graphic:"boxes/top_right"});
			ws += '<td class="top_right_' + lClass + '" style="width:10px; height:10px; ' + lStyle + '"></td></tr>';
			ws += '<tr><td class="left_' + lClass + '"></td><td id="content_' + lID + '" class="content_' + lClass + '">';
			ws += lDiv.innerHTML;
			ws += '</td><td class="right_' + lClass + '"></td></tr>';
			var lStyle = PMG_background({ext:"png",graphic:"boxes/bottom_left"});
			ws += '<tr><td class="bottom_left_' + lClass + '" style="width:10px; height:10px; ' + lStyle + '"></td><td class="bottom_' + lClass + '"></td>';
			var lStyle = PMG_background({ext:"png",graphic:"boxes/bottom_right"});
			ws += '<td class="bottom_right_' + lClass + '" style="width:10px; height:10px; ' + lStyle + '"></td></tr>';
			ws += '</table>';
		
			lDiv.innerHTML = ws;
		}
	}	
}

function createBox(ctl){
	var lDiv = document.getElementById(ctl);
	
	if(!lDiv){
		alert(ctl + " not found in createRoundedBox()");
		return;
	}else{
		var lBoxTop = "";
		var lBoxBottom = "";
		lBoxTop = writeTableBox({name:"grey",top:true});
		lBoxBottom = writeTableBox({name:"grey",top:false});
		lDiv.innerHTML = lBoxTop + lDiv.innerHTML + lBoxBottom;
	}
}

// ******************************************** //
//              TEXT SIZE FUNCTIONS   
// ******************************************** //
var gFontSize = {};
gFontSize.initialized = false;
function initFontSizeButtons(p){
	
	this.obj = p;
	this.obj.pImage_off = p.src;
	this.obj.pImage = p.src.split("_off.gif")[0] + ".gif";
	this.p_off_size = (p.id.indexOf("plus") != -1)? gProps.textSize.maximum : gProps.textSize.minimum;
	
	this.obj.onclick = function(){
		PMG_textSize(this);
	}
	
	this.enableMe = function(){
		if(this.obj){
			this.pEnabled = true;
			this.obj.src = this.obj.pImage;
			this.obj.style.cursor = "pointer";
		}
	}
	
	this.disableMe = function(){
		if(this.obj){
			this.pEnabled = false;
			this.obj.src = this.obj.pImage_off;
			this.obj.style.cursor = "default";
		}
	}

	this.checkSize = function(pSize){
		if(pSize == this.p_off_size){
			this.disableMe();
		}else{
			this.enableMe();
		}
	}

	//p.style.cursor = "pointer";
	//p.src = p.Image_off;
}

function PMG_textSize(p){
	if(!p){p = {}}
	
	if(!gFontSize.initialized){
		gFontSize.initialized = true;
		var lContainer = document.getElementById("text_size_links");
		if(lContainer){
			var lButtons = lContainer.getElementsByTagName("img");
			if(lButtons.length){
				for(var x = 0; x<lButtons.length; x++){
					if(lButtons[x].id){
						gFontSize[lButtons[x].id] = new initFontSizeButtons(lButtons[x]);
					}
				}
			}
		}else{
			// Text buttons not found abort //
			return;
		}
	}

	if(typeof(p) == "object"){
		if(p.id){
			p.direction = p.id.split("_").pop();
		}else{
			p.direction = null;
		}
	}	

	//gCookie.props.name = "text_size";	
	var lSize = gProps.cookie.text_size;//cookieJar_read(gCookie.props);
	
	// initialize the font size //
	if(!lSize){lSize = gProps.textSize.initial_size;}
	
	// called in the onload function to check font size //
	switch(p.direction){
		case "plus":
			lSize = parseInt(lSize) + gProps.textSize.increment;
			break;
		case "minus":
			lSize = parseInt(lSize) - gProps.textSize.increment;
			break;
	}
	
	// Check Max & Min of the text size prop //
	lSize = (lSize > gProps.textSize.maximum)? gProps.textSize.maximum : lSize;
	lSize = (lSize < gProps.textSize.minimum)? gProps.textSize.minimum : lSize;
	// Store current size in the cookie /
	gCookie.props.value = lSize;
	gCookie.props.name = "text_size";
	gProps.cookie.text_size = lSize;
	cookieJar_write(gCookie.props)
	
	gFontSize.text_minus.checkSize(lSize);
	gFontSize.text_plus.checkSize(lSize);

	// Find the current div to set the font size //
	var lContainer = (gProps.textSize.container)? document.getElementById(gProps.textSize.container) : document.getElementById("content_container");
	
	var lTags = null;
	var lDiv = null;
	
	// set the current font size //
	if(lContainer){
		lContainer.style.fontSize = lSize + "%";
		var lShow = true;
		// this allows special pages to control their own visibility meal planner & activity planner//
		for(var x in gProps.textSize.visibility){
			if(gProps.textSize.visibility[x] == gProps.page){
				lShow = false;
				break;
			}
		}
		if(lShow){
			//lContainer.style.visibility = "visible";
		}
	}else{
		//alert("lContainer not defined in PMG_textSize()");	
	}
	
	// show the current font size in the tracer debug //
	if(gDebug.tools && gProps.textSize.enabled){
		gDebug.tracer(lSize,true);
	}
}

function disableIE6Please(){
	var lSite = document.getElementById("site_container")

	if(lSite){
		var lDiv = document.createElement("div");
		lDiv.id = "disableIE6";
		
		var lBrowsers = '<img src="/media/images/icons/browsers.gif" alt="" />'
		
		var lMessage = '<table>';
		lMessage += '<tr><td valign="top" width="25%">';
		lMessage += '<p class="boldText" style="font-size:125%;color:red;">Your Web Browser<br />is no longer supported.</p>';
		lMessage += '</td>';
		lMessage += '<td valign="top">';
		lMessage += 'To experience everything that MerckEngage.com has to offer, we recommend that you upgrade to a newer version of your web browser.';
		lMessage += '</td>';
		lMessage += '<td>';
		lMessage += '</td>';
		lMessage += '</tr>';
		lMessage += '</table>';

		if(gProps.IE.browser_message){
			lMessage = lBrowsers;
		}

		lDiv.innerHTML = lMessage;
		lSite.insertBefore(lDiv,lSite.childNodes[0]);
	}
	
}

function PMG_print(){
	window.print();
}

function showPrintArticleButton(){
	if(gProps.print.enabled){
		var lPrint = document.getElementById("global_print_article");
		//lPrint.style.display = 'inline';
	}
}


function swapShow(obj){
	if(typeof(obj)!="object"){return};
	var lDiv = document.getElementById(obj.div);
	if(lDiv){
		lDiv.style.display = (lDiv.style.display == "block")? "none" : "block";
	}
}


/*********************************************/
/*            OPEN A POPUP ALERT             */
/*********************************************/
var popup_tooltip = false;
var popup_tooltipShadow = false;
var popup_shadowSize = 4;
var popup_tooltipMaxWidth = 250;
var popup_tooltipMinWidth = 100;
var popup_iframe = false;
var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;

function showPopup(e, strMessage)
{
	var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	if(!popup_tooltip){
		popup_tooltip = document.createElement('DIV');
		popup_tooltip.id = 'popup_tooltip';
		popup_tooltipShadow = document.createElement('DIV');
		popup_tooltipShadow.id = 'popup_tooltipShadow';
		
		document.body.appendChild(popup_tooltip);
		document.body.appendChild(popup_tooltipShadow);	
		
		
		if(tooltip_is_msie){
			popup_iframe = document.createElement('IFRAME');
			popup_iframe.frameborder='5';
			popup_iframe.style.backgroundColor='white';
			popup_iframe.src = '#';
			popup_iframe.style.zIndex = 100;
			popup_iframe.style.position = 'absolute';
			document.body.appendChild(popup_iframe);
		}
	}

	// SSK added 4.28.08 fix offset issue //
	popup_tooltip.style.visibility = 'hidden';
	popup_tooltipShadow.style.visibility = 'hidden';
	if(tooltip_is_msie)popup_iframe.style.visibility = 'hidden';

	popup_tooltip.style.display='block';
	popup_tooltipShadow.style.display='block';
	if(tooltip_is_msie)popup_iframe.style.display='block';

	
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0) st=0; 
	//var leftPos = e.clientX + e.srcElement.offsetLeft;
	var lElement = (e.srcElement)? e.srcElement : e.target;
	//lElement.style.background = "lime";
	var lCoords = PMG_getCoords(lElement);
	//gDebug.getVar(lElement)
	var leftPos = e.clientX + lElement.offsetLeft;

	//gDebug.getVar(e)
	popup_tooltip.style.width = null;	// Reset style width if it's set 
	var htmlcontext = strMessage;
	htmlcontext+='<div align="right"><a href="JavaScript:hidePopupToolTip()">close</a></div>';
	popup_tooltip.innerHTML = htmlcontext;

	popup_tooltip.style.left = leftPos + 'px';
	//popup_tooltip.style.top = e.clientY + 6 + st + 'px';
	popup_tooltip.style.top = lCoords.bottom + 3 + 'px';

	if(popup_tooltip.offsetWidth > popup_tooltipMaxWidth){
		popup_tooltip.style.width = popup_tooltipMaxWidth + 'px';
	}

	var tooltipWidth = popup_tooltip.offsetWidth;		
	if(tooltipWidth<popup_tooltipMinWidth){
		tooltipWidth = popup_tooltipMinWidth;
	}

	popup_tooltip.style.width = tooltipWidth + 'px';
	popup_tooltipShadow.style.width = popup_tooltip.offsetWidth + 'px';
	popup_tooltipShadow.style.height = popup_tooltip.offsetHeight + 'px';		

	if((leftPos + tooltipWidth)>bodyWidth){
		popup_tooltip.style.left = (popup_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
		popup_tooltipShadow.style.left = (popup_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + popup_shadowSize) + 'px';
	}

    // JAK added 10.17.08 to keep pop-ups inside browser window.
    var leftMargin = Math.max(leftPos - popup_tooltip.clientWidth,0);
    
	if(tooltip_is_msie){
		// SSK added 4.28.08 fix offset issue //
		//popup_iframe.style.left = popup_tooltip.style.left;
		popup_iframe.style.left = leftMargin + 'px';
		popup_iframe.style.top = popup_tooltip.style.top;
		popup_iframe.style.width = popup_tooltip.offsetWidth + 'px';
		popup_iframe.style.height = popup_tooltip.offsetHeight + 'px';
	}
	// SSK added 4.28.08 fix offset issue //
	popup_tooltip.style.left = leftMargin + 'px';
	popup_tooltipShadow.style.left =  (leftMargin + popup_shadowSize) + 'px';
	popup_tooltipShadow.style.top = parseInt(popup_tooltip.style.top) + popup_shadowSize + 'px';

	//gDebug.tracer(popup_tooltip.clientWidth)
	popup_tooltip.style.visibility = 'visible';
	popup_tooltipShadow.style.visibility = 'visible';
	if(tooltip_is_msie)popup_iframe.style.visibility = 'visible';

	// END showPopup() //
}

function hidePopupToolTip()
{
	popup_tooltip.style.display='none';
	popup_tooltipShadow.style.display='none';		
	if(tooltip_is_msie)popup_iframe.style.display='none';		
}

// Function toggles hide and show elements //
function hideShow(pArray){
	if(!pArray){
		pArray = {obj:[]};
	}
	
	if(pArray.obj.length){
		for(var x = 0; x<pArray.obj.length; x++){
			var lObj = document.getElementById(pArray.obj[x]);
			if(lObj){
				lObj.style.display = (lObj.style.display == "block")? "none" : "block";
				lObj.style.visibility = (lObj.style.display == "visible")? "hidden" : "visible";
			}else{
				alert(pArray.obj[x] + " not found in " + location.href);
			}
		}
	
	}else{
		alert("pArray is not defined in hideShow() called from\n" + location.href);
	}
}

// ***************************************************************************** //
// OPEN A POPUP WINDOW = Default is 800x600 with chrome = "status" only
// pWin = {}
// pWin.name = "window name"
// pWin.w = integer window width
// pWin.h = integer window height
// pWin.chrome = {} contains all chrome settings ({toolbar:'yes',status:'yes'})
// pWin.center = boolean set to false to respect left and top window properties :)
// ***************************************************************************** //
var gWindow_pmg = false;
function PMG_newWindow(pWin){

	// focus the existing window if one is open //
	// need to check because IE bugs exist - make sure available //
	if(!gBrowser.ie6 && typeof(gWindow_pmg) == "object"){
		if(typeof(gWindow_pmg.closed) != "undefined"){
			if(!gWindow_pmg.closed){
				gWindow_pmg.focus();
			}
		}
	}
	
	// TEMP Hotfix for external link //
	if(pWin.loc == "http://www.mercksource.com/pp/us/cns/cns_hl_dorlands_split.jsp?pg=/ppdocs/us/common/dorlands/dorland/misc/dmd-a-b-000.htm"){
		pWin.loc = "http://www.nlm.nih.gov/medlineplus/mplusdictionary.html";
	}
	
	var pChrome = {};
	pChrome.fullscreen = "no";
	pChrome.titlebar = (pWin.nochrome)? "no" : "yes";
	pChrome.toolbar = (pWin.nochrome)? "no" : "yes";
	pChrome.location = (pWin.nochrome)? "no" : "yes";
	pChrome.directories = (pWin.nochrome)? "no" : "yes";
	pChrome.status = "yes";
	pChrome.menubar = (pWin.nochrome)? "no" : "yes";
	pChrome.scrollbars = (pWin.nochrome && !pWin.scrollbars)? "no" : "yes";
	pChrome.resizable = (pWin.nochrome)? (pWin.resize)? "yes" :"no" : "yes";
	
	pChrome.width = (pWin.w)? pWin.w : 800; // Default width for all popups //
	pChrome.height = (pWin.h)? pWin.h : 600; // Default height for all popups //
	pChrome.innerHeight = pChrome.height; // used with firefox //
	pChrome.top = "0";
	pChrome.left = "0";
 
 	// if the name is not defined then use the default name for all windows //
 	if(typeof(pWin.name) == "undefined"){
		pWin.name = (gBrowser.ie6)? PMG_TimeStamp() : "pWindow";
	}
	//alert(pWin.name)
	
	// Always center window 
	if(typeof(pWin.center) == "undefined"){
		pWin.center = true;
	}
	// loop and change properties //
	if(pWin.chrome){
		for(prop in pWin.chrome){
			pChrome[prop] = pWin.chrome[prop];
		}
	}

	// This will center the window on the screen //
	// center is enabled by default //
	if (pWin.center != false) {
		var lMinus = 40;
		var lPlus = 10;
		// fix for 800x600 center window //
		if(screen.height < 700){
			lMinus = 0;
			lPlus = 20;
		}

		var ah = screen.availHeight - lMinus;
		var aw = screen.availWidth - 10;
		
		//alert("ah = " + ah + "\npWin.preferedV = " + pWin.preferedV);
		if(pWin.preferedV){
			//alert(pWin.preferedV);
			if(ah > pWin.preferedV){
				//alert("ah = " + ah + "\npWin.preferedV = " + pWin.preferedV);
				pChrome.innerHeight = pWin.preferedV;
				pChrome.height = pWin.preferedV;
				pChrome.scrollbars = "no";
			}
		}

		var x = (aw - pChrome.width) / 2;
		var y = (ah - (pChrome.innerHeight + lPlus)) / 2;
		pChrome.left = x;
		pChrome.top = y;

	}
	// setup the window chrome //
	var lNewChrome = ""
	for(prop in pChrome){
		lNewChrome += prop + '=' + pChrome[prop] + ",";
	}

	// open window and set reference //
	//prompt("",lNewChrome)
	//gWindow_pmg = new window.open(pWin.loc,pWin.name,lNewChrome);
	gWindow_pmg = new returnWindow(pWin.loc,pWin.name,lNewChrome);
	//alert(gWindow_pmg)
}

function returnWindow(loc,name,chrome){
	return window.open(loc,name,chrome)
}

function PMG_TimeStamp(){
		var p_date = new Date();
		var p_time = new String(p_date.getTime());
		var p_sub = p_time.substr((p_time.length-4),p_time.length-1);
		return p_sub;
}

function PMG_getDate(){
		var d = new Date();
		var lDay = new String(d.getDate());
		var lMonth = new String(d.getMonth()+1);
		var lYear = d.getFullYear();
		
		if(lMonth.length==1){
			lMonth = ("0" + lMonth);
		}

		if(lDay.length==1){
			lDay = ("0" + lDay);
		}
		
		var lDate = lMonth + "/" + lDay + "/" + lYear;
		//var lDate = p_date.format("m/d/yy");
		return lDate;
}

// ******************************************** //
// 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 PMG_closeWindow(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();
}

/*********************************************/
/*            WRITE FLASH OBJECT             */
/*********************************************/
function writeFlash(p){

	if(!p.vars){p.vars = ""};
	if(!p.id){p.id = "flash_id"};
	if(!p.movie){alert("No swf passed to writeFlash()")};

	var ws = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + p.width + '" height="' + p.height +'" id="' + p.id + '">';
	ws += '<param name=movie value="' + gPaths.flash + p.movie + '">';
	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="' + p.vars + '">';
	ws += '<embed src="' + gPaths.flash + p.movie + '" FlashVars="' + p.vars + '" quality="high" wmode="transparent" width="' + p.width + '" height="' + p.height + '" name="' + p.id + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	ws += '</object>'

	if(p.inline){
		return ws;
	}else{
		document.write(ws);
	}
	
	return true;
}

// SSK is called everywhere flash is written //
// This is not used for the HCC video //
function checkFlashValid(p){
	if(gProps.flash.available){
		p.obj.write(p.div);
	}else{
		var lDiv = document.getElementById(p.div);
		if(lDiv){
			
			var obj = ""//{loc:gProps.flash.getLink};
			var w = '<div id="' + p.div + '_no_flash" class="no_flash_containers">';
			w += '<p id="no_flash_message">' + gProps.flash.message + '</p>';
			w += '<a href="javascript:void(0);" onclick="PMG_newWindow({loc:gProps.flash.getLink}); return false;">';
			w += PMG_img({path:gPaths.images + "icons/",graphic:gProps.flash.image,style:"border:none;"})
			w += '</a>';
			w += '</div>';
			lDiv.innerHTML = w;
		}
	}

	
}

// This function is called from the av_player.swf for mp3 files //
function selectAudio(p){
	var lFlash = document.getElementById("flash_mp3_id");
	if(lFlash){
		lFlash.loadAudioFile(gPaths.audio + p.file + ".mp3");
	}else{
		var lText = document.getElementById("no_flash_message");
		if(lText){
			alert(lText.innerHTML);
		}
	}
}

function stopFlashAudio(p){
	alert("stopFlashAudio is depricated. Please use closeAV_Panel() \n" + location.href);
	if(gBrowser.vendor == "IE"){
		var lObj = p || "flash_mp3_id";
		var lFlash = document.getElementById(lObj);
		lFlash.comFlash();
	}	
}

function writePlusBox(p){

	if(typeof(p) != "object"){
		p = {text:"Title not passed to writePlusBox()"}
	}
	
	var s = '';

	s += '<table cellpadding="0" cellspacing="0" border="0">';
	s += '<tr>';
	s += '<td class="plus_sign">+</td>';
	s += '<td>' + p.text + '</td>';
	s += '</tr>';
	s += '</table>';
	
	if(p.inline){
		return s;
	}else{
		document.write(s);
	}
	return true;
}

function initBullets(p){

	if(!p){
		p = {div:"content"}
	}
	
	var lContainer = document.getElementById(p.div);
	if(lContainer){
		var lDivs = lContainer.getElementsByTagName("div");
		if(lDivs.length){
			
			
			for(var x = 0; x<lDivs.length; x++){
				var lText = "";
				var lName = lDivs[x].className;
				var lNumber = 0;
				var lUseNumbers = (lDivs[x].id.indexOf("number_bullets") != -1)? true : false;
				if(lName.indexOf("bullets_wrapper") != -1){
					var lTextStyle = "bullet_text_td";
					for(var i = 0; i<lDivs[x].childNodes.length; i++){
						lText += '<table class="bullets_table" cellpadding="0" cellspacing="0" border="0">';
						var lTag = lDivs[x].childNodes[i].nodeName.toLowerCase();
						if(lTag != "#text"){
							if(lTag == "span"){
								switch(lDivs[x].childNodes[i].className){
									case "indent_1":
										var lStyle = "bullet_img_td_1";
										var lBullet = PMG_img({ext:"gif",graphic:"icons/bullet_indent_1",cname:"bullets"});
										break;
									default:
										var lStyle = "bullet_img_td";
										var lBullet = PMG_img({ext:"gif",graphic:"icons/bullet",cname:"bullets"});
										break;
								}
								
								if(lUseNumbers){
									lBullet = ++lNumber + ".";
								}
								
								if(i == (lDivs[x].childNodes.length-2)){
									lTextStyle = "bullet_text_td_last";
								}
								
								lText += '<tr><td class="' + lStyle + '">' + lBullet + '</td><td class="' + lTextStyle + '">' + lDivs[x].childNodes[i].innerHTML + '</td></tr>'
							}
						}
						// add space padding to bottom //
						if(i == (lDivs[x].childNodes.length-1)){
							//lText += '<tr><td class="bullet_img_td_padding">&nbsp;</td><td class="bullet_img_td_padding">&nbsp;</td></tr>'
						}
						
						lText += '</table>';
					}
					lDivs[x].innerHTML = lText;
				}
			}	
			
		}
	
	}
	
	
	var lPanel = document.getElementById("main_content");
	if(lPanel){
		//lPanel.style.visibility = "visible";
	}
}

function insertArticleWrapper(){
	
	var lCreate = null;
	var lGraphic = null;
	var lCallout = null;

	// this is the article default image 271.jpg //
	if(gProps.article.image == true){
		gProps.article.image = gProps.qs.ID + ".jpg";
	}

	if(gProps.article.image != null){
		var pImage = gProps.article.image.split(".")
		lGraphic = PMG_img({ext:pImage[1],graphic:"articles/" + pImage[0],cname:"article_image"});
	}
	
	//alert(gProps.article.callout)
	if(gProps.article.callout){
		var lDiv = document.getElementById(gProps.article.callout + "_callout");
		if(lDiv){
			lCallout = '<div class="article_callout"><div class="article_callout_content">' + lDiv.innerHTML +'</div></div>';
			// delete the original div //
			lDiv.parentNode.removeChild(lDiv);
		}
	}

	if (gProps.article.bottom) {
		var div_bottom = document.getElementById(gProps.article.bottom + "_bottom");
		if(div_bottom){
			div_bottom.style.display = 'block';
		}
	}	
	
	if(lGraphic || lCallout){
		var lHTML = ""
		if(lGraphic){
			lHTML = lGraphic;
		}
		
		if(lCallout){
			lHTML += lCallout;
		}
		
		lCreate = document.createElement("div");
		lCreate.className = "article_callout_wrapper";
		
		lCreate.innerHTML = lHTML;
		
		var lContainer = document.getElementById("column_middle_content_div");
		var lP = lContainer.getElementsByTagName("p");
		lContainer.insertBefore(lCreate,lP[0]);
		
		// find the breadcrumbs //
		if(gProps.section != "green"){
			var lCrumb = document.getElementById("breadcrumb_div");
			if(!lCrumb){ lCrumb = document.getElementById("breadcrumb_container");}
			var lA = null;
			if(lCrumb){
				
				var lCrumbs = lCrumb.getElementsByTagName("a");
				if(lCrumbs){
					lA = lCrumbs[lCrumbs.length-1];
				}
				
				if(lA){
					var lHeader = document.createElement("p");
					lHeader.className = (gProps.article.titles[lA.innerHTML.toLowerCase()])? "article_sub_top_header_nocap" : "article_sub_top_header";
					lHeader.innerHTML = (gProps.article.titles[lA.innerHTML.toLowerCase()])? gProps.article.titles[lA.innerHTML.toLowerCase()] : lA.innerHTML;
					lContainer.insertBefore(lHeader,lContainer.childNodes[0]);
				}
			}
		}
		
		//lContainer.insertBefore(lCreate,lCreate.childNodes[2]);
	}
	initBullets();
}


function initBulletImages(obj){

	alert("initBulletImages() is deprecated.\nShould use initBullets()\n\n Called in " + location.href)

	obj.div = obj.div || "content";
	if(!obj.bullet){
		obj.bullet = {graphic:"bullet"}
	}
	
	var lContainer = document.getElementById(obj.div);
	var lTags = null;
	var lBullets = [];
	
	if(lContainer){
		lTags = lContainer.getElementsByTagName("div");
	}

	if(lTags){
		for(var x = 0; x<lTags.length; x++){
			if(lTags[x].className.indexOf("ol_div|") != -1){
				lBullets.push(lTags[x])
			}
		}	
	}
	
	if(lBullets.length){
		for(var x = 0; x<lBullets.length; x++){
			var lName = lBullets[x].className.split("|");
			var w = '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
			var lBullet = (obj.bullet.number)? ((typeof(lName[2]) == "undefined")? (x+1) + "." : lName[2]) : PMG_img(obj.bullet); 
			
			/*
			var lBullet = PMG_img(obj.bullet);
			if(obj.bullet.number){
				lBullet = (typeof(lName[2]) == "undefined")? (x+1) + "." : lName[2];
				//lBullet = (typeof(lName[2]) != "undefined")? lName[2] : (x+1) + ".");
			}
			*/
			w += '<tr><td class="' + lName[1] + '_td_img" valign="top"><div class="' + lName[1] + '_div_img">' + lBullet + '</div></td>';
			w += '<td class="li_text_td"><div class="li_text_div">' + lBullets[x].innerHTML + '</div></td></tr></table>';
			lBullets[x].innerHTML = w;
			//alert(lBullets[x].id)
			lBullets[x].className = lName[1] + "_div"
		}
	}
	
	/*
	var lBullet = '<img class="li_1_img" src="' + gPaths.images + 'bullet.jpg" width="8" height="8" border="0" />';
	var lTags = document.getElementById(p).getElementsByTagName("div");
	
	for(var x = 1; x<lTags.length; x++){
		if(lTags[x].className == "li_1_div"){
			lTags[x].innerHTML = lBullet;
		}
	}
	
	*/
}

/***************************************/
/*            HTTP REQUEST             */
/***************************************/
function PMG_request(p){
	var AJAX = {};
	var url = p.file;
	var target = document.getElementById(p.target);
	
	if(!target){target = "PASS"}
	
	if(target){
		target.innerHTML = 'Loading...';
		if(window.XMLHttpRequest){
			AJAX.request = new XMLHttpRequest();
		}else{
			if(window.ActiveXObject){
				AJAX.request = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		if(typeof(AJAX.request) != "undefined"){
			AJAX.request.onreadystatechange = function(){PMG_requestDone(url, target, AJAX.request);};
			AJAX.request.open("GET", url, true);
			AJAX.request.send("");
		}
	}
}  

function PMG_requestDone(url, target, request){
	var lText = null;
	if(request.readyState == 4){ // only if p_x is "loaded"
		if(request.status == 200){ // only if "OK"
			//document.getElementById(target).innerHTML = p_x.responseText;
			//target.innerHTML = p_x.responseText;
			lText = request.responseText;
		}else{
			//document.getElementById(target).innerHTML=" dynamicUpdates() Error:\n" + p_x.status + "\n" + p_x.statusText;
			//target.innerHTML = " PMG_request() Error:\n" + p_x.status + "\n" + p_x.statusText;
			lText = "PMG_requestDone() Error:\n" + request.status + "\n" + request.statusText;
		}
	}
	
	if(lText){
		if(target == "PASS"){
			return lText;
		}else{
			target.innerHTML = lText;
		}
	}
	
	return false;
}

/***************************************/
/*        GLOBAL TAB NAVIGATION        */
/***************************************/
var gTabs = {};
function initGlobalTabs(p){
	gTabs = p;
	switch(p.subsection){
		case "blue":
			switch(p.hilite){
				case "tab_2":
					gProps.article.callout = "activity";
					break;
				
			}
			break;
		case "green":
				gProps.article.image = null;
				gTabs.hidelinks = true;
				// hides the sub links in the condition library //
				if(location.href.indexOf("for_your_office") != -1){
					gTabs.hidelinks = false;
				}
				
			break;
	}
	// IE 6 needs this @#$%!! //
	// can not manipulate the document before </body> tag is drawn //
	//add_onload("loadGlobalTabs")
	
}

function loadGlobalTabs(){
	var p = gTabs;
	gTabs  = {};

	var lContainer = document.getElementById("global_tab_div");
	gProps.section = p.subsection;
	var lTags = null;
	if(lContainer){
		lTags = lContainer.getElementsByTagName("a");
	}

	if(lTags){
		for(var x = 0; x<lTags.length; x++){
			lTags[x].p_props = p;
			gTabs[lTags[x].id] = new globalTabButton(lTags[x]);
		}	
	}

	// assign the sub tab navigation //
	if(p){

		// SSK temp code //
		var lSubTabs = document.getElementById(p.subsection + "_sub_tab_container");
		if(lSubTabs){
			var lTags = null;
			lTags = lSubTabs.getElementsByTagName("a");
			if(lTags){
				for(var x = 0; x<lTags.length; x++){
					lTags[x].p_props = p;
					//lTags[x].p_props.create_pipe = (x < lTags.length-1)? true : false;
					gTabs[lTags[x].id] = new globalTabButton(lTags[x]);
					lTags[x].style.visibility = (p.hidelinks)? "hidden" : "visible";
					// add the pipe divider //
					if(!p.hidelinks){
						if(x > 0){
							var lSpan = document.createElement("span");
							lSpan.className = "sub_tab_pipe";
							lSubTabs.insertBefore(lSpan,lTags[x]);
						}
					}
				}	
			}

			lSubTabs.style.display = "block";
		
			var lCG = document.getElementById("NAV_CG_Link");
			if(lCG){
				var lLink = lCG.cloneNode(true);
				lSubTabs.appendChild(lLink);
				lLink.style.display = "block";
				lCG.parentNode.removeChild(lCG);
			}
		
		}

	}
	
}


function globalTabButton(obj){

	obj.p_subnav = (obj.parentNode.parentNode.id.indexOf("sub_tab") != -1)? true : false;
	obj.p_enabled = ((location.href.indexOf("/hcp/") != -1) || gBrowser.ie6)? false : true;

	// These are the sub navigation links //
	if(obj.p_subnav){
		obj.p_selected = (obj.id.indexOf(obj.p_props.hilite) != -1)? true : false;
		obj.p_class_hi = "global_tabs_link_hi";
		obj.p_class_lo = "global_tabs_link_lo";
		// check if the current subtab should be hilited //
		//if(obj.p_selected){obj.className = obj.p_class_hi}
		obj.onmouseover = function(){
			if(!this.p_selected){
				//this.className = this.p_class_hi;
			}
		}
	
		obj.onmouseout = function(){
			if(!this.p_selected){
				//this.className = this.p_class_lo;
			}
		}
		
		obj.onmousedown = function(){
			if(!this.p_selected){
				this.p_selected = true;
				//this.className = this.p_class_hi;
			}
		}
	}else{
		if(obj.p_enabled){
			// These are the main circus color image links //
			obj.p_image = obj.childNodes[0];
			obj.p_src = obj.p_image.src.split("/").pop().split(".")[0];
			obj.p_name = obj.p_src.split("_")[0];
			obj.p_open = false;
			obj.p_container = document.getElementById("global_tab_div");
			obj.p_selects = [];
			
			var lDropdown = document.getElementById(obj.p_name + "_dropdown");
			if(lDropdown){
				obj.p_dropdown = lDropdown.cloneNode(true);
				obj.p_dropdown.p_id = obj.id;
				var lDiv = document.createElement("div");
				//lDiv.style.width = obj.
				lDiv.style.width = (obj.offsetWidth-4) + "px";
				lDiv.style.height = "4px";
				lDiv.style.fontSize = 0;
				lDiv.style.background = "#ffffff";
				lDiv.style.position = "absolute";
				lDiv.style.top = "-4px";
				lDiv.style.left = obj.offsetLeft + "px";
				obj.p_dropdown.p_cover = lDiv;
				obj.p_dropdown.appendChild(obj.p_dropdown.p_cover);
				//obj.p_dropdown.innerHTML += obj.p_name + " = " + obj.p_src + " = " + obj.p_dropdown;
				lDropdown.parentNode.removeChild(lDropdown);
	
				if(gBrowser.ie6){
					obj.p_selects = document.getElementsByTagName('select');
				}
				
			}
			
			if(obj.p_name.indexOf("home") == -1){
				obj.p_selected = (obj.p_src.indexOf("_hi") != -1)? true : false;
				obj.p_image_lo = new Image();
				obj.p_image_lo.src = gPaths.images + "header/" + obj.p_name + "_lo.gif";
				obj.p_image_hi = new Image();
				obj.p_image_hi.src = gPaths.images + "header/" + obj.p_name + "_hi.gif";
			
				//gDebug.getVar(obj.p_image_lo)
				// do not initialize for HCP site //
				if(obj.p_enabled){
					obj.onmouseover = function(){
						gTabs[this.id].stopTimer();
						if(!this.p_selected){
							this.p_image.src = this.p_image_hi.src;
						}
						
						if(this.p_dropdown){
							if(!this.p_coords){
								document.body.appendChild(this.p_dropdown);
							}
							this.p_coords = PMG_getCoords(obj.p_container);
	
							this.p_dropdown.onmouseover = function(){
								gTabs[this.p_id].stopTimer();
								gTabs[this.p_id].stopSelectsTimer();
							}
							
							this.p_dropdown.onmouseout = function(){
								gTabs[this.p_id].initTimer();
								gTabs[this.p_id].initSelectsTimer();
							}
							
							// IE 6 only //
							if(obj.p_selects.length){
								this.p_dropdown.onmousedown = function(){
									this.onmouseout = function(){};
								}
							}
	
							this.p_dropdown.style.visibility = "hidden";
							this.p_dropdown.style.display = "block";
							
							// More IE 6 crap #$%$!!! /
							this.hideSelects();
							
							// position the dropdown IE 8 in compatibility mode is weird? //
							lOffset = (gBrowser.documentMode == 7)? 1 : 0;
							this.p_dropdown.style.top = this.p_coords.bottom + "px";
							this.p_dropdown.style.left = this.p_coords.x - lOffset + "px";
							this.p_dropdown.style.visibility = "visible";
			
						}
						
						this.style.border = "none";
					}
			
	
					obj.onmouseout = function(){
						gTabs[this.id].initTimer();
						gTabs[this.id].initSelectsTimer();
					}
				}
			
			
			
				obj.showSelects = function(){
					// More IE 6 crap #$%$!!! /
					if(this.p_selects.length){
						var lShow = true;
						
						for(var i in gTabs){
							if(gTabs[i].p_dropdown){
								if(gTabs[i].p_dropdown.style.display == "block"){
									lShow = false;
								}
							}
						}
					
						if(lShow){
							for(var x = 0; x<this.p_selects.length; x++){
								this.p_selects[x].style.visibility = "visible";
							}
						}
					}
				}
				
				obj.hideSelects = function(){
					// More IE 6 crap #$%$!!! /
					if(this.p_selects.length){
						for(var x = 0; x<this.p_selects.length; x++){
							this.p_selects[x].style.visibility = "hidden";
						}
					}
				}
				
				obj.hideMe = function(){
					//this.stopTimer();
					if(!this.p_selected){
						this.p_image.src = this.p_image_lo.src;
						this.style.border = "none";
					}
		
					if(this.p_dropdown){
						this.p_dropdown.style.display = "none";
					}
					
				}
				
				
				
				obj.initTimer = function(){
					this.p_timer = window.setTimeout('gTabs["' + this.id + '"].hideMe();', 50);
				}
				
				obj.stopTimer = function(){
					window.clearTimeout(this.p_timer);
					this.p_timer = null;
				}
				
				obj.initSelectsTimer = function(){
					this.p_selects_timer = window.setTimeout('gTabs["' + this.id + '"].showSelects();', 150);
				}
				
				obj.stopSelectsTimer = function(){
					window.clearTimeout(this.p_selects_timer);
					this.p_selects_timer = null;
				}
			}
			
			
			/*
			obj.onmouseout = function(){
				if(!this.p_selected){
					this.p_image.src = this.p_image_lo.src;
					this.style.border = "none";
				}
	
				if(this.p_dropdown){
					this.p_dropdown.style.display = "none";
				}
	
			}
			*/
			return obj;
		}
	}	
}

/********************************/
/*            BOXES             */
/********************************/
function initBoxes(obj){
	alert("function initBoxes() is deprecated.\nIt should be removed from this page.\n\n" + unescape(location.href));
}

/********************************/
/*            ICONS             */
/********************************/
function initIcons(obj){
	alert("function initIcons() is deprecated.\nIt should be removed from this page.\n\n" + unescape(location.href));
}

/********************************/
/*            LINKS             */
/********************************/
function initLocalLinks(obj){
	alert("initLocalLinks() is depricated please remove it from \n" + location.href);
	var lContainer = document.getElementById(obj.div);
	var lTags = null;
	var lLinks = [];
	if(lContainer){
		lTags = lContainer.getElementsByTagName("a");
	}

	if(lTags){
		for(var x = 0; x<lTags.length; x++){
			if(lTags[x].className == "autoLinks"){
				/*
				lTags[x].onclick = function(){
					var lLink = this.childNodes[0].data.split(" ").join("_");
					location.href = lLink + ".aspx";
				}
				*/
				
				lTags[x].tabIndex = "0";
			}
		}	
	}
}


/********************************/
/*        FORM BUTTONS          */
/********************************/
function initFormButtons(obj){
	
	alert("function initFormButtons() is deprecated.\nIt should be removed from this page.\n\n" + unescape(location.href));
	
	var lContainer = document.getElementById(obj.div);
	var lTags = null;
	var lButtons = [];
	if(lContainer){
		lTags = lContainer.getElementsByTagName("div");
	}

	if(lTags){
		for(var x = 0; x<lTags.length; x++){
			if(lTags[x].id.indexOf("button|") != -1){
				lButtons.push(lTags[x]);				
			}
		}	
	}
	
	if(lButtons.length){
		for(var x = 0; x<lButtons.length; x++){
			var lButton = lButtons[x].id.split("|");
			var lContent = lButtons[x].innerHTML;
			var w = '';
			w += writeTableBox({type:lButton[1],top:true,name:"button"});
			w += lContent;
			w += writeTableBox({type:lButton[1],top:false,name:"button"});
			
			lButtons[x].innerHTML = w;
			lButtons[x].id = "button_" + lButton[2] + "_div";
		}	
	}
}

function formButtonClick(p){

	alert("function formButtonClick() is deprecated.\nIt should be removed from this page.\n\n" + unescape(location.href));

	if(typeof(p) == "object"){
		var pLink = null;
		switch(p.id){
			case "mp_preferences":
				pLink = "pref.aspx"
				break;
		    case "mp_create":
		        pLink = "Weekly.aspx?CREATE=YES"
		        break;
		    case "mp_view":
		        pLink = "Weekly.aspx"
		        break;
			case "active_more":
				pLink = "small_steps.aspx"
				break;
			default:
				//gDebug.getVar(p.style);
				alert('"' + p.id + '" not found in formButtonClick()')
				break;
		}
		
		if(pLink){
			location.href = pLink;
		}
	}else{
		location.href = p;
	}
}

/********************************/
/*        CHECKBOXLIST          */
/********************************/
function validateMaxChecks(strId, intMax)
{
    var i = 0, checkedItems = 0, setDisabled = false;
    var currentListItem = document.getElementById(strId + '_' + i);

    // count the number of checked items
    while (currentListItem != null){
        if (currentListItem.checked){
            checkedItems++;
        }
        i++;
        currentListItem = document.getElementById(strId + '_' + i);
    }

    // disable unchecked items if the maximum checked items has been reached
    setDisabled = (checkedItems >= intMax);
    while (i > 0){
        i--;
        currentListItem = document.getElementById(strId + '_' + i);
        if (currentListItem.checked == false || intMax == 0){
            currentListItem.disabled = setDisabled;
        }
    }

    return;
}

/********* BACK BUTTON LOGIC ***********/
/* Used in the healthy u section */
function initBackButton(){

	var w = '';
	w += '<div class="button_container_right">';
	w += '<a id="backLink" href="javascript:void(0);" onclick="clickBackButton(this);return false;" class="orangeButton">back</a>';
	w += '</div><br  style="clear:both;" />';

	document.write(w);
}

function clickBackButton(obj){
	switch(obj.id){
		case "backLink":
			history.go(-1);
			break;
		default:
			break;
	}
}

/******************************************/
/************ GRAPHIC BUTTONS *************/
/******************************************/

function initFooterButtons(){
	
	var lContainer = document.getElementById("footerLinks");
	var lTags = null;
	var lLinks = [];
	
	if(lContainer){
		lTags = lContainer.getElementsByTagName("a");
	}

	if(lTags){
		for(var x = 0; x<lTags.length; x++){
			if(lTags[x].className == "footer_links"){
				lLinks.push(lTags[x])
			}
		}	
	} 
	
	if(lTags.length){
		for(var x = 0; x<lTags.length; x++){
			var i = lTags[x];
			i.p_name = lTags[x].id.split("_")[1];
			i.p_path = gPaths.images + "footer/";
			i.p_image_roll = "btn_" + i.p_name + "_over.gif";
			createButtonObj(i);
		}
	}
	// SSK removed for new design 4/13/2009 //
	//assignBackgroundColor();
}

function createButtonObj(obj){
	//gDebug.getVar(obj)
	obj.p_image = obj.childNodes[0];
	obj.p_image_lo = obj.p_image.src;
	var a = obj.p_image_lo.split("/");
	var b = '';
	for(var i = 0; i<a.length-1; i++){
		b += a[i] + "/";
	}
	obj.p_image_hi = new Image();
	obj.p_image_hi.src = b + obj.p_image_roll;
	
	obj.onmouseover = function(){
		obj.p_image.src = obj.p_image_hi.src;
		//gDebug.tracer(obj.p_image_hi.src)
	}

	obj.onmouseout = function(){
		obj.p_image.src = obj.p_image_lo;
	}
}


function initLinkColors(obj){

	var lContainer = document.getElementById(obj.div);
	var lTags = null;
	var lLinks = [];

	if(lContainer){
		lTags = lContainer.getElementsByTagName("a");
	}

	if(lTags){
		for(var x = 0; x<lTags.length; x++){
			if(lTags[x].className == "arrowLinks_grey"){
				lLinks.push(lTags[x])
			}
		}	
	}

	if(lTags.length){
		for(var x = 0; x<lTags.length; x++){
			if(lTags[x].href == location.href){
				lTags[x].style.color = "#541c72";
			}
		}
	}

	//showPrintButton();
}

function PDF_globalLink(p){
	if(!p || !p.id){
		alert("Object ID not passed to PDF_globalLink()\nCalled from " + location.href);
		return
	}

	var PDF = {nochrome:true, resize:true};
	
	switch(p.id){
		case "Link_Instructions":
			//PDF.file = "MRKRET_588_Link_Instructions.zip";
			location.href = gPaths.pdf + "MRKRET_588_Link_Instructions.zip"
			return;
			break;
		case "globalTabDAQ":
		case "HE_index_DAQ":
		case "HE_yourdoc_DAQ":
		case "HPP_DAQ":
		case "MS_Transition":
			PDF.file = "MRK_09136_20952422(46)_BeforeYourHealthCareVisit.pdf";
			break;
		case "globalTabFC":
		case "HE_index_FC":
		case "HE_yourdoc_FC":
		case "HPP_FC":
			PDF.file = "MRK_09136_20952422(23)_After Chcklst.pdf";
			break;
		case "HEI_index_IQR":
		case "ART_294_IQR":
		case "ART_IQR":
			PDF.file = "MRKRET_669_NOND_1007224_0033_Insurance_QuickRef_Downloadable_PDF_Lv4.pdf";
			break;
		case "globalTabSM":
		case "HP_index_men_chart":
		case "HE_S_SM":
			PDF.file = "MRKRET_479_MULT_1000354_0000_GeneralScreenings_Men_Lv2.pdf";
			break;
		case "globalTabSW":
		case "HP_index_women_chart":
		case "HE_S_SW":
			PDF.file = "MRKADD_468_MULT_1000362_0000_ScreeningWomen_Lv2.pdf";
			break;
		case "HE_Activity_HAAY":
		case "LN_DB_Activity_HAAY":
		case "GF_index_HAAY":
		case "ART_71_HAAY":
		case "SM_Activity_HAAY":
		case "MED_MAT_HAAY":
			PDF.file = "MRK_09136_20952422(20)_ActivityAssesTool.pdf";
			break;
		case "HE_Activity_SP":
		case "LN_DB_Activity_SP":
		case "ART_65_SP":
		case "ART_68_SP":
		case "ART_69_SP":
		case "ART_71_SP":
		case "ART_71_SP_1":
		case "ART_76_SP":
		case "SM_Activity_SP":
		case "MED_MAT_SP":
		case "LCA_SP":
			PDF.file = "MRK_09136_20952422(44)_Sample Planner.pdf";
			break;
		case "SM_DR_Goals":
		case "C_DR_Goals":
			PDF.file = "templates/MRK_09136_20952422(24)_DisngResults_Goals withDr.pdf";
			break;
		case "HE_Nutrition_FL":
			PDF.file = "FoodLog.pdf";
			break;
		case "ART_250_AT":
			PDF.file = "parent_home/AsthmaTracker.pdf";
			break;
		case "ART_250_AAP":
			PDF.file = "parent_home/AsthmaActPlan.pdf";
			break;
		case "ART_308_GoodFats":
			PDF.file = "meal_planner_good_fats.pdf";
			break;
		case "fax_sign_up_fax_a":
			PDF.hcp = true;
			PDF.file = "MerckEngage_adult_signup_form.pdf";
			break;
		case "fax_sign_up_fax_p":
			PDF.hcp = true;
			PDF.file = "MerckEngage_parent_signup_form.pdf";
			break;
		case "FAX_Enrollment":
		case "SM_FAX_Enrollment":
			PDF.hcp = true;
			PDF.file = "MRK_08151A_HCP_Enrollment_Fax_Form.pdf";
			break;
		case "BLANK_MT":
			PDF.file = "trackers/21050329(56) Migraine Tracker.pdf";
			break;
		case "MED_MAT":
		case "globalTabMW":
			PDF.file = "Medication_Worksheet.pdf";
			break;
		case "globalTabTTM":
			PDF.file = "TipsforTakingMeds.pdf";
			break;
			// PARENT SECTION //
		case "P_ALLERGYT": // Allergy Tracker //
			PDF.file = "parent_home/AllergyTracker.pdf";
			break;
		case "P_ECARD": // Emergency Card //
			PDF.file = "MRKADD_468_ASTH_1000357_0000_EmergencyCard.pdf";
			break;
		case "P_AAP": // Asthma Action Plan //
			PDF.file = "MRKADD_468_ASTH_1000355_0000_AsthmaActionPlan.pdf";
			break;
		case "P_ASTHMAT": // Asthma Tracker //
			PDF.file = "MRKADD_468_ASTH_1000349_0000_AsthmaTracker.pdf";
			break;
		case "P_QCARD": // Question Card  //
			PDF.file = "MRKADD_ASTH_1000358_0000_QuestionsCard.pdf";
			break;
		case "P_SCHOOL": // School Checklist //
			PDF.file = "MRKRET_479_ASTH_1000359_0000_School Checklist.pdf";
			break;
		case "ART_CO": // Insurance Article callout //
			PDF.file = "MRKRET_669_NOND_1007224_0033_Insurance_QuickRef_Downloadable_PDF_Lv4.pdf";
			break;
		case "PDF_CCG": // Cholesterol Care Guide //
		case "CL_index_CCG":
			PDF.file = "MRKRET_544_Cholesterol_Care_Guide.pdf";
			break;
		case "PDF_CGS": // Cholesterol Goals Sheet //
		case "globalTabCGA":
		case "CL_index_CGS":
			PDF.file = "MRKRET_544_Cholesterol_Goals_Activity_Sheet.pdf";
			break;
		case "PDF_DIAB": // Diabetes patient action plan //
		case "globalTabDAP":
		case "CL_index_DIAB":
			PDF.file = "MRKRET_DIAB_1004299_0000_544_Patient_Action_Plan_FIN.pdf";
			break;
		case "PDF_HAP": // Hypertension Action Plan //
		case "globalTabHAP":
		case "CL_index_HAP":
			PDF.file = "MRKRET_544_Hypertension_Action_Plan.pdf";
			break;
		case "PDF_DPAP": // Diabetes Patient Action Plan //
		case "CL_index_DPAP":
			PDF.file = "MRKRET_DIAB_1004299_0000_544_Patient_Action_Plan_FIN.pdf";
			break;
		case "PDF_AAAP": // ASTHMyths Asthma Action Plan //
			PDF.file = "MRKRET_547_RESP_1003915_0000_Asthma_Action_Plan_Lv2.pdf";
			break;
		case "PDF_QBIP": // Bipolar I Questions //
			PDF.file = "MRKRET_578_NEUR_1009331_0018_Bipolar_Questions_Downloadable_PDF_Lv7.pdf";
			break;
		case "PDF_QSCHIZ": // Schizophrenia Questions //
			PDF.file = "MRKRET_578_NEUR_1009331_0017_Schizophrenia_Questions_Downloadable_PDF_Lv6.pdf";
			break;
		case "PDF_HELPPLAN_BIP": // Mental Illness Help Plan //
		case "PDF_HELPPLAN_SCHIZ":
			PDF.file = "MRKRET_578_NEUR_1009331_0016_Plan_Getting_Help_PDF_Lv4.pdf";
			break;
		default:
			alert("Object.id = " + p.id + " not defined in PDF_globalLink()");
			break;
	}
	
	if(PDF.file){
		PDF.loc = (PDF.hcp)? gPaths.hcp.pdf + PDF.file : gPaths.pdf + PDF.file;
		PMG_newWindow(PDF);
		PDF.track_name = "PDF_" + p.id;
		trackClick(PDF)
	}
}


// ***************************************************************************** //
// 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){
	if(typeof(pLoc) == "object"){
		if(pLoc.path){
			// pass the full path from the obj //
		}else{
			pLoc.loc = gPaths.pdf + pLoc.loc + ".pdf";
		}
		PMG_newWindow(pLoc);
	}else{
	//alert(pLoc)
		// Code is for dynamic PDF's //	
		//window.open(pLoc,"printpdf","width=800,height=600,status=yes,toolbar=no,menubar=no,location=no,resizable=yes");
		PMG_newWindow({loc:pLoc, name:"printpdf", nochrome:true, resize:true});
		if (document.PDFLauncher != null){
			document.PDFLauncher.target = "printpdf";
			document.PDFLauncher.action = pLoc;
			document.PDFLauncher.submit();
		}
	}
}


// ***************************************************************************** //
// gXML = XMLHttpRequest() - All XML Object functions
// ***************************************************************************** //
var gXML = {};
gXML.parseXML = function(text) {
    if(typeof DOMParser != "undefined"){
        // Mozilla, Firefox, and related browsers
        return (new DOMParser()).parseFromString(text, "application/xml");
    }else{
		if(typeof ActiveXObject != "undefined"){
	        // Internet Explorer. //
	        var doc = gXML.newDocument( );
	        doc.loadXML(text);
	        return doc;
    	}else{
	        // As a last resort, try loading the document from a data: URL, Safari //
	        var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
	        var request = new XMLHttpRequest();
	        request.open("GET", url, false);
	        request.send(null);
	        return request.responseXML;
	    }
	}
}


gXML.loadAsync = function(url, callback) {
    var xmldoc = gXML.newDocument();

    // If we created the XML document using createDocument, use
    // onload to determine when it is loaded
    if (document.implementation && document.implementation.createDocument) {
        xmldoc.onload = function(){
			callback(xmldoc);
		}
    }else{
		// IE, use onreadystatechange as with XMLHttpRequest
		xmldoc.onreadystatechange = function() {
            if (xmldoc.readyState == 4){
				callback(xmldoc);
			}
        }
    }

    // Now go start the download and parsing
    xmldoc.load(url);
}

gXML.load = function(url) {
    var xmldoc = gXML.newDocument();
    xmldoc.async = false;
    xmldoc.load(url);
    return xmldoc;
}

gXML.newDocument = function(rootTagName, namespaceURL) {
    if (!rootTagName) rootTagName = "";
    if (!namespaceURL) namespaceURL = "";
	
    if (document.implementation && document.implementation.createDocument) {
        // This is the W3C standard way to do it
        return document.implementation.createDocument(namespaceURL,rootTagName, null);
    }else{
		// This is the IE way to do it //
        // Create an empty document as an ActiveX object //
        // If there is no root element, this is all we have to do //
        var doc = new ActiveXObject("MSXML2.DOMDocument");

        // If there is a root tag, initialize the document
        if(rootTagName){
            // Look for a namespace prefix
            var prefix = "";
            var tagname = rootTagName;
            var p = rootTagName.indexOf(':');
            if(p != -1){
                prefix = rootTagName.substring(0, p);
                tagname = rootTagName.substring(p+1);
            }

            // If we have a namespace, we must have a namespace prefix
            // If we don't have a namespace, we discard any prefix
            if (namespaceURL) {
                if(!prefix){
					prefix = "a0"; // What Firefox uses
				}
            }else{
				prefix = "";
			}

            // Create the root element (with optional namespace) as a
            // string of text
            var text = "<" + (prefix?(prefix+":"):"") + tagname + (namespaceURL?(" xmlns:" + prefix + '="' + namespaceURL +'"'):"") + "/>";
            // And parse that text into the empty document
            doc.loadXML(text);
        }
        return doc;
    }
}


// add a function to the onload //
function add_onload(pFunction){
	if(window.attachEvent){
		window.attachEvent("onload", eval(pFunction));
	}else{
		window.addEventListener("load", eval(pFunction), false);
	}
}


function leavingMerckEngage(p){

	if(!p){
		alert("ID not passed to leavingMerckEngage() from \n" + location.href);
		return;
	}
	
	if(p.track_name){
		if(!p.id){
			p.id = p.track_name;
		}
	}else{
		p.track_name = p.id;
	}
	
	switch(p.id){
		case "just_walk":
			p.loc = "http://www.walkwithadoc.org";
			break;
		case "food_safety":
			p.loc = "http://www.foodsafety.gov";
			break;
		case "healthcare":
			p.loc = "http://www.healthcare.gov";
			break;
		case "medlineplus":
			p.loc = "http://www.medlineplus.com";
			break;
		case "healthfinder":
			p.loc = "http://www.healthfinder.gov";
			break;
		case "insurekids":
			p.loc = "http://www.insurekidsnow.gov";
			break;
		case "talkaboutrx":
			p.loc = "http://www.talkaboutrx.org";
			break;
		case "FDA":
			p.loc = "http://www.fda.gov";
			break;
		case "PPARX":
			p.loc = "http://www.pparx.org";
			break;
		case "RXA":
			p.loc = "http://www.rxassist.org";
			break;
		case "MS_APP":
		case "imigraine":
			// iPhone App //
			p.loc = "http://itunes.apple.com/us/app/imanage-migraine/id340537912?mt=8";
			break;
		case "ichemo":
			// iPhone App //
			p.loc = "http://itunes.apple.com/us/app/ichemodiary/id334253464?mt=8";
			break;
		case "vree":
			// iPhone App //
			p.loc = "http://itunes.apple.com/us/app/vree-for-diabetes/id355923059?mt=8";
			break;
		case "coppertone":
			// iPhone App //
			p.loc = "http://itunes.apple.com/us/app/coppertone-myuvalert/id380035439?mt=8";
			break;
		case "about.com":
			p.loc = "http://www.about.com";
			break;
		case "aanma.org":
			p.loc = "http://www.aanma.org/";
			break;
		case "aaaai.org":
			p.loc = "http://www.aaaai.org";
			break;
		case "aap.org":
			p.loc = "http://www.aap.org";
			break;
		case "acaai.org":
			p.loc = "http://www.acaai.org";
			break;
		case "aafa.org":
			p.loc = "http://www.aafa.org";
			break;
		case "clevelandclinic.org":
			p.loc = "http://www.clevelandclinic.org";
			break;
		case "emedicinehealth.com":
			p.loc = "http://www.emedicinehealth.com/index.asp";
			break;
		case "kidshealth.org":
			p.loc = "http://www.kidshealth.org";
			break;
		case "mayoclinic.com":
			p.loc = "http://www.mayoclinic.com";
			break;
		case "pollen.com":
			p.loc = "http://www.pollen.com/Pollen.com.asp";
			break;
		case "webmd.com":
			p.loc = "http://www.webmd.com";
			break;
		case "lungusa.org":
			p.loc = "http://www.lungusa.org";
			break;
		case "cdc.com_asthma":
			p.loc = "http://www.cdc.gov/asthma/children.htm";
			break;
		case "cdc.com_tobacco":
			p.loc = "http://www.cdc.gov/tobacco/quit_smoking/index.htm";
			break;
		case "epa.gov":
			p.loc = "http://www.epa.gov/iaq/asthma";
			break;
		case "nhlbi.nih.gov_asthma":
			p.loc = "http://www.nhlbi.nih.gov/health/public/lung/asthma/phy_astr.htm";
			break;
		case "nhlbi.nih.gov":
			p.loc = "http://www.nhlbi.nih.gov/health/public/lung/index.htm";
			break;
		case "nhlbi.nih.gov_cardio":
			p.loc = "http://www.nhlbi.nih.gov/health/public/heart/index.htm";
			break;
		case "nhlbi.nih.gov_cholesterol":
			p.loc = "http://www.nhlbi.nih.gov/guidelines/cholesterol";
			break;
		case "stroke.org":
			p.loc = "http://www.stroke.org/";
			break;
		case "nhlbi.nih.gov_cce":
			p.loc = "http://www.nhlbi.nih.gov/chd/";
			break;
		case "americanheart.org":
			p.loc = "http://www.americanheart.org";
			break;
		case "strokeassociation.org":
			p.loc = "http://www.strokeassociation.org";
			break;
		case "diabetes.org":
			p.loc = "http://www.diabetes.org/";
			break;
		case "diabetesaction.org":
			p.loc = "http://www.diabetesaction.org/site/PageServer?pagename=index";
			break;
		case "diabetes-exercise.org":
			p.loc = "http://www.diabetes-exercise.org/";
			break;
		case "idf.org":
			p.loc = "http://www.idf.org";
			break;
		case "diabetes.niddk.nih.gov":
			p.loc = "http://www.diabetes.niddk.nih.gov";
			break;
		case "niddk.nih.gov":
			p.loc = "http://www2.niddk.nih.gov/HealthEducation/HealthNutrition";
			break;
		case "ndep.nih.gov":
			p.loc = "http://ndep.nih.gov";
			break;
		case "niddk.nih.gov":
			p.loc = "http://www2.niddk.nih.gov";
			break;
		case "jdf.org":
			p.loc = "http://www.jdf.org";
			break;
		case "americanheart.or":
			p.loc = "http://www.americanheart.org/";
			break;
		case "ash-us.org":
			p.loc = "http://www.ash-us.org";
			break;
		case "nhlbi.nih.gov_hbp":
			p.loc = "http://www.nhlbi.nih.gov/hbp";
			break;
		case "achenet.org":
			p.loc = "http://www.achenet.org";
			break;
		case "americanheadachesociety.org":
			p.loc = "http://www.americanheadachesociety.org";
			break;
		case "headaches.org":
			p.loc = "http://www.headaches.org";
			break;
		case "headachenech.com":
			p.loc = "http://www.headachenech.com";
			break;
		case "eatright.org":
			p.loc = "http://www.eatright.org";
			break;
		case "health.gov":
			p.loc = "http://www.health.gov/dietaryguidelines";
			break;
		case "nal.usda.gov":
			p.loc = "http://www.nal.usda.gov/fnic";
			break;
		case "niddk.nih.gov_nutrition":
			p.loc = "http://www.niddk.nih.gov/health/nutrition.htm";
			break;
		case "niddk.nih.gov_weight":
			p.loc = "http://www.niddk.nih.gov/health/nutrit/nutrit.htm";
			break;
		case "nlm.nih.gov":
			p.loc = "http://www.nlm.nih.gov/medlineplus/weightcontrol.html";
			break;
		case "lunguse.org":
			p.loc = "http://www.lungusa.org/about-us/lung-helpline.html";
			break;
		case "diabetes_educator":
		case "diabetes_educator_LN":
			p.loc = "http://www.diabeteseducator.org/DiabetesEducation/Find.html";
			break;
		case "travel_tips":
		case "travel_tips_LN":
			p.loc = "http://www.diabetes.org/living-with-diabetes/complications/frequent-travelers.html";
			break;
		case "medicare.gov":
			// Article 292 //
			p.loc = "http://www.medicare.gov";
			break;
		case "shiptalk.org":
			// Article 292 //
			p.loc = "http://www.shiptalk.org";
			break;
		case "cms.hhs.gov":
			// Article 292 //
			p.loc = "http://www.cms.hhs.gov";
			break;
		case "medical_dictionary":
			p.loc = "http://www.nlm.nih.gov/medlineplus/mplusdictionary.html";
			break;
		case "webmd":
			p.loc = "http://www.webmd.com";
			break;
		case "webmd_michael_smith":
			p.loc = "http://www.webmd.com/michael-w-smith";
			break;
		case "scriptyourfuture.com_wallet_card":
			// RX for Health index.aspx //
			p.loc = "http://scriptyourfuture.org/?page_id=13";
			break;
		case "scriptyourfuture.com_pledge":
			// RX for Health index.aspx //
			p.loc = "http://scriptyourfuture.org/?page_id=17";
			break;
		case "mexp_migrainesupport.com":
		case "mexp_achenet.org":
		case "mexp_headaches.org":
			// Migraine Experience Links //
			p.name = "MEXP_EXTERNAL";
			break;
		default:
			alert(p.id + " is not defined in leavingMerckEngage()\nCalled from " + location.href);
			break;
	}
	
	var lOK = confirm(gProps.leaving_merck.text);
	if(lOK){
  		PMG_newWindow(p);
		if(p.track_name){
			// this is here for backwards compatability //
			// global track_link_ should be used moving forward //
			trackClick(p);
		}
  	}
}

// ********************************* //
// returns the x and y of an element //
// ********************************* //
function PMG_getCoords(pObj){
	//gDebug.getVar(pObj)
	//gDebug.getVar(pObj.getClientRects()[0])
	if(pObj){
		var lCoords = {x:0,y:0,width:pObj.offsetWidth,height:pObj.offsetHeight};
		while(pObj){
			lCoords.x += parseInt(pObj.offsetLeft);
			lCoords.y += parseInt(pObj.offsetTop);
			pObj = pObj.offsetParent;
			//alert("pObj.id = " + pObj.id);
		}
		lCoords.right = (lCoords.x + lCoords.width);
		lCoords.bottom = (lCoords.y + lCoords.height);
		return lCoords;
	}
	
	return false;
}


function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		var M = {x:ev.pageX, y:ev.pageY};
	}else{
		var M = {};
		M.x = (ev.clientX + document.body.scrollLeft - document.body.clientLeft);
		M.y = (ev.clientY + (document.body.scrollTop  - document.body.clientTop));
	}
	// DEBUG TOOLS //
	if(typeof(gDebug) != "undefined"){
		if(gDebug.tools){
			var lLoc = "x = " + M.x + "<br>y = " + M.y;
			gDebug.tracer(lLoc,true)	
		}
	}
		
	return M;
}

// ********************************* //
//          Form functions           //
// ********************************* //
var gForms = {};
// this function will only allow numbers to be entered into a field //
gForms.numbers_only = function(e){
	var lKey = (e)? e.which : event.keyCode;
	// key 48 = 0, key 57 = 9, key 8 = backspace, key 0 = TAB //
	if(!this.pError){
		this.pError = document.getElementById(this.id + "_error");
	}else{
		if(this.pError.style.display != "none"){
			this.pError.style.display = "none";
		}
	}
	
	var lOK = ((lKey >= 48) && (lKey <= 57));

	if(lOK || (lKey == 8) || (lKey == 0)){
		return true;
	}else{
		//alert(lKey)
		return false;
	}
}

gForms.assignEnterKey = function(e){
	var lKey = (e)? e.which : event.keyCode;
	//var lOK = ((lKey >= 48) && (lKey <= 57));
	
	if((lKey == 13) && gForms.enterKey){
		gForms.enterKey.onclick();
		return false;
	}
}

gForms.trim = function(pString){
	return pString.replace(/^\s+|\s+$/g,"");
}

gForms.trim_left = function(pString){
	return pString.replace(/^\s+/,"");
}

gForms.trim_right = function(pString){
	return pString.replace(/\s+$/,"");
}

// ******************************************** //
// validates e-mail address   
// p = {}
// p.address = string (email address)
// p.error = object error container
// ******************************************** //
gForms.validEmail = function(p){
	var lValid = false;
	
	if(typeof(p) != "object"){
		alert("object not passed to gForms.validEmail()");
	}else{
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		lValid = reg.test(p.email);
		// show the error message /
		if(p.error && !lValid){
			p.error.style.display = "block";
			p.error.style.visibility = "visible";
		}
	}
	
	return lValid;
}

gForms.ie_width = function(p){
	if(p.length){
		for(var x = 0; x<p.length; x++){
			var lSelect = document.getElementById(p[x]);
			
			if(lSelect){
				// store the assigned width //
				lSelect.pWidth = lSelect.style.width;
				// make sure that no item is selected onload //				
				/*
				for(var i = 0; i<lSelect.options.length; i++){
					lSelect.options[i].selected = false;
				}
				*/
				lSelect.options[0].selected = true;
				lSelect.onchange = function(){
					//alert(this.value)
					if(this.value){
						if(this.value.toLowerCase() != "null"){
							this.style.width = "auto";
							location.href = this.value;
						}
					}
				}
				
				// IE needs to resize the width in order to fit long titles //
				if(gBrowser.vendor == "IE"){
					lSelect.pEnabled = false;
					if(gBrowser.ie6){
						/*
						lSelect.onmousedown = function(){
							this.style.width = "auto";
							this.pEnabled = true;
							this.options[0].selected = true;
						}
						*/
						
						/*
						lSelect.onclick = function(){
							this.pEnabled = true;
						}
						*/
					}else{
						lSelect.onmousedown = function(){
							this.style.width = "auto";
							this.pEnabled = true;
						}

						lSelect.onmouseout = function(){
							if(!this.pEnabled){
								this.onblur();
							}
						}

					}
					
					lSelect.onblur = function(){
						this.style.width = this.pWidth;
						this.pEnabled = false;
					}
					
					
				}
			}
			
		}
	}
}

// ******************************************** //
function validateHelpFinder(){
	var lDD = document.getElementById("HF_Product_DD");
	var lZipcode = document.getElementById("HF_Zip");
	// Need to add validation //	
	if(lDD){
		// No dropdown was selected //
		if(lDD.value == 0){
			lDD.pError = document.getElementById(lDD.id + "_error");
			if(lDD.pError){
				lDD.pError.style.display = "block";
				lDD.onchange = function(){
					if(this.value){
						this.pError.style.display = "none";
					}
					
					helpFinderChange(this);
				}
			}

		}else{
			//gDebug.getVar(gGoogle[lDD.value]);
			var lSearch = gGoogle[lDD.value];
			var lURL = "http://www.google.com/search";
			var lZip = "";
			// Zipcode is not required for a national search //
			if(lSearch.pType != "search"){
				lURL = "http://maps.google.com/maps";
				lZip = lZipcode.value;
				// a valid zipcode is required for a local map search //
				if(lZip == "" || lZip.length <5){
					lZipcode.pError = document.getElementById(lZipcode.id + "_error");
					if(lZipcode.pError){
						lZipcode.pError.style.display = "block";
						return;
					}
				}else{
					//lZipcode.pError.style.display = "none";
				}
			}
			
			var lString = '"' + lDD[lDD.selectedIndex].text.toLowerCase() + '"';
			if(lSearch.pString){
				lString = lSearch.pString;
			}
			
			//alert(lString);
			var lOK = confirm(gProps.leaving_merck_help_finder.text);
			if(lOK){
		  		PMG_newWindow({loc:lURL + "?q=" + lString + " " + lZip,nochrome:true,chrome:{scrollbars:"yes"}})
				trackClick({track_name:"help_finder"})
		  	}
			
		}
		
	}else{
		alert("HF_Product_DD not found in help_finder.ascx")
	}
}


function helpFinderChange(p){
	if(gGoogle[p.value]){
		var lA = document.getElementById("HelpFinder").getElementsByTagName('input');
		var lA2 = document.getElementById("HelpFinder").getElementsByTagName('select');
		var lZip = document.getElementById("HF_Zip_error");
		for(var x = 0; x<lA.length; x++){
			lA[x].disabled = (gGoogle[p.value].pType == "search");
		}
		
		lA2[1].disabled = (gGoogle[p.value].pType == "search");
		if(lZip){
			lZip.style.display = "none";
		}
		
	}
}

// supress javascript error "flash_id" //
function stopError(msg,url,l){
	if(gDebug.tools && gDebug.showErrors){
		alert(msg);
	}
	return true;
}
if(!gDebug.tools){
	window.onerror = stopError;
}

function passTracking(p){
	
	if(!p){return}
	if(!p.track_name){
		p.track_name = (p.id.id)? p.id.id : p.id;
	}
	
	//gDebug.getVar(p);
	var lLoc = null;
	switch(p.track_name){
		case "Allergies":
			//lLoc = "http://merckservices-ut.merck.com/usacontent/merckengage/index.html?c=1";
			//lLoc = "http://www.merckservices.com/usacontent/merckengage/index.html?c=1";
			lLoc = "http://www.singulair.com";
			break;
		case "Asthma":
			//lLoc = "http://merckservices-ut.merck.com/usacontent/merckengage/index.html?c=2";
			//lLoc = "http://www.merckservices.com/usacontent/merckengage/index.html?c=2";
			lLoc = "http://www.singulair.com";
			break;
		case "Cholesterol":
			//lLoc = "http://merckservices-ut.merck.com/usacontent/merckengage/index.html?c=3";
			//lLoc = "http://www.merckservices.com/usacontent/merckengage/index.html?c=3";
			//lLoc = "http://vytorin.com/ezetimibe_simvastatin/vytorin/consumer/index.jsp";
			lLoc = "http://www.zetia.com/ezetimibe/zetia/consumer/index.jsp";
			break;
		case "CINV":
			lLoc = "http://www.emend.com";
			break;
		case "COPD":
			lLoc = "http://merckservices-ut.merck.com/usacontent/merckengage/index.html?c=4";
			//lLoc = "http://www.merckservices.com/usacontent/merckengage/index.html?c=4";
			break;
		case "Diabetes (type 2)":
			//lLoc = "http://merckservices-ut.merck.com/usacontent/merckengage/index.html?c=5";
			//lLoc = "http://www.merckservices.com/usacontent/merckengage/index.html?c=5";
			lLoc = "http://www.januvia.com";
			break;
		case "Hair loss (alopecia)":
			lLoc = "http://www.propecia.com";
			break;
		case "High blood pressure":
			lLoc = "http://www.cozaar.com/losartan_potassium/cozaar/consumer/index.jsp";
			break;
		case "HIV":
			lLoc = "http://www.isentress.com";
			break;
		case "Migraine":
			lLoc = "http://www.maxalt.com";
			break;
		case "Osteoporosis":
			lLoc = "http://www.fosamax.com/alendronate_sodium/fosamax/consumer/index.asp";
			break;
		case "Patient assistance program":
			lLoc = "http://www.merck.com/merckhelps";
			break;
		case "MerckSource":
			lLoc = "http://www.mercksource.com";
			break;
		case "Merck manual":
			lLoc = "http://www.merck.com/mmhe/index.html";
			break;
		case "Go red":
			lLoc = "http://www.goredforwomen.org/";
			break;
		case "Merck":
			lLoc = "http://www.merck.com/";
			break;
		case "google":
			lLoc = "https://www.google.com/accounts/NewAccount";
			break;
		case "msn":
			lLoc = "https://signup.live.com/signup.aspx";
			break;
		case "yahoo":
			lLoc = "https://edit.yahoo.com/registration";
			break;
		case "footer_privacy":
		case "merck_privacy":	
			lLoc = "http://www.merck.com/policy/privacy/home.html";
			break;
		case "footer_terms":
			lLoc = "http://www.merck.com/policy/termsofuse/home.html";
			break;
		case "footer_copyright":
			lLoc = "http://www.merck.com/policy/copyright/home.html";
			break;
		case "footer_merck":
		case "merck_overbrand":
			lLoc = "http://www.merck.com";
			break;
		case "pa_program": // patient assistance program landing_page.aspx //
			lLoc = "http://www.merck.com/merckhelps/patientassistance/home.html";
			break;
		case "library_allergies":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=allergies";
			break;
		case "library_asthma":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=asthma";
			break;
		case "library_cholesterol":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=cholesterol";
			break;
		case "library_diabetes":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=diabetes";
			break;
		case "library_hbp":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=high-blood-pressure";
			break;
		case "library_migraine":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=migraine";
			break;
		case "library_obesity":
			lLoc = "http://www.mercksource.com/pp/us/cns/ConditionGuides.jsp?menuItem=ConditionPage&condition=obesity";
			break;
		case "cdc":
			lLoc = "http://www.cdc.gov/";
			break;
		case "nih":
			lLoc = "http://www.nlm.nih.gov/";
			break;
		case "fda":
			lLoc = "http://www.fda.gov/";
			break;
		default:
			alert("link id not passed to passTracking()");
			break;
			
	}
	
	// Track the branded link that the user selected //
	if(lLoc){
		PMG_newWindow({loc:lLoc});
		trackClick(p);
	}
	
}

function downloadPDF(p){
alert("downloadPDF() is depricated. Called from\n" + location.href);	
	if(!p){
		alert("Object not passed to downloadPDF()");
		return;
	}
	
	if(!p.id){
		p.id = p.track_name;
	}

	switch(p.id){
		case "pdf_checkup_before":
			p.loc = "MRK_09136_20952422(46)_BeforeYourHealthCareVisit";
			break;
		case "pdf_checkup_after":
			p.loc = "MRK_09136_20952422(23)_After Chcklst";
			break;
		case "men_chart":
		case "women_chart":
			p.loc = p.track_name;
			p.track_name = "pdf_screening_" + p.track_name;
			break;
		case "pdf_insurance_quickref":
			p.loc = "MRK_09052D_Insurance QuickRef Downloadable PDF";
			break;
	}
	
	
	if(p.loc){
		openPDFWindow(p);
		if(p.track_name){
			trackClick(p);
		}
	}
	
}

var gTrackObj = {};
function trackClick(pObj){
	if(!pObj){return}
	// HCP - may use gUsper.hcp object for tracking //
	pObj.user = gUsers.login;
	pObj.page = gProps.tracking_source;
	if(gUsers.hcp.HCP_ID){
		pObj.user = "hcp_" + gUsers.hcp.HCP_ID;
	}
	
	gTrackObj = pObj;
	//gDebug.getVar(pObj);
	if(typeof(Sys) == "object"){
		Sys.Net.WebServiceProxy.invoke('/GlobalMethods.asmx', 'Track_Click', false, {"strID":pObj.user, "strResource":pObj.track_name, "strSource":pObj.page}, trackClickSuccess, trackClickFailed);
	}else{
		alert("Sys not defined in trackClick(). called from\n" + location.href);
	}
}

function trackClickSuccess(p){
	if(gDebug && gDebug.tools){
		gDebug.tracer("trackClickSuccess()\n<b>" + gTrackObj.track_name + "</b>");
		//var lError = gDebug.getVar(p, true);
		//alert("trackClickSuccess \n" + lError)
	}
}

function trackClickFailed(p){
	if(gDebug && gDebug.tools){
		gDebug.tracer("trackClickFailed()\n<b>" + gTrackObj.track_name + "</b>");
		//var lError = gDebug.getVar(p, true);
		//alert("trackClickFailed \n" + lError)
	}
}


function initClickTracking(e){
	var obj = {};
	obj.element = (e.srcElement)? e.srcElement : e.target;
	obj.track_name = false;
	var ID = null;
	
	// this allows for the span labels added from the global.resx file //
	if(obj.element.id == "" && obj.element.nodeName.toLowerCase() == "span"){
		obj.element = obj.element.parentNode; 
	}
	
	if(obj.element.id){
		if(obj.element.id.indexOf("track_link") != -1){
			ID = obj.element.id.split("track_link").pop();
		}
	}

	if(ID){
		if(obj.element.nodeName){
			switch(obj.element.nodeName.toLowerCase()){
				case "a":
				case "img":
				case "div":
					obj.track_name = "gT" + ID;
					break;
				default:
					break;
			}
		
			if(obj.track_name){
				//gDebug.getVar(obj)
				trackClick(obj);
			}
		}
	}
}

// this function finds the HCP in the header and redirects //
// This should be used with hyperlinks that point to the HCP website //
function goToHCPSite(){
	var lDiv = document.getElementById("links_nav_utility");
	var lLink = null;
	var lA = [];
	if(lDiv){
		lA = lDiv.getElementsByTagName("a");
	}

	if(lA.length){
		for(var x =0; x<lA.length; x++){
			if(lA[x].id && lA[x].id.indexOf("Nav_HCP") != -1){
				lLink = lA[x].href;
			}
		}
	}
	
	if(lLink){
		location.href = lLink;
	}else{
		alert("hcp_link_url not found in goToHCPSite()");
	}
}

function gotoRXSavings(p){
	PMG_newWindow({name:"RXSavings",loc:p.href,w:1024,nochrome:true,chrome:{scrollbars:"yes"}});
}

function gotToLatestHE(){
	var lDiv = document.getElementById("orange_sub_tab_container");
	var lA = [];
	if(lDiv){
		lA = lDiv.getElementsByTagName("a");
	}
	
	
	if(lA.length){
		for(var i = 0; i<lA.length; i++){
			if(lA[i].id.toLowerCase().indexOf("linksubnav_hc_he") != -1){
				var lHref = unescape(lA[i].href)
				eval(lHref)
				break;
			}
		}
	}
}

// ********************************* //
//          Opinion Labs             //
// ********************************* //
// this is called from the html_head.ascx control //
function checkOpinionLabs(){
	if(gProps.opinion_labs.visitor){
		_sp = '%3A\\/\\/';
		_rp = '%3A//'+'visitor.';
		//custom_var=UserId|window.location.href;
		//O_GoT('Feedback');
	}
}

// This is called from the footer.ascx control //
function initOpinionLabs(){
	// Make sure OL is enabled //
	if(gProps.opinion_labs.enabled){

		var lContent = '<p>Help make MerckEngage work better for you.</p>';
	
		switch(gProps.opinion_labs.content){
			case "mp":
				lContent = '<p>What do you think about the <b>Eating Well</b> section? Your feedback can help make it better.</p>';
				break;
			case "ap":
				lContent = '<p>What do you think about the <b>Getting Fit</b> section? Your feedback can help make it better.</p>';
				break;
			case "library":
				lContent = '<p>What do you think about the <b>Condition Library</b> section? Your feedback can help make it better.</p>';
				break;
			default:
				break;
		}
			
		var w = '';
		w += '<div id="opinion_labs">';
		w += writeTableBox({name:"grey",top:true,write:false});
		w += '<a id="oo_engine" href="javascript:O_LC();" class="bodyLinks" onclick="trackClick({track_name:this.id}); return true;"><img id="oo_engine" src="/js/onlineopinionS3tS/sm_008AD1_oo.gif" border="0" alt="[+]" />Share Your Feedback</a>';
		w += lContent
		w += writeTableBox({name:"grey",top:false,write:false});
		w += '</div>';
		
		document.write(w);
	}
}

// ********************************* //
//              GoFar                //
// ********************************* //
function initGoFar(){
	
	// check for global initialization //
	if(gProps.gofar.enabled){
		var lTime = "";
		if(gProps.gofar.init){
			// lTime is used to pass an extended query to the GoFar survey //
			switch(gProps.gofar.init){
				case 45:
					lTime = "&xm=1";
					break;
				default:
					// nothing //
					break;
			}
		}else{
			// If not turned on at the page level //
			// loop over the available pages that are enabled //
			var lPages = gProps.gofar.pages;
			var lArticles = gProps.gofar.articles;
			
			if(gProps.page.toLowerCase() == "article.aspx"){
				for(var x = 0; x<lArticles.length; x++){
					var lArticle = gProps.qs.ID;
					if(lArticles[x] == lArticle){
						gProps.gofar.init = true;
						gProps.gofar.enabled_page = lArticle;
						break;
					}
				}
			
			}else{
				var lLoc = unescape(location.href).split("?")[0];
				lLoc = lLoc.split(location.hostname)[1];
				for(var x = 0; x<lPages.length; x++){
					if(lPages[x] == lLoc){
						gProps.gofar.init = true;
						gProps.gofar.enabled_page = lLoc;
						break;
					}
				}
			}
			
			if(!gProps.gofar.init && gProps.gofar.force_display){
				gProps.gofar.init = true;
				gProps.gofar.enabled_page = lLoc;
			}
					
		}
			
		if(gProps.gofar.init){
			var SSL = location.protocol;
			//document.writeln('<link href="', SSL, '//www.customersat3.com/csc/ty/8201_dhtmlpop.css', '" rel="stylesheet" type="text/css" />');
			//document.writeln('<script src="', SSL, '//www.customersat3.com/csc/8201_sk.asp?si=BfOLANLQtPM%3D', lTime, '" type="text/javascript"><\/script>');
			document.writeln('<script src="', SSL, '//siterecruit.comscore.com/sr/merckengage/broker.js', lTime, '" type="text/javascript"><\/script>');
		
			//<link rel="stylesheet" href="http://www.customersat3.com/csc/ty/8201_dhtmlpop.css" type="text/css" />
			// **** 45 seconds **** //
			//<script language="javascript" src="http://www.customersat3.com/csc/8201_sk.asp?si=BfOLANLQtPM%3D&xm=1"></script>
			// **** 5 seconds **** //
			//<script language="javascript" src="http://www.customersat3.com/csc/8201_sk.asp?si=BfOLANLQtPM%3D"></script>
			
			//var lW = '<script type="text/javascript" src="https://www.customersat3.com/csc/8685_parentMachinery.asp?baby=/8685_b.html&si=BfOLANLQtPM%3D"></script>';
			//document.write(lW)
		}
	}
}

// ********************************* //
//            AddThis                //
// ********************************* //
function initAddThis(){
	
	// check for global initialization //
	if(gProps.addthis.enabled){
		if(gProps.addthis.override){
			// force AddThis to display //
			gProps.addthis.init = true;
		}else{
			// If not forced display at the page level //
			// loop over the available pages that are enabled //
			for(var x = 0; x<gProps.addthis.pathnames.length; x++){
				var lPath = gProps.addthis.pathnames[x];
				if(lPath.path.toLowerCase() == location.pathname.toLowerCase()){
					//gDebug.getVar(lPath);
					gProps.addthis.init = true;
					gProps.addthis.enabled_page = location.pathname;
					break;
				}
			}
					
		}
			
		if(gProps.addthis.init){
			var SSL = location.protocol;
			document.writeln('<script src="', SSL, '//s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4e6796061051a944', '" type="text/javascript"><\/script>');
			var lContainer = document.getElementById("nav_utility_container");		
			if(lContainer){
				/*
				var lDiv = document.createElement("div");
				lDiv.id = "addthis_toolbox";
				//lDiv.addthis:url = "http://www.merckengage.com";
				lDiv.className = "addthis_toolbox addthis_default_style";
				lDiv.style.position = "absolute";
				lDiv.style.top = "4px";
				lDiv.style.right = "240px";
				lDiv.style.width = "165px";
				//lDiv.style.border = "1px solid red";
				lContainer.appendChild(lDiv);
				*/
				//var lTemp = lContainer.innerHTML;
				lContainer.innerHTML += '<div style="position:absolute;top:4px;right:240px;width:165px;" id="addthis_toolbox" class="addthis_toolbox addthis_default_style" addthis:url="http://www.merckengage.com' + location.pathname + '"></div>';
				
				/*
				if(gProps.addthis.graphic){
					//	<meta property="og:image" content="http://www.merckengage.com/media/images/logos/gray_oa.gif" />
					var lMeta = document.createElement("meta");
					lMeta.property = "og:image";
					lMeta.content = "http://www.merckengage.com/media/images/logos/gray_oa.gif";
					
					var lHead = document.getElementsByTagName("head");
					if(lHead){
						//lHead[0].appendChild(lMeta);
						//lHead[0].innerHTML += '<meta property="og:image" content="http://www.merckengage.com/media/images/logos/gray_oa.gif">';
						
					}
				}
				*/
				add_onload("displayAddthis");
			}		
		}
	}
}

function displayAddthis(){
	
	var lDiv = document.getElementById("addthis_toolbox");		
    var lAddThis = [{id:"facebook",title:"Send to Facebook"},{id:"twitter",title:"Tweet This"},{id:"email",title:"Email"}];
	//var lAddThis = [{id:"twitter",title:"Tweet este"},{id:"facebook",title:"Enviar a Facebook"},{id:"email",title:"Correo"}];
	
	if(lDiv){
		//addthis_config.ui_language = "es";
		//addthis_config.ui_cobrand = "www.MerckEngage.com";
		addthis_config.url = "http://www.merckengage.com";
		
		lDiv.innerHTML = '<span style="position:relative;float:left;padding-right:5px;">Share this page</span>';
				
		for (var x = 0;  x<lAddThis.length; x++) {
			var ID = lAddThis[x].id;
			var lTitle = lAddThis[x].title || "";
		    lDiv.innerHTML += '<a class="addthis_button_' + ID + '" title="' + lTitle + '"></a>';
		}
		
		if(typeof(addthis)){
			addthis.toolbox("#addthis_toolbox");
		}
		
	}
}

// This is for external links that are in multiple places //
function scatLinks(p){
	
	if(!p || !p.id){
		alert("Proper id not passed to scatLinks()");
		return;
	}
	
	switch(p.id.toLowerCase()){
		case "privacy pdf":
			p.loc = "http://www.merck.com/policy/pdf/Privacy_Notice_Consumer_2007.pdf";
			break;
	}
	
	if(p.loc){
		PMG_newWindow(p)
	}else{
		alert("id = " + p.id + "\nThis id is not defined in scatLinks()");
	}
	
}

/*********************************/
/*****     HCP NOT FOUND     *****/
/*********************************/
var select_hcp_class = '';
var selected_hcp = 'empty';
var selected_original_class = '';
function init_select_hcp_table(obj) {
	var lTable = document.getElementById(obj.id);
	var lTags = null;        	
	if(lTable){
		lTags = lTable.getElementsByTagName("tr");
	}        	
	// initialize all the tr's in the select hcp table //
	if(lTags){
		var lFlop = true;
		for(var x = 0; x<lTags.length; x++){
			lTags[x].className = (lFlop)? "hcp_search_color" : "hcp_search_white";
			lFlop = !lFlop;
		}
	}
}

function select_hcp_onmouseover(obj) {
    select_hcp_class=obj.className;
    obj.className='hcp_search_hl';
}

function select_hcp_onmouseout(obj) {
    obj.className=select_hcp_class;
}

function select_hcp_onclick(obj) {
	var hcp_id = document.getElementById('hcpID');
	if (obj.id) {
		if (hcp_id) {
			if (selected_hcp != 'empty') { // PM - reset an HCP to unselected if it was previously selected
				var previous_selected_hcp = document.getElementById(selected_hcp);
				previous_selected_hcp.className = selected_original_class;
			}
			selected_hcp = obj.id;
			selected_original_class = select_hcp_class; // PM - retain the origianl class in case HCC selects another HCP
			hcp_id.value = obj.id; // PM - hidden fiels that will be used to update the HCC's HCP
		    obj.className='hcp_search_hl';
			select_hcp_class = obj.className;
		}
	}
}

/**********************************/
/*****     FLASH TRACKERS     *****/
/**********************************/
function initTrackers(){

	var lOK = false;
	var lAdd = null;
	
	if(gProps.qs && gProps.qs.MENUID){
		switch(gProps.qs.MENUID){
			case "Migraine":
				lOK = "Migraine_Flash";
				lAdd = gProps.qs.PADD;
				
				gPanels.MTracker_Help = {};
				gPanels.MTracker_Help.panel = 'MTracker_Help';
				gPanels.MTracker_Help.immobilize = true;
				gPanels.MTracker_Help.dragable = false;
				gPanels.MTracker_Help.width = 610;
				gPanels.MTracker_Help.cssStyle = "blue";
				gPanels.MTracker_Help.db = true;
				
				break;
			default:
				break;
		}
	
	}
	
	if(lOK){
		var lContainer = document.getElementById("content");
		var lDivs = lContainer.getElementsByTagName("div");
		var lDiv = null;
		for(var x = 0; x<lDivs.length; x++){
			if(lDivs[x].id.indexOf(lOK) != -1){
				lDiv = lDivs[x];
				break;
			}
		}
		
		
		if(lDiv){
			//lDiv.style.height = "800px";
			lDiv.style.paddingTop = "0.5em";
			var lPath = '';
			var lSWF = gPaths.flash + "trackers/";
			lPath += lSWF + "condition_trackers.swf?pStatus=" + gUsers.login;
			// This forces the Migraine Tracker to start at the Add Record //
			if(lAdd){
				lPath += "&pAddRecord=true";
			}

			var so = new SWFObject(lPath, "tracker_id", "720", "1185", "9", "#ffffff");
			so.addParam("wmode", "transparent");
			so.addParam("allowScriptAccess", "always");
			so.addParam("base", lSWF);
			//so.write(lDiv);
			//gProps.flash.available = gProps.flash.flex;
			checkFlashValid({div:lDiv.id,obj:so});
			
		}
		
	}
	
	//content
}


/*********************************/
/******     CO-BRANDING     ******/
/*********************************/
function initCoBranding(){

	// do not do co-branding if disabled //
	// This allows us to remove it entirely or just 1 page //
	if(!gProps.co_branding.me.enabled){
		return;
	}

	// MAke sure the co-branding cookie exists //
	if(gProps.cookie_net && gProps.cookie_net.MECB){
		
		// Make sure the global object is defined for the particular partner //
		var lBrand = gProps.cookie_net.MECB.toLowerCase();
		var lBrandObj = gProps.co_branding[lBrand];
		if(!lBrandObj){
			//alert(gProps.co_branding[lBrand] + " not defined");
			return;
		}
		
		var lContainer = document.getElementById("full_screen_container");

		if(lContainer){
			var lDiv = document.createElement("div");
			lDiv.id = lBrand + "_co_branding_wrapper";
			lDiv.className = "co_branding_wrapper";
			var lContent = document.createElement("div");
			lContent.id = lBrand + "_co_branding_content"
			lContent.className = "co_branding_content";
			
			// Add the default merck disclaimer if applicable //
			if(lBrandObj.me_disclaimer){
				var lP = document.createElement("p");
				lP.id = "co_branding_disclaimer";
				lP.innerHTML = gProps.co_branding.me.disclaimer;
				lContent.appendChild(lP);
			}else{
				// Place holder for custom logic //
				// This is if a partner requires custom disclaimer etc. //
			}
			lDiv.appendChild(lContent);
			
			// Add the close "x" to the container //
			var lImage = document.createElement("img");
			lImage.className = "co_branding_close"
			lImage.src = gPaths.images + "buttons/close.gif";
			lImage.onclick = coBrandingClose; 
			lDiv.appendChild(lImage);

			// render the co-branding content on-screen //
			lContainer.insertBefore(lDiv,lContainer.childNodes[0]);
		}
	}
}

// Close Button Co-Branding function //
function coBrandingClose(){
	var lNode = this.parentNode;
	// make sure the parent nod is available //
	if(lNode.id){
		// hide the div //
		lNode.style.display = "none";
		// this ensures the co-branding will not display in initCoBranding() //
		cookie_delete({cookie:"MECB"});
	}
}

/******************************************/
/******     MIGRAINE EXPERIENCE      ******/
/******************************************/
function migraineExperience(){
	PMG_newWindow({loc:"/media/flash/migraine_experience/migraine_experience.aspx",name:"EXP_WINDOW",w:945,nochrome:true,scrollbars:true,resize:true,preferedV:730});
}

/*********************************/
/******     PAGE LOADS      ******/
/*********************************/
// This function is called on-load for every page within MerckEngage //
function ME_LoadFunction(){
	// disable IE 6 Please! //	
	if(gBrowser.ie6 && gProps.IE && gProps.IE.disableIE6){
		disableIE6Please();
	}

	// set in the config_pmg.js this allows any "a" tag containing "track_link" in the id to be tracked //
	if(gProps.global_tracking){
		if(window.attachEvent){
			document.attachEvent("onclick", initClickTracking);
		}else{
			document.addEventListener("click", initClickTracking, false);
		}
	}
	
	// make sure the gProps Object exists //
	if(typeof(gProps) == "object"){
		if(gProps.green_callout && gProps.green_callout.length){
			var lShow = true;
			for(var x = 0; x<gProps.green_callout.length; x++){
				var lPage = gProps.green_callout[x].toLowerCase();
				if((gProps.page.toLowerCase() == lPage) || (location.pathname == "/")){
					lShow = false;
					break;
				}
			}

			if(lShow){
				var lDiv = document.getElementById("dashboard_container_oa");
				if(lDiv){
					lDiv.style.display = "block";
				}
			}
		}
		
		// Add the PMG_textSize to the onload function //	
		if(gProps.textSize.enabled){
			PMG_textSize();
		}

	}
	//if(!this.frameElement && !this.opener){
	if(!this.frameElement){
		var lMegaDropDowns = true;
		for(var x = 0; x<gProps.megadd.length; x++){
			var lPage = gProps.megadd[x];
			if(gProps.page == lPage){
				lMegaDropDowns = false;
				break;
			}
		}
		
		if(lMegaDropDowns){
			loadGlobalTabs();
		}
		initTitlePop();
	}
	
	// show a lightbox if applicable //
	gLightBox.initOnload();

	
	if(gProps.carousel){
		if(gProps.carousel.condition_library){
			initConditionCarousel();
		}
		
		if(gProps.carousel.cta){
			initCTACarousel();
		}
	}
	
	var lContainer = document.getElementById("content_container");
	if(lContainer && !gProps.show_loading){
		lContainer.style.visibility = "visible";
	}
	
	if (gBrowser.vendor == "IE"){
    	document.documentElement.attachEvent('onmousedown',function(){event.srcElement.hideFocus=true});
	}

}

/*******************************************************************/
/***********************   HPP FUNCTIONS   *************************/
/*******************************************************************/
var gHpp_Popups = {};

function hpp_Popup(p){
	// error check //
	if(typeof(p)!= "object"){
		alert("Object must be passed to hpp_Popup()");
		return;
	}
	if(!p.panel){
		alert("panel is not defined in hpp_Popup()");
		return;
	}
	
	if(!p.align){
		alert("align is not defined in hpp_Popup()");
		return;
	}
	
	// this is the top container //
	if(!p.container){
		p.container = document.getElementById("content_container");
	}else{
		p.container = document.getElementById(p.container);
	}
	
	
	var lPanel = p.panel;
	
	if(!gHpp_Popups[lPanel]){
		// create the popup panel //
		//lPanel.style.display = "block";
		gHpp_Popups[lPanel] = {};
		gHpp_Popups[lPanel].panel = document.getElementById(lPanel);
		gHpp_Popups[lPanel].src_div = document.getElementById(p.align);
		gHpp_Popups[lPanel].container = p.container;
		gHpp_Popups[lPanel].pSwitchImage = p.switchImage;
		gHpp_Popups[lPanel].pBottomAlign = p.bottom_align;
		
		if(!gHpp_Popups[lPanel].panel || !gHpp_Popups[lPanel].src_div){
			alert("objects not found in hpp_Popup()");
			return;
		}
		
		gHpp_Popups[lPanel].closeAllPanels = function(){
			for(var i in gHpp_Popups){
				if(gHpp_Popups[i].pOpen){
					gHpp_Popups[i].closePanel();
				}
			}
		}
		
		gHpp_Popups[lPanel].openPanel = function(){
			this.closeAllPanels();
			this.pOpen = true;
			this.panel.style.visibility = "hidden";
			this.panel.style.display = "block";
			this.panel.style.position = "absolute";
			this.panel.style.zIndex = 901;
			this.setLoc();
			this.panel.style.visibility = "visible";

			// Firefox needs this to align images //
			if((gBrowser.vendor != "IE") && this.pSwitchImage){
				this.src_div.style.zIndex = 950;
				this.src_div.style.backgroundImage = 'url(/media/images/dashboard/tab_hi.gif)';
			}
		}
		
		gHpp_Popups[lPanel].closePanel = function(){
			this.pOpen = false;
			this.panel.style.visibility = "hidden";
			this.panel.style.display = "none";
			// Firefox needs this //
			if(gBrowser.vendor != "IE" && this.pSwitchImage){
				this.src_div.style.zIndex = 899;
				this.src_div.style.backgroundImage = 'url(/media/images/dashboard/tab.gif)';
			}
			// IE 6 hide the iframe //
			if(this.iframe){
				this.iframe.style.visibility = "hidden";
				this.iframe.style.display = "none";
			}
		}
		
		gHpp_Popups[lPanel].setLoc = function(){
			var src_div = PMG_getCoords(this.src_div);
			//gDebug.getVar(src_div)
			var offset = PMG_getCoords(this.container);
			var x = ((src_div.x-offset.x) - (this.panel.clientWidth-4)) + "px";
			var lTop = (this.pBottomAlign)? (this.panel.clientHeight-(src_div.height-2)) : 0;
			var y = (src_div.y-offset.y)-lTop + "px";
			
			
			//alert(src_div.y)
			//alert(offset.y)
			
			// IE 6 need an iFrame to cover dropdpwn lists //
			if(gBrowser.ie6){
				//var iFrame = document.getElementById("hpp_iframe");
				if(!this.iframe){
					this.iframe = document.createElement('iframe');
					this.iframe.id = "hpp_iframe";
					this.iframe.style.position = "absolute";
					this.iframe.style.background = "#ffffff";
					this.iframe.style.visibility = "hidden";
					this.iframe.style.display = "none";
					this.iframe.style.overflow = "hidden";
					this.iframe.frameBorder = "none";
					this.iframe.src = "/blank.html";
					this.container.insertBefore(this.iframe,this.container.childNodes[1]);
				}
			
				// position the iFrame IE 6 only //
				this.iframe.style.position = "absolute";
				this.iframe.style.zIndex = 900;
				this.iframe.style.visibility = "visible";
				this.iframe.style.width = this.panel.clientWidth + "px";
				this.iframe.style.height = (this.panel.clientHeight) + "px";
				this.iframe.style.left = x;
				this.iframe.style.top = y;
				this.iframe.style.display = "block";
			}
			this.panel.style.left = x;
			this.panel.style.top = y;
			//gDebug.getVar(src_div);
		}
		
	}
	
	if(gHpp_Popups[lPanel].pOpen){
		gHpp_Popups[lPanel].closePanel();
	}else{
		gHpp_Popups[lPanel].openPanel();
	}
}

// all HPP/Dashboard onclick events //
function dashboardClick(pObj){
	//gDebug.getVar(pObj);
	if(!pObj || !pObj.id){
		pObj = {id:null};
	}
	
	switch(pObj.id){
		case "calendar":
			hpp_Popup({panel:'hpp_calendar',align:'dashboard_cal_link'});
			break;
		case "coach":
			hpp_Popup({panel:'hpp_coach',align:'coach_click',switchImage:true});
			break;
		case "instructions":
			hpp_Popup({panel:'hpp_info',align:'info_click',switchImage:true,bottom_align:true});
			break;
		case "cg_instructions":
			hpp_Popup({panel:'cg_info',align:'cg_info_click',switchImage:true,bottom_align:true});
			break;
		case "meal_planner_tool":
		case "activity_planner_tool":
			// check if a user is loged in - called from the left nav column //
			var lPath = (pObj.id == "activity_planner_tool")? "/01_plan/activity/activity_planner/planner.aspx" : "/01_plan/nutrition/planner_mp.aspx";
			if(!gUsers.authenticated()){
				lPath += "?MODE=edit";
			}
			location.href = lPath;
			break;
		case "meal_preferences":
			// check if a user is loged in //
			if(gUsers.authenticated()){
				PMG_iFrame({id:'meal_preferences',loc:'/01_plan/nutrition/pref_mp.aspx'});
			}else{
				location.href = "/01_plan/nutrition/planner_mp.aspx?MODE=edit";
			}
			break;
		case "activity_preferences":
			if(gUsers.authenticated()){
				PMG_iFrame({id:'activity_preferences',loc:'/01_plan/activity/activity_planner/pref_ap.aspx'});
			}else{
				location.href = "/01_plan/activity/activity_planner/planner.aspx?MODE=edit";
			}
			break;
		case "articles_meal":
		case "articles_activity":
			PMG_iFrame({id:'articles_add',loc:'/01_plan/articles.aspx'});
			break;
		case "cancel_call":
			gLightBox.init({div:'ccr'});
			break;
		case "call_cancel_yes": // Cancel Heath Coach Call //
			__doPostBack('CCR_Cancel_Yes','');
			break;
		case "call_cancel_no":
			gPanel.ccr.closePanel();
			break;
		case "calories_burned":
			PMG_iFrame({id:'calories_burned',loc:'/01_plan/nutrition/cal_burn.aspx'});
			break;
		default:
			alert(pObj.id + " not found in dashboardClick()");
			break;
	}

}

function playHCCVideo(){
	var lContainer = document.getElementById("plan_landing_top");
	if(lContainer){
		var lCreate = document.createElement("div");
		//flv_id
		lCreate.id = "hcc_flv";
		lCreate.style.width = "435px";
		lCreate.style.height = "365px";
		//lCreate.style.border = "1px solid #bbbbbb";
		//lCreate.style.background = "url(/media/images/01_plan/hcc.jpg) no-repeat";
		lCreate.style.position = "absolute";
		lCreate.style.left = "0px";
		lCreate.style.top = "0px";
		lCreate.style.overflow = "hidden";
		
		//lContainer.parentNode.appendChild(lCreate);
		lContainer.appendChild(lCreate);
		var lPath = '';
		lPath += gPaths.flash + "av_player/av_player.swf?";
		lPath += (gUsers.visitor())? "p_video=" + gPaths.video + "hcc_rv.flv" : "p_video=" + gPaths.video + "hcc_hpp.flv";
		//lPath += "p_video=" + gPaths.video + "hcc.flv";
		lPath += "&p_width=435";
		lPath += "&p_height=365";
		lPath += "&p_auto_play=true";
		lPath += "&p_hide_controls=true";
		lPath += "&p_callAtEnd=hccVideoEnd";
		//lPath += "&p_image=" + gPaths.images + "01_plan/hcc.png";
		var so = new SWFObject(lPath, "flv_id", "435", "390", "8", "#ffffff");
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess", "always");
		so.write("hcc_flv");
	
		// IE needs this line to prevent <form></form> error //
		// http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=1 //
		if(gBrowser.vendor == "IE"){
			window.flv_id = document.forms[0].flv_id;
		}
	}
}

function initHCCVideo(){
	
	if(gProps && gProps.qs){
		if(gProps.qs.FVP == "true"){
			playHCCVideo();
			gProps.qs.FVP = "false";
			return;
		}
	}
	
	// video is only for registered users //
	if(gUsers.authenticated()){
		//var lContainer = document.getElementById("hcc_top");
		//var lContainer = document.getElementById("plan_landing_top");
		// Make the cookie unique to login user id //
		gCookie.props.name = "hccvideo_" + gUsers.login;
		gCookie.props.value = true;
		var lCookie = gProps.cookie["hccvideo_" + gUsers.login];
		// set to null for testing only //
		//lCookie = null;
		if(lCookie || !gProps.flash.available){
			hccVideoEnd();
		}else{
			cookieJar_write(gCookie.props);
		}
		
		if(!lCookie && gProps.flash.available){
			//showVideoBar();
			playHCCVideo();
		}
	}else{
		hccVideoEnd();
	}
		
}

function showVideoBar(){
	var lBar = document.getElementById("plan_landing_top");
	if(lBar){
		lBar.style.background = 'url("/media/images/01_plan/landing_gradient.jpg") left bottom repeat-x';
		lBar.style.minHeight = (gUsers.visitor())? "339px" : "325px";
		lBar.style.border = "0px solid #bbbbbb";
		if(gBrowser.ie6){
			lBar.style.height = (gUsers.visitor())? "339px" : "325px";
		}
	}
}

function hccVideoEnd(p){
	//initBullets();
	
	if(gProps && gProps.qs){
		if(gProps.qs.FVP == "true"){
			playHCCVideo();
			gProps.qs.FVP = "false";
			return;
		}
	}
	
	formatHCC_Panels();
	
	var lFlash = document.getElementById("hcc_flv");
	if(lFlash){
		lFlash.style.display = "none";
	}
	
	var lContent = document.getElementById("HCC_feature");
	if(lContent){
		// show the calorie balance callout //
		//createRoundedBox({divs:[{id:"calorie_balance_callout", className:"green"}]});
		//lContent.style.display = "block";
		lContent.style.visibility = "visible";
	}
	
}

function formatHCC_Panels(p){

	var lDiv = document.getElementById("content");
	if(lDiv){
		var lDivs = lDiv.getElementsByTagName("div");
		var lHTML = false;
		if(lDivs.length){
			for(var x = 0; x<lDivs.length; x++){
				if(lDivs[x].className == "hcc_plan_links"){
					if(lHTML){
						lDivs[x].innerHTML = lHTML;
						lHTML = false;
					}
					if(lDivs[x].id.indexOf("hcc_plan_links_") != -1){
						lHTML = lDivs[x].innerHTML;
						//lDivs[x+1].innerHTML = lDivs[x].innerHTML;
					}
				}
			}
			
		}
	}
		
}

// ********************************* //
//            Planners               //
// ********************************* //
function submitPreferences_AP(){
	gPanel.activity_preferences.closePanel();
	location.href = "/01_plan/activity/activity_planner/planner.aspx?MODE=edit";
	return false;
}

function submitPreferences_MP(){
	gPanel.meal_preferences.closePanel();
	location.href = "/01_plan/nutrition/planner_mp.aspx?MODE=edit";
	return false;
}

function skipThisStep(){
   	parent.gPanel.activity_preferences.closePanel();
   	parent.location.href = "/01_plan/activity/activity_planner/planner.aspx?MODE=edit";
}

function skipThisStep_MP(){
   	parent.gPanel.meal_preferences.closePanel();
   	parent.location.href = "/01_plan/nutrition/planner_mp.aspx?MODE=edit";
}


function showPlannerTutorial(pObj){
	
	var lPreviousPanel = pObj.prev_panel || null;
	
	if(!gPanel[pObj.id]){
		gPanels[pObj.id] = {};
		gPanels[pObj.id].panel = pObj.id;
		gPanels[pObj.id].immobilize = true;
		gPanels[pObj.id].dragable = false;
		gPanels[pObj.id].cssStyle = "blue";
		gPanels[pObj.id].width = 550;
		gPanels[pObj.id].script = closeAV_Panel;
		

		var lVideo = (gUsers.visitor())? "tutorial_getting_fit_oa.flv" : "tutorial_getting_fit.flv";
		var lGraphic = "activity/ap/instruction_video.jpg";
		if(pObj.id.indexOf("_mp") != -1){
			lVideo = (gUsers.visitor())? "tutorial_eating_well_oa.flv" : "tutorial_eating_well.flv";
			lGraphic = "nutrition/instruction_video.jpg";
		}
		
		var lPath = '';
			
		lPath += gPaths.flash + "av_player/av_player.swf?";
		lPath += "p_video=" + gPaths.video + lVideo;
		lPath += "&p_width=450";
		lPath += "&p_height=253";
		//lPath += "&p_auto_play=true";
		lPath += "&p_image=" + gPaths.images + lGraphic;
		var so = new SWFObject(lPath, "flv_id", "450", "278", "8", "#ffffff");
		
		// Create Divs //
		var lCreate = document.createElement("div");
		lCreate.id = pObj.id;
		lCreate.className = "alert_content";
		// create the flash wrapper //
		var lDiv = document.createElement("div");
		lDiv.id = "tutorial_" + pObj.id;
		// create the button wrapper //
		var lContainer = document.createElement("div");
		lContainer.className = "button_container_center";
		var w = '<a href="javascript:void(0);" class="orangeButton" onclick="gPanel.' + pObj.id + '.closePanel();return false;">Close</a>';
		lContainer.innerHTML = w;
		
		lCreate.appendChild(lDiv);
		//lCreate.appendChild(lContainer);
		document.body.appendChild(lCreate);
		
		gLightBox.init({div: pObj.id});
		checkFlashValid({obj:so,div:lDiv.id})
		//so.write(lDiv.id);
		
		if(gBrowser.vendor == "IE"){
			var lFlash = document.getElementById("flv_id");
			if(lFlash){
				window.flv_id = lFlash;
				//window.flv_id = document.forms[0]["flv_id"];
			}
		}
		

	}else{
		gPanel[pObj.id].openPanel();
	}
	
	gPanel[pObj.id].previous_panel = lPreviousPanel;
	
}

// This is called from the Add More Article LightBox "Submit" //
function submitArticles(){
	gPanel.articles_add.closePanel();
	//location.reload(false);
	location.href = location.href;
}

/* PM - Remove from planner.js */
function plannerViewRecipe(p){
	if (p.recipe == null) {
		PMG_iFrame({id:'recipe_view',loc:'/01_plan/nutrition/recipe_mp.aspx?RecipeID=' + p.id + '&MEAL=' + p.type});
	} else {
		PMG_iFrame({id:'recipe_view',loc:'/01_plan/nutrition/recipe_mp.aspx?RecipeID=' + p.id + '&MEAL=' + p.type + '&TABLE=' + p.recipe});
	}	
}

/*Priti - Created for iframe to show on Add Recipe Page */
function nutritionViewRecipe(p){
	PMG_iFrame({id:'recipe_view',loc:'/01_plan/nutrition/create_meal.aspx?RecipeID=' + p.id});
}

function close_CopyMeal(){
//alert();
	//PMG_iFrame({id:'recipe_view',loc:'/01_plan/nutrition/create_meal.aspx?RecipeID=' + p.id + '&MEAL=' + p.type});
	//PMG_iFrame({id:'recipe_view',loc:'/01_plan/nutrition/library_mp.aspx?RecipeID=' + p.id + '&MEAL=' + p.type});
}

function CopyMeal_Clicked(MealID, ConsumerID){
	var newMealName=document.getElementById("txtNewMealName").value;
	PageMethods.btnCopyMeal_clicked(MealID, ConsumerID, newMealName, CopyMeal_Clicked_Succeeded, CopyMeal_Clicked_Failed);
}

function CopyMeal_Clicked_Succeeded(result){
    //parent.gPanel.copy_meal.closePanel();
	parent.window.location.href = "library_mp.aspx?TYPE=favorites";
}

function CopyMeal_Clicked_Failed(error){
	//alert("CopyMeal_Clicked_Failed")
    //alert();
}

function initStateRestrictions(){
	
	//_ddstate
	var lStates = document.getElementsByTagName("select");
	var lState = null;
	if(lStates.length){
		for(var x = 0; x<lStates.length; x++){
			if(lStates[x].id){
				if(lStates[x].id.toLowerCase().indexOf("ddstate") != -1){
					lState = lStates[x];
					break;
				}
			}
		}
	}
	
	if(lState){
		// save the original values //
		lState.pState_from = lState.value.toUpperCase();
		lState.pID = lState.value.toLowerCase();
		
		lState.onchange = function(){
			var lValue = this.value.toUpperCase();
			var lShow = false;
			// get the state restriction values //
			this.pMove_from = (gProps.state_restrictions[this.pState_from])? gProps.state_restrictions[this.pState_from].from : false;
			this.pMove_to = (gProps.state_restrictions[lValue])? gProps.state_restrictions[lValue].to : false;

			if(this.pState_from != lValue){
				// show the content if a state is moved from //
				if(this.pMove_from){
					var lP = document.getElementById("sr_from_" + this.pState_from.toLowerCase());
					if(lP){
						lP.style.display = "block";
						lShow = true;
					}
				}

				if(this.pMove_to){
					var lValue = lValue.toLowerCase();
					var lP = document.getElementById("sr_to_" + lValue.toLowerCase());
					// this is only for member eligible for Health Coach Calls //
					if(gUsers.type == "HCC"){
						if((lValue == "ma") || (lValue == "ri") || (lValue == "dc")){
							var lP = document.getElementById("sr_to_ma_ri_dc");
						}
					}
					
					if(lP){
						lP.style.display = "block";
						lShow = true;
					}
				}

			}			
			
			if(lShow){
				gLightBox.init({div:"state_restrictions"})
			}
			
		}
	}
}

function migraine3dExit(){
	gPanel.migraine_journal.closePanel();
	/*
	var lDiv = document.getElementById("migraine_journal_content");
	var lContainer = document.getElementById("alert_container");
	if(lDiv){
		gPanel.migraine_journal.closePanel();
		lContainer.removeChild(lDiv);
		gPanel.migraine_journal = null;
	}
	*/
	
}

function migraine3dTracker(){
	location.href = "/01_plan/trackers/tracker.aspx?menuID=Migraine";
}

function initMigraineJournalWindow(){
	//PMG_newWindow({loc:gPaths.flash + "migraine_journal/migraine.html",nochrome:true})
	trackClick({track_name:'migraine_school'});
	PMG_newWindow({loc:gPaths.flash + "migraine_journal/migraine.aspx",nochrome:true,chrome:{scrollbars:"yes"}})
}


function initMigraineJournal(){

	if(!gPanel.migraine_journal){
	
		// MIGRAINE JOURNAL //
		gPanels.migraine_journal = {};
		gPanels.migraine_journal.panel = 'migraine_journal';
		gPanels.migraine_journal.immobilize = true;
		gPanels.migraine_journal.dragable = false;
		gPanels.migraine_journal.width = 850;
		gPanels.migraine_journal.cssStyle = "blue";
		gPanels.migraine_journal.script = function(){
			// remove the flash from the container //
			var lContainer = document.getElementById("migraine_journal");
			if(lDiv){
				lContainer.innerHTML = "";
			}
		}
	
		// Create Divs //
		var lCreate = document.createElement("div");
		lCreate.id = "migraine_journal";
		lCreate.className = "alert_content";
		document.body.appendChild(lCreate);
	}
	
	
	var so = new SWFObject(gPaths.flash + "migraine_journal/Migraine3d.swf", "Migraine3d", "800", "600", "9", "#FFFFFF");
	so.addParam("wmode", "opaque");
	//so.addParam("wmode", "transparent");
	so.addParam("migraine3dExit", "javascript:migraine3dExit();");
	so.addParam("migraine3dTracker", "javascript:migraine3dTracker();");
	so.addParam("expressinstall", gPaths.flash + "migraine_journal/scripts/expressInstall.swf");
	so.addVariable("sndpath", gPaths.flash + "migraine_journal/sound");
	so.addVariable("flvspath", gPaths.flash + "migraine_journal/flvs");
	//so.addVariable("MigraineJournalUrlMac", "MERCK_Migraine_Journal-MAC.zip");
	//so.addVariable("MigraineJournalUrlPc", "MERCK_Migraine_Journal-WIN.zip");
	//checkFlashValid({obj:so,div:"migraine_journal"})
	gLightBox.init({div:"migraine_journal"});
	so.write("migraine_journal");
}


/********************************************/
/*              PMG LIGHTBOX                */
/********************************************/
//w += '<div style="font-weight:bold;text-align:right;color:black;">&copy;blausen  2009</div>';
var gPanel = {};
function initPanels(){
	
	var lDiv = document.getElementById("window_immobilize");
	if(!lDiv){
		var lDiv = document.createElement('div');
		lDiv.id = "window_immobilize";
		// "internet explorer cannot open the internet site" "operation aborted"
		// IE ERROR //
		//It is not possible append to the BODY element from script that isn’t a direct child to the BODY element //
		//document.body.appendChild(lDiv);
	}
	
	for(var x in gPanels){
		var lPanel = document.getElementById(gPanels[x].panel + "_content");
		// make sure that the panel exists //
		if(lPanel){
			gPanel[x] = new PMG_panel(gPanels[x]);
			// init the global alerts only //
			// local alerts are initialized in the onclick //
			if(!gPanels[x].local){
				gPanel[x].content.innerHTML = initPanelContent({html:gPanel[x].content.innerHTML,style:gPanel[x].p_style,obj:gPanel[x]});
			}
		}
	}
}

function initPanelContent(p){

		var ws = '';
		ws += '<table class="alert_table" cellpadding="0" cellspacing="0" border="0">';
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/tl",ext:"png",scale:"scale",props:"no-repeat"});
		ws += '<tr><td class="alert_tl" style="' + lStyle + ';">';
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/t",ext:"png",scale:"scale",props:"repeat-x"});
		ws += '</td><td class="alert_top" style="' + lStyle + ';"></td>';
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/tr",ext:"png",scale:"scale",props:"no-repeat"});
		ws += '<td class="alert_tr" style="' + lStyle + ';"></td></tr>';
		
		// CONTENT //
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/l",ext:"png",scale:"scale",props:"repeat-y"});
		ws += '<tr><td class="alert_left" style="' + lStyle + ';width:15px;"></td>';
		//var lStyle = PMG_background({graphic:"alerts/default",ext:"png",scale:"scale",props:"repeat"});
		//ws += '<td id="alert_container_' + p.style + '" style="' + lStyle + ';" class="alert_content_td">';
		ws += '<td id="alert_container_' + p.obj.name + '" class="alert_content_td">';
		ws += '<div id="' + p.obj.name + '_drag" class="alert_close_container">';
		
		var lCoseButton = (p.obj.p_close_button)? "alert_close_" + p.obj.p_close_button : "alert_close";
		ws += '<a id="alert_close_' + p.obj.name + '" href="javascript:void(0);" class="' + lCoseButton +'" onclick=""></a></div>';
		ws += p.html + '</td>';
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/r",ext:"png",scale:"scale",props:"repeat-y;"});
		ws += '<td class="alert_right" style="' + lStyle + ';"></td></tr>'
	    
		// Add the bottom //
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/bl",ext:"png",scale:"scale",props:"no-repeat"});
		ws += '<tr><td class="alert_bl" style="' + lStyle + ';"></td>';
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/b",ext:"png",scale:"scale",props:"repeat-x"});
		ws += '<td class="alert_bottom" style="' + lStyle + ';"></td>';
		var lStyle = PMG_background({graphic:"alerts/" + p.style + "/br",ext:"png",scale:"scale",props:"no-repeat;"});
		ws += '<td class="alert_br" style="' + lStyle + ';"></td></tr>'
		ws += '</table>'
		
		return ws;
}

// ******************************************** //
//               LIGHTBOX ALERT   
// ******************************************** //
function PMG_panel(p){

	this.disable = document.getElementById("window_immobilize");
	this.container = document.getElementById("full_screen_container");
	this.site_container = document.getElementById("site_container");
	//this.title_bar = document.getElementById("alert_title_bar");
	this.p_enabled = false;
	this.p_open = false;
	this.p_initialized = false;
	this.p_local = p.local || false;
	this.p_top = p.top || false; // default will center popup in window //
	this.p_style = p.cssStyle || "white";
	this.p_script = p.script || null;
	this.p_leaveFields = p.leaveFields || false;
	this.p_hide_close = p.hide_close || false; // hide the close button //
	this.p_close_button = (p.closeButton)? p.closeButton : false; // allow custom close button /
	this.p_load_once = (p.load_once)? true : false;
	this.p_iFrame_loaded = false;
	this.panel = document.getElementById("alert_container");
	this.content = (typeof(p.local) != "undefined")? document.getElementById("local_content") : document.getElementById(p.panel + "_content");
	//this.title = (typeof(p.local) != "undefined")? document.getElementById("local_title") : document.getElementById(p.panel + "_title");
	this.immobilize = p.immobilize;
	this.p_immobilize_image = p.immobilize_image || "/media/images/alerts/window_immobilize.png";
	this.dragable = false; //p.dragable; force all drag features off //
	this._width = p.width;
	this.name = p.panel;
	this.location = p.location || 'center';
	this.buttons = {};//document.getElementById("alert_buttons").childNodes;
	this.previous_panel = p.previous_panel || null;
	this.clear_forms = p.clearForms || false;
	this.access_key = p.accessKey || false;
	this.tracking = (p.tracking)? true : false;
	this.show_top = (p.showTop)? true : false;
	this.hideOnOpen = (p.hideOnOpen)? document.getElementById(p.hideOnOpen) : false; // prop to hide site under the lightbox //

	
	this.closePanel = function(){
		this.p_enabled = false;
		this.p_open = false;
		this.showHideForms(true);
		this.assignKey();
		
		//this.title.style.display = "none";
		this.content.style.display = "none";
		this.panel.style.display = "none";
		this.panel.style.visibility = "hidden";
		this.disable.style.display = "none";
		this.disable.style.visibility = "hidden";
		
		// Clear the forms //
		this.clearFormsMe();
		// remove the onscroll behaviors //
		if(window.attachEvent){
			window.detachEvent("onscroll", gLightBox.onScroll);
			window.detachEvent("onresize", gLightBox.onResize);
		}else{
			window.removeEventListener("scroll", gLightBox.onScroll, false);
			window.removeEventListener("resize", gLightBox.onResize, false);
		}
			
		// execute additional script //
		if(this.p_script){
			this.p_script();
		}
	
		if(this.previous_panel){
			if(gPanel[this.previous_panel]){
				gPanel[this.previous_panel].openPanel();
			}else{
				alert(this.previous_panel + "does not exist in gPanels object");
			}
		}
	}
	
	// This function will clear the forms dialog //
	this.clearFormsMe = function(){
		if(this.clear_forms){
			var lInputs = this.content.getElementsByTagName('input');
			if(lInputs.length){
				for(var x = 0; x<lInputs.length; x++){
					switch(lInputs[x].type){
						case "text":
						case "password":
							lInputs[x].value = "";
							break;
						case "checkbox":
							lInputs[x].checked = false;
							break;
					}
				}
			}
			
			var lSpans = this.content.getElementsByTagName('span');
			if(lSpans.length){
				for(var x = 0; x<lSpans.length; x++){
					if(lSpans[x].className == "form_validation_text"){
						lSpans[x].style.display = "none";
					}
				}
			}			
		}
	}
	
	// this function will allow the Enter Key to execute the LightBox //
	// this.access_key needs to be set to the button id //
	// This is not functioning now, we should get this working //
	this.assignKey = function(pEnable){
		if(this.access_key){
			var lButton = document.getElementById(this.access_key);
			if(lButton){
				if(pEnable){
					// store the current keypress //
					this.pSave_onkeypress = document.onkeypress;
					gForms.enterKey = lButton;
					document.onkeypress = gForms.assignEnterKey;
				}else{
					// restore the current keypress //
					document.onkeypress = this.pSave_onkeypress;
				}
			}
		}
	}
	
	// IE 6 needs to hide all drop down forms //
	// this code is causing some funky behavior need to revisit //
	this.showHideForms = function(p_show){
		// check for dropdown form items to hide in IE 6 only //
		if(gBrowser.ie6){
			var lContent = document.getElementById("content");
			if(lContent){
				var lForms = lContent.getElementsByTagName('select');
				var lShow = (p_show == true)? "visible" : "hidden";

				if(lForms.length){
					for(var x = 0; x<lForms.length; x++){
						lForms[x].style.visibility = lShow;
					}
				}
			}
		}
	}

	this.checkFormLocation = function(pCoords){
		//gDebug.getVar(pCoords);
		//gDebug.getVar(this.p_rect)
		var lChange = false;
		if((pCoords.left > this.p_rect.left) & (pCoords.left < this.p_rect.right)){
			if((pCoords.top > this.p_rect.top) & (pCoords.top < this.p_rect.bottom)){
				lChange = true;
			}
		}
		
		return lChange;
	}
	
	// Called in the window.onScroll() to resize the lightbox //
	this.resizeDisable = function(){
		if(this.p_enabled){
			var lHeight = (document.documentElement.clientHeight)? document.documentElement.clientHeight : document.body.clientHeight;
			if(this.immobilize){
				var lScroll = document.body.scrollTop || document.documentElement.scrollTop;
				this.checkDisableExists();
				this.disable.style.width = (this.container.clientWidth-1) + "px";
				this.disable.style.height = (lHeight + lScroll) + "px";
			}
		}
	}
	
	this.centerPanel = function(pScroll){

		switch(this.location){
			case 'mouse':
				// alert(window.event.srcElement.offsetTop)
				this._top = 100;
				this._left = 100;
				
				break;
			default:
				//var lAvailableHeight = (window.innerHeight)? Math.round((window.innerHeight/2) + window.pageYOffset) : (document.documentElement.clientHeight/2) + document.documentElement.scrollTop;
				//var lContentHeight = (this.site_container.clientHeight/2)
				this._left = (document.body.clientWidth/2) - (this.panel.clientWidth/2);
				if(this.p_top){
					this._top = this.p_top;
				}else{
					this._top = (window.innerHeight)? ((window.innerHeight/2)-(this.panel.clientHeight/2) + window.pageYOffset) : (document.documentElement.clientHeight/2)-(this.panel.clientHeight/2) + document.documentElement.scrollTop;
					//document.documentElement.cumulativeScrollOffset
					//scrollHeight
				}
				break;
		}
		this.panel.style.left = this._left + "px";
		if(this._top < 25){
			this._top = 100;
		}else{
			this._top = (this._top-36);
		}
		
		// This allows the top of the LightBox to show up in the client view //
		if(this.show_top){
			var lScroll = document.body.scrollTop || document.documentElement.scrollTop;
			this._top = (lScroll + 10);
		}
		
		//this.panel.style.top = (this._top < 25)? "100px" : (this._top-36) + "px";
		this.panel.style.top = this._top + "px";
		this.panel.style.visibility = "visible";
		this.p_open = true;
		this.p_rect = {left:this._left,top:this._top,right:(this.panel.clientWidth+this._left),bottom:(this.panel.clientHeight+this._top)};
		//gDebug.getVar(this.p_rect)
	}

	this.checkDisableExists = function(){
		// Add the immobilize window //
		if(!this.disable){
			this.disable = document.createElement('div');
			this.disable.id = "window_immobilize";
			var lContainer = document.getElementById("full_screen_container");
			lContainer.appendChild(this.disable);
			//document.body.appendChild(this.disable);
		}
	}
	
	this.openPanel = function(){
		// IE 7 bug work around - with Flash video //
		if(this.p_restore){
			this.content.innerHTML = this.p_restore;
		}
		gLightBox.close_AllPanels();
		
		// IE 6 @#$%!!! //
		// hide Mega DropDowns //
		/*
		if(gTabs){
			for(var i in gTabs){
				if(gTabs[i].hideMe){
					gTabs[i].hideMe();
				}
			}
		}
		*/
		this.panel.style.width = this._width + "px";
		// display needs to be set in order to calculate width and height //
		this.panel.style.display = "block";
		this.content.style.display = "block";
		// local popup only swap content and title //
		if(this.p_local){
			this.content.innerHTML = initPanelContent({html:document.getElementById(this.name + "_content").innerHTML,style:this.p_style});
		}else{
		}
	
		// Show the panel //
		this.centerPanel();
		this.showHideForms();
		// pause video if playing //
		gLightBox.pauseAV();
		
		// do lightbox assigned in config_pmg.js //
		if(this.immobilize){
			this.checkDisableExists();
			// set the transparency for IE only //
			if((gBrowser.vendor == "IE") && !gBrowser.support_png){
				//this.disable.style.filter = 'alpha(opacity=50)';
				this.disable.style.background = "none";
				this.disable.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.p_immobilize_image + '",sizingMethod="scale")';
			}
			this.p_enabled = true;
			this.resizeDisable();
			this.disable.style.display = "block";
			//this.disable.style.width = "99.9%";
			this.disable.style.visibility = "visible";			
		}
		
		if(this.hideOnOpen){
			this.hideOnOpen.style.visibility = "hidden";
		}
		
		// Close function //
		var lClose = {};
		lClose.onclick = function test_close(){
			var lPanel = p.panel;
			if(p.local){
				lPanel = p.local;
			}
			//if(gBrowser.vendor == "IE"){location.reload();}
			gPanel[lPanel].closePanel();
		}
		
		// assign the close panel to the X //
		var lX = document.getElementById("alert_close_" + this.name);
		if(lX){
			// hide the close button //
			if(this.p_hide_close){
				lX.style.display = "none";
			}
			// allow for custon close scripts //
			if(this.p_script){
				//lClose.onclick = this.p_script; 
			}
			
			lX.onclick = lClose.onclick;
		}
		
		// BUTTONS //
		for(var x in this.buttons){
			if(this.buttons[x].id){
				this.buttons[x].onclick = function(){
					//gPanel[p.panel].closePanel();
					lClose.onclick();
					return false;
				}
			}
		}
		lClose.onmousedown = function(ev){
			// prevent the X from draging the window //
			if(gBrowser.vendor == "IE"){
				event.cancelBubble = true;
			}else{
				ev.stopPropagation();
			}
		}
		// make the panel dragable not working SSK 20081205 //
		if(this.dragable){
			document.onmousemove = move_Alert;
			//alert(this.name)
			this.drag_div = document.getElementById(this.name + "_drag");
			this.drag_div.style.cursor = "move";
			//this.title_bar.style.cursor = "move";
			//makeDraggable(this.title_bar);
			makeDraggable(this.drag_div);
		}else{
			//this.title_bar.style.cursor = "default";
			//this.drag_div.style.cursor = "default";
		}
		
		
		// This allows the lightbox to change size //
		if(window.attachEvent){
			window.attachEvent("onscroll", gLightBox.onScroll);
			window.attachEvent("onresize", gLightBox.onResize);
		}else{
			window.addEventListener("scroll", gLightBox.onScroll, false);
			window.addEventListener("resize", gLightBox.onResize, false);
		}
		
		this.assignKey(true);
		// check if object has an iFrame object //
		if(this.pFrame){
			this.pFrame.obj = this.content.getElementsByTagName("iframe")[0];
			if(this.pFrame.obj){
				if(!this.p_iFrame_loaded){
					if(this.pFrame.obj.src != this.pFrame.iframe){
						this.pFrame.obj.src = this.pFrame.iframe;
						// prevents the iFrame from loading again //
						if(this.p_load_once){
							this.p_iFrame_loaded = true;
						}
					}
				}
			}
		}
		
		// track that the lightbox was opened //
		if(this.tracking){
			trackClick({track_name:"lb_" + this.name});
		}

	}
	
	// SSK 20100930 - added for calorie burn tool //
	// should be added to other iFrame tools //
	this.resizeiFrame = function(obj){
		// IE needs to define pFrame.pContainer if the .aspx page posts back //
		//if(!this.pFrame.pContainer){
			var lDivs = this.pFrame.obj.contentWindow.document.getElementsByTagName("div");
			
			if(lDivs.length){
				for(var x = 0; x<lDivs.length; x++){
					if(lDivs[x].className == "iframe_content"){
						this.pFrame.pContainer = lDivs[x];
					}
				}
			}
		//}
		this.pFrame.obj.style.width = (this._width-75) + "px";
		this.pFrame.pContainer.style.width = (this._width-75) + "px";
		//alert(this.pFrame.obj.contentWindow.document.getElementById("calories_burned_iframe"))
		var lDivs = this.pFrame.obj.contentWindow.document.getElementsByTagName("div");
		if(lDivs.length){
			for(var x = 0; x<lDivs.length; x++){
				if(lDivs[x].className.indexOf("iframe_content") != -1){
					// SSK - does not work in IE 6 when iFrame reduces height. Use div height instead //
					//this.pFrame.obj.style.height = this.pFrame.obj.contentWindow.document.body.clientHeight + 'px';
					this.pFrame.obj.style.height = lDivs[x].clientHeight + "px";
					this.centerPanel();
					break;
				}
			}
		}
	}
	
}

// This function allows a sigle page to have custom popups //
// It must be added to the onload function in order to work properly //
function formatPagePanels(){

	var lDisable = document.getElementById("window_immobilize");
	var lContainer = document.getElementById("full_screen_container");	

	if(!lDisable){
		lDisable = document.createElement('div');
		lDisable.id = "window_immobilize";
		lContainer.appendChild(lDisable);
	}

	// this is to add a single .aspx pages gPanels //	
	var lHolder = document.getElementById('alert_container').parentNode;
	var lContent = document.getElementById("alert_container");
	lHolder.removeChild(lContent);
	lContainer.appendChild(lContent);
	
	initPanels();

}



function formatSinglePanel(obj){
	
	if(typeof(obj) != "object" || typeof(obj.panels) != "object"){
		alert("obj.panels need to be an array. Called in formatSinglePanel()");
		return;
	}

	var lAppend = false;
	if(!document.getElementById("window_immobilize")){
		var lCreate = document.createElement('div');
		lCreate.id = "window_immobilize";
		lAppend = true;
	}
	
	var lAlert = document.getElementById("alert_container");
	if(!lAlert){
		lAlert = document.createElement('div');
		lAlert.id = "alert_container";
	}

	var lContainer = document.getElementById("full_screen_container");	
	

	
	for(var x = 0; x<obj.panels.length; x++){
		// this is to add a single .aspx pages gPanels //	
		var lPanel = obj.panels[x];
		var lContent = document.getElementById(lPanel + "_replace");
		if(!lContent){return;}
		var lHolder = lContent.parentNode;
		var lHTML = lContent.innerHTML;
		lContent.innerHTML = "";
		lHolder.removeChild(lContent);
		//lContainer.appendChild(lContent);
		
		// Create the Content Divs //
		var lDiv = document.createElement('div');
		lDiv.id = lPanel + "_content";
		lDiv.className = "alert_content";
		lDiv.innerHTML = lHTML;
		lAlert.appendChild(lDiv);
		//alert(document.getElementById("window_immobilize").parentNode.nodeName)
	}
	
	if(lAppend){
		var lMashBaby = document.getElementById("full_screen_container");
		if(lMashBaby){
			lMashBaby.appendChild(lCreate);
			lMashBaby.appendChild(lAlert);
			//document.body.appendChild(lCreate);
			//document.body.appendChild(lAlert);
		}
	}

	
	initSinglePanel(obj.panels)
	
}

var gPopups = {};
gPopups.pCurrent = null;
gPopups.init = function(p){
	if(!gPopups[p.obj.id]){
		var lButton = new createDynamicPopup(p);
		gPopups[p.obj.id] = lButton;
	}
}

function initDynamicPopups(){
	var lA = document.getElementsByTagName("a");
	
	alert("initDynamicPopups() is deprecated, please remove it from \n\n" + location.href);
	
	if(lA.length){
		for(var x = 0; x<lA.length; x++){
			var ID = lA[x].id;
			// check each <a></a> to see if it is a rollover or click //
			var lOver = (ID.indexOf("popup_over") != -1);
			var lClick = (ID.indexOf("popup_click") != -1);
			if(lOver || lClick){
				lA[x].pStyles = lA[x].className;
				lA[x].pClick = lClick;
				lA[x].pOver = lOver;
				//var lButton = new createDynamicPopup(lA[x]);
				//gPopups.push(lButton);
			}
		}
	}
}

function createDynamicPopup(p){

	this.p_obj = p.obj;
	this.p_obj.pUse_iFrame = (p.iframe == true)? true : false;
	this.p_obj.pOver = (this.p_obj.id.indexOf("popup_over") != -1)? true : false;
	this.p_obj.className = "bodyLinks";
	var lStyles = p.style;
	this.p_obj.pPanel = p.obj.id.split("-")[0];
	var lDiv = document.getElementById(this.p_obj.pPanel + "_popup_content");
	this.p_obj.p_text = (lDiv)? lDiv.innerHTML : this.p_obj.title;
	this.p_obj.p_id = p.obj.id.split("-")[0];
	this.p_obj.id = this.p_obj.p_id; 
	this.p_obj.p_container = (p.container)? document.getElementById(p.container) : document.getElementById("full_screen_container");
	
	// allows custom sizes for the iFrame //
	if(lStyles){
		// offset has not been implemented yet //
		this.p_obj.pStyles = {w:false,h:false,l:false}
		for(var x in lStyles){
			this.p_obj.pStyles[x] = lStyles[x];
		}
		
	}else{
		this.p_obj.pStyles = null;
	}
	
	// IE 6 needs an iFrame @#$! //
	this.p_obj.initMe = function(){
		var iFrame = document.getElementById(this.pPanel + "_popup_iframe");
		if(iFrame && this.pUse_iFrame){
			this.p_frame = iFrame;
		}else{
			// create the iFrame //
			if(this.pUse_iFrame){
				var iFrame = document.createElement('iframe');
				iFrame.id = this.pPanel + "_popup_iframe";
				iFrame.className = "dynamic_iframe";
				iFrame.style.position = "absolute";
				iFrame.style.left = "0px";
				iFrame.style.top = "0px";
				iFrame.style.visibility = "hidden";
				iFrame.style.display = "none";
				iFrame.style.overflow = "hidden";
				iFrame.scrolling = "no";
				iFrame.frameBorder = "0";
				iFrame.src = "/blank.html";
				
				this.p_container.appendChild(iFrame);
				this.p_frame = iFrame;
			}
			
			var iPOP = document.createElement('div');
			iPOP.id = this.pPanel + "_dynamic_popup";
			iPOP.className = "dynamic_popup";
			iPOP.style.position = "absolute";
			iPOP.style.left = "0px";
			iPOP.style.top = "0px";
			iPOP.style.visibility = "hidden";
			iPOP.style.display = "none";
			iPOP.style.overflow = "hidden";
			this.p_container.appendChild(iPOP);
			
		}
	}
	
	// show or hide the iFrame popup //	
	this.p_obj.showMe = function(pShow){
		
		if(!this.p_content){
			//this.p_content = window.frames[0].document.getElementById("iframe_popup");
			this.p_content = document.getElementById(this.pPanel + "_dynamic_popup");
		}
		
		if(pShow){
			
			var lCoords = PMG_getCoords(this);
			//gDebug.getVar(lCoords)
			this.pOpen = true;
			// reset the previous object //
			if(gPopups.pCurrent && (gPopups.pCurrent != this)){
				gPopups.pCurrent.showMe(false);
			}
			gPopups.pCurrent = this;
			//this.scrollTopMe();
			this.p_ScrollTop = 0;
			if(this.p_frame){
				this.p_frame.style.position = "absolute";
				this.p_frame.style.zIndex = 900;
				this.p_frame.style.display = "block";
			}
			
			this.p_content.style.position = "absolute";
			this.p_content.style.zIndex = 901;
			this.p_content.style.display = "block";

			var lOffset_Left = 0;
			if(this.pStyles){
				if(this.pStyles.w){
					this.p_content.style.width = this.pStyles.w + "px";
				}
				if(this.pStyles.h){
					this.p_content.style.height = this.pStyles.h + "px";
				}
				
				if(this.pStyles.l){
					lOffset_Left = this.pStyles.l;
				}
				
			}		
			

			// default x,y = Above, Middle of <a></a> //
			var lX = (lCoords.right-(lCoords.width/2)) + lOffset_Left;
			var lY = (lCoords.y-(this.p_content.clientHeight+20)) - this.p_ScrollTop;
			this.p_content.innerHTML = this.p_text
			
			var lFrame = PMG_getCoords(this.p_content);
			this.p_content.style.height = lFrame.height + "px";
			this.p_content.style.width = lFrame.width + "px";
			
			var lContainer = (this.p_container.id == "full_screen_container")? PMG_getCoords(document.getElementById("site_container")) : PMG_getCoords(document.getElementById(this.p_container.id));
			//var lContainer = PMG_getCoords(document.getElementById("site_container"));
			//gDebug.getVar(lContainer)
			// prevent the popup from going outside to the right of the layout //
			if((lX + lFrame.width) > lContainer.right){
				//lX = (lContainer.right - (lFrame.width+15));
				lX = (lContainer.right - (lFrame.width+15));
				
			}
			
			// prevent the popup from going outside to the left //
			if(lX < lContainer.x){
				lX = (lContainer.x+15);
			}

			if(this.p_frame){
				this.p_frame.style.left = lX + "px";
				this.p_frame.style.top = lY + "px";
			}

			this.p_content.style.left = lX + "px";
			this.p_content.style.top = lY + "px";
			
			if(this.p_frame){
				this.p_frame.style.visibility = "visible";
			}
			this.p_content.style.visibility = "visible";
						
		}else{
			this.pOpen = false;
			this.p_content.style.visibility = "hidden";
			if(this.p_frame){
				this.p_frame.style.visibility = "hidden";
			}
		}
	}
	
	this.p_obj.scrollTopMe = function(){
		var lTop = 0;
		var p = this.parentNode;
		
		while(p.scrollTop >= 0){
			lTop += p.scrollTop;
			p = p.parentNode;
		}
		
		// Allow for the window sroll bar //
		var lOffset = document.documentElement.scrollTop;
		switch(gBrowser.vendor){
			case "Safari":
				lOffset = document.body.scrollTop;
				break;
			default:
				break;
		}
		
		this.p_ScrollTop = (lTop-lOffset);
	}
	
	
	this.p_obj.initMe();
	
	if(this.p_obj.pOver){
		// clear the title tag for rollover //
		this.p_obj.title = "";
		
		this.p_obj.onmouseover = function(e){
			//this.initMe();
			this.showMe(true);
		}
		
		this.p_obj.onmouseout = function(){
			this.showMe(false);
		}
		// init the original mouseover //
		this.p_obj.onmouseover();
	
	}else{
		this.p_obj.onclick = function(){
			//this.initMe();
			if(!this.pOpen){
				this.showMe(true);
			}else{
				this.showMe(false);
			}
			return false;
		}
		
		// init the original mouseclick //
		this.p_obj.onclick();
	
	}

}

// SSK NEW TITLE TAG POP UPS ADDED 20100910 //
function initTitlePop(p){
	//alert("initTitlePop() = " + location.href)
	var lA = document.getElementsByTagName("a");
	var lLinks = [];
	if(!p){
		p = {};
	}
	if(lA.length){
		for(var x = 0; x<lA.length; x++){
			var lID = lA[x].id;
			if(lID && lID.toLowerCase().indexOf("pmg_pop_") != -1){
				if(!lA[x].showMe){
					lLinks.push(lA[x]);
				}	
			}
		}
	}
	
	if(lLinks.length){
		for(var x = 0; x<lLinks.length; x++){
			if(p.create_id){
				lLinks[x].id = "pmg_pop_" + PMG_TimeStamp();
			}
			new titlePopLink(lLinks[x]);
		}
	}
}

function titlePopLink(p){
	p.pName = p.id.split("_").pop();
	p.pText = (document.getElementById(p.pName + "_popup_content"))? document.getElementById(p.pName + "_popup_content").innerHTML : p.title;
	p.title = "";
	p.pBottom = (p.id.indexOf("_bottom") != -1)? true : false;
	p.style.display = "inline-block";
	p.pDiv = null;
	
	p.onmouseover = function(e){
		this.pEvent = (e)? e : window.event;
		if(!this.pDiv){
			this.init();
		}
		this.showMe();
	}
	
	p.onmouseout = function(){
		this.pDiv.style.display = "none";
		//make sure remnents are not hanging around //
		var lDivs = document.body.getElementsByTagName("div");
		for(var x = 0; x<lDivs.length; x++){
			var lDiv = lDivs[x];
			if(lDiv.className && lDiv.className == "pop_content"){
				lDiv.style.display = "none";
			}
		}
		
	}
	
	p.showMe = function(){
		this.pCoords = mouseCoords(this.pEvent);
		this.pDiv.style.display = "block";
		var lScroll = (gBrowser.vendor == "IE")? document.documentElement.scrollTop : 0;
		lScroll -= (this.pDiv.clientHeight + this.clientHeight);
		this.pDiv.style.top = (this.pCoords.y + lScroll) + "px";
		if(this.pBottom){
			this.pDiv.style.top = (this.pCoords.y + lScroll) + (this.pDiv.clientHeight + (this.clientHeight+20)) + "px";
		}
		var lLeft = this.pCoords.x;

		if((lLeft + this.pDiv.offsetWidth) > document.body.clientWidth){
			lLeft = (lLeft - ((lLeft + this.pDiv.offsetWidth) - (document.body.clientWidth-10)));
		}
		
		
		this.pDiv.style.left = lLeft + "px";
		this.pDiv.style.visibility = "visible";
	}
	
	p.init = function(){
		this.pDiv = document.createElement('div');
		this.pDiv.id = this.pName + "_pop_content";
		if(gDebug && gDebug.tools == true){
			if(parent.gDebug){
				parent.gDebug.tracer(this.pDiv.id,true);
			}else{
				gDebug.tracer(this.pDiv.id,true);
			}
		}
		this.pDiv.className = "pop_content";
		this.pDiv.innerHTML = this.pText;
		document.body.appendChild(this.pDiv);
		
	}
	
	return p;
}

// This is needed for IE only Firefox by default will pause the AV //
// pID passes the ID of the flash control //
function closeAV_Panel(pID){
	if(gBrowser.vendor == "IE"){
		var lFlash = (pID)? document.getElementById(pID) : document.getElementById("flv_id");
		if(lFlash && lFlash.pauseVideo){
			lFlash.pauseVideo();
		}else{
			// IE 7 bug - allows for the video or audio to stop playing //
			/*
			this.p_restore = this.content.innerHTML;
			if(this.p_restore){
				this.content.innerHTML = "";
			}
			*/
		}
	}
}

function GetInnerSize() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}

// allows for a single panel to be added to the global panels array //
function initSinglePanel(p){
	var lPanels = p;
	
	if(typeof(p) != "object"){
		lPanels = [p];
	}
	
	for(var x =0; x<lPanels.length; x++){
		gPanel[lPanels[x]] = new PMG_panel(gPanels[lPanels[x]]);
		// init the global alerts only //
		// local alerts are initialized in the onclick //
		if(!gPanel[lPanels[x]].local){
			gPanel[lPanels[x]].content.innerHTML = initPanelContent({html:gPanel[lPanels[x]].content.innerHTML,style:gPanel[lPanels[x]].p_style,obj:gPanel[lPanels[x]]});
		}
	}
}

// ********************************* //
//   Opens a gPanel with an iFrame   //
// ********************************* //
function PMG_iFrame(p){
	if(p.div){
		p.id = p.div;
	}
	var iFrame = document.getElementById("iframe_" + p.id);
	//var iSrc = p.loc; // PM - needed to add to reload the iFrame
	// create the iFrame //
	if(!iFrame){
		var iFrame = document.createElement("iframe");
		iFrame.id = "iframe_" + p.id;
		iFrame.style.position = "relative";
		iFrame.style.left = "0px";
		iFrame.style.top = "0px";
		iFrame.style.visibility = "visible";
		iFrame.style.display = "block";
		iFrame.style.overflow = "hidden";
		iFrame.scrolling = "no";
		iFrame.frameBorder = "0";
		iFrame.src = "/common/popup.html";
		//iFrame.src = p.loc;

		// Check to see if the immobilize div exists //
		var lAppend = false;
		if(!document.getElementById("window_immobilize")){
			var lWindow = document.createElement('div');
			lWindow.id = "window_immobilize";
			lAppend = true;
		}
		
		// Check to see if the alert container exists //
		var lAlert = document.getElementById("alert_container");
		if(!lAlert){
			lAlert = document.createElement('div');
			lAlert.id = "alert_container";
		}
		
		// creat a reference to the main site container //
		var lContainer = document.getElementById("full_screen_container");	
	
		// Create the Content Divs //
		var lDiv = document.createElement('div');
		lDiv.id = p.id + "_content";
		lDiv.className = "alert_content";
		lDiv.appendChild(iFrame);
		//iFrame.src = "planner_iframe.aspx";
		lAlert.appendChild(lDiv);
		//alert(document.getElementById("window_immobilize").parentNode.nodeName)
	
		if(lAppend){
			document.body.appendChild(lWindow);
			document.body.appendChild(lAlert);
		}
		// IE need this after the blank.html file is loaded //
		initSinglePanel([p.id])
	} else {
		//iFrame.src = "http://www.google.com";
		//iFrame.src = iSrc; // Need to reload the iFrame
		//iFrame.src = p.loc;
	}
	
	if(iFrame.src != p.loc){
		//iFrame.src = p.loc;
	}
	gPanel[p.id].pFrame = {iframe:p.loc,pDefaultSrc:"/common/popup.html"}
	gPanel[p.id].openPanel();
	//iFrame.src = (p.loc)? p.loc : "http://www.google.com";
	//alert("PMG_iFrame('" + pObj.id + "') \nWe will use an iFrame to display this content.")
}


gLightBox.init = function(p){
	if(typeof(p) != "object"){
		alert("Object not passed to gLightBox.init()");
		return;
	}
	
	// check if the panel already exists //
	if(gPanel[p.div]){
		gPanel[p.div].openPanel();
	}else{
		// create and launch the panel //
		if(!gPanels[p.div]){alert(p.div + " not defined in gPanels"); return;}
		
		if(gPanels[p.div]){
			if(gPanels[p.div].iFrameLoc && !p.loc){
				p.loc = gPanels[p.div].iFrameLoc;
			}
		}
		
		if(p.loc){
			PMG_iFrame(p);
			return false;
		}

		var lContent = document.getElementById(p.div);
		
		switch(p.div){
			case "loading_panel":
			case "saving_panel":
				lContent = document.createElement("div");
				lContent.id = p.div;
				lContent.innerHTML = (p.div == "saving_panel")? "<p>Saving Data...</p>" : "<p>Loading Data...</p>";
				document.body.appendChild(lContent);
				break;
		}
		
		
		if(!lContent && !gPanels[p.div].db){
			alert(p.div + " not found on page\n" + location.href); 
			return;
		}
		
		// Check to see if the immobilize div exists //
		var lAppend = false;
		if(!document.getElementById("window_immobilize")){
			var lCreate = document.createElement('div');
			lCreate.id = "window_immobilize";
			lAppend = true;
		}
		
		// Check to see if the alert container exists //
		var lAlert = document.getElementById("alert_container");
		if(!lAlert){
			lAlert = document.createElement('div');
			lAlert.id = "alert_container";
		}
	
		if(gPanels[p.div].db){
			var lDiv = document.createElement('div');
			lDiv.id = p.div + "_content";
			lDiv.className = "alert_content";
			lAlert.appendChild(lDiv);
			gLightBox.props.db = p.div;
			//gLightBox.getDatabase_content(p);

			Sys.Net.WebServiceProxy.invoke('/GlobalMethods.asmx', 'GetGenericLightBox', true, {"strTitle":p.div} , gLightBox.populateLightBox);
			/*
			if(PageMethods && PageMethods.GetGenericLightBox){
				PageMethods.GetGenericLightBox(p.div, gLightBox.populateLightBox)
				
			}else{
				alert("PageMethods.GetGenericLightBox() not defined in " + unescape(location.href));
				return;
			}
			*/
		}else{
			// creat a reference to the main site container //
			var lContainer = document.getElementById("full_screen_container");	
				
			// Get the parent of the content div //	
			var lHolder = lContent.parentNode;
			var lClone = lContent.cloneNode(true);
			lClone.style.display = "block";
			var lHTML = lContent.innerHTML;
			lHolder.removeChild(lContent);
	
			// Create the Content Divs //
			var lDiv = document.createElement('div');
			lDiv.id = p.div + "_content";
			lDiv.className = "alert_content";
			lDiv.appendChild(lClone);
			lAlert.appendChild(lDiv);
		}
		
		if(lAppend){
			var lMashBaby = document.getElementById("full_screen_container");
			if(lMashBaby){
				lMashBaby.appendChild(lCreate);
				lMashBaby.appendChild(lAlert);
				//document.body.appendChild(lCreate);
				//document.body.appendChild(lAlert);
			}
		}
		
		initSinglePanel([p.div])
		if(gPanels[p.div].db){
			// this is needed to make sure the content is centered //
			gPanel[p.div].centerPanel();
			setTimeout('gPanel["' + p.div + '"].openPanel()',100);
		}else{
			gPanel[p.div].openPanel();
		}
	}
	
}


gLightBox.populateLightBox = function(pResult){


	if(gLightBox.props.db){
		var lButtons = [{id:"close",label:"Close"}];
		
		if(gPanels[gLightBox.props.db].buttons){
			lButtons = gPanels[gLightBox.props.db].buttons;
		}

		if(lButtons.length){
			var lButton_wrapper = document.createElement('div');
			if(gPanels[gLightBox.props.db].button_loc){
				lButton_wrapper.className = "button_container_" + gPanels[gLightBox.props.db].button_loc;
			}else{
				lButton_wrapper.className = (lButtons.length == 1)? "button_container_center" : "button_container_right";
			}
			// Create the Buttons //
			for(var x = 0; x<lButtons.length; x++){
				//gDebug.getVar(lButtons[x]);
				var lA = document.createElement('a');
				lA.p_id = gLightBox.props.db
				lA.id = gLightBox.props.db + "_" + lButtons[x].id.toLowerCase();
				lA.className = lButtons[x].className || "orangeButton";
				lA.href = "javascript:void(0);";
				lA.style.marginLeft = (lButtons.length == 1)? "0px" : "10px";
				// all buttons need an id and a label //
				if(lButtons[x].id){
					if(!lButtons[x].action){
						// default close button //
						lA.onclick = function(){
							gPanel[this.p_id].closePanel();
						}
					}else{
						// this is for custom "Submit" button //
						lA.pSaveClick = lButtons[x].action;
						lA.onclick = function(){
							eval(this.pSaveClick);
						}
					}
				}
				
				var lText = document.createTextNode(lButtons[x].label);
				lA.appendChild(lText);
				lButton_wrapper.appendChild(lA);
			}
		}

		var lContainer = document.getElementById("alert_container_" + gLightBox.props.db);
		var lDiv_content = document.createElement('div');
		lDiv_content.id = gLightBox.props.db;
		lDiv_content.className = "alert_content_db";
		lDiv_content.innerHTML = pResult;
		lContainer.appendChild(lDiv_content);
		
		if(lButtons.length){
			lContainer.appendChild(lButton_wrapper);
		}
		
		// see if any bullets need formatting //
		if(lDiv_content.innerHTML.indexOf("bullets_wrapper") != -1){
			initBullets({div:gLightBox.props.db});
		}
		
		
	}else{
		//alert(result)
	}
}

// this function resizes the screen //
gLightBox.onScroll = function(){
	for(var x in gPanel){
		if(gPanel[x].p_enabled){
			gPanel[x].resizeDisable();
			break;
		}
	}
}

// centers the alert lightbox in the window //
gLightBox.onResize = function(){
	for(var x in gPanel){
		if(gPanel[x].p_enabled){
			gPanel[x].resizeDisable(true);
			gPanel[x].centerPanel();
			break;
		}
	}
}

// called when a lightbox is closed //
gLightBox.close_AllPanels = function(){
	for(var x in gPanel){
		if(gPanel[x].p_open){
			if(typeof(gPanel[x].closePanel) == "function"){
				gPanel[x].closePanel();
			}
		}
	}

	//document.onmousemove = "";
	//document.onmouseup = "";
	//gDND_Object = null;
}

// this is called when a lightbox is opened //
gLightBox.pauseAV = function(pID){
	var lFlash = (pID)? document.getElementById(pID) : document.getElementById("flv_id");
	if(lFlash && lFlash.pauseVideo){
		//alert("lFlash = " + lFlash + "\nlFlash.pauseVideo = " + lFlash.pauseVideo);
		lFlash.pauseVideo();
	}
}

gLightBox.loadingData = function(){
	//document.body.style.cursor = "wait";
	gLightBox.init({div:"loading_panel"});
}

gLightBox.loadingData_Done = function(){
	document.body.style.cursor = "default";
	if(gPanel.loading_panel){
		gPanel.loading_panel.closePanel();
	}
}

gLightBox.savingData = function(){
	//document.body.style.cursor = "wait";
	gLightBox.init({div:"saving_panel"});
}

gLightBox.savingData_Done = function(){
	document.body.style.cursor = "default";
	if(gPanel.saving_panel){
		gPanel.saving_panel.closePanel();
	}
}


gLightBox.showRecipeLightBox = function(){
	if(gProps.qs.RECIPEID){
		//gDebug.getVar(gProps.qs);
		//RecipeID=' + p.id + '&MEAL=' + p.type + '&TABLE=' + p.recipe
		plannerViewRecipe({id:gProps.qs.RECIPEID,type:gProps.qs.MEAL,recipe:gProps.qs.TABLE})
	}
}

// Enables a LightBox to display onload //
gLightBox.initOnload = function(){
	if(gProps && gProps.qs){
		if(gProps.qs.LB){
			var lBox = gProps.qs.LB.toLowerCase();
			if(gPanels[lBox]){
				if(gPanels[lBox].is_iframe){
					switch(lBox){
						case "calories_burned":
							dashboardClick({id:'calories_burned'});
							break;
						default:
							alert("gProps.qs.LB = " + lBox + "\nNot defined in gLightBox.initOnload()");
							break;
					}

				}else{
					gLightBox.init({div:lBox});
				}
			}
		}
	}
}

gLightBox.dbLink = function(p){

	switch(p.panel){
		case "already_connected_hcp":
			location.href = "/99_Admin/MyProfile.aspx";
			break;
		default:
			alert("Panel not found in gLightBox.dbLink()");
			break;
	}
}

/***********************************************/
/************  GENERIC FUNCTIONS  **************/
/***********************************************/
function showPanel(pObj){
	
	var lPreviousPanel = null;
	
	if(pObj.previousPanel){
		lPreviousPanel = pObj.previousPanel;
	}
	
	gLightBox.init({div:pObj.panel});
	gPanel[pObj.panel].previous_panel = lPreviousPanel;
	
	if(pObj.panel == "coach_calls"){
		var so = new SWFObject(gPaths.flash + "av_player/av_player.swf?p_type=audio&p_auto_play=false", "flash_mp3_id", "350", "50", "8");
		so.addParam("salign", "tl");
		//so.write("flash_audio");
		checkFlashValid({obj:so,div:"flash_audio"});
		if(gHpp_Popups && gHpp_Popups.hpp_coach){
			gHpp_Popups.hpp_coach.closePanel();
			//initBullets({div:"coach_calls"});
		}
	}
	
}

// This function is called from the iFram onload //
function initHeights(containers){
    // defaults if not passed //
	if (!containers){
        containers = {};
    }
	
	containers.iframe_id = containers.iframe_id || 'iframe_view';
    containers.main_id = containers.main_id || 'main_container';
    containers.content_id = containers.content_id || 'content_wrapper';

    var iFrameID = parent.document.getElementById(containers.iframe_id);
    var mainID = document.getElementById(containers.main_id);
    var contentID = document.getElementById(containers.content_id);
	
	//alert("iFrameID = " + iFrameID + "\nmainID = " + mainID + "\ncontentID = " + contentID)
	if(iFrameID && mainID && contentID){
		// Change the heights of the wrapper and iframe to the accomodate all of the content, this will remove the need for the inner scrollbar
		mainID.style.height = contentID.clientHeight + 5 + 'px';
		iFrameID.style.height = contentID.clientHeight + 'px';
		// we may want to call this too //
		if(parent.gPanel && parent.gPanel.recipe_view){
			parent.gPanel.recipe_view.centerPanel();
		}
	}
}

function initLibraryVideo(){

	if(gVideos[gProps.library.category] && gVideos[gProps.library.category].video){
		
		var lContainer = document.getElementById("library_video_link_wrapper");
		var lGraphic = document.getElementById("img_library_video_link");
		var lLink = document.getElementById("library_video_link");
		if(lContainer){
		
			gPanels.library_video = {};
			gPanels.library_video.panel = "library_video";
			gPanels.library_video.immobilize = true;
			gPanels.library_video.dragable = false;
			gPanels.library_video.cssStyle = "blue";
			gPanels.library_video.width = 400;
			gPanels.library_video.script = closeAV_Panel;
			
			
			
			lGraphic.src = gPaths.images + "library/vid_" + gProps.library.category + ".jpg";
			lGraphic.onclick = function(){
				//alert(gVideos[gProps.library.category].video);
				if(gPanel.library_video){
					gPanel.library_video.openPanel();
				}else{
					var lCreate = document.createElement("div");
					lCreate.id = "library_video";
					lCreate.style.textAlign = "center";
					lCreate.className = "alert_content";
					// create the flash wrapper //
					var lDiv = document.createElement("div");
					lDiv.id = "library_video_wrapper";
					
					var lBlausen = document.createElement("div");
					lBlausen.id = "blausen";
					
					lCreate.appendChild(lDiv)
					lCreate.appendChild(lBlausen)
					document.body.appendChild(lCreate);
				
					var lPath = '';
					lPath += gPaths.flash + "av_player/av_player.swf?";
					lPath += "p_video=" + gPaths.video + gProps.library.category + ".flv";
					var so = new SWFObject(lPath, "flv_id", "320", "265", "8", "#000000");
					so.addParam("wmode", "transparent");
					
					gLightBox.init({div:'library_video'});
					checkFlashValid({obj:so,div:"library_video_wrapper"});
					//so.write("library_video_wrapper");
					
					
					if(gBrowser.vendor == "IE"){
						var lFlash = document.getElementById("flv_id");
						if(lFlash){
							window.flv_id = lFlash;
						}
						//window.flv_id = document.forms[0]["flv_id"];
					}

					
				}
			}
			
			lLink.onclick = lGraphic.onclick;
			
			//gLightBox.init({div:'library_video'})
			
			//alert(lGraphic)
			
			lContainer.style.display = "block";
		}
		
	}
}

// ********************************* //
// VALIDATE THE E_MAIL RECIPE DIALOG //
// ********************************* //
function emailRecipe_click(p){
	//gDebug.getVar(p.recipe)
	gPanel.recipe_view.saveUrl = true;
	// Save the gPanel.planner_dd if available //
	gPanel.recipe_view.previous_panel_save = gPanel.recipe_view.previous_panel;
	gPanel.recipe_view.previous_panel = null;
	
	gLightBox.init({div:"email_recipe"});
	
	gPanel.email_recipe.emailClose = function(){
		gPanel.recipe_view.openPanel();
		// Restore the planner_dd panel if available //
		if(gPanel.recipe_view.previous_panel_save){
			gPanel.recipe_view.previous_panel = gPanel.recipe_view.previous_panel_save;
		}
	}
	
	
	// Initialize the form validations //
	if(!gPanel.email_recipe.p_form_fields){
		// this was getting all the fiels in the alert container - just needs the fields in the e-mail form //
		//gPanel.email_recipe.p_form_fields = gPanel.email_recipe.panel.getElementsByTagName("input");
		gPanel.email_recipe.p_form_fields = gPanel.email_recipe.content.getElementsByTagName("input");
		// attach methods //
		for(var x = 0; x<gPanel.email_recipe.p_form_fields.length; x++){
			var lField = gPanel.email_recipe.p_form_fields[x];
			var lID = (lField.id.indexOf("email_recipe_id_") != -1)? lField.id.split("email_recipe_id_")[1] : lField.id;
			gPanel.email_recipe.p_form_fields[x].pID = lID;
			var lError = (lField.id.indexOf("email_recipe_id_") != -1)? lField.id.split("email_recipe_id_")[1]+"_error" : lField.id+"_error";
			lField.error_text = document.getElementById(lError);
			lField.type_text = document.getElementById(lField.id + "_copy");
			
			if(lField.type_text){
				lField.onkeyup = function(){
					this.type_text.innerHTML = this.value;
				}
			}
			
			lField.showError = function(pShow){
				var lVisible = (pShow)? "visible" : "hidden";
				if(this.error_text){
					this.error_text.style.visibility = lVisible;
				}
			}
			
			lField.onfocus = function(){
				this.showError();
			}
							
			
			if(lID.indexOf("email") != -1){
				lField.p_email = true;
			}
			
		}
		
	}		
	
	// redifine the close button on the LightBox //
	var lButton = document.getElementById("alert_close_email_recipe");
	if(lButton){
		lButton.onclick = gPanel.email_recipe.emailClose;
	}

	gPanel.email_recipe.validate = function(){

		var lOK = true;
		// Make sure all fields are not empty //
		//gDebug.getVar(this.p_form_fields)
		for(var x = 0; x<this.p_form_fields.length; x++){
			var lField = this.p_form_fields[x];
			var lValue = gForms.trim(lField.value);
			if(lValue == ""){
				lField.showError(true);
				lOK = false;
			}
		}

		// Validate E-mail fields //
		for(var x = 0; x<this.p_form_fields.length; x++){
			var lField = this.p_form_fields[x];
			var lValue = gForms.trim(lField.value);

			// make sure all fields are not empty //
			if(lField.p_email){
				if(!gForms.validEmail({email:lValue})){
					lField.showError(true);
					lOK = false;
				}
			}
		}
	
		if(lOK){
			var props = {}
			for(var x = 0; x<gPanel.email_recipe.p_form_fields.length; x++){
				var lField = gPanel.email_recipe.p_form_fields[x];
				props[lField.pID] = gForms.trim(lField.value);
			}
		
			//gDebug.getVar(props);
			/*
			email_from = wilburSmith@youplace.net
			name_from = Wilbur
			recipient_email = this@that.com
			recipient_name = Scott
			*/
			
			//SendRecipeByEmail(string strToName, string strToEmail, string strFromName, string strFromEmail, string recipeID)
			if(Sys.Net.WebServiceProxy){
				gLightBox.init({div:"email_recipe_thankyou"});
				gPanel.email_recipe_thankyou.showRecipe = function(){
					gPanel.recipe_view.openPanel();
				}

				Sys.Net.WebServiceProxy.invoke('/GlobalMethods.asmx', 'SendRecipeByEmail', false, {"strToName":props.recipient_name,"strToEmail":props.recipient_email,"strFromName":props.name_from,"strFromEmail":props.email_from,"recipeID":p.recipe.loc.split("?")[1],"recipeImage":p.recipe.image,"recipeTitle":p.recipe.title});
			}else{
				alert("Sys.Net.WebServiceProxy not found in \n" + location.href)
			}
		}


	}

}

// setup the condition library carousel //
function initConditionCarousel(){
	
	//var lTemp = document.getElementById("Condition_Library_Content").getElementsByTagName("div");
	var lCarousel = document.getElementById("condition_carousel");
	if(!lCarousel){
		return;
	}
	var lDivs = lCarousel.getElementsByTagName("div")
	var lConditions = [];
	var lTitles = [];
	if(lDivs.length){
		for(var x = 0; x<lDivs.length; x++){
			if(lDivs[x].className == "condition_carousel_container"){
				lConditions.push(lDivs[x]);
				lTitles.push(lDivs[x].getElementsByTagName("p")[0].innerHTML);
			}
		}
	}
	
	if(lConditions.length){
		for(var x = 0; x<lConditions.length; x++){
			var lSizes = lConditions[x].getElementsByTagName("div");
			var lLeft = null;
			var lRight = null;

			for(var i = 0; i<lSizes.length; i++){
				if(lSizes[i].className == "condition_carousel_left"){
					lLeft = lSizes[i];
				}else{
					if(lSizes[i].className == "condition_carousel_right"){
						lRight = lSizes[i];
					}
				}
			}
			
			if(lLeft && lRight){
				if(lRight.clientHeight < lLeft.clientHeight){
					lRight.style.height = lLeft.clientHeight + "px";
				}
			}
			
			//alert(lConditions[x])
			//alert(lConditions[x].clientWidth)
		}
	}
	
	lCarousel.style.width = (lConditions[0].clientWidth * lConditions.length) + "px";
	//alert(lCarousel.clientWidth)

	//lCarousel.innerHTML = lConditions[0];
	//Effect.Fade(lCarousel,{duration:3.0,from:0,to:1});

	afterFinish = function(){
		//lCarousel.style.visibility = "visible";
		//new Effect.Move(this.pObj, { x: -720, y: 0, mode: 'relative' });
		//alert("initButtons");
		var lDiv = document.getElementById("condition_carousel_controls");
		var lA = [];
		if(lDiv){
			lA = lDiv.getElementsByTagName("img");
		}
		
		if(lA.length){
			for(var x = 0; x<lA.length; x++){
				lA[x].pCarousel = this.pObj.carousel;
				lA[x].pConditions = this.pObj.conditions;
				lA[x].pTitles = this.pObj.titles;
				gButtons[lA[x].id] = new conditionCarouselButton(lA[x])
				//gButtons[lA[x].id].obj = lA[x];
			}
		}
		
		gButtons.right.scaleCarousel();
		gButtons.right.enableMe();
		gButtons.right.updateTitleMe();
	}
	
	//lCarousel.style.visibility = "hidden";
	//var lAnimate = new Effect.Move(lConditions[0], {pObj:lConditions[0],afterFinish:afterFinish,x: 720, y: 0, mode: 'relative' });
	lCarousel.style.visibility = "visible";
	var lAnimate = new Effect.Move(lCarousel, {pObj:{titles:lTitles,carousel:lCarousel,conditions:lConditions},afterFinish:afterFinish,x: -725, y: 0, mode: 'relative' });
	
	

}

//var gButtons = {};
function conditionCarouselButton(p){
	//gDebug.getVar(p)
	p.pImages = {disabled:p.src};
	p.pImages.lo =  gPaths.images + "buttons/cc_" + p.id + "-lo.gif";
	p.pImages.hi =  gPaths.images + "buttons/cc_" + p.id + "-hi.gif";
	p.pEnabled = false;
	p.pCurrentSlide = 1;
	p.pLastSlide = p.pConditions.length;
	p.pIncrement = (p.id == "right")? +1 : -1;
	p.pAnimating = false;
	p.pButton = (p.id == "right")? "left" : "right";
	p.pTitle = document.getElementById("condition_carousel_title");
	
	p.enableMe = function(){
		this.src = this.pImages.lo;
		this.style.cursor = "pointer";
		this.pEnabled = true;
	}
	
	p.disableMe = function(){
		this.src = this.pImages.disabled;
		this.style.cursor = "default";
		this.pEnabled = false;
	}
	
	
	p.onmouseover = function(){
		if(this.pEnabled){
			this.src = this.pImages.hi;
		}
	}

	p.onmouseout = function(){
		if(this.pEnabled){
			this.src = this.pImages.lo;
		}
	}

	
	p.onclick = function(){
		if(this.pEnabled && !this.pAnimating){
			this.pAnimating = true;
			this.nextSlide();
		}
	}
	
	
	p.nextSlide = function(){
		var lMove = (this.id == "right")? -this.pConditions[0].clientWidth : this.pConditions[0].clientWidth;
		//new Effect.Move(this.pCarousel,{pButton:this,afterFinish:this.afterFinish,x:lMove,y:0,mode:'relative',transition:Effect.Transitions.spring});
		new Effect.Move(this.pCarousel,{pButton:this,afterFinish:this.afterFinish,x:lMove,y:0,mode:'relative'});
		//transition: Effect.Transitions.spring 
		var lNum = (this.pCurrentSlide + this.pIncrement);
		this.updateMe(lNum);
		gButtons[this.pButton].pCurrentSlide = lNum;
		this.updateTitleMe();
		this.scaleCarousel();
		//setInterval('gButtons["' + this.id + '"].scaleCarousel()',50)
		//Effect.SlideDown("condition_carousel_wrapper", {duration:1.0,scaleFrom:100,scaleTo:200});
	}
	
	
	p.scaleCarousel = function(){
		document.getElementById("condition_carousel_wrapper").style.height = this.pConditions[this.pCurrentSlide-1].clientHeight + "px";

		//new Effect.Move("condition_carousel_wrapper",{x:lMove,y:0,mode:'relative'});
		
		/*
		var lHeight = document.getElementById("condition_carousel_wrapper").clientHeight;
		var lNewHeight = this.pConditions[this.pCurrentSlide-1].clientHeight;
		
			//gDebug.tracer(lHeight == lNewHeight)		
		if(lHeight != lNewHeight){
			if(lHeight > lNewHeight){
				document.getElementById("condition_carousel_wrapper").style.height = (lHeight - 1) + "px";
			}else{
				document.getElementById("condition_carousel_wrapper").style.height = (lHeight + 1) + "px";
			}
		}else{		
			clearInterval(this.pInterval);
		}
		*/
	}
		
	p.afterFinish = function(){
		this.pButton.pAnimating = false;
		//this.pButton.updateTitleMe();
	}
	
	p.updateMe = function(pNum){
		this.pCurrentSlide = pNum;
		//gDebug.tracer(this.pCurrentSlide == this.pLastSlide);
		switch(this.id){
			case "left":
				switch(this.pCurrentSlide){
					case 1:
						this.disableMe();
						break;
				}
				
				if(this.pCurrentSlide == (this.pLastSlide-1)){
					gButtons.right.enableMe();				
				}
				break;
			case "right":
				switch(this.pCurrentSlide){
					case 2:
						gButtons.left.enableMe();
						break;
				}
				
				if(this.pCurrentSlide == this.pLastSlide){
					this.disableMe();
				}
				
				break;
		}
		
	}
	
	p.updateTitleMe = function(){
		//alert(this.pTitles)
		this.pTitle.innerHTML = this.pTitles[this.pCurrentSlide-1]
		//new Effect.Tween(this.pTitle, this.pTitle.innerHTML, this.pTitles[this.pCurrentSlide-1], 'innerHTML');
		
		//document.getElementById("condition_carousel_wrapper").style.height = this.pConditions[this.pCurrentSlide-1].clientHeight + "px";
	}

	return p;
}


// setup the CTA carousel //
function initCTACarousel(){
	var lCarousel = document.getElementById("cta_carousel_slide");
	if(!lCarousel){
		return;
	}
	
	var lDivs = lCarousel.getElementsByTagName("div")
	
	if(lDivs.length){
		for(var x = 0; x<lDivs.length; x++){
			var lLink = lDivs[x].innerHTML;
			var lText = '<table class="ctac_tables" cellpadding="0" cellspacing="0" border="0"><tr><td>' + lLink + '</td></tr></table>';
			lDivs[x].innerHTML = lText;
		}
	}
	
	//lCarousel.style.width = (lDivs[0].clientWidth * lDivs.length) + "px";
	
	var lA = lCarousel.parentNode.parentNode.getElementsByTagName("img");

	if(lA.length){
		for(var x = 0; x<lA.length; x++){
			if(lA[x].id.indexOf("curve") == -1){
				lA[x].pCarousel = lCarousel;
				lA[x].pConditions = lDivs;
				gButtons[lA[x].id] = new conditionCTAButton(lA[x])
			}
		}
	}	

	if(gBrowser.vendor != "IE"){
		if(gProps.carousel.landing_page){
			lCarousel.parentNode.parentNode.style.opacity = 0;
			//lCarousel.parentNode.parentNode.style.filter = 'DXImageTransform.Microsoft.Alpha(opacity=0)';
			Effect.Fade(lCarousel.parentNode.parentNode,{duration:1.5,from:0,to:1});
		}
	}
	gButtons.ctac_right.enableMe();
	
}

function conditionCTAButton(p){
	//gDebug.getVar(p)
	p.pImages = {disabled:p.src};
	p.pImages.lo =  gPaths.images + "buttons/" + p.id + "-lo.gif";
	p.pImages.hi =  gPaths.images + "buttons/" + p.id + "-hi.gif";
	p.pEnabled = false;
	p.pStartSlide = (gProps.carousel.landing_page)? 5 : 3;
	p.pCurrentSlide = p.pStartSlide;
	p.pLastSlide = p.pConditions.length;
	p.pIncrement = (p.id == "ctac_right")? +1 : -1;
	p.pAnimating = false;
	p.pButton = (p.id == "ctac_right")? "ctac_left" : "ctac_right";
	
	p.enableMe = function(){
		this.src = this.pImages.lo;
		this.style.cursor = "pointer";
		this.pEnabled = true;
	}
	
	p.disableMe = function(){
		this.src = this.pImages.disabled;
		this.style.cursor = "default";
		this.pEnabled = false;
	}
	
	
	p.onmouseover = function(){
		if(this.pEnabled){
			this.src = this.pImages.hi;
		}
	}

	p.onmouseout = function(){
		if(this.pEnabled){
			this.src = this.pImages.lo;
		}
	}

	
	p.onclick = function(){
		if(this.pEnabled && !this.pAnimating){
			this.pAnimating = true;
			this.nextSlide();
		}
	}
	
	
	p.nextSlide = function(){
		var lMove = (this.id == "ctac_right")? -this.pConditions[0].clientWidth : this.pConditions[0].clientWidth;

		//new Effect.Move(this.pCarousel,{pButton:this,afterFinish:this.afterFinish,x:lMove,y:0,mode:'relative',transition:Effect.Transitions.spring});
		//transition: Effect.Transitions.spring 
		var lNum = (this.pCurrentSlide + this.pIncrement);
		this.updateMe(lNum);
		gButtons[this.pButton].pCurrentSlide = lNum;
		
		if(this.id == "ctac_right"){
			if(lNum == this.pLastSlide){
				lMove = (lMove/2) + 7;
				//lMove = (lMove/2);
			}
		}else{
			if(lNum == this.pLastSlide-1){
				lMove = (lMove/2) - 7;
				//lMove = (lMove/2);
			}
		}
		
		new Effect.Move(this.pCarousel,{pButton:this,afterFinish:this.afterFinish,x:lMove,y:0,mode:'relative',duration:0.5});
		//transition:Effect.Transitions.spring
	}
	
		
	p.afterFinish = function(){
		this.pButton.pAnimating = false;
	}
	
	p.updateMe = function(pNum){
		this.pCurrentSlide = pNum;
		//gDebug.tracer(this.pCurrentSlide == this.pLastSlide);
		switch(this.id){
			case "ctac_left":
				switch(this.pCurrentSlide){
					case this.pStartSlide:
						this.disableMe();
						break;
				}
				
				if(this.pCurrentSlide == (this.pLastSlide-1)){
					gButtons.ctac_right.enableMe();				
				}
				break;
			case "ctac_right":
				switch(this.pCurrentSlide){
					case (this.pStartSlide + 1):
						gButtons.ctac_left.enableMe();
						break;
				}
				
				if(this.pCurrentSlide == this.pLastSlide){
					this.disableMe();
				}
				
				break;
		}
		
	}

	return p;
}

function hcpReportSample(){
	PMG_newWindow({loc:'/hcp/for_you/patient_update.aspx?id=sample',nochrome:true,chrome:{scrollbars:'yes'}});
}

add_onload("ME_LoadFunction");

