<table border="0" cellpadding="0" cellspacing="0" width="100%">
<?php
	include('includes/date_format_js.php');
	 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();"'); 
?>
<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 begins_date = document.cart_quantity.begins_date.value;
		var end_date = document.cart_quantity.end_date.value;
		var period = document.cart_quantity.period.value;
		var display_start_date = document.cart_quantity.display_start_date.value;
		var display_begins_date = document.cart_quantity.display_begins_date.value;
		var display_end_date = document.cart_quantity.display_end_date.value;
		
		var start_date_count = 0;
		var begins_date_count = 0;
		var end_date_count = 0;
		var currend_date_count = date_format(currend_date,'Y-m-d','',true).getTime();
		if(display_start_date!=0)start_date_count = date_format(start_date,'Y-m-d','',true).getTime();
		if(display_begins_date!=0)begins_date_count = date_format(begins_date,'Y-m-d','',true).getTime();
		if(display_end_date!=0)end_date_count = date_format(end_date,'d/m/y','',true).getTime();
		/*alert(currend_date_count);
		alert(start_date_count);
		alert(begins_date_count);
		alert(end_date_count);*/
		/*var begin_date = document.cart_quantity.begin_date.value;
		var split_date = begin_date.split("-");
		if(split_date[0]!=0)begin_date = document.cart_quantity.begin_date.value;
		var end_date = document.cart_quantity.end_date.value;
		var diff_date = document.cart_quantity.difference_date.value;
		var period_extends = document.cart_quantity.period_extends.value;*/
		if (document.cart_quantity.xsell_forced_item){
			if (!document.cart_quantity.xsell_forced_item.checked) error="<?php echo addslashes(ERROR_XSELL_FORCED);?>";
		} 
		/*if(document.cart_quantity.start_date_exceed.value=="exceeded"){
			if(begin_date==0)error = "<?php echo TEXT_ERR_SUBSCRIPTION_START;?>"+document.cart_quantity.start_date.value;
			else if(period_extends=="period_extends" && begin_date!=0){
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE;?> ("+begin_date+"<?php echo TEXT_BETWEEN;?>"+end_date+")";
			} else if(period_extends=="" && begin_date!=0){
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE;?> "+begin_date;
			}
		} else if(document.cart_quantity.begin_date_exceed.value=="exceeded"){
			if(period_extends=="period_extends"){
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE;?> ("+begin_date+"<?php echo TEXT_BETWEEN;?>"+end_date+")";
			} else {
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE;?> "+begin_date;
			}
		} else if(document.cart_quantity.end_date_exceed.value=="exceeded" && end_date!=0 && diff_date=="occure"){
			error = "<?php echo TEXT_ERR_SUBSCRIPTION_ENDS;?> "+begin_date;
		} else*/
		if(start_date_count > currend_date_count){
			if(begins_date_count==0)error = "<?php echo TEXT_ERR_SUBSCRIPTION_START;?>"+display_start_date;
			else if(begins_date_count!=end_date_count && begins_date_count!=0 && period!=0){
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE_FROM;?> "+display_begins_date+"<?php echo TEXT_BETWEEN;?>"+display_end_date;
			}else if(begins_date_count==end_date_count && begins_date_count!=0){
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE_AFTER;?> "+display_begins_date;
			}
		} else if(begins_date_count > currend_date_count){
			if(begins_date_count!=end_date_count){
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE_FROM;?> "+display_begins_date+"<?php echo TEXT_BETWEEN;?>"+display_end_date;
			} else {
				error = "<?php echo TEXT_ERR_FURTHEST_START_DATE_AFTER;?> "+display_begins_date;
			}
		} else if(end_date_count < currend_date_count && end_date!=0){
			error = "<?php echo TEXT_ERR_SUBSCRIPTION_ENDS;?> "+display_end_date;
		} else	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="<? 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'))); ?>";
	}
