
$(document).ready(function() {
    //          createDropDown('aah_bolge_seciniz','dropdown_h');
    //            initDropDown('aah_bolge_seciniz','dropdown_h');
    //alert($(".dropdown_select_startServicePoint").attr('id'));
    createDropDown($(".dropdown_select_startServicePoint").attr('id'), 'dropdown_h1');
    initDropDownWithSelectedChange($(".dropdown_select_startServicePoint").attr('id'), 'dropdown_h1', $(".dropdown_select_endServicePoint").attr('id'), 'dropdown_h2');
    //initDropDown('ctl00_SearchControl_CustomSearch_StartServicePoint','dropdown_h1');
    //initDropDownFirst('ctl00_SearchControl_CustomSearch_StartServicePoint','dropdown_h1','StartServicePoint');
    createDropDown($(".dropdown_select_endServicePoint").attr('id'), 'dropdown_h2');
    initDropDown($(".dropdown_select_endServicePoint").attr('id'), 'dropdown_h2');
    $(".dropdown_select_start_time").each(function() {
        if ($(this).attr('id').indexOf('_StartDate_') > 0) {
            createDropDown($(this).attr('id'), 'dropdown_h3');
            initDropDown($(this).attr('id'), 'dropdown_h3');
        }
        else {
            createDropDown($(this).attr('id'), 'dropdown_h4');
            initDropDown($(this).attr('id'), 'dropdown_h4'); 
        }
    });
//    createDropDown('ctl00_SearchControl_CustomSearch_StartDate_StartTime', 'dropdown_h3');
//    initDropDown('ctl00_SearchControl_CustomSearch_StartDate_StartTime', 'dropdown_h3');
    //createDropDown('ctl00_SearchControl_CustomSearch_EndDate_StartTime', 'dropdown_h4');
    //initDropDown('ctl00_SearchControl_CustomSearch_EndDate_StartTime', 'dropdown_h4');
    createDropDown('ctl00_MainContent_Checkout_CreditCardControl_CardType', 'dropdown7');
    initDropDown('ctl00_MainContent_Checkout_CreditCardControl_CardType', 'dropdown7');

    createDropDown('ctl00_MainContent_Checkout_CreditCardControl_ExpirationMonth', 'dropdown4');
    initDropDown('ctl00_MainContent_Checkout_CreditCardControl_ExpirationMonth', 'dropdown4');
    createDropDown('ctl00_MainContent_Checkout_CreditCardControl_ExpirationYear', 'dropdown5');
    initDropDown('ctl00_MainContent_Checkout_CreditCardControl_ExpirationYear', 'dropdown5');

    createDropDown('ctl00_MainContent_RequestedVehicleType', 'dropdown5');
    initDropDown('ctl00_MainContent_RequestedVehicleType', 'dropdown5');
    //           createDropDown('ctl00_LoginControl_LoginControl_co_il2_secniz','dropdown_h5');
    //            initDropDown('ctl00_LoginControl_LoginControl_co_il2_secniz','dropdown_h5');  
    //             createDropDown('ctl00_LoginControl_LoginControl_co_ulke2_secniz','dropdown_h6');
    //            initDropDown('ctl00_LoginControl_LoginControl_co_ulke2_secniz','dropdown_h6');  


    //			

    //            createDropDown('aah_baslangic_tarihi','dropdown_h3');
    //            initDropDown('aah_baslangic_tarihi','dropdown_h3');
    //			
    //            createDropDown('aah_bitis_tarihi','dropdown_h4');
    //            initDropDown('aah_bitis_tarihi','dropdown_h4');
    //			
    //            createDropDown('aas_bolge_seciniz','dropdown');
    //            initDropDown('aas_bolge_seciniz','dropdown');
    //			
    //            createDropDown('aas_sehir_secniz','dropdown1');
    //            initDropDown('aas_sehir_secniz','dropdown1');
    //			
    //            createDropDown('aas_arac_noktalari','dropdown2');
    //            initDropDown('aas_arac_noktalari','dropdown2');
    //			
    //            createDropDown('aas_baslangic_tarihi','dropdown3');
    //            initDropDown('aas_baslangic_tarihi','dropdown3');
    //			
    //            createDropDown('aas_bitis_tarihi','dropdown4');
    //            initDropDown('aas_bitis_tarihi','dropdown4');
    //			
    //            createDropDown('co_il_secniz','dropdown5');
    //            initDropDown('co_il_secniz','dropdown5');
    //			
    //            createDropDown('co_ulke_secniz','dropdown6');
    //            initDropDown('co_ulke_secniz','dropdown6');
    //			
    //            createDropDown('co_odemetipi_secniz','dropdown7');
    //            initDropDown('co_odemetipi_secniz','dropdown7');
    //			
    //            createDropDown('co_cinsiyetiniz','dropdown8');
    //            initDropDown('co_cinsiyetiniz','dropdown8');
    //			
    //            createDropDown('co_il2_secniz','dropdown9');
    //            initDropDown('co_il2_secniz','dropdown9');
    //			
    //            createDropDown('co_ulke2_secniz','dropdown10');
    //            initDropDown('co_ulke2_secniz','dropdown10');
});

