﻿function setFocus() {
  if ((navigator.userAgent.toLowerCase().indexOf("msie") < 0) || (parseInt(navigator.appVersion) >= 4)) {
    focus();
  }
}
function requireFrames(Url) {
	if (top.frames.length < 1) {
		top.location = Url;
	}
}
function breakFrames() {
  if (top.location != self.location) {
	  top.location = self.location
	}
}
function fccApps(License) {
	open('http://wireless2.fcc.gov/UlsApp/ApplicationSearch/applMain.jsp?applID=' + License, 'NewWindow', 'status=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');
}
function fccCall(CallSign) {
	open('http://gullfoss2.fcc.gov/cgi-bin/ws.exe/genmen/uls/call_res.hts?db_id=19&rows=&callsign=' + CallSign,'NewWindow', 'status=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');
}
function fccLics(License) {
	open('http://wireless2.fcc.gov/UlsApp/UlsSearch/license.jsp?licKey=' + License, 'NewWindow', 'status=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');
}
function GotoPage(APageNo) {
  if (APageNo > 1) {
    location.href = GPageURL.replace(/{%PAGENO%}/,APageNo);
  } else {
    location.href = GPageURL.replace(/{%PAGENO%}/,"");
  }
}

function stopRKey(ev) {
  var evt  = (ev) ? ev : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
 }

// Keep the page from going to the prior page when the backspace is pressed.
function disableBackSpace(event) {
  var key;
  if (event) {
    key = event.which ? event.which : event.keyCode;
    if (key == null || key != 8) {
      // return when the key is not backspace key.  
      return true;
    }
  }
  else {
    return true;
  }

  if (event.srcElement) {
    // in IE  
    tag = event.srcElement.tagName.toUpperCase();
    type = event.srcElement.type;
    readOnly = event.srcElement.readOnly;
    if (type == null) {
      // Type is null means the mouse focus on a non-form field. disable backspace button  
      return false;
    }
    else {
      type = event.srcElement.type.toUpperCase();
    }

  }
  else {
    // in FF  
    tag = event.target.nodeName.toUpperCase();
    type = (event.target.type) ? event.target.type.toUpperCase() : "";
  }

  // we don't want to cancel the keypress (ever) if we are in an input/text area  
  if (tag == 'INPUT' || type == 'TEXT' || type == 'TEXTAREA') {
    if (readOnly == true) {
      // if the field has been disabled, disable the back space button  
      return false;
    }
    if (((tag == 'INPUT' && type == 'RADIO') || (tag == 'INPUT' && type == 'CHECKBOX')) && key == 8) {
      return false; // the mouse is on the radio button/checkbox, disbale the backspace button  
    }
    return true;
  }

  // if we are not in one of the above things, then we want to cancel (true) if backspace  
  return (key != 8);
}

// check the browser type  
function browserName() {
  var agt = navigator.userAgent.toLowerCase();
  if (agt.indexOf("opera") != -1) return 'Opera';
  if (agt.indexOf("staroffice") != -1) return 'Star Office';
  if (agt.indexOf("webtv") != -1) return 'WebTV';
  if (agt.indexOf("beonex") != -1) return 'Beonex';
  if (agt.indexOf("chimera") != -1) return 'Chimera';
  if (agt.indexOf("netpositive") != -1) return 'NetPositive';
  if (agt.indexOf("phoenix") != -1) return 'Phoenix';
  if (agt.indexOf("firefox") != -1) return 'Firefox';
  if (agt.indexOf("safari") != -1) return 'Safari';
  if (agt.indexOf("skipstone") != -1) return 'SkipStone';
  if (agt.indexOf("msie") != -1) return 'Internet Explorer';
  if (agt.indexOf("netscape") != -1) return 'Netscape';
  if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';

  if (agt.indexOf('\/') != -1) {
    if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
      return navigator.userAgent.substr(0, agt.indexOf('\/'));
    }
    else {
      return 'Netscape';
    }
  }
  else if (agt.indexOf(' ') != -1) {
    return navigator.userAgent.substr(0, agt.indexOf(' '));
  }
  else {
    return navigator.userAgent;
  }
}

// Global events (every key press)  
if (browserName() == "FireFox") {
  // FireFox is ignoring the keydown so we have to call keypress 
  document.onkeypress = function (event) { return disableBackSpace(event); }
}
else {
  document.onkeydown = function (event) { return disableBackSpace(event); }
} 
