/*********************************************/
/*           SUPERNUS FUNCTIONS              */
/*********************************************/
var gButtons = {};
gButtons.about = {text:"About Us",href:"about_us.aspx"};
gButtons.about.subnav = [gButtons.about,{text:"Vision and<br>Strategy", href:"vision_strategy.aspx"},{text:"Our Heritage", href:"heritage.aspx"},{text:"Executive<br>Profiles", href:"executive_profiles.aspx"},{text:"Board Member<br>Profiles", href:"board_profiles.aspx"}];
gButtons.research = {text:"Research &amp;<br>Development",href:"research_development.aspx", onclick:true};
gButtons.research.subnav = [gButtons.research,{text:"Product<br>Pipeline", href:"products.aspx"},{text:"Late-stage<br>Neurology<br>Portfolio",left_text:"Neurology Portfolio", href:"neurology.aspx"},{text:"Psychiatry Portfolio", href:"psychiatry.aspx"}, {text:"Clinical Trials", href:"clinical_trials.aspx"}];
gButtons.investors = {text:"Investors",href:"http://abea-5zngzm.client.shareholder.com/index.cfm"};

var lServer = "http://abea-5zngzm.client.shareholder.com/";
gButtons.investors.subnav = [gButtons.investors];
gButtons.investors.subnav.push({text:"Press Releases",left_text:"Press Releases", href:lServer + "releases.cfm"});
gButtons.investors.subnav.push({text:"Events & Presentations",left_text:"Events & Presentations", href: lServer + "events.cfm"});
gButtons.investors.subnav.push({text:"Corporate Governance",left_text:"Corporate Governance", href:lServer + "governance.cfm"});
gButtons.investors.subnav.push({text:"Financial Information",left_text:"Financial Information", href:lServer + "financials.cfm"});
gButtons.investors.subnav.push({text:"Stock<br />Information",left_text:"Stock Information", href:lServer + "stockquote.cfm"});
gButtons.investors.subnav.push({text:"Investor FAQs",left_text:"Investor FAQs", href:lServer + "faq.cfm"});
gButtons.investors.subnav.push({text:"Contact Us",left_text:"Contact Us", href: lServer + "contactus.cfm"});

gButtons.investors = null;

// insert the Investors links //
if(typeof(gInvestors) == "object" && gInvestors.length){
	//gButtons.investors.subnav = gInvestors;
	//gButtons.investors.subnav.unshift(gButtons.investors);
}else{
	//gButtons.investors.subnav = [gButtons.investors,{text:"Investors link 1", href:"page_name_1.aspx"},{text:"Investors link 2", href:"page_name_2.aspx"}];
	//gInvestors.push({text:"Investor<br />Overview",left_text:"Investor Overview", href:"http://abea-5zngzm.client.shareholder.com/index.cfm"});
	
}

gButtons.media = {text:"Media",left_text:"Media: 2010-2011",href:"media.aspx?media=m2011",subPage:["media.aspx?media=m20111128","media.aspx?media=m20110311","media.aspx?media=m20100713","media.aspx?media=m20100127"]};
gButtons.media.subnav = [gButtons.media]
//gButtons.media.subnav.push({left_text:"2010-2011", href:"media.aspx?pr=2011"});
gButtons.media.subnav.push({left_text:"2008-2009", href:"media.aspx?media=m2009",subPage:["media.aspx?media=m20090728","media.aspx?media=m20090130","media.aspx?media=m20081217","media.aspx?media=m20080423"]});
gButtons.media.subnav.push({left_text:"2006-2007", href:"media.aspx?media=m2007",subPage:["media.aspx?media=m20070919","media.aspx?media=m20070806","media.aspx?media=m20060626","media.aspx?media=m20060613","media.aspx?media=m20060221","media.aspx?media=m20060112"]});
gButtons.contact = {text:"CONTACT",href:"contactus.aspx"};

// Init the panels //
var gPanels = {};

