<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
	<?php
	// BOF: Lango Added for template MOD
	if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
	$header_text = '&nbsp;'
	//EOF: Lango Added for template MOD
	?>
	<tr>
		<td>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
					<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_history.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
				</tr>
			</table>
		</td>
	</tr>
	<?php
	// BOF: Lango Added for template MOD
	}else{
	$header_text = HEADING_TITLE;
	}
	// EOF: Lango Added for template MOD
		if(!isset($hide_row_top)) {
	?>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	<?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
	?>
	<tr>
		<td>
		<script language=javascript>
		   function validateForm(frm)
		   {
			 var error_result="";
			 var address="";
			 if (frm.invite_list.length<=0){
				error_result="<?php echo addslashes(stripslashes(ERR_EMPTY_ADDRESS)); ?>";
				alert(error_result);
				return false;
			 }
			 for ($icnt=0;$icnt<frm.invite_list.length;$icnt++){
			 	address+=frm.invite_list.options[$icnt].value + ";";
			 }
			 frm.invite_address.value=address;
			 return true;
		   }
		   function addAddress(){
		   
		   	var error_result="";
		   	if (document.invite_friend.txt_name.value=="" || document.invite_friend.txt_email.value==""){
				error_result="<?php echo addslashes(stripslashes(ERR_EMPTY_EMAIL)); ?>";
			} else if (document.invite_friend.txt_email.value.indexOf("@",0)<0){
				error_result="<?php echo addslashes(stripslashes(ERR_INVALID_EMAIL)); ?>";
			}
			if (error_result!=""){
				alert(error_result);
				return;
			}
			
			var pos=document.invite_friend.invite_list.selectedIndex;
			var oOption = document.createElement("OPTION");
			var dataAdd=document.invite_friend.txt_name.value+":>"+document.invite_friend.txt_email.value;
			oOption.text=dataAdd;
			oOption.value=dataAdd;
			if(document.invite_friend.invite_list.add.length==2){
			 document.invite_friend.invite_list.add(oOption,null);
			}else {
			 document.invite_friend.invite_list.add(oOption,pos);
			}
			document.invite_friend.invite_list.selectedIndex=pos;
			document.invite_friend.txt_name.value="";
			document.invite_friend.txt_email.value=""
			//document.invite_friend.invite_list.add(oOption,null);
			//document.invite_friend.txt_name.value="";
			//document.invite_friend.txt_email.value="";
		   
		   }
		   function deleteAddress(){
		   sIndex=document.invite_friend.invite_list.selectedIndex;
		   	if (sIndex<0) return;
				document.invite_friend.invite_list.remove(sIndex);
			if (sIndex>0 && sIndex<document.invite_friend.invite_list.length-1)
				sIndex=sIndex+1;
			else if (sIndex>0)
				sIndex=sIndex-1;
			else if (sIndex>=document.invite_friend.invite_list.length) sIndex=document.invite_friend.invite_list.length-1;
				document.invite_friend.invite_list.selectedIndex=sIndex;
							
		  /* 	var iIndex;
			iIndex=document.invite_friend.invite_list.selectedIndex;
		   	if (!document.invite_friend.invite_list.selectedIndex>0)
				document.invite_friend.invite_list.remove(iIndex); */
		   }

		</script>
		<table border="0" cellspacing="0" cellpadding="2">
	    <?php 
			echo tep_draw_form('invite_friend',tep_href_link(FILENAME_SUBSCRIPTION_INVITE_FRIEND,'','SSL'),'post','onSubmit="return validateForm(this)"'); 
			echo '<input type="hidden" name="suID" value="' . $subscription_id . '">';
			echo '<input type="hidden" name="action" value="invite">';
			echo '<input type="hidden" name="invite_address" value="">';
	    ?>
			<tr>
				<td class="main"><?php echo TEXT_INVITE_DESCRIPTION; ?></td>
		    </tr>
			<tr>
				<td class="main"><?php echo tep_get_subscription_name($subscription_id); ?></td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr>
				<td class="main"><?php echo TEXT_INVITE_EMAIL;?></td>
			</tr>
			<tr>
				<td>
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
						<tr>
							<td class="main"><?php echo TEXT_INVITE_NAME . '&nbsp;' . tep_draw_input_field('txt_name','','size=25') . '&nbsp;&nbsp;';?> </td>
							<td class="main"><?php echo TEXT_INVITE_ADDRESS . '&nbsp;' . tep_draw_input_field('txt_email','','size=25')  . '&nbsp;&nbsp;';?></td>
							<td class="main"><?php echo '<a href="javascript:addAddress();">' . tep_template_image_button('button_add.gif',IMAGE_ADD_ADDRESS) . '</a>&nbsp;<a href="javascript:deleteAddress()">' . tep_template_image_button('button_delete.gif',IMAGE_DELETE_ADDRESS) . '<a>';?></td>
						</tr>
						<tr>
							<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
						</tr>
						<tr>
							<td class="main" colspan="3"><?php echo tep_draw_pull_down_menu('invite_list',array(),'','size=5 style="width:100%"');?></td>
						</tr>
					</table>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr>
				<td class="main"><?php echo TEXT_COMMENT;?></td>
			</tr>
			<tr>
				<td class="main"><?php echo tep_draw_textarea_field('invite_comments',false,'40','4'); ?><td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr>
				<td class="main"><?php echo TEXT_INVITE_NOTE; ?></td>
			</tr>
            <tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
            <?php 
				$message_query=tep_db_query("SELECT * from " . TABLE_SUBSCRIPTION_MESSAGES . " where subscription_id='" . $HTTP_GET_VARS['suID'] . "' and message_type='INV'");
				if (tep_db_num_rows($message_query)){
					$send_details=array();
					$message_result=tep_db_fetch_array($message_query);
					$send_details["text"]=$message_result["message_text"];
					$send_details["subscription_id"]=$subscription_id;
					$send_details["cID"]=$customer_id;
            ?>
						<tr>
							<td>
								<table border="0" width="100%" cellspacing="0" cellpadding="1" class="infoBox">
									<tr>
										<td>
											<table border="0" width="100%" cellspacing="0" cellpadding="4" class="infoBoxContents">
												<tr>
													<td class="main"><?php echo tep_replace_subscription_invite_mail_content($send_details); ?></td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
			<?php } ?>
			</table>
		</td>
	</tr>
	<?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>
	<?php 	$back_url=tep_href_link(FILENAME_ACCOUNT, '', 'SSL');	
			if (isset($HTTP_GET_VARS["path"])){
				if ($HTTP_GET_VARS["path"]=="ASC")
					$back_url=tep_href_link(FILENAME_ACCOUNT_SUBSCRIPTIONS, tep_get_all_get_params(array("path")), 'SSL');
				else if($HTTP_GET_VARS['path']!='ACC')
				     $back_url=tep_href_link(FILENAME_ACCOUNT_RESERVATIONS, tep_get_all_get_params(array("path")), 'SSL');		
			}
	?>
		<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 align=left class="main"><?php echo '<a href="' . $back_url . '">' . tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
								<td align=right class="main"><?php echo tep_template_image_submit('button_invite.gif', IMAGE_BUTTON_INVITE); ?></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</form>
</table>
