/* MCP Library of reusable JavaScript functions
*
*/

// Global for country code
var GLOBAL_COUNTRY_CODE = "--";

// Global for setting if we are using global country code or not
var USE_GLOBAL_COUNTRY_CODE = false;

/* Retrieves the query string appended to the URL in the browser.
* Helper method and included here as we want a localized query
* string retriever method
*/
function MCPGetQueryString ()
{
	// Retrieves the appended query string (string after ? in URL)
	var queryString = location.search.substring(1, location.search.length);
	return queryString;
}

/* Gets the to be directed URL from the landing page
* This retrieves the actual URL that user wants to direct to after directing them
* to the MCP master URL
*/
function MCPGetActualDirectedURL ()
{
	return document[MCP_MASTER_FORM_NAME].MCP_URL.value;
}

/* Sets the to be directed URL from the landing page
*/
function MCPSetActualDirectedURL (URL)
{
	document[MCP_MASTER_FORM_NAME].MCP_URL.value = URL;
}

/* Gets and sets the to be directed URL from the landing page. This sets for all different currencies
*/
function MCPGetActualDirectedEUR_URL ()
{
	return document[MCP_MASTER_FORM_NAME].MCP_URL_EUR.value;
}


function MCPSetActualDirectedEUR_URL (URL)
{
	document[MCP_MASTER_FORM_NAME].MCP_URL_EUR.value = URL;
}

function MCPGetActualDirectedUSD_URL ()
{
	return document[MCP_MASTER_FORM_NAME].MCP_URL_USD.value;
}


function MCPSetActualDirectedUSD_URL (URL)
{
	document[MCP_MASTER_FORM_NAME].MCP_URL_USD.value = URL;
}

function MCPGetActualDirectedGBP_URL ()
{
	return document[MCP_MASTER_FORM_NAME].MCP_URL_GBP.value;
}


function MCPSetActualDirectedGBP_URL (URL)
{
	document[MCP_MASTER_FORM_NAME].MCP_URL_GBP.value = URL;
}

/* Gets the to be constant to be directed URL from the landing page
*
*/
function MCPGetConstantDirectedURL ()
{
	return document[MCP_MASTER_FORM_NAME].MCP_URL_CONSTANT.value;
}

/* Sets the to be constant directed URL from the landing page
*/
function MCPSetConstantDirectedURL (URL)
{
	document[MCP_MASTER_FORM_NAME].MCP_URL_CONSTANT.value = URL;
}

/* Goes/sends the user to the specified URL
*/
function MCPGo(URL)
{
	// Sets the location to go to in the user browser
	window.location = URL;
}

/* Submits the named form to the Master MCP URL using POST method
*/
function MCPPost(formName)
{
	// Sends user to the master MCP redirect URL if MCP is enabled
	// else send them to the actual form that they wanted to go
	if (IsMCPEnabled())
	{
		if (IsNetscape() == true)
		{
			document.mcpForm.action = MCP_MASTER_URL;
			document.mcpForm.submit();
		}
		else
		{
			formName.action = MCP_MASTER_URL;
			formName.submit();	// Submits the form
		}
	}
	else
	{
		//formName.action = MCPGetActualDirectedURL();
		MCPGo(MCPGetActualDirectedURL());
	}
}

function MCPPost_EUR(formName)
{
	// Sends user to the master MCP redirect URL if MCP is enabled
	// else send them to the actual form that they wanted to go
	if (IsMCPEnabled())
	{
		if (IsNetscape() == true)
		{
			document.mcpForm.action = MCP_MASTER_EUR_URL;
			document.mcpForm.submit();
		}
		else
		{
			formName.action = MCP_MASTER_EUR_URL;
			formName.submit();	// Submits the form
		}
	}
	else
	{
		//formName.action = MCPGetActualDirectedURL();
		MCPGo(MCPGetActualDirectedURL());
	}
}

