function slide_tog(div_id){
	 $("#" + div_id).slideToggle("slow");
}

function text_chnange(div_id,div_content,div_content2){
	if( $("#" + div_id).html() == div_content) {
	 	$("#" + div_id).text(div_content2);
	 	document.getElementById('arrow_brown_down').setAttribute("src","img/close_brown.gif");
	} else {
		$("#" + div_id).text(div_content);
		document.getElementById('arrow_brown_down').setAttribute("src","img/arrow_brown_down.gif");
	}
}


function toggle_img(img_id,img_src1,img_src2){
	if(document.getElementById(img_id).getAttribute("src") == img_src2){
	 	document.getElementById(img_id).setAttribute("src",img_src1);
	} else {
		document.getElementById(img_id).setAttribute("src",img_src2);
	}
}

function select_center(center){
	$.get("index.php?page=quiere_hacerse_socio_form", { center: center }, function(data)
	{
		 $("#center_selected").html(data);
		 if (center == '0')  document.getElementById('show_content').style.display = 'none';
	});
}

function select_center2(center){
	$.get("index.php?page=quiere_hacerse_socio_preinscripcion2", { center: center }, function(data)
	{
		$("#center_selected").html(data);
		if (center == '0')  document.getElementById('show_content').style.display = 'none';
	});
}

function sum_total2(price1, price2, center){
	if(price1 == ''){
		price1 = 0;
	}

	$.get("index.php?page=quiere_hacerse_socio_form", { price1: price1, price2: price2, center: center }, function(data)
		{
			 $("#registration_total").html(data);
		});
}

function sum_all(price1, center,offer){
	if(price1 == ''){
		price1 = 0;
	}

	// Price2 is got here, it is not a parameter
    price2 = document.getElementsByName("service");
    //alert(price2[0].value);
	aux = '';


	// This gives the ids for other services.
    for (i=0;i<price2.length;++i)  {
	  if (price2[i].checked)  {
			j = price2[i].value
		 	aux = aux + ',' + j ;
	  }
    }

	if (price2 != '') price2 = aux.substring(1,aux.length)


	$.get("index.php?page=quiere_hacerse_socio_form", { price1: price1, price2: price2, center: center, offer: offer }, function(data)
		{
			 $("#registration_total").html(data);
		});

}

function change_form(step, lng, center_id, membership_id, offer_id, other_services_id, lngID){

	if( step == 2 ){
		$.get("index.php?page=quiere_hacerse_socio_form_2&lng=" + lng, {center_id: center_id, membership_id: membership_id, other_services_id: other_services_id, lngID: lngID, offer_id: offer_id  }, function(data)
			{
				document.getElementById('step_images_1').style.display = 'none';
				document.getElementById('form_container').style.display = 'none';
				$("#step2_form").html(data);
			});
	}
	if ( step == 3 ){
		alert('dentro');
	}
}


function form_go_back(step){
	if (step == 1){
		$("#step2_form").html('');
		document.getElementById('step_images_1').style.display = 'block';
		document.getElementById('form_container').style.display = 'block';
	}
}


function change_image(id,image){
	document.getElementById(id).setAttribute("src",image);
}

/* ********************** */
/* Running  			  */
/* ********************** */
function select_city_routes(center_id){
	$.get("index.php?page=routes", { center_id: center_id }, function(data)
		{
			 $("#routes_div").html(data);
		});
}

function select_running_club_link(){
	$.get("index.php?page=running_club_select_center", { }, function(data)
		{
			 $("#running_club_options").html('');
			 $("#running_club_select_center").html(data);

		});
}





/* ********************** */
/* Tail    				  */
/* ********************** */
function change_disp(div_id){
	if( $('#'+div_id).css('display') == 'none' ){
		$('#'+div_id).slideDown("");
	}else{
		$('#'+div_id).slideUp("");
	}
}

