var fetchedIds = [];
var uAgent=navigator.userAgent,isIE=false,isIE5=false,ieVersion=0,isFirefox=false,i=uAgent.indexOf('MSIE'),isOpera=uAgent.indexOf('Opera')>-1;
if(i>0&&!isOpera){
  isIE=true;
  ieVersion=parseFloat(uAgent.substr(i+5));
  isIE5=(ieVersion<5.5);
  if(ieVersion>=7.0)alphaPNG=true;
}
else {
  isFirefox=(uAgent.indexOf('Firefox')>0?true:false);
  alphaPNG=true;
};

function menu_MOvr(id){
    o = document.getElementById(id);
    with(o.style){
        backgroundImage = 'url(./images/top_menu_ho.png)';   
        //color = '#FFFFFF';
    }
    
    for(var i in o.childNodes){
     if(o.childNodes[i].tagName&&o.childNodes[i].tagName=="NOBR"){
      for(var j in o.childNodes[i].childNodes){
         if(o.childNodes[i].childNodes[j].tagName&&o.childNodes[i].childNodes[j].tagName=="A"){
          o.childNodes[i].childNodes[j].firstChild.style.color = "#FFFFFF";
          return;
         }
      }
     }
    }
}

function menu_MOut(id){
    o = document.getElementById(id);
    with(o.style){
        backgroundImage = 'url(./images/top_menu_bg.png)';   
        color = '#000000';
    }
    for(var i in o.childNodes){
     if(o.childNodes[i].tagName&&o.childNodes[i].tagName=="NOBR"){
      for(var j in o.childNodes[i].childNodes){
         if(o.childNodes[i].childNodes[j].tagName&&o.childNodes[i].childNodes[j].tagName=="A"){
          o.childNodes[i].childNodes[j].firstChild.style.color = "#000000";
          return;
         }
      }
     }
    }
}

function initShorten(){
}

var boxContentBrain = new Array();
var boxStateBrain   = new Array();
var boxInterval = null;

function modifyBoxContent(objId){
    var obj = document.getElementById("elem_"+objId);
    obj = obj.rows[1];
    obj = obj.cells[1];
    if(obj.firstChild&&obj.firstChild.firstChild){
        if(obj.firstChild.firstChild.style&&obj.firstChild.firstChild.style.visibility == "hidden") var check = true;
        obj.firstChild.removeChild(obj.firstChild.firstChild);
        if(check) modifyBoxContent(objId);
    } else if(obj.firstChild){
        if(obj.firstChild.style&&obj.firstChild.style.visibility == "hidden") var check = true;
        obj.removeChild(obj.firstChild);
        if(check) modifyBoxContent(objId);
    } else {
        window.clearInterval(boxInterval);  
        boxInterval = null;    
    }
}

var submitContentBrain = new Array();
var submitStateBrain   = new Array();

function shortensubmit(tableid,triggerid){
    var table = document.getElementById(tableid);
    var trigger = document.getElementById(triggerid);
    if(table){
        if(!submitStateBrain[triggerid]){
            submitContentBrain[triggerid] = table.innerHTML;
            
            var datum = table.rows[1].cells[1].innerHTML.substring(0,19);
            var quelle = table.rows[3].cells[1].innerHTML;
            var ueberschrift = table.rows[4].cells[1].innerHTML;
            var dings = table.rows[5].cells[0].innerHTML;
            
            if(quelle.length>30) quelle = quelle.substring(0,30)+"...";
            if(ueberschrift.length>100) ueberschrift = ueberschrift.substring(0,100)+"...";
            
            table.deleteRow(0);
            table.deleteRow(1);
            table.deleteRow(1);
            table.deleteRow(1);
            table.deleteRow(1);
            table.deleteRow(1);
            
            table.rows[0].innerHTML = "";
            var newCont = "<span id='"+triggerid+"' style=\"cursor:pointer;\" onclick=\"shortensubmit('"+tableid+"','"+triggerid+"');\"><img style=\"position:relative; top:1px; width:12; height:12;\" src=\"./images/expand.png\"></span>&nbsp;";
                                                                                                                                        
            table.rows[0].insertCell(0).innerHTML = newCont;
            table.rows[0].cells[0].style.cssText = "text-align:right;";
            table.rows[0].insertCell(0).innerHTML = dings;
            table.rows[0].insertCell(0).innerHTML = ueberschrift;
            table.rows[0].insertCell(0).innerHTML = quelle;
            table.rows[0].insertCell(0).innerHTML = datum;
            table.rows[0].setAttribute("align","left");
            table.setAttribute("width","100%");
            //table.rows[0].cells[0].setAttribute("width","160");
            //table.rows[0].cells[1].setAttribute("width","250");
            //table.rows[0].cells[3].setAttribute("width","120");
            //table.rows[0].cells[4].setAttribute("width","10");
            
            submitStateBrain[triggerid] = true;
        } else {                                                       
          table.innerHTML = submitContentBrain[triggerid];
          if(trigger) trigger.innerHTML = "<img style=\"position:relative; top:1px; width:12; height:12;\" src=\"./images/shorten.png\">";
          submitStateBrain[triggerid] = false;
        }
    }
}

