/**
 * Search results related javascript module.  It handles many tasks related 
 * to search results.  All these results may comes from the components like:
 * Keyword search, ontology tree(subject and publication), advanced search 
 * and pagination component.  Primarily, it renders various JSON objects 
 * containing informatin related to, articles, authors, references, bibliography
 * , ontology tree etc. It supports two components, they are Advanced search 
 * and Pagination component.
 *
 * @author Veeresh D.
 * @date March 2008
 */

var totalArticleResultsFound;   //This value is required by pagination component
var resultDetailsKeyword;
var rateArticleHTML;
var isSearchInHistory = false;

var searchResults =
{

/**
Renders the keyword search results from the JSON result object

@param keyResults JSON result object of keyword search results
@param keyString Input keyword
@param startArticleNo Default or starting article number
*/
renderJSONSearchResults: function(keyResults, keyString, startArticleNo, sortByType)
{
	var resultDetailsHTML = "";
	var authorTempObj, adsHTML = "", authorSuggestionHTML = "";
	var i, j, resultHTML;
	var articleNo;
	var articleType;
	var firstName,lastName = "";
	hideTopNotification();
	components.penel.loadBanner();
	try
	{
		var articleObject = eval('(' + keyResults + ')');
	}
	catch(e)
	{
	    alert("Unable to parse list of article data!\n\n" + e.description);
		return false;
	}
    
    totalArticleResultsFound = 0;
	
	if ( articleObject.searchResult == null)
	{
	    alert("No search results found: " + keyString);
	    return false;
    }
    totalArticleResultsFound = articleObject.searchResult.totalArticleResultsFound;
    
    if ( articleObject.searchResult.articles == null && global.variables.recentSearchType == "subjectOntologySearch" )
    {
        //alert(articleObject.searchResult.statusMessage);
        tempData = "<DIV class='myComSocContent monthIssue'>";
	    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to access subjects.<BR><BR>";  	
	    //tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&subject=" + escape(keyString) + "> Login</A><BR>";
	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> View by CommOntology Topic available to ComSoc Members Only.<BR><BR>";
	    tempData += "If you are a member, please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&subject=" + escape(keyString) + ">LOGIN</A> with your IEEE Web Account<BR>";
        
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	    return false;
    }
    else if ( articleObject.searchResult.articles == null && global.variables.recentSearchType == "authorSearch" )
	{ 
	    if( keyString.length <=2 )
	    {  
	        var asc;
	        asc = keyString.toString().charCodeAt(0);
	        
	        if( asc>=65 && asc<=90 )
	        {
	            asc = asc - 65 + 1; 
	            tabAuthDir.getAuthorDirTab(asc, keyString);
	        } 
	        else if( asc>=97 && asc<=122 ) 
	        {
	             asc = asc - 97 + 1;  
	             tabAuthDir.getAuthorDirTab(asc, keyString);
	        }
	        else
	            alert("No search results found: " + keyString);	        
	        return false;
	    }  
	    
	    if( articleObject.searchResult.authorSuggestionList == null || articleObject.searchResult.authorSuggestionList.length <= 0 )
	    {
	        //alert("No results for author(s): " + keyString);
	        tempData = "<P class=searchResultItem style='margin: 1px;'>Author Search</P>";
	        tempData += "<HR style='height: 1px;'>".bold() + showAlertInformation(1, "No results for author(s): " + keyString);
	        document.getElementById("queryResultsDivId").innerHTML = "<BR>" + tempData + "<BR>";
            searchResults.hideAllPanels();
            historyIsItResultDetails = 0;
	        parityHistory.setInHistory();
	        return false;
	    }
	    else if( articleObject.searchResult.authorSuggestionList.length == 1 )
	    {
	        if( global.variables.authorSearchCount == 0 )
	        {
	            var param = articleObject.searchResult.authorSuggestionList[0].lastName;
	            param = param.replace("<font color=saxblue>","");
	            param = param.replace("</font>","");
	            global.variables.authorSearchCount = 1; /* To block the next infinite call via search results.  It will be reinitialized in submitSearch() */
	            submitKeywordSearch(param, "author");
	        }
	        else
	        {   
	            tempData = "<P class=searchResultItem style='margin: 1px;'><B>Author Search</B></P>";
	            tempData += "<HR style='height: 1px;'>".bold() + showAlertInformation(1, "No results for author(s): " + keyString);
	            document.getElementById("queryResultsDivId").innerHTML = "<BR>" + tempData + "<BR>";
                searchResults.hideAllPanels();
                historyIsItResultDetails = 0;
	            parityHistory.setInHistory();
	        }
	        return false;
	    }
	    else
	    {
	        var noOfColumns = 4;
            var colIndex = 0;   
	        var rowIndex = 0;
	        var cellIndex, totalCells;
	        var authorList = new Array();
	        
	        authorSuggestionHTML += "<DIV style='' class=searchResultPageTitle>Query Results<HR style='height: 1px'></DIV>";        
	        authorSuggestionHTML += "<P class=searchResultItem><IMG src='" + ROOT_URL + "images/information-alert.gif' /> Did you mean following authors:</p>";
	        authorSuggestionHTML += "<TABLE  width=99%>";
	       
	        totalCells = articleObject.searchResult.authorSuggestionList.length;
	        if ( (totalCells % 4) != 0 )
	            totalCells = totalCells + (4 - totalCells % 4);
	    
	        for( var i = 0; i < totalCells/4; i++)
	        {
	            authorSuggestionHTML += "<TR>";
	            for( var j = 0; j < 4; j++)
	            {
	                cellIndex = i + j*(totalCells/4);
	                authorSuggestionHTML += "<TD class=searchResultItem>";	
			        if ( cellIndex < articleObject.searchResult.authorSuggestionList.length)
	                {
	                    var param = articleObject.searchResult.authorSuggestionList[cellIndex].lastName;
	                    param = param.replace("<FONT color=saxblue>","");
	                    param = param.replace("</FONT>","");
	                    authorSuggestionHTML += "<A class=searchResultItem href=?keyword=" + param + "&type=author onclick=\"return submitKeywordSearch('" + escape(param) +"','author')\">";
                        authorSuggestionHTML += articleObject.searchResult.authorSuggestionList[cellIndex].lastName + " ";
			            authorSuggestionHTML += articleObject.searchResult.authorSuggestionList[cellIndex].firstName;
			            authorSuggestionHTML += "</A>";		        
	                }
	                else
	                    authorSuggestionHTML += "";
	            
	                authorSuggestionHTML += "</TD>";	            
	            }	               
                authorSuggestionHTML += "</TR>";	        
	        }
	        
	        authorSuggestionHTML += "</TABLE>";
	        document.getElementById("queryResultsDivId").innerHTML = authorSuggestionHTML;
	            
	        searchResults.hideAllPanels();
	        
	        historyIsItResultDetails = 0;
	        parityHistory.setInHistory();	
	
	        printer.printerPageType = 1;
	        printer.showPrinterPageLink();
	    }
	    return false;
    }
    else if ( articleObject.searchResult.articles == null )
    {
        alert("No articles found");
	    return false;
    }
    
    resultDetailsHTML = "<DIV style='' class=searchResultPageTitle>Query Results<HR style='height: 1px'></DIV>";
	
	for(var i = 0; i < articleObject.searchResult.advertisements.length; i++)
	{
	    if ( articleObject.searchResult.advertisements[i].imageFile != null )
	    {
	        adsHTML += "<DIV style='background-color: #E7EEF3; border: 1px dotted steelblue; cursor: pointer; margin-bottom: 5px;' onclick=window.open('" + articleObject.searchResult.advertisements[i].url + "')>";
	        adsHTML += "<TABLE  cellpadding=5 cellspacing=0 width=98%>";
	        adsHTML += "<TR valign=top>";
	        adsHTML += "<TD class=searchResultItem width=5px><IMG src=" + articleObject.searchResult.advertisements[i].imageFile + " /></TD>";
	        adsHTML += "<TD class='monthIssue'>" + articleObject.searchResult.advertisements[i].textMessage + "<BR>";
	        adsHTML += "<FONT color=blue>" + articleObject.searchResult.advertisements[i].url + "</FONT></TD>";
	        adsHTML += "</TR>";	        
	        adsHTML += "</TABLE>";
	        adsHTML += "</DIV>";
	    }
	}
	
	resultDetailsHTML += adsHTML;
	
	resultDetailsHTML += "<TABLE  border=0 cellpadding=5 cellspacing=0 width=98%>";
    resultDetailsHTML += "<TR valign=top>";
    
    //Module 45 Modifications to Current Issue View on DL
        resultDetailsHTML += "<TD vAlign=top align=left>";
        resultDetailsHTML += "<IMG src="+articleObject.searchResult.imagePath+ " border=1 alt=Cover align=left width=100 />";
        for( i = 0; i < articleObject.searchResult.articles.length; i ++){
        	if(i == articleObject.searchResult.articles.length-1){
        	    if(articleObject.searchResult.articles[i].parentTitle != null){
        	    	//alert("articleObject.searchResult.articles[i].parentTitle="+articleObject.searchResult.articles[i].parentTitle);
        	    	//alert("articleObject.searchResult.articles[i].parentTitle="+articleObject.searchResult.articles[i].parentTitle.length);
        	    	resultDetailsHTML += "<TD width=50% class=searchResultItem vAlign=top align=left>"
        	    		resultDetailsHTML += "<B>"+articleObject.searchResult.articles[i].parentTitle.fontcolor("steelblue")+",</Br>";
        	    }
        	    if(articleObject.searchResult.articles[i].month != null){
        	        resultDetailsHTML += articleObject.searchResult.articles[i].month.fontcolor("steelblue")+" " + articleObject.searchResult.articles[i].year.fontcolor("steelblue") + "</Br>";
        	    }
        	    if(articleObject.searchResult.articles[i].volume != null){
        	        //alert("articleObject.searchResult.articles[i].volume="+articleObject.searchResult.articles[i].volume);
        	        resultDetailsHTML += "Vol."+articleObject.searchResult.articles[i].volume+", ";
        	    }
        	    if(articleObject.searchResult.articles[i].issueNumber != null){
        	        //alert("articleObject.searchResult.articles[i].issueNumber="+articleObject.searchResult.articles[i].issueNumber);
        	        resultDetailsHTML += "no."+articleObject.searchResult.articles[i].issueNumber+"</Br>";
        	    }
        	    break;
        	}
    }
    
    resultDetailsHTML += "<TD width='49%' style='text-align: left;' class=searchResultItem id=searchDetailsLeft" + startArticleNo +">";
    //resultDetailsHTML += ("Results for \"(" + keyString.fontcolor("steelblue") + ")\"").bold();
    
    //commented - Module 45 Modifications to Current Issue View on DL
    /*
    if ( articleObject.searchResult.criteria.nodeLabel.indexOf("<FONT color=saxblue>") != 0 )
        resultDetailsHTML += ("Results for \"(" + articleObject.searchResult.criteria.nodeLabel.fontcolor("steelblue") + ")\"").bold();
    else
        resultDetailsHTML += ("Results for \"(" + articleObject.searchResult.criteria.nodeLabel + ")\"").bold();
    */
    
    resultDetailsHTML += ("<BR>Your search matched " + (totalArticleResultsFound + "").fontcolor("steelblue") + " documents").bold();
    resultDetailsHTML += "<P style='margin: 7px'>";
        
    if ( articleObject.searchResult.isFavorite == "true")
    {
        resultDetailsHTML += "<INPUT id=saveSearchId type=button value='View/Edit Favorites' " + getButtonClass() +" onclick='access.myComSoc.getMyComSocInfo(); access.myComSoc.myComSocGetFavorites(); ' style='margin-top: 5px;' >";
        if ( saveSearchType == "ontologySubject")
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologySubject','" + keyString + "')\" >";
        else if ( saveSearchType == "ontologyPublication")
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologyPublication','" + keyString + "')\" >";
        else if ( saveSearchType == "keywordSearch")
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";
        else if ( saveSearchType == "authorSearch")
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";        
    }
    else if ( articleObject.searchResult.isFavorite == "false")
    {
        if ( saveSearchType == "ontologySubject")
        {
            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Subject' " + getButtonClass() +" onclick=\"searchResults.saveSubject('" + saveSearchItem +"','ontologySubject','" + keyString + "')\" style='margin-top: 5px;' >";
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologySubject','" + keyString + "')\" >";
        }
        else if ( saveSearchType == "ontologyPublication")
        {
            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Publication' " + getButtonClass() +" onclick=\"searchResults.savePublication('" + saveSearchItem +"','ontologyPublication','" + keyString + "')\" style='margin-top: 5px;' >";
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologyPublication','" + keyString + "')\" >";
        }
        else if ( saveSearchType == "keywordSearch")
        {
            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Search' " + getButtonClass() +" onclick=\"searchResults.saveSearch('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" style='margin-top: 5px;' >"; 
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";
        } 
        else if ( saveSearchType == "authorSearch")
        {
            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Search' " + getButtonClass() +" onclick=\"searchResults.saveSearch('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" style='margin-top: 5px;' >"; 
            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";
        }            
    }
    
    //resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick='searchResults.manageFilter()' >";
    
    if ( articleObject.searchResult.isDownloadIssue == "true" )
    {
        resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Download Issue' onclick=searchResults.addIssueArticlesToDownload('" + articleObject.nodeID +"') >";        
    }
    
    resultDetailsHTML += "</P>";
    resultDetailsHTML += "<DIV class='myComSocContent monthIssue' id=sortByOptions>";    
    resultDetailsHTML += "<IMG src='" + ROOT_URL + "images/sortBy.gif' />" + " Sort By:  ".bold();    
    resultDetailsHTML += "<SPAN id=sortByOption style='color: gray' class=searchResultItem></SPAN>";
    resultDetailsHTML += "</DIV>";
    resultDetailsHTML += "</TD>";
    
    //commented - Module 45 Modifications to Current Issue View on DL
    //resultDetailsHTML += "<TD width='49%' class=searchResultItem id=searchDetailsRight" + startArticleNo +">";
    //Module 45 Modifications to Current Issue View on DL
	resultDetailsHTML += "<DIV class=searchResultItem id=searchDetailsRight" + startArticleNo +">";
        resultDetailsHTML += "</DIV>";
        
    /*
    if ( articleObject.searchResult.subjects != null)
    {     
		resultDetailsHTML += "<IMG src='" + ROOT_URL + "images/subjectsRelated.png' />" + " Related Subjects: ".bold();     
		for(var i = 0; typeof(articleObject.searchResult.subjects) != "undefined" && i < articleObject.searchResult.subjects.length; i++)
		{
		    if ( articleObject.searchResult.subjects[i].ontologyLabel != null )
		    {
		        //resultDetailsHTML += "<A href=# onclick=\"treeSub.getSubjectResults('" + articleObject.searchResult.subjects[i].id + "','" + trim(articleObject.searchResult.subjects[i].ontologyLabel) + "')\">";
			    //resultDetailsHTML += highLightKeyword(trim(articleObject.searchResult.subjects[i].ontologyLabel), keyString);
			    resultDetailsHTML += "<A href=?subject=" + articleObject.searchResult.subjects[i].id + " onclick=\"return treeSub.getSubjectResults('" + articleObject.searchResult.subjects[i].id + "','" + trim(articleObject.searchResult.subjects[i].ontologyLabel) + "')\">";
                resultDetailsHTML += highLightKeyword(trim(articleObject.searchResult.subjects[i].ontologyLabel), trim(keyString));
                resultDetailsHTML += "</A>";
			    if ( i != articleObject.searchResult.subjects.length - 1)
				    resultDetailsHTML += ", ";
			}
		}
    }
    resultDetailsHTML += "<td>";
    */
    //Module 45 Modifications to Current Issue View on DL
    resultDetailsHTML += "</TD>";
    
    resultDetailsHTML += "</TR>";
    resultDetailsHTML += "</TABLE>";
    
    resultHTML = "<TABLE  border=0 cellpadding=0>";
	
	for( i = 0; i < articleObject.searchResult.articles.length; i ++)
	{
		if( i%2 == 0)
		    resultHTML += "<TR style='background-color: whitesmoke; padding-top: 5px'>";
		else
		    resultHTML += "<TR style='background-color: white; padding-top: 5px'>";
		
		articleNo = articleObject.searchResult.articles[i].articleID;
		articleType = articleObject.searchResult.articles[i].pubType;
		
		resultHTML += "<TD class=searchResultItem id=articleNo" + ((startArticleNo-1)*10 + (i%10)+1) +" >";
		resultHTML += (((startArticleNo-1)*10 + (i%10)+1)+ ". ").bold();
		
		//resultHTML += "<A href=# onclick=\"searchResults.getArticleData('" + articleObject.searchResult.articles[i].articleID + "') \">";
		resultHTML += "<B><A href=?article=" + articleObject.searchResult.articles[i].articleID + " onclick=\"return searchResults.getArticleData('" + articleObject.searchResult.articles[i].articleID + "') \">";
		
		resultHTML += "\"" + highLightKeyword(validateDataItem("",articleObject.searchResult.articles[i].articleTitle), keyString) + "\"</A></B>, ";
		
		authorTempObj = articleObject.searchResult.articles[i].authors;
		for( j = 0; authorTempObj != null && j < authorTempObj.length; j ++)
		{
			firstName = articleObject.searchResult.articles[i].authors[j].firstName;
			lastName = articleObject.searchResult.articles[i].authors[j].lastName;
		     //resultHTML += "<A href=#" + articleObject.searchResult.articles[i].authors[j].authorID +" onclick=\"searchResults.getAuthorData(" + articleObject.searchResult.articles[i].authors[j].authorID +")\">";
		     if(firstName != null || lastName != null)
		     {
		     	resultHTML += "<A href=?author=" + articleObject.searchResult.articles[i].authors[j].authorID +" onclick=\"return searchResults.getAuthorData(" + articleObject.searchResult.articles[i].authors[j].authorID +")\">";
		     	if(firstName != null && firstName != "zzzz" && firstName != "zzz2")
		     		resultHTML += highLightKeyword(validateDataItem("", articleObject.searchResult.articles[i].authors[j].firstName), keyString) + " ";
		     	if(lastName != null && lastName != "zzzz" && lastName != "zzz2")	
				 	resultHTML += highLightKeyword(validateDataItem("", articleObject.searchResult.articles[i].authors[j].lastName), keyString) + "</A>, ";
			 }
		}
		
		resultHTML += articleObject.searchResult.articles[i].parentTitle.italics();
		resultHTML += validateDataItem(", Vol. ", articleObject.searchResult.articles[i].volume);
		resultHTML += validateDataItem(", no. ", articleObject.searchResult.articles[i].issueNumber) + ", ";
		
		resultDetailsKeyword = validateDataItem("", articleObject.searchResult.articles[i].parentTitle);
		resultDetailsKeyword += ", " + articleObject.searchResult.articles[i].month + " " + articleObject.searchResult.articles[i].year;
        
        //resultHTML += "<A href=# onclick=\"treePub.pubGetPublicationResults('" + articleObject.searchResult.articles[i].issueObjectNodeID + "','" + resultDetailsKeyword + "')\">";
		resultHTML += ( articleObject.searchResult.articles[i].issueObjectNodeID ) ? "<A href=?publication=" + articleObject.searchResult.articles[i].issueObjectNodeID + "&label=" + escape(resultDetailsKeyword) + " onclick=\"return treePub.pubGetPublicationResults('" + articleObject.searchResult.articles[i].issueObjectNodeID + "','" + resultDetailsKeyword + "')\">" : " ";
		resultHTML += articleObject.searchResult.articles[i].month + " ";
		resultHTML += articleObject.searchResult.articles[i].year;
		resultHTML += ( articleObject.searchResult.articles[i].issueObjectNodeID ) ? "</A>" : " "; 
		
		resultHTML += validateDataItem(", pp. ", articleObject.searchResult.articles[i].startPage);
		resultHTML += validateDataItem("-" , articleObject.searchResult.articles[i].endPage);		
		
		var articleTempObject = validateDataItem("", articleObject.searchResult.articles[i].articleAbstract);
		
		if ( articleTempObject != null && articleTempObject.length > 0 )		    
		{
		    resultHTML += "<BR>" + highLightKeyword(articleTempObject, keyString) + "..."; //highLightKeyword(articleTempObject.substr(0, 200), keyString) + "...";
		    //alert("articleTempObject=" + highLightKeyword(articleTempObject, keyString));    
        }
        
		resultHTML += "&nbsp;<FONT id=displayArticleRatesFontId class='searchResultItem'>";	        
		if ( articleObject.searchResult.articles[i].articleRating != null )
	    {    
	        for(var k = 0; k < articleObject.searchResult.articles[i].articleRating.averageRate; k++)
	        {
	            resultHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' height=15 width=15 />";		    
	        }
	        for(var j = articleObject.searchResult.articles[i].articleRating.averageRate; j < 5; j++)
	        {
		        resultHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' class='transparent_class' height=15 width=15 />";
	        }
	        resultHTML += "</FONT>";
	        resultHTML += ("(" + articleObject.searchResult.articles[i].articleRating.count + " Rated)").fontcolor("gray");	        
	    }
	    else
	    {       	        
	        for(var k = 0; k < 5; k++)
	        {
	            resultHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' class='transparent_class' height=15 width=15 />";    
	        }	        
	        resultHTML += "</FONT>";        
	    }
		
		if( articleObject.searchResult.articles[i].price != null )
		{
		    resultHTML += "<P style='margin: 0; padding: 0; text-align: right' class=searchResultItem><b>$" + articleObject.searchResult.articles[i].price + "&nbsp;</b>" ;
		    
		    if( articleObject.searchResult.articles[i].price == '0.00' )
		    {
		        if( downloadCartList.hasItem(articleNo) )
		        {
		            //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Download Article' DISABLED=disable/>&nbsp;";
		        }
		        else
		            resultHTML += "<INPUT type=button " + getButtonClass() +" id=addToDownloadId" + articleNo + " value='Download Article' onclick='searchResults.addToDownload(" + articleNo + ")'/>&nbsp;";
		            
		        //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Buy Article' DISABLED=disable /></p>";
		    }
		    else
		    {
		        //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Download Article' DISABLED=disable/>&nbsp;";
		        
		        if( shoppingCartList.hasItem(articleNo) )
		        {
		            //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Buy Article' DISABLED=disable /></p>";	        
		        }
		        else
		        {
		            //resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false)' type=button value='Buy Article' /></p>";		        
		            resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false,\"" + articleType + "\")' type=button value='Buy Article' /></p>";
		        }
		    }
		}
		else
		{
		    resultHTML += "<P style='margin: 0; padding: 0; text-align: right'> ";
		    resultHTML += "<INPUT type=button " + getButtonClass() +" id=addToDownloadId" + articleNo + " value='Download Article' onclick='searchResults.addToDownload(" + articleNo + ")'/>&nbsp;";
		    //resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false)' type=button value='Buy Article' /></p>";		    
		    resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false,\"" + articleType + "\")' type=button value='Buy Article' /></p>";
		}
		resultHTML += "</TD>";
		resultHTML += "</TR>";
	}
	resultHTML += "</TABLE>";
	
	document.getElementById("queryResultDetailsDivId").innerHTML = resultDetailsHTML;
    document.getElementById("queryResultsDivId").innerHTML = resultHTML;
        
    /*
        The below paramter '0' = Execute later on explicit request, because by default it is
        relevance type.  It is done here mainly for the purpose of setting 
        format styles and associating with its functions
    */
    if ( typeof(sortByType) == "undefined" )
        sortByType = "relevance";
    
    //Update the font size from MyComSoc preferences
    searchResults.setSearchResultPageFontSize(startArticleNo, global.variables.myComSocUserFont);
    searchResults.showSearchResultsBorder();
	searchResults.showSearchResultsDetailsBorder();
	showPagination();
	components.penel.hideMonthIssues();  // Close notification/dialog content after getting the serach results
	components.penel.hideCurrentIssues();
	components.penel.hideTopArticle();
	components.penel.hideAds();
	printer.printerPageType = 0;
	printer.showPrinterPageLink();
	searchResults.setSortByType(sortByType, 0);
	document.getElementById("homebodyId").scrollTop = 1;    //Move the page cursor on top
	
	
	return true;
},


//Module 45 Modifications to Current Issue View on DL
/**
 * SearchResults For the Keyword Search
 */

renderJSONKeywordSearchResults: function(keyResults, keyString, startArticleNo, sortByType)
{
		var resultDetailsHTML = "";
		var authorTempObj, adsHTML = "", authorSuggestionHTML = "";
		var i, j, resultHTML;
		var articleNo;
		//Code change for BuyArticle tutorialFix
		var articleType;
		var firstName,lastName = "";
		hideTopNotification();
		components.penel.loadBanner();
		try
		{
			var articleObject = eval('(' + keyResults + ')');
		}
		catch(e)
		{
		    alert("Unable to parse list of article data!\n\n" + e.description);
			return false;
		}
	    
	    totalArticleResultsFound = 0;
		
		if ( articleObject.searchResult == null)
		{
		    alert("No search results found: " + keyString);
		    return false;
	    }
	    totalArticleResultsFound = articleObject.searchResult.totalArticleResultsFound;
	    
	    if ( articleObject.searchResult.articles == null && global.variables.recentSearchType == "subjectOntologySearch" )
	    {
	        //alert(articleObject.searchResult.statusMessage);
	        tempData = "<DIV class='myComSocContent monthIssue'>";
		    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to access subjects.<BR><BR>";  	
		    //tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&subject=" + escape(keyString) + "> Login</A><BR>";
	        //Changing the Login Screen
	        tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> View by CommOntology Topic available to ComSoc Members Only.<BR><BR>";  	
		    tempData += "If you are a member, please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&subject=" + escape(keyString) + ">LOGIN</A> with your IEEE Web Account<BR>";
	        
		    tempData += "</DIV>";
		    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
		    document.getElementById("queryResultsDivId").innerHTML = tempData;
		    searchResults.hideAllPanels();
		    historyIsItResultDetails = 0;
		    parityHistory.setInHistory();
		    return false;
	    }
	    else if ( articleObject.searchResult.articles == null && global.variables.recentSearchType == "authorSearch" )
		{ 
		    if( keyString.length <=2 )
		    {  
		        var asc;
		        asc = keyString.toString().charCodeAt(0);
		        
		        if( asc>=65 && asc<=90 )
		        {
		            asc = asc - 65 + 1; 
		            tabAuthDir.getAuthorDirTab(asc, keyString);
		        } 
		        else if( asc>=97 && asc<=122 ) 
		        {
		             asc = asc - 97 + 1;  
		             tabAuthDir.getAuthorDirTab(asc, keyString);
		        }
		        else
		            alert("No search results found: " + keyString);	        
		        return false;
		    }  
		    
		    if( articleObject.searchResult.authorSuggestionList == null || articleObject.searchResult.authorSuggestionList.length <= 0 )
		    {
		        //alert("No results for author(s): " + keyString);
		        tempData = "<P class=searchResultItem style='margin: 1px;'>Author Search</P>";
		        tempData += "<HR style='height: 1px;'>".bold() + showAlertInformation(1, "No results for author(s): " + keyString);
		        document.getElementById("queryResultsDivId").innerHTML = "<BR>" + tempData + "<BR>";
	            searchResults.hideAllPanels();
	            historyIsItResultDetails = 0;
		        parityHistory.setInHistory();
		        return false;
		    }
		    else if( articleObject.searchResult.authorSuggestionList.length == 1 )
		    {
		        if( global.variables.authorSearchCount == 0 )
		        {
		            var param = articleObject.searchResult.authorSuggestionList[0].lastName;
		            param = param.replace("<font color=saxblue>","");
		            param = param.replace("</font>","");
		            global.variables.authorSearchCount = 1; /* To block the next infinite call via search results.  It will be reinitialized in submitSearch() */
		            submitKeywordSearch(param, "author");
		        }
		        else
		        {   
		            tempData = "<P class=searchResultItem style='margin: 1px;'><B>Author Search</B></P>";
		            tempData += "<HR style='height: 1px;'>".bold() + showAlertInformation(1, "No results for author(s): " + keyString);
		            document.getElementById("queryResultsDivId").innerHTML = "<BR>" + tempData + "<BR>";
	                searchResults.hideAllPanels();
	                historyIsItResultDetails = 0;
		            parityHistory.setInHistory();
		        }
		        return false;
		    }
		    else
		    {
		        var noOfColumns = 4;
	            var colIndex = 0;   
		        var rowIndex = 0;
		        var cellIndex, totalCells;
		        var authorList = new Array();
		        
		        authorSuggestionHTML += "<DIV style='' class=searchResultPageTitle>Query Results<HR style='height: 1px'></DIV>";        
		        authorSuggestionHTML += "<P class=searchResultItem><IMG src='" + ROOT_URL + "images/information-alert.gif' /> Did you mean following authors:</p>";
		        authorSuggestionHTML += "<TABLE  width=99%>";
		       
		        totalCells = articleObject.searchResult.authorSuggestionList.length;
		        if ( (totalCells % 4) != 0 )
		            totalCells = totalCells + (4 - totalCells % 4);
		    
		        for( var i = 0; i < totalCells/4; i++)
		        {
		            authorSuggestionHTML += "<TR>";
		            for( var j = 0; j < 4; j++)
		            {
		                cellIndex = i + j*(totalCells/4);
		                authorSuggestionHTML += "<TD class=searchResultItem>";	
				        if ( cellIndex < articleObject.searchResult.authorSuggestionList.length)
		                {
		                    var param = articleObject.searchResult.authorSuggestionList[cellIndex].lastName;
		                    param = param.replace("<FONT color=saxblue>","");
		                    param = param.replace("</FONT>","");
		                    authorSuggestionHTML += "<A class=searchResultItem href=?keyword=" + param + "&type=author onclick=\"return submitKeywordSearch('" + escape(param) +"','author')\">";
	                        authorSuggestionHTML += articleObject.searchResult.authorSuggestionList[cellIndex].lastName + " ";
				            authorSuggestionHTML += articleObject.searchResult.authorSuggestionList[cellIndex].firstName;
				            authorSuggestionHTML += "</A>";		        
		                }
		                else
		                    authorSuggestionHTML += "";
		            
		                authorSuggestionHTML += "</TD>";	            
		            }	               
	                authorSuggestionHTML += "</TR>";	        
		        }
		        
		        authorSuggestionHTML += "</TABLE>";
		        document.getElementById("queryResultsDivId").innerHTML = authorSuggestionHTML;
		            
		        searchResults.hideAllPanels();
		        
		        historyIsItResultDetails = 0;
		        parityHistory.setInHistory();	
		
		        printer.printerPageType = 1;
		        printer.showPrinterPageLink();
		    }
		    return false;
	    }
	    else if ( articleObject.searchResult.articles == null )
	    {
	        alert("No articles found");
		    return false;
	    }
	    
	    resultDetailsHTML = "<DIV style='' class=searchResultPageTitle>Query Results<HR style='height: 1px'></DIV>";
		
		for(var i = 0; i < articleObject.searchResult.advertisements.length; i++)
		{
		    if ( articleObject.searchResult.advertisements[i].imageFile != null )
		    {
		        adsHTML += "<DIV style='background-color: #E7EEF3; border: 1px dotted steelblue; cursor: pointer; margin-bottom: 5px;' onclick=window.open('" + articleObject.searchResult.advertisements[i].url + "')>";
		        adsHTML += "<TABLE  cellpadding=5 cellspacing=0 width=98%>";
		        adsHTML += "<TR valign=top>";
		        adsHTML += "<TD class=searchResultItem width=5px><IMG src=" + articleObject.searchResult.advertisements[i].imageFile + " /></TD>";
		        adsHTML += "<TD class='monthIssue'>" + articleObject.searchResult.advertisements[i].textMessage + "<BR>";
		        adsHTML += "<FONT color=blue>" + articleObject.searchResult.advertisements[i].url + "</FONT></TD>";
		        adsHTML += "</TR>";	        
		        adsHTML += "</TABLE>";
		        adsHTML += "</DIV>";
		    }
		}
		
		resultDetailsHTML += adsHTML;
		
		resultDetailsHTML += "<TABLE  border=0 cellpadding=5 cellspacing=0 width=98%>";
	    resultDetailsHTML += "<TR valign=top>";
	    resultDetailsHTML += "<TD width='49%' style='text-align: left;' class=searchResultItem id=searchDetailsLeft" + startArticleNo +">";
	    //resultDetailsHTML += ("Results for \"(" + keyString.fontcolor("steelblue") + ")\"").bold();
	    
	    if ( articleObject.searchResult.criteria.nodeLabel.indexOf("<FONT color=saxblue>") != 0 )
	        resultDetailsHTML += ("Results for \"(" + articleObject.searchResult.criteria.nodeLabel.fontcolor("steelblue") + ")\"").bold();
	    else
	        resultDetailsHTML += ("Results for \"(" + articleObject.searchResult.criteria.nodeLabel + ")\"").bold();
	    
	    resultDetailsHTML += ("<BR>Your search matched " + (totalArticleResultsFound + "").fontcolor("steelblue") + " documents").bold();
	    resultDetailsHTML += "<P style='margin: 7px'>";
	        
	    if ( articleObject.searchResult.isFavorite == "true")
	    {
	        resultDetailsHTML += "<INPUT id=saveSearchId type=button value='View/Edit Favorites' " + getButtonClass() +" onclick='access.myComSoc.getMyComSocInfo(); access.myComSoc.myComSocGetFavorites(); ' style='margin-top: 5px;' >";
	        if ( saveSearchType == "ontologySubject")
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologySubject','" + keyString + "')\" >";
	        else if ( saveSearchType == "ontologyPublication")
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologyPublication','" + keyString + "')\" >";
	        else if ( saveSearchType == "keywordSearch")
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";
	        else if ( saveSearchType == "authorSearch")
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";        
	    }
	    else if ( articleObject.searchResult.isFavorite == "false")
	    {
	        if ( saveSearchType == "ontologySubject")
	        {
	            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Subject' " + getButtonClass() +" onclick=\"searchResults.saveSubject('" + saveSearchItem +"','ontologySubject','" + keyString + "')\" style='margin-top: 5px;' >";
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologySubject','" + keyString + "')\" >";
	        }
	        else if ( saveSearchType == "ontologyPublication")
	        {
	            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Publication' " + getButtonClass() +" onclick=\"searchResults.savePublication('" + saveSearchItem +"','ontologyPublication','" + keyString + "')\" style='margin-top: 5px;' >";
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + saveSearchItem +"','ontologyPublication','" + keyString + "')\" >";
	        }
	        else if ( saveSearchType == "keywordSearch")
	        {
	            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Search' " + getButtonClass() +" onclick=\"searchResults.saveSearch('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" style='margin-top: 5px;' >"; 
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";
	        } 
	        else if ( saveSearchType == "authorSearch")
	        {
	            resultDetailsHTML += "<INPUT id=saveSearchId type=button value='Save Search' " + getButtonClass() +" onclick=\"searchResults.saveSearch('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" style='margin-top: 5px;' >"; 
	            resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick=\"searchResults.manageFilter('" + escape(saveSearchItem) +"','" + saveSearchType + "','')\" >";
	        }            
	    }
	    
	    //resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Create Filter' onclick='searchResults.manageFilter()' >";
	    
	    if ( articleObject.searchResult.isDownloadIssue == "true" )
	    {
	        resultDetailsHTML += "&nbsp;<INPUT type=button " + getButtonClass() +" value='Download Issue' onclick=searchResults.addIssueArticlesToDownload('" + articleObject.nodeID +"') >";        
	    }
	    
	    resultDetailsHTML += "</P>";
	    resultDetailsHTML += "<DIV class='myComSocContent monthIssue' id=sortByOptions>";    
	    resultDetailsHTML += "<IMG src='" + ROOT_URL + "images/sortBy.gif' />" + " Sort By:  ".bold();    
	    resultDetailsHTML += "<SPAN id=sortByOption style='color: gray' class=searchResultItem></SPAN>";
	    resultDetailsHTML += "</DIV>";
	    resultDetailsHTML += "</TD>";
	    resultDetailsHTML += "<TD width='49%' class=searchResultItem id=searchDetailsRight" + startArticleNo +">";
	    
	    if ( articleObject.searchResult.subjects != null)
	    {     
			resultDetailsHTML += "<IMG src='" + ROOT_URL + "images/subjectsRelated.png' />" + " Related Subjects: ".bold();     
			for(var i = 0; typeof(articleObject.searchResult.subjects) != "undefined" && i < articleObject.searchResult.subjects.length; i++)
			{
			    if ( articleObject.searchResult.subjects[i].ontologyLabel != null )
			    {
			        //resultDetailsHTML += "<A href=# onclick=\"treeSub.getSubjectResults('" + articleObject.searchResult.subjects[i].id + "','" + trim(articleObject.searchResult.subjects[i].ontologyLabel) + "')\">";
				    //resultDetailsHTML += highLightKeyword(trim(articleObject.searchResult.subjects[i].ontologyLabel), keyString);
				    resultDetailsHTML += "<A href=?subject=" + articleObject.searchResult.subjects[i].id + " onclick=\"return treeSub.getSubjectResults('" + articleObject.searchResult.subjects[i].id + "','" + trim(articleObject.searchResult.subjects[i].ontologyLabel) + "')\">";
	                resultDetailsHTML += highLightKeyword(trim(articleObject.searchResult.subjects[i].ontologyLabel), trim(keyString));
	                resultDetailsHTML += "</A>";
				    if ( i != articleObject.searchResult.subjects.length - 1)
					    resultDetailsHTML += ", ";
				}
			}
	    }
	    resultDetailsHTML += "<td>";
	    resultDetailsHTML += "</TR>";
	    resultDetailsHTML += "</TABLE>";
	    
	    resultHTML = "<TABLE  border=0 cellpadding=0>";
		
		for( i = 0; i < articleObject.searchResult.articles.length; i ++)
		{
			if( i%2 == 0)
			    resultHTML += "<TR style='background-color: whitesmoke; padding-top: 5px'>";
			else
			    resultHTML += "<TR style='background-color: white; padding-top: 5px'>";
			
			articleNo = articleObject.searchResult.articles[i].articleID;
			//Code change for BuyArticle tutorialFix
			articleType = articleObject.searchResult.articles[i].pubType;
			
			resultHTML += "<TD class=searchResultItem id=articleNo" + ((startArticleNo-1)*10 + (i%10)+1) +" >";
			resultHTML += (((startArticleNo-1)*10 + (i%10)+1)+ ". ").bold();
			
			//resultHTML += "<A href=# onclick=\"searchResults.getArticleData('" + articleObject.searchResult.articles[i].articleID + "') \">";
			resultHTML += "<B><A href=?article=" + articleObject.searchResult.articles[i].articleID + " onclick=\"return searchResults.getArticleData('" + articleObject.searchResult.articles[i].articleID + "') \">";
			
			resultHTML += "\"" + highLightKeyword(validateDataItem("",articleObject.searchResult.articles[i].articleTitle), keyString) + "\"</A></B>, ";
			
			authorTempObj = articleObject.searchResult.articles[i].authors;
			for( j = 0; authorTempObj != null && j < authorTempObj.length; j ++)
			{
				firstName = articleObject.searchResult.articles[i].authors[j].firstName;
				lastName = articleObject.searchResult.articles[i].authors[j].lastName;
			     //resultHTML += "<A href=#" + articleObject.searchResult.articles[i].authors[j].authorID +" onclick=\"searchResults.getAuthorData(" + articleObject.searchResult.articles[i].authors[j].authorID +")\">";
			     if(firstName != null || lastName != null)
			     {
			     	resultHTML += "<A href=?author=" + articleObject.searchResult.articles[i].authors[j].authorID +" onclick=\"return searchResults.getAuthorData(" + articleObject.searchResult.articles[i].authors[j].authorID +")\">";
			     	if(firstName != null && firstName != "zzzz" && firstName != "zzz2")
			     		resultHTML += highLightKeyword(validateDataItem("", articleObject.searchResult.articles[i].authors[j].firstName), keyString) + " ";
			     	if(lastName != null && lastName != "zzzz" && lastName != "zzz2")	
					 	resultHTML += highLightKeyword(validateDataItem("", articleObject.searchResult.articles[i].authors[j].lastName), keyString) + "</A>, ";
				 }
			}
			
			resultHTML += articleObject.searchResult.articles[i].parentTitle.italics();
			resultHTML += validateDataItem(", Vol. ", articleObject.searchResult.articles[i].volume);
			resultHTML += validateDataItem(", no. ", articleObject.searchResult.articles[i].issueNumber) + ", ";
			
			resultDetailsKeyword = validateDataItem("", articleObject.searchResult.articles[i].parentTitle);
			resultDetailsKeyword += ", " + articleObject.searchResult.articles[i].month + " " + articleObject.searchResult.articles[i].year;
	        
	        //resultHTML += "<A href=# onclick=\"treePub.pubGetPublicationResults('" + articleObject.searchResult.articles[i].issueObjectNodeID + "','" + resultDetailsKeyword + "')\">";
			resultHTML += ( articleObject.searchResult.articles[i].issueObjectNodeID ) ? "<A href=?publication=" + articleObject.searchResult.articles[i].issueObjectNodeID + "&label=" + escape(resultDetailsKeyword) + " onclick=\"return treePub.pubGetPublicationResults('" + articleObject.searchResult.articles[i].issueObjectNodeID + "','" + resultDetailsKeyword + "')\">" : " ";
			resultHTML += articleObject.searchResult.articles[i].month + " ";
			resultHTML += articleObject.searchResult.articles[i].year;
			resultHTML += ( articleObject.searchResult.articles[i].issueObjectNodeID ) ? "</A>" : " "; 
			
			resultHTML += validateDataItem(", pp. ", articleObject.searchResult.articles[i].startPage);
			resultHTML += validateDataItem("-" , articleObject.searchResult.articles[i].endPage);		
			
			var articleTempObject = validateDataItem("", articleObject.searchResult.articles[i].articleAbstract);
			
			if ( articleTempObject != null && articleTempObject.length > 0 )		    
			{
			    resultHTML += "<BR>" + highLightKeyword(articleTempObject, keyString) + "..."; //highLightKeyword(articleTempObject.substr(0, 200), keyString) + "...";
			    //alert("articleTempObject=" + highLightKeyword(articleTempObject, keyString));    
	        }
	        
			resultHTML += "&nbsp;<FONT id=displayArticleRatesFontId class='searchResultItem'>";	        
			if ( articleObject.searchResult.articles[i].articleRating != null )
		    {    
		        for(var k = 0; k < articleObject.searchResult.articles[i].articleRating.averageRate; k++)
		        {
		            resultHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' height=15 width=15 />";		    
		        }
		        for(var j = articleObject.searchResult.articles[i].articleRating.averageRate; j < 5; j++)
		        {
			        resultHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' class='transparent_class' height=15 width=15 />";
		        }
		        resultHTML += "</FONT>";
		        resultHTML += ("(" + articleObject.searchResult.articles[i].articleRating.count + " Rated)").fontcolor("gray");	        
		    }
		    else
		    {       	        
		        for(var k = 0; k < 5; k++)
		        {
		            resultHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' class='transparent_class' height=15 width=15 />";    
		        }	        
		        resultHTML += "</FONT>";        
		    }
			
			if( articleObject.searchResult.articles[i].price != null )
			{
			    resultHTML += "<P style='margin: 0; padding: 0; text-align: right' class=searchResultItem><b>$" + articleObject.searchResult.articles[i].price + "&nbsp;</b>" ;
			    
			    if( articleObject.searchResult.articles[i].price == '0.00' )
			    {
			        if( downloadCartList.hasItem(articleNo) )
			        {
			            //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Download Article' DISABLED=disable/>&nbsp;";
			        }
			        else
			            resultHTML += "<INPUT type=button " + getButtonClass() +" id=addToDownloadId" + articleNo + " value='Download Article' onclick='searchResults.addToDownload(" + articleNo + ")'/>&nbsp;";
			            
			        //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Buy Article' DISABLED=disable /></p>";
			    }
			    else
			    {
			        //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Download Article' DISABLED=disable/>&nbsp;";
			        
			        if( shoppingCartList.hasItem(articleNo) )
			        {
			            //resultHTML += "<INPUT type=button " + getButtonClass() +" value='Buy Article' DISABLED=disable /></p>";	        
			        }
			        else
			        {
			            //resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false)' type=button value='Buy Article' /></p>";
			        	//Code change for BuyArticle tutorialFix
			        	resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false,\"" + articleType + "\")' type=button value='Buy Article' /></p>";
			        }
			    }
			}
			else
			{
			    resultHTML += "<P style='margin: 0; padding: 0; text-align: right'> ";
			    resultHTML += "<INPUT type=button " + getButtonClass() +" id=addToDownloadId" + articleNo + " value='Download Article' onclick='searchResults.addToDownload(" + articleNo + ")'/>&nbsp;";
			    //resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false)' type=button value='Buy Article' /></p>";		    
				//Code change for BuyArticle tutorialFix
			    resultHTML += "<INPUT id=addCartButtonId"+ articleNo +" " + getButtonClass() +" onclick='searchResults.addToShoppingCart(" + articleNo + ",false,\"" + articleType + "\")' type=button value='Buy Article' /></p>";
			}
			resultHTML += "</TD>";
			resultHTML += "</TR>";
		}
		resultHTML += "</TABLE>";
		
		document.getElementById("queryResultDetailsDivId").innerHTML = resultDetailsHTML;
	    document.getElementById("queryResultsDivId").innerHTML = resultHTML;
	        
	    /*
	        The below paramter '0' = Execute later on explicit request, because by default it is
	        relevance type.  It is done here mainly for the purpose of setting 
	        format styles and associating with its functions
	    */
	    if ( typeof(sortByType) == "undefined" )
	        sortByType = "relevance";
	    
	    //Update the font size from MyComSoc preferences
	    searchResults.setSearchResultPageFontSize(startArticleNo, global.variables.myComSocUserFont);
	    searchResults.showSearchResultsBorder();
		searchResults.showSearchResultsDetailsBorder();
		showPagination();
		components.penel.hideMonthIssues();  // Close notification/dialog content after getting the serach results
		components.penel.hideCurrentIssues();
		components.penel.hideTopArticle();
		components.penel.hideAds();
		printer.printerPageType = 0;
		printer.showPrinterPageLink();
		searchResults.setSortByType(sortByType, 0);
		document.getElementById("homebodyId").scrollTop = 1;    //Move the page cursor on top
		
		
		return true;

},


/**
Gets the article detail informaion from the server

@return personID Unique person id
*/
getAuthorData: function(authorID)
{
	var ajaxRequest = zXmlHttp.createRequest();
	showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{
				hideTopNotification();
				searchResults.renderAuthorData(ajaxRequest.responseText, authorID);			
				latestSearchResultFunCall = "searchResults.getAuthorData('" + authorID + "')";				
			}
			else
			{
				hideTopNotification();//hideNotification('queryResultsDivId');
				alert("Unable to get author data response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 				
			}
		}		
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "person.action?authorID=" + authorID + ((loginStatus == false) ? "" : "&nullParam=" + new Date()), true);	//Server URL
	//ajaxRequest.open("GET", "http://localhost:8181/comsocdl/html/person.action-425161" , true);	//Server URL
	ajaxRequest.send(null);
	return false;    //To deactive the anchor tag's link redirection
},

