// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

ie = false;
ff = false;
op = false;
sa = false;
ns4 = false;

if ( BrowserDetect.browser == "Explorer" )
  ie = true;
else if ( BrowserDetect.browser == "Firefox" )
  ff = true;
else if ( BrowserDetect.browser == "Opera" )
  op = true;
else if ( BrowserDetect.browser == "Safari" )
  sa = true;


memberlayer = 0;

// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function Confirm( confirmtext, link )
{
  answer = confirm( confirmtext );

  if ( answer == true )
    window.location = link;
  else
    return false;
}

// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function AreYouSure()
{
  return confirm("Are you sure you want to delete this item?")
}

// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function ServiceChange()
{
  var value = document.getElementById( 'service' ).value;

  if ( value < 9 )
    document.getElementById( 'other' ).value = '';
}

// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function toggleDetail( memid, id )
{
//  top = document.getElementById( memid ).clientTop;
//  left = document.getElementById( memid ).clientLeft;

  state = document.getElementById( id ).style.visibility;

  if ( state == "visible" )
    document.getElementById( id ).style.visibility = "hidden";
  else
  {
    document.getElementById( id ).style.visibility = "visible";
//    document.getElementById( id ).style.top = top;
//    document.getElementById( id ).style.left = left;
  }
}

// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function showDetails( droplayer )
{
	if( ie || op || ff || sa )
	{
		document.getElementById( droplayer ).style.visibility = "visible";

        scrolltop = document.documentElement.scrollTop;
        ypos = 40 + scrolltop;

        if ( ie || sa )
        {
          document.getElementById( droplayer ).style.posLeft = 0;
	      document.getElementById( droplayer ).style.posTop = ypos;
        }
        else
        {
          document.getElementById( droplayer ).style.left = 0 + "px";
          document.getElementById( droplayer ).style.top = ypos + "px";
        }
	}
    else
	{
	  eval('document.layers[' + droplayer + '].visibility="visible"');
	}

//window.status = "ypos=" + ypos + ", scrolltop=" + scrolltop + ", currentypos=" + currentypos;
}


// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function hideDetails( droplayer )
{
    if ( ie || op || ff || sa )
	{
		document.getElementById( droplayer ).style.visibility="hidden";
//		document.getElementById( "eid" ).style.visibility="visible";
	}
    else
	{
        eval('document.layers[' + droplayer + '].visibility="hidden"');
//        eval('document.layers[eid].visibility="visible"');
	}

//    memberlayer = 0;
}

// **************************************************************
// Function:    Confirm( confirmtext, link )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
if ( ns4 )
{ // Netscape
    document.captureEvents( Event.MOUSEMOVE );
    document.onmousemove = getMousePosition;
}
else if ( ie || op || ff || sa )
{ // Internet Explorer, Opera
    document.onmousemove = getMousePosition;
}

//document.onmousemove = getMousePosition;
// Global variables
mouseX = 0; // Horizontal position of the mouse on the screen
mouseY = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
leftpos = 0;
toppos = 0;

// **************************************************************
// Function:    getMousePosition( e )
// Description: confirm user action
// Inputs:      confirmtext - the text to display
//              link - the confirm link
// Outputs:     redirection or false
// **************************************************************
function getMousePosition(e)
{
    if ( !e )
      var e = window.event;

	if ( e.clientX || e.clientY )
	{
      // IE, Firefox, Safari, Opera
      // Because the clientX property returns a value relative to the client, you can add the value of the scrollLeft
      // property to determine the distance of the x-coordinate from the edge of the body element.
		mouseX = e.clientX;
		mouseY = e.clientY;

        if ( ie || ff || op )
        {
		  mouseX += document.documentElement.scrollLeft;
		  mouseY += document.documentElement.scrollTop;
        }
        else
        {
		  mouseX += document.documentElement.scrollLeft;
		  mouseY += window.pageYOffset;
        }
	}

      // width of viewport
        xMousePosMax = document.documentElement.clientWidth + document.documentElement.scrollLeft;

      // height of viewport
      if ( sa || op )
        yMousePosMax = window.innerHeight + window.pageYOffset;
      else
        yMousePosMax = document.documentElement.clientHeight + document.documentElement.scrollTop;


        // this is required due to the #container being position: relative
        // find the left edge of the container...
        xtraoffset = ( xMousePosMax / 2 ) - 419;

        // ...default is 20
        if ( xtraoffset < 20 )
          xtraoffset = 20;

        if ( ( mouseX + 400 ) > xMousePosMax )
            xoffset = ( mouseX + 400 ) - xMousePosMax;
        else
            xoffset = 0;

        if ( ( mouseY + 250 ) > yMousePosMax )
            yoffset = ( mouseY + 250 ) - yMousePosMax;
        else
            yoffset = 0;

        xpos = 0;
        ypos = 0;

        if ( memberlayer )
        {
          if ( ie || sa )
          {
            xpos = mouseX + 10 - xoffset - xtraoffset;
            ypos = mouseY + 10 - yoffset; // - 639;

            document.getElementById( memberlayer ).style.posLeft = xpos;
	    	document.getElementById( memberlayer ).style.posTop = ypos;
          }
          else
          {
            xpos = parseInt( mouseX + 10 - xoffset - xtraoffset );
            ypos = parseInt( mouseY + 10 - yoffset ); // - 639 );

            // Firefox seems to need the +"px" to work at all! Opera will work with or without
            document.getElementById( memberlayer ).style.left = xpos + "px";
	    	document.getElementById( memberlayer ).style.top = ypos + "px";
          }
        }

//        window.status = "xpos=" + xpos + ", ypos=" + ypos;
//    window.status = "mouseY=" + mouseY + ", yoffset=" + yoffset + ", ypos=" + ypos + "calendarlayer=" + calendarlayer;
}


