//---------------------------------------------------------------------
// function used by oec - url art is relative to bcom/client, ebi, bschool, bol, etc.

function openAssembly(id, type, width, height) {
 var i_width;
 if ((new Number(width) + 32) < 375) {
   i_width="375";
 } else if (new Number(width) + 32 > new Number(screen.availWidth)) {
   i_width= new Number(screen.availWidth) - 64;
 } else {
   i_width= new Number(width) + 32;
 }

 var i_height;
 if (new Number(height) + 220 < 400) {
   i_height="400";
 } else if (new Number(height) + 220 > new Number(screen.availHeight)) {
   i_height= new Number(screen.availHeight) - 64;
 } else {
  i_height = new Number(height) + 220;
 }

 window.open("/eb/art?id="+id+"&type="+type, "EB_Media", "resizable=yes,scrollbars=yes,status=yes,width="+i_width+",height="+i_height+",top=0,left=0");

}

function openRelativeAssembly(id, type, width, height) {
 var i_width;
 if ((new Number(width) + 32) < 375) {
   i_width="375";
 } else if (new Number(width) + 32 > new Number(screen.availWidth)) {
   i_width= new Number(screen.availWidth) - 64;
 } else {
   i_width= new Number(width) + 32;
 }

 var i_height;
 if (new Number(height) + 220 < 400) {
   i_height="400";
 } else if (new Number(height) + 220 > new Number(screen.availHeight)) {
   i_height= new Number(screen.availHeight) - 64;
 } else {
  i_height = new Number(height) + 220;
 }

 var h = "";
 if(location.pathname == '/search'){ h = "/all/"; }
 window.open(h + "art?id="+id+"&type="+type, "EB_Media", "resizable=yes,scrollbars=yes,status=yes,width="+i_width+",height="+i_height+",top=0,left=0");

}

function openFlagHistory(tocId, width, height) {
 var i_width = new Number(screen.availWidth) - 200;
 var i_height = new Number(screen.availHeight) - 200;

 /*
  if ((new Number(width) + 32) < 375) {
	 i_width="375";
  } else if (new Number(width) + 32 > new Number(screen.availWidth)) {
	 i_width= new Number(screen.availWidth) - 64;
  } else {
	 i_width= new Number(width) + 32;
  }

   var i_height;
if (new Number(height) + 160 < 400) {
   i_height="400";
} else if (new Number(height) + 160 > new Number(screen.availHeight)) {
   i_height= new Number(screen.availHeight) - 64;
} else {
  i_height = new Number(height) + 160;
}

	*/
window.open("/eb/article-"+tocId, "EB_Article", "resizable=yes,scrollbars=yes,status=yes,width="+i_width+",height="+i_height+",top=0,left=0");

}

function openTable(tocid) {
	var i_width = new Number(screen.availWidth) - 200;
	var i_height = new Number(screen.availHeight) - 200;

	window.open("/eb/table?tocId="+tocid, "EB_Article", "resizable=yes,scrollbars=yes,status=yes,width="+i_width+",height="+i_height+",top=0,left=0");

}

//---------------------------------------------------------------------
// date display

function showDate() {
  var today = new Date();
  var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  var year = (today.getYear() < 1000) ? today.getYear() + 1900 : today.getYear();

  document.write(months[today.getMonth()] + " " + today.getDate() + ", " + year);
}


//---------------------------------------------------------------------
// search drop-down

function checkSearch() {
	var form = document.forms["searchform"];
	var ct = form.elements["ct"];
	var query = escape(form.elements["query"].value);
      var fuzzyCheck = form.elements["spelling"];
      var fuzzy = "N";
	var DICTIONARY_INDEX = 6;
	var THESAURUS_INDEX = 7;
	if ( fuzzyCheck && fuzzyCheck.checked  )
	{
		fuzzy = "Y";
	}

	var url = "/search?query="+query;
	if(ct != null){
	  if (ct.options[ct.selectedIndex].value == "dict") {
	    url = "/dictionary?book=Dictionary&va="+query+"&query="+query;
	  } else if(ct.options[ct.selectedIndex].value == "thes") {
	    url = "/thesaurus?book=Thesaurus&va="+query+"&query="+query;
	  } else {
	    url = "/search?query="+query+"&ct="+ct.options[ct.selectedIndex].value+"&fuzzy="+fuzzy;
	  }
	}
	window.parent.location = url;
}


//--------------------------------------------------------------------
//browser check functions

function is_MacIE() {
     return ( navigator.userAgent.toLowerCase().indexOf("mac") != -1 );
}

function is_IE() {
     return (  navigator.userAgent.indexOf("MSIE") != -1 );
}

function get_IEversion() {
     IEPos = navigator.appVersion.indexOf('MSIE');
     return parseInt( navigator.appVersion.substring(IEPos + 5, navigator.appVersion.indexOf(';', IEPos)) );
}

function get_NNversion() {
     return parseFloat(navigator.appVersion);
}

//--------------------------------------------------------------------
// for generic pop up window

function openBrowserWindow(theURL, winName, features) {
	window.open(theURL, winName, features);
}


//-------------------------------------------------------------------
// sized for customer service pop-up window