function shrink(objId,contId){
    var obj = document.getElementById("elem_"+objId);
    var cont = document.getElementById(contId);
    if(!boxStateBrain[objId]){
        if(!isIE) boxContentBrain[objId] = obj.innerHTML;
        else      boxContentBrain[objId] = obj.outerHTML;
        
        while(obj.rows.length>2) obj.deleteRow(1);
        
        boxStateBrain[objId] = true;
        if(cont) cont.innerHTML = "<img style=\"position:relative; top:1px; width:12; height:12;\" src=\"./images/expand.png\">";
    } else {
      if(!isIE) obj.innerHTML = boxContentBrain[objId];
      else      obj.outerHTML = boxContentBrain[objId];
      
      if(cont) cont.innerHTML = "<img style=\"position:relative; top:1px; width:12; height:12;\" src=\"./images/shorten.png\">";
      boxStateBrain[objId] = false;
    }    
}  

function updateTimer(){
    var timer = document.getElementById("timer");
    if(timer){
        if(!timer.objDate){
            timer.objDate = new Date(0);
            var seconds = parseInt(timer.innerHTML);
            timer.objDate.setSeconds(seconds);
        }
        
        var month = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni","Juli", "August", "September", "Oktober", "November", "Dezember");
        var week = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch","Donnerstag", "Freitag", "Samstag");
        
        var d = timer.objDate;
        d.setSeconds(d.getSeconds()+1);
        var minutes = ""+d.getMinutes()+"";
        var hours = ""+d.getHours()+"";
        var seconds = ""+d.getSeconds()+"";
        if(minutes.length==1) minutes = "0"+minutes;
        if(hours.length==1)   hours = "0"+hours;
        if(seconds.length==1) seconds = "0"+seconds;
        
        timer.innerHTML = week[d.getDay()]+" &bull; "+d.getDate()+". "+month[d.getMonth()]+" "+d.getFullYear()+" &bull; "+hours+":"+minutes+":"+seconds+" Uhr";
        timer.style.cssText = "font-family: Tahoma,Nimbus sans,sans-serif,Verdana; color:#000000; font-size:12px; position:relative; left:10px; top:-1px;";
    }
}

function resetInps(dontMail){
  if(!dontMail) document.getElementById("report_email").value = "";
  document.getElementById("report_url").value = "";
  document.getElementById("report_sourcename").value = "";
  document.getElementById("report_headline").value = "";
  document.getElementById("report_shorttext").value = "";
}

var inputField = null;
var cntCharsLeft = null;
function CheckTextLength()
{
if(!inputField)   inputField = document.getElementById('report_shorttext');
if(!inputField)   inputField = document.getElementById('video_desc');
if(!cntCharsLeft) cntCharsLeft = document.getElementById('charsLeft');
  if(inputField){
    var maxLength=500, textinhalt=inputField.value;
        if(cntCharsLeft){
           var charsLeft = maxLength-textinhalt.length;
           cntCharsLeft.innerHTML = "("+charsLeft+" Zeichen &uuml;brig)";
        }
  }
}

function inputFocus(id){
  if(!fetchedIds[id]) fetchedIds[id] = document.getElementById(id);
    if(fetchedIds[id]){
       var obj = fetchedIds[id];
       if(obj.value=="Suche:") obj.value = "";
       /*with(obj.style){
         border  = "1px solid black";
       } */
    } else alert('unable to fetch id '+id)
}

function inputBlur(id){
  if(!fetchedIds[id]) fetchedIds[id] = document.getElementById(id);
    if(fetchedIds[id]){
       var obj = fetchedIds[id];
       /*with(obj.style){
         border  = "0px solid black";
       } */
    } else alert('unable to fetch id '+id)    
}
function inputMOV(id){
  if(!fetchedIds[id]) fetchedIds[id] = document.getElementById(id);
    if(fetchedIds[id]){
       var obj = fetchedIds[id];
       /*with(obj.style){
         backgroundColor  = "#efefef";
       }*/
    } else alert('unable to fetch id '+id)
}

function inputMOT(id){
  if(!fetchedIds[id]) fetchedIds[id] = document.getElementById(id);
    if(fetchedIds[id]){
       var obj = fetchedIds[id];
       /*with(obj.style){
         backgroundColor  = "#FFFFFF";
       } */
    } else alert('unable to fetch id '+id)    
}

