



function setCloseSetResult(value){
	
	close_set_result=value;
	
}



function showGamerInfo(){
		
	
	if(isNaN(document.getElementById('users_list_select').selectedIndex)) return;
	
	document.getElementById('gamer_name_id').value=document.getElementById('users_list_select').options[document.getElementById('users_list_select').selectedIndex].text;
	document.getElementById('gamer_info_id').value=document.getElementById('users_list_select').options[document.getElementById('users_list_select').selectedIndex].descr.value;
	document.getElementById('gamer_id_id').value=document.getElementById('users_list_select').options[document.getElementById('users_list_select').selectedIndex].value;
	
	
	
}


function openSetResult(){
	
	
	
	if(document.getElementById('users_list_select').selectedIndex==-1) return;
   	var positions=document.getElementById('users_list_select').options[document.getElementById('users_list_select').selectedIndex].value.split('||');
   	if(document.getElementById('set_result_'+positions[0]+'_'+positions[1]))
   	document.getElementById('set_result_'+positions[0]+'_'+positions[1]).style.display='block';   		
		
} 

function deleteResult(){
	if(!confirm('Удаление данного матча может привести к удалению всех зависимых матчей')) return;
	if(document.getElementById('users_list_select').selectedIndex==-1) return;
	
	var positions=document.getElementById('users_list_select').options[document.getElementById('users_list_select').selectedIndex].value.split('||');
	
	
	if(document.getElementById('set_select_form_'+positions[0]+'_'+positions[1])){
		form=document.getElementById('set_select_form_'+positions[0]+'_'+positions[1]);
		form.status.value=0;
   		form.position[0].checked=true;
   		sendFormResult(form);
   	   
   	}	
}




var close_set_result=1;





function closeSetResult(position,opponent_position){
	return; // пока закрываем по крестику
	if(!close_set_result) return;
	if(!document.getElementById('set_result_'+position+'_'+opponent_position)) return;
	document.getElementById('set_result_'+position+'_'+opponent_position).style.display='none';
	
	
}




function sendFormResult(form){
	
	
	
	close_set_result=1;
	if(form.position[2])
		if(form.position[2].checked){
			form.position[0].checked=true;
			form.status.value=3;
		}
	
	
	
	if(form.position[0].checked)
		form.opponent.value=form.position[1].value;
	
	if(form.position[1].checked){
		form.opponent.value=form.position[0].value;	
		form.current_cell.value=form.position[1].value;	
	}
	
	form.submit();	
	
}

 function showSetResult(cell_position,opponent_position){
 	
 	
 	
 	
	if(!document.getElementById('set_result_'+cell_position+'_'+opponent_position))
		return;
	if(!document.getElementById('cell_'+cell_position+'_'+opponent_position))
		return;
		
	if(document.getElementById('set_result_'+cell_position+'_'+opponent_position).style.display=='block')
		return;

		
	//document.getElementById('set_result_'+cell_position+'_'+opponent_position).style.left=mouseX-70+'px';
	//document.getElementById('set_result_'+cell_position+'_'+opponent_position).style.top=mouseY-10+'px';
	document.getElementById('set_result_'+cell_position+'_'+opponent_position).style.display='block';
	
///	alert(	document.getElementById('set_result_'+cell_position+'_'+opponent_position).style.left);
}

function tournamentEditFormSubmit(form){
	var maps = new Array();
	
	for(i=0;i<document.getElementById('users_list_select').options.length;i++)
	{
		 if((i==document.getElementById('users_list_select').selectedIndex)||(document.getElementById('users_list_select').selectedIndex==-1))
		 	 continue;   
		 if(document.getElementById('users_list_select').options[i].text.replace(/^\d+\. /,'').replace(/^ +/,'').replace(/ +$/,'')==document.getElementById('gamer_name_id').value.replace(/^ +/,'').replace(/ +$/,''))
		 	{
		 		alert('Игрок с таким именем уже существует'); 
		 		return;  
		 	}      
	}  
	form.gamer_name.value=document.getElementById('gamer_name_id').value.replace(/^ +/,'').replace(/ +$/,'');
	form.gamer_info.value=document.getElementById('gamer_info_id').value;
	form.gamer_id.value=document.getElementById('gamer_id_id').value;  
	form.game_name.value=document.getElementById('game_name_id').value;   
	form.tour_name.value=document.getElementById('tour_name_id').value; 

	
	if(document.getElementById('maps_list')){
		if(document.getElementById('maps_list').options.length>0){
	
			for( var i=0; i<document.getElementById('maps_list').options.length;i++)
				maps[i]=document.getElementById('maps_list').options[i].text;
						
			
			form.maps.value=maps.join("[@]");
			
		}
	}
	form.submit();

}
