<HTML><HEAD>
<%
use strict;
my $refseq = $Request->QueryString('db');
my $table = $Request->QueryString('table');
$table =~ s/\.\.//g;
my $doc_dir = "./data/";   ###this information should be stored in a config file
my $space="&nbsp;";

unless ($table && open(TAB, "< $doc_dir$table")) {
	print "<h2>Error: Can't find this table!</h2>";
    $Response->End();
    exit;
}
my $txtfile ='';
while(<TAB>){
	unless (/^#/){
		$txtfile .= $_;
	}
}
close(TAB);
$txtfile =~ s/\n+/\n/gs;

my @tables = ();
if ($txtfile =~ /<table>/i){
	@tables = split(/<table>/i, $txtfile);
	for(my $i=0; $i<@tables; $i++){
		$tables[$i] = "<table>$tables[$i]";
	}
}else{
	$tables[0] = '';
	$tables[1] = $txtfile;
}

for(my $i=1; $i<@tables; $i++){
	my @lines = split(/\n/,$tables[$i]);
	my $FOOTER = 0;
	my $cols = 0;
	my @link = ();
	my $desc='';
	my $if_table = 0;
	my $line_count = 0;
	foreach(@lines){
		my $line = $_;
		$line =~ /^<(.+?)>/;
		my $tag = $1;
		
		if ($line_count == 0){
			if ($tag =~ /page_title/i) {  #### title of the page
				$line =~ s/^<.+?>//;
				print "<TITLE>$line</TITLE></HEAD><BODY text='#000088' bgcolor='#FFFFFF' topmargin='2'>\n";
			}
			else
			{
				print "<TITLE>TableView</TITLE></HEAD><BODY text='#000088' bgcolor='#FFFFFF' topmargin='2'>\n";
			}
			$line_count += 1;
		}elsif ($tag =~ /img_tag/i) {  #### image to be included 
			$line =~ s/^<.+?>//;
			print "<a href=\"/variation\"><img border=\"0\" src=\"$line\" align=\"left\"></img></a><br><br><br>\n";
		}elsif ($tag =~ /table/i) {  #### name of tables 
			$line =~ s/^<.+?>//;
			if($if_table)
			{
				print "</table>\n";	
				$if_table = 0;
				@link = ();
			}
			print "<p align=\"left\"><font face=\"arial\" size=\"3\" color=\"#000088\">$line</font><br><br>\n";
			
		}elsif ($tag =~ /title/i){   ######### title of table
			$line =~ s/^<.+?>//;
			if($if_table)
			{
				print "</table><br>\n";	
				$if_table = 0;
				@link = ();
			}
		print "<p align=\"left\"><font face=\"arial\" size=\"4\">$line</font><br><br>\n";
			
		}elsif ($tag =~ /text/i){   ######### some text to be included in the html page
			$line =~ s/^<.+?>//;
			if($if_table)
			{
				print "</table>\n";	
				$if_table = 0;
				@link = ();
			}
			print "<font face=\"Arial\" size=\"2\">$line</font>\n<br><br>\n";
			
		}elsif ($tag =~ /description/i) {  ##### description of table
			$line =~ s/^<.+?>//;
			if($if_table)
			{
				print "</table>\n";	
				$if_table = 0;
				@link = ();
			}
			$desc = $line;
			
		}elsif ($tag =~ /header/i) {  ##### header of table
			my $tag = '';
			if ($line =~ s/^<(.+?)>//){
				$tag = $1;
				$tag =~ s/header\s*//ig;
			}
			my $width = "100%";
			$width = $tag if ($tag && $tag >= 480);
			my @cols = split(/\t/,$line);
			$cols = @cols + 0;
			if ($desc){
				print "<table bordercolor='#00609A' border='0' cellpadding='0' cellspacing='0'  width='$width'>\n<tr>\n";
				print "<td><font face=\"Arial\" size=\"2\">$desc</font></td></tr></table>\n";
			}
			$if_table = 1;
			print "<table bordercolor='#00609A' border='1' cellpadding='1' cellspacing='0'  width='$width'>\n<tr>\n";
			for(my $i=0; $i<@cols; $i++){
				if ($cols[$i] =~ s/<(.*?)>$//){
					$link[$i] = $1;
				}
			print "<td bgcolor='#d9e4f8'><font face=\"Arial\" size=\"2\"><b>$cols[$i]$space</b></font></td>\n";
			}
			print "</tr>\n";
		}elsif ($tag =~ /footer/i) {  ##### footer of table
			$FOOTER++;
			$line =~ s/^<.+?>//;
			print "</table>\n<p>$line</p>\n";
		}else{   #### body of table
			my $tag='';
			if ($line =~ s/^<(.+?)>//){
				$tag = $1;
				$tag =~ s/row\s*//ig;
			}
			print "<tr>\n";
			my @cols = split(/\t/,$line);
			for(my $i=0; $i<$cols; $i++){
				my $cell = '';
				if ($link[$i] && $cols[$i]){
					if ($cols[$i] eq "-" or $cols[$i] =~ /Please/)
					{
						$cell = "$cols[$i]$space";
					}
					else
					{
						my $cols2 = '';
						if ($cols[$i] =~ /^(.+?) \/ (.+?)$/){
							$cols[$i] = $1;
							$cols2 = $2;
						}
						my $link = $link[$i];
						my $linkid = $cols[$i];
						$linkid =~ s/\*|<.*?>//g;
						if ($linkid=~/^(.+?)_variant.*$/i){
							$linkid = "$1*";
						}
						$link =~ s/\*/$linkid/;
						my $link2 = $link[$i];
						$link2 =~ s/\*/$cols2/;
						my $cell2 = '';
						$cell2 = "/ <a href='$link2'>$cols2</a>" if ($cols2);
						$cell = "<a href='$link'>$cols[$i]</a>$space$cell2";
					}
				}else{
					$cell = "$cols[$i]$space";
				}
				my $bg = '';
				$bg = ' bgcolor="#BBBBBB"' if ($tag =~ /s/i);
				my $style = "<td$bg>";
				$style = "<td$bg><b>" if ($tag =~ /b/i); 
				my $font = "<font face=\"Arial\" size=\"2\">";
				print "$style$font$cell</font></td>\n";
			}
			print "</tr>\n";
		}
	}
	unless($FOOTER){
		print "</table>\n";
	}
}
%>
<br><a href="/autism/">Home</a>

</BODY></HTML>
