// JavaScript Document
var quoi=false;


  //////////////////
 // Partout   /////
////////////////// 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function form_call(adress){
document.getElementById('link_identification').style.color='#666666';
document.getElementById('link_education').style.color='#666666';
document.getElementById('link_preferences').style.color='#666666';
document.getElementById('link_attachment').style.color='#666666';
document.getElementById('link_selection').style.color='#666666';
document.getElementById('link_messages').style.color='#666666';
anticache=Math.floor((100)*Math.random()+1);	
id_link='link_'+adress;
hash='#'+adress;
adress=adress+'.php?n='+anticache;	
document.getElementById('my_account_loader').style.display='';	
$("#my-body-account").load(adress, function() {
window.location.hash=hash;
document.getElementById(id_link).style.color='red';
document.getElementById('my_account_loader').style.display='none';
});
}
/* _________________________________________________________________________________________________________________________________________*/



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function kps_form(){
// SENDING THE FORMS WITH AJAX
// prepare the form when the DOM is ready 
$(document).ready(function() {	
    var options = { 
        success:       showResponse  // post-submit callback
    }; 
    // bind form using 'ajaxForm'
    $('#myForm').ajaxForm(options);
}); 
function showResponse(responseText)  {
    if (responseText=='error')
		{document.getElementById('my_account_erreur').style.display=''; return false;}
	else if (responseText=='valid attachement'){
		form_call('attachment');
		tableau_bord();
		document.getElementById('my_account_loader').style.display='none';
	}
	else if (responseText=='not valid attachement'){
		document.getElementById('my_account_erreur').style.display='';
		document.getElementById('my_account_loader').style.display='none';
	}
   else {
	   	sablier();
		tableau_bord();
   		document.getElementById('my_account_erreur').style.display='none';}
}
}
/* _________________________________________________________________________________________________________________________________________*/



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function modifyText(){
$('#myForm').submit();
}
/* _________________________________________________________________________________________________________________________________________*/




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sablier(){
document.getElementById('my_account_loader').style.display='';
setTimeout("document.getElementById(\'my_account_loader\').style.display=\'none\'", 600);
}
/* _________________________________________________________________________________________________________________________________________*/


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function tableau_bord(){
 		anticache=Math.floor((100)*Math.random()+1);
		adress='tableau-bord.php?n='+anticache;	
		$('#my-account-14').load(adress);
}
/* _________________________________________________________________________________________________________________________________________*/






  //////////////////////
 // PREFERENCES   /////
//////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function alt(id,type) {
var d = document.getElementById(id);
var e = document.getElementById('myaccount_deroulant_anycity')?document.getElementById('myaccount_deroulant_anycity'):null;
var f = document.getElementById('myaccount_deroulant_duration')?document.getElementById('myaccount_deroulant_duration'):null;
var g = document.getElementById('myaccount_deroulant_starting')?document.getElementById('myaccount_deroulant_starting'):null;
if (type==1) {
d.style.display='';	
if (e) e.style.display='none';
if (f) f.style.display='none';
if (g) g.style.display='none';

}
else if (type==2){
d.style.display='none';	
if (e) e.style.display='';
if (f) f.style.display='';
if (g) g.style.display='';
}
}
/* _________________________________________________________________________________________________________________________________________*/





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
function contage_checked(){
var chboxes=document.getElementById('menu_scopes').getElementsByTagName('input');
var decompte=0;
for (var i=0;i<chboxes.length;i++)
   {
    if(chboxes[i].type == 'checkbox')
     {
      if (chboxes[i].checked == true){decompte++};
     }
   }
   
if (decompte==1){max_reach(false); document.getElementById('txt_choose').innerHTML=decompte+' selected sector';} 
else if (decompte>1){max_reach(false); document.getElementById('txt_choose').innerHTML=decompte+' selected sectors';}
else {document.getElementById('txt_choose').innerHTML='Choose job sector(s) here.';}
if (decompte>2){max_reach(true); document.getElementById('txt_choose').innerHTML=decompte+' sectors max'; return false;}


 } 
/* _________________________________________________________________________________________________________________________________________*/ 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
function max_reach(type){
var chboxes=document.getElementById('menu_scopes').getElementsByTagName('input');
for (var e=0;e<chboxes.length;e++)
   {
    if((chboxes[e].type == 'checkbox')&&(chboxes[e].checked==false))
     {
      chboxes[e].disabled = type;
     }
   }	
}
/* _________________________________________________________________________________________________________________________________________*/ 
 
 
   /////////////////////
 // ATTACHMENTS   /////
//////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
function attachement_delete(type){
adress_remove='functions/function_remove_attachment.php?mode='+type;	
$.get(adress_remove);
form_call('attachment');
tableau_bord();
}

/* _________________________________________________________________________________________________________________________________________*/ 


   /////////////////////
 //   SELECTION   /////