/* Retrieves the MCP URL using a backup script and by invoking a POST request
*/
function MCPGetCountryCodeUsingHTTPRequest ()
{
	// Country code to return on
	var countryCode = "--";

	// Initialize the HTTP Request object correctly
	// Attempt to create the XMLHttp object through various ways and until one is succesfully created
	var xmlhttp = false;
	try
	{
  		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	}
 	catch (e)
 	{
  		try
  		{
   			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch (E)
  		{
   			xmlhttp = false;
   		}
 	}

	if (!xmlhttp && typeof XMLHttpRequest!=undefined)
	{
  		// For Mozilla based browsers
  		xmlhttp = new XMLHttpRequest();
	}

	// Perform request
	if (xmlhttp)
	{
		// Opens the specified URL, provides callback (anonymous) function (function())
		// Specifies true so that it is asynchronous communication and it will be fast
		xmlhttp.open("GET",MCP_HTTP_REQUEST_URL,true);
 		xmlhttp.onreadystatechange=function()
 		{
   			if (xmlhttp.readyState==4)
   			{
    				// Sets country code
    				countryCode =xmlhttp.responseText;
    				//alert(countryCode);
   			}
  		}
 		xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
 		xmlhttp.send(null);
 	}

 	//alert(countryCode);
 	return countryCode;
}

/* Call back function for the non-asynchronous HTTP Request operation
*/
function MCPHTTPRequesutCallback (xmlhttp)
{
	var countryCode = "--";
   	if (xmlhttp.readyState==4) {
    		countryCode = xmlhttp.responseText;
   	}
   	return countryCode;
}

/* Redirects user to the specified URL after the stated amount of time has elapsed
*/
function MCPRedirect(URL, timeOut)
{
	// Sets a timeout timer/alarm to fire and to call the sending fucntion after
	// the specified time
	setTimeout('MCPGo('+URL+')', timeOut);
}

/* Submits the form to the master MCP URL after a specified
* amount of time has elapsed
*/
function MCPRedirectSubmit (timeOut, formName)
{
	if (IsNetscape())
	{
		setTimeout("MCPPost('" + formName + "')", timeOut);
	}
	else
	{
		window.setTimeout('MCPPost('+ formName + ')', timeOut);
	}
}

/* Submits the form to the master MCP EURO URL after a specified
* amount of time has elapsed
*/
function MCPRedirectSubmit_EUR (timeOut, formName)
{
	window.setTimeout('MCPPost_EUR('+ formName + ')', timeOut);
}

/* Retrieves the domain or root path in which the named page is currently residing
* Attempts to identify by retrieving the page URL
*/
function MCPGetDomain (page)
{
	// Retrieves the page URL
	var entireURL = location.href;

	// Splits on the the page and retrieves the domain name correctly
	var entireURLArray = entireURL.split(page);
	var domain = entireURLArray[0];
	return domain;
}

/* Basic wrapper that initializes the MCP URL correctly
*
*/
function MCPInitializeMCPURL (page)
{
	// Change page to lower case
	page = page.toLowerCase();

	// Replace certain placeholders identifier
	var placeholder = new RegExp(/xxxxx/);
	page = page.replace(placeholder, "XXXXX");

	// Retrieves the domain by examining the page identifier
	var domain = MCPGetDomain(page);

	// Retrieves the current MCP URL value
	// Uses constant if it has been defined
	var currentMCPURL;

	if (MCPGetConstantDirectedURL() != '')
	{
		currentMCPURL = MCPGetConstantDirectedURL();
	}
	else
	{
		currentMCPURL = MCPGetActualDirectedURL();
		MCPSetConstantDirectedURL(currentMCPURL);	// Initialize the constant value
	}

	// Concatenates the domain to the current MCP URL value
	currentMCPURL = domain + currentMCPURL;

	// Sets the MCP URL value
	MCPSetActualDirectedURL(currentMCPURL);
}

function MCPInitializeMCPURL_ALL (page)
{
	// Change page to lower case
	page = page.toLowerCase();

	// Replace certain placeholders identifier
	var placeholder = new RegExp(/xxxxx/);
	page = page.replace(placeholder, "XXXXX");

	// Retrieves the domain by examining the page identifier
	var domain = MCPGetDomain(page);

	// Retrieves the current MCP URL value
	// Uses constant if it has been defined
	var currentMCPURL;
	var currentMCPURL_EUR;
	var currentMCPURL_USD;
	var currentMCPURL_GBP;


	if (MCPGetConstantDirectedURL() != '')
	{
		currentMCPURL 		= MCPGetConstantDirectedURL();
		currentMCPURL_EUR 	= MCPGetConstantDirectedURL();
		currentMCPURL_GBP 	= MCPGetConstantDirectedURL();
		currentMCPURL_USD 	= MCPGetConstantDirectedURL();
	}
	else
	{
		currentMCPURL = MCPGetActualDirectedURL();
		currentMCPURL_EUR = MCPGetActualDirectedEUR_URL();
		currentMCPURL_GBP = MCPGetActualDirectedGBP_URL();
		currentMCPURL_USD = MCPGetActualDirectedUSD_URL();
		MCPSetConstantDirectedURL(currentMCPURL_EUR);	// Initialize the constant value (allows back button)
	}

	// Concatenates the domain to the current MCP URL value
	currentMCPURL = domain + currentMCPURL;
	currentMCPURL_EUR = domain + currentMCPURL_EUR;
	currentMCPURL_GBP = domain + currentMCPURL_GBP;
	currentMCPURL_USD = domain + currentMCPURL_USD;

	// Sets the MCP URL value
	MCPSetActualDirectedURL(currentMCPURL);
	MCPSetActualDirectedUSD_URL(currentMCPURL_USD);
	MCPSetActualDirectedEUR_URL(currentMCPURL_EUR);
	MCPSetActualDirectedGBP_URL(currentMCPURL_GBP);
}

/* Returns true if MCP is enabled else returns false
*/
function IsMCPEnabled ()
{
	return ENABLE_MCP;
}

/* Returns true if supplied country code is an European Union country
*/
function IsEUR (countryCode)
{
	// Goes thru all the elements in the EUR dollar lookup table
	// If country code matches, break and sets flag to true
	var flag = false;

	if (countryCode == undefined)
		countryCode = GetCountryCode();

	for (var x =0; x < EUR_ARRAY.length; x++)
	{
		if (countryCode == EUR_ARRAY[x])
		{
			flag = true;
			break;
		}
	}

	return flag;
}

/* Returns true if supplied country code is a GBP country
*/
function IsGBP (countryCode)
{
	// Goes thru all the elements in the Sterling pound lookup table
	// If country code matches, break and sets flag to true
	var flag = false;

	if (countryCode == undefined)
		countryCode = GetCountryCode();

	for (var x =0; x < GBP_ARRAY.length; x++)
	{
		if (countryCode == GBP_ARRAY[x])
		{
			flag = true;
			break;
		}
	}

	return flag;
}

/* Gets MCP country code correctly from the query string in the
* browser URL. Returns the MCP country code
*/
function GetCountryCode ()
{
	// Checks if there are any meaningful values for the global country code
	if ((GetGlobalCountryCode() != "--") && (GetGlobalCountryCode() != undefined) && (GetGlobalCountryCode() != null) && (GetGlobalCountryCode() != ""))
	{
		return GetGlobalCountryCode();
	}
	else	// Proceed to process normally
	{
		// Initialize global country code
		if (GetUseGlobalCountryCode())
		{
			SetGlobalCountryCode(MCPGetCountryCodeUsingHTTPRequest());
		}

		// Gets the entire query string
		var queryString = MCPGetQueryString();

		// Splits on ampersand sign to retrieves elements in query string
		var queryStringArray = queryString.split('&' /*ampersand*/);
		var countryString;	// Contains MCP identifier with country code
		var countryStringIndex;

		if (queryStringArray[0])
		{
			// Loops through element by element of the query string array, looking for
			// the mcp identifier
			for (var x=0; x < queryStringArray.length; x++)
			{
				// Regular expression obecjt to match on the mcp identifier
				var regExp = new RegExp(MCP_IDENTIFIER);
				var currentElement = queryStringArray[x];

				// Does the regular expression match the current element?
				if (regExp.exec(currentElement))
				{
					// Sets the country string value correctly and stops looping
					countryString = currentElement;
					countryString = countryString.substring(0,6);	// Ensures valid values
					countryStringIndex = x;
					break;
				}
			}
			if (countryString == undefined)
			{
				countryString = queryString;
			}
		}
		else	// If no elements found, use entire query string
		{
			countryString = queryString;
		}

		// Retrieves the country code and returns it
		var countryCodeArray = countryString.split('=');	/*mcp=SG*/
		var countryCode = countryCodeArray[1];

		// If country code is not defined, lets try to get the value from the cookie
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
				countryCode = GetMCPCookieStringCountryCode();
		}

		// If cookie retrieval fail, lets get the value using HTTP Request
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
				countryCode = MCPGetCountryCodeUsingHTTPRequest();
		}

		// Checks again to see if country code was not correctly set, if that is the case,
		// lets create a meaningful empty value
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
				countryCode = '--';
		}
		else
		{
			// Meaningful value obtained, sets it to the global country code
			SetGlobalCountryCode(countryCode);
		}

		return countryCode;
	}
}
/* Gets MCP country code correctly from the query string in the
* browser URL. Returns the MCP country code
*/
function GetCountryCodeWithOtherParam (noOfPrecedingParam)
{
	if (noOfPrecedingParam == undefined)
	{
		noOfPrecedingParam = 1;
	}

	// Checks if there are any meaningful values for the global country code
	if ((GetGlobalCountryCode() != "--") && (GetGlobalCountryCode() != undefined) && (GetGlobalCountryCode() != null) && (GetGlobalCountryCode() != ""))
	{
		return GetGlobalCountryCode();
	}
	else	// Proceed to process normally
	{
		// Initialize global country code
		if (GetUseGlobalCountryCode())
		{
			SetGlobalCountryCode(MCPGetCountryCodeUsingHTTPRequest());
		}

		// Gets the entire query string
		var queryString = MCPGetQueryString();

		// Splits on ampersand sign to retrieves elements in query string
		var queryStringArray = queryString.split('&' /*ampersand*/);
		var countryString;	// Contains MCP identifier with country code
		var countryStringIndex;
		var entireStringUsed;

		if (queryStringArray[noOfPrecedingParam])
		{
			// Loops through element by element of the query string array, looking for
			// the mcp identifier
			for (var x=0; x < queryStringArray.length; x++)
			{
				// Regular expression obecjt to match on the mcp identifier
				var regExp = new RegExp(MCP_IDENTIFIER);
				var currentElement = queryStringArray[x];

				// Does the regular expression match the current element?
				if (regExp.exec(currentElement))
				{
					// Sets the country string value correctly and stops looping
					countryString = currentElement;
					countryString = countryString.substring(0,6);	// Ensures valid values
					countryStringIndex = x;
					break;
				}
			}
			entireStringUsed = 0;
		}
		else	// If no elements found, use entire query string
		{
			countryString = queryString;
			entireStringUsed = 1;
		}

		var countryCodeArray;
		var countryCode;

		// Retrieves the country code and returns it
		if (entireStringUsed)
		{
			countryCodeArray = countryString.split('mcp=');	/*mcp=SG*/
		}
		else
		{
			countryCodeArray = countryString.split('=');	/*mcp=SG*/

		}
		countryCode = countryCodeArray[1];


		// If country code is not defined, lets try to get the value from the cookie
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
				countryCode = GetMCPCookieStringCountryCode();
		}

		// If cookie retrieval fail, lets get the value using HTTP Request
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
				countryCode = MCPGetCountryCodeUsingHTTPRequest();
		}

		// Checks again to see if country code was not correctly set, if that is the case,
		// lets create a meaningful empty value
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
				countryCode = '--';
		}
		else
		{
			// Meaningful value obtained, sets it to the global country code
			SetGlobalCountryCode(countryCode);
		}

		return countryCode;
	}



}

