// Create the namespace
if( !window.com ) {
	/**
	 * @ignore
	 **/
	window.com = new Object();
}
if( !com.bigbad ) {
	/**
	 * @ignore
	 **/
	 com.bigbad = new Object();
}

/**
 * @class Popup Features for simple creation of popup windows with given features.
 * <p><b>Usage:</b></p>
 * <dl>
 *   <dt>To create a popup that is not resizable and does not display the status bar, scroll bars, tool bar, or menu bar</dt>
 *   <dd><code>var myPopupFeatures = new com.bigbad.PopupFeatures( {scrollbars:false,status:false,resizable:false} );</code></dd>
 *   <dd><code>window.open( "myUrl", "myTarget", myPopupFeatures.toString() );</code></dd>
 *
 *   <dt style="margin-top: 12px;">To create a popup that uses all of the default features except for having a unique width and height</dt>
 *   <dd><code>window.open( "myUrl", "myTarget",</code><code style="display: block; padding-left: 20px;">com.bigbad.PopupFeatures.defaultPopupFeatures.toString( {width:500,height:400} ) );</code></dd>
 *
 * </dl>
 *
 * <p>Note: not all properties are available in all browsers</p>
 *
 * @author Gregory Ramsperger <Gregory.Ramsperger@BigBad.com>
 * @version 1.1, June 22, 2005
 *
 * @constructor
 * @param defaults <dfn>Object</dfn> Object whose properties will be used as default values for this instance. See <code>toString()</code>
 **/
com.bigbad.PopupFeatures = function( defaults ) {
	if( defaults == null ) return;

	// transfer all properties into this object.
	var prop;
	for( prop in defaults ) {
		this[prop] = defaults[prop];
	}
}

/**
 * Convert the PopupFeatures instance to a string
 * @param overrides <dfn>Object</dfn> Object whose properties will be used to override the instance properties
 * @return the string to be used as the features parameter in the <code>window.open( <i>url</i>, <i>target</i>, <i>features</i> )</code> call.
 * @type String
 **/
com.bigbad.PopupFeatures.prototype.toString = function( overrides ) {
	if( overrides == null ) overrides = new Object();

	var rtn = new Array();
	for( prop in this ) {
		var val;
		if( (val = this.getPropValue(prop, overrides))!=null ) {
			if( typeof val == "function" ) continue;
			switch( prop ) {
				case "left":
					rtn[rtn.length] = "screenX=" + val;
				case "top":
					rtn[rtn.length] = "screenY=" + val;
				default:
					rtn[rtn.length] = prop + "=" + val;
			}
		}
	}
	return rtn.join(",");
}

/**
 * Retrieve the set value a given property.
 * <p>Boolean values are converted to the strings "yes" or "no", representing <code>true</code> and <code>false</code> respectively
 * @private
 * @param prop <dfn>String</dfn> Name of the property to retrieve.
 * @param overrides <dfn>Object</dfn> Object whose properties will be used in place of instance values for popup properties. See <code>toString()</code>
 * @return the value or <code>null</code> if the value was not set.
 **/
com.bigbad.PopupFeatures.prototype.getPropValue = function( prop, overrides ) {
	var val = null;
	if( overrides == null ) val = this[prop];
	else val = ( overrides[prop] != null ) ? overrides[prop] : this[prop];
	return ( val == null ) ? null : (typeof val == "boolean" ? ( val ? "yes" : "no" ) : val );
}

