function drc(id, onoff) {
    if (onoff == 1)
     {
       document.getElementById(id).src = "./images/nav_2.gif";
       if (id=="mapCtrl_imgbtnNNW" || id=="mapCtrl_imgbtnWNW" || id=="mapCtrl_imgbtnNW")
       {
        document.getElementById("mapCtrl_imgbtnWNW").src = "./images/nav_2.gif";  
        document.getElementById("mapCtrl_imgbtnNNW").src = "./images/nav_2.gif";
        document.getElementById("mapCtrl_imgbtnNW").src = "./images/nav_2.gif";
       }
       else if (id=="mapCtrl_imgbtnSSW" || id=="mapCtrl_imgbtnWSW" || id=="mapCtrl_imgbtnSW")
       {
        document.getElementById("mapCtrl_imgbtnSSW").src = "./images/nav_2.gif";  
        document.getElementById("mapCtrl_imgbtnWSW").src = "./images/nav_2.gif";
        document.getElementById("mapCtrl_imgbtnSW").src = "./images/nav_2.gif";       
       }
       else if (id=="mapCtrl_imgbtnSSO" || id=="mapCtrl_imgbtnOSO" || id=="mapCtrl_imgbtnSO")
       {
        document.getElementById("mapCtrl_imgbtnSSO").src = "./images/nav_2.gif";  
        document.getElementById("mapCtrl_imgbtnOSO").src = "./images/nav_2.gif";       
        document.getElementById("mapCtrl_imgbtnSO").src = "./images/nav_2.gif";
       }
       else if (id=="mapCtrl_imgbtnNNO" || id=="mapCtrl_imgbtnONO" || id=="mapCtrl_imgbtnNO")
       {
        document.getElementById("mapCtrl_imgbtnNNO").src = "./images/nav_2.gif";  
        document.getElementById("mapCtrl_imgbtnONO").src = "./images/nav_2.gif";       
        document.getElementById("mapCtrl_imgbtnNO").src = "./images/nav_2.gif";
       }
     }
    else
     {
       document.getElementById(id).src = "./images/nav_.gif";
       if (id=="mapCtrl_imgbtnNNW" | id=="mapCtrl_imgbtnWNW" || id=="mapCtrl_imgbtnNW")
       {
        document.getElementById("mapCtrl_imgbtnWNW").src = "./images/nav_ecken.gif";
        document.getElementById("mapCtrl_imgbtnNNW").src = "./images/nav_ecken.gif";
        document.getElementById("mapCtrl_imgbtnNW").src = "./images/nav_ecken.gif";
       }
       else if (id=="mapCtrl_imgbtnSSW" || id=="mapCtrl_imgbtnWSW" || id=="mapCtrl_imgbtnSW")
       {
        document.getElementById("mapCtrl_imgbtnSSW").src = "./images/nav_ecken.gif";  
        document.getElementById("mapCtrl_imgbtnWSW").src = "./images/nav_ecken.gif"; 
        document.getElementById("mapCtrl_imgbtnSW").src = "./images/nav_ecken.gif";      
       }
       else if (id=="mapCtrl_imgbtnSSO" || id=="mapCtrl_imgbtnOSO" || id=="mapCtrl_imgbtnSO")
       {
        document.getElementById("mapCtrl_imgbtnSSO").src = "./images/nav_ecken.gif";  
        document.getElementById("mapCtrl_imgbtnOSO").src = "./images/nav_ecken.gif";       
        document.getElementById("mapCtrl_imgbtnSO").src = "./images/nav_ecken.gif";
       }
       else if (id=="mapCtrl_imgbtnNNO" || id=="mapCtrl_imgbtnONO" || id=="mapCtrl_imgbtnNO")
       {
        document.getElementById("mapCtrl_imgbtnNNO").src = "./images/nav_ecken.gif";  
        document.getElementById("mapCtrl_imgbtnONO").src = "./images/nav_ecken.gif";  
        document.getElementById("mapCtrl_imgbtnNO").src = "./images/nav_ecken.gif";     
       }
     }
}

