//<SCRIPT> // <- dummy script tag used to enable InterDev syntax coloring
//------------------------------------------------------------------------
// File:    imkDHTMLLib.js
// Author:  Al Yanchak
// Date:    12/31/98
//
// Revised: 4/18/99
//
// I-Mark DHTML Library functions
//
// Copyright© 1999, I-Mark Inc. All Rights Reserved
//
// WARNING: The information in this file is protected by copyright law
// and international treaty provisions. Unauthorized reproduction or
// distribution of this file, or any portion of it, may result in severe
// criminal and civil penalties, and will be prosecuted to the maximum
// extent possible under the law.  Further, you may not reverse engineer,
// decompile, or disassemble the file.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// browser detection
//
// The following global variables are used in many of the I-Mark DHTML
// library functions. By including this file at the head of an HTML page,
// the global variables will be defined and the browser detection routine
// will set them as required
//------------------------------------------------------------------------
var user_agent;
var IsNN4;
var IsNN6;
var IsIE4;
var IsIE5
var IsWin;
var IsMac;
var IsOtherOS;

function DoDetect()
{
  user_agent = navigator.userAgent.toLowerCase();

  IsNN4 = (document.layers) ? true : false;
  IsIE4 = (document.all)    ? true : false;
//  IsIE4 = (document.all && !document.getElementById)    ? true : false;
  IsIE5 = (IsIE4 && document.getElementById) ? true : false;
  IsNN6 = (!IsIE4 && document.getElementById) ? true : false;
  IsWin = (user_agent.indexOf("win") != -1) ? true : false;
  IsMac = (user_agent.indexOf("mac") != -1) ? true : false;
  IsOtherOS = !IsWin && !IsMac              ? true : false;
}

DoDetect();

//------------------------------------------------------------------------
// imkFindFrame
//
// Locates a frame object by name, by searching recursively through the
// document heirarchy. To search the entire heirarchy, pass 'null' as the
// level paramter, otherwise pass the level at which the search is to be
// started.
//
// returns: the frame window object, or null if it is not found
//------------------------------------------------------------------------
function imkFindFrame(frameName, level)
{
  var theFrame = null;
  
  if(!level)
    level = top;
  
  var i;
  for(i = 0; i < level.frames.length; i++)
  {
		try
		{
			if(level.frames[i].name == frameName)
			  theFrame = level.frames[i];
			else
			  theFrame = imkFindFrame(frameName, level.frames[i]);
		}
		catch(err)
		{
		}    
    if(theFrame != null)
      break;
  }
  
  return theFrame
}

//------------------------------------------------------------------------
// imkOpenLocation
//
// Opens the URL specified in 'loc' in the specified frame target
//
// returns: nothing
//------------------------------------------------------------------------
function imkOpenLocation(loc, target)
{
  // default target if none specified
  if(!target)
    target = "_self";

  switch(target)
  {
    case "_blank":
      open(loc);
      break;
      
    case "_parent":
      window.parent.location = loc;
      break;
      
    case "_self":
      self.location = loc;
      break;
      
    case "_top":
      top.location = loc;
      break;
      
    default:
      var frm = imkFindFrame(target);
      if(frm != null)
		    frm.location = loc;
  }
}

//------------------------------------------------------------------------
// imkReplaceLocation
//
// Opens the URL specified in 'loc' in the specified frame target
//
// returns: nothing
//------------------------------------------------------------------------
function imkReplaceLocation(loc, target)
{
  // default target if none specified
  if(!target)
    target = "_self";
    
  switch(target)
  {   
    case "_parent":
      window.parent.location.replace(loc);
      break;
      
    case "_self":
      self.location.replace(loc);
      break;
      
    case "_top":
      top.location.replace(loc);
      break;
      
    default:
      var frm = imkFindFrame(target);
      if(frm != null)
		    frm.location.replace(loc);
  }
}

//------------------------------------------------------------------------
// imkLTrim
//
// Trims leading whitespace from a string
//
// returns: string
//------------------------------------------------------------------------

function imkLTrim(theString)
{
  return (!imkIsEmpty(theString)) ? theString.substr(theString.search(/\S/)) : theString;
}

//------------------------------------------------------------------------
// imkRTrim
//
// Trims trailing whitespace from a string
//
// returns: string
//------------------------------------------------------------------------

function imkRTrim(theString)
{
  return (!imkIsEmpty(theString)) ? theString.substr(0, theString.search(/\S\s*$/) + 1) : theString;
}

//------------------------------------------------------------------------
// imkTrim
//
// Trims leading and trailing whitespace from a string
//
// returns: string
//------------------------------------------------------------------------

function imkTrim(theString)
{
  return imkRTrim("" + imkLTrim("" + theString));
}

//------------------------------------------------------------------------
// imkIsEmpty
//
// Determines if a variant is empty, null, undefined or contains only whitespace
//
// returns: true  --> if empty, null, undefined or contains only whitespace
//          false --> otherwise
//------------------------------------------------------------------------

