//function blockError(){return true;}
//window.onerror = blockError;

var sendping=1;
var tuneflag=1;
var timerIDband;
var callsign = "";
var password="";
var band=5;
var cwdata="";  var pskdata="";
var oktocommand=false;
var linkconnected=false;var logon=false; var logoff=false;
var cmddelay=500;  // loop time until next try to set command
var wpm = 20;
var cwfactor=400;
var timerset = 0; var timersetDelay = 0;
var stimer = 10000;
var timeset1; var timeset2; var timeset3; var timesetcheck; var timerlogoff=0;
var timerDelay;
var timerCR;
var cwwin; var pskwin;
var cwwinflag=0;
var genwin; var genwinflag=0;
var pskwinflag=0;
var temp;
var timeset;
var telemval="";
var allowupdate=true;
var pingurl;
var allowtx;
var usejavatelem=0;
var usejavacmd=0;
var updatecoune=0;
var pingready=1;
var pingwait=0;
var javarxenabled=0;
var javatxenabled=0;
var ULFreq=145920000;
var DLFreq=435300000;
var satcmd=""
var sattrack="http://www.amsat.org/amsat-new/tools/predict/index.php/?ele=0&doPredict=Predict&count=15";
var satname="&satellite=ISS";
var saturl="";
var infomessage=false;
var XMLok = true;
var soundtype=1;
var telemtype=2; var telemtext=["","FALLBACK","DEFAULT","BETTER","BEST"]; 
var firstpass=true;
var urlfwd="";
var lastchat="";
 
if (navigator.javaEnabled()) {javatxenabled=1};

var isUDP = false;

//*************************************************************************************************************
//  INITIALIZATION
//*************************************************************************************************************

var usejavacmd=0;
var usejavaping=0;
var update=3000;
var cktelem=0;

function initwebxcvr(){
	pingurl=window.location.toString();	
	pingurl=pingurl.replace("radio","ping");
	pingurl=pingurl.replace("8080","47880");
	pingurl=pingurl.replace("com/","com:47880/");
	temp=pingurl.substr(7)
	nn=temp.indexOf(":")
	if (nn<0) nn=temp.indexOf("/");
	myurl=temp.substr(0,nn);
	window.document.radio.SetVariable("irburl", myurl);
	updateallowed=true;
	updatestatus();	
	if(firstpass) readcookie();	firstpass=false;
	usejavacmd=0;
	usejavaping=0;
	if(javatxenabled==1) {if(udptx) {if(udptx.running==1 )usejavacmd=1;}}
	if(telemtype==1 || telemtype==3) usejavacmd=0;

	if (timesetKA==1)clearTimeout(timerKA);
	timersetKA=1;	
	timerKA = setTimeout("reloadping()",update);
	//resize();
	//var strNav=navigator.userAgent;
	//var isPPC=strNav.indexOf("240x320");
	//if (isPPC>-1){radio.width=250; radio.height=150; logon.width=250; logon.height=20;};
	
	parent.window.status= (statusdata2.message=="") ? "Internet Remote Base": statusdata2.message;

	//checkID=setTimeout("sendchecktohost()",5000);

	timersetRL=1; 	timerRL=setTimeout("reloadpage()",20000);	

	pingradio();

	if(telemtype>2) {loadXMLDoc(XMLurl);}


	//window.document.radio.SetVariable("lblcmd", "NORMAL");
	if(infomessage==false) infomsg(); 

}

var tenmin=10*60*1000;
var tmrreload=setTimeout("parent.location.reload()", tenmin);
var tmrfault=setTimeout("setfault()",5000);
var faulttmr=1;

function setfault(){
	tmrfault=setTimeout("setfault()",5000);
	window.document.radio.SetVariable("_faultflag", 0);
}
function savetelem(x) {}

function readtelem() {}


function updatestatus2(){}

function updateshort(){}

function infomsg(){
	infomessage=true;
	//alert('IMPORTANT INFO MESSAGE RE: WEBRADIO:  The browser WebRadio polls the host to obtain the remote status. An advanced "hidden" poll can be started by clicking on the Menu button and then clicking the "BEST" interface button. Note this may not be supported on all browsers. YOU CAN DISREGARD THIS MESSAGE IF YOU WANT, BUT USING THE "HIDDEN POLLING" IS MORE EFFICIENT. ');
}


