<?php

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
 require(DIR_WS_JAVASCRIPT . "general.js");
      require(DIR_WS_INCLUDES . "date-picker.js");
	  include(DIR_WS_INCLUDES.'date_format_js.php');
	  
	  //Hide the Store Membership subscription in the front end. and redirect to shopping cart page 
	  if(isset($HTTP_GET_VARS['stored_flag'])&& $HTTP_GET_VARS['stored_flag']=='y')
	  {
	  echo tep_draw_form('shopping_cart', tep_href_link(FILENAME_SHOPPING_CART, tep_get_all_get_params(array('subs_action','subscription_id')) . 'subs_action=add_subscription'),'post','onSubmit="return validateForm();"'); 

	  echo '<input type=hidden name="subscription_id" value='.$HTTP_GET_VARS['subscription_id'].'>';
	  echo '<input type="hidden" name="your_start_date" id="your_start_date" value="' . date(EVENTS_DATE_FORMAT) . '">';
		?>
		</form>
		<script >
		document.shopping_cart.submit();
		</script>
	  <?php 
	  }
	  //Added line 5-9, 12-23 by sobi
	/*if(isset($HTTP_POST_VARS['events_id']) && $HTTP_POST_VARS['events_id'] >0)
		 echo tep_draw_form("checkout_event",tep_href_link(FILENAME_CHECKOUT_EVENT,tep_get_all_get_params() . "event_action=buy_product&element_type=E"),'post','onSubmit="return validateForm();"');
	else if($services->service_id>0)
		echo tep_draw_form("add_service",tep_href_link(FILENAME_SHOPPING_CART,tep_get_all_get_params().'service_action=buy_service&service_id='.$services->service_id),'post','onSubmit="return validateForm();"');
	else */
	   echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SUBSCRIPTION_INFO, tep_get_all_get_params(array('subs_action','subscription_id')) . 'subs_action=add_subscription'),'post','onSubmit="return validateForm();"'); 
	   
	if($HTTP_POST_VARS['events_id']>0){
		reset($HTTP_POST_VARS);
		while(list($key,$value)=each($HTTP_POST_VARS)){
			if (is_array($value)){
				for ($icnt=0;$icnt<count($value);$icnt++){
					echo tep_draw_hidden_field($key . "[]",$value[$icnt]);	
				}
			} else {
				echo tep_draw_hidden_field($key,$value);
			}
		}
	}