function f_open_window_max( aURL, aWinName )
{
  var wOpen;
  var sOptions;

  //sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
  sOptions = 'status=yes,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
  sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
  sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
  sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
  wOpen = window.open( aURL, aWinName, sOptions );
  //wOpen.location = aURL;
  wOpen.focus();
  wOpen.moveTo( 0, 0 );
  wOpen.resizeTo( screen.availWidth, screen.availHeight );
}

function VehicleZoom()
{ 
  var obj = document.getElementById("_vehicleList");

  if(obj.selectedIndex > -1 && obj != null)
    document.getElementById("btnZoom").click();    
}

function StationZoom()
{
  var obj = document.getElementById("_stationList");
  
  if(obj.selectedIndex > -1 && obj != null)
    document.getElementById("btnStationZoom").click();
}

function HideInfo()
{
  var obj = document.getElementById("divVehicleInfo");
  var obj2 = document.getElementById("iFrame");
 
  if(obj != null)
  {
    obj.style.visibility = "hidden"; 
    obj2.style.visibility = "hidden";
  }
}
function ShowInfo(element)
{
  var obj = document.getElementById(element);
  var x1 = findPosLeft(obj) + getElementWidth(element);
  var y1 = findPosTop(obj) + getElementWidth(element);
  var x2 = getElementWidth('divVehicleInfo');
  var y2 = getElementHeight('divVehicleInfo');
  document.getElementById('divVehicleInfo').style.left = (x1 - x2) + "px";
  document.getElementById('divVehicleInfo').style.top = y1 + "px";
  
  document.getElementById('iFrame').style.width = x2 + "px";
  document.getElementById('iFrame').style.height = y2 + "px";
  document.getElementById('iFrame').style.left = (x1 - x2) + "px";
  document.getElementById('iFrame').style.top = y1 + "px";

  if(!IsIE6())
    document.getElementById('iFrame').style.visibility = "hidden";
}
function IsIE6()
{
  // Gibt an ob es sich um den Internet Explorer 6 handelt
  var name = navigator.appName;
  var version = navigator.appVersion;
  if(name == "Microsoft Internet Explorer")
  {
    // 4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1)
    var elements = version.split("; ");
    if(elements[1] == "MSIE 6.0")
      return true;
  }
  return false;
}


function Drucke()
{
    document.getElementById("aDruck").style.visibility = "hidden";
    window.print();    
}

function OpenAuftrVerw()
{
    window.open('auftragsverwaltung.aspx','Auftragsverwaltung','height='+(screen.height-65)+',width='+(screen.width-10)+',resizable=yes,scrollbars=yes,top=0,left=0');
}

function DelEditInfoAuftrag(id,message)
{   
    if(id=='allDelete')
    {  
        var ok = ConfirmBox(message);
        if(ok)
        {
            document.getElementById('hiddenAuftragID').value = "allDelete,";

            //alle angehakten Checkboxen durchgehen
            for (var i = 0; i < document.forms[0].length; ++i) 
            {            
                if(document.forms[0].elements[i].type == "checkbox")
                {                
                    if(document.forms[0].elements[i].checked)
                    {      
                        document.getElementById('hiddenAuftragID').value += "c" + document.forms[0].elements[i].id.replace("delGroup","") + ",";
                    }        
                }            
            }
        }
        else
            document.getElementById('hiddenAuftragID').value = "abbr";
            
        return;
    }

    if(message!="")
    {
        var ok = ConfirmBox(message);
        if(ok)
            document.getElementById('hiddenAuftragID').value = id;
        else
            document.getElementById('hiddenAuftragID').value = "abbr";           
    }
    else
        document.getElementById('hiddenAuftragID').value = id;
}

function DeleteFromList(id)
{
    document.getElementById('ctl00_ContentPlaceHolder1_hiddenListValueID').value = id;
}

function ConfirmBox(message)
{
    if(confirm(message))
        return true;
    else return false;
}

