//it returns true if the parameter is empty
function isEmpty(Param)
{ return ((Param == null) || (Param.length == 0)) }

//It parses and returns query string value.
//It return ""(empty string) if there is no query string name in the parameter
//argument checking is case insentive in this method
function GET(argname){
	query = location.search.substring(1);
	pairs = query.split("&");
	for(i=0; i<pairs.length; i++){
		key   = pairs[i].split("=")[0];
		value = pairs[i].split("=")[1];
		if(key.toLowerCase()  == argname.toLowerCase()){
			return value;
		}
	}
	return "";
}

///The caller must pass the publication id and server domain name to display the latest/archive issue.
function GetClientLinksBody(PublicationID,ServerDomain)
{
	if (isEmpty(ServerDomain))
		Alert("Server Domain information is missing.");

	issueID = GET("IssueId");
	sortBy = GET("sortby");
	ByTopic = GET("ByTopic");
	if(issueID != "")
	{
		document.write('<iframe id="clientlinks" name="clientlinks" src ='+ServerDomain+'/ArchiveIssue.aspx?PubId='+PublicationID+'&IssueID='+issueID+' width="546px" height="600px" frameborder="0" scrolling="Yes"></iframe>');
	}
	else
	{
		///display message is saying that publication id is not found.
		if (isEmpty(PublicationID))
		{
			Alert("Publication ID is not found.");
		}
		else
		{
			//checking the current request topic
			//call ArchiveIssuesByTopic.aspx page if the request is topic
			if (sortBy.toLowerCase() == 'topic')
			{
				document.write('<iframe id="clientlinks" name="clientlinks" src ='+ServerDomain+'/ArchiveIssuesByTopic.aspx?PubId='+PublicationID+' width="546px" height="600px" frameborder="0" scrolling="Yes"></iframe>');
			}
			else
			{
				//checking the current request geography
				//call ArchiveIssuesByGeography.aspx page if the request is geography
				//display Archive issue list if we do not see any specific request(topic or Geography)
				if (sortBy.toLowerCase() == 'geography')
				{
					document.write('<iframe id="clientlinks" name="clientlinks" src ='+ServerDomain+'/ArchiveIssuesByGeography.aspx?PubId='+PublicationID+' width="546px" height="600px" frameborder="0" scrolling="Yes"></iframe>');
				}
				else
				{
				    if(ByTopic !="")
				    {
				        document.write('<iframe id="clientlinks" name="clientlinks" src ='+ServerDomain+'/ArchiveIssueList.aspx?PubId='+PublicationID+'&ByTopic='+ByTopic+' width="546px" height="600px" frameborder="0" scrolling="Yes"></iframe>');
				    }
				    else 
				    {
					    document.write('<iframe id="clientlinks" name="clientlinks" src ='+ServerDomain+'/ArchiveIssueList.aspx?PubId='+PublicationID+' width="546px" height="600px" frameborder="0" scrolling="Yes"></iframe>');
					}
				}
			}
		}
	}


}
