<!-- common functions :::
// written or changed by Vady.
// vady@i.com.ua

// 2use popup() function: <a href="javascript:;" onClick="javascript:popup('name', '#link', 0, 0, 300, 150, 0, 0, 1, 1, 1); return false;"></a>

function popup(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable, maxscreen){
	var _openedwin;
	var wint = (screen.height - height) / 2;
	var winl = (screen.width - width) / 2;
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
	var winstatscoordinates = (navigator.appName.indexOf("Microsoft")>=0)?',left=0,top=0':',screenX=0,screenY=0';
	var winh = (navigator.appName.indexOf("Microsoft")!=-1)?document.body.offsetHeight:window.innerHeight;
	var winw = (navigator.appName.indexOf("Microsoft")!=-1)?document.body.offsetWidth:window.innerWidth;
	
	if(maxscreen) {
		_openedwin = window.open(url, name, 'width='+(winw-20)+',height='+winh+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str+winstatscoordinates);	
	} else {
		_openedwin = window.open(url, name, 'left='+winl+',top='+wint+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
	}
}

function maximize() {
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	} else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

function restore() {
	obj.src = obj.lsrc;
}

function cl(id,what) {
	var im;
	im = findObj(id,'');
	im.src = "images/" + what;
}

function change(id,src) {
	var lsrc;
	obj = findObj(id,'');
	if (!src) src = id + "-o.gif";
	if(!obj.lsrc) obj.lsrc = obj.src;
	obj.src = src;
}

function preloadImgs() {
	var d = document;
	if(d.images) {
		if(!d.IMGs) d.IMGs=new Array();
		var i,j=d.IMGs.length,a=preloadImgs.arguments;
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){
		d.IMGs[j]=new Image; d.IMGs[j++].src = a[i];
		}
	}
}

function findObj(n, d) { //v4.01
	var p,i,x;	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function mOvr(src,img,over) {
	if(!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.className = 'momenu';
	}
	change(img,over);
}

function mOut(src) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.className = 'mmenu';
	}
	restore();
}

function mClk(src) {
	if (event.srcElement.tagName == 'TD') {
		src.children.tags('A')[0].click();
	}
}

function urlencode(ch) {
   ch = ch.replace(/[ ]/g,"+") 
   return escape(ch) 
}
function urldecode(ch) {
   ch = ch.replace(/[+]/g," ")
   return unescape(ch)
}

function popupimg(name, url, width, height){
	var imgss;
	winl = (screen.width) ? (screen.width - width) / 2 : 0;
	wint = (screen.height) ? (screen.height - height) / 2 : 0;
	var winname = urlencode(name);
	var settings = 'left='+winl+',top='+wint+',width='+width+',height='+height+',toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes';
	myimgss = window.open('','imgpoint',settings);
	myimgss.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><title>'+urldecode(winname)+' // gallery @ deborah.com.ua</title></head><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table height="100%" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><a href="javascript:self.close();"><img src="'+url+'" name="fullbimg" alt="Нажмите, чтобы закрыть окно..." width="'+width+'" height="'+height+'" border="0"></a></td></tr></table></body></html>');
	if(myimgss.window.focus) {
		myimgss.window.focus();
	}
}

function _open(lnk) {
	if(window.opener) {
		window.opener.location.href = lnk;
		window.opener.focus();
	} else {
		var _opensnewwin = window.open(lnk, "_blank", "");
		_opensnewwin.focus();
	}
}

function openImg(id, img, name, desc, lang){
//	var winl = (screen.width) ? (screen.width - 200) / 2 : 0;
//	var wint = (screen.height) ? (screen.height - 60) / 2 : 0;
	name = (name == '') ? '#'+Math.floor(Math.random(23543)*5000) : name;
	desc = (desc == '') ? '' : desc;
	var opener_link ='/openfile.php?id='+id+'&img='+img+'&l='+lang+'&n='+name+'&d='+desc;
	var windowPIC = window.open(opener_link,urlencode(img),'left=0,top=0,height=100,width=200,toolbar=no,location=no,fullscreen=no,directories=no,copyhistory=no,menubar=no,status=no,scrollbars=no,resizable=no');
	//windowPIC.focus();
}

// -->