function openCS(theURL) {
       window.open(theURL, '', 'scrollbars=yes,resizable=yes,width=650,height=420');
}

//---------------------------------------------------------------------
// STTK LaunchTool

function LaunchTool(sttk_id) {
        window.open(sttk_id,'_blank','width=561,height=336,top=20,left=10,resizable=yes');
}


//-----------------------------------------------------------------------
function openVideo(videoID) {
    	window.open("/video/player?vid="+videoID,"videoWin","width=450,height=415");
}

//-----------------------------------------------------------------------
function openTimelinesWindow(prod){
	var wnd;
        if (navigator.appName.indexOf("Netscape") == -1) {
                wnd = window.open("/timelines-" + prod + "/eb_ie.html","Timelines","width=600,height=400,toolbar=no,location=no,top=0,left=0,resizable=no,menubar=no,screenX=50,screenY=50,left=50,top=50");
        } else {
	        wnd = window.open("/timelines-" + prod + "/eb_nn.html","Timelines","width=614,height=414,toolbar=no,location=no,top=0,left=0,resizable=no,menubar=no,screenX=50,screenY=50,left=50,top=50");
	}
	wnd.focus();
}

//-----------------------------------------------------------------------
function openTimelines(prod, isInternational){
	var wnd;
      var openFile;
        if (navigator.appName.indexOf("Netscape") == -1) {
            if (isInternational.indexOf("true") >= 0){
              openFile = "eb_int_ie.html";
            } else {
              openFile = "eb_us_ie.html";
            }

                wnd = window.open("/timelines-" + prod + "/" + openFile,"Timelines","width=600,height=400,toolbar=no,location=no,top=0,left=              0,resizable=no,menubar=no,screenX=50,screenY=50,left=50,top=50");
        } else {
            if (isInternational.indexOf("true") >= 0){
              openFile = "eb_int_nn.html";
            } else {
              openFile = "eb_us_nn.html";
            }       
	        wnd = window.open("/timelines-" + prod + "/" + openFile,"Timelines","width=614,height=414,toolbar=no,location=no,top=0,left=0,resizable=no,menubar=no,screenX=50,screenY=50,left=50,top=50");
	}
	wnd.focus();
}

//-----------------------------------------------------------------------
function redirectTimeline() {
      var form = document.forms["timeline"];
      var type = form.elements["type"].value;
      openTimelinesWindow(type); 
}
//-----------------------------------------------------------------------
function openAtlas(prod){
   window.open('/' +prod+ '/atlas','atlas','height=500, width=740, menubar=yes, resizable=yes, toolbar=no, scrollbars=yes')
}

//-----------------------------------------------------------------------
function doBodyOnLoad(){
   if (document.location.href.indexOf('wordpedia.eb.com') >= 0) {
      return
   } 
   if (document.forms[0] && document.forms[0].query) {
       document.forms[0].query.focus()
   }
}

//-----------------------------------------------------------------------
function openMwPron(lib,dir,fname){
   if (lib == "c10") {
	window.open("http://cougar.eb.com/sound/" + dir + "/" + dir + fname,"Pronunciation","width=100,height=50,toolbar=no,location=no,top=0,left=0,resizable=no,menubar=no,screenX=50,screenY=50,left=50,top=50");
   } else {
	window.open("http://cougar.eb.com/soundc11/" + dir + "/" + dir + fname,"Pronunciation","width=100,height=50,toolbar=no,location=no,top=0,left=0,resizable=no,menubar=no,screenX=50,screenY=50,left=50,top=50");
   }
}


//------------------------------------------------------------------------
//TOC scripts
  

  function changeTocNode(tocId, imgId){
     var leDiv = document.getElementById(tocId);

     if (leDiv.style.display == "none") {
         leDiv.style.display = "block";
         document.getElementById(imgId).src = "/bcom/images/toc_minus.gif";
     } else {
         leDiv.style.display = "none";
         document.getElementById(imgId).src = "/bcom/images/toc_plus.gif";
     }
     return true;
  }

  function openAllTocNodes(){
     document.getElementById("expand").style.display="none";
     document.getElementById("collapse").style.display="block";     
     var allDiv = document.getElementsByTagName("table");
     var i;
     for (i=0;i<allDiv.length;i++) {
        var thisDiv = allDiv[i]; 
        if(thisDiv.id && thisDiv.id.indexOf('toc') != -1) {
           thisDiv.style.display = "block";
           var imgIdName = 'img' + thisDiv.id.substr(thisDiv.id.indexOf('c')+1);
           document.getElementById(imgIdName).src = "/bcom/images/toc_minus.gif";
        }
     }
     return false;
  }

  function collapseAllTocNodes(){
     document.getElementById("collapse").style.display="none";
     document.getElementById("expand").style.display="block";
     var allDiv = document.getElementsByTagName("table");
     var i;
     for (i=0;i<allDiv.length;i++) {
        var thisDiv = allDiv[i]; 
        if(thisDiv.id && thisDiv.id.indexOf('toc') != -1) {
           thisDiv.style.display = "none";
           var imgIdName = 'img' + thisDiv.id.substr(thisDiv.id.indexOf('c')+1);
           document.getElementById(imgIdName).src = "/bcom/images/toc_plus.gif";
        }
     }
     return false;
  }






