function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}
function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}
function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}
function PlaceVideo(URL, width, height) {
    document.write('<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" width="'+width+'" height="'+height+'">');
    document.write('<param name="src" value="'+URL+'">');
    document.write('<embed src="' + URL + '" PLUGINSPAGE="http://www.apple.com/quicktime/download" type="image/x-macpaint" width="' + width + '" height="' + height + '"></embed>');
    document.write('</object>');
}
function serverHtmlReturn(args,context) 
{
    //reSizePopUp(700, 600);
    el = document.getElementById('poptpop');
    el.innerHTML = args;
    reSizePopUp(700, 371);
}
function serverHtmlError(args, context)
{
    alert("PROBLEM=" + args + " " + context);
}
function getPeopleData(id) {
    el = document.getElementById('poptpop');
    el.innerHTML = '<br/><br/>Please wait - fetching data,<br/><br/>';
    reSizePopUp(700, el.clientHeight);
    changeOpacity('poptBc', 0, 8);
    serverHtmlRequest(id, 2);
}
function getGalleryImage(id) {
    el = document.getElementById('poptpop');
    el.innerHTML = '<br/><br/>Please wait - fetching data,<br/><br/>';
    reSizePopUp(700, 200);
    changeOpacity('poptBc', 0, 8);
    serverHtmlRequest(id, 3);
}
function getPartData(id) {
    document.getElementById('poptpop').innerHTML = "<img class='popImg' src='SITES/littletowns/images/ScubaPopUpTop.jpg'/><center><h3>- Please wait -</h3></center>";
    reSizePopUp(700, 371);
    changeOpacity('poptBc', 0, 8);
    serverHtmlRequest(id, 2);
}
function changeColour(element, current, endat)
{
    el = document.getElementById(element);
    var curCol = '#' + toHex(current) + toHex(current) + toHex(current);
    el.style.backgroundColor = curCol;
    if ( current < endat ) 
        current += 1;
    else
        current -= 1;
    if ( current != endat )
    {
        setTimeout('changeColour("'+element.toString()+'",'+current.toString()+','+endat.toString()+');', 50);
    }
}
function toHex(dec) {

    // create list of hex characters
    var hexCharacters = "0123456789ABCDEF"
    // if number is out of range return limit
    if (dec < 0)
            return "0"
    if (dec > 16)
            return "F"
    // decimal equivalent of second hex character in converted number
    var i = dec % 16
    // return hexadecimal equivalent
    return hexCharacters.charAt(i)
}
function closePopUp()
{
    sels = document.getElementsByTagName('select');
    for ( selI = 0; selI < sels.length; selI++ )
    {
        sels[selI].style.visibility = 'visible';
    }
    el = document.getElementById('poptpop');
    el.style.display = 'None';
    changeOpacity('poptBc', 8, 0)
    el = document.getElementById('ctl00_ContentPlaceHolder1_selectDD');
    if ( el != null )
        el.style.visibility = 'visible';
}
function showPopUp(id)
{
    reSizePopUp(700, 600);
    changeOpacity('poptBc', 0, 8);
    s = "<img width='690px' height='550px' onLoad='reSizePopUp(700, 600);' src='" + id + "' /><br/><center>Click anywhere to close</center>";
    el = document.getElementById('poptpop');
    el.innerHTML = s;
}
function reSizePopUp(theWidth, theHeight)
{
    sels = document.getElementsByTagName('select');
    for ( selI = 0; selI < sels.length; selI++ )
    {
        sels[selI].style.visibility = 'hidden';
    }
    var winWidth, winHeight, d=document, winClient, scrollTop;
    
    if (typeof window.scrollWidth!='undefined') {
        winWidth = window.scrollWidth;
        winHeight = window.scrollHeight;
        winClient = window.innerHeight;
        scrollTop = window.scrollTop;
    } else if ( d.documentElement
           && typeof d.documentElement.scrollWidth!='undefined'
            && d.documentElement.clientWidth!=0 ) {
                winWidth = d.documentElement.scrollWidth;
                winHeight = d.documentElement.scrollHeight;
                winClient = d.documentElement.clientHeight;
                scrollTop = d.documentElement.scrollTop;
    } else if ( d.body
           && typeof d.body.scrollWidth!='undefined') {
                winWidth = d.body.scrollWidth;
                winHeight = d.body.scrollHeight;
                winClient = d.body.clientHeight;
                scrollTop = d.body.scrollTop;
    }
    el = document.getElementById('poptBc');
    el.style.display = 'Block';
    el.style.height = winHeight+"px";
    el.style.width = winWidth+"px";
    
    el = document.getElementById('poptpop');
    el.style.display = 'Block';
    topwidth = winWidth /2 - (theWidth/2);
    topheight = winClient /2 - (theHeight/2) + scrollTop;
    //el.style.width = theWidth + "px";
    el.style.left= topwidth + "px";
    el.style.top = topheight + "px";
}
function changeOpacity(element, current, endat)
{
    el = document.getElementById(element);
    el.style.filter = "alpha(opacity="+current*10+")";
    el.style.opacity = "0." + current;
    if ( current < endat ) 
        current += 1;
    else
        current -= 1;
    if ( current != endat )
    {
        setTimeout('changeOpacity("'+element.toString()+'",'+current.toString()+','+endat.toString()+');', 25);
    }
    else if ( current == 0 )
    {
        el = document.getElementById('poptBc');
        el.style.display = 'None';
    }
}

