function Set_Cookie( name, value, expires)
{
	var path = "/";

	// set time, it's in millisecond s
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" );
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) 
{
	// first we split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we are at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) 
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function emptyframe()
{
	//window.frames["METAR"].document.body.innerHTML='<span style="font-size:10px;font-weight:bold;font-family:verdana;"><img src="/loading.gif" width="13px" height="13px"/> Loading. Please wait ...</span>';
	//document.getElementById('METAR').innerHTML='<span style="font-size:10px;font-weight:bold;font-family:verdana;"><img src="/loading.gif" width="13px" height="13px"/> Loading. Please wait ...</span>';

	document.getElementById('METAR').src='about:blank';

	// var iframeWin = window.frames.METAR;
	// iframeWin.document.open();
	// iframeWin.document.write('<span style="font-size:10px;font-weight:bold;font-family:verdana;"><img src="/loading.gif" width="13px" height="13px"/> Loading. Please wait ...</span>');
	// iframeWin.document.close();

	return true;
}

function load_frames()
{
	document.body.style.display = '';
	// For the donate page to open, commented the metar submit and added src=donate.php
	document.forms.CA_METAR.submit();
	// document.getElementById('METAR').src='/donate.php';
}

function update_metar()
{
	document.getElementById('METARCELL').innerHTML = '<a name="METARTOP"/><div id="METARDIV" style="display:block;text-align:center;color:red; font-size:10px;font-weight:bold;margin:0px;padding:0px;"> <a style="color:black; text-decoration:none;background-color: red;" href="javascript:expand_metar()">&lt;--Expand Frame--&gt;</a></div> <IFRAME ID="METAR" NAME="METAR" WIDTH=100% HEIGHT=220 MARGINWIDTH=10 MARGINHEIGHT=10 SCROLLING=YES HSPACE=10 VSPACE=1 style="border-style:inset;border:1px solid #00a0ff;"> <A HREF="/weather/metar.php">If you can see this, your browser does not understand IFRAME.  Please click here to go to the METAR page</A> </IFRAME>';
	document.getElementById('METAR').src='http://www.67knots.com/weather/metar.php';
}

function update_winds()
{
	document.getElementById('WINDCELL').innerHTML = '<div style="display:block;text-align:center;color:red; font-size:10px;font-weight:bold;padding-bottom:0px;margin-bottom:0px;"> <IFRAME ID="WINDS" NAME="WINDS" WIDTH=100% HEIGHT=150 MARGINWIDTH=10 MARGINHEIGHT=5 FRAMEBORDER=0 SCROLLING=NO HSPACE=10 VSPACE=1> <A HREF="/weather/winds.html">If you can see this, your browser does not understand IFRAME.  Please click here to go to the Winds page</A> </IFRAME> <a style="color:red; text-decoration:none;" href="javascript:update_winds()">Wind information is updated every 15 mins from NavCanada website. <br>Click here to update now [... takes a minute]</a> </div>';
	document.getElementById('WINDS').src='http://www.67knots.com/weather/update.php?get=winds';
}

function expand_metar()
{
	document.getElementById('METARCELL').innerHTML = '<a name="METARTOP"/><div id="METARDIV" style="display:block;text-align:center;color:red; font-size:10px;font-weight:bold;margin:0px;padding:0px;"> <a style="color:black; text-decoration:none;background-color: red;" href="javascript:shrink_metar()">--&gt;Shrink Frame&lt;--</a></div> <IFRAME ID="METAR" NAME="METAR" WIDTH=100% HEIGHT=480 MARGINWIDTH=10 MARGINHEIGHT=10 SCROLLING=YES HSPACE=10 VSPACE=1 style="border-style:inset;border:1px solid #00a0ff;"> <A HREF="/weather/metar.php">If you can see this, your browser does not understand IFRAME.  Please click here to go to the METAR page</A> </IFRAME>';
	document.getElementById('METAR').src='http://www.67knots.com/weather/metar.php';
	document.location.href="#METARTOP";
}

function shrink_metar()
{
	document.getElementById('METARCELL').innerHTML = '<a name="METARTOP"/><div id="METARDIV" style="display:block;text-align:center;color:red; font-size:10px;font-weight:bold;margin:0px;padding:0px;"> <a style="color:black; text-decoration:none;background-color: red;" href="javascript:expand_metar()">&lt;--Expand Frame--&gt;</a></div> <IFRAME ID="METAR" NAME="METAR" WIDTH=100% HEIGHT=220 MARGINWIDTH=10 MARGINHEIGHT=10 SCROLLING=YES HSPACE=10 VSPACE=1 style="border-style:inset;border:1px solid #00a0ff;"> <A HREF="/weather/metar.php">If you can see this, your browser does not understand IFRAME.  Please click here to go to the METAR page</A> </IFRAME>';
	document.getElementById('METAR').src='http://www.67knots.com/weather/metar.php';
	document.location.href="#DOCTOP";
}

function findX(obj) 
{
	var curleft = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
		}
	}
	return curleft;
}

function findY(obj) 
{
	var curtop = 0;
	if (obj.offsetParent) 
	{
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function getWindowSize(t)
{

	var windowX = 0;
	var windowY = 0;

	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		windowX = window.innerWidth;
		windowY = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		windowX = document.documentElement.clientWidth;
		windowY = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		windowX = document.body.clientWidth;
		windowY = document.body.clientHeight;
	}

	if (t == "X") { return windowX; }
	if (t == "Y") { return windowY; }
}

function resizeIframe(multiply)
{
	var x = getWindowSize('X');
	var y = getWindowSize('Y');

	var obj = document.getElementById('TIMESTAMP');

	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}

	var space = y - curtop - 15;
	var size = metarsize;

	if (multiply == 0)
	{
		size = size + space;
	}
	else if (multiply == 1)
	{
		size = size + space;
	}
	else
	{
		size = size * multiply;
	}

	metarsize = size;
	document.getElementById('METAR').height = metarsize;
	Set_Cookie('metarsize', metarsize, 30);
}

