function PassFlash() {

    thisMovie("diplom").SetVariable("DiplomH1", "Diplom");
    thisMovie("diplom").SetVariable("DiplomH2", "Brandtex løbet");
    thisMovie("diplom").SetVariable("DiplomNavn", "Navn Tore Ajer");
    thisMovie("diplom").SetVariable("DiplomKm", "Km 2,1");
    thisMovie("diplom").SetVariable("DiplomTid", "i tiden 10:30 min");
    thisMovie("diplom").SetVariable("DiplomDato", "Brande den 23 sep. 2008");
    showPrintdiv();
}

function PrintFlash() {
    thisMovie("diplom").PrintDiplom();
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function isBrowserIE() {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return true;
    } else {
        return false;
    }
}




function showPrintdiv() {
	document.getElementById('printdiv').style.display = 'inline-block';
}

function showErrordiv() {
alert('Fejl i opslag');
//	document.getElementById('printdiv').style.display = 'inline-block';
}
//XML Handling

function getDiplomData() {
//PassFlash(); //bruges til test
  try {
    liame = document.getElementById('liame').value;
  } catch(err) {
    liame = 'NoUser';
  }
    strXML = postxml("getDiplomData.asp", 'liame=' + liame ); //+ '&drowssap=' + drowssap
}
 
function postxml(url, data) {
    xmlhttp = null
    xmlhttp = new XMLHttpRequest();
    //xmlhttp
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
           // alert('gg' + xmlhttp.responseText);
                XMLRoot = loadXML(unescape(xmlhttp.responseText).replace(/\+/g, " "));
              // alert('jow3' + getXmlValue(XMLRoot, '/Diplom/DiplomNavn', 0));
               //alert('sd' + xmlDoc.getElementsByTagName("DiplomNavn")[0].childNodes[0].nodeValue);

                thisMovie("diplom").SetVariable("DiplomNavn", "Navn: " + xmlDoc.getElementsByTagName("DiplomNavn")[0].childNodes[0].nodeValue);
                thisMovie("diplom").SetVariable("DiplomKm", "Km: " + xmlDoc.getElementsByTagName("DiplomKm")[0].childNodes[0].nodeValue);
                thisMovie("diplom").SetVariable("DiplomTid", "i tiden " + xmlDoc.getElementsByTagName("DiplomTid")[0].childNodes[0].nodeValue);
                thisMovie("diplom").SetVariable("DiplomDato", "Brande den " + xmlDoc.getElementsByTagName("DiplomDato")[0].childNodes[0].nodeValue);
				
                
                //thisMovie("diplom").SetVariable("DiplomNavn", "Navn: " + getXmlValue(XMLRoot, '/Diplom/DiplomNavn', 0));
                //thisMovie("diplom").SetVariable("DiplomKm", "Km: " + getXmlValue(XMLRoot, '/Diplom/DiplomKm', 0));
                //thisMovie("diplom").SetVariable("DiplomTid", "i tiden " + getXmlValue(XMLRoot, '/Diplom/DiplomTid', 0));
                //thisMovie("diplom").SetVariable("DiplomDato", "Brande den " + getXmlValue(XMLRoot, '/Diplom/DiplomDato', 0));
				
				showPrintdiv();
            } else {
				showErrordiv();
				
                return ("Problem retrieving XML data")
            }
        }
    }
   //  alert('jow4');
	xmlhttp.open("POST", url, true);
	
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
   // xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //xmlhttp.setRequestHeader("Content-length", data.length);
    //xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(data);
}

if (isBrowserIE()) {
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
} else {
	var xmlDoc = document.implementation.createDocument("","",null);
}


function loadXML(inXML) {
    xmlDoc.async = "false";
	if (isBrowserIE()) {
		xmlDoc.loadXML(inXML);
	} else {
		var parser=new DOMParser();
		xmlDoc = parser.parseFromString(inXML,"text/xml");
	}
    return xmlDoc;
}

function getXmlValue(inRoot, inPath, level) {
    if (inRoot.nodeName == inPath.split("/")[inPath.split("/").length - 1]) {
        return inRoot.text;
        //return inRoot.nodeValue;
    }
//alert(inRoot.nodeValue)
    for (var i = 0; i < inRoot.childNodes.length; i++) {
        try {
            if (inRoot.childNodes[i].nodeType == 1) {
                if (inRoot.childNodes[i].nodeName == inPath.split("/")[level + 1]) {
                    return getXmlValue(inRoot.childNodes[i], inPath, level + 1);
                }
            }
        } catch (e) {
            alert("121" + e);
        }
    }
}
 

// submit tilmeld form

function submitTilmeld() {

	//valider
	var strMissing
	strMissing = ""
	if (document.getElementById("id11").value == "" ) {
		strMissing = strMissing + "Navn skal være udfyldt";
	}
	if (document.getElementById("id15").value == "" ) {
		strMissing = strMissing + "Køn skal være udfyldt";
	}
	if (valButton(tilmeldBruger.distance) == null) {
		strMissing = strMissing + " Distance skal være udfyldt";
	}
//alert('|' + strMissing + '|');
	if (strMissing == "" ) {
		document.tilmeldBruger.submit();
	}
}

/*function tabnext(event) { 
    if( event.keyCode == 13 ) { 
    	event.keyCode=9; 
	//	return event.keyCode; //true 
    }   
}  
*/
var cle;
 function detect(Event) {
  // Event appears to be passed by Mozilla
  // IE does not appear to pass it, so lets use global var
  if(Event==null) {
  		alert('null');
  		Event=event;
  		}
  cle = Event.keyCode;
 }
 
