/************************************************************************************/
/*
 * Disclaimer: Coremetrics is not responsible for hosting or maintenance or this file
 *
 */
/************************************************************************************/
/*===========================GLOBAL VARIABLES ===============================*/
// options for debug mode when sending tag:
// 1: only alert
// 2: only send tag
// 3: alert & send tag
var G_PS_DEBUG_MODE = 2;

// current page url
var G_PS_URL_PATH = "" + document.location.href.toLowerCase();

/*========================= END GLOBAL VARIABLES =============================*/


/*========================= MARKETING VARIABLES ==================================*/
	if(GetManualMMC()!=null)	{
		var manual_cm_mmc = GetManualMMC();
	}

/*========================= END MARKETING VARIABLES ==============================*/


/*======================= GENERAL UTILITY FUNCTION ===========================*/

function GetManualMMC()
{
	if(G_PS_URL_PATH.indexOf("plt=")>=0)	{
		var PLT = psGetParamValue("plt");
		return "PLT-_-" + PLT + "-_-NA-_-NA";
	}
	else 	{ 
		return null;
	}			
}



/*
 * Get parameter value from URL
 */
function psGetParamValue(param)
{
	var term = "";
	var temp=psGetValueFromUrl(G_PS_URL_PATH,param);
	if(psCheckElementExist(temp)==false)
	{
		return null;
	}
	temp=temp.replace(/[+]/g, " ") ;
	term=temp;
	return term;
}

/* PURPOSE: extract value from the URL
 * in format of http://xxx.com/page.ext?key1=value1&key2=value2
 * or key1=value1&key2=value2
 * RETURN: string value of the parameter
 */
function psGetValueFromUrl(pUrl, pKey)
{
	pUrl = (pUrl != null) ? "?" + psTrim(pUrl.toLowerCase()) : null;
	pKey = (pKey != null) ? psTrim(pKey.toLowerCase()) : null;

	if (pUrl == null || pKey == null || pUrl.indexOf(pKey) == -1) 
		return null;
	
	var start = pUrl.indexOf('&' + pKey + '=');
	start = (start == -1) ? pUrl.indexOf('?' + pKey + '=') : start;
	if (start >= 0)
	{
		start = start + pKey.length;
		var end = pUrl.indexOf("&", start);
		if(end == -1) 
			end = pUrl.length;
		var middle = pUrl.indexOf("=", start);
		return pUrl.substring(middle + 1, end);
	}
	return null;
}

function psCheckElementExist(pElement){
    if(typeof(pElement) == "undefined" || pElement == null)
    {
        return false;
    }

    return true;
}


/* PURPOSE: Remove all leading & trailing spaces of a string
 * Note: [&nbsp;] is also considered as a space
 * RETURN: string
 */
function psTrim(pStr)
{
	if (pStr == null || typeof(pStr) != "string")
		return pStr;
	return (pStr != null) ? pStr.replace(/&nbsp;|\u00A0/gi, ' ').replace(/^\s+|\s+$/g, '') : null;
}

/*======================= END GENERAL UTILITY FUNCTION ===========================*/
