#!/mod/bin/jimsh

source /mod/webif/lib/setup
require system.class

#puts "Humax [system model] Fox T2 ([system hostname])"

puts "
<!DOCTYPE html> 
<html>
<head>
<title>
	Humax [system model] Fox T2 ([system hostname])
</title>
"

puts {
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=no,initial-scale=1"> 
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<link rel="stylesheet" href="/lib/jquery.mobile/jquery.mobile.css" />
<link rel="stylesheet" href="/m/style.css" type="text/css"/>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/lib/jquery.mobile/jquery.mobile.js">
</script>
<script type="text/javascript" src="/m/script.js"></script>
<link rel="apple-touch-icon" href="/img/mobile_57.png" />
<link rel="apple-touch-icon" sizes="57x57" href="/img/mobile_57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/img/mobile_72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/img/mobile_114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/img/mobile_144.png" />
}
noheader
jqplugin enadis
puts {
</head> 
}

if {[dict exists $env SCRIPT_NAME]} {
	set pageid [string range $env(SCRIPT_NAME) 3 end-4]
} else {
	set pageid test
}

set _dialog 0
if {[string range $pageid end-1 end] eq "_d"} {
	set _dialog 1
}

set _bare 0
if {[string range $pageid end-1 end] eq "_b"} {
	set _bare 1
}

puts "<body>"

proc _header {{title ""}} {

	if {$title eq ""} {
		set title "[system model] ([system hostname])"
	}

	return "
<div class=ui-btn-right style=\"top: -5px\">
    <div style=\"display: inline-block; margin-right: 10px;\">
	<a data-theme=a data-icon=home data-iconpos=notext data-role=button
	    data-direction=reverse href=index.jim></a>
    </div>
    <div style=\"display: inline-block;\">
	<a data-theme=a data-icon=refresh data-iconpos=notext data-role=button
	    class=refresh data-direction=reverse href=#></a>
    </div>
</div>
<h1>$title</h1>
	"
}

if {$_bare} {
	puts ""
} elseif {$_dialog} {
	puts "<div data-role=page id=${pageid}page>\n"
} else {
	puts "
<div data-role=page data-add-back-btn=true id=${pageid}page>

 <div class=\"hidden status\"></div>

 <div data-role=header data-theme=a>
    [_header]
 </div>
 <div data-role=content>
	"
}

set renderstart [clock milliseconds]

