var nn4 = document.layers?1:0;
var ie4 = document.getElementById?0:1;
var opera = (navigator.userAgent.indexOf("Opera")!=-1)?1:0;
var ns6 = (document.getElementById && !document.all && !opera)?1:0;


function mo(o){o.className=='stateoff'?o.className='stateon': o.className=o.className; }
function mx(o){o.className=='stateon'?o.className='stateoff': o.className=o.className; }


function getTop(el) {
	var element = document.getElementById(el);
	var top = element.offsetTop;
	while ((element = element.offsetParent) != null)
	top += element.offsetTop; return top;
}
function getLeft(el) {
	var element = document.getElementById(el);
	var left = element.offsetLeft;
	while ((element = element.offsetParent) != null)
	left += element.offsetLeft; return left;
}
function showPhoto(nomer, source) {
	var picture = eval("document.form"+nomer+".snimka"+nomer);
	picture.src = source;
}


rotPic=new Array();
function rotatePhotos(imId,arr,dur) {
		if (dur==null) dur=2000;
		var pointer=rotPic.length;
		var data={
				srcs:arr,
				duration:dur,
				imgId:imId,
				num:0,
				pix:new Array()
		};
		rotPic[pointer]=data;
		sp(pointer);
}

//##############################
//BEGIN news bar-a !!!
//##############################
function lib_bwcheck(){
        this.ver=navigator.appVersion
        this.agent=navigator.userAgent
        this.dom=document.getElementById?1:0
        this.opera5=this.agent.indexOf("Opera 5")>-1
        this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
        this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
        this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
        this.ie=this.ie4||this.ie5||this.ie6
        this.mac=this.agent.indexOf("Mac")>-1
        this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
        this.ns4=(document.layers && !this.dom)?1:0;
        this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
        return this
}
var bw=new lib_bwcheck()

nWorks = 1

nSlidespeed = 2

nBetweendelay = 5000
nFont = 'verdana, tahoma, arial, helvetica'
nFontsize = 10
nFadespeed = 50

nColor=new Array('#EDF2FC', '#EFDAE3','#F2AAB1','#F6797E','#FA494C','#FD191A','#FF0000')

function makeNewsObj(obj,nest,olyr,font,size,color,news,fadespeed,betweendelay,slidespeed,works,newsheight) {
    nestOrig=nest;
    nest=(!nest) ? "":'document.'+nest+'.'
           this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;
           this.writeref=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj+".document"):0;
           this.overflowref=bw.dom? document.getElementById(olyr):bw.ie4?document.all[olyr]:bw.ns4?eval(nest+"document.layers." +olyr+".document"):0;
           this.cont_lyr=bw.dom? document.getElementById(nestOrig):bw.ie4?document.all[nestOrig]:bw.ns4?eval(nest+"document"):0;
        if(font) {
        	this.color=new Array(); this.color=eval(color); this.news=new Array(); this.news=eval(news)
                this.font=font; this.size=size; this.speed=fadespeed; this.delay=betweendelay; this.newsheight=newsheight;
                this.newsWrite=b_newsWrite; this.y=1;
                this.fadeOut=b_fadeOut;
                this.slideIn=b_slideIn; this.moveIt=b_moveIt; this.slideSpeed=slidespeed; this.works=works
                if(bw.dom || bw.ie4){this.css.fontFamily=this.font; this.css.fontSize=this.size; this.css.color=this.color[0]}
        }
        this.obj = obj + "Object";         eval(this.obj + "=this"); return this
}

var px = bw.ns4||window.opera?"":"px";

function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x+px; this.css.top=this.y+px;}

function b_newsWrite(num,i) {
        if (bw.ns4){
                this.writeref.write("<a onMouseOver=\"isMoving=0\" onMouseOut=\"isMoving=1\" class=\"news\" href=\""+this.news[num]['link']+"\">"
                        +"<font face=\""+this.font+"\" color=\""+this.color[i]+"\">"+this.news[num]['text']+"</font></a>")
                this.writeref.close()
        }else this.writeref.innerHTML = '<a onMouseOver=\"isMoving=0\" onMouseOut=\"isMoving=1\" id="'+this.obj+'link' +'" class="news" href="'+this.news[num]['link']+'">'+this.news[num]['text']+'</a>'
}

