// JavaScript Document


var current_pseudo='';
function initiate_pseudo(pseudo)
{
current_pseudo=pseudo
}

function Check_log()
{
current_pseudo="<?php echo trim($current_pseudo);?>";
if(current_pseudo.length>0)
{
  document.getElementById("log_in_div").innerHTML='<a href="javascript:deLog();">Déconnexion</a>'

  return 1;
}
else
{
  return 0;
}
}
function deLog()
{
	delCook('cookiessessionlog');
	delCook('cookiessessionpseudo');
  window.location.replace('../index.php');
}	

var club_admin_rights=0;
function isowner(_pseudo,_clubid)
{
$.ajax({
  type: "POST",
	url: "../php/is_the_club_owner.php",
	data: "card_club_id="+ _clubid+"& user_pseudo="+ _pseudo,
     
success:function(feedback)
    { 
     is_club_owner=feedback; 
     club_admin_rights=feedback;
     /*if (feedback==1){club_admin_rights=1;}
     else {club_admin_rights=0;}*/  
    } 
});
}


function convert_date(date)
{
if(date!="Date")
{
var date_array=date.split(',')
var month_names=new Array('janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre')
var event_month_array=date_array[1].split(' ')
var event_month=event_month_array[2];


var event_day=event_month_array[1];
if (event_day.length==1)
{
event_day="0"+event_day;
}


for( i=0; i<=month_names.length-1; i++)
{
  if (event_month==month_names[i])
  {
  event_month=i+1;
  if (event_month<10)
  {
  event_month="0"+event_month.toString();
  }
  }
}

var event_year=date_array[2]

var event_date=event_year+'-'+event_month+'-'+event_day
return event_date;
}
else
{
return "0000-00-00";
}
}


function Enable_Score_Field(increment)
{
document.getElementById('Score1').style.backgroundColor="#E1E1E1";
document.getElementById('Score2').style.backgroundColor="#E1E1E1";
document.getElementById('Score1').readOnly =false;
document.getElementById('Score2').readOnly =false;
}

function Enable_End_Comment_Field()
{
document.getElementById('end_comment_text').style.backgroundImage="url(images/coach_comment.png)";
document.getElementById('end_comment_area').readOnly =false;
}


/*
function getParent(element, parentTagName) 
{
//alert(element.tagName);
if ( ! element )
return null;
else if ( element.nodeType == 1 && element.tagName.toLowerCase() == parentTagName.toLowerCase() )
return element;
else
return getParent(element.parentNode, parentTagName);
}
*/



//////////////////Cookies/////////////////////
function setCook(nom,valeur) 
{
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + (  24*15*  60 * 60 * 1000)); // 1 heure
	document.cookie = nom + "=" + escape(valeur) + ";expires=" + expDate.toGMTString() + "; path=/";
}

function delCook(nom) 
{
	setCook(nom,"",-1);
}


///////////////////button functions//////////////////////////
function change_back(button)
{
document.getElementById(button).style.backgroundImage="url(images/button_background.png)"
}

function restore_back(button)
{
document.getElementById(button).style.backgroundImage="none"
}

function change_back2()
{
document.getElementById("Validate_Event_button").style.color="#FDDBBE"
}

function restore_back2()
{
document.getElementById("Validate_Event_button").style.color="#FFFFFF"
}





function selectOptionByValue(selObj, val){ 
    var A= document.getElementById(selObj).options, L= A.length;
    while(L){ 
        if (A[--L].value== val){ 
            document.getElementById(selObj).selectedIndex= L; 
            L= 0; 
        } 
    } 
} 

