//
// $Id: main.js 48 2008-02-09 23:37:31Z claudio.felber $
//
// Javascript code used throughout the website.
//
// Author: Claudio Felber (claudio.felber@perron2.ch)
// Created: 2002-12-12
//
// Copyright (c) 2002-2008, Perron2 GmbH, All Rights Reserved.
//

$(document).ready(function() {
	var labels = $('table.shaded th');
	var maxwidth = 0;
	labels.each(function() {
		var width = $(this).width();
		if (width > maxwidth) {
			maxwidth = width;
		}
    });
	labels.width(maxwidth - 10);
});

function question(question, action) {
	if (confirm(question)) {
		location = action;
	}
}

function button(name) {
    document.forms[0].elements.action.value = name;
    document.forms[0].submit();
}

function longSubmit() {
//	var progress = document.getElementById('progress');
//	progress.style.display = 'block';
	document.forms[0].submit();
}

function progress() {
	var progress = document.getElementById('progress');
	progress.style.display = '';
	alert('Hossa');
	return true;
}

function maxpopup(url) {
    var width = 600;
    var height = 440;

    if (screen.width > 800) {
        width = 800
        height = 600;
    }

    popup(url, width, height);
}

function popup(url, width, height) {
    var left = 10;
    var top = 10;

    var features = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',' +
        'scrollbars=yes,resizable=yes,location=no,directories=no,status=no,menubar=no';

    win = open(url, 'popup', features);
    setTimeout('win.focus();', 250);
}

function picture(name, width, height) {
    var features = 'width=' + width + ',height=' + height + ',left=10,top=10';

    win = window.open('', 'popup', features);

    win.document.open();
    win.document.write('<html><head><title>Bild</title></head>');
    win.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
    win.document.write('<img src="' + name + '" width="' + width + '" height="' + height + '" onClick="self.close()">');
    win.document.write('</body>');
    win.document.write('</html>');
    win.document.close();

    win.focus();
    setTimeout('win.focus();', 250);
}

function focusControl(control) {
	var elem = null;

	if (typeof(control) == 'string') {
		elem = document.getElementById(control);
		if (elem == null) {
			for (var i = 0; i < document.forms.length; i++) {
				for (var j = 0; j < document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].name == control) {
						elem = document.forms[i].elements[j];
						break;
					}
				}
			}
		}
	}

	if (elem == null) {
		if (document.forms[0]) {
			for (var i = 0; i < document.forms[0].elements.length; i++) {
				var elem = document.forms[0].elements[i];
				if (elem.type == 'text' || elem.type == 'select-one' || elem.type == 'textarea' || elem.type == 'radio' || elem.type == 'checkbox') {
					break;
				}
			}
		}
	}
	
	if (elem != null) {
		elem.focus();
		if (elem.type == 'text') {
			elem.select();
		}
	}
}