/**
Renders the authors data and displays

@param authorData Author data as a JSON object and it is to be rendered
*/
renderAuthorData: function(authorData, authorId)
{
	var tempFlag = 0;
	try
	{
		var authorListObject = eval('(' + authorData + ')'); //Author server JSON object evaluation
		if ( authorListObject.authorCitation == null )
		    throw "No author found";
	}
	catch(e)
	{
		//alert("Unable to get author data: " + e);// + e.description); 
		tempData = "<BR>" + "<P class=searchResultItem> " + showAlertInformation(2, "Author not found") + "</P>"
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
		return false;
	}	
    tempHTML = "<DIV style='' class=searchResultPageTitle>Author Profile<HR style='height: 1px'></DIV>";
	
	if ( authorListObject.authorCitation.isFavorite == "true")
	    tempHTML += "<INPUT id=saveSearchId type=button value='View/Edit Favorites' " + getButtonClass() +" onclick='access.myComSoc.getMyComSocInfo(); access.myComSoc.myComSocGetFavorites(); ' style='margin-top: 5px;' >";
	else if ( authorListObject.authorCitation.isFavorite == "false" )
	    tempHTML += "<INPUT id=saveSearchId type=button value='Save Author' " + getButtonClass() +" onclick=searchResults.saveAuthor('" + authorId +"','author') style='margin-top: 5px;' >";	    
	
	tempHTML += "<P id=authorDetailsId class=searchResultItem style='font-size: 10px'>";
	if ( authorListObject.authorCitation.author != null )
	{
	    tempHTML += "Author: <U><FONT color=steelblue font-family: 'Arial'>";
	    tempHTML += validateDataItem("", authorListObject.authorCitation.author.firstName);
	    tempHTML += validateDataItem(" ", authorListObject.authorCitation.author.midName);
	    tempHTML += validateDataItem(" ", authorListObject.authorCitation.author.lastName);
	    tempHTML += "</FONT> </U>";
	    tempHTML = tempHTML.bold();
	    tempFlag = 1;
	}
	
	if ( authorListObject.authorCitation.publicationContributions != null )
	{
	    tempHTML += "<BR><BR>Article(s):<BR><BR>".bold();
	    for( j = 0; j < authorListObject.authorCitation.publicationContributions.contributions.length; j++)
        {
            tempHTML += ((j+1) + "").bold() + ". ";
            tempHTML += searchResults.prepareNewPubRefInfo(authorListObject.authorCitation.publicationContributions.contributions[j]);    
            tempHTML += "<BR><BR>";
        }
        tempFlag = 1;        
	}
	
	if ( authorListObject.authorCitation.biography != null )
	{
	    var tempBio = validateDataItem("<BR>Biography:<BR>".bold(), authorListObject.authorCitation.biography);
	    tempBio = tempBio.replaceAll("<p>","<BR><BR>");
	    tempBio = tempBio.replaceAll("</p>","");
	    tempBio = tempBio.replaceAll("<p />","<BR><BR>");
	    tempHTML += tempBio;
	    tempFlag = 1;
	}
	tempHTML += "</P>";
	
	if ( tempFlag == 0 )
	    tempHTML = "<DIV style='' class=searchResultPageTitle>Author Profile<HR style='height: 1px'></DIV><FONT class=searchResultItem style='font-size: 10px'>" + showAlertiveInformation("Invalid author data found!") +"</FONT><BR><BR>";
	
	document.getElementById("queryResultsDivId").innerHTML = tempHTML;
	
	if ( tempFlag != 0 )
	{
	    //Update the font size from MyComSoc preferences
        searchResults.setAuthorPageFontSize("authorDetailsId", global.variables.myComSocUserFont);
    }
    
    searchResults.hideAllPanels();
    /*
	if ( authorListObject.authorCitation.isFavorite == "false" )
	{
	    global.setSaveSearchParams(authorId, "author");	
	}
	*/
	
	printer.printerPageType = 2;	
	printer.showPrinterPageLink();
	
	historyIsItResultDetails = 0;
	parityHistory.setInHistory();
	document.getElementById("homebodyId").scrollTop = 1;    //Move the page cursor on top
	
	components.penel.hideBanner();
},