function CountLetters()
{
    var iMaxLength = 300;
    var tmp = document.getElementById('tbMessage').value;
    var noch = 300;

    if (tmp.length > iMaxLength)
        document.getElementById('tbMessage').value = tmp.substring(0, iMaxLength);
        
    noch = noch - tmp.length;

    if(noch < 0)
        noch = 0;
            
    document.getElementById('lbCount').innerHTML = "Noch " + noch + " Zeichen zul&auml;ssig.";
}
function CountLettersOnLoad()
{
    var noch = document.getElementById('tbMessage').value.length;
    noch = 300 - noch;
        
    document.getElementById('lbCount').innerHTML = "Noch " + noch + " Zeichen zul&auml;ssig.";
}
function SelectAll(select, obj)
{
    if(select)
    {
        for (var i = 0; i < document.forms[0].length; ++i) 
        {
            if(document.forms[0].elements[i].type == "checkbox")
            {
                document.forms[0].elements[i].checked = true;
            }
        }

        document.getElementById(obj).innerHTML = "Markierung aufheben";
        document.getElementById(obj).onclick = new Function("SelectAll(false, 'aSelect')");
    }
    else
    {
        for (var i = 0; i < document.forms[0].length; ++i) 
        {
            if(document.forms[0].elements[i].type == "checkbox")
            {
                document.forms[0].elements[i].checked = false;
            }
        }

        document.getElementById(obj).innerHTML = "Alle markieren";
        document.getElementById(obj).onclick = new Function("SelectAll(true, 'aSelect')");        
    }
}

var centeredWindow = null;
function OpenWindowCentered(url, title, offset_left_right, height)
{
    var winWidth = screen.width - offset_left_right;
    var left = (screen.width - winWidth) / 2;
    
    if(centeredWindow == null || centeredWindow.closed)
        centeredWindow = window.open(url, title, 'scrollbars=yes, resizable=yes, height=' + height + ', width=' + winWidth + ', left=' + left + ', top=200');
    else
        centeredWindow.focus();
}
function CloseWindowCentered()
{
    if(centeredWindow != null && !centeredWindow.closed)
        centeredWindow.close();
    centeredWindow = null;
}
function ShowInteressentWindow()
{
    var winWidth = screen.width - 300;
    var left = (screen.width - winWidth) / 2;
    document.getElementById('divInteressent').style.left = left + "px";
    document.getElementById('divInteressent').style.width = winWidth + "px";
}

var chatWnd;
function ShowChatWindow()
{
    var scrWidth = screen.width;
    var winWidth = 815;
    var left = (scrWidth - winWidth) / 2;
    if(typeof chatWnd == 'undefined' || chatWnd.closed)    
        chatWnd = window.open('webchat.aspx','Chat', 'scrollbars=no, resizable=no, height=310, width='+winWidth+', left='+left+', top=200');
    else
        chatWnd.focus();        
}
function CloseChatWindowOnLogout()
{
    if(typeof chatWnd != 'undefined')
    {
        if(!chatWnd.closed)
        {
            chatWnd.close();
        }
    }
    window.setTimeout("GoToLoginPage()", 500);
}
function GoToLoginPage()
{
    window.location.href = "http://www.cibtrack.de/menue/content/memberlogin.aspx";
}
function RefreshCountUser()
{
    new Ajax.Request('ajaxClient.aspx',
    {
        method: 'post',
        parameters: {action: 'ChatterCount'},
        onSuccess: UpdateChatUser
    });  
}
function UpdateChatUser(anzahl)
{
    $('lbAnzChatter').innerHTML = anzahl.responseText.split('|')[0];
    $('lbAnzChatterGlobal').innerHTML = anzahl.responseText.split('|')[1];
}

function GeocodeAllTBS()
{
    new Ajax.Request('ajaxClient.aspx',
    {
        method: 'post',
        parameters: {action: 'GeocodeTBS'},
        onLoading: function() {
            $('lbNotice').innerHTML = "<img src=\"images/ajaxloader.gif\" />&nbsp;&nbsp;<span>Bitte warten.<br />Geokodiere Tagesbaustellen...</span>";
        },
        onSuccess: function() {
            $('lbNotice').innerHTML = "Geokodierung erfolgreich beendet!<br />Sie k&ouml;nnen das Fenster nun schliessen.";
            window.close();
        }
    });
}

