/*var cmsurl;
        var cmsurl2  ;
        var cmsjson1, cmsjson2;	
		
		Ascii/Native编码互转  http://tool.chinaz.com/tools/native_ascii.aspx
		*/
$(function () {
    classinit1();
    $(document).on("click", "#select1", function () {
        $("#cmscata_div").show();
    });
    $("#cmsclass1").hover(function () {
        cmscata1state = true;
    }, function () {
        cmscata1state = false;
    });
    $(document).click(function () {
        if (cmscata1state == false) {
            $("#cmscata_div").hide();
        }
    });

    $(document).on("click", "#cmscata_submit", function () {
        $("#cmscata_div").hide();
        $("#select1").html("已选择分类");
    });
    $(document).on("click", ".cmsul0 li input", function () {
        var objid = $(this).val();
        var depth0 = parseInt($(this).prop("title"));
        var ul = document.getElementById("cmsul" + objid);
        var flag = false;
        flag = $(this).get(0).checked;
        if (ul == null) {
            var hb2 = "";
            hb2 = Selectchange(objid, depth0);
            if (hb2 != "") {
                $(this).parent().after("<li>" + hb2 + "</li>");
            }
        }
        else {
            if (flag == true)
                ul.style.display = "block";
            else
			{
                ul.style.display = "none";
				$("#cmsul" + objid).find("input").prop("checked",false);
			}
        }

    });


});
		function classinit1(){
			    var classid=0;
			    $.getJSON(cmsurl + "?data=?", function (json) {
			        cmsjson1 = json.info;
			        var status1 = json.status;
			        var selclass = 0;
			        if (status1 == 1) {
			            if (cmsjson1.length > 0) {
			                var nowarr = filterarr(cmsjson1, "parent_id", "0");
			                var divid = "cmscata_div";
			                if (nowarr.length > 0) {
			                    var depth0 = 0;
			                    if (depth0 > cmsdepth1)
			                        cmsdepth1 = depth0;
			                    // var ndiv = document.getElementById(divid); //create seldiv
			                    var hb = "";
			                    hb = hb + "<div class=\"scrollbox\"><ul class=\"cmsul" + depth0 + "\" id=\"cmsul" + depth0 + "\">";
			                    for (i = 0; i < nowarr.length; i++) {
			                        hb = hb + "<li class=\"li0\"><input type=\"checkbox\" name=\"cmssel1\" title=\"" + depth0 + "\" value=\"" + nowarr[i].id + "\" ><label for=\"checkbox\">" + nowarr[i].name + "</label></li>";
			                        //var hb2 = "";
			                        //  hb2 = Selectchange(nowarr[i].id, depth0);
			                        //console.log(hb2);
			                        // if (hb2 != "")
			                        //    hb = hb + "<li>" + hb2 + "</li>";

			                    } //for      

			                    hb = hb + "</ul></div>";
			                    hb = hb + "<div class=\"submit\"><input type=\"button\" value=\"确定\" id=\"cmscata_submit\" \/> </div>";
			                    $("#" + divid).html(hb);
			                }

			            }
			        }

			    });
	  }
	  function addclass() { 
      
      }
     function isArray(o) {
       return typeof o=='object'&&Object.prototype.toString.call(o).slice(8,-1).toLowerCase()=='array';
     }
     function searcharr(array,type,value) {
		  if(!isArray(array)) throw new Error('\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662f\u6570\u7ec4\u7c7b\u578b');
		  var arr=[];
		  arr=array.filter(function(a) { 
		   return a[type].indexOf(value)!=-1;
		  });
		  return arr;
	} 
	
	function filterarr(array,type,value) {
		  if(!isArray(array)) throw new Error('\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662f\u6570\u7ec4\u7c7b\u578b');
		  var arr=[];
		  arr=array.filter(function(a) { 
		    return a[type]==value;
		  });
		  return arr;
	}
	function Selectchange(selid, depth1) {
	    var hb3 = "";
	    if (selid != 0) {
	        var nowarr2 = filterarr(cmsjson1, "parent_id", selid);
	        if (nowarr2.length > 0) {
	            depth1 = depth1 + 1;
	            if (depth1 > cmsdepth1) {
	               cmsdepth1 = depth1;
	                $("#cmsdepth1").val(cmsdepth1);
	            }
	            hb3 = hb3 + "<ul class=\"cmsul" + depth1 + "\" id=\"cmsul" + selid + "\">";
	            for (j = 0;j < nowarr2.length; j++) {
	                hb3 = hb3 + "<li><input type=\"checkbox\" name=\"cmssel1\" title=\"" + depth1 + "\" value=\"" + nowarr2[j].id + "\" ><label for=\"checkbox\">" + nowarr2[j].name + "</label></li>";
	                //var hb4 = "";
                   //if (depth1<3)
	                 //   hb4 = Selectchange(nowarr2[j].id, depth1);
                   // if (hb4!="")
	               //     hb3 = hb3 + "<li>" + hb4 + "</li>";
                } //for
	            hb3 = hb3 + "</ul>";
	        }
	       
	    }	    
	    return hb3;
    }
   //create one option
    function opt(sel, txt, value, issel) {  
        var op = document.createElement("option");
        op.value = value;
        op.text = txt;
        if (issel==1)
            op.setAttribute("selected", "selected");
        sel.options.add(op);
    }
