var req;

function getXMLHTTP(){
    xmlHttp=null;
    if (typeof XMLHttpRequest != "undefined") {
        xmlHttp = new XMLHttpRequest();
    }
    if (!xmlHttp) {
        // Internet Explorer 6 und älter
        try {
            xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                xmlHttp  = null;
            }
        }
    }
    return xmlHttp;
}

// Locations nach Stadt
function checkforreadylocations(){

if(req.readyState == 4) {
        if(req.status == 200) {
            document.getElementById("slocationDiv").innerHTML=req.responseText;
            breaknow=true;
        }
        if(breaknow)
        {
            return false;
        }
        alert("Es ist ein Fehler beim Laden der Locations aufgetreten.");
        document.getElementById("slocationDiv").innerHTML=req.responseText;
    }
}

function getLocations(preset){
        req=null;
        req=getXMLHTTP();
        req.onreadystatechange=checkforreadylocations;
        var cityid=null;
        cityid=document.getElementById("scity").value;
        var lcat=null;
        lcat=document.getElementById("slcat").value;
        var poststr=null;
        poststr="cityID="+cityid+"&lcat="+lcat;
        if(typeof(preset)!='undefined')
        {
            poststr=poststr+"&preset="+preset;
        }
        req.open("GET", "/getLocations.ajax.php?"+poststr, true);

        req.send(null);
}

//Städte nach Region

function checkforreadycities(){

if(req.readyState == 4) {
        if(req.status == 200) {
            document.getElementById("scityDiv").innerHTML=req.responseText;
            breaknow=true;
            getLocations();
        }
        if(breaknow)
        {
            return false;
        }
        alert("Es ist ein Fehler beim Laden der cities aufgetreten.");
        document.getElementById("scityDiv").innerHTML=req.responseText;
    }
}

function getCities(preset){
        req=null;
        req=getXMLHTTP();
        req.onreadystatechange=checkforreadycities;
        var regionid=null;
        regionid=document.getElementById("sregion").value;
        var poststr=null;
        poststr="regionID="+regionid;
        if(typeof(preset)!=undefined)
        {
            poststr=poststr+"preset="+preset;
        }
        req.open("GET", "/getCities.ajax.php?"+poststr, true);

        req.send(null);
}

// Regionen nach Land
function checkforreadyregions(){

if(req.readyState == 4) {
        if(req.status == 200) {
            document.getElementById("sregionDiv").innerHTML=req.responseText;
            breaknow=true;
            getCities();
        }
        if(breaknow)
        {
            return false;
        }
        alert("Es ist ein Fehler beim Laden der cities aufgetreten.");
        document.getElementById("sregionDiv").innerHTML=req.responseText;
    }
}

function getRegions(preset){
        req=null;
        req=getXMLHTTP();
        req.onreadystatechange=checkforreadyregions;
        var countryid=null;
        countryid=document.getElementById("scountry").value;
        var poststr = "countryID="+countryid;
        if(typeof(preset)!=undefined)
        {
            poststr=poststr+"preset="+preset;
        }
        req.open("GET", "/getRegions.ajax.php?"+poststr, true);

        req.send(null);
}

function checkforreadypeoplefinder(){
if(req.readyState == 4) {
        if(req.status == 200) {
            document.getElementById("profile_people_finder").innerHTML=req.responseText;
            breaknow=true;
        }
        if(breaknow)
        {
            return false;
        }
        alert("Es ist ein Fehler beim Laden der Locations aufgetreten.");
        document.getElementById("profile_people_finder").innerHTML=req.responseText;
    }
}

function getPeopleFinderContents(highlight){
        req=null;
        req=getXMLHTTP();
        var addition='';
        if(typeof(highlight)!='undefined') addition='?highlight='+highlight;
        req.onreadystatechange=checkforreadypeoplefinder;
        req.open("GET", "/getPeopleFinderContents.ajax.php"+addition, true);
        req.send(null);
}

function delPeopleFinderContents(id,confirm){
        req=null;
        req=getXMLHTTP();
        req.onreadystatechange=checkforreadypeoplefinder;
        
        var poststr = "del="+id;
        if(typeof(confirm)!='undefined' && confirm==true)
        {
            poststr=poststr+"&confirm=true";
        }
        req.open("GET", "/getPeopleFinderContents.ajax.php?"+poststr, true);
        req.send(null);
}

