// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		
		calendar.create();		// create a popup calendar
		calendar.parseDate(el.value); // set it to a new date
	}
	calendar.setDateFormat("%Y-%m-%d %H:%M:%S");
	calendar.setFirstDayOfWeek(1);
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}


function open_pic(pic_location, page_title, pic_width, pic_height) {
	var imgVar = new Image ();
	imgVar.src = pic_location;
	newWin = window.open ('', 'pic_window', 'height=' + pic_height + ',width=' + pic_width + 
		',top=20,left=20,resizable=no');
	newWin.document.write ('<html><head><title>' + page_title + '</title></head>');
	newWin.document.write ('<body style="margin: 0px; text-align: center; vertical-align: middle">');
	newWin.document.write ('<a href="javascript:window.close()"><img src="' + pic_location + '" height="' + 
		pic_height + '" width="' + pic_width + '" name="im" border="0"></a></body></html>');
	newWin.document.close ();
}
function automatic_submit(lang) {
	var els = self.content.document.forms[0].elements;
	for (i = 0; i < els.length; i++) {
		if (els[i].name == 'article') {
			self.content.document.forms[0].relocate_lang.value = lang.options[lang.selectedIndex].value;
			self.content.document.forms[0].submit();
		}
	}
}


function change_class(ID, oldClass, newClass) { 
	if (document.getElementById) {
		var el = document.getElementById(ID);
		var ar = document.getElementById('menu_div').getElementsByTagName('a');
		if (el.className == oldClass) {
			for (var i=0; i<ar.length; i++) {
				if (ar[i].className == newClass) {
					ar[i].className = oldClass;
				}
			}
			el.className = newClass;
		}
	} 
} 

function ask(message, url){
	if(confirm(message)) location.href = url;
}
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=300,left = 362,top = 84');");
}
document.onselectstart = new Function('return false');


