//smartsite site root: equivalent to ~/
var siteroot = (typeof(fullsiteroot) == "function") && (typeof(sitehost) == "function") ? fullsiteroot().replace(sitehost(), "") : "/";
//language
var lang = location.href.indexOf("/en/") > - 1 ? "en" : "fr";
//fixes double slash in URLs
var normalizePath = function(string) {return string.replace(/(\/+)|\\+/g, "/");}
//escapes <, > & and " into corresponding html entities
var escapeHTML = function(string) {return string.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");}
//rounds a number to two decimals places. Returns a string
var toCurrency = function(number) {return number.toFixed(2);}
//IE background image cache script
//@cc_on try {document.execCommand("BackgroundImageCache", false, true);} catch(e) {}
var isHCP = location.href.indexOf("/hcp/") > -1 || location.href.indexOf("elements/error_404_hcp/") > -1;
var isMsWalks = location.href.indexOf("/ms_walks/") > -1 ;
var isPSK = location.href.indexOf("/psk/") > -1 ;

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

Event.observe(window, "load", function() {
	
	 if(isMsWalks || isPSK) {
	
		showInfoBox();	
		fontResizing(); 
	 }
	 if (isHCP) {
		
		  //set font size
		 if (location.href.match(/\/hcp\/.+/)) {
			 var maincontent = $('content');
			
			 var cookieValue = Cookie.get('userFontSize');
			 if (maincontent) maincontent.style.fontSize = (cookieValue != null ? maincontent.style.fontSize = cookieValue + '%' : "100%");
			// document.getElementById("content").className="content"
			// maincontent.className="content";
		 }
		
		 if($('navfontsmall')){
			
			 $('navfontsmall').observe('click',decreasefontsize);
			 $('navfontbig').observe('click',increasefontsize);
		 } 
		
		 /*  external links popup */
		 if ($('content')) {
			$('content').select('a[href^="http"]').invoke('observe','click',function(ev){																		 
				Event.stop(ev);
				// only use for external pages except privacy policy
				var txtmsg = "<h2>You Are About to Leave an Acorda Therapeutics, Inc. Website.</h2>";
				txtmsg += "	<p><strong>Please note:</strong></p>";
				txtmsg += "<p>By clicking on this link, you will be leaving Ampyra.com and going to another, entirely independent website. Acorda Therapeutics, Inc. provides these links as a service to its website visitors and users; however, it takes no responsibility for the information presented on any websites but its own.</p>";
				var txtok = "Yes, leave";
				var txtcancel = "No, stay";
				var modalmsg = new Element('div',{'id':'leavemodal'});
				modalmsg.className = "hidden";
				var modaltxt = new Element('div',{'class':'leavemodal'}).update(txtmsg+'<br><br>');
				var proceedbtn = new Element('button',{'class':'button','onclick':'openLink("'+this.href+'","")'}).update('<span><span>'+txtok+'</span></span>');
				var cancelbtn = new Element('button',{'class':'button','onclick':'Modal.close()'}).update('<span><span>'+txtcancel+'</span></span>');
				$('layout').insert(modalmsg);
				$('leavemodal').update('');
				$('leavemodal').insert(modaltxt);
				$('leavemodal').down().insert(proceedbtn);
				$('leavemodal').down().insert(cancelbtn);
				Modal.open({contentEl: 'leavemodal', modalStyle:'leavemodal'});
					
			});
		 }

		/*  external links on footer popup */
		if ($('disclaimer')) {
			$('disclaimer').select('a[href^="http"]').invoke('observe','click',function(ev){																		 
				Event.stop(ev);
				// only use for external pages except privacy policy
					var txtmsg = "<h2>You Are About to Leave an Acorda Therapeutics, Inc. Website.</h2>";
					txtmsg += "	<p><strong>Please note:</strong></p>";
					txtmsg += "<p>By clicking on this link, you will be leaving Ampyra.com and going to another, entirely independent website. Acorda Therapeutics, Inc. provides these links as a service to its website visitors and users; however, it takes no responsibility for the information presented on any websites but its own.</p>";
					var txtok = "Yes, leave";
					var txtcancel = "No, stay";
					var modalmsg = new Element('div',{'id':'leavemodal'});
					modalmsg.className = "hidden";
					var modaltxt = new Element('div',{'class':'leavemodal'}).update(txtmsg+'<br><br>');
					var proceedbtn = new Element('button',{'class':'button','onclick':'openLink("'+this.href+'","")'}).update('<span><span>'+txtok+'</span></span>');
					var cancelbtn = new Element('button',{'class':'button','onclick':'Modal.close()'}).update('<span><span>'+txtcancel+'</span></span>');
					$('layout').insert(modalmsg);
					$('leavemodal').update('');
					$('leavemodal').insert(modaltxt);
					$('leavemodal').down().insert(proceedbtn);
					$('leavemodal').down().insert(cancelbtn);
					Modal.open({contentEl: 'leavemodal', modalStyle:'leavemodal'});
						
			});
		}
	 }
	$$('#radiocontainer a').each(function(el){
		var button = $('radiobutton');
		el.observe('click',function(ev){
			Event.stop(ev);
			$$('#radiocontainer a').each(function(oldel){
				oldel.removeClassName('selectedfirst');
				oldel.removeClassName('selected');
				oldel.removeClassName('selectedlast');				
			});
			if(el.hasClassName('first')){
				el.addClassName('selectedfirst');
			}
			else if(el.hasClassName('last')){
				el.addClassName('selectedlast');
			}
			else{
				el.addClassName('selected');
			}
			new Effect.Move(button,{ x: ((el.offsetLeft + (el.offsetWidth / 2)) - (button.offsetWidth / 2)), y: 31,mode:'absolute'});
			$('sliderValue').value = el.id;
		})
	});
	
	$$('.question a').each(function(button){
		disableRecommendedwithCookie(button);
	});
		
	$$('.questiondiv').each(function(qd) {
		$(qd).select(".radio").each(function(el) {
			el.observe('click', function(){
				var allchecked = 0;
				var score = 0;
				$(qd).select(".radio").each(function(el2) {
							var ZV = String(el2.getAttribute("zimentvalue"));
							if (el2.checked && ZV.match(/^\d+$/g)) {
								score = score + parseInt(ZV);
								allchecked++;
							}
						});

				if (allchecked >= 3 && (score >= 2 && score <= 5)) {
					if($('ZimentQuestion_' + qd.id)) $('ZimentQuestion_' + qd.id).removeClassName('hidden')					
				} else {
					if($('ZimentQuestion_' + qd.id)) $('ZimentQuestion_' + qd.id).addClassName('hidden')					
				}
			});
		});
	});
	
	showHideAddress();
	//Add the dragging of the images for the Discussion Guide
	if($('radiobutton')){
		var button = $('radiobutton');
		var container = $('radiocontainer');
		new Draggable(button, {
			zindex : 9999,
			constraint:'horizontal',
			snap: function(x, y) {
				return[ (x < 0) ? 0 : (x > (container.offsetWidth - button.offsetWidth) ? (container.offsetWidth - button.offsetWidth) :x),y];
			},
			onDrag:function(){
				var loc = button.offsetLeft;
				var aCounter = 0;
				$$('#radiocontainer a').each(function(el){
					el.removeClassName('selectedfirst');
					el.removeClassName('selected');
					el.removeClassName('selectedlast');
					if(loc>=el.offsetLeft && loc<(el.offsetLeft + el.offsetWidth)){
						if(aCounter == 0){
							el.addClassName('selectedfirst');
						}
						else if(aCounter == ($$('#radiocontainer a').length - 1)){
							el.addClassName('selectedlast');
						}
						else{
							el.addClassName('selected');
						}
					}
					aCounter = aCounter + 1;
				});
			},
			onEnd:function(){
				var loc = button.offsetLeft;
				$$('#radiocontainer a').each(function(el){
					if(loc>=el.offsetLeft && loc<(el.offsetLeft + el.offsetWidth)){
						new Effect.Move(button,{ x: ((el.offsetLeft + (el.offsetWidth / 2)) - (button.offsetWidth / 2)), y: 31,mode:'absolute'});
						$('sliderValue').value = el.id;
					}
				});
			}
		});
	}
	
	//Put the button in the right spot
	if($('radiobutton')){
		var element;
		if($('sliderValue').value.length > 0){
			element = $($('sliderValue').value);
			$('radiobutton').style.top = 31+"px";
			$('radiobutton').style.left = ((element.offsetLeft + (element.offsetWidth / 2)) - ($('radiobutton').offsetWidth / 2))+"px";
		}
		else{
			element = $$('#radiocontainer a').first();
			$('radiobutton').style.top = 31+"px";
			$('radiobutton').style.left = ((element.offsetLeft + (element.offsetWidth / 2)) - ($('radiobutton').offsetWidth / 2))+"px";
		}
	}
	
	$$(".seminarregitemheader .collapser").invoke("observe", "click", function(e) {
		Event.stop(e)
		$(this).up(".seminarregitemheader").next(".seminarregitembody").toggleClassName("hidden")
		$(this).toggleClassName("collapsed")
		this.innerHTML = this.innerHTML == "Click to hide" ? "Click to show" : "Click to hide"
	})
	
});

var isLarge = false;
var increasefontsize = function() {
	if (isLarge ) return
	isLarge = true;
	var maincontent = $('content');
	
	if (maincontent.style.fontSize == '')
		maincontent.style.fontSize = '100%';
	var currrentpercentage = eval(maincontent.style.fontSize.replace('%',''));
	if (currrentpercentage < 130) {
		currrentpercentage = currrentpercentage + 10
		maincontent.style.fontSize = currrentpercentage + '%';
		Cookie.set('userFontSize',currrentpercentage,240)
	}
}

var decreasefontsize = function() {
	
	if (!isLarge) return
	isLarge = false;
	var maincontent = $('content');
	var currrentpercentage = eval(maincontent.style.fontSize.replace('%',''));
	if (currrentpercentage > 100) {
		currrentpercentage = currrentpercentage - 10
		maincontent.style.fontSize = currrentpercentage + '%';
		Cookie.set('userFontSize',currrentpercentage,240)
	}
}

var openLink = function(href,inner){
	Modal.close();
	if (typeof(pageTracker) != "undefined" && pageTracker != null && pageTracker) {
		pageTracker._trackEvent('Exit Links','Exit',href);
		pageTracker._trackPageview('/outbound/' + href);
	}
	window.open(href,'');	
}

var gotoConsumerSite = function (host, ssva_vid) {
	gotoSite(host, ssva_vid, 'home/');
}

var gotoHcpSite = function (host, ssva_vid) {
	gotoSite(host, ssva_vid, 'hcp/');
}

var gotoSite = function (host, ssva_vid, page) {
	var href = 'http://' + host + page;
	
	if (typeof(pageTracker) != "undefined" && pageTracker != null && pageTracker) {
		pageTracker._trackEvent('Exit Links','Exit',href);
		pageTracker._trackPageview('/outbound/' + href);
	}

	window.location.href = href + '?ssva_vid=' + ssva_vid;
}

var GaUtmzCookieValue = {};
var SetGaUtmzCookieValue = function () {
	var UnParsedCookie = document.cookie;
	UnParsedCookie = UnParsedCookie.replace(/^.*__utmz=141250475(\d|\.)+(utm[^;]+).*$/gi, "$2");
	UnParsedCookie = UnParsedCookie.split("|");
	for (var i=0; i<UnParsedCookie.length; i++) {
		var Utm = UnParsedCookie[i].split("=");
		if (Utm.length > 1) {
			GaUtmzCookieValue[Utm[0].replace(/^\s+|\s+$/gi, "")] = Utm[1].replace(/^\s+|\s+$/gi, "");
		}
	}
}

Event.observe(window, "load", SetGaUtmzCookieValue);

var splashLink = function (href, ssva_vid) {
	if (typeof(pageTracker) != "undefined" && pageTracker != null && pageTracker) {
		pageTracker._trackEvent('Exit Links','Exit',href);
		pageTracker._trackPageview('/outbound/' + href);
		
		var DestHref = href + '?ssva_vid=' + ssva_vid;
		if (GaUtmzCookieValue) {
			if (GaUtmzCookieValue["utmccn"] != null && GaUtmzCookieValue["utmccn"].length > 0) DestHref += '&utm_campaign=' + GaUtmzCookieValue["utmccn"];
			if (GaUtmzCookieValue["utmcmd"] != null && GaUtmzCookieValue["utmcmd"].length > 0) DestHref += '&utm_medium=' + GaUtmzCookieValue["utmcmd"];
			if (GaUtmzCookieValue["utmcsr"] != null && GaUtmzCookieValue["utmcsr"].length > 0) DestHref += '&utm_source=' + GaUtmzCookieValue["utmcsr"];
			if (GaUtmzCookieValue["utmcct"] != null && GaUtmzCookieValue["utmcct"].length > 0) DestHref += '&utm_content=' + GaUtmzCookieValue["utmcct"];
			if (GaUtmzCookieValue["utmctr"] != null && GaUtmzCookieValue["utmctr"].length > 0) DestHref += '&utm_term=' + GaUtmzCookieValue["utmctr"];
		}
		window.location.href = DestHref;
	}
}

/**************** cookies ********************************/
/**
 * @author 	Maxime Haineault (max@centdessin.com)
 * @version	0.3
 * @desc 	JavaScript cookie manipulation class
 * 
 */
Cookie = {
	/** Get a cookie's value
	 *
	 *  @param integer	key		The token used to create the cookie
	 *  @return void
	 */
	get: function(key) {
		// Still not sure that "[a-zA-Z0-9.()=|%/]+($|;)" match *all* allowed characters in cookies
		tmp =  document.cookie.match((new RegExp(key +'=[a-zA-Z0-9.()=|%/]+($|;)','g')));
		if(!tmp || !tmp[0]) return null;
		else return unescape(tmp[0].substring(key.length+1,tmp[0].length).replace(';','')) || null;		
	},	
	
	/** Set a cookie
	 *
	 *  @param integer	key		The token that will be used to retrieve the cookie
	 *  @param string	value	The string to be stored
	 *  @param integer	ttl		Time To Live (hours)
	 *  @param string	path	Path in which the cookie is effective, default is "/" (optional)
	 *  @param string	domain	Domain where the cookie is effective, default is window.location.hostname (optional)
	 *  @param boolean 	secure	Use SSL or not, default false (optional)
	 * 
	 *  @return setted cookie
	 */
	set: function(key, value, ttl, path, domain, secure) {
		cookie = [key+'='+    escape(value),
		 		  'path='+    ((!path   || path=='')  ? '/' : path),
		 		  'domain='+  ((!domain || domain=='')?  window.location.hostname : domain)];		
		if (ttl)         cookie.push('expires='+Cookie.hoursToExpireDate(ttl));
		if (secure)      cookie.push('secure');
		return document.cookie = cookie.join('; ');
	},
	
	/** Unset a cookie
	 *
	 *  @param integer	key		The token that will be used to retrieve the cookie
	 *  @param string	path	Path used to create the cookie (optional)
	 *  @param string	domain	Domain used to create the cookie, default is null (optional)
	 *  @return void
	 */
	unset: function(key, path, domain) {
		path   = (!path   || typeof path   != 'string') ? '' : path;
        domain = (!domain || typeof domain != 'string') ? '' : domain;
		if (Cookie.get(key)) Cookie.set(key, '', 'Thu, 01-Jan-70 00:00:01 GMT', path, domain);
	},

	/** Return GTM date string of "now" + time to live
	 *
	 *  @param integer	ttl		Time To Live (hours)
	 *  @return string
	 */
	hoursToExpireDate: function(ttl) {
		var time = (parseInt(ttl) * 60 * 60 * 1000)
		if (parseInt(ttl) == 'NaN' ) return '';
		else {
			now = new Date();
			now.setTime(now.getTime() + time);
			return now.toGMTString();			
		}
	},

	/** Return true if cookie functionnalities are available
	 *
	 *  @return boolean
	 */
	test: function() {
		Cookie.set('b49f729efde9b2578ea9f00563d06e57', 'true');
		if (Cookie.get('b49f729efde9b2578ea9f00563d06e57') == 'true') {
			Cookie.unset('b49f729efde9b2578ea9f00563d06e57');
			return true;
		}
		return false;
	},
	
	/** If Firebug JavaScript console is present, it will dump cookie string to console.
	 * 
	 *  @return void
	 */
	dump: function() {
		if (typeof console != 'undefined') {
			console.log(document.cookie.split(';'));
		}
	}
}
/**************** end cookies ********************************/
// xDocSize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDocSize(){
	var b=document.body, e=document.documentElement;var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
	if (e) {esw = e.scrollWidth;eow = e.offsetWidth;esh = e.scrollHeight;eoh = e.offsetHeight;}
	if (b) {bsw = b.scrollWidth;bow = b.offsetWidth;bsh = b.scrollHeight;boh = b.offsetHeight;}
	return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

//Modal mask
/* modal mask */
var Modal = {
	width : 400,
	onOpen : function() {},
	onClose : function() {},
	onResize : function() {},
	open : function(options) {
		options = options || {};
		var title = options.title || "";
		var url = options.url || "";
		var params = options.params || {};
		var contentEl = options.contentEl || "";
		var onComplete = params.onComplete || function() {};
		var v1 = "";
		var v2 = "";
		Modal.onOpen = options.onOpen || function() {};
		Modal.onClose = options.onClose || function() {};
		Modal.onResize = options.onResize || function() {};
		Modal.onTransferContent = options.onTransferContent || function() {};
		Modal.modalStyle = options.modalStyle || "standardmodal";
		Modal.top = options.top || 100;
		Modal.width = options.width || 400;
		Modal.cleanUp();//clean up old modal
		params.onComplete = function() {
			if ($("modalloader")) $("modalloader").remove();//in case of error, don't show loading animation forever
			onComplete.apply(null, arguments);
		};
		
		if (url != "") {
			$("modalcontent").innerHTML = "<div id='modalloader' class='modalloader'></div>";//show loading animation
			if (Modal.updater) Modal.updater.transport.abort();//abort old ajax requests
			if($('pageTitle')) v1= $('pageTitle').value.replace("\xAE", "&reg;");
			//if($('pageRelativeUrl')) v2 = $('pageRelativeUrl').value.replace("\xAE", "&reg;");
			v2 = (window.location.pathname + window.location.search).replace(siteroot, "");
			
			if (params["method"] == null || params["method"] == "") params["method"] = "get";
			Modal.updater = new Ajax.Updater("modalcontent", url+(url.indexOf("?") >= 0 ? "&" : "?")+"title="+escape(v1)+"&relativeurl="+escape(v2), params);
		}
		else if (contentEl != "") {//make sure moving contentEl into the modal doesn't duplicate id's
			Modal.contentOrigin = $(contentEl);
			Modal.transferContent(Modal.contentOrigin, "modalcontent");
		}
		$("modalcontainer").addClassName(Modal.modalStyle).removeClassName("hidden");
		$("modaltitle").innerHTML = title;
		Modal.resize();
		Modal.onOpen();//use params.onComplete if you want something to run after the AJAX finishes
	},
	close : function() {
		Modal.onClose();
		Modal.cleanUp();
	},
	cleanUp : function() {
		$("modalcontainer").removeClassName(Modal.modalStyle).addClassName("hidden");
		if (Modal.contentOrigin) {//make sure restoring contentEl doesn't duplicate id's
			Modal.transferContent("modalcontent", Modal.contentOrigin);
			Modal.contentOrigin = null;
		}
	},
	resize : function() {
		var dimensions = document.viewport.getDimensions();
		var height = $("modalbody").offsetHeight;
		var left = (document.documentElement.offsetWidth / 2) - (Modal.width / 2);
		var top = (dimensions.height > height + Modal.top) ? Modal.top : (dimensions.height - height) / 2;
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		left = (left > 0) ? left : 0;
		top = (top > 0) ? top : 0;
		$("modalbody").setStyle({
			width : Modal.width + "px",
			left : (scrollLeft + left) + "px",
			top : (scrollTop + top) + "px"
		});
		
		//only calculate scroll dimensions after modal body has been repositioned
		$("modalmask").hide();//hide mask temporarily to measure document size
		//alert(Prototype.Browser.Gecko);
		FFwidth = (Prototype.Browser.Gecko || Prototype.Browser.WebKit) ? 18 : 0;
		var scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight, dimensions.height);
		var scrollWidth = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth, dimensions.width) - FFwidth;
		$("modalmask").setStyle({
			height : scrollHeight + "px",
			width : scrollWidth + "px"
		});
		
		
		
		$("modalmask").show();
		Modal.onResize();
	},
	transferContent : function(source, dest) {
		$(dest).innerHTML = $(source).innerHTML;
		$(source).innerHTML = "";
		Modal.onTransferContent();
	}
}
Event.observe(window, "resize", Modal.resize);
Event.observe(window,"load",function() {
	$("modalcloser").observe("click", Modal.close);	
});

