/*********************************************/
/*              PMG FUNCTIONS                */
/*********************************************/

// ******************************************** //
// WRITE BULLET LIST   
// obj = {};
// obj.text = array of items
// obj.id = class id for the bullet;
// obj.inline = boolean write or return string
// ******************************************** //
function PMG_writeBullets(obj){
	var w = '';
	
	if(!p.clas){p.clas = "1"}
	for(var x in obj.text){
		w += '<div id="bullet_div" class="bullet_' + p.clas + '">' + obj.text[x] + '</div>\n'
	}
	
	if(obj.inline){
		return w;
	}else{
		document.write(w);
	}

	return false;
}


// ******************************************** //
// 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 = "bodyContentLinks"}
	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.inline){
		return ws;
	}else{
		document.write(ws);
	}
	
	return true;
}




var gCurrentDiv = false;
function changeRightContent(p_id){
	
	var lContent = p_id.split("_")[0];
	var lQuote = document.getElementById(lContent + "_quote_div");

	if(gCurrentDiv){
		gCurrentDiv.style.display = "none";
	}
	
	if(typeof(gCurrentCareer) == "object"){
		gCurrentCareer.style.display = "none";
	}

	if(typeof(gCurrentBio) == "object"){
		gCurrentBio.style.display = "none";
	}

	if(lQuote && lQuote.style){
		document.getElementById("quote_content").style.margin = lQuote.style.margin;
	}
	//document.getElementById("quote_content").innerHTML = (lQuote)? lQuote.innerHTML : "";
	//document.getElementById("quote_content").innerHTML = (lQuote)? "" : "";
	
	gCurrentDiv = document.getElementById(lContent + "_div");
	if(gCurrentDiv == null){alert(lContent + "_div not on " + location.href);return}
	gCurrentDiv.style.display = "block";

}

function writePeopleLinks(p){
	var w = '';
	for(var x in gButtons.people){
		var lB = gButtons.people[x];
		lB.text = lB.name;
		lB.id = lB.name.split(" ")[1].toLowerCase();
		lB.clas = "bio_name_links";
		lB.script = "bioNameClick";
		lB.inline = true;
		w += '<div class="bio_name_link_div">' + PMG_writeLink(lB) + '<span class="bio_title">, ' + lB.title_full + '</span></div>';
		
	}
	
	document.write(w);
}

var gCurrentBio = false;
function bioNameClick(p_id){
	if(gCurrentBio){
		gCurrentBio.style.display = "none";
	}
	gCurrentBio = document.getElementById(p_id + "_div");
	if(gCurrentBio){
		//gCurrentDiv = gCurrentBio;
		gCurrentBio.style.display = "block";
	}
}

// ***************************************************************************** //
// 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);
	gWindow_pmg.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();

}

/*********************************************/
/*            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;
}


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 = "#e0c087";
		lText.style.color = "#e0c087";
	}else{
		lDiv.style.display = "none";
		lPlus.innerHTML = "+";
		lPlus.style.color = "#6a4397";
		lText.style.color = "#6a4397";
	}
}

function initNewsLinks(){

	var lDiv = document.getElementById("news_div");
	var lTags = lDiv.getElementsByTagName("a");
	var lNews_obj = false;
	var lNews = false;
	// Check for query string to display a news article //	
	if(gPaths.qs != ""){
		if(gPaths.qs.indexOf("news=")){
			lNews = gPaths.qs.split("news=")[1];
		}
	}
	
	for(var x = 0; x<lTags.length; x++){
		if(typeof(lTags[x]) == "object"){
			if(lTags[x].id){
				//tracer_debugTool(lTags[x].id)
				lTags[x].onclick = function newsLinkClick(){
					var lHide = document.getElementById("news_div");
					var id = this.id.split("#")[1];
					var lContent = document.getElementById("div_" + id);
					gCurrentDiv = document.getElementById("article_div");
					if(!lContent){
						alert(id + " div not found in\n" + location.href);
					}else{
						var lLink = '<div>' + PMG_writeLink({id:"news_button",text:"Return To News",clas:"arrow_links",inline:true,style:"margin-left:0px;",script:"changeRightContent"}) + '</div>';
						gCurrentDiv.innerHTML = lContent.innerHTML + lLink
						lHide.style.display = "none";
						gCurrentDiv.style.display = "block";
					}
				}
				
				// check to display news article //
				if(lTags[x].id.split("#")[1] == lNews){
					lNews_obj = lTags[x];
				}

			}
		}
	}


	if(lNews_obj){
		
		lNews_obj.onclick();
	}else{
		//changeRightContent("news");
		changeRightContent(lNews);
	}
	
}


function PMG_downloadPDF(p){
	
	var obj = {}
	obj.loc = gPaths.pdf + p + ".pdf";
	
	PMG_newWindow(obj);
}


function writeCareerLinks(p){
	var w = '';
	for(var x in gButtons.careers){
		var lB = gButtons.careers[x];
		//lB.text = lB.name;
		//lB.id = lB.name.split(" ")[1].toLowerCase();
		lB.clas = "career_title_links";
		lB.script = "careerClick";
		lB.inline = true;
		w += '<div class="bio_name_link_div">' + PMG_writeLink(lB) + '</div>';
	}
	
	document.write(w);
}

var gCurrentCareer = false;
function careerClick(p_id){
	if(gCurrentCareer){
		gCurrentCareer.style.display = "none";
	}
	gCurrentCareer = document.getElementById(p_id + "_div");
	if(gCurrentCareer){
		//gCurrentDiv = gCurrentCareer;
		gCurrentCareer.style.display = "block";
	}
}


function checkPageLoader(p){
	var lDiv = p;
	if(gPaths.qs){
		if(gPaths.qs.indexOf("show=") != -1){
			lDiv = gPaths.qs.split("show=")[1];
		}
	}
	
	changeRightContent(lDiv);
}