var all_clubs_data
var club_id_to_display=''
function show_club_search_result(data,page)
{

all_clubs_data=data.split("#sep#");
var intermediaire_array=""
var intermediaire_string=""
for( i=0; i<all_clubs_data.length-1; i++)
  {  
  intermediaire_string=all_clubs_data[i]
  intermediaire_array=intermediaire_string.split("##")
  all_clubs_data[i]=new Array()
  for( j=0; j<intermediaire_array.length-1; j++)
  {
  all_clubs_data[i][j]=intermediaire_array[j]
  }  
  }

document.getElementById("search_table_div").innerHTML=''
  +'<table id="club_search_result_Table" class="search_tables" width="100%" border="0" cellspacing="0" cellpadding="0">'
  +'<tr><th><b>Sport</b></th>'
  +'<th><b>Club</b></th>'
  +'<th><b>Catégorie</b></th>'
  +'<th><b>Coach</b></th>'
  +'<th><b>Code Postal</b></th></tr></table>'


for( j=0; j<intermediaire_array.length-1; j++)
  {  

var club_sport_array = all_clubs_data[0][j];
var club_name_array = all_clubs_data[1][j];
var club_name_dim_array = all_clubs_data[2][j];
var club_zip_array = all_clubs_data[3][j];
var club_cat_array = all_clubs_data[4][j];
var club_coach_array = all_clubs_data[5][j];
var club_id_array = all_clubs_data[6][j];

var NewEventsRow = document.getElementById("club_search_result_Table").insertRow(-1);
NewEventsRow.id="Club_Search_Row"+j;
document.getElementById('Club_Search_Row'+j).style.width = "100%";
document.getElementById('Club_Search_Row'+j).style.cursor = "pointer";
document.getElementById('Club_Search_Row'+j).style.fontSize = "13px";
document.getElementById('Club_Search_Row'+j).style.height = "20px";
document.getElementById('Club_Search_Row'+j).style.borderBottom = "solid 1px #CCCCCC";


if(j/2 == Math.round(j/2))
{
document.getElementById('Club_Search_Row'+j).style.backgroundColor = "#EFEFFE";
}
else
{
document.getElementById('Club_Search_Row'+j).style.backgroundColor = "#FFFFFF";
}
document.getElementById('Club_Search_Row'+j).style.cursor = "pointer";
document.getElementById('Club_Search_Row'+j).onmouseover = function () {this.style.color = "#3383bb";};
document.getElementById('Club_Search_Row'+j).onmouseout = function () {this.style.color = "#000000";};

document.getElementById('Club_Search_Row'+j).onclick = function () {

var row_for_id=this.rowIndex;
club_id_to_display=all_clubs_data[6][row_for_id-1]

//////////////////Read the club card info////////////////////

Read_club_card_info(club_id_to_display)
};


var NewEventsCell=NewEventsRow.insertCell(0);
NewEventsCell.id='Club_sport_Cell'+j;
document.getElementById('Club_sport_Cell'+j).innerHTML=club_sport_array;


var NewEventsCell=NewEventsRow.insertCell(1);
NewEventsCell.id='Club_Name_Cell'+j;
document.getElementById('Club_Name_Cell'+j).innerHTML=club_name_array+" ("+club_name_dim_array+")";

var NewEventsCell=NewEventsRow.insertCell(2);
NewEventsCell.id='Club_Cat_Cell'+j;
document.getElementById('Club_Cat_Cell'+j).innerHTML=club_cat_array;

var NewEventsCell=NewEventsRow.insertCell(3);
NewEventsCell.id='Club_Coach_Cell'+j;
document.getElementById('Club_Coach_Cell'+j).innerHTML=club_coach_array;

var NewEventsCell=NewEventsRow.insertCell(4);
NewEventsCell.id='Club_Zip_Cell'+j;
document.getElementById('Club_Zip_Cell'+j).innerHTML=club_zip_array;
document.getElementById('Club_Zip_Cell'+j).style.width='50px';
  
  }

}

