/*
  myscript.js  --  by Jim Pool as used on
  http://freepages.genealogy.rootsweb.com/~jimpool/
  reference link:
  <SCRIPT SRC="myscript.js" TYPE=text/javascript LANGUAGE=JavaScript1.2></SCRIPT>
  revision: 27 Aug 2008
*/

function showcode() {  // show rendered code in a textarea
  putcode = document.getElementById("codearea");
  if(putcode.getElementsByTagName("textarea").length>0) {
    putcode.innerHTML = "";
  } else {
    orgcode = document.getElementsByTagName('html')[0].outerHTML;
    boxcode = '<textarea name="txtcode" rows="12" cols="90" wrap="off" readonly ';
    boxcode = boxcode + 'style="padding: 7px; font-family: Verdana; font-size: 9pt; ';
    boxcode = boxcode + 'font-weight: bold; background-color: rgb(255,255,153)"></textarea>';
    putcode.innerHTML = boxcode;
    txtcode.value = orgcode;
  }
}

/*
function showcode() {  // place a textarea with rendered HTML code in a space named "codearea"
  pcode = document.getElementById("codearea");
  if(pcode.getElementsByTagName("textarea").length>0) {
    pcode.innerHTML = "";
  } else {
    ncode = document.getElementsByTagName('html')[0].outerHTML;
    pcode.innerHTML = '<textarea class="area" name="delivered" rows="12" cols="90" wrap="off" readonly></textarea>';
    delivered.value = ncode;
  }
}
*/

function view(code) {  // view source file code in Notepad
  url = window.location.href;
  x = url.split("/");
  filename = x[x.length-1];
  path = (url.substring(0,url.indexOf(filename)));
  if (code=="name a file") { alert("A name is needed.");return; }
  if (code==" ") code = filename;
  window.location.href="view-source:" + path + code;
}

function content(){}

function notable() {  // delete first table - RootsWeb banner
//  nocode = document.getElementsByTagName('table')[0];
//  if (nocode) nocode.outerHTML = "";
//  nocode = document.getElementsByTagName('div')[0];
//  if (nocode) nocode.outerHTML = "";
}

function notop() {
  // delete body padding
  xfix=document.getElementById('userContentFP');
  if(xfix) {
    xfix.style.paddingRight='0px';
    xfix.style.paddingLeft='0px';
    xfix.style.paddingTop='0px';
    xfix.style.paddingBottom='0px';
  }
  // delete top banner
  xout = document.getElementsByTagName('div')[0];
  if (xout) xout.outerHTML="";
}

function nobot() { // delete footer
  xbody = document.getElementById('fp_ftr');
//  if(xbody) { document.body.innerHTML = xbody.innerHTML; }
//  if(xbody) { xbody.style.padding = ""; }
  if(xbody) { xbody.outerHTML = ""; }
}

function dms(n) {  // convert decimal degrees to degrees/minutes/seconds
  deg = parseInt( n * 1 );
  min = parseInt( (n * 1 - deg) * 60 );
  sec = Math.round( (n * 1 - deg - (min / 60)) * 360000 ) / 100;
  if (isNaN(deg)) deg = "__";
  if (isNaN(min)) min = "__";
  if (isNaN(sec)) sec = "__";
  document.write(deg+"° "+min+"\' "+sec+"\"");
}

function gps(n) {
  deg = parseInt( n * 1 );
  decmin = Math.round( (n * 1 - deg) * 600000 ) / 10000;
  if (isNaN(deg)) deg = "__";
  if (isNaN(decmin)) decmin = "__";
  document.write(deg+"° "+decmin+"\' ");
}

function pll(pp) {  // parse decimal latitude / longitude

  // write gps (decimal minutes) version
  d = pp.indexOf("°");
  c = pp.indexOf(":");
  document.write("<br>"+pp.substr(0,c+2));
  gps(pp.substr(c+2,d-c-2));
  c = pp.lastIndexOf(":");
  document.write(pp.substr(d+1,c-d+1));
  d = pp.lastIndexOf("°");
  gps(pp.substr(c+2,d-c-2));
  document.write(pp.substr(d+1));

  // write dms (degree, minute, second) version
  d = pp.indexOf("°");
  c = pp.indexOf(":");
  document.write("<br>"+pp.substr(0,c+2));
  dms(pp.substr(c+2,d-c-2));
  c = pp.lastIndexOf(":");
  document.write(pp.substr(d+1,c-d+1));
  d = pp.lastIndexOf("°");
  dms(pp.substr(c+2,d-c-2));
  document.write(pp.substr(d+1));

}


