﻿var top_value;
var min_height=250;
var bottom_distance=100;
var tesstpath = window.location.href;
var kanhanURLstr= "/TuniS/";

function getFixedPosition()
{
	var new_value;
	new_value = (($("body").scrollTop() || $("html").scrollTop()) + ($(window).height() - bottom_distance - parseInt($("#gototop_zone ").css("margin-top")) - parseInt($("#gototop_zone .gototop_bottom").css("height"))));
		
		if (new_value < min_height)
			return min_height;
		else if (new_value>($(document).height()-parseInt($("#gototop_zone .gototop_bottom").css("height"))-bottom_distance))
			return ($(document).height()-parseInt($("#gototop_zone .gototop_bottom").css("height"))-bottom_distance);
		else
			return new_value;
}

function updatePosition()
{
	top_value=getFixedPosition();
	$("#gototop_zone .gototop_bottom").stop(true,true).animate( { top:(top_value+"px")}, 100 );
	$("#gototop_zone ").stop(true,true).animate( { height:(top_value+parseInt($("#gototop_zone .gototop_bottom").css("height"))+"px")}, 100 );
}

function getPath(){
	var langs = ['eng', 'chi', 'chi'];
	var currentLang = langs[0];
	for(x in langs){
		if(location.href.search("/"+langs[x]+"/")!=-1){
			currentLang = langs[x];
		}
	}
	return [location.href.substr(0, location.href.search('/'+currentLang+'/')), currentLang];
}
var temp = getPath();
var currentPath = temp[0];
var currentLang = temp[1];
var currentPathLang = temp[0] + '/' + temp[1] + '/';

if (currentPathLang.indexOf('https://') == -1) {
    if (currentPathLang.indexOf('sc.hkcic.org/TuniS/www.hkcic.org') == -1) {
        var currentPathLanghttps = currentPathLang.replace(/http/gi, "https");
    }
    else {
        var currentPathLanghttps = currentPathLang.replace(/http/gi, "https");
        currentPathLanghttps = currentPathLanghttps.replace('sc.hkcic.org/TuniS/www.hkcic.org', "www.hkcic.org");
    }
    var currentPathLangnohttps = currentPathLang;
}
else {
    if (currentPathLang.indexOf('sc.hkcic.org/TuniS/www.hkcic.org') == -1) {
        var currentPathLanghttps = currentPathLang;
    }
    else {
        var currentPathLanghttps = currentPathLang;
        currentPathLanghttps = currentPathLanghttps.replace('sc.hkcic.org/TuniS/www.hkcic.org', "www.hkcic.org");
    }    
    var currentPathLangnohttps = currentPathLang.replace(/https/gi, "http");
}


function SwitchLang(charsetID){
	var url = window.location.toString();
	var isStaticURL = false;
	var langPaths = new Array("eng", "chi", "chi");
	var langTypes = new Array("langType=1033", "langType=1028", "langType=1028");
	var oldLangPath = "";
                  var oldLangType="";

	// Check url type (is static page or dynamic page)
	for (i=0; i < langPaths.length; i++){
		if (url.indexOf("/"+langPaths[i]+"/") != -1){
			oldLangPath = "/"+langPaths[i]+"/";
			oldLangType=langTypes[i];
			isStaticURL = true;
			break;
		}
	}

	if (isStaticURL){
		var path;
		path = window.location.href;
		
		var kanhan_url = "sc.hkcic.org/TuniS/www.hkcic.org"; // without http:// in prefix
		if(charsetID==3){
			// chanage domain path
			path = path.replace(window.location.toString().split("//")[1].split("/")[0],kanhan_url);
		}else{
			// if kanhan url change back to eng or chi
			if(url.indexOf(kanhan_url)!=-1){
			    path = path.replace(kanhan_url, "www.hkcic.org");
			}
		}
		
		path = path.replace(oldLangPath, "/"+langPaths[charsetID - 1]+"/");
		window.location =path.replace(oldLangType, langTypes[charsetID - 1]);
	}else{
		if (url.indexOf("lang=") != -1){
			window.location = 
				url.replace(/lang=\d/, "lang="+charsetID);
		}
	}
}


function update_index_flash_width(){
			if (($.browser.msie&& /MSIE 6\.0/i.test(window.navigator.userAgent)&& !/MSIE 7\.0/i.test(window.navigator.userAgent))){
				/*if ($(window).width()>=parseInt($('body').css('max-width')))
					$('body').width(parseInt($('body').css('max-width')));*/
				if ($(window).width()<=parseInt($('body').css('min-width')))
					$('body').width(parseInt($('body').css('min-width')));
				else
					$('body').width('100%');
			}
}

