var xmlHttp

function showHint(str) { 
        xmlHttp=GetXmlHttpObject(stateChanged)        
        if (str == "q")
            var url="ajaxtesting2.php"
        else
            var url="ajaxtesting.php"    
        xmlHttp.open('post',  url);
        xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        f1val = document.getElementById('felt1').value;
        poststring = "arg1=" + f1val
        xmlHttp.send(poststring)
}

function htmlsk_til_norsk(txt) {
    txt = txt.replace(/ZaeligZ/g,"æ")
    txt = txt.replace(/ZoslashZ/g,"ø")
    txt = txt.replace(/ZaringZ/g,"å")
    txt = txt.replace(/ZoumlZ/g,"ö")
    txt = txt.replace(/ZaumlZ/g,"ä")
    txt = txt.replace(/ZeacuteZ/g,"é")
    txt = txt.replace(/ZegraveZ/g,"è")
    txt = txt.replace(/ZuumlZ/g,"ü")
    txt = txt.replace(/ZAEligZ/g,"Æ")
    txt = txt.replace(/ZOslashZ/g,"Ø")
    txt = txt.replace(/ZAringZ/g,"Å")
    txt = txt.replace(/ZOumlZ/g,"Ö")
    txt = txt.replace(/ZAumlZ/g,"Ä")
    txt = txt.replace(/ZEacuteZ/g,"É")
    txt = txt.replace(/ZEgraveZ/g,"È")
    txt = txt.replace(/ZUumlZ/g,"Ü")
    return txt
}

function norsk_til_htmlsk(txt) {
    txt = txt.replace(/æ/g,"ZaeligZ")
    txt = txt.replace(/ø/g,"ZoslashZ")
    txt = txt.replace(/å/g,"ZaringZ")
    txt = txt.replace(/ö/g,"ZoumlZ")
    txt = txt.replace(/ä/g,"ZaumlZ")
    txt = txt.replace(/é/g,"ZeacuteZ")
    txt = txt.replace(/è/g,"ZgraveZ")
    txt = txt.replace(/ü/g,"ZuumlZ")
    txt = txt.replace(/Æ/g,"ZAEligZ")
    txt = txt.replace(/Ø/g,"ZOslashZ")
    txt = txt.replace(/Å/g,"ZAringZ")
    txt = txt.replace(/Ö/g,"ZOumlZ")
    txt = txt.replace(/Ä/g,"ZAumlZ")
    txt = txt.replace(/É/g,"ZEacuteZ")
    txt = txt.replace(/È/g,"ZEgraveZ")
    txt = txt.replace(/Ü/g,"ZUumlZ")
    return txt
}

function evalResponse() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		response = xmlHttp.responseText
		response = htmlsk_til_norsk(response)
		eval (response)
	}
}

function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}

function GetXmlHttpObject(handler) {
	var objXmlHttp=null
	ua = navigator.userAgent.toLowerCase();
	mozilla=false
	opera=false
	msie=false
	if (ua.indexOf("mozilla")>=0)
		mozilla=true
	if (ua.indexOf("opera")>=0)
		opera=true
		if (ua.indexOf("msie")>=0)
		msie=true
	if (opera)
		browser = "moz"
	else if (!msie)
		browser = "moz"
	else if (msie)
		browser = "msie"
	else
		browser = "moz"
	if (browser == "moz") {
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		return objXmlHttp
	} else {
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP"
		}
		try {
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler
			return objXmlHttp
		} catch(e) {
			alert("Error. Scripting for ActiveX might be disabled")
			return
		}
	}
}

function GetXmlHttpObjectSimple() {
    if (window.XMLHttpRequest)
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    if (window.ActiveXObject) 
        // code for IE6+, IE5
        return new ActiveXObject("Msxml2.XMLHTTP");
    return null;
}

function straight_url_eval_params(url, params, sync) {
    var x;
    if(sync) {       
        xmlHttp=GetXmlHttpObjectSimple();    
        xmlHttp.open('post', url, false);        
    } else {
        xmlHttp=GetXmlHttpObject(evalResponse);  
        xmlHttp.open('post', url);      
    }
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    poststring = "rand=" + Math.random();
    for (x in params) {
        poststring = poststring + "&" + x + "=" + params[x];
    }
    xmlHttp.send(poststring);
    if(sync) { 
        return xmlHttp.responseText; 
    }
}

function straight_url_eval(url) {
    xmlHttp=GetXmlHttpObject(evalResponse)
    xmlHttp.open('post',  url);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    poststring = "rand=" + Math.random()
    xmlHttp.send(poststring)
}