// external site link
function confirmExit(theLocation, theMessage) {
	var txtmsg = "This link will open an external website";
	var txtok = "Proceed";
	var txtcancel = "Cancel";
	var modalmsg = new Element('div',{'id':'leavemodal','class':'hidden'});
	var modaltxt = new Element('div',{'class':'leavemodal'}).update(txtmsg+'<br><br>');
	var proceedbtn = new Element('button',{'class':'button','onclick':'openLink("'+theLocation+'","")'}).update('<span><span>'+txtok+'</span></span>');
	var cancelbtn = new Element('button',{'class':'button','onclick':'Modal.close()'}).update('<span><span>'+txtcancel+'</span></span>');
	$('layout').insert(modalmsg);
	$('leavemodal').update('');
	$('leavemodal').insert(modaltxt);
	$('leavemodal').down().insert(proceedbtn);
	$('leavemodal').down().insert(cancelbtn);
	Modal.open({contentEl: 'leavemodal'});
}

var Behaviour = {
	//param: Object sheet = {cssRule : callback}
	//	where cssRule is a string and callback is a function that passes a DOM element as its parameter and returns null, i.e. void callback(DOMElement element)
	register : function(sheet) {Behaviour.list.push(sheet);},
	//call apply after ajaxing stuff if you want behaviour rules to apply to ajaxed elements
	apply : function() {
		for (h = 0; sheet = Behaviour.list[h]; h++) {
			for (selector in sheet) {
				list = $$(selector);
				if (!list) continue;
				for (i = 0; element = list[i]; i++) {
					if (element.getAttribute("behaviourized") != "true") {
						sheet[selector](element);
						element.setAttribute("behaviourized", "true");
					}
				}
			}
		}
	},
	//private
	list : new Array()
}
Event.observe(window, "load", function() {
	Behaviour.register({			
		"ul.tabs li a,ul.viewtypes li a" : function() {
			var tabs = [];
		
			return function(element) {
				var index = element.href.indexOf("#") + 1;
				if (index) {
					var body = document.getElementById(element.href.substring(index));
					if (body) {
						element.href = "javascript:;";
						tabs.push({tab : element.parentNode, body : body});
						Event.observe(element, "click", function() {
							setHomeTabCookie(element.id);
							for (var tab, i = 0; tab = tabs[i]; i++) {
								Element.removeClassName(tab.tab, "selected");
								Element.removeClassName(tab.tab, "previous");
								Element.addClassName(tab.body, "hidden");
							}
							Element.addClassName(element.parentNode, "selected");
							Element.addClassName(element.parentNode.previous(),"previous");
							Element.removeClassName(body, "hidden");
						})
					}
				}
			}
		}()
   });
	
	if(!isHCP ) {
		
		if(!isMsWalks){
			var userFontCookie = Cookie.get("userFontClass");
			var fontButtonCookie = Cookie.get("disabledFontButton");
			if($$(".homecontainer").length == 0 && userFontCookie != null) $(document.body).addClassName(userFontCookie);
			if(fontButtonCookie != null) {
				$$(".fontsize").invoke("removeClassName", "fontsizedisabled");
				if($$("."+fontButtonCookie).length > 0) $$("."+fontButtonCookie)[0].addClassName("fontsizedisabled");
			}
		}
		Behaviour.register({
			"ul.tabs li,button" : function(element) {
				Event.observe(element, "mouseover", function() {if(!element.hasClassName("selected")) Element.addClassName(element, "over");})
				Event.observe(element, /*@cc_on "mouseleave" || @*/"mouseout", function() {Element.removeClassName(element, "over");})
			},
			
			"a[href^='http']" : function(element) {
				var url = element.href;
				if(url.indexOf('ampyra') < 0) {
					Event.observe(element, "click", function(e) {
						Event.stop(e);
						Modal.open({
							title : "You Are About to Leave an<br />Acorda Therapeutics, Inc. website.",
							url : siteroot + "elements/widgets/leaving_site/",
							modalStyle : "leavingsite",
							params : {
								onComplete : function() {
									$$(".buttons")[0].down(".button").observe("click", function(){openLink(url)})
								}
							}
						})			
					}.bind(element))
				}
			},
			".fontsize" : function(element) {
				var fontsize = $$(".fontsize");
				var size = element.className.substring(13, 18);
				Event.observe(element, "click", function() {
					fontsize.invoke("removeClassName", "fontsizedisabled");
					element.addClassName("fontsizedisabled");
					for (var i = 1; i <= 3; i++) {
						Element.removeClassName(document.body, "size" + i);
					}
					var disabledButton = element.className.split(" ")[1];
					document.body.addClassName(size);
					Cookie.set('userFontClass', size, 240);
					Cookie.set('disabledFontButton', disabledButton, 240);
				}.bind(element))
			},
			".answer" : function(element) {
				var expandbu = $(element).down(".expand");
				var content = $(element).down("div").innerHTML;
				var shortcontent = content.substring(0, 150);
				if (content == shortcontent) expandbu.style.display = "none";
				else $(element).down("div").innerHTML = shortcontent + "...";
				Event.observe(expandbu, "click", function(e) {
					Event.stop(e);
					if(expandbu.hasClassName("collapse")){
						expandbu.innerHTML = "read more";
						expandbu.removeClassName("collapse");
						$(element).down("div").addClassName("answerc");
						$(element).down("div").innerHTML = shortcontent + "...";						
					} else {
						expandbu.innerHTML = "read less";
						expandbu.addClassName("collapse");
						$(element).down("div").removeClassName("answerc");
						$(element).down("div").innerHTML = content;
						pageTracker._trackEvent("Common Question FAQ","Read More",expandbu.getAttribute("question"));
					}
				}.bind(element))
			},
			".question a" : function(button) {
				var containertd = $(button).up();
				var containertop = $$(".faqcontainer")[0].cumulativeOffset()[1];
				Event.observe(button, "click", function(e) {
					Event.stop(e);
					if(!containertd.hasClassName("disabled")) {
						containertd.addClassName("disabled");
						setRecommendedCookie($(button).id);
						var originnumber = parseInt($(button).down(".rank").innerHTML);
						var top = containertd.cumulativeOffset()[1];
						var height = containertd.offsetHeight;
						$(button).down(".rank").innerHTML = originnumber + 1;
						new Ajax.Request(siteroot+'all_about_ampyra/faq/submitscore?questionid='+$(button).id,{asynchronous:true,method:'GET'});
						$("faqtip").removeClassName("hidden");
						$("faqtip").setStyle({top : (top - containertop - height) + "px"});
						setTimeout(function(){$("faqtip").addClassName("hidden");}, 1500)
					}
				}.bind(button))			
			},
			"a.tooltip" : function(element) {
				var tooltipcontent = $(element).readAttribute("rel")
				var tooltip = $("tooltipcontainer");
				var offset = $(element).cumulativeOffset();
				Event.observe(element, "mouseover", function() {
					tooltip.down(".tooltipcontent").innerHTML = tooltipcontent;
					var left = offset.left;
					var top = offset.top - $(tooltip).getHeight() - 10;
					tooltip.setStyle({"top":top + "px","left":left + "px"});
					if(tooltip.hasClassName("hidden")) Element.removeClassName(tooltip, "hidden");
					
					var GaEventName = String(element.getAttribute("gaeventname"));
					if (GaEventName != null && GaEventName != "undefined" && GaEventName.length > 0) {
						pageTracker._trackEvent("Links", GaEventName, document.getElementById("pageRelativeUrl").value + document.getElementById("pageAction").value + "/");
					}
				})
				Event.observe(element, /*@cc_on "mouseleave" || @*/"mouseout", function() {
					Element.addClassName(tooltip, "hidden");
				})
			}
		});
		showQuestions("describe");
	}
	Behaviour.apply();

})

