/***********************************************************
*       functions_main.js
*
* JavaScript functions used by the main page of the MDB interface.
*  Dataset radio button with unique selection 
*
*
************************************************************/

// ----------- VARIABLES --------
// Initialization of tab for dataset/captor 
var pc_dataset = new Array();
//Flag to know the submit button pressed
var submitButton = '0';
var target = "result";
// Counter of selected dataset type
var counterIR = 0;
var counterMW = 0;

//function station_valid()	//Test FONCTION OF STATION CHECKBOX
//{
//  // If box station is checked then enable the depth field
//  if(document.form_select_data.station_src.checked==true){
//   
//    document.form_select_data.valid_depth.disabled=false;
//    document.form_select_data.viewDepth.disabled=false;
//    document.form_select_data.viewDepthQC.disabled=false;
//    
//    //return (false);
//  }
//  else {
//    document.form_select_data.valid_depth.disabled=true;  //disabled au lieu de true
//    document.form_select_data.viewDepth.disabled=true;
//    document.form_select_data.viewDepthQC.disabled=true;
//  }
//}


// Enabled or disabled the proximity_confidence checkboxes according to the UNIQUE dataset selected
function set_prox_conf_sensor(sensor_type){

    if(sensor_type == 'IR'){
       pcIR(false); // enable
       pcMW(true);  // disable
    }
    if(sensor_type == 'MW'){
      pcMW(false); // enable
      pcIR(true);  // disable
    }   
    if(sensor_type == '-'){
      pcMW(true); // enable
      pcIR(true);  // disable
    }   
}


// Enabled or disabled the proximity_confidence checkboxes according to the UNIQUE dataset selected
function set_prox_conf_Radio(dataset_index)
{
  var checkbox_value = dataset_index.value;
  
  if(dataset_index.checked){
    
    if(pc_dataset[checkbox_value]== 'IR'){
       pcIR(false); // enable
       pcMW(true);  // disable
    }
    if(pc_dataset[checkbox_value]== 'MW'){
      pcMW(false); // enable
      pcIR(true);  // disable
    }   
    if(pc_dataset[checkbox_value]== '-'){
      pcMW(true); // enable
      pcIR(true);  // disable
    }   

  }
}


// Disable or not the 'proximity confidence' checkbox
function pcIR(value){
  document.form_select_data.pc0.disabled = value;
  document.form_select_data.pc1.disabled = value;
  document.form_select_data.pc2.disabled = value;
  document.form_select_data.pc3.disabled = value;
  document.form_select_data.pc4.disabled = value;
  document.form_select_data.pc5.disabled = value;
  document.form_select_data.pc6.disabled = value;
}

function pcMW(value){
  document.form_select_data.pc7.disabled = value;
  document.form_select_data.pc8.disabled = value;
  document.form_select_data.pc9.disabled = value;
  document.form_select_data.pc10.disabled = value;
}

// Reset value to 0 and 100 % or delete all :
function pc_delete(value){
  document.form_select_data.ppc_min_0.value = value;
  document.form_select_data.ppc_min_1.value = value;
  document.form_select_data.ppc_min_2.value = value;
  document.form_select_data.ppc_min_3.value = value;
  document.form_select_data.ppc_min_4.value = value;
  document.form_select_data.ppc_min_5.value = value;
  document.form_select_data.ppc_min_6.value = value;

  if (value == '0') { value = '100'; } //Case of reset to 0% (for min) and 100% (for max)
  document.form_select_data.ppc_max_0.value = value;
  document.form_select_data.ppc_max_1.value = value;
  document.form_select_data.ppc_max_2.value = value;
  document.form_select_data.ppc_max_3.value = value;
  document.form_select_data.ppc_max_4.value = value;
  document.form_select_data.ppc_max_5.value = value;
  document.form_select_data.ppc_max_6.value = value;

}



//Window for result
function fen_result(){
      
    fen_r = window.open("","result","1,0,0,0,0,scrollbars=yes,resizable=yes,height=200,width=600,top=50,left=50");
    if(self.focus) fen_r.focus();
    
}

// onSubmit with either submit button
function check_form(){
  try{
    // Check that Name and E-mail were filled in  
    if (document.form_select_data.client_name.value == ""  || document.form_select_data.client_mail.value == ""){
      alert("WARNING :\n  Please, enter your name and your e-mail for data extraction !");
      return false;
    }else{

    // Create window to show result
    fen_result();    
    

    // Identify action to do : to export to file or to view
//    if (submitButton == '0'){ // Export data           
//      document.form_select_data.counter_file.value++;
//      
//      //METTRE CETTE VALEUR DANS UN FICHIER POUR LA CONSERVER POUR TOUTES LES CESSIONS
//
//
//      if (document.form_select_data.counter_file.value > 5) { document.form_select_data.counter_file.value = 0; }
//      return true;
//    }else{
//      
//      
//      return true;
//
//    }

    
    return true;
    }
  }catch(err){
    alert('JAVASCRIPT ERROR !');
    document.write("We got an error in the javascript code !");
  }




function sendValidationCommand(){  
   var dt=new Date();
   //window.status=dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds();
   alert("-->"+dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds());

   //setTimeout("window.location.href = 'http://knik:17000/MdbViewer/consultation/mdb_test_file_exist.php';", '2000');
   
   setTimeout("sendValidationCommand();",'2000');

 }

// function test(){
//   //setTimeout("/MdbViewer/consultation/mdb_test_file_exist.php';", '2000');
//
//   <?php
//     include("./mdb_test_file_exist.php");
//
//
//   ?>
//   setTimeout("test();",'2000');
// }

}

      

