/**
* alert message stuff
*/
function showAlertMessage(alertText)
{
	var newText = '';
	if (alertText == null) {
		alertText = '';
	}
	while (newText != alertText) {
		newText = alertText;
		alertText = alertText.replace("\r\n", "<br />");
		alertText = alertText.replace("\n", "<br />");
		alertText = alertText.replace("\r", "<br />");
	}
	document.getElementById('alertText').innerHTML = alertText;	
	document.getElementById('alertBoxLayer').style.display='block';
	document.getElementById('alertButton').style.display='block';
	var h = document.getElementById('alertText').clientHeight;
	if (h != 0) {
		document.getElementById('alertBox').style.height = (h+48)+"px";
		var h1 = document.getElementById('alertBox').clientHeight;
	}
	if (window.reDisplaySelectboxes)
	{
		reDisplaySelectboxes();
	}
}
function hideAlertMessage()
{
	document.getElementById('alertBoxLayer').style.display='none';
	document.getElementById('alertButton').style.display='none';
	document.getElementById('confirmButton').style.display='none';
	if (window.reDisplaySelectboxes)
	{
		reDisplaySelectboxes();
	}
}
function conflictWithAlertLayer(left, width, top, height)
{
	var layerLeft = document.getElementById('alertBox').offsetLeft;
	var layerTop = document.getElementById('alertBox').offsetTop + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	var layerWidth = document.getElementById('alertBox').offsetWidth;
	var layerHeight = document.getElementById('alertBox').offsetHeight;
	//window.status = ((layerLeft < left && layerTop < top && layerLeft + layerWidth > left && layerTop + layerHeight > top) 				 + " " + 				(layerLeft < left + width && layerTop < top && layerLeft + layerWidth > left + width && layerTop + layerHeight > top) 				 + " " + 				(layerLeft < left + width && layerTop < top + height && layerLeft + layerWidth > left + width && layerTop + layerHeight > top + height) 				 + " " +  (layerLeft < left && layerTop < top + height && layerLeft + layerWidth > left && layerTop + layerHeight > top + height) + " " + layerTop+ " " + top + " "  + height);

	return (layerLeft < left && layerTop < top && layerLeft + layerWidth > left && layerTop + layerHeight > top
			||
			layerLeft < left + width && layerTop < top && layerLeft + layerWidth > left + width && layerTop + layerHeight > top
			||
			layerLeft < left + width && layerTop - 18 < top + height && layerLeft + layerWidth > left + width && layerTop + layerHeight > top + height
			||
			layerLeft < left && layerTop - 18 < top + height && layerLeft + layerWidth > left && layerTop + layerHeight > top + height
			);
	//return document.getElementById('alertBoxLayer').style.display == 'block';
}

function resizeAndCropImage(img) {
	if (img) {
		var w = img.width;
		var h = img.height;
		img.style.height = 'auto';
		var h2 = img.height;
		var diff = h2 - h;
		if (diff != 0) {
			img.style.position = 'absolute';
			if (diff > 0) {
				var offsetTop = Math.round(diff / 2);
				var offsetBottom = diff - offsetTop;
				img.style.clip = 'rect(' + offsetTop + 'px, auto, ' + (h2 - offsetBottom) + 'px, auto)';
				var m = parseInt(img.style.marginTop);
				if (!m) {
					m = 0;
				}
				img.style.marginTop = (m - offsetTop) + 'px';
			} else {
				img.style.height = h + 'px';
				img.style.width = 'auto';
				var w2 = img.width;
				diff = w2 - w;
				if (diff > 0) {
					var offsetLeft = Math.round(diff / 2);
					var offsetRight = diff - offsetLeft;
					img.style.clip = 'rect(auto, ' + (w2 - offsetRight) + 'px, auto, ' + offsetLeft + 'px)';
					var m = parseInt(img.style.marginLeft);
					if (!m) {
						m = 0;
					}
					img.style.marginLeft = (m - offsetLeft) + 'px';
				} else {
					img.style.width = w + 'px';
				}
			}
		}
		img.onload = function() {};
	}
}