?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB;?>">
<script language="javascript">
	var conditions;
	function validateForm(){
		var error="";
		var currend_date = document.cart_quantity.currend_date.value;
		var start_date = document.cart_quantity.start_date.value;
		var finish_date = document.cart_quantity.finish_date.value;
		var latest_start_date = document.cart_quantity.latest_start_date.value;
		
		var subscription_type = document.cart_quantity.subscription_type.value;
		var subscription_period = document.cart_quantity.subscription_period.value;
		var subscription_date_type = document.cart_quantity.subscription_date_type.value;
		var deliveries_perday = document.cart_quantity.deliveries_perday.value;
		var deliveries_perday_date = document.cart_quantity.deliveries_perday_date.value;
		
		var display_start_date = document.cart_quantity.display_start_date.value;
		var display_finish_date = document.cart_quantity.display_finish_date.value;
		var display_latest_start_date = document.cart_quantity.display_latest_start_date.value;
		var your_start_date = document.cart_quantity.your_start_date.value;
		var your_start_date_count = '';
		if(your_start_date!=""){
			var date_error = true;
			if((your_start_date).indexOf("-")!=-1){
				date_error = IsValidDate(date_format(your_start_date,'','d-m-Y'),'dd-mm-YYYY');
			} else {
				date_error = false;
			}
			if(!(date_error)){
				alert("* <?php echo ERR_START_DATE;?>");
				return false;
			} else {
				your_start_date_count = date_format(your_start_date,'','',true).getTime();
			}
		}
		var start_date_count = 0;
		var finish_date_count = 0;
		var latest_start_date_count = 0;
		var deliveries_perday_date_count = 0;
		var currend_date_count = date_format(currend_date,'','',true).getTime();
		if(your_start_date_count=="")your_start_date_count = date_format(currend_date,'','',true).getTime();
		if(display_start_date!=0)start_date_count = date_format(start_date,'Y-m-d','',true).getTime();
		if(display_finish_date!=0){
			finish_date_count = date_format(finish_date,'Y-m-d','',true).getTime();
			if(finish_date_count>0){
				deliveries_perday_date_count = date_format(deliveries_perday_date,'','',true).getTime();
			}else{
				alert("Invalid Subscription Start and End Date");
				return false;
			}
		}
		if(display_latest_start_date!=0)latest_start_date_count = date_format(latest_start_date,'Y-m-d','',true).getTime();
		if (document.cart_quantity.xsell_forced_item){
			if (!document.cart_quantity.xsell_forced_item.checked) error="<?php echo addslashes(ERROR_XSELL_FORCED);?>";
		}
		if(subscription_date_type == 'F' && subscription_type != 'C'){
			if(currend_date_count >= start_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_FIXED_NON_CASUAL);?>";
			}
		} else if(subscription_date_type == 'F' && subscription_type == 'C'){
			if(currend_date_count >= deliveries_perday_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_FIXED_CASUAL);?>";
			}
		} else if(subscription_date_type == 'L' && subscription_type != 'C'){
			if(currend_date_count >= latest_start_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_FLEXIBLE_NON_CASUAL);?>";
			}
		} else if(subscription_date_type == 'L' && subscription_type == 'C'){
			if(currend_date_count >= deliveries_perday_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_FLEXIBLE_CASUAL);?>";
			}
		} else if(subscription_date_type == 'P' && subscription_type != 'C'){
			if(your_start_date_count < start_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_PREDEFINED_START);?>";
			} else if(your_start_date_count > latest_start_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_PREDEFINED_NON_CASUAL);?>";
			}
		} else if(subscription_date_type == 'P' && subscription_type == 'C'){
			if(your_start_date_count < start_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_PREDEFINED_START);?>";
			} else if(your_start_date_count > deliveries_perday_date_count){
				error = "<?php echo addslashes(TEXT_ERR_SUBSCRIBE_PREDEFINED_CASUAL);?>";
			}
		}
		if (error!=""){
			alert(error);
			return false;
		}
		error = "";
		if (error=="" && !document.cart_quantity.agreed.checked){
			error = "<?php echo addslashes(TEXT_ERR_AGREED);?>";
		} 
		if (error!=""){
			alert(error);
			return false;
		}
		return true;
	}
	
	function showConditions(){
		var handle;
		var feats;
		vtop=screen.availHeight /2 - screen.availHeight /6;
		vleft=screen.availWidth/2 - screen.availWidth/6;
		feats="height=350,width=350,location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,status=no,left=" + vleft + ",top=" + vtop ;	
		handle=window.open("","conditions",feats);
		handle.document.open();
		handle.document.write('<html><head><title>Conditions</title><base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"><link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE_STYLE;?>"></head>');
		handle.document.write('<body class="conditions"><div class="main">');
		handle.document.write(conditions);
		handle.document.write('</div></body></html>');
		handle.document.close();
	}
	function free_trial(){
		if (!document.cart_quantity.agreed.checked){
			error="<?php echo addslashes(TEXT_ERR_AGREED);?>";
			alert(error);
			return;
		} 
		location.href="<?php echo tep_href_link(FILENAME_SUBSCRIPTION_TRIAL_CONFIRM,tep_get_all_get_params(array('subs_action'))); ?>";
	}
	function do_show(obj){  // added by sobi 
		if(obj.checked){ 
			document.getElementById('subs_info').style.display='none';
			document.getElementById('btn_cart').style.display='none';
			document.getElementById('btn_continue').style.display='';
		}else{
		 	document.getElementById('subs_info').style.display='';
			document.getElementById('btn_cart').style.display='';
			document.getElementById('btn_continue').style.display='none';
		 }
	}
