var g_httpCgiUrl = "/wcm/idcplg?IdcService=SS_GET_PAGE&";

/////////////////////////////////////////////////////////////////////////////
// Function : NavNode (constructor)
// Comments :
/////////////////////////////////////////////////////////////////////////////
function NavNode(id, label, href, parent)
{
	this.m_parent = null;
	this.m_level = 0;

	if (parent)
	{
		this.m_parent = parent;
		this.m_level = parent.m_level+1;
	}

	this.m_id = id;

	// assume that m_label will most often be used directly as HTML
	this.m_rawlabel = label;

	label = label.replace(/&/g, '&amp;');
	label = label.replace(/</g, '&lt;');
	label = label.replace(/>/g, '&gt;');
	label = label.replace(/"/g, '&quot;');

	this.m_label = label;

	this.m_href = href;
	this.m_subNodes = new Array();

	var argValues = NavNode.arguments;
	var argCount = NavNode.arguments.length;

	for (i = 4 ; i < argCount ; i++)
	{
		var attrName = argValues[i].split("==")[0];
		var attrValue = argValues[i].split("==")[1];

		eval("this.cp_" + attrName + " = '" + attrValue + "';");
	}

	NavNode.prototype.addNode = addNode;
	NavNode.prototype.isSelected = isSelected;
}

/////////////////////////////////////////////////////////////////////////////
// Function : addNode
// Comments :
/////////////////////////////////////////////////////////////////////////////
function addNode(id, label, href)
{
	var newIndex = this.m_subNodes.length;
	var newNode = new NavNode(id, label, href, this);

	var argValues = addNode.arguments;
	var argCount = addNode.arguments.length;

	for (i = 3 ; i < argCount ; i++)
	{
		var attrName = argValues[i].split("==")[0];
		var attrValue = argValues[i].split("==")[1];

		eval("newNode.cp_" + attrName + " = '" + attrValue + "';");
	}

	this.m_subNodes[newIndex] = newNode;
	return newNode;
}

/////////////////////////////////////////////////////////////////////////////
// Function : isSelected
// Comments :
/////////////////////////////////////////////////////////////////////////////
function isSelected()
{
    var pos = window.location.href.lastIndexOf("/");
    var docname = window.location.href.substring(pos+1, window.location.href.length);

    pos = this.m_href.lastIndexOf("/");
    var myname = this.m_href.substring(pos+1, this.m_href.length);

    if (docname == myname)
		return true;
	else
		return false;
}

/////////////////////////////////////////////////////////////////////////////
// Function : isTrue
// Comments :
/////////////////////////////////////////////////////////////////////////////
function isTrue( boolStr )
{
	if( boolStr.length > 0 )
	{
		var boolChar = boolStr.substring(0,1).toUpperCase();
		if( ( boolChar == '1' ) || ( boolChar == 'T' ) )
		{
			return true;
		}
	}

	return false;
}

/////////////////////////////////////////////////////////////////////////////
// Function : customSectionPropertyExists
// Comments :
/////////////////////////////////////////////////////////////////////////////
function customSectionPropertyExists(csp)
{
	return (typeof csp != _U && csp != null);
}

/////////////////////////////////////////////////////////////////////////////
// Function : getCustomSectionProperty
// Comments :
/////////////////////////////////////////////////////////////////////////////
function getCustomSectionProperty(csp)
{
	if (customSectionPropertyExists(csp))
	{
		return csp;
	}
	else
	{
		return "";
	}
}

/////////////////////////////////////////////////////////////////////////////
// Function : link
// Comments :
/////////////////////////////////////////////////////////////////////////////
function link(dDocName,ssTargetNodeId)
{
	if ((dDocName.search("http://") != -1) || (dDocName.search("https://") != -1))
		window.open(dDocName);
	else
	{
		var newUrl = "";
		newUrl += g_httpCgiUrl;
		newUrl += "ssDocName=" + dDocName;

		var currentUrl = "" + window.location;

		// Continue propagation of the "SSContributor" parameter
		if( SSContributor )
		{
			var paramName = "SSContributor=";
			var pos = currentUrl.indexOf( paramName );
			if( pos != -1 )
			{
				var subStr = currentUrl.substring( pos+paramName.length, pos+paramName.length+1 );
				if( isTrue( subStr ) )
				{
					newUrl += "&" + paramName + "true";
				}
			}
		}

		// Continue propagation of the "previewId" parameter
		var previewId = "previewId=";
		var posStart = currentUrl.indexOf( previewId );
		if( posStart != -1 )
		{
			var posEnd = currentUrl.indexOf("&", posStart);
			var value = "";
			if (posEnd == -1)
			{
				value = currentUrl.substring(posStart+previewId.length, currentUrl.length);
			}
			else
			{
				value = currentUrl.substring(posStart+previewId.length, posEnd);
			}
			newUrl += "&" + previewId + value;
		}

		// We now always add the node that the link is on as part of the URl also.
		if( g_ssSourceNodeId != _U && g_ssSourceNodeId != null )
			newUrl += "&ssSourceNodeId=" + g_ssSourceNodeId;

		// If we have a specific target nodeId then add that to the URL also
		if( ssTargetNodeId != _U && ssTargetNodeId != null )
			newUrl += "&ssTargetNodeId=" + ssTargetNodeId;

		// Navigate to the new url
		window.location = newUrl;
	}
}

/////////////////////////////////////////////////////////////////////////////
// Function : nodelink
// Comments :
/////////////////////////////////////////////////////////////////////////////
function nodelink(nodeId)
{
	var newUrl = "";
	newUrl += g_httpCgiUrl;
	newUrl += "nodeId=" + nodeId;

	var currentUrl = "" + window.location;

	// Continue propagation of the "SSContributor" parameter
	if( SSContributor )
	{
		var paramName = "SSContributor=";
		var pos = currentUrl.indexOf( paramName );
		if( pos != -1 )
		{
			var subStr = currentUrl.substring( pos+paramName.length, pos+paramName.length+1 );
			if( isTrue( subStr ) )
			{
				newUrl += "&" + paramName + "true";
			}
		}
	}

	// Continue propagation of the "previewId" parameter
	var previewId = "previewId=";
	var posStart = currentUrl.indexOf( previewId );
	if( posStart != -1 )
	{
		var posEnd = currentUrl.indexOf("&", posStart);
		var value = "";
		if (posEnd == -1)
		{
			value = currentUrl.substring(posStart+previewId.length, currentUrl.length);
		}
		else
		{
			value = currentUrl.substring(posStart+previewId.length, posEnd);
		}
		newUrl += "&" + previewId + value;
	}

	// We now always add the node that the link is on as part of the URl also.
	if( g_ssSourceNodeId != _U && g_ssSourceNodeId != null )
		newUrl += "&ssSourceNodeId=" + g_ssSourceNodeId;

	// Navigate to the new url
	window.location = newUrl;
}
/////////////////////////////////////////////////////////////////////////////
var g_navNode_Root = new NavNode('2162','TradeGov','javascript:cnslink(0)',null);
g_navNode_1=g_navNode_Root.addNode('2184','Iraq','javascript:cnslink(1)','secondaryUrlVariableField==region2');
g_navNode_1_0=g_navNode_1.addNode('2310','Iraq\x20Invest','javascript:cnslink(2)','secondaryUrlVariableField==region2');
g_navNode_2=g_navNode_Root.addNode('2185','Afghanistan','javascript:cnslink(3)','secondaryUrlVariableField==region2');
// introduced by connection server
var g_cnsnodes = new Array();
g_cnsnodes[0] = '/index.asp';
g_cnsnodes[1] = '/iraq/index.asp';
g_cnsnodes[2] = '/iraq/IraqInvest/index.asp.asp';
g_cnsnodes[3] = '/afghanistan/index.asp';
function cnslink(pageid) {
var newUrl = '';
newUrl += g_prefixToStaticRoot;
newUrl += g_cnsnodes[pageid];
window.location = newUrl;
}