
// variables -------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------

var isIE4 = document.all;
var isIE5 = document.all && document.getElementById;
var isNS4 = document.layers;
var isNS6 = document.getElementById && !document.all; 
var isIENew = isIE5;
var isNSNew = isNS6;
var isIE = navigator.appName.indexOf("Microsoft") != -1;

window.defaultStatus = "LCCA";

function strltrim() { return this.replace(/^\s+/,''); }
function strrtrim() { return this.replace(/\s+$/,''); }
function strtrim() { return this.replace(/^\s+/,'').replace(/\s+$/,''); }
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;


// window functions -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------

function _calcWndIdent() {
	d = new Date();
	return "wnd" + d.getHours() + d.getMinutes() + d.getSeconds() + d.getMilliseconds();
}

function _centerWindow(wHandle, w, h) {
	posX = (screen.availWidth - w) / 2;
	posY = (screen.availHeight - h) / 2;
	wHandle.moveTo(posX, posY);
}

function openWnd(url, w, h, wndName, bNoScroll, x, y) {
	if(!w) w = 640;
	if(!h) h = 480;
	if(!wndName) wndName = _calcWndIdent();
	if(!(x || y)) {
		x = (screen.availWidth - w) / 2;
		y = (screen.availHeight - h) / 2;
	}
	wnd = window.open(url,wndName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + (bNoScroll ? "no" : "yes") + ",resizable=yes,width="+w+",height="+h + 
								  (x || y ? ',left='+x+',top='+y+',screenX='+x+',screenY='+y : ''));
	
	return wnd;
}

function openFullWnd(url) {
	wndName = _calcWndIdent();
	wnd = window.open(url,wndName,"toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes");
	return wnd;
}

function openImage(imId, imPath, imWidth, imHeight, sOpener, objTypeId, objId) {
	//alert(imId + ": " + imPath + ", " + imWidth + " x " + imHeight + " - " + sOpener);
	if(sOpener == "FILE")
		window.location = "/llmc/download_file.php?iid=" + imId;
	else if(sOpener == "OPEN")
		openWnd("/llmc/download_file.php?disposition=inline&iid=" + imId, screen.availWidth - 50, screen.availHeight - 50, "imPreview" + imId, false);
	else {
		if(imWidth > 1024 || imHeight > 768 && imPath) {
			openFullWnd(imPath);
			
		} else {
			
			var capW = 15; //30;
			var capH = 100; //90;
			var w = imWidth ? (parseInt(imWidth) + capW) : 400;
			var h = imHeight ? (parseInt(imHeight) + capH) : 300;
			//if(w < 400) w = 400;
			var loc = "/llmc/view_image.php?id=" + imId + "&ww=" + w + "&wh=" + h;
			if(sOpener != 'FLASH')
				loc += (objTypeId ? "&tid=" + objTypeId : "") + (objId ? "&oid=" + objId : "");
			//if(caption) loc += "&caption=" + caption; // ** sould be url-encoded ** (encodeURIComponent ? encodeURIComponent(caption) : escape(caption));
			//console.debug(loc);
			openWnd(loc, w, h, "imPreview" + imId, true);
		}
	}
}


// other functions -------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------




