var usingStarIcons = false;

// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use

// 26Aug09 DVD	Corrected call of qrz.com to conform to their v2 spec
//  2Feb10 DVD	Added scroll wheel zoom
// 29Mar10 DVD	Changes to endpoint() for new labeled_marker

var popbackground="azure" //specify backcolor or background image for pop window
var windowtitle="Solar Info from HamQSL"  //pop window title

function detectexist(obj){
	return (typeof obj !="undefined")
}

function jkpopimage(imgpath, popwidth, popheight, href){

function getpos(){
	leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
	toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
	if (window.opera){
		leftpos-=screenLeft
		toppos-=screenTop
	}
}

	getpos()
	var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
	var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
	if (typeof jkpopwin=="undefined" || jkpopwin.closed) {
		jkpopwin=window.open("","",winattributes)
	} else {
		//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
		//jkpopwin.moveTo(leftpos, toppos)
		jkpopwin.resizeTo(popwidth, popheight+30)
	}
	jkpopwin.document.open()
	jkpopwin.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><a href="'+href+'" target="_blank"><img src="'+imgpath+'" style="margin-bottom: 0.5em"><br>'+'</a></body></html>')
	jkpopwin.document.close()
	jkpopwin.focus()
}

function endpoint (call1, text1, lat1, lon1, endIcon, startype, label) {
	var end1 = new GLatLng(lat1, lon1);
	if (startype == '') {
		if (label == 1) {
			var mark1 = createMarker(end1, call1, text1, endIcon);
		} else {
		        var mark1 = new GMarker(end1,{title:call1+text1, icon:endIcon});
		}
	} else {
		var colorArray = new Array("", "FFFF00", "#CB9D7C" );
		var starColor = colorArray[startype.substring(0,1)];
		var iconText = startype.substring(1,3);
		var icon1 = MapIconMaker.createLabeledMarkerIcon({addStar: true,
		    label: iconText, primaryColor: endIcon, starPrimaryColor: starColor});
	        var mark1 = new GMarker(end1,{title:call1+text1, icon:icon1});
	}
	map.addOverlay(mark1);
	GEvent.addListener(mark1, "click", function() { window.open('http://www.qrz.com/db/'+call1,'',
	'scrollbars=yes,menubar=no,height=600,width=850,resizable=yes,toolbar=no,location=no,status=no');});
}

function path (lat1, lon1, lat2, lon2, color, thickness, opacity) {
	var end1 = new GLatLng(lat1, lon1);
	var end2 = new GLatLng(lat2, lon2);
	if (typeof opacity == 'undefined') opacity = 1;
        var polyOptions = {geodesic:true};
        var polyline = new GPolyline([end1, end2], color, thickness, opacity, polyOptions);
	map.addOverlay(polyline);
}


function DrawGoogleMap() {
    var starttime = new Date();
    if (GBrowserIsCompatible()) {
//	alert(window.location.host); 

	blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
	greenIcon = new GIcon(G_DEFAULT_ICON);
	greenIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";
	redIcon = new GIcon(G_DEFAULT_ICON);
	redIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/red/blank.png";
	pinkIcon = new GIcon(G_DEFAULT_ICON);
	pinkIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/pink/blank.png";
	orangeIcon = new GIcon(G_DEFAULT_ICON);
	orangeIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/orange/blank.png";

	IconUnknown = new GIcon(G_DEFAULT_ICON);
	IconUnknown.image = "icons/unknown.png";
	IconLurker = new GIcon(G_DEFAULT_ICON);
	IconLurker.image = "icons/lurker.png";
	IconNPN = new GIcon(G_DEFAULT_ICON);
	IconNPN.image = "icons/npn.png";
	Icon2 = new GIcon(G_DEFAULT_ICON);
	Icon2.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/pink/marker2.png";
	Icon6 = new GIcon(G_DEFAULT_ICON);
	Icon6.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/pink/marker6.png";
	Icon10 = new GIcon(G_DEFAULT_ICON);
	Icon10.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/marker10.png";
	Icon12 = new GIcon(G_DEFAULT_ICON);
	Icon12.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/marker12.png";
	Icon15 = new GIcon(G_DEFAULT_ICON);
	Icon15.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/marker15.png";
	Icon17 = new GIcon(G_DEFAULT_ICON);
	Icon17.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/marker17.png";
	Icon20 = new GIcon(G_DEFAULT_ICON);
	Icon20.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/marker20.png";
	Icon30 = new GIcon(G_DEFAULT_ICON);
	Icon30.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/orange/marker30.png";
	Icon40 = new GIcon(G_DEFAULT_ICON);
	Icon40.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/red/marker40.png";
	Icon80 = new GIcon(G_DEFAULT_ICON);
	Icon80.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/red/marker80.png";
	Icon160 = new GIcon(G_DEFAULT_ICON);
	Icon160.image = "icons/red160.png";

        map = new GMap2(document.getElementById("map_canvas"));
	map.addMapType(G_PHYSICAL_MAP);
	map.enableScrollWheelZoom();
	var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10,10));
	map.addControl(new GSmallMapControl(),bottomLeft);
        var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
        map.addControl(new GMapTypeControl(), topRight);
	FinishGoogleMap();
    }
    var stoptime = new Date();
    return stoptime - starttime;
}