function setTelemtype(x){
	if(x==1) {try{telemtype=1; XMLActive=false; XMLok=false; initwebxcvr();  usejavacmd=0;} catch(e) {alert("ERROR 5")} }
	else if(x==2){try{telemtype=2; XMLActive=false; XMLok=false;  initwebxcvr(); usejavacmd=1;} catch(e) {alert("ERROR 6")} }
	else if(x==3){try{telemtype=3; XMLActive=true; XMLok=true;  initwebxcvr(); usejavacmd=0;}catch(e) {alert("ERROR 7")} }
	else if(x==4) {try{telemtype=4; XMLActive=true; XMLok=true;  initwebxcvr(); usejavacmd=1;}catch(e) {alert("ERROR 8")} }
}

function resettelemtype(){ 
	if(cktelem>0 && cktelem<5) setTelemtype(cktelem);
}


//*************************************************************************************************************
//  COOKIE PROCESSING
//*************************************************************************************************************

var info=new String ("");

function setcookie(){
	theDate=new Date(2007,1,1,0,0,0,0);
	temp=password;
	temp1=callsign;
	temp2=telemtype.toString();
	temp1=temp1.toUpperCase();
	info=temp1 + ':' + temp+":"+ temp2;  //alert(info)
	document.cookie="info=" + info + ";expires="+theDate;
} 

function readcookie(){
	if(document.cookie != "") { 
		info=document.cookie.split("=")[1];
		array=info.split(":");
		if (array==null){}else{
			callsign=array[0].toString();
			callsign=callsign.toUpperCase();
			password=array[1].toString();
			try{
				if(array[2]) { 
					cktelem=parseInt(array[2]); //alert( info,cktelem)
					tmrtt=setTimeout("resettelemtype()",5000); 
				}
			}catch(e) { alert("Error 9") }
			window.document.logon.SetVariable("_callsign", callsign);
			window.document.logon.SetVariable("_password", password);
		}  

	}
} 


//*************************************************************************************************************
//  LOGON, LOGOFF, ETC
//*************************************************************************************************************

function sendlogon(){
	var temp="status=check1 CS=" + callsign + "/PW=" + password + "/RS=OLG/VV=10.100/XS=0/"
	sendcommand(temp);
	setcookie();
}

function sendlogoff(){
	var temp="status=check1 CS=" + callsign + "/PW=" + password + "/RS=OXG/VV=10.100/XS=0/"
	if(linkconnected) sendcommand(temp);
}

function sendcheck() {
	//var temp="status=check1 CS=" + callsign + "/PW=" + password + "/RS=ONG/VV=10.100/XS=0/"
	//return temp
}

function sendconnected() {
	//var temp="status=check1 CS=" + callsign + "/PW=" + password + "/RS=OYG/VV=10.100/XS=0/"
	//return temp
}

function sendchecktohost(){
	//checkID=setTimeout("sendchecktohost()",5000);
	//var temp=sendcheck();
	//if (linkconnected) temp=sendconnected();
	//sendcommand(temp);
	//if (linkconnected) {var temp=sendconnected();sendcommand(temp)};
}


//*************************************************************************************************************
//  COMMANDING
//*************************************************************************************************************

var timersetJS=0;
var timerJS;

var timersetCMD=0;
var timerCMD;
var commandtoremote=new String();

function sendcommand(x){
	if(x!='') commandtoremote=commandtoremote+x.toString()+";" 
	if(oktocommand){
		if (parent.command) {		
			statusdata.tuneflag= 0;
			if (usejavacmd==0) { 
				//if(XMLActive==true){
				//	temp=XMLCmdurl+"?cmdsent="+commandtoremote;
				//	loadXMLDoc(temp);
				//}else{
					parent.command.location= "?cmdsent="+commandtoremote;  
				//}
				resetupdate();
				temp=commandtoremote.substr(0,2);
				temp=(temp=="IV" || temp=="EQ"  || temp=="SP" || temp=="SM" || temp=="RX" || temp=="TX" );
				if (temp==false) setupdatetimer();			
				resettmrTuneflag();
				commandtoremote="";
			} 
			else if(usejavacmd==1){
				if (commandtoremote.indexOf('=check1')>-1 ) {
					udptx.send(commandtoremote);}
				else {
					temp1=commandtoremote.indexOf('P1');
					temp2=commandtoremote.indexOf('P2');
			 		if(temp1==0 || temp2==0) {temp=commandtoremote} else {temp="CMD"+commandtoremote};
					udptx.send(temp); 
					setTuneflag(); statusdata.tuneflag=1;
					resetupdate();
					temp=commandtoremote.substr(0,2);
					temp=(temp=="IV" || temp=="EQ"  || temp=="SP" || temp=="SM" || temp=="RX" || temp=="TX" || temp=="MD" );
					if(temp==false) setupdatetimer(); 
					if(temp==true) updatecount=0;
 				}
				commandtoremote="";
			}	
			
		} else {
			timerCMD=setTimeout("sendcommand('')",100); timersetCMD=1;
		}
 	} 
}

