<?
#linke Home >> Link1 >> Link2
function trail($id,$ret=""){
	global $catetree,$site_conf,$i_mod_list;
	$url=ge_url($cid);
	$ret="<a href=\"$url\" class=trail>".$catetree[$id][name]."</a> &#187; ".$ret;
	$pid=$catetree[$id][pid];
	if($pid>0){
		$ret = trail($pid,$ret);
	}	
	return $ret;
}
function linknav($id,$mark="|"){
	global $catetree,$site_conf;
	if(count($catetree[$id][child])>0){
		$pid=$id;
	}else{
		$pid=$catetree[$id][pid];
	}
	$ret=getsmenu($pid,$id);
	return implode($mark,$ret);
}

function hlinknav($id,$mark="|"){
	global $catetree,$site_conf;
	if(count($catetree[$id][child])>0){
		$pid=$id;
	}else{
		$pid=$catetree[$id][pid];
	//if(!$pid) $pid=0;
	}
	$ret="";
	$ret=getsmenu($pid,$id);
	$num = ceil(count($ret)/2);
	if(count($ret)>0 && is_array($ret)){
		$i=1;
		$rt="<table width=100% border=0 cellpadding=0 cellspacing=0>";
		foreach($ret as $link){
			if($i==1) $rt.="<tr>";
			$rt.="<td align=center>$link</td>";
			if($i==$num){
				$rt.="</tr>";
				$i=0;
			}
			$i++;
		}	
	}
	$rt.="</tr></table>";
	return $rt;
}

function insert_vlink($var){
	global $catetree,$site_conf;
	$id =$var[cid];
	$step = $var[step]?$var[step]:2;
	$mark =  $var[mark]?$var[mark]:"&middot;";
	$width =  $var[width]?$var[width]:"100%";
	$height =  $var[height]?$var[height]:"20";
	if(count($catetree[$id][child])>0){
		$pid=$id;
	}else{
		$pid=$catetree[$id][pid];
	}
	$ret=getsmenu($pid,$id);
	$ret2= "<table width=$width border=0 cellpadding=0 cellspacing=0>";
	$i=1;
	foreach($ret as $item){
	if($i==	1) $ret2.= "<tr height=$height>";
		$ret2.= "<td> $mark $item</td>";
	if($i==$step) {
		$ret2.= "</tr><tr><TD background=".PLUS_URL."/images/line.jpg 
                                height=1 colspan=$step><IMG height=1 
                                src=\"".PLUS_URL."/images/splash.gif\" 
                                width=1></TD></TR>";
		$i=0;
	}
	$i++;
	}
	$ret2.= "</table>";
	return $ret2;
}
#hormenu
function insert_hmenu($vars){
	global $catetree,$site_conf;
	$id=$vars[id];
	$bg=$vars[bg];
	$hi=$vars[hi];
	$width=$vars[width];
	$height=$vars[height];
	$check_ids = getNavId($id);
	$ret="<table border=0 cellpadding=0 cellspacing=0><tr><td width=6>&nbsp;</td>";
	foreach($catetree[0][child] as $sid){
		if($catetree[$sid][status]!='yes') continue;
		$sum++;
		$abg=in_array($sid,$check_ids)?$hi:$bg;
		$url=ge_url($sid);
		$ret.=" <td height=$height width=$width background=$abg align=center><a href=\"$url\" class=himenu>".$catetree[$sid][name]."</a></td><td width=6>&nbsp;</td>";
	}
	$ret.="</tr></table>";
	return $ret;
}
#navtab
function tabnav($id){
	global $catetree,$site_conf,$i_mod_list;
	$pid=0;
	$pid_s=getPid($id);
	$pids=explode(",",$pid_s);
	$ret="<TABLE height=18 cellSpacing=0 cellPadding=0 width=\"100%\" border=0><TBODY><TR vAlign=top>";
	foreach($catetree[$pid][child]  as $sid){
		if($catetree[$sid][status]!='yes') continue;
		$url=ge_url($sid);
		$name=$catetree[$sid][name];
		if(in_array($sid,$pids)){
			$class="nav2";
			$subid=$sid;	
		}else{
			$class="nav";	
		}
		$ret.="<TD><TABLE class=$class cellSpacing=6 cellPadding=0 width=\"100%\"  border=0> <TBODY><TR> <TD align=middle><A class=tablink  href=\"$url\">$name</A></TD> </TR>  </TBODY>              </TABLE></TD>              <TD width=6><IMG height=6 src=\"".PLUS_URL."/images/spacer.gif\"  width=6></TD>";
	}
	$ret.="</TR></TBODY></TABLE>";
	$subids=count($catetree[$subid][child]);
	if($subids >0){
		$tree=gettabsmenu($subid,$id);
		$menu=implode(" | ",$tree);
		$ret.="<TABLE class=nav2 cellSpacing=6 cellPadding=0 width=\"100%\" border=0><TBODY><TR><TD>$menu</TD></TR></TBODY></TABLE>";
		
	}
	return $ret;
}
function buttonnav($id){
	global $catetree,$site_conf,$i_mod_list;
	$cell_bg="";
	$cell_over="#DFDFDF";
	$cell_out="";
	$cell_active="#DFDFDF";
	$cell_width="100%";
	$cell_align="center";
	$subids=count($catetree[$id][child]);
	if($subids<=0) $pid=$catetree[$id][pid];else $pid=$id;
	$ret.="<table border=0 width=$cell_width border=0 cellpadding=0 cellspacing=0>";
	foreach($catetree[$pid][child] as $sid){
		if($catetree[$sid][status]!='yes') continue;
		$url=ge_url($sid);
		$name=$catetree[$sid][name];
		if($sid==$id){
		$ret.="<tr height=33 background=".PLUS_URL."/menu/menubg3.gif><td bgcolor=\"$cell_active\" align=\"$cell_align\" onMouseOver =\"this.style.backgroundColor='$cell_over'\" onMouseOut =\"this.style.backgroundColor='$cell_active'\"><a href=$url class=buttonlink>$name</a></td></tr>";
		}else{
		$ret.="<tr height=33><td bgcolor=\"$cell_bg\" align=\"$cell_align\" onMouseOver =\"this.style.backgroundColor='$cell_over'\" onMouseOut =\"this.style.backgroundColor='$cell_out'\"><a href=$url class=buttonlink>$name</a></td></tr>";
		}
		$ret.="        <tr><TD background=images/line.jpg 
                                height=1><IMG height=1 
                                src=".PLUS_URL."/images/splash.gif
                                width=1></TD></TR>";
	}
	$ret.="</table>";
	return $ret;
}

