$(document).ready(function() {


    $("#sp_1_val").focus(function() {
        if ($(this).val() == "Name / Product No.") {
            $(this).val("");
        }
    });

    $("#sp_1_val").blur(function() {
        if ($(this).val() == "") {
            $(this).val("Name / Product No.");
        }
    });

    // clean form
    $("input[name$='txtSearch']").val("");



    if ($("input[name$='txtBrand']").val() != 0) {
        $("input[name$='txtBrand']").val(0);
    }
    if ($("input[name$='txtCategory']").val() != 0) {
        $("input[name$='txtCategory']").val(0);
    }
    if ($("input[name$='txtRange']").val() != 0) {
        $("input[name$='txtRange']").val(0);
    }

    $("#sp_1_val").change(function() {
    $("input[name$='txtSearch']").val($("#sp_1_val").val());

    });

    $("div.sp_2 div.sp_btn").click(function() {
        //alert("Hello0");
        $("div.sp_sub2 ul").html($("div.sp_brand").html());
        $("div.sp_sub2").toggle();
        $("div.sp_sub3").hide();
        $("div.sp_sub4").hide();
        $("div.sp_sub2 ul li").click(function() {

            brand = $(this).html();
            idx = $(this).attr("idx");
            cid = $(this).attr("cid");
			catid = $(this).attr("cid");
            $("#search_product_brand").val(brand);

            $("input[name$='txtBrand']").val(cid); //find and change.


            $("#sp_2_val").val(cid);
            $("div.sp_sub2").hide();
            //alert(cid);
            //alert($("div[cid='"+cid+"']").innerHTML);
            /*			
            tmp_html="";
            for(i=0;i<$("div.sp_range").size();i++){
            if(cid==$("div.sp_range")[i].attr("cid")){
            tmp_html=$("div.sp_range")[i].innerHTML;
            }
            }
            */
            $("div.sp_sub3 ul").html($("div." + cid)[0].innerHTML);
            //$("div.sp_sub4 ul").html($("div.sp_type")[idx].innerHTML);

            $("#search_product_category").val("Range");
            $("#sp_3_val").val("");
            $("input[name$='txtCategory']").val(0);
            $("#search_product_range").val("SubType");
            $("#sp_4_val").val("");
            $("input[name$='txtRange']").val(0);
            click_subs();
            ///////////////////////////////
            //	category = $(this).html();
            //idx = $(this).attr("idx");
            //	cid = $(this).attr("cid");
            //	 $("#search_product_category").val(category);
            //$("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneMain_ProductSearchBox_txtCategory").val(cid);
            // $("#sp_3_val").val(cid);

            $("#search_product_range").val("SubType");
            $("#sp_4_val").val("");
            $("div.sp_sub4 ul").html($("div.allcat." + cid)[0].innerHTML);

            $("div.sp_sub3").hide();
            li_over();
            $("div.sp_sub4 ul li").click(function() {
                subtype = $(this).html();
                idx = $(this).attr("idx");
                cid = $(this).attr("cid");
                $("#search_product_range").val(subtype);
                $("input[name$='txtRange']").val(cid);
                $("#sp_4_val").val(cid);
                $("div.sp_sub4").hide();
            });








            //////////////////////////////

            //click_subs();
        });
        li_over();
    });
    $("div.sp_3 div.sp_btn").click(function() {
        $("div.sp_sub3").toggle();
        $("div.sp_sub2").hide();
        $("div.sp_sub4").hide();
        li_over();
    });
    $("div.sp_4 div.sp_btn").click(function() {
        $("div.sp_sub4").toggle();
        $("div.sp_sub2").hide();
        $("div.sp_sub3").hide();
        li_over();
    });








    $("div.sp_btn").mouseover(function() {
        $(this).css("background-color", "#f0f0f0");
    });
    $("div.sp_btn").mouseout(function() {
        $(this).css("background-color", "#ffffff");
    });


});



function li_over(){
	$("div.sp_div ul li").mouseover(function(){
		$(this).css("background-color","#f0f0f0");
	});
	$("div.sp_div ul li").mouseout(function(){
		$(this).css("background-color","#ffffff");
	});

}

function click_subs() {
    $("div.sp_sub3 ul li").click(function() {
        category = $(this).html();
        idx = $(this).attr("idx");
        cid = $(this).attr("cid");
		catid = $("input[name$='txtBrand']").val();
        $("#search_product_category").val(category);
        $("input[name$='txtCategory']").val(cid);
        $("#sp_3_val").val(cid);

        $("#search_product_range").val("SubType");
        $("#sp_4_val").val("");
        $("input[name$='txtRange']").val(0);
        $("div.sp_sub4 ul").html($("div.cat" + catid + ".subcat." + cid)[0].innerHTML);

        $("div.sp_sub3").hide();
        li_over();
        $("div.sp_sub4 ul li").click(function() {
            subtype = $(this).html();
            idx = $(this).attr("idx");
            cid = $(this).attr("cid");
            $("#search_product_range").val(subtype);
            $("input[name$='txtRange']").val(cid);
            $("#sp_4_val").val(cid);
            $("div.sp_sub4").hide();
        });
    });
    /*
    category = $(this).html();
    idx = $(this).attr("idx");
    cid = $(this).attr("cid");
    */
	
}
