// JavaScript Document
function get_wi(pre,tbProductName,tbWI,whe,k)
 {
	 $.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'get_wi',
					  		   client:pre,
							   tbProductName:tbProductName,
							   tbWI:tbWI
							  },
					  dataType:'json',
					  success: function(data)
					  {
							if(whe==""){
							$("#tbInspectLevel").val(data['tbInspectLevel']);
							$("#Critical").val(data['tbCritical']);
							$("#Major").val(data['tbMajor']);
							$("#Minor").val(data['tbMinor']);
							$("#tbTestPlan").val(data['tbTestPlan']);
							$("#tbKitBom").val(data['tbKitBom']);
							$("#tbPacking").val(data['tbPacking']);
							$("#tbStyle").val(data['tbStyle']);
							$("#Per").val(tbWI);
							$("#Plan").val(tbWI);
							$("#Kit").val(tbWI);
							}else if(whe=="Per"){
							$("#tbSpec_"+k).val('Per inspection general criteria and golden sample & production artwork');
							}else if(whe=="Plan"){
							$("#tbSpec_"+k).val(data['tbTestPlan']);
							}else if(whe=="Kit"){
							$("#tbSpec_"+k).val(data['tbKitBom']);
							}else if(whe=="Spec"){
							$("#tbSpec_"+k).val('Per factory spec.');
							}else if(whe=="AC"){
							$("#tbSpec_"+k).val('V:100-240V, Freq:50/60HZ');
							}else if(whe=="Hi"){
							$("#tbSpec_"+k).val('3000V AC, 5mA, 2S');
							}else if(whe=="Run"){
							$("#tbSpec_"+k).val('On rated voltage at least 2 hours');
							}else if(whe=="BT"){
							$("#tbSpec_"+k).val('Per factory spec:10M');
							}else if(whe=="Rub"){
							$("#tbSpec_"+k).val('Rub 15s with cotton with 75% alcohol');
							}
					   }
			 });  		 
 }
 
 function get_topic()
 {
	 $.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'get_topic',
					  		   tbCategory:$("#tbCategory :selected").val()
					  		  },
					  dataType:'json',
					  success: function(data)
					  {
addOptions("#tbTopical",data,"tbDescript","tbTopical",0);
					  }
				   }); 
 }
 
 function get_defect()
 {
	$("#tbDefection").val($("#tbTopical :selected").val());
 }
 
 function save_defect(pre,rep)
 {
	if(rep!="")
	{	
		$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'save_defect',
					  		   tbFN:$("#tbFN").val(),
							   rep:rep,
							   client:pre,
					  		   tbCategory:$("#tbCategory").val(),
					  		   tbTopical:$("#tbTopical :selected").text(),
					  		   tbDefection:$("#tbDefection").val(),
					  		   tbSerial_NO:$("#tbSerial_NO").val(),
					  		   tbCritical:$("#tbCritical").val(),
					  		   tbMajor:$("#tbMajor").val(),
					  		   tbMinor:$("#tbMinor").val()
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#show_defects").html(data);//非累加条目
							cleanitem("#tbCategory","#tbTopical","#tbDefection","#tbSerial_NO","#tbCritical","#tbMajor","#tbMinor");
							disable("#tbCategory","#tbTopical","#tbDefection","#tbSerial_NO","#tbCritical","#tbMajor","#tbMinor");
					   }
			 	  });  	
	}
	else
	{
	alert("Report Numbers Is Empty,Error!" );
	}
 }
 
 function adddefect()
 {
	enable("#tbCategory","#tbTopical","#tbDefection","#tbSerial_NO","#tbCritical","#tbMajor","#tbMinor");
	cleanitem("#tbFN");
 }
 
 function deldefect(pre,id,rep)
 {
	$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'del_defect',
					  		   id:id,
							   client:pre,
							   rep:rep
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#show_defects").html(data);
					   }
			 });  	
 }
 
 function editdefect(pre,id,rep)
 {
	
		enable("#tbCategory","#tbTopical","#tbDefection","#tbSerial_NO","#tbCritical","#tbMajor","#tbMinor");
	$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'getdefect',
							   id:id,
							   client:pre,
							   rep:rep
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#tbFN").val(data['tbFN']);
							$("#tbCategory").append("<option value='" + data['tbCategory'] + "' selected='selected'>" + data['tbCategory'] + "</option>"); 
							$("#tbTopical").append("<option value='" + data['tbTopical'] + "' selected='selected'>" + data['tbTopical'] + "</option>"); 
							$("#tbDefection").val(data['tbDefection']);
							$("#tbSerial_NO").val(data['tbSerial_NO']);
							$("#tbCritical").val(data['tbCritical']);
							$("#tbMajor").val(data['tbMajor']);
							$("#tbMinor").val(data['tbMinor']);
					   }
			 	  });  	
 }
 
 function save_point(pre,rep,k)
 {
	var ids='';
	if(k==0){ 
		ids=$("#tbTestedID_"+k).val();
	}
	else{
		ids=$("#tbTestedID_"+k+" :selected").val();
	}
	
	if(rep!="")
	{	
		$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'save_point',
							   rep:rep,
							   client:pre,
					  		   tbTestedID:ids,
							   tbPosition:k,
					  		   tbQty:$("#tbQty_"+k).val(),
					  		   tbTestResult:$("#tbTestResult_"+k+" :selected").val(),
					  		   tbSpec:$("#tbSpec_"+k).val(),
							   tbTN:$("#tbTN_"+k).val()
							  },
					  dataType:'json',
					  success: function(data)
					  {
						$("#show_points").html(data);//非累加条目
cleanitem("#tbTN_"+k);				
disable("#save_"+k);
$(function(){
		$("#save_"+k).css('background','red');

	});
					   }
			 	  });  	
	}
	else
	{
	alert("Report Numbers Is Empty,Error!" );
	}
 }
 
 function editpoint(pre,id,rep,k)
 {
	enable("#save_"+k);
	$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'getpoint',
							   id:id,
							   client:pre,
							   rep:rep
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#tbTN_"+k).val(data['tbTN']);
							$("#tbTestedID_"+k).append("<option value='" + data['tbTestedID'] + "' selected='selected'>" + data['tbCheckPoint'] + "</option>"); 
							$("#tbQty_"+k).val(data['tbQty']);
							$("#tbTestResult_"+k).append("<option value='" + data['tbResult'] + "' selected='selected'>" + data['tbResult'] + "</option>"); 
							$("#tbSpec_"+k).val(data['tbSpec']);
					   }
			 	  });  	
 }
 
 function delpoint(pre,id,rep)
 {
	$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'del_point',
					  		   id:id,
							   client:pre,
							   rep:rep
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#show_points").html(data);
					   }
			 });  	
 }
 
 function add_serial(pre)
 {
	  if(add_form.tbReportNumber.value==""){
		 alert("Report Number Is Empty,Please Contact Admin!");
		 add_form.serial_add.focus();
	  }else if(add_form.serial_add.value==""){
		 alert("Serial Number Must Be Filled!");
		 add_form.serial_add.focus();
	  }else if(add_form.count.value==""){
		 alert("Count Must Be Filled!");
		 add_form.count.focus();
	  }else{
		var rep = $("#tbReportNumber").val();
		var tbSerial = $("#serial_add").val();
		var count = $("#count").val();		
		$.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'add_serial',
							   rep:rep,
							   client:pre,
							   tbSerial:tbSerial,
							   count:count
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#show_serial").append(data);
					   }
			 	 });  			
		//alert(tbReportNumber+","+tbSerial+","+count);
		add_form.serial_add.focus();
	  }	 
	  return false;
 }
 
 function delserial(pre,id,rep)
 {
	 $.ajax({ url: 'report_create.php',
					  type: 'post',
					  data:{act:'del_serial',
					   		   client:pre,
							   id:id,
							   rep:rep
							  },
					  dataType:'json',
					  success: function(data)
					  {
							$("#show_serials").html(data);
					   }
			 });  			
 }