function autofill_inst_city(inst_ctr) {
  var inst_type, count, cnt;
  var ctr_id = this.extraParams;
  if ( ctr_id.indexOf('school') > 0 ) {
    inst_type = 'school';
    count = ctr_id.substring(10);
  } else {
    inst_type = 'college';
    count = ctr_id.substring(16);
  }
  var inst_val = trim(inst_ctr.selectValue);
  if ( inst_val != "" ) {
    last_index = inst_val.lastIndexOf(",");
    if ( last_index > 0 ) {
      var temp_inst = trim(inst_val.substr(0,last_index));
      var temp_city = trim(inst_val.substr(last_index+1));
      if ( temp_inst != "" && temp_city != "" ) {
        if ( inst_type == 'school' ) {
          document.getElementById('div_school'+count).value = temp_inst;
          document.getElementById('div_school_city'+count).value = temp_city;
        }
        if ( inst_type == 'college' ) {
          document.getElementById('div_college_name'+count).value = temp_inst;
          document.getElementById('div_college_city'+count).value = temp_city;
        }
      }
    }
  }
}
function validate_classmate_search(frm) {
  var i=0;
  if(frm.searchfor_user.checked == false && frm.searchfor_comm.checked == false){
    showToolTip_from('searchfor_comm', __('Please choose either or both school and community.'),50, 6);
    i=1;
  } else if(frm.org_name.value == ""){
    showToolTip_from('year_of_passing', __('Please choose school or college to search.'),50, 6);
    i=1;
  }
  if(frm.searchfor_comm.checked) {
    if(frm.searchfor_user.checked){
      document.getElementById('mode').value = 'user';
    } else {
    document.getElementById('mode').value = 'community';
    }
  } else {
  document.getElementById('mode').value = 'user';
  }
  if(i == 1){
    return false;}
   else{
     return true;
   }
}
function lookupLocal() {
var oSuggest;
  $('[@id^="#div_school"]').each(function() {
  oSuggest = $(this).autocompleter;
  });
  $('[@id^="#div_college_name"]').each(function() {
  var oSuggest = $(this)[0].autocompleter;
  });
  return false;
}
var pre_output_school, pre_output_college;
function auto_load_institute(output_school, output_college) {
  pre_output_school = output_school;
  pre_output_college = output_college;
  $('input[@id^="div_school"]').each(function() {
   if($(this).attr('type') == "text" && $(this).attr('name').indexOf("city") <= 0){
    $(this).autocompleteArray(
      output_school,
      {
        delay:10,
        minChars:1,
        matchSubset:1,
        autoFill:false,
        maxItemsToShow:10,
        extraParams:$(this).attr('id'),
        onItemSelect:autofill_inst_city
      }
    );
   }
  });
  $('input[@id^="div_college_name"]').each(function() {
   if($(this).attr('type') == "text" && $(this).attr('name').indexOf("city") <= 0){
    $(this).autocompleteArray(
      output_college,
      {
        delay:10,
        minChars:1,
        matchSubset:1,
        autoFill:false,
        maxItemsToShow:10,
        extraParams:$(this).attr('id'),
        onItemSelect:autofill_inst_city
      }
    );
   }
  });
}
function display_headline_field() {
  var tab_value = addslashes(document.getElementById('headline').innerHTML);
  if(tab_value == __('No Status')) {
      tab_value = '';
  }
  document.getElementById('current_tab_input').value = trim(tab_value);
  document.getElementById('headline').style.display = 'none';
  document.getElementById('changeHeadline').style.display = 'block';
  document.getElementById('current_tab_input').focus();
}

function save_headline() {
  var val = document.getElementById('current_tab_input').value;
  val = trim(val);
  var tab_value = stripslashes(val);
  $.get(
    "save_headline.php",
    {
      'value': tab_value,
      'random': (new Date().getTime())
    },
    function(data) {
    }
  );
  if(tab_value == '') {
      document.getElementById('headline').innerHTML = __('No Status');
  } else {
    document.getElementById('headline').innerHTML = tab_value;
  }
  document.getElementById('changeHeadline').style.display = 'none';
  document.getElementById('headline').style.display = 'block';
}