// Confirm Leaving //
gPanels.confirm_leaving = {};
gPanels.confirm_leaving.panel = 'confirm_leaving';
gPanels.confirm_leaving.immobilize = true;
gPanels.confirm_leaving.cssStyle = "black";
gPanels.confirm_leaving.width = 500;
gPanels.confirm_leaving.db = true;
gPanels.confirm_leaving.buttons = [{id:"ok",className:"okButton",action:"gPanel.confirm_leaving.openSite()"},{id:"cancel",className:"cancelButton"}];;

gPanels.privacy_policy = {};
gPanels.privacy_policy.panel = 'privacy_policy';
gPanels.privacy_policy.immobilize = true;
gPanels.privacy_policy.cssStyle = "black";
gPanels.privacy_policy.width = 725;
gPanels.privacy_policy.db = true;

gPanels.legal_policy = {};
gPanels.legal_policy.panel = 'legal_policy';
gPanels.legal_policy.immobilize = true;
gPanels.legal_policy.cssStyle = "black";
gPanels.legal_policy.width = 725;
gPanels.legal_policy.db = true;

gPanels.our_history = {};
gPanels.our_history.panel = 'our_history';
gPanels.our_history.immobilize = true;
gPanels.our_history.cssStyle = "black";
gPanels.our_history.width = 750;

var gProps = {};
gProps.page = unescape(location.href).split('?')[0].split("/").pop();
gProps.pageQS = gProps.page + location.search;

//gServerPath = "http://staging.supernus.com";
var gPaths = {};
if(typeof(gServerPath) == "undefined"){
	var lScripts = document.getElementsByTagName("script");
	for(var x = 0; x<lScripts.length; x++){
		var s = lScripts[x];
		if(s && s.src && s.src.indexOf("js/supernus.js") != -1){
			gServerPath = s.src.split("js/supernus.js")[0];
		}
	}
}
gPaths.base = gServerPath;
if(gPaths.base.charAt(gPaths.base.length-1) != "/"){gPaths.base = gPaths.base + "/"}
gPaths.css = gPaths.base + "css/";
gPaths.js = gPaths.base + "js/";
gPaths.media = gPaths.base + "media/";
gPaths.images = gPaths.media + "images/";
gPaths.debug = gPaths.base + "debug/";
gPaths.pdf = gPaths.media + "pdf/";

// init query strings //
gProps.qs = {}
// Check the Query String //
if(location.search){
	var qs = location.search.split("?")[1].split("&");
	if(qs.length){
		for(var x in qs){
			var i = qs[x].split("=");
			// Force all properties to uppercase //
			gProps.qs[i[0].toLowerCase()] = i[1];	
		}
	}
}

var gDebug = {};
gDebug.tools = (location.host == "localhost" || (location.host.indexOf("sklink") != -1))? true : false; // turn on the debug tools? //
//gDebug.tools = false;
gDebug.showErrors = false;
gDebug.code = "68696685717978"; // debugon //
gDebug.keyboard = false; // turn on number keys //
//gDebug.title = "HCP";
gDebug.colors = {};
gDebug.colors.bgcolor = "#182a76";
gDebug.colors.text = "#ffffff";
gDebug.colors.background = false;
gDebug.colors.elements = {div:"red",p:"aqua",span:"lime",h1:"orange",h2:"pink",table:"black"};

var gBrowser = {};
gBrowser.supported = false;
gBrowser.support_png = true;
gBrowser.browsers = ["Opera","Chrome","Safari","Flock","Firefox"];

for(var x in gBrowser.browsers){
	if(navigator.userAgent.indexOf(gBrowser.browsers[x]) != -1){
		gBrowser.vendor = gBrowser.browsers[x]
		gBrowser.version = navigator.vendorSub;
		break;
	}
	
	gBrowser.os = (navigator.platform == "Win32")? "windows" : navigator.platform;
	gBrowser.ie6 = false;
	gBrowser.safari_win = false;
}

