var isvote=false;
function getAbsolutePos(el){
  var SL=0
  var ST=0;
  if(el.tagName.toLowerCase()=='div') {
    if(el.scrollLeft) SL=el.scrollLeft;
    if(el.scrollTop) ST=el.scrollTop;
  }
  var r={ x: el.offsetLeft - SL, y: el.offsetTop - ST };
  if(el.offsetParent) {
    var tmp=this.getAbsolutePos(el.offsetParent);
    r.x+=tmp.x;
    r.y+=tmp.y;
  }
  return r;
}
var xoff=1;
var yoff=0;
var xoff_end;
var yoff_end=-280;
var diff;

function testf(){
	items=document.getElementsByClassName('seltown');
	for(i=0;i<items.length;i++){
		if(items[i].style.display=='block'){
			return false;
		}
	}
	return true;
}

function showInp(){
	if(document.getElementById("inpDiv").style.display=='none'){
		document.getElementById("inpDiv").style.display="block";
		document.getElementById("hero").focus();		
	}
	else{
		document.getElementById("inpDiv").style.display="none";
	}
}

function testsub(){
	if(!testf()){
		return false;
	}
	return true;	
}

var langs=0;

document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}
function setAjax(obj){
	var t=obj.value;	
	var type=obj.id;
	if(parseInt(t)>0){
		
		url=window.location.href;
		url=url.split('/');
		url = 'http://'+url[2]+'/ajax.php?type='+type+'&txt='+encodeURIComponent(t);		
		if(url!=lasturl){
			loadXMLDoc(url);
			lasturl=url;
		}
	}
}

function getAjax(obj){
	
	var t=obj.value;
	var type=obj.id;
	if(t.length>0){
		url=window.location.href;
		url=url.split('/');
		url = 'http://'+url[2]+'/ajax.php?type='+type+'&txt='+encodeURIComponent(t);		
		if(url!=lasturl){
			loadXMLDoc(url);
			lasturl=url;
		}
	}
	else{ 
		lasturl='';
		hidf("sel"+obj.id);
	}
}

function keycheck(e,id){
	var code;	
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if(id!=''){
		var obj=document.getElementById('sel'+id);
		var contt=document.getElementById('selinp'+id);		
	}
	else{
		var obj=document.getElementById('seltown');
		var contt=document.getElementById('conttown');
	}
	
	var sel;
	if(obj.style.display=='block'){
		var count=contt.childNodes.length;
		if (code==13) {
			sel=-1;
			for(i=0;i<count;i++){
				if(contt.childNodes[i].className=='itemsel'){
					sel=i;
				}
			}
			if(sel!=-1){				
				if(id!=''){
					document.getElementById(id).value=contt.childNodes[sel].firstChild.nodeValue;
				}
				else{
					document.getElementById('city').value=contt.childNodes[sel].firstChild.nodeValue;
				}
			}			
			setTimeout('hide("'+id+'")',500);
		}		

		if(code==38||code==40){
			
			if(code==38||code==40){
				sel=-1;
				for(i=0;i<count;i++){
					if(contt.childNodes[i].className=='itemsel'){
						sel=i;
						contt.childNodes[i].className='item';
					}
				}
				if (code == 38) {
					sel--;
					if(sel<0){
						sel=count-1;
					}
				}
				if (code == 40) {
					sel++;
					if(sel>=count){
						sel=0;
					}
				}
				if(count>0){
					contt.childNodes[sel].className='itemsel';
				}
			}
		}
	}
	
}


function selItem(o){
	var oid=o.parentNode.id;	
	var oid=oid.substring(6);	
	document.getElementById(oid).value=o.firstChild.nodeValue;
}

function setHero(id){
	yoff_end=-600;
	var hero=document.getElementsByClassName("he"+id)[0];
	document.getElementById("upGif").style.top="0px";
	document.getElementById("upGif").style.display="none";
	hero.style.left=hero.offsetLeft+"px";		
	diff=hero.offsetLeft - parseInt(hero.style.left);	
	hero.style.left=(parseInt(hero.style.left)-diff)+"px";	
	
	xoff_end=hero.offsetLeft+(hero.offsetWidth/2);
	
	document.getElementById("hands").style.left=document.getElementById("hands").offsetLeft+"px";
	diff=document.getElementById("hands").offsetLeft - parseInt(document.getElementById("hands").style.left);
	document.getElementById("hands").style.left=(parseInt(document.getElementById("hands").style.left)-diff)+"px";
	
	if(document.getElementById("up")){
		//document.getElementById("up").href="/hero?up="+id;
	}
	move(hero.offsetLeft);
}


