﻿<!--//
/*Javascript File for Common Functions
Created on 1st Feb 2010
*/
//Add multiple functions to window.onload Event.
function addLoadEvent(func) {       
	var oldonload = window.onload;       
	if (typeof window.onload != 'function') {       
		window.onload = func;       
	}
	else {       
		window.onload = function() {       
			if (oldonload) {       
				oldonload();       
			}       
			func();       
		}       
	}       
}
//------------------------------------------------------------------------------------------
//Capture Events
function getEvent(e){if(e==null){e=window.event;}if(e.srcElement){var o=e.srcElement;}if(e.currentTarget){var o=e.currentTarget;}if(e.target){var o=e.target;}return o;}
function getKeyCode(e){if(e==null){e=window.event;} return e.keyCode;}
//------------------------------------------------------------------------------------------
//Checking Function(s)
function isArray(){if (typeof arguments[0] == 'object'){var c=arguments[0].constructor.toString().match(/array/i);return (c!= null);}return false;}
//------------------------------------------------------------------------------------------
function trim(s){return s.replace(/^\s*|\s*$/g,"");}
//------------------------------------------------------------------------------------------
//Layout Function(s)
function hideStatusBar(){return true;}
if (document.layers){document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);}
document.onmouseover=hideStatusBar;document.onmouseout=hideStatusBar;
//------------------------------------------------------------------------------------------
//Handle external Links for anchor <a>
function extLinks(){   
 if (!document.getElementsByTagName) return;   
 var anchors = document.getElementsByTagName("a");   
 for (var i=0; i<anchors.length; i++){   
   var anchor = anchors[i];   
   if (anchor.getAttribute("href") && anchor.getAttribute("rel")=="external"){anchor.target = "_blank";}
}   
}
addLoadEvent(extLinks);
//------------------------------------------------------------------------------------------
//Print innerHTML contents of given IDs
function printContent(id){
	var strTop=document.getElementById('cell_topMenu').innerHTML.toString();
	var strContent=document.getElementById(id).innerHTML.toString();
	var printWin=window.open('','printWin','width=650,location=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=yes');
	printWin.document.title='Innovation and Technology Fund | 創新及科技基金';
	printWin.document.open();
	printWin.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>');
	printWin.document.writeln('<title>Innovation and Technology Fund | 創新及科技基金</title>');
	printWin.document.writeln('<meta name="application-name" content="Innovation and Technology Fund | 創新及科技基金"/>');
	printWin.document.writeln('<meta name="description" content="Innovation and Technology Fund | 創新及科技基金">');
	printWin.document.writeln('<sc'+'ri'+'pt type="text/javascript" src="/Include/js_Common.js">'+'</'+'sc'+'ri'+'pt>');
	printWin.document.writeln('<sc'+'ri'+'pt type="text/javascript" src="/Include/js_Menu.js">'+'</'+'sc'+'ri'+'pt>');
	printWin.document.writeln('<sc'+'ri'+'pt language="javascript" type="text/javascript" defer\>'); 
	printWin.document.writeln('function Print(){document.body.offsetHeight;window.print()}');
	printWin.document.writeln('<\/'+'script\>'); 
	printWin.document.writeln('<link href="http://localhost/Include/CSS.css" rel="stylesheet">');
	printWin.document.writeln('<style type="text/css">img{border:none;}</style>');
	printWin.document.writeln('</head><body onload="Print();window.close();"><div style="width:604px;"><table id="printTable" border="0" cellpadding="0" cellspacing="0"><tr><td>');
	printWin.document.writeln('<table id="printTopTable" border="0" cellpadding="0" cellspacing="0" style="text-align: justify;"><tr><td>');
	printWin.document.writeln(strTop);
	printWin.document.writeln('</td></tr></table>');
	printWin.document.writeln('<table id="contentTable" border="0" cellpadding="0" cellspacing="0" style="text-align: justify;">');
	printWin.document.writeln(strContent);
	printWin.document.writeln('</table></td></tr></table></div></body>');
	printWin.document.writeln('</html>');
	printWin.document.close();
	//printWin.window.focus();
	//printWin.window.print();
	//printWin.window.close();
	return false
}
//------------------------------------------------------------------------------------------
//Enable Tool Tips
if (window.addEventListener){window.addEventListener("load", enableToolTip, false);}else if (window.attachEvent){window.attachEvent("onload", enableToolTip);}
function enableToolTip(){var a=document.getElementsByTagName("*");for(i=a.length-1;i>-1;i--){if (a[i].alt){a[i].title = a[i].alt;}}}
//------------------------------------------------------------------------------------------
//List Related Function
//Nested Order List
function genNestedOrderList(ol,prefix,indent,n){
	var intNum=n;
	var intIndent=indent,intIndentSize=14; //should be same as the font-size set in CSS
	var strPre=prefix;
	if(!intNum){intNum=1;}
	if(!intIndent){intIndent=0;}
	if(!strPre){strPre='';}
	if(ol){ol.style.listStyleType='none';}
	if(ol){
	for(var i=0;i<ol.childNodes.length;i++){
		if(ol.childNodes[i].nodeType==1 && ol.childNodes[i].tagName=='LI'){
			if(intIndent==0){
			ol.childNodes[i].innerHTML='<b>'+strPre+intNum.toString()+'.</b>'+ol.childNodes[i].innerHTML;
			}else{
			ol.childNodes[i].innerHTML=strPre+intNum.toString()+'.'+ol.childNodes[i].innerHTML;
			}
			ol.childNodes[i].style.textIndent=intIndent-intIndentSize;
			if(ol.childNodes[i].childNodes.length>0){
				var j=0, olFlag=false, child=ol.childNodes[i].childNodes;
				while(j<child.length && olFlag==false){
					if(child[j].tagName=='OL'){olFlag=true;}
					j++;
				}
				if(olFlag==true){genNestedOrderList(child[j-1],strPre+intNum.toString()+'.',intIndent-intIndentSize);}
			}
			intNum++;
		}
	}
	}
}
//------------------------------------------------------------------------------------------
function continueList(prevListID){	//Get the previous list last number, and +1 return
	var ol = document.getElementById(prevListID);
	var intCount=0; var liIndex=0;
	if(ol){
		if(ol.tagName=="OL"){
			for(var i=0;i<ol.childNodes.length;i++){
			if(ol.childNodes[i].nodeType==1 && ol.childNodes[i].tagName=='LI'){
				if(liIndex==0){liIndex=i;}
				intCount+=1; //count + 1
				alert(ol.childNodes[i].value);
			}
			}
			if(ol.childNodes[liIndex].value==0||ol.childNodes[liIndex].value==-1){return intCount+1;}
			else{return ol.childNodes[liIndex].value+intCount;}
		}
	}
	return 0;
}
//------------------------------------------------------------------------------------------
function setListStartValue(id,value){
	var ol = document.getElementById(id);
	var blnCheck=true;
	if(ol){
		if(ol.tagName=="OL"){
		var i=0
		while(i<ol.childNodes.length && blnCheck==true){
			if(ol.childNodes[i].nodeType==1 && ol.childNodes[i].tagName=='LI'&&blnCheck==true){
				ol.childNodes[i].value=value;
				blnCheck=false;
			}
			i++;
		}
		}
	}
}
//------------------------------------------------------------------------------------------
function checkWinOS(){
	var os=0;
	if(navigator.platform == "Win16" ){os=1;}
	if(navigator.platform == "Win32" ){os=1;}
	if(navigator.platform == "Win64" ){os=1;}
	if(os==1){return true;}else{return false;}
}
//------------------------------------------------------------------------------------------
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
//------------------------------------------------------------------------------------------
//Function use to switch FONT CSS
function changeFontSize(size){
	if(!size){size="0";}
	var oStyle = document.getElementsByTagName("link");
	for(var i=0;i<oStyle.length;i++){
		if(oStyle[i].getAttribute("rel").indexOf("style")!=-1){
			if(oStyle[i].title.toString().toUpperCase().indexOf("CSSFONT")!=-1){
				if(oStyle[i].title.toString().toUpperCase()=="CSSFONT0"){oStyle[i].disabled=true;}
				if(oStyle[i].title.toString().toUpperCase()=="CSSFONT"+size.toString().toUpperCase()){
					oStyle[i].disabled=false;
				}else{oStyle[i].disabled=true;}
			}
		}
	}
	
}
//addLoadEvent(changeFontSize);
//------------------------------------------------------------------------------------------
function setOLNum(ol,startNum,prefix, handleChild){
	if(ol){
		var intStart=parseInt(startNum,10);
		if(isNaN(intStart)){intStart=1;}
		//var li=ol.getElementsByTagName("li");
		if(ol.hasChildNodes){
			for(var i=0;i<ol.childNodes.length;i++){
				//alert(li[i].innerHTML);
				if(ol.childNodes[i].innerHTML.toString().toUpperCase().indexOf('<SPAN CLASS=BOLD>')==0){
					ol.childNodes[i].innerHTML="<span class='bold' style='padding-right:0.8em'>"+prefix.toString()+intStart.toString()+'.</span>'+ol.childNodes[i].innerHTML
				}else{
					ol.childNodes[i].innerHTML="<span>" + prefix.toString()+intStart.toString()+"&nbsp;&nbsp;</span>"+ol.childNodes[i].innerHTML
				}
				var subOL = ol.childNodes[i].getElementsByTagName("ol");
				if(subOL&&handleChild){setOLNum(subOL[0],1,prefix.toString()+intStart.toString()+".",true);}
				intStart++;
			}
		}
		return intStart
	}
}
//------------------------------------------------------------------------------------------
//Fix for IE7 CSS list and Count
if(getInternetExplorerVersion()<8.0 && getInternetExplorerVersion()>-1){addLoadEvent(fixIE7OLList);}
function fixIE7OLList(){
//Fix PPS numbering
var olPPS=document.getElementById("pps");
if(olPPS){//add number back
	setOLNum(olPPS,1,"",true);
}
//Fix FAQ numbering
var Num=1;
var olFAQ=document.getElementById("faq_list1");
if(olFAQ){Num=setOLNum(olFAQ,1,"",false);}
var olFAQ2=document.getElementById("faq_list2");
if(olFAQ2){Num=setOLNum(olFAQ2,Num,"",false);}
}
