
/* ident '@(#)news_index.js	1.1' */

function sort_by( field ) {
	var f = document.forms['search_options_form'];
	f.sort_by.value = field;
	f.submit();
}

function date_range( field ) {
	var f = document.forms['search_options_form'];
	f.date_option.value = field;
	f.submit();
}

function change_page( page_no ) {
    var f = document.forms['search_options_form'];
    f.page_no.value = page_no;
	f.submit();
}

function scroll_nav() { // IE only
    var sd = document.getElementById('scroller');
	var st = sd.scrollTop;
	var nd = document.getElementById('sidebar');
	nd.style.top = st;
	var nb = document.getElementById('sidebarbackground');
	nb.style.top = st;
}

function reformatHTML()
{
	// Open the links in the parent window
	var A = document.getElementsByTagName('A');
	for ( var i = 0; i < A.length; i ++ )
	{
		// If it's not a javascript link
		if ( A[i].href.indexOf('javascript:') == -1 )
		{
		    A[i].href = 'javascript:popup("' + A[i].href + '", 850, 480 );';
		    A[i].target = '_self';
		}
		// If it's an article link
		if ( A[i].className && ( A[i].className == 'articlelink' ))
		{
			// Then change the text
			A[i].innerHTML = 'read full article in a popup window';
		}
	}
	// Append the date to the end of the title
	var D = document.getElementsByTagName('DIV');
	for ( var i = 0; i < D.length; i ++ ){
		if ( D[i].className == 'date' ){
			var date = reformatDate( D[i].innerHTML.toString() );
		    D[i+1].innerHTML += '<br /><span class="date">' + date + '</span>';
			i ++; // skip the title div
		}
	}
}

function reformatDate( d ){
	d = d.split('\n').join(''); // Remove new lines
	d = d.split('\r').join(''); // Remove carriage returns
	d = ' ' + d; // Ensure it has a preceding space for IE
	var month, day, date;
	var md = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var mn = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	do { // Recursively replace double spaces with singles until there are none
		d = d.split('  ').join(' ');
	} while ( d.indexOf('  ') != -1 );
	date = d.split(' '); // Split up the string
	day = date[2];
	for ( var i = 0; i < 12; i ++ ){ // months
		if ( date[3] == md[i] ){ // if match
			month = mn[i]; // get month name
			break;
		}
	}
	// return formatted date
	return day + ' ' + month + ' ' + date[4];
}

function popup( win, w, h )
{
  if ( window.pop ){ window.pop.close(); } // close an open one
  pop = window.open( win,'news_popup','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no,copyhistory=no,locationbar=no,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0');
}
window.onload = function(){ reformatHTML(); if (document.all){ scroll_nav(); } }