function handUp(hero,id){
	if(nothold){
		xoff_end=hero.offsetLeft+(hero.offsetWidth/2);	
		move(hero.offsetLeft);
		document.getElementById("upGif").style.display="none";
		document.getElementById("hands").style.left=document.getElementById("hands").offsetLeft+"px";
		diff=document.getElementById("hands").offsetLeft - parseInt(document.getElementById("hands").style.left);
		document.getElementById("hands").style.left=(parseInt(document.getElementById("hands").style.left)-diff)+"px";	
		if(document.getElementById("up")){
			//document.getElementById("up").href="/hero?up="+id;	
		}			
	}
}

function heroUp(div,id){
	nothold=false;
	var upGif=document.getElementById("upGif");
	items=document.getElementsByClassName("item");
	count=items.length;
	for(i=0;i<count;i++){		
		items[i].style.cursor="pointer";
	}
	div.style.cursor="default";
	upGif.style.cursor="pointer";
	upGif.style.top="0px";
	upGif.value=id;
	upGif.onclick=function onclick(event){setAjax(this);};
	yoff=0;
	setHero(id);
	yoff_end=-275;
}

function blockItems(){
	items=document.getElementsByClassName("item");
	count=items.length;
	for(i=0;i<count;i++){
		items[i].onclick=function onclick(event){};
		items[i].style.cursor="default";
	}
}

function moveUp(){
	
	var up=document.getElementById("upGif");
	
	
	if(parseInt(up.style.top)<-10){
		up.style.display="block";
	}
	else{
		up.style.display="none";
		if(up.getElementsByTagName("a")[0]){
			up.getElementsByTagName("a")[0].style.display="none";
		}
	}
	var val=0;	
	
	if(parseInt(up.style.top)>parseInt(yoff_end)){
		val=-5;
	}
	else{
		val=5;
	}	
	if(parseInt(up.style.top)>parseInt(yoff_end)-3 && parseInt(up.style.top)>parseInt(yoff_end)+3){			
		yoff=parseInt(up.style.top)+val;	
		up.style.top=(yoff)+"px";	
		setTimeout("moveUp()",0.2);		
	}
	else{
		
		if(up.getElementsByTagName("a")[0]){		
			up.getElementsByTagName("a")[0].style.display="block";
		}			
	}
}

function move(){
	var hands=document.getElementById("hands");
	var val=0;
	
	if(parseInt(hands.style.left)<parseInt(xoff_end)){
		val=5;
	}
	else{
		val=-5;
	}	
	if(parseInt(hands.style.left)<parseInt(xoff_end)-3 && parseInt(hands.style.left)<parseInt(xoff_end)+3){		
		xoff=parseInt(hands.style.left)+val;	
		hands.style.left=(xoff)+"px";	
		setTimeout("move()",0.2);
		stop=false;
	}
	else if(parseInt(hands.style.left)>parseInt(xoff_end)-3 && parseInt(hands.style.left)>parseInt(xoff_end)+3){		
		xoff=parseInt(hands.style.left)+val;	
		hands.style.left=(xoff)+"px";	
		setTimeout("move()",0.2);
		stop=false;
	}
	else{				
		moveUp();
	}
}

function ctrlcheckp(e) {
	var code;	
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

		if ((code == 37) && (e.ctrlKey == true)) {
			var destination = document.getElementById('previous_page');
			if (destination) {
				location.href = destination.href;
			}
		}
		if ((code == 39) && (e.ctrlKey == true)) {
			var destination = document.getElementById('next_page');
			if (destination) {
			location.href = destination.href;
		}
	}
}
///////slayder/////weight height////////////
var sl_x=new Array();
var sl_start_left=new Array();
var sl_start=new Array();
var lay_left=new Array();
lay_left[1]=0;
lay_left[2]=0;

function slaystart(num,e){
	if(!sl_start[num]){
		sl_start[num]=true;
		sl_start_left[num]=lay_left[num];
		sl_x[num] = (window.Event) ? e.pageX : event.clientX;
	}
	else{
		sl_start[num]=false;
	}
}

function slaymove(num,e){
	if(sl_start[num]){
		var x_tmp = (window.Event) ? e.pageX : event.clientX;
		lay_left[num]=parseInt(sl_start_left[num])+parseInt(x_tmp-sl_x[num]);
		if(lay_left[num]<0) lay_left[num]=0;
		if(lay_left[num]>188) lay_left[num]=188;
		slaydraw(num);
	}
}

function slayend(num){
	if(sl_start[num]){
		sl_start[num]=false;
	}
}

function slayclick(num,e){
	if(sl_start[num]){
		var x_tmp = (window.Event) ? e.pageX : event.clientX;
		t=getAbsolutePos(document.getElementById('laybg'+num));
		lay_left[num]=(x_tmp-t.x);
		slaydraw(num);
	}
}

