/**
 * User and personal features javascript module
 * 
 * @author Veeresh D.
 * @date March 2008
 */

var loginStatusFlag = 0;	//It forms a default behavior of login to indicate user about unsuccessful authentication
var autoOpenFavorites = false;	//It is required to open MyComSoc's MyFavourite items automatically after it gets update
var downloadAllTimer, downloadWindowObject;
var articleNosArray = new Array();
var checkoutCartParam = "";

var access =
{
	/**
	Gets the static login html content from server and loads into dialog form component
    
	@param uriName URL address of the static html content file
	@param title Title name of the dialog form component
	@param dWidth Width of the dialog form component
	@param dHeight Height of the dialog form component
	@param dLeft Left of the dialog form component
	@param dTop Top of the dialog form component
	*/
	getLoginPageHTML: function(uriName, title, dWidth, dHeight, dLeft, dTop)
	{
		var ajaxRequest = zXmlHttp.createRequest();
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				if (ajaxRequest.status == 200)
				{
					components.showDialogBox(ajaxRequest.responseText, title, dWidth, dHeight, dLeft, dTop);					
				}
				else
				{
					alert("Unable to get response!: " + ajaxRequest.responseText);	
				}
			}
		}
		ajaxRequest.open("GET", ROOT_URL + "html/global/" + uriName);	
		ajaxRequest.send(null);			
	},
	
	/**
	Login User function does user authentication.   
	This function will hit the server and returns either 0 or 1 based on authentication
	*/
	authenticateUser: function()
	{
		if( document.getElementById("loginId").innerHTML == "Login")
		{
		    /*
			Below function indirectly calls loginUser() method that comes with 
			login form, from that place another Login button is located for 
			reading user information and calling loginUser() for authentication
			*/
			if ( getBrowserName() == "Safari" || getBrowserName() == "Mozilla"  || getBrowserName() == "Firefox" )
			    access.getLoginPageHTML('loginPageHTML.htm','ComSoc Login','50%','50%','200px','130px');	
			else
			    access.getLoginPageHTML('loginPageHTML.htm','ComSoc Login','700','500px','200px','130px');				
		}
		else
			access.logoutUser();
	},
	
	/**
	Login User function does user authentication.  
	This function will hit the server and returns either 0 or 1 based on authentication
	*/
	checkLoginUserStatus: function()
	{
	    var ajaxRequest = zXmlHttp.createRequest();		    
	    ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				if (ajaxRequest.status == 200)
				{
				    loginStatusFlag = ajaxRequest.responseText;
					access.renderCheckLoginUserStatus(ajaxRequest.responseText);							
				} 		
			} 
		}	
		ajaxRequest.open("GET", ROOT_DB_URL + "drmaction.action?path=GetLoginStatus&nullParam=" + new Date(), true);
		//ajaxRequest.open("GET", ROOT_DB_URL + "DRM-drmaction.action?path=GetLoginStatus&nullParam=" + new Date(), true);
		ajaxRequest.send(null);				
	},
	
	loadFavorites: function()
	{
	    var ajaxRequest = zXmlHttp.createRequest();		    
	    ajaxRequest.open("GET", ROOT_DB_URL + "removefavorite.action?nullParam=" + new Date(), true);
	   	ajaxRequest.send(null);				
	},

	/**
	Login User function does user authentication.  
	This function will hit the server and returns either 0 or 1 based on authentication
	*/
	callFunctionAfterLogin: function(functionString)
	{
	    var ajaxRequest = zXmlHttp.createRequest();		    
	    ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				if (ajaxRequest.status == 200)
				{
				    loginStatusFlag = ajaxRequest.responseText;
					access.rendercallFunctionAfterLogin(ajaxRequest.responseText, functionString);							
				} 		
			} 
		}	
		ajaxRequest.open("GET", ROOT_DB_URL + "drmaction.action?path=GetLoginStatus&nullParam=" + new Date(), true);
		//ajaxRequest.open("GET", ROOT_DB_URL + "DRM-drmaction.action?path=GetLoginStatus&nullParam=" + new Date(), true);
		ajaxRequest.send(null);				
	},
		
    /**
	This function does necessary rendering after successful login operation
	*/
	rendercallFunctionAfterLogin: function(loginJSONObject, functionString)
	{	    	
	    try
	    {
		    var loginObject = eval('(' + loginJSONObject + ')');
	    }
	    catch(e)
	    {
		    loginStatus = false;
		    alert("Unable to parse authentication data!\n\n" + e.description); 
		    return false;
	    }
	    if( loginObject.response.ALoginResponseDAO.status == true )
		{
		    loginStatus = true;
		}
		else
		{
		    loginStatus = false;
		    //  !!!IMPORTANT - If the user had already logged in before refresh, so it should nothing.		    
		}		
		if ( functionString )
	    {
	        eval(functionString);
	    }
	},
	
	/**
	This function does necessary rendering after successful login operation
	*/
	renderCheckLoginUserStatus: function(loginJSONObject)
	{	    	    
	    try
	    {
		    var loginObject = eval('(' + loginJSONObject + ')');
	    }
	    catch(e)
	    {
		    loginStatus = false;
		    alert("Unable to parse authentication data!\n\n" + e.description); 
		    return false;
	    }
	    if( loginObject.response.ALoginResponseDAO.status == true )
		{
		    loginStatus = true;
		    
		    /* !!! To refresh the tree automatically after saving subject into MyComSoc */
		    treeSub.getSubTreeInitData();
		    treePub.getPubTreeInitData();
		    
		    document.getElementById("loginId").innerHTML = "Logout";
		    access.loadFavorites();
		    document.getElementById("loginId").href = "/comsocdl/DRM-authentication.action?path=LogoffUser";
		    document.getElementById("loginUserName").innerHTML  = "Welcome <B>" + loginObject.response.ALoginResponseDAO.userName.fontcolor("white") + "</B>, ";
		    access.myComSoc.setLoginFontsize(); //To update the user preferred font size		    
		}
		else
		{
		    //alert('veresh=' + callAfterCallLogin);	
	        loginStatus = false;
		    //  !!!IMPORTANT - If the user had already logged in before refresh, so it should nothing.		    
		}	
		if ( callAfterCallLogin )
	    {
	        eval(callAfterCallLogin);
	        callAfterCallLogin = "";
	    }
	},
	
	/**
	Login User function does user authentication.  
	This function will hit the server and returns either 0 or 1 based on authentication
	*/
	loginUser: function()
	{
		var ajaxRequest = zXmlHttp.createRequest();	
		/*
		if ( Number(document.getElementById("loginName").value.length) <= 0 || Number(document.getElementById("loginPassword").value.length) <= 0)
	    {
		    alert("Please fill the user information!");
		    return;
	    }
	    */
		document.getElementById("loginStatusInfo").style.display = ""; 	//To refresh login status information
		document.getElementById("loginStatusInfo").innerHTML = "<IMG src='images/progress-icon-indicator.gif'>&nbsp;<B>Authentication in progress... <B>".fontcolor("green"); 			//To refresh login status information
		document.getElementById("loginUserName").innerHTML = "";			//Irrespective of response, the user name must not appear
		//document.getElementById("loginPassword").innerHTML = "";			//Irrespective of response, the user password must not appear
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				if (ajaxRequest.status == 200)
				{
					loginStatusFlag = ajaxRequest.responseText;
					access.doAfterLogin(ajaxRequest.responseText);							
				} 
				else
				{	
					/*
					This function have to be called when server unable to response
					for authentication, then it uses default value 0 as logout status.
					Ultimately, it indicates the failed status of authentication
					*/ 
					access.doAfterLogin();			
				}					
			} 
		}
		//ajaxRequest.open("GET", "/ajaxLogin/checklogin.jsp?name=" + document.all.loginName.value + "&password=" + document.all.loginPassword.value);
		ajaxRequest.open("GET", ROOT_DB_URL + "drmaction.action?path=LoginUser&cid=90218991&nullParam=" + new Date(), true);
		//ajaxRequest.open("GET", ROOT_DB_URL + "drmaction.action?path=LoginUser&cid=90218991&nullParam=" + new Date(), true);
		ajaxRequest.send(null);				
	},
	
	/**
	Login User function does user authentication.   
	This function will hit the server and returns either 0 or 1 based on authentication
	*/
	logoutUser: function()
	{
		var ajaxRequest = zXmlHttp.createRequest();	
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				if (ajaxRequest.status == 200)
				{
					loginStatusFlag = ajaxRequest.responseText;
					access.doAfterLogout(ajaxRequest.responseText);									
				} 
				else 
				{	
					access.doAfterLogout();
				}
			}
		}
		//ajaxRequest.open("GET", "/ajaxLogin/checklogin.jsp?name=admin&password=password");
		ajaxRequest.open("GET", ROOT_DB_URL + "drmaction.action?path=LogoffUser&nullParam=" + new Date(), true);
		ajaxRequest.send(null);			
	},
	
	/**
	This function does necessary rendering after successful login operation
	*/
	doAfterLogin: function(loginJSONObject)
	{
	    try
	    {
		    var loginObject = eval('(' + loginJSONObject + ')');
		    if ( loginObject.response == null )
		        throw "Login exception";
	    }
	    catch(e)
	    {
	        loginStatus = false;
	        document.getElementById("loginStatusInfo").innerHTML = "Server is either down or busy. Try again!";		
			alert("Unable to parse authentication data!\n\n" + loginJSONObject); 
		    return false;
	    }
	    
		if( loginObject.response.ALoginResponseDAO.status == true )
		{
		    loginStatus = true;
		    
		    //global.variables.myComSocUserFont = "large"; //loginObject.response.fontSize
		    
		    document.getElementById("loginId").innerHTML = "Logout";
		    document.getElementById("loginUserName").innerHTML  = "Welcome to <B>" + loginObject.response.ALoginResponseDAO.userName.fontcolor("white") + "</B>, ";
		    /* !!! To refresh the tree automatically after saving subject into MyComSoc */
		    treeSub.getSubTreeInitData();
		    treePub.getPubTreeInitData();
		    
		    /* !!! Below line of code executes the most recent function call of search results */
		    eval( latestSearchResultFunCall );
		    
		    components.closeDialogBox();
		}
		else
		{
		    loginStatus = false;
		    document.getElementById("loginName").value = "";		//Reset input user name text field
			document.getElementById("loginPassword").value = "";	//Reset input user password text field		
			document.getElementById("loginStatusInfo").innerHTML = "[ Invalid user name or password, please try again ]"; 
			document.getElementById("loginStatusInfo").style.display = '';		
			alert("No login response found!\n\n" + loginObject.response.ALoginResponseDAO.statusMessage);			
		}
		access.myComSoc.setLoginFontsize(); //To update the user preferred font size
	},
	
	/**
	This function does necessary rendering after successful logout operation
	*/
	doAfterLogout: function(logoutJSONObject)
	{
	    try
	    {
		    var logoutObject = eval('(' + logoutJSONObject + ')');
	    }
	    catch(e)
	    {
		    alert("Unable to parse authentication data!\n\n" + e.description); 
		    return false;
	    }	    
		if(logoutObject != null || logoutObject.response != null )
		{
			loginStatusFlag = 0;
			loginStatus = false;
			
			document.getElementById("loginId").innerHTML= "Login";
			document.getElementById("loginUserName").innerHTML = "";
			
			tab.initTabPanel(); //Here, whole page needs to be reloaded
			
			/* !!! To refresh the tree automatically after saving subject into MyComSoc */
		    treeSub.getSubTreeInitData();
		    treePub.getPubTreeInitData();
		    
			global.variables.myComSocUserFont = null; //loginObject.response.fontSize
			parityHistory.clearHistoryPage();
		}
		else
		{
			alert("Unable to logout, Please try again!");  //This have to appear in a global notification dialog box
		}	
	},
	
	shoppingCart: function()
    {
	    /* **************************************************************************
	     * Subclass object gets populated with seperate shopping class.             *
	     * It is object oriented javascript programming by components architecture  *
	     ***************************************************************************/
    },
    
    myComSoc: function()
    {
	    /* **************************************************************************
	     * Subclass object gets populated with seperate shopping class.             *
	     * It is object oriented javascript programming by components architecture  *
	     ***************************************************************************/
    },
    
    downloadCart: function()
    {
	    /* **************************************************************************
	     * Subclass object gets populated with seperate download class.             *
	     * It is object oriented javascript programming by components architecture  *
	     ***************************************************************************/
    },
            
    /**
	Show the MyComSoc My Personal Library
	*/
	myComSocMyPersonalLibrary: function()
	{
	    var tempMyComSocMyPersonalLibrary;
	    
	    var ajaxRequest = zXmlHttp.createRequest();	
	    ajaxRequest.onreadystatechange = function()
	    {
		    if(ajaxRequest.readyState == 4)
		    {
			    if (ajaxRequest.status == 200) 
			    {
				    tempMyComSocMyPersonalLibrary = access.renderMyComSocMyPersonalLibrary(ajaxRequest.responseText);								
			    } 
			    else 
			    {	
                    alert("Unable to get response of top articles!: " + ajaxRequest.responseText);	
			    }				
		    }       
	    }	
	    ajaxRequest.open("GET", ROOT_DB_URL + "downloads.action?articleType=Home", true);		
	    ajaxRequest.send(null);	
	    
		return tempMyComSocMyPersonalLibrary;		
	},
	
	/**
	Renders the MyComSoc's My Personal Library
	*/
	renderMyComSocMyPersonalLibrary: function(jsonObject)
	{
	    var articleObject = eval('(' + jsonObject + ')');
        var authorTempObj;
	    var i, j, resultHTML;
    	
	    if ( articleObject.topDownloadedArticles == null)
	    {
	         resultHTML = "No articles found!";
	         return resultHTML;
        }          
         
        resultHTML = "<TABLE  border=0 cellpadding=0>";	
    	
	    for( i = 0; i < articleObject.topDownloadedArticles.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'>";
    		
		    resultHTML += "<TD class=searchResultItem>";
		    resultHTML += ((i+1) + ". ").bold();
    		
		    authorTempObj = articleObject.topDownloadedArticles[i].authors;
    		
		    for( j = 0; authorTempObj != null && j < authorTempObj.length; j ++)
		    {
		        resultHTML += "<A href=# class=searchResultItem";
                resultHTML += " onclick=\"searchResults.getAuthorData(" + articleObject.topDownloadedArticles[i].authors[j].authorID +")\">";
		        resultHTML += articleObject.topDownloadedArticles[i].authors[j].firstName;
			    resultHTML += articleObject.topDownloadedArticles[i].authors[j].lastName + ", ";			
			    resultHTML += "</A>";				
		    }
		    resultHTML += "<A href=#" + articleObject.topDownloadedArticles[i].articleID + " class=searchResultItem";
            resultHTML += " onclick=\"searchResults.getArticleData('" + articleObject.topDownloadedArticles[i].articleID + "'," + (i+1) + ")\">";
            resultHTML += articleObject.topDownloadedArticles[i].articleTitle.bold() + "</A>, ";
		    resultHTML += articleObject.topDownloadedArticles[i].parentTitle.italics() + ", ";
    		
		    resultHTML += "Vol. " + articleObject.topDownloadedArticles[i].volume + ", ";
		    resultHTML += "no. " + articleObject.topDownloadedArticles[i].issueNumber + ", ";
    		
		    var resultDetailsKeyword = articleObject.topDownloadedArticles[i].parentTitle.bold();
		    resultDetailsKeyword += ", " + articleObject.topDownloadedArticles[i].month + " " + articleObject.topDownloadedArticles[i].year;
              
		    resultHTML += "<A href=# class=searchResultItem";
            resultHTML += " onclick=\"pubGetPublicationResults('" + articleObject.topDownloadedArticles[i].issueObjectNodeID +"','" + resultDetailsKeyword +"')\">";
            resultHTML += articleObject.topDownloadedArticles[i].month + " ";
		    resultHTML += articleObject.topDownloadedArticles[i].year;
		    resultHTML += "</A>, "; 
    		
		    resultHTML += "pp. " + articleObject.topDownloadedArticles[i].startPage + "-";
		    resultHTML += articleObject.topDownloadedArticles[i].endPage;		
    		
		    resultHTML += "</TD>";	
		    resultHTML += "</TR>";
	    }
	    resultHTML += "</TABLE>";
		return resultHTML; 
	},
		
	tempFunction: function()
	{
		alert("Hi Veeresh");
	}
}

/********************************************** BEGIN **************************************************
* Download cart class serving for super class: access *
******************************************************************************************************/