/**
Prepares the publication reference information

@param pubRefObj JSON publication reference object 
*/
preparePubRefInfo: function(pubRefObj)
{
    var pubRefInfoHTML = "";
     
	for( i = 0; i < pubRefObj.PubRef.Author.length; i++)
	{
		pubRefInfoHTML += "<A href=# onclick=\"searchResults.getAuthorData(" + pubRefObj.PubRef.Author[i].ObjNodeID +")\">";
		pubRefInfoHTML += (pubRefObj.PubRef.Author[i].Name.FirstName || "");
		pubRefInfoHTML += " " + (pubRefObj.PubRef.Author[i].Name.LastName || "");  	                      
		pubRefInfoHTML += "</A>, ";        
	}
	
	pubRefInfoHTML += "<A href=# onclick=\"searchResults.getArticleData('" + pubRefObj.PubRef.ObjNodeID +"')\">";
	pubRefInfoHTML += validateDataItem("", pubRefObj.PubRef.ArticleTitle).bold();            
	pubRefInfoHTML += "</A>, "; 
    
	pubRefInfoHTML += (pubRefObj.PubRef.ParentTitle || "");            
    
	pubRefInfoHTML += validateDataItem(", Vol ", pubRefObj.PubRef.Volume); 
	pubRefInfoHTML += validateDataItem(", no ", pubRefObj.PubRef.IssueNumber);  
	
	pubRefInfoHTML += "<A href=# onclick=\"treePub.pubGetPublicationResults('" + pubRefObj.PubRef.IssueObjNodeID +"','" + pubRefObj.PubRef.ParentTitle +"')\">";
	pubRefInfoHTML += "," + validateDataItem(" ", pubRefObj.PubRef.Date.Month);
	pubRefInfoHTML += validateDataItem(" ", pubRefObj.PubRef.Date.Year);        
	pubRefInfoHTML += "</A>"; 
    
	pubRefInfoHTML += validateDataItem(", pp ", pubRefObj.PubRef.StartPage); 
	pubRefInfoHTML += validateDataItem("-", pubRefObj.PubRef.EndPage); 
	
	if( pubRefObj.PubRef.SummaryText != null )
	{
	    var tempFlag = 0;
	    var value;	
	    var tempAbstractData = "";
	
	    if ( typeof(pubRefObj.PubRef.SummaryText) == "object" )
	    {
		    for (var propName in pubRefObj.PubRef.SummaryText) 
		    {
			    value = pubRefObj.PubRef.SummaryText[propName];
			   
			    if ( propName == "#text" )
			    {
				    tempAbstractData += value ; 
				    tempFlag = 1;
			    }
			    else if ( propName == "p" )
			    {
			        if ( typeof(pubRefObj.PubRef.SummaryText[propName]["#text"]) == "undefined" )
				        tempAbstractData += value; 
				    else
				        tempAbstractData += pubRefObj.PubRef.SummaryText[propName]["#text"]; 
				    tempFlag = 1;
			    }
		    }	
	    }	    		
	    if ( tempFlag == 0 )	
	        tempAbstractData += ( pubRefObj.PubRef.SummaryText || "" );
	
	    pubRefInfoHTML += "<BR>" + tempAbstractData.substr(0, 200) + "..."; 	   
	 }
	return pubRefInfoHTML;
},


