/**************************************************

Joshua K Roberson
Extra and random small but useful functions

**************************************************/

// Popup window
// IE7 has a security setting that displays address bar even if turned off
function extras_popUp(URL, w, h, scroll) {
  day = new Date();
  id = day.getTime();
  if(w == 0 || w > screen.width)  w = screen.width;
  if(h == 0 || h > screen.height) h = screen.height;
  LeftPos = (screen.width) ? (screen.width-w)/2 : 0;
  TopPos  = (screen.height) ? (screen.height-h)/2 : 0;
  settings = 'resizable=1,toolbar=0,location=0,statusbar=0,menubar=0,width='+w+',height='+h+',top='+TopPos+',left='+LeftPos+',scrollbars='+scroll;
  eval("page" + id + " = window.open(URL, '" + id + "', '"+settings+"');");
  return false;
}


// Redirect popup opener
function extras_redirectOpener(link) {
  if(window.opener) {
    window.opener.location.href=link
    window.close()
  } else {
    window.location.href=link;
  }
}


// Reload popup opener
function extras_reloadOpener() {
  if(window.opener) {
    window.opener.location.reload(true);
    window.close()
  } else {
    window.location.reload(true);
  }
}


// Inject Stock Chart into element after the 'onload' body event
// <body onload="extras_loadStockChart();"><div id="ajax_stockChart"></div>
function extras_loadStockChart() {
    var headTag = document.getElementsByTagName("head").item(0);
    if(headTag != null) { // Write to element if exists
	var scriptTag = document.createElement("script");
	//scriptTag.src = 'http://studio-5.financialcontent.com/hart?Account=oilandgasinvestor&Module=stockquote3&Output=jscallback&Callback=extras_stockChartLoader'; // Graphs
	scriptTag.src = 'http://studio-5.financialcontent.com/hart?Account=oilandgasinvestor&Module=stockquote4&Output=jscallback&Callback=extras_stockChartLoader'; // No Graphs
	headTag.appendChild( scriptTag );
    }
}
function extras_stockChartLoader (HTML,JS) {
    var obj = document.getElementById('ajax_stockChart');
    if(obj != null) { // Write to element if exists
	obj.innerHTML = HTML;
	eval(JS);
    }
}


// Show longer list when "more" link clicked
function extras_toogleDisplay(id_hide, id_show) {
  var id1 = id_hide;
  var id2 = id_show;
  var div1 = null;
  var div2 = null;

  if(document.getElementById) {
    div1 = document.getElementById(id1);
    div2 = document.getElementById(id2);
  } else if(document.all) {
    div1 = document.all[id1];
    div2 = document.all[id2];
  } else if(document.layers) {
    div1 = document.layers[id1];
    div2 = document.layers[id2];
  }

  div1.style.display = 'none';
  div2.style.display = 'block';
  return false;
}


// Show element if hidden or hide element if shown when link clicked
function extras_toggleElement(id) {
  var id1 = id;
  var div1 = null;

  if(document.getElementById) {
    div1 = document.getElementById(id1);
  } else if(document.all) {
    div1 = document.all[id1];
  } else if(document.layers) {
    div1 = document.layers[id1];
  }

  if(div1.style.display == 'none') {
    div1.style.display = 'block';
  } else {
    div1.style.display = 'none';
  }
  return false;
}