function redirectUser(sessid){
    document.location.href="./index.php?XESS="+sessid+"&page=acp";
}

var currentNews = {
                   entry0:{txt:'Zur Zeit keine News',link:'http://net-news-express.de'}
                  };
                  
function setDynHeadline(obj,innerHTMLforChild){
  if(obj){
     for(var i in obj.childNodes){
       if(obj.childNodes[i].id=="dyn_headline") obj.childNodes[i].innerHTML = innerHTMLforChild;
     }
  }
}

function getAppWidth(){
  if (typeof window.innerWidth != 'undefined') {
       return window.innerWidth;
  } else if (typeof document.documentElement != 'undefined'
          && typeof document.documentElement.clientWidth != 'undefined'
          && document.documentElement.clientWidth != 0)
  {
        return document.documentElement.clientWidth;
  } else {
        return document.getElementsByTagName('body')[0].clientWidth;
  }
}

function getAppHeight(){
       if (typeof window.innerHeight != 'undefined') {
            return window.innerHeight
       } else if (typeof document.documentElement != 'undefined'
               && typeof document.documentElement.clientHeight != 'undefined'
               && document.documentElement.clientHeight != 0)
       {
             return document.documentElement.clientHeight
       } else {
             return document.getElementsByTagName('body')[0].clientHeight
       }
}

function checkFinishedSearch(ev){
  /*ev = ev||window.event;
  var obj = document.getElementById("newsgrepsearchq");
  if(ev.keyCode==13&&obj){
   var squery = obj.value;
   var linkToCall = "http://news-grep.de/index.php/news/search?str_search="+escape(squery)+"&page=1";
   window.open(linkToCall, "_blank", "resizable=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,toolbar=1,width=1000,height=800");
  }*/
}

function nne_open_extern(link){
  window.open(link, "_blank", "resizable=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,toolbar=1,width=1000,height=800");
}

                  
var newstickerdiv = null;  
function initNewsticker(){
      newstickerdiv = document.getElementById('newsticker');  
      newstickerdiv.style.overflow = 'hidden';
      if(isIE) newstickerdiv.style.width = getAppWidth();
      newstickerdiv.xPos = getAppWidth();
      newstickerdiv.moveSpeed = 12;
      newstickerdiv.direction = true;
      newstickerdiv.isInvestigated = false;
      
      var leftcorner = document.createElement('span');
      leftcorner.style.cssText = "position:absolute; left:0px;top:0px; width:104px;z-index:3; height:27px; background-image:url(./images/nt_leftcorner2.png);";
      newstickerdiv.appendChild(leftcorner);

      var rightcorner = document.createElement('span');
      rightcorner.id = "newsticker_rightcorner";
      rightcorner.style.cssText = "position:absolute; top:0px; right:0px; width:104px;z-index:3; height:27px; background-image:url(./images/nt_rightcorner.png);";
      if(isIE) rightcorner.style.cssText = "position:absolute; top:0px; left:"+(getAppWidth()-104)+"px; width:104px;z-index:3; height:27px; background-image:url(./images/nt_rightcorner.png);";
      newstickerdiv.appendChild(rightcorner);

      
      var msgLength = 0;
      var noBreak = document.createElement('nobr');
      var floatDiv = document.createElement('div');
      floatDiv.style.position = 'absolute';
      floatDiv.style.top = '3px';
      floatDiv.setAttribute("id","floatDiv");
      
      var myMessage = '';
      var span = null;
      for(var i in currentNews){
          span = document.createElement('span');
          span.innerHTML = currentNews[i].txt;
          span.style.cursor = 'pointer';
          span.link = currentNews[i].link;

          msgLength += span.innerHTML.length;
          floatDiv.appendChild(span);
          
          span.onmouseover = function(){
            newstickerdiv.isInvestigated = true;
            this.style.cssText = 'text-decoration:underline; cursor:pointer;';
          }
          
          span.onmouseout = function(){
            newstickerdiv.isInvestigated = false;
            this.style.cssText = 'text-decoration:none; cursor:pointer;';
          }
          
          span.onclick = function(){
              window.open(this.link, "popup", "resizable=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,toolbar=1,width=1000,height=800");
          }
          
          cutspan = document.createElement('span');
          cutspan.innerHTML = ' +++ ';
          cutspan.style.cursor = 'pointer';
          
          cutspan.onmousedown = function(ev){
              document.body.onmousemove = function(ev){
                // clear timer
                newstickerdiv.isInvestigated = false;
                newstickerdiv.isOnDrag = false;                  
                clearInterval(newstimer);
                newstimer = null;
                
                ev = ev||window.event;
                if(!newstickerdiv.firstX){
                    newstickerdiv.firstX = ev.clientX;
                    newstickerdiv.firstLeft = parseInt(newstickerdiv.fDiv.style.left);
                }
                  
                var newPos = newstickerdiv.firstLeft-((newstickerdiv.firstX-ev.clientX));
                newstickerdiv.fDiv.style.left = newPos+'px';
                newstickerdiv.xPos = newPos;
                if(ev.preventdefault) ev.preventDefault();
                document.onselectstart = function (ev) {
                    ev = ev||window.event;
                    if(ev.preventdefault) ev.preventDefault();
                    return false;  
                };
                document.ondragstart = function (ev) {
                    ev = ev||window.event;
                    if(ev.preventdefault) ev.preventDefault();
                    return false;  
                };
                
              };
              
              document.body.onmouseup = function(){
                  newstickerdiv.isInvestigated = false;
                  newstickerdiv.isOnDrag = false;
                  document.onselectstart = null;
                  document.ondragstart = null;
                  document.body.onmousemove = null;
                  newstickerdiv.firstX = null;
                  if(!newstimer) newstimer = window.setInterval("animateNewsticker();",200);
              };
              newstickerdiv.isInvestigated = true;
              newstickerdiv.isOnDrag = true;
          }
          
          cutspan.onmouseup = function(event){
              newstickerdiv.isInvestigated = false;
              newstickerdiv.isOnDrag = false;
              document.body.onmousemove = null;
              document.body.onmouseup = null;
              document.onselectstart = null;
              document.ondragstart = null;
              newstickerdiv.firstX = null;
              if(!newstimer) newstimer = window.setInterval("animateNewsticker();",200);
          }
          
          floatDiv.appendChild(cutspan);
      }
      
      msgLength = msgLength*9;
      newstickerdiv.msgLength = msgLength;
      
      noBreak.appendChild(floatDiv);
      newsticker.fDiv = floatDiv;
      newstickerdiv.appendChild(noBreak);    
}