</script>
<?php
  if ($subscription_check['total'] < 1) {
?>
      <tr>
        <td class="main" align="center"><b><?php new infoBox(array(array('text' => TEXT_SUBSCRIPTION_NOT_FOUND))); ?></b></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_template_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
<?php
  } else {
  	$split_date_format = split("-",EVENTS_DATE_FORMAT);
	$database_date_format = '';
	for($i=0;$i<sizeof($split_date_format);$i++){
		$database_date_format .= "%" . $split_date_format[$i];
		if($i!=(sizeof($split_date_format)-1))
			$database_date_format .= "-";
	}
	if($database_date_format=='')$database_date_format='%d-%m-%Y';
	$att_period_query = tep_db_query("select subscription_period,deliveries_perday from " . TABLE_SUBSCRIPTIONS . " where subscription_id = '" . (int)$HTTP_GET_VARS['subscription_id'] . "'");
	$att_period_result = tep_db_fetch_array($att_period_query);
	$period_value = $att_period_result['subscription_period'];
	$deliveries_perday = $att_period_result['deliveries_perday'];
	if($att_period_result['subscription_period'] > 0)
	$period_value -= 1;
	if($att_period_result['deliveries_perday'] > 0)
	$deliveries_perday -= 1;
  	$subscription_info_sql = "select su.subscription_id, sud.subscription_name, sud.subscription_description, su.subscription_image, sud.subscription_url, su.subscription_costs, su.subscription_tax_class_id, su.subscription_date_added, su.subscription_date_available, " .
											" su.subscription_free_trial,su.subscription_free_days,su.deliveries_perday, " .
											" date_format(date_sub(date_format(su.subscription_finish_date,'%Y-%m-%d'),INTERVAL " . $deliveries_perday . " DAY),'" . $database_date_format . "') as deliveries_perday_date, " .
											"su.subscription_type,su.subscription_conditions,su.subscription_start_date,date_format(su.subscription_start_date,'" . $database_date_format . "') as display_start_date, " .
											" date_format(su.subscription_finish_date,'" . $database_date_format . "') as display_finish_date, " . 
											" subscription_finish_date,su.subscription_period,su.subscription_date_type,su.subscription_latest_start_date, " .
											" date_format(su.subscription_latest_start_date,'" . $database_date_format . "') as display_latest_start_date " .
											" from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where su.subscription_status = '1' and su.subscription_id = '" . (int)$HTTP_GET_VARS['subscription_id'] . "' and sud.subscription_id = su.subscription_id and sud.language_id = '" . (int)$languages_id . "'";
	//echo $subscription_info_sql;
	$subscription_info_query = tep_db_query($subscription_info_sql);
    $subscription_info = tep_db_fetch_array($subscription_info_query);
    tep_db_query("update " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " set subscription_viewed = subscription_viewed+1 where subscription_id = '" . (int)$HTTP_GET_VARS['subscription_id'] . "' and language_id = '" . (int)$languages_id . "'");
    $subscription_costs = $currencies->display_price($subscription_info['subscription_costs'], tep_get_tax_rate($subscription_info['subscription_tax_class_id']));
    $subscription_name = $subscription_info['subscription_name'];
 	 $conditions="<table height='90%' border=0 width=100% align=center><tr><td class=main height=70 valign=top>";
  	 $conditions.='<b>' . addslashes(stripslashes(TEXT_SUBSCRIPTION_NAME)) . '</b><br>' . str_replace("\n","<br>",addslashes(stripslashes($subscription_info['subscription_name']))) . '<p>';
	if ($subscription_info['subscription_conditions']!='') {
	    $conditions.='<b>' . addslashes(stripslashes(TEXT_CONDITIONS)) . '</b><br>' . str_replace("\n","<br>",addslashes(stripslashes($subscription_info['subscription_conditions']))) .  '<p>';
	}
	$conditions.='</td></tr></table><table width="100%"><tr><td align="right" class="main"><a href="javascript:window.close();">[ close ]</a></td></tr></table>';
	$conditions.="</table>";
	echo '<script language="javascript">conditions="'. addslashes(stripslashes($conditions)) .'"</script>';

	echo '<input type="hidden" name="start_date" id="start_date" value="' . $subscription_info['subscription_start_date'] . '">';
	echo '<input type="hidden" name="display_start_date" id="display_start_date" value="' . $subscription_info['display_start_date'] . '">';
	
	echo '<input type="hidden" name="finish_date" id="finish_date" value="' . $subscription_info['subscription_finish_date'] . '">';
	echo '<input type="hidden" name="display_finish_date" id="display_finish_date" value="' . $subscription_info['display_finish_date'] . '">';
	
	echo '<input type="hidden" name="latest_start_date" id="latest_start_date" value="' . $subscription_info['subscription_latest_start_date'] . '">';
	echo '<input type="hidden" name="display_latest_start_date" id="display_latest_start_date" value="' . $subscription_info['display_latest_start_date'] . '">';
		
	echo '<input type="hidden" name="subscription_date_type" id="subscription_date_type" value="' . $subscription_info['subscription_date_type'] . '">';
	echo '<input type="hidden" name="subscription_period" id="subscription_period" value="' . $subscription_info['subscription_period'] . '">';
	echo '<input type="hidden" name="subscription_type" id="subscription_type" value="' . $subscription_info['subscription_type'] . '">';
	echo '<input type="hidden" name="deliveries_perday" id="deliveries_perday" value="' . $subscription_info['deliveries_perday'] . '">';
	echo '<input type="hidden" name="deliveries_perday_date" id="deliveries_perday_date" value="' . $subscription_info['deliveries_perday_date'] . '">';
	
	echo '<input type="hidden" name="currend_date" id="currend_date" value="' . date(EVENTS_DATE_FORMAT) . '">';
	
	$filter_array=array('start_date','display_start_date','finish_date','display_finish_date','latest_start_date','display_latest_start_date','subscription_date_type','subscription_period','subscription_type','deliveries_perday','deliveries_perday_date');
	$POST_HIDDEN='';
	tep_get_post_vars($HTTP_POST_VARS,'',$filter_array);
	echo $POST_HIDDEN;
	
	// product hidden values for linked subscriiption  Added line 243-252 by sobi
	/* if (isset($HTTP_POST_VARS['attrValues']) && isset($HTTP_POST_VARS['attrIds'])){
		for ($icnt=0,$n=count($HTTP_POST_VARS['attrValues']);$icnt<$n;$icnt++){
			echo '<input type="hidden" name="attrIds[]"  value="' . $HTTP_POST_VARS['attrIds'][$icnt] . '">';
			echo '<input type="hidden" name="attrValues[]"  value="' . $HTTP_POST_VARS['attrValues'][$icnt] . '">';
		}
	}
	echo '<input type="hidden" name="products_id" id="products_id" value="' . $HTTP_POST_VARS['products_id'] . '">';
	echo '<input type="hidden" name="product_stock" id="product_stock" value="' . $HTTP_POST_VARS['product_stock'] . '">';
	echo '<input type="hidden" name="attribute_stock" id="attribute_stock" value="' . $HTTP_POST_VARS['attribute_stock'] . '">';
	*/
	
	$subscription_type_array=array(
							'B'=>TEXT_SUBSCRIPTION_BASIC,
							//'D'=>TEXT_SUBSCRIPTION_DIGITAL,
							'C'=>TEXT_SUBSCRIPTION_CASUAL,
							'S'=>TEXT_SUBSCRIPTION_SEASONAL);

?>
<?php
// BOF: WebMakers.com Added: Show Featured subscription
if (SHOW_HEADING_TITLE_ORIGINAL=='yes') {
$header_text = '&nbsp;';
?>
      
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php
}else{
$header_text =  $subscription_name  .'<br>' . tep_draw_separator('pixel_trans.gif', '100%', '4');
}
?>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD    Added line 282 - 295 by sobi
if($subscription_info['subscription_type']=='M' && !tep_session_is_registered('customer_id'))
{
?>
 <tr>
		<td>
			<table border="0" cellpadding="2" cellspacing="2">
				<tr>
					<td><?php echo tep_draw_checkbox_field('member_subs','Y','','onclick="javascript:do_show(this);"'); ?></td>
					<td class="main">Already subscribed this Store Member subscription</td>
				</tr>
			</table>
		</td>
	</tr>
<?php }?>
	<table border="0" cellpadding="2" cellspacing="0" width="100%" id="subs_info">
      <tr>
        <td class="main" valign="top" colspan="2">
<?php
    if (tep_not_null($subscription_info['subscription_image'])) {
?>
          <table border="0" cellspacing="0" cellpadding="2" align="right">
            <tr>
              	<td>
					<?php echo tep_image(DIR_WS_IMAGES . $subscription_info['subscription_image'] , $subscription_info['subscription_image'])?>
				</td>
			</tr>
          </table>
<?php
    }
?>
          <p><?php echo stripslashes($subscription_info['subscription_description']); ?></p>
        </td>
      </tr>
	  
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	  <!--<tr>
	  	<td class="smallText" valign="top" width="100%" colspan="2">
			<?php echo '<b>' . TEXT_TYPE . '</b>&nbsp;' . $subscription_type_array[$subscription_info['subscription_type']];?>
		</td>
	  </tr>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>-->
	  <tr>
	  	<td class="smallText" valign="top" width="100%" colspan="2">
			<?php echo '<b>' . TEXT_COSTS . '</b>&nbsp;' . $subscription_costs;?>
		</td>
	  </tr>
	<?php 
		if(($subscription_info['subscription_type']=='S' && $subscription_info['subscription_date_type']!='F') || $subscription_info['subscription_type']=='B'){
	?>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td class="smallText" valign="top" width="100%" colspan="2">
				<?php echo '<b>' . TEXT_SUBSCRIPTION_PERIOD . '</b>&nbsp;' . $subscription_info['subscription_period'] . '&nbsp;' . TEXT_DAYS;?>
		</td>
      </tr>
	  <?php
	    	}
      ?>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	  <tr>
	  	<td class="smallText" valign="top" width="100%" colspan="2"><?php echo $subscription_details;?></td>
	  </tr>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	  <?php  if($subscription_info['subscription_date_type']=='P'){?>
	  <tr>
	  	<td valign="top" colspan="2">
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr>
			<td valign="top" class="smallText" width="100%" colspan="2">
			<?php 
				$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);
				echo TEXT_ENTER_YOUR_SUBSCRIBE_DATE . '&nbsp;';
				echo tep_draw_input_field("your_start_date",date(EVENTS_DATE_FORMAT)," size=10 id='your_start_date' onblur='check_date()'",false,'text',false);
			?>
			<a href="javascript:show_calendar('cart_quantity.your_start_date',null,null,'<?php echo $date_format;?>');"
			   onmouseover="window.status='Date Picker';return true;"
			   onmouseout="window.status='';return true;" onblur="check_date()"><?php echo tep_image(DIR_WS_IMAGES .'icon_calendar.gif');?>  
			</a><?php echo '<input type="hidden" name="to_date" id="to_date" value="" size="10" align="left" disabled="true">';?>
			</td>
		</tr>
		</table>
		</td>
	  </tr>
	  	<?php 
	  		} else{
				echo '<input type="hidden" name="your_start_date" id="your_start_date" value="' . date(EVENTS_DATE_FORMAT) . '">';
			}
		?>
	  <?php if ($subscription_info["subscription_free_trial"]=='Y') { ?>
		  <tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '20'); ?></td>
		  </tr>
		  <tr>
			<td class="smallText" valign="top" colspan="2">
				<?php 
					echo sprintf(TEXT_INFO_FREE_TRIAL,$subscription_info["subscription_free_days"]) .'<br><br>';
					echo '<a href="javascript:free_trial();">' . tep_template_image_button('button_free_trial.gif',IMAGE_FREE_TRIAL) . '</a>';
				?>
			</td>
		  </tr>
	  <?php } ?>
	  <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '20'); ?></td>
     </tr> 
	<tr>
		<td class="main" valign="middle" colspan="2"><?php echo tep_draw_checkbox_field('agreed','1',false) . TEXT_AGREEMENT . '<b><a id="agree" href="javascript:showConditions();" class="infoBoxHeadingPage">' . TEXT_TERMS . '</a></b>';?>
	</tr>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '20'); ?></td>
      </tr>
