<!-- Browsercheck -->

IE = (document.all) ? 1 : 0; //Internet Explorer
N = (document.layers) ? 1 : 0; //Netscape 4
N6 = (document.getElementById && !document.all) ? 1 : 0; //Netscape 6

function Initialize_theWorld() {
	theWorldWidth = 650;
	theWorldHeight = 325;
	theWorldTop = 130;
	SatelliteWidth = 20;
	SatelliteHeight = 26;
	if (IE) {
		theWorldLeft = (document.body.clientWidth / 2) - (theWorldWidth / 2);
		document.all.theWorldBackground.style.left = theWorldLeft;
		document.all.theWorldBackground.style.top = theWorldTop;
		document.all.theWorld.style.left = theWorldLeft;
		document.all.theWorld.style.top = theWorldTop;
		document.all.theWorldBackground.style.visibility = "visible";
		document.all.theWorld.style.visibility = "visible";
		}
	else if (N||N6) {
		theWorldLeft = ((window.innerWidth - 14) / 2) - (theWorldWidth / 2);
		if (N) {
			if (navigator.userAgent.indexOf("Win") == -1) {theWorldTop = 100;} //MacNetscape needs correction
			document.layers.theWorldBackground.left = theWorldLeft;
			document.layers.theWorldBackground.top = theWorldTop;
			document.layers.theWorld.left = theWorldLeft;
			document.layers.theWorld.top = theWorldTop;
			document.layers.theWorldBackground.visibility = "show";
			document.layers.theWorld.visibility = "show";
			}
		else if (N6) {
			document.getElementById("theWorldBackground").style.left = theWorldLeft;
			document.getElementById("theWorldBackground").style.top = theWorldTop;
			document.getElementById("theWorld").style.left = theWorldLeft;
			document.getElementById("theWorld").style.top = theWorldTop;
			document.getElementById("theWorldBackground").style.visibility = "visible";
			document.getElementById("theWorld").style.visibility = "visible";
			}
		}
	if (document.IGP.Satellite.value != "" && document.IGP.Satellite.value != "PEPC") {Show_Satellite("Initialize", document.IGP.Satellite.value, document.IGP.PD_Satellite_name.value);}
	}

function Begin_follow_mouse(e) {
	AccuracyNr = 1;
	if (document.IGP.Accuracy[1].checked) {AccuracyNr = 2;}
	if (document.IGP.Accuracy[2].checked) {AccuracyNr = 5;}
	Adjust_position = (Math.round((650 / 360) * AccuracyNr) - 1);
	if (IE) {
		document.all.Horizontal.style.posLeft = theWorldLeft;
		document.all.Vertical.style.posTop = theWorldTop;
		document.all.Horizontal.style.visibility = "visible";
		document.all.Vertical.style.visibility = "visible";
		document.all("Accuracy" + AccuracyNr).style.visibility = "visible";
		}
	else if (N||N6) {
		if (N) {
			document.captureEvents(Event.MOUSEMOVE);
			document.layers.Horizontal.left = theWorldLeft;
			document.layers.Vertical.top = theWorldTop;
			document.layers.Horizontal.visibility = "show";
			document.layers.Vertical.visibility = "show";
			document.layers["Accuracy" + AccuracyNr].visibility = "show";
			}
		else if (N6) {
			document.getElementById("Horizontal").style.left = theWorldLeft;
			document.getElementById("Vertical").style.top = theWorldTop;
			document.getElementById("Horizontal").style.visibility = "visible";
			document.getElementById("Vertical").style.visibility = "visible";
			document.getElementById("Accuracy" + AccuracyNr).style.visibility = "visible";
			}
		}
	document.onmousemove = Set_lat_lon;// Do not use onMouseMove, but onmousemove or it will not work in Netscape 6
	}

function End_follow_mouse(e) {
	document.IGP.Data.value = "";
	if (IE) {
		document.all.Horizontal.style.visibility = "hidden";
		document.all.Vertical.style.visibility = "hidden";
		document.all.Accuracy2.style.visibility = "hidden";
		document.all.Accuracy5.style.visibility = "hidden";
		}
	else if (N||N6) {
		if (N) {
			document.releaseEvents(Event.MOUSEMOVE);
			document.layers.Horizontal.visibility = "hidden";
			document.layers.Vertical.visibility = "hidden";
			document.layers.Accuracy2.visibility = "hidden";
			document.layers.Accuracy5.visibility = "hidden";	
			}
		else if (N6) {
			document.getElementById("Horizontal").style.visibility = "hidden";
			document.getElementById("Vertical").style.visibility = "hidden";
			document.getElementById("Accuracy2").style.visibility = "hidden";
			document.getElementById("Accuracy5").style.visibility = "hidden";
			}
		}
	document.onmousemove = null;
	}

