/* Functions required on 'weather' pages */

/* Controls check-box toggling of map layers */
var maplayerimage;
function togglelayer(mapname) {
  //status check
  docid = 'toggle'+imglayertype; 
  if (document.getElementById(docid).checked) {
  maplayerimage='http://www.metoffice.gov.uk/weather/images/'+imglayertype+'_'+mapname+'.gif'
  document.map.mapimg.alt = imglayertype.substr(0,1).toUpperCase()+imglayertype.substr(1);
  document.map.mapimg.src = maplayerimage;
  }
  else {
  document.map.mapimg.alt = "";
  document.map.mapimg.src = 'http://www.metoffice.gov.uk/lib/template/spacer.gif';
  }
}

var maplayers = new Array();
var maplayersimages = new Array();
var maplayersalts = new Array();
var image;
var types = new Array('relief','boundaries','motorway','primroads');
function togglelayers(mapname) {
  //status check
  if (document.getElementById('togglerelief').checked) {maplayers[0] = true;}else{maplayers[0] = false;}
  if (document.getElementById('toggleboundaries').checked) {maplayers[1] = true;}else{maplayers[1] = false;}
  if (document.getElementById('togglemotorways').checked) {maplayers[2] = true;}else{maplayers[2] = false;}
  if (document.getElementById('toggleroads').checked) {maplayers[3] = true;}else{maplayers[3] = false;}
  //
  for (i=0;i<types.length;i++) {
  if (maplayers[i]) {
  maplayersimages[i]='/weather/images/'+types[i]+'_'+mapname+'.gif'
  maplayersalts[i]=types[i].toUpperCase();
  } else {
  maplayersimages[i]='/lib/template/spacer.gif';
  maplayersalts[i]='';
  }
  document.map.mapimg[i].alt = maplayersalts[i];document.map.mapimg[i].src = maplayersimages[i];
  }
  }


function cboxclick(item,type,mapname)
{

	if (isArray(document.map.map)) {
		cbox = document.map.map[item];
		image = document.map.mapimg[item]
	} else {
		cbox = document.map.map;
		image = document.map.mapimg
	}
	// check if already checked and toggle
	if (cbox.checked) { 
		cbox.checked=false; 
		image.src='http://www.metoffice.gov.uk/lib/template/spacer.gif'
	}
	else { 
		cbox.checked=true; 
		image.src='http://www.metoffice.gov.uk/weather/images/'+type+'_'+mapname+'.gif'
	}
		
}

function updateProgress(id, day) {

	if ((id != '') || (id == 0)) {
		updateHourProgress(id)		
	}
	if ((day != '') || (day == 0)) {
		updateDayProgress(day)		
	}
	
}

function updateHourProgress(id) {

	maxids = 24
	// Deselect all the 'hour' tabs first
	for (var i=0; i<maxids; i++) {
		idname = 'p'+i
		identity=document.getElementById(idname);
		if (identity != null) {
			identity.className='progressbar';
		}
	}

	// Then grey-out the past hours
	for (var i=0; i<map.FirstImg; i++) {
		idname = 'p'+i
		identity=document.getElementById(idname);
		if (identity != null) {
			identity.className='deselected';
		}
	}

	// Then change the style of the selected hour to 'selected'
	idname = 'p'+id
	identity=document.getElementById(idname);
	if (identity != null) {
		identity.className='progressbarSel';
	}
	document.cookie="imagenumber="+id //to remember the image number when you go to a new page
}

function updateDayProgress(day) {

	maxids = 6

	// Deselect all the 'day' tabs first
	for (var i=0; i<maxids; i++) {
		idname = 'd'+i
		identity=document.getElementById(idname);
		if (identity != null) {
			identity.className='progressbar';
		}
	}

	// Then grey-out the past hours
	for (var i=0; i<map.FirstImg; i++) {
		idname = 'p'+i
		identity=document.getElementById(idname);
		if (identity != null) {
			identity.className='deselected';
		}
	}

	// Then change the style of the selected day to 'selected'
	idname = 'd'+day
	identity=document.getElementById(idname);
	if (identity != null) {
		identity.className='progressbarSel';
	}
	
}

function updateAltTags (Num) {
		
        for (i=0; i<map.FrameTags[Num].length; i++) {
                idname = 's'+i
				identity=document.getElementById(idname);
				if (identity != null) {
	                identity.alt = map.FrameTags[Num][i]
    	            identity.title = map.FrameTags[Num][i]
				}
        }

}

function changeLayers(id) {

	ids = new Array ('d1to2','d3to5','d6to15','seasonal')	
	
	MM_setTextOfLayer('textForecast','',eval(id))
	
	for (var i=0; i<4; i++) {
		identity=document.getElementById(ids[i]);
		identity.className='deselectedTab';
	}
	
	identity=document.getElementById(id);
	identity.className='selectedTab';

}

/* This is temporary, until the text forecast processing is in place */
//var currentLayer = 'd1to2'
//var seasonal = "<h3>Seasonal forecasting:</h3><p class=\"smallPara\">Seasonal forecasting is a developing area of meteorology and, although these forecasts are not as accurate as our short-term forecasts, they do demonstrate some skill in predicting what may happen for a season (a three-month period) ahead.</p><p>The forecasts provide an estimation of broad trends in temperature and rainfall and will normally be expressed in probabilistic terms, with the more likely outcome highlighted.  Information contained in these forecasts can allow business to plan ahead for weather that is forecast to be different from normal.</p><p><a href='/weather/seasonal/winter2008_9/'>Early indications for Winter 2008/9</a> Issued: Thu 10 July 2008</p><p><a href='/weather/seasonal/summer2008/'>Forecast for the remainder of Summer 2008</a> Updated: Wed 30 July 2008</p><p><a href='/weather/seasonal/spring2008/'>Spring 2008 forecast appraisal</a> Updated: Wed 6 Aug 2008</p><p><a href='/weather/seasonal/winter2007_8/'>Winter 2007/8 forecast appraisal</a> Updated: Wed 7 May 2008</p>"
/* end temporary code */
