//	--------------------------------------------------------------------------
//
//
//
//	--------------------------------------------------------------------------


function urlClass ()
{
	this.url			= window.location;
	this.getParameter	= _url_getParameter;

	this._prm	= new Array();

	var prm = this.url.search.substring(1);	//	skip = "?" character
	var ar1 = prm.split ("&");
	for (var i=0; i<ar1.length; i++) {
		if (ar1[i] != "") {
			var ar2 = ar1 [i].split ("=");
			if (ar2.length == 2) {
				var key = ar2 [0];
				var val = ar2 [1];
				if (key != "" && val != 0) {
					this._prm [key] = val;
				}
			}
		}
	}
}

function _url_getParameter (key)
{
	return this._prm [key];
}


//	--------------------------------------------------------------------------
//
//
//
//	--------------------------------------------------------------------------


function doiClass (doi)
{
	this.getDocument	= _doi_getDocument;
	this._doi			= doi;
}

function _doi_getDocument ()
{
	return this._doi;
}


//	--------------------------------------------------------------------------
//
//
//
//	--------------------------------------------------------------------------


function sosiCommand (cmd, mod, qry, ran)
{
	this.cmd	= cmd;
	this.mod	= mod;
	this.qry	= qry;
	this.ran	= ran;
}


//	--------------------------------------------------------------------------
//
//
//
//	--------------------------------------------------------------------------


function winmanClass ()
{
	//	Interface function
	this.command	= _winman_command;
	this.getUrl		= _winman_getUrl;
	this.getOptions	= _winman_getOptions;
	this.register	= _winman_register;
	this.close		= _winman_close;

	//	Protected functions
	this._getInterface	= _winman_getInterface;
	this._childWins		= Array();
	this._commands		= Array();					//	Saved commands

	this._childWins [0] = null;		//	_childWins [0]: OPENER !!

	try {
	if (window.opener && window.opener.sosiGetInterface) {
		var ri = window.opener.sosiGetInterface();
		if (ri) {
			var name = window.opener.name;
			this._childWins [name] = new winClass (name, window.opener, ri);
			this._childWins [name].setInterface (ri);
			this._childWins [0] = this._childWins [name];
		}
	}
	}
	catch (err) { }
}

function _winman_close (name)
{
//	alert ("close: " + name + " " + this._childWins.length);
	for (i=1; i<this._childWins.length; i++) {
		var win = this._childWins [i];
		if (win) {
			var name = win.getName();
//			alert ("closing child window " + name);
			win.closeWindow();
		}
	}
/*
	if (this._childWins [name]) {
		this._childWins [name].closeWindow();
	}
*/
}

function _winman_command (name, cmd, mod, qry, ran)
{
	var ri = this._getInterface (name);
	if (ri != null) {
		this._childWins [name].focus();
		if (cmd != null) {
			ri.command (cmd, mod, qry, ran);
		}
	}
	else {
		this._commands [name] = new sosiCommand (cmd, mod, qry, ran);
		this._childWins [name].openWindow();
	}
}

function _winman_getInterface (name)
{
	var ri = null;
	if (this._childWins [name] == null) {
		//	The child window was not opened so far
		this._childWins [name] = new winClass (name, null, null);
		this._childWins [this._childWins.length] = this._childWins [name];
//		alert ("child windows: " + this._childWins.length);
	}
	else {
		ri = this._childWins [name].getInterface();
	}
//	alert ("get interface " + name + " " + ri);
	return ri;
}

function _winman_register (name, ri)
{
	this._childWins [name].setInterface (ri);
//	this._childWins [name].command ("start", "", _dat + "#" + _sid);
}

function _winman_getUrl (name)
{
	var prm = location.search;
	if (prm) prm = "&" + prm.substring (1);
	if (this._commands [name]) {
		var qry = this._commands [name].qry;
		if (qry && qry != "") prm = "&qry=" + this._commands [name].qry;
	}
	switch (name) {
	case "user":
		return "../user/index.html?app=sos" + prm;
	case "curr":
		return "../curr/index.html?app=sos" + prm;
	case "back":
		return "../back/index.html?app=sos" + prm;
	case "guide":
		return "../guide/index.html?app=sos";
	}
}

function _winman_getOptions (name)
{
	switch (name) {
	case "user":
	case "curr":
	case "back":
		break;
	}
	return "location=0,toolbar=0,menubar=0,directories=0,copyhistory=0,resizable=1";
}


//	--------------------------------------------------------------------------
//
//
//
//	--------------------------------------------------------------------------


function winClass (name, win, ri)
{
	this.getName		= _win_getName;
	this.getInterface	= _win_getInterface;
	this.setInterface	= _win_setInterface;
	this.openWindow		= _win_openWindow;
	this.closeWindow	= _win_closeWindow;
	this.command		= _win_command;
	this.focus			= _win_focus;
	this._name			= name;
	this._winObj		= win;
	this._interface		= ri;
}

function _win_getName ()
{
	return this._name;
}