function downloadCart()
{
    this.getDownloadCart = getDownloadCart;	
    this.renderDownloadCart = renderDownloadCart;
    this.removeDownloadCartItem = removeDownloadCartItem;
    this.clearDownloadCart = clearDownloadCart;
    this.renderClearDownloadCart = renderClearDownloadCart;
    this.getDownloadAll = getDownloadAll;    
}

/**
Shows the download cart items
*/
function getDownloadCart()
{
    if ( loginStatus == false )
	{
	    //alert("Please login to access download cart!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    tempData += "<img src=" + ROOT_URL + "images/alertAttention.gif /> Download Cart is accessible 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&src=downloadcart>Login</A><BR>";  	
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
	    document.getElementById("queryResultsDivId").innerHTML = tempData;
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	    printer.showPrinterPageLink(); /*It inturn calls or shows history link */
	    components.penel.hideBanner();   
	    return false;	 
	}
	
	var ajaxRequest = zXmlHttp.createRequest();    
    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);
    
    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {				
		        hideTopNotification();//hideNotification('queryResultsDivId');
		        access.downloadCart.renderDownloadCart(ajaxRequest.responseText);
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('queryResultsDivId');
			    alert("Unable to get download cart response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }		 
		    components.penel.hideBanner();   
		}		
	}			
    ajaxRequest.open("GET", ROOT_DB_URL + "downloadCart.action?nullParam=" + new Date() , true);	
    ajaxRequest.send(null);
    return false;	
}

/**
Render the download cart items
*/
function renderDownloadCart( downloadCartListResponse )
{	
    var downloadCartListObject;
    var downloadCartHTML = "";   
    var rowCount = 0;
    var authorTempObj;
    var resultDetailsKeyword;
    var downloadURL = ROOT_DB_URL + "download.action"; 
    
    try
    {
        downloadCartListResponse = downloadCartListResponse.replaceAll("&quot;", "\"");
        downloadCartListObject = eval('(' + downloadCartListResponse + ')');	   	        
    }
    catch(e)
    {
	    alert("Unable to get download cart response! \n\n" + e.description); 
	    return false;
    }
    
    downloadCartHTML += "<P class='helpHeading' align='center'>Download Cart</P>";
    
    if( downloadCartListObject.articlesForDownload.articlesList.length == 0 )
    {
        downloadCartHTML += "<P class=searchResultItem> " + showAlertInformation(1, "Download cart is empty") + "</P>";
        document.getElementById("queryResultsDivId").innerHTML = downloadCartHTML;
	
	    printer.hidePrinterPageLink();
	    searchResults.hideAllPanels();
        
        historyIsItResultDetails = 0;
	    parityHistory.setInHistory();       
        	     	    		         
        return;
    }
    
    downloadCartHTML += "<TABLE  border=1 cellpadding=5 cellspacing=0 width=98%>";
	  		        
    downloadCartHTML += "<TR>";
    downloadCartHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader width=3px >S.No.</TH>";
    downloadCartHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader align='center'>Content Information</TH>";
    downloadCartHTML += "</TR>";
    
    for( i = 0; i < downloadCartListObject.articlesForDownload.articlesList.length; i ++)
	{ 
	    if( i%2 == 0)
		    downloadCartHTML += "<TR style='background-color: whitesmoke; padding-top: 5px'>";
		else
		    downloadCartHTML += "<TR style='padding-top: 5px'>";
	
        downloadCartHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	
        downloadCartHTML += "<B>" + (++rowCount) + ". </B>"; 
	    downloadCartHTML += "</TD>";	
    			     		                       
	    downloadCartHTML += "<TD class=searchResultItem>";	        	
		authorTempObj = downloadCartListObject.articlesForDownload.articlesList[i].authors;
		
		for( j = 0; authorTempObj != null && j < authorTempObj.length; j ++)
		{
		    downloadCartHTML += "<A href=# onclick=\"searchResults.getAuthorData(" + downloadCartListObject.articlesForDownload.articlesList[i].authors[j].authorID +")\">";
		    downloadCartHTML += (downloadCartListObject.articlesForDownload.articlesList[i].authors[j].firstName || "");
			downloadCartHTML += " " + (downloadCartListObject.articlesForDownload.articlesList[i].authors[j].lastName || "") + ", ";			
			downloadCartHTML += "</A>";				
		}
		
		downloadCartHTML += "<A href=#" + downloadCartListObject.articlesForDownload.articlesList[i].articleID;
		downloadCartHTML += " onclick=\"searchResults.getArticleData('" + downloadCartListObject.articlesForDownload.articlesList[i].articleID + "') \">";
		downloadCartHTML += downloadCartListObject.articlesForDownload.articlesList[i].articleTitle.bold() + "</A>, ";
		downloadCartHTML += (downloadCartListObject.articlesForDownload.articlesList[i].parentTitle.italics() || "") + ", ";
		
		downloadCartHTML += "Vol. " + (downloadCartListObject.articlesForDownload.articlesList[i].volume || "") + ", ";
		downloadCartHTML += "no. " + (downloadCartListObject.articlesForDownload.articlesList[i].issueNumber || "") + ", ";
		
		resultDetailsKeyword = downloadCartListObject.articlesForDownload.articlesList[i].parentTitle;
		resultDetailsKeyword += ", " + downloadCartListObject.articlesForDownload.articlesList[i].month + " " + downloadCartListObject.articlesForDownload.articlesList[i].year;
		
        downloadCartHTML += "<A href=# onclick=\"pubGetPublicationResults('" + downloadCartListObject.articlesForDownload.articlesList[i].issueObjectNodeID +"','" + resultDetailsKeyword +"')\">";
        downloadCartHTML += (downloadCartListObject.articlesForDownload.articlesList[i].month || "") + " ";
		downloadCartHTML += (downloadCartListObject.articlesForDownload.articlesList[i].year || "");
		downloadCartHTML += "</A>, "; 
		
		downloadCartHTML += "pp. " + (downloadCartListObject.articlesForDownload.articlesList[i].startPage || "") + "-";
		downloadCartHTML += (downloadCartListObject.articlesForDownload.articlesList[i].endPage || "");		
		
		var articleTempObject = downloadCartListObject.articlesForDownload.articlesList[i].articleAbstract;
		
		if ( articleTempObject != null )
		    downloadCartHTML += "<BR>" + articleTempObject.substr(0, 200) + "...";
		    	                  	                                                          
        downloadCartHTML += "<p style='margin: 0; padding: 0; text-align: right'><INPUT class=button_bluesmall type=button onclick=\"access.downloadCart.removeDownloadCartItem('" + downloadCartListObject.articlesForDownload.articlesList[i].articleID + "')\" value='Remove'></p>";             
        downloadCartHTML += "</TD>"; 
        downloadCartHTML += "</TR>";
    }         
    
	downloadCartHTML += "</TABLE><BR>";	
	
	downloadCartHTML += "<P align=center>";
	downloadCartHTML += "<INPUT class=button_orangedark id=cartDownloadId onclick=access.downloadCart.getDownloadAll('" + downloadURL + "') type=button value=Download>&nbsp";
    downloadCartHTML += "<INPUT class=button_grey id=cartDownloadClearId type=button title='Clears the download cart items' onclick='access.downloadCart.clearDownloadCart()' value='Clear All'>&nbsp;&nbsp;";
    downloadCartHTML += "</P>";
    
    document.getElementById("queryResultsDivId").innerHTML = downloadCartHTML;
	
	printer.printerPageType = 7;	
    printer.showPrinterPageLink();
    
    searchResults.hideAllPanels();
    
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();    
	document.getElementById("homebodyId").scrollTop = 1;    //Move the page cursor on top	    		
}

/**
Remove the download cart item
*/
function removeDownloadCartItem( articleId )
{
    if ( confirmAlert("Do you want to remove this item from Download Cart?\n\nClick OK to Remove") == false )  return;
    
    var ajaxRequest = zXmlHttp.createRequest();
    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);

    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {					     
		        hideTopNotification();//hideNotification('queryResultsDivId');
		        access.downloadCart.renderDownloadCart(ajaxRequest.responseText);
		        downloadCartList.removeItem(articleId);		        
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('queryResultsDivId');
			    alert("Unable to remove download cart item. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }
	     }		
     }
    ajaxRequest.open("GET", ROOT_DB_URL + "downloadCart.action?action=remove&articleID=" + articleId + "&nullParam=" + new Date(), true);	
    ajaxRequest.send(null);
}

/**
Clears the download cart items
*/
/**
Clears the download cart items
*/
function clearDownloadCart()
{
    if ( confirmAlert("Do you want to clear the Download Cart?\n\nClick OK to Clear") == false )  return;
    
    var ajaxRequest = zXmlHttp.createRequest();
    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);
    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {						     
		        hideTopNotification();//hideNotification('queryResultsDivId');
		        access.downloadCart.renderClearDownloadCart(ajaxRequest.responseText);		        
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('queryResultsDivId');
			    alert("Unable to clear download cart items. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }
	     }		
     }
     
    ajaxRequest.open("GET", ROOT_DB_URL + "downloadCart.action?clearall=true&nullParam=" + new Date(), true);	
    ajaxRequest.send(null);	    		        
}

/**
Render download cart clear items
*/
/**
Render download cart clear items
*/
function renderClearDownloadCart( clearDownloadCartResponse )
{
    var clearDownloadCartHTML; 
    var clearDownloadCartObject;
     
    try
    {
        clearDownloadCartResponse = clearDownloadCartResponse.replaceAll("&quot;", "\"");
        clearDownloadCartObject = eval('(' + clearDownloadCartResponse + ')');	   	        
    }
    catch(e)
    {
	    alert("Unable to get clear shopping cart response! \n\n" + e.description); 
	    return false;
    }
    
    if( clearDownloadCartObject.articlesForDownload.articlesList.length==0 )
    {
        clearDownloadCartHTML = "<P class=blueHeading align='center'><B>Download Cart</B></P>";
        clearDownloadCartHTML += "<P class=searchResultItem>" + showAlertInformation(1, "Download cart is empty") + "</P>";
    	  
        document.getElementById("queryResultsDivId").innerHTML = clearDownloadCartHTML; 
        printer.hidePrinterPageLink();
        downloadCartList = new Hash();  
        
        historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
    }   
}

/**
Get download cart's download page
*/
function getDownloadAll(downloadURL)
{  
    if( downloadCartList.length>0 )
    {
        downloadWindowObject = window.open(downloadURL);
        tab.initTabPanel();  
        downloadCartList = new Hash(); 
    }
    else
    {
        alert("Download cart is empty");
    }       
}

access.downloadCart = new downloadCart;	/*	<< IMPORTANT!!!  INSTANTIATION OF INNER DOWNLOAD CART CLASS TO SUPER CLASS ACCESS	*/

/********************************************** END **************************************************
* Download cart class serving for super class: access *
*****************************************************************************************************/


/********************************************** BEGIN **************************************************
 * Shopping cart class serving for super class: access *
 ******************************************************************************************************/
function shoppingCart()
{
	this.getShoppingCart = getShoppingCart;	
	this.renderShoppingCart = renderShoppingCart;	
	this.removeShoppingCartItem = removeShoppingCartItem;
    this.clearShoppingCart = clearShoppingCart;
    this.renderClearShoppingCart = renderClearShoppingCart;
    this.getShoppingCartCheckout = getShoppingCartCheckout;
    this.renderGetShoppingCartCheckout = renderGetShoppingCartCheckout;
    this.validateShoppingCheckoutFields = validateShoppingCheckoutFields;
    this.checkoutTransaction = checkoutTransaction;
    this.clearCheckoutPaymentFields = clearCheckoutPaymentFields;
    this.getShoppingCartReceipt = getShoppingCartReceipt;
}

/**
Shows the shopping cart items
*/
function getShoppingCart(articleURL,articleType)
{	
	if(articleType == "tutorial")
       loginStatus = true;
       
    if ( loginStatus == false )
	{
	    //alert("Please login to access shopping cart!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
        tempData += "<img src=" + ROOT_URL + "images/alertAttention.gif /> Shopping Cart is accessible 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&src=shoppingcart>Login</A><BR>";
        tempData += "</DIV>";
        tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;
        document.getElementById("queryResultsDivId").innerHTML = tempData;
        searchResults.hideAllPanels();
        historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	    printer.showPrinterPageLink(); /*It inturn calls or shows history link */
	    components.penel.hideBanner();
	    return;	 
	}
	
    var ajaxRequest = zXmlHttp.createRequest();
	
    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);

    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {				
		        hideTopNotification();//hideNotification('queryResultsDivId');
		        access.shoppingCart.renderShoppingCart(ajaxRequest.responseText,articleURL,articleType);		        
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('queryResultsDivId');
			    alert("Unable to get shopping cart response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }
		    components.penel.hideBanner();
		}		
	}			
    ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?path=ShoppingCartList&nullParam=" + new Date() , true);	
    ajaxRequest.send(null);
    return false;	
}