function Read_club_card_info(read_club_id)
{

$.ajax({
  type: "POST",
	url: "../php/get_card_info.php",
	data: "card_club_id="+ read_club_id,
     
success:function(feedback)
    { 
    var club_card_info=feedback.split('#sep#');
    var card_name=club_card_info[0];
    var card_level=club_card_info[1];
    var card_licence=club_card_info[2];
    var card_coach=club_card_info[3];
    var card_stade=club_card_info[4];
    var card_site=club_card_info[5];
    var card_adress=club_card_info[6];
    var card_name_dim=club_card_info[7];
    var card_sport=club_card_info[8];
  
    
    document.getElementById('main_register_info_club_name').innerHTML=club_card_info[0];
    document.getElementById('main_register_info_club_level').innerHTML=club_card_info[1];
    document.getElementById('main_register_info_club_licence_read').innerHTML=club_card_info[2];
    document.getElementById('main_register_info_club_coach').innerHTML=club_card_info[3];
    document.getElementById('main_register_info_club_stade').innerHTML=club_card_info[4];
    document.getElementById('main_register_info_club_site').innerHTML=club_card_info[5];
    document.getElementById('register_info_club_adress').innerHTML=card_adress;
    document.getElementById('main_register_info_club_sport').innerHTML=First2UpperCase(card_sport);

    $('#club_member_page').fadeIn()

    //document.getElementById('dialog_club').innerHTML=card_name_dim
    //document.getElementById('dialog_zip').innerHTML=document.getElementById('get_clicked_club_zip').value

    } 
});
    
$.ajax({
  type: "POST",
	url: "../php/get_logos.php",
	data: "card_club_id="+ read_club_id,
     
success:function(feedback2)
    {    
    var card_logo_info=feedback2.split('#sep#');
    var card_logo_picture=trim(card_logo_info[1]);
    var card_logo_owner=card_logo_info[0];

    if(card_logo_picture=="none")
    {
    var img_path='../photos/_12313Empty456789-4563/club.png'
    }
    else
    {
    var img_path='../photos/_club_logo/'+read_club_id+'/'+card_logo_picture+'.jpg'    
    }
    document.getElementById('preview').src=img_path
    } 
}); 

//////////////////////////get team/////////////////////

$.ajax({
  type: "POST",
	url: "../php/get_club_team.php",
	data: "card_club_id="+ read_club_id,
     
success:function(feedback)
    {     
          var club_team_data=feedback.split('##team_sep##');          
          var intermediaire_array=""
          var intermediaire_string=""
          for( i=0; i<club_team_data.length; i++)
            {  
            intermediaire_string=club_team_data[i]
            intermediaire_array=intermediaire_string.split("###sepa###")
          
            club_team_data[i]=new Array()
            for( j=0; j<intermediaire_array.length-1; j++)
            {
            club_team_data[i][j]=intermediaire_array[j]
            }  
            }
            
            document.getElementById("club_members").innerHTML="";
            document.getElementById("club_spectators").innerHTML="";
            ///document.getElementById("club_members_spectator").innerHTML='<table id="main_club_team_spectator_table" width="100%" border="0" cellspacing="3" cellpadding="0"></table>';
                        
            
            
            var player_number=0
            var spectator_number=0
            for( i=0; i<intermediaire_array.length-1; i++)          
            {
              
              var member_club_status=club_team_data[5][i]
 
              if(club_team_data[2][i]=="none")
              {
              var team_pic_path='../photos/_12313Empty456789-4563/user_'+club_team_data[4][i]+'.png'
              }
              else
              {
              var team_pic_path='../photos/'+club_team_data[3][i]+'/avatar/50/'+club_team_data[2][i]+'.jpg'
              }
              
              if(member_club_status=="pl")
              {              
                var player_list=''
                +'<li class="ui-widget-content ui-corner-tr" id="'+club_team_data[3][i]+'">'
                +'<img src='+team_pic_path+' onclick="Javascript:GoToUser(\''+club_team_data[3][i]+'\')" alt='+club_team_data[0][i]+' '+club_team_data[1][i]+' width="52" height="56" />'
                +'<h5 class="ui-widget-header">'+club_team_data[0][i]+'<br/>'+club_team_data[1][i]+'</h5>'
                +'</li>'

                $('#club_members').append(player_list)
              
              player_number+=1;
              }
              else
              {
                var spectators_list=''
                +'<li class="ui-widget-content ui-corner-tr" id="'+club_team_data[3][i]+'">'
                +'<img src='+team_pic_path+' onclick="Javascript:GoToUser(\''+club_team_data[3][i]+'\')" alt='+club_team_data[0][i]+' '+club_team_data[1][i]+' width="41" height="43" //>'
                +'<h5 class="ui-widget-header">'+club_team_data[0][i]+'<br/>'+club_team_data[1][i]+'</h5>'
                +'</li>'

                $('#club_spectators').append(spectators_list)              
              spectator_number+=1;              
              }
            } 
document.getElementById('main_register_info_club_adherants').innerHTML="<b>"+player_number+"</b> joueurs <span style='margin-left:27px;' onclick='Javascript:Show_Players()'><u>voir</u></span> <br><b>"+spectator_number+"</b> spectateurs <span onclick='Javascript:Show_Spectators()'><u>voir</u></span>"
    }
});
}