function processcmd(command,args) {
	if (command=="PSK") {
		//pskwindow();
	} else if (command=="CW") {
		cwwindow();
	} else if (command=="STOP") {
		sendping=0;
	} else if (command=="GO") {
		sendping=1;
	} else if (command=="SKYPE")  {
			sendcommand ('NM8');
	} else if (command=="IRBSOUND")  {
			sendcommand ('NM5');
			openwindow("http://www.w4mq.com/irbsound");
	} else if (command=="FWDWEB")  {
				sendcommand ('NM10');
				urlfwd="http://fwd.pulver.com/callme.php?userid=" + statusdata2.pulver;
				openwindow(urlfwd);
	} else if (command=="FWDCON")  {
			sendcommand ('NM11');
	} else if (command=="send_var") {
  		sendcommand (args);
	} else if (command=="XF1") { try{setTelemtype(1); setcookie();} catch(e) {alert("Error 1")}
	} else if (command=="XF2") { try{setTelemtype(2); setcookie();} catch(e) {alert("Error 2")}
	} else if (command=="XF3") { try{setTelemtype(3); setcookie();} catch(e) {alert("Error 3")}
	} else if (command=="XF4") { try{setTelemtype(4); setcookie();} catch(e) {alert("Error 4")}
	} else if (command=="SPECIAL") {
		sendcommand (args);
		if (pingready==1)pingwait=1;
	} else if (command=="RESET") {
		telemtype=2; setcookie();
		parent.location.reload();
	} else if (command=="AO51") {
		satname="&satellite=AO-51";
		satcmd="FA145920000;MD4;FG20$0;TN1;SP;FA435300000;"
		ULFreq=145920000; DLFreq=435300000;
		saturl="http://www.amsat.org/amsat-new/tools/predict"
		if( callsign=="W4MQ" && pingurl.indexOf("192.168")>-1) saturl="http://192.168.0.2:47880/remote/AO-51.html";
		trackwindow();	
	} else if (command=="ISSR") {
		satname="&satellite=ISS";
		satcmd="FA437800000;MD4;FG20$0;TN1;SP;FA145800000;"
		ULFreq=437800000; DLFreq=145800000;
		saturl="http://www.amsat.org/amsat-new/tools/predict"
		if( callsign=="W4MQ" && pingurl.indexOf("192.168")>-1) saturl="http://192.168.0.2:47880/remote/ISS.html";
		trackwindow();
	} else if (command=="ISS") {
		satname="&satellite=ISS";
		satcmd="FA144490000;MD4;FG20$0;TN1;SP;FA145800000;"
		ULFreq=144490000; DLFreq=145800000;
		saturl="http://www.amsat.org/amsat-new/tools/predict"
		if( callsign=="W4MQ" && pingurl.indexOf("192.168")>-1) saturl="http://192.168.0.2:47880/remote/ISS.html";
		trackwindow();
	} else if (command=="TRACK") {
		//trackwindow();
	} else if (command=="SETUP") {
		//sendcommand(satcmd);
		//setupradioforsat();
	}
}

function processlogon(command,args) {
	temp=args
		temp=temp.substr(2);
		if (temp.indexOf("LOGOFF")>-1) {
			sendlogoff()
			logoffID0=setTimeout("sendlogoff()",1000);
			logoffID=setTimeout("sendlogoff()",3000);
			logoffID1=setTimeout("sendlogoff()",6000);
			logoffID1=setTimeout("sendlogoff()",1000);
		} else if (temp.indexOf("LOGON")>-1) {
			temp=temp.substr(5);
			xx=temp.indexOf(",");
			call=temp.substr(0,xx); pw=temp.substr(xx+1);

			callsign=call.toString();
			callsign=callsign.toUpperCase(); 
			password=pw.toString();	
			sendlogon();
			logoffID0=setTimeout("sendlogon()",1000);
			logoffID=setTimeout("sendlogon()",2000);
		} else if (temp.indexOf("AUDIO")>-1)  {
			window.document.radio.SetVariable("audiomenu", 1);
		}	
}