function MapOneVehicle()
{            
    var list_mapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped');
    var list_unmapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped');

    if(list_unmapped.selectedIndex == -1)
        return;
    
    var newEntry = new Option(list_unmapped.options[list_unmapped.selectedIndex].text, list_unmapped.options[list_unmapped.selectedIndex].value);
    var index = list_mapped.length;
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped').options[index] = newEntry;
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped').options[list_unmapped.selectedIndex] = null;
    
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped').options[0].selected = "true";
}
function UnMapOneVehicle()
{            
    var list_mapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped');
    var list_unmapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped');

    if(list_mapped.selectedIndex == -1)
        return;
    
    var newEntry = new Option(list_mapped.options[list_mapped.selectedIndex].text, list_mapped.options[list_mapped.selectedIndex].value);
    var index = list_unmapped.length;
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped').options[index] = newEntry;
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped').options[list_mapped.selectedIndex] = null;
    
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped').options[0].selected = "true";
}    
function MapAllVehicles()
{
    var list_mapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped');
    var list_unmapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped');
    
    if(list_unmapped.length < 1)
        return;
    
    var length = list_unmapped.length;
    var mappedLength = list_mapped.length;

    for(i = 0; i < length; i++)
    {
        var newEntry = new Option(list_unmapped.options[0].text, list_unmapped.options[0].value);
        var index = list_mapped.length;
        document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped').options[mappedLength] = newEntry;
        document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped').options[0] = null;
        mappedLength++;
    }
    
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped').options[0].selected = "true";
}
function UnMapAllVehicles()
{
    var list_mapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped');
    var list_unmapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped');
    
    if(list_mapped.length < 1)
        return;
    
    var length = list_mapped.length;
    var unmappedLength = list_unmapped.length;

    for(i = 0; i < length; i++)
    {
        var newEntry = new Option(list_mapped.options[0].text, list_mapped.options[0].value);
        var index = list_unmapped.length;
        document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped').options[unmappedLength] = newEntry;
        document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped').options[0] = null;
        unmappedLength++;
    }
    
    document.getElementById('ctl00_ContentPlaceHolder1_vehiclesUnmapped').options[0].selected = "true";
}   
function WriteVehicleIDs()
{   
    var list_mapped = document.getElementById('ctl00_ContentPlaceHolder1_vehiclesMapped');
        
    for(i = 0; i < list_mapped.length; i++)
    {
        document.getElementById('ctl00_ContentPlaceHolder1_hdMapped').value += list_mapped.options[i].value + "<";
    }     
}
function findPosLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;		
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
		}
	}
	return curleft;
}
function findPosTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {		
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop;
		}
	}
	return curtop;
}
function getElementWidth(Elem) {
	
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}

		var xPos = elem.offsetWidth;
		
		return xPos;
}
function getElementHeight(Elem) {
	
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}

		var yPos = elem.offsetHeight;
		
		return yPos;
}
function ChangeMapVollbildSize()
{
    var mapWidth = document.getElementById('tbMapVB_Breite').value;
    var mapHeight = document.getElementById('tbMapVB_Hoehe').value;

    new Ajax.Request('ajaxClient.aspx',
    {
        method: 'post',
        parameters: {action: 'ChangeMapVollbildMapSize', breite: mapWidth, hoehe: mapHeight},
        onSuccess: function(resp) {
            if(resp.responseText != "error")
            {
                document.getElementById('gMap').style.width = mapWidth + "px";
                document.getElementById('gMap').style.height = mapHeight + "px";
                map.checkResize();
            }
        }
    });  
}


var autoAktualisieren;

function startUp(doCountUser)
{
  if(doCountUser)
    window.setInterval(RefreshCountUser, 3000);

  if(document.getElementById('_vehicleList').selectedIndex != -1)
  {
   count = 1;   
   merkerIndex = document.getElementById('_vehicleList').selectedIndex;
  }
  
  if(document.getElementById('_stationList').selectedIndex != -1)
  {
   count2 = 1;
   merkerIndex2 = document.getElementById('_stationList').selectedIndex;  
  }

  if(document.form1.btnAutoReload.value > 0)
  {
    autoAktualisieren = document.form1.btnAutoReload.value;
    InitializeTimer(autoAktualisieren);
  }  
}

//#################################################
//#################################################
//--------------- AutoPostBack Timer --------------
//#################################################
//#################################################

