var doc=document,win=window,sById=(doc.getElementById)?true:false;
function setStyleName(objId, styleName) {document.getElementById(objId).style.display = styleName;}
function setCookie(name,value,expires,path,domain,secure){document.cookie=name+'='+escape(value)+((expires)?';expires='+expires.toGMTString():'')+';path='+((path)?path:'/')+';domain='+((domain)?domain:'boston.com')+((secure)?';secure':'');}

function ifSafari() {if((navigator.userAgent.indexOf("Macintosh")!=-1)||(navigator.userAgent.indexOf("Mac_PowerPC")!=-1)){document.write("<style type='text/css' media='all'>@import 'http://www.boston.com/universal/css/bcom_hp_styles_safari.css';</style>")};}


function getCookie(name){var dc=document.cookie,prefix=name+'=',begin=dc.indexOf('; '+prefix);if(begin==-1){begin=dc.indexOf(prefix);if(begin!=0)return null;}else begin+=2;var end=dc.indexOf(';',begin);if(end==-1)end=dc.length;return unescape(dc.substring(begin+prefix.length,end));}

function expireCookie(name,path,domain){document.cookie=name+'=;expires=Thu, 01-Jan-70 00:00:01 GMT;path='+((path)?path:'/')+';domain='+((domain)?domain:'boston.com');}

function windowLoaded(){}
/* For two tab and three tab widget */
function tabs(view,hideA,hideB) {
  if (view.style.visibility == "hidden")
    {view.style.visibility = "visible"; view.style.display = "block"; hideA.style.visibility = "hidden"; hideB.style.visibility = "hidden"; hideA.style.display = "none"; hideB.style.display = "none";}
  else {view.style.visibility = "visible"; view.style.display = "block";}
}

function tabs2(view,hideA) {
  if (view.style.visibility == "hidden")
    {view.style.visibility = "visible"; view.style.display = "block"; hideA.style.visibility = "hidden"; hideA.style.display = "none";}
  else {view.style.visibility = "visible"; view.style.display = "block";}
}


/* Local Search Form Omniture Tracking for sitewide topRight form */
var var5='hp_header_';

function keyword(){
  if (document.getElementById('textField').value != "" && document.getElementById('textField').value != null){return document.getElementById('textField').value.toLowerCase();}
  else{return "User_Blank"}
}

var otherTab;
   function choose(tab){
     if (tab != otherTab){
     tab.className="searchOn";
     otherTab.className="";
     otherTab=tab;
       if (tab.id == "searchLocal"){
         document.getElementById("tab").value="";
       } else if (tab.id == "searchSite"){
         document.getElementById("tab").value="ssearch";
       }
     }
   }

function searchSubmit(){
omnitureCode(document.getElementById("tab"));
}

function omnitureCode(tabName){
  var temp5 = var5;
  if (tabName.value==""){if(document.getElementById('p1')!=null){document.getElementById('p1').value='Header_Searchbox_GreaterBoston'};temp5=var5 + 'searchbox_greaterboston';}
  if (tabName.value=="ssearch"){if(document.getElementById('p1')!=null){document.getElementById('p1').value='Header_Searchbox_Site'};temp5=var5 + 'searchbox_site';}
if(keyword()!="User_Blank"){  
s_linkType='o'; s_linkName='search_query'; s_eVar2=keyword(); s_eVar5=temp5; s_lnk=s_co(document.getElementById('searchForm')); s_gs('nytbglobe');}
  
}

function openWindow(url,name,props){try{props=props.replace(/(resizable|scrollbars)\=no/g,'$1=yes');var nw=win.open(url,name,props);nw.focus();window.event.cancelBubble=true;}catch(e){}}  
function MM_openBrWindow(url,name,props){openWindow(url,name,props);}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* For Search pages - Podzinger */

