
//########################################################################
// Pfad zum Verzeichnis Public ohne Host
// Auch in Datei adminFunctions.js (public/javascript) anpassen!
var  ApplicationPath =  '/';
//########################################################################

var host = 'http://' + location.host;
var divId = 'moreInfos';

function getXhr() {
    var xhr = null; 
     
    if(window.XMLHttpRequest) // Firefox and others
       return new XMLHttpRequest(); 
    else if(window.ActiveXObject){ // Internet Explorer 
       try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
               return new ActiveXObject("Microsoft.XMLHTTP");
            }
    }
    else { // XMLHttpRequest not supported
       return null;
    }
}

function register(testtypeid, language, location, locationid)
{
	//alert(testtype);
	var testtype = "/register/" + testtypeid;
	var loc = "/loc/" + locationid;
	var lang = "/lang/" + document.getElementById('lang').value;
	if(document.getElementById(divId).name = 'free'){
		var ask = confirm('Wollen Sie sich wirklich in ' + location + ' anmelden?');
		if(ask)
		{	
			//alert(ServerUrl + ApplicationPath + "default/index/test" + testtype +  lang + loc);
			window.location.href = host + ApplicationPath + "default/index/test" + testtype +  lang + loc;
		}
	}else{
		alert('Eine Anmeldung ist leider nicht mehr möglich da nun alle Plätze wärend Ihrer anmeldung belegt wurden.')
	}
}

function goBack()
{
	window.history.back();
}
function goToUrl(href)
{
	window.location.href = href;
}

function showTip(testid, lang, mapid,xhr)
{
	
	 document.getElementById(divId).style.display = 'block';
	 xhr.onreadystatechange = function(){
		 	if(xhr.readyState == 4 && xhr.status == 200){
		    	if(xhr.responseText  != 'null')
		    	{
		    		//alert(xhr.responseText);
	    			var json = eval("(" + xhr.responseText + ")");
	    			var divContent = document.getElementById(divId);
	    			divContent.innerHTML = '<h1 style="margin:0 0 5px 0;">Verfügbare Eignungsanalysen:</h1>';
	    			
    				var tbl     = document.createElement("table");
    		        var tblHead = document.createElement("thead");
    		        var tblBody = document.createElement("tbody");

    				var row = document.createElement("tr");
    				
    				var widths = new Array();
    				widths[0] = 30;
    				widths[1] = 40;
    				widths[2] = 30;
    				
    				var headers = Array();
    				headers[0] = "Typ";
    				headers[1] = "Testbeginn";
    				headers[2] = "Freie Plätze";
    				
    				for (var i = 0; i < 3; i++) {
    					var cell = document.createElement("td");
    					//var cellText = document.createTextNode("Testtyp , Testbegin , Freie Plätze");
    					var cellText = document.createTextNode(headers[i]);
    					cell.appendChild(cellText);
    					cell.setAttribute("width", widths[i] + "%");
    					cell.setAttribute("style", "font-weight:bold");
    					row.appendChild(cell);
    				}
    		        tblHead.appendChild(row);
    		        
    		        
    		        for (var j = 0; j < json.length; j++) {
    		            // creates a table row
    		        	var cellcontent = Array();
        				cellcontent[0] = json[j].testtype;
        				cellcontent[1] = json[j].dateBegin;
        				cellcontent[2] = json[j].places;
        				
    		            var row2 = document.createElement("tr");
    		        	//alert(json[j].testtype + "," + json[j].dateBegin + "," + json[j].places);
    		            for (var i = 0; i < 3; i++) {
    		                var cell = document.createElement("td");
    		                var cellText = document.createTextNode(cellcontent[i]);
    		                cell.appendChild(cellText);
    		                row2.appendChild(cell);
    		            }

    		            tblBody.appendChild(row2);
    		        }

    		        tbl.appendChild(tblHead);
    				tbl.appendChild(tblBody);
    				tbl.setAttribute("width","400")
    				divContent.appendChild(tbl);
    				//return tbl;
    				
	    		}
		    	else
		    	{
		    		document.getElementById(divId).innerHTML = 'Keine Tests Verfügbar!';
		    		document.getElementById(divId).name = 'free';
		    		//return false;
		    	}
		    }
		    else {
		    	document.getElementById(divId).innerHTML = '<img src="' + ApplicationPath + 'images/loading.gif" />';
		    }
	}
	xhr.open('GET', host + ApplicationPath + 'default/index/gettests/testid/' + testid + '/lang/' + lang + '/mapid/' + mapid, true);
	xhr.send(null);
	
	//alert(infoText);
}

function unshowTip()
{
	//alert(divId);
	document.getElementById(divId).style.display = 'none'
	document.getElementById(divId).innerHTML = '';
}

function showInfos(type,xhr)
{
	//document.getElementById('moreInfos').innerHTML = '<p><b>Form</b><br/> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero <p>';
	document.getElementById('moreInfos').style.display = 'block';
	 xhr.onreadystatechange = function(){
		 	if(xhr.readyState == 4 && xhr.status == 200){
		    	if(xhr.responseText  != 'null')
		    	{
		    		var json = eval("(" + xhr.responseText + ")");
		    		var infoContent = '';
		    		json[0].id;
		    		infoContent += '<h1>Multicheck Junior ' + json[0].name + '</h1><br/>';
		    		infoContent += '<b>Preis</b><br/>';
		    		infoContent += 'EUR ' + json[0].price;
		    		infoContent += '<br/><br/><b>Form</b><br/>';
		    		infoContent +=json[0].form;
		    		infoContent += '<br/><br/><b>Mitzubringen</b><br/>';
		    		infoContent +=json[0].tobring;
		    		infoContent += '<br/><br/><b>Inhalte</b><br/>';
		    		infoContent +=json[0].contents;
		    		infoContent += '<br/><br/><b>Abmeldung</b><br/>';
		    		infoContent +=json[0].unsubscribe;
		    		//infoContent += '<p>Warnung<p>';
		    		//json[0].warning;
		    		//json[0].language;
		    		//json[0].shortname;
		    		document.getElementById('moreInfos').innerHTML = infoContent;
	    		}
		    	else
		    	{
		    		document.getElementById('moreInfos').innerHTML = '';
		    	}
		    }
		    else {
		    	document.getElementById(divId).innerHTML = '<img src="' + ApplicationPath + 'images/loading.gif" />'
		    }
	}
	xhr.open('GET', host + ApplicationPath + 'default/index/gettesttypes/type/' + type, true);
	xhr.send(null);
	
	//alert(infoText);
}

function unshowInfos()
{
	//alert(divId);
	document.getElementById('moreInfos').style.display = 'none'
	document.getElementById('moreInfos').innerHTML = '';
}

//document.onmousemove = move_Area;
