        // webcam5.2.js - $Id: webcam6.0.js,v 1.3 2005/04/01 13:20:08 henrik Exp $

        //        Production Script
        var isIE = (navigator.userAgent.indexOf( "MSIE" ) > 0 ) ? true : false;
        var imageSrc,
	     imageSrc2,
	     imageSrc3,
                previousImage,
                updatePeriod,
                now,
                nextDue,
                timerPeriod,
                remoteWin,
                timerID = null;
        var imageLoaded = false;
        var imgbuffer = new Image();
        var imgbuffer2 = new Image();
	var imgbuffer3 = new Image();
        var downloadStart = new Date().getTime();
        var lastSuccess = downloadStart;
        var isOwner = true;
        var clientVersion = '6.0';

        function getClientVersion() {
                return clientVersion;
        }

        function setIsOwner( ownerStatus ) {
                isOwner = ownerStatus;
        }

        function getIsOwner() {
                return isOwner;
        }

        function onBeforeLoad() {
                if(!getIsOwner()) {
                        if( !isRemoteWin() && getIntop() ) {
                                getIntop().displayWebCamStatus();
                        }
                }
        }

        function getIntop() {
                return top.frames[0];
        }

        function camInit(period) {
                onBeforeLoad();
                updatePeriod = period*1000;
                downloadStart = new Date().getTime();
                lastsuccess = downloadStart;
                imageSrc = document.refrimage.src;
	        imageSrc2 = document.refrimage2.src;	
		imageSrc3 = document.refrimage3.src;
                if( imageSrc.indexOf( "?" ) > 0 ) {
                        imageSrc = imageSrc.substr( 0, imageSrc.indexOf( "?" ) );
                }
                if( imageSrc2.indexOf( "?" ) > 0 ) {
                        imageSrc2 = imageSrc2.substr( 0, imageSrc2.indexOf( "?" ) );
                }
		if( imageSrc3.indexOf( "?" ) > 0 ) {
			imageSrc3 = imageSrc3.substr( 0, imageSrc3.indexOf( "?" ) );
		}

                imgbuffer.onload =  function () { imageLoad();  };
                imgbuffer.onerror = function () { imageError(); };
	        imgbuffer2.onload =  function () { imageLoad();  };
                imgbuffer2.onerror = function () { imageError(); };
		imgbuffer3.onload = function () { imageLoad();  };
		imgbuffer3.onerror = function () { imageError(); };
                startTimer();
                if( checkForClock() )
                        startClockUpdates();
        }

        function launchRemote(w,h,htmlfile) {
                var klugedWidth = w + 150;
                var klugedHeight = h + 150;
                remoteWin=window.open(htmlfile,"","resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,copyhistory=0,width=" + klugedWidth + ",height=" + klugedHeight + "");
                remoteWin.creator=self;
        }

        function startTimer() {
                if (timerID != null) {
                        window.clearTimeout(timerID);
                        timerID = null;
                }

                nextDue = lastSuccess + updatePeriod;
                now = new Date().getTime();
                timerPeriod = Math.max((nextDue-now),0);

                if (timerPeriod > 0) {
                        timerID = window.setTimeout("timerExpire()", timerPeriod);
                } else {
                        timerExpire();
                }
        }

        function timerExpire() {
                timerID = null;
                getImage();
        }

        function getImage() {
                imageLoaded = false;
                downloadStart = new Date().getTime();
                imgbuffer.src = imageSrc + "?" + downloadStart ;
	        imgbuffer2.src = imageSrc2 + "?" + downloadStart ;
		imgbuffer3.src = imageSrc3 + "?" + downloadStart ;
        }

        function imageLoad() {
                document.refrimage.src = imgbuffer.src;
	        document.refrimage2.src = imgbuffer2.src; 
		document.refrimage3.src = imgbuffer3.src;
                imageLoaded = true;
                lastSuccess = downloadStart;
                startTimer();
        }

        function imageError() {
                getImage();
        }

        function checkForClock(){
                if( this.document.clock.time ){
                        return true;
                }
                return false;
        }

        function startClockUpdates() {
                window.setInterval("updateClock()", 100);
        }

        function updateClock() {
                now = new Date().getTime();
                var timeLeft = Math.ceil((nextDue - now)/1000);
                var value = (timeLeft > 0) ? timeLeft : "-";
                if( document.clock.time ) {
                        if (value != document.clock.time.value) {        // update if changed
                                document.clock.time.value = value;
                        }
                }
        }

        function isRemoteWin() {
                var retval = false;
                if( getUrl() ) {
                        if( getUrl().toLowerCase().indexOf( 'remote' ) >= 0 ) {
                                retval = true;
                        }
                }
                return retval;
        }

        function getUrlStatus() {
                var retval = "";
                if( getUrl() != null ) {
                        if( getUrl().toLowerCase().indexOf( '_on' ) < 0 &&
                                getUrl().toLowerCase().indexOf( '_off' ) < 0 ) {
                                return retval;
                        } else {
                                retval = ( getUrl().toLowerCase().indexOf( '_on' ) < 0 )
                                ? 'off' : 'on';
                        }
                }
                return retval;
        }

        function getUrl() {
                return this.location.href;
        }

        function getBaseUrl() {
                var retval = null;
                if( getUrl() ) {
                        var lastSlash = getUrl().toLowerCase().lastIndexOf( '/' );
                        if( lastSlash < 0 ) {
                                lastSlash = getUrl().toLowerCase().lastIndexOf( '\\' );
                        }
                        var prefix = getUrl().toLowerCase().substr( 0, lastSlash + 1 );
                        retval = ( prefix!=null ) ? prefix : '/';
                }
                return retval;
        }

        function Cam_Start() {               
	  fenster = window.open("webcam.php?pagename=popup&num=1", 
	"WindCAM", "toolbar=0, location=0, directories=0, menubar=0,status=0,resizable");
	  fenster.moveTo(100,100);
	  fenster.resizeTo(680,530);
	  fenster.focus();
	  }

    function Cam2_Start() {               
	  fenster = window.open("webcam.php?pagename=popup&cam=webcam2_kiel&num=2", 
	"WindCAM", "toolbar=0, location=0, directories=0, menubar=0,status=0,resizable");
	  fenster.moveTo(100,100);
	  fenster.resizeTo(680,530);
	  fenster.focus();
	  }

     function Cam3_Start() {
               fenster = window.open("webcam.php?pagename=popup&cam=webcam3_kiel&num=3",
               "WindCAM", "toolbar=0, location=0, directories=0, menubar=0,status=0,resizable");
                 fenster.moveTo(100,100);
           fenster.resizeTo(980,770);
             fenster.focus();
      }

       function clearinput(form) {
            if (form.value == form.defaultValue) {
	             form.value = ""
	}
   }

function noenter(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	return KeyID != 13;
}