function tr(txcall, txgrid, rxcall, rxgrid, distance, color, band, score, offset, imd, age, utc) {

var	imdcolor;
if (imd.substring(0,1) == 'D') {
	imdcolor = ' bgcolor=palegreen';
	imd = imd.substring(1) + '%';
}
if (imd == 'CQ') {
	imd = "NPN";
	imdcolor = ' bgcolor=peru';
}
document.write('<tr><td align="center">' + txcall +
	'</td><td align="center">' + txgrid +
	'</td><td align="center">' + rxcall +
	'</td><td align="center">' + rxgrid +
	'</td><td align="center">' + distance +
	'</td><td align="center"><font color=' + color + '>' + band   +
	'</font></td><td align="center">' + score +
	'</td><td align="center">' + offset +
	'</td><td align="center"' + imdcolor + '>' + imd +
	'</td><td align="center">' + age +
	'</td><td align="center">' + utc +
	'</td></tr>');
}

function loadcatch(v, band, last, center, call, maptype, geo, zoom) {

var url = './catch' + v + '.php?last=' + last;
if(band)
	url = url + '&band=' + band;
if(maptype)
	url = url + '&maptype=' + maptype;
if(geo)
	url = url + '&geo=' + geo;
if(zoom)
	url = url + '&zoom=' + zoom;
if(center)
	url = url + '&center=' + center;
if(call)
	url = url + '&call=' + call;

window.location = url;

}

function loadself(v, band, last, center, call, maptype, geo, zoom) {

var url = './self' + v + '.php?last=' + last;
if(band)
	url = url + '&band=' + band;
if(maptype)
	url = url + '&maptype=' + maptype;
if(geo)
	url = url + '&geo=' + geo;
if(zoom)
	url = url + '&zoom=' + zoom;
if(center)
	url = url + '&center=' + center;
if(call)
	url = url + '&call=' + call;

window.location = url;
}