$(window).load(function() {
    /*FF*/
    $(document).scroll(function() {
        updatePosition();
    });
    /*IE*/
    $(window).scroll(function() {
        updatePosition();
    });
    $(window).resize(function() {
        updatePosition();
        update_index_flash_width();
        if ($('#index_page').length == 0)
            extendContent();
    });
    updatePosition();
    if ($('#index_page').length == 0)
        extendContent();
    update_index_flash_width();
    if (($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent))) {
        if ($('#index_page').length > 0) {
            if ($('.footer_row').width() > $('.footer_row_secondline').width())
                $('.footer_row_secondline').width($('.footer_row').width());
            else if ($('.footer_row').width() < $('.footer_row_secondline').width())
                $('.footer_row').width($('.footer_row_secondline').width());
        }
    }
});

function configureLeftMenu() {
    $("#nav_zone li ul").each(function() {
        var currSub = $(this);
        $(this).parent().hover(function() {
            //alert($(this).prev());
            hideAll();
            $('#main_zone').css({ 'z-index': '-1' });
            var mainMenu = $(this).parent("#nav_zone");
            mainMenu.attr("active", 1)
            var iWidth = mainMenu.width();
            currSub.css({ display: "block" }).show();
            selected = 0;
            if (!currSub.prevAll("a:eq(0)").hasClass("selected")) {
                //alert(currSub.prevAll("a:eq(0)").hasClass("selected"));
                selected = 1;
                currSub.prevAll("a:eq(0)").addClass("selected");
            }
            var subMenuWidth = currSub.width();
            var subMenuHeight = currSub.height();
            //currSub.children("li").children("iframe").css("width", subMenuWidth+"px").css("height", subMenuHeight+"px");
            /*currSub.prev("iframe").css({
            "width": subMenuWidth+"px",
            "height": subMenuHeight+"px",
            "display": "block"
            })*/
        }, function() {
            $('#main_zone').css({ 'z-index': '0' });
            currSub.hide();
            //currSub.prev("iframe").css('display', 'none');
            if (selected == 1)
                currSub.prevAll("a:eq(0)").removeClass("selected");
        });
    });
}


function Print() {

    var divMyArea = document.getElementById("right_content");

    if (divMyArea.innerHTML != '') {
        var generator = window.open(self.location, '_blank', 'toolbar=1,titlebar=1,status=0,menubar=yes,location= 1,scrollbars=yes');

        generator.document.write('<html><head><title>Popup</title>');
        generator.document.write('<link href="/files/chi/css/style.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/eng/css/style.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/frontpage/css/theme_trade.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/frontpage/css/theme_training.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/frontpage/css/theme_levy.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/frontpage/css/theme_general.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/frontpage/css/theme_services.css" rel="stylesheet" type="text/css" />');
        generator.document.write('<link href="/files/frontpage/css/theme_about_cic.css" rel="stylesheet" type="text/css" />');
        generator.document.write('</head><body id=' + document.body.id + '>');
        generator.document.write(divMyArea.innerHTML);
        generator.document.write('</body></html>');

    }
}

function hideAll(){
	$("#nav_zone li ul").each(function(){
		$(this).css('display', 'none');
		//$(this).prev("iframe").css('display', 'none');
	});
}

function getY(arg){
	var y = 0;
	if (arg.offsetParent){
		y = getY(arg.offsetParent);
	}
	return arg.offsetTop + y;
}

function getX(arg){
	var x = 0;
	if (arg.offsetParent){
		x = getX(arg.offsetParent);
	}
	return arg.offsetLeft + x;
}

var templateSize = {
	reset: function(){
	},
	set: function(size, me){
		$('body')
			.removeClass('font_size_small')
			.removeClass('font_size_medium')
			.removeClass('font_size_large')
			.addClass('font_size_'+size);
		$('#lang_zone').find('#large_btn, #medium_btn, #small_btn').each(function(){
			var thisSize = this.id.replace("_btn", "");
			this.className = thisSize;
			if(thisSize==size) this.className += " "+thisSize+"_selected";
		});
	}
}

