﻿var root={
  "year": "2007",
  "title": "國際觀摩影展單元",
  "child": [
    {
      "name": "開/閉幕片",
      "id": "s-07-00",
      "isLeaf": true,
      "disabled": false,
      "child": null
    },
    {
      "name": "金馬獎入圍影片",
      "id": "s-07-01",
      "isLeaf": true,
      "disabled": false,
      "child": null
    },
    {
      "name": "數位奧德賽",
      "id": "s-07-02",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "怪ㄎㄚ正傳",
          "id": "s-07-02-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "花花世界",
          "id": "s-07-02-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "夢遊異境",
          "id": "s-07-02-3",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "數位觀摩",
          "id": "s-07-02-4",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "影迷嘉年華",
      "id": "s-07-03",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "大師饗宴",
          "id": "s-07-03-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "年度熱門電影",
          "id": "s-07-03-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "影壇新映象",
      "id": "s-07-04",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "東南亞新勢力",
          "id": "s-07-04-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "焦點導演：雅絲敏阿莫",
          "id": "s-07-04-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "羅馬尼亞新浪潮 ",
          "id": "s-07-04-3",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "焦點導演：路西安品特萊",
          "id": "s-07-04-4",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "華語電影世界",
      "id": "s-07-05",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "話題華語影片",
          "id": "s-07-05-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "台灣影壇新世代",
          "id": "s-07-05-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "臺灣新銳短片輯",
          "id": "s-07-05-3",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "她‧Just Do It",
          "id": "s-07-05-4",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "世界之窗",
      "id": "s-07-06",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "全球視野",
          "id": "s-07-06-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "一鳴驚人",
          "id": "s-07-06-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "只要我長大",
      "id": "s-07-07",
      "isLeaf": true,
      "disabled": false,
      "child": null
    },
    {
      "name": "光影人生與傳奇",
      "id": "s-07-08",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "電影二三事",
          "id": "s-07-08-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "藝術家二三事",
          "id": "s-07-08-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "向大師致敬",
      "id": "s-07-09",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "李翰祥",
          "id": "s-07-09-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "胡金銓",
          "id": "s-07-09-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "楊德昌",
          "id": "s-07-09-3",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    },
    {
      "name": "次文化派對",
      "id": "s-07-11",
      "isLeaf": false,
      "disabled": false,
      "child": [
        {
          "name": "音樂無界限",
          "id": "s-07-11-1",
          "isLeaf": true,
          "disabled": false,
          "child": null
        },
        {
          "name": "麻辣午夜場",
          "id": "s-07-11-2",
          "isLeaf": true,
          "disabled": false,
          "child": null
        }
      ]
    }
  ]
}
var progMM;
var ct;
var progImgs;
var showString=(document.all) ? "block" : "table-row";
function prepareProgImgs(){
	progImgs=new Array();
	progImgs.push({n:"/gh_tc/tmp_imgs/bullet_prog-1-dot.gif", o:"/gh_tc/tmp_imgs/bullet_prog-1-dot-o.gif", sn:"/gh_tc/tmp_imgs/bullet_prog-1-shr.gif", 
				  so:"/gh_tc/tmp_imgs/bullet_prog-1-shr-o.gif", en:"/gh_tc/tmp_imgs/bullet_prog-1-exp.gif", eo:"/gh_tc/tmp_imgs/bullet_prog-1-exp-o.gif"});
	progImgs.push({n:"/gh_tc/tmp_imgs/bullet_prog-2-dot.gif", o:"/gh_tc/tmp_imgs/bullet_prog-2-dot-o.gif", sn:"/gh_tc/tmp_imgs/bullet_prog-2-shr.gif", 
				  so:"/gh_tc/tmp_imgs/bullet_prog-2-shr-o.gif", en:"/gh_tc/tmp_imgs/bullet_prog-2-exp.gif", eo:"/gh_tc/tmp_imgs/bullet_prog-2-exp-o.gif"});
}
function prepareNode(node, parent, lvl){
	ct++;	
	node.rowId="prog_"+ct;
	node.imgId="prog_img_"+ct;
	node.parentNode=parent;
	if(!node.isLeaf) node.isExpand=false;
	node.lvl=lvl;
	progMM[node.id]=node.rowId;
}
function fillRow(tag, n){
	
}
function createProgMenu(rootnode, maxLvl, name){
	progMM=new Object();
	prepareProgImgs();
	var tag=new TagObj();
	var stack=new Array();
	ct=0;
	var matchName=false;
	tag.beginTag("table", "cellspacing" , 0,  "cellpadding",0, "border", 0, "id", "progmenu");
	tag.beginTag("tr");
	tag.beginTag("td", "colspan", 3,"class", "prog-title");
	tag.beginTag("div", "class", "year");
	tag.writeString(rootnode.year);
	tag.closeTag("div");
	tag.writeString(rootnode.title);
	tag.closeTag("tr");
	tag.beginTag("tr");
	tag.beginTag("td");
	tag.closeTag("td");
	tag.beginTag("td");
	tag.beginTag("img","src", "/gh_resource/imgs/spacer.gif", "height", 1, "width", 10);
	tag.closeTag("td");
	tag.beginTag("td");
	tag.beginTag("img","src", "/gh_resource/imgs/spacer.gif", "height", 1, "width", 100);
	tag.closeTag("tr");
	stack.push({node:rootnode, parent:null, index:null, lvl:0});
	while(stack.length>0){
		var n=stack.pop();
		if(!n.parent){
			stack.push({node:n.node.child[0], parent:n.node, index:0, lvl:1});
		}else{
			prepareNode(n.node, n.parent, n.lvl);
			n.index++;
			if(n.index<n.parent.child.length){
				stack.push({node:n.parent.child[n.index], parent:n.parent, index:n.index, lvl:n.lvl});
			}
			if(!n.node.isLeaf){
				stack.push({node:n.node.child[0], parent:n.node, index:0, lvl:n.lvl+1});
			}
			tag.beginTag("tr", "id", n.node.rowId, "class", "prog-"+n.node.lvl, "style", "display:none");
			if(n.lvl>1){
				tag.beginTag("td", "colspan", maxLvl-n.lvl+1);
				tag.closeTag("td");
			}
			tag.beginTag("td", "class", "ci");
			if(n.node.disabled){
				tag.beginTag("img", "src", "/gh_tc/tmp_imgs/bullet_prog-dis.gif");
			}else if(n.node.isLeaf){
				matchName=matchName || (n.node.id==name);
				tag.beginTag("img", "src", progImgs[n.lvl-1].n, "id", n.node.imgId);
			}else{
				tag.beginTag("img", "src", progImgs[n.lvl-1].sn, "id", n.node.imgId);
			}
			tag.closeTag("td");
			tag.beginTag("td", "colspan", maxLvl-n.node.lvl+1, "class", "cn");
			if(n.node.disabled){
				tag.writeString(n.node.name);
			} else if(n.node.isLeaf){
				tag.beginTag("a", "href", baseSectionUrl+"?id="+n.node.id);
				tag.writeString(n.node.name);
				tag.closeTag();
			}else{
				tag.beginTag("a", "href", "javascript:toggleProgMenu('"+n.node.rowId+"')");
				tag.writeString(n.node.name);
				tag.closeTag();
			}
			tag.closeTag("tr");
			//document.write(n.node.name+","+n.node.lvl+","+n.node.rowId+"<br>");			
		}
	}
	tag.closeTag("table");
	var str=tag.getTagString();
	//MM_findObj("hello").value=str;
	if(!matchName) {
		return;
	}
	document.write(str);
	rematchProgMenu(rootnode);
	for(var i=1;i<=ct;i++){
		var obj=MM_findObj("prog_"+i);
		if(obj.progNode.lvl==1){
			obj.style.display=	showString;
		}
	}
	setProgMenuHilight(name);
}
function setProgMenuHilight(name){
	if(!name) return;
	var row=MM_findObj(progMM[name]);
	var n=row.progNode;
	n.isHilight=true;
	row.className="prog-"+n.lvl+"-o";
	if(n.isLeaf){
		MM_findObj(n.imgId).src=progImgs[n.lvl-1].o;
	}else{
		MM_findObj(n.imgId).src=(n.isExpanded) ? progImgs[n.lvl-1].eo : progImgs[n.lvl-1].so;
		ceChild(n, true);
	}
	setProgMenuHilight(n.parentNode.id);
}
function rematchProgMenu(rootnode){
	var stack=new Array();
	stack.push(rootnode);
	while(stack.length>0){
		var n=stack.pop();
		if(n.rowId)	{
			MM_findObj(n.rowId).progNode=n;
		}
		if(n.child){
			for(var i=0;i<n.child.length;i++){
				stack.push(n.child[i]);
			}
		}
	}
}
function toggleProgMenu(id){
	var obj=MM_findObj(id);
	ceChild(obj.progNode, !obj.progNode.isExpanded);
}
function ceChild(n, state){
	var child=n.child;
	var imgsrc;
	if(n.isHilight){
		imgsrc=(state)? progImgs[n.lvl-1].eo : progImgs[n.lvl-1].so;
	}else{
		imgsrc=(state)? progImgs[n.lvl-1].en : progImgs[n.lvl-1].sn;
	}
	MM_findObj(n.imgId).src=imgsrc;
	for(var i=0;i<child.length;i++){
		MM_findObj(child[i].rowId).style.display=(state) ? showString:"none";
	}
	n.isExpanded=state;
}

function loadCartOperation(id){
	if(document.all){
	   document.frames["op"].location.href="/gh_tc/ff/cart_operator.aspx?f_id="+id;
	}else{
		window.frames["op"].location.href="/gh_tc/ff/cart_operator.aspx?f_id="+id;
	}
}
function setFilmCartStatus(res){
	cmdTxt=(res)? "del" : "add" ;
	MM_findObj("cartIcon").src=(!res)? "/gh_resource/imgs/08/cart_add.gif" : "/gh_resource/imgs/08/cart_del.gif" ;	
	MM_findObj("cartCmd").blur();
}
function sendCommand(){
	if(document.all){
		document.frames["op"].sendCommand(cmdTxt);
	}else{
		window.frames["op"].sendCommand(cmdTxt);
	}
}
var cmdTxt;