/**
 * <p>Copy parent window's history to the new child window.</p>
 * <p>Default: no value</p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.copyhistory = null;

/**
 * <p>New window is dependent on parent window and is closed automatically if parent is closed.</p>
 * <p>Default: no value</p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.dependent = null;

/**
 * <p>New window has directory buttons</p>
 * <p>Default: <code>false</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.directories = false;

/**
 * <p>height of new window in pixels</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.height = null;

/**
 * <p>Height of content (visible body area) in new window in pixels</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.innerHeight = null;

/**
 * <p>Width of content (visible body area) in new window in pixels</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.innerWidth = null;

/**
 * <p>Initial position on screen of the left edge of the popup window</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.left = null;

/**
 * <p>New window has the location bar</p>
 * <p>Default: <code>false</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.location = false;

/**
 * <p>New window has the menu bar</p>
 * <p>Default: <code>false</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.menubar = false;

/**
 * <p>Height of the new window (including chrome) in pixels</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.outerHeight = null;

/**
 * <p>Width of the new window (including chrome) in pixels</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.outerWidth = null;

/**
 * <p>New window is resizable by the user</p>
 * <p>Default: <code>true</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.resizable = true;

/**
 * <p>New window has the scroll bars</p>
 * <p>Default: <code>true</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.scrollbars = true;

/**
 * <p>New window has the status bar</p>
 * <p>Default: <code>true</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.status = true;

/**
 * <p>New window has the tool bar</p>
 * <p>Default: <code>false</code></p>
 * @type Boolean
 **/
com.bigbad.PopupFeatures.prototype.toolbar = false;

/**
 * <p>Initial position on screen of the top edge of the popup window</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.top = null;

/**
 * <p>Width of new window in pixels</p>
 * <p>Default: no value</p>
 * @type Number
 **/
com.bigbad.PopupFeatures.prototype.width = null;

/**
 * PopupFeatures instance using all of the default values.
 * @type com.bigbad.PopupFeatures
 **/
com.bigbad.PopupFeatures.defaultPopupFeatures = new com.bigbad.PopupFeatures();


/**
 * @class Popup for simple creation of popup windows.
 * <p>Note: All methods are static</p>
 *
 * @author Gregory Ramsperger <Gregory.Ramsperger@BigBad.com>
 * @version 1.0, June 22, 2005
 *
 * @constructor
 **/
com.bigbad.Popup = function() {}

/**
 * Popup a window using the properties of an HTML anchor tag.
 * <p><strong>Accessibility note:</strong> This method should be used whenever popping up window from an anchor link. This allows browsers without JavaScript to reach the window. Additionally, search engines will also be able to crawl though this link.</p>
 * 
 * <p><b>Usage:</b></p>
 * <dl>
 *   <dt>Open popup using width and height set in PopupFeatures instance.</dt>
 *   <dd><code>&lt;a href="/some/url/" target="myWin" onclick="return com.bigbad.Popup.popupDom(this, myPopupFeatures);"&gt;popup&lt;/a&gt;</code></dd>
 *
 *   <dt style="margin-top: 1em;">Open popup using width and height overrides to the default PopupFeatures instance.</dt>
 *   <dd><code>&lt;a href="/some/url/" target="myWin" onclick="return com.bigbad.Popup.popupDom(this, null, {width:600,height:400} );"&gt;popup&lt;/a&gt;</code></dd>
 *
 *   <dt style="margin-top: 1em;">Open popup using width and height overrides to the default PopupFeatures instance.</dt>
 *   <dd><code>&lt;a href="/some/url/" target="myWin" onclick="return com.bigbad.Popup.popupDom(this, myPopupFeatures, {width:600,height:400} );"&gt;popup&lt;/a&gt;</code></dd>
 * </dl>
 *
 *
 * @param anchor <dfn>HTMLAElement</dfn> reference to an anchor tag.
 * @param features <dfn>com.bigbad.PopupFeatures</dfn>, <i>optional</i> features of the new window.
 * @param overrides <dfn>Object</dfn>, <i>optional</i> overrides to features parameter
 * @return <code>false</code> on success.
 * @see com.bigbad.PopupFeatures#toString
 **/
com.bigbad.Popup.popupDom = function( anchor, features, overrides ) {
	com.bigbad.Popup.popup( 
		anchor.href,
		anchor.target,
		features,
		overrides
	);
	return false;
}