/**
Prepares the publication reference information

@param pubRefObj JSON publication reference object 
*/
prepareNewPubRefInfo: function(pubRefObj,articleURL)
{
    var pubRefInfoHTML = "";
    for(var i = 0; pubRefObj.authors != null && i < pubRefObj.authors.length; i++)
	{
		//pubRefInfoHTML += "<A href=# onclick=searchResults.getAuthorData(" + pubRefObj.authors[i].authorID +")>";
		if(articleURL != null && articleURL != 'undefined' && articleURL != "")
			pubRefInfoHTML += "<A href=# onclick=\"window.open(ROOT_URL+'?author=" + pubRefObj.authors[i].authorID +"')\">";
		else
		pubRefInfoHTML += "<A href=?author=" + pubRefObj.authors[i].authorID +" onclick=\"return searchResults.getAuthorData(" + pubRefObj.authors[i].authorID +")\">";
	    
	    	pubRefInfoHTML += validateDataItem("", pubRefObj.authors[i].firstName);
		pubRefInfoHTML += validateDataItem(" ", pubRefObj.authors[i].midName); 
		pubRefInfoHTML += validateDataItem(" ", pubRefObj.authors[i].lastName);
		pubRefInfoHTML += "</A>, ";
		
	}
	
	//pubRefInfoHTML += "<A href=# onclick=searchResults.getArticleData(" + pubRefObj.articleID +")>";
	if(articleURL != null && articleURL != 'undefined' && articleURL != "")
		pubRefInfoHTML += "<B><A href=# onclick=\"window.open(ROOT_URL+'?article=" + pubRefObj.articleID +"')\">";
	else
	pubRefInfoHTML += "<B><A href=?article=" + pubRefObj.articleID + " onclick=\"return searchResults.getArticleData('" + pubRefObj.articleID + "') \">";
	
	pubRefInfoHTML += "\"" + validateDataItem("", pubRefObj.articleTitle) + "\"";
	pubRefInfoHTML += "</A></B>, "; 
	
    pubRefInfoHTML += validateDataItem("", pubRefObj.parentTitle);            
    pubRefInfoHTML += validateDataItem(", vol. ", pubRefObj.volume); 
	pubRefInfoHTML += validateDataItem(", no. ", pubRefObj.issueNumber);  
	//pubRefInfoHTML += ", <A href=# onclick=\"treePub.pubGetPublicationResults('" + pubRefObj.issueObjectNodeID +"','" + (pubRefObj.parentTitle +", "+ pubRefObj.month +" "+ pubRefObj.year ) +"')\">";
	if(articleURL != null && articleURL != 'undefined' && articleURL != "")
		pubRefInfoHTML += ", <A href=# onclick=\"window.open(ROOT_URL+'?publication=" + pubRefObj.issueObjectNodeID + "&label=" + escape(pubRefObj.parentTitle +", "+ pubRefObj.month +" "+ pubRefObj.year) +"')\">";
	else
		pubRefInfoHTML += ", <A href=?publication=" + pubRefObj.issueObjectNodeID + "&label=" + escape(pubRefObj.parentTitle +", "+ pubRefObj.month +" "+ pubRefObj.year) + " onclick=\"return treePub.pubGetPublicationResults('" + pubRefObj.issueObjectNodeID + "','" + pubRefObj.parentTitle +", "+ pubRefObj.month +" "+ pubRefObj.year + "')\">";
	pubRefInfoHTML += validateDataItem(" ", pubRefObj.month);
	pubRefInfoHTML += validateDataItem(" ", pubRefObj.year);        
	pubRefInfoHTML += "</A>";
	pubRefInfoHTML += validateDataItem(", pp. ", pubRefObj.startPage); 
	pubRefInfoHTML += validateDataItem("-", pubRefObj.endPage); 
	
	if ( validateDataItem("", pubRefObj.articleAbstract) != "" )
	{
	    var tempAbs = pubRefObj.articleAbstract + "...";//.substr(0, 200) + "...";
	    tempAbs = tempAbs.replaceAll("<p>","");
	    tempAbs = tempAbs.replaceAll("</p>","");
	    tempAbs = tempAbs.replaceAll("<P />","");
	    pubRefInfoHTML += "<BR>" + tempAbs;
	}
	 
	 
	return pubRefInfoHTML;
},

/**
Gets the author detail informaion from the server

@return personID Unique person id
*/
getArticleData: function(articleID)
{
    var ajaxRequest = zXmlHttp.createRequest();   
	showTopNotification();
	ajaxRequest.onreadystatechange = function()
	{	
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200 && ajaxRequest.responseText != "")
			{
			    searchResults.renderArticleData(articleID, ajaxRequest.responseText);
				latestSearchResultFunCall = "searchResults.getArticleData('" + articleID + "')";
				hideTopNotification();
			}
			else
			{
				//alert("Unable to get article data response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 
				showNotification('queryResultsDivId', '  Request Failed!', 3);
			}
		}
	}
	//ajaxRequest.open("GET", ROOT_DB_URL + "publication.action?articleID=" + articleID + ((loginStatus == false) ? "" : "&nullParam=" + new Date()), true);	//Server URL
	ajaxRequest.open("GET", ROOT_DB_URL + "publication.action?articleID=" + articleID + "&nullParam=" + new Date(), true);	//Server URL
	//ajaxRequest.open("GET", "http://localhost:8181/comsocdl/html/publication.actionnew6" , true);	//Server URL
	ajaxRequest.send(null);
	return false;    //To diactive the anchor tag's link redirection
},