</script>
<?php
  if ($subscription_check['total'] < 1) {
?>
      <tr>
        <td><?php new infoBox(array(array('text' => TEXT_SUBSCRIPTION_NOT_FOUND))); ?></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_begins_attendance_period 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_begins_attendance_period'];
	if($att_period_result['subscription_begins_attendance_period'] > 0)
	$period_value -= 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_period,su.subscription_free_trial,su.subscription_free_days," .
											"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_begins_date,'" . $database_date_format . "') as display_begins_date,date_format(date_add(subscription_begins_date , INTERVAL " . $period_value . " DAY),'" . $database_date_format . "') as display_end_date, " . 
											" subscription_begins_date,su.subscription_begins_attendance_period,date_add(subscription_begins_date , INTERVAL " . $period_value . " DAY) as subscription_end_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(chr(13). chr(10),"<br>",addslashes(stripslashes($subscription_info['subscription_name']))) . '<p>';
	if ($subscription_info['subscription_conditions']!='') {
	    $conditions.='<b>' . addslashes(stripslashes(TEXT_CONDITIONS)) . '</b><br>' . str_replace(chr(13). chr(10),"<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>';
	if($subscription_info['subscription_start_date']!=0){
		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'] . '">';
	} else{
		echo '<input type="hidden" name="start_date" id="start_date" value="0">';
		echo '<input type="hidden" name="display_start_date" id="display_start_date" value="0">';
	}
	
	if($subscription_info['subscription_begins_date']!=0){
		echo '<input type="hidden" name="begins_date" id="begins_date" value="' . $subscription_info['subscription_begins_date'] . '">';
		echo '<input type="hidden" name="display_begins_date" id="display_begins_date" value="' . $subscription_info['display_begins_date'] . '">';
	} else{
		echo '<input type="hidden" name="begins_date" id="begins_date" value="0">';
		echo '<input type="hidden" name="display_begins_date" id="display_begins_date" value="0">';
	}
	
	if($subscription_info['subscription_end_date']!=0){
		echo '<input type="hidden" name="end_date" id="end_date" value="' . $subscription_info['subscription_end_date'] . '">';
		echo '<input type="hidden" name="display_end_date" id="display_end_date" value="' . $subscription_info['display_end_date'] . '">';
	} else{
		echo '<input type="hidden" name="end_date" id="end_date" value="0">';
		echo '<input type="hidden" name="display_end_date" id="display_end_date" value="0">';
	}
	
	if($subscription_info['subscription_begins_attendance_period']!=0)
		echo '<input type="hidden" name="period" id="period" value="' . $subscription_info['subscription_begins_attendance_period'] . '">';
	else
		echo '<input type="hidden" name="period" id="period" value="0">';
	echo '<input type="hidden" name="currend_date" id="currend_date" value="' . date('Y-m-d') . '">';	
	//$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);
	/*echo '<input type="hidden" name="start_date" id="start_date" value="' . $subscription_info['start_date'] . '">';
	echo '<input type="hidden" name="begin_date" id="begin_date" value="' . $subscription_info['begin_date'] . '">';
	echo '<input type="hidden" name="end_date" id="end_date" value="' . $subscription_info['end_date'] . '">';
	if($subscription_info['begin_count_date']==$subscription_info['end_count_date']){
		echo '<input type="hidden" name="period_extends" id="period_extends" value="">';
	} else {
		echo '<input type="hidden" name="period_extends" id="period_extends" value="period_extends">';
	}
	if($subscription_info['begin_count_date'] > $subscription_info['currend_date'] || $subscription_info['end_count_date'] < $subscription_info['currend_date']){
		if($subscription_info['begin_count_date']!="" && $subscription_info['begin_count_date']!=$subscription_info['end_count_date']){
			echo '<input type="hidden" name="difference_date" id="difference_date" value="occure">';
		} else {
		echo '<input type="hidden" name="difference_date" id="difference_date" value="">';
		}
	}else {
		echo '<input type="hidden" name="difference_date" id="difference_date" value="">';
		}
	if($subscription_info['start_count_date'] > $subscription_info['currend_date']){
		echo '<input type="hidden" name="start_start_date_exceed" id="start_date_exceed" value="exceeded">';
	} else {
		echo '<input type="hidden" name="start_date_exceed" id="start_date_exceed" value="">';
	}
	if($subscription_info['begin_count_date'] > $subscription_info['currend_date']){
		echo '<input type="hidden" name="begin_date_exceed" id="begin_date_exceed" value="exceeded">';
	} else {
		echo '<input type="hidden" name="begin_date_exceed" id="begin_date_exceed" value="">';
	}
	if($subscription_info['end_count_date'] < $subscription_info['currend_date']){
		echo '<input type="hidden" name="end_date_exceed" id="end_date_exceed" value="exceeded">';
	} else {
		echo '<input type="hidden" name="end_date_exceed" id="end_date_exceed" value="">';
	}*/
	$subscription_type_array=array(
							'T'=>TEXT_SUBSCRIPTION_TANGIBLE,
							'D'=>TEXT_SUBSCRIPTION_DIGITAL,
							'C'=>TEXT_SUBSCRIPTION_CASUAL,
							'S'=>TEXT_SUBSCRIPTION_SEASON);

?>
<?php
// BOF: WebMakers.com Added: Show Featured subscription
if (SHOW_HEADING_TITLE_ORIGINAL=='yes') {
$header_text = '&nbsp;';
?>
      <tr>
        <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading" valign="top"><?php echo $subscription_name; ?></td>
            <td class="pageHeading" align="right" valign="top"><?php echo $subscription_costs; ?></td>
          </tr>
        </table></td>
      </tr>
      <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
?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
      <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><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	  <tr>
	  	<td class="smallText" valign="top" width="60%"><?php echo '<b>' . TEXT_TYPE . '</b>&nbsp;&nbsp;&nbsp;' . $subscription_type_array[$subscription_info['subscription_type']];?></td>
	  	<td class="smallText" valign="top" width="40%"><?php echo '<b>' . TEXT_COSTS . '</b>' . $subscription_costs;?></td>
	  </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	  <tr>
	  	<td class="smallText" valign="top" width="60%"><?php echo '<b>' . TEXT_PERIOD . '</b>' . $subscription_details .'&nbsp;'. $subscription_info['subscription_period']. '&nbsp;' . TEXT_DAYS;?></td>
	  	<td class="smallText" valign="top" width="40%">
			<?php 
				if($subscription_info['subscription_start_date']!=0)echo '<b>' . TEXT_SUBSCRIPTION_BEGINS . '</b>' .  $subscription_info['display_start_date'];
			?>
		</td>
	  </tr>
	  <?php if ($subscription_info["subscription_free_trial"]=='Y') { ?>
		  <tr>
			<td><?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><?php echo tep_draw_separator('pixel_trans.gif', '100%', '20'); ?></td>
     </tr> 
	   <tr>
        <td><?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 . '<a id="agree" href="javascript:showConditions();" class="blue">' . TEXT_TERMS . '</a>';?>
	</tr>
      <tr>
        <td><?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
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
// EOF: Lango Added for template MOD
?>
      <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 class="main">&nbsp;</td>
                <td class="main" align="right"><?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"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
    </table>
<?php 
//Added for x sell
      include(DIR_WS_MODULES . FILENAME_XSELL_SUBSCRIPTIONS_BUYNOW);
} ?>
</form>
</table>