<? 
require_once "include/application.php"; 
require_once "include/function.php";
require_once "include/parameter.php";

if($btnAdd){
	$err=false;
	
	$adv=book_adv();


	$ye=yearly_expired($memberno);

	if(date("Y-m-d") > $expiry){
		$action_msg="Membership program tenure is expired.<br>";
		$err=true;
	}

		
	/*if(system_date($cin1) < $adv){
		$action_msg="Invalid check in date(1)! Must book before 2 weeks in advance.<br>";
		$err=true;
	}

	if(system_date($cin2) < $adv){
		$action_msg.="Invalid check in date(2)! Must book before 2 weeks in advance.<br>";
		$err=true;
	}

	if(system_date($cin3) < $adv){
		$action_msg.="Invalid check in date(3)! Must book before 2 weeks in advance.<br>";
		$err=true;
	}
*/
	if(system_date($cout1) > $ye){
		$action_msg.="Invalid Check out date(1)! Annual entitlement date is expiry.<br>";
		$err=true;
	}

	if(system_date($cout2) > $ye){
		$action_msg.="Invalid Check out date(2)! Annual entitlement date is expiry.<br>";
		$err=true;
	}

	if(system_date($cout3) > $ye){
		$action_msg.="Invalid Check out date(3)! Annual entitlement date is expiry.<br>";
		$err=true;
	}
	
	
	// check bal
	  if($cin1 && $cout1){
		  $nonight=get_days(system_date($cin1),system_date($cout1));
		  $tot=$nonight * $rooms;
		  if($tot > $bal){
			  $action_msg.="Reservation for 1st choice is over the balance!<br>";
			  $err=true;
		  }

	  }
	  

	  if($cin2 && $cout2){
		  $nonight=get_days(system_date($cin2),system_date($cout2));
		  $tot=$nonight * $rooms;
		  if($tot > $bal){
			  $action_msg.="Reservation for 2nd choice is over the balance!<br>";
			  $err=true;
		  }
	  }


	  if($cin3 && $cout3){
		  $nonight=get_days(system_date($cin3),system_date($cout3));
		  $tot=$nonight * $rooms;
		  if($tot > $bal){
			  $action_msg.="Reservation for 3rd choice is over the balance!<br>";
			  $err=true;
		  }
	  }
	  

	
	
	
	if($err==false){
	$stamp=nextid('n_stamp');
	  $sql="
		  INSERT INTO `ivc_reservation` (
		  `irs_memberno` ,
		  `irs_cardno` ,
		  `irs_for` ,
		  `irs_guestname` ,
		  `irs_guestic` ,
		  `irs_guestcontact` ,
		  `irs_guestemail` ,	
		  irs_room1,	
		  `irs_checkin1` ,
		  `irs_checkout1` ,
		  `irs_adult1` ,
		  `irs_child1` ,
		  `irs_checkin2` ,
		  `irs_checkout2` ,
		  `irs_checkin3` ,
		  `irs_checkout3` ,
		  `irs_usertype` ,
		  `irs_userid`, irs_created ,irs_stamp
		  )
		  VALUES ('$memberno','$no', '$reserv', \"$gname\", '$gic', '$gcontact', '$gemail', '$rooms','".system_date($cin1)."', '".system_date($cout1)."', '$adult1', '$child1', 
		  '".system_date($cin2)."', '".system_date($cout2)."',  '".system_date($cin3)."', '".system_date($cout3)."',  'A', '".$_SESSION["egoUser"]."',now(),'$stamp'
		  )
	  ";
	  @mysql_query($sql) or die(mysql_error());
	
	
		print("<script type='text/javascript'>alert('Reservation is booked.')</script>");
		print("<script type='text/javascript'>location.href='reservConfirm.php'</script>");
	}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>
  <link rel="stylesheet" href="datepicker/themes/winter.css" />
<!-- Loading Calendar JavaScript files -->
    <script type="text/javascript" src="datepicker/zapatec.js"></script>
    <script type="text/javascript" src="datepicker/calendar.js"></script>
<!-- Loading language definition file -->
    <script type="text/javascript" src="datepicker/calendar-en.js"></script>


<title><? echo TITLE?></title></head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php";
if(array_search("Reservation",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");

 ?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>"  ONSUBMIT="return ValidateAddReservation(this)">
	  <table width="800" height="250" border="0" align="center" cellpadding="0" cellspacing="0">


	  <tr>
        
        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="30" class="TitleH3">New Reservation </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;
              <input name="hadult" type="hidden" id="hadult" value="<? echo $hadult ?>" />
              <input name="hchild" type="hidden" id="hchild" value="<? echo $hchild ?>" /></td>
          </tr>

        </table>
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="53%" valign="top"><table border="0" cellpadding="2" width="100%" cellspacing="1" class="small">
                <tr>
                  <td width="190" class="TextH1">Card No. : <span class="require">*</span></td>
                  <td width="222" class="TextH1"><input name="no" type="text" class="small" id="no" value="<? echo $no ?>" maxlength="30" onblur="membershipInfo(this.value)"/>
                    <input name="btnInfo2" type="button" class="btnInfo" id="btnInfo2" value="..." onclick="DialogWindow('popup/popName.php','Search','Classic');"/></td>
                </tr>
                <tr>
                  <td class="TextH1">&nbsp;</td>
                  <td class="TextH1">&nbsp;</td>
                </tr>
                <tr>
                  <td class="TextH1">Membership No :</td>
                  <td class="TextH1">                    <input name="memberno" type="text" class="info" id="memberno" onfocus="if(document.images){blur()}" value="<? echo $memberno ?>" size="30">
</td>
                </tr>
                <tr>
                  <td class="TextH1">Principal's Name  :</td>
                  <td class="TextH1">
                    <input name="name" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $name ?>" size="30" />
		</td>
                </tr>
                <tr>
                  <td class="TextH1">Type of Product    :</td>
                  <td class="TextH1">
                                      <input name="scheme" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $scheme ?>" size="30" />
</td>
                </tr>
                <tr>
                  <td class="TextH1">Villas    :</td>
                  <td class="TextH1"><input name="room" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $room ?>" size="30" />
</td>
                </tr>
                <tr>
                  <td class="TextH1">NRIC/Passport  :</td>
                  <td class="TextH1">
                  <input name="ic" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $ic ?>" size="30" />
</td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1">

                  <div align="left">Home  Contact No. : </div></th>
                  <td class="TextH1">                  <input name="homeno" type="text" class="info" id="homeno"  onfocus="if(document.images){blur()}" value="<? echo $homeno ?>" size="30" /></td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left">Mobile No. : </div></th>
                  <td class="TextH1">
                                    <input name="mobile" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $mobile ?>" size="30" />
</td>
                </tr>
                <tr class="editTbl">
                  <th height="11" class="TextH1"><div align="left">Fax No. : </div></th>
                  <td class="TextH1">                  <input name="fax" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $fax ?>" size="30" />
</td>
                </tr>

                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left">Email : </div></th>
                  <td class="TextH1">                  <input name="email" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $email ?>" size="30" /></td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left"> Program Tenure : </div></th>
                  <td class="TextH1">                  <input name="program" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $program ?>" size="10" /> Year(s ) </td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left">Membership  Expired : </div></th>
                  <td class="TextH1"><input name="expiry" type="text" class="info" id="expiry"  onfocus="if(document.images){blur()}" value="<? echo $exp ?>" size="10" /></td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left"> Annual Entitlement : </div></th>
                  <td class="TextH1"><input name="entnights" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $entnights ?>" size="10" />
 Night(s)</td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left">Annual Entitlement<br />  
                    Expired : </div></th>
                  <td class="TextH1"><input name="yrexp" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $yrexp ?>" size="10" />
                  </td>
                </tr>
                <tr>
                  <td class="TextH1">Free Maintenance Fees :</td>
                  <td class="TextH1"><input name="freemaint" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $freemaint ?>" size="10" />
                  Year(s) </td>
                </tr>
                <tr class="editTbl">
                  <th height="23" class="TextH1"><div align="left"> Balance of Nights : </div></th>
                  <td class="TextH1"><input name="bal" type="text" class="info"  onfocus="if(document.images){blur()}" value="<? echo $bal ?>" size="10" />
                  Night(s)
</td>
                </tr>

              </table></td>
              <td width="47%" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="2">
                <tr>
                  <td colspan="2" class="TextH1">Reservation Request  <span class="require">*</span></td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#333333" class="TextH1"><span class="white14">Please choose </span><br />
                    <input name="reserv" type="radio" value="Personal" <?=($reserv=="Personal" ? "CHECKED" : " ")?>/>
                    <span class="white14">For personal
                      use</span>
                    <input name="reserv" type="radio" value="Guest" <?=($reserv=="Guest" ? "CHECKED" : " ")?>/>
                    <span class="white14"> For guest use </span></td>
                  </tr>
                <tr>
                  <td colspan="2" bgcolor="#3DC3CE" class="TextH1">If for guest use, please indicate the following:</td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#3DC3CE" class="TextH1">Guest's Full Name : <span class="require">*</span> 
                    <input name="gname" type="text" class="small" id="gname" value="<? echo $gname ?>" maxlength="50" /></td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#3DC3CE" class="TextH1">Guest's IC / Passport No : <span class="require">*</span>
                    <input 
      name="gic" id="gic" style="WIDTH: 180px" value="<? echo $gic ?>" size="20" maxlength="20" /></td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#3DC3CE" class="TextH1">Guest's Contact No : 
                    <span class="require">*</span>
                    <input 
      name="gcontact" id="gcontact" style="WIDTH: 180px" value="<? echo $gcontact ?>" size="20" maxlength="20" /></td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#3DC3CE" class="TextH1">Guest's Email : 
                    <input 
      name="gemail" id="gemail" style="WIDTH: 180px" value="<? echo $gemail ?>" size="20" maxlength="20" /></td>
                </tr>
                <tr>
                  <td colspan="2" class="TextH1"><div align="center"></div></td>
                </tr>
                <tr>
                  <td class="TextH1">No of Adults : <span class="require">*</span></td>
                  <td class="TextH1"><?
echo "<select name='adult1'>";

if($btnAdd){
	for($i=1; $i<=$hadult; $i++){
		echo '<option value="'.$i.'" '; 
		if($adult1==$i)echo 'selected';
		echo '>'.$i.'</option>';
	}
}
 echo '</select> ';

?>
                    &nbsp; No of Childrens : <span class="require">
                      <?
echo "<select name='child1'>";
if($btnAdd){
	for($i=1; $i<=$hchild; $i++){
		echo '<option value="'.$i.'" '; 
		if($child1==$i)echo 'selected';
		echo '>'.$i.'</option>';
	}
}
 echo '</select> ';

?>
                    </span></td>
                </tr>
                <tr>
                  <td class="TextH1">No of Villas : <span class="require">*</span></td>
                  <td class="TextH1"><?
echo "<select name='rooms'>";

if($btnAdd){
	for($i=1; $i<=$hadult * $entnights; $i++){
		echo '<option value="'.$i.'" '; 
		if($rooms==$i)echo 'selected';
		echo '>'.$i.'</option>';
	}
}

 echo '</select> ';

?>
                    &nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#FF9900" class="TextH1"><div align="center">1st Choice </div></td>
                </tr>
                <tr>
                  <td width="37%" class="TextH1">Check In Date : <span class="require">*</span></td>
                  <td width="63%" class="TextH1"><input name="cin1" type="text" class="small" id="cin1"   value="<? echo $cin1 ?>" size="15" maxlength="10" />
                    <button id="trigger_cin1">...</button>
                    <script type="text/javascript">//<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        electric          : false,
        inputField        : "cin1",
        button            : "trigger_cin1",
        ifFormat          : "%d/%m/%Y",
        daFormat          : "%Y/%m/%d"
      });
    //]]></script>
                    <span class="subItem"> dd/mm/yyyy</span></td>
                </tr>
                <tr>
                  <td class="TextH1">Check Out Date : <span class="require">*</span></td>
                  <td class="TextH1"><input name="cout1" type="text" class="small" id="cout1"   value="<? echo $cout1 ?>" size="15" maxlength="10" />
                    <button id="trigger_cout1">...</button>
                    <script type="text/javascript">//<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        electric          : false,
        inputField        : "cout1",
        button            : "trigger_cout1",
        ifFormat          : "%d/%m/%Y",
        daFormat          : "%Y/%m/%d"
      });
    //]]></script>
                    <span class="subItem"> dd/mm/yyyy</span></td>
                </tr>
                <tr>
                  <td class="TextH1">&nbsp;</td>
                  <td class="TextH1">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#FF9966" class="TextH1"><div align="center">2nd Choice </div></td>
                </tr>
                <tr>
                  <td class="TextH1">Check In Date : <span class="require">*</span></td>
                  <td class="TextH1"><input name="cin2" type="text" class="small" id="cin2"   value="<? echo $cin2 ?>" size="15" maxlength="10" />
                      <button id="trigger_cin2">...</button>
                    <script type="text/javascript">//<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        electric          : false,
        inputField        : "cin2",
        button            : "trigger_cin2",
        ifFormat          : "%d/%m/%Y",
        daFormat          : "%Y/%m/%d"
      });
    //]]></script>
                      <span class="subItem"> dd/mm/yyyy</span></td>
                </tr>
                <tr>
                  <td class="TextH1">Check Out Date : <span class="require">*</span></td>
                  <td class="TextH1"><input name="cout2" type="text" class="small" id="cout2"   value="<? echo $cout2 ?>" size="15" maxlength="10" />
                      <button id="trigger_cout2">...</button>
                    <script type="text/javascript">//<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        electric          : false,
        inputField        : "cout2",
        button            : "trigger_cout2",
        ifFormat          : "%d/%m/%Y",
        daFormat          : "%Y/%m/%d"
      });
    //]]></script>
                      <span class="subItem"> dd/mm/yyyy</span></td>
                </tr>
                <tr>
                  <td class="TextH1">&nbsp;</td>
                  <td class="TextH1">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2" bgcolor="#FF9999" class="TextH1"><div align="center">3rd Choice </div></td>
                </tr>
                <tr>
                  <td class="TextH1">Check In Date : <span class="require">*</span></td>
                  <td class="TextH1"><input name="cin3" type="text" class="small" id="cin3"   value="<? echo $cin3 ?>" size="15" maxlength="10" />
                      <button id="trigger_cin3">...</button>
                    <script type="text/javascript">//<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        electric          : false,
        inputField        : "cin3",
        button            : "trigger_cin3",
        ifFormat          : "%d/%m/%Y",
        daFormat          : "%Y/%m/%d"
      });
    //]]></script>
                      <span class="subItem"> dd/mm/yyyy</span></td>
                </tr>
                <tr>
                  <td class="TextH1">Check Out Date : <span class="require">*</span></td>
                  <td class="TextH1"><input name="cout3" type="text" class="small" id="cout3"   value="<? echo $cout3 ?>" size="15" maxlength="10" />
                      <button id="trigger_cout3">...</button>
                    <script type="text/javascript">//<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        electric          : false,
        inputField        : "cout3",
        button            : "trigger_cout3",
        ifFormat          : "%d/%m/%Y",
        daFormat          : "%Y/%m/%d"
      });
    //]]></script>
                      <span class="subItem"> dd/mm/yyyy</span></td>
                </tr>
                <tr>
                  <td colspan="2" class="TextH1">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2" class="TextH1">Remarks (if any):</td>
                </tr>
                <tr>
                  <td colspan="2" class="TextH1"><textarea name="remark" cols="50" rows="4" id="remark" ><? echo $remark ?></textarea></td>
                </tr>
              </table></td>
            </tr>
          </table>
          <table border="0" cellpadding="2" width="100%" cellspacing="1" class="small">
            <tr>
              <td height="30" class="TextH1"><p>Reservation Request
                
                Disclaimer:
                
                </p>
                <p>The Reservation Request made is an invitation to treat, the IVCB (Iconic Vacation Club Berhad) will not take the Reservation Request as a final and confirm reservation made by the member. The Reservation Request only serves as a request to the date and availability of room(s). IVCB will not be responsible for any reservation request made by member that is not in accordance to the terms and conditions herein.                  </p>
                <p>Waiting Approval
                  
                  Disclaimer:                  </p>
                <p>Thank you for your reservation, we are in the midst of processing your reservation. We will revert when your reservation is confirmed. Kindly check your status of reservation under the 'Confirmation Record'.                  </p>
                <p>Confirmation Record
                  
                  Disclaimer:                  </p>
                <p>Your reservation is accepted / rejected. Kindly keep your Booking No. as a reference upon your checking in the resort. Last minutes cancellation (3 days before check-in date) or no turn ups will constitute to usage of your entitlement. No replacement will be entertained. The Management decision is final. </p></td>
            </tr>
            <tr>
              <td height="1" bgcolor="#999999"></td>
            </tr>
            <tr>
              <td height="30" class="TextH1"><span class="require">* Denotes a require_onced field</span></td>
            </tr>
            <tr>
              <td class="text12">
                  <input name="btnAdd" type="submit" class="btn" id="btnAdd" value="Book Now" onclick="return confirm('Are you sure ?')"/>
&nbsp;</td>
            </tr>
          </table></td>

      </tr>
 
    </table><br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333" class="Footer" align="center"><br />
    <? require_once "footer.php"; ?></td>
  </tr>
</table>
</body>
</html>
