﻿function InitLoad(swtich,id,divID)
      {
          $.ajax({
       
           url: "loadData/ReturnSelectData.aspx",
           data: "swithchid="+swtich+"&id="+id,
           cache:false,
           error:function(e){
           
           alert("操作频繁或服务器忙");
       },
        
       success: function(msg){
        
		  document.getElementById(divID).innerHTML+=msg;
	 
       }
     
       }); 
      
      }
      
      
      function onChangeCategory(swtich,id,divID)
      {
        
        $.ajax({
       
           url: "loadData/ReturnSelectData.aspx",
           data: "swithchid="+swtich+"&id="+id,
           cache:false,
           error:function(e){
        
           alert("操作频繁或服务器忙");
       },
        
       success: function(msg){
          
          propetytoend="true";
          if(id=="")
          {   
             selectLength = (id.length / 3-1);
             $("#"+divID+" #"+divID+"_"+"0").nextAll().remove();
           
             $("#hideValue_"+divID).attr("value",$("#"+divID+" #"+divID+"_"+"0").val());
          }
          
         else if(id!="")
          { 
             var selectLength = "0";
             if (id != "000")
             {
             
               selectLength = (id.length / 3-1);
               $("#"+divID+" #"+divID+"_"+selectLength).nextAll().remove();
               $("#propertydiv"+divID).remove();
      
             }
             if(msg.indexOf("propertydiv")==-1)
             { 
 

                 $("#"+divID).append(msg);
                 
                  $("#propetylay").hide();
                  $("#selectedPropety").html(propetyLayValue);
               //   $("[@id*=hideValue_propertyItem]").attr("value","");

              }
             
             else
             {  
//                $("#overLay").show();
//                $("#proudctItem_productItempanel select").hide();
//                $("#propetylay_content select").show(); 
//                document.getElementById("propetylay_content").innerHTML=msg;
//               
//                if($.cookie('araeToCompany_propety_restoreValue')!=null)
//                {  
//                    
//                   var restorepr=$.cookie('araeToCompany_propety_restoreValue').split('|');
//                    
//                   for(j=1;j<restorepr.length;j++)
//                   {   
//                    
//                        // $("#proudctItem_productItempanelProperty1").get(0).value ="101:1996";
//                      $("#proudctItem_productItempanelProperty"+j).get(0).value =restorepr[j-1];
//                       
//                   }
//                
//                }
//                
//                $("#propertydivproudctItem_productItempanel ul").eq(6).hide();
//               
//                $("#propertydivproudctItem_productItempanel ul").eq(7).hide();
//               
//                $("#proudctItem_productItempanelProperty4").get(0).value ="69:1202";
//                $("#proudctItem_productItempanelProperty4").attr("disabled","disabled")
//                $("#overLay").attr("left","130px");$("#overLay").attr("top","10px");
                
                 
                 
              //   document.getElementById("proudctItem_productItempanel").innerHTML=msg;
                  
                   $("#"+divID).html(msg);
                  if(swtich=="3")
                  {
                    $("#propertydivdataItem_dataItempanel ul").eq(0).hide();
                    $("#propertydivdataItem_dataItempanel ul").eq(1).hide();
                  }
//                   $("#propertydivproudctItem_productItempanel ul").eq(6).hide();
//               
//                $("#propertydivproudctItem_productItempanel ul").eq(7).hide();
              // $("#propertydivproudctItem_productItempanel ul").eq(3).hide();
//                $("#proudctItem_productItempanelProperty4").get(0).value ="69:1202";
//                $("#proudctItem_productItempanelProperty4").attr("disabled","disabled")
                
                
                
                StorePropertyValue();
                
             }
            
            $("#hideValue_"+divID).attr("value",$("#"+divID+" #"+divID+"_"+selectLength).val());
           
          }
       }
      
       
       }); 
      }
      
      
      var checkState="true"; 
      function onCheckSelectToEnd()
      {
         var propetyValue="";
//         var proudctItemValue=$("#proudctItem_productItempanel .proudctItem_productItempanel_:last").attr("value"); 
//         
//         if(proudctItemValue=="" || proudctItemValue==undefined)
//         {
//            checkState="false";
//            alert("产品必须选择到最后一级");
//            return false;
//         } 

        if(document.getElementById("propertydivproudctItem_productItempanel"))
        {
           $(".propertydiv select").each(function(){
             if($(this).val()!="")
             {
               propetyValue+=$(this).val().replace(":","-")+"|";
               $("[@id*=hideValue_propertyItem]").attr("value",propetyValue)  ;
             }
            
            });
            
            if($("[@id*=hideValue_propertyItem]").val()!="")
            {
              $("[@id*=hideValue_propertyItem]").attr("value","|"+$("[@id*=hideValue_propertyItem]").val());
            }
            
           // alert( $("[@id*=hideValue_propertyItem]").val())
        
        } 
         
        else
        {   
            checkState="true";
            return true;
        } 
      }
      
      //提交数据
      function  OnsumbitData()
      {  
         
         if(checkState=="false")
         {
           return false ;
         }
         else
         {
          
          return true;
         }
      
      }
      
 /////以下针对弹出层编写    
       var checkLayState;
       function CheckPropetyLay()
       {
        
          var propertyValue=$(".propertydiv .proudctItem_productItempanelProperty:last").attr("value");
           
          if(propertyValue=="")
          {
            checkLayState="false";
            alert("属性必须选择到最后一级")
            return false;
          }
          else
          {

              checkLayState="true";
              return true;
          }
        
       }
     
