﻿   var http_request = false;
  function showDetails(id){
    var e=document.getElementById(id);
    if(!e)return true;
    if(e.style.display=="none") {
      e.style.display="block"
    }
    else {
      e.style.display="none"
    }
    return true;
  }

   function makeRequest(url, parameters, divName, method) {
      base_url = "/include/";
   
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         //alert('Cannot create XMLHTTP instance');
         return false;
      }

      if (method == 'GET' || method == 'POST') {
        http_request.onreadystatechange = new Function('fx', 'updateDiv("'+divName+'")');      
      }
      else {
        http_request.onreadystatechange = notifySuccess;
      }

      if (method == 'GET' || method == 'OK') {
        http_request.open(method, base_url + url + parameters, true);
        http_request.send(null);
      }
      else if (method == 'POST') {
        http_request.open('POST', base_url + url, true);
        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http_request.setRequestHeader("Content-length", parameters.length);
        http_request.setRequestHeader("Connection", "close");

        http_request.send(parameters);
      }
   }

   function updateDiv(divName) {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById(divName).innerHTML = result;            
         } else {
            //alert('There was a problem with the request.\nStatus Code: ' + http_request.status);
         }
      }
   }
   
   function notifySuccess() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert('Request was sent');
         } else {
            //alert('There was a problem with the request.\nStatus Code: ' + http_request.status);
         }
      }
   }
   
   function getCalendar(year, month) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";

      makeRequest('cal.php', getstr, 'leftProgramCol', 'GET');
   }
   
   function getSchedule(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";
      
      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }
   
   function getVideoLengths(id) {
      var getstr = "?";
      getstr += "id=" + id + "&";

      makeRequest('action.videolengths.php', getstr, 'airbox-hdd-output', 'GET');
   }
   
   function getCurrentSchedule() {
      var getstr = "";
      
      makeRequest('current_schedule.php', getstr, 'current_schedule', 'GET');
   }
   
   function login(year, month, day) {
      var postStr = "user="      + encodeURI( document.getElementById("user").value ) +
                    "&pass="     + encodeURI( document.getElementById("pass").value ) +
                    "&remember=" + ((encodeURI( document.getElementById("remember").checked) ? '1':'0') ) +
                    "&sublogin=" + encodeURI( document.getElementById("sublogin").value ) +
                    
                    "&year=" + year +
                    "&month=" + month +
                    "&day=" + day +
                    
                    "&action=login&";

      makeRequest('schedule.php', postStr, 'rightProgramCol', 'POST');
   }
   
   function uploadPLY(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day +
                    
                "&action=uploadPLY&";

      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }
   
   function uploadPLYNotFixed(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day +
                    
                "&action=uploadPLY2&";

      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }
   
   function logout(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";
      
      getstr += "action=logout&";

      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }
   
   function addToSchedule(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";
      getstr += "startTime=" + document.getElementById('startTime').value + "&";
      getstr += "endTime=" + document.getElementById('endTime').value + "&";
      getstr += "title=" + document.getElementById('title').value.replace(/&/g, '%26').replace(/'/g, "\\'") + "&";
      getstr += "category=" + document.getElementById('category').value + "&";
      
      getstr += "action=addToSchedule&";

      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }

   function handleNewsletterForm(lang) {
      var poststr = "";
      poststr += "lang=" + lang + "&";
      poststr += "email=" + document.getElementById('nlform-email').value + "&";
      poststr += "action=" + document.getElementById('nlform-action').value + "&";
      
      makeRequest('newsletterform.php', poststr, 'newsletter_form', 'POST');
   }
   
   function addToTomorrow(cat, start, end, title, promptFlag) {
      var getstr = "?";
      getstr += "start=" + start + "&";
      getstr += "end=" + end + "&";

      if (promptFlag == null) {
        title = prompt("Titel der morgigen Sendung", title);
      }

      getstr += "title=" + title.replace(/&/g, '%26').replace(/'/g, "\\'") + "&";
      getstr += "category=" + cat + "&";
      
      getstr += "action=addToTomorrow&";

      if (title != null) {
        makeRequest('schedule.php', getstr, 'rightProgramCol', 'OK');
      }
   }
   
   function addGlobalTomorrow(arr) {
      for (var i = 0; i < arguments.length; i++) {
        cat   = arguments[i][0];
        start = arguments[i][1];
        end   = arguments[i][2];
        title = arguments[i][3];
        
        var getstr = "?";
        getstr += "start=" + start + "&";
        getstr += "end=" + end + "&";

        getstr += "title=" + title.replace(/&/g, '%26').replace(/'/g, "\\'") + "&";
        getstr += "category=" + cat + "&";
        
        getstr += "action=addToTomorrow&";

        if (title != null) {
          makeRequest('schedule.php', getstr, 'rightProgramCol', 'OK');
        }
      }
   }
  
   function chooseAlternative(id, alternativeTitle, year, month, day) {
      var getstr = "?";
      getstr += "altTitle=" + alternativeTitle.replace(/&/g, '%26').replace(/'/g, "\\'").replace(/\+/g, "\\+")  + "&";
      getstr += "altId=" + id + "&";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";

      getstr += "action=chooseAlternative&";

      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }


   function deleteFromSchedule(id, year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";
      getstr += "delId=" + id + "&";
      
      getstr += "action=delete&";

      makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
   }
   
   function deleteDayFromSchedule(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";
      
      getstr += "action=deleteDay&";

      if (confirm("Sind Sie sicher, dass Sie alle Einträge vom "+day+"."+month+"."+year+" löschen möchten?")) {
        makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
      }
   }
   
   function deleteMonthFromSchedule(year, month, day) {
      var getstr = "?";
      getstr += "year=" + year + "&";
      getstr += "month=" + month + "&";
      getstr += "day=" + day + "&";
      
      getstr += "action=deleteMonth&";

      if (confirm("Sind Sie sicher, dass Sie alle Einträge im Monat "+month+"."+year+" löschen möchten?")) {
        makeRequest('schedule.php', getstr, 'rightProgramCol', 'GET');
      }
   }

function openLink(url) {
  window.frames["if"].location.href = url;
  //parent.if.location.href = url;
}
	
function switchToLiveStream(flag) {
  var so = new SWFObject('player.swf','mpl','560','420','9');
  so.addParam('allowscriptaccess','always');
  so.addParam('allowfullscreen','true');
  
  if (flag == true) {
    so.addParam('flashvars','&backcolor=000033&frontcolor=9999FF&lightcolor=9999FF&file=gates&streamer=rtmp://fms.0x47.de/live&controlbar=over&autostart=true&displayclick=fullscreen&type=rtmp');
    str = "<a href='javascript:void(0);' onclick='javascript:switchToLiveStream(false);'>zurück zum Livestream von Light Channel TV</a>";
  }
  else {
    so.addParam('flashvars','&backcolor=000033&frontcolor=9999FF&lightcolor=9999FF&file=german&streamer=rtmp://fms.0x47.de/live&controlbar=over&autostart=true&displayclick=fullscreen&type=rtmp');
    str = "Fr. 10.07. 19:30 Uhr/Sa 11.07. 9:30 Uhr, 14:30 Uhr, 16:30 Uhr u. 18 Uhr - Erweckungswochenende in Stuttgart-Untertürkheim<br />\nFür Livestream bitte <a href='javascript:void(0)' onclick='javascript:switchToLiveStream(true);'>hier klicken</a>!";
  }
  so.write('player');
  
  document.getElementById('liveDiv').innerHTML = str;     
  return true;
}

  function writePlayer(playerUrl, streamer, streamName, divName, image) {
    var flashvars = '&backcolor=000033&frontcolor=9999FF&lightcolor=9999FF&file=' + streamName + '&streamer='
     + streamer + '&controlbar=over&autostart=true&displayclick=fullscreen&type=rtmp';
     
    if (image != '') {
      flashvars += '&image=' + image;
    }
  
    var so = new SWFObject(playerUrl,'mpl','560','420','9');
    so.addParam('allowscriptaccess','always');
    so.addParam('allowfullscreen','true');
    so.addParam('flashvars', flashvars);
    so.write(divName);
  }

  function writePlayer16by9(playerUrl, streamer, streamName, divName, image) {
    var flashvars = '&backcolor=000033&frontcolor=9999FF&lightcolor=9999FF&file=' + streamName + '&streamer='
     + streamer + '&controlbar=over&autostart=true&displayclick=fullscreen&type=rtmp&stretching=exactfit';

    if (image != '') {
      flashvars += '&image=' + image;
    }

    var so = new SWFObject(playerUrl,'mpl','560','315','9');
    so.addParam('allowscriptaccess','always');
    so.addParam('allowfullscreen','true');
    so.addParam('flashvars', flashvars);
    so.write(divName);
  }