var doc=document,win=window,sById=(doc.getElementById)?true:false; 
function openWindow(url,name,props){try{props=props.replace(/(resizable|scrollbars)\=no/g,'$1=yes');var nw=win.open(url,name,props);nw.focus();window.event.cancelBubble=true;}catch(e){}}   

var bcHomepage;
var bcCategoryPage;
var homepageSWF = "homepage_thumbs"; //shorthand for ExternalInterface calls
var categorySWF = "category_thumbs"; //shorthand for ExternalInterface calls
var titleIDs = new Array();


function onTemplateLoaded()
{
	//set listeners for the player
	callFlash("addEventListener", "contentLoad", "onContentLoad");	
	callFlash("addEventListener", "mediaReady", "onMediaReady");
	
	//get elements from the page
	bcHomepage = document.getElementById("bcHomepage");
	bcCategoryPage = document.getElementById("bcCategoryPage");
	bcArticlePage = document.getElementById("bcArticlePage");
	bcRelatedVideos = document.getElementById("bcRelatedVideos");
	bcPlayerThumbnails = document.getElementById("bcPlayerThumbnails");
	bcThumbnailTitle = document.getElementById("bcThumbnailTitle");
	bcTitleHeadline = document.getElementById("bcTitleHeadline");
	bcPaging = document.getElementById("bcPaging");
	bcDescription = document.getElementById("bcDescription");
	bcVideoHeader = document.getElementById("bcVideoHeader"); //the VIDEO header on the article page
}

function onContentLoad()
{
	if(bcHomepage || bcCategoryPage) callFlash("getFeaturedLineup"); //if it's the homepage player or category player...
	if(bcHomepage) thisMovie(homepageSWF).unhide(); //remove the covering piece
	
	if(bcArticlePage) onMediaReady(); //manual call
}

function onMediaReady()
{
	callFlash("getCurrentTitle");	
}

function getCurrentTitle_Result(titleDTO)
{
	//for the category and article pages
	if(bcTitleHeadline) bcTitleHeadline.innerHTML = titleDTO.displayName;
	if(bcDescription) bcDescription.innerHTML = titleDTO.shortDescription;
	if(bcVideoHeader) bcVideoHeader.style.visibility = "visible"; //show the VIDEO header on the article page
}

function getFeaturedLineup_Result(lineupDTO)
{
	titleIDS = new Array();
	titleIDs = lineupDTO.videoIds; //assign the array from the lineupDTO
	
	//build up a list of the title ids of the current (featured) lineup
	for(var i = 0; i < lineupDTO.videoIds.length; i++)
	{
		callFlash("getTitleById", lineupDTO.videoIds[i]); //get each titleDTO from the lineup
	}
	
	if (bcRelatedVideos) bcRelatedVideos.innerHTML = "RELATED VIDEOS (" + lineupDTO.videoIds.length + ")";
	if (bcRelatedVideos) bcRelatedVideos.style.color = "#000";
	onMediaReady();

	if (bcHomepage) thisMovie(homepageSWF).getPage("next"); //run the getPage function in the swf
	if (bcCategoryPage) thisMovie(categorySWF).buildThumbnails();
}

function getTitleById_Result(titleDTO)
{
	//builds the arrays in the swf
	if (bcHomepage) thisMovie(homepageSWF).buildTitleIDs(Number(titleDTO.id));
	if (bcHomepage) thisMovie(homepageSWF).buildTitles(String(titleDTO.displayName));
	if (bcHomepage) thisMovie(homepageSWF).buildThumbArray(String(titleDTO.thumbnailURL));
	if (bcCategoryPage) thisMovie(categorySWF).buildTitleIDs(Number(titleDTO.id));
	if (bcCategoryPage) thisMovie(categorySWF).buildTitles(String(titleDTO.displayName));
	if (bcCategoryPage) thisMovie(categorySWF).buildThumbArray(String(titleDTO.thumbnailURL));
	if (bcCategoryPage) thisMovie(categorySWF).buildDescriptions(String(titleDTO.shortDescription));
	
	//build up the arrays we'll need for later
	/*
	titleNames.push(titleDTO.displayName);
	thumbnails.push(titleDTO.thumbnailURL);	
	descriptions.push(titleDTO.shortDescription);
	*/
}

