var killerPoints;
var inScroller, slideshowNmb, slideshowLinks, cityDetails, cityDetailsTimer = 0, newlyCarouselFx = [], actualCarouselInt = [], carouselNavigation = [], switcherObjLeft = [], switcherObjRight = [], runningCarousel = [], hasRunCarousel = [], yearResults, priceResults, multiResults, todaysOffer, customSelects;
var searchTabs = null;

function buildPromos(bgs){
	bgs.each(function(val){
		$(val.id).setStyle("background","url('"+val.src+"') bottom right no-repeat");
	});
}

function makeTheReady(){
  var container = $('searchtabs') || false;
	if (container) {
	  searchTabs = new SimpleTabs(container, {selector: 'h4'});
	  container.getElements('.hide').removeClass('hide');
		todaysOffer = $('searchingType').getElement('h5') || false;
		if (todaysOffer){
			todaysOffer = todaysOffer.get('text');
			$$('#searchingType a span').each(function(el){
				t = el.get('html');
				el.set('html',todaysOffer+' '+t);
			});
		}
	}

	var buildtabs = $('buildtabs') || false;
	if (buildtabs) {
	  new SimpleTabs(buildtabs, {selector: 'h4'});
	}

    var buildtabs2 = $('buildtabsCars') || false;
    if (buildtabs2) {
      new SimpleTabs(buildtabs2, {selector: 'h4', classMenu: 'tab-menu-cars'});
    }

	var newlycarousel = $('newlycarousel') || false;
	if (newlycarousel) {
	  new SimpleTabs(newlycarousel, {selector: 'h4'});
	}

  var resultsTable = $('tablecars') || false;
  if (resultsTable) {
  	resultsTable.getElements('table').addEvents({
  		mouseenter:function(){
  			this.addClass('hoverTable');
			},
			mouseleave:function(){
  			this.removeClass('hoverTable');
			}
		});
	}

var makeaccordion = $('makeaccordion') || false;
	if (makeaccordion) {
		$$('.h0').removeClass('h0');
		new Accordion(makeaccordion.getElements('h4'),makeaccordion.getElements('div.accord'),{
			display:false,
			show:0,
			opacity:true,
			wait:true,
			onActive:function(toggler,element){
				toggler.getLast().set('html','&#9660;');
			},
			onBackground:function(toggler,element){
				toggler.getLast().set('html','&#9650;');
			}
		});
	}

	var comparediv = $('comparediv') || false;
	if (comparediv) {
		comparediv.getElements('.carCompare').each(function(comp){
			comp = comp.getFirst();
			comp.addEvents({
				'mouseenter':function(){
					this.getNext().addClass('vis');
				},
				'mouseleave':function(){
					this.getNext().removeClass('vis');
				}
			});
			comp.getNext().addEvents({
				'mouseleave':function(){
					this.removeClass('vis');
				},
				'mouseenter':function(){
					this.addClass('vis');
				}
			});
			comp.getParent().addEvents({
				'mouseenter':function(ex){
					ex = new Event(ex);
					ex.stop();
					this.addClass('hovered');
				},
				'mouseleave':function(ex){
					ex = new Event(ex);
					ex.stop();
					this.removeClass('hovered');
				}
			});
		});
	}

  var resultsTableBig = $('tableimgs') || false;
  if (resultsTableBig) {
  	resultsTableBig.getElements('.one').each(function(one){
			one.addEvents({
	  		'mouseenter':function(){
	  			one.addClass('over');
				},
				'mouseleave':function(){
	  			one.removeClass('over');
				}
			});
		});
  	resultsTableBig.getElements('.oneL').addEvents({
  		'mouseenter':function(){
  			this.addClass('overL');
			},
			'mouseleave':function(){
  			this.removeClass('overL');
			}
		});
	}

	var fotoslides = $('fotoslides') || false;
	if (fotoslides) {
		slideshowLinks = fotoslides.getFirst().getElements('a[rel!=carGallery]');
		if (slideshowLinks.length > 0) {
			new Element('a',{'href':'#','class':'scrollBtn',html:'&#9668;'}).addClass('lft').addEvents({
				'mouseenter':function(){
					$clear(inScroller);
					inScroller = setInterval(function(){
						var oldScroll = this.getScroll().x;
						if(this.getScrollSize().x-this.getWidth() > (oldScroll-1)){
							this.scrollTo(oldScroll-5);
						}
						else $clear(inScroller);
					}.bind(this),25);
				}.bind(fotoslides),
				'mouseleave':function(){$clear(inScroller);},
				'click':function(e){e.stop();}
			}).inject(fotoslides,'before');
			new Element('a',{'href':'#','class':'scrollBtn',html:'&#9658;'}).addClass('rgt').addEvents({
				'mouseenter':function(){
					$clear(inScroller);
					inScroller = setInterval(function(){
						var oldScroll = this.getScroll().x;
						if(this.getScrollSize().x-this.getWidth() > (oldScroll+1)){
							this.scrollTo(oldScroll+5);
						}
						else $clear(inScroller);
					}.bind(this),25);
				}.bind(fotoslides),
				'mouseleave':function(){$clear(inScroller);},
				'click':function(e){e.stop();}
			}).inject(fotoslides,'after');

			slideshowNmb = 0;
			var cntR = slideshowLinks.length;
			slideshowLinks.each(function(ahref,inda){
				ahref.addEvent('click',function(e){
					e = new Event(e);
					e.stop();
					refreshSlideshow(false,inda,cntR);
					return false;
				});
			});
			slideshowLinks[0].addClass('selectedThumb');
			var elmNav = $('fotonavig').getElement('div');
			new Element('span',{'class':'counter'}).adopt(new Element('strong',{'text':'1'})).adopt(new Element('strong',{'text':' / '+cntR})).inject(elmNav);
			if (cntR > 1) {
				var arrow = new Element('a',{'class':'arrow','href':'#'});
				arrow.clone().addClass('prev').addEvent('click',function(e){
					e.stop();
					refreshSlideshow(true,-1,cntR);
				}).inject(elmNav,'top');
				arrow.clone().addClass('next').addEvent('click',function(e){
					e.stop();
					refreshSlideshow(true,1,cntR);
				}).inject(elmNav,'bottom');
			}
		}
	}

	setTimeout(function(){makeTheAfterReady();},20);

}