function imkIsEmpty(value)
{
  if (typeof(value) == "number")
    value = value.toString();
    
  return (value == "" || value == null || value == "undefined" || value.search(/^\s*$/) != -1) ? true : false;
}

//------------------------------------------------------------------------
// imkGetPageX, imkGetPageY
//
// Returns the absolute X or Y coordinate of the object
//
// based on method described in "Determining Element Page Coordinates"
// found at http://www.webreference.com/dhtml/diner/realpos/
//
// returns: integer
//
// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
//------------------------------------------------------------------------
function imkGetPageX(obj)
{
  if (!obj)
    return 0;
  
  if (IsNN4)
  {
    return (obj.pageX) ? obj.pageX : 0;
  }
  else
  {
    var pageX = obj.offsetLeft;
    var parent = obj.offsetParent;

    while (parent != null)
    {
      pageX += parseInt(parent.offsetLeft);
      if (parent.tagName == "TABLE") 
        if (!isNaN(parseInt(parent.border)))
          pageX += parseInt(parent.border);
      parent = parent.offsetParent;
    }
    return pageX;
  }
}

function imkGetPageY(obj)
{
  if (!obj)
    return 0;

  if (IsNN4)
  {
    return (obj.pageY) ? obj.pageY : 0;
  }
  else
  {
    var pageY = obj.offsetTop;
    var parent = obj.offsetParent;

    while (parent != null)
    {
      pageY += parseInt(parent.offsetTop);
      if (parent.tagName == "TABLE") 
        if (!isNaN(parseInt(parent.border)))
          pageY += parseInt(parent.border);
      parent = parent.offsetParent;
    }
    return pageY;
  }
}
//------------------------------------------------------------------------
// imkGetOptionValue
//
// returns the value of the curently selected option (radio) group
//
// Modified on 1/13/03 to accomodate option 'groups' with only a single
// radio button - Al Yanchak
//------------------------------------------------------------------------
function imkGetOptionValue(objOption)
{
  if(typeof(objOption.checked) == "boolean")
  {
    return objOption.value;
  }
  else
  {
    var i;
    for(i = 0; i < objOption.length; i++)
    {
      if(objOption[i].checked == true)
        return objOption[i].value;
    }
  }
  return "";
}