function setupradioforsat(){sendcommand(satcmd)}

//*************************************************************************************************************
//  TELEMTRY PROCESSING
//*************************************************************************************************************


// Update for getting telemetry from the host

function pingradio() { 	
	pingready=0; pingwait=0;
	if (timesetKA==1)clearTimeout(timerKA);
	timesetKA=1; 
	timerKA = setTimeout("reloadping()",update);	 
	if(!XMLActive)if(parent.ping)parent.ping.location=pingurl;
	if(XMLActive)loadXMLDoc(XMLurl);		
}

var startup=0; 

//list of items from status ping window

var checkID;  

var statusdata ={tuneflag:1, rxfreq:7203, txfreq:"7203.000", AGC:"MedLo", NR:"NR1", notch:"Auto", 
	rit:"Off", rfgain:"100",afgain:"0", monitor:"Off", rxeq:"H-Boost", 
	txeq:"H-Boost", cwspeed:"20", micgain:"50", atten:"On", preamp:"On",  
	squelch:"Off", split:"Off",  amplifier:"N/A", band:"40m",
	mode:"LSB", filter:"2.4kHz", filterlo:"0.1kHz", power:"100W",
	antenna:"DIPOLE", azimuth:"180", rotator:"0", allowtransmit:"true", txflag:"false",
	mtr1:"1", mtr1name:"Signal", mtr2name:"SWR", mtr1val:"S-9", mtr2:"15", mtr2val:"1.35", time:"000", clock:" ",
	station:"IRB", control:"", PTT:"false",
	offset:"SIMPLEX", tone:"Off",ant1:"Dipole", ant2:"Beam", ant3:"", ant4:"", ant5:""};
 
var statusdata2 ={skype:"",message:"", pskdata:"", psklevel:"50", pskqual:"50", pskinfo:"", pskimd:"-10", 
			pskfreq:"14071.500", pskwf:"", lat:"", long:"", allowvox:"0", telnet:"dxc.w4mq.net", pulver:"", 
			version:"5", cwtone:"600", chat:""};