function b_slideIn(num,i){
        if (this.y>0) {
                if (i==0){this.moveIt(0,this.newsheight); this.newsWrite(num,this.color.length-1)}
                if (isMoving) {
                	this.moveIt(this.x,this.y-this.slideSpeed);
                	i++;
                }
                setTimeout(this.obj+".slideIn("+num+","+i+");",50);
        }
        else setTimeout(this.obj+".fadeOut("+num+","+(this.color.length-1)+")",this.delay);
}

function b_fadeOut(num,i) {
        if (i>=0) {
                if (i==0 || bw.ns4) {
                	
                	 this.newsWrite(num,i);
                	 this.cont_lyr.filters[0].Apply();
		         this.overflowref.style.visibility='visible';
		         this.cont_lyr.filters[0].Play();
                }
                if (isMoving) { i--; }
                setTimeout(this.obj+".fadeOut("+num+","+i+")",this.speed);
        }else {
        	this.overflowref.style.visibility='hidden';
                num ++;
                if(num==this.news.length) num=0;
                works = !this.works?0:this.works==1?1:Math.round(Math.random());
                if(works==0) setTimeout(this.obj+".fadeIn("+num+",0)",500);
                else if (works==1) { this.y=1; setTimeout(this.obj+".slideIn("+num+",0)",500) }
        }
}

function fadeInit() {
        oNews = new makeNewsObj('divNews','divNewsCont','divOverflow',nFont,nFontsize,"nColor","nNews",nFadespeed,nBetweendelay,nSlidespeed,nWorks,nNewsheight)
        oNewsCont = new makeNewsObj('divNewsCont')
        works = !oNews.works?0:oNews.works==1?1:Math.round(Math.random())
        if (works==0) oNews.fadeIn(0,0)
        else if (works==1) oNews.slideIn(0,0)
        oNewsCont.css.visibility = "visible";
}

//##############################
//END news bar-a !!!
//##############################


function enDisExcludeFieds(o,re,valueOnStartEditing,valueOnCancel) {
	o.oldOnClick=o.onclick;
	var f=o.form;
	for (var i=0; i<f.elements.length; i++) {
		if (!re.exec(f.elements[i].name)&&o!=f.elements[i]) f.elements[i].disabled=true;
	}
	o.value=valueOnStartEditing;
	f.reset();
	o.onclick=function() {
		for (var i=0; i<f.elements.length; i++) {
			if (!re.exec(f.elements[i].name)&&o!=f.elements[i]) f.elements[i].disabled=false;
		}
		o.onclick=o.oldOnClick;
		o.value=valueOnCancel;
	}
}

function checkEmail(email) {
	/* --[Email check - B]-- */
	var partsArray, dotsArray, tmpstr='';
	partsArray=email.split('@');
	if (typeof(partsArray[1])=='undefined') { tmpstr+='Please fill in correct the field \'Email\' . Can\'t find the monkey!'+"\n"; }
	else {
		if ((/([^0-9A-Za-z_\.]+)/i.exec(partsArray[0]))||(!partsArray[0])||((partsArray[0].length<2)||(partsArray[0].length>40))) { tmpstr+='Please fill in correct the field \'Email\'. The username is invalid'+"\n"; }
		if (partsArray.length>1) dotsArray=partsArray[1].split('.');
		else { tmpstr+='Please fill in correct the field \'Email\'. Can\'t find the monkey!'+"\n"; }
		if (typeof(dotsArray[1])=='undefined') { tmpstr+='Please fill in correct the field \'Email\'. Where is your top level domain?'+"\n"; }
		else {
			for (var i=0; i<dotsArray.length-1; i++) {
				if ((/([^0-9A-Za-z-]+)/i.exec(dotsArray[i]))||(!dotsArray[i])||((dotsArray[i].length<2)||(dotsArray[i].length>40))) { tmpstr+='Please fill in correct the field \'Email\'. The subdomain '+dotsArray[i]+': There is an invalid symbol.'+"\n"; }
			}
			if ((/([^A-Za-z]+)/i.exec(dotsArray[dotsArray.length-1]))||(!dotsArray[dotsArray.length-1])||((dotsArray[dotsArray.length-1].length<2)||(dotsArray[dotsArray.length-1].length>4))) { tmpstr+='Please fill in correct the field \'Email\'. The top-level domain is wrong.'+"\n"; }
		}
	}
	/* --[Email check - E]-- */
	return tmpstr;
}

