﻿/********************************************************************************************
function: openPopupWindow()	
arguments: href - the url to open. href may contain a fully qualified path or not.
           if the http:// portion of the argument is omitted, openPopupWindow assumes that the
           relative path start with /MCC and that the href argument contains a beginning '/'
           character.
********************************************************************************************/
function openPopupWindow(href)
{
  if (href.indexOf('http://') > 0)
  {
    window.open(href, 'mywindow','menubar=1,resizable=1,width=750,height=350');
    return;  
  }
  
  var host = parseUri(window.location).host;
  var newHref = 'http://' + host + '/MCC' + href;
  window.open(newHref, 'mywindow', 'menubar=1,resizable=1,width=750,height=350');
}

/********************************************************************************************
function: trim()	
arguments: str - the string to be trimmed
********************************************************************************************/
function trim(str)
{
  return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function IsUserAuthenticated()
{
  var hidAuthenticated = document.getElementById('ctl00___hidExternalUserIsAuthenticated');
  if (hidAuthenticated)
  {
    return hidAuthenticated.value.toLowerCase() == 'true';
  }
  return false;  
}

function LogoutUser()
{
  
  var hidAuthenticated = document.getElementById('ctl00___hidExternalUserIsAuthenticated');
  if (hidAuthenticated)
  {
    hidAuthenticated.value = 'true';
  }
}

/********************************************************************************************
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
********************************************************************************************/
function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};
