/*********************************************/
/*              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.href){p.href = ""}
	if(!p.script){p.script = "PMG_clickLink"}

	var ws = (p.arrow)? '<p class="triangle_links">' : '';
	ws += '<a class="bodyContentLinks" ';
	ws += 'href="#" ';
	ws += 'onfocus="this.blur();" ';
	ws += 'onclick="' + p.script + '(\'' + p.href + '\');return false;" ';
	ws += '>' + p.text + '</a>';
	ws += (p.arrow)? '</p>' : '';
	
	if(p.inline){
		return ws;
	}else{
		document.write(ws);
	}
	
	return true;
}


// ******************************************** //
// EXEC A BODY CONTENT LINK   
// _location = string
// can redirect or call PMG_newWindow();
// ******************************************** //
function PMG_clickLink(_location){
	
	var pLoc = null;

	switch(_location){
		case "azprivacystatement":
			pLoc = "/privacy.aspx";
			break;
		case "az_me":
			var p = {};
			//p.loc = "http://www.astrazeneca-us.com/content/patientAssistance/astrazeneca-pparx.asp?PPA=CorpID";
			p.loc = "http://www.azandme.com";
			p.w = 1024;
			PMG_newWindow(p);
			break;
		default:
		 	//alert("set branching logic for the \"" + p_id + "\" link in mp_functions.js")
			if(_location != ""){
				pLoc = _location + ".aspx";
			}else{
				alert("href not passed to PMG_clickLink() in functions_pmg.js");
			}
			break;
	}

	
	if(pLoc != null){
		location.href = pLoc;
	}
	
}

// ***************************************************************************** //
// 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 lAlt = (p.alt)? 'alt="' + p.alt + '"' : '';
	var lTitle = (p.title)? 'alt="' + p.title + '"' : '';
	
	if(lExt == "png" && gBrowser.vendor == "IE"){
			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 + ' src="' + lImage + '" ' + lSize + ' vspace="0" hspace="0" border="0" ' + lAlt + ' />';
	}
	
	
	if(p.inline){
		return ws;
	}else{
		document.write(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";
	
	if(lType == "png" && gBrowser.vendor == "IE"){
		ws += 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + lImage + '\', sizingMethod=\'' + lScale + '\')'
	} else {
		ws += 'background-image: url(\'' + lImage  + '\')';
	}

	return ws;
			
}

// ********************************* //
//        WRITE BOX			         //
// ********************************* //
function writeTableBox(pTop,pWrite){

	var ws = "";
	if(pTop){
		ws += '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
		ws += '<tr><td class="table_box_top_left"></td><td class="table_box_top"></td><td class="table_box_top_right"></td></tr>';
		ws += '<tr><td class="table_box_left"></td><td class="table_box_back">'
	}else{
		ws += '</td><td class="table_box_right"></td></tr>';
		ws += '<tr><td class="table_box_bottom_left"></td><td class="table_box_bottom"></td><td class="table_box_bottom_right"></td></tr>';
		ws += '</table>';
	}

	if(pWrite){
		document.write(ws);
	}else{
		return ws;
	}
	
	return true;
	
}

// ******************************************** //
// PRINT POPUP WINDOW   
// ******************************************** //
function PMG_print(){
	window.print();
}


// ***************************************************************************** //
// 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){
 
	// close the existing window if one is open //
	/*
	if(typeof(gWindow_pmg) == "object"){
		if(gWindow_pmg != false){
			//getVariable_debugTool(gWindow_pmg.window)
			gWindow_pmg.close();
			alert("close")
			gWindow_pmg = false;
		}
	}
	*/
	
	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)? "no" : "yes";
	pChrome.resizable = (pWin.nochrome)? "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 = "pWindow";
	}
	// 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;
		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 //
	gWindow_pmg = window.open(pWin.loc,pWin.name,lNewChrome);

	if(gWindow_pmg && gWindow_pmg.focus){
		gWindow_pmg.focus();
	}
	
}

var gMP_window = false;
function PMG_newWindow2(pWin){
 
	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)? "no" : "yes";
	pChrome.resizable = (pWin.nochrome)? "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 = "pWindow";
	}
	// 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;
		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 //
	if(!gMP_window || gMP_window.closed){
		// launch new window if it was closed //
		gMP_window = window.open(pWin.loc,pWin.name,lNewChrome);
	}else{
		// check if the winlow location == the intended page //
		if(gMP_window.location.href.indexOf(pWin.loc) == -1){
			gMP_window.location.href = pWin.loc;
		}
	}
	

	
	gMP_window.focus();
	
}

// ******************************************** //
// 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();

}

// ***************************************************************************** //
// 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){
	alert("** PDF MEMBER FOUND ERROR PDF **")
	newWindow = PMG_newWindow({loc:pLoc,name:'printpdf',nochrome:true,w:800,h:600});
	
	document.PDFLauncher.target = "printpdf";
	document.PDFLauncher.action = pLoc;
	document.PDFLauncher.submit();
	
}

/*********************************************/
/*            WRITE FLASH OBJECT             */
/*********************************************/
function writeFlash(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=6,0,0,0" width="' + p.width + '" height="' + p.height +'" id="' + p.id + '">';
	ws += '<param name=movie value="' + 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="' + p.movie + '" FlashVars="' + p.vars + '" quality="high" wmode="transparent" bgcolor="#ffffff" 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;
	}
}


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 PMG_faqClick(pNum){
	var lDiv = document.getElementById("faqAnswer" + pNum);
	var lPlus = document.getElementById("faqPlus_Minus" + pNum);
	var lText = document.getElementById("faqQuestion" + pNum);
	var lShow = (lDiv.style.display != "block")? true : false;
	
	if(lShow){
		lDiv.style.display = "block";
		lPlus.innerHTML = "&ndash;";
		lPlus.style.color = "#0000ff";
		lText.style.color = "#0000ff";
	}else{
		lDiv.style.display = "none";
		lPlus.innerHTML = "+";
		//lPlus.style.color = "#6a4397";
		//lText.style.color = "#6a4397";
	}
	
	
}

function PMG_faqRollOver(pNum){
	var lDiv = document.getElementById("faqAnswer" + pNum);
	var lPlus = document.getElementById("faqPlus_Minus" + pNum);
	var lText = document.getElementById("faqQuestion" + pNum);
	var lShow = (lDiv.style.display != "block")? true : false;
	
	if(lShow){
		lPlus.style.color = "#0000ff";
		lText.style.color = "#0000ff";
	}
	
}

function PMG_faqRollOut(pNum){
	var lDiv = document.getElementById("faqAnswer" + pNum);
	var lPlus = document.getElementById("faqPlus_Minus" + pNum);
	var lText = document.getElementById("faqQuestion" + pNum);
	var lShow = (lDiv.style.display != "block")? true : false;

	if(lShow){
		lPlus.style.color = "#6a4397";
		lText.style.color = "#6a4397";
	}
	
}

