// 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){
	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';
	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 simplepopup(url,width,height) {
	winl = (screen.width) ? (screen.width - width) / 2 : 0;
	wint = (screen.height) ? (screen.height - height) / 2 : 0;
	var settings = 'left='+winl+',top='+wint+',width='+(width+40)+',height='+(height+40)+',toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes';
	window.open(url,'imgpoint',settings);
}

function emptypopup (name,width,height) {
	winl = (screen.width) ? (screen.width - width) / 2 : 0;
	wint = (screen.height) ? (screen.height - height) / 2 : 0;
	var settings = 'left='+winl+',top='+wint+',width='+width+',height='+height+',toolbar=no,menubar=no,status=yes,scrollbars=no,resizable=no';
	window.open('about:blank',name,settings);
}

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 = base_path + 'img/' + a[i];
		}
	}
}

function addEvent(obj, eventType,fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on"+eventType, fn);
			return r;
		}
	}
}

var __eventListeners = [];

function addEvent(instance, eventName, listener) {
    var listenerFn = listener;
    if (instance.addEventListener) {
        instance.addEventListener(eventName, listenerFn, false);
    } else if (instance.attachEvent) {
        listenerFn = function() {
            listener(window.event);
        }
        instance.attachEvent("on" + eventName, listenerFn);
    } else {
        throw new Error("Event registration not supported");
    }
    var event = {
        instance: instance,
        name: eventName,
        listener: listenerFn
    };
    __eventListeners.push(event);
    return event;
}
/* * * * * * * * * * * * * * * * */
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 winname = name;
	var settings = 'left='+winl+',top='+wint+',width='+(width+40)+',height='+(height+40)+',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)+'</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="Click to close the window..." width="'+width+'" height="'+height+'" border="0"></a></td></tr></table></body></html>');
	myimgss.document.close();
	if(myimgss.window.focus) {
		myimgss.window.focus();
	}
}
/* * * * * * * * * * * * * * * * */
function urlencode(ch) {
	ch = ch.replace(/[ ]/g,"%20")
	return escape(ch)
}
function urldecode(ch) {
   ch = ch.replace(/[+]/g," ")
   return unescape(ch)
}
/* * * * * * * * * * * * * * * * */
function cPanels (id,active) {
	this.active = active;
	this.activeLink = null;
	this.ID = id;
	this.root = document.getElementById(id);
	this.childs = [];
	this.bookmarks = null;
	this.init = function () {
		var i,j;
		if (this.root) {
			var elements = this.root.getElementsByTagName('div');
			if (elements) {
				j = 0;
				for (i in elements) {
					if (elements[i].className == 'ptab') {
						if (j == this.active) {
							elements[i].style.display = 'block';
						}
						this.childs[j] = elements[i];
						j++;

					} else if(elements[i].className == 'bookmarks') {
						this.bookmarks = new cBookmarks(elements[i].id,this.active);
						this.bookmarks.init();
					}
				}
				this.total = j;
			}
		}
	}
	this.activate = function (pIndex,link) {
		if (this.childs[this.active]) {
			this.childs[this.active].style.display = 'none';
			if (this.bookmarks && this.bookmarks[this.active]) {
				this.bookmarks[this.active].id = '';
			}
			if (this.activeLink) {
				this.activeLink.className = '';
			}

		}
		if (this.childs[pIndex]) {
		    this.childs[pIndex].style.display = 'block';
		    this.active = pIndex;
		    this.activeLink = link;
		    if (this.activeLink) {
		    	this.activeLink.className = 'selected';
		    }
		    /*
		    if (this.bookmarks[pIndex]) {
		    	this.bookmarks[pIndex].id = 'bmsel';
		    }
		    */
		    if (this.bookmarks) this.bookmarks.activate(pIndex);
		}
	}
}

/* * * * * * * * * * * * * * * * */
function getOffsetLeft(el) {
	var left = el.offsetLeft;
	if (el.offsetParent) left += getOffsetLeft(el.offsetParent);
	return left;
}
/* * * * * * * * * * * * * * * * */
function getOffsetTop(el) {
	var top = el.offsetTop;
	//alert(el.nodeName + ' class:' + el.className + ' offset:' + el.offsetTop);
	if (el.offsetParent) top += getOffsetTop(el.offsetParent);
	return top;
}

/* * * * * * * * * * * * * * * * */
function validateform(fi,errormsg) {
	var el,noerr;
	noerr = true;
	for (var i in fi) {
		el = document.onfrm[fi[i]];
		if (el) {
			if (el.value == '') {
				noerr = false;
				el.style.background = '#ffdddd';
			} else {
				el.style.background = '#ffffff';
			}
		}
	}
	if (!noerr) alert(errormsg);
	return noerr;
}

/* * * * * * * * * * * * * * * * */
function setLang(lang) {
	var link = location.href;
	var preg = /^http:\/\/(\w{2,3}\.)?(.+)/;
	var rez;
	if (rez = link.match(preg)) {
		location.href = 'http://' + lang + '.' + rez[2];
	}


}
/* * * * * * * * * * * * * * * * */
function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

/* * * * * * * * * * * * * * * * */
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
/* * * * * * * * * * * * * * * * */
function printPage(mode) {
	if ((mode == undefined) || (mode != 1)) {
		var wint = (screen.height - 600) / 2;
		var winl = (screen.width - 800) / 2;
		var url = location.href + '?print';
		window.open(url, 'Print', 'left='+winl+',top='+wint+',width=800,height=600,toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=no,location=no');
	} else {
		window.print();
	}
	return false;
}
/* * * * * * * * * * * * * * * * */
function cScroller () {
	this.objects = {};
	this.speed = 10;

	this.init = function (objID,state) {
		var obj = {};
		obj.obj = document.getElementById(objID);
		obj.state = state;
		obj.timer = null;
		obj.maxScroll = (parseInt(obj.obj.scrollHeight) - parseInt(obj.obj.offsetHeight));
		this.objects[objID] = obj;
	}

	this.down = function (id,timer) {
		if (this.objects[id] == undefined) {
			this.init(id,1);
		}
		var obj = this.objects[id];
		if (timer == undefined) {
			obj.state = 1;
		}

		if ((obj.maxScroll > obj.obj.scrollTop) && (obj.state == 1)) {
			obj.obj.scrollTop = (parseInt(obj.obj.scrollTop) + this.speed);
			obj.timer = setTimeout(this.down.bind(this,id,true),100);
		}

	}

	this.up = function (id,timer) {
		if (this.objects[id] == undefined) {
			this.init(id,-1);
		}
		var obj = this.objects[id];
		if (timer == undefined) {
			obj.state = -1;
		}

		if ((obj.obj.scrollTop > 0) && (obj.state == -1)) {
			obj.obj.scrollTop = (parseInt(obj.obj.scrollTop) - this.speed);
			if (obj.obj.scrollTop < 0) obj.obj.scrollTop = 0;
			obj.timer = setTimeout(this.up.bind(this,id,true),100);
		}
	}

	this.stop = function (id) {
		if (this.objects[id]) {
			clearTimeout(this.objects[id].timer);
			this.objects[id].state = 0;
		}
	}



}


/* * * * * * * * * * * * * * * * */

