//standard.js
//common utility functions

/****************************/
/**  STANDARD BCOM COOKIE  **/

var BCOM_ID_COOKIE_NAME = "bcomID";
var SERVER_ID = Math.round(Math.random() * 898) + 305;
var DOMAIN_NAME = ".britannica.com";

if (!hasCookie(BCOM_ID_COOKIE_NAME))
{
	setCookie(BCOM_ID_COOKIE_NAME, createUniqueID(), DOMAIN_NAME);
}

function hasCookie(name)
{
	return (document.cookie.indexOf(name + "=") > -1);
}

function createUniqueID()
{
	var time = (new String((new Date()).getTime()));
	return (SERVER_ID + time);
}

function setCookie(name, val, domain)
{
        var exp = new Date();
        var tenYears = exp.getTime() + (315360000000);
        exp.setTime(tenYears);
	var str = "";
	str += name + "=" + val;
	domain ? str += ";domain=" + domain + "; path=/; expires=" + exp.toGMTString() : str += "";
	document.cookie = str;
}

/**  STANDARD BCOM COOKIE  **/
/****************************/

//do browser detection here
//placeholder for now; more robust testing to follow
var isNN, isIE, isMac;
var agent = navigator.userAgent;
var isMac;

if (agent.lastIndexOf('Mac')<0) isMac=false;
else isMac=true;

if (document.all){
	isIE = true;
} else if (document.layers){
	isNN = true;
	document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP | Event.RESIZE);
    window.onresize=myResizeFunction;
}

//standard handler for dealing with
//netscape's bad habits
if (isNN)
{var ws = window.innerWidth;
 var hs = window.innerHeight;}

function myResizeFunction()
{if (isNN)
 {if ((window.innerWidth != ws) || (window.innerHeight != hs))
       {window.location.href=window.location.href;}
	   }
}
//makes layers, courtesy of peterg
function mkLay(n,w,h,x,y,z,vis,cnt,exn,exe) {
	if (isNN) {
		vis == 1 ? vis='show' : vis='hide';
		document.write('<layer width='+w+' height='+h+' left='+x+' top='+y+' name="'+n+'" z-index='+z+' visibility="'+vis+'" '+exn+'>'+cnt+'</layer>');
	} else if (isIE) {
		vis == 1 ? vis='visible' : vis='hidden';
		document.write('<div id="'+n+'" style="position:absolute;width:'+w+';height:'+h+';left:'+x+';top:'+y+';z-index:'+z+';visibility:'+vis+';'+exe+'" >'+cnt+'</div>');
	}
}

//cross-browser function to handle layer visibility
function visLay(nme,vis) {
	if (isNN) {
		vis ? vis='show' : vis='hide';
		document.layers[nme].visibility=vis;
	} else if (isIE) {
		vis ? vis='visible' : vis='hidden';
		document.all[nme].style.visibility=vis;
	}
}

//point struct; conveniently stores x & y
function point(x,y){
	this.x = x;
	this.y = y;
	return this;
}

//ie-only function returns x & y location
//of element id by looping up thru dom
//returns point
function getAbsOffset(id){
	var offX, offY;
	myEl = document.all[id];
	offX = myEl.offsetLeft;
	offY = myEl.offsetTop;

if (isMac)
  while(myEl.parentElement != null){
		myEl =  myEl.parentElement;
		offX += myEl.offsetLeft;
		offY += myEl.offsetTop;
	}
else
while(myEl.offsetParent != null){
	  myEl =  myEl.offsetParent;
	  offX += myEl.offsetLeft;
	  offY += myEl.offsetTop;
	}

	myPoint = new point(offX, offY);
	return myPoint;
}

// A function that don't do anything
function donull () {}

///////////////////////////////////////
//layerPos()
//cross-browser layer positioning
///////////////////////////////////////
function LayerPos(id,x,y){
	if (isNN){
		if (x != null) document.layers[id].left = x;
		if (y != null) document.layers[id].top = y;
	} else if(isIE){
		if (x != null) document.all[id].style.posLeft = x;
		if (y != null) document.all[id].style.posTop = y;
	}
}


function SwitchImg(which,newSrc,nnLayer){
	var layerInfo = "";
	if (isNN){
		layerInfo = nnLayer;
	}
	eval(layerInfo + "document.images['" + which + "'].src = '" + newSrc.src + "'");
}