/**
Renders the Publication data and displays

@param articleID Article id
@param articleData Article summary page details
*/
renderArticleData: function(articleID, articleData)
{
	var tempFlag = 0;
	var isTutorial = 0;
	var tempBiblioData = "";
    var monthNames = new Array("January", " February", " March", " April", " May", " June", " July", " August", " September", " November", " October", " December");
    
	try
	{
	    var articleListObject = eval('(' + articleData + ')');
	    if ( articleListObject.publication.articleMetaData == null )
	        throw("No article found!")
	}
	catch(e)
	{
		//showNotification('queryResultsDivId', '  Request Failed!', 3);
		tempData = "<BR>" + "<P class=searchResultItem> " + showAlertInformation(2, "Article not found") + "</P>"
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
		return false;
	}
    
    tempHTML = "<DIV style='' class=searchResultPageTitle>Summary Page<HR style='height: 1px'></DIV>";
	tempHTML += "<A NAME='article'></A>";
        
	if( articleListObject.publication.price != null )
	{
        tempHTML += "<P style='margin: 3px; padding: 0;' class=searchResultItem>" ;
		tempHTML += "<b id=artilceSummaryPagePrice>Price: $" +  articleListObject.publication.price + "&nbsp;</b>" ;
		    
        if( articleListObject.publication.price == '0.00' )
		{
		    if( downloadCartList.hasItem(articleID) )
		    {
		        //tempHTML += "<INPUT type=button " + getButtonClass() +" value='Download Article' DISABLED=disable/>&nbsp;";
		    }
		    else
		        tempHTML += "<INPUT type=button id=addToDownloadId" + articleID + " " + getButtonClass() +" value='Download Article' onclick='searchResults.addToDownload(" + articleID + ")'/>&nbsp;";
		    //tempHTML += "<INPUT type=button value='Buy Article' " + getButtonClass() +" DISABLED=disable />";		    
	    }
	    else
	    {
		    //tempHTML += "<INPUT type=button value='Download Article' " + getButtonClass() +" DISABLED=disable/>&nbsp;";
		    if( shoppingCartList.hasItem(articleID) )
		    {
		        //tempHTML += "<INPUT type=button " + getButtonClass() +" value='Buy Article' DISABLED=disable /></p>";	        
		    }
		    else
		    {
		        //tempHTML += "<INPUT id=addCartButtonId"+ articleID +" onclick='searchResults.addToShoppingCart(" + articleID + ",false)' " + getButtonClass() +" type=button value='Buy Article' />";
		        if(articleListObject.publication.formats != null && articleListObject.publication.formats.length == 2
					    && (articleListObject.publication.formats[0].formatType == "preview\/html" || articleListObject.publication.formats[1].formatType == "preview\/html"))
				tempHTML += "<INPUT id=addCartButtonId"+ articleID +" onclick='searchResults.addToShoppingCart(" + articleID + ",false,\"FullTutorial\")' " + getButtonClass() +" type=button value='Buy Article' />";
			else
				tempHTML += "<INPUT id=addCartButtonId"+ articleID +" onclick='searchResults.addToShoppingCart(" + articleID + ",false)' " + getButtonClass() +" type=button value='Buy Article' />";
		    }
		}
	}
	else
	{
        tempHTML += "<P style='margin: 5px; padding: 0;'><INPUT type=button id=addToDownloadId" + articleID + " value='Download Article' " + getButtonClass() +" onclick='searchResults.addToDownload(" + articleID + ")'/>&nbsp;";
        tempHTML += "<INPUT id=addCartButtonId"+ articleID +" onclick='searchResults.addToShoppingCart(" + articleID + ",false)' " + getButtonClass() +" type=button value='Buy Article' />";        
	}
	
	if ( articleListObject.publication.isFavorite == "true")
	    tempHTML += "&nbsp;<INPUT id=saveSearchId type=button value='View/Edit Favorites' " + getButtonClass() +" onclick='access.myComSoc.getMyComSocInfo(); access.myComSoc.myComSocGetFavorites(); ' style='margin-top: 5px;' >";
	else if ( articleListObject.publication.isFavorite == "false")
	    tempHTML += "&nbsp;<INPUT id=saveSearchId type=button value='Save Article' " + getButtonClass() +" onclick=searchResults.saveArticle('" + articleID +"','article') ></p>";  
	
	tempHTML += "<P id=articleDetailsId class='searchResultItem'>";
	tempHTML += "Title: ".bold() + "<FONT class=articleTitle id=artilceSummaryTitle>" + validateDataItem("", articleListObject.publication.articleMetaData.articleTitle) + "</FONT>";
	
	if ( articleListObject.publication.formats != null && articleListObject.publication.formats.length > 0 )
	{
	    tempHTML += "<BR><BR>Full Text: ".bold();
	    if(articleListObject.publication.formats.length == 2)
	    {
	     	if(articleListObject.publication.formats[0].formatType == "preview\/html" || articleListObject.publication.formats[1].formatType == "preview\/html")
	     	isTutorial = 1;
	     	
	    }
	    for(var i = 0; i < articleListObject.publication.formats.length; i++)
	    {
	        //alert("formatType=" + articleListObject.publication.formats[i].formatType);
	        if ( articleListObject.publication.formats[i].formatType == "application\/pdf" )
	        {
	            if ( articleListObject.publication.price == "0.00" )
	            {
	                tempHTML += "<A href=# onclick=\"return searchResults.getFullText(" + articleID +",'application\/pdf')\" class=\"searchResultItem headerImagesId\">";              
	            }
	            else
	            {
	                tempHTML += "<A href=# onclick=\"return searchResults.addToShoppingCart(" + articleID +",true)\" class=\"searchResultItem headerImagesId\">";
	            }
	            tempHTML += "<IMG src='" + ROOT_URL + "images/pdf.gif' />"+ " PDF ".bold();
	            tempHTML += "</A> ";
	        }
	        else if ( articleListObject.publication.formats[i].formatType == "preview\/html" )
			{
			tempHTML += "<A href=# onclick=\"return searchResults.getFullText(" + articleID +",'preview\/html')\" class=\"searchResultItem headerImagesId\">";              
			tempHTML += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Preview ".bold();
			tempHTML += "</A> ";
	        }
	        else if ( articleListObject.publication.formats[i].formatType == "text\/html" )
	        {
	            if ( articleListObject.publication.price == "0.00" )
	            {
	                tempHTML += "<A href=# onclick=\"return searchResults.getFullText(" + articleID +",'text\/html')\" class=\"searchResultItem headerImagesId\">";              
	            }
	            else
	            {
	              if(isTutorial == 1)
	                tempHTML += "<A href=# onclick=\"return searchResults.addToShoppingCart(" + articleID +",true,'FullTutorial')\" class=\"searchResultItem headerImagesId\">";
	              else
	                tempHTML += "<A href=# onclick=\"return searchResults.addToShoppingCart(" + articleID +",true)\" class=\"searchResultItem headerImagesId\">";
	            }
	            if(isTutorial == 1)
	            	tempHTML += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Full Tutorial ".bold();
	            else
	            	tempHTML += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " HTML ".bold();
	            tempHTML += "</A> ";
	        }
	        if ( i < articleListObject.publication.formats.length - 1 )
	            tempHTML += " | ";
	    }
	}
	
	tempHTML += "&nbsp;<FONT id=displayArticleRatesFontId class='searchResultItem'>";
	if ( articleListObject.publication.articleRating != null )
	{
	    for( var k = 0; k < articleListObject.publication.articleRating.averageRate; k++)
	    {
	        tempHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' height=15 width=15 />";		    
	    }
	
	    for(var i = articleListObject.publication.articleRating.averageRate; i < 5; i++)
	    {
		    tempHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' class='transparent_class' height=15 width=15 />";
	    }
	    tempHTML += "</FONT>";
	    tempHTML += ("(" + articleListObject.publication.articleRating.count + " Rated)").fontcolor("gray");	        
	}
	else
	{       
	     for(var i = 0; i < 5; i++)
	     {
	        tempHTML += "<IMG src='" + ROOT_URL + "images/orangeStar.jpg' class='transparent_class' height=15 width=15 />";
	     }
	     tempHTML += "</FONT>";
	}
	tempHTML += "&nbsp;<FONT class='searchResultItem' id=rateArticleFontId></FONT>"; 
	
	var tempAuthorData = ""; 
	var firstName = "";
	var lastName = "";       
	if ( articleListObject.publication.articleMetaData.authors != null && articleListObject.publication.articleMetaData.authors.length > 0 )
	{
	    tempHTML += "<BR><BR>Author(s): ".bold();
            
	    for( i = 0; i < articleListObject.publication.articleMetaData.authors.length; i++)
        {
	        firstName = articleListObject.publication.articleMetaData.authors[i].firstName;
	        lastName = articleListObject.publication.articleMetaData.authors[i].lastName;
            //tempAuthorData += "<A href=# onclick=\"searchResults.getAuthorData(" + articleListObject.publication.articleMetaData.authors[i].authorID + ")\">";
            if(firstName != null || lastName != null)
            {
            	tempAuthorData += "<A href=?author=" + articleListObject.publication.articleMetaData.authors[i].authorID +" onclick=\"return searchResults.getAuthorData(" + articleListObject.publication.articleMetaData.authors[i].authorID +")\">";
            	if(firstName != null && firstName != "zzzz" && firstName != "zzz2")
            		tempAuthorData += articleListObject.publication.articleMetaData.authors[i].firstName;
            	if(lastName != null && lastName != "zzzz" && lastName != "zzz2")
	            	tempAuthorData += " " + articleListObject.publication.articleMetaData.authors[i].lastName;            
            	tempAuthorData += "</A>";	        
            
            	if ( i == articleListObject.publication.articleMetaData.authors.length - 2)
		        tempAuthorData += " and "; 
		    	else if ( i != articleListObject.publication.articleMetaData.authors.length - 1)
		        tempAuthorData += ", "; 
		     }
        }    
    }
    
    tempHTML += tempAuthorData;
	
	tempHTML += "<BR><BR>Bibliographic Entry: ".bold();
    tempBiblioData += tempAuthorData + ", ";
	tempBiblioData += validateDataItem("", articleListObject.publication.articleMetaData.articleTitle).bold();
	tempBiblioData += validateDataItem(", ", articleListObject.publication.threadTitle);
	tempBiblioData += validateDataItem(", vol. ", articleListObject.publication.articleMetaData.volume);
	tempBiblioData += validateDataItem(", no. ", articleListObject.publication.articleMetaData.issueNumber);
	
	//tempBiblioData += ", <A href=# onclick=\"treePub.pubGetNodeArticles('" + validateDataItem("", articleListObject.publication.articleMetaData.issueObjectNodeID) +"','" + (articleListObject.publication.threadTitle +", "+ articleListObject.publication.articleMetaData.month +" "+ articleListObject.publication.articleMetaData.year ) +"')\">";
	tempBiblioData += ( articleListObject.publication.articleMetaData.issueObjectNodeID ) ? ", <A href=?publication=" + validateDataItem("", articleListObject.publication.articleMetaData.issueObjectNodeID) + "&label=" + escape((articleListObject.publication.threadTitle +", "+ articleListObject.publication.articleMetaData.month +" "+ articleListObject.publication.articleMetaData.year )) + " onclick=\"return treePub.pubGetPublicationResults('" + validateDataItem("", articleListObject.publication.articleMetaData.issueObjectNodeID) + "','" + (articleListObject.publication.threadTitle +", "+ articleListObject.publication.articleMetaData.month +" "+ articleListObject.publication.articleMetaData.year ) + "')\">" : ", ";
	//tempBiblioData += ", <A href=?publication=" + validateDataItem("", articleListObject.publication.articleMetaData.issueObjectNodeID) + "&label=" + escape((articleListObject.publication.threadTitle +", "+ articleListObject.publication.articleMetaData.month +" "+ articleListObject.publication.articleMetaData.year )) + " onclick=\"return treePub.pubGetPublicationResults('" + validateDataItem("", articleListObject.publication.articleMetaData.issueObjectNodeID) + "','" + (articleListObject.publication.threadTitle +", "+ articleListObject.publication.articleMetaData.month +" "+ articleListObject.publication.articleMetaData.year ) + "')\">";
	tempBiblioData += validateDataItem("", articleListObject.publication.articleMetaData.month) ;
	tempBiblioData += validateDataItem(" ", articleListObject.publication.articleMetaData.year);
	tempBiblioData += ( articleListObject.publication.articleMetaData.issueObjectNodeID ) ? "</A>" : "";
	
	tempBiblioData += validateDataItem(", pp. ", articleListObject.publication.articleMetaData.startPage);
	tempBiblioData += validateDataItem("-", articleListObject.publication.articleMetaData.endPage);
	
	tempHTML += tempBiblioData;
	
	if ( articleListObject.publication.subjectWords != null && articleListObject.publication.subjectWords.length > 0 )
	{
	    tempHTML += "<BR><BR>Ontology Subjects: ".bold();
	    for(var i = 0; i < articleListObject.publication.subjectWords.length; i++)
	    {
		    //tempHTML += "<A href=# onclick=\"treeSub.getSubjectResults('" + articleListObject.publication.subjectWords[i].ontologyNodeID + "','" + articleListObject.publication.subjectWords[i].term + "') \">";
		    tempHTML += "<A href=?subject=" + articleListObject.publication.subjectWords[i].ontologyNodeID + "&term=" + escape(articleListObject.publication.subjectWords[i].term) + " onclick=\"return treeSub.getSubjectResults('" + articleListObject.publication.subjectWords[i].ontologyNodeID + "','" + articleListObject.publication.subjectWords[i].term + "')\">";
            tempHTML += validateDataItem("", articleListObject.publication.subjectWords[i].term);
		    tempHTML += "</A>; ";
	    }
	}
	
	if ( articleListObject.publication.keywords != null && articleListObject.publication.keywords.length > 0 )
	{
	    var term;
	    tempHTML += "<BR><BR>Keywords: ".bold();    
	    for(var i = 0; i < articleListObject.publication.keywords.length; i++)
	    {
		    term = validateDataItem("", articleListObject.publication.keywords[i].term);
		    term = term.replace("'s", "");  // ' (single quot) causes seperation of paramters in function
		    //tempHTML += "<A href=# onclick=\"submitKeywordSearch('" + term +"','keyword')\">";
		    tempHTML += "<A href=?keyword=" + escape(term) + " onclick=\"return submitKeywordSearch('" + term +"','keyword')\">";
            tempHTML += "" + trim(validateDataItem("", articleListObject.publication.keywords[i].term));
		    tempHTML += "</A>";
    		
		    if ( i != articleListObject.publication.keywords.length - 1)
			    tempHTML += "; ";		
	    }
    }
    
	tempFlag = 0;	
	tempHTML += "<BR><BR>Abstract: ".bold() + "<BR>";
	if ( articleListObject.publication.articleMetaData.articleAbstract != null )
	{
	    var tempAbs = articleListObject.publication.articleMetaData.articleAbstract;
	    tempAbs = tempAbs.replaceAll("<p>","<BR><BR>");
	    tempAbs = tempAbs.replaceAll("</p>","");
	    tempAbs = tempAbs.replaceAll("<p />","<BR><BR>");
	    if ( tempAbs != null || tempAbs != undefined )
	        tempHTML += tempAbs;
	    tempFlag = 1;
	}	
	if ( tempFlag == 0 )
        tempHTML += "None";
    
	tempFlag = 0;
	
	var quickLinksData, linkFlag = 0;
	quickLinksData = "<BR><BR>Quick Links: ".bold();
	if ( articleListObject.publication.articleCitations != null && articleListObject.publication.articleCitations.length > 0 )
	{
	    quickLinksData += "<A HREF=\"#citation\" style='color: blue'>Citations</A>";
	    linkFlag = 1;
	}
	if ( articleListObject.publication.patentCitations != null && articleListObject.publication.patentCitations.length > 0 )
	{
	    if ( linkFlag++ == 1 ) 
	        quickLinksData += ", ";
	    quickLinksData += "<A HREF=\"#patents\" style='color: blue'>Patents</A>";
	}
	if ( linkFlag > 0 ) 
	    quickLinksData += " <IMG src='" + ROOT_URL + "images/quickLinks-down.gif'>";
	else
	    quickLinksData = "";    // If no links found
	    
	tempHTML += quickLinksData;
	if ( articleListObject.publication.refrences != null && articleListObject.publication.refrences.length > 0 )
	{
	    tempHTML += "<BR><BR>References:<BR>".bold();
	    tempHTML += "<SPAN class=spanShortCutLinks><A HREF='#historyBack' style='color: blue'>Back to top ^</A></SPAN>";
	    tempHTML += "<BR>The papers listed below are references to articles within the collection. Please refer to the paper itself for a full list of references.".bold();
	    for(var i = 0; i < articleListObject.publication.refrences.length; i++)
	    {
		    tempHTML += "<BR><BR>[" + articleListObject.publication.refrences[i].refLabel.bold() + "] ";
		    tempHTML += searchResults.prepareNewPubRefInfo(articleListObject.publication.refrences[i].referenceArticles); 		    
	    }
	}
	
	if ( articleListObject.publication.articleCitations != null && articleListObject.publication.articleCitations.length > 0 )
	{
	    tempHTML += "<BR><BR><BR><A NAME='citation' style='color:black'>Citations:</A><BR>".bold();    
	    tempHTML += "<SPAN class=spanShortCutLinks><A HREF='#historyBack' style='color: blue'>Back to top ^</A></SPAN>";
	    tempHTML += "<BR>The papers listed below are those that contain a reference to the paper you have selected. These citations are only from the articles within the collection.".bold();
	    for(var i = 0; i < articleListObject.publication.articleCitations.length; i++)
	    {
		    tempHTML += "<BR><BR>" + ((i+1) + ". ").bold();
		    tempHTML += searchResults.prepareNewPubRefInfo(articleListObject.publication.articleCitations[i].citations); 		    
	    }
	}
	
	if ( articleListObject.publication.patentCitations != null && articleListObject.publication.patentCitations.length > 0 )
	{
	    tempHTML += "<BR><BR><BR><A NAME='patents' style='color:black'>Patent Citations:</A><BR>".bold();    
	    tempHTML += "<SPAN class=spanShortCutLinks><A HREF='#historyBack' style='color: blue'>Back to top ^</A></SPAN>";
	    tempHTML += "<BR>The papers listed below are those that contain a reference to the paper you have selected. These citations are only from the articles within the collection.".bold();
	
	    var patentDate;
	    for(var i = 0; i < articleListObject.publication.patentCitations.length; i++)
	    {
		    tempHTML += "<BR><BR>" + ((i+1) + ". ").bold();
		    for(var j = 0; j < articleListObject.publication.patentCitations[i].inventors.length; j++)
	        {
	            tempHTML += validateDataItem("", articleListObject.publication.patentCitations[i].inventors[j].firstName);
	            tempHTML += validateDataItem(" ", articleListObject.publication.patentCitations[i].inventors[j].lastName);    
	            tempHTML += ", ";
		    }
    		
		    tempHTML += "<B><A href=http://patft.uspto.gov/netacgi/nph-Parser?u=/netahtml/srchnum.htm&Sect1=PTO1&Sect2=HITOFF&p=1&r=1&l=50&f=G&d=PALL&s1=" + validateDataItem("", articleListObject.publication.patentCitations[i].patentNumber) +".PN.&OS=PN/" + validateDataItem("", articleListObject.publication.patentCitations[i].patentNumber) +"&RS=PN/" + validateDataItem("", articleListObject.publication.patentCitations[i].patentNumber) + " target=_blank>";
		    tempHTML += "\"" + validateDataItem("", articleListObject.publication.patentCitations[i].patentTitle) + "\"";
		    tempHTML += "</A></B>";
		    tempHTML += validateDataItem(", U.S. Patent: ", formatCSNumber(articleListObject.publication.patentCitations[i].patentNumber));
    		
    		if ( validateDataItem("", articleListObject.publication.patentCitations[i].fillingDate) != "" )
		    {
		        patentDate = monthNames[Number(articleListObject.publication.patentCitations[i].fillingDate.substr(4,2))-1]
		        patentDate += " " + articleListObject.publication.patentCitations[i].fillingDate.substr(6,2) + ", ";
		        patentDate += articleListObject.publication.patentCitations[i].fillingDate.substr(0,4);
		        tempHTML += " " + patentDate;
		    }
	    }
    }
    
	tempHTML += "</P>";   
	document.getElementById("queryResultsDivId").innerHTML = tempHTML;	
    
    if(  articleListObject.publication.rated== "yes" )
	    rateArticleHTML = "<INPUT type=button " + getButtonClass() +" value='Submit' DISABLED=disable/>";   
	else
	{
	    rateArticleHTML = "<input id=rateArticleButtonID" + articleID + " type=button " + getButtonClass();    
	    rateArticleHTML += " value='Rate Article'" + " onclick='searchResults.getRateArticleStarsHTML(" + articleID + ")' />";
	}
	
    document.getElementById("rateArticleFontId").innerHTML = rateArticleHTML;		
		
	//Update the font size from MyComSoc preferences
    searchResults.setArticlePageFontSize("articleDetailsId", global.variables.myComSocUserFont);
    
    searchResults.hideAllPanels();
	/*
	if ( articleListObject.publication.isFavorite == "false")
	{
	    global.setSaveSearchParams(articleID, "article");
	}
	*/
	historyIsItResultDetails = 0;
	parityHistory.setInHistory();	
	
	printer.printerPageType = 1;
	printer.showPrinterPageLink();
	document.getElementById("homebodyId").scrollTop = 1;    //Move the page cursor on top
	
	components.penel.hideBanner();
},

