
function viewfile(params) {
	var url = params.url;
	var warning = typeof(params.showWarning) != 'undefined' ? params.showWarning : false;
	var language = typeof(params.language) != 'undefined' && params.language ? params.language : 'en';
	var newwindow = typeof(params.newWindow) != 'undefined' ? params.newWindow : false;
	if (warning) {
		if (language=='en') 
			alert('Important Notice: The company name listed in this manual has changed to Redmond Group of Companies. Please refer to this website for warranty and service details.');
		else
			alert("Avis important: L'entreprise dont il est fait mention dans le prsent document excerce dornavant ses activits sous le nom de Redmond Group of Companies, veuillez consulter ce site Web pour obtenir de plus amples renseignements sur la garantie et le service.");
	}
	if (newwindow) 
		window.open(url);
	else 
		window.location=url;
}
		
function deleteRow(tbl, rowIndex) {
	var tbl = $(tbl);
	tbl.deleteRow(rowIndex);
}

function toggleImage(id, img1, img2) {
	if ($(id).src.match(img1)) {
		if (document.all) 	
			setTimeout(function() {$(id).src = img2}, 200);
		else
			$(id).src = img2;
	}	
	else {
		if (document.all) 	
			setTimeout(function() {$(id).src = img1}, 200);
		$(id).src = img1;
	}
}

function toggleDelete(id, imgid) {
	if ( $(id).value == "true" ) {  
		$(id).value = "false";
		if (document.all) 	
			setTimeout(function() {$(imgid).src = "/administration/layouts/gridicon/delete"}, 200);
		else
			$(imgid).src = "/administration/layouts/gridicon/delete"
	}
	else {
		$(id).value = "true";
		if (document.all) 	
			setTimeout(function() {$(imgid).src = "/administration/layouts/gridicon/cancel"}, 200);
		else
			$(imgid).src = "/administration/layouts/gridicon/cancel";
	}
}

////////////////////////////////////////////////////////////////////////////////////
// CUSTOM AUTOCOMPLETER WITH MULTI-TOKEN SEARCHES
// Taken from Autocompleter.Local, then modified.
// The built-in one can't search on "kli intra" to find klick intranet, for e.g.

Autocompleter.Local2 = Class.create();
Autocompleter.Local2.prototype = Object.extend(new Autocompleter.Base(), {
  initialize: function(element, update, array, options) {
    this.baseInitialize(element, update, options);
    this.options.array = array;
  },

  getUpdatedChoices: function() {
    this.updateChoices(this.options.selector(this));
  },

  setOptions: function(options) {
    this.options = Object.extend({
      choices: 10,
      partialSearch: true,
      partialChars: 2,
      multiWordSearch: false,
      ignoreCase: true,
      fullSearch: false,
      selector: function(instance) {
        var ret       = []; // Beginning matches
        var partial   = []; // Inside matches
        var entry     = instance.getToken();
        var count     = 0;

        for (var i = 0; i < instance.options.array.length &&  
          ret.length < instance.options.choices ; i++) { 

		  var found = false;
          var elem = instance.options.array[i];
          var foundPos = instance.options.ignoreCase ? 
            elem.toLowerCase().indexOf(entry.toLowerCase()) : 
			elem.indexOf(entry);

		  while (foundPos != -1) {
			
            if (foundPos == 0 && elem.length != entry.length) { 
              ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" + 
			    elem.substr(entry.length) + "</li>");
			  found = true;
              break;
			} 
			else if (entry.length >= instance.options.partialChars && instance.options.partialSearch && foundPos != -1) {
              if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
                partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
                  elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
                  foundPos + entry.length) + "</li>");
			    found = true;
                break;
              }
		    }

            foundPos = instance.options.ignoreCase ? 
              elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : 
              elem.indexOf(entry, foundPos + 1);

		  }

		  if (!found && instance.options.multiWordSearch) {
		    var filterstring = String(entry).replace(/\?/g,".?").replace(/\\/g,"\]").replace(/\'/g,"\'").replace(/\[/g,"\\[").replace(/\]/g,"\\]").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\*/g,"\\*").replace(/\$/g,"\\$").replace(/ /g,".*");
		    var filter = new RegExp(filterstring,"ig");
		    if (elem.match(filter))
			  partial.push("<li>" + elem + "</li>");
		  }
        }
        if (partial.length)
          ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
        return "<ul>" + ret.join('') + "</ul>";
      }
    }, options || {});
  }
});

// this method is broken and causes javascript error 
Element.collectTextNodesIgnoreClass = function(element, className) {  
          if ($(element)&&$(element.childNodes)) {
		  return $A($(element).childNodes).collect( function(node) {
		    return (node.nodeType==3 ? node.nodeValue : 
		      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? 
			Element.collectTextNodesIgnoreClass(node, className) : ''));
		  }).flatten().join('');
	}
	else {
		return '';
	}
}

/// CUSTOM AJAX AUTOCOMPLETER
/// (just for updating a div, not for a drop-down list)
Ajax.Autocompleter2 = Class.create();
Ajax.Autocompleter2.prototype = Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
  initialize: function(element, update, url, options) {
	  this.baseInitialize(element, update, options);
    this.options.asynchronous  = true;
    this.options.onComplete    = this.onComplete.bind(this);
    this.options.defaultParams = this.options.parameters || null;
    this.url                   = url;
  },

  getUpdatedChoices: function() {
    entry = encodeURIComponent(this.options.paramName) + '=' + 
      encodeURIComponent(this.getToken());

    this.options.parameters = this.options.callback ?
      this.options.callback(this.element, entry) : entry;

    if(this.options.defaultParams) 
      this.options.parameters += '&' + this.options.defaultParams;

    new Ajax.Request(this.url, this.options);
  },

  onComplete: function(request) {
    this.updateChoices(request.responseText);
  },
    
  onKeyPress: function(event) {
    if(this.active)
      switch(event.keyCode) {
       case Event.KEY_TAB:
       case Event.KEY_RETURN:
         Event.stop(event);
       case Event.KEY_ESC:
         Event.stop(event);
         return;
       case Event.KEY_LEFT:
       case Event.KEY_RIGHT:
         return;
       case Event.KEY_UP:
         this.markPrevious();
         this.render();
         if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
         return;
       case Event.KEY_DOWN:
         this.markNext();
         this.render();
         if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
         return;
      }
     else 
      if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN) 
        return;

    this.changed = true;
    this.hasFocus = true;

    if(this.observer) clearTimeout(this.observer);
      this.observer = 
        setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  }, 
  
  startIndicator: function() {
    this.hide();
    if(this.options.indicator) Element.show(this.options.indicator);
  },
  
  onHover: function(event) {
  },
  
  onClick: function(event) {
  },
  
  onBlur: function(event) { 
  }

});


// this method is broken and causes javascript error 
Element.collectTextNodesIgnoreClass = function(element, className) {  
          if ($(element)&&$(element.childNodes)) {
		  return $A($(element).childNodes).collect( function(node) {
		    return (node.nodeType==3 ? node.nodeValue : 
		      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? 
			Element.collectTextNodesIgnoreClass(node, className) : ''));
		  }).flatten().join('');
	}
	else {
		return '';
	}
}
		