// --------------------------------------------------------------------
// Norme de packaging : 1.0.6
// Nom du package - Package name : cultural-heritage-laws-database
// Nom du programme - Program Name : utils.js
// Auteurs - Authors :
// - THRIERR Eric eric@excellent-rameur.com
// Version : 0.0.2
// Description : javascript de fonctions utilitaires
// Historique - History :
// - 2006-12-01 / Eric Thrierr / fichier initial
// - 2008-11-20 / Eric Thrierr / deplacement de la fonction utils.reset dans search.js
// --------------------------------------------------------------------
// $Id: utils.js,v 1.2 2008/12/05 14:11:00 uid1012 Exp $
String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}
function switchLanguage(lang) {
	  utils.changeLang("lng", lang);
}
var utils = new Object();
utils.init = function() {
	this.form = document.natlawsDbForm;
	if (this.form.elements["documents[]"]) {
		if (this.form.elements["documents[]"][1]) this.changeDocuments(this.form.elements["documents[]"][1]);
	}
}
utils.onload = (window.onload) ? window.onload : function () {};
window.onload = function () {utils.onload(); utils.init()};
utils.changeLang = function (element, lang) {
	if (this.form.elements["search"]) this.form.change.value = "lang";
	this.form.elements[element].value = lang;
	this.form.submit();
}
utils.changeSelect = function (node) {
	if (node.options[0].selected) for (var i = 1; i < node.options.length; i++) node.options[i].selected = false;
	return true;
}
utils.newSearch = function () {
	this.form.change.value = "search";
	this.form.criteria.value = "";
	this.form.submit();
}
utils.changeSearch = function () {
	this.form.change.value = "search";
	this.form.submit();
}
utils.changeColumns = function () {
	this.form.change.value = "columns";
	this.form.submit();
}
utils.changePageSize = function () {
	this.form.newsize.value = this.form.pagesize.options[this.form.pagesize.selectedIndex].value;
	this.form.submit();
}
utils.showPage = function (page) {
	this.form.show.value = page;
	this.form.submit();
}
utils.changeDocuments = function (node) {
	var transtypes = document.getElementById("natlawsDbTranstypes");
	if (node.checked) transtypes.className = "transtypes";
	else transtypes.className = "natlaws-display-none";
}
utils.changeSort = function (sort) {
	this.form.sort.value = sort;
	this.form.change.value = "sort";
	this.form.submit();
	return false;
}

utils.changeImg = function (image, source) {
	document[image].src = source;
	return true;
}
utils.view = function (node, id, width, height) {
	return utils.popup (node, "view" + id, "scrollbars,resizable,width=" + width + ",height=" + height);
}
utils.help = function (node, width, height) {
	return utils.popup (node, "help", "scrollbars,resizable,width=" + width + ",height=" + height);
}
utils.contactlink = function (node, width, height) {
	return utils.popup (node, "contactlink", "scrollbars,resizable,width=" + width + ",height=" + height);
}
utils.disclaimer = function (node, width, height) {
	return utils.popup (node, "disclaimer", "scrollbars,resizable,width=" + width + ",height=" + height);
}
utils.popup = function (url, name, features) {
	if (features) {
		var width = parseInt (features.replace(/.*width=/, ""));
		var height = parseInt (features.replace(/.*height=/, ""));
		var newWindow = window.open(url, name, features);
		if (width && height && window.resizeTo) newWindow.resizeTo (width, height);
		if (window.moveTo) newWindow.moveTo(0,0);
	} else var newWindow = window.open(url, name);
	newWindow.focus();
	return false;
}
utils.removeClassName = function(elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}
utils.addClassName = function(elem, className) {
	utils.removeClassName(elem, className);
	elem.className = (elem.className + " " + className).trim();
}
utils.toggle = function (node, id) {
	var element = document.getElementById(id);
	if (element.className.indexOf("display-none") >= 0) {
		utils.removeClassName(element, "display-none");
		utils.addClassName(element, "display-block");
		utils.addClassName(node, "unfolded");
	} else {
		utils.removeClassName(element, "display-block");
		utils.addClassName(element, "display-none");
		utils.removeClassName(node, "unfolded");
	}
}