function refreshSlideshow(increase,intgr,cntr){
	var fotoactual = $('fotoactual');
	if (fotoactual.hasClass('loadingImg')) return;
	fotoactual.addClass('loadingImg');
	if (!increase && slideshowNmb == intgr) {
		fotoactual.removeClass('loadingImg');
		return;
	}

	if (increase) slideshowNmb += (intgr + cntr);
	else slideshowNmb = intgr;
	slideshowNmb %= cntr;

	fotoactual.empty();
	
	var gallery = $('fotoslides').getElement('a[rel=carGallery]') || false;
	if (gallery)
		$$('a.selectedThumb').getParent().getElement('a[rel=carGallery]').addClass('smoothbox');
	
	slideshowLinks.removeClass('selectedThumb');
	
	$('fotonavig').getElement('div').getElement('strong').set('text',(slideshowNmb+1));

	var elmP = $('fotonavig').getElement('p');

	if(killerPoints != undefined) elmP.innerHTML = select_slogan();

	if (!gallery){
		new Asset.image(slideshowLinks[slideshowNmb].addClass('selectedThumb').get('href'),{onload:function(){this.inject($('fotoactual').removeClass('loadingImg'));}});
	}else{	
		new Asset.image(slideshowLinks[slideshowNmb].addClass('selectedThumb').get('href'),{onload:function(){
		
					var d = new Element('div').adopt(slideshowLinks[slideshowNmb].getParent().getElements('a')[1].cloneNode(true));
				
					slideshowLinks[slideshowNmb].getParent().getElements('a')[1].removeClass('smoothbox');
					
					d.inject($('fotoactual'));
					$$('#fotoactual a').set("style", "display: inline");
					$('fotoactual').removeClass('loadingImg');
					TB_init();
			}
	});
	}
}

function loadModels(parentEl, destination, simple){
	destination.loader();
	var request = new Request.JSON({
			url: '/ajax/getmodels.php',
			onComplete: function(resp) {
				destination.populate(resp);
			}
		}).get({'simple': simple ? 1 : 0, 'make' : parentEl.selectElement.get('value')});
}

