/* onload initialization functions */

var initfuncs=new Array();

function addInitFunc(func) {
  initfuncs[initfuncs.length]=func;
}

function initialize() {
  for(i=0;i<initfuncs.length;i++) {
    initfuncs[i]();
  }
}

/* cursor functions */

function cursor_wait() {
  document.body.style.cursor = 'wait';
}

function cursor_clear() {
  document.body.style.cursor = 'default';
}

/* overlay loading functions */

function show(id){
   document.getElementById(id).style.display='block';
}
function hide(id){
   document.getElementById(id).style.display='none';
}

var id_where=new Array();
var xmlhttp=new Array();

var busy=0;

function loadArgs(what,where,skin,args) {
   cursor_wait();
   id_where[0]=where;
   busy=1;
   loadXMLDoc(0,what+"?skin="+skin+"&"+args);
}

function load(what,where,skin){
/*   cursor_wait();
   id_where[0]=where;
   busy=1;
   loadXMLDoc(0,what+"?skin="+skin);
*/
   loadArgs(what,where,skin,'');
}

function loadDoubleArgs(what0,where0,skin0,args0,what1,where1,skin1,args1) {
   cursor_wait();
   id_where[0]=where0;
   id_where[1]=where1;
   busy=2;
   loadXMLDoc(0,what0+"?skin="+skin0+"&"+args0);
   loadXMLDoc(1,what1+"?skin="+skin1+"&"+args1);
}

function loadDouble(what0,where0,skin0,what1,where1,skin1) {
/*   cursor_wait();
   id_where[0]=where0;
   id_where[1]=where1;
   busy=2;
   loadXMLDoc(0,what0+"?skin="+skin0);
   loadXMLDoc(1,what1+"?skin="+skin1); */
   loadDoubleArgs(what0,where0,skin0,'',what1,where1,skin1,'');
}


function loadXMLDoc(idx,url) {
   xmlhttp[idx]=null
   // code for Mozilla, etc.
   if (window.XMLHttpRequest) {
   	xmlhttp[idx]=new XMLHttpRequest()
   }
   // code for IE
   else if (window.ActiveXObject) {
  	xmlhttp[idx]=new ActiveXObject("Microsoft.XMLHTTP")
   }
   if (xmlhttp[idx]!=null) {
	if(idx==0) xmlhttp[idx].onreadystatechange=state_Change0;
	else xmlhttp[idx].onreadystatechange=state_Change1;
  	xmlhttp[idx].open("GET",url,true)
  	xmlhttp[idx].send(null)
   } else {
  	alert("Your browser does not support XMLHTTP.")
	busy--;
        if(busy<=0) cursor_clear();
   }
}

function state_Change0() {
  state_Change(0);
}
function state_Change1() {
  state_Change(1);
}

function state_Change(idx) {

   // if xmlhttp shows "loaded"
   if (xmlhttp[idx].readyState==4) { // if "OK"
  	if (xmlhttp[idx].status==200) {
		document.getElementById(id_where[idx]).innerHTML=xmlhttp[idx].responseText;
 		show(id_where[idx]);
		window.scrollTo(0,0);
	        busy--;
                if(busy<=0) cursor_clear();
      	} else {
    		alert("Problem retrieving XML data")
	        busy--;
                if(busy<=0) cursor_clear();
     	}
   }
}



/* rightbar functions */

// mark the text in element with id 
function changeColor(id,col) {
  var elm = document.getElementById(id);

  if(elm==null) return;

  elm.style.color=col;
}

function changeColorAll(container,prefix,col) {
  var elm = document.getElementById(container);

  if(elm==null) return;

  var elms = elm.getElementsByTagName("div");

  for(i=0;i<elms.length;i++) {
    if(elms[i].id.indexOf(prefix)==0) {
      elms[i].style.color=col;
    }
  } 
}

function showImage(container,img) {
  var elm = document.getElementById(container).getElementsByTagName('img');

  if(elm==null) return;

  elm[0].setAttribute('src',img);
}

function geoTagNavToggle(what) {
    if(what=='tag') {
      enable='tagnav'; enablelink='tagnavlink';
      disable='geonav'; disablelink='geonavlink';
    } else {
      disable='tagnav'; disablelink='tagnavlink';
      enable='geonav'; enablelink='geonavlink';
    }
    document.getElementById(disable).style.display='none';
    document.getElementById(enable).style.display='block';
    document.getElementById(disable+'legend').style.display='none';
    document.getElementById(enable+'legend').style.display='block';
    document.getElementById(disablelink).style.color='#777777';
    document.getElementById(enablelink).style.color='#000000';
}