function slaydraw(num){
		if(num==1){
			temp=parseInt(lay_left[num]/1.25)+100;
			document.getElementById('height').value=temp;
			document.getElementById('slayval'+num).innerHTML=parseInt(temp/100)+'� '+(temp-parseInt(temp/100)*100)+'��';
		}
		if(num==2){
			temp=parseInt(lay_left[num]/1.1)+35;
			document.getElementById('weight').value=temp;
			document.getElementById('slayval'+num).innerHTML=parseInt(temp)+'��';
		}	
	obj=document.getElementById('layval'+num);
	obj.style.left=lay_left[num]+'px';
}
///////////end slayder////////////////////////


/*function funfoto(e){
	document.getElementById('foto').style.display='block';
	x = (window.Event) ? e.pageX : event.clientX;
	y = (window.Event) ? e.pageY : event.clientY;

	d=0;
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		d=document.documentElement.scrollTop;
	}
	y=y+d;
	document.getElementById('foto').style.cursor='pointer';
	r=getAbsolutePos(document.getElementById('brovise'));
	if(r.x>x){
		document.getElementById('foto').style.display='none';
	}
	
	if(r.y>y){
		document.getElementById('foto').style.display='none';
	}

	if((r.x+document.getElementById('ffnam').clientWidth)<x){
		document.getElementById('foto').style.display='none';
	}

	if((r.y+document.getElementById('ffnam').clientHeight)<y){
		document.getElementById('foto').style.display='none';
	}
	
	document.getElementById('foto').style.left=x-r.x-36+'px';
	document.getElementById('foto').style.top=y-r.y-3+'px';
}*/

var cont_h=0;
var cont_w=0;
var isdrag=false;
var isresize=false;

var drag_h=160;
var drag_w=120;
var drag_x=0;
var drag_y=0;

var start_x=0;
var start_y=0;
var ss_x=0;
var ss_y=0;

var proc_w=3;
var proc_h=4;


function preparecroper(a,imgt,w,h){
	document.getElementById('close').style.display='block';
	document.getElementById(a+'_c').style.width=w+'px';
	document.getElementById(a+'_c').style.height=h+'px';
	document.getElementById(a+'_c').style.backgroundImage='url('+imgt+')';
	document.getElementById('butsave').style.display='block';
	document.getElementById('sel').style.display='block';
	
	if(w>h && document.getElementById('crop_task_id').value!=1){
		proc_w=4;
		proc_h=3;
		drag_h=120;
		drag_w=160;
	}
	else{
		proc_w=3;
		proc_h=4;
		drag_h=160;
		drag_w=120;
	}
	
	if((h/proc_h)>(w/proc_w)){
		drag_w=w-20;
		drag_x=10;
		drag_h=drag_w/proc_w*proc_h;
		drag_y=(h-drag_h)/2;
	}
	else{
		drag_h=h-20;
		drag_y=10;
		drag_w=drag_h/proc_h*proc_w;
		drag_x=(w-drag_w)/2;
	}
	//alert(drag_w+' '+);
	
	drag_draw();
	cont_h=h;
	cont_w=w;
}

/////////////////////drag
//window.onload=drag_draw;

function drag_draw(){
	obj=document.getElementById('sel');
	obj.style.height=drag_h+'px';
	obj.style.width=drag_w+'px';
	obj.style.left=drag_x+'px';
	obj.style.top=drag_y+'px';
	
	
	document.getElementById('crop_x').value=drag_x;
	document.getElementById('crop_y').value=drag_y;
	document.getElementById('crop_h').value=drag_h;
	document.getElementById('crop_w').value=drag_w;
}

function startsel(e){
	if(!isresize){
		isdrag=true;
		start_x = (window.Event) ? e.pageX : event.clientX;
		start_y = (window.Event) ? e.pageY : event.clientY;
		ss_x=drag_x;
		ss_y=drag_y;
	}
}

function endsel(){
	isdrag=false;
	isresize=false;
}

function movesel(e){
	if(isdrag && !isresize){
		cx = (window.Event) ? e.pageX : event.clientX;
		cy = (window.Event) ? e.pageY : event.clientY;
		drag_x=ss_x+cx-start_x;
		drag_y=ss_y+cy-start_y;
		if(drag_x<0) drag_x=0;
		if(drag_y<0) drag_y=0;
		if((drag_x+drag_w)>cont_w){
			drag_x=cont_w-drag_w-2;
		}
		if((drag_y+drag_h)>cont_h){
			drag_y=cont_h-drag_h-2;
		}
		drag_draw();
	}
	else if(isresize){
		resizesel(e);
	}
}