function Set_lat_lon(e) {
	if (IE) {
		Pos_x = event.offsetX;
		Pos_y = event.offsetY;
		if (navigator.userAgent.indexOf("Win") == -1) { //MacIE needs scroll correction
			Pos_x += document.body.scrollLeft;
			Pos_y += document.body.scrollTop;
			}
		document.all.Vertical.style.left = Pos_x + theWorldLeft;
		document.all.Horizontal.style.top = Pos_y + theWorldTop;
		document.all("Accuracy" + AccuracyNr).style.left = Pos_x + theWorldLeft - Adjust_position;
		document.all("Accuracy" + AccuracyNr).style.top = Pos_y + theWorldTop - Adjust_position;
		}
	else if (N||N6) {
		if (N) {
			Pos_x = e.pageX - theWorldLeft;
			Pos_y = e.pageY - theWorldTop;
			document.layers.Vertical.left = Pos_x + theWorldLeft;
			document.layers.Horizontal.top = Pos_y + theWorldTop;
			document.layers["Accuracy" + AccuracyNr].left = Pos_x + theWorldLeft - Adjust_position;
			document.layers["Accuracy" + AccuracyNr].top = Pos_y + theWorldTop - Adjust_position;
			}
		else if (N6) {
			Pos_x = e.pageX - theWorldLeft;
			Pos_y = e.pageY - theWorldTop;
			document.getElementById("Vertical").style.left = Pos_x + theWorldLeft;
			document.getElementById("Horizontal").style.top = Pos_y + theWorldTop;
			document.getElementById("Accuracy" + AccuracyNr).style.left = Pos_x + theWorldLeft - Adjust_position;
			document.getElementById("Accuracy" + AccuracyNr).style.top = Pos_y + theWorldTop - Adjust_position;
			}
		}
	Set_lon = Math.round((Pos_x - (theWorldWidth / 2)) * (360 / theWorldWidth));
	Set_lat = Math.round(((theWorldHeight / 2) - Pos_y) * (180 / theWorldHeight));
	Data_text = "Coordinates: "
	if (Set_lat < 0) {
		Data_text += -Set_lat + "\u00B0S ";
		}
	else {
		Data_text += Set_lat + "\u00B0N ";
		}
	if (Set_lon < 0) {
		Data_text += -Set_lon + "\u00B0W";
		}
	else {
		Data_text += Set_lon + "\u00B0E";
		}

	//Set satellite variables 
	Sat_lon = document.IGP.Satellite.value;
	if (Sat_lon == "PEPC") {
		if (Set_lat >= 13 && Set_lat <= 90 && Set_lon >= -180 && Set_lon <= -30) {
			Sat_lon = -97;
			Sat_name = "Telstar 5";
			}
		else {
			if (Set_lat >= -90 && Set_lat <= 13 && Set_lon >= -180 && Set_lon <= -30) {
				Sat_lon = -15;
				Sat_name = "Telstar 12";
				}
			else {
				if (Set_lat >= 36 && Set_lat <= 90 && Set_lon >= -30 && Set_lon <= 31) {
					Sat_lon = -12.3;
					Sat_name = "Atlantic Bird 1" ;
					}
				else {
					if (Set_lat >= -50 && Set_lat <= -9 && Set_lon >= 110 && Set_lon <= 180) {
						Sat_lon = 160;
						Sat_name = "Optus B1" ;
						}
					else {
						Sat_lon = 76.5;
						Sat_name = "Apstar 2R";
						}
					}
				}
			}
		Show_Satellite("MouseOver", Sat_lon, Sat_name);
		}
  
	E = 3959;
	Cc = 26200;
	Radians = 0.0174533;	//2Pi/360
	
	Aa = Set_lat * Radians;

	S = (Sat_lon - Set_lon) * Radians;
	
	a = Math.pow((Cc * Math.cos(S) - E * Math.cos(Aa)), 2);
	b = Math.pow((Cc * Math.sin(S)), 2);
	c = Math.pow((E * Math.sin(Aa)), 2);
	
	Dd = Math.sqrt(a + b + c);

	if (Aa == 0) {Aa = 0.0000000001;}
	AZ = (Math.atan(Math.tan(S) / Math.sin(Aa)));
	AZ = 180 - (AZ / Radians);
	if (Set_lat < 0) {AZ = AZ - 180;}
	if (AZ < 0) {AZ = AZ + 360;}
	
	a = Math.pow(Dd, 2);
	b = Math.pow(E, 2);
	c = Math.pow(Cc, 2);
	
	VL = ((a + b - c) / (2 * Dd * E));
	
	if (Math.sqrt(1 - Math.pow(VL, 2)) == 0) {VL = -0.99999999;}
	EL = ((1.5708 - Math.atan(VL / (Math.sqrt(1 - Math.pow(VL, 2))))));
	EL = (EL / Radians) - 90;
	
	Polarity = (Math.atan(Math.sin(S) / Math.tan(Aa)));
	Polarity = Polarity / Radians;

	Elevation = Math.round(EL, 0);
	Azimuth = Math.round(AZ, 0);
	Polarization = -Math.round(Polarity, 0);

	if (Elevation > 0) {
		if (IE || N6) {document.IGP.Data.style.color = "#0000FF";}
		Data_text += ". Alignment: azimuth = " + Azimuth + "\u00B0, elevation = " + Elevation + "\u00B0 and polarization = " + Polarization + "\u00B0.";
		}
	else {
		if (IE || N6) {document.IGP.Data.style.color = "#FF0000";}
		Data_text += ". Satellite out of reach!";
		}
	document.IGP.Data.value = Data_text;
	}

