

/*******************************************************************************/
/* open a new window and bring to the top                                      */
/*******************************************************************************/
function openWin(url,name) {
  newWin = window.open(url,name, 'menubar=1,scrollbars=1,location=1,toolbar=1,resizable=1,status=1, width='+(screen.width * .75)+',height='+(screen.height * .75)+',left=40,top=40')
  newWin.focus()
}


/*******************************************************************************/
/* call the tracking php to count the visitor                                  */
/*******************************************************************************/
function count() {

  document.write( "\<SCRIPT type='text/javascript' SRC='/xtrack/count.php?refer=" + escape(document.referrer) + "'\>\</SCRIPT\>" );

}

/**************************************************************/
/* show a pop-up element                                      */
/**************************************************************/
function showElement(elementid,evnt,pos) {

  if( document.getElementById  &&  document.getElementById(elementid) ) {
  
      theElement = document.getElementById(elementid);

      var cursor = getPosition(evnt);

      /* hide the element in case it needs to move */
      hideElement(elementid);

      //* ie6 lets select lists show through the pop-up - so hide any selects on the page (probably none)
      selectLists = document.getElementsByTagName('select');
      for (var counter=0; counter<selectLists.length; counter++) {
          selectLists[counter].style.visibility = 'hidden';
      }
  
      /* get the width and height of the window */
      var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      }
      else {
        if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        }
        else {
            if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
        }
      }

      /* get the width and height of the element */
      
      theElement.style.display='block';      /* have to set display to make Firefox find width/height */

      var wide  = theElement.clientWidth;	
      var high  = theElement.clientHeight;

      /* get the current scroll x and y coordinate */
      var xy = getScrollXY();

      /* position the popup in the center or above/below the cursor depending on the variable        */
      /* for cursor positioned popups - position image above cursor if it will fit - otherwise below */
      if( pos == 'cursor' ) {
          var elementtop = cursor.y - high - 20;
          if( elementtop < xy.y ) { 
              var newtop  = cursor.y + 40;
          }
          else { 
              var newtop  = cursor.y - high - 30;
          }
          /* set the left position to center the popup */
          var newleft = parseInt(((myWidth - wide) / 2));
      }
      else { 
          var topadd  = parseInt((myHeight - high) / 2);
          var newtop  = xy.y + topadd;
          /* set the left position to center the popup - do not let cursor enter popup area */
          var newleft = parseInt(((myWidth - wide) / 2));
          if ( newleft + wide > cursor.x ) {
              newleft = cursor.x - wide - 20;
          }
      }
    
      newtop      = newtop  + 'px'; 
      newleft     = newleft + 'px';

      theElement.style.display = 'inline';
      theElement.style.top  = newtop;
      theElement.style.left = newleft;
      theElement.style.width  = wide + 'px';
      theElement.style.height = high + 'px';
      initImage(elementid);

  }
}

/**************************************************************/
/* hide the image popups                                      */
/**************************************************************/
function hideElement(elid) {
  if (document.getElementById) {
      //* select lists might have been hidden - reshow them
      selectLists = document.getElementsByTagName('select');
      for (var counter=0; counter<selectLists.length; counter++) {
          selectLists[counter].style.visibility = 'visible';
      }
      document.getElementById(elid).style.visibility = 'hidden';
      clearTimeout(fadeInId);
      clearTimeout(fadeOutId);
      fadeOut(elid,0);
  }
}

/**************************************************************/
/* fade out the popup                                         */
/**************************************************************/
function fadeElement(elid) {
  if (document.getElementById) {
      //* select lists might have been hidden - reshow them
      selectLists = document.getElementsByTagName('select');
      for (var counter=0; counter<selectLists.length; counter++) {
          selectLists[counter].style.visibility = 'visible';
      }
      clearTimeout(fadeInId);
      fadeOut(elid,100);
  }
}

/**************************************************************/
/* fade in/out functionality                                  */
/**************************************************************/
var fadeInId  = 0;
var fadeOutId = 0;

function initImage(imageId) {
  clearTimeout(fadeOutId);
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}

function setOpacity(obj, opacity) {
  opacity = (opacity >= 100)?99.999:opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    setOpacity(obj, opacity);
    if (opacity < 100) {
       opacity += 10;
       fadeInId = setTimeout("fadeIn('"+objId+"',"+opacity+")", 30);
    }
    else {
       fadeInId = 0;
    }
  }
}

function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    setOpacity(obj, opacity);
    if(opacity > 0) {
       opacity -= 10;
       fadeOutId = setTimeout("fadeOut('"+objId+"',"+opacity+")", 30);
    }
    else {
       obj.style.visibility='hidden';
       fadeOutId = 0;
    }
  }
}





/**************************************************************/
/* Utility Functions                                          */
/**************************************************************/

/******************************************/
/** trim a string                        **/
/******************************************/
function trim(str)
{
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

/******************************************/
/** get the scroll x and y coordinates   **/
/******************************************/
function getScrollXY() {

  var scrollxy = {x:0, y:0};

  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrollxy.y = window.pageYOffset;
    scrollxy.x = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrollxy.y = document.body.scrollTop;
    scrollxy.x = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrollxy.y = document.documentElement.scrollTop;
    scrollxy.x = document.documentElement.scrollLeft;
  }
  return scrollxy;
}

/******************************************/
/** get the position of the cursor       **/
/******************************************/
function getPosition(e) {

    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
    //alert'pagex');
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    //alert'after cursor set1');
    }
    else {
    //alert'not pagex');
        cursor.x = e.clientX +
            (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
        cursor.y = e.clientY +
            (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
    //alert'after cursor set2');
    }
    //alert'x=' + cursor.x + ' y=' + cursor.y);
    return cursor;

 }
