
var vwd = 800;
var vht = 600;
var emedtvvideo = null;
var useDivVWnd = false;
function showVWnd( url ) {
	window.location = url;
   //hideClickDiv();
   //if ( useDivVWnd ) showVWndDiv(url); else showVWndWindow(url);
}
function showVWndWindow( url ) {
    var h = vht;
    if ( screen && screen.height && h < screen.height - 30 ) h = screen.height - 45;
    if ( screen && screen.availHeight && h > screen.availHeight - 45 ) h = screen.availHeight - 45;
    if ( h > 900 ) h = 900;
    if ( h < 600 ) h = 600;
    vwndOk = false;
    emedtvvideo = window.open(url,"emedtvvideo2","width="+vwd+",height="+h+",left=200,top=5,status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1");
    if ( emedtvvideo ) {
        emedtvvideo.focus();
    } else {
        //alert("The video window could not be created.\n\nIt may have been stopped by your popup blocker.");
       showClickDiv(url );
    }
}



var vdiv;
var oldwndresize;
var oldwndscroll;
function hideVdiv() {
    if ( vdiv && vdiv.parentNode ) vdiv.parentNode.removeChild( vdiv );
    if ( window.onscroll == positionVideoScroll ) window.onscroll = oldwndscroll;
    if ( window.onresize == positionVideoResize ) window.onresize = oldwndresize;
}
function positionVideoResize(e) {
    positionVideo();
    if ( oldwndresize ) oldwndresize( e );
}
function positionVideoScroll(e) {
    positionVideo();
    if ( oldwndscroll ) oldwndscroll( e );
}
function positionVideo() {
  if ( vdiv ) {
      var wndWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
          wndWidth = window.innerWidth;
          wndHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
          wndWidth = document.documentElement.clientWidth;
          wndHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
          wndWidth = document.body.clientWidth;
          wndHeight = document.body.clientHeight;
      }
      var doc = document.documentElement ? document.documentElement:document.body;
      vdiv.style.top = ((wndHeight - vht)/2 + doc.scrollTop) + "px";
      vdiv.style.left = ((wndWidth - vwd)/2 + doc.scrollLeft) + "px";
  }
}
function showVWndDiv( url ) {
    hideVdiv();
    oldwndscroll = window.onscroll;
    oldwndresize = window.onresize;
    window.onscroll = positionVideo;
    window.onresize = positionVideo;
    vdiv = document.createElement("div");
    var doc = document.documentElement ? document.documentElement:document.body;
    positionVideo();
    vdiv.style.backgroundColor = "white";
    vdiv.style.zIndex = 10000000;
    vdiv.style.position = "absolute";
    vdiv.style.width = vwd + "px";
    vdiv.style.height = vht + "px";
    vdiv.style.borderWidth = "1px";
    vdiv.style.borderColor = "gray";
    vdiv.style.borderStyle = "solid";
    var iframe = document.createElement("iframe");
    iframe.frameBorder = "0";
    iframe.style.borderWidth = "0"
    iframe.style.width = "760px";
    iframe.style.height = "550px";
    iframe.style.marginRight = "15px";
    iframe.src = url;
    vdiv.appendChild( iframe );

    var closebtnX = document.createElement("button");
    closebtnX.style.borderWidth = "1px";
    closebtnX.style.borderColor = "#999999";
    closebtnX.style.borderStyle = "solid";
    closebtnX.onclick = hideVdiv;
    closebtnX.appendChild( document.createTextNode("X") );
    closebtnX.style.position = "absolute";
    closebtnX.style.left = "765px";
    closebtnX.style.width = "15px";
    closebtnX.style.padding = "0";
    closebtnX.style.fontSize = "8pt";
    closebtnX.style.color = "#4444DD";
    closebtnX.style.margin = "0";
    vdiv.appendChild( closebtnX );

    var closebtn = document.createElement("button");
    closebtn.style.borderWidth = "1px";
    closebtn.style.borderColor = "#999999";
    closebtn.style.marginRight = "10px";
    closebtn.style.borderStyle = "solid";
    closebtn.style.color = "#4444DD";
    closebtn.onclick = hideVdiv;
    vdiv.style.textAlign = "right";
    closebtn.appendChild( document.createTextNode("Close Video Window") );
    vdiv.appendChild( closebtn );
    document.body.appendChild( vdiv );
}

function hideClickDiv() {
    if ( vdiv && vdiv.parentNode ) vdiv.parentNode.removeChild( vdiv );
    if ( window.onscroll == positionVideoScroll ) window.onscroll = oldwndscroll;
    if ( window.onresize == positionVideoResize ) window.onresize = oldwndresize;
}
function positionClickResize(e) {
    positionClickDiv();
    if ( oldwndresize ) oldwndresize( e );
}
function positionClickScroll(e) {
    positionClickDiv();
    if ( oldwndscroll ) oldwndscroll( e );
}

var helperWidth = 300;
var helperHeight = 200;