function updatestatus(){
  if (radio) {
	window.document.radio.SetVariable("_faultflag", 1);
	resetreloadtimer();	
	resettimer();
	pingready=1;
	temp1=statusdata2.skype; temp1=temp1.replace(" ","_"); temp1=temp1.replace(" ","_");
	statusdata2.skype=temp1;
	temp1=statusdata2.message; statusdata2.message=(temp1.length>=4) ? temp1 : "";
	tuneflag=statusdata.tuneflag;
	var rotOK =false;

	window.document.radio.SetVariable("_tuneflag", 1);
	window.document.radio.SetVariable("_skypename", statusdata2.skype);
	window.document.radio.SetVariable("_fwdnumber", statusdata2.pulver);
	window.document.radio.SetVariable("_version", statusdata2.version);
	window.document.radio.SetVariable("javatx", usejavacmd);
	window.document.radio.SetVariable("_mtr1name", statusdata.mtr1name);
	window.document.radio.SetVariable("_mtr1value", statusdata.mtr1val);
	window.document.radio.SetVariable("_mtr1", statusdata.mtr1);
	window.document.radio.SetVariable("_mtr2name", statusdata.mtr2name);
	window.document.radio.SetVariable("_mtr2value", statusdata.mtr2val);
	window.document.radio.SetVariable("_mtr2", statusdata.mtr2);
	window.document.radio.SetVariable("ant1", statusdata.ant1.toUpperCase());
	window.document.radio.SetVariable("ant2", statusdata.ant2.toUpperCase());
	window.document.radio.SetVariable("ant3", statusdata.ant3.toUpperCase());
	window.document.radio.SetVariable("ant4", statusdata.ant4.toUpperCase());
	window.document.radio.SetVariable("ant5", statusdata.ant5.toUpperCase());
	window.document.radio.SetVariable("lblantenna", statusdata.antenna.toUpperCase());

	linkconnected=( callsign.length > 0 && statusdata.control.toUpperCase()==callsign.toUpperCase()) ? true : false;
	allowtx=linkconnected && (statusdata.allowtransmit=="true");
	oktocommand=(linkconnected || (statusdata.control==""));
	temp=statusdata.txfreq;
	window.document.radio.SetVariable("lblTxFreq", temp.toString());

	if (linkconnected) { update=3000} else {update=3000};
	if (statusdata.mode=="CW") update=3000;

	temp=(allowtx==true) ? 1 : 0;
	window.document.radio.SetVariable("_allowtx", temp);
	temp=(statusdata2.allowvox==1) ? 1 : 0;
	window.document.radio.SetVariable("_allowvox", temp); 
	temp=(linkconnected==true) ? 1 : 0; 
	window.document.radio.SetVariable("_linkconnected", temp);
	window.document.logon.SetVariable("_linkconnected", temp);
	temp=(oktocommand==true) ? 1 : 0;
	window.document.radio.SetVariable("_oktocommand", temp);
	var statusline=statusdata.station+"--";
	if (statusdata.control=="" || statusdata.time==0){statusline=statusline+"AVAILABLE"} 
		 else {statusline=statusline+"Control OP: "+statusdata.control}
	window.document.radio.SetVariable("status", statusline);
	temp=statusdata.station+"_remotebase"; if(statusdata2.skype!="") temp=statusdata2.skype;
	window.document.radio.SetVariable("skypename",temp);
	temp=(statusdata.split=="On") ? 1 : 0;
	window.document.radio.SetVariable("_split", temp);
	temp=(temp==1) ? "SPLIT" :"";
	window.document.radio.SetVariable("lblsplit", temp);
	window.document.radio.SetVariable("lblUTC", statusdata.clock);
	wpm=statusdata.cwspeed;	

	parent.window.status= (statusdata2.message=="") ? statusdata.station+" Internet Remote Base": statusdata2.message;

	if (statusdata2.chat!="" && statusdata2.chat!=lastchat){
		lastchat=statusdata.chat;
		statusdata2.chat="";
		//alert(lastchat.replace("%%",": ");
		}
} // if radio

if (startup==1)	window.document.logon.SetVariable("lbltime", statusdata.time);

startup=1;



if (allowupdate==true) {

  if (radio) {
	window.document.radio.SetVariable("_rotator", statusdata.rotator);
	if (statusdata.rotator==1){temp=statusdata.azimuth}else{temp=""};
	window.document.radio.SetVariable("_azimuth", temp);	
	temp=statusdata.AGC;
	temp=(temp.indexOf("Fast")>-1) ? "FAST" :((temp.indexOf("Med")>-1) ? "MED" :((temp.indexOf("Slow")>-1) ? "SLOW" : "")) ;	
	window.document.radio.SetVariable("lblAGC", temp);
	window.document.radio.SetVariable("lbl2mode", statusdata.mode);
	window.document.radio.SetVariable("lbl2band", statusdata.band);
	temp=parseFloat(statusdata.filter); 
	temp=(temp < 10) ? temp*1000 : temp; 
	temp=(statusdata.mode=="CW") ? temp=temp/100 : temp=(temp-1000)/200;
	temp=parseInt(temp.toString());
	window.document.radio.SetVariable("_filterHI", temp);
	temp=parseFloat(statusdata.filterlo); 
	temp=(temp < 10) ? temp*1000 : temp; 
	temp=temp/100;
	window.document.radio.SetVariable("_filterLO", temp);  
	temp= (statusdata.NR=="NR1") ? "NR-SSB" : ((statusdata.NR=="NR2") ? "NR-CW" :"");
	window.document.radio.SetVariable("lblNR", temp);
	temp=statusdata.notch;
	temp=(temp.indexOf("Off")>-1) ? "" : "NOTCH" 
	window.document.radio.SetVariable("lblNotch", temp);
	temp=statusdata.atten; temp=(temp.indexOf("Off")>-1) ? "" : "ATTEN"
	window.document.radio.SetVariable("lblAtten", temp);
	temp=statusdata.preamp; temp=(temp.indexOf("Off")>-1) ? "" : "PREAMP"
	window.document.radio.SetVariable("lblPreamp", temp);
	temp=(statusdata.rxeq=="H-Boost") ? "RX-EQ" : "";
	window.document.radio.SetVariable("lblRxEq",temp );
	temp=(statusdata.txeq=="H-Boost") ? "TX-EQ" : "";
	window.document.radio.SetVariable("lblTxEq",temp );
	temp=statusdata.rxfreq; temp=parseFloat(temp.toString())*1000;
	window.document.radio.SetVariable("rxfreq", temp);
	tempa=statusdata.antenna.toUpperCase();
	//window.document.radio.SetVariable("Ant", tempa);

	window.document.radio.SetVariable("_PTT", statusdata.PTT);
	window.document.radio.SetVariable("lblPower", statusdata.power);
	temp=parseInt(statusdata.power);
	window.document.radio.SetVariable("_power", temp);
	window.document.radio.SetVariable("_rfgain", statusdata.rfgain);
	window.document.radio.SetVariable("_afgain", statusdata.afgain);
	window.document.radio.SetVariable("_squelch", statusdata.squelch);
	temp="";
	if (statusdata.mode=="FM") temp=statusdata.offset;
	window.document.radio.SetVariable("lblrptr", temp);
	window.document.radio.SetVariable("_tone", statusdata.tone);
	window.document.radio.SetVariable("_micgain", statusdata.micgain);
	temp=(statusdata.txflag=="true") ? 1 : 0;
	window.document.radio.SetVariable("_txflag", temp);
	//window.document.radio.SetVariable("_telnet", statusdata2.telnet);

	window.document.radio.SetVariable("_newdata", 1);

	if(linkconnected) pingtimer();

  } // if radio
} // if allowupdate
}