function put_center_timetable(i){
	
	if (  (document.getElementById('select_center_div_' + i).innerHTML).length > 14){
		aux = (document.getElementById('select_center_div_' + i).innerHTML).split(' - ');
		text = aux[aux.length-1];// Puts name of the center
		document.getElementById('center_selected_timetable').innerHTML = text;// Puts name of the center
	}else{
		document.getElementById('center_selected_timetable').innerHTML = document.getElementById('select_center_div_' + i).innerHTML; // Puts name of the center
	}
	document.getElementById('select_center_div').style.display = 'none' // Like a slideUp
	$.get("index.php?page=show_timetable&center_id=" + i, {center_id : i}, function(data){
	  document.getElementById('TICKER').innerHTML = data;
	  restart_ticker();
	});


	$.get("index.php?page=show_timetable&center_id=" + i, {only_button : '1'}, function(data){
	  document.getElementById('timetablebutton').innerHTML = data;
	});
	

}



function redirect(url){
	document.location.href=url;
}

function open_new_window(str) {
	open(str, 'Sizewindow', 'width=640,height=450,scrollbars=yes,toolbar=no');
}


/* **************************** */
/* Airport text					*/
/* **************************** */

function airport_text(miprueba){
	var text= new Array();
	text = document.getElementById(miprueba).innerHTML;
	document.getElementById(miprueba).innerHTML = '';
	var new_text;
	new_text = '';


	setTimeout('put_text("'+miprueba+'","'+text+'","'+new_text+'",0,0)',1);

}


function put_text(miprueba, text,new_text, pos, abc_pos){
	var abc = Array();
	abc = [' ', '.', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-'];
	var text_array = text.split("");

	//text = text.split("");



	if (abc[abc_pos] == text_array[pos]){
			document.getElementById(miprueba).innerHTML = new_text + text_array[pos];
			new_text= document.getElementById(miprueba).innerHTML;
	}else{
		document.getElementById(miprueba).innerHTML = new_text + abc[abc_pos];
	}

	 if (abc[abc_pos] == text_array[pos]){
		if(pos < text.length - 1){
			abc_pos = 0;
			pos++;
			setTimeout('put_text("'+miprueba+'","'+text+'", "'+new_text+'", "'+pos+'", "'+abc_pos+'")',1);
		}
	 }else{
	  if(abc_pos < 30){
		abc_pos++;
		setTimeout('put_text("'+miprueba+'", "'+text+'", "'+new_text+'", "'+pos+'", "'+abc_pos+'")',1);
	  }

	 }
}


function display_center_info(div1,div2,arrow_id){
	$("#"+div1).slideToggle("fast", function(){
		if(document.getElementById(arrow_id).getAttribute("src") == "img/arrow.gif"){
			document.getElementById(arrow_id).setAttribute("src","img/arrow_up.gif");
		}else{
			document.getElementById(arrow_id).setAttribute("src","img/arrow.gif");
		}
	});
	$("#"+div2).slideToggle();
}

function change_arrow(arrow_id){
	if(document.getElementById(arrow_id).getAttribute("src") == "img/arrow.gif"){
		document.getElementById(arrow_id).setAttribute("src","img/arrow_up.gif");
	}else{
		document.getElementById(arrow_id).setAttribute("src","img/arrow.gif");
	}
}

/* **************************** */
/* Yahoo weather RSS    		*/
/* **************************** */

function showRSS(str) {
 	xmlHttp=GetXmlHttpObject()
 	if (xmlHttp==null) {
  		alert ("Browser does not support HTTP Request")
  		return
  	}
 	var url="temps/weather.test.php"
 	url=url+"?q="+str
 	url=url+"&sid="+Math.random()
 	xmlHttp.onreadystatechange=stateChanged
 	xmlHttp.open("GET",url,true)
 	xmlHttp.send(null)
}


function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
  		document.getElementById("rssOutput").innerHTML=xmlHttp.responseText
  	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e) {
 		// Internet Explorer
 		try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 		}
 		catch (e) {
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 		}
	}
	return xmlHttp;
}



