<?
session_start();
include("include/db.inc.php"); 
include("include/functions.php"); 
include("include/bit_functions.inc.php");

if($_SESSION['lang']=='')
	{
		$_SESSION['lang'] = "en";
	}	

	include 'languages/lang_common_'.$_SESSION['lang'].'.php';
   $db1=new db;
   $db1->open();
  mysql_query("SET NAMES 'utf8'");  
  $currency_symbol_new=symbol_currency(); 	
   $uid=$_SESSION['uid'];
   $pid=$_POST['pid'];
   $bid=$_POST['bid'];
   
   
   if(remainbid1($uid) <= 0)
	{
	echo _NOBID_AJX_;
	exit;
	}
	
   $numsold= mysql_num_rows(mysql_query("select id from t123go_product_sold where pid='".$pid."'"));
   
   if($bid!='' && $numsold==0)
   { 
$rec2=mysql_fetch_array(mysql_query("select starting_bidprice,bid_price,type1,total_bids from t123go_product where pid='$pid'"));

$bid_incr=get_increment($rec2['type1'],$rec2['total_bids']);	  
	  
	   if($rec2['bid_price']!='')
	   {
	  	 $price=$rec2[bid_price] + $bid_incr[0];
	   }
	   else
	   {
	   	$price=$rec2[starting_bidprice] + $bid_incr[0];		
	   }
	   
	 if(mysql_num_rows(mysql_query("select id from t123go_bid where pid='$pid' ")) > 0) 
	 {
	  $rec=mysql_fetch_array(mysql_query("select uid from t123go_bid where pid='$pid' order by id desc limit 0,1")); 
	  if($rec[0]!=$uid)
	   {  
		   mysql_query("insert into t123go_bid set uid='$uid',pid='$pid',product_price='$price',bid_time=now()");		  
		  $diff=mysql_fetch_array(mysql_query("SELECT TIME_TO_SEC( TIMEDIFF( end_time, now( ))),
		  date_format(end_time,'%Y-%m-%d %H:%i:%s')as et FROM t123go_product where pid='$pid'")) ;  
		
		   mysql_query("update t123go_product set end_time=DATE_ADD('$diff[et]', INTERVAL $bid_incr[1] SECOND),
		   bid_price='$price',total_bids=total_bids+1,bider_id='$uid',bid_type='single' where pid='$pid'");
		   mysql_query("update user set no_bids=no_bids-1 where id='".$uid."'");	 
		
	   echo "0";
	   }
	   else
	   {
	   echo "maxbid";	   
	   }
	 }
  	 else
   	 {  
	    mysql_query("insert into t123go_bid set uid='$uid',pid='$pid',product_price='$price',bid_time=now()");	   
	  $diff=mysql_fetch_array(mysql_query("SELECT TIME_TO_SEC( TIMEDIFF( end_time, now( ))),bid_time,
	  date_format(end_time,'%Y-%m-%d %H:%i:%s')as et FROM t123go_product where pid='$pid'")) ;  
	 
	   mysql_query("update t123go_product set end_time=DATE_ADD('$diff[et]', INTERVAL $bid_incr[1] SECOND),
	   bid_price='$price',total_bids=total_bids+1,bider_id='$uid',bid_type='single' where pid='$pid'");	
	   mysql_query("update user set no_bids=no_bids-1 where id='".$uid."'");   
	 
  
   	  echo "0";
	  echo "maxbid";	
       }
	   
	
   }
?>