var all_players_data
function show_player_search_result(data)
{

all_players_data=data.split("#sep#");
var intermediaire_array=""
var intermediaire_string=""
for( i=0; i<all_players_data.length; i++)
  {  
  intermediaire_string=all_players_data[i]
  intermediaire_array=intermediaire_string.split("##")
  all_players_data[i]=new Array()
  for( j=0; j<intermediaire_array.length-1; j++)
  {
  all_players_data[i][j]=intermediaire_array[j]
  }  
  }

//document.getElementById("core_event").innerHTML='<table id="Events_Table" width="400px" border="0" cellspacing="2" cellpadding="0"></table>'
document.getElementById("search_player_table_div").innerHTML=''
  //+'<div style="font-size:13px;color:black;margin-top:35px;margin-bottom:10px;"><u>Résultat de la recherche</u> :</div>'
  +'<table id="player_search_result_Table" class="search_tables" width="100%;" border="0" cellspacing="2" cellpadding="2">'
  +'<tr><th><b>Nom</b></th>'
  +'<th><b>Prénom</b></th>'
  +'<th><b>Pseudo</b></th></tr></table>'


for( j=0; j<intermediaire_array.length-1; j++)
{  

var player_name_array = all_players_data[0][j];
var player_fname_array = all_players_data[1][j];
var player_pseudo_array = all_players_data[2][j];
var player_id_array = all_players_data[3][j];

var NewEventsRow = document.getElementById("player_search_result_Table").insertRow(-1);
NewEventsRow.id="Player_Search_Row"+j;
document.getElementById('Player_Search_Row'+j).style.width = "100%";
document.getElementById('Player_Search_Row'+j).style.cursor = "pointer";
document.getElementById('Player_Search_Row'+j).style.fontSize = "13px";
document.getElementById('Player_Search_Row'+j).style.height = "15px";
document.getElementById('Player_Search_Row'+j).style.borderBottom = "solid 1px #CCCCCC";
if(j/2 == Math.round(j/2))
{
document.getElementById('Player_Search_Row'+j).style.backgroundColor = "#EFEFFE";
}
else
{
document.getElementById('Player_Search_Row'+j).style.backgroundColor = "#FFFFFF";
}
document.getElementById('Player_Search_Row'+j).style.cursor = "hand";
document.getElementById('Player_Search_Row'+j).onmouseover = function () {this.style.color = "#3383bb";};
document.getElementById('Player_Search_Row'+j).onmouseout = function () {this.style.color = "#000000";};


var NewEventsCell=NewEventsRow.insertCell(0);
NewEventsCell.id='Player_name_cell'+j;
document.getElementById('Player_name_cell'+j).innerHTML=player_name_array;

var NewEventsCell=NewEventsRow.insertCell(1);
NewEventsCell.id='Player_fname_cell'+j;
document.getElementById('Player_fname_cell'+j).innerHTML=player_fname_array;

var NewEventsCell=NewEventsRow.insertCell(2);
NewEventsCell.id='Player_pseudo_cell'+j;
document.getElementById('Player_pseudo_cell'+j).innerHTML=player_pseudo_array;


  document.getElementById('Player_Search_Row'+j).onclick = function () 
    {
      var row_for_id=this.rowIndex;
      var player_pseudo_to_display=document.getElementById('Player_pseudo_cell'+(row_for_id-1)).innerHTML
      get_user_card_info(player_pseudo_to_display)
    }
  }
}


