// JavaScript Document
function UniWin()
{
	this.width = window.innerWidth != undefined ? window.innerWidth : document.body.offsetWidth;
	this.height = window.innerHeight != undefined ? window.innerHeight : document.body.offsetHeight;
}

function plotSize() {
	var uniwin = new UniWin();
	var screenheight = screen.height;
	var screenwidth = screen.width;
	var browserheight = uniwin.height;
	var browserwidth = uniwin.width;
	/*  	window.alert( 'Screen Height = ' + screenheight );
	window.alert( 'Screen Width = ' + screenwidth );
	window.alert( 'Browser Height = ' + browserheight );
	window.alert( 'Browser Width = ' + browserwidth );*/
	if (browserwidth < 1016) {
		setBrowserSize('1024', browserheight);
		var uniwin = new UniWin();
		var browserwidth = uniwin.width;
		if (browserwidth < 995) {
			window.alert( 'This site is best viewed with a minimum width of 1024 pixels - please consider increasing the width of your browser if possible.' );
		}
	}
	var uniwin = new UniWin();
	var browserwidth = uniwin.width;
	var d=new Date(); 
	var e=d.getTime();
	setCookie("browserwidth", browserwidth, 365);
	Div_hide('plotrefresh');
	if (ge('ship_d')) {
		ge('ship_d').title = "Please wait — generating plots...";
		var plotname1 = "/carbon-ops/images/d-" + e + ".png";
		var image1 = new Image();
    	image1.onload = function() { 
			ge('ship_d').src = this.src;
			ge('ship_d').title = "Click to view data plots from RRS Discovery";
		};	
		image1.src = plotname1;
	}
	if (ge('ship_jc')) {
		ge('ship_jc').title = "Please wait — generating plots...";
		var plotname2 = "/carbon-ops/images/jc-" + e + ".png";
		var image2 = new Image();
    	image2.onload = function() { 
			ge('ship_jc').src = this.src;
			ge('ship_jc').title = "Click to view data plots from RRS James Cook";
		};	
		image2.src = plotname2;
	}
	if (ge('ship_jr')) {
		ge('ship_jr').title = "Please wait — generating plots...";
		var plotname3 = "/carbon-ops/images/jr-" + e + ".png";
		var image3 = new Image();
    	image3.onload = function() { 
			ge('ship_jr').src = this.src; 
			ge('ship_jr').title = "Click to view data plots from RRS James Clark Ross";
		};
		image3.src = plotname3;
	}
	if (ge('ship_pd')) {
		ge('ship_pd').title = "Please wait — generating plots...";
		var plotname4 = "/carbon-ops/images/pd-" + e + ".png";
		var image4 = new Image();
    	image4.onload = function() { 
			ge('ship_pd').src = this.src;
			ge('ship_pd').title = "Click to view data plots from RV Prince Madog";
		};
		image4.src = plotname4;
	}
	if (ge('ship_pq')) {
		ge('ship_pq').title = "Please wait — generating plots...";
		var plotname5 = "/carbon-ops/images/pq-" + e + ".png";
		var image5 = new Image();
    	image5.onload = function() { 
			ge('ship_pq').src = this.src; 
			ge('ship_pq').title = "Click to view data plots from RV Plymouth Quest";
		};
		image5.src = plotname5;
	};
}

function setBrowserSize(w,h) {
	moveTo(0, 0);
	if( typeof( window.innerHeight ) == 'number' ) {
	    window.innerWidth = w;
		window.innerHeight = h;
	} else {
	   	resizeTo(w, h);
	}
    return false;
}

function ge(id)
{
    return document.getElementById(id);
}

function windowSize() {
	var ver = navigator.appVersion;
	if (ver.indexOf("MSIE") != -1) {
		var uniwin = new UniWin();
		var browserwidth = uniwin.width;
		var browserwidthprev = getCookie('browserwidth');
		if (browserwidth != browserwidthprev) {
			Div_show('plotrefresh');
		}	
	} else {
		plotSize();
		Div_hide('plotrefresh');
	}
}

    function pause(numberMillis) {
        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true) {
            now = new Date();
            if (now.getTime() > exitTime)
                return;
        }
    }

function gotoplots(ship) {
	setCookie("ship", ship, 365, "/carbon-ops/data/plots/");
	window.location = "/carbon-ops/data/plots/";
}

function setimagewidth(imageid) {
	if(!ge(imageid).src.indexOf('loading.gif')) {
		ge(imageid).width = 416;
	} else {
		var uniwin = new UniWin();
		var browserwidth = uniwin.width;
		ge(imageid).width = (475+(parseInt(browserwidth) - 1048));
	}
}

function Load_Map() {
	var newhtml = '<iframe name="COPSINDX" id="mapframe" src="/maps/data/carbonops/viewer.htm" onload="plotSize();"></iframe>';
	ge('mapdiv').innerHTML = newhtml;
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 

window.onresize = windowSize;
	