function getMultiCount() {
	multiResults = $('multiResults').getElement('strong span');
	var pmin = $('p1').get('value');
	var pmax = $('p2').get('value');
	var ymin = $('y1').get('value');
	var ymax = $('y2').get('value');
	var icategory = $('icategory').get('value');
	var itype = $('itype').get('value');
	var imake = $('imake').get('value');
	var imodel = $('imodel').get('value');

	var request = new Request.JSON({
			url: '/ajax/carscount.php',
			onComplete: function(resp) {
				multiResults.set('text', resp);
			}
		}).get(
			{
				'action' : 'multi',
				'pmin' : pmin,
				'pmax' : pmax,
				'ymax' : ymax,
				'ymin' : ymin,
				'make' : imake,
				'model' : imodel,
				'body' : itype,
				'category' : icategory
			}
		);

}


function makeTheSliders(){
	orderedLists = $$('.textPageIn ol');
	if (orderedLists.length > 0) {
		orderedLists.each(function(ol){
			ol.getChildren().each(function(li,ind){
				new Element('span',{'class':'numb','text':(ind+1)}).inject(li,'top');
			});
			//new Element('span',{'class':'numb','text':el.get('value')});
		});
	}
	var priceSlider = $('price-slider') || false;
	if (priceSlider) {
		priceResults = $('priceResults').getElement('strong span');
		mySlideA = new SliderX(priceSlider, priceSlider.getElement('.gutter'), {
			range: [0,100],
			snap: true,
			steps: 300,
			offset: 0,
			onChange: function(pos){
				xx = priceRecount(pos.step);
				yy = priceRecount(pos.maxstep);
				pos.bg.setStyles({'left':pos.leftEdge,'width':Math.abs(pos.rightEdge.toInt()-pos.leftEdge.toInt()+9).round()});
				//pos.inputOne.set('value',xx).getNext().set('text',FormatNumberBy3(xx, ".", " ")+' Kč');
				//pos.inputTwo.set('value',yy).getNext().set('text',FormatNumberBy3(yy, ".", " ")+' Kč');
				pos.inputOne.set('value',xx).getNext().set('text',FormatNumberBy3(xx, ".", " ")+'');
				pos.inputTwo.set('value',yy).getNext().set('text',FormatNumberBy3(yy, ".", " ")+'');
			},
			onComplete:function(pos) {

				var request = new Request.JSON({
					url: '/ajax/carscount.php',
					onComplete: function(resp) {
						priceResults.set('text', resp);
					}
				}).get({'action' : 'price', 'min' : this.elementInputOne.value, 'max' : this.elementInputTwo.value});

			}
		}).setMin(Setting.PriceMin).setMax(Setting.PriceMax);
	}

	var yearSlider = $('year-slider') || false;
	if (yearSlider) {
		yearResults = $('yearResults').getElement('strong span');
		mySlideB = new SliderX(yearSlider, yearSlider.getElement('.gutter'), {
			range: [1976,2009],
			snap: false,
			steps:89,
			offset: 0,
			onChange: function(pos){
				xx = pos.step;
				yy = pos.maxstep;
				pos.bg.setStyles({'left':pos.leftEdge,'width':Math.abs(pos.rightEdge.toInt()-pos.leftEdge.toInt()+9).round()});
				pos.inputOne.set('value',xx).getNext().set('text',xx);
				pos.inputTwo.set('value',yy).getNext().set('text',yy);
			},
			onComplete:function(pos) {

				var request = new Request.JSON({
					url: '/ajax/carscount.php',
					onComplete: function(resp) {
						yearResults.set('text', resp);
					}
				}).get({'action' : 'year', 'min' : this.elementInputOne.value, 'max' : this.elementInputTwo.value});
			}
		}).setMin(Setting.YearMin).setMax(Setting.YearMax);
	}

	var multiPriceSlider = $('multi-price-slider') || false;
	if (multiPriceSlider) {
		multiResults = $('multiResults').getElement('strong span');
		mySlideX = new SliderX(multiPriceSlider, multiPriceSlider.getElement('.gutter'), {
			range: [0,100],
			snap: true,
			steps: 300,
			offset: 0,
			onChange: function(pos){
				xx = priceRecount(pos.step);
				yy = priceRecount(pos.maxstep);
				pos.bg.setStyles({'left':pos.leftEdge,'width':Math.abs(pos.rightEdge.toInt()-pos.leftEdge.toInt()+9).round()});
				//pos.inputOne.set('value',xx).getNext().set('text',FormatNumberBy3(xx, ".", " ")+' Kč');
				//pos.inputTwo.set('value',yy).getNext().set('text',FormatNumberBy3(yy, ".", " ")+' Kč');
				pos.inputOne.set('value',xx).getNext().set('text',FormatNumberBy3(xx, ".", " ")+'');
				pos.inputTwo.set('value',yy).getNext().set('text',FormatNumberBy3(yy, ".", " ")+'');
			},
			onComplete:function(pos) {
				getMultiCount();
			}
		}).setMin(Setting.PriceMin).setMax(Setting.PriceMax);
	}

	var multiYearSlider = $('multi-year-slider') || false;
	if (multiYearSlider && multiPriceSlider) {
		mySlideY = new SliderX(multiYearSlider, multiYearSlider.getElement('div.gutter'), {
			range: [1976,2009],
			snap: false,
			steps:89,
			offset: 0,
			onChange: function(pos){
				xx = pos.step;
				yy = pos.maxstep;
				pos.bg.setStyles({'left':pos.leftEdge,'width':Math.abs(pos.rightEdge.toInt()-pos.leftEdge.toInt()+9).round()});
				pos.inputOne.set('value',xx).getNext().set('text',xx);
				pos.inputTwo.set('value',yy).getNext().set('text',yy);
			},
			onComplete:function(pos) {
				getMultiCount();
			}
		}).setMin(Setting.YearMin).setMax(Setting.YearMax);
	}

	var newlycarousel = $('newlycarousel') || false;
	var isSmall = $$('#financingetc.frame.small') || false;
	if (newlycarousel) {
		var newlycarouselOne = newlycarousel.getElements('.similarity') || false;
		if (newlycarouselOne) {
			var posun = newlyCarouselFx.length;
			newlycarouselOne.each(function(el,inx){
				var childs = el.getFirst().getChildren();
				if (childs.length > 1) buildCarousel(el,'.one',inx+posun,'left',(isSmall ? 286 : 584),el.getElement('.carouselNav'));
			});
		}
	}

	var similarCarouselArea = $('buildtabs') || false;
	if (similarCarouselArea) {
		var similarity = similarCarouselArea.getElements('.similarity') || false;
		if (similarity) {
			var posun = newlyCarouselFx.length;
			similarity.each(function(el,inx){
				var childs = el.getFirst().getChildren();
				if (childs.length > 1) buildCarousel(el,'.one',inx+posun,'left',577,el.getElement('.carouselNav'));
			});
		}
	}

    var similarCarouselArea2 = $('buildtabsCars') || false;
    if (similarCarouselArea2) {
        var similarity = similarCarouselArea2.getElements('.similarity') || false;
        if (similarity) {
            var posun = newlyCarouselFx.length;
            similarity.each(function(el,inx){
                var childs = el.getFirst().getChildren();
                if (childs.length > 1) buildCarousel(el,'.one',inx+posun,'left',577,el.getElement('.carouselNav'));
            });
        }
    }

	var historycars = $('historycars') || false;
	if (historycars) {
		var posun = newlyCarouselFx.length;
		var childs = historycars.getFirst().getChildren();
		if (childs.length > 1) buildCarousel(historycars,'.one',posun,'top',484,historycars.getElement('.carouselNav'));
	}

	var tooltips = $$('.hasTooltip');
	if (tooltips.length > 0) {
		tooltips.each(function(el){
				var content = el.get('title').split('::');
				el.store('tip:title', content[0]);
				el.store('tip:text', content[1]);
		});
		new Tips(tooltips,{delay:100,fixed:true,offsets:{x:0,y:-40},className:'tip-all'});
	}
	//done_loading();
}