function dropdownnav($cid=0,$aid=0){
	$tree=getMenuTree($cid);
	$ret.="<select name='quick_nav' size=1 onChange=\"if(this.value != '') document.location = this.value\"  class=dropdownnav>";
	foreach($tree as $key=>$val){
		$ret.="<option value='$val[url]' ".($key==$aid?"selected":"").">$val[name]</option>";
	}
	$ret.="</select>";
	return $ret;
}
function getsmenu($id,$thsid){
	global $catetree,$site_conf,$i_mod_list;
	$sum=0;
	$num  = count($catetree[$id][child]);
	if($num==0) return array();
	foreach($catetree[$id][child] as $sid){
		if($catetree[$sid][status]!='yes') continue;
		$sum++;
		$class=($sid == $thisid)?"linknav2":"linknav";
		$url=ge_url($sid);
		$ret[]=" <a href=\"$url\" class=$class>".$catetree[$sid][name]."</a>";
	}
	if($sum==0) return array(); else return $ret;
}

function gettabsmenu($id,$thisid){
	global $catetree,$site_conf,$i_mod_list;
	$sum=0;
	foreach($catetree[$id][child] as $sid){
		if($catetree[$sid][status]!='yes') continue;
		$sum++;
		$class=($sid == $thisid)?"tablink2":"tablink";
		$url=ge_url($sid);
		$ret[]=" <a href=\"$url\" class=$class>".$catetree[$sid][name]."</a>";
	}
	if($sum==0) return FALSE; else return $ret;
}

function getPid($id,$ret=""){
	global $catetree;
	$ret.=",".$id;
	if($id=="0"){
		return $ret;
	}else{
	$pid=$catetree[$id][pid];
	$ret=getPid($pid,$ret);
}
return $ret;
}

function getMenuTree($cid=0,$deepth=0,$ret=array()){
		global $catetree,$site_conf,$i_mod_list;
		foreach($catetree[$cid][child] as $sid){
		if($catetree[$sid][status]=='yes'  && $sid>0){
		 $ret[$sid][name]=str_repeat("--",$deepth).$catetree[$sid][name];
		$url=ge_url($sid);
		 $sum=count($catetree[$sid][child]);
		if($sum>0){
			 $ret = getMenuTree($sid,$deepth+1,$ret);
			}
		}
		}
		return $ret;
}

