<?php
session_start();


include_once('../../admin/db/saucerer.php');

$db_handle = new DBController();
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
  case "add":
    if(!empty($_POST["quantity"])) {
      $productByCode = $db_handle->runQuery("SELECT * FROM shop WHERE id='" . $_GET["id"] . "'");
      $itemArray = array($productByCode[0]["id"]=>array('name'=>$productByCode[0]["name"], 'id'=>$productByCode[0]["id"], 'quantity'=>$_POST["quantity"], 'cat'=>$productByCode[0]["cat"], 'type'=>$productByCode[0]["type"], 'price'=>$productByCode[0]["price"], 'image'=>$productByCode[0]["image"]));
      

      
      if(!empty($_SESSION["cart_item"])) {
        if(in_array($productByCode[0]["id"],array_keys($_SESSION["cart_item"]))) {
          foreach($_SESSION["cart_item"] as $k => $v) {
              if($productByCode[0]["id"] == $k) {
                if(empty($_SESSION["cart_item"][$k]["quantity"])) {
                  $_SESSION["cart_item"][$k]["quantity"] = 0;
                }
                $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
              }
          }
        } else {
          $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
        }
      } else {
        $_SESSION["cart_item"] = $itemArray;
      }
    }
  break;
  case "remove":
    if(!empty($_SESSION["cart_item"])) {
      foreach($_SESSION["cart_item"] as $k => $v) {
          if($_GET["id"] == $k)
            unset($_SESSION["cart_item"][$k]);        
          if(empty($_SESSION["cart_item"]))
            unset($_SESSION["cart_item"]);
      }
    }
  break;
  case "empty":
    unset($_SESSION["cart_item"]);
  break;  
}
}
?>

<?php

$result = mysqli_query($mysqli, "SELECT * FROM shop ORDER BY id");

if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `shop` WHERE CONCAT(`name`, `cat`, `type`, `price`) 
LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);

}
else {
$query = "SELECT * FROM `shop` ";
$search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
include("../../admin/db/search.php");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}

?>

<!DOCTYPE html>
<html lang="en">
    
<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        
        <link rel="icon" href="../../img/fav-icon.png" type="image/x-icon" />
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <title>Search | Irungi Kitchen &copy;</title>

        <!-- Icon css link -->
        <link href="../../css/font-awesome.min.css" rel="stylesheet">
        <link href="../../vendors/linearicons/style.css" rel="stylesheet">
        <link href="../../vendors/flat-icon/flaticon.css" rel="stylesheet">
        <link href="../../vendors/stroke-icon/style.css" rel="stylesheet">
        <!-- Bootstrap -->
        <link href="../../css/bootstrap.min.css" rel="stylesheet">
        
        <!-- Rev slider css -->
        <link href="../../vendors/revolution/css/settings.css" rel="stylesheet">
        <link href="../../vendors/revolution/css/layers.css" rel="stylesheet">
        <link href="../../vendors/revolution/css/navigation.css" rel="stylesheet">
        <link href="../../vendors/animate-css/animate.css" rel="stylesheet">
        
        <!-- Extra plugin css -->
        <link href="../../vendors/owl-carousel/owl.carousel.min.css" rel="stylesheet">
        <link href="../../vendors/magnifc-popup/magnific-popup.css" rel="stylesheet">
        <link href="../../vendors/jquery-ui/jquery-ui.min.css" rel="stylesheet">
        <link href="../../vendors/nice-select/css/nice-select.css" rel="stylesheet">
        
        <link href="../../css/style.css" rel="stylesheet">
        <link href="../../css/responsive.css" rel="stylesheet">

        
    </head>
    <body>
        
        <!--================Main Header Area =================-->
		<header class="main_header_area">
            <div class="top_header_area row m0">
                <div class="container">
                    <div class="float-left">
                        <a href="tel:+256707681086"><i class="fa fa-phone" aria-hidden="true"></i> +256 707 681086</a>
                        <a href="mailto:admin@irungikitchen.com"><i class="fa fa-envelope-o" aria-hidden="true"></i> admin@irungikitchen.com</a>
                    </div>
                    <div class="float-right">
                        <ul class="h_social list_style">
                            <li><a href="https://facebook.com/irungikitchen"><i class="fa fa-facebook"></i></a></li>
                            <li><a href="https://twitter.com/irungikitchen"><i class="fa fa-twitter"></i></a></li>
                            <li><a href="https://instagram.com/irungikitchen"><i class="fa fa-instagram"></i></a></li>
                            <li><a href="https://wa.me/256707681086?text=https://irungikitchen.com *Let's Chat* %0D%0A  %0D%0A Hello, Welcome to Irungi Whatsapp Support, what do you want to talk about? %0D%0A  %0D%0A"><i class="fa fa-whatsapp"></i></a></li>
                        </ul>
                        <ul class="h_search list_style">

                            <!--Cart-->
                            <li class="shop_cart">

                                