/**
 * Popup a window
 *
 * <p><b>Usage:</b></p>
 * <dl>
 *   <dt>Open popup using width and height set in PopupFeatures instance.</dt>
 *   <dd><code>var myWin = com.bigbad.Popup.popup("/some/url/", "myWin", myPopupFeatures);</code></dd>
 *
 *   <dt style="margin-top: 1em;">Open popup using width and height overrides to the default PopupFeatures instance.</dt>
 *   <dd><code>var myWin = com.bigbad.Popup.popup("/some/url/", "myWin", null, {width:600,height:400} );</code></dd>
 *
 *   <dt style="margin-top: 1em;">Open popup using width and height overrides to the default PopupFeatures instance.</dt>
 *   <dd><code>var myWin = com.bigbad.Popup.popup("/some/url/", "myWin", myPopupFeatures, {width:600,height:400} );</code></dd>
 * </dl>
 *
 * @param url <dfn>String</dfn> initial URL of the popup window
 * @param target <dfn>String</dfn> the name of the newly created window
 * @param features <dfn>com.bigbad.PopupFeatures</dfn>, <i>optional</i> features of the new window.
 * @param overrides <dfn>Object</dfn>, <i>optional</i> overrides to features parameter
 * @return the newly created Window instance
 * @see com.bigbad.PopupFeatures#toString
 **/
com.bigbad.Popup.popup = function( url, target, features, overrides ) {
	if( target == null || target == "" || target == "_blank" || target == "_new" ) target = "popup";
	if( features == null ) features = com.bigbad.PopupFeatures.defaultPopupFeatures;

	var win = window.open(
		url,
		target,
		features.toString( overrides )
	);
	win.focus();
	return win;
}
// Create the namespace
if( !window.com ) {
	/**
	 * @ignore
	 **/
	window.com = new Object();
}
if( !com.jitjat ) {
	/**
	 * @ignore
	 **/
	 com.jitjat = new Object();
}

/**
 * Robust Image Rollover Class
 * <p>Example:</p>
 * 
 * <pre><code>
 * &lt;script language="javascript" type="text/javascript"&gt;
 *   var ro = new com.jitjat.RollOvers();
 *   ro.addPreloader( function() {
 *      this.addRollover( "home", ["over","down"],"/images/nav/primary/",".gif","-",true);
 *      this.preloaded = true;
 *   });
 *
 * &lt;/script&gt;
 * &lt;a href="/" 
 *     onmouseover="return ro.swapImage('home', 'over');"
 *     onmouseout="return ro.swapImage('home', 'normal');"
 *     onmousedown="return ro.swapImage('home', 'down');"
 *     onmouseup="return ro.swapImage('home', 'over');"&gt;&lt;img id="home" src="/images/nav/primary/home.gif" /&gt;&lt;/a&gt;
 * </code></pre>
 *
 *
 * @constructor
 * @author Gregory Ramsperger <gregory-at-jitjat.com>
 **/
com.jitjat.RollOvers = function() {}

/**
 * Preload state: true if the images represented in this rollover set have been preloaded
 * <p>Instances must set this to true.</p>
 * @type boolean
 */
com.jitjat.RollOvers.prototype.preloaded = false;

/**
 * Create a "normal" state by default.
 * @type boolean
 */
com.jitjat.RollOvers.prototype.createNormalState = false;

/**
 * All rollovers created by this set.
 * @private
 * @type Array
 */
com.jitjat.RollOvers.prototype.rollovers = new Object();

/**
 * Preload the image.
 * @private
 * @param url <dfn>String</dfn> the URL of the image to be loaded
 * @type Image
 * @return The <code>Image</code> loaded from the given URL
 **/
com.jitjat.RollOvers.prototype.createImage = function( uri ) {
	var img = new Image();
	img.src = uri;
	return img;
}

/**
 * Swap the given image.
 * @param id <dfn>string</dfn> the unique ID of the image to be swapped
 * @param newState <dfn>string</dfn> the new state of the image.
 * @type boolean
 * @return <code>true</code>
 **/