function getPeopleFinderMatches(id){
        req=null;
        req=getXMLHTTP();
        req.onreadystatechange=checkforreadypeoplefinder;
        var poststr=null;
        poststr="sid="+id;
        req.open("GET", "/getPeopleFinderContents.ajax.php?"+poststr, true);
        req.send(null);
}


function checkforreadyHotspotContents(){
if(req.readyState == 4) {
        if(req.status == 200) {
            document.getElementById("profile_people_finder").innerHTML=req.responseText;
            breaknow=true;
        }
        if(breaknow)
        {
            return false;
        }
        alert("Es ist ein Fehler beim Laden der Locations aufgetreten.");
        document.getElementById("profile_people_finder").innerHTML=req.responseText;
    }
}

function getHotspotContents(lid){
        req=null;
        req=getXMLHTTP();
        req.onreadystatechange=checkforreadyHotspotContents;
        var poststr=null;
        poststr="lid="+lid;
        req.open("GET", "/HotspotContents.ajax.php?"+poststr, true);
        req.send(null);
}

// Hinzufügen von Daten

function addCity(hotspotfinder){
        
        var regionid=null;
        regionid=document.getElementById("sregion").value;
        var poststr=null;
        poststr="rid="+regionid+"&TB_iframe=true&height=350&width=550";
        if(typeof(hotspotfinder)!='undefined')
        {
            poststr+="&hotspot=true";
        }
        TB_show('Stadt hinzuf&uuml;gen','addCity.ajax.php?'+poststr,'','./images/trans.gif');
}

// Hinzufügen von Daten

function addLocation(hotspotfinder){
        
        var cityid=null;
        cityid=document.getElementById("scity").value;
        var categoryid=null;
        categoryid=document.getElementById("slcat").value;
        
        var poststr=null;
        poststr = "cid="+cityid+"&slcat="+categoryid+"&TB_iframe=true&height=250&width=450";
        if(typeof(hotspotfinder)!='undefined')
        {
            poststr="hotspot=true&"+poststr;
        }
        TB_show('Location hinzuf&uuml;gen','addLocation.ajax.php?'+poststr,'','./images/trans.gif');
}


// Adminbereich JS

function updateFeaturedFrame(checked){
  //  var lid;
  //  var lfid;
  
    if(document.getElementById('lid') !== null)
        lid=document.getElementById('lid').value;
    if(document.getElementById('lfid') !== null)    
        lfid=document.getElementById('lfid').value;
    if(typeof(checked)!='undefined' && checked)
    {
        var poststr='?';
        if(typeof(lid)=='undefined')
        {
            if(typeof(lfid)=='undefined' || lfid=='')
            {
                poststr+='new=true';
            }
            else
            {
                poststr+='lfid='+lfid;
            }
        }
        else
        {
            poststr+='lid='+lid;
        }
        document.getElementById('featuredFrame').height='400';
        frames.featuredFrame.location.href='/admin/admin_featured_locations.php'+poststr;
    }
    else
    {
        document.getElementById('featuredFrame').height='0';
        frames.featuredFrame.location.href='/admin/admin_featured_locations.php?unfeatured=true';
    }
}

function showFeaturedInfo(lid){
    document.hotspotFinder.lfdetail.value=lid;
    document.hotspotFinder.action='/hotspot_detail.php?lid='+lid;
    document.hotspotFinder.submit();
}

function showHelp(type){
    
    if(typeof(type)!='undefined')
    {
        var poststr='type='+type+'&TB_iframe=true&height=250&width=450';
    }
    else
    {
        return false;
    }   
    TB_show('Hilfe','showHelp.ajax.php?'+poststr,'','./images/trans.gif');
}

function suggestHotSpot(){
        
        var cityid=null;
        cityid=document.getElementById("scity").value;
        var categoryid=null;
        categoryid=document.getElementById("slcat").value;
        
        var poststr=null;
        poststr = "cid="+cityid+"&slcat="+categoryid+"&TB_iframe=true&height=250&width=450";
        TB_show('HotSpot vorschlagen','HotSpotRequest.ajax.php?'+poststr,'','./images/trans.gif');
}