// check for IE //
if(!gBrowser.vendor){
	if(navigator.appMinorVersion){
		gBrowser.vendor = navigator.appName.split(" ")[0];
	}
}

switch(gBrowser.vendor){
	case "Microsoft":
		gBrowser.vendor = "IE";
		lUserAgent = navigator.userAgent.split(";");
		gBrowser.version = lUserAgent[1].split(" ")[2];
		// Only support IE versions 5.0+ //
		if(gBrowser.version >= "6.0"){
			gBrowser.supported = true;
		}
		if(gBrowser.version < "7.0"){
			gBrowser.support_png = false;
			gBrowser.ie6 = true;
		}
		
		break;
	case "Netscape":
		// Only support Netscape versions 7.1+ //
		if(gBrowser.version >= "7.1"){
			gBrowser.supported = true;
		}
		break;
	case "Firefox":
			gBrowser.supported = true;
			// Support al Firefox browsers //
			if(gBrowser.version == ""){
				var lVersion = navigator.userAgent.split("/");
				gBrowser.version = lVersion[lVersion.length-1];
			}
		break;
	case "Flock":
			gBrowser.supported = true;
			if(gBrowser.version == ""){
				var lVersion = navigator.userAgent.split("/");
				gBrowser.version = lVersion[lVersion.length-1];
			}
		break;
	case "Opera":
			gBrowser.supported = true;
			if(!gBrowser.version){
				var lVersion = navigator.userAgent.split("/");
				gBrowser.version = lVersion[1].split(" ")[0];
			}
		break;
	case "Safari":
			gBrowser.supported = true;
			var lVersion = navigator.userAgent.split("/");
			gBrowser.version = lVersion[lVersion.length-2].split(" ")[0];
			gBrowser.safari_win = (gBrowser.os == "windows")? true : false;
		break;
	case "Chrome":
			gBrowser.supported = true;
			var lVersion = navigator.userAgent.split("/");
			gBrowser.version = lVersion[lVersion.length-2].split(" ")[0];
		break;
		default:
		 	gBrowser.supported = false;
			gBrowser.version = navigator.userAgent;
			break
}

// add all the styles //
document.writeln('\n\t<link rel="shortcut icon" type="image/x-icon" href="' + gPaths.images + 'supernus.ico" />');
document.writeln('\t<link rel="stylesheet" media="screen" href="' + gPaths.css + 'supernus.css" />');
document.writeln('\t<link rel="stylesheet" media="screen" href="' + gPaths.css + 'lightbox.css" />');
document.writeln('\t<link rel="stylesheet" media="print" href="' + gPaths.css + 'print.css" />');
if(gDebug.tools){(document.writeln('\t<link rel="stylesheet" media="screen" href="' + gPaths.debug + 'debug.css" />'))};
document.writeln('\t<script type="text/javascript" src="' + gPaths.js + 'lightbox.js"></script>');
document.writeln('\t<script type="text/javascript" src="' + gPaths.js + 'prototype.js"></script>');
document.writeln('\t<script type="text/javascript" src="' + gPaths.js + 'scriptaculous.js?load=effects"></script>');
if(gDebug.tools){document.writeln('\t<script type="text/javascript" src="' + gPaths.debug + 'debug.js"></script>')};


function investorsLink(){
	//alert("Investors link has not been assigned yet.");
	location.href = gButtons.investors.href;
	//location.href = "supernus_investors.html";
}