function tabnext(Event,quoi) {
	detect(Event);
	setTimeout('cle=""',100);
	if(cle=='13') {
	//	alert('ojw1');
	//		alert(' - ' + 'id' + (parseInt(quoi.id.substring(2,4), 10)+parseInt(1,10)));//quoi.tagName + 
			document.getElementById('id' + (parseInt(quoi.id.substring(2,4))+parseInt(1))).focus();
	}
}

function setHold(sel) {
    if (document.getElementById('id18').options[document.getElementById('id18').selectedIndex].value != "") {
	    document.getElementById('id17').value = document.getElementById('id18').options[document.getElementById('id18').selectedIndex].value
	}
}


function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}


function submitAdminLogin() {
	document.adminlogin.submit();
}

function submitAdminUpload() {
	document.adminupload.submit();
}

function submitRedigerBruger() {
	document.redigerBruger.submit();
}

function submitSetDiplomDato() {
	//diplomdato = document.getElementById("diplomdato").value; 
	document.admindato.submit();
}

function submitSletDiplomData() {
	//diplomdato = document.getElementById("diplomdato").value; 
	document.admindellob.submit();
}

function submitNytLob() {
	//diplomdato = document.getElementById("diplomdato").value; 
	document.adminnytlob.submit();
}
function submitSletBruger() {
	strGuid = document.getElementById('Guid').value
	var strRes
	if (strGuid.length >23) {
		strRes = postxmlDelete("tilmeldDelete.asp", "brugerGuid=" + strGuid + "&brugerDelete=1")
	}
}

function postxmlDelete(url, data) {
    xmlhttp = null
    xmlhttp = new XMLHttpRequest();
    xmlhttp
    xmlhttp.onreadystatechange = function() {
   
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
         
				document.getElementById("selectUser").innerHTML = unescape(xmlhttp.responseText).replace(/\+/g, " ");
            } else {
				
                alert("Bruger kunne ikke slettes");
            }
        }
    }
    xmlhttp.open("POST", url, false);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", data.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(data);
}



//Galleri
var arrImg =new Array()
var icurrent = 0
var icount = 0
function postxmlHentGalleri(url, data) {
//alert(url + '  ' + data);
    xmlhttp = null
    xmlhttp = new XMLHttpRequest();
    xmlhttp
    xmlhttp.onreadystatechange = function() {
   
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
         
				//document.getElementById("selectUser").innerHTML = unescape(xmlhttp.responseText).replace(/\+/g, " ");
				
				arrImg = unescape(xmlhttp.responseText).replace(/\+/g, " ").split(";")
				//arrImg = "http://brandelob.ajer.dk/_images/billeder/tores-kniv1.jpg;http://brandelob.ajer.dk/_images/billeder/tores-kniv2.jpg;http://brandelob.ajer.dk/_images/billeder/tores-kniv3.jpg".split(";")
				document.getElementById("imgsrc").src = arrImg[0];
				document.getElementById("imgNext").style.display = "block";
				document.getElementById("imgPrevious").style.display = "none";
				icount = arrImg.length
				icurrent = 0
            } else {
				
                alert("Kunne ikke hente billederne");
            }
        }
    }
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", data.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(data);
}


function preloadimages() {


    if (icurrent < icount) {
        pic1= new Image(940,560); 
        pic1.src=arrImg[icurrent+1];//imgpath + "gz08yei" + checkdigits((icurrent + 1)) + ".jpg"; 
    }
    
    if ((icurrent + 1) < icount) {
        pic2= new Image(940,560); 
        pic2.src=arrImg[icurrent+2];//imgpath + "gz08yei" + checkdigits((icurrent + 2)) + ".jpg"; 
    }
    
    if (icurrent > 1) {
        pic3= new Image(940,560); 
        pic3.src=arrImg[icurrent-1];//imgpath + "gz08yei" + checkdigits((icurrent - 1)) + ".jpg"; 
    }
    
    if ((icurrent - 1) > 1) {
        pic4= new Image(940,560); 
        pic4.src=arrImg[icurrent-2];//imgpath + "gz08yei" + checkdigits((icurrent - 2)) + ".jpg"; 
    }



}

function imgnext() {
    //document.getElementById("imgsrc").src = "_images/logo2.gif"; // imgpath + "blank.gif";
    document.getElementById("imgPrevious").style.display = "block";
    
    icurrent = icurrent + 1;
    //alert(arrImg[icurrent] + ' ' + icurrent);
    document.getElementById("imgsrc").src = arrImg[icurrent];//imgpath + "gz08yei" + checkdigits(icurrent) + ".jpg";
    
    if (icurrent == icount-1 || icount == 0) {

       document.getElementById("imgNext").style.display = "none";
    }
    preloadimages();

}

function imgprevious() {
    //document.getElementById("imgsrc").src = "_images/logo2.gif"; //  imgpath + "blank.gif";
    document.getElementById("imgNext").style.display = "block";
    
    icurrent = icurrent - 1;
    // alert(arrImg[icurrent] + ' ' + icurrent);
    document.getElementById("imgsrc").src = arrImg[icurrent];//imgpath + "gz08yei" + checkdigits(icurrent) + ".jpg";
    
    if (icurrent == 0 || icount == 0) {
       document.getElementById("imgPrevious").style.display = "none";
    }
    preloadimages();


}