var setPrimaryTabCookie = function(tabname){
	if(Cookie.test){
		if(tabname != '/splash/'){
			document.cookie ='primarytab='+escape(tabname)+'; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
		}
	}
}

var checkSplash = function(sitename){
	if(sitename == 'hcp'){
		$('consumerselector').checked = false;
		if($('hcpselector').checked){
			setSplashCookie(sitename);
		}
		else{
			removeSplashCookie(sitename);
		}
	}
	else if(sitename == 'consumer'){
		$('hcpselector').checked = false;
		if($('consumerselector').checked){
			setSplashCookie(sitename);
		}
		else{
			removeSplashCookie(sitename);
		}	
	}
}

var setSplashCookie = function(sitename){
	if(Cookie.test){
		document.cookie ='splashcheck='+escape(sitename)+'; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
	}
}

var removeSplashCookie = function(sitename){
	if(Cookie.test){
		document.cookie ='splashcheck=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/'
	}
}
var setHomeTabCookie = function(tabname){
	if(Cookie.test){
		document.cookie ='hometab='+escape(tabname)+'; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
	}
}

var setRecommendedCookie = function(questionid){
	if(Cookie.test){
		document.cookie='recommended'+questionid+'='+questionid+'; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/';
	}
}

var disableRecommendedwithCookie = function(button){
	var cookies = document.cookie.split('; ');
	var cooky;
	for(i=0;i<cookies.length;i++){
		cooky = cookies[i].split('=');
		if(cooky[0] == 'recommended'+button.id){
			if($(cooky[1])){
				button.up().addClassName("disabled");
			}
		}
	}
}

