  var win = null;

  function closePopup()
  {
    if (win != null) win.close(); 
      win = null;           
  }

  function openWindow(wnd, _width, _height)
  {
    closePopup();
    posx = (screen.width) ?   (screen.width-_width)/2 : 0;
    posy = (screen.height) ? (screen.height-_height)/2 : 0;
    settings = 'height='+_height+',width='+_width+',top='+posy+',left='+posx+',scrollbars=yes,resizable=yes,alwaysRaised=yes'
    win = window.open(wnd,'popwindow',settings)
    if(win.window.focus){win.window.focus();}
  }

 

function SetControlDisableStateByCheckControl(id1, id2)
{

  if (document.getElementById(id1)) 
    document.getElementById(id1).disabled = (!document.getElementById(id2)) || (!document.getElementById(id2).checked);
}

function AddToFavorites(defaultTitle, defaultUrl) 
{ 
  if (window.external) 
  {
    var title = (defaultTitle && (defaultTitle != '')) ? defaultTitle : document.title;
    var url   = (defaultUrl && (defaultUrl != '')) ? defaultUrl : location.href;
//    window.external.addFavorite(location.href, document.title) 
    window.external.addFavorite(url, title); 
  } 
  else
  { 
   alert("Sorry! Your browser doesn't support this function.");
  }
  return false; 
}

window.onresize = flip;
//window.onscroll = flip;

function flip() {
  var width  = GetWindowWidth();
  var div = document.getElementById("bookmark");
  if (div && (width > 595))
  {
    div.style.pixelLeft = width - 160 - 5;
  }
}

function GetWindowWidth()
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