/* Gets MCP country code in a customized fashion
*/
function GetCustomCountryCode()
{
	var countryCode = "";

	// Gets using query string way, lets see if any value has been appended to URL
	countryCode = GetCountryCode();

	if (countryCode == "" || countryCode == undefined || countryCode == null || countryCode == '--')
	{
		// Since traditional query string way yielded nothing, lets attempt to get it from
		// any cookies stored
		countryCode = GetMCPCookieStringCountryCode();
	}

	// Perform one final error correction
	if (countryCode == "" || countryCode == undefined || countryCode == null)
	{
		countryCode = '--';
	}

	return countryCode;
}

/* Retrieves the type of currency based on the country code passed
* in. Returns the type of currency being used
*/
function GetCurrencyType (countryCode)
{
	var currencyType;

	// Checks if MCP is enabled or not
	if (IsMCPEnabled())
	{
		// Checks if country code was not correctly passed in
		if (countryCode == undefined || countryCode == null || countryCode == "")
			countryCode = GetCountryCode();

		if (IsEUR(countryCode))
			currencyType = "EUR";
		else if (IsGBP(countryCode))
			currencyType = "GBP";
		else
			currencyType = "USD";
	}
	else
	{
		currencyType = "USD";
	}

	return currencyType;
}

/* Sets the form field for country code
*/
function SetCountryCode (form, value)
{
	if (value == undefined)
		form.CountryCode.value = GetCountryCode();
	else
		form.CountryCode.value = value;
}