/**
Render the shopping cart items
*/
function renderShoppingCart( shoppingCartListResponse, articleURL,articleType )
{	
    var shoppingCartListObject;
    var shoppingCartHTML;     
    var rowCount = 0;
    var cartObj;
    
    checkoutCartParam = "";
    
    try
    {
        shoppingCartListResponse = shoppingCartListResponse.replaceAll("&quot;", "\"");
        shoppingCartListObject = eval('(' + shoppingCartListResponse + ')');	   	        
    }
    catch(e)
    {
	    alert("Unable to get shopping cart response! \n\n" + e.description); 
	    return false;
    }
   
    cartObj = shoppingCartListObject.shoppingCartData.cart;
    shoppingCartHTML = "<P class=helpHeading align='center'>Shopping Cart</P>";
   
    if( cartObj.cartArticles != null &&
         cartObj.cartArticles.length == 0 )
    {
        shoppingCartHTML += "<P class=searchResultItem>" + showAlertInformation(1, "Shopping cart is empty") + "</P>";
        document.getElementById("queryResultsDivId").innerHTML = shoppingCartHTML;
		
	if(articleURL!=null && articleURL!='undefined')
	        return;
	     if(articleType == null)
	{   
		printer.hidePrinterPageLink();
	    searchResults.hideAllPanels();
	    historyIsItResultDetails = 0;
		parityHistory.setInHistory();    
	}
        return;
    }
    
           
       
      
    shoppingCartHTML += "<TABLE  border=1 cellpadding=5 cellspacing=0 width=98%>";
	shoppingCartHTML += "<TR>";
    shoppingCartHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader>S.No.</TH>";
    shoppingCartHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader align='center'>Content Information</TH>";
    shoppingCartHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader> Price </TH>";
    shoppingCartHTML += "</TR>";
    
    if (  cartObj.cartArticles != null ) 
    {		        
        for( var i = 0; i < cartObj.cartArticles.length; i++)
        {	           
		    if( (rowCount++)%2 == 0)
	            shoppingCartHTML += "<TR style='background-color: whitesmoke; padding-top: 5px'>";
	        else
	            shoppingCartHTML += "<TR style='background-color: white; padding-top: 5px'>";  
	            
	        shoppingCartHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	
		    shoppingCartHTML += "<B>" + (rowCount) + ". </B>"; 
		    shoppingCartHTML += "</TD>";	
		   
		    if ( cartObj.cartArticles[i].dataInstances.miniArticle != null )
	        {
	            //Article Title
	            checkoutCartParam += "&eid" + rowCount + "=" + cartObj.cartArticles[i].dataInstances.miniArticle.articleID + 
	                             "&numberOf" + rowCount  + "=" + cartObj.cartArticles[i].numberOf;
	            
	            shoppingCartHTML += "<TD class=searchResultItem >";		                  	                        
                shoppingCartHTML += searchResults.prepareNewPubRefInfo(cartObj.cartArticles[i].dataInstances.miniArticle, articleURL);  
                shoppingCartHTML += "<p  style='margin: 0; padding: 0; text-align: right'>";
                shoppingCartHTML += "<INPUT class=button_bluesmall type=button value='Remove' onclick=\"access.shoppingCart.removeShoppingCartItem('" + cartObj.cartArticles[i].dataInstances.miniArticle.articleID + "', '" + articleURL + "')\"></p>";             
                shoppingCartHTML += "</TD>";        
	        }
	        else
	        {
	            checkoutCartParam += "&iid" + rowCount + "=" + cartObj.cartArticles[i].dataInstances.id + 
	                             "&numberOf" + rowCount  + "=" + cartObj.cartArticles[i].numberOf;
	             articleURL = "articleURL";
	            //Tutorial Title
	            shoppingCartHTML += "<TD class=searchResultItem >";	
	            shoppingCartHTML += cartObj.cartArticles[i].dataInstances.description;// + "(Tutorial)";
	             shoppingCartHTML += "<p  style='margin: 0; padding: 0; text-align: right'>";
                shoppingCartHTML += "<INPUT class=button_bluesmall type=button value='Remove' onclick=\"access.shoppingCart.removeShoppingCartItem('" + cartObj.cartArticles[i].dataInstances.id + "', '" + articleURL + "', '" + articleType + "')\"></p>";             
	            shoppingCartHTML += "</TD>";  	     
	        }
		        
            shoppingCartHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	                 
            shoppingCartHTML += "<B>$" + cartObj.cartArticles[i].price + "</B>";   
            shoppingCartHTML += "</TD>";	
            shoppingCartHTML += "</TR>";
          
        }	        
    }
    
    if( cartObj.promotion != null )
    {
        shoppingCartHTML += "<TR>";         
        shoppingCartHTML += "<TD class=searchResultItem>&nbsp;</TD>";         
        shoppingCartHTML += "<TD class=searchResultItem>"; 
        shoppingCartHTML += "<TABLE width=100%>"; 
        shoppingCartHTML += "<TR>"; 
        shoppingCartHTML += "<TD class=searchResultItem style=''>"; 
        shoppingCartHTML += showAlertInformation(1,"Promotion Code: " + cartObj.promotion.promotionCode  + "<BR>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description: " + cartObj.promotion.description);
        
        if( cartObj.promotion.error != null && cartObj.promotion.error != "" )
            shoppingCartHTML += showAlertInformation(2,"Promotion Error: " + cartObj.promotion.error);
            
        shoppingCartHTML += "</TD>"; 
        shoppingCartHTML += "<TD style='text-align: right; vertical-align: top' class=searchResultItem>" + "Subtotal:".bold() + "<BR>Discount:".bold(); 
        shoppingCartHTML += "</TD>"; 
        shoppingCartHTML += "</TR>"; 
        shoppingCartHTML += "</TABLE>"; 
        shoppingCartHTML += "</TD>";         
        shoppingCartHTML += "<TD style='text-align: right; vertical-align: top' class=searchResultItem>";   
        shoppingCartHTML += ("$" + cartObj.subTotal).bold() + "<BR>";
        shoppingCartHTML += ("$" + cartObj.promotion.discount).bold();
        shoppingCartHTML += "</TD>";
        shoppingCartHTML += "</TR>";
    }
    
    shoppingCartHTML += "<TR>";
    shoppingCartHTML += "<TD class=searchResultItem>&nbsp;</TD>";
    shoppingCartHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";
    shoppingCartHTML += "Total:".bold() + "</TD>";
    shoppingCartHTML += "<TD  class=searchResultItem style='text-align: right; vertical-align: top'>" + ( "$" + cartObj.total).bold() + "</TD>";
    shoppingCartHTML += "</TR>"; 
	shoppingCartHTML += "</TABLE><BR>";	
	
	shoppingCartHTML += "<P class=searchResultItem style='text-align: center;' >";
	shoppingCartHTML += "Promotion Code:".bold() + " <INPUT id=shoppingCartPromotionCodeID type=input>&nbsp;&nbsp;";
    shoppingCartHTML += "<INPUT class=button_orangedark id=shoppingCartCheckout type=button  value=Checkout onclick=\"access.shoppingCart.getShoppingCartCheckout('"+ articleURL +"')\">&nbsp";
    shoppingCartHTML += "<INPUT class=button_grey id=shoppingCartClear type=button title='Clears the shopping cart items' onclick=\"access.shoppingCart.clearShoppingCart('"+ articleURL +"')\" value='Clear All'>&nbsp;&nbsp;";
    shoppingCartHTML += "</P>";	
    
    
    
     
    if(articleURL != null)
    { 
       document.getElementById("queryResultsDivId").innerHTML = shoppingCartHTML;
       return;
    }
  
    if(articleType != null && articleType == "tutorial")
    { 
         document.getElementById("queryResultsDivId").innerHTML = shoppingCartHTML;
         return;
    }
    document.getElementById("queryResultsDivId").innerHTML = shoppingCartHTML;
  
    printer.printerPageType = 4;
    printer.showPrinterPageLink();
       
    searchResults.hideAllPanels();
    
    
    historyIsItResultDetails = 0;
    parityHistory.setInHistory();    
    document.getElementById("homebodyId").scrollTop = 1;    //Move the page cursor on top
    
   
}

/**
Remove the shopping cart item
*/
function removeShoppingCartItem(articleId, articleURL,articleType)
{
 
    if ( confirmAlert("Do you want to remove this item from Shopping Cart?\n\nClick OK to Remove") == false )  
    	return; 
   
    var ajaxRequest = zXmlHttp.createRequest();
    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);

    ajaxRequest.onreadystatechange = function()
    {
       
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {					     
		        hideTopNotification();//hideNotification('queryResultsDivId');
		        access.shoppingCart.renderShoppingCart(ajaxRequest.responseText, articleURL,articleType);
		        
		        if(articleURL==null || articleURL=='undefined')
		        shoppingCartList.removeItem(articleId);
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('queryResultsDivId');
			    alert("Unable to remove shopping cart item. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }
        }		
    }
  
   if(articleType == "tutorial")
     	ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?remove=true&iid=" + articleId + "&nullParam=" + new Date(), true);	
   else
    	ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?remove=true&eid=" + articleId + "&nullParam=" + new Date(), true);	
    ajaxRequest.send(null);
}

/**
Clears the shopping cart items
*/
function clearShoppingCart(articleURL)
{

    if ( confirmAlert("Do you want to clear Shopping Cart?\n\nClick OK to Clear") == false )  return;
    
    var ajaxRequest = zXmlHttp.createRequest();
    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);

    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {						     
		        hideTopNotification();//hideNotification('queryResultsDivId');
		        access.shoppingCart.renderClearShoppingCart(ajaxRequest.responseText, articleURL);		        
		    }
		    else
		    {
			    hideTopNotification();//hideNotification('queryResultsDivId');
			    alert("Unable to clear shopping cart items. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }
	    }		
    } 
   
    ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?clearall=true&nullParam=" + new Date(), true);	
    ajaxRequest.send(null);	    		        
}

/**
Render shopping cart clear items
*/
function renderClearShoppingCart( clearShoppingCartResponse, articleURL )
{
    var clearShoppingCartHTML; 
    var clearShoppingCartObject;
    var cartObj;
     
    try
    {
        clearShoppingCartResponse = clearShoppingCartResponse.replaceAll("&quot;", "\"");
        clearShoppingCartObject = eval('(' + clearShoppingCartResponse + ')');	   	        
    }
    catch(e)
    {
	    alert("Unable to get clear shopping cart response! \n\n" + e.description); 
	    return false;
    }
    
    cartObj = clearShoppingCartObject.shoppingCartData.cart;
    
    if( cartObj.cartArticles.length == 0 )
    {
        clearShoppingCartHTML = "<P class=blueHeading align='center'><B>Shopping Cart</B></P>";
        clearShoppingCartHTML += "<P class=searchResultItem>" + showAlertInformation(1, "Shopping cart is empty") + "</P>";  
    	  
        document.getElementById("queryResultsDivId").innerHTML = clearShoppingCartHTML;  
        
        if(articleURL==null||articleURL=='undefined')
        {
        printer.hidePrinterPageLink();
        shoppingCartList = new Hash();
        
        historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	}    
    }   
}

/**
Get shopping cart's checkout page
*/
function getShoppingCartCheckout(articleURL)
{	
    var ajaxRequest = zXmlHttp.createRequest();
    var shoppingCartPromotionCode = "";   
    var shoppingCartCheckoutObject;
     
    if( document.getElementById("shoppingCartPromotionCodeID") != null )
        shoppingCartPromotionCode = document.getElementById("shoppingCartPromotionCodeID").value;
    
	if( shoppingCartPromotionCode.length != 0 )
	{
	    checkoutCartParam += ( "&promotionCode=" + shoppingCartPromotionCode );
	}

   
    showTopNotification();

    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200)
		    {			
		        hideTopNotification();
		        
		        try
                {
                    shoppingCartCheckoutObject = eval('(' + ajaxRequest.responseText + ')');	   	        
                }
                catch(e)
                {
	                alert("Unable to get checkout shopping cart response! \n\n" + e.description); 
	                return false;
                }
		      
		        if( shoppingCartCheckoutObject.shoppingCartData.checkout.cart.total == "0.00" )
                {

                    access.shoppingCart.checkoutTransaction("");
                    return;
                }
		       
		        components.penel.getShoppingCartCheckoutHTMLPage("shoppingCart/checkout.htm", ajaxRequest.responseText,articleURL);  				        
		    }
		    else
		    {
			    hideTopNotification();
			    alert("Unable to get shopping cart checkout response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000)); 			    
		    }
	    
	   }		
    }
    ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?checkout=true" + checkoutCartParam + "&nullParam=" + new Date(), true);	
    ajaxRequest.send(null);  			    	     		  	
}
	
/**
Render shopping cart's checkout page
*/
function renderGetShoppingCartCheckout( shoppingCartCheckoutResponse, pageName, articleURL )
{     
    var checkoutHTML = "";
    var shoppingCartCheckoutObject;
    var rowCount = 0;
    var cartObj ;
    var clearShoppingCartHTML; 
   
    try
    {
    
        shoppingCartCheckoutResponse = shoppingCartCheckoutResponse.replaceAll("&quot;", "\"");
        shoppingCartCheckoutObject = eval('(' + shoppingCartCheckoutResponse + ')');	   	        
    }
    catch(e)
    {
	    alert("Unable to get checkout shopping cart response! \n\n" + e.description); 
	    return false;
    }
    
 
     
    if( shoppingCartCheckoutObject.shoppingCartData.checkout != null )
        cartObj = shoppingCartCheckoutObject.shoppingCartData.checkout;
    else
        cartObj = shoppingCartCheckoutObject.shoppingCartData.receipt;
        
    
    
    if( pageName == "receipt" && cartObj.cart.error == null )
    {      
        access.shoppingCart.getShoppingCartReceipt(cartObj, articleURL);
        return;
    }
   
    checkoutHTML += "<TABLE  border=1 cellpadding=5 cellspacing=0 width=98%>";
	  		        
    checkoutHTML += "<TR>";
    checkoutHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader>S.No.</TH>";
    checkoutHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader align='center'>Content Information</TH>";
    checkoutHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader> Price </TH>";
    checkoutHTML += "</TR>";
     
    if ( cartObj.cart.cartArticles != null ) 
    {	
    
        for( var i = 0; i < cartObj.cart.cartArticles.length; i++)
        {	     	    
		    if( (rowCount++)%2 == 0)
	            checkoutHTML += "<TR style='background-color: whitesmoke; padding-top: 5px'>";
	        else
	            checkoutHTML += "<TR style='background-color: white; padding-top: 5px'>";  
	          
	        checkoutHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	
		    checkoutHTML += "<B>" + (rowCount) + ". </B>"; 
		    checkoutHTML += "</TD>";	
	                 
            if ( cartObj.cart.cartArticles[i].dataInstances.miniArticle != null )
	        {
	            //Article Title
	            checkoutHTML += "<TD class=searchResultItem >";	
	            checkoutHTML += searchResults.prepareNewPubRefInfo(cartObj.cart.cartArticles[i].dataInstances.miniArticle, articleURL);           
                checkoutHTML += "</TD>";      
	        }
	        else
	        {
	            //Tutorial Title
	            checkoutHTML += "<TD class=searchResultItem >";	
	            checkoutHTML += cartObj.cart.cartArticles[i].dataInstances.description;// + "(Tutorial)";
	            checkoutHTML += "</TD>";  	             
	        }
                        
            checkoutHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	                 
            checkoutHTML += "<B>$" + cartObj.cart.cartArticles[i].price + "</B>";   
            checkoutHTML += "</TD>";
            checkoutHTML += "</TR>";
        }	        
    }
    else
    {
        clearShoppingCartHTML = "<P class=blueHeading align='center'><B>Shopping Cart</B></P>";
        clearShoppingCartHTML += "<P class=searchResultItem>" + showAlertInformation(1, "Shopping cart is empty") + "</P>";  
    	  
        document.getElementById("queryResultsDivId").innerHTML = clearShoppingCartHTML;  
        printer.hidePrinterPageLink();
        shoppingCartList = new Hash();
        
        historyIsItResultDetails = 0;
	    parityHistory.setInHistory();
	    return;
    }
   
    if( cartObj.cart.promotion != null )
    {
        checkoutHTML += "<TR>";         
        checkoutHTML += "<TD class=searchResultItem>&nbsp;</TD>";         
        checkoutHTML += "<TD class=searchResultItem>"; 
        checkoutHTML += "<TABLE width=100%>"; 
        checkoutHTML += "<TR>"; 
        checkoutHTML += "<TD class=searchResultItem style=''>"; 
        checkoutHTML += showAlertInformation(1,"Promotion Code: " + cartObj.cart.promotion.promotionCode  + "<BR>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description: " + cartObj.cart.promotion.description);
       
        if( cartObj.cart.promotion.error != null && cartObj.cart.promotion.error != "" )
            checkoutHTML += showAlertInformation(2,"Promotion Error: " + cartObj.cart.promotion.error);
            
        checkoutHTML += "</TD>"; 
        checkoutHTML += "<TD style='text-align: right;vertical-align: top' class=searchResultItem>" + "Subtotal:".bold() + "<BR>Discount:".bold(); 
        checkoutHTML += "</TD>"; 
        checkoutHTML += "</TR>"; 
        checkoutHTML += "</TABLE>"; 
        checkoutHTML += "</TD>";         
        checkoutHTML += "<TD style='text-align: right; vertical-align: top' class=searchResultItem>";   
        checkoutHTML += ("$" + cartObj.cart.subTotal).bold() + "<BR>";
        checkoutHTML += ("$" + cartObj.cart.promotion.discount).bold();
        checkoutHTML += "</TD>";
        checkoutHTML += "</TR>";
    }
  
    checkoutHTML += "<TR>";
    checkoutHTML += "<TD class=searchResultItem>&nbsp;</TD>";
    checkoutHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	     
    checkoutHTML += "Total:".bold() + "</TD>";
    checkoutHTML += "<TD id=totalCheckOutArticlePriceTD class=searchResultItem style='text-align: right; vertical-align: top'>" + ("$" + cartObj.cart.total).bold() + "</TD>";
    checkoutHTML += "</TR>";
    checkoutHTML += "</TABLE>";
    
    if(articleURL!=null && articleURL!='undefined')
    {
       checkoutHTML += "<DIV style='display:none' id='articleURLValueId'>"+ articleURL +"</DIV>";
    }
    
    document.getElementById("checkoutContentDivId").innerHTML = checkoutHTML; 
   
    if( cartObj.cart.error != null )
    {
        document.getElementById("transactionErrorMsgDiv").innerHTML = "<B>" + cartObj.cart.error + 
                                                   "<BR>Please re-enter your information and try again.</B>"; 
    }
       
    resetTextField("card-number,cvv2");
    document.getElementById("card-expmonth").selectedIndex = 0;
    document.getElementById("card-expyear").selectedIndex = 0;
    
    document.getElementById("name").value = validateDataItem("", cartObj.user.name);     
    document.getElementById("address").value = validateDataItem("", cartObj.user.address);     
    document.getElementById("city").value = validateDataItem("", cartObj.user.city);     
    document.getElementById("state").value = validateDataItem("", cartObj.user.state);
    document.getElementById("country").value = validateDataItem("", cartObj.user.country);
    document.getElementById("postalcode").value = validateDataItem("", cartObj.user.postalCode);     
    document.getElementById("phone").value = validateDataItem("", cartObj.user.phone);     
    document.getElementById("email").value = validateDataItem("", cartObj.user.email);
     
     
     
     if(articleURL!=null)
     	return;
    printer.printerPageType = 6;	
    printer.showPrinterPageLink();
    
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();
}
	
