
var http2;
var url2 = "http://stillinger.jus.no/annonseshow.php?text=";
var isWorking2 = false;


function handleRelatert() {
  l = document.getElementById('annonseShow');
  nivaa = 0;
  n = 0;
  if (l) {
	  l.innerHTML = 'Vent litt.  Laster ....';
	  var t;
	  if (http2.readyState == 4) {
	  	if (http2.status == 200) {
		    resp = http2.responseText;
	        l.innerHTML = resp;
	        colorResponse();
		} else l.innerHTML = '';
	      isWorking = false;
	  }
   }
}

function colorResponse(){
	v = document.getElementById('tSok').value;
	divs = document.getElementsByTagName('div');
	for (i=0;i<divs.length;i++){
	   nm = divs[i].className;
	   if (nm.substring(0,4)=='supl')	{
		   resp = divs[i].innerHTML ;
		   resp = resp.substring(0,resp.indexOf(v))+'<font color="red">' + v + '</font>' + resp.substring(resp.indexOf(v)+v.length);
		   divs[i].innerHTML = resp;
	   }

	}
}
function visAnnonse(){
	if (document.getElementById('tSok').value.length > 0) {
    http2 = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			http2 = new XMLHttpRequest();
        } catch(e) {
			http2 = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	http2 = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		http2 = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		http2 = false;
        	}
		}
    }
	if(http2) {
		if (v = document.getElementById('tSok').value) {
			if (o=document.getElementById('annonseBlokk'))
			  o.style.display='none';
			http2.onreadystatechange = handleRelatert;
			http2.open("GET", url2+v, true);
			http2.send("");
		}
	}
	colorResponse(v);
	} else alert ('Du må angi noe å søke på!');
}


function settPos(obj){
	d = document.getElementById(obj);
	h = findPosY(d);
	if (o=document.getElementById('annonseshow')){
		h=h-30;
		o.style.top = h+'px';
	}
}

function visAlle(){
	document.location.href = 'http://stillinger.jus.no/';

}