<?php
/**
 * JE GroupBuy package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2011 - 2012 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

// no direct access
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT.DS.'helpers');
JHTML::addIncludePath(JPATH_BASE.DS.'components'.DS.'com_content'.DS.'helpers');
$params		= JComponentHelper::getParams('com_jegroupbuy');
$doc	 	= & JFactory::getDocument();

$shadowbox  = JURI::base().'components/com_jegroupbuy/assets/js/shadowbox.js';

// Joomla predefined function for modal
	JHTML::_('behavior.modal');

?>
<style type="text/css">
.rsc_comment_container {
	clear:both;
	margin-bottom:14px;
	overflow:hidden;
	width:100%;
}
.productdetails table, tr, td
{
	border:none;
}

</style>
<script src="<?php echo  JURI::base();?>components/com_jegroupbuy/assets/js/addComment.js"></script>

<!-- Included javascript files and functions -->
<script language="JavaScript" type="text/javascript" src="<?php echo $shadowbox ?>"></script>

<script type="text/javascript">
	Shadowbox.init();
</script>

<?php
$payment_url =  JRoute::_('index.php?option=com_jegroupbuy&task=paymentDetails&pid='.$this->items->id);
$settings = $this->settings;
?>
<form action="<?php echo JRoute::_('index.php'); ?>" name="productForm">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>

<link rel="stylesheet" type="text/css" href="<?php echo JURI::root().'components/com_jegroupbuy/assets/css/style.css'?>">
<table cellpadding="0" cellspacing="0" width="98%" border="0">
	<tr>
		<td width="100%" style="border:solid 2px #D2D2D2;padding:20px 0 20px 0;">
			<table cellpadding="0" cellspacing="0" width="100%" border="0" class="productdetails">
				<tr>
					<td align="center">
						<?php if($this->shop->store_logo == '' || null){ ?>
							<img src="<?php echo JURI::base().'/components/com_jegroupbuy/assets/images/shopping.jpg'; ?>" border="0">
						<?php } else { ?>
							<img width="200px" src="<?php echo JURI::base().'/images/jegroupbuy/storelogo/'.$this->shop->store_logo; ?>" border="0">
						<?php } ?>
					</td>
					<td width="45%" valign="top">
						<table cellpadding="0" cellspacing="0" width="100%" border="0" >
							<tr>
								<td width="100%" >
								<h2 style="margin:0px;padding:6px;"><?php echo $this->items->title; ?></h2>
								</td>
							</tr>
							<tr>
								<td width="100%" style="padding:10px 20px 0 0; ">
									<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td width="100%" style="border:solid 1px #CACACA;height:45px;">
												<table cellpadding="0" cellspacing="0" width="100%" border="0">
													<tr>
														<td width="33%" align="center" valign="middle">
															<table cellpadding="0" cellspacing="0" width="50%" border="0">
																<tr>
																	<td id="buynow_button_bg_left"></td>
																	<td id="buynow_button_bg" align="center" ><a style="text-decoration:none;" href="<?php echo $payment_url; ?>"><?php echo JText::_("COM_JEGROUPBUY_BUY"); ?></a></td>
																	<td id="buynow_button_bg_right"></td>
																</tr>
															</table>
														</td>
														<td width="33%" align="center" style="font-size:12px;font-weight:bold;"><?php echo sprintf(JText::_("COM_JEGROUPBUY_YOU_PAY"),$this->items->deal_price); ?></td>
														<td width="33%" align="center" style="font-size:12px;font-weight:bold;color:red;"><?php echo sprintf(JText::_("COM_JEGROUPBUY_YOU_SAVE"),$this->items->you_save); ?></td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td width="100%" style="border:solid 1px #CACACA;height:25px;" align="center">
												<?php
												$db	= JFactory::getDBO();

												$query = "SELECT count(*) FROM #__jegroupbuy_payment AS p WHERE p.p_id = ".$this->items->id;
												$db->setQuery($query);
												$number_of_bought		= $db->loadResult();

												$total_products = $this->items->total_bought;

												unset($deal_date_sp);
												$deal_date = JHTML::_('date',  $this->items->deal_to_date, "%Y-%m-%d");
												$deal_date_sp = explode("-",$deal_date);
												?>
												<span class="prod_timer">
													<script language="JavaScript" type="text/javascript">
													TargetDate = "<?php echo $deal_date_sp[1]; ?>/<?php echo $deal_date_sp[2]; ?>/<?php echo $deal_date_sp[0]; ?> 11:59 PM";
													BackColor = "palegreen";
													ForeColor = "navy";
													pID = "<?php echo $this->items->id; ?>";
													eCheck = "<?php echo $this->items->expired; ?>";
													CountActive = true;
													CountStepper = -1;
													LeadingZero = true;
													number_of_bought = "<?php echo $number_of_bought; ?>";
													total_products = "<?php echo $total_products; ?>";
													DisplayFormat = "%%D%% <?php echo JText::_("COM_JEGROUPBUY_DAYS"); ?>, %%H%% <?php echo JText::_("COM_JEGROUPBUY_HOURS"); ?>, %%M%% <?php echo JText::_("COM_JEGROUPBUY_MINUTES"); ?>, %%S%% <?php echo JText::_("COM_JEGROUPBUY_SECONDS"); ?>.";
													FinishMessage = "<span style='color:red;'><?php echo JText::_("COM_JEGROUPBUY_EXPIRED"); ?></span>";
													</script>
													<script language="JavaScript" src="components/com_jegroupbuy/assets/js/countdown.js" type="text/javascript"></script>
												</span>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td width="100%" style="padding:5px 20px 0 0;">
									<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td width="50%" style="border:solid 1px #CACACA;height:45px;">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<td  align="center" style="background-color:#0A6EAC;height:30px;color:#FFFFFF;font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_ACTUAL_VALUE"); ?></td>
													</tr>
													<tr>
														<td  align="center" style="height:30px;"><?php echo $this->items->product_price; ?></td>
													</tr>
												</table>
											</td>
											<td width="50%" style="border:solid 1px #CACACA;height:45px;">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<td  align="center" style="background-color:#58595B;height:30px;color:#FFFFFF;font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_BOUGHT"); ?></td>
													</tr>
													<tr>
														<td  align="center" style="height:30px;"><?php echo sprintf(JText::_("COM_JEGROUPBUY_NUMBER_OF_COUPONS"),$this->number_of_bought,$this->items->total_bought); ?></td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>

							<?php
							//echo "welcome".$settings->show_subscription;
							if($settings->show_share)
							{
								?>
							<tr>
								<td width="100%" style="padding:5px 20px 0 0;">
									<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td width="100%" style="border:solid 1px #CACACA;height:45px;">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<?php
															//$base	= JURI::root();
															//$link	= $base.JRoute::_('index.php?option=com_jegroupbuy&task=productdetails&pid='.$this->items->id.'&tmpl=component' , false);
														?>
														<td  align="left" style="padding-left:25px;height:30px;">
														<?php
															//JHtml::_('icon.email', $this->items->id, $params,$this->access);
															$pathimg=JURI::root()."components/com_jegroupbuy/assets/images/emailToFrnd.gif";
														?>

														<?php echo JText::_("COM_JEGROUPBUY_SHARE_WITH"); ?>&nbsp;<?php echo  "&nbsp;".$this->emailtoFriend."&nbsp;".$this->faceBook."&nbsp;".$this->twitter."&nbsp;"; ?></td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>

							<tr>
								<td width="100%" style="padding:5px 20px 0 0;">
									<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td width="50%" style="border:solid 1px #CACACA;height:45px;">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<td  align="center" style="background-color:#0A6EAC;height:30px;color:#FFFFFF;font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_SHOP_NAME"); ?></td>
													</tr>
													<tr>
														<td  align="center" style="background-color:#58595B;height:30px;color:#FFFFFF;font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_SHOP_URL"); ?></td>
													</tr>
												</table>
											</td>
											<td width="50%" style="border:solid 1px #CACACA;height:45px;">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<td  align="center" style="height:30px; border-bottom:solid 1px #CACACA;"><?php echo $this->shop->shop_name; ?></td>
													</tr>
													<tr>
														<td  align="center" style="height:30px;color:#FF0000;font-weight:bold;padding:5px;"><?php echo $this->shop->email; ?></td>
													</tr>
												</table>
											</td>
										</tr>
										<?php if($this->shop->shop_url !=  '' || null){ ?>
										<table>
											<tr>
												<td align="center" width="50%" style="color:red;font-weight:bold;padding:5px;"><?php echo JText::_("COM_JEGROUPBUY_SHOP_VISIT").'</p>'." : "; ?></td>
												<td  style="padding:5px;">
													<a rel="shadowbox" target="_blank" title= "<?php echo $this->shop->shop_url; ?>" text-decoration:"underline" align="center"  style="font-size:12px;" href= "<?php echo $this->shop->shop_url; ?>"><?php echo $this->shop->shop_url; ?></a>
												</td>
											</tr>
										</table>
										<?php } ?>
									</table>
								</td>
							</tr>
							<?php
							}
							//echo "welcome".$settings->show_subscription;
							if($settings->show_subscription)
							{
								if($this->com_count > 0)
								{
								?>
								<tr>
									<td width="100%" style="padding:5px 20px 0 0;">
										<table cellpadding="0" cellspacing="0" width="100%" border="0">
											<tr>
												<td width="100%" style="border:solid 1px #CACACA;height:45px;">
													<table cellpadding="0" cellspacing="0" border="0" width="100%">
														<tr>
															<td  align="left" style="padding-left:25px;height:30px;"><?php echo JText::_("COM_JEGROUPBUY_SUBSCRIBE_WITH"); ?>&nbsp;<?php echo $this->subscribeEmail."&nbsp;"; ?></td>
														</tr>
													</table>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<?php
								}
							}
							?>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<h2><?php echo JText::_("COM_JEGROUPBUY_PRODUCT_DESCRIPTION"); ?></h2>
		</td>
	</tr>
	<tr>
		<td>
			<?php echo $this->items->description; ?>
		</td>
	</tr>
<?php
if($settings->show_googlemap)
{
if($this->googlemap !="")
{
?>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<h2><?php echo JText::_("COM_JEGROUPBUY_GOOGLE_MAP"); ?></h2>
		</td>
	</tr>
	<tr>
		<td align="center">
			<?php echo $this->googlemap; ?>
		</td>
	</tr>
<?php
}
}
if($settings->show_comments )
{
?>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<h2><?php echo JText::_("COM_JEGROUPBUY_COMMENTS"); ?></h2>
		</td>
	</tr>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<div id="commentContainer">

		<table cellpadding="0" cellspacing="0" width="100%">
			<tr>
		<?php
		$k = 0;
		$bgclr = '';
		foreach($this->comments AS $row)
		{
		if($k == 0)
		{
			$bgclr = "#F8F8F8";
		}else
		{
			$bgclr = "#FAFDF5";
		}
		?>
		<tr>
			<td style="border: 1px solid rgb(0, 0, 0);background-color:<?php echo $bgclr; ?>;border-color:#F1F1F1;padding:5px 15px 5px 10px;">
				<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
						<td width="50%" style="padding:5px;border-bottom:dotted 1px #999999;">
							<b><?php echo $row->name; ?></b>&nbsp; <i><?php echo JHTML::_('date',$row->cdate, JText::_('DATE_FORMAT_LC4')); ?></i>
						</td>
					</tr>
					<tr>
						<td width="100%" style="padding:5px;">
							<?php
							$order   = array("\r\n", "\n", "\n\r", "\t");
							$replace = '<br/>';
							$comments = str_replace($order, $replace, $row->comments);
							$comments =  chunk_split ($comments,80, "<br/>");
							echo $comments;
							?>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<?php
			$k = 1 - $k;
		}
		?>
		</table>
			</div>
		</td>
	</tr>
<?php
	$user =& JFactory::getUser();
	if (!$user->get('guest')) {
		if($this->userid > 0)
		{
?>
	<tr>
		<td>
			<textarea cols="80" rows="6" name="comment"></textarea><br/>
		</td>
	</tr>
	<tr>
		<td align="left">
			<input onclick="addComment();" type="button" name="commentButton" class="button" value="add comments"/>
		</td>
	</tr>
<?php
 		}
	} else { ?>
		<tr>
			<td align="left">
				<?php echo JText::_("COM_JEGROUPBUY_LOGIN"); ?>
			</td>
		</tr>

<?php
	}
}
?>
</table>
</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<?php if($this->settings == '1') { ?>
<tr>
<td>
<p class="copyright" align="center">
	<?php require_once( JPATH_COMPONENT . DS . 'copyright' . DS . 'copyright.php' ); ?>
</p>
</td>
</tr>
<?php } ?>
</table>
<input type="hidden" name="path" value="<?php echo JURI::base();?>"/>
<input type="hidden" name="pid" value="<?php echo $this->items->id;?>"/>
</form>