function makeTheAfterReady(){

	var topmenu = $('dropmenu');
	if (topmenu) {
		topmenu.getElements('li.menu').each( function( elem ){
			var list = elem.getElement('ul.links') || false;
			if (list){
				new Element('li',{'class':'submenuTop'}).inject(list,'top');
				new Element('li',{'class':'submenuBottom'}).inject(list,'bottom');
				var sizes = list.getSize();
				listN = new Element('div',{'class':'hide'}).addClass('inMenu').adopt(list.clone().setStyle('visibility','visible'));
				list = listN.replaces(list);

				if (Browser.Engine.trident) new Element('div',{'class':'bgIframe'}).inject(list,'bottom').setStyles({'width':sizes.x,'height':sizes.y}).set({'html':'<iframe width="'+sizes.x+'" height="'+sizes.y+'" frameborder="0" scrolling="no" src=""></iframe>'}).set('opacity',0.01).getFirst().set('opacity',0.01);

				elem.addEvents({
					'mouseenter' : function(){
						list.removeClass('hide');
					},
					'mouseleave' : function(){
						list.addClass('hide');
					}
				});
			}
		})
	}

	var selects = $$('.customSelect');

	if (selects.length > 0) {
		customSelects = [];
		selects.each(function(el,ind){
			customSelects[ind] = new CustomSelect(el,el.getProperty('class').replace('customSelect','').clean(),false,3,true);
			customSelects[ind].addEvent('change', function(e){getMultiCount();});
			if (el.get('id') == 'makespan') customSelects[ind].addEvent('change', function(){loadModels(this, customSelects[3]);});
		});
		if($('imake').get('value') != ''){
			loadModels(customSelects[2], customSelects[3]);
		}
	}

	var smallSelects = $$('span.smallSelect') || false;
	if (smallSelects.length > 0) {
		customSelects = [];
		smallSelects.each(function(el,ind){
			customSelects[ind] = new CustomSelect(el,el.getProperty('class').replace('smallSelect','').clean(),true,0,false);
			if(el.get('id') == 'bindMake') {
				customSelects[ind].addEvent('change', function(e){
					var dest = customSelects.filter(function(item){
						return item.id == 'bindModel';
					})[0];
					loadModels(this, dest, true);
				});
			}
		});

		/*if($('filter_make').get('value') != '' && $('filter_model').get('value') == ''){
			dest = customSelects.filter(function(item){return item.id == 'bindModel'})[0];
			source = customSelects.filter(function(item){return item.id == 'bindMake'})[0];
			loadModels(source, dest, true);
		}*/
	}


	var ajaxSuggestEl = $('ajaxsearchinput') || false;
	if (ajaxSuggestEl) {

		$$('#content4search label[for]').addEvent('click',function(e){
			$(this.get('for')).focus();
			this.addClass('hide');
		});
		$$('#content4search label[for]').each(function(el){if(ajaxSuggestEl.value.length > 0) el.addClass('hide');});
		$$('#content4search input.text','textarea').addEvents({
			'focus':function(){
				this.addClass('focus').getPrevious().addClass('hide');
			},
			'blur':function(){
				if (this.get('value')=="") this.getPrevious().removeClass('hide');
				this.removeClass('focus');
			}
		});

		new Autocompleter.Ajax.Xhtml(ajaxSuggestEl, '/ajax/search.php', {
	    postVar: 'query',
	    markQuery:true,
	    minLength:2,
	    useSelection:false,
	    fxOptions:false,
	    zIndex:100000
		});

	}

	/*textInputs = $$('input[type=text]') || false;
	if (textInputs.length == 0) textInputs.set('value','');*/

	cityDetails = $$('#cities .city div') || false;
	if (cityDetails.length > 0) {
		cityDetails.fade('hide');
	  $$('#cities .city a').each(function(el){
	  	el.getNext().addEvents({'mouseenter':function(){$clear(cityDetailsTimer)},'mouseleave':function(){cityDetailsTimer=setTimeout(function(){cityDetails.fade('out')},500)}});
	  	el.addEvents({mouseenter:function(){$clear(cityDetailsTimer);cityDetails.fade("hide");this.getNext().fade('show');},mouseleave:function(){cityDetailsTimer=setTimeout(function(){cityDetails.fade('out')},5000);}}).getNext().getElement('strong').set('title',el.get('title')).addEvent('click',function(e){e.stop();window.location.href=el.get('href');});
		});
	}

	setTimeout(function(){makeTheSliders();},20);

}