// called onload - initialize all the global navigations //
function initSupernus(){
	var lContainer = document.getElementById("header");
	if(lContainer){
		var lA = document.createElement("a");
		lA.id = "supernus_logo";
		lA.href = gPaths.base + "index.aspx";
		lA.innerHTML = '<img src="' + gPaths.images + 'supernus_logo.gif" width="282" height="65" alt="Supernus" />'
		lContainer.appendChild(lA);
		
		var lU = document.createElement("ul");
		lU.id = "header_nav";
		var li = document.createElement("li");
		li.innerHTML = "&nbsp;"
		li.style.height = "56px";
		li.style.width = "4px";
		lU.appendChild(li);
		
		for(var x in gButtons){
			if(gButtons[x] != null){
				var li = document.createElement("li");
				var lA = document.createElement("a");
				lA.id = "header_" + x;
				lA.className = "headerLinks";
				lA.innerHTML = gButtons[x].text;
				if((gButtons[x].href.indexOf("http:") == -1)){
					lA.href = gPaths.base + gButtons[x].href;
				}else{
					
					//lA.href = gButtons[x].href;
					
					lA.href = "javascript:void(0);";
					lA.onclick = function(){
						investorsLink();
						return false;
					}
					
					
				}
				li.appendChild(lA);
				lU.appendChild(li);
				
	
				if(gButtons[x].subnav){
					var lDD = document.createElement("div");
					lDD.id =  x + "_dd";
					lDD.className = (gBrowser.ie6)? "header_dd_ie6" : "header_dd";
					var lLeftNav = false;
					
					for(var i = 0; i<gButtons[x].subnav.length; i++){
						var lSub = gButtons[x].subnav[i];
						var lSA = document.createElement("a");
						lSA.id = x + "_" + i;
						lSA.className = "headerSubLinks";
						
						if(gProps.page && (lSub.href.toLowerCase().indexOf(gProps.page.toLowerCase()) != -1)){
							lSA.className = "headerSubLinksHL";
							lLeftNav = true;
						}else{
							if(gProps.page && (gProps.page.toLowerCase() == gButtons[x].href.toLowerCase())){
								lLeftNav = true;
							}
						}
						
						lSA.innerHTML = lSub.text;
						lSA.href = (lSub.href.indexOf("http:") == -1)? gPaths.base + lSub.href : lSub.href;
						lDD.appendChild(lSA);
					}
									
					if(lLeftNav){
						gButtons[x].pLeftNav = lDD.cloneNode(true);
						gButtons[x].pLeftNav.id = x + "_leftnav";
						gButtons[x].pLeftNav.className = "leftnav";
						gButtons[x].pLeftNav.innerHTML = gButtons[x].pLeftNav.innerHTML.split("<br>").join(" ");
						gButtons[x].pLeftNav.innerHTML = gButtons[x].pLeftNav.innerHTML.split("<BR>").join(" ");// IE needs this//
						// rename the left nav links //
						for(var j = 0; j<gButtons[x].pLeftNav.getElementsByTagName("a").length; j++){
							// allows for custom formatting in the left navigation //
							if(gButtons[x].subnav[j].left_text){
								gButtons[x].pLeftNav.getElementsByTagName("a")[j].innerHTML = gButtons[x].subnav[j].left_text;
							}
							gButtons[x].pLeftNav.getElementsByTagName("a")[j].id = x + "_leftNav_" + j;
							
							// allow for custom subpage HL //						
							if(gButtons[x].subnav[j].subPage && gButtons[x].subnav[j].subPage.length){
								if(gButtons[x].subnav[j].href.indexOf("?") != -1 && gButtons[x].subnav[j].href == gProps.pageQS){
									gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = "leftNavLinksHL";
								}else{
									for(var sp = 0; sp<gButtons[x].subnav[j].subPage.length; sp++){
										if(gProps.pageQS == gButtons[x].subnav[j].subPage[sp]){
											gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = "leftNavLinksHL";
											break;
										}else{
											gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = "leftNavLinks";
										}
									}
								}
							}else{
								// pageQS was added to allow custom content per page for Media.aspx //
								if(gButtons[x].subnav[j].href.indexOf("?") != -1 && gButtons[x].subnav[j].href == gProps.pageQS){
									// split the href to find the appropriate querry string //
									gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = "leftNavLinksHL";
								}else{
									if(gButtons[x].subnav[j].href == gProps.pageQS){
										gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = "leftNavLinksHL";
									}else{
										gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = "leftNavLinks";
										//gButtons[x].pLeftNav.getElementsByTagName("a")[j].className = (gButtons[x].pLeftNav.getElementsByTagName("a")[j].className == "headerSubLinks")? "leftNavLinks" : "leftNavLinksHL";
									}
								}
							}
						}
					}
					document.body.appendChild(lDD);
					// disable a dropdown menu for the media tab //
					lA.p_menu = (x == "media" || x == "investors")? false : lDD;
					
					
				}
				gButtons[x].pButton = new initTabButton(lA);
				// if this page has a sub nav, than add it //
				if(gButtons[x].pLeftNav){
					var lDiv = document.getElementById("left_nav_container");
					if(lDiv){
						lDiv.appendChild(gButtons[x].pLeftNav);
						
					}
				}
			}
		}
		
		lContainer.appendChild(lU);
		
		/*
		if(gBrowser.vendor == "IE"){
			var h1 = document.getElementById("index_image_title");
			if(h1){
				h1.filters = "progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color='#333333');";

			}
		}
		*/
		// enable the viewport //
		var lContainer = document.getElementById("site_wrapper");
		if(lContainer){
			//lContainer.style.visibility = "visible";
			lContainer.style.display = "block";
		}
		
	}
	
	if(gProps.page.toLowerCase().indexOf("investors") != -1){
		attachSearch();
	}
}