var changeAssessmentFormgotoPage = function(gotopage){
	if($('gotopage')) $('gotopage').value = gotopage;
	if($('step2form')) $('step2form').submit();
}

var emailGuide = function(DG_ID, fname){
	new Ajax.Request(siteroot+'talking_to_your_hcp/discussion_guide/download/email?DiscussionGuideID=' + DG_ID + '&filename='+fname+'&email='+$('emailAddress').value, {method: 'get',
		onSuccess: function(transport) {
			if(transport.responseText.length == 0){
				$('errorDiv').removeClassName('hidden');
				pageTracker._trackPageview('/talking_to_your_hcp/discussion_guide/download/email/tryagain/');
				pageTracker._trackEvent('Form Validation Failure', '/talking_to_your_hcp/discussion_guide/download/email/', 'email');
			} else{
				$('errorDiv').addClassName('hidden');
				$('emailInput').addClassName('hidden');
				$('eaddress').innerHTML = transport.responseText;
				$('MessageDiv').removeClassName('hidden');
				pageTracker._trackPageview('/talking_to_your_hcp/discussion_guide/download/email/complete/');
				RenderSemPixels();
				doClick();
			}
		}
	});
}

var sendToFriend = function(){
	$('yourEmailError').addClassName('hidden');
	$('theirEmailError').addClassName('hidden');
	$('nameError').addClassName('hidden');
	
	new Ajax.Request(siteroot+'elements/widgets/send_to_friend/sendemail?'+$('SendtoFriendForm').serialize(), {method: 'get',
		onSuccess: function(transport) {
			if(transport.responseText.length > 0){
				var retvals = transport.responseText.split(',');
				for (var i=0; i<retvals.length; i++) {
					if (String(retvals[i]).length > 0) $(retvals[i]).removeClassName('hidden');
				}
				var TrackingUrl = $('pageRelativeUrl').value + $('pageAction').value + '/send_to_friend/';
				pageTracker._trackPageview(TrackingUrl + 'tryagain/');
				pageTracker._trackEvent('Form Validation Failure', TrackingUrl, transport.responseText);
			} else {
				Modal.close();
				if (!isHCP)
					Modal.open({title:'E-mail this Page to a Friend',width:'750',url:siteroot+'elements/widgets/send_to_friend/thankyou/'});
				else
					Modal.open({title:'E-mail this Page to a Friend',width:'750',url:siteroot+'elements/widgets/send_to_friend/thankyouHCP/'});
			}
		}
	});

}