function insert_menu($arg){
	$ctype=$arg[ctype];
	$cid=$arg[cid];
	$mark=$arg[mark];
	switch($ctype){
		case "link":return linknav($cid,$mark);break;
		case "hlink":return hlinknav($cid,$mark);break;
		case "trail":return trail($cid);break;
		case "tab":return tabnav($cid);break;
		case "button":return buttonnav($cid);break;
		case "dropdown":return dropdownna($cid);break;
		default:echo linknav($cid,$mark);
	}
}

function insert_buttonnavs($var){
	global $catetree,$site_conf,$i_mod_list;
	$id=$var[id];
	$check_ids = getNavId($id);
	$cell[cell_bg]="#D6E0E3";
	$cell[cell_over]="#DFDFDF";
	$cell[cell_out]="#D6E0E3";
	$cell[cell_active]="#DFDFDF";
	$cell[cell_width]="100ге";
	$cell[cell_align]="left";
	$cell[mark]= "<img src=".PLUS_URL."/images/bullet.gif border=0 align=absmiddle>";
	$cell[amark2] = "<img src=".PLUS_URL."/images/abullet.gif border=0 align=absmiddle>";
	$cell[amark] = "<img src=".PLUS_URL."/images/tree_img/joinbottom.gif border=0 align=absmiddle>";
	$pid =$id;
	$ret.="<table border=0 width=$cell[cell_width] border=0>";
	$ret.=showNavs($id,0,$check_ids,$deepth=0,$cell);
	$ret.="</table>";
	return $ret;
}

function showNavs($id,$sid,$check_ids,$deepth=0,$cell){
	global $catetree,$site_conf;
	foreach($catetree[$sid][child] as $ssid){
			$sname=$catetree[$ssid][name];
			//$surl=($site_conf[sitehtml]==1 && !in_array($catetree[$ssid][type],$i_mod_list))?"category"._HTML_EXT."/$ssid/index.html":"index.php?cid=$ssid";
			$surl=ge_url($ssid);
			if(in_array($ssid,$check_ids)){
				$mark = ($deepth>0)?$cell[amark]:$cell[amark2];
				if($ssid ==$id){
				$ret.="<tr  height=36><td background=menu/menubg3.gif>".str_repeat("&nbsp;&nbsp;&nbsp;",$deepth)."<a href=$surl class=buttonlink>".$mark."$sname</a></td></tr>";
			}else{
			$ret.="<tr height=36><td background=menu/menubg3.gif>".str_repeat("&nbsp;&nbsp;&nbsp;",$deepth)."<a href=$surl class=buttonlink>".$mark."$sname</a></td></tr>";	
			}
				if(count($catetree[$ssid][child])>0) $ret.=showNavs($id,$ssid,$check_ids,$deepth+1,$cell);
			}else{
				$mark = ($deepth>0)?$cell[amark]:$cell[mark];
				$ret.="<tr  height=36><td bgcolor=\"".$cell[cell_bg]."\" align=\"".$cell[cell_align]."\" onMouseOver =\"this.style.backgroundColor='".$cell[cell_over]."'\" onMouseOut =\"this.style.backgroundColor='".$cell[cell_bg]."'\" background=menu/menubg3.gif valign=middle>".str_repeat("&nbsp;&nbsp;&nbsp;",$deepth)."<a href=$surl class=buttonlink>".$mark."$sname</a></td></tr>";	
		}
	}	
	return $ret;
}
function getNavId($cid,$ret="")
{
	global $catetree;
	//$ret="<a href=index.php?cid=$cid>".$catetree[$cid][name]."</a>&nbsp;&raquo;&nbsp;".$ret;
	$ret[]=$cid;
	$pid=$catetree[$cid][pid];
	if($pid>0)
	{
		$ret=getNavId($pid,$ret);
	}
	return $ret;
}

function ge_url($cid){
	global $site_conf,$catetree;
	$html_path = $site_conf[system][html_path];
	$html_ext = $site_conf[system][html_ext];
	if($site_conf[system][outhtml]=="yes"){
		$path = getCategoryPath($cid);
		$url=PLUS_URL."/".$html_path.$path."index.".$html_ext;
	}else{
		$url = "index.php?cid=$cid";
	}
	if($catetree[$cid][ctype]=='url') $url = $catetree[$cid][url];
	return $url;
}

