	<?php 
		include('header.php');
		include('config.php');
	?>
	<div class="InnerContainer" >            
        <h2>Add New Lender</h2>
        <div class="Border"></div>
		<form name="add_form" id="add_form" method="post" onsubmit="return ValidateForm()">
			<table align="center" cellpadding="5" cellspacing="0" border="0" width="40%" class="ListContent MediumSize" style="text-align:center;">
				<tr>    
                    <th colspan="2" align="left">Add New Lender</th>                          
                </tr>
				<tr>
					<td align="right">Lender's Name:</td>
					<td align="left"><input type="text" name="name" id="name" value="<?php echo $row['lender_name']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Upfront Commission:</td>
					<td align="left"><input type="text" name="front" id="front" value="<?php echo $row['front']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 1:</td>
					<td align="left"><input type="text" name="trail1" id="trail1" value="<?php echo $row['trail1']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 2:</td>
					<td align="left"><input type="text" name="trail2" id="trail2" value="<?php echo $row['trail2']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 3:</td>
					<td align="left"><input type="text" name="trail3" id="trail3" value="<?php echo $row['trail3']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 4:</td>
					<td align="left"><input type="text" name="trail4" id="trail4" value="<?php echo $row['trail4']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 5 onwards:</td>
					<td align="left"><input type="text" name="trail5" id="trail5" value="<?php echo $row['trail5']; ?>" /></td>
				</tr>
				<tr>
					<td colspan="2" style="text-align:center;"><input class="Submit" type="submit" name="submit" value="Save" />&nbsp;&nbsp; <a href="lenders.php"><input class="Cancel" type="button" name="cancel" value="cancel" /></a></td>
				</tr>
			</table>
		</form>
	</div>
		<script  type="text/javascript">
			 var frmvalidator = new Validator("add_form");
			 frmvalidator.addValidation("name","req","Please enter Lender's Name");
			 frmvalidator.addValidation("front","req","Please enter Upfront Commission");
			 frmvalidator.addValidation("front","numeric","Please enter numbers only for Upfront Commission");
			 frmvalidator.addValidation("trail","req","Please enter numbers only for Trail Commission");
			 frmvalidator.addValidation("trail","numeric","Please enter numbers only for Trail Commission");
			 
		</script>
		<?php
			if(isset($_POST['submit']))
			{
				$query = "insert into `tbllenders` (lender_name, front, trail1, trail2, trail3, trail4, trail5) values('".$_POST['name']."',".$_POST["front"].",".$_POST["trail1"].", ".$_POST["trail2"].",".$_POST["trail3"].",".$_POST["trail4"].", ".$_POST["trail5"].")";
				$result = mysql_query($query);
				echo  $query;
				$id=0;
				$id = mysql_insert_id();
				
				//$sql = 'INSERT INTO `tbllenderdetails`(`lenderid`, `front`, `Trail`, `Period`) VALUES ('.$id . ',0,0,1),('.$id . ',0,0,2), ('.$id . ',0,0,3), ('.$id . ',0,0,4),('.$id . ',0,0,5)';
				//$result = mysql_query($sql);	  
				if($result)
				{
					echo "<script language='javascript'>alert('Record has been added successfully')</script>";
					echo "<script>window.location='lenders.php';</script>";
				}
			}
		?>
	</body>
</html>