﻿		
		// Search Plugin for IE7/Firefox - Brent Green (2007-02-27)
		function AddSearchPlugin()
		{
			document.cookie = 'RealAgeSearchPlugin=800; expires=Thu, 31 Dec 2099 20:00:00 UTC; path=/';
			if (window.external)
				window.external.AddSearchProvider("http://realage.com/srch/searchplugins/raopensearch.xml");
		}
		// End Search Plugin
		
		//Preload images
		var imgGreenUp;
		var imgRedDown;
		var imgClearUp;
		var imgClearDown;
		
		imgGreenUp = new Image();
		imgRedDown = new Image();
		imgClearUp = new Image();
		imgClearDown = new Image();
		
		imgGreenUp.src   = RA_IMAGE_PATH + "Icons/icon_thumb-good-green.gif";
		imgRedDown.src   = RA_IMAGE_PATH + "Icons/icon_thumb-bad-red.gif";
		imgClearUp.src   = RA_IMAGE_PATH + "Icons/icon_thumb-good.gif";
		imgClearDown.src = RA_IMAGE_PATH + "Icons/icon_thumb-bad.gif";	

		var XmlHttp;
		var DivID;
		var LastImage; //holds the last image for the mouseover effect to return the image to it's prior state
		var LastId;
		var SearchTermEncoded;
		
		SearchTermEncoded = RA_SEARCH_TERM_ENCODED;

		function GetMoreResults(aDC, aQuery, aDivID, aCatno)
		{
			
			XmlHttp = RealAge.Utils.CreateXmlHttp();
			
			if(XmlHttp!=null)
			{
			var now = new Date();
			document.getElementById(aDivID);
			DivID = aDivID;
			XmlHttp.onreadystatechange = ProcessResponseMoreResults;
			XmlHttp.open("GET",RA_HOMEPAGE_PATH + "srch/raSearch2Mthds.aspx?Catno=" + aCatno + "&DC=" + aDC + "&MR=1&query=" + aQuery + "&T=" + now.getTime(),  true);
			XmlHttp.send(null);
			}
		}

		function ProcessResponseMoreResults()
		{
			if(XmlHttp.readyState == 4)
			{
				if(XmlHttp.status == 200)
				{
					var retval=XmlHttp.responseText;
					document.getElementById('MR' + DivID).innerHTML  = retval;
					//turn off more results line
					//document.getElementById('Secondary' + DivID).style.display = "none"; 
					document.getElementById('DivMoreResults' + DivID).innerHTML = '';
				}
				else
				{
					//alert("Error retrieving data!" );
				}
			}
		}
		
		var lastTouchedID = null;

		function ScoreSearchResult(aDocId, aScore, aMemId)
		{
		    var recordScore = true;
		    /*
		    if (aScore == "1" && document.getElementById('hidOrigImgUp' + aDocId).value.indexOf('green') > 0)
		    {
			    recordScore = false;
		    }
		    if (aScore == "-1" && document.getElementById('hidOrigImgDn' + aDocId).value.indexOf('red') > 0)
		    {
			    recordScore = false;
		    }
		    */
    		
		    //Check to see if the feedback history is showing, if so then place a link in the div tag
		    if(LastId == 'ST6' && aScore != '0')
		    {
			    document.getElementById('tdShowFeedBackHistory').innerHTML = "<a class=\"linkLike\" onclick=\"JavaScript:ShowFeedBackHistory(\'1\');\"><img src=\"" + RA_IMAGE_PATH + "Buttons/bt_refreshfeedback.gif\" border=\"0\"></a>";
			    //document.getElementById('FeedbackNavDiv').innerHTML = '';
		    }

		    //If the LastImage is null then don't record the score
		    if (LastImage == null && aScore != 0)
		    {
			    recordScore = false;
		    }
		    else
		    {
			    //clear LastImage if the user clicked and the score will be recorded so the Image stays "on"
			    LastImage = null;
		    }
		
		    if (recordScore){
    			
		        XmlHttp = RealAge.Utils.CreateXmlHttp();
    			
		        if(XmlHttp!=null)
		        {
		            var now = new Date();
		            XmlHttp.onreadystatechange = ProcessResponse;
		            XmlHttp.open("GET",RA_HOMEPAGE_PATH + "srch/raSearch2Mthds.aspx?query=" + SearchTermEncoded + "&score=" + aScore + "&docid=" + aDocId + "&memid=" + aMemId + "&T=" + now.getTime(),  true);
		            XmlHttp.send(null);

		            if (aScore == '1')
			            {
				            document.getElementById('ImgUp' + aDocId).src = imgGreenUp.src;
				            document.getElementById('ImgDwn' + aDocId).src = imgClearDown.src;
			            }
		            else if (aScore == '-1')
			            {
				            document.getElementById('ImgDwn' + aDocId).src = imgRedDown.src; 
				            document.getElementById('ImgUp' + aDocId).src = imgClearUp.src; 
			            }		
		            }
		            else
		            {
		            //IE 5.2 for the mac doesn't support this functionality
		            //Need to submit page to record score
		            //If score is equal to zero (0)
		            //Don't do anything
		        }
	        }
    		        
		    if (aScore == '0') {
	            // It's a view
	            
		        if(lastTouchedID) {
	                result  = document.getElementById("SearchResult-" + lastTouchedID);
	                summary = document.getElementById("Summary-" + lastTouchedID);
	                ratings = document.getElementById("Ratings-" + lastTouchedID);
    	                   
	                summary.style.border = '0px';
	                //summary.style.borderBottom = '1px solid cccccc'
	                summary.style.backgroundColor = 'white';
	                ratings.style.border = '0px';
	                //ratings.style.borderBottomWidth = '1px solid cccccc'
	                ratings.style.backgroundColor = 'white';
		        }
	                 
	            result  = document.getElementById("SearchResult-" + aDocId);
	            summary = document.getElementById("Summary-" + aDocId);
	            ratings = document.getElementById("Ratings-" + aDocId);
	                   
	            summary.style.border = '1px solid cccccc';
	            summary.style.backgroundColor = '#fafeda';
	            ratings.style.border = '1px solid cccccc';
	            ratings.style.borderLeftWidth = '0px';
	            ratings.style.backgroundColor = '#fbe8bd';
	            
	            lastTouchedID = aDocId;
	            
	            //border: 560xVaries px, hex cccccc. 

                //yellow background: hex fafeda.
                //orange background: hex fbe8bd. 

	        }
	        
		}

		function ProcessResponse()
		{
		//No response to process at this time
		}
		
			function GotoSearch()
			{
				window.location.href = RA_SEARCH_PAGE_PATH + "?m=1&CS=Y&query=" + document.getElementById("txtSearchText").value;
			}
			
			var NS4;
    		NS4 = (document.layers) ? true : false;
	    
			function checkEnterForSuggestTopic(e)
			{ 	
			
				var code = 0;
			
				if (NS4)
					{
					code = e.which;
					}
				else
					{
					code = e.keyCode;
					}

				if (code==13)
				{
					RecordSuggestURL();
					return false;
				}

			}

			function RecordSuggestURL()
			{
				var suggestedURL = document.getElementById("txtSuggestURL").value;
				document.getElementById("txtSuggestURL").value = "";
				if (suggestedURL == null || suggestedURL == "")
				{
					document.getElementById("ErrSuggestURL").innerHTML = "<b>Please enter a suggestion</b>";
				}
				else
				{
				
					document.getElementById("ErrSuggestURL").innerHTML = "";
				
					ShowSearchToolText('ST5');

					XmlHttp = RealAge.Utils.CreateXmlHttp();
					
					if(XmlHttp!=null)
					{
					var now = new Date();
					XmlHttp.open("GET",RA_HOMEPAGE_PATH + "srch/raSearch2Mthds.aspx?SuggestedURL=" + suggestedURL + "&T=" + now.getTime(),  true);
					XmlHttp.send(null);
					}
				}
			
			}
			
			function RecordTracking(aMemId,aId)
			{

				XmlHttp = RealAge.Utils.CreateXmlHttp();
				
				if(XmlHttp!=null)
				{
					var now = new Date();
					XmlHttp.open("GET",RA_HOMEPAGE_PATH + "srch/raSearch2Mthds.aspx?TrackId=" + aId + "&memid=" + aMemId + "&T=" + now.getTime(),  true);
					XmlHttp.send(null);
				}
			}			
			
			function ShowSearchToolText(aId)
			{
				if (LastId != null)
				{
					document.getElementById(LastId).style.display = "none";
					document.getElementById(LastId + 'H').style.display = "none";
					
					if (document.getElementById(LastId + 'L'))  // not available in smartsearch.aspx
					document.getElementById(LastId + 'L').style.fontWeight = "normal";
				}
				document.getElementById(aId).style.display = "block";
				document.getElementById(aId + 'H').style.display = "block";
				
				if (document.getElementById(LastId + 'L'))  // not available in smartsearch.aspx
    				document.getElementById(aId + 'L').style.fontWeight = "bold";
    				
				LastId = aId;
			}
			
			function CreateBookmarkLink() 
				{ 
					title = "RealAge Smart Search";   
					url = RA_SEARCH_PAGE_PATH;
					ShowSearchToolText('ST4');
					if (window.sidebar) 
					{ 
						// Mozilla Firefox Bookmark		
						window.sidebar.addPanel(title, url,"");	
					} 
					else if( window.external ) 
					{ 
						// IE Favorite		
						window.external.AddFavorite( url, title); 
					}	
					else if(window.opera && window.print) 
					{ 
						// Opera Hotlist		
						return true; 
					}
				}
				
			function changeClass(aID, aClass)
			{
				document.getElementById(aID).className = aClass;
			}
			
			var ImgSetting;
			
			function changeTmb(aDocID, aType, aEventType)
			{	
				// 0 = Default off
				// 1 = Has been set, don't touch
				
				var LocalLastImage;
				var like;
				
				like = document.getElementById('likeit'+ aDocID);
				
				//only set the LastImage if this is a mouseover event (mover)
				if (aEventType == 'mover')
				{
					if (aType == 'UP')
					{
						if (like != null)
						{
							like.src = '../App_Images/Miscellaneous/srch_ilikeit.gif';
						}
						LocalLastImage = document.getElementById('ImgUp' + aDocID).src;
						if (LocalLastImage == imgClearUp.src)
						{
							LastImage = LocalLastImage;
							document.getElementById('ImgUp' + aDocID).src = imgGreenUp.src;
						}
					}
					else if (aType == 'DN')
					{
						if (like != null)
						{
							like.src = '../App_Images/Miscellaneous/srch_dontlike.gif';
						}
						LocalLastImage = document.getElementById('ImgDwn' + aDocID).src;
						if (LocalLastImage == imgClearDown.src)
						{
							LastImage = LocalLastImage;
							document.getElementById('ImgDwn' + aDocID).src = imgRedDown.src;
						}
					}
					
				}
				else if (aEventType == 'mout')
				{
					if (LastImage != null)
					{
						var ImageToReplace;
						//reinstate image

						if (aType == 'UP')
						{
							ImageToReplace = 'ImgUp' + aDocID;
						}
						else if (aType == 'DN')
						{
							ImageToReplace = 'ImgDwn' + aDocID;
						}
						if (LastImage != null)
						{
							document.getElementById(ImageToReplace).src = LastImage;
							LastImage = null;
						}
					}
					if (like != null)
					{
						like.src = '../App_Images/Miscellaneous/srch_likeless.gif';
					}					
				}
			}
			
			function ShowFeedBackHistory(aPage)
			{
				//Given a page, show that page's feedback history
				XmlHttp = RealAge.Utils.CreateXmlHttp();
				if(XmlHttp!=null)
				{
					var now = new Date();
					XmlHttp.onreadystatechange = ShowFeedBackHistoryResponse;
					XmlHttp.open("GET",RA_HOMEPAGE_PATH + "srch/raSearch2Mthds.aspx?FBP=" + aPage + "&T=" + now.getTime(),  true);
					XmlHttp.send(null);
				}

			}
			
			function ShowFeedBackHistoryResponse()
			{
				//Clear refresh for feedback history, do this first so it doesn't show to the user while we wait for
				//a response back from the server
				document.getElementById('tdShowFeedBackHistory').innerHTML = ""; 

				if(XmlHttp.readyState == 4)
				{
					if(XmlHttp.status == 200)
					{
						var retval=XmlHttp.responseText;
						//split string using <-(N)->
						var feedbackHistory;
						var navigation;
						var splitIndex;
						var retvalLength;
						splitIndex = retval.indexOf('<-(N)->');
						retvalLength = retval.length;
						if (splitIndex == -1)
						{
							//We do not have feedback history
							document.getElementById('FeedbackDiv').innerHTML  = retval;						
							document.getElementById('FeedbackNavDiv').innerHTML = '&nbsp;';
						}
						else
						{
							//We have feedback history
							feedbackHistory = retval.substring(0, splitIndex);
							navigation = retval.substring(splitIndex + 7, retvalLength);
							document.getElementById('FeedbackDiv').innerHTML = feedbackHistory;
							document.getElementById('FeedbackNavDiv').innerHTML = navigation;
						}
					}
					else
					{
						//alert("Error retrieving data!" );
					}
				}				
			}
			
			function ClearFeedBackHistory()
			{
				//Clear refresh for feedback history, 
				document.getElementById('tdShowFeedBackHistory').innerHTML = ""; 			
			
				//Given a page, show that page's worth of feedback history

				XmlHttp = RealAge.Utils.CreateXmlHttp();
				
				if(XmlHttp!=null)
				{
					var now = new Date();
					XmlHttp.onreadystatechange = ClearFeedBackHistoryResponse;
					XmlHttp.open("GET",RA_HOMEPAGE_PATH + "srch/raSearch2Mthds.aspx?FBC=yes" + "&T=" + now.getTime(),  true);
					XmlHttp.send(null);
				}

			}
			
			function ClearFeedBackHistoryResponse()
			{
				if(XmlHttp.readyState == 4)
				{
					if(XmlHttp.status == 200)
					{
						var retval=XmlHttp.responseText;
						
						document.getElementById('FeedbackDiv').innerHTML = retval;
						//clear navigation for feedback history 
						document.getElementById('FeedbackNavDiv').innerHTML = '&nbsp;';
						//clear out current page ratings
						ClearCurrentPageVisualRatings();
					}
					else
					{
						//alert("Error retrieving data!" );
					}
				}				
			}
			
		function ClearCurrentPageVisualRatings()
		{
		
			var allImgs = document.body.getElementsByTagName("IMG");
			var currentImg;
			for (i=0;i<allImgs.length;i++)
			{
				currentImgID = allImgs[i].getAttribute("ID");
				if (currentImgID != null)					
					{
						if (currentImgID.indexOf('ImgUp') > -1 )
						{
							allImgs[i].src = imgClearUp.src;
						}
						else if(currentImgID.indexOf('ImgDwn') > -1)
						{
							allImgs[i].src = imgClearDown.src;
						}
					}
			} 						
		
		}
			