/* Sets the type of currency in the form field
*/
function SetCurrencyType (form, value)
{
	if (value == undefined)
		form.CurrencyType.value = GetCurrencyType(GetCountryCode());
	else
		form.CurrencyType.value = value;
}

/* Sets the currency denomination value to form field
*/
function SetCurrencyDenomination (form, value)
{
	if (value == undefined)
		form.CurrencyDenomination.value = GetCurrencyDenomination();
	else
		form.CurrencyDenomination.value = value;
}

/* Gets the correct converted price based on price passed in.
* Returns converted price
*/
function GetPrice (price, countryCode)
{
	// Checks type country user is from and then performs necessary conversion
	// Conversion rates defined in configuration file
	var convertedPrice = price;

	// Checks if MCP is enabled or not
	if (IsMCPEnabled())
	{
		// Checks if country code was not correctly passed in
		if (countryCode == undefined || countryCode == null || countryCode == "" || countryCode == "--")
		{
			countryCode = GetCountryCode();
			//alert(countryCode);
		}

		if (IsEUR(countryCode))
		{
			// Converts the price based on the type of product bought
			// Looks up the correct price from the correct look up table
			// using the product name as the key
			convertedPrice = MCP_EUR_PRICES[price];

			// If no identifiable product, lets just perform any necessary currency conversion
			if (convertedPrice == NaN || convertedPrice == null || convertedPrice == undefined || convertedPrice == 0 || convertedPrice == "")
			{
				convertedPrice = price;
				convertedPrice *= USD_TO_EUR_RATE;
			}
		}
		else if (IsGBP(countryCode))
		{
			convertedPrice = MCP_GBP_PRICES[price];

			if (convertedPrice == NaN || convertedPrice == null || convertedPrice == undefined || convertedPrice == 0 || convertedPrice == "")
			{
				convertedPrice = price;
				convertedPrice *= USD_TO_GBP_RATE;
			}
		}
		else
		{
			convertedPrice = MCP_STANDARD_PRICES[price];

			if (convertedPrice == NaN || convertedPrice == null || convertedPrice == undefined || convertedPrice == 0 || convertedPrice == "")
			{
				convertedPrice = price;
				convertedPrice *= 1;
			}
		}
	}
	else
	{
		convertedPrice = MCP_STANDARD_PRICES[price];

		if (convertedPrice == NaN || convertedPrice == null || convertedPrice == undefined || convertedPrice == 0 || convertedPrice == "")
		{
			convertedPrice = price;
			convertedPrice *= 1;
		}
	}

	// Converts to the required decimal places
	convertedPrice = FormatCurrency(convertedPrice);
	return convertedPrice;
}