function initTabButton(p){
	
	p.p_open = false;
	p.p_id = p.id.split("_")[1];
	if(p.p_menu){
		p.p_menu.p_id = p.p_id;
	}
	p.p_timer = null;
	p.p_class = p.className;
	p.p_classHL = p.className + "HL";
	p.animate = false;
	
	p.effect = {}
	p.effect.fps = 50;
	p.effect.duration = 0.3;
	p.effect.delay = 0;
	p.effect.scaleFrom = 0;
	p.effect.scaleTo = 100;
	p.effect.from = 0;
	p.effect.to = 1.0;
	
	p.onmouseover = function(){
		gButtons[this.p_id].pButton.stopTimer();
		if(!this.p_open){
			this.p_open = true;
			if(this.p_menu){
				this.p_menu.style.visibility = "visible";
				this.p_menu.style.display = "none";
				$(this.p_menu).clonePosition(this,{setWidth:false,setHeight:false,offsetLeft:0,offsetTop:56});
				//gDebug.tracer(this.offsetLeft)
				if(this.animate){
					new Effect.BlindDown(this.p_menu,this.effect);
				}else{
					this.p_menu.style.display = "block";
				}
				
			}
			this.className = this.p_classHL;
			this.style.textDecoration = "none";
			
		}
	}
	
	p.onmouseout = function(){
		gButtons[this.p_id].pButton.initTimer();
	}
	
	if(p.p_menu){
		p.p_menu.onmouseover = function(){
			gButtons[this.p_id].pButton.stopTimer();
		}
		
		p.p_menu.onmouseout = function(){
			gButtons[this.p_id].pButton.initTimer();
		}
	}
	p.initTimer = function(){
		this.p_timer = window.setTimeout('gButtons["' + this.p_id + '"].pButton.hideMe();', 100);
	}
	
	p.stopTimer = function(){
		window.clearTimeout(this.p_timer);
		this.p_timer = null;
	}
	
	p.hideMe = function(){
		this.className = this.p_class;
		if(this.p_menu){
			this.p_menu.style.visibility = "hidden";
		}
		this.p_open = false;
	}
	
	return p;
}

// 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 learnMore(p){

	var lPath = null;
	
	switch(p.id){
		case "lm_vision":
			lPath = gButtons.about.subnav[1].href;
			break;
		case "lm_products":
			lPath = gButtons.research.subnav[1].href;
			break;
	}
	
	if(lPath){
		location.href = gPaths.base + lPath;
	}else{
		alert(p.id + " is not defined in learnMore()");
	}
}

