/* To $() assigns document.getElementById */
var $ = function (e) { return (typeof e == 'string' ? document.getElementById(e) : e); }

/*
 * Input value on focus will be emptied and "empty" class will be added,
 * on blur value will be restored if input will still be empty
 * 
 * Usage:
 * 		<input id="inp" type="text" value="-- search --" onfocus="EmptyInput.set(this, true);" />
 * or
 *		<script type="text/javascript">
 *	 		EmptyInput.set('inp');
 * 		</script>
 */
var EmptyInput = {
	focusHandler: function () {
		if (this.value == this._initialValue && this.value == this._defaultValue)
		{
			this.className = this.className.replace(/empty/g, '');
			this.value = '';
		}
	},
	blurHandler: function () {
		if (this.value == '' && ( !this._leaveEmpty ))
		{
			this.className += ' empty';
			this.value = this._initialValue;
		}
	},
	set: function (el, call_focus, defValue, leaveEmpty) {
		var _self = $(el);
		
		if (_self._initialValue || !_self.tagName || (_self.tagName != 'INPUT' && _self.tagName != 'TEXTAREA')) return;
		
		if ( !leaveEmpty )
			leaveEmpty = false;
		
		_self._initialValue = _self.value;
		_self._defaultValue = defValue;
		_self._leaveEmpty   = leaveEmpty;
		
		_self.className += ' empty';
		
		_self.onfocus = function () { EmptyInput.focusHandler.apply(this); };
		_self.onblur  = function () { EmptyInput.blurHandler.apply(this); };
		
		if (call_focus) _self.onfocus();
	}
};

/* ------------------------- Page font size -------------------------------- */

var FontSize = {
	//List of font sizes
	fontSizes: ['68.8%', '75%', '81.3%'],
	
	//Current font size index
	fontSizeIndex: 1,
	
	//Set font size
	setFontSizeIndex: function (ind) {
		ind = parseInt(ind);
		if (ind >= 0 && ind < this.fontSizes.length) {
			this.fontSizeIndex = ind;
			createCookie('fontSize', this.fontSizeIndex, 356);
		}
		
		for(var i=0,j=this.fontSizes.length; i<j; i++) {
			var el = document.getElementById('fontSize' + i);
			if (el) {
				if (i == ind)
					el.className = 'size-' + i + ' active';
				else
					el.className = 'size-' + i;				
			}
		}
		
		document.body.style.fontSize = this.getFontSize();
	},
	
	//Returns font size index
	getFontSizeIndex: function () {
		return this.fontSizeIndex;
	},
	
	//Returns font size
	getFontSize: function () {
		return this.fontSizes[this.getFontSizeIndex()];
	},
	
	//Load font size from cookie
	restoreFontSize: function () {
		//In browsers other than IE6, document.cookie wont be empty
		if (!document.cookie) {
			var defFontSize = readCookie('fontSize');
			this.setFontSizeIndex(defFontSize);
		}
	}
};

/* ------------------------- Browser detection -------------------------------- */

var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();