<div class="navbarr">
  <div class="dropdownn">
    <button class="dropbtnn">
        <a href="#"><i class="lnr lnr-cart"></i> 

                            <!--Cart icon start-->
<?php
if(isset($_SESSION["cart_item"])){
    $total_quantity = 0;
    $total_price = 0;
?>  

<?php   
    foreach ($_SESSION["cart_item"] as $item){
        $item_price = $item["quantity"]*$item["price"];
    ?>
        
        <?php
        $total_quantity += $item["quantity"];
        $total_price += ($item["price"]*$item["quantity"]);
    }
    ?>

                                <span><?php echo number_format($total_quantity); ?></span>

    <?php
} else {
?>

                                <span>0</span>


        <?php 
}
?>

                            </a>
    </button>
    <div class="dropdownn-content">

        <?php
if(isset($_SESSION["cart_item"])){
    $total_quantity = 0;
    $total_price = 0;
?>  



<?php   
    foreach ($_SESSION["cart_item"] as $item){
        $item_price = $item["quantity"]*$item["price"];
    ?>

    <aside class="left_sidebar p_sale_widget">
                                
                                <div class="media">
                                    <div class="d-flex">
                                        <?php echo "<img src='../../admin/images/".$item['image']."' alt='".$item['name']."'>"; ?>
                                    </div>
                                    <div class="media-body">
                                        <h4><?php echo $item["name"]; ?></h4>
                                        <ul class="list_style">
                                            <li class="quantity"><?php echo $item["quantity"]; ?> × <?php echo "UGX ".  number_format ($item["price"]); ?></li>

                                            <li class="remove"><a title="Remove" href="../?action=remove&id=<?php echo $item["id"]; ?>"><i class="fa fa-trash"></i></a></li>

                                            <li><h5><?php echo "UGX ".  number_format ($item_price); ?></h5></li>
                                        </ul>
                                        
                                    </div>

                                </div>

                                    <div class="breaker"></div>

                            </aside>

      
                                                    

                                                    

<?php
        $total_quantity += $item["quantity"];
        $total_price += ($item["price"]*$item["quantity"]);
    }
    ?>


<?php
} else {
?>



                    


<?php 
}
?>



<?php
if(isset($_SESSION["cart_item"])){
    $total_quantity = 0;
    $total_price = 0;
?>  



<?php   
    foreach ($_SESSION["cart_item"] as $item){
        $item_price = $item["quantity"]*$item["price"];
    ?>

              <?php
        $total_quantity += $item["quantity"];
        $total_price += ($item["price"]*$item["quantity"]);
    }
    ?>


    <div class="cart-total">
                                                
                                                <h5>Total : <span><?php echo "UGX ". number_format($total_price); ?></span> 
                                                </h5>

                                            <div class="cart-btn" align="center">
                                                <a href="../../Shop/Cart">View Cart<span></span></a>
                                                <a href="../../Shop/Checkout">Checkout<span></span></a>
                                                <a href="../?action=empty" class="empty">Empty Cart</a>
                                            </div>

                                        </div>


    <?php
} else {
?>

<div class="no_items" align="center">

   <p> No Items Detected</p>

   <a href="../../Shop">GO TO SHOP <i class="lnr lnr-store" style="margin-left: 5px;"></i></a>

</div>

<?php 
}
?>


    </div>
  </div> 