jQuery(function(){
	if (typeof(configureLeftMenu)=="function") {
		configureLeftMenu();
	}
		$('#lang_zone').find('#large_btn, #medium_btn, #small_btn').bind('click', function(){
		var thisSize = this.id.replace("_btn", "");
		templateSize.set(thisSize, this);
	});
	$("#gototop_zone .gototop_bottom").each(function(){
		$(this).click(function(){
			current_scrollvalue=$("body").scrollTop()||$("html").scrollTop();
			if (current_scrollvalue>0)
				pageScroll(0,3);
			return false;
		}		
		)}
	)
	
	
		if (indexbanner_list.length>3 && $('#banner_index0').length>0)
	 indexbanner_timer = setInterval("rotate_banner()",3000);
	 
	 
	 $("ol > li").each(function(){
	 if (currentLang!='eng')
	 {
		$(this).html('<span style="letter-spacing: '+$('.content_area').css('letter-spacing')+'">'+$(this).html()+'</span>');
		$(this).css({'margin-left': (parseInt($(this).css('margin-left'))+parseInt($('.content_area').css('letter-spacing')))+'px'});
		$(this).css({'letter-spacing': '0em'});
	 }
	 });
	
	 $('a.show_div, a.hide_div').each(function(){
		var $this = $(this);
		var triggerClass = ['hide', 'show'];
		var isShowHide = this.className.replace("_div", "");
		var action = {
			to: triggerClass[(isShowHide==triggerClass[0]?0:1)],
			from: isShowHide
		}
		var thisName = this.id.replace("_"+isShowHide, "");
		var thisParentTr = $this.parents('tr:eq(0)');
		$this.bind('click', function(){
			$("#"+thisName+'.showhide_tr').attr('class', 'showhide_tr '+triggerClass[0]);
			$("#"+thisName).attr('class', 'showhide_tr '+action.to);
		});
	 });
})

var pageScrollTimer;
function pageScroll(toY,frms,cuY) { 
current_scrollvalue=$("body").scrollTop()||$("html").scrollTop();
if (pageScrollTimer) clearTimeout(pageScrollTimer);
if (!toY || toY < 0) toY = 0;
if (!cuY) cuY = 0 + current_scrollvalue;
 if (!frms) frms = 6;

 //if (toY > cuY && toY > (getAnchorPosObj('end','enddiv').y) - getInnerSize().height) toY = (getAnchorPosObj('end','enddiv').y - getInnerSize().height) + 1;
 cuY += (toY - current_scrollvalue) / frms; if (cuY < 0) cuY = 0;
 var posY = Math.floor(cuY);
 window.scrollTo(0, posY);

 if (posY != toY) {
 pageScrollTimer = setTimeout("pageScroll("+toY+","+frms+","+cuY+")",10);
 }
} 

indexlink= new Array();

