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 leaveSite(obj){
	var tempLink = $(obj).attr('href');
    tempLink.indexOf("extSite=") != -1 ? tempLink = tempLink.substr(tempLink.indexOf("extSite="), tempLink.length) : null;     
    
	if(tempLink.indexOf('http://' || 'https://') >-1){
	
		var warningmsg1 = "You have clicked on a link that will take you out of this website";
		var warningmsg2 = "You have clicked on a link that will take you out of the MSActiveSource.com website";
		var warningmsg3 = "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.";
		
		// The order of these if statments matters!
		if (tempLink.indexOf("www.biogenidec.com")>-1){
			return confirm(warningmsg1);
		} else if (tempLink.indexOf("www.msleadersofhope.com")>-1){
			return confirm(warningmsg1);
		} else if(tempLink.indexOf("boss.streamos.com")>-1){
			return true;
		} else if(tempLink.indexOf("www.avonex.com")>-1){
			return confirm(warningmsg2);
		} else if(tempLink.indexOf("https://www.msactivesource.com")>-1){
			return confirm(warningmsg2);
		} else if(tempLink.indexOf("www.tysabri.com")>-1){
			return confirm(warningmsg2);
		} else if(tempLink.indexOf("msas/home")>-1){
			return confirm(warningmsg2);
		} else if(tempLink.indexOf("www.mymsyoga.com")>-1){
			return confirm(warningmsg2);
		} else{
			return confirm(warningmsg3);
		}
	}else{
		return true;
	}
	
}


//from msas.js 
 function doFramesBuster()
{
  if ( top.location != self.location )
	breakFrames();
}

function breakFrames()
{
	setTimeout( "top.location.href = sThisURL", 1.5*1000 );
}

$(document).ready(function(e) {
    doFramesBuster();
});

/***** qTip init ******/

$(document).ready(function(e) 
{
   // Use the each() method to gain access to each elements attributes
   $('.tip-it').each(function()
   {
	   $(this).click(function(ev) {ev.preventDefault();});
	   
	   var tipElem = '#' + $(this).attr('rel');
	   
      $(this).qtip(
      {
         content: $(tipElem)
            // Set the text to an image HTML string with the correct src URL to the loading image you want to use
            //url: $(this).attr('rel') // Use the rel attribute of each element for the url to load
         ,
         position: {
            corner: {
               target: 'topMiddle', // Position the tooltip above the link
               tooltip: 'bottomMiddle'
            }
         },
         show: { 
            when: 'click', 
            solo: true, // Only show one tooltip at a time
			ready: false
         },
         hide: false,
         style: {
            tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
            border: {
               width: 0,
               radius: 4,
			   color: '#398bd1'
            },
            name: 'light', // Use the default light style
            width: 122,
			padding: 0
         },
		 api:{
			 onShow : function(){
				var closeDiv = document.getElementById('close');
				closeDiv.style.left = this.elements.tooltip.width() + this.elements.tooltip.position().left - 15 +'px';
				closeDiv.style.top = this.elements.tooltip.position().top - 10 + 'px';
				closeDiv.style.display = "block";
			 },
			 onHide : function(){
				var closeDiv = document.getElementById('close');
				closeDiv.style.display = "none";
			 }
		 }
      })
   });
});
function closeTip(){
	$('.tip-it').qtip("hide");
}