</div>

                            </li>


                            <!--Search-->
                            <li style="margin-left: 15px;"><a class="popup-with-zoom-anim" href="#test-search"><i class="fa fa-search"></i></a></li>
                        </ul>
					</div>
				</div>
			</div>
			<div class="main_menu_area">
				<div class="container">
					<nav class="navbar navbar-expand-lg navbar-light bg-light">
						<a class="navbar-brand" href="../../">
						<img src="../../img/irungi.png" alt="Irungi Kitchen">
                        <img src="../../img/irungi-logo.png" alt="Irungi Kitchen">
						</a>
						<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
							<span class="my_toggle_menu">
                            	<span></span>
                            	<span></span>
                            	<span></span>
                            </span>
						</button>
						<div class="collapse navbar-collapse" id="navbarSupportedContent">
							<ul class="navbar-nav mr-auto">
                                <li><a href="../../">Home</a></li>
                                <li class="active"><a href="../../Shop">Shop</a></li>
                                <li><a href="../../Menu">Our Menu</a></li>
                                <li class="dropdown submenu">
                                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Our Products</a>
                                    <ul class="dropdown-menu">

                                        

    <?php
              
              $sql = "SELECT * FROM shop GROUP BY cat ORDER BY id ASC";

              //use for MySQLi-OOP
              $query = $conn->query($sql);
              while($row = $query->fetch_assoc()){
                                    echo '<li><a href="../../'.$row["cat"].'">'.$row["cat"].'</a></li>';
                        }
    ?>

                                    </ul>
                                </li>
                            </ul>
                            <ul class="navbar-nav justify-content-end">
                                <li><a href="../../Catalogue">Catalogue</a></li>
                                <li><a href="../../Blog">Blog</a></li>
                                <li><a href="../../About Us">About Us</a></li>
                                <li><a href="../../Contact Us">Contact Us</a></li>
                            </ul>
                        </div>
                    </nav>
                </div>
            </div>
        </header>
        <!--================End Main Header Area =================-->
        
        <!--================End Main Header Area =================-->
        <section class="banner_area">
        	<div class="container">
        		<div class="banner_text">
        			<h3><?php echo "$valueToSearch"; ?></h3>
        			<ul>
        				<li><a href="../../">Home</a></li>
        				<li><a href="#">Search</a></li>
        			</ul>
        		</div>
        	</div>
        </section>
        <!--================End Main Header Area =================-->
        
        <!--================Product Area =================-->
        <section class="product_area p_100">
        	<div class="container">
        		<div class="row product_inner_row">
        			<div class="col-lg-9">
        				
        				<div class="row product_item_inner grid_portfolio_area">

