/*jQuery('#sf_fieldset_hourly_cost').ready(function(){

    jQuery('#sf_fieldset_hourly_cost .sf_admin_form_row').hide();
    jQuery('#sf_fieldset_hourly_cost .sf_admin_form_row input[value!=""]').parent().parent().parent().show();
    jQuery('#hourly_cost_selector').show();
    jQuery('#hourly_cost_submit').click(function(){
        val = jQuery('#hourly_cost_selector select').val();
        jQuery('.sf_admin_form_field_'+val).show();
        jQuery('#hourly_cost_selector select option[value='+val+']').remove();
        return false;
    });

});*/


jQuery('.sf_admin_form').ready(function(){
    jQuery('.sf_admin_form fieldset h2').click(function(){
        jQuery(this).next('.fieldset').toggle();
        jQuery(this).toggleClass('on');
        return false;
    });
    jQuery('.sf_admin_form fieldset .fieldset').hide();
    // display the first fieldset
    jQuery('.sf_admin_form fieldset .fieldset:first').show();    
    jQuery('.sf_admin_form fieldset h2:first').addClass('on');
    // display a fieldset if it contains an error
    jQuery('.sf_admin_form fieldset .fieldset .errors').parent().show();
    jQuery('.sf_admin_form fieldset .fieldset .errors').parent().prev().addClass('on');
});

jQuery('#api_generate_key').ready(function(){
    jQuery('#api_generate_key').click(function(){
        var password = generatePassword(8, false);
        jQuery('#api_key').val(password);
        return false;
    });
});

jQuery('#translations_list').ready(function(){
    jQuery('#translations_list table').hide();
    jQuery('#translations_list li:first table').show();
    jQuery('#translations_list li .translation_label').click(function(){
        jQuery(this).next('table').toggle();
    })
});


function generatePassword(length, special) {
  var iteration = 0;
  var password = "";
  var randomNumber;
  if(special == undefined){
      var special = false;
  }
  while(iteration < length){
    randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
    if(!special){
      if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
      if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
      if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
      if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
    }
    iteration++;
    password += String.fromCharCode(randomNumber);
  }
  return password;
}