/**
Get the set of stars to rate article
@param articleID Article id to get its rate details
*/
getRateArticleStarsHTML: function( articleID )
{	
    var rateArticleStarsHTML = rateArticleHTML;
    var param;
    
    if ( loginStatus == false )
	{
	     //alert("Please login to rate article!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to rate this article.<BR><BR>";  	
	    //tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + articleID + ">Login</A><BR>";  	
	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif />";  	
	    tempData += " Please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + articleID + ">LOGIN</A> with your IEEE Web Account<BR>";
	    
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    return;	 
	}
	else
	{ 
	    rateArticleStarsHTML += "<FONT class='searchResultItem' id=rateArticleStarsFontId>";
	    
	    for(var i=0; i<5; i++)
	    {
	        param = "rate_" + (i+1);
	        rateArticleStarsHTML += "<IMG src='" + ROOT_URL + "images/redStar.jpg' id=" + param + " class='transparent_class' onclick='searchResults.setRate(\"" + param + "\"," + articleID + ")' height=15 width=15 />";
	    }
	     
	    rateArticleStarsHTML += "</FONT>";
	    document.getElementById("rateArticleFontId").innerHTML = rateArticleStarsHTML;
	}	 
},

/**
Set the rate of an article
@param rateImg ID of an image that represents the rate of the article(1-5)
@param articleID Article id to set its rate
*/
setRate: function(rateImg, articleID)
{	 
    var rateTag, rateInfo;
    rateInfo = rateImg.split("_"); 
	
	for(var k = 0; k < Number(rateInfo[1]); k++)
	{
		rateTag = document.getElementById(rateInfo[0] + '_' + (k+1) );
		rateTag.className = '';
	}
	
	for(var i = Number(rateInfo[1]); i < 5; i++)
	{
		rateTag = document.getElementById(rateInfo[0] + '_' + (i+1) );
		rateTag.className = 'transparent_class';
	}
	
	document.getElementById("rateArticleButtonID" + articleID).value = "Submit";
	document.getElementById("rateArticleButtonID" + articleID).onclick = function(){ searchResults.sendArticleRates(articleID, Number(rateInfo[1]) ); };		  
},

/**
Send the rate of an article
@param articleID Article id to set its rate
@param rate Rate of an article(1-5)
*/
sendArticleRates: function(articleID, rate)
{	
    var ajaxRequest = zXmlHttp.createRequest();
	showNotification('queryResultsDivId', 'Loading...', 0);	
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{	
			    hideNotification('queryResultsDivId');
			   	searchResults.renderSendArticleRates(ajaxRequest.responseText, articleID);		    
			}
			else
			{
				hideNotification('queryResultsDivId');
				alert("Unable to rate article. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
			}
		}
	}	
	ajaxRequest.open("GET", ROOT_DB_URL + "articlerates.action?articleId=" + articleID + "&rate=" + rate +"&nullParam=" + new Date() , true);	
	ajaxRequest.send(null);
},

/**
Render the response holding the new rate of an article
@param articleRatesResults Article data with new rate value
@param articleID Article id to set its rate
*/
renderSendArticleRates: function(articleRatesResults, articleID)
{	
    var articleRatesResultsObject;
    
    try
	{
		var articleRatesResultsObject = eval('(' + articleRatesResults + ')');
	}
	catch(e)
	{
		alert("Unable to get article rate response! \n\n" + e.description); 
		return;
	}
	
	if ( articleRatesResultsObject.rateArticle == "Failure" )
	{
	    alert("Rate to article failed");	
	    return;
    }	
    else if(  articleRatesResultsObject.rateArticle == "Success" ) 
    {   
        document.getElementById("rateArticleButtonID" + articleID).disabled = "disable";
        document.getElementById("rateArticleStarsFontId").style.display = "none";
        //articleRatedList.setItem(articleID,"1");
        searchResults.getArticleData(articleID);
    }        
    
},

/**
Add issue articles to download cart

@param issueTOCId TOCID of issue
*/
addIssueArticlesToDownload: function(issueTOCId)
{	
    if ( loginStatus == false )
	{
	     alert("Please login to access download cart!");
	     return;	 
	}
	window.open(ROOT_DB_URL + "download.action?tocID=" + issueTOCId);    
},


/**
Add to download cart list
*/
addToDownload: function(articleID)
{	
    if ( loginStatus == false )
	{
	    //alert("Please login to download article!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to download this article.<BR><BR>";  	
	    //tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + articleID + ">Login</A><BR>";
	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> ";
	    tempData += "Please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + articleID + ">LOGIN</A> with your IEEE Web Account<BR>";  	
	    
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();	    
	    return;	 
	}
	    	
    if( downloadCartList.length >= downloadCartUpperLimit )
    {
        alert("Download cart limit exceeded.");
        return;
    }
    var ajaxRequest = zXmlHttp.createRequest();
	showTopNotification();
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{	
			    hideTopNotification();
			    searchResults.renderJSONGetDownloadCartResults(ajaxRequest.responseText, articleID);			    
			}
			else
			{
				hideTopNotification();
				alert("Unable to add to download. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
			}
		}		
	}
	
	ajaxRequest.open("GET", ROOT_DB_URL + "downloadCart.action?articleID=" + articleID + "&action=add&nullParam=" + new Date() , true);	
	ajaxRequest.send(null);
},

/**
Render download cart list
*/
renderJSONGetDownloadCartResults: function( addToDownloadResults, articleID )
{
    var getDownloadCartObject;
    
    try
	{
		var getDownloadCartObject = eval('(' + addToDownloadResults + ')');
	}
	catch(e)
	{
		alert("Unable to get download response! \n\n" + e.description); 
		return;
	}
	
	if ( getDownloadCartObject.articlesForDownload == null || getDownloadCartObject.articlesForDownload.message == "failure" )
	{
	    alert("Add to download cart failed for item ");	
	    return;
    }	
    else if(  getDownloadCartObject.articlesForDownload.message == "success" ) 
    {   
        document.getElementById("addToDownloadId" + articleID).disabled = "disable";
        alert("Article is added to download cart");        
        downloadCartList.setItem(articleID,"1");
    }    
},

/**
This method helps in handling article downloads from comsoc portal(ie. Current Issues)
@param articleURL Item id
@param autoShowShoppingCart This flag indicates loading of shopping cart immediately or not
*/
handleComsocPortalDownloads: function(articleURL)
{
	if(articleURL != null)	
   	loginStatus = true;
   if ( loginStatus == false )
   {
   	    //alert("Please login to buy article!");
   	    tempData = "<DIV class='myComSocContent monthIssue'>";
   	    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to Buy/Add article.<BR><BR>";  	
   	    //tempData += "If you are a ComSoc member please <A href=https://kanin.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&articleURL=" + articleURL + ">Login</A><BR>";
   	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif />";  	
	    tempData += " Please <A href=https://kanin.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&articleURL=" + articleURL + ">LOGIN</A> with your IEEE Web Account<BR>";
   	    
   	    tempData += "</DIV>";
   	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
   	    document.getElementById("queryResultsDivId").innerHTML = tempData;
   	    searchResults.hideAllPanels();
   	    historyIsItResultDetails = 0;
   	    parityHistory.setInHistory(); 
   	    return;	 
	}
   var ajaxRequest = zXmlHttp.createRequest();
	
	showTopNotification();
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{
				
			    hideTopNotification();
			    searchResults.renderJSONGetShoppingCartResults(ajaxRequest.responseText, "", "", "", articleURL);			    
			}
			else
			{
				hideTopNotification();
				alert("Unable to get shopping cart response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    			    
			}
		}		
	}
	
    ajaxRequest.open("GET", ROOT_DB_URL + "forwardcontrolleddata.action?url=" + articleURL + "&nullParam=" + new Date() , true);		
	ajaxRequest.send(null);
},

/**
Add the items to the shopping cart

@param articleID Item id
@param autoShowShoppingCart This flag indicates loading of shopping cart immediately or not
*/
addToShoppingCart: function(articleID, autoShowShoppingCart, articleType)
{
    var ajaxRequest = zXmlHttp.createRequest();
    if(articleType == "tutorial")
       loginStatus = true;
	
	if ( loginStatus == false )
	{
	    //alert("Please login to buy article!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to Buy/Add article.<BR><BR>";  	
	    //tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + articleID + ">Login</A><BR>";
	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> ";  	
	    tempData += "Please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + articleID + ">LOGIN</A> with your IEEE Web Account<BR>";
	    
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory(); 
	    return;	 
	}
	
	showTopNotification();
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{				   		
			    hideTopNotification();
			    //alert("ajaxRequest.responseText=" + ajaxRequest.responseText);    return ;
			    searchResults.renderJSONGetShoppingCartResults(ajaxRequest.responseText, articleID, autoShowShoppingCart, articleType);			    
			}
			else
			{
				hideTopNotification();
				alert("Unable to get shopping cart response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    			    
			}
		}		
	}
	
    if ( articleType == "tutorial" )
	    ajaxRequest.open("GET", ROOT_DB_URL + "forwardcontrolleddata.action?iid=" + articleID + "&nullParam=" + new Date() , true);	
    else if ( articleType == "FullTutorial" )
	  ajaxRequest.open("GET", ROOT_DB_URL + "forwardcontrolleddata.action?eid=" + articleID + "&type=text/html&nullParam=" + new Date() , true);	
    else
	  ajaxRequest.open("GET", ROOT_DB_URL + "forwardcontrolleddata.action?eid=" + articleID + "&nullParam=" + new Date() , true);		
	ajaxRequest.send(null);
},

/**
Render response after adding into the shopping cart list

@param addToCartResults JSON response data
*/
renderJSONGetShoppingCartResults: function( addToCartResults, articleID, autoShowShoppingCart, articleType, articleURL )
{
    try
	{
		var getShoppingCartObject = eval('(' + addToCartResults + ')');
	}
	catch(e)
	{
		alert("Unable to get shopping cart response! \n\n" + e.description); 
		return;
	}
	
	if ( getShoppingCartObject.response.message == null)
	{   
	    alert("Add to shopping cart failed for item ");	
	    return;
    }	
    else
    {
        if ( articleURL != null )

	    {
	        if ( getShoppingCartObject.response.message == "Article is added to Cart" )
	        {
	            access.shoppingCart.getShoppingCart( articleURL );
	        }
	        else if ( getShoppingCartObject.response.message == "Data is sent to the User" )
	        {
	            searchResults.getFullTextFile(("url=" + articleURL));
	        }
	        return;
	    }
        
        if ( articleType != null && articleType == "tutorial" )
	    {
	    	
	    	if ( getShoppingCartObject.response.message == "Article is added to Cart" )
	        {
	             access.shoppingCart.getShoppingCart(articleURL,articleType);
	        }
	        else if ( getShoppingCartObject.response.message == "Data is sent to the User" )
	        {
	            searchResults.getFullTextFile(("iid=" + articleID), "", articleType);
	        }
	        return;
	    }
	    
        if ( document.getElementById("addCartButtonId"+articleID) )
        {
            document.getElementById("addCartButtonId"+articleID).disabled = "disable";
            alert("Article is added to shopping cart");            
            shoppingCartList.setItem(articleID,"1");            
        }        
        /*  //To Redirect automatically after clicking PDF/HTML icon for downloading
        if ( autoShowShoppingCart == true ) 
            access.shoppingCart.getShoppingCart();    
        */
    }
},

/**
Changes the value and status of the button attribute

@param id Button id
@param text Button label
@param attribute Button attribute
*/
setOperationParameter: function(id, text, attribute)
{
    document.getElementById(id).value = text; 
    document.getElementById(id).disabled = attribute;
},

/**
* Set or reset the checkbox
*/
setOrReset: function(articleNumber)
{               
   var articleCheckbox =  document.getElementById("articleCheckbox" + articleNumber);
   
   if( articleCheckbox!=null ) 
       articleCheckbox.status = !articleCheckbox.status;               
},

/**
Gets the articles of keywords from the server

@return personID Unique person id
*/
getArticleKeywordData: function(articleKeyword)
{
	var ajaxRequest = zXmlHttp.createRequest();
	
	showTopNotification();
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{
			    hideTopNotification();
				searchResults.renderJSONSearchResults(ajaxRequest.responseText, articleKeyword, 1);	//seachResults.js			
				/**
				Below paramter "totalArticleResultsFound" is populated by above function
				*/
				if ( totalArticleResultsFound != 0)
					initResultPages(totalArticleResultsFound, 10, articleKeyword, "keyword", articleKeyword);   //Pagination component initialization				
			}
			else
			{
				hideTopNotification();
				alert("Unable to get keyword search response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "search.action?searchType=keyword&searchString=" + articleKeyword, true);
	ajaxRequest.send(null);
	return false;
},

/**
Get the advanced search component as a HTML data
*/
getAdvancedSearch: function()
{
    var ajaxRequest = zXmlHttp.createRequest();	
	showTopNotification();
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
				hideTopNotification();
			   	components.penel.hideBanner();
				searchResults.renderAdvancedSearch(ajaxRequest.responseText);								
			} 
			else 
			{
				hideTopNotification();
                components.penel.hideBanner();
				alert("Unable to get response!: " + ajaxRequest.responseText);	
			}				
		}       
	}	
	ajaxRequest.open("GET", ROOT_URL + "html/global/advancedSearch.htm");	
	ajaxRequest.send(null);
},

/**
Renders and loads the advanced search component from the server

@param data Plain html data of top advanced search component
*/
renderAdvancedSearch: function(data)
{	
	var advancedSearchHTML = "";
	tempFlag = 0;
	
	if ( data.length > 0 )
	{	
		tempFlag = 1;		
		//advancedSearchHTML += "<DIV style='' class=searchResultPageTitle>Advanced Query<HR style='height: 1px'></DIV>";
	    advancedSearchHTML += data;
	}	
	if ( tempFlag == 0)	
	{
		document.getElementById("queryResultsDivId").innerHTML = "Unable to get advanced search feature!";	//If the content is empty, then no need to show its component
		return;															
	}			
	
	advancedSearchHTML += "<HR>";
	advancedSearchHTML += "<FONT CLASS=helpHeading>Tips</FONT>".bold();
	advancedSearchHTML += "<OL CLASS=helpText>";
	advancedSearchHTML += "<LI><B>Check your spelling</B>. Are the words in your query spelled correctly? </LI>";
	advancedSearchHTML += "<LI><B>Try using synonyms</B>. Maybe the document you're looking for uses slightly different words, like \"phone\" instead of \"telephone\". </LI>";
	advancedSearchHTML += "<LI><B>Make your query more general</B>. For example, instead of using specific subject names, try using the generic subject category</LI>";
	advancedSearchHTML += "</OL>";
	
	document.getElementById("queryResultsDivId").innerHTML = "<DIV style='' class=searchResultPageTitle>Advanced Query<HR style='height: 1px'></DIV>" + 
	components.getFormHTMLComponent("Advanced Search", advancedSearchHTML) + "<BR>";
	        
	searchResults.advancedSearchAddYears();     // Initialize the multiple date and keyword parameters
	searchResults.hideAllPanels();
	
	historyIsItResultDetails = 0;
	parityHistory.setInHistory();	
},

/**
Renders and loads the advanced search component from the server

@param data Plain html data of top advanced search component
*/
advancedSearchAddYears: function()
{
	var monthList = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var monthMaxDay = new Array("1/31","2","3/31","4/30","5/31","6/30","7/31","8/31","9/30","10/31","11/30","12/31");
	var monthMinDay = new Array("1/1","2/1","3/1","4/1","5/1","6/1","7/1","8/1","9/1","10/1","11/1","12/1");
	
	for(var i = new Date().getFullYear(); i > 1949; i--)
	{
		//document.all.advSrcDateFromYear.options[document.all.advSrcDateFromYear.options.length] = 		
		document.getElementById("advSrcDateFromYear").options[document.getElementById("advSrcDateFromYear").options.length] =
		new Option(i, i, false, false );
		
		//document.all.advSrcDateToYear.options[document.all.advSrcDateToYear.options.length] = 
		document.getElementById("advSrcDateToYear").options[document.getElementById("advSrcDateToYear").options.length] =
		new Option(i, i, false, false );		
	}
	
	for(var i = 0; i < 12; i++)
	{
		//document.all.advSrcDateFromMonth.options[document.all.advSrcDateFromMonth.options.length] = 
		document.getElementById("advSrcDateFromMonth").options[document.getElementById("advSrcDateFromMonth").options.length] =
		new Option(monthList[i], monthMinDay[i], false, false ); 
		
		//document.all.advSrcDateToMonth.options[document.all.advSrcDateToMonth.options.length] = 
		document.getElementById("advSrcDateToMonth").options[document.getElementById("advSrcDateToMonth").options.length] =
		new Option(monthList[i], monthMaxDay[i], false, false );				
	}		
},