//////////////////////////////显示属性层///////////////////////////////////
      
      function showLay()
      {
//         $("#overLay").show();
//         $("#proudctItem_productItempanel select").hide();
//         $("#propetylay_content select").show(); 
      
      }     
      
     /* 关闭层*/
      function closeLay()
      {
        $("#overLay").hide();
        $("#proudctItem_productItempanel select").show();
      }
      
      function closeSet()
      {
        propetytoend="false";
      
      }
      
      var propetyLayValue;  var propetytoend;  var propetyLayText;  var restoreLayvalue;
      function PostParentPropety()
      {  var propetyText="";
        propetytoend="true"
        propetyLayValue="";
        propetyLayText="";
        restoreLayvalue="";
        $("[@id*=hideValue_propertyItem]").attr("value","")  ;
        onCheckSelectToEnd();
        $(".propertydiv select").each(function(){
        propetyText+=$(this).find("option:selected").text()+" | ";
        restoreLayvalue+=$(this).val()+"|"; 
        $.cookie('araeToCompany_propety_restoreValue',restoreLayvalue,{expires:7});//属性的还原的value
       
         if($(this).val()=="")
         {
//           alert("属性值要选择到最后一级");
//           propetytoend="false";
//           return false;
         }
         
        
      
         else if($(this).val()!="")
         { 

          if($(this).find("option:selected").text()!="")
          {
            propetyLayText+=$(this).find("option:selected").text()+" | ";
           
          }
         }
        });
        if( $("[@id*=hideValue_propertyItem]").attr("value")!="")
        {   
          
        }
        
        if(propetytoend=="true")
        {
          // $("#propetylay").show();
//           $("#selectedPropety").html(propetyLayText);
            var arrayText=new Array('厂家','材质','表面','板/卷','宽度规格(mm)','厚度规格(mm)','含税分类','长度规格(mm)');
            var showpropetytext_array=propetyText.split("|");
            var showpropetytext="";
            for(var i=0;i<showpropetytext_array.length-1;i++)
            {
              if(showpropetytext_array[i].indexOf("请选择")==-1)
              {  
                  showpropetytext+=arrayText[i]+":<font style='color:red;'>"+showpropetytext_array[i]+"</font> "; 
                 
              }
              else if(i==6)
              {
                   showpropetytext+=arrayText[i]+":<font style='color:red'>含税</font> "; 
              }
            }
              showpropetytext.replace("undefined:",""); 
              $("#selectedPropety").html(showpropetytext);
              $.cookie('araeToCompany_propety_text',showpropetytext,{expires:7});//属性的文字描述
           closeLay();
        }
       
       
      }
      
  
 var restorI={"6":0,"7":0,"4":0,"5":0};
 
 var requestid={"6":0,"7":0,"4":0,"5":0};
 
 
  function onChangeCategory1(swtich,id,divID,trueid)
      {
        //swtich="6";
       //alert(typeof(swtich)); 
        $.ajax({
       
           url: "../loadData/ReturnSelectData.aspx",
           data: "swithchid="+swtich+"&id="+id,
           cache:false,
           error:function(e){
           
           alert("操作频繁或服务器忙");
       },
        
       success: function(msg){
          
       $("#"+divID).append(msg);
          
         if(swtich=="6"){
            restorI["6"]=restorI["6"]+1;
            requestid["6"]=trueid.substring(0,(restorI["6"]+1)*3);
            
            $("#"+divID+"_"+restorI["6"]).get(0).value = requestid["6"];
            if(restorI["6"]>(trueid.length/3-2))
            {
            return false;
            }
            else
            {
              onChangeCategory1(swtich,requestid["6"],divID,trueid)
            }
         
         }
         else if(swtich=="7"){
            restorI["7"]=restorI["7"]+1;
             requestid["7"]=trueid.substring(0,(restorI["7"]+1)*3);
             
               $("#"+divID+"_"+restorI["7"]).get(0).value = requestid["7"];
            if(restorI["7"]>(trueid.length/3-2))
            {
            return false;
            }
            else
            {
             onChangeCategory1(swtich,requestid["7"],divID,trueid)
            }
         }
         else if(swtich=="4"){
            restorI["4"]=restorI["4"]+1;
             requestid["4"]=trueid.substring(0,(restorI["4"]+1)*3);
             
               $("#"+divID+"_"+restorI["4"]).get(0).value = requestid["4"];
            if(restorI["4"]>(trueid.length/3-2))
            {
            return false;
            }
            else
            {
             onChangeCategory1(swtich,requestid["4"],divID,trueid)
            }
         }
         else if(swtich=="5"){
            restorI["5"]=restorI["5"]+1;
             requestid["5"]=trueid.substring(0,(restorI["5"]+1)*3);
             
               $("#"+divID+"_"+restorI["5"]).get(0).value = requestid["5"];
            if(restorI["5"]>(trueid.length/3-2))
            {
            return false;
            }
            else
            {
             onChangeCategory1(swtich,requestid["5"],divID,trueid)
            }
         }
     
       }
        
       
       }); 
       
       jQuery("#"+divID+"_0").get(0).value =trueid.substring(0,3);
      }
 
 
   
 
      
 function  RestoreSelect(swtich,id,divID)
 {
 
    var  idlength="";
    if(id!="000")
    {  
       
       idlength=(id.length / 3);
   
       $.ajax({
       
           url: "../loadData/ReturnSelectData.aspx",
           data: "swithchid="+swtich+"&id=000",
           cache:false,
           error:function(e){
           
           alert("操作频繁或服务器忙");
       },
        
       success: function(msg){
         
		  document.getElementById(divID).innerHTML+=msg;
		  //  InitParm();
		  if(idlength==1)
          {
            jQuery("#"+divID+"_0").get(0).value =id;
          }
		  
		  else
          {
             var idsplit=id.substring(0,3);
             jQuery("#"+divID+"_0").get(0).value =id;
             onChangeCategory1(swtich,idsplit,divID,id);
             
         
          }
       }
      
       
       }); 


    }
 
 }     
 
 /*----重填-----*/
 function resumbit()
 {
     $(".propertydiv select").each(function(){
      $(this).get(0).value="";
     
     });
  
    $("#proudctItem_productItempanelProperty3").get(0).value ="69:1202";
 }     
      
      
      