//for the purposes of the external interface API with flash, since microsoft and mozilla have different references to the swf file
function thisMovie(movieName) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
	{
        return window[movieName];
    }
    else 
	{
        return document[movieName];
    }
}

var doc=document,win=window,sById=(doc.getElementById)?true:false;

// popup
function openWindow(url,name,props){try{props=props.replace(/(resizable|scrollbars)\=no/g,'$1=yes');var nw=win.open(url,name,props);nw.focus();window.event.cancelBubble=true;}catch(e){}}  
				  
// Code for onHover - Homepage 
var primary_id='tab1';

// Dan's additions for TTD widget fix on HomePage
function switchTab1(){document.getElementById('tab1').className='active';document.getElementById('tab2').className='';document.getElementById('tab3').className='';document.getElementById('zventsFooter').style.display='block'}
			function switchTab2(){document.getElementById('tab1').className='';document.getElementById('tab2').className='active';document.getElementById('tab3').className='';document.getElementById('zventsFooter').style.display='block'}
			function switchTab3(){document.getElementById('tab1').className='';document.getElementById('tab2').className='';document.getElementById('tab3').className='active';document.getElementById('zventsFooter').style.display='none'}
			var primary_id='tab1';
			function switchTabA(){document.getElementById('tabA').className='active';document.getElementById('tabB').className=''}
			function switchTabB(){document.getElementById('tabA').className='';document.getElementById('tabB').className='active'}
			function ShowDiv(a,b,c,d){
				var i;
				if(c) {i=c} else {i=1};
				var z;
				while(z=document.getElementById(b+i)){
					if((i>=c)&&(i<=d)){
						if(i==a){
							z.style.display='block'
						}else{
							z.style.display='none'
						}
					}
					i++
				}
			}
			
//-------------------------------------------------------------------------------------------------
// Simple tab clicker from Zvents
//-------------------------------------------------------------------------------------------------
// <ul>
//     <li><a id="tabOne" onclick="tabber.click(this);">One</a></li>
//     <li><a id="tabTwo" onclick="tabber.click(this);">Two</a></li>
// </ul>
// <div id="divOne">
//     Tab One Content
// </div>
// <div id="divTwo">
//     Tab Two Content
// </div>
//-------------------------------------------------------------------------------------------------

tabber = {

	// Click a tab: give it the 'active' class and show its matching DIV
	click: function( clicked ) {
		var ul = clicked.parentNode.parentNode;  // A --> LI --> UL
		var tabs = ul.getElementsByTagName('a');
		
		for( i = 0;  i < tabs.length;  ++i ) {
			var a = tabs[i], on = ( a == clicked );
			a.className = ( on ? 'active' : '' );
			tabber.show( a.id.replace(/^tab/,'div'), on );
		}
	},
	
	// Special clicker for Zvents Today/Tomorrow/Search tabs:
	// hide or show footer, and load tomorrow's events on demand
	zclick: function( clicked, when ) {
		tabber.click( clicked );
		tabber.show( 'zventsFooter', ! when );
		
		if( ZventsTomorrowID && when == 'Tomorrow' ) {
			Z.widget.popular({
				id: ZventsTomorrowID,
				load: { when: when }
			});
			ZventsTomorrowID = null;
		}
	},
	
	// Show or hide a block level element
	show: function( id, show ) {
		document.getElementById(id).style.display =
			show ? 'block' : 'none';
	}
};
			
// james stuff added today

