var pathWebJS = '/js';

var spj_pathInclude = '/js';
var spj_dirNameImpoer = 'spj';

//spj = new Object();


Function.prototype.defaults = function()
{
  var _f = this;
  var _a = Array(_f.length-arguments.length).concat(
    Array.prototype.slice.apply(arguments));
  return function()
  {
    return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(
      _a.slice(arguments.length, _a.length)));
  };
};



spjClass = function()
{
	this.pathInclude = '/js';
	this.dirNameImport = 'spj';
	this.packagesImported = new Array();
	
	this.init();
};

spjClass.prototype.init = function()
{
	this._setNavigator();
	this._setOS();
	
};

spjClass.prototype._setNavigator = function()
{
	this.navigator = this.navigator || {
		
		userAgent     : null,
		isKHTML       : null,
		isSafari      : null,
		isKonqueror   : null,
		isOpera       : null,
		isIE          : null,
		isMozilla     : null,
		
		version       : null,
		versionMajor  : null,
		versionFloat  : null,
		codeName      : null,
		name	      : null,
		cookieEnabled : null,
		platform      : null,
		userAgent     : null,
		
		
		
		init : function()
		{
			this.userAgent = navigator.userAgent;
			
			this.isKHTML = this.userAgent.indexOf("KHTML") > -1 
					|| this.userAgent.indexOf("Konqueror") > -1
					|| this.userAgent.indexOf("AppleWebKit") > -1;
					
			if(this.isKHTML){
				this.isSafari = this.userAgent.indexOf("AppleWebKit") > -1;
				this.isKonqueror = this.userAgent.indexOf("Konqueror") > -1;
			}
			else{
				this.isSafari = false;
				this.isKonqueror = false;
			}
							
			
			this.isOpera = this.userAgent.indexOf("Opera") > -1;
			this.isIE = this.userAgent.indexOf("compatible") > -1
						&& this.userAgent.indexOf("MSIE") > -1
						&& !this.isOpera;
			
						
						
						
			this.isMozilla = this.userAgent.indexOf("Gecko") > -1
							 && !this.isKHTML;	
			
			this.version = navigator.appVersion;
			this.codeName = navigator.appCodeName;
			this.name     = navigator.appName;
			this.cookieEnabled = navigator.cookieEnabled;
			this.platform = navigator.platform;
			if(this.isIE){
				var msieOffset = this.userAgent.indexOf("MSIE ");
				this.versionFloat = parseFloat(
										this.userAgent.substring(
												msieOffset + 5, 
														this.userAgent.indexOf(
																	";", 
																	msieOffset
														)
										)
									);
				
				//alert('version float: '+this.versionFloat);
				
			}
			else{
				this.versionFloat = parseFloat(this.version);
			}
			
			this.versionMajor = parseInt(this.versionFloat);
			
		}
		
	};
	this.navigator.init();
					 
					 
};

spjClass.prototype._setOS = function()
{
	this.os = this.os ||  {
		
		isWin  : null,
		isMac  : null,
		isUnix : null,
		
		init : function()
		{
			this.isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
			this.isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC")
						  || (navigator.platform == "Macintosh");
			this.isUnix = (navigator.platform == "X11") && !this.isWin && !this.isMac;
		}
			
	};
	this.os.init();	
		
};



/*
spjClass.prototype.include = function(fileName)
{
	var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    var includePath = this.pathInclude + "/" +fileName;
    //alert('including path: '+includePath);
    //js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', includePath);
    html_doc.appendChild(js);
    return false;
}
*/
spjClass.prototype.include = function(fileName)
{
	var includePath = this.pathInclude + "/" +fileName;
	document.write('<' + 'script');
    //document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + includePath + '">');
    document.write('</' + 'script' + '>');
};

spjClass.prototype.includeInternal = function(dirPackage,fileName)
{
	var path = this.dirNameImport + "/" + dirPackage + "/" + fileName;
	//alert('path internal to include: '+path);
	this.include(path);
};


spjClass.prototype.register = function(packageName)
{
	var pathToInclude = this.dirNameImport + "/" + packageName + "/" + "init.js";
	//alert('registering: '+pathToInclude);
	this.include(pathToInclude);
};

spjClass.prototype.getClientBrowser = function()
{
	//returns 1 for Netscape, 2 for ie
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  	return 1;  
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	 	return 2;
	 }
	}
	
};

spjClass.prototype.clone = function(obj)
{
	if( typeof(obj) != 'object'){
		return obj;
	}
	if(obj == null) {
		return obj;
	}

	var clonedObj = new Object();

	for(var i in obj){
		clonedObj[i] = this.clone(obj[i]);
	}
		

	return clonedObj;
	
};





var spj = new spjClass();

//if browser is ie and version less than 9, make it comform to the standards:
if(spj.navigator.isIE){
	//alert('version: '+spj.navigator.version);
	//alert('version major: '+spj.navigator.versionMajor);
	if(spj.navigator.versionMajor<9){
		//alert('including ie fixes22!');
		spj.include('spj/ext/iefix/IE9.js');
		
	}
}

spj.register('core');
spj.register('display');
spj.register('php');
//alert('EEEEE');