/*
Validates shopping cart's checkout form fields
*/
function validateShoppingCheckoutFields()
{  
    var articleURL="";
    
    if(document.getElementById("articleURLValueId")!=null)
    {
     articleURL = document.getElementById("articleURLValueId").innerHTML;
        }
    
    var checkoutTransactionParam = ""; 
  
    if ( !validNum("card-number","Card Number",true) )
	    return false;
	else
	    checkoutTransactionParam += "card-number=" + document.getElementById("card-number").value;
	        
    if (!validRequired("cvv2","Card Security Code",true))
	    return false;
	else
	    checkoutTransactionParam += "&cvv2=" + document.getElementById("cvv2").value;   	 
	       
	if ( document.getElementById("card-expmonth").selectedIndex == 0 )
    {
        alert("Please Select Expiration Month");
		return false;
    }
    else
        checkoutTransactionParam += "&card-expmonth=" + document.getElementById("card-expmonth").value; 
         
    if ( document.getElementById("card-expyear").selectedIndex == 0 )
	{
		alert("Please Select Expiration Year");
		return false;
	}
	else
	    checkoutTransactionParam += "&card-expyear=" + document.getElementById("card-expyear").value;  
	   
	if (!validRequired("name","Billing Full Name",true))
		return false;
    else
         checkoutTransactionParam += "&name=" + document.getElementById("name").value;    

	if (!validRequired("address","Billing Address",true))
		return false;
    else
         checkoutTransactionParam += "&address=" + document.getElementById("address").value;

	if (!validRequired("city","Billing City",true))
		return false;
	else
	    checkoutTransactionParam += "&city=" + document.getElementById("city").value;
		
    if ( document.getElementById("state").selectedIndex == 0 )
	{
	    alert("Please Select Your Billing State");
		return false;
	}
	else
	    checkoutTransactionParam += "&state=" + document.getElementById("state").value;  

	if (!validRequired("postalcode","Billing Postal Code",true))
		return false;
    else
        checkoutTransactionParam += "&postalcode=" + document.getElementById("postalcode").value;  		

	if (document.getElementById("country").selectedIndex == 0 )
	{
		alert("Please Select Your Billing Country");
		return false;
	}
	else
	    checkoutTransactionParam += "&country=" + document.getElementById("country").value;   

	if (!validEmail("email","Email Address",true))
		return false;
	else
	    checkoutTransactionParam += "&email=" + document.getElementById("email").value;  

	if (!validNum("phone","Phone Number",true))
		return false;
    else
         checkoutTransactionParam += "&phone=" + document.getElementById("phone").value; 
         
    if (!validNotes("notes"))
                  	return false;
          	
    else
    	
           checkoutTransactionParam += "&notes=" + document.getElementById("notes").value; 
    		
    access.shoppingCart.checkoutTransaction(checkoutTransactionParam,articleURL);
    
	return true;		
}

/**
Authorize the shopping cart transaction items.
*/
function checkoutTransaction(checkoutTransactionParam, articleURL)
{ 
    var ajaxRequest = zXmlHttp.createRequest();
  
    if( checkoutTransactionParam != "" )
        document.getElementById("authorizeTransactionMsgID").style.display = "";
    else
        showTopNotification();
        
    
        
    ajaxRequest.onreadystatechange = function()
    {
        if(ajaxRequest.readyState == 4)
	    {
	     
		    if (ajaxRequest.status == 200)
		    {					        
		        if(checkoutTransactionParam!= "")
                    document.getElementById("authorizeTransactionMsgID").style.display = "none"; 
                else
                    hideTopNotification();
		
		        
		        access.shoppingCart.renderGetShoppingCartCheckout(ajaxRequest.responseText, "receipt", articleURL);
		    }
		    else
		    {
		        if(checkoutTransactionParam!= "")
                    document.getElementById("authorizeTransactionMsgID").style.display = "none"; 
                else
                    hideTopNotification();
                    
			    alert("Unable to get checkout transaction response. Please try again!: \n\n" + ajaxRequest.responseText.substring(1,2000));
		    }
		  
	    }	
	   
    } 
    ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?purchase=true&" + checkoutTransactionParam + "&nullParam=" + new Date(), true);	
    ajaxRequest.send(null);  
}

/**
Get shopping cart receipt after successful purchase transaction
*/
function getShoppingCartReceipt(shoppingCartReceiptObject, articleURL)
{
    var receiptHTML = "";
    var rowCount = 0;
    var cartObj;
   	var isTutorial = 0;
   	
    cartObj = shoppingCartReceiptObject.cart;
    
    //receiptHTML = "<P class=blueHeading align='center'><B>Receipt</B></P>";
    receiptHTML = "<P align='center'><IMG src='" + ROOT_URL + "images/logo_ReceiptPage.jpg' />";
    receiptHTML += "<center><font face='Arial' size='2'>IEEE Communications Society</font></center>";
    receiptHTML += "<center><font face='Arial' size='2'>3 ParkAvenue, 17th Flr,</font></center>";
    receiptHTML += "<center><font face='Arial' size='2'>New York, NY 10016</font></center>";
    receiptHTML += "<center><font face='Arial' size='2'>USA</font></center></P><br><br>";
    
    //receiptHTML += "<P class=searchResultItem style='text-align: center'><B>PLEASE CLICK ON THE TEXT LINK TO DOWNLOAD THE CONTENT THAT YOU JUST PURCHASED</B></p>";
    receiptHTML += "<P class=searchResultItem style='text-align: center'><B>PLEASE CLICK ON TEXT LINK TO ACCESS THE ITEM YOU JUST PURCHASED</B></p>";
    
    
    receiptHTML += "<TABLE  border=1 cellpadding=5 cellspacing=0 width=98%>";
	  		        
    receiptHTML += "<TR>";
    receiptHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader>S.No.</TH>";
    //receiptHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader align='center'>Content Information</TH>";
    receiptHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader align='center'>Description</TH>";
    
    receiptHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader> Price </TH>";
    receiptHTML += "</TR>";
 
 
    if ( cartObj.cartArticles != null ) 
    {		        
        for( var i = 0; i < cartObj.cartArticles.length; i++)
        {	     	                 
		    if( (rowCount++)%2 == 0)
	            receiptHTML += "<TR style='background-color: whitesmoke; padding-top: 5px'>";
	        else
	            receiptHTML += "<TR style='background-color: white; padding-top: 5px'>";  
	        
	        receiptHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	
		    receiptHTML += "<B>" + (rowCount) + ". </B>"; 
		    receiptHTML += "</TD>";	
	
            if ( cartObj.cartArticles[i].dataInstances.miniArticle != null )
	        {
	            //Article Title
	            receiptHTML += "<TD class='searchResultItem headerImagesId''>";
	   
                receiptHTML += searchResults.prepareNewPubRefInfo( cartObj.cartArticles[i].dataInstances.miniArticle, articleURL);  
                //receiptHTML += "<P><B>Full Text: </B><A style='color: blue' target=_blank href='" + ROOT_DB_URL + "forwarddata.action?eid=" + cartObj.cartArticles[i].dataInstances.miniArticle.articleID + "'> <IMG src=" + ROOT_URL + "images/pdf.gif /> (PDF) </A></P>";         
                receiptHTML += "<P><B>Full Text: </B>";
            	if(cartObj.cartArticles[i].dataInstances.miniArticle.formats != null && cartObj.cartArticles[i].dataInstances.miniArticle.formats.length ==2) 
				{
				if(cartObj.cartArticles[i].dataInstances.miniArticle.formats[0].formatType == "preview\/html" || cartObj.cartArticles[i].dataInstances.miniArticle.formats[1].formatType == "preview\/html" )
					isTutorial = 1;
				}
                
                for(var j = 0; cartObj.cartArticles[i].dataInstances.miniArticle.formats != null && j < cartObj.cartArticles[i].dataInstances.miniArticle.formats.length; j++)
	            {
	                if ( cartObj.cartArticles[i].dataInstances.miniArticle.formats[j].formatType == "application\/pdf" )
	                {
	                    receiptHTML += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + cartObj.cartArticles[i].dataInstances.miniArticle.articleID + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
	                    receiptHTML += "<IMG src='" + ROOT_URL + "images/pdf.gif' />"+ " PDF ".bold();
	                    receiptHTML += "</A>";
	                }
	               else if ( cartObj.cartArticles[i].dataInstances.miniArticle.formats[j].formatType == "text\/html" )
	               {
	                    receiptHTML += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + cartObj.cartArticles[i].dataInstances.miniArticle.articleID + "','text\/html')\"  class=\"searchResultItem headerImagesId\">";
	                   	if(isTutorial ==1)
	                    {
	                    	receiptHTML += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Full Tutorial ".bold();
	                    	isTutorial = 0;
	                    }
	                    else
	                    	receiptHTML += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " HTML ".bold();
	                    receiptHTML += "</A>";
	                }
	                else if ( cartObj.cartArticles[i].dataInstances.miniArticle.formats[j].formatType == "preview\/html" )
					{
						receiptHTML += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + cartObj.cartArticles[i].dataInstances.miniArticle.articleID + "','preview\/html')\"  class=\"searchResultItem headerImagesId\">";
						receiptHTML += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Preview ".bold();
						receiptHTML += "</A>";
	                }
	                if ( j < cartObj.cartArticles[i].dataInstances.miniArticle.formats.length - 1 )
	                    receiptHTML += " | ";
	            }
                  
                receiptHTML += "</P></TD>"; 
	        }
	        else
	        {
	            //Tutorial Title
	            receiptHTML += "<TD class='searchResultItem headerImagesId'>";	
	            receiptHTML += cartObj.cartArticles[i].dataInstances.description;// + "(Tutorial)";
	            //receiptHTML += "<P><B>Full Text: </B><A style='color: blue' target=_blank href='" + ROOT_DB_URL + "forwarddata.action?iid=" + cartObj.cartArticles[i].dataInstances.id + "'> <IMG src=" + ROOT_URL + "images/pdf.gif /> (PDF) </A></P>";
	            if(cartObj.cartArticles[i].dataInstances.url != null && cartObj.cartArticles[i].dataInstances.url != "")
		   		{
		   	          receiptHTML += "<P><B>Full Text: </B>";
		   		      receiptHTML += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + cartObj.cartArticles[i].dataInstances.id + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
		       	      receiptHTML += "<IMG src='" + ROOT_URL + "images/download.png' style='border: 0px' />Download File</A></P>";
                }
                receiptHTML += "</TD>";  	             
	        }
	            
            receiptHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	                 
            receiptHTML += "<B>$" + cartObj.cartArticles[i].price + "</B>";   
            receiptHTML += "</TD>";	
            receiptHTML += "</TR>";
        }	        
    }
 
    if( cartObj.promotion != null )
    {
        receiptHTML += "<TR>";         
        receiptHTML += "<TD class=searchResultItem>&nbsp;</TD>";         
        receiptHTML += "<TD class=searchResultItem>"; 
        receiptHTML += "<TABLE width=100%>"; 
        receiptHTML += "<TR>"; 
        receiptHTML += "<TD class=searchResultItem >"; 
        receiptHTML += showAlertInformation(1,"Promotion Code: " + cartObj.promotion.promotionCode  + "<BR>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description: " + cartObj.promotion.description);
        
        if( cartObj.promotion.error != null && cartObj.promotion.error != "" )
            receiptHTML += showAlertInformation(2,"Promotion Error: " +cartObj.promotion.error);
            
        receiptHTML += "</TD>"; 
        receiptHTML += "<TD style='text-align: right;vertical-align: top' class=searchResultItem>" + "Subtotal:".bold() + "<BR>Discount:".bold(); 
        receiptHTML += "</TD>"; 
        receiptHTML += "</TR>"; 
        receiptHTML += "</TABLE>"; 
        receiptHTML += "</TD>";         
        receiptHTML += "<TD style='text-align: right; vertical-align: top' class=searchResultItem>";   
        receiptHTML += ("$" + cartObj.subTotal).bold() + "<BR>";
        receiptHTML += ("$" + cartObj.promotion.discount).bold();
        receiptHTML += "</TD>";
        receiptHTML += "</TR>";
    }
    
    receiptHTML += "<TR>";
    receiptHTML += "<TD class=searchResultItem>&nbsp;</TD>";
    receiptHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>";	     
    receiptHTML += "Total:".bold() + "</TD>";
    receiptHTML += "<TD class=searchResultItem style='text-align: right; vertical-align: top'>" + ("$" + cartObj.total).bold() + "</TD>";
    receiptHTML += "</TR>"; 
     
    receiptHTML += "</TABLE>";
    receiptHTML += "<BR>";
    
    receiptHTML += "<DIV style='border: 1px solid silver;'>";
    receiptHTML += "<TABLE  border=0 cellpadding=5 cellspacing=0 width=98%>";
	  		        
    receiptHTML += "<TR>";
    receiptHTML += "<TH style='padding: 3px' class=shoppingCartTableHeader align='center' colspan=2>Confirmation(" + shoppingCartReceiptObject.date + ")</TH>";
    receiptHTML += "</TR>";
    
    receiptHTML += "<TR>";
    receiptHTML += "<TD>&nbsp;</TD><TD class=searchResultItem style='text-align: left'><b>Billing Address:</b><BR>";
     
    if ( shoppingCartReceiptObject.user.name != null)
        receiptHTML += shoppingCartReceiptObject.user.name + "<BR>";
    
    if ( shoppingCartReceiptObject.user.address != null )
        receiptHTML += shoppingCartReceiptObject.user.address + "<BR>";
    
    if ( shoppingCartReceiptObject.user.city != null )
        receiptHTML += shoppingCartReceiptObject.user.city + ", ";
    
    if ( shoppingCartReceiptObject.user.state != null )
        receiptHTML += shoppingCartReceiptObject.user.state + ", ";
    
    if ( shoppingCartReceiptObject.user.country != null )
        receiptHTML += shoppingCartReceiptObject.user.country + " ";
        
    if ( shoppingCartReceiptObject.user.postalcode != null )
        receiptHTML += shoppingCartReceiptObject.user.postalcode;
      
    receiptHTML += "</TD></TR>";
    
    receiptHTML += "<TR>";
    receiptHTML += "<TD class=searchResultItem style='text-align: center' colspan=2><BR><B>PLEASE PRINT AND SAVE THIS RECIPT FOR FUTURE REFERENCE</B></TD>";
    receiptHTML += "</TR>";
   
     
    receiptHTML += "</TABLE>";
    receiptHTML += "</DIV>";
    receiptHTML += "<BR>";
    
    receiptHTML += "<P id=authorizeTransactionMsgID style='display: none; text-align: center; font-family: Arial; color: green;'><IMG src=" + ROOT_URL + "images/progress-icon-indicator.gif />&nbsp;Authorization in progress...</P>";
    	  
    
    document.getElementById("queryResultsDivId").innerHTML = receiptHTML;
    
    if(articleURL == null || articleURL == '')
       {
       	printer.printerPageType = 8;
        printer.showPrinterPageLink();
     
        historyIsItResultDetails = 0;
	parityHistory.setInHistory();
	}
}

/**
Clears the shopping cart payment fields.
*/
function clearCheckoutPaymentFields()
{
    var articleURL="";
        
    if(document.getElementById("articleURLValueId")!=null)
    {
    	articleURL = document.getElementById("articleURLValueId").innerHTML;
        
    }
    
    access.shoppingCart.getShoppingCartCheckout(articleURL);
}

access.shoppingCart = new shoppingCart;	/*	<< IMPORTANT!!!  INSTANTIATION OF INNER SHOPPING CART CLASS TO SUPER CLASS ACCESS	*/

/********************************************** END **************************************************
* Shopping cart class serving for super class: access *
*****************************************************************************************************/

/********************************************** BEGIN **************************************************
* myComSoc class serving for My ComSoc Preferences *
******************************************************************************************************/
function myComSoc()
{
    var myFavSearches = "";
    var myFavSearchSubject = "";
    var myFavSearchPublications = "";
    var myFavSearchAuthor = "";
    
	this.getMyComSocInfo = getMyComSocInfo;
	this.getMyComSocDetails = getMyComSocDetails;
	this.renderMyComSocDetails = renderMyComSocDetails;
	this.myComSocGetFavorites = myComSocGetFavorites;
	this.renderMyComSocGetFavorites = renderMyComSocGetFavorites;
	
	this.myComSocViewRights = myComSocViewRights;
	this.renderMyComSocViewRights = renderMyComSocViewRights;
	this.updateMyComSocViewRights = updateMyComSocViewRights;
	
	this.myComSocEditLayout = myComSocEditLayout;
	this.renderMyComSocEditLayout = renderMyComSocEditLayout;	
	this.updateMyComSocFontsize = updateMyComSocFontsize;
	this.selectFont = selectFont;
	this.setLoginFontsize = setLoginFontsize;
	
	this.myComSocViewPurchases = myComSocViewPurchases;	
	this.viewPurchasesFromComSocPortal = viewPurchasesFromComSocPortal;	
	this.renderComSocPortalViewPurchases = renderComSocPortalViewPurchases;
	this.renderComSocViewPurchases = renderComSocViewPurchases;	
	this.setPurchaseHistorySortByType = setPurchaseHistorySortByType;
	this.preparePurchaseRefInfo = preparePurchaseRefInfo;
	
	this.removeFavoriteItem = removeFavoriteItem;
	this.setFavoriteNotifyItem = setFavoriteNotifyItem;
	this.renderSetFavoriteNotifyItem = renderSetFavoriteNotifyItem;
	this.downloadPurchasedHistoryItems = downloadPurchasedHistoryItems;	
	
	this.getHelpMainHTML = getHelpMainHTML;
	this.renderHelpMainHTML = renderHelpMainHTML;
	this.getAccessRules = getAccessRules;
}

