// JavaScript Document

/*
 VERSION    $Revision: 268 $ $Name$
 DATE       $Date: 2006-06-22 15:21:26 -0300 (qui, 22 jun 2006) $
 AUTHOR     $Author: samuel $
*/

// -
var libraryPATH = '/jslib/';
if (String(document.location.pathname).search(/\/dev/) > -1) {
    libraryPATH = '/dev/jslib/';
}
if (String(document.location.pathname).search(/\/jslib/) > -1) {
    libraryPATH = './';
}

// -
var Plugins = new Array();
var processElements = false;

// Constructor
function compileApp( pDocument ) {
	
	// -
	if (! pDocument) 
		pDocument = document;
	
	// -
	initializeDebug( pDocument );
	initializeDate( pDocument );
	initializeCurrency( pDocument );
	
	// -
	for (var c = 0; c < Plugins.length; c++) 
		if (Plugins[c].initialize)
			Plugins[c].initialize(pDocument);
	// -
	if (processElements) {
		for (var f = 0; f < pDocument.forms.length; f++) {
			appCompileForm(pDocument.forms[f], f);
		}
	}
	// -
	for (var c = 0; c < Plugins.length; c++) 
		if (Plugins[c].terminate) 
			Plugins[c].terminate(pDocument);
	// -
	document.jslibCompiled = true;
}

// - Compila um form
function appCompileForm ( form, index ) {
	//
	if (form.getAttribute('OnBeforeCompile')) {
		var content = form.getAttribute('OnBeforeCompile');
		form.onBeforeCompile = function () { return(eval(content)) };
		form.onBeforeCompile();
	}
	
	// -
	for (var c = 0; c < Plugins.length; c++) {
		if (Plugins[c].startForm) 
			Plugins[c].startForm(form, index);
	}
	// -
	for (var e = 0; e < form.length; e++) {
	for (var c = 0; c < Plugins.length; c++) 
		if (Plugins[c].processElement) 
			Plugins[c].processElement(form.elements[e], e);
	}
	// -
	for (var c = 0; c < Plugins.length; c++) 
		if (Plugins[c].finishForm) 
			Plugins[c].finishForm(form, index);

	//
	if (form.getAttribute('OnAfterCompile')) {
		var content = form.getAttribute('OnAfterCompile');
		form.onAfterCompile = function () { return(eval(content)) };
		form.onAfterCompile();
	}
}

// -
function appAddCompile ( component ) {
    Plugins[Plugins.length] = component;
	processElements = processElements || (component.processElement ? true : false) || (component.startForm ? true : false) || (component.finishForm ? true : false);
}

// -
function include( src, path ) {
	
	//
	src = src.split('.');
	if ( src[ src.length - 1 ] == 'js') 
		src.length -= 1;
	
	// 
	path = path || libraryPATH || '';
	if ( path.substr( path.length - 1 ) != "/" )
		path += "/";
	
	// 
	document.write('<script language="Javascript1.2" src="' + path + src.join('/') + '.js"><\/script>');
	
}

// -
include('debug');
include('general');
include('browser');
include('date');
include('currency');
include('html');

// -
include('autochange');
include('newoption');
include('mask');
include('validate');
include('disableonsubmit');
include('focus');
include('radioselect');

// -
include('oneventmanager');
include('location');
include('htmlcopy');
include('sorttable');
include('elements');

