var Popup=null;
var NS4 = (document.layers) ? true : false;

function checkEnter(event)
{
	var code = 0;
	if (NS4)
		code = event.which;
	else
		code = event.keyCode;
	if (code==13){
		submitSearch();
	}
}

function submitSearch()
{
	var url ="<ptl:createPortalPageChangeURL pageName='search' doRedirect='false'/>";
	var intxt = document.bannersearch.search.value;
	var tempurl = url+"&param="+intxt
	if(intxt==""){
		alert("Please enter the search term.");
	}else{
		self.location=tempurl;
	}
}

function submitOnEnter(event, myObject){

    var code = 0;
    if (NS4)
        code = event.which;
    else
        code = event.keyCode;
    if (code==13){

        for (var i=0; i<document.forms.length; i++) {
            for (var j=0; j<document.forms[i].elements.length; j++)
            {
                 if (document.forms[i].elements[j] == myObject) {
                    document.forms[i].submit();
                    return true;
                 }
             }
        }
    }

    return false;
}

function leaveSite(obj){
	var tempLink = obj.href;
    if (tempLink.indexOf("extSite=") != -1) {
        tempLink = tempLink.substr(tempLink.indexOf("extSite="), tempLink.length);
        //alert(tempLink);        
    }
    // The order of these if statments matters!
	if (tempLink.indexOf("www.biogenidec.com")>-1){
		return confirm("You have clicked on a link that will take you out of this website");
	} else if (tempLink.indexOf("www.msleadersofhope.com")>-1){
		return confirm("You have clicked on a link that will take you out of this website");
	} else if(tempLink.indexOf("boss.streamos.com")>-1){
		return true;
	} else if(tempLink.indexOf("www.avonex.com")>-1){
		return confirm("You have clicked on a link that will take you out of the MSActiveSource.com website");
	} else if(tempLink.indexOf("https://www.msactivesource.com")>-1){
		return confirm("You have clicked on a link that will take you out of the MSActiveSource.com website");
	} else if(tempLink.indexOf("www.tysabri.com")>-1){
		return confirm("You have clicked on a link that will take you out of the MSActiveSource.com website");
	} else if(tempLink.indexOf("msas/home")>-1){
		return confirm("You have clicked on a link that will take you out of the MSActiveSource.com website");
	} else if(tempLink.indexOf("www.mymsyoga.com")>-1){
		return confirm("You have clicked on a link that will take you out of the MSActiveSource.com website");
	} else{
		return confirm("You are leaving MSActiveSource.com. This link will take you to a website that is outside the control of Biogen Idec. We provide links as a public service and for informational purposes only. We do not make or imply any endorsement of external web sites.");
	}
}



function localOnLoad() {}  //empty function call to rid error

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions

//from msas.js 
 function doFramesBuster()
{
  if ( top.location != self.location )
	breakFrames();
}

function breakFrames()
{
	setTimeout( "top.location.href = sThisURL", 1.5*1000 );
}


function onLoad()
{
   
    doFramesBuster();
   
}


// text sizer
function changeFontSize(utilCss, fontReq) {

	if (utilCss) {
	
		//(fontSizeVal == 2) ? (fontSizeVal=0):(fontSizeVal++);
		
		fontSizeVal = fontReq;
		
		toggleFont();
		
	} else {
	
		if (fontSizeVal != 0) {
		
		toggleFont();
			
		}
	}
	
}

function toggleFont() {

	var newCss = '/msas/site/styles/msas' + fontSizeVal + '.css';
		
	
	$('<link rel="stylesheet" type="text/css" media="all" href="'+newCss+'" >').appendTo("head");


	$.cookie('fontSizeSetting', fontSizeVal, { path: '/', expires: 1000 });
	
	
}


/**
 * Strange name because Weblogic has its own openPopup method.
 **/
function openDefaultPopup(destination) {
    openPopup(645, 450, destination, 'yes', 'yes');
}

function openPopup(width,height,destination,scrollbars)
{
	openPopup(width,height,destination,scrollbars,"no");
}

function openPopup(width,height,destination,scrollbars,menu)
{
	LeftPosition=(screen.availWidth)?(screen.availWidth-width)/2:50;
	TopPosition=(screen.availHeight)?(screen.availHeight-height)/2:50;
	settings='width='+width+',height='+height+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbars+',location=no,directories=no,status=no,menubar='+menu+',toolbar=yes,resizable=yes';
	Popup = window.open(destination,'popup',settings);
	Popup.focus();
}