indexlink.push({ secnum: "1", subsecnum: "0", link: "about_cic/index.aspx", target: "_self" });
indexlink.push({ secnum: "1", subsecnum: "1", link: "about_cic/profile.aspx", target: "_self" });
indexlink.push({ secnum: "1", subsecnum: "2", link: "about_cic/functions.aspx", target: "_self" });
//indexlink.push({ secnum: "1", subsecnum: "3", link: "about_cic/governance.aspx", target: "_self" });
indexlink.push({ secnum: "1", subsecnum: "3", link: "about_cic/ciccouncil.aspx", target: "_self" });
indexlink.push({ secnum: "1", subsecnum: "4", link: "about_cic/recruit.aspx", target: "_self" });
indexlink.push({ secnum: "1", subsecnum: "5", link: "about_cic/tender.aspx", target: "_self" });
indexlink.push({ secnum: "1", subsecnum: "6", link: "about_cic/registration.aspx", target: "_self" });
indexlink.push({ secnum: "2", subsecnum: "0", link: "services/index.aspx", target: "_self" });
indexlink.push({ secnum: "2", subsecnum: "1", link: "http://www.hkcic.org/vsrs/index_e.htm", target: "_blank" });
indexlink.push({ secnum: "2", subsecnum: "2", link: "http://www.cwra.org.hk/LatestNews/News.asp", target: "_blank" });
indexlink.push({ secnum: "3", subsecnum: "0", link: "levy/index.aspx", target: "_self" });
indexlink.push({ secnum: "3", subsecnum: "1", link: "https://levy.hkcic.org", target: "_blank" });
indexlink.push({ secnum: "3", subsecnum: "2", link: "levy/guidelines.aspx", target: "_self" });
indexlink.push({ secnum: "3", subsecnum: "3", link: "levy/forms.aspx", target: "_self" });
indexlink.push({ secnum: "3", subsecnum: "4", link: "levy/decision.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "0", link: "courses/index.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "1", link: "courses/newclasses.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "2", link: "courses/newentrants.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "3", link: "courses/inservice.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "4", link: "courses/output.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "5", link: "employer/index.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "6", link: "courses/applicants.aspx", target: "_self" });
indexlink.push({ secnum: "4", subsecnum: "7", link: "courses/recommend.aspx", target: "_self" });
indexlink.push({ secnum: "5", subsecnum: "0", link: "skilltest/index.aspx", target: "_self" });
indexlink.push({ secnum: "5", subsecnum: "1", link: "skilltest/bc-trades.aspx", target: "_self" });
indexlink.push({ secnum: "5", subsecnum: "2", link: "skilltest/em-trades.aspx", target: "_self" });
indexlink.push({ secnum: "5", subsecnum: "3", link: "skilltest/mc-trades.aspx", target: "_self" });
indexlink.push({ secnum: "5", subsecnum: "4", link: "skilltest/achievement.aspx", target: "_self" });


function jumpSection(langNum, sectionNum, subSectionNum) {
    var selected_lang, langtype;
    if (langNum == 1) {
        selected_lang = 'eng';
        langtype = 1033;
    }
    else if (langNum == 2) {
        selected_lang = 'chi';
        langtype = 1028;
    }
    else if (langNum == 3) {
        selected_lang = 'chi';
        langtype = 1028;
    }
    for (var i = 0; i < indexlink.length; i++) {
        if (sectionNum == indexlink[i].secnum & subSectionNum == indexlink[i].subsecnum) {
            var url = '';
            if (indexlink[i].link.indexOf('http://') == -1 && indexlink[i].link.indexOf('https://') == -1)
                url = currentPath + '/' + selected_lang + '/' + indexlink[i].link + '?langType=' + langtype;
            else
                url = indexlink[i].link;
            if (indexlink[i].target == '_self')
                location.href = url;
            else if (indexlink[i].target == '_blank')
                window.open(url, 'popup');
        }
    }

}

function jumpTopSection(topSectionNum) {
    if (topSectionNum == 1)
        location.href = currentPathLangnohttps + 'main.aspx';
    else if (topSectionNum == 2)
        location.href = currentPathLanghttps + 'member/login.aspx';
    else if (topSectionNum == 3)
        location.href = currentPathLangnohttps + 'info/index.aspx';
    else if (topSectionNum == 4)
        location.href = currentPathLangnohttps + 'news/index.aspx';
    else if (topSectionNum == 5)
        location.href = currentPathLangnohttps + 'contact/index.aspx';
    else if (topSectionNum == 6)
        location.href = 'http://intranet.hkcic.org/';
}

function jumpIndexTopSection(topSectionNum) {
    if (topSectionNum == 1)
        location.href = currentPathLanghttps + 'member/login.aspx';
    else if (topSectionNum == 2)
        location.href = currentPathLangnohttps + 'info/index.aspx';
    else if (topSectionNum == 3)
        location.href = currentPathLangnohttps + 'news/index.aspx';
    else if (topSectionNum == 4)
        location.href = currentPathLangnohttps + 'contact/index.aspx';
    else if (topSectionNum == 5)
        location.href = 'http://intranet.hkcic.org/';
}

function searchContent(searchVar) {
    if (currentLang == 'eng') {
        location.href = currentPathLangnohttps + 'SearchResults.aspx?QueryExpr=' + encodeURIComponent(searchVar) + '&ResultsPage=1&langType=1033';
    }
    else {
        location.href = currentPathLangnohttps + 'SearchResults.aspx?QueryExpr=' + encodeURIComponent(searchVar) + '&ResultsPage=1&langType=1028';
    }
    //location.href = currentPathLang + 'test1.aspx?QueryExpr=' + encodeURIComponent(searchVar);   
    
}

indexbanner_list = new Array();
static_banner = new Array();
filepath = currentPath + '/files/' + currentLang + '/graphics/';


static_banner.push({ filename: filepath + 'banner_GovHK.gif', link: "http://www.gov.hk", target: "_blank" });
if (currentLang == 'eng') {
//    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllEngDoc/5584B42D17421037482575EF001F9AF4/$FILE/CAP_587_e_b5.pdf", target: "_blank" });
//    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1033", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_SportDay.gif', link: currentPathLang + "news/event.aspx?langType=1033", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1033", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index_e.htm", target: "_blank" });   
//     indexbanner_list.push({ filename: filepath + 'banner_FormDownload.gif', link: currentPathLang + "download/index.aspx?langType=1033", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_OpenDay.gif', link: currentPathLang + "news/event.aspx?langType=1033", target: "" });
     
     
     
     
    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllEngDoc/5584B42D17421037482575EF001F9AF4/$FILE/CAP_587_e_b5.pdf", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1033", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_BasicCraft.gif', link: currentPathLang + "courses/newentrants01.aspx?langType=1033", target: "" });
     
    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1033", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index_e.htm", target: "_blank" });   
    indexbanner_list.push({ filename: filepath + 'banner_SupervisorTech.gif', link: currentPathLang + "courses/newentrants02.aspx?langType=1033", target: "" });
     
    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllEngDoc/5584B42D17421037482575EF001F9AF4/$FILE/CAP_587_e_b5.pdf", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1033", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_EnhancedConstManpower.gif', link: currentPathLang + "courses/newentrants06.aspx?langType=1033", target: "" });
     
    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1033", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index_e.htm", target: "_blank" });   
    indexbanner_list.push({ filename: filepath + 'banner_BasicCraft.gif', link: currentPathLang + "courses/newentrants01.aspx?langType=1033", target: "" });

    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllEngDoc/5584B42D17421037482575EF001F9AF4/$FILE/CAP_587_e_b5.pdf", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1033", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_SupervisorTech.gif', link: currentPathLang + "courses/newentrants02.aspx?langType=1033", target: "" });

    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1033", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index_e.htm", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_EnhancedConstManpower.gif', link: currentPathLang + "courses/newentrants06.aspx?langType=1033", target: "" });
     
     
  
}
else {
//    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllChinDoc/07833296D111C455482575EF001F8EDF/$FILE/CAP_587_c_b5.pdf", target: "_blank" });
//    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1028", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_SportDay.gif', link: currentPathLang + "news/event.aspx?langType=1033", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1028", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index.htm", target: "_blank" });    
//     indexbanner_list.push({ filename: filepath + 'banner_FormDownload.gif', link: currentPathLang + "download/index.aspx?langType=1028", target: "" });
//    indexbanner_list.push({ filename: filepath + 'banner_OpenDay.gif', link: currentPathLang + "news/event.aspx?langType=1028", target: "" });
   
   
   
   
    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllChinDoc/07833296D111C455482575EF001F8EDF/$FILE/CAP_587_c_b5.pdf", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1028", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_BasicCraft.gif', link: currentPathLang + "courses/newentrants01.aspx?langType=1028", target: "" });

    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1028", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index.htm", target: "_blank" });    
    indexbanner_list.push({ filename: filepath + 'banner_SupervisorTech.gif', link: currentPathLang + "courses/newentrants02.aspx?langType=1028", target: "" });
   
    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllChinDoc/07833296D111C455482575EF001F8EDF/$FILE/CAP_587_c_b5.pdf", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1028", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_EnhancedConstManpower.gif', link: currentPathLang + "courses/newentrants06.aspx?langType=1028", target: "" });

    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1028", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index.htm", target: "_blank" });    
    indexbanner_list.push({ filename: filepath + 'banner_BasicCraft.gif', link: currentPathLang + "courses/newentrants01.aspx?langType=1028", target: "" });
   
    indexbanner_list.push({ filename: filepath + 'banner_Ordinance.gif', link: "http://www.legislation.gov.hk/blis_pdf.nsf/CurAllChinDoc/07833296D111C455482575EF001F8EDF/$FILE/CAP_587_c_b5.pdf", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_HotCourses.gif', link: currentPathLang + "courses/recommend.aspx?langType=1028", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_SupervisorTech.gif', link: currentPathLang + "courses/newentrants02.aspx?langType=1028", target: "" });

    indexbanner_list.push({ filename: filepath + 'banner_Vacancy.gif', link: currentPathLang + "about_cic/recruit.aspx?langType=1028", target: "" });
    indexbanner_list.push({ filename: filepath + 'banner_VSRS.gif', link: "http://www.hkcic.org/vsrs/index.htm", target: "_blank" });
    indexbanner_list.push({ filename: filepath + 'banner_EnhancedConstManpower.gif', link: currentPathLang + "courses/newentrants.aspx06?langType=1028", target: "" });
   
   
   
}
    