//*************************************************************************************************************
//  TIMERS
//*************************************************************************************************************

function pingtimer(){timerpoll = setTimeout("pingradio()",250);}
function resettimer(){
	if(timesetKA==1) {clearTimeout(timerKA);}
	timesetKA=1; timerKA = setTimeout("reloadping()",update);
}

//Update for setting the tuneflag following a command sent by the GUI
var tmrTuneflag; var tmrTuneflagSet=0;

function setTuneflag() {
	window.document.radio.SetVariable("_tuneflag", 1);
}

function resettmrTuneflag(){
	if(tmrTuneflagSet==1) clearTimeout(tmrTuneflag); 
	tmrTuneflagSet=1; tmrTuneflag = setTimeout("setTuneflag()",150);
}

var update=3000;
var timerKA; var timesetKA=0;

function reloadping(){
	timesetKA=0;
	pingradio();
}
var timerpoll=0;
var javaupdate=3000;

var timersetUD=0;
var timerUD;
function setupdatetimer(){ 
//***************
	if (radio)	window.document.radio.SetVariable("_newdata", 0);
//*******************
	if (timersetUD==1)clearTimeout(timerUD);
	timersetUD=1; 
	allowupdate=false; 
	timerUD=setTimeout("resetupdate()",2000)
}

function resetupdate(){
	if (timersetUD==1)clearTimeout(timerUD);
	timersetUD=0; 
	allowupdate=true;
}

var timersetRL=0;
var timerRL;

function resetreloadtimer(){ 
	if (timersetRL==1)clearTimeout(timerRL);
	timersetRL=1; timerRL=setTimeout("reloadpage()",10000);
}

function reloadpage(){
	if (timersetRL==1)clearTimeout(timerRL); 
	//document.location.reload();
}


//*************************************************************************************************************
//  WINDOWS
//*************************************************************************************************************


function cwwindow(){
var mybars="directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no";
var myoptions ="scrollbars=no,width=300, height=170,resizable=yes";
var myfeatures = mybars + "," + myoptions;
var myurl = "cw.html";
cwwin = open(myurl,"CW",myfeatures);
cwwin.focus();
cwwinflag=1;
}

function openwindow(x){
var mybars="directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no";
var myoptions ="scrollbars=no,width=500, height=400,resizable=yes";
var myfeatures = mybars + "," + myoptions;
var myurl = x.toString();
genwin = open(myurl,"",myfeatures);
genwin.focus();
genwinflag=1;
}

function trackwindow(){
var mybars="directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no";
var myoptions ="scrollbars=no,width=500, height=450,resizable=yes";
var myfeatures = mybars + "," + myoptions;
var myurl = "satellite.html";
tkwin = open(myurl,"Track",myfeatures);
tkwin.focus();
}