<?php while($row = mysqli_fetch_array($search_result)):?>


        					<div class="col-lg-4 col-md-4 col-6 '.$filter.'">
        						<div class="cake_feature_item">
									<div class="cake_img">
										<img src="../../admin/images/<?php echo $row["image"]; ?>" alt="<?php echo $row["name"]; ?>">
									</div>
									
                                    <div class="cake_text">


								<?php echo '<h4><b>Ush</b><br>'. number_format ($row["price"]).'</h4>'; ?>

										<h3><?php echo $row["name"]; ?></h3>

								

		 

								<?php 

									echo '<form method="post" action="./?action=add&id='.$row["id"].'">

                                        <div class="quantity">
                                                <span class="qty-minus" onclick="var effect = document.getElementById('.$row["id"].'); var qty = effect.value; if( !isNaN( '.$row["id"].' ) &amp;&amp; qty &gt; 1 ) effect.value--;return false;"><i class="fa fa-minus" aria-hidden="true"></i></span>

                                                <input type="hidden" name="valueToSearch" value="'.$valueToSearch.'">

                                                <input type="text" class="qty-text" id="'.$row["id"].'" step="1" min="1" max="12" name="quantity" value="1">

                                                <span class="qty-plus" onclick="var effect = document.getElementById('.$row["id"].'); var qty = effect.value; if( !isNaN( '.$row["id"].' )) effect.value++;return false;"><i class="fa fa-plus" aria-hidden="true"></i></span>

                                                <button type="submit" name="search" value="5" class="pest_btn">Add to cart</button>

                                            </div>

                                        </form>';

                                     ?>

									</div>
								</div>
        					</div>


 <?php endwhile;?>

        					

        				</div>
        				
        			</div>
        			<div class="col-lg-3">
        				<div class="product_left_sidebar">
        					<aside class="left_sidebar search_widget">
        						<div class="input-group">
									<input type="text" class="form-control" placeholder="Enter Search Keywords">
									<div class="input-group-append">
										<button class="btn" type="button"><i class="icon icon-Search"></i></button>
									</div>
								</div>
        					</aside>

        					<aside class="left_sidebar p_catgories_widget">
        						<div class="p_w_title">
        							<h3>Product Categories</h3>
        						</div>
        						<ul class="list_style">

    <?php
              
              $sql = "SELECT cat, COUNT(cat) FROM shop GROUP BY cat ORDER BY id ASC";

              //use for MySQLi-OOP
              $query = $conn->query($sql);
              while($row = $query->fetch_assoc()){
                                    echo '<li><a href="../../'.$row["cat"].'">'.$row["cat"].' ('.$row["COUNT(cat)"].')</a></li>';
                                    } 
    ?>
        						</ul>
        					</aside>


        				<aside class="left_sidebar p_sale_widget">


       <?php 

					$sql = "SELECT * FROM shop WHERE trend = '1' AND price != '' AND instock = '1'";
            		$query = $conn->query($sql);
            			if($query->num_rows > 0){

            		echo '<div class="p_w_title">
        							<h3>Top Sale Products</h3>
        						</div>';

            		}

        ?>

       <?php
              
              $sql = "SELECT * FROM shop WHERE trend = '1' AND price != '' ORDER BY id ASC";

              //use for MySQLi-OOP
              $query = $conn->query($sql);
              while($row = $query->fetch_assoc()){

						echo '<div class="media">';
        							echo '<div class="d-flex">';
        								echo '<img src="../../admin/images/'.$row["image"].'" alt="'.$row["name"].'">';
        							echo '</div>';
        							echo '<div class="media-body">';
        								echo '<a href="../../Shop/Single/?title='.$row["name"].'"><h4>'.$row["name"].'</h4></a>';
        								echo '<ul class="list_style">
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        								</ul>';
        								echo '<h5>UGX '.number_format ($row["price"]).'</h5>';
        							echo '</div>';
        						echo '</div>';
					}

	   ?>

        					</aside>

        					

        					<aside class="left_sidebar p_sale_widget">

       <?php 

					$sql = "SELECT * FROM shop WHERE arrivals = '1' AND price != '' AND instock = '1'";
            		$query = $conn->query($sql);
            			if($query->num_rows > 0){

            		echo '<div class="p_w_title">
        							<h3>New Arrivals</h3>
        						</div>';

        				}

       ?>

        						<?php
              
              $sql = "SELECT * FROM shop WHERE arrivals = '1' AND price != '' AND instock = '1' ORDER BY arrival_time DESC";

              //use for MySQLi-OOP
              $query = $conn->query($sql);
              while($row = $query->fetch_assoc()){

						echo '<div class="media">';
        							echo '<div class="d-flex">';
        								echo '<img src="../../admin/images/'.$row["image"].'" alt="'.$row["name"].'">';
        							echo '</div>';
        							echo '<div class="media-body">';
        								echo '<a href="../../Shop/Single/?title='.$row["name"].'"><h4>'.$row["name"].'</h4></a>';
        								echo '<ul class="list_style">
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        									<li><a><i class="fa fa-star-o"></i></a></li>
        								</ul>';
        								echo '<h5>UGX '.number_format ($row["price"]).'</h5>';
        							echo '</div>';
        						echo '</div>';
					}

	   ?>
        						

        					</aside>
        				</div>
        			</div>
        		</div>
        	</div>
        </section>
        <!--================End Product Area =================-->
        
        <!--================Newsletter Area =================-->
        <section class="newsletter_area">
        	<div class="container">
        		<div class="row newsletter_inner">
        			<div class="col-lg-6">
        				<div class="news_left_text">
        					<h4>Join our Newsletter list to get all the latest offers, discounts and other benefits</h4>
        				</div>
        			</div>
        			<div class="col-lg-6">
        				<div class="newsletter_form">
							
                            <form>

                                <div class="input-group username"><input type="text" id="username" name="username" value=""></div>

                                <div class="input-group">
                                    <input type="email" id="email" class="form-control" placeholder="Enter your email address">
                                    <div class="input-group-append">
                                        <button class="btn btn-outline-secondary" type="submit" id="newsletter">Subscribe Now</button>
                                    </div>

                                </div>

                                    <div align="center" class="message_box" style="margin:10px 0px;"></div>

                                </form>

        				</div>
        			</div>
        		</div>
        	</div>
        </section>
        <!--================End Newsletter Area =================-->
        
        <!--================Footer Area =================-->
        <footer class="footer_area">
            <div class="footer_widgets">
                <div class="container">
                    <div class="row footer_wd_inner">
                        <div class="col-lg-3 col-6">
                            <aside class="f_widget f_about_widget">
                                <img src="../../img/footer-logo.png" alt="Irungi Kitchen">
                                <p>A confectionary kitchen with fresh natural goodness, in which baked sparkles of joy spread into your mouth from its origin.</p>
                                <ul class="nav">
                            <li><a href="https://facebook.com/irungikitchen"><i class="fa fa-facebook"></i></a></li>
                            <li><a href="https://twitter.com/irungikitchen"><i class="fa fa-twitter"></i></a></li>
                            <li><a href="https://instagram.com/irungikitchen"><i class="fa fa-instagram"></i></a></li>
                            <li><a href="https://wa.me/256707681086?text=https://irungikitchen.com *Let's Chat* %0D%0A  %0D%0A Hello, Welcome to Irungi Whatsapp Support, what do you want to talk about? %0D%0A  %0D%0A"><i class="fa fa-whatsapp"></i></a></li>
                                </ul>
                            </aside>
                        </div>
                        <div class="col-lg-3 col-6">
                            <aside class="f_widget f_link_widget">
                                <div class="f_title">
                                    <h3>Quick links</h3>
                                </div>
                                <ul class="list_style">
                                    <li><a href="../../Menu">Our Menu</a></li>
                                    <li><a href="../../Catalogue">Catalogue</a></li>
                                    <li><a href="../../About Us">About Us</a></li>
                                    <li><a href="../../Contact Us">Contact Us</a></li>
                                </ul>
                            </aside>
                        </div>
                        <div class="col-lg-3 col-6">
                            <aside class="f_widget f_link_widget">
                                <div class="f_title">
                                    <h3>Work Times</h3>
                                </div>
                                <ul class="list_style">
                                    <li><a>Mon - Fri: 8am - 8pm</a></li>
                                    <li><a>Sat: 9am - 4pm</a></li>
                                    <li><a>Sun: Closed</a></li>
                                </ul>
                            </aside>
                        </div>
                        <div class="col-lg-3 col-6">
                            <aside class="f_widget f_contact_widget">
                                <div class="f_title">
                                    <h3>Contact Info</h3>
                                </div>
                                <h4><a href="tel:+256707681086" style="color: white;">+256 707 681086</a></h4>
                                <p>Plot 22, Bukoto Street <br />Kampala, Uganda</p>
                                <h5><a href="mailto:admin@irungikitchen.com" style="color: #f195b2;">admin@irungikitchen.com</a></h5>
                            </aside>
                        </div>
                    </div>
                </div>
            </div>
            <div class="footer_copyright">
                <div class="container">
                    <div class="copyright_inner">
                        <div class="float-left">
                            <h5><a href="#">Irungi Kitchen © <script>document.write(new Date().getFullYear());</script></a></h5>
                        </div>
                        <div class="float-right">
                            <a target="_blank" href="https://customassistinc.com">Powered by Custom Assist Inc<b class="animated infinite flash">.</b></a>
                        </div>
                    </div>
                </div>
            </div>
        </footer>
        <!--================End Footer Area =================-->
        
        
        <!--================Search Box Area =================-->
        <div class="search_area zoom-anim-dialog mfp-hide" id="test-search">
            <div class="search_box_inner">
                <h3>Search</h3>

                <form action="../../Shop/Search/index.php" method="POST">
                <div class="input-group">
                    <input type="search" name="valueToSearch" class="form-control" placeholder="Search for..." required>
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="submit" name="search" ><i class="icon icon-Search"></i></button>
                    </span>
                </div>
              </form>

            </div>
        </div>
        <!--================End Search Box Area =================-->
        
        
        
        
        
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="../../js/jquery-3.2.1.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="../../js/popper.min.js"></script>
        <script src="../../js/bootstrap.min.js"></script>
        <!-- Rev slider js -->
        <script src="../../vendors/revolution/js/jquery.themepunch.tools.min.js"></script>
        <script src="../../vendors/revolution/js/jquery.themepunch.revolution.min.js"></script>
        <script src="../../vendors/revolution/js/extensions/revolution.extension.actions.min.js"></script>
        <script src="../../vendors/revolution/js/extensions/revolution.extension.video.min.js"></script>
        <script src="../../vendors/revolution/js/extensions/revolution.extension.slideanims.min.js"></script>
        <script src="../../vendors/revolution/js/extensions/revolution.extension.layeranimation.min.js"></script>
        <script src="../../vendors/revolution/js/extensions/revolution.extension.navigation.min.js"></script>
        <!-- Extra plugin js -->
        <script src="../../vendors/owl-carousel/owl.carousel.min.js"></script>
        <script src="../../vendors/magnifc-popup/jquery.magnific-popup.min.js"></script>
        <script src="../../vendors/isotope/imagesloaded.pkgd.min.js"></script>
        <script src="../../vendors/isotope/isotope.pkgd.min.js"></script>
        <script src="../../vendors/datetime-picker/js/moment.min.js"></script>
        <script src="../../vendors/datetime-picker/js/bootstrap-datetimepicker.min.js"></script>
        <script src="../../vendors/nice-select/js/jquery.nice-select.min.js"></script>
        <script src="../../vendors/jquery-ui/jquery-ui.min.js"></script>
        <script src="../../vendors/lightbox/simpleLightbox.min.js"></script>
        
        <script src="../../js/theme.js"></script>

        <script>