var start_index = 0;
var counter = 0;
no_of_banner = 30;
if (indexbanner_list.length < no_of_banner) {
    no_of_banner = indexbanner_list.length;
}


function generateindex_banner() {
    var html_text = '';
    current_index = start_index;

    if (counter == 0) {
        html_text += '<div id="dynamic_banner">';
        html_text += '<a href="' + static_banner[counter].link + '" target="' + static_banner[counter].target + '"><img src="' + static_banner[counter].filename + '" /></a>';
        current_index = (current_index + 1) % indexbanner_list.length;
    }
    for (var i = 0; i < no_of_banner; i++) {
        current_index = (current_index + 1) % indexbanner_list.length;
        html_text += '<span id="banner_index' + current_index + '" onMouseOver="OnMouseStop=true;" onMouseOut="OnMouseStop=false;"';
        if (current_index > 2) {
            html_text += ' style="display:none";';
        }
        html_text += '>';
        html_text += '<a href="' + indexbanner_list[current_index].link + '" target="' + indexbanner_list[current_index].target + '"><img src="' + indexbanner_list[current_index].filename + '" /></a>';
        html_text += '</span>';
    }
    if (counter == 0) {
        html_text += '</div>';
        $("#index_page .banner_zone").html(html_text);
    }
    else {
        $("#index_page .banner_zone #dynamic_banner").html(html_text);
    }
    start_index = (start_index + 1) % indexbanner_list.length;
    counter++;
}

