/**
 *reload sub-field list depend on field
 *reload  software depend on field
 *reload specialty depend on field
 *
 */
 

$(function(){

    $("#backtostep1").live('click', function(){
        window.location ="app/register/person_step_1";
        return false;
    });
    
    $("#job_field").change(function(){
        $("#job_subfield").children().remove();
        $("#scroll_box_specialty").children().remove();
        $("#scroll_box_software").children().remove();
        var url = 'app/register/get_job_subfield_specialties_software_list/';
        $.post(
               url,
               { 'job_field_id': $(this).val() },
                function(data){
                    var aData = data.split('||');
                    if(aData[0] != 'no_data')
                        $("#job_subfield").append(aData[0]);
                    if(aData[1] != 'no_data')
                        $("#scroll_box_specialty").append(aData[1]);
                    if(aData[2] != 'no_data')
                        $("#scroll_box_software").append(aData[2]);
                }, "html");
    });
    
    $("#job_subfield").change(function(){
        $("#job_subfield option:selected").each(function () {
            if($(this).text() == "Other") {
                $(".other_subfield_row").show();
                $("#other_subfield_row").val('1');
            }
            else {
                $(".other_subfield_row").hide();
                $("#other_subfield_row").val('0');
            }
        });
    });
    
    $("#job_subfield option:selected").each(function () {
        if($(this).text() == "Other") {
            $(".other_subfield_row").show();
            $("#other_subfield_row").val('1');
        }
        else {
            $(".other_subfield_row").hide();
            $("#other_subfield_row").val('0');
        }
    });
});

function setStateArea(country_id, state_id, state_others, area_id , area_others){
       
        //alert(country_id + '-' + state_id +'-' + state_others + '-' + area_id +'-'+ area_others);
        if(country_id){
            var url = 'app/register/get_state_list/';
            $.post(
                   url,
                   { 'country_id': country_id , 'selected': state_id},
                    function(data){
                       //alert(data);
                       if(data == 'no_data'){
                            $("#state_id").hide();
                            $("#area_id").hide();
                            $("#state_others").show();
                            $("#state_others").val(state_others) ;
                            $("#area_others").show();
                             $("#area_others").val(area_others)  ;
                       }else{
                            $("#state_id").children().remove();
                            $("#area_id").children().remove();
                            
                            $("#state_id").show();
                            $("#area_id").show();
                            var url = 'app/register/get_area_list/';
                            $.post(
                            url,
                            { 'state_id': state_id, 'selected': area_id},
                             function(data){
                                //alert(data);
                                 if(data == 'no_data'){
                                     $("#area_id").hide();
                                     $("#area_others").show();
                                 }else{
                                     $("#area_id").show();
                                     $("#area_others").hide();
                                     $("#area_id").append(data);
                                 }
                             }, "html");
                            $("#state_others").hide();
                            $("#area_others").hide();
                            
                            $("#state_id").append(data);
                       }
                    }, "html");
        }
    }