function satwindow(){
var mybars="directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no";
var myoptions ="scrollbars=yes,width=650, height=600,resizable=yes";
var myfeatures = mybars + "," + myoptions;
var myurl = saturl;
//var grid="";
//if (statusdata.station=="W4MQ") grid="FM18hw";
//if (statusdata.station=="VK3UR") grid="QF12vk";
//if (statusdata.station=="W6WTG") grid="DM05mj";
//mytitle="Enter Satellite and Grid: "+grid;
satwin = open(myurl,"Satellite", myfeatures);
satwin.focus();
} 

function closecwwin(){ if(window.cwwin) window.cwwin.close();
				 cwwinflag=0; cwdata=""}

function pskwindow(){
var mybars="directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no";
var myoptions ="scrollbars=no,width=460, height=420,resizable=no";
var myfeatures = mybars + "," + myoptions;
var myurl = "psk.html";

pskwin = open(myurl,'PSK31',myfeatures);
pskwin.focus();
pskwinflag=1;
}

var intialresize=0;
function resize() {
 	var myWidth = 0; 
	var myHeight = 0; 

if( typeof( window.innerWidth ) == 'number' ) {
 //Non-IE
 	myWidth = window.innerWidth; 
	myHeight = window.innerHeight; 
} else if( 
	document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
//IE 6+ in 'standards compliant mode' 
	myWidth = document.documentElement.clientWidth; 
	myHeight = document.documentElement.clientHeight; 
} else if(
	document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
 //IE 4 compatible 
	myWidth = document.body.clientWidth; 
	myHeight = document.body.clientHeight;
 } 
//window.alert( 'Width = ' + myWidth ); 
//window.alert( 'Height = ' + myHeight );
if (myWidth!=500) {
		if (initialresize==0)window.resizeTo(540,480);
		initialresize=1;
		temph=myWidth*0.6; temph=parseInt(temph.toString());
		window.resizeBy(0,50+temph-myHeight);
		if (radio) radio.width=myWidth;
		if (radio) radio.height=temph; 
		if (logon) logon.width=myWidth;
		if (logon) logon.height=temph;
	}
}

//*************************************************************************************************************
//  XML HTTP REQUEST PROCESSING
//*************************************************************************************************************
var req;
var XMLActive=false;
var xmltimer=1;
var xmltmr=setTimeout("XMLActive=false", 3000);
var XMLurl="XMLRequest";  //myurl+":47880/XMLRequest";
var XMLCmdurl="XMLCmd";    //myurl+"/XMLCmd";
 
function processReqChange() 
{ 
//alert (reg.readyState); 
// only if req shows "complete" 
if (req.readyState == 4 && req.responseText.indexOf("parent")<0) { 
// only if "OK" 
	if(!XMLok) return;
	if (req.status==200 && req.responseText.length>400) { 
		var d=statusdata;   var g=statusdata2;
		temp=req.responseText; temp=temp.toString();
		if(password=="STAN")alert(temp);
		array=temp.split(";");
		temp="";
		if (array==null){}else{
			if(array.length>20) {
				XMLActive=true;
				if(xmltimer==1){xmltimer=0; clearTimeout(xmltmr)};
				for(j=0;j<array.length;j=j+1){eval(array[j])}
			}
		 }
		updatestatus();

	} else { 
		//if(password=="STAN")//("There was a problem retrieving the XML data:\n" + req.statusText); 
	} 
   } 
} 

// code from Google...
function getXmlObj(){
	var C=null;
	try{
		C=new ActiveXObject("Msxml2.XMLHTTP")
	}catch(e){
		try{
			C=new ActiveXObject("Microsoft.XMLHTTP")
		}catch(sc){
			C=null
		}
	}
	if(!C && window.XMLHttpRequest){C=new XMLHttpRequest()}
	if(!C) c;
	return C
}

function loadXMLDoc(url){

if(req&&req.readyState!=0){req.abort();}else{	
req=false;	
try {
		req=new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
		 	req=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {}
	}
if(!req && window.XMLHttpRequest){
	try{
		req=new XMLHttpRequest();XMLActive=true; 
	} catch(e){
		XMLActive=false; 
	}
}

//alert(req.readystate);
	//if(req&&req.readyState!=0){req.abort()}else{req=getXmlObj()};
	if(req){
		XMLActive=true; 
		url="XMLRequest";  //XMLurl;
		//if(password=="STAN")alert(url);
		//alert(url);
		req.open("GET",url,true);
		req.onreadystatechange=processReqChange;
		req.send(null)
	} else {XMLActive=false; }
}
}