function trim(str) {
	return str.replace(/^(\s+)/,"").replace(/(\s+)$/,"");
}

function _prepare () {
	var i=0;
	while (i<this.elements.length) {
		if (this.elements[i].type!='hidden'&&this.elements[i].disabled==false&&typeof(this.elements[i].turnedToHtmlArea)!='undefined'&&!this.elements[i].turnedToHtmlArea) {
			this.elements[i].focus();
		}
		i++;
	}
	this.prepared=true;
}

function _check() { //checking any form, with check methods defined in its elements!
	var noerror = true;
	var i=0;
	while (i<this.elements.length&&noerror) {
		if (typeof(this.elements[i].check)!='undefined') {
			if (!this.elements[i].check()) noerror=false;
		}
		i++;
	}
	return noerror;
}

var newwin=false;
var wwidth=490;
var wheight=350;
if (document.layers) wheight=300;
var wleft=Math.round(screen.width/8);
var wtop=Math.round(screen.height/4);
function openWin(url,w,h,scrollbars) {
	if (w!=null) wwidth=w;
	if (h!=null) wheight=h;
	if (newwin.closed) newwin=false;
	//alert('left='+wleft+',top='+wtop+',width='+wwidth+',height='+wheight+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+(scrollbars?'1':'0')+',resizable=0);
	if (!newwin) newwindow = window.open(url, '', 'left='+wleft+',top='+wtop+',width='+wwidth+',height='+wheight+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+(scrollbars?'1':'0')+',resizable=0');
	else newwindow=newwin;
	return newwindow;
}

function izpukvane(o) {
	o.style.paddingTop='0px';
	o.style.paddingBottom='1px';
	o.style.paddingLeft='1px';
	o.style.paddingRight='0px';
}

function vdlubvane(o) {
	o.style.paddingTop='1px';
	o.style.paddingBottom='1px';
	o.style.paddingLeft='0px';
	o.style.paddingRight='1px';
}

src_preloaded=new Array();
function preloadPics(src) {
	for (var i=0; i<src.length; i++) {
		src_preloaded[src_preloaded.length]=new Image();
		src_preloaded[src_preloaded.length-1].src=src[i];
	}
	return src;
}
rotPic=new Array();

function sp(pointer) {
	var data=rotPic[pointer];
	
	//alert('pointer:'+pointer+' src:'+data.srcs+' duration:'+data.duration+' imgId:'+data.imgId+' num:'+data.num+' pix:'+data.pix+'');
	//alert(data.srcs.length);
	
	var n=(data.num+1)%data.srcs.length;
	if (data.pix[n] && (data.pix[n].complete || data.pix[n].complete==null)) {
		document[data.imgId].style.filter="blendTrans(duration=1)"
		document[data.imgId].filters.blendTrans.Apply();
		document[data.imgId].src = data.pix[data.num=n].src;
		document[data.imgId].filters.blendTrans.Play();
	}
	data.pix[n=(data.num+1)%data.srcs.length] = new Image;
	data.pix[n].src = data.srcs[n];
	setTimeout("sp("+pointer+")",data.duration);
}
function cBrowser() {
	var userAgent = navigator.userAgent.toLowerCase()
	this.version = parseInt(navigator.appVersion)
	this.subVersion = parseFloat(navigator.appVersion)
	this.ns  = ((userAgent.indexOf('mozilla')!=-1) && ((userAgent.indexOf('spoofer')==-1) && (userAgent.indexOf('compatible') == -1)))
	this.ns2 = (this.ns && (this.version == 2))
	this.ns3 = (this.ns && (this.version == 3))
	this.ns4b = (this.ns && (this.subVersion < 4.04))
	this.ns4 = (this.ns && (this.version == 4))
	this.ns5 = (this.ns && (this.version == 5))
	this.ie   = (userAgent.indexOf('msie') != -1)
	this.ie3  = (this.ie && (this.version == 2))
	this.ie4  = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 4.')!=-1))
	this.ie5  = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 5.0')!=-1))
	this.ie55 = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 5.5')!=-1))
	this.ie6 = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 6.0')!=-1))
	this.op3 = (userAgent.indexOf('opera') != -1)
	this.win   = (userAgent.indexOf('win')!=-1)
	this.mac   = (userAgent.indexOf('mac')!=-1)
	this.unix  = (userAgent.indexOf('x11')!=-1)
	this.name = navigator.appName
	this.dom = this.ns5 || this.ie5 || this.ie55 || this.ie6
}
var bw = new cBrowser();