/**
Get the MyComSoc homepage's partial data

@param source It contains the source information(link or button) from which it is called
@param optionalFunction Function name of the my-comsoc items(favroties, colors, history..)

*/
function getMyComSocInfo(source, optionalFunction)
{
    var tempData;
	//loginStatus = false;
	if ( loginStatus == false )
	{
	    //alert("Please login to access MyComSoc!");
	    tempData = "<DIV class='myComSocContent monthIssue'>";
	    tempData += "<img src=" + ROOT_URL + "images/alertAttention.gif /> My ComSoc is accessible 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&src=mycomsoc onclick='return access.authenticateUser()'>Login</A><BR><BR>";  	
	    tempData += "If you are a ComSoc member please <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser&src=mycomsoc>Login</A><BR><BR>";  	
	    //tempData += "&raquo; <A href='https://dl.comsoc.org/cocoon/comsoc/html/about.htm#ACCESS' target=_black>Access Rules</A><BR>";
	    tempData += "&raquo; <A href=# onclick=\"return access.myComSoc.getHelpMainHTML('helpPages/helpMain.htm')\">Access Rules</A><BR>"; 
	    tempData += "&raquo; <A href=http://dl.comsoc.org/comsocdl/DRM-authentication.action?path=LoginUser onclick='return access.authenticateUser()'>Registration</A><BR>";  	
	    //tempData += "&raquo; <A href=# onclick='return access.authenticateUser()'>Registration</A><BR>";
	    tempData += "&raquo; <A href='mailto:dl-feedback@comsoc.org' target=_black>Feedback</A><BR>";
	    tempData += "</DIV>";
	    tempData = "<BR>" + components.getPlainFormHTMLComponent("Login", tempData) + "<BR>" ;	    
	}
	else
	{       
	    var userName = "".bold();
    	
	    var manageAccoutnData = "";
	    var manageComSocAliasesData = "";
	    var myArticleData = "";
	    var myPersonalLibraryData = "";
	    
	    showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);
    	
	    document.getElementById("queryResultsDivId").style.align = "right";
    	
	    tempData = "<DIV style='' class=searchResultPageTitle>My ComSoc<HR style='height: 1px'></DIV>";
	    tempData += "<DIV class='myComSocContent monthIssue'>";
	    tempData += "<BR>Hello, <font id=myComSocUserName>" + userName + "</font>";
	    tempData += "<BR>Welcome back to your personal ComSoc page.";
	    tempData += "(If you're not Staff Communication Society, please <A href=# onclick='return access.authenticateUser()'>Click Here</A>)<BR><BR>";
    	
	    tempData += "<DIV class='notificationMessage myComSocContent'>You Have <B id=myComSocNoOfPreferences>No</B> &nbsp;NEW ARTICLES based on your preferences</DIV><BR>";
    	
	    manageAccoutnData = "<A href=# onclick='return access.myComSoc.myComSocGetFavorites()'><IMG src='" + ROOT_URL + "images/mycomsoc/myMyComSoc1ViewFavourites.png' style='border: 0px;'>&nbsp;View/Edit your favorites</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
	    manageAccoutnData += "<A href=# onclick='return access.myComSoc.myComSocViewRights()'><IMG src='" + ROOT_URL + "images/mycomsoc/myMyComSoc2ViewAccessrights.png' style='border: 0px;'>&nbsp;View your access rights</A> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
	    manageAccoutnData += "<A href=# onclick='return access.myComSoc.myComSocEditLayout()'><IMG src='" + ROOT_URL + "images/mycomsoc/myMyComSoc4EditLayout.png' style='border: 0px;'>&nbsp;Edit your layout</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
	    manageAccoutnData += "<A href=# onclick='return access.myComSoc.myComSocViewPurchases(\"Date\")'><IMG src='" + ROOT_URL + "images/mycomsoc/myMyComSoc4ViewPurchases.png' style='border: 0px;'>&nbsp;View your purchases</A><BR>";
	    manageAccoutnData += "<DIV id=manageAccountInfo>&nbsp;</DIV>";
    	
	    tempData += components.getFormHTMLComponent("Manage Account", manageAccoutnData);
        /*
	    manageComSocAliasesData = "<DIV id=myComSocAliases>&nbsp;</DIV>";
        tempData += "<BR>" + components.getFormHTMLComponent("Manage COMSOC Aliases ", manageComSocAliasesData);
        */
        myArticleData = "<DIV id=myComSocMyArticles>&nbsp;</DIV>";
        tempData += "<DIV id=myComSocMyArticlesBody><BR>" + components.getFormHTMLComponent("My Articles", myArticleData) + "</DIV>";
        
        myPersonalLibraryData = "<DIV id=myComSocMyPersonalLib>&nbsp;</DIV>";
        tempData += "<BR>" + components.getFormHTMLComponent("My Personal Library", myPersonalLibraryData);	
        
        tempData += "<BR>If you would like to change your preferences, go to <A href=#  onclick='return access.myComSoc.myComSocGetFavorites()' >My ComSoc</A>" 
	    tempData += "</DIV>";
	}
	
    document.getElementById("queryResultsDivId").innerHTML = tempData;
    searchResults.hideAllPanels();
	printer.printerPageType = 5;
    printer.showPrinterPageLink();	 
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();	    
	components.penel.hideBanner();
	
    if ( source =="homepage" && loginStatus == true ) /* The 'source' value is checked to facilitate View/Edit favorite action for 'Save Search/Article/Author' */ 
        access.myComSoc.getMyComSocDetails();
    if ( optionalFunction != null && optionalFunction != "" )
        eval(optionalFunction);
}

/**
Get the MyComSoc homepage details
*/
function getMyComSocDetails()
{
	var ajaxRequest = zXmlHttp.createRequest();	
	showTopNotification();//showNotification('queryResultsDivId', 'Loading...', 0);
	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
				hideTopNotification();//hideNotification('queryResultsDivId');
    		    access.myComSoc.renderMyComSocDetails(ajaxRequest.responseText);
			}
			else
			{	
				hideTopNotification();//hideNotification('queryResultsDivId');	
				alert("MyComSoc homepage - Unable to get response!: " + ajaxRequest.responseText);	
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "mycomsoc.action?sinceDays=30&nullParam=" + new Date(), true);
	//ajaxRequest.open("GET", "http://localhost:8181/comsocdl/html/mycomsoc.action10.25", true);
	ajaxRequest.send(null);
}

/**
Get the MyComSoc homepage details
*/
function renderMyComSocDetails(jsonData)
{    
    var myComSocData;
    var myArticlesData = "";
    var myPersonalLibData = "";
    
    try
    {
        myComSocData = eval('(' + jsonData + ')');
        
        if ( myComSocData.personalizationData.notifications == null )
        {
            throw myComSocData.personalizationData.statusMessage;
        }
    }
    catch(e)
    {
	    alert("Unable to parse MyComSoc data!\n\n" + e); 
	    return;
    }    
    
    if ( document.getElementById("myComSocUserName") )
        document.getElementById("myComSocUserName").innerHTML = myComSocData.personalizationData.userFavorite.name.bold();
    
    if ( document.getElementById("myComSocNoOfPreferences") )
        document.getElementById("myComSocNoOfPreferences").innerHTML = myComSocData.personalizationData.notifications.totalResults;
    
    // My Articles - Keyword notification
    for (var i = 0; i < myComSocData.personalizationData.notifications.keywordNotifications.length; i++) 
    {
        var notification = myComSocData.personalizationData.notifications.keywordNotifications[i];
        myArticlesData += "<TR><TD style='vertical-align:top;'><IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-search.gif> ";
        //myArticlesData += "<A href=# class=searchResultItem onclick=\"submitKeywordSearch('" + convertSpecialCharacters(notification.query) + "','keyword') \">";
        myArticlesData += "<A class=searchResultItem href=?keyword=" + escape(trim(notification.query)) + " onclick=\"return submitKeywordSearch('" + trim(notification.query) +"','keyword')\">";
        myArticlesData += convertSpecialCharacters(notification.displayLabel) + "(" + notification.paperResultsTotal +")</A></TD></TR>";
        
        if ( Number(notification.paperResultsTotal) == 0 )
        {
            myArticlesData += "<TR><TD class=searchResultItem>No Results for " + notification.displayLabel + "<HR></TD></TR>";
        }
    }
    
    // My Articles - Subject notification
    for (var i = 0; i < myComSocData.personalizationData.notifications.subjectNotifications.length; i++) 
    {
        var notification = myComSocData.personalizationData.notifications.subjectNotifications[i];
        myArticlesData += "<TR><TD style='vertical-align:top;'><IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-subjects.gif> ";
        //myArticlesData += "<A href=# class=searchResultItem onclick=\"treeSub.getSubjectResults('" + notification.ontologyNodeID + "','" + convertSpecialCharacters(notification.displayLabel) + "') \">";
        myArticlesData += "<A class=searchResultItem href=?subject=" + notification.ontologyNodeID + "&term=" + convertSpecialCharacters(notification.displayLabel) + " onclick=\"return treeSub.getSubjectResults('" + notification.ontologyNodeID + "','" + convertSpecialCharacters(notification.displayLabel) + "')\">";
        myArticlesData += convertSpecialCharacters(notification.displayLabel) + "(" + notification.paperResultsTotal +")</A></TD></TR>";
        
        if ( Number(notification.paperResultsTotal) == 0 )
        {
            myArticlesData += "<TR><TD class=searchResultItem>No Results for " + notification.displayLabel + "<HR></TD></TR>";
        }
    }
    
    // My Articles - Publication notification
    for (var i = 0; i < myComSocData.personalizationData.notifications.publicationNotifications.length; i++) 
    {
        var notification = myComSocData.personalizationData.notifications.publicationNotifications[i];
        myArticlesData += "<TR><TD style='vertical-align:top;'><IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-publications.gif> ";
        //myArticlesData += "<A href=# class=searchResultItem onclick=\"treePub.pubGetPublicationResults('" + notification.ontologyNodeID + "','" + convertSpecialCharacters(notification.displayLabel) + "') \">";
        myArticlesData += "<A class=searchResultItem href=?publication=" + notification.ontologyNodeID + "&label=" + convertSpecialCharacters(notification.displayLabel) + " onclick=\"return treePub.pubGetPublicationResults('" + notification.ontologyNodeID + "','" + convertSpecialCharacters(notification.displayLabel) + "')\">";
		myArticlesData += convertSpecialCharacters(notification.displayLabel) + "(" + notification.paperResultsTotal +")</A></TD></TR>";
        
        if ( Number(notification.paperResultsTotal) == 0 )
        {
            myArticlesData += "<TR><TD class=searchResultItem>No Results for " + notification.displayLabel + "<HR></TD></TR>";
        }
    }
    
    //My Articles - Person notification
    for (var i = 0; i < myComSocData.personalizationData.notifications.personNotifications.length; i++) 
    {
        var personNotifiction = myComSocData.personalizationData.notifications.personNotifications[i];
        myArticlesData += "<TR><TD><IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-authors.gif> ";
        //myArticlesData += "<A href=# class=searchResultItem onclick=\"searchResults.getAuthorData('" + personNotifiction.person.personID + "') \">";    
        myArticlesData += "<A class=searchResultItem href=?author=" + personNotifiction.person.personID +" onclick=\"return searchResults.getAuthorData(" + personNotifiction.person.personID +")\">";
		myArticlesData += getProperName(personNotifiction.person.givenName) + " " + getProperName(personNotifiction.person.middleName) + " " + getProperName(personNotifiction.person.surName);
        myArticlesData += "(" + personNotifiction.paperResultsTotal +")</A></TD></TR>";
        
        if ( Number(personNotifiction.paperResultsTotal) == 0 )
        {
            myArticlesData += "<TR><TD class=searchResultItem>No Results for " +(getProperName(personNotifiction.person.givenName) + " " + getProperName(personNotifiction.person.middleName) + " " + getProperName(personNotifiction.person.surName)) + "<HR></TD></TR>";            
        }
    }
    
    if ( myArticlesData == "" )
        myArticlesData = "<TABLE  border=0 width=99% cellpadding=5px><TR><TD class=searchResultItem>No Results</TD></TR></TABLE>";
    else
        myArticlesData = "<TABLE  border=0 width=99% cellpadding=5px>" + myArticlesData + "</TABLE>";
    
    if ( document.getElementById("myComSocMyArticles") )
        document.getElementById("myComSocMyArticles").innerHTML = myArticlesData;
        
    // My Personal Library
    for (var i = 0; myComSocData.personalizationData.pubRefs != null && i < myComSocData.personalizationData.pubRefs.length; i++) 
    {
        myComSocData.personalizationData.pubRefs[i].articleAbstract = null; //Abstract is not require
        myPersonalLibData += "<TR><TD class=searchResultItem>" + ((i+1) + ". ").bold() + searchResults.prepareNewPubRefInfo(myComSocData.personalizationData.pubRefs[i]) + "<BR><BR></TD></TR>";
    }
    
    if ( myPersonalLibData == "" )
        myPersonalLibData = "<TABLE  border=0 width=99% cellpadding=5px><TR><TD class=searchResultItem>No favorite papers</TD></TR></TABLE>";
    else
        myPersonalLibData = "<TABLE  border=0 width=99% cellpadding=5px>" + myPersonalLibData + "</TABLE>";
    
    if ( document.getElementById("myComSocMyPersonalLib") )
        document.getElementById("myComSocMyPersonalLib").innerHTML = myPersonalLibData;
    
    mycomsocFontResize("myComSocMyPersonalLib");
    
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();
}

/**
Shows the MyComSoc access rights
*/
function myComSocGetFavorites()
{
    var ajaxRequest = zXmlHttp.createRequest();	
    showTopNotification();//showNotification('manageAccountInfo', 'Loading...', 0);	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();//hideNotification('manageAccountInfo', 'Loading...', 0);	
	            access.myComSoc.renderMyComSocGetFavorites(ajaxRequest.responseText);					
			}
			else
			{
				hideTopNotification();//hideNotification('manageAccountInfo', 'Loading...', 0);	
	            document.getElementById("manageAccountInfo").innerHTML = "<HR>View/Edit Favorites".bold() + showAlertInformation(2, "MyComSoc Favorites - Unable to get response");
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "removefavorite.action?nullParam=" + new Date(), true);
	//ajaxRequest.open("GET", "http://localhost:8181/comsocdl/html/removefavorite.action-KaninMyComSocFavorites", true);
	ajaxRequest.send(null);	
	return false;
}