/* Gets correct currency denomination (as HTML encoded text)
*/
function GetCurrencyDenomination(countryCode)
{
	// Determines the correct currency then return the correct denomination
	var denomination;

	// Checks if MCP is enabled or not
	if (IsMCPEnabled())
	{
		// Checks if country code was not correctly passed in
		if (countryCode == undefined || countryCode == null || countryCode == "")
			countryCode = GetCountryCode();

		if (IsEUR(countryCode))
			denomination = EUR_SIGN;
		else if (IsGBP(countryCode))
			denomination = GBP_SIGN;
		else
			denomination = USD_SIGN;
	}
	else
	{
		denomination = USD_SIGN;
	}

	return denomination;
}

/* Prints currency denomination to user screen
*/
function PrintCurrencyDenomination (countryCode)
{
	var denomination = GetCurrencyDenomination(countryCode);
	document.write(denomination);
}

/* Gets correct currency denomination (as HTML encoded text)
*/
function GetCurrencyDenominationWithParamURL(countryCode)
{
	// Determines the correct currency then return the correct denomination
	var denomination;

	// Checks if MCP is enabled or not
	if (IsMCPEnabled())
	{
		// Checks if country code was not correctly passed in
		if (countryCode == undefined || countryCode == null || countryCode == "")
			countryCode = GetCountryCodeWithOtherParam();

		if (IsEUR(countryCode))
			denomination = EUR_SIGN;
		else if (IsGBP(countryCode))
			denomination = GBP_SIGN;
		else
			denomination = USD_SIGN;
	}
	else
	{
		denomination = USD_SIGN;
	}

	return denomination;
}

/* Prints currency denomination to user screen
*/
function PrintCurrencyDenominationWithParamURL (countryCode)
{
	var denomination = GetCurrencyDenominationWithParamURL(countryCode);
	document.write(denomination);
}


/* Prints the currency type out to screen
*/
function PrintCurrencyType (currencyType)
{
	document.write(currencyType);
}

/* Prints price to user browser, pass in price to print
*/
function PrintPrice (price)
{
	// Gets converted price then prints it out to browser
	var convertedPrice = GetPrice(price);
	document.write(convertedPrice);

}