function get_user_card_info(u_pseudo)
{

$.ajax({
  type: "POST",
	url: "../php/get_user_info.php",
	data: "current_pseudo="+ u_pseudo,
     
success:function(feedback)
    {
    var user_card_info=feedback.split('#sep#');
    var user_avatar=user_card_info[0];
    var user_name=user_card_info[1];
    var user_firstname=user_card_info[2];
    var user_email=user_card_info[3];
    var user_birthday=user_card_info[4];
    var user_mobile=user_card_info[5];
    var user_address=user_card_info[6];
    var lock_value=user_card_info[7];
    var user_clubs=user_card_info[8];
    var user_clubs_zip=user_card_info[9];
    var user_clubs_id=user_card_info[10];
    var user_clubs_pic=user_card_info[11];
    var user_clubs_owner=user_card_info[12];
    var user_clubs_status=user_card_info[13];
    var member_since=user_card_info[14];
    var user_clubs_array=user_clubs.split("#");
    var user_clubs_zip_array=user_clubs_zip.split("#");
    var member_clubs=""

    for(i=0;i<user_clubs_array.length-1;i++)
    {
    member_clubs+='- '+user_clubs_array[i]+' ('+user_clubs_zip_array[i]+')<br> ';
    }
    
    lock_info=lock_value
    if(lock_value =='1')
    {
    document.getElementById('register_info_club_adress').innerHTML='confidentiel';
    document.getElementById('register_user_Mobile').innerHTML='confidentiel';
    document.getElementById('register_user_Mail').innerHTML='confidentiel';
    document.getElementById('register_user_Birth').innerHTML='confidentiel';
    }
    else
    {
    document.getElementById('register_info_club_adress').innerHTML=user_address;
    document.getElementById('register_user_Mobile').innerHTML=user_mobile;
    document.getElementById('register_user_Birth').innerHTML=user_birthday;    
    document.getElementById('register_user_Mail').innerHTML=user_email;
    }
    
    document.getElementById('preview').src=user_avatar
    document.getElementById('register_user_FirstName').innerHTML=user_firstname
    document.getElementById('register_user_Name').innerHTML=user_name

    document.getElementById('user_clubs_blocs').innerHTML=""
    create_club_cards(user_clubs_id,user_clubs,user_clubs_zip,user_clubs_pic,user_clubs_owner,user_clubs_status,member_since)
    }
})
}

function Join_the_selected_club()
{

    if(club_id_to_display=='')
    {
    alert('Aucun club n\'est séléctionné !')
    }
    else
    {
    $.ajax({
    	type: "POST",
    	url: "../php/is_already_member.php",
    	data: "user_pseudo="+ current_pseudo +"& club_id="+ club_id_to_display,
         
    success:function(feedback)
        { 
          if (feedback==0)
          {$('#already_member').dialog('open');}
          else if((feedback==1))
          {$('#dialog_join_club').dialog('open');}
          else
          {$('#already_demand').dialog('open');}
        } 
    });	
    }
}

//////////////////////////////allow to join club///////////////////////////////////

