//
// Page.js - Gestión general de la página y sus diálogos
//
// $Id: page.js 1.8 2008/10/14 13:39:39 jordinas Exp $
//
// Joan Ordinas - <jordinas@EscolaDelTreball.ORG>
//

//========================================================================

//
function _Page(sLang, sBase) {
	function State_save() { State.save(); }

	this.Language = sLang;
	this.Base = sBase;
	this.aExitFunctions = new Array();

	this.atexit(State_save);

	// cbc: CSS Browse Code
    if (navigator.userAgent.indexOf("X11") != -1) {
      this.cbc = "nix";
    } else if (navigator.userAgent.indexOf("Mac") != -1) {
      this.cbc = "mac";
    } else if (navigator.userAgent.indexOf("Win") != -1) {
      if (navigator.appVersion.indexOf("MSIE 5.") != -1) {
		this.cbc = "ie5";
      } else {
		this.cbc = "win";
      }
    } else { 
		this.cbc = "win";
    }
}

_Page.prototype.atexit = function(f) {
	this.aExitFunctions[this.aExitFunctions.length] = f;	// push
}

_Page.prototype.exit = function() { //<body onunload="Page.exit();">
	for (var i = this.aExitFunctions.length-1; i >= 0; --i) {
		this.aExitFunctions[i]();
	}
}

//========================================================================

// Para enviar correo a un usuario de la Escuela
_Page.prototype.openMailer = function(sTo) {
	var sURL;
	if (sTo.indexOf('@') != -1) {
		sURL = 'mailto:'+sTo;
	} else {
		sURL = 'mailto:'+sTo+"@correu.escoladeltreball.org";
	}
	if (!State.Session.mail) {
		var bOk = confirm(g_msg_mail);
		if (bOk) {
			State.Session.mail = true;
			location.href = sURL;
		}
	} else {
		location.href = sURL;
	}
}

_Page.prototype.openContact = function() {
	var sTo = "orientacio";
	var sPage = escape(location.href);
	this.openMailer(sTo+"@correu.escoladeltreball.org?"+'subject='+sPage+'&'+'body='+sPage);
}

//========================================================================

_Page.prototype.status = function() {
	window.status = g_msg_status;
	return true;
}

_Page.prototype.mstatus = function() {
	window.status = g_msg_mailer;
	return true;
}


