function toggle(num){

    var d = 'frame-text';
    var s = 'con'+num;
    var a = 'ca';
    copyContent(d, s);
    putArrow(a, num);
}

function toggleText(num){
    
    var d = 'frame-text';
    var s = 'con'+num;
    var a = 'ca';

    copyContent(d, s);
    putArrow(a, num);
}

function copyContent(d, s){
    //var v = 'movieContent';
    var nd = document.getElementById(d);
    //if(typeof ActiveXObject == 'object') {	
    //	var vid = new Object();
    //	vid.wmv = document.getElementById('player').object;
    //	vid.wmv.controls.stop();
    //}
    
    nd.innerHTML=document.getElementById(s).innerHTML;
}

function tabOnclickFunc(){
    clearTabContent();
}

function clearTabContent(){
    var v = 'movieContent';
    var p = document.getElementById(v);
    p.innerHTML='<div id=movieContent></div>';
    
}


function stopvideo(){
    var v = 'movieContent';
    //alert('stop');
    var p = document.getElementById(v);
    //p.stopVideo();
    //alert(p);
    //p = document.getElementById('photo_gallery');
    
    //alert(p);
    p.innerHTML='<div id=movieContent></div>';
    
}


function  setVisibleDiv(div, header){
    var divList = document.getElementsByTagName('div');
    var maxDiv = divList.length;
    for (var i=0; i<maxDiv; i++){		
	var divID = divList[i].id;	
	if (divID.charAt(0)==header){		
	    if ((divID.length>3) && (divID.length<6))
	    {
		divList[i].style.display = (divID == div) ? 'block' : 'none';		
	    }
	}
    }
}


function  setVisibleDiv3(div, header){
    var divList = document.getElementsByTagName('div');
    var maxDiv = divList.length;
    for (var i=0; i<maxDiv; i++){		
	var divID = divList[i].id;	
	var headerLen = header.length
	if (divID.substr(0,headerLen)==header)
	{
	    divList[i].style.display = (divID == div) ? 'block' : 'none';
	}
    }
    location.href = "#"+div;
}



function showScrollbar(id){
    
    var d = document.getElementById(id);
    if(d !=null){
	d.style.overflowX="hidden";
	d.style.overflowY="auto";
    }
    
}

function hideScrollbar(id){
    
    var d = document.getElementById(id);
    if(d !=null){
	d.style.overflowX="hidden";
	d.style.overflowY="hidden";
    }
    
}

function toggleDiv(id)
{ 
    var style = getObjectStyle(id);
    if (style) style.display = (style.display=='none') ? 'inline' : 'none';
}

function putArrow(c, a){
    //clear arrow
    var max = 12;
    for (var i=1; i<=max; i++){
	var b = c+i;
	var d = document.getElementById(b);
	d.innerHTML = '';
    }
    
    var arrowImg;
    if (a<=6){
	arrowImg = '/ACMS/upload/hkcc/Tfc/images/arrow-up.gif';
    }else{
	arrowImg = '/ACMS/upload/hkcc/Tfc/images/arrow-down.gif';
    }
    
    var d = document.getElementById(c+a);
    d.innerHTML='<img src=\"'+arrowImg+'\">';
}

function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 ){
	var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	var aQueryString = strQueryString.split("&");
	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	    if (
		aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
		var aParam = aQueryString[iParam].split("=");
		strReturn = aParam[1];
		break;
	    }
	}
    }
    return unescape(strReturn);
} 

function setDiv(d)
{
    
    var divName = getURLParam(d);
    if (divName){
	var head = divName.charAt(0);
	setVisibleDiv(divName, head);
    }
}


function fellowship(n)
{
    return n;
}

function busRoute(a){
    var bustlist = a;
    var routestr = "http://www.kmb.hk/tc/services/search.html?busno=";
    for (var no in a){
	var rs="<a href=\'"+routestr + buslist[no]+"'"+" target=_'new'>"+buslist[no].toUpperCase()+"</a>";
	if(no >0) document.write(",");
	document.write(rs);
    }
}

function searchMap(address_str){
    //location.href="http://www.google.com/maps?f=q&source=s_q&hl=zh-TW&geocode=&q="+address+"&ie=UTF8&hq="+address+"&z=15&iwloc=A";
    var address = encodeURI(address_str);
    window.open("http://www.google.com/maps?f=q&source=s_q&hl=zh-TW&geocode=&q="+address+"&ie=UTF8&hq="+address+"&z=15&iwloc=A");
}

function switch_video(id, video_file, title)
{ 
    var base = "";
    var file = base+video_file;
    var d = document.getElementById(id);
    var agent=navigator.userAgent.toLowerCase();
    var is_iphone = (agent.indexOf('ip')!=-1);
    if (is_iphone){
	d.innerHTML = "<h3>"+title+"</h3><div><video id='vid1' width='320' height='240' src='"+file+"' controls='true' type='video/mp4'></video></div>";
    }else{
	d.innerHTML = "<h3>"+title+"</h3><div><embed src='upload/skhhsc/swf/player.swf'  allowscriptaccess='always' allowFullScreen='true' type='application/x-shockwave-flash' wmode='opaque' width='320' height='240' FlashVars='file="+file+"&&stretching=fill&volume=20'></embed></div>";
    }

   

}