/**
Prepares the advanced search query paramters and sends it to server for results
*/
advancedSearchPrepreQueryParamters: function()
{
    var type0 = document.getElementById("advSrcType1").options[document.getElementById("advSrcType1").selectedIndex].value;
	var query0 = document.getElementById("asKeyword1").value;
    
	var oper1 = document.getElementById("advSrcCondition1").options[document.getElementById("advSrcCondition1").selectedIndex].value;
	var type1 = document.getElementById("advSrcType2").options[document.getElementById("advSrcType2").selectedIndex].value;
	var query1 = document.getElementById("asKeyword2").value;

	var oper2 = document.getElementById("advSrcCondition2").options[document.getElementById("advSrcCondition2").selectedIndex].value;
	var type2 = document.getElementById("advSrcType3").options[document.getElementById("advSrcType3").selectedIndex].value;
	var query2 = document.getElementById("asKeyword3").value;

	var oper3 = document.getElementById("advSrcCondition3").options[document.getElementById("advSrcCondition3").selectedIndex].value;
	var type3 = document.getElementById("advSrcType4").options[document.getElementById("advSrcType4").selectedIndex].value;
	var query3 = document.getElementById("asKeyword4").value;

	var startMonth = document.getElementById("advSrcDateFromMonth").options[document.getElementById("advSrcDateFromMonth").selectedIndex].value;
	var startYear = document.getElementById("advSrcDateFromYear").options[document.getElementById("advSrcDateFromYear").selectedIndex].value.substring(2,4);

	var endMonth = document.getElementById("advSrcDateToMonth").options[document.getElementById("advSrcDateToMonth").selectedIndex].value;
	var endYear = document.getElementById("advSrcDateToYear").options[document.getElementById("advSrcDateToYear").selectedIndex].value.substring(2,4);
    //*/
	/* Leap Year Check */
	if (endMonth == '2' && eval(endYear % 4))
		endMonth = '2/28';
	else if(endMonth == '2')
		endMonth = '2/29';
	
	var stYear = document.getElementById("advSrcDateFromYear").options[document.getElementById("advSrcDateFromYear").selectedIndex].value;
	var edYear = document.getElementById("advSrcDateToYear").options[document.getElementById("advSrcDateToYear").selectedIndex].value;
	var yearDiff = stYear - edYear;	//alert("yeardate=" + date +"-" + stYear +"-" + edYear +"-"+ yearDiff);
	
	var stMonth = startMonth.split("/")[0];
	var edMonth = endMonth.split("/")[0];
	var monthDiff = stMonth - edMonth; //alert("yearmonth=" + date +"-" + stMonth +"-" + edMonth +"-"+ monthDiff);
	if ( yearDiff > 0 )
	{
	    alert("Please select the start date that is less than the end date value(Year)");
	    return ;
	}
	else if ( yearDiff == 0 &&  monthDiff > 0 )
	{
        alert("Please select the start date that is less than the end date value(Month)");
        return ;
	}
	
	var date = ' AND date:"' + startMonth + '/' + startYear + ', ' + endMonth + '/' + endYear + '"';
	
	/* Add " " around exact phrase and add lname: before author last name */
	if (type0 == 3 && query0 != "") 
		query0 = ('"'+query0+'"')
	else if (type0 == 4 && query0 != "") 
		query0 = ('lname:'+'"'+query0+'"');
	
	if (type1 == 3 && query1 != "") 
		query1 = ('"'+query1+'"')
	else if (type1 == 4 && query1 != "") 
		query1 = ('lname:'+'"'+query1+'"')
	
	if (type2 == 3 && query2 != "")
		query2 = ('"'+query2+'"')
	else if (type2 == 4 && query2 != "") 
		query2 = ('lname:'+'"'+query2+'"');
	
	if (type3 == 3 && query3 != "") 
		query3 = ('"'+query3+'"');
	else if (type3 == 4 && query3 != "") 
		query3 = ('lname:'+'"'+query3+'"');
	
	/* Don't display "AND, OR, but NOT" if textbox is empty  */
	if (query0 == "") 
		oper1 = "";
	if (query1 == "") 
		oper1 = "";
	if (query2 == "") 
		oper2 = "";
	if (query3 == "") 
		oper3 = "";
	
	if (query0 == "" && query1 == "") 
	{
		oper1 = "";
		oper2 = "";
	}
	if (query0 == "" && query1 == "" && query2 == "") 
	{
		oper1 = "";
		oper2 = "";
		oper3 = "";
	}
		
	//if (document.all.advSrcDateFromMonth.options[document.all.advSrcDateFromMonth.selectedIndex].text == 'Month' && advSrcDateFromYear.options[advSrcDateFromYear.selectedIndex].text == 'Year' && document.all.advSrcDateToMonth.options[document.all.advSrcDateToMonth.selectedIndex].text == 'Month' && document.all.advSrcDateToYear.options[document.all.advSrcDateToYear.selectedIndex].text == 'Year') 
	if (document.getElementById("advSrcDateFromMonth").options[document.getElementById("advSrcDateFromMonth").selectedIndex].text == 'Month' && advSrcDateFromYear.options[advSrcDateFromYear.selectedIndex].text == 'Year' && document.getElementById("advSrcDateToMonth").options[document.getElementById("advSrcDateToMonth").selectedIndex].text == 'Month' && document.getElementById("advSrcDateToYear").options[document.getElementById("advSrcDateToYear").selectedIndex].text == 'Year') 
		date = "";
	else if (query0 == "" && query1 == "" && query2 == "" && query3 == "") 
		date = 'date:"' + startMonth + '/' + startYear + ', ' + endMonth + '/' + endYear + '"';
	
	if (oper1 == " OR " && oper2 == " OR " && oper3 == " OR ") 
		queryString = query0 + oper1 + query1 + oper2 + query2 + oper3 + query3 + date;
	else if (oper1 == " OR " && oper2 != " OR " && oper3 == " OR ") 
		queryString = query0 + oper1 + "(" + query1 + oper2 + query2 + ")" + oper3 + query3 + date;
	else if (oper1 != " OR " && oper2 == " OR " && oper3 == " OR ") 
		queryString = query0 + oper1 + query1 + oper2 + query2 + oper3 + query3 + date;
	else if (oper1 == " OR " && oper2 != " OR " && oper3 != " OR " && query1 != "" && query2 != "") 
		queryString = query0 + oper1 + "(" + query1 + oper2 + query2 + oper3 + query3 + ")" + date;
	else if (oper2 == " OR " && query2 != "" && query3 != "") 
		queryString = query0 + oper1 + query1 + oper2 + "(" + query2 + oper3 + query3 + ")" + date;
	else (queryString = query0 + oper1 + query1 + oper2 + query2 + oper3 + query3 + date);
    
    searchResults.submitAdvancedSearch("keyword", queryString);    
},

/**
Submits the given keyword for search and gets the search results

@parameter searchType Seach type
@parameter queryParamters Advance query paramters, it contains set of keywords and range of dates
*/
submitAdvancedSearch: function(searchType, queryParamters)
{
    var searchString = "";	
    if ( validateTextField("asKeyword1,asKeyword2,asKeyword3,asKeyword4") == false )
    {
        alert("Please enter atleast one keyword/phrase/author");            
        return ;   
    }    
	var ajaxRequest = zXmlHttp.createRequest();
	
	document.getElementById("keywordSearchId").value = queryParamters;
	document.getElementById("keywordSearchId").style.color = "black";
			    
	showTopNotification();
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
		    if (ajaxRequest.status == 200)
			{		
			    hideTopNotification();
			    global.variables.recentSearchType = "keywordSearch";
			    global.setSaveSearchParams(queryParamters, global.variables.recentSearchType);
				
		        var flag = searchResults.renderJSONSearchResults(ajaxRequest.responseText, queryParamters, 1);	//seachResults.js			
			    if ( flag == false )
    		    {
    		        return false;   // Do nothing when no results
    		    }
			    /**
		         Below paramter "totalArticleResultsFound" is populated by above function
		         */
		        if ( totalArticleResultsFound != 0)
                    initResultPages(totalArticleResultsFound, 10, queryParamters, "keyword", queryParamters);   //Pagination component initialization
                
                historyIsItResultDetails = 1;
	            parityHistory.setInHistory();
	            
	            latestSearchResultFunCall = "submitKeywordSearch('" + unescape(queryParamters) + "','keyword')";
			}
			else
			{
				alert("Unable to get keyword search response. Please try again!"); 
			}
		} 
	}
	//alert("url=" + ROOT_DB_URL + "search.action?searchType=" + searchType + "&searchString=" + escape(queryParamters) + "&nodeLabel=" + queryParamters);
	ajaxRequest.open("GET", ROOT_DB_URL + "search.action?searchType=" + searchType + "&searchString=" + escape(queryParamters) + "&nodeLabel=" + escape(queryParamters) + ((loginStatus == false) ? "" : "&nullParam=" + new Date()), true);
	ajaxRequest.send(null);
	return false;
},

/**
Clears or empty the search results
*/
emptySearchResults: function()
{
	document.getElementById("queryResultsDivId").innerHTML = "";
	
	searchResults.hideSearchResultsBorder();	
	hidePagination();
	
	searchResults.emptySearchResultsDetails();		
},

/**
Hides the search results border
*/
hideSearchResultsBorder: function()
{
	document.getElementById("queryResultsDivId").style.borderColor = "white";				
	document.getElementById("queryResultsDivId").style.marginBottom = "0px";		
	searchResults.hideSearchResultsDetailsBorder();
},

/**
Show the search results border
*/
showSearchResultsBorder: function()
{
	document.getElementById("queryResultsDivId").style.borderColor = "silver";			
	document.getElementById("queryResultsDivId").style.marginBottom = "5px";					
},

/**
Clears or empty the search results
*/
emptySearchResultsDetails: function()
{
	document.getElementById("queryResultDetailsDivId").innerHTML = "";			
	searchResults.hideSearchResultsDetailsBorder();
	//printer.hidePrinterPageLink();	
},

/**
Hide the search result details border
*/
hideSearchResultsDetailsBorder: function()
{
    document.getElementById("queryResultDetailsDivId").style.borderColor = "white";
	document.getElementById("queryResultDetailsDivId").style.marginBottom = "0px";		
},

/**
Show the search result details border
*/
showSearchResultsDetailsBorder: function()
{
	document.getElementById("queryResultDetailsDivId").style.borderColor = "silver";	
	document.getElementById("queryResultDetailsDivId").style.marginBottom = "5px";	
	printer.showPrinterPageLink();
},

/**
Get PDF fulltext of an article

@parameter id Article id
*/
getFullText: function(id, type)
{
	if ( loginStatus == false )
	{
	    //alert("Please login to access shopping cart!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Article can be downloaded only by ComSoc Members.<BR><BR>";  	
	    tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + id + "> Login</A><BR>";  	
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	    return;	 
	}
    //window.open(ROOT_DB_URL + "forwarddata.action?" + type +"eid=" + id); 
    searchResults.getFullTextFile(("eid=" + id), type);
    return false;
},

/**
Get PDF fulltext of an article

@parameter id Article id
*/
getFullTextFile: function(id, type, articleType)
{
	var ajaxRequest = zXmlHttp.createRequest();
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{
			    var docURL = "", docObj;
				try
	            {
		            docObj = eval('(' + ajaxRequest.responseText + ')');
		            if ( docObj != null && docObj.response.path != null &&  docObj.response.path != "" ) 
		            {
		            	if( articleType == "tutorial" || id.substring(0,3) == "url")
		                   window.location.href=(ROOT_DB_URL + "documentDownloader" + docObj.response.path);		                  		                
		                else
		                   window.open(ROOT_DB_URL + "documentDownloader" + docObj.response.path,"downloadWindow","width=800, height=600, menubar=1, resizable=1");		                
		         	}
	            }
	            catch(e)
	            {
		            alert("Unable to download file\n\n" + e.description); 		            
	            }				
			}
			else
			{
				alert("Unable to get response! " + ajaxRequest.responseText);	
			}
		}
	}
	if ( articleType == "tutorial" )
	    ajaxRequest.open("GET", ROOT_URL + "forwardcontrolleddata.action?"+ id + "&null=" + new Date(), true);	
	else if( id.substring(0,3) == "url" )
	    ajaxRequest.open("GET", ROOT_URL + "forwardcontrolleddata.action?"+ id + "&null=" + new Date(), true);
	else
	    ajaxRequest.open("GET", ROOT_URL + "forwardcontrolleddata.action?type=" + type +"&"+ id + "&null=" + new Date(), true);	
	ajaxRequest.send(null);
	return false;
},

/**
Save search
*/
saveSearch: function(itemRef, itemType, itemLabel)
{
    if ( historyCurrentIndex < (historyObject.length - 1) )
    {
        /* In history */
        searchResults.saveHistoryItem(itemRef, itemType, itemLabel);        
    }
    else
    {
        /* Not in history */
        itemRef += "";  //It doesn't have any extra query parameter
        searchResults.saveItem(itemRef, itemType, itemLabel);
    }        
},

/**
Save search
*/
saveArticle: function(itemRef, itemType)
{
    searchResults.saveItem(itemRef, itemType);
},

/**
Save author
*/
saveAuthor: function(itemRef, itemType)
{
	searchResults.saveItem(itemRef, itemType);
},

/**
Save publication
*/
savePublication: function(itemRef, itemType, itemLabel)
{
    if ( historyCurrentIndex < (historyObject.length - 1) )
    {
        /* In history */
        searchResults.saveHistoryItem(itemRef, itemType, itemLabel);        
    }
    else
    {
        /* Not in history */
        itemRef += "&label=" + escape(itemLabel);   //It is for the extra parameter "label"
        searchResults.saveItem(itemRef, itemType, itemLabel);
    } 
    //searchResults.saveHistoryItem(itemRef, itemType, itemLabel); //Working
},

/**
Save subject
*/
saveSubject: function(itemRef, itemType, itemLabel)
{
    if ( historyCurrentIndex < (historyObject.length - 1) )
    {
        /* In history */
        searchResults.saveHistoryItem(itemRef, itemType, itemLabel);        
    }
    else
    {
        /* Not in history */
        itemRef += "&term=" + escape(itemLabel);   //It is for the extra parameter "label"
        searchResults.saveItem(itemRef, itemType, itemLabel);
    } 
    //searchResults.saveHistoryItem(itemRef, itemType, itemLabel); //Working
},

/**
Save subject
*/
saveHistoryItem: function(itemRef, itemType, itemLabel)
{
    var ajaxRequest = zXmlHttp.createRequest();
	showTopNotification();
	ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {	
			    hideTopNotification();
			    try
                {
                    var articleObject = eval('(' + ajaxRequest.responseText + ')');
                }
                catch(e)
                {
                    alert("Unable to save item\n\n" + e.description);
                    return false;
                }
                if ( articleObject.searchResult != null)
                {
                    if ( itemType == "ontologySubject" )
                    {
                        latestSearchResultFunCall = "treeSub.getNodeArticles('" + itemRef + "','" + itemLabel + "')";
                        itemRef += "&term=" + escape(itemLabel);
                    }
                    else if ( itemType == "ontologyPublication" )
                    {
                        latestSearchResultFunCall = "treePub.pubGetNodeArticles('" + itemRef + "','" + itemLabel + "')";
                        itemRef += "&label=" + escape(itemLabel);
                    }
                    else if ( itemType == "keywordSearch" )
                    {
                        latestSearchResultFunCall = "submitKeywordSearch('" + itemRef + "','keyword')";
                        itemRef += "";                        
                    }
                    else if ( itemType == "authorSearch" )
                    {
                        latestSearchResultFunCall = "submitKeywordSearch('" + itemRef + "','author')";
                        //itemRef += "&label=" + escape(itemLabel);
                    }
                    searchResults.saveItem(itemRef, itemType);
    		        return false;   // Do nothing when no results
                }   
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('subTreeNote');
			    alert("Unable to save item"); 
		    }
	    }
    }
    if ( itemType == "keywordSearch" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?searchType=keyword&searchString=" + itemRef + "&nodeLabel=" + itemRef + ((loginStatus == false) ? "" : "&nullParam=" + new Date()), true);
    else if ( itemType == "authorSearch" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?searchType=keyword&searchString=" + itemRef + "&nodeLabel=" + itemRef + ((loginStatus == false) ? "" : "&nullParam=" + new Date()), true);
    else if ( itemType == "ontologySubject" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?nodeID=" + itemRef + "&nodeLabel=" + escape(itemLabel) + "&ontologyType=subjects&nullParam=" + new Date(), true);
    else if ( itemType == "ontologyPublication" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?nodeID=" + itemRef + "&nodeLabel=" + escape(itemLabel) + "&ontologyType=publication&nullParam=" + new Date(), true);	//Struts class source
    ajaxRequest.send(null);
},

/**
Save item

@parameter itemRef Id of the item, that can be a article, author or keyword search
@parameter itemType Type of the search
*/
saveItem: function(itemRef, itemType)
{   
    var ajaxRequest = zXmlHttp.createRequest();	
    var targetURL = ROOT_DB_URL;
    showTopNotification();
	
    if ( itemType == "article" )
        targetURL += "setfavorite.action?addFavoriteArticle=true&articleID=" + itemRef;
    else if ( itemType == "author" )
        targetURL += "setfavorite.action?addFavoritePerson=true&authorID=" + itemRef;
    else
        targetURL += "setfavorite.action?saveSearch=true";
    
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
	            searchResults.renderSaveItemResults(ajaxRequest.responseText, itemType, itemRef);
			}
			else
			{	
				alert("Save " + itemType + " - Unable to get response!: " + ajaxRequest.responseText);	
			}
		}
	}
	ajaxRequest.open("GET", targetURL + "&nullParam=" + new Date(), true);		
	ajaxRequest.send(null);
},