var showHideAddress = function(){
	if($('mailkit')){
		if($('mailkit').checked){
			$('addressdiv').removeClassName('hidden');
		}
		else{
			$('addressdiv').addClassName('hidden');
		}
	}
}

var showQuestions = function(radio) {
	var radio = $(radio);
	if (radio) {
		var target = $$("input[name='" + radio.name + "']");
		target.each(function(e){
			if(e.checked) $$("#" + e.value).invoke("removeClassName", "hidden");
			else $$("#" + e.value).invoke("addClassName", "hidden");
		});
	}
}

var RenderSemPixels = function () {
	var SIF = document.getElementById("SemIFrame");
	var PRU = document.getElementById("pageRelativeUrl");
	if (SIF && PRU) {
		var PRUValue = PRU.value;
		if (PRUValue.substr(0, 1) == "/") PRUValue = PRUValue.substr(1);
		SIF.src = siteroot + PRUValue + "sempixels.html?a=" + Number(new Date());
	}
}

var ResendConfirmationEmail = function(RID) {
	if (confirm("Are you sure you want to resend the confirmation email?")) {
		document.getElementById("ResendConfirmationEmailButton_" + RID).style.display = "none";
		document.getElementById("ResendConfirmationEmailSending_" + RID).style.display = "";
		new Ajax.Request(
				siteroot + "seminar/register/resendconf/" + RID, 
				{
					method:"post", 
					onComplete:function() {
								document.getElementById("ResendConfirmationEmailSending_" + RID).style.display = "none";
								document.getElementById("ResendConfirmationEmailSent_" + RID).style.display = "";
								setTimeout(function () { Effect.Fade("ResendConfirmationEmailSent_" + RID, { afterFinish:function(){ document.getElementById("ResendConfirmationEmailButton_" + RID).style.display = ""; } }); }, 2000);
							}
				}
				);
	}
}