function animateNewsticker(){
    if(!newstickerdiv) initNewsticker();
    if(!newstickerdiv.isInvestigated){
      var floatDiv = document.getElementById("floatDiv");
      var news_rightc = document.getElementById("newsticker_rightcorner");
      if(floatDiv){
          if(news_rightc&&isIE){
           if(getAppWidth()-104!=parseInt(news_rightc.style.left)){
             news_rightc.style.left = getAppWidth()-104;
             floatDiv.style.width  = getAppWidth();
             newstickerdiv.style.width = getAppWidth();
           }
          }
          floatDiv.style.left = newstickerdiv.xPos - newstickerdiv.moveSpeed;
          //if(newstickerdiv.direction) floatDiv.style.left = newstickerdiv.xPos - newstickerdiv.moveSpeed;
          //else                        floatDiv.style.left = newstickerdiv.xPos + newstickerdiv.moveSpeed;
          
          
          newstickerdiv.xPos = parseInt(floatDiv.style.left);
          if(newstickerdiv.xPos+newstickerdiv.msgLength<0) newstickerdiv.xPos = getAppWidth();
          //if(newstickerdiv.xPos+newstickerdiv.msgLength<0) newstickerdiv.direction = false;
          //if(newstickerdiv.xPos>0)                         newstickerdiv.direction = true;
      }
    }
}

function nne_closeToolTip() {
   if(document.getElementById('tooltip')){
      with(document.getElementById('tooltip').style){
                    visibility = "hidden";
                    position = "absolute";
                    top = "0px";
                    left = "0px";
      }
   }
}

function nne_showToolTip(ev,txt){
    var body = document.getElementsByTagName("body")[0];
        if(!document.getElementById('tooltip')){
          var div = document.createElement("div");
          div.id = "tooltip";
          var textdiv = document.createElement("div");
          textdiv.id = "tooltip_text";
          div.appendChild(textdiv);
          div.style.cssText = "position:absolute; background-color:#FFFFFF; border:2px solid black;-moz-border-radius:10px;-khtml-border-radius:10px;visibility:hidden;";
          body.appendChild(div);
        }
        if(document.getElementById('tooltip')){
           document.getElementById("tooltip_text").innerHTML="&nbsp;"+unescape(txt)+"&nbsp;";
           var o = document.getElementById('tooltip');
           o.onclick = function(){
              with(this.style){
                     visibility = "hidden";
                     position = "absolute";
                     top = "0px";
                     left = "0px";
              }
           }
           with(o.style){
               left = (ev.clientX+26)+"px";
               top  = (ev.clientY+body.scrollTop+1)+"px";
               visibility = "visible";
           };
        }
}

function toggleCheckbox(){
  var h = document.getElementsByTagName("input");
  for(var i in h){
   if(h[i].type=="checkbox") h[i].click();
  }
}

  var newstimer = window.setInterval('animateNewsticker();',200);
  var timer = window.setInterval('updateTimer();',1000);