/**
Render saved item results

@parameter saveResponse Status or response of the saved item
*/
renderSaveItemResults: function(saveResponse, saveType, saveRef)
{
	var saveItemData = null;
	/* New code - begin */
	        
	try
    {
        saveItemData = eval('(' + saveResponse + ')');		    
    }
    catch(e)
    {
	    alert("Unable to save item!\n\n" + e.description); 
	    return false;
    }
	
	saveResponse = saveItemData.userFavorite.statusMessage;
	/* New code - end */
	if ( saveResponse.toLowerCase() == "success")
	{
	    document.getElementById("saveSearchId").disabled = "disable";
	    alert("Item saved successfully!");		    
    
	    if ( saveType== "article" )
            searchResults.getArticleData(saveRef);
        else if ( saveType== "author" )
            searchResults.getAuthorData(saveRef);
        else
            //targetURL += "setfavorite.action?saveSearch=true"; */
            /* !!! Below line of code executes the most recent function call of search results */
		    eval( latestSearchResultFunCall );
		    
		if ( saveType == "ontologySubject" )
		    treeSub.getSubTreeInitData();   // To refresh the tree automatically after saving subject into MyComSoc
	    else if ( saveType == "ontologyPublication" )
	        treePub.getPubTreeInitData();   //  " " 
	}
	else
	{
	    //alert("Unable to save item: " + saveItemData.userFavorite.statusMessage);
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    //tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif /> Please login to save the item.<BR><BR>";
	    //tempData += "If you are a ComSoc member please";
	    tempData += "<IMG src=" + ROOT_URL + "images/alertAttention.gif />";
	    tempData += " Please ";
	    
	    if ( saveType== "article" )
	        tempData += "<A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&article=" + saveRef + ">LOGIN</A>";
	    else if ( saveType== "author" )
            tempData += "<A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&author=" + saveRef + ">LOGIN</A>";
        else
        {
            if ( saveSearchType == "ontologySubject" )
                tempData += "<A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&subject=" + saveRef + ">LOGIN</A>";
            else if ( saveSearchType == "ontologyPublication" )
                tempData += "<A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&publication=" + saveRef + ">LOGIN</A>";
            else if ( saveSearchType == "keywordSearch" )
                tempData += "<A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&keyword=" + escape(saveRef) + ">LOGIN</A>";
            else if ( saveSearchType == "authorSearch" )
                tempData += "<A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&keyword=" + escape(saveRef) + "&type=author>LOGIN</A>";
            //authorSuggestionHTML += "<A class=searchResultItem href=?keyword=" + param + "&type=author onclick=\"return submitKeywordSearch('" + param +"','author')\">";            
        }    
            tempData += " with your IEEE Web Account<BR>";
        
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	}
},

/**
Create filter
*/
manageFilter: function(itemRef, itemType, itemLabel)
{
    if ( historyCurrentIndex < (historyObject.length - 1) )
    {
        /* In history */
        searchResults.createHistoryFilter(itemRef, itemType, itemLabel);
        isSearchInHistory = true;
    }
    else if ( historyCurrentIndex == (historyObject.length - 1) && isSearchInHistory == true)
    {
        /* In history */
        searchResults.createHistoryFilter(itemRef, itemType, itemLabel);
        isSearchInHistory = false;
    }
    else
    {
        /* Not in history */
        searchResults.createFilter();        
    } 
    //searchResults.createFilter();
},

/**
Save subject
*/
createHistoryFilter: function(itemRef, itemType, itemLabel)
{
    var ajaxRequest = zXmlHttp.createRequest();
	showTopNotification();
	
	ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {	
			    hideTopNotification();
			    try
                {
                    var articleObject = eval('(' + ajaxRequest.responseText + ')');
                }
                catch(e)
                {
                    alert("Unable to save item\n\n" + e.description);
                    return false;
                }
                if ( articleObject.searchResult != null)
                {
                    if ( itemType == "ontologySubject" )
                    {
                        latestSearchResultFunCall = "treeSub.getNodeArticles('" + itemRef + "','" + itemLabel + "')";
                        itemRef += "&term=" + escape(itemLabel);
                    }
                    else if ( itemType == "ontologyPublication" )
                    {
                        latestSearchResultFunCall = "treePub.pubGetNodeArticles('" + itemRef + "','" + itemLabel + "')";
                        itemRef += "&label=" + escape(itemLabel);
                    }
                    else if ( itemType == "keywordSearch" )
                    {
                        latestSearchResultFunCall = "submitKeywordSearch('" + itemRef + "','keyword')";
                        itemRef += "";                        
                    }
                    else if ( itemType == "authorSearch" )
                    {
                        latestSearchResultFunCall = "submitKeywordSearch('" + itemRef + "','author')";
                        //itemRef += "&label=" + escape(itemLabel);
                    }
                    searchResults.createFilter();
    		        return false;   // Do nothing when no results
                }   
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('subTreeNote');
			    alert("Unable to save item"); 
		    }
	    }
    }
    if ( itemType == "keywordSearch" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?searchType=keyword&searchString=" + itemRef + "&nodeLabel=" + itemRef + "&nullParam=" + new Date(), true);
    else if ( itemType == "authorSearch" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?searchType=keyword&searchString=" + itemRef + "&nodeLabel=" + itemRef + "&nullParam=" + new Date(), true);
    else if ( itemType == "ontologySubject" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?nodeID=" + itemRef + "&nodeLabel=" + escape(itemLabel) + "&ontologyType=subjects&nullParam=" + new Date(), true);
    else if ( itemType == "ontologyPublication" )
        ajaxRequest.open("GET", ROOT_DB_URL + "search.action?nodeID=" + itemRef + "&nodeLabel=" + escape(itemLabel) + "&ontologyType=publication&nullParam=" + new Date(), true);	//Struts class source
    ajaxRequest.send(null);
},

/**
Create filter
*/
createFilter: function()
{
    var ajaxRequest = zXmlHttp.createRequest();
    showTopNotification();
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
			    //alert("history=" + ajaxRequest.responseText);
				searchResults.renderCreatedFilter(ajaxRequest.responseText);
			}
			else
			{	
			    hideTopNotification();  /* Do nothing if unable to create filters*/
				//alert("createFilter - Unable to get response!: " + ajaxRequest.responseText);
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "handlefilter.action?add=true&clear=false&nullParam=" + new Date(), true);		
	ajaxRequest.send(null);
},

/**
Get the filter data, mainly after refresh or new login
*/
getFilter: function()
{
    var ajaxRequest = zXmlHttp.createRequest();    
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)   
			{
				searchResults.renderCreatedFilter(ajaxRequest.responseText);
			}
			else
			{	/* Do nothing if unable to get filters*/			
				//alert("GetFilter - Unable to get response!: " + ajaxRequest.responseText);
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "handlefilter.action?nullParam=" + new Date(), true);		
	ajaxRequest.send(null);
},

/**
Render create filter data

@parameter jsonData Response of the created filter
*/
renderCreatedFilter: function(jsonData)
{   
    var createFilterData = null;
	var filterData = "";
	
	try
	{
	    createFilterData = eval('(' + jsonData + ')');
	}
	catch(e)
	{
	    alert("createFilter - Unable to get response!: ");
		return false;
	}
    
    for( i = 0; i < createFilterData.filterResponse.length; i++)
	{
	    if ( createFilterData.filterResponse[i].applied == true ) 
	        filterData += "<INPUT id=chk" + i +" type=checkbox checked onclick='searchResults.applyFilter(" + createFilterData.filterResponse.length +")'>"
	    else
	        filterData += "<INPUT id=chk" + i +" type=checkbox onclick='searchResults.applyFilter(" + createFilterData.filterResponse.length +")'>"
	    
	    if ( createFilterData.filterResponse[i].filterType == "search" ) 
	        filterData += "<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-search.gif width=15px> ";
	    else if ( createFilterData.filterResponse[i].filterType == "author" ) 
	        filterData += "<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-authors.gif width=15px> ";
	    else if ( createFilterData.filterResponse[i].filterType == "publication" ) 
	        filterData += "<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-publications.gif width=15px> ";
	    else if ( createFilterData.filterResponse[i].filterType == "subjects" ) 
	        filterData += "<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-subjects.gif width=15px> ";
	    
	    filterData += createFilterData.filterResponse[i].filterName.fontcolor("FIREBRICK") + "<BR>"	    
	}
	
	if ( filterData == "" ) return;
	
	filterData = "Filters".bold() + "<BR>" + filterData + "<DIV align=right><INPUT type=button value='Clear Filter' " + getButtonClass() +" onclick='searchResults.clearFilter()'></DIV>";
	document.getElementById("filterDiv").innerHTML = filterData;
	document.getElementById("filterDiv").style.display = "";
},

/**
Clear filter
*/
clearFilter: function()
{
    if ( confirmAlert("Do you want to clear filters?\n\nClick OK to clear") == false )  return;
    
	var ajaxRequest = zXmlHttp.createRequest();
	showTopNotification();
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
				searchResults.renderClearFilter(ajaxRequest.responseText);
			}
			else
			{	
			    hideTopNotification();
				alert("clearFilter - Unable to get response!: " + ajaxRequest.responseText);
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "handlefilter.action?add=flase&clear=true&nullParam=" + new Date());		
	ajaxRequest.send(null);
},

/**
Render create filter data

@parameter jsonData Response of the cleared filter
*/
renderClearFilter: function(jsonData)
{   
    var clearFilterData = null;
	var filterData = "";
	try
	{
	    clearFilterData = eval('(' + jsonData + ')');
	}
	catch(e)
	{
	    alert("renderClearFilter - Unable to clear filters!");
		return false;
	}
	if (clearFilterData.add == "flase")
	{
        document.getElementById("filterDiv").innerHTML = "";    	
        document.getElementById("filterDiv").style.display = "none";
    }
},

/**
Clear filter

@parameter countOfFilters Response of the applied filter
*/
applyFilter: function(countOfFilters)
{    
    var filterParamters = "";
    var ajaxRequest = zXmlHttp.createRequest();	
	showTopNotification();
	for( var i = 0; i < countOfFilters; i++)
	{
	    //alert("status= " + document.getElementById("chk" + i).checked);
	    if ( document.getElementById("chk" + i).checked == true )    //IE=status & checked, but Safari=checked
	        filterParamters += "chk" + i + "=on&apply" + i + "=true&";
	    else
	        filterParamters += "apply" + i + "=false&";
	}
	filterParamters += "add=false&clear=false";
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
				//alert("ajaxRequest.responseText - " + ajaxRequest.responseText);		
			}
			else
			{	
			    hideTopNotification();
				alert("Apply filter - Unable to get response!: " + ajaxRequest.responseText);	
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "handlefilter.action?" + filterParamters +"&nullParam=" + new Date(), true);
	ajaxRequest.send(null);	
},

/**
Set font size for search result page

@parameter startRecordNo Starting number of record
@parameter userFontSize Ending number of record
*/
setSearchResultPageFontSize: function(startRecordNo, userFontSize)
{
    var artNo;
	var newFontSize = searchResults.getFontSize(userFontSize);
	
	for( var i = 0; i < 10; i++)
	{
	    artNo = ((startRecordNo-1)*10 + (i%10)+1);
	    document.getElementById("searchDetailsLeft" + startRecordNo).style.fontSize = newFontSize + "px";	
	    document.getElementById("searchDetailsRight" + startRecordNo).style.fontSize = newFontSize + "px";	
	    document.getElementById("sortByOptions").style.fontSize = newFontSize + "px";	
	    
	    if ( document.getElementById("articleNo" + artNo) != null)
	        document.getElementById("articleNo" + artNo).style.fontSize = (newFontSize + "px");
	}   
},

/**
Set font size for author page
*/
setArticlePageFontSize: function(articleDetailsId, userFontSize)
{       
    var newFontSize = searchResults.getFontSize(userFontSize);
    
    if ( document.getElementById("artilceSummaryPagePrice") )
        document.getElementById("artilceSummaryPagePrice").style.fontSize = (newFontSize + "px");
    
    if ( document.getElementById("artilceSummaryTitle") )
        document.getElementById("artilceSummaryTitle").style.fontSize = (newFontSize + "px");
    
    //if ( document.getElementById("" + articleDetailsId) )
        document.getElementById("" + articleDetailsId).style.fontSize = (newFontSize + "px");  
},

/**
Set font size for author page
*/
setAuthorPageFontSize: function(authorDetailsId, userFontSize)
{
    var newFontSize = searchResults.getFontSize(userFontSize);
    if ( document.getElementById("" + authorDetailsId) )
        document.getElementById("" + authorDetailsId).style.fontSize = (newFontSize + "px");
},

/**
Set the user font size
*/
getFontSize: function(userFontSize)
{
    var newFontSize = "12"; // Default
    
    if ( userFontSize == null )
        return newFontSize;  //Default
    
    if ( userFontSize == "small")           //Small
	    newFontSize = 10;
	else if ( userFontSize == "medium")     //Medium
	    newFontSize = 12;
	else if ( userFontSize == "large")      //Large 
	    newFontSize = 14;
	else if ( userFontSize == "xlarge")     //X-Large 
	    newFontSize = 16;   
	
	return newFontSize;
},

/**
Set search result sort type
*/
setSortByType: function(sortType, executeImmediateFlag)
{
    if ( sortType == "relevance" )
    {
        global.variables.sortSearchBy = "relevance";
        document.getElementById("sortByOption").innerHTML = " Relevance | <A style='color: blue' href=# onclick=searchResults.setSortByType('date','1')>Date</A>";        
    }
    else
    {
        global.variables.sortSearchBy = "date";
        document.getElementById("sortByOption").innerHTML = " <A href=# style='color: blue' onclick=searchResults.setSortByType('relevance','1')>Relevance</A> | Date";           
    }    
    
    /* !!! Below line of code executes the most recent function call of search results BY SETTING the sort options */
    if ( executeImmediateFlag == 1 && latestSearchResultFunCall != "" )
	{
	    /* IMPORTANT!!! */
	    eval(recentPaginationInitCall);     //It re-initializes the pagination component
	    eval( "getResultPage('p_1_10')" );  //It gets the first page after initialization  -
	                                        //usually it happens after clicking on first page 
	                                        //thumbnails, but here it needs to be called or 
	                                        //open first page AFTER clicking on sort order immediately.
	}	    
},

/**
Get the search result sort type
*/
getSortByType: function()
{
    if ( global.variables.sortSearchBy == "relevance" )
        return "";  // !!IMPORTANT - By default the search results are sorted by relevance, so it does not require any extra parameter to define its sort type
    else
        return "&sortBy=date";
},

/**
Show the printer page link
*/
showSortByOptions: function()
{
	//document.getElementById("sortOptionsId").style.display = '';	
},

/**
Show the printer page link
*/
hideSortByOptions: function()
{
    //document.getElementById("sortOptionsId").style.display = "none";	
},

/**
Hide all external panels and show only seach results or query page ONLY
*/
hideAllPanels: function()
{
    hidePagination();
	searchResults.emptySearchResultsDetails();
	searchResults.showSearchResultsBorder();
	
	components.penel.hideTopArticle();
	components.penel.hideMonthIssues();  
	components.penel.hideCurrentIssues();	
	components.penel.hideAds();	
}
}
