// Javascript from Moodle modules
/* $Id: javascript.php,v 1.2.2.1 2006/12/05 10:05:29 janne Exp $ */
/* ImageGallery object's constructor */
function ImageGallery () {
    this.ratio = 1.3333333333;
};
/* Change width value */
ImageGallery.prototype.change_dim_width = function (hvalue, fieldname) {
    if ( document.getElementById) {
        var elem = document.getElementById('menu' + fieldname);
        if ( elem ) {
            var newWidth = Math.round(hvalue * this.ratio);
            elem.value = newWidth;
        }
    }
};
/* Change height value */
ImageGallery.prototype.change_dim_height = function (vvalue, fieldname) {
    if ( document.getElementById ) {
        var elem = document.getElementById('menu' + fieldname);
        if ( elem ) {
            var newHeight = Math.round(vvalue / this.ratio);
            elem.value = newHeight;
        }
    }
};

ImageGallery.prototype._newWidth =  function (height) {
};

/**
 * Make HTTP GET request and get ImageGallery's categories if any.
 *
 */
ImageGallery.prototype._HTTPGET = function (cmid, sesskey, url, galleryid, cmd) {

    var req;
    var fullurl = url +'?id='+ cmid +'&sesskey='+ sesskey +'&gallery='+ galleryid +'&cmd='+ cmd;

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        //req.onreadystatechange = processReqChange;
        //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
        req.open("GET", fullurl, false);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            //req.onreadystatechange = processReqChange;
            req.open("GET", fullurl, false);
            req.send();
        }
    }

    return req.responseXML;

};

/**
 * Clear category entries from category dropdown menu.
 *
 */
ImageGallery.prototype._clearEntries = function () {

    if ( document.getElementById ) {
        var elem = document.getElementById('cat_id');
        for ( var i = 0; i < elem.options.length; i++ ) {
            var curEntry = elem.options[i];
            if ( curEntry.getAttribute('value') > 0 ) {
                elem.removeChild(curEntry);
            }
        }
        // crappy hack to remove last entry.
        if ( elem.options.length > 1 ) {
            elem.removeChild(elem.options[1]);
        }
    }
};

/**
 * Add category entries into category dropdown menu.
 *
 */
ImageGallery.prototype._getCat = function ( cmid, sesskey, url, galleryid, cmd ) {

    this._clearEntries();
    if ( document.getElementById ) {
        var output = document.getElementById('cat_id');
        var content = this._HTTPGET(cmid, sesskey, url, galleryid, cmd);

        if ( content ) {
            var categories = content.getElementsByTagName('category');
            for ( var i = 0; i < categories.length; i++ ) {
                var curEntry = categories[i];
                var catId = curEntry.getAttribute('id');
                var catName = curEntry.firstChild.nodeValue;
                if ( catId && catName ) {
                    var optVal = document.createElement('option');
                    optVal.setAttribute("value", catId);
                    if ( i < 1 ) {
                        optVal.setAttribute('selected', 'selected');
                    }
                    var txt = document.createTextNode(catName);
                    optVal.appendChild(txt);
                    output.appendChild(optVal);
                }
            }
        }
    }
};

iGallery = new ImageGallery(); // Initialize new object.var slideNo=-1;
var currentSlideNo=0;
var autoSync = false;

<!--goto next slide -->
function gotoNextSlide(){
	if(numberOfSlides!=slideNo){
		slideNo += 1;
		displaySlide();
	}else{
		alert("Slide Show Ends!");
	}	
}

<!-- goto previous slide -->
function gotoPrevSlide(){
	if(slideNo > 1){
		slideNo -= 1;
		displaySlide();
	}else{
		alert("We are at the first slide!");
	}
}

<!-- goto first slide -->
function gotoFirstSlide(){
	if(slideNo != 1){
		slideNo= 1;
		displaySlide();
	}else{
		alert("Already on the first slide!");
	}
}

<!-- goto first slide -->
function gotoLastSlide(){
	if(slideNo != numberOfSlides){
		slideNo=numberOfSlides;
		displaySlide();
	}else{
		alert("Already on the last slide!");
	}
}

function displaySlide(){
	var slide= slidePath+"Slide"+slideNo+".JPG";
	var FO = {	movie:slide,width:600,height:450,majorversion:"7",build:"0",bgcolor:"#FFFFFF"};
	UFO.create(	FO, "slide-show");	
}

<!-- Trig Auto Sync -->
function trigAutoSync(){
	autoSync= document.getElementById('autosync').checked;
	checkAutoSync();
}

<!-- Handle Presenters Auto Sync -->
function checkAutoSync(){
	clearMsg();
	if(autoSync){
		if(currentSlideNo!=slideNo) syncSlide();
	}
	setTimeout('checkAutoSync()',1000);
}

<!-- Clear Messages -->
function clearMsg(){
	document.getElementById('slide-nav').innerHTML= '';
}

<!-- Async Calls -->

var handleGetSuccess = function(o){
	if(o.responseText !== undefined){
		currentSlideNo = o.responseText;
	}
}

var handleGetFailure = function(o){
	if(o.responseText !== undefined){
		document.getElementById('currentslide').innerHTML= 'Error: '+o.statusText;
	}
}

var callbackGet =
{
	success:handleGetSuccess,
	failure:handleGetFailure,
	argument: { param:"param", bar:"bar" }
};

<!-- Async Call the server to update the current slide number -->
var handleSetSuccess = function(o){
	if(o.responseText !== undefined){
		document.getElementById('slide-nav').innerHTML= 'The Global Current Slide Changed';
		currentSlideNo = slideNo;
	}
}

var handleSetFailure = function(o){
	if(o.responseText !== undefined){
		alert('Updating the status failed:'+o.statusText);
	}
}