cToolTip = {
	offsetX			: 20,
	offsetY			: 3,
	nTimeout 		: 1000,
	bShowDelayed	: true,
	nSteps			: 5,
	nSpeed			: 35
}

var hTarget = null
var hToolTop = null

cToolTip.showTip = function( nLeft, nTop, hTarget, sText )
{
	if( typeof sText == "undefined" )
	{
		sText = hTarget.getAttribute( "tooltip" )
		if( sText )
		{
			if( ( typeof sText == "undefined" ) || ( sText.length = 0 ) ) return
			if( sText.substr( 0, 5 ) == "data:" )
			{
				sText = eval( sText.substr( 5 ) )
			}
		}
		else
		{
			return
		}
	}
	
	if( hTarget.hToolTip )
	{
		this.hideTip( hTarget )
		return
	}
	
	hTarget.bStay = false
	
	hToolTip = document.createElement( "DIV" )
	hToolTip.className = "motooltip"
	
	if( this.bShowDelayed )
	{
		hToolTip.style.visibility = "hidden"
	}

	document.body.appendChild( hToolTip )
	hToolTip.innerHTML = sText

	hTarget.hToolTip = hToolTip
	
	hToolTip.onmousedown = function()
	{
		hTarget._onblur = hTarget.onblur
		hTarget.onblur = null
		hTarget.bStay = true
	}

	hToolTip.onmouseup = function()
	{
		hTarget.onblur = hTarget._onblur
		hTarget._onblur = null
		hTarget.bStay = false
		hTarget.focus()
	}
	
	hTarget.onblur = function()
	{
		if( ( hTarget.bStay ) || ( typeof hTarget.hToolTip == "undefined" ) ) return
		document.body.removeChild( hTarget.hToolTip )
		hTarget.hToolTip = null
		hTarget.onblur = null
		hTarget.onmouseout = null
	}

	/* just a quick hack better use cMoDomEvent */
	function mo()
	{
		hTarget.onmousemove = new Function('')
	}
	
	if( document.attachEvent ) 
	{
		hTarget.attachEvent( 'onmouseout', mo )
	}
	else if( document.addEventListener )
	{
		hTarget.addEventListener( 'mouseout', mo, false )
	}
	else if( document.all )
	{
		hTarget.onmouseout = mo
	}
	
	hTarget.onmousemove = function(hEvent)
	{
		if( hEvent == null ) hEvent = window.event
		if( ( hTarget.bStay ) || ( typeof hTarget.hToolTip == "undefined" ) ) return

		nLeft = hEvent.clientX
		nTop = hEvent.clientY
		cToolTip.setPos( hTarget, nLeft, nTop )
	}
	

	//correct position
	var nDocWidth = document.width ? document.width : document.documentElement.offsetWidth - 25	
	var aDocScroll = getScroll()

	if( nLeft > nDocWidth - hToolTip.offsetWidth )
	{
		nLeft = nLeft - hToolTip.offsetWidth - this.offsetX + aDocScroll.x + "px"
	}
	else
	{
		nLeft = nLeft + this.offsetX + aDocScroll.x + "px"
	}
	
	nTop = nTop + this.offsetY + aDocScroll.y + "px"

	hToolTip.style.left = nLeft
	hToolTip.style.top = nTop
	
	hToolTip.style.visibility = "visible"

	if( this.bShowDelayed )
	{
		this.showDelayed( 1 )
	}
}