function keywordSelect(inputfield){
                if (document.getElementById(inputfield).value != "" && document.getElementById(inputfield).value != null){return document.getElementById(inputfield).value.toLowerCase();}
                else{return "User_Blank"}
              }            
             
             
              function travelWidgetSubmit(){
                var kw="";
		if (document.getElementById('textField2').value==""){
                alert('Please enter a keyword, like "Maine" or "Bermuda hotels"');
                }else{
                document.getElementById('travelSearchWidget').submit();
		kw="Travel-"+keywordSelect('textField2'); 
                travelWidgetomnitureCode('searchbox',kw);
                }
              }
              
              function travelWidgetomnitureCode(tabName,keyword,sco){      
                var temp5 = var5;              
                temp5=var5 + 'travel'+tabName;
                s_linkType='o'; s_linkName='search_query'; s_eVar2=keyword; s_eVar5=temp5; s_lnk=s_co(document.getElementById('searchForm')); s_gs('nytbglobe');
              }

var count=0;
                  
                  function clickLink(){
                  var widgetkeyword='';
                    if(count == 0){
                      count++;
                    }
                    else if (count==1){
                      var mylist=document.getElementById("destinations")
                      var urlString = mylist.options[mylist.selectedIndex].value;
            
                      if (urlString !='none'){
                        if (urlString.match('s.sm.query=')){
                          widgetkeyword = 'Travelbrowse-' + urlString.substring(urlString.indexOf('s.sm.query=')+11);
                          travelWidgetomnitureCode('browse',widgetkeyword);                        
                        }
                         window.location=mylist.options[mylist.selectedIndex].value
                      }                      
                      count=0;
                     
                    }
                  }

//NYTD Pixel
var Nytd_Pixel_rel_version = "0.1";
var Nytd_Pixel_values = new String();
var Nytd_Pixel_global_values = new String("&g=");

function Nytd_Pixel_addGlobalTaxonomyValue(value) {
  if (Nytd_Pixel_global_values.charAt(Nytd_Pixel_global_values.length-1) != '=') { Nytd_Pixel_global_values += "/"; }
  Nytd_Pixel_global_values += value;
}

function Nytd_Pixel() {
  if (Nytd_Pixel_global_values.length != 0){ Nytd_Pixel_values += Nytd_Pixel_global_values; }
  Nytd_Pixel_values += "&u=" + escape(document.URL);
  document.write('<img src="http://up.nytimes.com/?d=2' + Nytd_Pixel_values + '" height="1" width="1" border="0" id="upixel">');
}

// Registration, Redesigned
function showLoginRRD(twidth){
  if(!twidth)twidth=191;
  var cookie1=getCookie('pathAuth'),cookie2=getCookie('pathAuthSess');
  if(cookie1!=null||cookie2!=null){
  	document.writeln('<div align="center"><span id="mc"><a href="http://www.boston.com/?__goto=mcenter">Preferences</a></span> | <span id="lo"><a href="http://www.boston.com/?__goto=logout">Log Out</a></span></div>');
	}
  else{
  	document.writeln('<div align="center"><span id="si"><a href="http://www.boston.com/?__goto=loginonlypage">Sign In</a></span> | <span id="rn"><a href="http://www.boston.com/?__goto=loginpage">Register Now</a></span></div>');
	}
}

//Digg
eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('36={7:9(6,4,5,3){35(!6)34;4=4||\'\';5=5||\'\';3=3||\'\';33.32(\'31://30.29/28-27?26=2&6=\'+6+\'&4=\'+4+\'&5=\'+5+\'&3=\'+3,20 19().17(),\'21=1,22=1,15=0,13=1,25=1,11=1,18=23,14=12,10 = 24,8 = 16\')}}', 10,37,'|||topic|title|bodytext|url|remoteSubmit|top|function|left|resizable|600|statusbar|height|location|150|getTime|width|Date|new|toolbar|scrollbars|575|470|menubar|phase|submit|remote|com|digg|http|open|window|return|if|Digg'.split('|')))