function startresize(e){
	isdrag=false;
	isresize=true;
	start_x = (window.Event) ? e.pageX : event.clientX;
	start_y = (window.Event) ? e.pageY : event.clientY;
	ss_x=drag_w;
	ss_y=drag_h;
}

function endresize(){
	isresize=false;
}

function resizesel(e){
	if(isresize){
		cx = (window.Event) ? e.pageX : event.clientX;
		cy = (window.Event) ? e.pageY : event.clientY;
		drag_w=cx-start_x+ss_x;
		drag_h=cy-start_y+ss_y;
		
		
		if((drag_w/proc_w)>(drag_h/proc_h)){
			drag_h=drag_w/proc_w*proc_h;
		}
		else{
			drag_w=drag_h/proc_h*proc_w;
		}
		
		if(drag_w<(proc_w*20)){
			drag_w=(proc_w*20);
		}
		if(drag_h<(proc_h*20)){
			drag_h=(proc_h*20);
		}
		if((drag_w+drag_x)>cont_w){
			drag_w=cont_w-drag_x-2;
		}
		if((drag_h+drag_y)>cont_h){
			drag_h=cont_h-drag_y-2;
		}
		
		if((drag_w/proc_w)>(drag_h/proc_h)){
			drag_w=drag_h/proc_h*proc_w;
		}
		else{
			drag_h=drag_w/proc_w*proc_h;
		}
		drag_draw();
	}
}

/////////////////////end drag



function closew(){
	document.getElementById('sel').style.display='none';
	Obj=document.getElementById('bgcropcont_c');
	Obj.style.width="0";
	Obj.style.height="0";
	Obj=document.getElementById('bgcropcont');
	Obj.style.width="300px";
	Obj.style.height="300px";
	Obj.style.marginLeft="-150px";
	Obj.style.marginTop="-150px";
	Obj.style.display="none";
	Obj=document.getElementById('bgcrop');
	Obj.style.display="none";
	Obj.style.opacity = '0';
	Obj.style.filter = 'alpha(opacity=0)';
	document.getElementById('butsave').style.display='none';
	document.getElementById('close').style.display='none';
	document.getElementById('bgcropcont_c').style.backgroundImage='none';
}

function testsize(){
	obj=document.getElementById('bgcropcont');
	r=getAbsolutePos(obj);
	if(r.x<0){
		obj.style.left=0;
		obj.style.marginLeft=0;
	}
	if(r.y<0){
		obj.style.top=0;
		obj.style.marginTop=0;
	}
}

function handleResponse(imgt,w,h,task_id) {
	//alert(imgt+'|'+w+"|"+h);
	if(w>200 || h>200){
  	resizer('bgcropcont',w+32,h+80,imgt);
  	document.getElementById('formaterror1').style.display='none';
  	document.getElementById('crop_task_id').value=task_id;
  	document.getElementById('crop_img').value=imgt;
	}
	else{
		if(imgt==0){
			txt='������ ����� �� ������ ���� ������ ��� 2��.';
		}
		else if(w==0 && h==0){
			txt='�������� ������ ����������� �����.';
		}
		else{
			txt='����������� ����� ���� ������ ��� 200�200.';
		}
		document.getElementById('formaterror1').style.display='block';
		document.getElementById('formaterror').innerHTML=txt;
		closew();
	}
}