function buildCarousel(el,childs,cnt,prop,val,nav) {
	var newlyCarouselArea = $(el) || false;
	if (newlyCarouselArea) {
		var newlyCarousels = newlyCarouselArea.getElements(childs) || false;
		actualCarouselInt[cnt] = -1;
		newlyCarouselFx[cnt] = new Fx.Elements(newlyCarousels,{'onComplete':function(){runningCarousel[cnt]=false;},transition:'quad:out',duration:500});
		actualCarouselInt[cnt] -= 1;

		hasRunCarousel[cnt] = false;
		runningCarousel[cnt] = false;

		var strLeft = [];
		var strRight = [];
	  for(var ix = 0; ix < newlyCarousels.length; ix++) {
	  	strLeft[ix] = ix+":{'"+prop+"':"+val+",'zIndex':30}";
	  	strRight[ix] = ix+":{'"+prop+"':"+(-val)+",'zIndex':30}";
		}

	  carouselNavigation[cnt] = nav;
	  spanka = new Element('span',{'class':'circle','text':' '});
	  spanka.clone().removeClass('circle').addClass('circleArrowPrev').addEvent('mouseup',function(e){
	  	runCarousel((actualCarouselInt[cnt]-1),cnt,newlyCarousels.length);
			e.stop();
			return false;
		}).inject(carouselNavigation[cnt]);
		switcherObjLeft[cnt] = [];
		switcherObjRight[cnt] = [];
	  newlyCarousels.each(function(el,ind){
	  	var strLeftX = new Array().extend(strLeft);
	  	var strRightX = new Array().extend(strRight);
	  	strLeftX[ind] = ind+":{'"+prop+"':["+(-val)+",0],'zIndex':40}";
	  	strRightX[ind] = ind+":{'"+prop+"':["+val+",0],'zIndex':40}";
	  	switcherObjLeft[cnt][ind] = JSON.decode("{"+strLeftX.join(",")+"}");
	  	switcherObjRight[cnt][ind] = JSON.decode("{"+strRightX.join(",")+"}");
		  spanka.clone().addEvent('click',function(e){runCarousel(ind,cnt,newlyCarousels.length);e.stop();return false;}).inject(carouselNavigation[cnt]);
		});
	  spanka.clone().removeClass('circle').addClass('circleArrowNext').addEvent('click',function(e){
			runCarousel((actualCarouselInt[cnt]+1),cnt,newlyCarousels.length);
			e.stop();
			return false;
		}).inject(carouselNavigation[cnt]);
	  carouselNavigation[cnt] = carouselNavigation[cnt].getElements('span.circle');
		runCarousel(0,cnt,newlyCarousels.length);
	}
}

