//es una bandera que me indica si estoy en la seccion de resumen o no
var banResumen=false;

function updateCarrerasHtml(calendarid){
	var aleatorio = Math.round(Math.random()*10000);
	if(banResumen){
		strUrl = '/modules/championship/championship.ajax.php?place=1&op=chglist&calendarid=' + $("calen").value+'&catego_id=' + $("idCategoria").value;
		AppObj.Ajax.updaterAjax( strUrl,"divCampeonato");				
	}else{
		strUrl = '/upload/htmls/campeonato_'+calendarid+'_'+$("idCategoria").value+'.htm?ale='+aleatorio;
		AppObj.Ajax.updaterAjax( strUrl,"divCampeonato");		
	}

}

function changeCatego(catego_id,calendarid){
	var aleatorio = Math.round(Math.random()*10000);
	if(banResumen){
		strUrl = '/modules/championship/championship.ajax.php?place=1&op=chglist&calendarid=' + $("calen").value+'&catego_id=' + $("idCategoria").value;				
		strUrl = '/modules/championship/championship.ajax.php?place=1&op=chglist&calendarid=' + $("calen").value+'&catego_id=' +catego_id;
		AppObj.Ajax.updaterAjax( strUrl,"divCampeonato");		
	}else{
		strUrl = '/upload/htmls/campeonato_'+calendarid+'_'+catego_id+'.htm?ale='+aleatorio;
		AppObj.Ajax.updaterAjax( strUrl,"divCampeonato");			
	}

}

function selpiloto(idpiloto){
	var objHighlight = $V(idpiloto).toQueryParams();
	var intFirstDriver = '';
	if(idpiloto.value!=""){
		var elementos=$$('tr.pilotos');		
		elementos.each(function(ele){ 
 			var objCurrentDriver = ele.id.toQueryParams();
 			
			if (objCurrentDriver.team == objHighlight.team || objHighlight.driver == objCurrentDriver.driver) {
				
				if (intFirstDriver=='') intFirstDriver =  objCurrentDriver.driver;
				ele.setStyle({ backgroundColor: '#CCCCCC'}) ;
			} else {
				ele.setStyle({ backgroundColor: '#FFFFFF'}) ;
			}
				
		});

		Effect.ScrollTo('ancla_' + intFirstDriver);				
		
		//window.location.href="#ancla"+idpiloto.value;
	}
}

	function exportpdf(){
			var body=document.getElementsByTagName("body");
			var frm=document.createElement('form');
			frm.id="frm_send";
			frm.name="frm_send";		
			frm.action='/modules/championship/index.php' ;
			frm.method="post";
			frm.target="_blank";
			
			
			var idop=document.createElement('input');
			idop.type="hidden";
			idop.id="op";
			idop.name="op";
			idop.value="exportpdf";
			frm.appendChild(idop);
			
			var idCategoria=document.createElement('input');
			idCategoria.type="hidden";
			idCategoria.id="idCategoria";
			idCategoria.name="idCategoria";
			idCategoria.value=$("idCategoria").value;
			frm.appendChild(idCategoria);		
			
			var placev;
			if(banResumen){placev=2} else {placev=1};
			
			var place=document.createElement('input');
			place.type="hidden";
			place.id="place";
			place.name="place";
			place.value=placev;
			frm.appendChild(place);					
			
			var intidcalendario=document.createElement('input');
			intidcalendario.type="hidden";
			intidcalendario.id="intidcalendario";
			intidcalendario.name="intidcalendario";
			intidcalendario.value=$("calen").value;
			frm.appendChild(intidcalendario);		
			
			body[0].appendChild(frm);
			
			frm.submit();
			Element.remove(frm);
	}

	function exportexcel(){
			var body=document.getElementsByTagName("body");
			var frm=document.createElement('form');
			frm.id="frm_send";
			frm.name="frm_send";		
			frm.action='/modules/championship/index.php' ;
			frm.method="post";
			frm.target="_blank";
			
			
			var idop=document.createElement('input');
			idop.type="hidden";
			idop.id="op";
			idop.name="op";
			idop.value="exportexcel";
			frm.appendChild(idop);
			
			var idCategoria=document.createElement('input');
			idCategoria.type="hidden";
			idCategoria.id="idCategoria";
			idCategoria.name="idCategoria";
			idCategoria.value=$("idCategoria").value;
			frm.appendChild(idCategoria);		
			
			var placev;
			if(banResumen){placev=2} else {placev=1};
			
			var place=document.createElement('input');
			place.type="hidden";
			place.id="place";
			place.name="place";
			place.value=placev;
			frm.appendChild(place);				
			
			var intidcalendario=document.createElement('input');
			intidcalendario.type="hidden";
			intidcalendario.id="intidcalendario";
			intidcalendario.name="intidcalendario";
			intidcalendario.value=$("calen").value;
			frm.appendChild(intidcalendario);		
			
			body[0].appendChild(frm);
			
			frm.submit();
			Element.remove(frm);
	}

	function chgListChampionship ( value ) {
		var aleatorio = Math.round(Math.random()*10000);
		if(value==1) {
			strUrl = '/upload/htmls/campeonato_resumen_anual_'+$("calen").value+'_'+$("idCategoria").value+'.htm?ale='+aleatorio;
			window.open(strUrl);
		} else {
			strUrl = '/modules/championship/championship.ajax.php?place=2&op=chglist&calendarid=' + $("calen").value+'&catego_id=' + $("idCategoria").value;
			AppObj.Ajax.updaterAjax( strUrl,"calendario");						
			banResumen=false;		
		}
	}
	