function imkSetOptionValue(objOption, val)
{
  if(typeof(objOption.checked) == "boolean")
  {
    if(objOption.value == val)
      objOption.checked = true;
  }
  else
  {
    var i;
    for(i = 0; i < objOption.length; i++)
    {
      if(objOption[i].value == val)
        objOption[i].checked = true;
    }
  }
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkGetWidth(obj)
{
  if (IsNN4)
    return (obj.clip.width) ? obj.clip.width : 0;
  else if (IsIE4)
    return (obj.style.visibility == "hidden") ? obj.scrollWidth : obj.offsetWidth;
  else if(IsNN6)
    return (obj.style.width) ? parseInt(obj.style.width) : 0;
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkSetWidth(obj, theWidth)
{
  if (!obj) return -1;
  
  if (IsNN4)
    obj.clip.width = theWidth;

  if (IsIE4 || IsNN6)
    obj.style.width = theWidth;
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkGetHeight(obj)
{
  if (IsNN4)
    return (obj.clip.height) ? obj.clip.height : 0;
  else if (IsIE4)
    return (obj.style.visibility == "hidden") ? obj.scrollHeight : obj.offsetHeight;
  else if(IsNN6)
    return (obj.style.height) ? parseInt(obj.style.height) : 0;
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkSetHeight(obj, theHeight)
{
  if (!obj) return -1;
  
  if (IsNN4)
    obj.clip.height = theHeight;

  if (IsIE4)
  {
    var int_width = (obj.style.visibility == "hidden") ? obj.scrollWidth : obj.offsetWidth;
    obj.style.clip = "rect(0 " + int_width + " " + theHeight + " 0)";
  }
  else if(IsNN6)
    obj.style.height = theHeight;
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkGetClientWidth()
{
  if (IsNN4)
    return window.innerWidth;
  else if (IsIE4)
    return document.body.clientWidth
  else
    return parseInt(window.innerWidth);
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkGetClientHeight()
{
  if (IsNN4)
    return window.innerHeight;
  else if (IsIE4)
    return document.body.clientHeight
  else
    return parseInt(window.innerHeight);
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkGetDocumentWidth()
{
  if(IsIE4 == true)
    return parseInt(document.body.scrollWidth);
  else
    return parseInt(window.innerWidth) + parseInt(window.pageXOffset);
}

// *** MODIFIED ***
//
// Modified By:  Al Yanchak
// Date:         12/12/2003
//
// Desc: Modified to properly handle Netscape 6+ browsers
function imkGetDocumentHeight()
{
  if(IsIE4 == true)
    return parseInt(document.body.scrollHeight);
  else
    return parseInt(window.innerHeight) + parseInt(window.pageYOffset);
}

function imkSetZIndex(obj, zIndex)
{
  if (!obj)
    return;

  if (IsIE4)
    obj.style.zIndex = zIndex;

  if (IsNN4)
    obj.zIndex = zIndex;
}

function imkMoveTo(obj, cx, cy)
{
  if (IsNN4)
  {
    obj.moveTo(cx, cy);
  }
  else if (IsIE4)
  {
    obj.style.pixelLeft = cx;
    obj.style.pixelTop  = cy;
  }
  else
  {
    obj.style.left = cx;
    obj.style.top  = cy;
  }
}

function imkMoveBy(obj, dx, dy)
{
  if (IsNN4)
  {
    obj.moveBy(dx, dy);
  }
  else if (IsIE4)
  {
    obj.style.pixelLeft += dx;
    obj.style.pixelTop  += dy;
  }
  else
  {
    obj.style.left += dx;
    obj.style.top  += dy;
  }
}

function imkShow(obj)
{
  if (!obj)
    return;

  if (IsNN4)
    obj.visibility = "visible";
  else
      obj.style.visibility = "visible";
}

function imkHide(obj)
{
  if (!obj)
    return;

  if (IsNN4)
    obj.visibility = "hidden";
  else
    obj.style.visibility = "hidden";
}


//------------------------------------------------------------------------
// imkSwitchImg()
//
// replaces the src of the image identified my imgID with the source
// identified in newFile
//------------------------------------------------------------------------
function imkSwitchImg(imgID, newFile)
{
  if(document.images)
    document.images[imgID].src = newFile;
}

//------------------------------------------------------------------------
// HandleResize() 
//
// Netscape 4.x resize bug handler. On resize, Netscape will trash 
// positions of CSS positioned elements, forcing the need for a page
// reload to reset them, however, NS 4.0x browsers toss an extra resize 
// event after a page loads and scroll bars are added causing an infinite
// loop of page reloads. To work around, we must save the original
// window size in a global to see if we have a true resize event before
// reloading the page.
//
// Add the line "onresize='HandleResize();'" to the body to tag to enable
//------------------------------------------------------------------------
if(IsNN4 == true)
{
  var origWidth   = window.innerWidth;
  var origHeight = window.innerHeight;
}

function HandleResize()
{
  if(IsNN4 == true)
    if (window.innerWidth != origWidth || window.innerHeight != origHeight)
      self.location.reload();
}

// IE places an annoying square around links and images when they are clicked on
// this removes focus from that object and removes the square!
function RemoveFocus(obj)
{
  if (IsIE4)
    obj.blur();
  return;
}

function rf(obj)
{
  if (IsIE4)
    obj.blur();
  return;
}

function imkGetLastStyleAttr(selector, attr)
{
  var i;
  var j;
  var theAttr = "";

  for(i = 0; i < document.styleSheets.length; i++)
  {
    var element;
    if (IsNN6 && !IsIE4)
    {
      for(j = 0; j < document.styleSheets[i].cssRules.length; j++)
      {
        if (document.styleSheets[i].cssRules[j].selectorText == selector)
        {
          var attVal = eval("document.styleSheets[" + i + "].cssRules[" + j + "].style." + attr);
          if (attVal)
            theAttr = attVal;
        }
      }
    }
    else
    {
      for(j = 0; j < document.styleSheets(i).rules.length; j++)
        if(document.styleSheets(i).rules(j).selectorText == selector)
        {
          var attVal = eval("document.styleSheets(" + i + ").rules(" + j + ").style." + attr);
          if(attVal)
            theAttr = attVal;
        }
    }
  }
 
  return theAttr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------
// imk_GetCookie
//
// gets the named cookie and returns its value
//---------------------------------------------------------------------
function imk_GetCookie(str_cookieName) 
{
  var str_cookie = "";
  if (document.cookie.length > 0) // if there are any cookies
  {
    str_srch = str_cookieName + "="
    var pos1 = document.cookie.indexOf(str_srch) 
    if (pos1 != -1) 
    {
      pos1 += str_srch.length; 
      var pos2 = document.cookie.indexOf(";", pos1) 
      if (pos2 == -1) 
        pos2 = document.cookie.length

      str_cookie = unescape(document.cookie.substring(pos1, pos2));
    } 
  }
  return str_cookie;
}

//---------------------------------------------------------------------
// imk_SetCookie
//
// sets the named cookie, value, and (optional) expiration
//---------------------------------------------------------------------
function imk_SetCookie(str_cookieName, str_value, expire) 
{
  var str_exp;
  if(expire)
    str_exp = "; expires=" + expire.toGMTString() + "; path=/"
  else
    str_exp = "";
  
 
  document.cookie = str_cookieName + "=" + 
                    escape(str_value) +
                    str_exp;
}

function imkXMLEscape(str)
{
  str = "" + str;
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/\"/g, "&quot;");
	str = str.replace(/'/g, "&apos;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	return str;
}