function runCarousel(ix,c,counter){
	if (runningCarousel[c]) return false;

	runningCarousel[c] = true;
	var switcherObj = []

	if (ix>actualCarouselInt[c]) switcherObj = switcherObjRight[c];
	else switcherObj = switcherObjLeft[c];

	ix = Math.abs((ix + counter)%counter);

	if (ix === actualCarouselInt[c]) return;
	runningCarousel[c] = true;

	if (hasRunCarousel[c]) carouselNavigation[c][actualCarouselInt[c]].removeClass('selectedSpan');
	actualCarouselInt[c] = ix;
	hasRunCarousel[c] = true;
	carouselNavigation[c][ix].addClass('selectedSpan');
	newlyCarouselFx[c].start(switcherObj[ix]);
}


function FormatNumberBy3(num, decpoint, sep) {
  if (arguments.length == 2) sep = ",";
	if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  num = num.toString();
  a = num.split(decpoint);
  x = a[0];
  y = a[1];
  z = "";
  if (typeof(x) != "undefined") {
    for (i=x.length-1;i>=0;i--) z += x.charAt(i);
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep) z = z.slice(0, -sep.length);
    x = "";
    for (i=z.length-1;i>=0;i--) x += z.charAt(i);
    if (typeof(y) != "undefined" && y.length > 0) x += decpoint + y;
  }
  return x;
}

var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		var strWidth = screen.availWidth - 10;
		var strHeight = screen.availHeight - 160;
	}

	var leftVal = (screen.width - strWidth ) / 2;
	var topVal = (screen.height - strHeight) / 2;

	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left="+leftVal+",top="+topVal+"";
	if (type == "scroll") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left="+leftVal+",top="+topVal+"";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function login(lang)
{

	var request = new Request.JSON({
			url: '/ajax/login.php?lang=' + lang,
			onComplete: function(resp) {
				if(resp.ok)
				{
					TB_remove();
					document.location.reload();
				}
				else
				{
					$('loginError').innerHTML = '<span style="color:red">'+ resp.msg +'</span>';
				}
			}
		}).get({'login': $('loginInput').value, 'pass' : $('passInput').value});
		$('loginError').innerHTML = '<img src="/images/ajax-loader.gif" style="margin:0px; border:0px"/>';
}

// window.addEvent('domready',function(){makeTheReady();});

