function C_CookieDomain()
{
  // return the domain to be used for a cookie 
  // stripped of the subdomain part
  return window.location.host.replace(/www\.|secure\./,'');
}

function C_GetCookie(sCookie)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sCookie == aCrumb[0] && aCrumb[1])
	  return unescape(aCrumb[1]);
  }
  // a cookie with the requested name does not exist
  return null;
}

function C_DropCookie()
{
  domain = C_CookieDomain(cookie);
  document.cookie = cookie + '=;domain=.' + domain + ';path=/;expires=Mon, 31 Dec 1999 23:59:59 GMT';
}

function C_SetCookie(cookie,value,till)
{
  domain = C_CookieDomain();
  until = '';
  if (till)
  {
  	until = ';expires=' + till;
  }
  document.cookie = cookie + '=' + value + ';domain=.' + domain + ';path=/' + until;
}

// set the visibility state true or false = visible or hidden
function C_Show (id,state)
{
	sr = document.getElementById(id);
	sr.style.visibility = state ? 'visible':'hidden';
}

// set the display state 0 = collapse 1 = display 2 = toggle
function C_Display (id,state)
{

element = document.getElementById(id);
	if (element)
	{
		if (state == 2)// toggle
		{
			if (element.style.display == 'none')
			{
				element.style.display='block'
				return true;
			}
			else
			{
				element.style.display='none'
				return false;
			}
		}
		else
		{
			element.style.display= state == 0 ? 'none':'block';
			return state != 0;
		}
	}
	return false;
}


// move object to a specified position
// if relative is true move it by the number of pixels given
// if relative = false x & y is an absolute position
function C_Moveto(id,x,y,relative)
{
	sr = document.getElementById(id);
	if (relative)
	{
		x += sr.style.left;
		y += sr.style.top;
	}
	sr.style.left = x;
	sr.style.top = y;
	
}

// Center one window inside the visible portion of the browser window
function C_CenterinWindow(id)
{
// IE6 work around thanks to quirksmode http://www.quirksmode.org/index.html?/js/doctypes.html
	ie6doc = document.documentElement.scrollTop;
	sr = document.getElementById(id);
	x = ie6doc ? document.documentElement.scrollLeft:document.body.scrollLeft;//
	y = ie6doc ? document.documentElement.scrollTop:document.body.scrollTop;//
	w = ie6doc ? document.documentElement.clientWidth:document.body.clientWidth;//
	h = ie6doc ? document.documentElement.clientHeight:document.body.clientHeight;//
	iw = sr.clientWidth;
	ih = sr.clientHeight;
	deltax = ((w/2) - (iw/2));	//calculate the new pos relative to
	deltay = ((h/2) - (ih/2));	//the defining windows client area
	// if the object is in relative mode we ned to change it
	sr.style.position = 'absolute';
	C_Moveto(id,x + deltax,y + deltay,false)
}


// test to see if this script has been loaded
window.common_functions = true;