function positionClickDiv() {
  if ( vdiv ) {
      var wndWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
          wndWidth = window.innerWidth;
          wndHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
          wndWidth = document.documentElement.clientWidth;
          wndHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
          wndWidth = document.body.clientWidth;
          wndHeight = document.body.clientHeight;
      }
      var doc = document.documentElement ? document.documentElement:document.body;
      vdiv.style.top = ((wndHeight - helperWidth)/2 + doc.scrollTop) + "px";
      vdiv.style.left = ((wndWidth - helperHeight)/2 + doc.scrollLeft) + "px";
  }
}
function showClickDiv( url ) {
    hideVdiv();
    oldwndscroll = window.onscroll;
    oldwndresize = window.onresize;
    window.onscroll = positionClickDiv;
    window.onresize = positionClickDiv;
    vdiv = document.createElement("div");
    var doc = document.documentElement ? document.documentElement:document.body;
    positionClickDiv();
    vdiv.style.fontSize = "10pt";
    vdiv.style.zIndex = 10000000;
    vdiv.style.position = "absolute";
    vdiv.style.width = helperWidth + "px";
    vdiv.style.height = helperHeight + "px";
    vdiv.style.borderWidth = "1px";
    vdiv.style.borderColor = "gray";
    vdiv.style.borderStyle = "solid";
    vdiv.style.background = "white url(/images/v2/blockedbk.gif)  no-repeat";
    var closebtnX = document.createElement("button");
    closebtnX.style.borderWidth = "1px";
    closebtnX.style.borderColor = "#999999";
    closebtnX.style.borderStyle = "solid";
    closebtnX.onclick = hideVdiv;
    closebtnX.appendChild( document.createTextNode("X") );
    closebtnX.style.position = "absolute";
    closebtnX.style.top = "4px";
    closebtnX.style.left = (helperWidth-20)+ "px";
    closebtnX.style.width = "15px";
    closebtnX.style.padding = "0";
    closebtnX.style.fontSize = "8pt";
    closebtnX.style.color = "#4444DD";
    closebtnX.style.margin = "0";
    vdiv.appendChild( closebtnX );
    var txtdiv = document.createElement("div");
    txtdiv.innerHTML = "<br /><br /><br /><br /><br /><a href=\"#\" onclick=\"showVWnd('"+url+"'); return false;\" >Please Click Here to View the Video</a><br /><br />(it may have been blocked by your popup blocker)";
    txtdiv.style.width = "100%";
    txtdiv.style.textAlign = "center";
    vdiv.appendChild( txtdiv );
    document.body.appendChild( vdiv );
}



var newopener;
function setOpenerUrl( url ) {
  if ( useDivVWnd ) {
        setOpenerUrlDiv( url );
  } else {
        setOpenerUrlWindow( url );
  }
}
function setOpenerUrlDiv( url ) {
    document.location = url;
}
function setOpenerUrlWindow( url ) {
  if ( window.opener && ! window.opener.closed ) {
    window.opener.location = url;
    window.opener.focus();
  } else {
      if ( newopener && !newopener.closed ) {
          newopener.location = url;
      } else {
          newopener = window.open(url,"emedtvvideoopener","");
      }
      newopener.focus();
  }
}
function searchVideoById(searchString) {
    var ss = document.getElementById(searchString);
    dovideosearch( ss.value );
}
function setVideoText( text ) {
    var cc = document.getElementById("fulltextscroll");
    cc.innerHTML = text;
}
function dovideosearch( query ) {
    var sr = document.getElementById("searchresults");
    sr.src = "/search.html?hitsperpage=12&thumbs=true&searchString=" + escape("type:media AND (" + query  + ")");
    showSearchResults();
}
function dositesearch( query ) {
    setOpenerUrl("/search.html?hitsperpage=12&searchString=" + escape(query));
}
function toggleSRAndText() {
    if ( isTextShowing() ) showSearchResults();
    else showVideoText();
}
function isTextShowing() {
    var cc = document.getElementById("fulltext");
    return ( cc.style.display != "none" );
}
function showSRAndText( srdisplay, textdisplay ) {
    var sr = document.getElementById("searchbox");
    sr.style.display = srdisplay;
    var cc = document.getElementById("fulltext");
    cc.style.display = textdisplay;
}
function showSearchResults() {
    showSRAndText("", "none" );
}
function showVideoText() {
    showSRAndText( "none", "" );
}
function hideTextAndSearch() {
    showSRAndText( "none", "none" );
}
function watchedClip( presID1, presTitle1, clipID1, clipTitle1 ) {
	clipTitle1 = unescape( clipTitle1 );
    presTitle1 = unescape( presTitle1 );    
    urchinTracker('/video/'+presID1 +'/' + clipID1 + '/' + presTitle1 + '/' + clipTitle1);
    addToHistory1( presID1, presTitle1, clipID1, clipTitle1 );
}

function getXMLHttpRequest() {
  var req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch(e) {
      req = false;
    }
  } else if(window.ActiveXObject) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        req = false;
      }
    }
  }
  return req;
}
function addToHistory1 ( presID1, presTitle1, clipID1, clipTitle1 ) {
    var ajax = getXMLHttpRequest();
    ajax.open("GET", "/videodata/addToHistory.txt?clipID=" + clipID1 + "&presID=" + presID1 + "&presTitle="+presTitle1+"&clipTitle=" +clipTitle1, true );
    ajax.send('');
}

