var Main = {
	bookmarkurl: "http://www.saips.it",
	bookmarktitle: "SAIPS.IT",
	baseHTTP: "http://www.saips.it/",

	init: function ()
	{
		this.bottomBar = document.getElementById ('bottomBar');
		if (this.bottomBar)
		{
			var s = this.bottomBar.style;

			if (navigator.userAgent.indexOf ("MSIE") > 0)
			{
				s.position = "absolute";
				window.setInterval ("Main.updateBottomBar ()", 25);
			}
			s.width = document.body.offsetWidth + 'px';
			s.display = 'inline';
		}
	},

	bottomBar: null,
	updateBottomBar: function ()
	{
		var b = document.body;
		this.bottomBar.style.top = (b.scrollTop + b.offsetHeight - 97) + "px";
	},

	WordLoaded: false,
	WordVisible: false,
	hideArray: false,
	loadWord: function (docId, contRefId, hideArray)
	{
		if (this.WordVisible)
		{
			document.getElementById ("WordLinkText").innerHTML = "Carica il modulo di scrittura testi...";
			this.unloadWord ();
			this.WordVisible = false;
			return;
		}

		document.getElementById ("WordLinkText").innerHTML = "Chiudi il modulo di scrittura testi...";
		if (!this.WordLoaded)
		{
			this.WordCont = MMLoader.create ("iframe");
			this.WordCont.style.height = '680px';
			this.WordCont.style.width = '750px';
			this.WordCont.id = contRefId;
			document.getElementById (contRefId).appendChild (this.WordCont);
			this.WordCont.src = "rmt_word.php" + user.get + "&d=" + docId;

			this.WordLoaded = true;
		}

		if (!this.hideArray)
			this.hideArray = hideArray;
		for (i in this.hideArray)
			document.getElementById (hideArray[i]).style.display = 'none';

		this.WordVisible = true;
		this.WordCont.style.display = 'inline';
	},
	unloadWord: function ()
	{
		this.WordCont.style.display = 'none';

		for (i in this.hideArray)
			document.getElementById (this.hideArray[i]).style.display = 'inline';
	},

	switchDisplay: function (id)
	{
		var el = document.getElementById (id);

		if (typeof (el.oldStyleDisplay) != 'undefined')
			var oldDis = el.oldStyleDisplay;
		else
			var oldDis = false;

		el.oldStyleDisplay = el.style.display;

		if (el.style.display == 'none')
		{
			if (oldDis)
				el.style.display = oldDis;
			else
				el.style.display = 'inline';
		}
		else
		{
			if (oldDis)
				el.style.display = oldDis;
			else
				el.style.display = 'none';
		}
	},

	checkMail: function (email)
	{
		if (email == "")
			return 0;
		else if (email.length < 8)
			return 1;
		else
		{
			var regExp = /([a-z0-9_\-\.]+)@([a-z0-9_\-\.]+)\.([a-z0-9_\-\.]+)/gi;
			if (!regExp.test (email))
				return 1;
		}

		return -1;
	},
	checkMailAndSubmit: function (email)
	{
		var res = this.checkMail (email);
		if (res >= 0)
		{
			alert (dict.checkMail[res]);
			return false;
		}
		return true;
	}
};


var PImg = {
	staffBaseDir: 'http://www.saips.it/images/user/',
	Images: new Object (),
	gImages: new Object (),
	types: {
		'A': 'abstract/',
		'L': 'logos/',
		'S': 'staff/',
		'M': 'menu/'
	},
	SLink: "_l",
	SOver: "_o",
	defExt: ".gif",


	registerImages: function ()
	{
		var i = 0, l = arguments.length;

		while (i < l)
		{
			this.registerImage (arguments[i]);
			i++;
		}
	},
	registerImage: function (id)
	{
		var type = id.charAt (0);
		var srcL = this.baseDir + this.types[type] + id + this.SLink + this.defExt;
		var srcO = this.baseDir + this.types[type] + id + this.SOver + this.defExt;
		var img = new Image;
		img.src = srcO;

		this.Images[id] = {
			id: id,
			srcL: srcL,
			srcO: srcO,
			img: img
		};
	},
	registerStaffImage: function ()
	{
		var imgA, img, srcL, srcO;
		var baseDir = this.staffBaseDir, imgs = this.Images;
		var i = 0, l = arguments.length, SOver = "_o", defExt = ".gif";

		while (i < l)
		{
			imgA = arguments[i]; // [uId, type, imgId]
			srcL = baseDir + Math.floor (imgA[0] / 1000) + "/" + imgA[0] + "_" + imgA[1] + defExt;
			srcO = baseDir + Math.floor (imgA[0] / 1000) + "/" + imgA[0] + "_" + imgA[1] + SOver + defExt;
			img = new Image;
			img.src = srcO;

			imgs[imgA[2]] = {
				id: imgA[2],
				srcL: srcL,
				srcO: srcO,
				img: img
			};
			i++;
		}
	},
	registerGImages: function ()
	{
		var id, type, src, img;
		var baseDir = this.baseDir, types = this.types, gimgs = this.gImages;
		var i = 0, l = arguments.length, defExt = ".gif";

		while (i < l)
		{
			id = arguments[i];
			type = id.charAt (0);
			src = baseDir + types[type] + id + defExt;
			img = new Image;
			img.src = src;

			gimgs[id] = {
				id: id,
				src: src,
				img: img
			};

			i++;
		}
	},

	setG: function (elemId, imageId)
	{
		if (typeof (this.gImages[imageId]) != 'undefined')
			document.getElementById (elemId).src = this.gImages[imageId].src;
		else if (typeof (this.gImages[imageId.substr (2)]) != 'undefined')
			document.getElementById (elemId).src = this.gImages[imageId.substr (2)].src;
	},
	rOver: function (imageId)
	{
		if (this.Images[imageId] == undefined)
			PImg.registerImage (imageId);

		// if (typeof (this.Images[imageId]) != 'undefined')
			document.getElementById (imageId).src = this.Images[imageId].srcO;
	},
	rOut: function (imageId)
	{
		if (this.Images[imageId] == undefined)
			PImg.registerImage (imageId);

		// if (typeof (this.Images[imageId]) != 'undefined')
			document.getElementById (imageId).src = this.Images[imageId].srcL;
	}
};

var PTxt = {
	set: function ()
	{
		var i = 0, id, txt;
		while (i < arguments.length)
		{
			id = arguments[i];
			txt = arguments[i + 1];
			document.getElementById (id).innerHTML = txt;
			i += 2;
		}
	},
	unset: function ()
	{
		var i = 0, id;
		while (i < arguments.length)
		{
			id = arguments[i];
			document.getElementById (id).innerHTML = '';
			i++;
		}
	}
};

function openNewsLetter (userGet, nlId)
{
	if (nlId == 'null')
		return;
	if (userGet == '')
		userGet = "?&";

	window.open (Main.baseHTTP + userGet + 'p=17' + (typeof (nlId) != 'undefined' ? '&e=' + nlId : ''), 'newsletter', "width=718,scrollbars=yes,resizable=yes,status=no,location=no");
}

function MM_openBrWindow (theURL, winName, features) {
	window.open (theURL, winName, features);
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function preferiti ()
{
	if (document.all)
		window.external.AddFavorite (Main.bookmarkurl, Main.bookmarktitle);
}
function homepage ()
{
	if (document.all)
		document.body.style.behavior = 'url(#default#homepage)';

	try {
		document.body.setHomePage ('http://www.saips.it');
	} catch (e) {}
}
