<!--
// We have 3 sets of program, but we register one set only, depending on our category.
// So we have to get the category and page/item first.

function getRangeValue(val, lower, upper) {
    var i = parseInt(val);
    if (isNaN(i) || i<lower) i = lower;
    else if (i>upper) i = upper;
    return i;
}

var myLoc = window.location.href;
var idx = myLoc.lastIndexOf("/");
myLoc = myLoc.substring(++idx);

var s = myLoc;
idx = s.indexOf("tv_cat_");
if (idx>=0) {                    // a cat file, must be tv_cat_x_y.htm
    isCat = true;
    valArr = s.substring("tv_cat_".length).split("_");
} else {                        // a content file, must be tv_video_x_y.htm
    isCat = false;
    valArr = s.substring("tv_video_".length).split("_");
}
cat = parseInt(valArr[0]);
if (isNaN(cat) || cat<0) cat = 0;

// now register the programs
var prog = new Array();     // program id
var title = new Array();    // full title
var stitle = new Array();   // short title
var hasGB =  new Array();   // has GB version ?
function registerProg(p, t, s, has_GB) {
    var curIdx = prog.length;
    prog[curIdx] = p;
    title[curIdx] = t;
    stitle[curIdx] = s;
    hasGB[curIdx] = has_GB;
}
//
// actually register the programs, add new program of each category at end of list
//
switch (cat) {
case 2:         // Hong Kong 's Amended Copyright Law
    catTitle = "Hong Kong's Amended Copyright Law";
    catImage1 = "promote3.jpg"; catImage2 = ""; catImageHeight = 300;
    registerProg("19","Copyright in Education<br>(Student version)","Copyright in Education (Teacher ver)" ,false);
    registerProg("18","Copyright in Education<br>(Teacher version)","Copyright in Education (Student ver)",false);
    break;
case 1:         // Making Intellectual property your bussiness
    catTitle = "Making Intellectual Property Your Business - The Wealth Creation Series (4 Episodes)";
    catImage1 = "home62.gif"; catImage2 = "home63.gif"; catImageHeight = 150;
    registerProg("17","Registered Designs" ,"Registered Designs ", true);
    registerProg("16","Copyright","Copyright", true);
    registerProg("15","Patents","Patents", true);
    registerProg("14","Trademarks","Trademarks", true);
    break;
default:        // others default to 0, Creativity is Wealth
    catTitle = "Creativity is Wealth (13 Episodes)";
    catImage1 = "home60.gif"; catImage2 = "home61.gif"; catImageHeight = 150;
    registerProg("13","Respect Intellectual Property<br> Don't buy pirated products","Respect Intellectual Property..." ,false);
    registerProg("12","Register a patent:<br> protect your wealth","Register a patent: protect your..",false);
    registerProg("11","Creating wealth through brand building","Creating wealth through brand..." ,false);
    registerProg("10","You are what you wear.<br> Don't wear fake products.","You are what you wear. Don't...",false);
    registerProg("09","Copyright on Internet","Copyright on Internet",false);
    registerProg("08","A story of buying pirated goods.","A Story of buying pirated goods",false);
    registerProg("07","Respect the Copyright owners","Respect the Copyright owners",false);
    registerProg("06","Support Hong Kong creative industry","Support Hong Kong creative...",false);
    registerProg("05","Buying pirated products create vicious circle","Buying pirated products...",false);
    registerProg("04","Don't install pirated software","Don't install pirated software",false);
    registerProg("03","Go to cinema to see the movie Support Hong Kong <br> movie industry","Go to cinema to see the movie...",false);
    registerProg("02","Buying pirated goods are plundering","Buying pirated goods are...",false);
    registerProg("01","Pirated Products = <br> Poor Quality Products","Pirated Products=Poor Quality..." ,false);
}   // end switch
// end register

// calculate which one to display according to my page number
var pageView = 6 ;
if (isCat) {        // get page number
    var lastPage = Math.ceil(prog.length/pageView);
    var p = getRangeValue(valArr[1], 1, lastPage);
    var max = p * pageView;
    var start = prog.length - max + pageView -1 ;
    if (p<lastPage) {                               // simple case
        var end = prog.length - max;
        var lastPage = (max==prog.length);
    } else {                                        // last page
        var end = 0;
        var lastPage = true;
    }
} else id = getRangeValue(valArr[1], 0, prog.length-1);
//-->