var all_demands_data;
function build_demand_table(demands)
{
var user_pseudo=document.getElementById('session_member_pseudo').innerHTML;
$.ajax({
	type: "POST",
	url: "../php/get_demands.php",
  data: "user_pseudo="+ user_pseudo,
  
  
success:function(feedback)
    { 
      all_demands_data=feedback.split("#sep#");
      var intermediaire_array=""
      var intermediaire_string=""
      for( i=0; i<all_demands_data.length; i++)
        {  
        intermediaire_string=all_demands_data[i]
        intermediaire_array=intermediaire_string.split("##")
      
        all_demands_data[i]=new Array()
        for( j=0; j<intermediaire_array.length-1; j++)
        {
        all_demands_data[i][j]=intermediaire_array[j]
        }  
        }
        
      document.getElementById('join_demand_container').innerHTML='<table id="join_demand_div_table" class="search_tables" width="auto" border="0" cellspacing=0" cellpadding="0"></table>'
      
      for( j=0; j<intermediaire_array.length-1; j++)
      {  
      
      var join_club_asker = all_demands_data[0][j];
      var join_club_asker_name = all_demands_data[1][j];
      var join_club_asker_firstname = all_demands_data[2][j];
      var join_club_name = all_demands_data[3][j];
      var join_club_zip = all_demands_data[4][j];
      var join_club_sport=all_demands_data[5][j];
      var join_as=all_demands_data[6][j];
      var join_club_id=all_demands_data[7][j];
      var message_to_coach=all_demands_data[8][j];
      if(join_as=="sp")
      {var join_as_val="spectateur"}
      else
      {var join_as_val="joueur"}
      
      var NewEventsRow = document.getElementById("join_demand_div_table").insertRow(0);
      NewEventsRow.id="Club_Join_Row"+j;
      
      var NewEventsCell=NewEventsRow.insertCell(0);NewEventsCell.id='Club_checkbox_Cell'+j;
      document.getElementById('Club_checkbox_Cell'+j).style.verticalAlign='middle';
      document.getElementById('Club_checkbox_Cell'+j).innerHTML='<input type="checkbox" id="join_club_checkbox_'+j+'"><input id="who_wants_to_join'+j+'" type="hidden" value="'+join_club_asker+'#sep#'+join_club_id+'#sep#'+join_as+'">';
      var NewEventsCell2=NewEventsRow.insertCell(1);NewEventsCell2.id='Club_Join_Cell'+j;
      document.getElementById('Club_Join_Cell'+j).innerHTML="<div style='margin-top:10px;'><b>"+join_club_asker_name+" "+join_club_asker_firstname+"</b> souhaite rejoindre "+join_club_name+" ("+join_club_zip+") en temps que <font color='red'><b>"+join_as_val+"</b></font>.</div>";
      
      var NewEventsRow2 = document.getElementById("join_demand_div_table").insertRow(1);
      NewEventsRow2.id="Club_Message_Row"+j;
      
      var NewEventsCell3=NewEventsRow2.insertCell(0);NewEventsCell3.id='Club_mes_Cell'+j;
      document.getElementById('Club_mes_Cell'+j).innerHTML=''
      var NewEventsCell4=NewEventsRow2.insertCell(1);NewEventsCell4.id='Club_text_Cell'+j;
      document.getElementById('Club_text_Cell'+j).innerHTML='<div style="margin-bottom:10px;margin-top:10px;"><u><b>Message</b></u>: '+message_to_coach+'</div>';
      
      var NewEventsRow3 = document.getElementById("join_demand_div_table").insertRow(2);
      NewEventsRow3.id="Club_separator_Row"+j;
      document.getElementById('Club_separator_Row'+j).style.height='1px';
      
      var NewEventsCell5=NewEventsRow3.insertCell(0);NewEventsCell5.id='Club_sep1_Cell'+j;
      document.getElementById('Club_sep1_Cell'+j).style.backgroundColor="black"
      var NewEventsCell6=NewEventsRow3.insertCell(1);NewEventsCell6.id='Club_sep2_Cell'+j;
      document.getElementById('Club_sep2_Cell'+j).style.backgroundColor="black"      
       
      } 
    } 
});


 
  
}


function Allow_to_join_club(asker,club_tobe_j,ask_status,y_n,news_id,join_id)
{
      $.ajax({
      	type: "POST",
      	url: "../php/allow_to_join_club.php",
      	data: "asker_allowed_to_join="+ asker +"& club_to_be_joined_id="+ club_tobe_j+"& accept_refuse="+y_n+"& ask_status="+ask_status+"& news_id="+news_id+"& join_id="+join_id+"& allower="+current_pseudo,
           
      success:function(feedback)
          { 
            window.location.reload()
          } 
      });
}


function rollover(id,url)
{
document.getElementById(id).src='../images/'+url
//document.getElementById(id).style.color='red'
}


function see_convoqued()
{
document.getElementById('convocation_read_zone_div').style.display="block";
document.getElementById('convocation_zone_div').style.display="none";
$('.scroll-pane3').jScrollPane({scrollbarWidth:7, scrollbarMargin:10});
}

function back_to_convoque()
{
document.getElementById('convocation_read_zone_div').style.display="none";
document.getElementById('convocation_zone_div').style.display="block";
}

function get_comment_number(event_id2)
{  
      $.ajax({
      	type: "POST",
      	url: "../php/get_comment_number.php",
      	data: "event_id="+ event_id2,
           
      success:function(feedback2)
          { 
            document.getElementById('number_of_comment').innerHTML=feedback2
          } 
      });

}

function get_convoqued_people_number(event_id2)
{  
      $.ajax({
      	type: "POST",
      	url: "../php/get_convoqued_people_number.php",
      	data: "event_id="+ event_id2,
           
      success:function(feedback2)
          { 
            document.getElementById('number_of_convocation').innerHTML=feedback2
          } 
      });

}


/*var interval 
function update_comments()
{

if(document.getElementById('comment_zone_div').style.display=="block")
  {
   var event_number=document.getElementById('comment_event_id').value 
   interval=setInterval("See_comments("+event_number+")", 5*1000); 
  }

}
*/

