/**************************************************************************************
  Description: Class related to basic queries of the browser
		 Author: Roarke Lynch
		   Date: 20-Apr-05
		  Notes: none
 Dependencies: none
**************************************************************************************/

/* Constructor */
Browser = function() {
	this.params = new Object();
	if(location.search.length > 1) {
		pairs = (location.search.substr(1)).split("&");
		for(i = 0; i < pairs.length; i++) {
			param = pairs[i].split("=");
			if(param.length == 2) {
				this.params[ param[0] ] = unescape(param[1]);
			}
		}
	}
}

/* Class Methods */
Browser.writePlugins = function () {
	document.writeln("<pre>Complementos instalados (" + navigator.plugins.length + ")\n------------------------------\n");
	for(var i = 0; i < navigator.plugins.length; i++ )
	{
		plugin = navigator.plugins[i];
		if( (typeof plugin) != 'function' ) {
			document.writeln(i + "\n"); 
			document.writeln("\t[Name] " + plugin.name + "\n");
			document.writeln("\t[Description] " + plugin.description + "\n");
			document.writeln("\t[Filename] " + plugin.filename + "\n");
		}
	}
	document.writeln("</pre>");
}

Browser.detectControl = function(pluginName, activeXName, version) {
    if (navigator.plugins.length > 0) { // NS/Mozilla
		var re = new RegExp(pluginName, "i");
		for(var i = 0; i < navigator.plugins.length; i++) {
			var plugin = navigator.plugins[i];
			if( (plugin.name.match(re) != null) || (plugin.description.match(re) != null) )
			{
				if( (typeof version) != 'undefined') {
					var v = plugin.description.match(/\d{1,2}/);
					if( v >= version )
						return true;
					return false;
				}
				else 
					return true;
			}
		}
    }
    else if (window.ActiveXObject && window.execScript && navigator.userAgent.indexOf('Mac') == -1) { // Win IE
        Browser.hasActiveX = false;
        window.execScript("On error resume next: Browser.hasActiveX = IsObject(CreateObject('" + activeXName + "'))", "VBScript");
        var hasControl = Browser.hasActiveX;
        delete Browser.hasActiveX;
        return hasControl;
    }
    return false;
}

Browser.getParam = function(paramName) {
	var tb = new Browser();
	return tb.getParam(paramName);
}

/* Instance Methods */
Browser.prototype.protectFromFrames = function () {
	if (top.frames.length > 0){
		top.location.href = location.href;
	}
}

Browser.prototype.getParamNames = function() {
	pnames = new Array();
	for(var i in this.params) {
		pnames.push(i);
	}
	return pnames;
}

Browser.prototype.getParam = function(name) {
	return this.params[name];
}

