//used for all those mouseovers and mouseouts to swap images
function SwapImage(imageID, imageURL)
{
	var img = document.getElementById(imageID);
	
	if (img != null)
    	img.src = imageURL;
}

//used for the +/- thingy to toggle Learning Objects for a title
//if you specify the optional param, showIt, to 1, the block will display no matter what
function ToggleLearningObjectDisplay(divID, imageID, showIt)
{
	var elem = document.getElementById(divID);
	var imgShow = document.getElementById(imageID);
		
	if (elem) 
	{
		if (elem.style.display != 'block' || showIt == 1) 
		{
			if (imgShow) imgShow.src = "/Common/image/minusButton.gif";
			elem.style.display = 'block';
			elem.style.visibility = 'visible';
		} 
		else
		{
			if (imgShow) imgShow.src = "/Common/image/addButton.gif";
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
		}
	}
}

/* used to stop either media player from playing video */
function StopMediaPlayers()
{
	var oWM = document.getElementById('WMPlayer');
	if (oWM != null)
	{
		try
		{
			oWM.controls.stop();
		}
		catch (stopException)
		{
			//Suppress Error
		}
	}
	
	var oQT = document.getElementById('QTPlayer');
	if (oQT != null)
	{
		try
		{
			oQT.Stop();
		}
		catch (stopException)
		{
			//Suppress Error
		}
	}
}

function gotoPortalSearch()
{
  
    var txtKeyword = document.getElementById(masterPagePrefix + 'txtKeyword');
    if (txtKeyword == null)
        txtKeyword = document.getElementById(masterCommonPagePrefix + 'txtKeyword');
        
        
    var SearchColl = document.getElementById(masterPagePrefix + 'ddlCollections2');
    if (SearchColl == null)
        SearchColl = document.getElementById(masterCommonPagePrefix + 'ddlCollections2');
        
    
    var searchTerm = Trim(txtKeyword.value);
                
  if (SearchColl.options.length < 1){
        

//  if (searchTerm.length > 0)
//    {
        RemoveIllegalCharacters();
        if(searchTerm.match(/^\d*$/))
        {
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm); 
        }
        else
        {
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) +  "&rd=lo"
        }
    }
    
     else if (searchTerm.length > 0)
    {
        RemoveIllegalCharacters();
        if(searchTerm.match(/^\d*$/))
        {
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&sCid=" + SearchColl.options[SearchColl.selectedIndex].value;
        }
        else
        {
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) +  "&rd=lo&sCid=" + SearchColl.options[SearchColl.selectedIndex].value;
        }
    }
    
    return false;
}

function gotoPortalSearchHSC()
{
    var txtKeyword = document.getElementById(masterPagePrefix +'HSCSearchTxt');
    
    var SearchType = document.getElementById(masterPagePrefix +'HSSearch');
    
    var searchTerm = Trim(txtKeyword.value);
    
	


   if (searchTerm.length > 0)
    {
        
	
	RemoveIllegalCharacters();
        if(SearchType.value == "Search By Segments")
        {
        
   
	 //window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&sCid=" + SearchColl.options[SearchColl.selectedIndex].value;
            //window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&rd=lo&sCid=1882";
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&rd=lo";
        }
        else if(SearchType.value == "Search By Titles")
        {
            //window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) +  "&rd=lo&sCid=" + SearchColl.options[SearchColl.selectedIndex].value;
            //window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&sCid=1882";
             window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm);
        }
    }
    
    return false;  
}

function gotoPortalSearchFMG()
{
    var txtKeyword = document.getElementById(masterPagePrefix +'FMGSearchTxt');
    
    var SearchType = document.getElementById(masterPagePrefix +'FMGSearch');
    
    var searchTerm = Trim(txtKeyword.value);
    
	


   if (searchTerm.length > 0)
    {
        
	
	RemoveIllegalCharacters();
        if(SearchType.value == "Search By Segments")
        {
        
   
	 //window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&sCid=" + SearchColl.options[SearchColl.selectedIndex].value;
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) + "&rd=lo";
        }
        else if(SearchType.value == "Search By Titles")
        {
            //window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm) +  "&rd=lo&sCid=" + SearchColl.options[SearchColl.selectedIndex].value;
            window.location.href = "/PortalSearch.aspx?q=" + URLEncode(searchTerm);
        }
    }
    
    return false;  
}



function changeMainCollection()
{
    var url = window.location.href;
    var collection = "";
    
    if ($(masterPagePrefix + 'ddlCollections') == null)
    {
        collection = $F(masterCommonPagePrefix + 'ddlCollections');
    }
    else
    {
        collection = $F(masterPagePrefix + 'ddlCollections');    
    }
    
    //find first position of original id
    var searchString = 'cid=';
    var pos = url.indexOf(searchString);
       
    if (pos > -1)
    {
        //find end position of the querystring searchString
        var pos2 = url.substring(pos + searchString.length).indexOf('&');
        
        if (pos2 == -1)
        {
            //no end, remove the querystring from the url, including the final ?
            url = url.substring(0, pos - 1);
        }
        else
        {
            //end point, remove the middle searchString piece, bump up 1 to remove the &          
            url = url.substring(0, pos) + url.substring(pos + searchString.length + pos2 + 1);
        }
    }
    
    url = url.replace("sAll=t", "");
                 
    url += (url.indexOf("?") == -1) ? '?' : '&';    
    url = '/PortalHomeLanding.aspx?cid=' + collection;
    
    document.location.href = url;    
}