/* ------------------------- COOKIES --------------------------------------- */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
	if (document.cookie == '') {
		 //IE6 workaround
		window.name = name+"="+value+";";
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	
	if (document.cookie) {
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	} else {
		var ca = window.name.split(';'); //IE6 workaround
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

/* ------------------------- FROM old site --------------------------------------- */
var req;

function CRObj()
{
    var obj = null;
    try{
        obj = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
        try{
            obj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc){
            obj = null;
        }
    }

    if (!obj && typeof XMLHttpRequest != "undefined"){
        obj = new XMLHttpRequest();
    }
    return obj;
}

function serialize(x)
{
	function sN(x)
	{
		return((parseInt(x)==x)&&(x<2147483648)?'i':'d')+':'+x+';'
	}
	function sS(x)
	{
		x=escape(x);
		return 's:'+x.length+':"'+escape(x)+'";'
	}
	function sB(x)
	{
		return 'b:'+(x?1:0)+';'
	}
	function sO(x)
	{
		var a=[];
			for(var i in x)
				if('function'!=typeof(x[i]))
					a[a.length]=sX(isNaN(d=parseInt(i))?i:d)+sX(x[i]);
		return 'a:'+a.length+':{'+a.join('')+'}'
	}
	function sX(x)
	{
		if(x==null)return 'N;';
		switch(typeof(x))
		{
			case 'string':
				return sS(x);
			case 'number':
				return sN(x);
			case 'boolean':
				return sB(x);
			case 'object':
				return sO(x)
		}
	}
return sX(x)
}


function request(block,cmd,data)
{		
	req = CRObj();	
	if (req)
	{
	    req.onreadystatechange = requestDone;	    
	    q = location;
	    req.open("POST", q, true);	    
	    req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");	    
	    req.send(block+"=request&cmd="+cmd+"&data="+serialize(data));
	    //alert(block+"=request&cmd="+cmd+"&data="+serialize(data));return;
	}
}

function requestDone()
{
	if (req.readyState == 4)
	{
    	if (req.status == 200)
    	{
            if(req.responseText != '')
            {
				eval(req.responseText);
            }
        }
    }
}


//code for pdf forms
	
function showPopup( item, text ){
	popup = document.getElementById( 'popupDIV' );		
	if ( browser == 1 ){
		popup.childNodes[3].firstChild.firstChild.firstChild.firstChild.innerHTML = text;
	}
	else{
		hlpText = document.getElementById( 'hlpText' );
		hlpText.innerHTML = text;
	}
	popup.style.display = '';
	x = findPosX( item );
	y = findPosY( item );
	popup.style.position = 'absolute';		
	popup.style.left = (x + 29) + 'px';				
	popup.style.top = (y - 50) + 'px';
	
	if( browser == 1 ){
		var popupFRAME = document.getElementById( 'popupFRAME' );
		popupFRAME.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		popupFRAME.style.display = popup.style.display;
		popupFRAME.style.position = popup.style.position;
		popupFRAME.style.left = (x + 29) + 'px';
		popupFRAME.style.top = (y - 50) + 'px';
		popupFRAME.style.width = parseInt(popup.clientWidth) + 'px';
		popupFRAME.style.height = parseInt(popup.clientHeight) + 'px';
	}
}

function hidePopup( item ){
	popup = document.getElementById( 'popupDIV' );
	popup.style.display = 'none';
	
	if( browser == 1 ){
		var popupFRAME = document.getElementById( 'popupFRAME' );
		popupFRAME.style.display = popup.style.display;
	}
}

//this function find x coordinate by for object
function findPosX( obj ){
    var curleft = 0;
    if ( obj.offsetParent ){
    	while ( obj.offsetParent ){
                    curleft += obj.offsetLeft;
                    obj = obj.offsetParent;
                   }
	}
	else if ( obj.x )
		curleft += obj.x;
	return curleft;
}

//this function find y coordinate by for object
function findPosY( obj ){
    var curtop = 0;
    if ( obj.offsetParent ){
    	while ( obj.offsetParent ){
    		curtop += obj.offsetTop;
    		obj = obj.offsetParent;
    	}
    }
    else if ( obj.y )
    	curtop += obj.y;
    return curtop;
}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}

var rand;
var ssize = 231;
var esize = 361; 
var speed = 40;
var step = 20;
   
function resizeFlash(newHeight, newRand)
{
	esize = newHeight;
	rand = newRand;
   	reduceHeight();
}

function reduceHeight()
{
	ssize += step;
	if(ssize > esize)
	{
		ssize = esize;
	}
	setSize(ssize);
	if(ssize == esize)
	{
		clearTimeout(resize);
		return;
	}
	resize = setTimeout('reduceHeight()',speed);
}

function setSize(newHeight)
{
	var el = document.getElementById('flash'+rand);
   	el.style.height = newHeight + 'px';
   	
   	var o = el.getElementsByTagName('OBJECT');
   	if (o.length)
   	{
   		o[0].style.height = newHeight + 'px';
   	}
}