cToolTip.setPos = function( hTarget, nLeft, nTop )
{
	var nDocWidth = document.width ? document.width : document.documentElement.offsetWidth - 25	
	var aDocScroll = getScroll()
	
	if( nLeft > nDocWidth - hTarget.hToolTip.offsetWidth )
	{
		nLeft = nLeft - hTarget.hToolTip.offsetWidth - cToolTip.offsetX + aDocScroll.x + "px"
	}
	else
	{
		nLeft = nLeft + cToolTip.offsetX + aDocScroll.x + "px"
	}

	nTop = nTop + cToolTip.offsetY + aDocScroll.y + "px"

	hTarget.hToolTip.style.left = nLeft
	hTarget.hToolTip.style.top = nTop
}

cToolTip.hideTip = function( hTarget )
{
	if( hTarget.hToolTip != null )
	{
		document.body.removeChild( hTarget.hToolTip )
		hTarget.hToolTip = null
		hTarget.onblur = null
		hToolTip = null
	}
}

cToolTip.getTarget = function( hEvent )
{
	hElm =  ( hEvent.srcElement ) ? hEvent.srcElement : hEvent.originalTarget.parentNode
	if( typeof hElm.tagName == "undefined" ) return null
	//if( hElm.tagName.toUpperCase() == "A" )
	while( ( hElm.tagName ) && !( /body/i.test( hElm.tagName ) ) )
	{
		if ( hElm.getAttribute( 'tooltip' ) != null )
		{
			return hElm
		}
		
		hElm = hElm.parentNode
	}
	return null
}

cToolTip.showDelayed = function( nStep )
{
	if( hToolTip == null ||  nStep>this.nSteps ) return
	if( ( bw.ie55 || bw.ie6 ) && ( hToolTip.filters == null || hToolTip.filters.alpha == null ) ) return
	nOpacity = nStep*1/this.nSteps
	nOpacity = Math.floor( nOpacity * 100 )
	cToolTip.setTipOpacity(nOpacity)
	nStep++
	this.hDelayedTimeout = setTimeout( 'cToolTip.showDelayed('+nStep+')' , this.nSpeed )
}

cToolTip.setTipOpacity = function( nValue )
{
	if( hToolTip == null ) return
	if( bw.ie )
	{
		hToolTip.filters.alpha.opacity = nValue
	}
	else if( bw.ns5 )
	{
		hToolTip.style.MozOpacity = nValue+'%'
	}
}

cToolTip.show = function( hEvent, sText )
{
	if( !hEvent )
	{
		hEvent = window.event
		hEvent.returnValue = true
		hEvent.cancelBubble = false
	}
	hTarget = cToolTip.getTarget( hEvent )
	
	if( !hTarget )
	{
		return
	}
	else
	{
		cToolTip.showTip( hEvent.clientX, hEvent.clientY, hTarget, sText )
	}
}

cToolTip.hide = function( hEvent )
{
	if( !hEvent )
	{
		hEvent = window.event
		hEvent.returnValue = true
		hEvent.cancelBubble = false
	}
	hTarget = cToolTip.getTarget( hEvent )
	
	if( this.bShowDelayed )
	{
		clearTimeout( this.hDelayedTimeout )
	}

	if( !hTarget )
	{
		return
	}
	else
	{
		cToolTip.hideTip( hTarget )
	}
}


cToolTip.initAutoTips = function( )
{
	if( document.attachEvent ) 
	{
		document.attachEvent( 'onmouseover', cToolTip.show )
		document.attachEvent( 'onmouseout', cToolTip.hide )
	}
	else if( document.addEventListener )
	{
		document.addEventListener( 'mouseover', cToolTip.show, true )
		document.addEventListener( 'mouseout', cToolTip.hide, false )
	}
	else if( document.all )
	{
		document.onmouseover = cToolTip.show
		document.onmouseout = cToolTip.hide
	}
}

cToolTip.init = function()
{
	this.bShowDelayed = bw.ie55 || bw.ie6 || bw.ns5
}

cToolTip.init()

//helper functions
function getScroll()
{
	if ( typeof document.body.scrollTop != "undefined") 
	{
		var ieBox = document.compatMode != "CSS1Compat"
		var cont = ieBox ? document.body : document.documentElement
		return {x : cont.scrollLeft, y : cont.scrollTop}
	}
	else 
	{
		return {x : window.pageXOffset, y : window.pageYOffset}
	}
}