function MM_openBrWindow(theURL, winName, features) { // v2.0
	window.open(theURL, winName, features);
}

// prevalue
function fieldClear(obj, text) {
	if (text != null && !obj.first) {
		obj.value = text;
	}
	if (obj.Val) {
		if (obj.value == '') {
			obj.value = obj.Val;
			obj.Val = null;
			obj.first = null;
			obj.style.color = '#BFBFBF';
		} else {
			obj.Val = '';
		}
	} else if (!obj.first) {
		if (text) {
			obj.value = text;
		} else
			obj.value = '';
		obj.Val = obj.value;
		obj.first = true;
		obj.style.color = 'black';
	}
}

// limit textarea
function maxLength(obj, max) {
	if (obj.value.length > max - 1)
		obj.value = obj.value.substring(0, max - 1);
}

// confim deletion
function confirmDelete(text, location) {
	check = confirm(text);
	if (check == true)
		window.location = location;
	else
		return false;
}

// redirect to other page
function redirect(page) {
	var time;
	for (time = 1000; time < 6000; time = time + 1000) {

		var timer = 5 - (time / 1000);
		setTimeout("$('out').innerHTML=" + timer, time);
	}
	setTimeout("window.location.href=\'" + page + "\'", 5000);
}

// get window name for different openers
function getWindowName(name) {
	if (name != "")
		return window.opener.name;
	else
		return 'home';
}

// clear input fields
function clearFields() {
	for ( var i = 0; i < clearFields.arguments.length; i++) {
		$(clearFields.arguments[i]).value = '';
	}
}

// change title when typing into input field
function changeTitle(tmpID, value, def) {
	$(tmpID).innerHTML = value;
	if (value == '')
		$(tmpID).innerHTML = def;
}

function getAdjustedImage(url) {
	var image = new Image();
	image.src = url;
	var ratio = image.width / image.height;

	if (ratio > 1) { // landscape
		var width = 150;
		var height = (width * image.height) / image.width;
	} else if (ratio < 1) { // portrait
		var height = 150;
		var width = (image.width * height) / image.height;
	} else {
		var height = 150;
		var width = 150;
	}
	return '<img src="' + url + '" alt="" width="' + Math.round(width)
			+ '" height="' + Math.round(height) + '" />';
}

function imageExists(url) {
//	var image = new Image();
//	image.src = url;
//	if (typeof image.naturalWidth != "undefined")
//		return false;
//	else
		return true;
}