function resizer(a,w,h,imgt){
	ws=w;
	if(a=='galbg'){if(w<320) w=320;}
	
	stepsize=5;
	delay=25;

	obj=document.getElementById(a);
	w0=obj.clientWidth;
	h0=obj.clientHeight;
	dw=w-w0;
	dh=h-h0;
	
	
	m=Math.abs(dw);
	step=parseInt(m/stepsize);
	for(var i=0;i<=step;i++)	{
		if(step!=1){
			setTimeout('document.getElementById("'+a+'").style.marginLeft="-'+((w0+(dw/(step-1))*i)/2)+'px"; document.getElementById("'+a+'").style.width="'+(w0+(dw/(step-1))*i)+'px";',delay*i);			
		}
		else{
			setTimeout('document.getElementById("'+a+'").style.marginLeft="-'+((w0+(dw)*i)/2)+'px"; document.getElementById("'+a+'").style.width="'+(w0+(dw)*i)+'px";',delay*i);			
		}
	}
	dtime=step*delay;
	m=Math.abs(dh);
	step=parseInt(m/stepsize);

	for (var i=0;i<=step;i++)	{
		if(i<step){
			if(step!=1){
				setTimeout('document.getElementById("'+a+'").style.height="'+(h0+(dh/(step-1))*i)+'px";document.getElementById("'+a+'").style.marginTop="-'+((h0+(dh/(step-1))*i)/2)+'px";',delay*i+dtime);
			}
			else{
				setTimeout('document.getElementById("'+a+'").style.height="'+(h0+(dh)*i)+'px";document.getElementById("'+a+'").style.marginTop="-'+((h0+(dh)*i)/2)+'px";',delay*i+dtime);
			}
		}
		else{
			if(a=='galbg'){
				setTimeout('galimg("'+imgt+'","'+(ws-32)+'","'+(h-72)+'");',(delay*i+200)+dtime);
			}
			else{
				setTimeout('preparecroper("'+a+'","'+imgt+'","'+(w-32)+'","'+(h-80)+'")',(delay*i+200)+dtime);
			}
		}
	}
	
/////////variant-2
//	m=Math.abs(dw);
//	if(Math.abs(dw)<Math.abs(dh)){
//		m=Math.abs(dh);
//	}
//	step=parseInt(m/10);
	
//	for (var i=0;i<=step;i++)	{
//		if(i<step){
//			setTimeout('document.getElementById("'+a+'").style.marginLeft="-'+((w0+(dw/(step-1))*i)/2)+'px"; document.getElementById("'+a+'").style.width="'+(w0+(dw/(step-1))*i)+'px";document.getElementById("'+a+'").style.height="'+(h0+(dh/(step-1))*i)+'px";document.getElementById("'+a+'").style.marginTop="-'+((h0+(dh/(step-1))*i)/2)+'px";',50*i);
//		}
//		else{
//			if(a=='galbg'){
//				
//				setTimeout('galimg("'+imgt+'","'+(ws-32)+'","'+(h-72)+'");',(50*i+200));
//			}
//			else{
//				setTimeout('preparecroper("'+a+'","'+imgt+'","'+(w-32)+'","'+(h-80)+'")',(50*i+200));
//			}
//		}
//	}
}


function galimg(imgt,w,h){
	//alert(parseInrt);
	var freeball=parseInt(document.getElementById('freeball').value);
	var givenball=parseInt(document.getElementById('givenball').value);
	
	obj=document.getElementById('imggall')
	obj.style.height=h+'px';
	obj.style.width=w+'px';
	document.getElementById('imggall'+2).innerHTML='<img src="'+imgt+'">';
	
	document.getElementById('fotoitem').style.display='block';
	document.getElementById('namegal').style.display='block';
	document.getElementById('ballgal').style.display='block';
	
	if(document.getElementById('islogin').value==1 && document.getElementById('issex').value==1){
		document.getElementById('ratinggal').style.display='block';	
		document.getElementById('rfoot').style.display='block';	
		document.getElementById('lfoot').style.display='block';	
		
	if(freeball<=0 && givenball>0){
		document.getElementById('lfoot').style.display='none';
	}
	else{
		document.getElementById('lfoot').style.display='block';
	}
	
	if(freeball<=0 && givenball<0){
		document.getElementById('rfoot').style.display='none';
	}
	else{
		document.getElementById('rfoot').style.display='block';
	}
	
	if(freeball==0 && givenball==0){
		document.getElementById('rfoot').style.display='none';
		document.getElementById('lfoot').style.display='none';
		document.getElementById('ratinggal').style.display='none';	
	}
	}
}

function cropimgshow(a){
	showbg('bgcrop','bgcropcont');
	setTimeout('document.f1.submit()',900);
}

function resize() {
	if (document.compatMode && document.compatMode != "BackCompat"){
	   Height = document.documentElement.clientHeight;
	}
	else{
   	Height = document.body.clientHeight;
	}
	dh=document.getElementById('galbg').clientHeight;
	
	if(dh>Height){
		dh=Height;
	}
	document.getElementById('galbg').style.marginTop=(dh/2*-1)+'px';
	return false;
}

function check(){
	a='ch1';
	b='checki';
	if(document.getElementById(b).value==0){
		document.getElementById(a).className="check";
	}
}

function checkb(a,c){
	b=document.getElementById(c).value;
	if(b==0)	{
		a.className="checksel";
		document.getElementById(c).value=1;
	}
	else {
		a.className="check";
		document.getElementById(c).value=0;
	}
}

function selsex(a){
	document.getElementById('man').src='/res/gfx/sex_man.gif';
	document.getElementById('wman').src='/res/gfx/sex_wman.gif';
	document.getElementById('wmant').className='';
	document.getElementById('mant').className='';		

	document.getElementById('sex').value=a;
	document.getElementById(a).src='/res/gfx/sex_'+a+'_sel.gif';
	document.getElementById(a+'t').className='sel';
}