function getVideoSignalFromFlash(str){
	if (str == "1") {
		$("#nav").fadeOut(1600);
		video_play = 1;
		$('#s4').cycle('pause');
	 }
	if (str == "0")	{	$("#nav").fadeIn(1600);  video_play = 0; $('#s4').cycle('resume'); }

}
function pr_a(){
   getFlashMovie("flash_movie_ex_4").playVideoAgainToFlash();
  //document.getElementById('flash_movie_ex_4').playVideoAgainToFlash();
   return false;
}


function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function show_nav(action) {

   if(action == 1 && video_play == 1){ $("#nav").fadeIn(1600);  }
   if(action == 0 && video_play == 1 && in_out_box ==1){ $("#nav").fadeOut(1600); in_out_box = 0; }

}

function displayDatePicker2(){
	alert('a');
}

function content_replace(page,div){
		var div_id;
		div_id = "#"+div;
		$.get(page+"&only_page=1&without_title=1", function(data)
		{
			$("#timetable").html('');
			document.getElementById('timetable').style.padding = '0px';
			$("#timetable").html(data);
		});

}

/*
function illuminate(id){
	aux =id.indexOf('_');
	new_css = id.substring(0,aux);
	document.getElementById('horarios_actividades_css').href='css/horarios_actividades/horarios_cycling.css';

}
*/

/*
function illuminate(id){
	aux =id.indexOf('_');
	new_css = id.substring(0,aux);


	df_cycling_bg = '#0d106b';
	df_pilates_bg = '#6a3364';
	df_tonificacion_bg = '#664608';
	df_aerolatino_bg = '#3e5a00';
	df_radikal_bg = '#68000a';




	switch(new_css){
	  	case 'cycling':
			background = '#1a17de';
		break;
	  	case 'pilates':
			background = '#da63cd';
		break;
	  	case 'tonificacion':
			background = '#d38c11';
		break;
	  	case 'aerolatino':
			background = '#7cb600';
		break;
	  	case 'radikal':
			background = '#d70014';
		break;
		default:
			background = 'yellow';
	}


	for (i=1;i<=100;i++) {
		if(document.getElementById(new_css+'_'+i)){
			document.getElementById(new_css+'_'+i).style.background = background;
		}
	}

	for (j=1;j<=100;j++) {
		if (new_css != 'cycling'){
			if(document.getElementById('cycling_'+j)){
				document.getElementById('cycling_'+j).style.background = df_cycling_bg;
			}
		}

		if (new_css != 'tonificacion'){
			if(document.getElementById('tonificacion_'+j)){
				document.getElementById('tonificacion_'+j).style.background = df_tonificacion_bg;
			}
		}

		if (new_css != 'aerolatino'){
			if(document.getElementById('aerolatino_'+j)){
				document.getElementById('aerolatino_'+j).style.background = df_aerolatino_bg;
			}
		}

		if (new_css != 'radikal'){
			if(document.getElementById('radikal_'+j)){
				document.getElementById('radikal_'+j).style.background = df_radikal_bg;
			}
		}

		if (new_css != 'pilates'){
			if(document.getElementById('pilates_'+j)){
				document.getElementById('pilates_'+j).style.background = df_pilates_bg;
			}
		}


	}



}
*/

function illuminate(id){
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		
	}
	else
	{
	aux_css;
	aux =id.indexOf('_');
	new_css = id.substring(0,aux);

	if (new_css != '')
		document.getElementById('horarios_actividades_css').href='css/horarios_actividades/horarios_'+new_css+'.css';
	}
}



function show_form(id,email,activity,center_id){
		/* alert(id);
		alert(email);
		alert(activity); */
		$.get("index.php?page=std_form", {activity: activity, email: email, id: id, center_id: center_id},function(data)
		{
			 $("#"+id).html(data);
		     $("#"+id).slideToggle("slow");

		});

}

function a(){
	$("#std_form_1").slideToggle("slow");
}