function footerClick(p){

	var lPath = null;

	switch(p.id){
		case "f_sitemap":
			lPath = "sitemap.aspx";
			break;
		case "f_contact":
			lPath = "contactus.aspx";
			break;
		case "f_legal":
			//lPath = "legal.aspx";
			gLightBox.init({div:"legal_policy"});
			break;
		case "f_privacy":
			//lPath = "privacy.aspx";
			gLightBox.init({div:"privacy_policy"});
			break;
		default:
			alert("footer link not defined in footerClick()");
			break;
	}
	
	if(lPath){
		location.href = gPaths.base + lPath;
	}else{
		//alert("Waiting for content.");
	}
}

gLinks = {};
function initExpandLinks(){
	var lContainer = document.getElementById("expandableContent");
	var lAs = [];
	var lA = [];
	if(lContainer){
		lAs = lContainer.getElementsByTagName("a");
	}
	
	if(lAs.length){
		for(var x = 0; x<lAs.length; x++){
			if(lAs[x].id.indexOf("expand_") != -1){
				lA.push(lAs[x]);
			}
		}
	}
	
	if(lA.length){
		for(var x = 0; x<lA.length; x++){
			gLinks[lA[x].id] = new expandableLink(lA[x]);
		}
	}
}

function expandableLink(p){
	p.pID = p.id.split("_")[1];
	p.pContent = document.getElementById("content_" + p.pID);
	p.pOpen = false;
	p.pAnimation = false;
	p.pAnimate = true;
	
	p.afterFinish = function(){
		this.obj.pAnimation = false;
	}
	
	p.effectShow = {}
	p.effectShow.obj = p;
	p.effectShow.fps = 50;
	p.effectShow.duration = 0.5;
	p.effectShow.delay = 0;
	p.effectShow.scaleFrom = 0;
	p.effectShow.scaleTo = 100;
	p.effectShow.from = 0;
	p.effectShow.to = 1.0;
	p.effectShow.afterFinish = p.afterFinish;
	
	p.effectHide = {}
	p.effectHide.obj = p;
	p.effectHide.fps = 50;
	p.effectHide.duration = 0.5;
	p.effectHide.delay = 0;
	p.effectHide.scaleFrom = 100;
	p.effectHide.scaleTo = 0;
	p.effectHide.afterFinish = p.afterFinish;
	p.effectHide.from = 0;
	p.effectHide.to = 1.0;
	
	if(p.pContent){
		
		p.onclick = function(){
			//this.pContent.style.display = (this.pContent.style.display == "none")? "block" : "none"; 
			if(!this.pAnimation){
				if(this.pOpen){
					this.hideMe();
				}else{
					this.showMe();
				}
			}
		}
		
		p.showMe = function(){
			this.pOpen = true;
			//this.style.fontWeight = "bold";
			if(this.pAnimate){
				this.pAnimation = new Effect.BlindDown(this.pContent,this.effectShow);
			}else{
				this.pContent.style.display = "block";
			}
		}

		p.hideMe = function(){
			this.pOpen = false;
			//this.style.fontWeight = "normal";
			if(this.pAnimate){
				this.pAnimation = new Effect.BlindUp(this.pContent,this.effectHide);
			}else{
				this.pContent.style.display = "none";
			}
		}
	
	}

	return p;
}

// ********************************* //
// returns the x and y of an element //
// ********************************* //

function disclaimerLink(obj){
	
	if(!obj){
		alert("id not passed to disclaimerLink()");
		return;
	}
	
	var lLoc = false;
	
	switch(obj.id){
		case "clinical_trials":
			lLoc = {loc:"http://www.clinicaltrials.gov",pConfirm:true};
			break;
		case "nea":
			lLoc = {loc:"http://www.nea.com",pConfirm:true};
			break;
		case "abingworth":
			lLoc = {loc:"http://www.abingworth.com",pConfirm:true};
			break;
		case "collagenex":
			lLoc = {loc:"http://www.collagenex.com",pConfirm:true};
			break;
		case "indevus":
			lLoc = {loc:"http://www.indevus.com",pConfirm:true};
			break;
		default:
			alert(obj.id + " not defined in disclaimerLink()")
			return
			break;
	}
	
	if(lLoc){
		if(lLoc.pConfirm){
			//PMG_newWindow(lLoc);
			gLightBox.init({div:"confirm_leaving"});

			gPanel.confirm_leaving.p_url = lLoc;
			gPanel.confirm_leaving.openSite = function(){
				PMG_newWindow(this.p_url)
				this.closePanel();
			}

		}else{
			PMG_newWindow(lLoc);
		}
	}
	
}
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 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  + '\'); background-repeat: ' + lProps;
	}

	return ws;
}