///////////--------///////////
function showbg(lay,bgcont){
	if (document.compatMode && document.compatMode != "BackCompat"){
	   theHeight = document.documentElement.scrollHeight;
	}
	else{
   	theHeight = document.body.scrollHeight;
	}
	document.getElementById(lay).style.display='block';
	document.getElementById(lay).style.height=theHeight+'px';
	for (var i=0;i<=8;i++)	{
		if(i!=8){
			setTimeout('setOpacity('+i+',"'+lay+'")',100*i);
		}
		else{
			dtop=document.documentElement.scrollTop;	
			htop=document.documentElement.clientHeight;
			prc=50;
			if(htop>0){
				prc=parseInt(dtop/htop*100)+50;
			}
			
			document.getElementById(bgcont).style.top=prc+'%';
			setTimeout("document.getElementById('"+bgcont+"').style.display='block';",100*i);
		}
	}
}

function setOpacity(value) {
	Obj=document.getElementById('gallay');
	Obj.style.opacity = value/10;
	Obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}


//////////--------////////////

function show(user,task){
	dtop=document.documentElement.scrollTop;	
	htop=document.documentElement.clientHeight;
	prc=50;
	if(htop>0){
		prc=parseInt(dtop/htop*100)+50;
	}
	//alert(prc);
	document.getElementById('galbg').style.top=prc+'%';
	document.getElementById('galbg').style.display='block';
	
	url=window.location.href;
	url=url.split('/');
	url = 'http://'+url[2]+'/ajax.php?user_id='+user+'&task='+task; 
	loadXMLDoc(url);
}

function showgal(user,task){
	
	if (document.compatMode && document.compatMode != "BackCompat"){
	   theHeight = document.documentElement.scrollHeight;
	}
	else{
   	theHeight = document.body.scrollHeight;
	}
	if(document.getElementById('gallay').style.display=='block'){
		
		document.getElementById('fotoitem').style.display='none';
		document.getElementById('ballgal').style.display='none';
		document.getElementById('rfoot').style.display='none';
		document.getElementById('ratinggal').style.display='none';
		document.getElementById('lfoot').style.display='none';
		
		document.getElementById('imggall2').innerHTML='';
		obj=document.getElementById('imggall');
		obj.style.height=0+'px';
		obj.style.width=0+'px';		
		
		show(user,task);
	}
	else{
		document.getElementById('gallay').style.display='block';
		document.getElementById('gallay').style.height=theHeight+'px';
		
		for (var i=0;i<=8;i++)	{
			if(i!=8){
				setTimeout('setOpacity('+i+')',100*i);
			}
			else{
				setTimeout('show('+user+','+task+');',100*i);
			}
		}
	}
}

function hidegal(){
	if(isvote){
		location.href=window.location.href;
	}
	else{
		document.getElementById('fotoitem').style.display='none';
		document.getElementById('namegal').style.display='none';
		document.getElementById('ballgal').style.display='none';
		document.getElementById('lfoot').style.display='none';
		document.getElementById('rfoot').style.display='none';
		document.getElementById('ratinggal').style.display='none';
		document.getElementById('imggall2').innerHTML='';
		
		obj=document.getElementById('imggall');
		obj.style.height=0+'px';
		obj.style.width=0+'px';
		document.getElementById('gallay').style.display='none';
		
		obj=document.getElementById('galbg');
		obj.style.width='300px';
		obj.style.height='300px';
		obj.style.marginTop='-150px';
		obj.style.marginLeft='-150px';
	
		obj.style.display='none';
		
		Obj=document.getElementById('gallay');
		Obj.style.opacity = 0;
		Obj.style.filter = 'alpha(opacity=0)';
	}
}

var req;