//Facebook
function fbs_click() {
  u=location.href;
  t=document.title;
  void(window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=no,width=626,height=436'));
  return false;
}

    function classySwap() {
    var foo = Math.random();
    var bar;
    if (foo < 0.33) bar = 'cars'
    else
      if (foo > 0.66 ) bar = 're'
      else bar = 'jobs';
    var baz = bar + 'CfiedContent';
    var spaz = 'g' + bar + '_on';
    var jazz = 'g' + bar;
    if (bar == 'cars') {setStyleName('gcars_on', 'block'); setStyleName('gcars', 'none'); setStyleName(baz, 'block');}
    else { setStyleName(spaz,'block'); setStyleName(jazz,'none'); setStyleName('carsCfiedContent','None'); setStyleName(baz,'block');}
    }
var globeWidgetTab;
   function chooseGlobe(tab){
     if (tab != globeWidgetTab){
     tab.className="searchOn";
     globeWidgetTab.className="";
     globeWidgetTab=tab;
       if (tab.id == "globeArchive"){
         document.getElementById("gwsort").value="-articleprintpublicationdate";
         document.getElementById("gwdateRange").value="";
       } else if (tab.id == "todayGlobe"){
         document.getElementById("gwdateRange").value="today";
 document.getElementById("gwsort").value="";
       }
     }
   }


function globeWidgetSubmit(){
omnitureGlobeCode(globeWidgetTab.id);
}

function omnitureGlobeCode(tabName){
  if (tabName=="globeArchive"){temp5=temp5 + 'globearchive';}
  if (tabName=="todayGlobe"){temp5=temp5 + 'todaysglobe';}
  if(globekeyword()!="User_Blank"){
  s_linkType='o'; s_linkName='search_query'; s_eVar2=globekeyword(); s_eVar5=temp5;s_lnk=s_co(document.getElementById('articleright_searchbox')); s_gs('nytbglobe');
}
}


function globekeyword(){
  if (document.getElementById('globeText').value != "" && document.getElementById('globeText').value != null){return document.getElementById('globeText').value.toLowerCase();}
  else{return "User_Blank"}
}


function calImage(){
        CalDate=CalDate.toLowerCase()
        if(CalDate.indexOf(":")==-1){
                dte=CalDate.split("|")
        }else{
                dte=new Array();
                tmpDte=CalDate.split("-");
                dte[0]=tmpDte[0].substring(0,3);
                dte[1]=tmpDte[1];
                dte[3]=tmpDte[2].substring(0,4);
                tmpDte=tmpDte[0].split(", ");
                dte[2]=tmpDte[1];
        }
        if(dte[2].indexOf("0")==0){dte[2]=dte[2].charAt(1)}
        gbDate=parseInt(dte[2]);
        gbMonth=dte[1];
        gbYear=dte[3];
        var ldays = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
        for(i=0;i<ldays.length;i++){
                if(gbMonth.substring(0,3)==ldays[i]){gbMonNum=i};
        }
        gbMonNum = gbMonNum + 1;
        if (gbDate < 10) (gbDate = "0" + gbDate);
        else (gbDate = gbDate);
        if (gbMonNum < 10) (gbMonNum = "0" + gbMonNum);
        else (gbMonNum = gbMonNum);
        var popParams = "'http://www.boston.com/news/globe/larger_view','largerview','width=650,height=1100,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no'";
        document.write("<a href=\"http://www.boston.com/news/globe/larger_view\" class=\"imageLink\" onclick=\"openWindow(" +popParams + "); return false;\"><img src='http://cache.boston.com/globe/" + gbYear  + "/" + gbMonNum + "/" + gbDate + "/today_thumbnail.jpeg' alt='The Boston Globe' width='189' /></a>");}

function redirectSelectMenu(smenu){if(typeof(smenu)=='string'&&sById)smenu=doc.getElementById(smenu);if(smenu){var sval=smenu.options[smenu.selectedIndex].value;if(sval)document.location.href=sval;}}

//Need to figure a way to kill this
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function displayEmbed() {};
function changeImageOn() {};
function changeImageOff() {};


