// Firefox compatibility add-on for Weather-File.com
// version 0.1 BETA!
// 2009-10-26
// Copyright (c) 2009, James Blatchford
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Weather-File.com Compatibility
// @namespace     http://www.jard.co.uk/scripts/weatherfile
// @description   Firefox compatibility add-on for Weather-File.com's R-P-R weather stations
// @include       http://www.weather-file.com/highcliffe/
// @include       http://www.weather-file.com/highcliffe/index.htm
// @include       http://www.weather-file.com/hurst/
// @include       http://www.weather-file.com/lymington/
// @include       http://www.weather-file.com/portland/
// @include       http://www.weather-file.com/portland2/
// ==/UserScript==

var CurrURL = window.location.href;
// GM_log(CurrURL);
var CurrURLParts = CurrURL.split("/");

// Original frameset page has a meta refresh tag - kill that
var allMetas = document.getElementsByTagName('meta');
for (var i = 0; i < allMetas.length; i++) {
	thisMeta = allMetas[i];
	if (thisMeta.httpEquiv.match(/refresh/i)) {
		thisMeta.parentNode.removeChild(thisMeta);
		window.addEventListener("load", function(){window.stop();}, false); // STOP REFRESH
//		GM_log("RPR - Stopped meta-refresh");
	}
}

allFrames = document.getElementsByTagName('frame');
for (var j = 0; j < allFrames.length; j++) {
	thisFrame = allFrames[j];
	if (thisFrame.name.match(/dataset/i)) {
//		GM_log("RPR - Removing MS Tabular data control page");
		thisFrame.src = 'http://www.jard.co.uk/cgi-bin/rpr-weather/w.pl?site='+CurrURLParts[3];
//		GM_log("RPR - Now redirected to "+thisFrame.src);
	}
}