function boilerplate(type) {

document.write("<div style=\"text-align:left; padding-left:4px; padding-right:4px; padding-top:4px; padding-bottom:4px; ");
document.write("	border-style:solid; border-width:2px\">");


if(type=='F') {

document.write("<P><STRONG>What you see here </STRONG>is a list of the fragments, or partially received transmissions, ");
document.write("heard by the reporting stations. Fragments having a \"green\" score were reported as probable catches.<P> ");
document.write("<STRONG>Available options: </STRONG> band=  call=  and last=<br> ");
document.write("After band= you can specify one band code. You can use the 2-letter band codes (case doesn't matter),<br> ");
document.write("or numbers 600 160 80 60 40 30 20 17 15 12 10 6 2 and 222 432 902 and 1296  <br> ");
document.write("After call= you can specify one callsign; only fragments received by that station  will be shown.<br> ");
document.write("After last= you can specify an interval (doesn't have to be an integer, either) in hours<br><P> ");
document.write("<STRONG>Example: </STRONG>http://www.propnet.org/frag.php?last=2.5&band=10<P> ");

} else {

if(type=='C') {
document.write("<P><STRONG>What you see here </STRONG>is a display of the transmissions 'caught' via ");
document.write("PropNet over the requested time period. These are transmitted from one station via PSK31,");
document.write("received by another station, ");
document.write("reported to an Internet hub, stored in a database, and reported on these screens.  ");
document.write("The thickness of the lines corresponds to the rate at which the path was reported. There are four thicknesses, ");
document.write("representing 1-3, 4-6, 7-9, and 10+ average reports/hour of the interval you selected.<BR><BR>");
document.write("<STRONG>Path Score: </STRONG>This is the number of times the transmitting station was heard by the receiving station on this band over the preceding hour, ");
document.write("divided by the number of times the transmitting station says he is transmitting in his self-report. It can be very wrong, including >100%, because ");
document.write("the transmitting station might have just started transmitting, changed bands, or transmitted extra probes. ");
document.write("Also, a receiving station will sometimes capture a signal in two segment windows.<P>");
document.write("<STRONG>Freq &Delta;: </STRONG> The relative difference in frequency ");
document.write("between the received PSK31 stream frequency and the ");
document.write("receiving station's eventual transmit frequency. The ");
document.write("larger this number is, the further apart the two would ");
document.write("appear in the waterfall. For RX-only participants, the ");
document.write("TX frequency is assumed to be +1500 hz.<P>");
document.write("<STRONG>IMD: </STRONG> If the value in the IMD field is a percentage, the catch was not received perfectly, but was ");
document.write("identified from a partial reception supported by the list of stations known to be active, ");
document.write("and the number is the percentage of the identifying values received correctly. ");
document.write("If the field contains 'NPN', this is a not a catch of a PropNET participant, ");
document.write("but of another (NonPropNet) station transmitting near the PropNET anchor frequency. ");
document.write("Otherwise, the IMD field contains the IMD value reported by the receiving station, which is subject ");
document.write("to all the usual unreliability of such values, principally local noise.<P>");
}

if(type=='S') {
document.write("<P><STRONG>What you see here </STRONG>is a display of the stations connected ");
document.write("to the Internet who have reported their presence and operating");
document.write(" parameters within the requested time frame. Only the most recent ");
document.write(" report for each band is shown. <P> ");
}

document.write("<STRONG>URL Options: </STRONG>You can display two types of maps, Google (default) or Original. The following URL options ");
document.write("go after the URL in your address window. The first one is preceded by ? and the others start with & <P>");
document.write("<STRONG>Both maps: </STRONG>Available options include band=  call=  and last=<br>");
document.write("After band= you can specify one band code. You can use the 2-letter band codes (case doesn't matter),<br>");
document.write("or numbers 600 160 80 60 40 30 20 17 15 12 10 6 2 and 222 432 902 and 1296  <br>");
document.write("After call= you can specify one callsign; only paths to or from that callsign will be shown.<br>");
document.write("After last= you can specify an interval (doesn't have to be an integer, either) in hours<P>");
document.write("<STRONG>Google maps: </STRONG>Available options also include center=, which can be followed by a location code ");
document.write("<br>from this list: us na sa eu af as oc eh wh nh sh ww -- try 'em all! Or try center=<I>callsign</I><br>");
document.write("Mouse over a marker and then click on it.<br>");
document.write("Also, adding label=y will cause the callsign to be displayed next to the marker.<br>");
if (usingStarIcons) {
document.write("The icons topped by a yellow star represent stations that are Listening (or \"Lurking\") but not transmitting, ");
document.write("and the icons topped by a brown star represent Non-PropNet stations that were heard sending CQ.<br>");
} else {
document.write("The yellow L markers indicate stations that are Listening (or \"Lurking\") but not transmitting.<br>");
}
if(type=='S') {
  document.write("Also, the \"Call\" field of a Lurker has a yellow background.<br>");
}

document.write("<P><STRONG>Original maps: </STRONG> You must specify maptype=o, and you can also specify ");
document.write("a zoom level (zoom=1.5 or zoom=0.8, for example), or the URL of a .geo file after geo=<br><P>");
document.write("<STRONG>Example: </STRONG>http://www.propnet.org/catch.php?last=2.5&band=10&amp;center=na<P>");

document.write("<STRONG>Other Date Options: </STRONG>Instead of last=, you can specify date= (and optionally days=). This will ");
document.write("request the data from a particular date or range of dates. The value for date= should be in the format ");
document.write("yyyymmdd without any quotes, for example, &date=20080331. The value of days= defaults to &days=1. ");
document.write("Alternatively, you can request any start date/time with the format yyyy-mm-dd+hh:mi; for example, 2009-07-11+12:30. ");
document.write("And the days= value can be a real number; for example, use &days=0.04166 for one hour.<P>");

if(type=='C') {
document.write("<STRONG>Table Data Limit: </STRONG>Most of the website's bandwidth is comsumed downloading the event table. ");
document.write("As the usefulness of the data declines as more is displayed, the table is limited by default to 1000 rows. If you need ");
document.write("more, you can set the limit as high as 2500 with &limit=nnnn, but if you need to do that often, please ask the ");
document.write("webmaster for a better suggestion.<P>");
document.write("<STRONG>Download the table: </STRONG>You can save and later download the information in the table as a ");
document.write("CSV file that can be loaded into Excel.  You cause it to be created by declaring csv=filename, ");
document.write("and find the file later at www.propnet.org/csv/filename.csv<P>");
}

document.write("Want to know more? The PropNet story begins at our <A href=\"http://propnet.org\">Home Page</A>.<P>");
document.write("</div>");

}
}