com.jitjat.RollOvers.prototype.swapImage = function( id, newState ) {
	if( document.images && this.preloaded && this.rollovers[id] ) {
		if( newState == null && this.defaultStates[id] ) newState = this.defaultStates[id];
		if( newState == null ) return true;

		if( this.rollovers[id][newState] ) {
			// use getElementByID instead of document.images[id] to allow for <input type="image" />
			var ele = document.getElementById(id);
			if( ele && ele.src )
				ele.src = this.rollovers[id][newState].src;
		}
	}
	return true;
}

/**
 * Add images and their rollover states to the set using the IDs as the base file name.
 * <p>Images are loaded using the following naming convention:</p>
 * <p><code><var>urlPrefix</var> + <var>id</var> + <var>stateDelimiter</var> + <var>state</var> + <var>urlSuffix</var></code></p>
 *
 * @param ids <dfn>string or string[]</dfn> The unique id or ids of the images for which to create rollovers.
 * @param states <dfn>string or string[]</dfn> The rollover state or states to create for each image.
 * @param urlPrefix <dfn>string</dfn> The prefix to prepend to each id when creating the rollovers.
 * @param urlSuffix <dfn>string</dfn> The prefix to append to each id when creating the rollovers.
 * @param stateDelimiter <dfn>string</dfn> The character(s) to place between the id and state name when creating rollover images.
 * @param createNormalState <dfn>boolean</dfn> Create a "normal" state for the rollovers. If <code>null</code> or omitted, the RollOvers instance's createNormalState value will be used.
 * @type Void
 **/
com.jitjat.RollOvers.prototype.addRollover = function( ids, states, urlPrefix, urlSuffix, stateDelimiter, createNormalState ) {
	if( typeof ids == "string" ) ids = [ids];
	if( typeof states == "string" ) states = [states];

	if( typeof createNormalState != "boolean" ) createNormalState = this.createNormalState;

	for( var i=0; i<ids.length; i++ ) {
		this.rollovers[ids[i]] = new Object();

		if( createNormalState ) this.rollovers[ids[i]].normal = this.createImage( urlPrefix + ids[i] + urlSuffix );

		for( var j=0; j<states.length; j++ ) {
			this.rollovers[ids[i]][states[j]] = this.createImage( urlPrefix + ids[i] + stateDelimiter + states[j] + urlSuffix );
		}
	}
}

/**
 * Add images and their rollover states to the set.
 * <p>Images are loaded using the following naming convention:</p>
 * <p><code><var>urlPrefix</var> + <var>stateDelimiter</var> + <var>state</var> + <var>urlSuffix</var></code></p>
 *
 * @param uniqueRoId <dfn>string</dfn> The unique id of this set of rollovers. <var>uniqueRoId</var> does need to not match the unique id of the image.
 * @param states <dfn>string or string[]</dfn> The rollover state or states to create for each image.
 * @param urlPrefix <dfn>string</dfn> The prefix to prepend to each id when creating the rollovers.
 * @param urlSuffix <dfn>string</dfn> The prefix to append to each id when creating the rollovers.
 * @param stateDelimiter <dfn>string</dfn> The character(s) to place between the id and state name when creating rollover images.
 * @param createNormalState <dfn>boolean</dfn> Create a "normal" state for the rollovers. If <code>null</code> or omitted, the RollOvers instance's createNormalState value will be used.
 * @type Void
 **/
com.jitjat.RollOvers.prototype.addGenericRollover = function( uniqueRoId, states, urlPrefix, urlSuffix, stateDelimiter, createNormalState ) {
	if( typeof states == "string" ) states = [states];

	if( createNormalState != true && createNormalState != false ) createNormalState = this.createNormalState;

	this.rollovers[uniqueRoId] = new Object();

	if( createNormalState ) this.rollovers[uniqueRoId].normal = this.createImage( urlPrefix + urlSuffix );

	for( var j=0; j<states.length; j++ ) {
		this.rollovers[uniqueRoId][states[j]] = this.createImage( urlPrefix + stateDelimiter + states[j] + urlSuffix );
	}
}