var secs
var timerID = null
var timerRunning = false
var delay = 1000
function InitializeTimer(seconds)
{
    // Set the length of the timer,
    // in seconds. Your choise
    secs = seconds;

    StopTheClock();
    StartTheTimer();
}
function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();

        // Form1.Post1 is a HTML an input button
        // on your Design form. See below.
        document.form1.btnAutoReload.click();
        //Generate a Postback to the server
        InitializeTimer(autoAktualisieren);
        // Start the timer again
    }
    else
    {        
        if(secs < 10)
            document.getElementById("reloadSek").innerHTML = "0" + secs;
        else
            document.getElementById("reloadSek").innerHTML = secs;
        
        secs = secs - 1;                
        timerRunning = true;        
        timerID = self.setTimeout("StartTheTimer()", delay);
    }        
}


//#################################################
//#################################################
//---------------- Deselect Listbox ---------------
//#################################################
//#################################################

var count = 0;
var newIndex;
var merkerIndex;

function deselectStationBox(id)
{
 count++;
 
 if(count == 1)
 {
  merkerIndex = document.getElementById(id).selectedIndex;  
  return;
 }

 newIndex = document.getElementById(id).selectedIndex;

 if(merkerIndex == newIndex)
 {
  document.getElementById(id).selectedIndex = -1;
  count = 0;
 }
 else
   merkerIndex = document.getElementById(id).selectedIndex;
}


function ShowStatusDetailsInFahrtenbuch(id)
{
    if(document.getElementById(id).style.display == 'none')
        document.getElementById(id).style.display = 'block';
    else
        document.getElementById(id).style.display = 'none';
        
        return false;
}

/*
    Funktionen zum dynamischen Editieren von Zellen einer Tabelle
    -- zum Editieren eines Auftrages in der Auftragsliste (auftraginfo.aspx)
*/
var cellOpen = false;
function editCell (cell, auftragID, columnDB) 
{
    if(!cellOpen)
    {
        $('lbNotice').innerHTML = "";
    
        if (document.all) 
        {
            // IE
            cell.innerHTML = "<input type=\"text\" id=\"editCell\" value=\"" + cell.innerText + "\" style=\"width:110px;\" onkeydown=\"setCell(event, this.parentElement, this.value, "+auftragID+", '"+columnDB+"');\" onclick=\"event.cancelBubble = true;\" />";
            document.all.editCell.focus();
            document.all.editCell.select();
            cellOpen = true;
        }
        else if (document.getElementById) 
        {
            // Firefox
            cell.normalize();
            var input = document.createElement("input");
            input.setAttribute("type", "text");
            input.setAttribute("value", cell.firstChild.nodeValue);
            input.setAttribute("style", "110px");
            input.onkeydown = function (evt) { setCell(evt, this.parentNode, this.value, auftragID, columnDB); };
            input.onclick = function (evt) { 
                evt.cancelBubble = true;
                if (evt.stopPropagation)
                    evt.stopPropagation();
            };
            cell.replaceChild(input, cell.firstChild);
            input.focus();
            input.select();
            cellOpen = true;
        }
    }    
}
function setCell (ereignis, cell, value, auftragID, columnDB) 
{
  if(GetClickedKey(ereignis) == "13")
  {
    // Wenn Enter gedrückt wurde...  
    if (document.all)
      cell.innerText = value;
    else if (document.getElementById)
      cell.replaceChild(document.createTextNode(value), cell.firstChild);
    
    // Änderung per AJAX speichern
    new Ajax.Request('../ajaxClient.aspx',
    {
        method: 'post',
        parameters: {action: 'EditAuftrag', auftragID: auftragID, key: columnDB, value: value},
        onSuccess: function(msg) {            
            if(msg.responseText == "ERROR")
            {
                cell.style.backgroundColor = "#FF0000";
                $('lbNotice').style.color = "#FF0000";
                $('lbNotice').innerHTML = "Fehler beim Editieren!";
            }
            else
            {
                cell.style.backgroundColor = "#FFFFE3";
                $('lbNotice').style.color = "#008000";
                $('lbNotice').innerHTML = "Auftrag erfolgreich editiert!";
            }
        }
    });
      
    cellOpen = false;
  }
}
function GetClickedKey(Ereignis)
{
    if (!Ereignis)
        Ereignis = window.event;
        
    if (Ereignis.which) 
        Tastencode = Ereignis.which;
    else if (Ereignis.keyCode) 
        Tastencode = Ereignis.keyCode;
       
    return Tastencode;
}