/**
Shows the MyComSoc access rights
*/
function renderMyComSocGetFavorites(jsonData)
{
    var myFavorites;
    
    var myFavSearchesFlag = 0;
    var myFavSearchSubjectFlag = 0;
    var myFavSearchPublicationsFlag = 0;
    var myFavSearchAuthorFlag = 0;
    
    var myPersonalLibData = "";
    try
    {
        myFavorites = eval('(' + jsonData + ')');
        
        if ( myFavorites.myDLData.userFavorite == null )
        {
            throw myFavorites.myDLData.statusMessage;
        }
    }
    catch(e)
    {
	    document.getElementById("manageAccountInfo").innerHTML = "<HR>View/Edit Favorites".bold() + showAlertInformation(2, "Invalid MyComSoc Favorites data: " + e.bold());
	    return;
    }
    hideTopNotification();
    
    access.myComSoc.myFavSearches = "<TABLE  border=0 width=99% style='margin: 0px'>";
    access.myComSoc.myFavSearches += "<TR style='font-size: 9px; color: green;'><TD align=center>Remove</TD><TD>&nbsp;</TD><TD>Notify</TD></TR>";
    
    access.myComSoc.myFavSearchSubject = "<TABLE  border=0 width=99% style='margin: 0px'>";
    access.myComSoc.myFavSearchSubject += "<TR style='font-size: 9px; color: green;'><TD align=center>Remove</TD><TD>&nbsp;</TD><TD>Notify</TD></TR>";
    
    access.myComSoc.myFavSearchPublications = "<TABLE  border=0 width=99% style='margin: 0px'>";
    access.myComSoc.myFavSearchPublications += "<TR style='font-size: 9px; color: green;'><TD align=center>Remove</TD><TD>&nbsp;</TD><TD>Notify</TD></TR>";
    
    access.myComSoc.myFavSearchAuthor = "<TABLE  border=0 width=99% style='margin: 0px'>";
    access.myComSoc.myFavSearchAuthor += "<TR style='font-size: 9px; color: green;'><TD align=center>Remove</TD><TD>&nbsp;</TD><TD>Notify</TD></TR>";
    try
    {
        // My Favorite  - Author
        for (var i = 0; i < myFavorites.myDLData.userFavorite.favoriteAuthors.length; i++) 
        {
            var author = myFavorites.myDLData.userFavorite.favoriteAuthors[i];
            access.myComSoc.myFavSearchAuthor += "<TR>";
            access.myComSoc.myFavSearchAuthor += "<TD width=5%><INPUT title='Remove from MyComSoc Favorites' type=button value='X' style='height: 20px; width=18px' class='cancelButton' onclick=access.myComSoc.removeFavoriteItem("+ author.person.personID + ",'author') /></TD>";
            access.myComSoc.myFavSearchAuthor += "<TD>";
            //access.myComSoc.myFavSearchAuthor += "<A href=# class=searchResultItem";
            //access.myComSoc.myFavSearchAuthor += " onclick=\"searchResults.getAuthorData(" + author.person.personID +")\">";
            access.myComSoc.myFavSearchAuthor += "<A class=searchResultItem href=?author=" + author.person.personID +" onclick=\"return searchResults.getAuthorData(" + author.person.personID +")\">";
		    access.myComSoc.myFavSearchAuthor += getProperName(author.person.givenName) + " " + getProperName(author.person.middleName) + " " + getProperName(author.person.surName);
            access.myComSoc.myFavSearchAuthor += "</A> ";
            access.myComSoc.myFavSearchAuthor += "</TD>";
            access.myComSoc.myFavSearchAuthor += "<TD width=5%><INPUT id=favAuthorCheckItem" + author.notifyID +  " type=checkbox " + (( author.notifyByMail == 'T') ? "CHECKED" : "") + " onclick=access.myComSoc.setFavoriteNotifyItem(this.id,'PersonInterestOfUser',"+ author.notifyID + ") /></TD>";
            access.myComSoc.myFavSearchAuthor += "</TR>";
            myFavSearchAuthorFlag = 1;
        }
        
        // My Favorite  - Subjects
        for (var i = 0; i < myFavorites.myDLData.userFavorite.favoriteSubjects.length; i++) 
        {
            var subject = myFavorites.myDLData.userFavorite.favoriteSubjects[i];
            access.myComSoc.myFavSearchSubject += "<TR>";
            access.myComSoc.myFavSearchSubject += "<TD width=5%><INPUT title='Remove from MyComSoc Favorites' type=button value='X' style='height: 20px; width=18px' class='cancelButton' onclick=access.myComSoc.removeFavoriteItem("+ subject.searchID + ",'subjectOntology') /></TD>";
            access.myComSoc.myFavSearchSubject += "<TD>";                                    
            //access.myComSoc.myFavSearchSubject += "<A href=# class=searchResultItem";
            //access.myComSoc.myFavSearchSubject += " onclick=\"treeSub.getSubjectResults('" + subject.ontologyNodeID + "','" + subject.displayLabel + "') \">";
            access.myComSoc.myFavSearchSubject += "<A class=searchResultItem href=?subject=" + subject.ontologyNodeID + "&term=" + escape(subject.displayLabel) + " onclick=\"return treeSub.getSubjectResults('" + subject.ontologyNodeID + "','" + subject.displayLabel + "')\">";
            access.myComSoc.myFavSearchSubject += subject.displayLabel + "</A>";
            access.myComSoc.myFavSearchSubject += "</TD>";			        
            access.myComSoc.myFavSearchSubject += "<TD width=5%><INPUT id=favSubSearchCheckItem" + (subject.searchID) +  " type=checkbox " + (( subject.notifyByMail == 'T') ? "checked" : "") + " onclick=access.myComSoc.setFavoriteNotifyItem(this.id,'FavoriteSearchOfUser',"+ subject.searchID + ") /></TD>";
            access.myComSoc.myFavSearchSubject += "</TR>";
            myFavSearchSubjectFlag = 1;
        }
            
        // My Favorite  - Publications
        for (var i = 0; i < myFavorites.myDLData.userFavorite.favoritePublications.length; i++) 
        {
            var publication = myFavorites.myDLData.userFavorite.favoritePublications[i];
            access.myComSoc.myFavSearchPublications += "<TR>";
            access.myComSoc.myFavSearchPublications += "<TD width=5%><INPUT title='Remove from MyComSoc Favorites' type=button value='X' style='height: 20px; width=18px' class='cancelButton' onclick=access.myComSoc.removeFavoriteItem("+ publication.searchID + ",'publicationOntology') /></TD>";
            access.myComSoc.myFavSearchPublications += "<TD>";                                    
            //access.myComSoc.myFavSearchPublications += "<A href=# class=searchResultItem";
            //access.myComSoc.myFavSearchPublications += " onclick=\"treeSub.getSubjectResults('" + publication.ontologyNodeID + "','" + publication.displayLabel + "') \">";
            access.myComSoc.myFavSearchPublications += "<A class=searchResultItem href=?publication=" + publication.ontologyNodeID + "&label=" + escape(publication.displayLabel) + " onclick=\"return treePub.pubGetPublicationResults('" + publication.ontologyNodeID + "','" + convertSpecialCharacters(publication.displayLabel) + "')\">";
		    access.myComSoc.myFavSearchPublications += publication.displayLabel + "</A>";
            access.myComSoc.myFavSearchPublications += "</TD>";
            access.myComSoc.myFavSearchPublications += "<TD width=5%><INPUT id=favSubSearchCheckItem" + (publication.searchID) +  " type=checkbox " + (( publication.notifyByMail == 'T') ? "checked" : "") + " onclick=access.myComSoc.setFavoriteNotifyItem(this.id,'FavoriteSearchOfUser',"+ publication.searchID + ") /></TD>";
            access.myComSoc.myFavSearchPublications += "</TR>";
            myFavSearchPublicationsFlag = 1;
        }
        
        // My Favorite  - Keyword searches
        for (var i = 0; i < myFavorites.myDLData.userFavorite.favoriteKeywords.length; i++) 
        {
            var keyword = myFavorites.myDLData.userFavorite.favoriteKeywords[i];
            access.myComSoc.myFavSearches += "<TR>";
            access.myComSoc.myFavSearches += "<TD width=5%><INPUT title='Remove from MyComSoc Favorites' type=button value='X' style='height: 20px; width=18px' class='cancelButton' onclick=access.myComSoc.removeFavoriteItem("+ keyword.searchID + ",'search') /></TD>";
            access.myComSoc.myFavSearches += "<TD>";                           
            //access.myComSoc.myFavSearches += "<A href=# class=searchResultItem";
            //access.myComSoc.myFavSearches += " onclick=\"submitKeywordSearch('" + convertSpecialCharacters(keyword.query) + "','keyword')\">";
            access.myComSoc.myFavSearches += "<A class=searchResultItem href=?keyword=" + escape(keyword.query) + " onclick=\"return submitKeywordSearch('" + convertSpecialCharacters(keyword.query) +"','keyword')\">";
            access.myComSoc.myFavSearches += convertSpecialCharacters(keyword.displayLabel) + "</A>";
            access.myComSoc.myFavSearches += "</TD>";
            access.myComSoc.myFavSearches += "<TD width=5%><INPUT id=favSearchCheckItem" + (keyword.searchID) +  " type=checkbox " + (( keyword.notifyByMail == 'T') ? "checked" : "") + " onclick=access.myComSoc.setFavoriteNotifyItem(this.id,'FavoriteSearchOfUser',"+ keyword.searchID + ") /></TD>";
            access.myComSoc.myFavSearches += "</TR>";
            myFavSearchesFlag = 1;
	    }	
	    
	    // My Personal Library - with remove option
	    for (var i = 0; i < myFavorites.myDLData.pubRefs.length; i++) 
        {
            myFavorites.myDLData.pubRefs[i].articleAbstract = null; //Abstract is not require
            
            myPersonalLibData += "<TR>";
            myPersonalLibData += "<TD width=4% valign=top><INPUT title='Remove from MyComSoc Personal Library' type=button value='X' style='height: 20px; width=18px' class='cancelButton' onclick=access.myComSoc.removeFavoriteItem(" + myFavorites.myDLData.pubRefs[i].articleID + ",'article') /></TD>";
            myPersonalLibData += "<TD class=searchResultItem>" + ((i+1) + ". ").bold() + searchResults.prepareNewPubRefInfo(myFavorites.myDLData.pubRefs[i]) + "<BR><BR></TD>";
            myPersonalLibData += "<TD width=5%></TD>";
            myPersonalLibData += "</TR>";
        }
        if ( myPersonalLibData == "" )
            myPersonalLibData = "<TABLE  border=0 width=99% cellpadding=5px><TR><TD class=searchResultItem>No favorite papers</TD></TR></TABLE>";
        else
            myPersonalLibData = "<TABLE  border=0 width=99% cellpadding=5px>" + myPersonalLibData + "</TABLE>";
        
        document.getElementById("myComSocMyPersonalLib").innerHTML = myPersonalLibData;  
    }
    catch(e)
    {
        alert("Exception - Unable to parse MyComSoc Favorites data!");
        if ( myFavSearchesFlag != 0 )
            myFavSearchesFlag = 0;
        if ( myFavSearchSubjectFlag != 0 )
            myFavSearchSubjectFlag = 0;
        if ( myFavSearchPublicationsFlag != 0 )
            myFavSearchPublicationsFlag = 0;
        if ( myFavSearchAuthorFlag != 0 )
            myFavSearchAuthorFlag = 0;
    }
    
    access.myComSoc.myFavSearches += "</TABLE>";
    access.myComSoc.myFavSearchSubject += "</TABLE>";
    access.myComSoc.myFavSearchPublications += "</TABLE>";
    access.myComSoc.myFavSearchAuthor += "</TABLE>";
    
    if ( myFavSearchesFlag == 0 )
        access.myComSoc.myFavSearches = "<p class=searchResultItem style='padding: 2px;margin: 2px;'>No favorite searches</p>" ;
    if ( myFavSearchSubjectFlag == 0 )
        access.myComSoc.myFavSearchSubject = "<p class=searchResultItem style='padding: 2px;margin: 2px;'>No favorite subjects</p>" ;
    if ( myFavSearchPublicationsFlag == 0 )
        access.myComSoc.myFavSearchPublications = "<p class=searchResultItem style='padding: 2px;margin: 2px;'>No favorite publications</p>" ;
    if ( myFavSearchAuthorFlag == 0 )
        access.myComSoc.myFavSearchAuthor = "<p class=searchResultItem style='padding: 2px;margin: 2px;'>No favorite authors</p>" ;   	    
    
    var tempData = "";
	tempData = "<HR>View/Edit Favorites".bold() + "<BR>";
	tempData += "<BR>" + "" + components.getFormHTML2Component("<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-search.gif> My Favorite Searches", access.myComSoc.myFavSearches || "None");	     
    tempData += "<BR>" + "" + components.getFormHTML2Component("<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-subjects.gif> My Favorite Subjects", access.myComSoc.myFavSearchSubject || "None");	     
    tempData += "<BR>" + "" + components.getFormHTML2Component("<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-publications.gif> My Favorite Publications", access.myComSoc.myFavSearchPublications || "None");	     
    tempData += "<BR>" + "" + components.getFormHTML2Component("<IMG src=" + ROOT_URL + "images/mycomsoc/myarticles-authors.gif> My Favorite Authors", access.myComSoc.myFavSearchAuthor || "None");
    
    document.getElementById("manageAccountInfo").innerHTML = tempData;
    document.getElementById("myComSocMyArticlesBody").style.display = "none";   //Clear MyArticle panel box
    
	historyIsItResultDetails = 0;
	parityHistory.setInHistory();
	
	/* IMPORTANT!!  -  Opening or showing favorite items after updating w.r.t the operations 'Delete' or 'Nodify' */
    if ( autoOpenFavorites == true )
    {
        //autoOpenFavorites = false;
        //access.myComSoc.myComSocGetFavorites();
    }
}

/**
Remove favourite item
*/
function removeFavoriteItem(itemRef, deleteType)
{
    var targetURL = ROOT_DB_URL;
     
    if ( confirmAlert("Do you want to delete this item?\n\nClick OK to delete") == false )  return;
    
    var ajaxRequest = zXmlHttp.createRequest();	
    
    if ( deleteType== "article" )
    {
        targetURL += "removefavorite.action?deleteFavoriteArticle=true&articleID=" + itemRef;
        showTopNotification();//showNotification('myComSocMyPersonalLib', 'Loading...', 0);
    }
    else if ( deleteType== "author" )
    {
        targetURL += "removefavorite.action?deleteFavoritePerson=true&authorID=" + itemRef;
        showTopNotification();//showNotification('manageAccountInfo', 'Loading...', 0);    
    }
    else    //ontology
    {
        targetURL += "removefavorite.action?deleteSearch=true&searchID=" + itemRef;
        showTopNotification();//showNotification('manageAccountInfo', 'Loading...', 0);    
    }
    
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200)
			{
				//access.myComSoc.getMyComSocInfo();
				access.myComSoc.renderMyComSocGetFavorites(ajaxRequest.responseText);
				
				/* !!! To refresh the tree automatically after removing subject/publication from MyComSoc */
		        if ( deleteType == "subjectOntology" )
				    treeSub.getSubTreeInitData();
				else if ( deleteType == "publicationOntology" )
			        treePub.getPubTreeInitData();	    
				
				//autoOpenFavorites = true;
				
				/* The below function supposed get called, but it is not possible.  Because,
				 * it causes synchronization problem.  After calling getMyComSocInfo(), it
				 * takes some time to prepare myComSoc data and request for server data, so
				 * before it completes this transaction, it cannot be called.  If called,
				 * the output may not be updated.  So, the solution is to call this function
				 * after completion of the above function.
				 */
				//access.myComSoc.myComSocEditFavorites(); 
			}
			else
			{	
				alert("ComSoc Layout Preferences - Unable to get response!: " + ajaxRequest.responseText);	
				if ( deleteType== "article" )
				    hideNotification('myComSocMyPersonalLib');
				else
				    hideNotification('manageAccountInfo');
			}
		}
	}
	//ajaxRequest.open("GET", ROOT_DB_URL + "removefavorite.action?deleteSearch=true&searchID=" + favoriteItemId, true);		
	ajaxRequest.open("GET", targetURL + "&nullParam=" + new Date(), true);		
	ajaxRequest.send(null);
}

/**
Remove favourite item
*/
function setFavoriteNotifyItem(favCheckBoxItemId, favItemType, favoriteItemNo)
{   
    var notifyStatus = "True";
    notifyStatus = ( document.getElementById("" + favCheckBoxItemId).checked == true ) ? "True" : "False";
    
    //showNotification('manageAccountInfo', 'Loading...', 0);
    
    var ajaxRequest = zXmlHttp.createRequest();	
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
				//ajaxRequest.responseText - It is not required
				//access.myComSoc.getMyComSocInfo();
				//access.myComSoc.myComSocGetFavorites();
				//access.myComSoc.renderMyComSocGetFavorites(ajaxRequest.responseText);
				access.myComSoc.renderSetFavoriteNotifyItem(ajaxRequest.responseText);
				
				//autoOpenFavorites = true;
				/* The below function supposed get called, but it is not possible.  Because,
				 * it causes synchronization problem.  After calling getMyComSocInfo(), it
				 * takes some time to prepare myComSoc data and request for server data, so
				 * before it completes this transaction, it cannot be called.  If called,
				 * the output may not be updated.  So, the solution is to call this function
				 * after completion of the above function.
				 */
				//access.myComSoc.myComSocEditFavorites(); 
			}
			else
			{	
				alert("ComSoc Layout Preferences - Unable to get response!: " + ajaxRequest.responseText);	
			}
		}
	}
	//http://192.168.10.25:8181/comsocdl/setfavorite.action?notifyStatus=True&favoriteType=FavoriteSearchOfUser&searchID=6652
	ajaxRequest.open("GET", ROOT_DB_URL + "setfavorite.action?notifyStatus=" + notifyStatus + "&favoriteType=" + favItemType +"&searchID=" + favoriteItemNo + "&nullParam=" + new Date(), true);		
	ajaxRequest.send(null);
}

