/*
---------------------------------------------------------------------------------
AP GUI
---------------------------------------------------------------------------------
*/

function apGui(){
	/*
	this.id = 'apGui';
	this.isInit = false;
	this.pref = new Object();
	
	this.pref.mask_id = 'mask';
	this.pref.backgroundColor = '#000';
	this.pref.mask_alpha = 0.7;
	
	this.doc = document.body;
	
	this.setPreference = function(name,value){
		this.pref[name] = value;
		if (this.isInit) this.updateDisplay();
		return true;
	}
	
	this.init = function() {
		if (this.isInit) return true;
		this.mask = this.setMask(this.pref.mask_id);
		this.updateDisplay();
		return true;
	}
	
	this.updateDisplay = function() {
		this.isOpen = true;
		this.mask.style.backgroundColor = this.pref.backgroundColor;
		this.mask.style.opacity = this.pref.mask_alpha;
		this.mask.style.filter = "alpha(opacity="+ (this.pref.mask_alpha *100) +")";
		this.mask.style.display = "block";
		this.mask.style.height = document.body.scrollHeight + "px";	
	}
	*/
}
/*
apGui.prototype.removeWindow = function(){
	this.isOpen = false;
	this.doc.removeChild(this.win);
	this.mask.style.display = "none";
	
}

apGui.prototype.setMask = function(name){
	
	if (document.getElementById(name)) {
		document.body.removeChild(name);
	}
	var w = document.createElement("DIV");
	w.className = 'gui';
	w.id = name;
	w.style.position = "absolute";
	w.style.top = 0;
	w.style.right = 0;
	w.style.bottom = 0;
	w.style.left = 0;
	w.style.zindex = 90000;
	w.style.height = document.body.scrollHeight + "px";
	

	this.doc.appendChild(w);
	return w;
}


apGui.prototype.window = function(o){
	
	if (!this.isInit) {
		this.isInit = this.init();
	}
	this.updateDisplay();
	
	var w = document.createElement("DIV");
	w.style.zindex = 10000;
	w.className = 'guiWinBg';
	this.win = w;
	
	var yScroll = window.scrollY || document.documentElement.scrollTop;
	this.win.style.top = yScroll + (( YAHOO.util.Dom.getViewportHeight() / 100) * 4 ) + "px";

	var body = document.createElement("DIV");
	body.className='guiWin';
	this.body = body,
	this.body.id = o.id;
	w.appendChild(body);
	
	this.doc.appendChild(w);
	
	var title = document.createElement("DIV");
	title.id = "guiWinTitle";
	title.className='guiWinTitle';
	this.title = title;
	
	var dclose = document.createElement("DIV");
	//close.id = "guiWinClose";
	dclose.className='guiWinClose';
	this.close = close;
	this.title.appendChild(dclose);

	this.body.appendChild(title);
	
	var msg = document.createElement("DIV");
	this.body.appendChild(msg);
	this.msg = msg;
	
	msg.className='guiWinMsg';
	
	var bts = document.createElement("DIV");
	this.bts = bts;
	bts.className='guiWinBts';

	var bot = document.createElement("DIV");
	this.body.appendChild(bot);
	this.bot = bot;
	bot.className='guiWinBottom';
		
}



apGui.prototype.alert = function(msg,callBack){

	this.callBack = callBack;
	this.window('alert');
	
	var tx = document.createTextNode("Alert");
	this.title.innerHTML = ""; // clear -> do more eleguante later
	this.title.appendChild(tx);
	
	this.msg.innerHTML = ""; // clear -> do more eleguante later
	this.msg.appendChild(msg);
	
	var btOk = this.button("OK", function(e){ 
		var node = apGetTarget(e);
		node.win.removeWindow();
		node.callBack(true);
	},true);
	btOk.win = this;
	btOk.callBack = callBack;
	this.bts.appendChild(btOk);
	
	this.body.appendChild(this.bts);
}



apGui.prototype.forms = function(msg,callBack){

	this.callBack = callBack;
	var o = {id:'Attention'};
	this.window(o);
	
	var tx = document.createTextNode("Attention");
	this.title.innerHTML = ""; // clear -> do more eleguante later
	this.title.appendChild(tx);
	
	this.msg.innerHTML = ""; // clear -> do more eleguante later
	
	this.form = document.createElement("FORM");
	this.form.id = msg.id;
	this.msg.appendChild(this.form);
	this.form.appendChild(msg);
	
	var btOk = this.button("Valider", function(e){ 
		var node = apGetTarget(e);
		node.callBack(node.win.form);
		node.win.removeWindow();
		
	},true);
	
	btOk.win = this;
	btOk.callBack = callBack;
	this.bts.appendChild(btOk);
	
	var btKo = this.button("Annuler", function(e){
		var node = apGetTarget(e);
		node.win.removeWindow();
		node.callBack(false);
		
	},false);
	
	btKo.win = this;
	btKo.callBack = callBack;
	this.bts.appendChild(btKo);
	
	this.body.appendChild(this.bts);
	
}


apGui.prototype.button = function(txt,fn,dflt){

	var bt = document.createElement("div");
	var txbt = document.createTextNode(txt);
	bt.appendChild(txbt);

	if(dflt) { // default
		bt.className='guiBtDflt';
		addEvent(bt,"mouseover",function() { bt.className = "guiBtOver"; });
		addEvent(bt,"mouseout",function() { bt.className = "guiBtDflt"; });

	} else {
		bt.className='guiBt';
		addEvent(bt,"mouseover",function() { bt.className = "guiBtOver"; });
		addEvent(bt,"mouseout",function() { bt.className = "guiBt"; });
	}

	addEvent(bt,"click",fn);
	
	return bt;

}

apGui.prototype.progressWindow = function(o){

	var selects = new Array();

	//print_r(o);
	
	//this.callBack = o.callBack;
	var w = {id:o.id};
	this.window(w);
	
	var tx = document.createTextNode(o.title);
	var titleText = document.createElement("div");
	titleText.appendChild(tx);
	titleText.className='titleTooltip';
	
	
	this.msgText = document.createElement("div");
	this.msgText.className = "pMsg";
	if (o.msg) {
		this.msgText.innerHTML = o.msg;
	}
	titleText.appendChild(this.msgText);
	
	this.title.appendChild(titleText);
	
	this.msg.innerHTML = ""; // clear -> do more eleguante later
		
	this.content = document.createElement("div");
	this.content.className = "apForm";
	//this.msgText = document.createElement("div");
	//this.content.appendChild(this.msgText);
	
	this.msg.appendChild(this.content);
	
	
	var btOk = this.button("Ok", function(e){ 
		var node = apGetTarget(e);
		node.win.removeWindow();
	},true);
	
	btOk.win = this;
	//btOk.callBack = o.callBack;
	this.bts.appendChild(btOk);
	this.content.appendChild(this.bts);
	this.msg.appendChild(this.content);

	this.displayMessage = function (m){
		this.msgText.innerHTML = m;
	}
	
	
	this.closeWindow = function (d){
		if (d) {
			//progressWindow_Window = this;
			//this.tcount = setTimeout(progressWindow_removeWindow,d);
		} else {
			this.removeWindow();
			
		}
	}

	
	var btClose = document.createElement("a");
	btClose.className='btClose';
	
	btClose.win = this;
	addEvent(btClose,"click",function(e){
		var node = apGetTarget(e);
		node.win.removeWindow();
	});
	
	this.title.appendChild(btClose);

	
	return this;
}

var progressWindow_Window;
function progressWindow_removeWindow(){
	progressWindow_Window.removeWindow();
}

apGui.prototype.rubWindow = function(o){

	var selects = new Array();

	//print_r(o);
	
	//this.callBack = o.callBack;
	var w = {id:o.id};
	this.window(w);
	this.form = o.form;
	
	
	var tx = document.createTextNode(o.title);
	var help = document.createTextNode(o.help);
	var titleText = document.createElement("div");
	var p = document.createElement("p");
	p.className = "pHelp";
	titleText.appendChild(tx);
	p.appendChild(help);
	titleText.appendChild(p);
	titleText.className='titleHelp';
	
	this.title.appendChild(titleText);
	
	this.msg.innerHTML = ""; // clear -> do more eleguante later
	this.msg.appendChild(this.form);
	
	var btOk = this.button("Valider", function(e){ 
		var node = apGetTarget(e);
		node.callBack(node.win.form);
		node.win.removeWindow();
		
	},true);
	
	btOk.win = this;
	btOk.callBack = o.callBack;
	this.bts.appendChild(btOk);
	
	var btKo = this.button("Annuler", function(e){
		var node = apGetTarget(e);
		node.callBack(false);
		node.win.removeWindow();
		
	},false);
	
	btKo.win = this;
	
	btKo.callBack = o.callBack;
	this.bts.appendChild(btKo);
	this.form.appendChild(this.bts);
	
	var btClose = document.createElement("a");
	btClose.className='btClose';
	
	btClose.win = this;
	addEvent(btClose,"click",function(e){
		var node = apGetTarget(e);
		node.win.removeWindow();
	});
	
	this.title.appendChild(btClose);
	
	//o.update();
	
	//this.body.appendChild(this.bts);
	
}


apGui.prototype.divWindow = function(o){

	var selects = new Array();

	//print_r(o);
	
	//this.callBack = o.callBack;
	var w = {id:o.id + "_gui"};
	this.window(w);
	this.div = o.div;
	
	if (!o.action) o.action = 'confirm';
	
	
	var tx = document.createTextNode(o.title);
	var help = document.createTextNode(o.help);
	var titleText = document.createElement("div");
	var p = document.createElement("p");
	p.className = "pHelp";
	titleText.appendChild(tx);
	p.appendChild(help);
	titleText.appendChild(p);
	titleText.className='titleHelp';
	
	this.title.appendChild(titleText);
	
	this.msg.innerHTML = ""; // clear -> do more eleguante later
	this.msg.appendChild(this.div);
	
	//this.msg.innerHTML = "torotototo";
	if (o.action == 'confirm') {
		var btOk = this.button("Valider", function(e){ 
			var node = apGetTarget(e);
			node.callBack(node.win.div);
			node.win.removeWindow();
			
		},true);
		btOk.win = this;
		btOk.callBack = o.callBack;
		this.bts.appendChild(btOk);	
	
		var btKo = this.button("Annuler", function(e){
			var node = apGetTarget(e);
			node.callBack(false);
			
			node.win.removeWindow();
			
		},false);
		btKo.win = this;
		btKo.callBack = o.callBack;
		this.bts.appendChild(btKo);
	}
	else if (o.action == 'close') {
		var btOk = this.button("Fermer", function(e){ 
			var node = apGetTarget(e);
			node.callBack(node.win.div);
			node.win.removeWindow();
			
		},true);
		btOk.win = this;
		btOk.callBack = o.callBack;
		this.bts.appendChild(btOk);	
	}
	else if (o.action == 'none') {
		
	}
	this.div.appendChild(this.bts);
	
	var btClose = document.createElement("a");
	btClose.className='btClose';
	btClose.win = this;
	
	addEvent(btClose,"click",function(e){
		var node = apGetTarget(e);
		node.win.removeWindow();
	});
	
	this.title.appendChild(btClose);
	
	//o.update();
	
	//this.body.appendChild(this.bts);
	
}


apGui.prototype.confirmWindow = function(o){

	var selects = new Array();

	//print_r(o);
	
	//this.callBack = o.callBack;
	var w = {id:o.id};
	this.window(w);
	this.form = document.createElement("div");
	this.form.style.padding='5px 20px';
	
	var tx = document.createTextNode(o.title);
	var help = document.createTextNode(o.help);
	var titleText = document.createElement("div");
	var p = document.createElement("p");
	p.className = "pQuestion";
	titleText.appendChild(tx);
	p.appendChild(help);
	titleText.appendChild(p);
	titleText.className='titleHelp';
	
	this.title.appendChild(titleText);
	
	this.msg.innerHTML = ''; // clear -> do more eleguante later
	this.msg.appendChild(this.form);
	
	var btOk = this.button("Valider", function(e){ 
		var node = apGetTarget(e);
		node.callBack(node.win.form);
		node.win.removeWindow();
		
	},true);
	
	btOk.win = this;
	btOk.callBack = o.callBack;
	this.bts.appendChild(btOk);
	
	var btKo = this.button("Annuler", function(e){
		var node = apGetTarget(e);
		node.callBack(false);
		node.win.removeWindow();
		
	},false);
	
	btKo.win = this;
	
	btKo.callBack = o.callBack;
		this.bts.settings = o.settings;
	this.bts.appendChild(btKo);
	this.form.appendChild(this.bts);
	
	var btClose = document.createElement("a");
	btClose.className='btClose';
	
	btClose.win = this;
	addEvent(btClose,"click",function(e){
		var node = apGetTarget(e);
		node.win.removeWindow();
	});
	
	this.title.appendChild(btClose);
	

	//this.body.appendChild(this.bts);
	
}

apGui.prototype.yesNoWindow = function(o){

	var selects = new Array();

	//print_r(o);
	
	//this.callBack = o.callBack;
	var w = {id:o.id};
	this.window(w);
	this.form = document.createElement("div");
	this.form.style.padding='5px 20px';
	
	var tx = document.createTextNode(o.title);
	var help = document.createTextNode(o.help);
	var titleText = document.createElement("div");
	var p = document.createElement("p");
	p.className = "pQuestion";
	titleText.appendChild(tx);
	p.appendChild(help);
	titleText.appendChild(p);
	titleText.className='titleHelp';
	
	this.title.appendChild(titleText);
	
	this.msg.innerHTML = ''; // clear -> do more eleguante later
	this.msg.appendChild(this.form);
	if(o.html) this.form.appendChild(o.html);
	
	var btOk = this.button("Oui", function(e){ 
		var node = apGetTarget(e);
		node.callBack(node.win.form);
		node.win.removeWindow();
		
	},true);
	
	btOk.win = this;
	btOk.callBack = o.callBack;
	this.bts.appendChild(btOk);
	
	var btKo = this.button("Non", function(e){
		var node = apGetTarget(e);
		node.callBack(false);
		node.win.removeWindow();
		
	},false);
	
	btKo.win = this;
	
	btKo.callBack = o.callBack;
		this.bts.settings = o.settings;
	this.bts.appendChild(btKo);
	this.form.appendChild(this.bts);
	
	var btClose = document.createElement("a");
	btClose.className='btClose';
	
	btClose.win = this;
	addEvent(btClose,"click",function(e){
		var node = apGetTarget(e);
		node.win.removeWindow();
	});
	
	this.title.appendChild(btClose);
	

	//this.body.appendChild(this.bts);
	
}
*/
/*
----------------------------------
Shortcuts
----------------------------------
*/
function apToolTip(title, msg) {
		
	var winBody = new Object();
	winBody.id = "tooltipWindow";
	winBody.msg = title;
	winBody.content = document.createElement('p');
	winBody.content.innerHTML = msg;
	
	YAHOO.apBox.openNotifyBox(winBody);
	
}
