//
//	netforge javascript api
//
function netforge_class() {
	//
	//	get element by id cross browser class
	//
	this.getElementByID = function(id){
		var obj = null;
		if(document.getElementById){
			//	w3c dom method
			obj = document.getElementById(id);
		}else if(document.all){
			//	id's must be unique and not coincide with name
			obj = document.all[id];
		}
		//	will return null if no element exists
		return obj;
	}
	
	//
	//	preloads images
	//
	this.preloadImages = function(){
		var arguments = this.preloadImages.arguments;
		for (var i = 0; i < arguments.length; i++) 
		{
			var image = new Image();
			image.src = arguments[i];
		}
	}
	
	//
	//	addevent
	//
	this.addEvent = function(id, _event){
		
	}
	
	//
	//	writes text into a frame
	//
	this.writeIntoFrame = function(frameid, html) {
		var frame = this.getElementByID(frameid);
		var doc = frame.contentDocument;
        if (doc == undefined || doc == null)
            doc = frame.contentWindow.document;
		
        doc.open();
        doc.write(text);
        doc.close();
	}
	
	//
	//	sets the visibility of a list of elements
	//
	this.setVisibility = function(visible) {
		var arguments = this.setVisibility.arguments;
		this.altlist = Array(arguments.length);
		for (var i = 1; i < arguments.length; i++) 
		{
			var element = this.getElementByID(arguments[i]);
			if(visible == false){
				element.style.visibility = 'hidden'; 
				element.style.display = 'none';
			} else {
				element.style.visibility = 'visible'; 
				element.style.display = '';
			}
		}
	}
	
	//
	//	toggles visibility of multiple element base
	//
	this.toggleVisible = function() {
		var arguments = this.toggleVisible.arguments;
		this.altlist = Array(arguments.length);
		for (var i = 0; i < arguments.length; i++) 
		{
			var element = this.getElementByID(arguments[i]);
			if(element.style.visibility != 'hidden'){
				element.style.visibility = 'hidden'; 
				element.style.display = 'none';
			} else {
				element.style.visibility = 'visible'; 
				element.style.display = '';
			}
		}
	}
	
	//
	//	trimming strings
	//
	this.trim = function (str, chars) {
		return this.ltrim(this.rtrim(str, chars), chars);
	}
	 
	this.ltrim = function (str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	 
	this.rtrim = function (str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	//
	//  currency formatting strings
	//
	this.currencyFormat = function(amount, delimiter) {
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		if(delimiter == null)
			return s;
		
		var a = s.split('.',2)
		var d = a[1];
		var i = parseInt(a[0]);
		if(isNaN(i)) { return ''; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while(n.length > 3)
		{
			var nn = n.substr(n.length-3);
			a.unshift(nn);
			n = n.substr(0,n.length-3);
		}
		if(n.length > 0) { a.unshift(n); }
		n = a.join(delimiter);
		if(d.length < 1) { s = n; }
		else { s = n + '.' + d; }
		s = minus + s;
		return s;

	}

	
	this.root = '';
	
	//	will be initialized if you include window.js
	this.window = null;
	//	will be initialized if you include slideshow.js
	this.slideshow = null;
	//	will be initialize if you include validate.js
	this.validator = null;
	//	will be initialized if you include ajax.js (or installPlugins(root, "ajax"))
	this.ajax = null;
	//	will be initialized if you include comments.js (or installPlugins(root, "comments"))
	this.comments = null;
	//  will be initialized if you include table.js (or installPlugins(root, "table"))
	this.table = null;
	//	will be initialized if you include string.js (or installPlugins(root, "string"))
	this.string = null;
	
	//
	//	loads the plugins for you
	//
	this.installPlugins = function(root){
		this.root = root;
		sroot = root + 'jscript/';
		var arguments = this.installPlugins.arguments;
		this.altlist = Array(arguments.length);
		for (var i = 1; i < arguments.length; i++) 
		{
			document.write('<script language="javascript" src="'+sroot+arguments[i]+'.js"></script>');
		}
	}
}

var netforge = new netforge_class();