var $specailarray = new Array();
var $industryarray = new Array();
$.getScript('/js/ajax/ajax-selectedarray.php');
$(document).ready(function(){
    $('#cboxspecialties').click(function(){
        if($('#cboxspecialties').attr('checked')==true)
            $('#rspecialties').load('/js/ajax/ajax-specialties.php',function(){
                checkselected(1);
            });
        else
        {
            $('#rspecialties').html('');
            //alert($('#cboxspecialties').attr('checked'));
        }
    });
    $('#cboxindustries').click(function(){
        if($('#cboxindustries').attr('checked')==true)
            $('#rindustries').load('/js/ajax/ajax-industries.php',function(){
                checkselected(2);
            });
        else
            $('#rindustries').html('');
    });
    rebindselects();
    $('.rschange input,.rschange select').change(function(){
        $('#resource').submit(); 
    });
    $('#clrindustries').click(function(){
        $('#industries').val('');
    });
});

function checkselected($sel)
{
    $count = $('#filters input').length;
    var $i;
    for ($i=0;$i<$count;$+=1)
    {
        $name = $('#filters input').eq($i).attr('name');
        $name=$name.replace('Opt[','');
        $name=$name.replace(']','');
        $('#industries_'+$name).attr('checked','false');
        $('#specialties_'+$name).attr('checked','false');
    }
    rebindselects();
}

function rebindselects()
{
    $('.rselect input').click(function(){
        $optionid = $(this).attr('value');
        if($(this).attr('checked')==true)
        {
            $('.Opt'+$optionid).show();
            $('#Opt'+$optionid).remove();
            //alert('cked');
        }
        else
        {
            $('.Opt'+$optionid).hide();
            $('#filters').append('<input type="hidden" id="Opt'+$optionid+'" name="Opt['+$optionid+']" value="true"/>');
            //alert('nocked');
        }        
    });    
}


