<?php
	include("config.php");
	error_reporting(0);
	include("include/functions.php");
	
	if($_REQUEST['command']=='add' && $_REQUEST['pid']>0){
		$pid=$_REQUEST['pid'];
		addtocart($pid,1);
		header("location:shoppingcart.php");
		exit();
	}
	
	if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
		remove_product($_REQUEST['pid']);
	}
	else if($_REQUEST['command']=='clear'){
		unset($_SESSION['cart']);
	}
	else if($_REQUEST['command']=='update'){
		$max=count($_SESSION['cart']);
		for($i=0;$i<$max;$i++){
			$pid=$_SESSION['cart'][$i]['productid'];
			 $q=intval($_REQUEST['product'.$pid]);
			if($q>0 && $q<=999){
				$_SESSION['cart'][$i]['qty']=$q;
			}
			else{
				$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
			}
		}
	}
	
?>

<form name="form1">
	<input type="hidden" name="pid" />
    <input type="hidden" name="productimage" />
    <input type="hidden" name="command" />
</form>

<!DOCTYPE HTML>
<html>
	<head>
		<title><?php echo $tittle;?></title>
		<link href="css/style.css" rel='stylesheet' type='text/css' />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
		</script>
		<!----webfonts---->
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
		<!----//webfonts---->
		<!----start-alert-scroller---->
		<script src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery.easy-ticker.js"></script>
		<script type="text/javascript">
		$(document).ready(function(){
			$('#demo').hide();
			$('.vticker').easyTicker();
		});
		</script>
		<!----start-alert-scroller---->
		<!-- start menu -->
		<link href="css/megamenu.css" rel="stylesheet" type="text/css" media="all" />
		<script type="text/javascript" src="js/megamenu.js"></script>
		<script>$(document).ready(function(){$(".megamenu").megamenu();});</script>
		<script src="js/menu_jquery.js"></script>
		<!-- //End menu -->
		<!---slider---->
		<link rel="stylesheet" href="css/slippry.css">
		<script src="js/jquery-ui.js" type="text/javascript"></script>
		<script src="js/scripts-f0e4e0c2.js" type="text/javascript"></script>
		<script>
			  jQuery('#jquery-demo').slippry({
			  // general elements & wrapper
			  slippryWrapper: '<div class="sy-box jquery-demo" />', // wrapper to wrap everything, including pager
			  // options
			  adaptiveHeight: false, // height of the sliders adapts to current slide
			  useCSS: false, // true, false -> fallback to js if no browser support
			  autoHover: false,
			  transition: 'fade'
			});
		</script>
		<!----start-pricerage-seletion---->
		<script type="text/javascript" src="js/jquery-ui.min.js"></script>
		<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
		<script type='text/javascript'>//<![CDATA[ 
			$(window).load(function(){
			 $( "#slider-range" ).slider({
			            range: true,
			            min: 0,
			            max: 500,
			            values: [ 100, 400 ],
			            slide: function( event, ui ) {  $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
			            }
			 });
			$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) + " - $" + $( "#slider-range" ).slider( "values", 1 ) );
			
			});//]]>  
		</script>
		<!----//End-pricerage-seletion---->
		<!---move-top-top---->
		<script type="text/javascript" src="js/move-top.js"></script>
		<script type="text/javascript" src="js/easing.js"></script>
		<script type="text/javascript">
			jQuery(document).ready(function($) {
				$(".scroll").click(function(event){		
					event.preventDefault();
					$('html,body').animate({scrollTop:$(this.hash).offset().top},1200);
				});
			});
		</script>
		<!---//move-top-top---->
	</head>
	<body>
		<!---start-wrap---->
			<!---start-header---->
			<?php include("include/header.php"); ?>
			<!---//End-header---->
		<!--- start-content---->
		<div class="content product-box-main">
			<div class="wrap">
				<div class="content-left">
					<?php include("include/category.php"); ?>	
				</div>
				<div class="content-right product-box">
					
					<div class="product-grids">
						<!--- start-rate---->
							<script src="js/jstarbox.js"></script>
							<link rel="stylesheet" href="css/jstarbox.css" type="text/css" media="screen" charset="utf-8" />
							<script type="text/javascript">
								jQuery(function() {
									jQuery('.starbox').each(function() {
										var starbox = jQuery(this);
										starbox.starbox({
											average: starbox.attr('data-start-value'),
											changeable: starbox.hasClass('unchangeable') ? false : starbox.hasClass('clickonce') ? 'once' : true,
											ghosting: starbox.hasClass('ghosting'),
											autoUpdateAverage: starbox.hasClass('autoupdate'),
											buttons: starbox.hasClass('smooth') ? false : starbox.attr('data-button-count') || 5,
											stars: starbox.attr('data-star-count') || 5
										}).bind('starbox-value-changed', function(event, value) {
											if(starbox.hasClass('random')) {
												var val = Math.random();
												starbox.next().text(' '+val);
												return val;
											} 
										})
									});
								});
							</script>
							<!---//End-rate---->
                            
                            <?php 
							$cat=$_REQUEST['cat'];
     $res =mysql_query("select * from products where category='$cat'");
    $count  = mysql_num_rows($res);
    
            

				while($row_section=mysql_fetch_array($res))
        {
				$id= $row_section['serial'];
				$small_jpg= $row_section['small_jpg'];
				$name= $row_section['name'];
	            $sub_category=$row_section['sub_category'];
                $price= $row_section['price'];
				$proid= $row_section['product_id'];
			  ?> 	
					 <div class="product-grid fade">
							<div class="product-grid-head">
								<ul class="grid-social">
									<li><a class="facebook" href="#"><span> </span></a></li>
									<li><a class="twitter" href="#"><span> </span></a></li>
									<li><a class="googlep" href="#"><span> </span></a></li>
									<div class="clear"> </div>
								</ul>
								<!--<div class="block">
									<div class="starbox small ghosting"> </div> <span></span>
								</div>-->
							</div>
							<div class="product-pic">
								<a href="#"><img src="CryoM@dmin/<?php echo $small_jpg; ?>" title="product-name" width="300" height="200"/></a>
								<p>
								<a href="#"><?php echo $name; ?></a>
								<span><?php echo $sub_category; ?></span>
                                <p style="margin-left:200px; margin-top:-50px;">  
                                <?php
                                $useee=$_SESSION['username'];  
								if($useee==NULL)
								{
								?>                            
                                <a href="login.php" onClick="return confirm('Please Login')"><img src="images/xx.jpg" width="40" height="40"></a>
                                <?php } else {?>
                                <a href="#" onClick="addtocart(<?php echo $id; ?>)"><img src="images/xx.jpg" width="40" height="40"></a>
                                <?php } ?>
                                </p>
								</p>
							</div>
							<div class="product-info">
								<div class="product-info-cust">
									<a href="details.php?id=<?php echo $id; ?>" class="details">Details</a>
								</div>
								<div class="product-info-price">
									<a href="#"><?php echo $corrrency; ?> <?php echo $price; ?></a>
								</div>
								<div class="clear"> </div>
							</div>
							<div class="more-product-info">
								<span> </span>
							</div>
						</div>
                        
                        <?php } ?>
                        
                        
                        
                        
					  <div class="clear"> </div>
					</div>
					<!----start-load-more-products---->
					<!--<div class="loadmore-products">
						<a href="#">Loadmore</a>
					</div>-->
					<!----//End-load-more-products---->
				</div>
				<div class="clear"> </div>
			</div>
		</div>
		<!---- start-bottom-grids---->
		<?php include("include/footer.php"); ?>
		 <script language="javascript">
	function addtocart(pid){
		document.form1.pid.value=pid;

		document.form1.command.value='add';
		document.form1.submit();
	}
</script>