// ***************************************************************************** //
// 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();
			}
		}
	}
	
	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)? (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";
	}
	// 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 //
	//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)
}

PMG_TimeStamp = function(){
		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;
}

gValidate = {};
//gValidate.firstname = {};
//gValidate.lastname = {};
//gValidate.address = {};
//gValidate.city = {};
//gValidate.state = {};
//gValidate.zip = {};
//gValidate.telephone = {};
//gValidate.email = {};
//gValidate.contact = {};


function initContactUs(){
	var lContainer = document.getElementById("contact_form");
	var lValidate = ["firstname","lastname","phone","email","contact","postalcode"];
	if(lContainer){
		// find all the input items //
		var lItems = lContainer.getElementsByTagName("input");
		if(lItems.length){
			for(var x = 0; x<lItems.length; x++){
				var i = lItems[x];
				for(var prop = 0; prop<lValidate.length; prop++){
					if(i.id && (i.id.toLowerCase().indexOf(lValidate[prop]) != -1)){
						// phone number is not required //
						if(lValidate[prop] == "phone" || lValidate[prop] == "postalcode"){
							i.onkeypress = gForms.numbers_only;
						}else{
							// create the object reference //
							gValidate[i.id] = {};
							gValidate[i.id].obj = i;
						}
					}
				}
			}		
		}

		//gDebug.getVar(gValidate)
		
		// find all the select items //
		var lItems = lContainer.getElementsByTagName("select");
		if(lItems.length){
			for(var x = 0; x<lItems.length; x++){
				var i = lItems[x];
				for(var prop = 0; prop<lValidate.length; prop++){
					if(i.id && (i.id.toLowerCase().indexOf(lValidate[prop]) != -1)){
						// create the object reference //
						gValidate[i.id] = {};
						gValidate[i.id].obj = i;
					}
				}
			}		
		}
		

		// init all the objects //
		
		var lFocus = false;
		for(var prop in gValidate){
			gValidate[prop].button = new createFormValidators(gValidate[prop].obj);
			if(!lFocus){
				//gValidate[prop].obj.focus();
				lFocus = true;
			}
		}
	}
	
	var lButton = document.getElementById("submitButton");
	if(lButton){
		lButton = lButton.getElementsByTagName("a")[0];
		
		if(lButton){
			lButton.onclick = validateForm;
		}
		
	}
	
}

function validateForm(){

	var lPassValid = true;
	for(var prop in gValidate){
		var lValid = gValidate[prop].button.validateMe();
		if(!lValid){
			lPassValid = false;
		}
	}

	return lPassValid;
}

function createFormValidators(p){
	//alert(p.nodeName)
	p.pErrorText = document.getElementById("errorMessage");
	p.pColor = p.style.borderColor;
	
	p.onfocus = function(){
		this.style.borderColor = this.pColor;
		this.pErrorText.style.visibility = "hidden";
	}
	
	p.validateMe = function(){
		var lValid = true;
		switch(this.nodeName.toLowerCase()){
			case "input":
				var lText = this.value.split(" ").join("");
				this.value = lText;
				if(this.value == "" || this.value == this.pErrorText){
					lValid = false;
					break;
				}
				
				// check for e-mail address //
				if(this.id.toLowerCase().indexOf("email") != -1){
					lValid = gForms.validEmail({email:this.value});
					break;
				}
				
				// check for phone number //
				if(this.id.toLowerCase().indexOf("phone") != -1){
					if(this.value.length != this.maxLength){
						lValid = false;
						break;
					}
				}
				//alert(this.id)
				
				break;
			case "select":
				if(this.value == 0){
					lValid = false;
				}
				break;
		}
		
		if(!lValid){
			this.errorMe();
		}
		
		return lValid;
		//alert(this.value);
	}
	
	
	p.errorMe = function(){
		this.style.borderColor = "#ff0000";
		this.pErrorText.style.visibility = "visible";
	}
	
	return p;
}