var callbackSet =
{
	success:handleSetSuccess,
	failure:handleSetFailure,
	argument: { param:"param", bar:"bar" }
};

var callbackResetPr = {
  success: function(o) {
    alert(o.responseText);
  }
}
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
// NOTICE OF COPYRIGHT                                                     //
//                                                                         //
// Moodle - Filter for converting TeX notation to typeset mathematics      //
// using jsMath                                                            //
//                                                                         //
// Copyright (C) 2005 by Davide P. Cervone                                 //
// This program is free software; you can redistribute it and/or modify    //
// it under the terms of the GNU General Public License as published by    //
// the Free Software Foundation; either version 2 of the License, or       //
// (at your option) any later version.                                     //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details:                            //
//                                                                         //
//          http://www.gnu.org/copyleft/gpl.html                           //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

/****************************************************************/
/*
 *  Configure the jsMath filter here.  See also the filter.php file.
 */

jsMath = {
  Moodle: {
    version: 1.4,               // version of this file
    processSlashParens: 1,      // process \(...\) in text?
    processSlashBrackets: 1,    // process \[...\] in text?
    processDoubleDollars: 1,    // process $$...$$ in text?
    processSingleDollars: 0,    // process $...$ in text?
    fixEscapedDollars: 0,       // convert \$ to $ outside of math mode?
    mimetexCompatible: 1,       // make jsMath handle mimetex better?
    doubleDollarsAreInLine: 0,  // make $$...$$ be in-line math?
    allowDoubleClicks: 1,       // show TeX source for double-clicks?
    allowDisableTag: 1,         // allow ID="tex2math_off" to disable tex2math?
    showFontWarnings: 0,        // show jsMath font warning messages?
    loadFiles: null,            // a single file name or [file,file,...]
    loadFonts: null,            // a single font name or [font,font,...]
    scale: 120,                 // the default scaling factor for jsMath
    filter: 'filter/jsmath'     // where the filter is found
  }
};

//  If you want to use your own custom delimiters for math instead
//  of the usual ones, then uncomment the following four lines and
//  insert your own delimiters within the quotes.  You may want to
//  turn off processing of the dollars and other delimiters above
//  as well, though you can use them in combination with the
//  custom delimiters if you wish.

//     jsMath.Moodle.customDelimiters = [
//        '[math]','[/math]',        // to begin and end in-line math
//        '[display]','[/display]'   // to begin and end display math
//     ];

//  [Note that the code below doesn't do any special quoting of the
//  strings, so you should not use single quotes or backslashes as
//  part of your strings, unless you know what you are doing.  See
//  the jsMath author's documentation for the tex2math plugin for
//  more caveats about using custom delimiters.]

/****************************************************************/
/****************************************************************/
//
//            DO NOT MAKE CHANGES BELOW THIS
//
/****************************************************************/
/****************************************************************/

jsMath.Autoload = {
  findMathElements: 1,
  findTeXstrings: 0,
  findLaTeXstrings: 0,
  findCustomStrings: jsMath.Moodle.customDelimiters,
  loadFiles: jsMath.Moodle.loadFiles,
  loadFonts: jsMath.Moodle.loadFonts
};

if (jsMath.Moodle.processSingleDollars ||
    jsMath.Moodle.processDoubleDollars ||
    jsMath.Moodle.processSlashParens ||
    jsMath.Moodle.processSlashBrackets ||
    jsMath.Moodle.fixEscapedDollars) {

  jsMath.Autoload.findCustomSettings = {
    processSingleDollars: jsMath.Moodle.processSingleDollars,
    processDoubleDollars: jsMath.Moodle.processDoubleDollars,
    processSlashParens:   jsMath.Moodle.processSlashParens,
    processSlashBrackets: jsMath.Moodle.processSlashBrackets,
    fixEscapedDollars:    jsMath.Moodle.fixEscapedDollars,
    custom: 0
  };
}

jsMath.Autoload.scripts = document.getElementsByTagName('script');
jsMath.Autoload.root = jsMath.Autoload.scripts[jsMath.Autoload.scripts.length-1].src;
jsMath.Autoload.root = jsMath.Autoload.root.replace('/lib/javascript-mod.php',
                                                    '/'+jsMath.Moodle.filter+'/jsMath/');
jsMath.Autoload.scripts = null;

jsMath.tex2math = {
  doubleDollarsAreInLine: jsMath.Moodle.doubleDollarsAreInLine,
  allowDisableTag:        jsMath.Moodle.allowDisableTag
}
if (jsMath.Moodle.mimetexCompatible) {
  if (!jsMath.Autoload.loadFiles) {jsMath.Autoload.loadFiles = []}
  if (typeof(jsMath.Autoload.loadFiles) == 'string')
    {jsMath.Autoload.loadFiles = [jsMath.Autoload.loadFiles]}
  jsMath.Autoload.loadFiles[jsMath.Autoload.loadFiles.length] = "plugins/mimeTeX.js";
}

jsMath.Controls = {cookie: {scale: jsMath.Moodle.scale}};
if (!jsMath.Moodle.allowDoubleClicks) {
  jsMath.Click = {CheckDblClick: function () {}};
}
if (!jsMath.Moodle.showFontWarnings) {
  jsMath.Font = {Message: function () {}};
}

jsMath.Moodle.onload = window.onload
window.onload = function () {
  if (jsMath.Moodle.onload) {jsMath.Moodle.onload()} // call old handler
  if (document.getElementById("Process_jsMath")) {   // set by filter.php
    jsMath.Autoload.Check();
    jsMath.Autoload.Run();
    jsMath.Process();
  }
}

document.write('<script src="'+jsMath.Autoload.root+'plugins/autoload.js"></script>');
