var http;
var addr 		= "lib/ajax_funcs.php?";
var addrLogon 	= "lib/ajax_logon.php?";
var isWorking = false;
var divTag ;
var url			= "";


function handleGetData() {
  id = getObject(divTag);
  if (http.readyState == 4) {
  	if (http.status == 200) {
	  response = http.responseText;
	  layerContent = response ;
	  	 id.innerHTML = response ;
      isWorking = false;
      id.style.display = 'block';
	}
     else
	alert('Feil i forbindelsen til databasen');
    }
}

function handleLogon() {
  id = getObject('loggedOn');
  if (http.readyState == 4) {
  	if (http.status == 200) {
	  response = http.responseText;
      isWorking = false;
  	  id.innerHTML = response ;
	  if (url.length > 0)
			document.location.href='index.php?'+url;
	  else
			document.location.href='index.php';
    }
  }
}

function checkLogon(u,p,addr){
	url = addr;
    if(window.XMLHttpRequest) {
    	try {
			http = new XMLHttpRequest();
        } catch(e) {
			http = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	http = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		http = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		http = false;
        	}
		}
    }
	if(http) {
		http.onreadystatechange = handleLogon;
		v = 'u='+u+'&p='+ p ;
		http.open("GET", addrLogon + v, true);
		http.send("");
	}
}

function getData(v,tag){
	divTag = tag;
    http = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			http = new XMLHttpRequest();
        } catch(e) {
			http = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	http = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		http = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		http = false;
        	}
		}
    }
	if(http) {
		http.onreadystatechange = handleGetData;
		http.open("GET", addr + v, true);
		http.send("");
	}
}



function getObject( obj ) {
  if ( document.getElementById ) {
    if (obj = document.getElementById( obj )) {

    } else obj = null;
  } else if ( document.all ) {
    if (obj = document.all.item( obj )) {

    } else obj = null;
  } else {
    obj = null;
  }
  return obj;
}