function insert_ddMenu($var)
{
$cid=$var[cid];
$level = $var[level];
$bg_img = $var[bg_img];
$hl_img = $var[hl_img];
$top_width=$var[top_width];
$top_height= $var[top_height];
$sub_width = $var[sub_width];
$sub_height =$var[sub_height];
?>
<script type="text/javascript" src="<?=PLUS_URL?>/menu/doiMenuDOM.js"></script>
<script type="text/javascript" src="<?=PLUS_URL?>/menu/functions.js"></script>
<script type="text/javascript">
var mm2 = new TMainMenu('mm2','horizontal');
<?
/*
foreach($catetree as $id=>$val){
	$status = $catetree[$id][status];
	if($status !=1 ) continue;
	$title=$catetree[$id][name];
	$url="index.php?cid=$id";
	$pid = $catetree[$id][pid];
	echo "var pmDemo$id = new TPopMenu('$title','0','a','$url','$title');\n";
	if($pid>0){
	$ret.="pmDemo$pid.Add(pmDemo$id);\n";
	}else{
	$ret.="mm2.Add(pmDemo$id);\n";
	}
}

*/
	$ret=getDdMenuContent($cid,$cid,$level,1);
	echo $ret;
	echo "</script>";
	?>
	     <script language="JavaScript" type="text/JavaScript">
						//custom style 1
							mm2.SetPosition('relative',0,0);
							mm2.SetCorrection(1,0);
							mm2.SetCellSpacing(0);
							mm2.SetItemDimension(<?=$top_width?>,<?=$top_height?>);
							mm2.SetBackground('navy','','','');
							mm2.SetFont('verdana,tahoma,arial','10pt');
							mm2.SetItemText('#336699','center','normal','','nowrap');
							mm2.SetItemBackground('#e5e5e5','<?=$bg_img?>','repeat-x','');
							mm2.SetItemBorder(1,'#e5e5e5','solid');
							mm2.SetItemTextHL('#ff9900','center','normal','underline','nowrap');
							mm2.SetItemBackgroundHL('#e5e5e5','<?=$hl_img?>','repeat-x','');
							mm2.SetItemBorderHL(1,'#e5e5e5','solid');
							mm2.SetItemTextClick('white','center','normal','','nowrap');
							mm2.SetItemBackgroundClick('#e5e5e5','menu/menubg2.gif','repeat-x','');
							mm2.SetItemBorderClick(1,'navy','solid');
							mm2.SetBorder(1,'navy','solid');
							mm2._pop.SetCorrection(6,0);
							mm2._pop.SetItemDimension(<?=$sub_width?>,<?=$sub_height?>);
							mm2._pop.SetPaddings(0);
							mm2._pop.SetBackground('navy','','','');
							//mm2._pop.SetSeparator(150,'center','navy','');
							mm2._pop.SetExpandIcon(false,'',6);
							mm2._pop.SetFont('tahoma,verdana,arial','10pt');
							mm2._pop.SetShadow(false,'#B0B0B0',5);
							mm2._pop.SetDelay(500);
							mm2._pop.SetItemBorder(1,'#e5e5e5','solid');
							mm2._pop.SetItemBorderHL(1,'#e5e5e5','solid');
							mm2._pop.SetItemPaddings(0);
							mm2._pop.SetItemPaddingsHL(0);
							mm2._pop.SetItemText('navy','center','normal','','nowrap');
							mm2._pop.SetItemTextHL('black','center','normal','','nowrap');
							mm2._pop.SetItemBackground('#e5e5e5','<?=$bg_img?>','repeat-x','');
							mm2._pop.SetItemBackgroundHL('#e5e5e5','<?=$hl_img?>','repeat-x','');
							mm2.Build();
						</script>
	<?
}

function getDdMenuContent($topid,$pid=0,$level=3,$deepth=1){
	global $catetree;
	$level=5;
	foreach($catetree[$pid][child] as $cid){
		//echo $catetree[$cid][name];
		if($catetree[$cid][status]!='yes') continue;
		$title=$catetree[$cid][name];
		$url=ge_url($cid);
		//$pid = $catetree[$cd][pid];
		echo "var pmDemo$cid = new TPopMenu('$title','0','a','$url','$title');\n";
		if($pid!=$topid){
		$ret.="pmDemo$pid.Add(pmDemo$cid);\n";
		}else{
		$ret.="mm2.Add(pmDemo$cid);\n";
		}
		//if(count($catetree[$cid][child])>0 && $deepth<=$level)  $ret.=getDdMenuContent($topid,$cid,$level,$deepth+1);
		if(count($catetree[$cid][child])>0 && $deepth<=$level) {
		 $ret.=getDdMenuContent($topid,$cid,$level,$deepth+1);
		}
	}
	return $ret;
}
?>