function change_image(id,new_img,lng){
	switch(new_img){
	  	case 'timetable_on':
			if(lng == 'es')	document.getElementById(id).setAttribute("src","img/buttons/horarios-on.gif");
		break;

	  	case 'timetable_off':
			if(lng == 'es')  document.getElementById(id).setAttribute("src","img/buttons/horarios.gif");
		break;
		default:
			document.getElementById(id).innerHTML = new_img;
	}
}
var data_aux;
function get_activity_info(activity,lng,event){
	//alert(activity);
	//alert(activity.lastIndexOf('"'));
	//alert(activity.indexOf('<',activity.lastIndexOf('"')));
	//alert(activity.substring(activity.lastIndexOf('"')));
	// Gets the name of the activity from the ticker
	var name;
	//name = activity.substring(activity.lastIndexOf('"')+2,activity.indexOf('<',activity.lastIndexOf('"')) );
	name = activity;
	coord_y_info=event.clientY;

	$.get("index.php?page=activity_info", {name: name, lng: lng},function(data)
	{
		if(!(coord_y < coord_y_info - 20) )
		 Tip(data, BALLOON, true, ABOVE, false, FONTSIZE, 11, BGCOLOR, 'red', FONTCOLOR, '#999', WIDTH, 200, OFFSETX, -30, PADDING, 10);
	});
}


function coordenadas(event) {
	coord_x=event.clientX;
	coord_y=event.clientY;
	//return y;
}



function get_activity_info_timetable(activity,lng,event){
	//alert(activity);
	//alert(activity.lastIndexOf('"'));
	//alert(activity.indexOf('<',activity.lastIndexOf('"')));
	//alert(activity.substring(activity.lastIndexOf('"')));
	// Gets the name of the activity from the ticker
	var name;
	name = activity;
	if(activity.length != 1){
		coord_x_info=event.clientX;
		$.get("index.php?page=activity_info", {name: name, lng: lng},function(data)
		{
			if(coord_x > coord_x_info -20 && coord_x < coord_x_info + 20 )
			 Tip(data, BALLOON, true, ABOVE, false, FONTSIZE, 11, BGCOLOR, 'red', FONTCOLOR, '#999', WIDTH, 200, OFFSETX, -30, PADDING, 10);
		});
	}
}





function view_route(div_id,div_id2, lang){
	$("#" + div_id).slideToggle("slow");
	if (lang == 'es'){
		if (document.getElementById(div_id2).innerHTML != 'OCULTAR RUTA'){
			document.getElementById(div_id2).innerHTML = 'OCULTAR RUTA';
		}else{
			document.getElementById(div_id2).innerHTML = 'VER RUTA';
		}
	}
}


function change_header(center_id){
		$("#header_block").fadeTo("slow",0.01, function(){
			$.get("index.php?page=change_headers", {center_id: center_id},function(data)
			{
				 document.getElementById('header_block').style.opacity = '1';
				 $("#header_block").html(data);
			});
		});
}


function change_menu(menu_id,action){
	var id_of_menu = menu_id.substring(menu_id.indexOf('_')+1);

	if (action == 'on'){
		document.getElementById(menu_id).style.display = 'none';
		document.getElementById(menu_id+'h').style.display = 'block';
	}else{
		document.getElementById(menu_id+'h').style.display = 'none';
		document.getElementById(menu_id).style.display = 'block';
	}
}


function display_courtesy_img(img){
	$("#"+img).slideToggle();
}

function select_offer(reg_fee,offer,center){
	reg_fee = parseFloat(reg_fee);
	if(offer >0){
		$.get("index.php?page=select_offer", {offer: offer},function(data)
		{
			saving = parseFloat(data);
			new_reg_fee = (Math.ceil((reg_fee - ((saving * reg_fee) / 100 ))*100))/100;
			
			document.getElementById('reg_fee').innerHTML = '<span style="font-weight:normal;text-decoration:line-through;">'+ reg_fee + ' &euro;</span><br /><span style="color:#BF0000;">' +new_reg_fee+ ' &euro;</span>';
		});
	}else{
		document.getElementById('reg_fee').innerHTML = reg_fee;
	}



}






