/* ======================================================================

TIBCO Solutions Network JavaScript Library.

NAME: 		TSN Common Functions
VERSION:	0.1 BETA
AUTHOR: 	James Milne
DATE:	 	7/14/2002

COMMENT: 	This file contains JS functions that are used by the TSN Portal.

========================================================================= */


var KBHomeAddress= GetProtocol() + GetHost() + "/kb";

function GetProtocol()
{
	var location_array0 = document.location.toString();
	var location_array1 = location_array0.substring(0,location_array0.indexOf("//")+2);
	return location_array1;
}


function GetURI()
{
	var location_array0 = document.location.toString();
	var location_array1 = location_array0.substring(location_array0.indexOf("//")+2,location_array0.length);
	var location_array2 = location_array1.substring(location_array1.indexOf("/"),location_array1.length);
	return location_array2;
}


function GetHost()
{
	var location_array0 = document.location.toString();
	var location_array1 = location_array0.substring(location_array0.indexOf("//")+2,location_array0.length);
	var location_array2 = location_array1.substring(0,location_array1.indexOf("/"));
	return location_array2;
}

// GetParameter will return the value of myParameter.
// For example: http://server.com/page.htm?UserName=James
// 		GetParameter("UserName") would return James.

function GetParameter(myParameter)
{
	var address;
	var LCaddress; // LowerCase Address
	var pos;
	var tmpString;
	
	address=document.location.toString();
	LCaddress=address.toLowerCase();
	myParameter=myParameter.toLowerCase();

  	if (address) {		    
	    // Find the URL parameter
	    pos=LCaddress.indexOf(myParameter);
	    if (pos > 1) {
	    	pos=pos + myParameter.length + 1; // length of myParameter and +1 for '='
		    tmpString=address.substring(pos);
			// Check for myParam=myValue  or myParam=myValue&...
			    if (tmpString.indexOf('&') > 1) { // Has '&' 
			    	myValue=tmpString.substring(0,tmpString.indexOf('&')) } // trim the '&'
			    else {
			    	myValue=tmpString; } // No '&'}

			return myValue;
	  	}
	  	else {
	      return null;}
	}
}
// GetParentParameter will return the value of myParameter FROM THE PARENT PAGE.
// For example: http://server.com/page.htm?UserName=James
// 		GetParameter("UserName") would return James.

function GetParentParameter(myParameter)
{
	var address;
	var LCaddress;
	var pos;
	var tmpString;
	
	address=parent.document.location.toString();
	LCaddress=address.toLowerCase();
	myParameter=myParameter.toLowerCase();

  	if (address) {		    
	    // Find the URL parameter
	    pos=LCaddress.indexOf(myParameter);
	    if (pos > 1) {
	    	pos=pos + myParameter.length + 1; // length of myParameter and +1 for '='
		    tmpString=address.substring(pos);
			// Check for myParam=myValue  or myParam=myValue&...
			    if (tmpString.indexOf('&') > 1) { // Has '&' 
			    	myValue=tmpString.substring(0,tmpString.indexOf('&')) } // trim the '&'
			    else {
			    	myValue=tmpString; } // No '&'}

			return myValue;
	  	}
	  	else {
	      return null;}
	}
}