function hide_show_depending_on_owner()
{    
  if(document.getElementById("get_owner_or_not").value=='1')
  {
  document.getElementById('convocation_zone_div').style.display="block"
  document.getElementById('Image_back_convocation').style.display="block"
  document.getElementById('convocation_read_zone_div').style.display="none"
  document.getElementById('type_convocations_div').style.display="block"
  document.getElementById('convocation_state').style.display="none"
  $('.scroll-pane').jScrollPane({scrollbarWidth:7, scrollbarMargin:10});
  }
  else
  {
  document.getElementById('convocation_zone_div').style.display="none"
  document.getElementById('convocation_read_zone_div').style.display="block"
  document.getElementById('Image_back_convocation').style.display="none"
  document.getElementById('type_convocations_div').style.display="none" 
  document.getElementById('convocation_state').style.display="block" 
  $('.scroll-pane3').jScrollPane({scrollbarWidth:7, scrollbarMargin:10});
  }
}

function hide_div_clean_tables()
{
document.getElementById("read_convocations_div").innerHTML='<table id="convocations_table" width="100%"></table>';
document.getElementById("read_convoqued_people_div").innerHTML='<table id="convoqued_people_table" width="100%" border="0" cellspacing="0" cellpadding="0"></table>';

document.getElementById('comment_zone_div').style.display="none";
document.getElementById('convocation_zone_div').style.display="none";
document.getElementById('convocation_read_zone_div').style.display="none"
document.getElementById('core_event').style.display="block";
document.getElementById('club_search_result').style.display="none";
document.getElementById('Events_Right').style.display="block";
}


/////////////////////////dialogu/////////////////////////////////



function Cancel_modification(){

document.getElementById('delete_member').style.display="block";

var clicked_club_data=document.getElementById('get_clicked_club_button').value
clicked_club_data=clicked_club_data.split('#')
Read_Club_Id(clicked_club_data[0],clicked_club_data[0],clicked_club_data[2],clicked_club_data[3],clicked_club_data[4])
  
  ChangeBckgrdColorByClass2('text_info','textarea');
  document.getElementById('read_div_info_category').style.display="block"
  document.getElementById('div_info_category').style.display="none"   
  document.getElementById('read_info_club_licence').style.display="block";
  document.getElementById('div_info_club_licence').style.display="none" ; 
  document.getElementById('Modify_info_button_input').value="Modifier";
  document.getElementById('Modify_info_button_input').onclick=function () {Modify_club_card()}
  document.getElementById('cancel_info_button').style.display="none" ;

}

function Cancel_user_modification()
{
Load_user_info()

ChangeBckgrdColorByClass2('text_info','textarea');
document.getElementById('div_info_user_birth').style.display="none"
document.getElementById('read_info_user_birth').style.display="block"
document.getElementById('Modify_user_button_input').value="Modifier";
document.getElementById('Modify_user_button_input').onclick=function () {Modify_user_card()}
document.getElementById('cancel_info_button').style.display="none" ;
$('#overlay').hide();
$('#uploadifyUploader').hide();

document.getElementById('pswd_span').style.color="#969696";
document.getElementById('pswd_span').style.cursor="default";
document.getElementById('pswd_span').onclick = function () {;}

document.getElementById('lock').onclick = function () {}
document.getElementById('lock').style.cursor = 'default'
}

function getSelectedRadioValue (radiobutton){
 var returnValue = "";
 if (radiobutton.length == 1){
  returnValue = radiobutton.value;
 } else {
  for (i=0;i<radiobutton.length;i++){
   if (radiobutton[i].checked==true) {
    returnValue=radiobutton[i].value;
   }
  }
 }
 return returnValue;
}


function Load_Town()
{
var verif 	= /^[0-9]+$/
var club_zip_code= document.getElementById('register_zip_code').value;
if (club_zip_code!='' && club_zip_code.length==5 && verif.exec(club_zip_code) != null)
{
	$.ajax({
		type: "POST",
		url: "../php/get_town.php",
		data: "club_zip_code="+ club_zip_code,
	     
  success:function(feedback)
      { 
      document.getElementById('register_town').value=trim(feedback);
      } 
	});  
}

}