/**
 * Swap the given generic image.
 * @param id <dfn>string, image, image form input</dfn> the unique ID of the image to be swapped
 * @param uniqueRoId <dfn>string</dfn> the unique ID of the generic rollover
 * @param newState <dfn>string</dfn> the new state of the image.
 * @type boolean
 * @return <code>true</code>
 **/
com.jitjat.RollOvers.prototype.swapGenericImage = function( id, uniqueRoId, newState ) {
	if( document.images && this.preloaded && this.rollovers[uniqueRoId] ) {
		if( newState == null && this.defaultStates[uniqueRoId] ) newState = this.defaultStates[uniqueRoId];
		if( newState == null ) return true;

		if( this.rollovers[uniqueRoId][newState] ) {
			var ele = (id.nodeName.toLowerCase() == "img" || id.nodeName.toLowerCase() == "input") ? id : document.getElementById(id);
			if( ele && ele.src )
				ele.src = this.rollovers[uniqueRoId][newState].src;
		}
	}
	return true;
}

/**
 * Add images and their rollover states by name-src pairs
 * <p>Example:</p>
 * <p><code>var ro = new com.jitjat.RollOvers();<br />ro.addSimpleRollover( "myImg", {normal:"/img/src.jpg", over:"/img/src-over.jpg"} );</code></p>
 * 
 * @param uniqueRoId <dfn>string</dfn> the unique ID of the rollover
 * @param stateMap <dfn>object</dfn> an associative array of state to image source mappings.
 **/
com.jitjat.RollOvers.prototype.addSimpleRollover = function( uniqueRoId, stateMap ) {
	this.rollovers[uniqueRoId] = new Object();

	for( state in stateMap ) {
		if( typeof stateMap[state] == "string" )
			this.rollovers[uniqueRoId][state] = this.createImage( stateMap[state] );
	}
}

/**
 * Swap the given simple image.
 * @param id <dfn>string, image, image form input</dfn> the unique ID of the image to be swapped
 * @param uniqueRoId <dfn>string</dfn> the unique ID of the generic rollover
 * @param newState <dfn>string</dfn> the new state of the image.
 * @type boolean
 * @return <code>true</code>
 **/
com.jitjat.RollOvers.prototype.swapSimpleImage = function( id, uniqueRoId, newState ) {
	return this.swapGenericImage( id, uniqueRoId, newState );
/*
	if( document.images && this.preloaded && this.rollovers[uniqueRoId] ) {
		if( newState == null && this.defaultStates[uniqueRoId] ) newState = this.defaultStates[uniqueRoId];
		if( newState == null ) return true;

		if( this.rollovers[uniqueRoId][newState] ) {
			var ele = (id.nodeName.toLowerCase() == "img" || id.nodeName.toLowerCase() == "input") ? id : document.getElementById(id);
			if( ele && ele.src )
				ele.src = this.rollovers[uniqueRoId][newState].src;
		}
	}
	return true;
*/
}


/**
 * Default states for rollovers.
 * @private
 * @type Array
 **/
com.jitjat.RollOvers.prototype.defaultStates = new Object();

/** 
 * Set a default date for a rollover ID.
 * @param id <dfn>string</dfn> image id or generic rollover id.
 * @param state <dfn>string</dfn> the new default state of the rollover.
 * @return Void
 **/
com.jitjat.RollOvers.prototype.setDefaultState = function( id, state ) {
	if( id == null || id == "" ) return;
	
	if( typeof id == "string" ) id = [id];

	for( var i=0; i<id.length; i++ ) {
		if( state == null || state == "" ) delete this.defaultStates[id[i]];
		else this.defaultStates[id[i]] = state;
	}
}

/**
 * Preload the rollovers.
 * <p>Call the functions added via the <code>addPreloader( funcRef:Function )</code> method.
 **/
com.jitjat.RollOvers.prototype.preload = function() {
	for( var i=0; i<this.preloaders.length; i++ ) {
		this.preloaders[i].apply(this);
	}
	this.preloaded = true;
}