/* Prints price by using user defined country code
*/
function PrintPriceByCountryCode (price, countryCode)
{
	// Gets converted price then prints it out to browser
	var convertedPrice = GetPrice(price, countryCode);
	document.write(convertedPrice);
}

/* Sets the MCP Cookie string (recall JavaScript cookies are
* really just like string objects) with correct country code
* currency type and currency denomination. To achiveve this we store
* multiple cookies as each cookie can only have 1 name and value pair
*/
function SetMCPCookie(countryCode, currencyType, currencyDenomination)
{
	// Lets create the expiry date correctly
	var today = new Date();
	var expiry = new Date(today.getTime() + MCP_COOKIE_EXPIRY * 24 * 60 * 60 * 1000);

	// Set the corresponding cookies for the corresponding values that we are storing
	// Store each value into different cookie
	SetCookie(MCP_COOKIE_COUNTRYCODE, countryCode, expiry, '/','inklineglobal.com');
	SetCookie(MCP_COOKIE_CURRENCYTYPE, currencyType, expiry, '/','inklineglobal.com');
	SetCookie(MCP_COOKIE_CURRENCYDENOMINATION, currencyDenomination, expiry, '/','inklineglobal.com');
}

/* Gets the entire/all MCP Cookie string (including, name, expiry date, etc)
*/
function GetMCPCookieStringAll ()
{
	// Forms the return string, concatenates name value pairs on delimeters
	var cookieStringCountryCode = MCP_COOKIE_COUNTRYCODE + '=' + GetMCPCookieStringCountryCode() + ';';
	var cookieStringCurrencyType = MCP_COOKIE_CURRENCYTYPE + '=' + GetMCPCookieStringCurrencyType() + ';';
	var cookieStringCurrencyDenomination = MCP_COOKIE_CURRENCYDENOMINATION + '=' + GetMCPCookieStringCurrencyDenomination();

	var cookieStringAll = cookieStringCountryCode + cookieStringCurrencyType + cookieStringCurrencyDenomination;
	return cookieStringAll;
}

/* Gets the country code from the MCP Cookie string only
*/
function GetMCPCookieStringCountryCode ()
{
	var cookieString = GetCookie(MCP_COOKIE_COUNTRYCODE);
	if (cookieString == undefined || cookieString == null || cookieString == "")
		cookieString = "--";

	return cookieString;
}

/* Gets the currency type from the MCP Cookie string only
*/
function GetMCPCookieStringCurrencyType ()
{
	return GetCookie(MCP_COOKIE_CURRENCYTYPE);
}

/* Gets the currency denomination from the MCP Cookie string only
*/
function GetMCPCookieStringCurrencyDenomination ()
{
	return GetCookie(MCP_COOKIE_CURRENCYDENOMINATION);
}

/* Gets the global country code
*/
function GetGlobalCountryCode()
{
	return GLOBAL_COUNTRY_CODE;
}

/* Sets the global country code
*/
function SetGlobalCountryCode(countryCode)
{
	GLOBAL_COUNTRY_CODE = countryCode;
}

/* Gets the global country code
*/
function GetUseGlobalCountryCode()
{
	return USE_GLOBAL_COUNTRY_CODE;
}

/* Sets the global country code
*/
function SetUseGlobalCountryCode(enable)
{
	USE_GLOBAL_COUNTRY_CODE = enable;
}

/* Format currency to 2 decimal places
*/
function FormatCurrency(amount)
{
	// Stores the amount as a floating point number
	var i = parseFloat(amount);

	// If not a number, returns 0.00
	if(isNaN(i))
	{
		i = 0.00;
	}

	// Changes negative values to positive valus so that can work on it
	var minus = '';
	if (i < 0)
	{
		minus = '-';
	}
	// Uses absolute values to work on
	i = Math.abs(i);

	// Rounds number to nearest 1/100
	i = parseInt((i + .005) * 100);
	i = i / 100;

	// Prepares to pad with trailing zeros if necessary
	s = new String(i);
	if (s.indexOf('.') < 0)
	{
		s += '.00';
	}
	if(s.indexOf('.') == (s.length - 2))
	{
		s += '0';
	}

	// Puts back any minus sign
	s = minus + s;
	return s;
}

function IsNetscape ()
{
	if (parseInt(navigator.appVersion) >= 4)
	{
  		if(navigator.appName == "Netscape")
  		{
    			return true;
    	}
  }
  return false;
}