function downloadPDF(pID){
	if(!pID){
		pID = {};
	}
	
	var lPDF = null;
	
	switch(pID.id){
	case "20111128":
			lPDF = "Press release SPN 810 Phase IIb Initiation Final.pdf";
			break;
		case "20110311":
			lPDF = "Press release SPN 812 Phase IIa Results-Final.pdf";
			break;
		case "20100713":
			lPDF = "Press release SPN 812 Phase IIa Initiation 13Jul10 FINAL.pdf";
			break;
		case "20100127":
			lPDF = "Press release SPN 810 Phase IIa Results FINAL 27Jan10.pdf";
			break;
		case "20090728":
			lPDF = "49869-1_supcor_press_7-28-09_lo1.pdf";
			break;
		case "20090130":
			lPDF = "49869-1_supcor_press_1-30-09_lo1.pdf";
			break;
		case "20081217":
			lPDF = "49869-1_supcor_press_12-18-08_lo1.pdf";
			break;
		case "20080423":
			lPDF = "49869-1_supcor_press_4-23-08_lo2.2.pdf";
			break;
		case "20060626":
			lPDF = "49869-1_supcor_press_6-26-06_lo1.pdf";
			break;
		case "20060613":
			lPDF = "49869-1_supcor_press_6-13-06_lo1.pdf";
			break;
		case "20060221":
			lPDF = "49869-1_supcor_press_2-21-06_lo1.pdf";
			break;
		case "20060112":
			lPDF = "49869-1_supcor_press_1-12-06_lo1.pdf";
			break;
		default:
			alert("pID.id = " + pID.id + "\nNot definded in downloadPDF()");
			break;
	}
	
	if(lPDF){
		PMG_newWindow({loc:gPaths.pdf + lPDF,nochrome:true});
	}
	
}

function backClick(pID){
	
	history.go(-1);
	
	/*
	var lLoc = null;
	switch(pID.id){
		case "back_20100713":
		case "back_20100127":
		case "back_20110311":
			lLoc = "media.aspx?media=m2011";
			break;
		case "back_20090728":
		case "back_20090130":
		case "back_20081217":
		case "back_20080423":
			lLoc = "media.aspx?media=m2009";
			break;
		case "back_20070919":
		case "back_20070806":
		case "back_20060626":
		case "back_20060613":
		case "back_20060221":
		case "back_20060112":
			lLoc = "media.aspx?media=m2007";
			break;
		default:
			alert(pID.id + " not defined in backClick()");
			break;			
	}

	if(lLoc){
		location.href = lLoc;
	}
	*/
}

// ********************************* //
//          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;
}

// ******************************************** //
//                    NASDAQ                    //
// ******************************************** //
// These functions are used with the NASDAQ search + enter key //
function executeSearch(){
	var lField = document.getElementById("search_field");
	location.href = gServerPath + "search.aspx?q=" + lField.value;
}

// searchKey is attached to the text field onkeypress //
function searchKey(evt){
	var evt  = (evt)? evt : event;
	//gDebug.tracer(evt.keyCode)
    if (evt.keyCode == 13){
		// Chrome needs this function, does not work with executeSearch() //
		var lField = document.getElementById("search_field");
		window.location = gServerPath + "search.aspx?q=" + lField.value;
		return false;
	}
}

function attachSearch(){
	var lField = document.getElementById("search_field");
	if(lField){
		lField.onkeypress = searchKey;
	}
}


add_onload("initSupernus")