function initMembershipDropdowns()
{
     var ddListID=$("[id$='_Gender']").attr("id");
     createDropDown(ddListID, 'dropdown8');
     initDropDown(ddListID, 'dropdown8');
     createDropDown('ctl00_LoginControl_LoginControl_co_il2_secniz','dropdown9');
     initDropDownForCountry('ctl00_LoginControl_LoginControl_co_il2_secniz', 'dropdown9');
     createDropDown('ctl00_LoginControl_LoginControl_co_ulke2_secniz','dropdown10');
     initDropDown('ctl00_LoginControl_LoginControl_co_ulke2_secniz','dropdown10');    
}
        
        function initDropDown(id, itclass){        
            $("."+itclass+" dt a").click(function() {
                $("."+itclass+" dd ul").toggle();
				return false;
            });

            $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (!$clicked.parents().hasClass(itclass))
                    $("." + itclass + " dd ul").hide();
            });

            $("." + itclass + " dd ul li a").click(function() {
                var text = $(this).html();
                $("." + itclass + " dt a").html(text);
                $("." + itclass + " dd ul").hide(); 
                
                var source = $("#" + id);  
                source.val($(this).find("span.value").html())
                return false;
            });
        }

        /*test*/

        function initDropDownForCountry(id, itclass) {
            $("." + itclass + " dt a").click(function() {
                $("." + itclass + " dd ul").toggle();
                return false;
            });

            $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (!$clicked.parents().hasClass(itclass))
                    $("." + itclass + " dd ul").hide();
                bindCity();
            });

            $("." + itclass + " dd ul li a").click(function() {
                var text = $(this).html();
                $("." + itclass + " dt a").html(text);
                $("." + itclass + " dd ul").hide();

                var source = $("#" + id);
                source.val($(this).find("span.value").html())
                return false;
            });
        }

        function initDropDownWithSelectedChange(id, itclass,otherId,otherItClass) {
            $("." + itclass + " dt a").click(function() {
                $("." + itclass + " dd ul").toggle();
                return false;
            });

            $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (!$clicked.parents().hasClass(itclass))
                    $("." + itclass + " dd ul").hide();
            });

            $("." + itclass + " dd ul li a").click(function() {
                var text = $(this).html();
                $("." + itclass + " dt a").html(text);
                $("." + itclass + " dd ul").hide(); 

                var source = $("#" + id); 
                source.val($(this).find("span.value").html())
                if($(this).find("span.value").html() != "")
                {
                    $("." + otherItClass + " dt a").html(text);
                    $("." + otherItClass + " dd ul").hide();                               
                    var otherSource = $("#" + otherId);                
                    otherSource.val($(this).find("span.value").html());
                }
                
                return false;
            });
        }
        

        function initDropDownFirst(id, itclass, rawId){
        try
        {        
            $("."+itclass+" dt a").click(function() {
                $("."+itclass+" dd ul").toggle();
				return false;
            });

            $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (!$clicked.parents().hasClass(itclass))
                    $("." + itclass + " dd ul").hide();
                //setTimeout('__doPostBack(\''+ rawId +'\',\'\')', 0);
                __doPostBack(rawId, '');
            });
                        
            $("."+itclass+" dd ul li a").click(function() {
                var text = $(this).html();
                $("."+itclass+" dt a").html(text);
                $("."+itclass+" dd ul").hide();
                
                var source = $("#"+id);
                source.val($(this).find("span.value").html())
				
            });
             }
            catch(er)
            {
            alert(er.description);
            }
        }
           
        function createDropDown(id, itclass){
        try
        {
            var source = $("#"+id);
            var selected = source.find("option[selected]");
            var options = $("option", source);            
            $("#"+id+"_block").append('<dl id="'+id+'_target" class="'+itclass+'"></dl>')
            $("#"+id+"_target").append('<dt><a href="#">' + selected.text() + 
                '<span class="value">' + selected.val() + 
                '</span></a></dt>')
            $("#"+id+"_target").append('<dd><ul></ul></dd>')

            options.each(function(){
                $("#"+id+"_target dd ul").append('<li><a href="#">' + 
                    $(this).text() + '<span class="value">' + 
                    $(this).val() + '</span></a></li>');
            });
            }
            catch(er)
            {
            alert(er.description);
            }
        }
        function bindCity() {
            //setTimeout('__doPostBack(\'CountrySelectedChange\',\'\')', 1000);
           // __doPostBack('CountrySelectedChange', '');
        }