/**
 * An array of functions preload information.
 * @private
 * @type Array
 **/
com.jitjat.RollOvers.prototype.preloaders = new Array();

/**
 * Add a preloader function.
 * <p>Functions will be called via the Function.apply method. "<code>this</code>" will refer to this RollOvers instance.</p>
 **/
com.jitjat.RollOvers.prototype.addPreloader = function( funcRef ) {
	if( typeof funcRef == "function" )
		this.preloaders[this.preloaders.length] = funcRef;
}


/****
Instances
*****/

var ro = new com.jitjat.RollOvers();

ro.addPreloader( function() {
	this.addRollover( ["patients_and_families","health_care_professionals","resources_and_support"], ["on"], "/images/global/nav-primary/pc_nav-primary_", ".gif", "-", true );
	this.addRollover( ["btn-ask_a_medical_question", "btn-pompe_registry"], ["over"], "/images/global/pc_", ".gif", "-", true );
} );

var flashWinIndex = 0;
function popupFlash( flashSrc, flashWidth, flashHeight, flashTitle ) {
	com.bigbad.Popup.popup("/global/pc_flash_popup.asp?src=" + escape(flashSrc) + "&w=" + escape(flashWidth) + "&h=" + escape(flashHeight) + "&title=" + escape(flashTitle) , "flashWin"+(flashWinIndex++), null, {width:flashWidth+40,height:flashHeight+50} );
}

function linkClick( link, evt ) {}

function popupGlossary( link ) {
	link.href = link.href.replace("#","?jump=");
	link.href = link.href.replace('pc_eng_rs_glossary-popup-body.asp', 'pc_eng_rs_glossary-popup.asp');
	link.target = "glossary";

	return com.bigbad.Popup.popupDom( link, null, {width: 400, height: 400} );
}

// add to this array to allow other domains to ignore the disclaimer
var internalDomains = ["genzyme.com","pomperegistry.com","lsdregistry.net"];

function clickExternalLink( link ) {
	if( link.href.indexOf("http://" + location.host ) == 0 ) { // internal links marked as external
		if( link.href.indexOf( "/resources/glossary/pc_eng_rs_glossary-popup" ) >= 0 ) {
			link.target = "glossary";
			return popupGlossary( link );
		}
	} else if( link.href.indexOf( "disclaimer_jumpsite.asp" ) < 0 ) {
		link.target="_blank";
		for( var i=0; i<internalDomains.length; i++ ) {
			if( link.href.indexOf( internalDomains[i] ) >= 0 ) {
				return;
			}
		}
		link.href = "/global/disclaimer_jumpsite.asp?url=" + escape( link.href );
	}
	return null;
}

function addClassName( cn, ele ) {
	var currentCn = ele.className;
	cn = cn.trim();

	if( currentCn == null || currentCn.trim() == "" ) {
		ele.className = cn;
	} else {
		currentCn = currentCn.trim().split( new RegExp("/s") ).join(" ");
		if( (" " + currentCn + " ").indexOf(" " + cn + " ") < 0 ) {
			ele.className = currentCn + " " + cn;
		}
	}
}

function removeClassName( cn, ele ) {
	var currentCn = ele.className;
	if( currentCn == null || currentCn.trim() == "" ) return;

	cn = cn.trim();

	// don't continue if the class isn't included
	if( currentCn.indexOf( cn ) < 0 ) return;

	currentCn = currentCn.trim();

	// if the two equal, just remove all class names
	if( currentCn == cn ) {
		ele.className = "";
		return;
	}

	// the class name is one of many
	currentCn = currentCn.replace( new RegExp("\\s+" + cn + "\\s+","g"), " " );

	// the class name is at the beginning
	currentCn = currentCn.replace( new RegExp("^" + cn + "\\s+","g"), "" );

	// the class name is at the end
	currentCn = currentCn.replace( new RegExp("\\s+" + cn + "$","g"), " " );

	ele.className = currentCn;

}