var flash_video_event = function (VideoSource, VideoEvent) {
	if (VideoSource == siteroot + "local/flash/flv/HCP MOA_ 11_5_10_ CC.flv" && VideoEvent == "end") pageTracker._trackPageview("/hcp/all_about_ampyra/mechanism_of_action/video/MOA/complete/");
}

/********* FUNCTIONS FOR MSWALKS ********/

var showInfoBox = function(){
	
	if($('infobox')) {
		var moreinfo = $('moreinfo');
		var box = $('infobox');
		
		Event.observe(moreinfo, "mouseover", function(){ 
			box.toggle();
		}, false); 	
		
		Event.observe(moreinfo, "mouseout", function(){ 
			box.toggle();
		}, false); 		
	}
	
}

var mscontent = $('contentbody');

//set font size
var fontResizing = function(){

 		 
	mscontent = $('content');	
	var cookieValue = Cookie.get('userFontSize');
	if (mscontent) mscontent.style.fontSize = (cookieValue != null ? mscontent.style.fontSize = cookieValue + '%' : "100%");
	
	if($('navfontsmall')){		
		$('navfontsmall').observe('click',smallText);
		$('navfontmed').observe('click',mediumText);
		$('navfontbig').observe('click',largeText);
	} 	
}

/* font size increase */
function smallText() {	
 size = '100'; 
 mscontent.style.fontSize = size + '%';
 Cookie.set('userFontSize',size,100);
}

