/* M$M$2$M$M
This file is part of Mooffanka, a Web Content Management System
Copyright (C) 2000-2005 Francesco Sullo, email: sullof@sullof.com, Rome/Italy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mooffanka; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
For further information about Mooffanka: www.mooffanka.org
*/

var uGe = navigator.userAgent.toLowerCase().indexOf('gecko') != -1 ? 1 : 0
//uGe = 1

getElement = document.all ?
	function (idiv) { return document.all[idiv]} :
	function (idiv) { return document.getElementById(idiv)};

function showHiddenDiv() {
	var div
	for (var j=0;j<arguments.length;j+=2) {
		div = getElement(arguments[j])
		div.style.display = arguments[j+1]
	}
}

function confirmAndGo(x,y) {
	if (confirm(x)) self.location = y
}

function mooFileDownload(src,ext,w,h,alt) {
	window.open(src+(ext?"&showPage="+ext+"&nameOf="+alt:""),'','resizable=1,scrollbars=1,statusbar=1,menubar=1'+(w?',width='+(w+50)+',height='+(h+60):''))
}

function mooPopUpOpen(src,name,w,h,r,ns) {
	window.open(src,name,'resizable='+(r?1:0)+',scrollbars='+(ns?0:1)+(w?',width='+w:'')+(h?',height='+h:''))
}


function runTool(w,h,n,i,s) {
	eval("run_tool"+(i?i:'')+" = window.open(n,'run_tool"+(i?i:'')+"',' width='+(w?w:500)+', height='+(h?h:500)+', location=0, menubar=0, personalbar=0, resizable=1, toolbar=0, status=0,scrollbars=0')")
	eval("run_tool"+(i?i:'')+".focus()")
}

var QS = location.search.replace(/\?/,"").split("&")
var GET = []
for (var i=0;i<QS.length;i++) {
	var CQS = QS[i].split('=')
	GET[CQS[0]] = CQS[1]
}

if (GET['alert']) alert(unescape(GET['alert']))

function scanObject(x,y) {
	var s = [], v = []
	v[0] = window.innerWidth
	for (var i in x) {
		var e = i
		if (e.toLowerCase().indexOf('width') != -1) v[v.length] = i + " = "+x[i]
	}
	v.sort()
	alert(v.join(" // "))
}

var helpStatus = false

function setDiv() {
	if (opener) {
		var idiv = getElement('tbody')
		var tdiv = getElement('thelp')
//		FWinW=document.documentElement && document.documentElement.clientWidth?document.documentElement.clientWidth:document.all?document.body.clientWidth:window.innerWidth;
//		FWinH=document.documentElement && document.documentElement.clientHeight?document.documentElement.clientHeight:document.all?document.body.clientHeight:window.innerHeight;
		FWinW=document.all?document.body.clientWidth:window.innerWidth
		FWinH=document.all?document.body.clientHeight:window.innerHeight
		idiv.style.width = (FWinW+(uGe?-22:0))+"px"
		tdiv.style.width = (FWinW+(uGe?-22:0))+"px"
		if (!helpStatus) {
			idiv.style.height = (FWinH-20+(uGe?-22:0))+"px"
			tdiv.style.height = 0
			tdiv.style.top = FWinH
			tdiv.style.border = "0px"
		}
		else {
			FWinH = FWinH - 100
			idiv.style.height = (FWinH-20+(uGe?-22:0))+"px"
			tdiv.style.height = 100+(uGe?-22:0)+"px"
			tdiv.style.display = 'block'
			tdiv.style.top = FWinH
			tdiv.style.border = "#E2D7B3 solid 3px"
		}
	}
}

var mom_tool
function momTool(w,h,x,s) {
	var set =
		s ? ',location=0, menubar=1, 	personalbar=0, resizable=1, toolbar=0, status=1, scrollbars=1'
		: ',location=0, menubar=0, 	personalbar=0, resizable=1, toolbar=0, status=0, scrollbars=0'
	if (x && mom_tool && !mom_tool.closed && mom_tool.location) { 
		try {mom_tool.location = x }
		catch(e) {
			try { mom_tool.close() }
			catch(e) {}
			mom_tool = null
			mom_tool = window.open(x+"&noBack=1",'mom_tool','top=80,left=80,width='+w+',height='+h+set)
		}
		mom_tool.focus()
	}
	else if (x && !mom_tool) { mom_tool = window.open(x+"&noBack=1",'mom_tool','top=80,left=80,width='+w+',height='+h+set); mom_tool.focus() }
	else if (mom_tool) {
		if (!mom_tool.closed) mom_tool.close()
		mom_tool = null
	}
}

function close_edit_tool() {
	if (GET["$closeDirectly"] || self != top) {
		top.close()
	}
	else if (self == top) {
		try {
			if (window == opener.mom_tool) {
				opener.momTool()
				opener.focus()
			}
			else if (opener.top.toolbar) {
				if (window == opener.edit_tool) { 
					opener.top.toolbar.park_edit_tool()
					opener.top.editedDoc.focus()
				}
				else top.close()
			}
		}
		catch(e) { top.close() }
	}
}


function noGoBack() {
	alert(noBackMsg)
}


function helpTool(x) {
	momTool(500,500,x,1)
}


function checkNoWcms() {
	if (GET.$wcms && self != top) top.location = self.location.toString().replace(/\$wcms\=/,"noWcms=")
}