function Click_on_the_map() {
	document.IGP.Click_map.value = "Yes";
	document.IGP.Latitude.value = Set_lat;
	document.IGP.Longitude.value = Set_lon;
	}

function Show_Satellite(FromWhere, Sat_lon, Sat_name) {
	if (document.IGP.Satellite.value == "PEPC" && FromWhere != "MouseOver") {
		if (document.all) {
			document.all.SatelliteLocation.style.visibility = "hidden";
			}
		else if (document.layers||document.getElementById) {
			if (document.layers) {
				document.layers.SatelliteLocation.visibility = "hidden";
				}
			else if (document.getElementById) {
				document.getElementById("SatelliteLocation").style.visibility = "hidden";
				}
			}
		}
	else {
		if (Sat_name != "") {} else {Sat_name = document.IGP.PD_Satellite_name.value;}
		Sat_name_text = "<img name=\"Satellite\" alt=\"\" src=\"pics/Satellite.gif\" height=\"26\" width=\"20\">&nbsp;<a class=\"sat\">" + Sat_name + "</a>";
		Set_LeftPos = ((theWorldWidth / 2) - (SatelliteWidth / 2)) + (Sat_lon * theWorldWidth /360) + theWorldLeft;
		Set_TopPos = ((theWorldHeight / 2) - (SatelliteHeight / 2)) + theWorldTop;
		if (IE) {
			document.all.SatelliteLocation.style.left = Set_LeftPos;
			document.all.SatelliteLocation.style.top = Set_TopPos;
			document.all.SatelliteLocation.style.visibility = "visible";
			document.all.SatelliteLocation.innerHTML = Sat_name_text;
			}
		else if (N||N6) {
			if (N) {
				document.layers.SatelliteLocation.left = Set_LeftPos;
				document.layers.SatelliteLocation.top = Set_TopPos;
				document.layers.SatelliteLocation.visibility = "show";
				with(document.layers.SatelliteLocation.document){open(); write(Sat_name_text); close();}
				}
			else if (N6) {
				document.getElementById("SatelliteLocation").style.left = Set_LeftPos;
				document.getElementById("SatelliteLocation").style.top = Set_TopPos;
				document.getElementById("SatelliteLocation").style.visibility = "visible";
				document.getElementById("SatelliteLocation").innerHTML = Sat_name_text;
				}
			}
		}
	}