<?php

    if (tep_not_null($subscription_info['subscription_url'])) {
?>
      <tr>
        <td class="main" colspan="2"><?php echo sprintf(TEXT_MORE_INFORMATION, tep_href_link(FILENAME_REDIRECT, 'action=url&goto=' . urlencode($subscription_info['subscription_url']), 'NONSSL', true, false)); ?></td>
      </tr>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php
    }

    if ($subscription_info['subscription_date_available'] > date('Y-m-d H:i:s')) {
?>
      <tr>
        <td align="center" class="smallText" colspan="2"><?php echo sprintf(TEXT_DATE_AVAILABLE, tep_date_long($subscription_info['subscription_date_available'])); ?></td>
      </tr>
<?php
    } else {
?>
      <tr>
        <td align="center" class="smallText" colspan="2"><?php echo sprintf(TEXT_DATE_ADDED, tep_date_long($subscription_info['subscription_date_added'])); ?></td>
      </tr>
<?php
    }
?>
</table>
<?php if($subscription_info['subscription_date_type']=='P'){?>
	<script language="javascript" type="text/javascript">
		check_date();
		function check_date(){
		var your_choose_date = document.cart_quantity.your_start_date.value;
		var forward_period = document.cart_quantity.subscription_period.value;
			if(your_choose_date!=""){
				var date_error = true;
				if((your_choose_date).indexOf("-")!=-1){
					date_error = IsValidDate(date_format(your_choose_date,'','d-m-Y'),'dd-mm-YYYY');
				} else {
					date_error = false;
				}
				if(!(date_error)){
					alert("* <?php echo ERR_START_DATE;?>");
					return false;
				} else {
					var check_date = new Date();
					var split_date = document.cart_quantity.your_start_date.value.split("-");
					check_date.setDate(split_date[0]);check_date.setMonth(split_date[1]-1);check_date.setYear(split_date[2]);
					check_date.setMinutes(0);check_date.setSeconds(0);check_date.setHours(0);check_date.setMilliseconds(0);
					var to_forward_period = 1;
					if(forward_period != 0)to_forward_period = forward_period;
					var day = DateAdd('d',to_forward_period-1,check_date).getDate();
					var month = DateAdd('d',to_forward_period-1,check_date).getMonth();
					var year = DateAdd('d',to_forward_period-1,check_date).getYear();
					month +=1;
					//day -=1;if(day!=1)
					if(year<1000)year +=1900;
					if(day<10)day = 0+""+day;
					if(month<10)month = 0+""+month;
					document.cart_quantity.to_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
				}
			}
		}
	
	</script>
<?php }
// BOF: Lango Added for template MOD