var banner = no_of_banner;
var OnMouseStop = false;
function rotate_banner() {
    if (banner < 3 || OnMouseStop) {
        setTimeout("rotate_banner();", 3000);
        return;
    }
    for (j = 0; j < 3; j++) {
        temp_banner = document.getElementById("banner_index0").innerHTML;
        for (i = 0; i < parseInt(banner); i++) {
            next_banner = i + 1;
            if (next_banner >= parseInt(banner)) { next_banner = 0; }
            document.getElementById("banner_index" + i).innerHTML = document.getElementById("banner_index" + next_banner).innerHTML;
        }
        document.getElementById("banner_index" + (i - 1)).innerHTML = temp_banner;
    }
    //setTimeout("rotate_banner();",3000);
}

$(function() {
    $('#index_page #shortcuts #bottom .nav a.firstnav').each(
		function() {
		    var thisparent = $(this).parent('#index_page #shortcuts #bottom .nav');
		    $(this).hover(
				function() {
				    hideAllRollover();
				    thisparent.children('.rollover').show();
				}, function() {
				    //thisparent.children('.rollover').hide();
				}
			)
		}
	)
    $('#index_page #shortcuts #bottom .nav .rollover').each(
		function() {
		    $(this).hover(
				function() {
				}, function() {
				    $(this).hide();
				}
			)
		}
	)
})

function hideAllRollover() {
    $('#index_page #shortcuts #bottom .nav .rollover').each(
		function() {
		    $(this).hide();
		}
	)
}

function getViewportDimensions() {
    var intH = 0, intW = 0;

    if (self.innerHeight) {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if (document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}


function extendContent() {

    var totalheight = $("#top_zone").outerHeight(true) + $("#nav_zone_outer").outerHeight(true) + $("#bottom_zone_outer").outerHeight(true);
    var difference = getViewportDimensions().height - totalheight;
    //alert(difference+'='+($(window).height()+'-'+'('+$(".header").outerHeight()+'+'+$("#top_zone_outer").outerHeight()+'+'+$("#bottom_zone_outer").outerHeight()+')+6'));
    if (difference > $('.right_content').outerHeight(true)) {
        var new_height = difference - $('.breadcrumb').outerHeight(true) - 15;
        //Check IE6
        if (($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent))) {
            $('.main_content').height(new_height);
        }
        else {
            $('.main_content').css("min-height", new_height + "px");
        }
    }
    else if ($('.left_content').outerHeight(true) > $('.right_content').outerHeight(true)) {
        var new_height = $('.left_content').outerHeight(true) + 20 - $('.breadcrumb').outerHeight(true) - 15;
        //Check IE6
        if (($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent))) {
            $('.main_content').height(new_height);
        }
        else {
            $('.main_content').css("min-height", new_height + "px");
        }
    }
}


function mapSearchLink(searcnLink) {
 mywindow=window.open (currentPathLangnohttps + 'contact/' + encodeURIComponent(searcnLink) + '.aspx','mywindow','status=0,toolbar=0, menubar=0, width=600,height=500');
 mywindow.moveTo(0,0);
}