<script type="text/javascript">

 function isNumberKey(txt, evt) {

    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode == 46) {
        //Check if the text already contains the . character
        if (txt.value.indexOf('.') === -1) {
            return true;
        } else {
            return false;
        }
    } else {
        if (charCode > 31
             && (charCode < 48 || charCode > 57))
            return false;
    }
    return true;
}

</SCRIPT>

	<script>
		jQuery(document).ready(function() {			
			jQuery('#product_category').change(function() {
				var IDVal;
				var NMVal;
				var selection = jQuery('#product_category').val(); 
				jQuery('#product_sub_category').html('');   
				jQuery('#product_sub_category').append('<option value="">- select (pilih) -</option>');
				
				if (selection == '19') {
					$('#product_sub_category').hide();
					$('#product_category_other').show();
					$('#product_sub_category_other').show();
				} else {
					$('#product_sub_category').show();
					$('#product_category_other').hide();
					$('#product_sub_category_other').hide();
				}
				
				jQuery.post(
				  'listValue.php',{
					  'product_category':jQuery('#product_category').val()
				  }, function(data, textStatus) {
					 jQuery.each(data, function(index, value) {
						//alert (value);
						if (value == "Others, please specify (Lainnya, masukkan disini)") {
							IDVal = index;
							NMVal = value;
						} else {
							jQuery('#product_sub_category').append('<option value="' + index + '">' + value + '</option>');
						}
				  });
				  if (IDVal != '') {
					  jQuery('#product_sub_category').append('<option value="' + IDVal + '">' + NMVal + '</option>');
				  }
				},'json');
				//jQuery('#product_sub_category').append('<option value="' + IDVal + '">' + NMVal + '</option>');
			});
		
			jQuery('#product_sub_category').change(function() {
				<?php 
				$arrSubCategory = '';
				$sql = 
				"SELECT valueID, valueName FROM form_element_value WHERE valueName = 'Others, please specify (Lainnya, masukkan disini)' "; 
				if ($hasil = mysqli_query($conn, $sql)) {
					if (mysqli_num_rows($hasil)) {
						while ($data = mysqli_fetch_array($hasil)) {
							if ($arrSubCategory == '') {
								$arrSubCategory = "var arrSubCategory = [";
							} else {
								$arrSubCategory .= ", ";
							}
							$arrSubCategory .= "'".$data["valueID"]."'";
						}
						$arrSubCategory .= "];";
					}
					echo $arrSubCategory;
				}
				?>
				//var arrSubCategory = ['529', '536', '551', '560', '651', '570', '578', '591', '756'];
				
				var selection_sub = jQuery('#product_sub_category').val(); 
				if (jQuery.inArray( selection_sub, arrSubCategory ) != -1 ) {
					$('#product_sub_category_other').show();
				} else {
					$('#product_sub_category_other').hide();	
				}
			});	
			
			jQuery('#product_available_measure').change(function() {
				var selection_Extention = jQuery('#product_available_measure').val(); 
				if (selection_Extention == '743') {
					$('#product_available_measure_other').show();
				} else {
					$('#product_available_measure_other').hide();	
				}
			});		
			

			jQuery('#supply_ability_measure').change(function() {
				var selection_Extention = jQuery('#supply_ability_measure').val(); 
				if (selection_Extention == '743') {
					$('#supply_ability_measure_other').show();
				} else {
					$('#supply_ability_measure_other').hide();	
				}
			});		
			
			$('#addFile').click(function() {
				// when the add file button is clicked append
				// a new <input type="file" name="someName" />
				// to a filesContainer div
				$('#filesContainer').append (
					$('<input>').attr('type','file').attr('name','productImage[]')
				);
				jQuery('#filesContainer').append('<div style="margin-bottom:7px"></div>');
			});			
			
			
		});
    </script>        

	<?php
	function select2 ($tableName, $orderName ) {
		global $conn;
		$select = '';
		$sql8 = "select * from $tableName order by $orderName asc";
		//echo "<br>sql8: ".$sql8;
		if ($hasil8 = mysqli_query($conn, $sql8)) {
			if (mysqli_num_rows($hasil8) > 0) {
				$select = '
				<select name="'.$orderName.'" id="'.$orderName.'" style="height:25px;">
					<option value = "">- select (pilih) -</option>';
					while ($data8 = mysqli_fetch_array($hasil8)) {
						$select .= '
						<option value = "'.$data8["exhibitorID"].'">'.$data8["companyName"].'</option>';
					}
				$select .= '
				</select>';
			}
		}
		return $select; 
	}

	function select ($parentID, $id, $id_extention, $tableName1, $tableName2, $linkTo, $linkFrom, $keySearch1, $keySearch2 ) {
		global $product_category, $product_sub_category, $product_available_measure, $supply_ability_measure;
		global $conn; $selectOther = '';
		$sql8 = "select * from $tableName1, $tableName2 
				 where $linkTo = $linkFrom AND $keySearch1 = '$parentID' 
				 AND $keySearch2 = '$id' order by designORDER asc";
		//echo "<br>".$sql8;
		$select = '';
		if ($hasil8 = mysqli_query($conn, $sql8)) {
			if (mysqli_num_rows($hasil8) > 0) {
				while ($data8 = mysqli_fetch_array($hasil8)) {
					if (!$select) {
						$select = '
						<select name="'.$data8["designName"].'" id="'.$data8["designName"].'" style="height:25px;">
							<option value = "">- select (pilih) -</option>';
					
					}
					//echo $tableName1; 
					if ($tableName1 == "form_design") {
						$designID = $data8["designID"];					
					} else {
						$designID = $id_extention;
					}
					$sql88 = "select * from form_element, form_element_link, form_element_sub 
							  where elementID='".$data8["element"]."' and elementShow='1' 
							  and linkDesignID='".$designID."' 
							  and linkElementSubID=elementSubID order by elementSubName";
					//echo "<br>".$sql88;
					if ($hasil88 = mysqli_query($conn, $sql88)) {
						if (mysqli_num_rows($hasil88) == 1) {
							while ($data88 = mysqli_fetch_array($hasil88)) {
								$sql888 = "select * from form_element_value where 
										   elementSubParentID = '".$data88["elementSubID"]."' order by valueName";
								//echo $sql888;
								if ($hasil888 = mysqli_query($conn, $sql888)) {
									
									while ($data888 = mysqli_fetch_array($hasil888)) {
										//echo "<br>valueName : ".$data888["valueName"];
										if ($data888["valueName"] == "Other") {
											$selectOther = '
											<option value = "'.$data888["valueID"].'">'.$data888["valueName"].'</option>';
										} else {
											$selected = '';
											if ($product_sub_category == $data888["valueID"])
												$selected = "selected";
											$select .= '<option '.$selected.' value = "'.$data888["valueID"].'">
															'.$data888["valueName"].'
														</option>';
										}
									}
								}
							}
						} else if (mysqli_num_rows($hasil88) > 1) {
							$selectOther = '';
							while ($data88 = mysqli_fetch_array($hasil88)) {
								if ($data88["elementSubName"] == "others") {
									$selectOther = '
									<option value = "'.$data88["elementSubID"].'">'
										.$data88["elementSubDescription"].
									'</option>';
								} else {
									$selected = '';
									if (${$data8["designName"]} == $data88["elementSubID"])
										$selected = "selected";
									$select .= '
									<option '.$selected.' value = "'.$data88["elementSubID"].'">'
										.$data88["elementSubDescription"].
									'</option>';
								}
								
								//if ($$data88["designName"] == $data888["elementSubID"]) $select .= ' selected ';
							}
						} else {
							echo "row : ".mysqli_num_rows($hasil88);
							$sql888 = "select * from form_element_value where valueID = '".${$data8["designName"]}."'";
							//echo $sql888;
								if ($hasil888 = mysqli_query($conn, $sql888)) {
								while ($data888 = mysqli_fetch_array($hasil888)) {
									$sql8888 = "select * from form_element_value where elementSubParentID = '".$data888["elementSubParentID"]."'";
									if ($hasil8888 = mysqli_query($conn, $sql8888)) {
										while ($data8888 = mysqli_fetch_array($hasil8888)) {
											$selected = '';
											if ($$data8["designName"] == $data8888["valueID"])
												$selected = "selected";
											$select .= '
											<option '.$selected.' value = "'.$data8888["valueID"].'">'
												.$data8888["valueName"].
											'</option>';
											
										}
									}
								}
							}
						}
					}
				}
				$select = $select.'
				</select>';
			}
		}
		return $select; 
	}


	function text ($parentID, $id, $id_extention, $tableName1, $tableName2, $linkTo, $linkFrom, $keySearch1, $keySearch2) {
		global $conn, $product_name, $brandName, $product_available, $supply_ability;
		$sql8 = "select * from $tableName1, $tableName2 
				 where $linkTo = $linkFrom AND $keySearch1 = '$parentID' 
				 AND $keySearch2 = '$id' order by designORDER asc";
		//echo "<br>".$sql8;
		if ($hasil8 = mysqli_query($conn, $sql8)) {
			while ($data8 = mysqli_fetch_array($hasil8)) {
				global ${$data8["designName"]};
				if ($data8["tipe_input"] == 2) {
					$text = '
					<span>$</span> 
					<input type="text" onkeypress="return isNumberKey(this, event);" ';
				}
				else {
					$text = '
					<input type="text" ';
				}
				
				$text .= 'name="'.$data8["designName"].'" id="'.$data8["designName"].'" size="'.$data8["size"].'" value="'.${$data8["designName"]}.'" style="height:25px;">';
			}
		}
		return $text; 
	}
	
	function textarea ($parentID, $id, $id_extention, $tableName1, $tableName2, $linkTo, $linkFrom, $keySearch1, $keySearch2) {
		global $products_detil, $notes, $conn;
		$sql8 = "select * from $tableName1, $tableName2 
				 where $linkTo = $linkFrom AND $keySearch1 = '$parentID' 
				 AND $keySearch2 = '$id' order by designORDER asc";
		//echo $sql8;
		if ($hasil8 = mysqli_query($conn, $sql8)) {
			while ($data8 = mysqli_fetch_array($hasil8)) {
				global ${$data8["designName"]};
				$textarea = '<textarea cols="'.$data8["cols"].'" rows="'.$data8["row"].'" style="font-size:15px" name="'.$data8["designName"].'" id="'.$data8["designName"].'">'.(${$data8["designName"]} ? ${$data8["designName"]} : '').'</textarea>';
			}
		}
		return $textarea; 
	}
	
	function hidden () {
	}
	
	function radio () {
	}
	
	function checkbox () {
	}

	function others ($id) {
		/**
		global $conn;
		$sql8 = "select * from form_design_other where labelParentID = '$id' order by designORDER asc";		
		echo $sql8;		
		$others = '';
		if ($hasil8 = mysqli_query($conn, $sql8)) {
			while ($data8 = mysqli_fetch_array($hasil8)) {
				$others  = '
				<div id="'.$data8["designName"].'" style="padding-top:5px; display:none;">
					<input type="text" placeholder="'.$data8["labelName"].'" name="'.$data8["designName"].'" size="'.$data8["size"].'" value="'.${$data8["designName"]}.'" style="height:25px;">	
				</div>';
			}
		}
		return $others; */
	}

	function extention ($id) {
		global $conn;
		$sql8 = "select b.designID, b.labelParentID from form_design as a, form_design_extention as b 
				 where b.labelParentID = '$id' and a.designID = '$id' AND 
				 a.designID = b.labelParentID order by b.designORDER asc";
		//echo "<br>".$sql8;
		if ($hasil8 = mysqli_query($conn, $sql8)) {
			while ($data8 = mysqli_fetch_array($hasil8)) {
				$extention = select($data8["labelParentID"], $data8["designID"], $data8["labelParentID"], "form_design_extention", "form_element", "elementID", "element", "labelParentID", "designID");
			}
		}
		return $extention; 
	}
	?>
    