function trim (myString)
{
return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 


function Select_Sport_Category()
{
var selected_sport=document.getElementById('Sport_Name').value
for( i=0; i<document.getElementsByName('register_club_category').length; i++)
{
document.getElementsByName('register_club_category').item(i).style.display="none";
}

document.getElementById('register_club_category_'+selected_sport).style.display="block"

}

function Select_Sport_Category2()
{
var selected_sport=document.getElementById('search_sport').value

document.getElementById('div_search_club_category_').style.display="none";
document.getElementById('div_search_club_category_basketball').style.display="none";
document.getElementById('div_search_club_category_handball').style.display="none";
document.getElementById('div_search_club_category_football').style.display="none";
document.getElementById('div_search_club_category_futsal').style.display="none";
document.getElementById('div_search_club_category_volleyball').style.display="none";

document.getElementById('div_search_club_category_'+selected_sport).style.display="block"

}

function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


function First2UpperCase(texte) {
var t = new Array();
	for(j=0 ; j < texte.length ;j++) {
		if(j == 0) t[j] = texte.substr(j,1).toUpperCase();
		else t[j] = texte.substr(j,1).toLowerCase();
	}
	return t.join('');
}


function Decrease_font(textarea_id)
{
var typed_text=document.getElementById(textarea_id.id).value
if(typed_text.length<10)
{
textarea_id.style.fontSize="20px";
}

if(typed_text.length>9 && typed_text.length<15)
{
textarea_id.style.fontSize="13px";
}

}


function Modify_password()
{
$('#dialog_new_pswd').dialog('open');	
}




function GoToPic(photo_id,album_id,club_id,news_id)
{
  $.ajax({
  	type: "POST",
  	url: "../php/change_news_status.php",
  	data: "news_id="+ news_id,
         
  success:function(feedback)
      { 
        window.location = 'pictures.php?id='+club_id+'a139B2'+photo_id+'a139B2'+album_id+'a139B2'+'1';
      }
  }) 
}


function GoToAlbum(uploader_pseudo,album_id,news_id,club_id)
{
  $.ajax({
  	type: "POST",
  	url: "../php/change_news_status.php",
  	data: "news_id="+ news_id,
         
  success:function(feedback)
      { 
        window.location = 'pictures.php?id='+club_id+'a139B2'+uploader_pseudo+'a139B2'+album_id+'a139B2'+'0';;
      }
  }) 
}

function GoToComment(club_id,news_id)
{
  $.ajax({
  	type: "POST",
  	url: "../php/change_news_status.php",
  	data: "news_id="+ news_id,
         
  success:function(feedback)
      { 
        window.location = 'chat.php?id='+club_id+'a139B2'+club_id;
      }
  }) 
}

function GoToMatch(match_id,club_id,news_id)
{
  $.ajax({
  	type: "POST",
  	url: "../php/change_news_status.php",
  	data: "news_id="+ news_id,
         
  success:function(feedback)
      { 
        window.location = 'calendar.php?id='+match_id+'a139B2'+club_id;
      }
  }) 
}

function GoToUser(pseudo)
{
window.location = 'search_p.php?id='+pseudo;
}

function GoToClub(club_id)
{
window.location = 'search_c.php?id='+club_id+'a139B2'+club_id;
}


function news_number()
{
  $.ajax({
  	type: "POST",
  	url: "../php/get_news_number.php",
  	data: "pseudo="+ current_pseudo,
         
  success:function(feedback)
      { 
        //document.getElementById('news_n').innerHTML=feedback
      }
  })
}

function modify_string(change_string)
{
change_string=ReplaceAll(change_string,'&',"##et#commercial##")
change_string=ReplaceAll(change_string,'+',"*_*plus*_*")
change_string=ReplaceAll(change_string,'=',"*_*equal*_*")
//change_string=ReplaceAll(change_string,'\'','*_*quote*_*')
return change_string;
}

function modify_string2(change_string) // this is done for the search_c.php page , for the comment when asking to join a club
{
change_string=ReplaceAll(change_string,'&',"##et#commercial##")
change_string=ReplaceAll(change_string,'+',"*_*plus*_*")
change_string=ReplaceAll(change_string,'=',"*_*equal*_*")
change_string=ReplaceAll(change_string,'\'','*_*quote*_*')
return change_string;
}

function ReplaceAll(Source,stringToFind,stringToReplace)
{
  var temp = Source;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
}