function renderSetFavoriteNotifyItem(jsonData)
{   
    var favoriteData = null;
    try
	{
	    favoriteData = eval('(' + jsonData + ')');
	}
	catch(e)
	{
	    alert("Unable to parse favorites after set operation");
		return false;
	}
	if ( favoriteData.userFavorite.statusMessage == "Success" || favoriteData.userFavorite.statusMessage == "success" )
	{
	    //Do nothing
	}
	else
	    alert("Unable to set notify option: " + favoriteData.userFavorite.statusMessage);
	
	access.myComSoc.myComSocGetFavorites();
}

/**
Shows the MyComSoc access rights
*/
function myComSocViewRights()
{
	var ajaxRequest = zXmlHttp.createRequest();	
	showTopNotification();	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
			    access.myComSoc.renderMyComSocViewRights(ajaxRequest.responseText);											
			}
			else
			{	
				hideTopNotification();
				alert("ComSoc Access Rights - Unable to get response!: " + ajaxRequest.responseText);
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "subscriptionInfo.action?nullParam=" + new Date(), true);
	ajaxRequest.send(null);	
	return false;
}

/**
Render MyComSoc ccess rights
*/
function renderMyComSocViewRights(jsonObject)
{
    var ajaxRequest = zXmlHttp.createRequest();	
	showTopNotification();	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();	
	
			    var tempAccessRightsData = "Access Rights".bold() + "<BR>" + ajaxRequest.responseText;	    
                
                var temp = tempAccessRightsData;
                tempAccessRightsData = temp.replaceAll("<img src=\"","<img src=\"" + ROOT_URL );
                //alert("pre=" + tempAccessRightsData );
                //alert("pre=" + temp.replaceAll("<img src=\"","<img src=\"" + ROOT_URL ) );
                document.getElementById("manageAccountInfo").innerHTML = "<HR>" + tempAccessRightsData;    	    	    
                access.myComSoc.updateMyComSocViewRights(jsonObject);
			}
			else
			{	
				hideTopNotification();	
	            alert("ComSoc Access Rights - Unable to get response!xyz: " + ajaxRequest.responseText);
			}
		}
	}
	ajaxRequest.open("GET", ROOT_URL + "html/global/accessRights.htm", true);		
	ajaxRequest.send(null);	
	return false;
}

/**
Update access rights' information
*/
function updateMyComSocViewRights(jsonObject)
{
    var accessObject;
    var object;
    var iconType = ROOT_URL + "images/mycomsoc/checkbox.gif";
    
    try
    {
        //accessObject = eval('(' + "{\"subscriptionInfo\":[\"NONMEMBER\",\"NONMEMBER\",\"NONMEMBER\",\"CI\",\"TNSM\",\"EPPUNIVREGULAR\"]}" + ')');
	    accessObject = eval('(' + jsonObject + ')');  
	    
	    if ( accessObject.subscriptionInfo == null )
	    {
	        document.getElementById("manageAccountInfo").innerHTML = "<HR>Access Rights".bold() + showAlertInformation(2, "No subscription information found");
	        //document.getElementById("manageAccountInfo").innerHTML = "<HR>Purchase History List".bold() + showAlertInformation(2, e);
	        return false;
	    }
    }
    catch(e)
    {
	    alert("Unable to parse access rights data!\n\n" + e.description); 
	    return false;
    }
    
    // Hash all items of access rights to ease the access
    for(var i = 0; i < accessObject.subscriptionInfo.length; i++)  
    {
        tempHash.setItem(accessObject.subscriptionInfo[i], 1);            
    }
    
    // Determine the type of icon for various access rights
    if ( tempHash.hasItem('EPPUNIVLEGACY') == true || tempHash.hasItem('EPPLEGACY') == true )
    {
        iconType = ROOT_URL + "images/mycomsoc/checkboxOrangeChecked.gif";
    }
    else if ( tempHash.hasItem('EPPREGULAR') == true || tempHash.hasItem('EPPUNIVREGULAR') == true )
    {
        iconType = ROOT_URL + "images/mycomsoc/checkboxGreyChecked.gif";
    }
    
    // Set check for all items of one who is subscribed either EPPREGULAR or EPPUNIVREGULAR, or EPPUNIVLEGACY or EPPLEGACY
    for(var i = 0; i < myComSocAccessRights.length; i++)  
    {
        document.getElementById("accessRightsItem" + myComSocAccessRights[i]).src = iconType;                        
    }
    
    // Set the check option for particular one who is subscribed for that
    for(var i = 0; i < accessObject.subscriptionInfo.length; i++)  
    {
        object = document.getElementById("accessRightsItem" + accessObject.subscriptionInfo[i]);
        
        if ( object != null )
            object.src = ROOT_URL + "images/mycomsoc/checkboxOrangeChecked.gif";   
    }
    
    document.getElementById("myComSocMyArticlesBody").style.display = "none";   //Clear MyArticle panel box
    
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();
	            
    printer.printerPageType = 0;
    printer.showPrinterPageLink();
    
    hideNotification('manageAccountInfo');
}

/**
Show the myComSoc layout preferences
*/
function myComSocEditLayout()
{
    var ajaxRequest = zXmlHttp.createRequest();	
    showTopNotification();	
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
				hideTopNotification();
                access.myComSoc.renderMyComSocEditLayout(ajaxRequest.responseText);																			
			}
			else
			{	
				hideTopNotification();
				alert("ComSoc Layout Preferences - Unable to get response!: " + ajaxRequest.responseText);				
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "edituserprefs.action?nullParam=" + new Date());
	ajaxRequest.send(null);	
	return false;
}

/**
Render myComSoc layout preferences
*/
function renderMyComSocEditLayout(jsonData)
{
    var layoutOptions;
    var tempLayoutData;
    var fontType = 1;
    try
    {
        layoutOptions = eval('(' + jsonData + ')');		    
    }
    catch(e)
    {
	    alert("Unable to parse myComSoc layout preferences data!\n\n" + e.description); 
	    return false;
    }
    
    if ( layoutOptions.userPreference.fontSize == null)
    {
        document.getElementById("manageAccountInfo").innerHTML = "<HR>Edit Layout".bold() + "<BR>" + showAlertInformation(2, layoutOptions.userPreference.statusMessage);
        return false;
    }
    else if ( layoutOptions.userPreference.fontSize == "small")
        fontType = 1;
    else if ( layoutOptions.userPreference.fontSize == "medium")
        fontType = 2;
    else if ( layoutOptions.userPreference.fontSize == "large")
        fontType = 3;
    else if ( layoutOptions.userPreference.fontSize == "xlarge")
        fontType = 4;
    
    tempLayoutData = "<HR>Edit Layout".bold() + "<BR>";
    tempLayoutData += "<INPUT id=myComSocFontSize1 type=radio onclick='access.myComSoc.selectFont(1)' /> Small Font<BR>";	    	    	    	    
    tempLayoutData += "<INPUT id=myComSocFontSize2 type=radio onclick='access.myComSoc.selectFont(2)' /> Medium Font<BR>";	    	    	    	    
    tempLayoutData += "<INPUT id=myComSocFontSize3 type=radio onclick='access.myComSoc.selectFont(3)' /> Large Font<BR>";	    	    	    	    
    tempLayoutData += "<INPUT id=myComSocFontSize4 type=radio onclick='access.myComSoc.selectFont(4)' /> X-Large Font<BR><BR>";	    	    	
    tempLayoutData += "<INPUT id=updateFont class=button_blue type=button value='Update' onclick='access.myComSoc.updateMyComSocFontsize(" + fontType + ")'/>";	    	    	    	    
    
    document.getElementById("manageAccountInfo").innerHTML = tempLayoutData;;	    
    document.getElementById("myComSocFontSize" + fontType).checked = true;
    
    global.variables.myComSocUserFont = layoutOptions.userPreference.fontSize;
    document.getElementById("myComSocMyArticlesBody").style.display = "none";   //Clear MyArticle panel box
    
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();
}

/**
Set or Reset font ratio option
*/
function selectFont(radioId)
{
    for( var i = 1; i <= 4; i ++)
    {
        document.getElementById("myComSocFontSize" + i).checked = false;
    }	    
    document.getElementById("myComSocFontSize" + radioId).checked = true;
    document.getElementById("updateFont").onclick = function() { access.myComSoc.updateMyComSocFontsize(radioId); };	    
}

/**
Update MyComSoc's user settings for fontsize
*/
function updateMyComSocFontsize(radioId)
{
	var fontSizes = new Array('small','medium','large','xlarge')
	var ajaxRequest = zXmlHttp.createRequest();	
    showTopNotification();	
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
				hideTopNotification();
				access.myComSoc.renderMyComSocEditLayout(ajaxRequest.responseText);
				alert("New font size updated!");				
			}
			else
			{	
				hideTopNotification();
				alert("ComSoc Layout Preferences - Unable to get response!: " + ajaxRequest.responseText);					
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "edituserprefs.action?setFontSize=" + fontSizes[radioId-1] + "&nullParam=" + new Date(), true);		
	ajaxRequest.send(null);
}

/**
Set font size after login
*/
function setLoginFontsize()
{
    var ajaxRequest = zXmlHttp.createRequest();	
    
    ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			if (ajaxRequest.status == 200) 
			{
			    var jsonData, layoutOptions;
			    try
                {
                    layoutOptions = eval('(' + ajaxRequest.responseText + ')');
                    if ( layoutOptions.userPreference.fontSize == null)
                    {
                        alert("Invalid font size - " + layoutOptions.userPreference.fontSize); 
                        return false;
                    }
                    else
                        global.variables.myComSocUserFont = layoutOptions.userPreference.fontSize;                    
                }
                catch(e)
                {
	                /* Do nothing if unable to get font size */
	                return false;
                }
			}
			else
			{	
				alert("ComSoc Layout Preferences - Unable to get response!: " + ajaxRequest.responseText);				
			}
		}
	}
	ajaxRequest.open("GET", ROOT_DB_URL + "edituserprefs.action?nullParam=" + new Date());
	ajaxRequest.send(null);
}

/**
Show my Purchases history records
*/
function myComSocViewPurchases(purchaseHistorySortByType)
{
    var ajaxRequest = zXmlHttp.createRequest();	
	showTopNotification();
	
	if ( purchaseHistorySortByType == null || purchaseHistorySortByType == "" ) 
	    purchaseHistorySortByType = "Date";
	    
    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200) 
		    {
		        hideTopNotification();
		        access.myComSoc.renderComSocViewPurchases(ajaxRequest.responseText,purchaseHistorySortByType);   		        
		    } 
		    else
		    {	
                hideTopNotification();
                alert("Unable to get purchased articles!: " + ajaxRequest.responseText);                
		    }
	    }
    }
    // NEW URL JAn 2009    >>>>>>    comsocdl/showshoppingcart.action?path=ShoppingCartHistory&sortByTitle=true
    ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?path=ShoppingCartHistory" + ((purchaseHistorySortByType == "Title") ? "&sortByTitle=true" : "" ) + "&nullParam=" + new Date());
    //ajaxRequest.open("GET", "http://localhost:8181/comsocdl/html/showshoppingcart.actionKaninMyComSocPurchaseHistory3", true);		
    ajaxRequest.send(null);
	return false;
}

/**
Renders the Purchases history records
*/
function renderComSocViewPurchases(jsonData, purchaseHistorySortByType)
{
	var purchaseHistoryObject;
	var purchaseHistoryData;
	var purchaseArticleType;
	var isTutorial = 0;
	
	try
    {
        purchaseHistoryObject = eval('(' + jsonData + ')');		    
        
        if ( purchaseHistoryObject.shoppingCartData.purcheHistory == null || !document.getElementById("manageAccountInfo") )
        {
            throw purchaseHistoryObject.shoppingCartData.statusMessage;
        }
	}
    catch(e)
    {
        if ( document.getElementById("manageAccountInfo") )
	        document.getElementById("manageAccountInfo").innerHTML = "<HR>Purchase History List".bold() + showAlertInformation(2, e);
	    return;
    }
    
    purchaseHistoryData = "<HR>Purchase History List".bold();
    purchaseHistoryData += "<DIV class='monthIssue' id=purchaseHistorySortByOptions>";
    purchaseHistoryData += "<BR><IMG src='" + ROOT_URL + "images/sortBy.gif' />" + "Sort By:  ".bold();   
    purchaseHistoryData += "<SPAN id=purchaseHistorySortByOption style='color: gray' class=searchResultItem></SPAN>";
    purchaseHistoryData += "</DIV>";
    purchaseHistoryData += "<TABLE  border=0 cellpadding=5>";
    
    var docs;
    for(var i = 0; i < purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles.length; i ++)
    {
        docs = purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles[i];
        
        if( i%2 == 0 )
	        purchaseHistoryData += "<TR style='background-color: #E7EDF8; padding-top: 5px' onmouseover=setBgColor('purchaseItemNo" + i + "','silver') onmouseout=setBgColor('purchaseItemNo" + i + "','#E7EDF8')>";
	    else
	        purchaseHistoryData += "<TR style='background-color: #F3F6FA; padding-top: 5px' onmouseover=setBgColor('purchaseItemNo" + i + "','silver') onmouseout=setBgColor('purchaseItemNo" + i + "','#F3F6FA')>";
	    
	    purchaseHistoryData += "<TD class=searchResultItem id=purchaseItemNo" + i + ">";
	    purchaseHistoryData += ((i+1) + ". ").bold();
        
	    if ( docs.dataInstance.description == "" )
	    {
	        //Article Title
	        purchaseArticleType = "article";	        
	        purchaseHistoryData +=  searchResults.prepareNewPubRefInfo(docs.dataInstance.miniArticle);	        
	    }
	    else
	    {
	        //Tutorial Title
	        purchaseArticleType = "tutorial";
	        purchaseHistoryData += docs.dataInstance.description;// + "(Tutorial)";	        
	    }
	    
	    purchaseHistoryData += ".</TD>";
	    purchaseHistoryData += "<TD class='myComSocContent monthIssue' width=120px>";
	    
	  if ( purchaseArticleType == "article" )
	  {
	        //purchaseHistoryData += "<A target=_blank href="+ ROOT_DB_URL + "forwarddata.action?eid=" + docs.dataInstance.miniArticle.articleID +">";
	        //purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('','eid=" + docs.dataInstance.miniArticle.articleID + "')\">";
	        if(docs.dataInstance.miniArticle.formats != null && docs.dataInstance.miniArticle.formats.length ==2)
	        {
	        	if(docs.dataInstance.miniArticle.formats[0].formatType == "preview\/html" || docs.dataInstance.miniArticle.formats[1].formatType == "preview\/html")
	        	isTutorial = 1;
	        }
	        for(var j = 0; j < docs.dataInstance.miniArticle.formats.length; j++)
	        {
	            if ( docs.dataInstance.miniArticle.formats[j].formatType == "application\/pdf" )
	            {
	                purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + docs.dataInstance.miniArticle.articleID + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
	                purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/pdf.gif' />"+ " PDF ".bold();
	                purchaseHistoryData += "</A>";
	            }
	            else if ( docs.dataInstance.miniArticle.formats[j].formatType == "text\/html" )
	            {
	                purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + docs.dataInstance.miniArticle.articleID + "','text\/html')\"  class=\"searchResultItem headerImagesId\">";
	                if(isTutorial == 1)
	                {
	                	//purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Full Tutorial ".bold();
	                	purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " View Full Tutorial ".bold();
	                	isTutorial = 0;
	                }
	                else
	                	purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " HTML ".bold();
	                purchaseHistoryData += "</A>";
	            }
	            /*else if ( docs.dataInstance.miniArticle.formats[j].formatType == "preview\/html" )
		    	{
			    	 purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + docs.dataInstance.miniArticle.articleID + "','preview\/html')\"  class=\"searchResultItem headerImagesId\">";
			    	 purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Preview ".bold();
			    	 purchaseHistoryData += "</A><br>";
	            }*/
	            if ( j < docs.dataInstance.miniArticle.formats.length - 1 )
	                purchaseHistoryData += " <br> ";
	        }	         
        }
        else if(purchaseArticleType == "tutorial")
	{
		purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + docs.dataInstance.id + "','text\/html')\"  class=\"searchResultItem headerImagesId\">";
		purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/download.png' style='border: 0px' />"+ " View Full Tutorial ".bold() + "</A>";            
	}
        else
        {
            //purchaseHistoryData += "<A target=_blank href="+ ROOT_DB_URL + "forwarddata.action?iid=" + docs.dataInstance.id +">";
            
            purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + docs.dataInstance.id + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
            purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/download.png' style='border: 0px' />Download File</A>";
            /*
            for(var j = 0; j < docs.dataInstance.miniArticle.formats.length; j++)
	        {
	            if ( docs.dataInstance.miniArticle.formats[j].formatType == "application\/pdf" )
	            {
	                purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + docs.dataInstance.id + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
	                purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/pdf.gif' />"+ " PDF ".bold();
	                purchaseHistoryData += "</A>";
	            }
	            else if ( docs.dataInstance.miniArticle.formats[j].formatType == "text\/html" )
	            {
	                purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + docs.dataInstance.id + "','text\/html')\"  class=\"searchResultItem headerImagesId\">";
	                //purchaseHistoryData += "<A href=# onclick=\"return searchResults.getFullText(" + articleID +",'type=text\/html&')\" class=\"searchResultItem headerImagesId\">";              
	                purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " HTML ".bold();
	                purchaseHistoryData += "</A>";
	            }
	            if ( j < docs.dataInstance.miniArticle.formats.length - 1 )
	                purchaseHistoryData += " | ";
	        }
	        */
        }
        purchaseHistoryData += "</TD>";
        //purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/download.png' style='border: 0px' />Download File</A></TD>";
	    purchaseHistoryData += "</TR>";
    }
    purchaseHistoryData += "</TABLE>";
    
    if ( purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles.length == 0 )
        //purchaseHistoryData = "<HR>Purchase History List".bold() + "<BR>" + "No articles/tutorials found in purchase history";
        purchaseHistoryData = "<HR>Purchase History List".bold() + "<BR>" + showAlertInformation(1, "No articles/tutorials found in purchase history");
    
    document.getElementById("manageAccountInfo").innerHTML = purchaseHistoryData;
    document.getElementById("myComSocMyArticlesBody").style.display = "none";   //Clear MyArticle panel box
    
    if ( purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles.length != 0 )
    {
        if( purchaseHistorySortByType == 'Title' )
            access.myComSoc.setPurchaseHistorySortByType(purchaseHistorySortByType);
        else
            access.myComSoc.setPurchaseHistorySortByType(purchaseHistorySortByType); 
    }    
    historyIsItResultDetails = 0;
	parityHistory.setInHistory();
	components.penel.hideTopArticle();
}