$(document).ready(function() {
  var delay = 500;
  $('#newsletter').click(function(e){
    e.preventDefault();
    
    var username = $('#username').val();

    var newsletter = $('#newsletter').val();

    var email = $('#email').val();
        if(email == ''){
      $('.message_box').html(
      '<span style="color:white;font-weight:bold; font-size: 14px;">Please Enter An Email Address!</span>'
      );
      $('#email').focus();
            return false;
      }
    if( $("#email").val()!='' ){
      if( !isValidEmailAddress( $("#email").val() ) ){
      $('.message_box').html(
      '<span style="color:white;font-weight:bold; font-size: 14px;">Provided email address is incorrect!</span>'
      );
      $('#email').focus();
      return false;
      }
      }
    
          
      $.ajax
      ({
             type: "POST",
       url: "https://irungikitchen.com/Contact Us/newsletters/index.php",
             data: "email="+email+"&username="+username+"&newsletter="+newsletter,
       beforeSend: function() {
       $('.message_box').html(
       '<div align="center"><img src="../../img/ajax.gif" width="25" height="25"/></div>'
       );
       },    
             success: function(data)
       {
         setTimeout(function() {
                    $('.message_box').html(data);
                }, delay);
      
             }
       });
  });
      
});

//Email validation Function 
function isValidEmailAddress(emailAddress) {
    var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
    return pattern.test(emailAddress);
};
</script>

    </body>

</html>