function loadXMLDoc(url){
    if (window.XMLHttpRequest){
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject){
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function hide(a){
	setTimeout('hidf("sel'+a+'")',500);
}

function hid(a){
	setTimeout('hidf("'+a+'")',500);
}

function hidf(a){
	document.getElementById(a).style.display='none';
}

function chtown(){
	if(document.getElementById('town').value!=''){
		url=window.location.href;
		url=url.split('/');
		url = 'http://'+url[2]+'/ajax.php?checktown=1&txt='+document.getElementById('town').value+'&l='+document.getElementById('town').value.length; 
		loadXMLDoc(url);
	}
	else{
		document.getElementById('notown').style.display='none';
	}
}

function getTown(a){	
	setTimeout('getTownf("'+a+'")',100);
}

var lasturl='';
var lastch='';

function getTownf(a){	
	t=document.getElementById(a).value;
	c=t.charCodeAt(t.length-1);
	if((c>=65 && c<=97) || (c>=90 && c<=122)){
		document.getElementById(a).value=document.getElementById(a).value.substr(0,(t.length-1));
		setTimeout("document.getElementById('noeng').style.display='block';",100);
		hidf('townlist');
	}
	else{
		setTimeout("document.getElementById('noeng').style.display='none'",50);
		if(t.length>0){
			url=window.location.href;
			url=url.split('/');
			url = 'http://'+url[2]+'/ajax.php?txt='+t+'&l='+t.length;
			
			if(url!=lasturl){
				loadXMLDoc(url);
				lasturl=url;
			}
		}
		else{
			lasturl='';
			hidf('townlist');
		}
	}
}


function addtown(){
	document.getElementById('townnew').value=1;
	document.getElementById('notown').innerHTML='����� "'+document.getElementById('town').value+'" ����� ��������.';
}

function processReqChange()
{
	if (req.readyState == 4){
		if (req.status == 200){
			var a=req.responseXML;
			var root = a.documentElement;
			var type=root.getElementsByTagName("type");
			var cs=type[0].getAttribute("t");
			if(cs=="hero"){
				var hero=a.getElementsByTagName("item");
				var obj=document.getElementById("sel"+cs);
				var contt=document.getElementById("sel"+cs);
				
				contt.innerHTML='';
				
				div1=document.createElement('div');		
				div1.className="l";
				div1.innerHTML="";
				
				div2=document.createElement('div');
				div2.className="r";
				div2.innerHTML="";
				
				if(hero.length>0){
					obj.style.display='block';					
				}
				
				
				inp=document.createElement('div');		
				inp.className="inp";
				inp.id="selinp"+cs;
				
				inp.innerHTML="";				
				for(var i=0;i<hero.length;i++){
					var title=hero[i].getAttribute('title');
					var div=document.createElement('div');
					div.className='item';
					div.onclick = new Function('selItem(this)');
					div.onmouseout = new Function('outit(this)');
					div.onmouseover = new Function('indiv(this)');
					div.innerHTML=title;
					inp.appendChild(div);
				}
				div2.appendChild(inp);
				div1.appendChild(div2);				
				contt.appendChild(div1);
			}			
			else if(cs=="upGif"){			
				yoff_end=-600;
				moveUp();		
				var thanks=document.createElement("span");
				thanks.innerHTML="Спасибо";
				document.getElementById("anch").appendChild(thanks);
				document.getElementById("up").style.display="none";				
				blockItems();
			}

			var a=req.responseText;
			if(a=='ok'){;}
			else if(a.substr(0,9)=='checktown'){
				if(a!=''){
					istown=a.substr(10,11);
					if(istown==0){
						document.getElementById('notown').style.display='block';
						document.getElementById('notown').innerHTML='������ "'+document.getElementById('town').value+'" ��� � ����� ���� <span class="addtown" onclick="addtown()">��������</span>?';
						document.getElementById('townnew').value=0;
					}
					else{
						document.getElementById('notown').style.display='none';
					}
				}
			}
			else if(document.getElementById('townlist')){
				document.getElementById('townlist').style.display='block';
				document.getElementById('towncont').innerHTML=a;
				len=a.length;
				if(len==0){
					document.getElementById('townlist').style.display='none';
				}
			}
			else{
				if (window.ActiveXObject) {
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async=false;
			    xmlDoc.loadXML(a); 
				} 
				else if (document.implementation && document.implementation.createDocument) {
					var parser = new DOMParser();
					var xmlDoc = parser.parseFromString(a, "text/xml");
				} 
				else {
					alert('Your browser cannot handle this script');
				}
				var root = xmlDoc.documentElement;
				type=root.getAttribute("type");
				
				if(type=='gal')	{
					var viewuser=root.getElementsByTagName("viewuser");
					document.getElementById('islogin').value=viewuser[0].getAttribute("islogin");
					document.getElementById('ratinggal').innerHTML=viewuser[0].getAttribute("givenball");
					document.getElementById('givenball').value=viewuser[0].getAttribute("givenball");
					document.getElementById('freeball').value=viewuser[0].getAttribute("freeball");
					document.getElementById('issex').value=viewuser[0].getAttribute("issex");
					
					document.getElementById('allball').value=Math.abs(viewuser[0].getAttribute("givenball"))+Math.abs(viewuser[0].getAttribute("freeball"));
					
					var user=root.getElementsByTagName("user");
					document.getElementById('reader_id').value=user[0].getAttribute("reader_id");
					document.getElementById('namegal').innerHTML=user[0].getAttribute("name");
					document.getElementById('ballgal').innerHTML=user[0].getAttribute("rating");
					
					var items=root.getElementsByTagName("item");
					str='';
					for(i=1;i<=6;i++){
						
						if(items[(i-1)].getAttribute("type")==2){
							document.getElementById('balltask').value=i;
							str+='<div class="tek"><img src="/res/gfx/galact.gif" width="12" height="12" alt="" /></div>';
						}
						else if(items[(i-1)].getAttribute("type")==1){
							str+='<div class="ok"><img onclick="showgal('+items[(i-1)].getAttribute("reader_id")+','+items[(i-1)].getAttribute("task")+')" src="/res/gfx/galact.gif" width="12" height="12" alt="" /></div>';
						}
						else{
							str+='<div><img src="/res/gfx/galno.gif" width="12" height="12" alt="" /></div>';
						}
					}
					document.getElementById('fotoitem').innerHTML=str;
					
					var img=root.getElementsByTagName("img");
				

					resizer('galbg',parseInt(img[0].getAttribute("width"))+32,parseInt(img[0].getAttribute("height"))+72,img[0].getAttribute("src"));
				
			////xml///
							
				}
			}
		} 
		else {
    	alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}

function selTown(o,a,b){
	document.getElementById(b).value=o.firstChild.nodeValue;
}

var colorsel="#340013";
var colorok='black';

function odiv(a){
	for(count=0;document.getElementById('towncont').childNodes[count];count++){
		document.getElementById('towncont').childNodes[count].style.backgroundColor=colorok;
	}	
	a.style.backgroundColor=colorsel;
	a.style.zindex='51';
}

function outit(a){
	a.className="item";
}
function indiv(a){
	a.className="itemsel";
}
function outdiv(a){
	a.style.backgroundColor=colorok;
	a.style.zindex='50';
}

function ctrlcheck(e){
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
		if(document.getElementById('townlist').style.display=='block'){
		if (code == 13) {
			for(count=0;document.getElementById('towncont').childNodes[count];count++){;}
			sel=-1;
			for(i=0;i<count;i++){
				if(document.getElementById('towncont').childNodes[i].style.zIndex=='51'){
					sel=i;
				}
			}
			if(sel!=-1){
				document.getElementById('town').value=document.getElementById('towncont').childNodes[sel].firstChild.nodeValue;
			}
			hid('townlist');
		}
		
			if(code==38||code==40){
				for(count=0;document.getElementById('towncont').childNodes[count];count++){
				}
				sel=-1;
				for(i=0;i<count;i++){
					if(document.getElementById('towncont').childNodes[i].style.zIndex=='51'){
						sel=i;
						document.getElementById('towncont').childNodes[i].style.zIndex='50';
						document.getElementById('towncont').childNodes[i].style.backgroundColor=colorok;
					}
				}
			if (code == 38) {
				sel--;
				if(sel<0){
					sel=count-1;
				}
			}
			if (code == 40) {
				sel++;
				if(sel>=count){
					sel=0;
				}
			}
			if(count>0){
				document.getElementById('towncont').childNodes[sel].style.backgroundColor=colorsel;
				document.getElementById('towncont').childNodes[sel].style.zIndex='51';
			}
		}
	}
}

function testp(a){
	if(document.getElementById(a).style.display=='block'){
		return false;
	}
}

function giveball(type){
	var freeball=parseInt(document.getElementById('freeball').value);
	var givenball=parseInt(document.getElementById('givenball').value);
	var reader_id=document.getElementById('reader_id').value;
	//all=document.getElementById('allball').value;
	isvote=true;
	var task=document.getElementById('balltask').value;
	
	//document.title=freeball+'|'+givenball;
	
	if(type==1 && (freeball>0 || givenball<0)){
		
		if(givenball>=0){
			//alert(freeball-1);
			freeball=freeball-1;
			givenball=givenball+1;
		}
		else{
			givenball+=1;
			freeball+=1;
		}
	}
	if((givenball>0 || freeball>0) && type==2){
		if(givenball>0){
			givenball-=1;
			freeball+=1;
		}
		else{
			freeball-=1;
			givenball-=1;
		}
	}
	
	if(freeball<=0 && givenball>0){
		document.getElementById('lfoot').style.display='none';
	}
	else{
		document.getElementById('lfoot').style.display='block';
	}
	
	if(freeball<=0 && givenball<0){
		document.getElementById('rfoot').style.display='none';
	}
	else{
		document.getElementById('rfoot').style.display='block';
	}
	document.getElementById('givenball').value=givenball;
	document.getElementById('freeball').value=freeball;
	document.getElementById('ratinggal').innerHTML=givenball;

	url=window.location.href;
	url=url.split('/');
	url='http://'+url[2]+'/vote.php?type='+type+'&reader_id='+reader_id+'&task='+task;
	loadXMLDoc(url);
}