//////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
color_change();
// GetByClass qui n'existe pas en IE5
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function color_change(){
var elem_cell = document.getElementById('table').getElementsByTagName('tr');
a=1;
for(var z=1; z<elem_cell.length; z++){
	if (a==2){elem_cell[z].className='cellule_tableau_bis'; a=0;}
	else {elem_cell[z].className='cellule_tableau';}
	a++;
}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
// Ordre des lignes
function reorder_table(variable){
var elem = document.getElementsByClassName('numerotation');
for(var i=0; i<elem.length; i++){
	elem[i].innerHTML=i+1;
} 
// Couleurs des lignes
color_change();
// Envoi AJAX
//var reg=new RegExp("(&)", "g");
//variable=variable.replace(reg,"AND");
$.ajax({ url: "functions/temp_selection.php?mode=order",
		 type: "POST",
		 data: "variable="+variable,
		 success: function(data){
		 //alert (data);
		 document.getElementById('selection_not_saved').innerHTML='Your selection is not validated yet. Go to "<a href="<?php echo $link_root; ?>/my_account/#selection" style="color:#C30">Selection"</a> and validate later. Or send <a style="color:#C30; cursor:pointer" onclick="valid_myselection();">NOW</a>';
		  document.getElementById('div_save_selection').style.display='';
		 display_important_message();
      }});	  
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DELETE WITH AJAX THE SELECTION
function selection_delete(id){	
var adress = 'functions/temp_selection.php?mode=del&id='+id;	
$.ajax({
  url: adress,
  success: refresh_account()
});
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Affiche le DIV d'alert dans le header si celui ci contient qq chose.
/*function display_important_message(){
    importante_message=false;
	if (document.getElementById('obsolete_account').innerHTML!=""){importante_message=true;}
	if (document.getElementById('selection_not_saved').innerHTML!=""){importante_message=true;}	
	if 	(importante_message==true){document.getElementById('important_message').style.display="";}
	else {
	document.getElementById('important_message').style.display="none";	
	}
}*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function refresh_account(){
if (document.getElementById('my_account_loader')) document.getElementById('my_account_loader').style.display='';
if (document.getElementById('selection_not_saved')) document.getElementById('selection_not_saved').innerHTML="Attention: Your selection is not saved yet. Go to \"My account > my selection\" and validate it.";
display_important_message();
if (document.getElementById('div_save_selection')) document.getElementById('div_save_selection').style.display='';	
setTimeout("form_call('selection')", 1000)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function display_why_weekly(on){
	thisdiv = document.getElementById('bulle_why_weekly') ;
	if (on==1){
	thisdiv.innerHTML="When you apply to an internship, employer receive an email and get your application in their Kampus management systeme.<br />We let one week to employers to check your application before you possibly remove it.";
	thisdiv.style.display='block';
	}
	else {
	thisdiv.style.display='none';	
	}
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function initialise_table(){
    // Initialise the table
    $("#table").tableDnD({
	    onDragClass: "cell_on_drag",
		onDrop: function(table, row){
			variable=$.tableDnD.serialize();
			reorder_table(variable)}
			});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function valid_myselection(){
if (document.getElementById('my_account_loader')) document.getElementById('my_account_loader').style.display='';		
if (document.getElementById('div_save_selection')) document.getElementById('div_save_selection').style.display='none';
var adress = '../../my_account/functions/myselection_valid.php';
$.ajax({
  url: adress,
  success: function(){
	  //alert(data);
	  refresh_account(); 
	  if (document.getElementById('selection_not_saved')) document.getElementById('selection_not_saved').innerHTML='Your application has been sent to your selection.';}
}); 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





   ////////////////////////
 //   IDENTIFICATION /////
/////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function password(){
	document.getElementById('my_account_loader').style.display='';	
	$("#my-body-account").load("change_password.php",function(){
	document.getElementById('my_account_loader').style.display='none';						   							   
															  });
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function account_delete(){
	document.getElementById('my_account_loader').style.display='';	
	$("#my-body-account").load("delete_account.php",function(){
	document.getElementById('my_account_loader').style.display='none';						   							   
															  });
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function password_form(){
// SENDING THE FORMS WITH AJAX
// prepare the form when the DOM is ready 
$(document).ready(function() {	
    var options = { 
        success:       showResult  // post-submit callback
    }; 
    // bind form using 'ajaxForm'
    $('#formpassword').ajaxForm(options);
}); 
function showResult(responseText)  {
	document.getElementById('my-body-account').innerHTML=	responseText;
	password_form();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





  ////////////////////
 //   EDUCATION /////
////////////////////

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 // Charge toutes les options dans les array et show/ hide en function du type d'education 
 
 function refresh_education(){
document.getElementById('my_account_loader').style.display='';	
setTimeout("form_call('education')", 100)
}
 
 function change_edu_degree(type,edu){
var degree="edu"+edu+"_degree";
var subject="edu"+edu+"_subject";
var name="edu"+edu+"_school";
var country = "edu"+edu+"_country";
var year ="edu"+edu+"_year";


var degree= document.getElementById(degree);
var subject= document.getElementById(subject);
var name = document.getElementById(name);
var country = document.getElementById(country);
var year = document.getElementById(year);

	
	if (type==1){
		subject.value="";
		subject.disabled=true;
		name.value="";
		name.disabled=true;
		country.value="";
		country.disabled=true;
		year.value="";
		year.disabled=true;
	}
	
	else {
		subject.disabled=false;
		name.disabled=false;
		country.disabled=false;
		year.disabled=false;	
		
	}
	

// upload
modifyText();



// refresh
//if (type==1 || big_global==1) refresh_education();
		
 }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




 ////////////////////
 //   MESSAGES /////
////////////////////

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function display_message(id){
anticache=Math.floor((100)*Math.random()+1);	
adress='message_details.php?id='+id+'&n='+anticache;	
document.getElementById('my_account_loader').style.display='';
	$("#email_body").load(adress, function() {
document.getElementById('my_account_loader').style.display='none';
});
	
}


