function viewPurchasesFromComSocPortal(purchaseHistorySortByType)
{
    var ajaxRequest = zXmlHttp.createRequest();	
		
	if ( purchaseHistorySortByType == null || purchaseHistorySortByType == "" ) 
	    purchaseHistorySortByType = "Date";
	    
    ajaxRequest.onreadystatechange = function()
    {
	    if(ajaxRequest.readyState == 4)
	    {
		    if (ajaxRequest.status == 200) 
		    {
				access.myComSoc.renderComSocPortalViewPurchases(ajaxRequest.responseText,purchaseHistorySortByType);   		        
		    } 
		    else
		    {	
                alert("Unable to get purchased articles!: " + ajaxRequest.responseText);                
		    }
	    }
    }
    // NEW URL JAn 2009    >>>>>>    comsocdl/showshoppingcart.action?path=ShoppingCartHistory&sortByTitle=true
    ajaxRequest.open("GET", ROOT_DB_URL + "showshoppingcart.action?path=ShoppingCartHistory" + ((purchaseHistorySortByType == "Title") ? "&sortByTitle=true" : "" ) + "&nullParam=" + new Date());
    ajaxRequest.send(null);
	return false;
}


function renderComSocPortalViewPurchases(jsonData, purchaseHistorySortByType)
{
	var purchaseHistoryObject;
	var purchaseHistoryData;
	var purchaseArticleType;
	var isTutorial = 0;
	
	try
    {
        purchaseHistoryObject = eval('(' + jsonData + ')');		    
        
        if ( purchaseHistoryObject.shoppingCartData.purcheHistory == null || !document.getElementById("queryResultsDivId") )
        {
            throw purchaseHistoryObject.shoppingCartData.statusMessage;
        }
	}
    catch(e)
    {
        if ( document.getElementById("queryResultsDivId") )
	        document.getElementById("queryResultsDivId").innerHTML = "<HR>Purchase History List".bold() + showAlertInformation(2, e);
	    return;
    }
    
    purchaseHistoryData = "<HR>Purchase History List".bold();

    purchaseHistoryData += "<TABLE  border=0 cellpadding=5>";
    
    var docs;
    for(var i = 0; i < purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles.length; i ++)
    {
        docs = purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles[i];
        
        if( i%2 == 0 )
	        purchaseHistoryData += "<TR style='background-color: #E7EDF8; padding-top: 5px' onmouseover=setBgColor('purchaseItemNo" + i + "','silver') onmouseout=setBgColor('purchaseItemNo" + i + "','#E7EDF8')>";
	    else
	        purchaseHistoryData += "<TR style='background-color: #F3F6FA; padding-top: 5px' onmouseover=setBgColor('purchaseItemNo" + i + "','silver') onmouseout=setBgColor('purchaseItemNo" + i + "','#F3F6FA')>";
	    
	    purchaseHistoryData += "<TD class=searchResultItem id=purchaseItemNo" + i + ">";
	    purchaseHistoryData += ((i+1) + ". ").bold();
        
	    if ( docs.dataInstance.description == "" )
	    {
	        //Article Title
	        purchaseArticleType = "article";	        
	        purchaseHistoryData +=  searchResults.prepareNewPubRefInfo(docs.dataInstance.miniArticle);	        
	    }
	    else
	    {
	        //Tutorial Title
	        purchaseArticleType = "tutorial";
	        purchaseHistoryData += docs.dataInstance.description;// + "(Tutorial)";	        
	    }
	    
	    purchaseHistoryData += ".</TD>";
	    purchaseHistoryData += "<TD class='myComSocContent monthIssue' width=120px>";
	    
	 if ( purchaseArticleType == "article" )
	 {
	        if(docs.dataInstance.miniArticle.formats != null && docs.dataInstance.miniArticle.formats.length ==2)
	        {
	        	if(docs.dataInstance.miniArticle.formats[0].formatType == "preview\/html" || docs.dataInstance.miniArticle.formats[1].formatType == "preview\/html")
	        	isTutorial = 1;
	        }
	        for(var j = 0; j < docs.dataInstance.miniArticle.formats.length; j++)
	        {
	            if ( docs.dataInstance.miniArticle.formats[j].formatType == "application\/pdf" )
	            {
	                purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + docs.dataInstance.miniArticle.articleID + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
	                purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/pdf.gif' />"+ " PDF ".bold();
	                purchaseHistoryData += "</A>";
	            }
	            else if ( docs.dataInstance.miniArticle.formats[j].formatType == "text\/html" )
	            {
	                purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + docs.dataInstance.miniArticle.articleID + "','text\/html')\"  class=\"searchResultItem headerImagesId\">";
	                if(isTutorial == 1)
	                {
	                	//purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Full Tutorial ".bold();
	                	purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " View Full Tutorial ".bold();
	                	isTutorial = 0;
	                }
	                else
	                	purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " HTML ".bold();
	                purchaseHistoryData += "</A>";
	            }
	            /*else if ( docs.dataInstance.miniArticle.formats[j].formatType == "preview\/html" )
		    	{
		    	 purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('eid=" + docs.dataInstance.miniArticle.articleID + "','preview\/html')\"  class=\"searchResultItem headerImagesId\">";
		    	 purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/html.gif' />"+ " Preview ".bold();
		    	 purchaseHistoryData += "</A><br>";
	            }*/
	            if ( j < docs.dataInstance.miniArticle.formats.length - 1 )
	                purchaseHistoryData += " <br> ";
	        }	        
        }
        else if(purchaseArticleType == "tutorial")
	{
		purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + docs.dataInstance.id + "','text\/html')\"  class=\"searchResultItem headerImagesId\">";
		purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/download.png' style='border: 0px' />"+ " View Full Tutorial ".bold() + "</A>";            
	}
        else
        {
            purchaseHistoryData += "<A href=# onclick=\"searchResults.getFullTextFile('iid=" + docs.dataInstance.id + "','application\/pdf')\"  class=\"searchResultItem headerImagesId\">";
            purchaseHistoryData += "<IMG src='" + ROOT_URL + "images/download.png' style='border: 0px' />Download File</A>";
        }
        purchaseHistoryData += "</TD>";
        purchaseHistoryData += "</TR>";
    }
    purchaseHistoryData += "</TABLE>";
    
    if ( purchaseHistoryObject.shoppingCartData.purcheHistory.purchasedArticles.length == 0 )
        
        purchaseHistoryData = "<HR>Purchase History List".bold() + "<BR><BR>" + showAlertInformation(1, "No articles/tutorials found in purchase history");
    
    document.getElementById("queryResultsDivId").innerHTML = purchaseHistoryData;
}


/**
Set purchase history sort type
*/
function setPurchaseHistorySortByType (sortType)
{
    if ( sortType == "Title" )
    {     
        document.getElementById("purchaseHistorySortByOption").innerHTML = " Title | <A style='color: blue' href=# onclick=access.myComSoc.myComSocViewPurchases('date')>Date</A>";        
    }
    else
    {
        document.getElementById("purchaseHistorySortByOption").innerHTML = " <A href=# style='color: blue' onclick=access.myComSoc.myComSocViewPurchases('Title')>Title</A> | Date";    
    }
}

/**
Renders the Purchases history records
*/
function downloadPurchasedHistoryItems(id)
{
    alert("Download feature under implement: " + id);
    /*
    var downloadPurchasedItems;	
	try
    {
        downloadPurchasedItems = eval('(' + jsonData + ')');		    
	}
    catch(e)
    {
	    alert("Unable mo parse access rights data!\n\n" + e.description); 
	    return;
    }
    //
    */
    window.open(ROOT_DB_URL + "forwarddata.action?eid=" + id +"&nullParam=" + new Date());
    return false;    
}

/**
Prepares the publication reference information

@param pubRefObj JSON publication reference object 
*/
function preparePurchaseRefInfo(pubRefObj)
{
    var pubRefInfoHTML = "";k
    var max;
    
    if( pubRefObj.PubRef.Author != null &&  pubRefObj.PubRef.Author.length == undefined )
    {
        // IF there exist only one author
        pubRefInfoHTML += "<A href=# class=searchResultItem";
	    pubRefInfoHTML += " onclick=\"searchResults.getAuthorData(" + pubRefObj.PubRef.Author.ObjNodeID +")\">";
	    pubRefInfoHTML += validateDataItem("", pubRefObj.PubRef.Author.Name.FirstName);
	    pubRefInfoHTML += validateDataItem(" ", pubRefObj.PubRef.Author.Name.LastName);            
	    pubRefInfoHTML += "</A>, ";   
    }
    else
    {   
        // IF there exist more than one author
        for(var i = 0; pubRefObj.PubRef.Author != null && i < Number(pubRefObj.PubRef.Author.length); i++) // 
	    {	    
	        pubRefInfoHTML += "<A href=# class=searchResultItem";
		    pubRefInfoHTML += " onclick=\"searchResults.getAuthorData(" + pubRefObj.PubRef.Author[i].ObjNodeID +")\">";
		    pubRefInfoHTML += validateDataItem("", pubRefObj.PubRef.Author[i].Name.FirstName);
		    pubRefInfoHTML += validateDataItem(" " + pubRefObj.PubRef.Author[i].Name.LastName);            
		    pubRefInfoHTML += "</A>, ";     		
	    }
	}
	
	pubRefInfoHTML += "<A href=#" + pubRefObj.PubRef.ObjNodeID + " class=searchResultItem";
	pubRefInfoHTML += " onclick=\"searchResults.getArticleData('" + pubRefObj.PubRef.ObjNodeID +"')\">";
	pubRefInfoHTML += validateDataItem("", pubRefObj.PubRef.ArticleTitle).bold();            
	pubRefInfoHTML += "</A>, "; 
    
	pubRefInfoHTML += "" + validateDataItem("", pubRefObj.PubRef.ParentTitle);            
    
	pubRefInfoHTML += validateDataItem(" Vol ", pubRefObj.PubRef.Volume); 
	pubRefInfoHTML += validateDataItem(" no ", pubRefObj.PubRef.IssueNumber) + ", ";  
	
	pubRefInfoHTML += "<A href=# onclick=\"pubGetPublicationResults('" + pubRefObj.PubRef.IssueObjNodeID +"','" + validateDataItem("", 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" )
			    {
				    tempAbstractData += value ; 
				    tempFlag = 1;
			    }
		    }	
	    }
		
	    if ( tempFlag == 0 )	
	        tempAbstractData += "" + pubRefObj.PubRef.SummaryText;
	
	    pubRefInfoHTML += "<BR>" + tempAbstractData.substr(0, 200) + "..."; 	   
	 }
	return pubRefInfoHTML;	
}

/*
Loads the main html page 

@htmlFileURL Static html page of main help page
*/
function getHelpMainHTML(htmlFileURL)
{ 
    showTopNotification();
	var ajaxRequest = zXmlHttp.createRequest();	
	
	ajaxRequest.onreadystatechange = function()
	{
	    if(ajaxRequest.readyState == 4)
		{
		    if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
			    access.myComSoc.renderHelpMainHTML( ajaxRequest.responseText );
			    printer.printerPageType = 3;
	            printer.showPrinterPageLink();	
			} 
			else 
			{	
                hideTopNotification();
                alert("Unable to get help main page!: " + ajaxRequest.responseText);                
			}				
		}       
	}
	
	ajaxRequest.open("GET", ROOT_URL + "html/" + htmlFileURL , true);		
	ajaxRequest.send(null);
	return false;
	 
}

/*
Renders the main html page of help

@htmlData Data of html help page
*/
function renderHelpMainHTML(htmlData)
{ 
    document.getElementById("queryResultsDivId").innerHTML = htmlData;	    
    
    access.myComSoc.getAccessRules("helpPages/overview.htm");
	
	hidePagination();			//pagination.js
	
	searchResults.showSearchResultsBorder();
	searchResults.emptySearchResultsDetails();
	
	components.penel.hideMonthIssues();  // Close notification/dialog content after getting the serach results 
	components.penel.hideCurrentIssues();
	components.penel.hideTopArticle();
}

/*
Loads the html overview page and redirects to "Access Rules" link

@helpPageLinkURL Data of overview help page
*/
function getAccessRules(helpPageLinkURL)
{
	showTopNotification();
	var ajaxRequest = zXmlHttp.createRequest();	
	
	ajaxRequest.onreadystatechange = function()
	{
	    if(ajaxRequest.readyState == 4)
		{
		    if (ajaxRequest.status == 200) 
			{
			    hideTopNotification();
			    document.getElementById('helpLinkPageResult').innerHTML = "<HR style='border-TOP: 1PX SOLID STEELBLUE; HEIGHT: 1PX; margin: 0PX; padding: 0PX;'; />";	
	            document.getElementById('helpLinkPageResult').innerHTML += ajaxRequest.responseText;	            
	            document.getElementById("homebodyId").scrollTop = 950;    //Move the page cursor on top
			} 
			else 
			{	
                hideTopNotification();
                alert("Unable to get help overview page!: " + ajaxRequest.responseText);                
			}				
		}       
	}	
	ajaxRequest.open("GET", ROOT_URL + "html/" + helpPageLinkURL, true);		
	ajaxRequest.send(null);	
}

access.myComSoc = new myComSoc;	/*	<< IMPORTANT!!!  INSTANTIATION OF INNER MyComSoc CLASS TO SUPER CLASS ACCESS	*/

/********************************************** END **************************************************
* myComSoc class serving for My ComSoc Preferences *
*****************************************************************************************************/