function _win_getInterface ()
{
	if (this._winObj == null) return null;
	if (this._winObj.closed) return null;
	return this._interface;
}

function _win_setInterface (ri)
{
	this._interface = ri;
}

function _win_openWindow ()
{
	var url = _winMan.getUrl(this._name);
	this._winObj = window.open (url, this._name, _winMan.getOptions(this._name));
	if (this._winObj == null) {
		msg  = "Warning:\nA popup window blocker is activated on your computer.\n";
		msg += "Please de-activate the popup blocker for this site.\n";
		msg += "Please contact your IT support if you require assistance.";
		alert (msg);
		return false;
	}
	this._winObj.opener = self;
	return true;
}

function _win_closeWindow ()
{
	if (this._winObj) {
		this._winObj.close();
		this._winObj = null;
	}
	this._interface = null;
}

function _win_command (cmd, mod, qry, ran)
{
	if (this._interface != null) {
		this._interface.command (cmd, mod, qry, ran);
	}
}

function _win_focus ()
{
	this._winObj.focus();
}


//	----------------------------------------------------------------------------------------
//	
//	
//	
//	----------------------------------------------------------------------------------------


function optionClass ()
{
	this.className	= "option";
	this.getValue	= _option_getValue;
	this.setValue	= _option_setValue;
	this._values	= new Array();
}

function _option_getValue (name)
{
	return this._values [name];
}

function _option_setValue (name, value)
{
	this._values [name] = value;
}


//	----------------------------------------------------------------------------------------
//	
//	
//	
//	----------------------------------------------------------------------------------------


function popupClass (name)
{
	this.className	= "popup";

	this.open		= _popup_open;

	this.window		= null;
	this.name		= name;
}

function _popup_open (options)
{
	this.window = window.open ("popup.html", this.name, options);
}


//	----------------------------------------------------------------------------------------
//	
//	
//	
//	----------------------------------------------------------------------------------------


function idClass (name)
{
	this.className		= "id";
	this.loadName		= _id_loadName;
	this.setValues		= _id_setValues;
	this.toString		= _id_toString;
	this.tocName		= _id_tocName;
	this.docName		= _id_docName;
	this.nodeName		= _id_nodeName;
	this.iconName		= _id_iconName;
	this.textName		= _id_textName;
	this.getProject		= _id_getProject;
	this.setType		= _id_setType;
	this.getType		= _id_getType;
	this.getVolume		= _id_getVolume;
	this.getDocument	= _id_getDocument;

	this._name			= "";
	this._project		= "S";
	this._type			= "";
	this._volume		= 0;
	this._document		= 0;

	if (name != null) {
		this.loadName (name);
	}
}

function _id_loadName (name)
{
	var arr = _explode ("-", name);
	if (arr.length != 3) {
	}
	this._volume   = parseInt (_strToNum(arr [1]));
	this._document = parseInt (_strToNum(arr [2]));
	this._name	= name;
}

function _id_setValues (vol, doc)
{
	this._volume = vol;
	this._document = doc;
	this._name = "ST-" + _numToStr (this._volume, 3) + "-" + _numToStr (this._document, 5);
}

function _id_toString ()
{
	return this._name;
}

function _id_tocName ()
{
	return "ST-" + _numToStr (this._volume, 3) + "-" + _numToStr (this._document, 5);
}

function _id_docName ()
{
	return "SD-" + _numToStr (vol, 3) + "-" + _numToStr (doc, 5);;
}

function _id_nodeName ()
{
	return "node-" + this.toString();
}

function _id_iconName ()
{
	return "icon-" + this.toString();
}

function _id_textName ()
{
	return "text-" + this.toString();
}

function _id_getProject ()
{
	return this._project;
}

function _id_setType (value)
{
	if (value == null || value.length != 1) {
		return;
	}
	this._type = value.toUpperCase();
	this._name = "S" + this._type + "-" + _numToStr (this._volume, 3) + "-" + _numToStr (this._document, 5);
}

function _id_getType ()
{
	return this._type;
}

function _id_setVolume (value)
{
	this._volume = value;
}

function _id_getVolume ()
{
	return this._volume;
}

function _id_setDocument (value)
{
	this._document = value;
}

function _id_getDocument ()
{
	return this._document;
}



//	----------------------------------------------------------------------------------------
//	
//	
//	
//	----------------------------------------------------------------------------------------


function sessionClass (app, dat, sid)
{
	this.className	= "session";
	this._app = "";
	this._dat = "";
	this._sid = "";

	function getApplication ()
	{
		return _app;
	}

	function getSessionId ()
	{
		return _sid;
	}

	function getDate ()
	{
		return _dat;
	}

}


//	----------------------------------------------------------------------------------------
//	
//	
//	
//	----------------------------------------------------------------------------------------


function queryClass (obj, cmd, mod, qry, ran)
{
	this.obj = obj;
	this.cmd = cmd;
	this.mod = mod;
	this.qry = qry;
	this.ran = ran;
}


