<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
include(DIR_WS_INCLUDES . 'http.js');?>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<?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_account.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><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	<tr>
		<td>
			<table cellpadding="2" cellspacing="0" border="0" width="100%">
				<tr>
					<td class="infoboxheading"><b><?php echo HEADING_SUPPORT_PACK;?></b></td>
					<td class="infoboxheading" align="right"><b><?php echo HEADING_DATE_PURCHASED;?></b></td>
				</tr>	
				<?php 
				if(tep_db_num_rows($support_pack_query)>0) {
					 while($support_pack_result=tep_db_fetch_array($support_pack_query)){ ?>
							<tr id="support_pack_<?php echo $support_pack_result['products_id'];?>_<?php echo $support_pack_result['orders_id'];?>" height="25" class="moduleRow" style="cursor:hand; cursor:pointer" onmouseout="rowOutEffect(this);" onmouseover="rowOverEffect(this);" onClick="do_fetch_pack('get_software_pack','<?php echo $support_pack_result['products_id'];?>','<?php echo $support_pack_result['orders_id'];?>');">
								<td class="main"><?php echo $support_pack_result['products_name'];?></td>
								<td class="main" align="right"><?php echo format_date($support_pack_result['date_purchased']);?></td>
							</tr>
							<tr><td colspan="2" align="center" class="main"><div id="software_pack_<?php echo $support_pack_result['products_id'];?>_<?php echo $support_pack_result['orders_id'];?>" style="display:none; padding-left:10px"></div></td></tr>
					<?php } ?>
					<tr><td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_SUPPORT_PACKS);?></td><td class="smallText" align="right"><table cellpadding="0" cellspacing="0"><tr><td class="smallText"><?php echo TEXT_RESULT_PAGE ?></td><td class="pageNavigation"><?php echo  $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS);?></td></tr></table></td></tr>
				<?php } else {?>
					<tr><td class="main" align="center" colspan="2"><?php echo TEXT_NO_ITEMS; ?></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
	?>
</table>
<script>
var prev_id='';
var prev_sp_id='';
var prev_spl_id='';
	function rowOverEffect(object) {
	  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
	}
	
	function rowOutEffect(object) {
	  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
	}
	
	function do_fetch_pack(action,pid,oid){
		var command='';
		prev_sp_id='';
		prev_spl_id='';
		if(document.getElementById('software_pack_' + pid + '_' + oid).innerHTML!=''){
			document.getElementById('software_pack_' + pid + '_' + oid).innerHTML=''
			document.getElementById('software_pack_' + pid + '_' + oid).style.display='none';
		} else {	
			if(prev_id!=(pid + '_' + oid)){
				if(prev_id!=''){
					document.getElementById('software_pack_' + prev_id).style.display="none";
					document.getElementById('software_pack_' + prev_id).innerHTML="";
					document.getElementById('support_pack_' + prev_id).className="moduleRow";
				}
				document.getElementById('software_pack_' + pid + '_' + oid).style.display="";
				document.getElementById('support_pack_' + pid + '_' + oid).className="moduleRowSelected";
				document.getElementById('software_pack_' + pid + '_' + oid).innerHTML="Loading...";
				prev_id=pid + '_' + oid;
			}
			switch(action){
				case 'get_software_pack':
					command="<?php echo tep_href_link(FILENAME_SUPPORT_PACKS_LIST,'command=get_software_pack','NONSSL',true,false)?>" + "&pid=" + pid + "&oid=" + oid;
				break;
			}
		}
		if(command!='') do_get_command(command);
	}
	
	function do_result(result){//alert(result);
		var splt_array=result.split('{^{}^}');
		switch(splt_array[0]){
			case 'get_software_pack':
				document.getElementById('software_pack_' + splt_array[1]).style.display="";
				document.getElementById('software_pack_'+splt_array[1]).innerHTML=splt_array[2];
			break;
			case 'get_software_license':
				document.getElementById('sp_license_' + splt_array[1]).style.display="";
				document.getElementById('sp_license_'+splt_array[1]).innerHTML=splt_array[2];
			break;
			case 'open_license':
				document.getElementById('license_edit_' + splt_array[1]).style.display="";
				document.getElementById('license_edit_'+splt_array[1]).innerHTML=splt_array[2];
				document.getElementById('active_' + splt_array[1]).innerHTML='<?php echo tep_template_image('icon_active.gif');?>';
			break;
			case 'save_license':
				if(splt_array[1]=='error'){
				document.getElementById('license_edit_' + splt_array[2]).style.display="";
				document.getElementById('license_edit_'+splt_array[2]).innerHTML=splt_array[3];
				document.getElementById('active_' + splt_array[2]).innerHTML='<?php echo tep_template_image('icon_active.gif');?>';
				} else {
					document.getElementById('sp_license_' + splt_array[1]).style.display="";
					document.getElementById('sp_license_'+splt_array[1]).innerHTML='';
					document.getElementById('sp_license_'+splt_array[1]).innerHTML=splt_array[2];
				}
			break;
		}
	}
	
	function do_fetch_license(action,sp_id){
		var command='';
		
		switch(action){
			case 'get_software_license':
			prev_spl_id='';
				if(document.getElementById('sp_license_' + sp_id).innerHTML!=''){
					document.getElementById('sp_license_' + sp_id).innerHTML=''
					document.getElementById('sp_license_' + sp_id).style.display='none';
				} else {	
					if(prev_sp_id!=sp_id) {
						if(prev_sp_id!=''){
							document.getElementById('sp_license_' + prev_sp_id).style.display="none";
							document.getElementById('sp_license_' + prev_sp_id).innerHTML="";
							document.getElementById('packs_' + prev_sp_id).className="moduleRow";
						}
						document.getElementById('sp_license_' + sp_id).style.display="";
						document.getElementById('packs_' + sp_id).className="moduleRowSelected";
						document.getElementById('sp_license_' + sp_id).innerHTML="Loading...";	
						prev_sp_id=sp_id;
					}
					command='<?php echo tep_href_link(FILENAME_SUPPORT_PACKS_LIST,'command=get_software_license','NONSSL',true,false);?>' + '&sp_id=' + sp_id;
				}	
			break; 
			case 'open_license':
				if(document.getElementById('license_edit_' + sp_id).innerHTML!='') {
					document.getElementById('license_edit_' + sp_id).innerHTML='';
					document.getElementById('license_edit_' + sp_id).style.display='none';
					document.getElementById('active_' + sp_id).innerHTML='<?php echo tep_template_image('icon_inactive.gif');?>';
				} else {	
					if(prev_spl_id!=sp_id) {
							if(prev_spl_id!=''){
								document.getElementById('license_edit_' + prev_spl_id).style.display="none";
								document.getElementById('license_edit_' + prev_spl_id).innerHTML="";
								//document.getElementById('spl_' + prev_spl_id).className="moduleRow";
							}
							document.getElementById('license_edit_' + sp_id).style.display="";
							//document.getElementById('spl_' + sp_id).className="moduleRowSelected";
							document.getElementById('license_edit_' + sp_id).innerHTML="Loading...";	
							prev_spl_id=sp_id;
					}
				command='<?php echo tep_href_link(FILENAME_SUPPORT_PACKS_LIST,'command=open_license','NONSSL',true,false);?>' + '&lid=' + sp_id;
				}
			
			break;
		}
		if(command!='') do_get_command(command);
	}
	function validateForm(){ //alert('hai');
	var email_address;
	var error_msg='';
	var command='';
	var domain_name;
	email_address=document.license.email_address.value;
	domain_name=document.license.domain_name.value
		if(domain_name=='')
			error_msg+='* <?php echo ERR_DOMAIN_NAME;?>\n';
		else {
			 var url = domain_name.match(/^https?:\/\/[a-z0-9]([-_.]?[a-z0-9])+[.][a-z0-9][a-z0-9\/=?.&\~_-]+$/);
			 if(url == null) {
				error_msg +="* <?php echo INVALID_DOMAIN_NAME;?>\n";
			 }
		}
		if(document.license.customer_name.value=='')
			error_msg+='* <?php echo ERR_CUSTOMER_NAME?>\n';
		if(document.license.email_address.value=='')
			error_msg+='* <?php echo ERR_EMAIL_ADDRESS;?>\n';
		else if(email_address.length<	'<?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>'	)
			error_msg+='* <?php echo ENTRY_EMAIL_ADDRESS_ERROR;?>\n';
		else if(email_address.indexOf('@')<=0 || email_address.indexOf('.')<=0)
			error_msg+='* <?php echo INVALID_EMAIL;?>';
		if(error_msg!=''){
			alert(error_msg);
			return false;
		} else {
			command='<?php echo tep_href_link(FILENAME_SUPPORT_PACKS_LIST,'command=save_license','NONSSL',true,false);?>' + '&lid=' + document.license.license_id.value;
			do_post_command('license',command);
			return false;
		}	
		return false;		
	}
	
	
</script>