$(function(){
	/** Preliminary Settings **/
	$('#slidecontrol').fadeTo(500,.8);
	$('#slidecontrol').hover(function(){ $(this).fadeTo(200,1) }, function(){ $(this).fadeTo(200,.8) });
	
	/** homebanner "Learn More" button click function **/
	$('#homebanner_learnmore_button').click(function(){
		switch (ls){
			case 1:		slidehref = "/user/register"; break;
			case 2:		slidehref = "/ms-diet-and-exercise.xml"; break;
			case 3:		slidehref = "/ms-and-memory.xml"; break;
			case 4:		slidehref = "/multiple-sclerosis-treatment.xml"; break;
			default:	slidehref = "/user/register"; break;
		}
		self.location.href = slidehref; 
		
	});
	
	/** scbox (number boxes) click function **/
	$('.scbox').click(function(){		
		!$(this).hasClass('scbox_on') ? jumpSlide($(this).attr('value') * 1) : null;
	});
	
	/** Homebanner Images click function **/
	$('.homeslide, .slidetitle').click(function(){
		$('#homebanner_learnmore_button').click();
	});
	
	/** Easy "Button Press" Effects on images containing 'button' in their classes **/
	$("img[class*='button']").mousedown(function(){
		$(this).css({'margin-left':'1px', 'margin-top':'1px', 'margin-bottom':'-1px', 'margin-right':'-1px'});
	});
	$("img[class*='button']").bind('mouseup mouseout', function(){
		$(this).css({'margin-left':0, 'margin-top':0,'margin-bottom':0,'margin-right':0});
	});	
	
	/** Preload Slides **/
	$('.homeslide').each(function(){ $('<img/>')[0].src = $(this).attr('src') });
	$('.slidetitle').each(function(){ $('<img/>')[0].src = $(this).attr('src') });
	
	
	/** Start Sideshow **/
	pushSlide(1);
	
});
 
/** Slide Show Settings **/
var slides = 4;
var fdelay = 4000;		// delay time between slides w/fading
var edelay = 5000;		// delay time between slides without fading (ie)
var ftime  = 1000;		// slide fade-in time
var fpause = 8000;		// time to pause on user interaction
var s = 1;				// current slide count holder
var ns = 1;				// next slide count holder
var ls = 1;				// link switch for learnmore button setting
var pauseit;			// holds pause if evoked
 
function pushSlide(s){
	s = (s * 1);
	ns = s;
	ls = s;
	window.clearTimeout(pauseit);
	thisslide = $('#homeslide' + s);
	ns == slides ? ns = 1 : ns = (ns + 1);
	nextslide = $('#homeslide' + ns);
	if($.support.opacity){ 
		$(thisslide).delay(fdelay).fadeOut(ftime/2);
		pauseit = window.setTimeout(function(){ pushBox(ns); pushInfo(ns) }, fdelay);		
		$(nextslide).delay(fdelay).fadeIn(ftime, function(){ 
			pushSlide(ns);
		});
	}else{
		pauseit = window.setTimeout(function(){ 
					$(thisslide).hide();
					pushBox(ns); 
					pushInfo(ns) 
					}, edelay);
		$(nextslide).delay(edelay).show(0, function(){ 
			pushSlide(ns);
		});
	}
}
 
function jumpSlide(s){
	window.clearTimeout(pauseit);
	$('img').clearQueue();
	$(':animated').stop(true);	
	s = s * 1; ls = s;
	pushBox(s);
	pushInfo(s);
	jumpslide = $('#homeslide' + s);
	if($.support.opacity){
		$('.scbox').unbind('click');
		$('.homeslide').fadeOut(ftime/2);
		$(jumpslide).fadeIn(ftime, function(){
			$('.scbox').click(function(){		
			!$(this).hasClass('scbox_on') ? jumpSlide($(this).attr('value') * 1) : null;
			});
		});
	}else{
		$('.homeslide').hide();
		$(jumpslide).show();
	}	
	pauseit = window.setTimeout(function(){ pushSlide(s) }, fpause); 
}
 
 
function pushBox(ns){
	$('.scbox').each(function(){
		$(this).attr('value') * 1 == ns  ? $(this).addClass('scbox_on') : $(this).removeClass('scbox_on');
	});
}
 
function pushInfo(ns){
	if($.support.opacity){
		$('.slideinfo').fadeOut(ftime/2).each(function(){
			$(this).attr('value') * 1 == ns ? $(this).fadeIn(ftime) : null;
		});
	}else{
		$('.slideinfo').hide().each(function(){
			$(this).attr('value') * 1 == ns ? $(this).show() : null;
		});		
	}
}
 

