	<script type="text/javascript" src="js/messages.js"></script>
	<link rel="stylesheet" type="text/css" href="css/messages.css" />
	<link href="css/captcha.css" rel="stylesheet" type="text/css">
	<script>
		$(document).ready(function() { 
		
		 // refresh captcha
		 $('img#captcha-refresh').click(function() {  
				
				change_captcha();
		 });
		 
		 function change_captcha()
		 {
			document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
		 }
		 
		});
	</script>		 

	<?php

	$text_ .= '	<div id="spasi1a"></div>';
	$text_ .= '	<div class="titleb">'.$data["namaSubMenus"].'</div>';
	$text_ .= '	<div id="spasi1c"></div>';
	echo $text_;

	$idEvent = "Exhibitor";
	echo "<script>";
		echo "function validate(form) {";	
		$sql = "select designName from form_label, form_design where labelType='".$idEvent."' and labelID=labelParentID and validasi='YES' order by designID asc";
		if ($hasil = mysql_query($sql)) {
			while ($rec = mysql_fetch_array($hasil)) {
				if ($rec["designName"] != "website") {
					echo "var ".$rec["designName"]." = form.".$rec["designName"].".value;";
					echo "
					  if(".$rec["designName"]." == '') {
						inlineMsg('".$rec["designName"]."','Field can not be empty.',2);
						return false;
					  }
					";	
				}
			}
		}	
		echo "
				return true;
			}
		";

	echo "</script>";
	
	
	
	$action = $_POST["action"];
	$captchacode=$_REQUEST["captchacode"];
	//echo "captchacode : ".$captchacode;
	//echo "<br>Random Number : ".$_SESSION['random_number'];
	$ctr = 0;
	if ($action=="Submit") {		
		$nama = $_POST["nama"];
		$email = $_POST["email"];
		$negara = $_POST["negara"];
		
		$query = 
		" select * from form_exhibitor ".
		" where LOWER(nama)=LOWER('$nama') ".
		" and LOWER(email)=LOWER('$email') ";
		//echo "query : ".$query;
		$total = mysql_num_rows(mysql_query($query));
		//echo "<br>Total : ".$total;
		if ($total>0) {
			// Sudah ada 
			echo "<script>";
			echo "location.href = '?menu=$menu&id=$id&res=3'";
			echo "</script>";
		} else {
			// Insert Data
			$digits = 3;
			$kode = str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT);

			$sql = 
			" select labelType, labelName, designName ".
			" from form_label, form_design ".
			" where labelType='".$idEvent."' ".
			" and labelID=labelParentID ".
			" order by designID asc";
			if ($hasil = mysql_query($sql)) {
				while ($rec = mysql_fetch_array($hasil)) {
					// echo "test";
					if ($ctr == 0) {
						$sql2 = "insert into form_exhibitor values(null";
						$body = "Dear All, ";
						$body = $body."\n\nBerikut Informasi ".$rec["labelType"]." yang Daftar Online \n";
					}
					$sql2 = $sql2.", "; 
					$ctr++;
					$designName = $rec["designName"];
					$labelName = $rec["labelName"];				
					$$designName = $_POST[$designName];
					//echo "<br>Race Type 2 : ".$race_type;
					//echo "<br>Design Name : ".$designName;
					if ($designName=="negara") {
						//$elementSubStat = $_REQUEST["elementSubStat"];
						//echo "<br>elementSubStat : ".$elementSubStat;
						$sql5 = "select * from form_element_link as a, form_design as b, form_element_sub as c where c.elementSubID=a.linkElementSubID and a.linkDesignID=b.designID and designName='".$designName."'";
						//echo $sql5;
						if ($hasil5 = mysql_query($sql5)) {
							while ($rec5 = mysql_fetch_array($hasil5)) {
								//echo $rec5["elementSubStat"];
								if ($rec5["elementSubStat"] == "single") {
									$sql4 = "select * from form_element_value where valueID='".$$designName."'";
									//echo $sql4;
									if ($hasil4 = mysql_query($sql4)) {
										while ($rec4 = mysql_fetch_array($hasil4)) {
											$body = $body."\n\n".$labelName." : ".$rec4["valueName"];
										}
									}
								} else if ($rec5["elementSubStat"] == "multiple") {
									$sql4 = "select * from $designName where id='".$$designName."'";
									//echo $sql4;
									if ($hasil4 = mysql_query($sql4)) {
										while ($rec4 = mysql_fetch_array($hasil4)) {
											$body = $body."\n\n".$labelName." : ".$rec4[1];
											if ($designName=="race_type") {
												$race_type = $rec4[0];
												$fee = $rec4[4];
												//echo "<br>Race Type 333 : ".$race_type;
											}
										}
									}
								}	
							}
						}
						//echo "<br>Race Type 3 : ".$race_type;
						//$sql2 = $sql2."'".$$designName."'";
					} else {
						$body = $body."\n\n".$labelName." : ".$$designName;
					}
					$sql2 = $sql2."'".$$designName."'";
					//echo 'Test : '.$designName.": ".$$designName."<br>";
				}
	
				if ($ctr > 0) {
					$sql2 .= ")";
					$body = $body."\n\nRegards,";
					$body = $body."\nAutomatic Email Sending Program";	
					//echo "<br>Sql : ".$sql2."<br>";
					//echo "Body : ".$body."<br>";
					
					if ($hasil2 = mysql_query($sql2)) {
						$_SESSION["nama"] = $nama;
						$_SESSION["email"] = $email;
						
						$untuk = $email;
						if (mail ($untuk, "INDO AGRITECH 2016: Online Exhibitor Registration", $body, "From:INDO AGRITECH  <registrasi@indoagritech.com>")) {
							$body1 = "Dear ".$nama." 
									\n\nThank You.
									\n\nYou have recently registered at INDO AGRITECH  Expo & Forum 2016.
									\n\nOur officer will confirm your registration status as soon as posible 
									\n\nSincerely,\nINDO AGRIRECH Expo & Forum";
							//echo "Body : ".$body;
							mail ($email, 'INDO AGRITECH Registration Confirmation', $body1, 'INDO AGRITECH  <registrasi@indoagritech.com>');
						}
						
						echo "<script>";
						echo "location.href = '?menu=$menu&id=$id&res=1'";
						echo "</script>";
					} else {
						echo "<script>";
						echo "location.href = '?menu=$menu&id=$id&res=2'";
						echo "</script>";
					}
				}
			}	
			// Insert rec End
		}
	}
	?>	
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr valign="top">
			<td>
				<?php
				$res = $_REQUEST["res"];
				if ($res) {
					echo '<div>';
							if ($res==1) {
								echo "<div class='title3' style='color:#cc3333; padding:0; margin:0'>Registration Confirmation</div>";
								echo "<div style='height:220px;' id='spasi1c'>";
								echo "	<strong>Terima Kasih</strong> <br>
										Data Anda sudah kami terima. <br>
										Team sales kami akan menghubungi Anda segera.
										<div id='spasi1b'></div>
										<strong>Thank You</strong> <br>
										Your registration rec has been submitted. <br>
										Our sales team will contact you for furher information
										";
								echo "</div>";
							} else if ($res == 2) {
								echo "<div class='title3' style='color:#cc3333; padding:0; margin:0'>Registration Confirmation</div>";
								echo "<div style='height:220px;' id='spasi1c'>";
								echo "	<strong>Mohon Maaf</strong> <br>
										Data Anda Gagal Teregistrasi. <br>
										Silahkan Coba Lagi atau Hubungi Kami Lewat Menu Kontak.
										<div id='spasi1b'></div>
										<strong>We are sorry</strong> <br>
										Your request has not been submitted. <br>
										Please try again or contact our sales team
										";
								echo "</div>";
							} else if ($res == 3) {
								echo "<div class='title3' style='color:#cc3333; padding:0; margin:0'>Registration Confirmation</div>";
								echo "<div style='height:220px;' id='spasi1c'>";
								echo "	
									Data Anda Sudah Terdaftar. <br>
									<div id='spasi1b'></div>
									You Have Already Registered. <br>
									";
								echo "</div>";
							}
					echo '</div>';
				} else {
					?>	
					<div class="box" style="font-size:14px; line-height:18px; ">
						<form name="form" id="form" class="form" action="?menu=<?php echo $menu; ?>&id=<?php echo $id; ?>" onsubmit="return validate(this)" method="post">
							<?php
							$sql = "select * from form_label where labelType='$idEvent'";
							if ($hasil = mysql_query($sql)) {		
								while ($rec = mysql_fetch_array($hasil)) {
									echo "<h2>".$rec["labelNameTitle"]."</h2>";
									echo "<div id='spasi1a'></div>";
									$sql2 = "select * from form_design, form_element where elementID = element AND labelParentID = ".$rec["labelID"]." order by designID asc";
									// echo $sql2;
									if ($hasil2 = mysql_query($sql2)) {
										echo '<div id="spasi1"></div>';
										echo '<table width="100%" cellpadding="21" cellspacing="1" border="0" bgcolor="#999999">';
										while ($rec2 = mysql_fetch_array($hasil2)) {
											// Link ke Element
											$sql4 = "select * from form_element, form_element_link, form_element_sub where elementID='".$rec2["element"]."' 
													 and elementShow='1' and linkDesignID='".$rec2["designID"]."' and linkElementSubID=elementSubID";
											// echo $sql4;
											if($hasil4 = mysql_query($sql4)) {
												while ($rec4 = mysql_fetch_array($hasil4)) {
													$elementSubID = $rec4["elementSubID"];
													$elementSubName = $rec4["elementSubName"];
													$elementSubStat = $rec4["elementSubStat"];
													$elementName = $rec4["elementName"];
												}
											}
											// Link ke Element
											//echo $elementSubStat;
											if ($rec2["elementName"] != "hidden") {
												//echo "$designName : ".$$designName;
												echo '<tr valign="top" bgcolor="#eaecfb">';
												echo '	<td width="28%" align="right"><strong>'.$rec2["labelName"].'<br>(<i>'.$rec2["labelNameEng"].'</i>)</strong></td>';
												echo '	<td>';
														$inputName = $rec2["designName"];
														if ($elementName == "checkbox") $inputName .= "[]";
		
														if($rec2["elementShow"] == "1") {
															if($elementSubStat == "single") {
																if ($elementName == "select") {
																	$opsi = '';
																	$sql3="select * from form_element_value where elementSubParentID=".$elementSubID." order by valueID ";
																	// echo $sql3;
																	if($hasil3 = mysql_query($sql3)) {
																		while ($rec3 = mysql_fetch_array($hasil3)) {
																			if ($opsi == '') {
																				$opsi  = '<select name="'.$inputName.'" id="'.$inputName.'">';
																				$opsi .= "	<option value = ''>- select -</option>";
																			}
																			$opsi .= '<option ';
																			//echo "<br>".$$designName;
																			if ($$rec2["designName"]==$rec3["valueID"]) $opsi .= ' selected ';
																			$opsi .= 'value = "'.$rec3["valueID"].'">'.$rec3["valueName"].'</option>';
																		}
																		if ($opsi != '') {
																			$opsi .= '</select>';
																			echo $opsi;
																		}
																	}
																} else {
																	$opsi = '';
																	$sql3="select * from form_element_value where elementSubParentID=".$elementSubID." order by valueID ";
																	// echo $sql3;
																	if($hasil3 = mysql_query($sql3)) {
																		while ($rec3 = mysql_fetch_array($hasil3)) {
																			if ($opsi == '') {
																				$opsi = '<table celpadding="7" celspacing="0" border="0"> 
																							<tr>';
																			}
																			$opsi .= '<td><input ';
																			if ($$rec2["designName"]==$rec3["valueID"]) $opsi .= ' checked ';
																			$opsi.=' type="'.$elementName.'" name="'.$inputName.'" id="'.$inputName.'" value = "'.$rec3["valueID"].'"></td>';
																			
																			$opsi .= '<td>'.$rec3["valueName"].'</td>';
																			$opsi .= '<td width="14"></td>';
																		}
																		if ($opsi != '') {
																			$opsi .= '		</tr>
																						</table>';
																			echo $opsi;
																		}
																	}
																}
															} else if($elementSubStat == "multiple") {
																//echo "Element Name : ".$elementName;
																
																if ($elementName == "select") {
																	//echo "test";
																} else {
																	$sql3="select * from $elementSubName ";
																	//echo $sql3;
																	if ($hasil3 = mysql_query($sql3)) {
																		$tabelContent = '';
																		$rows_count = mysql_num_rows($hasil3);							
																		// echo '<br>Nomor : '.$rows_count;
																		for($i=0; $i<$rows_count; $i++) {
																			$rec3 = mysql_fetch_row($hasil3);
																			if ($i==0) {
																				$tabelContent = '
																				<table width="100%" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
																					<tr bgcolor="#FFFFCC">
																						<td></td>
																				';
																			} else {
																				$inputType = '<input ';
																				if ($$rec2["designName"]==$rec3[0]) $inputType .= ' checked ';
																				$inputType .= ' type="'.$elementName.'" name="'.$inputName.'" value="'.$rec3[0].'">';
																				
																				$tabelContent .= '
																					<tr bgcolor="#f8f3d3">
																						<td align="center">'.$inputType.'</td>
																				';
																			}
																			for($r=0;$r<count($rec3)-1;$r++) {
																				if ($r==0) {
																					$tabelContent .= '
																					<td	align="center">';
																					if ($i==0) 
																						$tabelContent .= '	
																							<strong>ID</strong></td>';
																					else {
																						$tabelContent .= '	
																							<strong>'.$i.'</strong></td>';
																					}
																				} else {
																					//echo $rec3[$r];
																					$tabelContent .= '
																					<td>';
																					if ($i==0) 
																					$tabelContent .= '
																						<strong>';
																					$tabelContent .= 
																							$rec3[$r];
																					if ($i==0) 
																					$tabelContent .= '
																						</strong>';
																					$tabelContent .= '
																					</td>';
																				}
																			}
																			$tabelContent .= '</tr>';
																		}
																		if ($tabelContent != '') {
																			$tabelContent .= '
																				</table>';
																			echo $tabelContent;
																		}	
																	}
																}
															}
														} else if($rec2["elementShow"] == "2") {
															$sql5 = "select * from form_element where elementID='".$rec2["element"]."' 
																	 and elementShow='2' ";
															//echo $sql4;
															if($hasil5 = mysql_query($sql5)) {
																while ($rec5 = mysql_fetch_array($hasil5)) {
																	$elementName = $rec5["elementName"];
																}
															}	
		
															//echo "<br> elementName : ".$elementName."<br>"; 
															if ($elementName == "textarea")	{
																echo '<textarea name="'.$rec2["designName"].'" id="'.$rec2["designName"].'" cols="'.$rec2["cols"].'" rows="'.$rec2["row"].'">'.$$rec2["designName"].'</textarea>';
															} else {
																echo '<input class="decodeIt" type="'.$rec2["elementName"].'" name="'.$rec2["designName"].'" id="'.$rec2["designName"].'" size="'.$rec2["size"].'" value="'.$$rec2["designName"].'">';
															}
														}
												echo '	</td>';
												echo '</tr>';
											}
										}
										echo '</table>';
									}
								}
							}									
							?>
							<div id="spasi1a"></div>
							<table width="100%" cellpadding="15" cellspacing="1" border="0" bgcolor="#999999">				<tr>
								<tr bgcolor="#1c75bc">
									<td align="center">
										<input type="hidden" name="ktsandi" id="ktsandi" value="<?php echo $_SESSION['random_number']?>">
										<input type="hidden" name="elementSubStat" id="elementSubStat" value="<?php echo $elementSubStat; ?>">
										<input type="submit" name="action" id="action" class="button" value="Submit">								
									</td>
								</tr>
							</table>
						</form>
					</div>
					<?php
				}
				?>
			</td>
		</tr>
	</table>