function Check_Go(form) {
	if (form.PD_Satellite.options[form.PD_Satellite.selectedIndex].text == "") {
		alert("You did not select a satellite. Please select one.");
		form.PD_Satellite.focus();
		return false;
		}

	if (form.PD_City.options[form.PD_City.selectedIndex].text == "" || form.PD_City.options[form.PD_City.selectedIndex].text == "<-- Select city -->") {
		if (form.PD_Region.options[form.PD_Region.selectedIndex].text == "" || form.PD_Region.options[form.PD_Region.selectedIndex].text == "<-- Select region -->") {
			alert("You did not select a region. Please select one.");
			form.PD_Region.focus();
			return false;
			}
	
		if (form.PD_Country.options[form.PD_Country.selectedIndex].text == "" || form.PD_Country.options[form.PD_Country.selectedIndex].text == "<-- Select country -->") {
			alert("You did not select a country. Please select one.");
			form.PD_Country.focus();
			return false;
			}
		alert("You did not select a city. Please select one.");
		form.PD_City.focus();
		return false;
		}	
	else {
		form.action = 'Set_Dish.php';
		return true;
		}
	}

function Check_Form(form) {
	//Remove leading spaces
	for (var i=0; form.Latitude.value.charAt(i)==" "; i++);
	form.Latitude.value = form.Latitude.value.substring(i,form.Latitude.value.length);
	for (var i=0; form.Longitude.value.charAt(i)==" "; i++);
	form.Longitude.value = form.Longitude.value.substring(i,form.Longitude.value.length);
	for (var i=0; form.Satellite.value.charAt(i)==" "; i++);
	form.Satellite.value = form.Satellite.value.substring(i,form.Satellite.value.length);
	
	if (form.Latitude.value == "" || form.Latitude.value == null) {form.Latitude.value = 0}
	if (form.Longitude.value == "" || form.Longitude.value == null) {form.Longitude.value = 0}
	if ((form.Satellite.value >= -180 && form.Satellite.value <= 180 && form.Satellite.value != null && form.Satellite.value != "") || (form.Satellite.value == "PEPC")) {
		if ((Math.abs(form.Satellite.value) - Math.floor(Math.abs(form.Satellite.value))) >= 0.5999999999) {
			alert("Satellite longitude is not in degrees (that means between " + parseInt(form.Satellite.value) + ".00 and " + parseInt(form.Satellite.value) + ".59).");
			form.Satellite.focus();
			return false;
			}
		else {
			if (form.Latitude.value >= -90 && form.Latitude.value <= 90) {
				if ((Math.abs(form.Latitude.value) - Math.floor(Math.abs(form.Latitude.value))) >= 0.5999999999) {
					alert("Latitude is not in degrees (that means between " + parseInt(form.Latitude.value) + ".00 and " + parseInt(form.Latitude.value) + ".59).");
					form.Latitude.focus();
					return false;
					}
				else {
					if (form.Longitude.value >= -180 && form.Longitude.value <= 180) {
						if ((Math.abs(form.Longitude.value) - Math.floor(Math.abs(form.Longitude.value))) >= 0.5999999999) {
							alert("Longitude is not in degrees (that means between " + parseInt(form.Longitude.value) + ".00 and " + parseInt(form.Longitude.value) + ".59).");
							form.Longitude.focus();
							return false;
							}
						else {
							return true;
							}
						}
					else {
						alert("Longitude must be between -180\u00B0 and 180\u00B0. Please enter new longitude.");
						form.Longitude.focus();
						return false;
						}
					}
				}
			else {
				alert("Latitude must be between -90\u00B0 and 90\u00B0. Please enter new latitude.");
				form.Latitude.focus();
				return false;
				}
			}
		}
	else {
		Alert_Text = "Satellite longitude must be between -180\u00B0 and 180\u00B0. Please enter new longitude.";
		alert(Alert_Text);
		form.Satellite.focus();
		return false;
		}
	}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

if (document.all||document.layers||document.getElementById){
	MM_preloadImages('pics/theWorld_2.gif', 'pics/Empty.gif', 'pics/Blue_dot.gif', 'pics/Satellite.gif', 'pics/Blue_17x17.gif', 'pics/Blue_7x7.gif');
	window.onload = Initialize_theWorld;
   if (document.all||document.getElementById) {window.onresize = new Function("window.location.reload()");}
	}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
MM_reloadPage(true);
