
// variables -------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------

var isIE = navigator.appName.indexOf("Microsoft") != -1;
var isIE4 = isIE && document.all;
var isIE5 = isIE && document.all && document.getElementById;
var isIENew = isIE5;
var isNS4 = document.layers;
var isNS6 = document.getElementById && !document.all; 
var isNSNew = isNS6;
var isBrCompl = document.getElementById;
var isPlatformMac = navigator.platform.indexOf('Win') < 0;

window.defaultStatus = "Vides Filmu Studija";

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) {
	if(!w) w = 640;
	if(!h) h = 480;
	if(!wndName) wndName = _calcWndIdent();
	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);
	if(wnd) _centerWindow(wnd, w, h);
	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 openPrintWnd(url) {
	openWnd(url, 692, 400);
}

function openImage(imId, imPath, imWidth, imHeight, sOpener, caption) {
	//alert(imId + ": " + imPath + ", " + imWidth + " x " + imHeight + " - " + sOpener);
	if(sOpener == "FILE")
		window.location = "vfs/download_file.php?iid=" + imId;
	else if(sOpener == "OPEN")
		openWnd("vfs/download_file.php?disposition=inline&iid=" + imId, screen.availWidth - 50, screen.availHeight - 50, "imPreview" + imId, false);
	else {
		var capW = 34; //30;
		var capH = 34; //90;
		var w = imWidth ? (parseInt(imWidth) + capW) : 400;
		var h = imHeight ? (parseInt(imHeight) + capH) : 300;
		//if(w < 400) w = 400;
		var loc = "vfs/view_image.php?id=" + imId + "&ww=" + w + "&wh=" + h;
		//if(caption) loc += "&caption=" + caption; // ** sould be url-encoded ** (encodeURIComponent ? encodeURIComponent(caption) : escape(caption));
		openWnd(loc, w, h, "imPreview" + imId, true);
	}
}


// other functions -------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------

function getOffsetCoords(obj) {
	realC = new Object();
	realC.top = obj.offsetTop;
	realC.left = obj.offsetLeft;
	
	while(obj.offsetParent.nodeName != 'BODY') {
		obj = obj.offsetParent;
		realC.top += obj.offsetTop;
		realC.left += obj.offsetLeft;
	}
	
	realC.width = obj.offsetWidth;
	realC.height = obj.offsetHeight;
	
	return realC;
}


