// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/* COMMON BETWEEN ORGS AND RESEARCHERS*/
function check_position()
{
     s = document.getElementById('position_position_id')	
     if (s.options[s.options.length-1].selected)
     	document.getElementById('position_position').disabled = false
    else
     	document.getElementById('position_position').disabled = true

}

function check_country()
{
     s = document.getElementById('contact_country_code')	
     if (s.options[s.options.length-1].selected)
     	document.getElementById('contact_country').disabled = false
    else
     	document.getElementById('contact_country').disabled = true

}

function check_domain()
{
     s = document.getElementById('contact_domain_list')	
     if (s.options[s.options.length-1].selected)
     	document.getElementById('contact_domain_other').disabled = false
    else
     	document.getElementById('contact_domain_other').disabled = true

}

/* Updates the parameters (passed along with browse links) 
   which determine the number of researchers/organisations to be displayed
   on screen, according to the user's selection
*/
function updateResultsPerPage(selectedValue) 
{
    //three categories of links for each one the browsing modes
    var linkCategoriesArray = ['country_link', 'area_link', 'language_link'];
    //for each category
    for(var i = 0; i < linkCategoriesArray.length; i++) {
        //get the corresponding links
        var linksArray = document.getElementsByName(linkCategoriesArray[i]);
        if(linksArray.length > 0) {
            //change each parameter according to the user's selected value
            changeUrlParameter(linksArray, linkCategoriesArray[i], selectedValue);
        }
    }
}
    
function changeUrlParameter(linksArray, linkName, selectedValue) 
{
    var linksArrayLength = linksArray.length;
    //for each link
    for(var i = 0; i < linksArrayLength; i++) {
        //get the first numeric value within the href, and replace it with
        //the user defined one 
        var href = linksArray[i].href.replace(/=[0-9][0-9]/, "=" + selectedValue);
        document.getElementById(linkName + "_" + i).href = href;
    }
}


/* ORGANISATIONS SPECIFIC*/
function check_region()
{
     s = document.getElementById('contact_region_code')	
     if (s.options[s.options.length-1].selected)
     	document.getElementById('contact_region').disabled = false
    else
     	document.getElementById('contact_region').disabled = true

}

function check_type()
{
     s = document.getElementById('organisation_org_type_ids')	
     if (s.options[s.options.length-1].selected)
     	document.getElementById('organisation_org_type').disabled = false
    else
     	document.getElementById('organisation_org_type').disabled = true

}

function check_parent()
{
  if ($('organisation_has_parent_yes').checked)
    $('organisation_parent_organisation').disabled = false
  else
   $('organisation_parent_organisation').disabled = true
}


/* RESEARCHERS SPECIFIC*/
function check_organisation()
{
     s = document.getElementById('person_organisation_id')	
     if (s.options[s.options.length-1].selected)
     	document.getElementById('person_organisation_other').disabled = false
    else
     	document.getElementById('person_organisation_other').disabled = true

}

function clearLang(lang)
{
  $('person_' + lang + '_skill_m').checked = "";
  $('person_' + lang + '_skill_f').checked = "";
  $('person_' + lang + '_skill_w').checked = "";

}


