class buildFAQ{
var $d;
var $length;
function buildFAQ($file){
$f= fopen($file, "r");
$this->d = fread($f, filesize($file));
fclose($f);
}
function buildList($fid){
$q = explode("{q:}", $this->d);
$out = "<dl class=\"faqdl\">";
$i = 0;
foreach ($q as $val){
if (strlen($val)>3){//skip BOM w pliku UTF
$i++;
$ans = explode("{a:}", $val);
$out.="<dt class=\"faqdt\"> <a href=\"#{$fid}_{$i}\" onclick=\"javascript: show_hide('{$fid}_{$i}'); return false;\">".trim($ans[0])."</a></dt>";
$out.="<dd class=\"faqdd\" id=\"{$fid}_{$i}\">".trim($ans[1])."</dd>";
}
}
$this->length=$i;
$out .= "</dl>";
return $out;
}
function buildOutput($fid, $type="FAQ"){
$output = "<script type=\"text/javascript\">
function show_hide(id){
var o = document.getElementById(id);
var s = o.style.display;
if (s != 'none'){
o.style.display = 'none';
}else{
o.style.display = 'block';
}
}
function hide_all(count, fid){
for(var i=1; i<=count; i++){
document.getElementById(fid+'_'+i).style.display = 'none';
}
}
</script>
";
switch ($type){
default:
case "FAQ":
$output .= $this->buildList($fid);
break;
}
$output .= "
<script type=\"text/javascript\">
hide_all({$this->length}, '$fid')
</script>
";
return $output;
}
}