function mediumText() {
 size = '110';
 mscontent.style.fontSize = size + '%';
 Cookie.set('userFontSize',size,100);
}

function largeText() {
 size = '120';	
 mscontent.style.fontSize =  size + '%';
 Cookie.set('userFontSize',size,100);
}

var InitPatientVideo = function(VideoName) {
	jQuery("video").mediaelementplayer({
			plugins:["flash","silverlight"],
			pluginPath:siteroot + "local/flash/",
			flashName:"flashmediaelement.swf",
			success:function(Elem) {
				var LastPercentage = -1;
				Elem.addEventListener("play", function() {
					if (Elem.currentTime == 0) pageTracker._trackEvent("Patient_Video", "Start", VideoName);
				}, false);
				Elem.addEventListener("ended", function() {
					pageTracker._trackEvent("Patient_Video", "Complete", VideoName);
				}, false);
				Elem.addEventListener("timeupdate", function() {
					var CurrentPercentage = Math.floor((Elem.currentTime/Elem.duration)*10)*10;
					if (CurrentPercentage != LastPercentage && !Elem.paused) {
						pageTracker._trackEvent("Patient_Video", "Watched_Percentage", VideoName, CurrentPercentage);
					}
					LastPercentage = CurrentPercentage;
				}, false);
			
				Modal.onClose = function () {
					Elem.pause();
				}
			}
			});
}