function GraphicSwap(flashpath,imagepath,width,height,border,url){
	//Modified by Brandon Cox bcox@inch.com
	//No Flash
	//if(isIE && (flashpath != "") & !isMac){
		//var str = '<OBJECT style="z-index: -10;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width='+ width +' height='+ height +'>  <param name="wmode" value="opaque">   <PARAM name="Movie" value="'+ flashpath +'"> </OBJECT>';
	//} else {
		var str = "";
		if (url != "") str+= '<A HREF="'+ url +'">';
		str += '<IMG SRC="'+ imagepath +'" WIDTH="'+ width +'" HEIGHT="'+ height +'" BORDER='+ border +'>';
		if (url != "") str+= '</A>';
	//}
	document.write(str);
}


var months = new Array();
months = ["Jan. ","Feb. ","Mar. ","Apr. ","May ","Jun. ","Jul. ","Aug. ","Sep. ","Oct. ","Nov. ","Dec. "];
var days = new Array();
days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

function ShowDate(){
	var today = new Date();
	document.write(days[today.getDay()] +", "+ months[today.getMonth()] + today.getDate() +", "+ today.getFullYear());
}

//Date display function for Australia
function ShowDate_au(){
	var today = new Date();
	document.write(days[today.getDay()] +", "+ today.getDate() +" "+ months[today.getMonth()] +" "+ today.getFullYear());
}

function LaunchTool(toolHTMLFile) {
	window.open(toolHTMLFile,'_blank','width=561,height=336,top=20,left=10,resizable=yes');
}

function LaunchHelp(helpHTMLFile) {
	window.open(helpHTMLFile,'Trouble','width=200,height=300,top=20,left=520,scrollbars=yes');
}


//VERSION 7.0 UPDATES TO THE STANDARD.JS FILE 5-5-00 BY B.SARSANY 
//Date function to change GMT string to local
function gmt2local(gmt,area){
	var today = new Date(gmt);
	var offst = today.toLocaleString();
	if (area == 1){
	
	document.write(days[today.getDay()] +", "+ months[today.getMonth()] + today.getDate() +", "+ today.getFullYear());
	}
	else {
	if (area == 2){
	document.write(days[today.getDay()] +", "+ today.getDate() +" "+ months[today.getMonth()] +" "+ today.getFullYear());
}
}
}



//Function to convert the offset and GMT time to local time
function date_calc(gmt,offset) {
	var today = new Date(gmt);
	var hours = offset;
	
	
	var houroffset=(60*60*1000*offset);
	
	var parsedate = Date.parse(today);
	var newdate=(parsedate+houroffset);
	var finaldate = new Date(newdate);
	return(finaldate);
	//document.write(finaldate);
	}
	
	
//Date function to change format of the date passed in
//display types
//type "" = type 1 us/au 
//type 1  = 'wednesday, Apr. 5, 2000' or 'wednesday, 5 Apr. 2000'
//type 2  = '10:50 pm'
//type 3  = 'mm/dd/yy' 
function date_formatter(gmt,area,disp) {
if (disp == ""){
	var today = new Date(gmt);
	var offst = today.toLocaleString();
	if (area == 1){
	
	document.write(days[today.getDay()] +", "+ months[today.getMonth()] + today.getDate() +", "+ today.getFullYear());
	}
	else {
	if (area == 2){
	document.write(days[today.getDay()] +", "+ today.getDate() +" "+ months[today.getMonth()] +" "+ today.getFullYear());
}
}
}

if (disp == "1"){
	var today = new Date(gmt);
	var offst = today.toLocaleString();
	if (area == 1){
	
	document.write(days[today.getDay()] +", "+ months[today.getMonth()] + today.getDate() +", "+ today.getFullYear());
	}
	else {
	if (area == 2){
	document.write(days[today.getDay()] +", "+ today.getDate() +" "+ months[today.getMonth()] +" "+ today.getFullYear());
}
}
}


if (disp == "2"){
	var today = new Date(gmt);
	
	hours = ["1","2","3","4","5","6","7","8","9","10","11","12","1","2","3","4","5","6","7","8","9","10","11","12"];
	var temp = today.getHours();
	
	//var ammm = "am";
	if (temp <= 12){var ampm = "AM";}else{var ampm = "PM";}
	
	var offst = today.toLocaleString();
	if (area == 1){
	
	document.write(hours[today.getHours()] +":"+ today.getMinutes() +" "+ ampm);
	}
	else {
	if (area == 2){
	document.write(hours[today.getHours()] +":"+ today.getMinutes() +" "+ ampm);
}
}
}

if (disp == "3"){
	var today = new Date(gmt);
	
	var offst = today.toLocaleString();
	if (area == 1){
	
	document.write(today.getMonth() +"/"+ today.getDate() +"/"+ today.getYear());
	}
	else {
	if (area == 2){
	document.write(today.getMonth() +"/"+ today.getDate() +"/"+ today.getYear());
}
}
}

}

document.writeln("<LINK REL='SHORTCUT ICON' HREF='/bcom/images/logo.ICO'>");