// EOF: Lango Added for template MOD
?>
      <tr>
        <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td colspan="2"><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
		
		<tr >
		<?php 
		//linked subscription
		$sub_query = tep_db_query("select * from " . TABLE_PRODUCTS_TO_SUBSCRIPTION . " where products_id = '" . tep_db_input(tep_db_prepare_input($HTTP_POST_VARS['products_id'])). "' ");
		if(tep_db_num_rows($sub_query) > 0){
        $check_sub = tep_db_fetch_array($sub_query);
		$link_subid=$check_sub['subscription_id'];
		
		if($link_subid == $subscription_info['subscription_id']) { ?>
		<td class="main"><b>This subscription was linked  to the product and for further processing add the Subscription also.</b></td>
		<?php }
		} ?>
		</tr>
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td width="10" nowrap="nowrap"> <?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main">&nbsp;</td>
                <td class="main" align="right" id="btn_cart"><?php echo tep_draw_hidden_field('subscription_id', $subscription_info['subscription_id']) . tep_template_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
                <td width="10" id="btn_continue" style="display:none"><a href="<?php echo FILENAME_SUBSCRIPTION_INFO . '?action=set_subscribe';?>"><?php echo tep_template_image_button('button_continue.gif', IMAGE_BUTTON_IN_CART); ?></a></td><!-- Added by sobi-->
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php 
//Added for x sell
      include(DIR_WS_MODULES . FILENAME_XSELL_SUBSCRIPTIONS_BUYNOW);
}
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
 ?>

</form>
