///////////////////////////////////////////////////////////////////////////////////////////////////////
// ua.js - Detect Browser
// Requires JavaScript 1.1

// work around bug in xpcdom Mozilla 0.9.1
window.saveNavigator = window.navigator;

document.write("<script language='JavaScript' src='/hongkong/js/blocksignin.js' type='text/javascript'></script>");
document.write("<script language='JavaScript' src='/hongkong/js/cc_blocksignin.js' type='text/javascript'></script>");

// Handy functions
function noop() {}
function noerror() { return true; }

function defaultOnError(msg, url, line)
{
  // customize this for your site
  if (top.location.href.indexOf('/evangelism/lib/js/errors/') == -1)
    top.location = '/evangelism/lib/js/errors/index.html?msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line);
}

// Display Error page... 
// XXX: more work to be done here
//
function reportError(message)
{
  // customize this for your site
  if (top.location.href.indexOf('/evangelism/lib/js/errors/') == -1)
    top.location = '/evangelism/lib/js/errors/index.html?msg=' + escape(message);
}

function pageRequires(cond, msg, redirectTo)
{
  if (!cond)
  {
    msg = 'This page requires ' + msg;
    top.location = redirectTo + '?msg=' + escape(msg);
  }
  // return cond so can use in <A> onclick handlers to exclude browsers
  // from pages they do not support.
  return cond;
}

function detectBrowser()
{
  var oldOnError = window.onerror;
  var element = null;
  
  window.onerror = defaultOnError;

  navigator.OS    = '';
  navigator.version  = 0;
  navigator.org    = '';
  navigator.family  = '';

  var platform;
  if (typeof(window.navigator.platform) != 'undefined')
  {
    platform = window.navigator.platform.toLowerCase();
    if (platform.indexOf('win') != -1)
      navigator.OS = 'win';
    else if (platform.indexOf('mac') != -1)
      navigator.OS = 'mac';
    else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
      navigator.OS = 'nix';
  }

  var i = 0;
  var ua = window.navigator.userAgent.toLowerCase();
  
  if (ua.indexOf('opera') != -1)
  {
    i = ua.indexOf('opera');
    navigator.family  = 'opera';
    navigator.org    = 'opera';
    navigator.version  = parseFloat('0' + ua.substr(i+6), 10);
  }
  else if ((i = ua.indexOf('msie')) != -1)
  {
    navigator.org    = 'microsoft';
    navigator.version  = parseFloat('0' + ua.substr(i+5), 10);
    
    if (navigator.version < 4)
      navigator.family = 'ie3';
    else
      navigator.family = 'ie4'
  }
  else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
  {
    i = ua.lastIndexOf('/')
    navigator.version = parseFloat('0' + ua.substr(i+1), 10);
    navigator.family = 'gecko';

    if (ua.indexOf('netscape') != -1)
      navigator.org = 'netscape';
    else if (ua.indexOf('compuserve') != -1)
      navigator.org = 'compuserve';
    else
      navigator.org = 'mozilla';
  }
  else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  {
      var is_major = parseFloat(navigator.appVersion);
    
    if (is_major < 4)
      navigator.version = is_major;
    else
    {
      i = ua.lastIndexOf('/')
      navigator.version = parseFloat('0' + ua.substr(i+1), 10);
    }
    navigator.org = 'netscape';
    navigator.family = 'nn' + parseInt(navigator.appVersion);
  }
  else if ((i = ua.indexOf('aol')) != -1 )
  {
    // aol
    navigator.family  = 'aol';
    navigator.org    = 'aol';
    navigator.version  = parseFloat('0' + ua.substr(i+4), 10);
  }

  navigator.DOMCORE1  = (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
  navigator.DOMCORE2  = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
  navigator.DOMHTML  = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
  navigator.DOMCSS1  = ( (navigator.family == 'gecko') || (navigator.family == 'ie4') );

  navigator.DOMCSS2   = false;
  if (navigator.DOMCORE1)
  {
    element = document.createElement('p');
    navigator.DOMCSS2 = (typeof(element.style) == 'object');
  }

  navigator.DOMEVENTS  = (typeof(document.createEvent) != 'undefined');

  window.onerror = oldOnError;
}

detectBrowser();

// ua.js - Detect Browser
///////////////////////////////////////////////////////////////////////////////////////////////////////

var supportBrowser = true;
if (navigator.org == "microsoft" && navigator.version >= 5.5) {
	supportBrowser = true;
} else if (navigator.org == "netscape" && navigator.version >= 6) {
	supportBrowser = true;
}

if (!supportBrowser) {
	location.href="/hongkong/english/browser.html";
}

BROWSER_NS = (document.layers) ? true : false;
BROWSER_NSold = (BROWSER_NS && (parseFloat(navigator.appVersion) < 6.0));


function getCurrentHTMLFilename() {
	var strFilename = new String(self.document.location.pathname)
	return	strFilename.substr(strFilename.lastIndexOf("/") + 1);
}

function getCurrentHTMLPathFilename() {
	return self.document.location.pathname;
}

function getAltLangURL(){
	var strPathName = new String(self.document.location.href)
	if (strPathName.search("chinese") > 0) {
		return strPathName.replace(/chinese/g, "english");
	} else {
		return strPathName.replace(/english/g, "chinese");
	}
	return strPathName;
}

function showImage(id,img){
	document.images[id].src = img;
}

function gotoCalcPage(form){
	if (form.optSelect.value == '0') {
		return false;
	} else if (form.optSelect.value == '1') {
		window.location = "/hongkong/english/personal_banking/investments/risk_profile.html"
	} else if (form.optSelect.value == '7') {
		window.location = "/hongkong/english/personal_banking/investments/calc_future.html"
	} else if (form.optSelect.value == '2') {
		window.location = "/hongkong/english/personal_banking/investments/calc_inv.html"
	} else if (form.optSelect.value == '3') {
		window.location = "/hongkong/english/personal_banking/deposits/calc_forex.html"
	} else if (form.optSelect.value == '4') {
		window.location = "/hongkong/english/personal_banking/deposits/calc_deposit.html"
	} else if (form.optSelect.value == '8') {
		window.location = "/hongkong/english/personal_banking/deposits/calc_maxi.html"		
	} else if (form.optSelect.value == '5') {
		window.location = "/hongkong/english/personal_banking/loans/calc_loan.html"
	} else if (form.optSelect.value == '6') {
		window.location = "/hongkong/english/personal_banking/loans/calc_mortgage.html"
	} else if (form.optSelect.value == '9') {
		window.location = "https://online.asia.ccb.com/PersonalHKWeb/servlet/EvaluationServlet?reqTrx=eValRequest&Lang=Eng&CalledFrom=LoanIndex"
	}
}
//		alert("loading util.js");

function gotoRatePage(form){
	if (form.optSelect.value == '0') {
		return false;
	} else if (form.optSelect.value == '1') {
		window.location = "/hongkong/english/rateenquiry/dep_rates_hkd.html";
	} else if (form.optSelect.value == '4') {
		window.location = "/hongkong/english/rateenquiry/dep_rates_usd.html";
	} else if (form.optSelect.value == '6') {
		window.location = "/hongkong/english/rateenquiry/dep_rates_cny.html";
	} else if (form.optSelect.value == '5') {
		window.location = "/hongkong/english/rateenquiry/dep_rates.html";
	} else if (form.optSelect.value == '2') {
		window.location = "/hongkong/english/rateenquiry/exchange_rates.html";
	} else if (form.optSelect.value == '3') {
		window.location = "/hongkong/english/rateenquiry/loan_rates.html";
	} else if (form.optSelect.value == '7') {
		window.location = "/hongkong/english/rateenquiry/gold_rates.html";
	}
}

function openCurrencyListWindow() {
	var url = "/hongkong/english/personal_banking/investments/currency_list.html"
	var hWnd = window.open(url,"popupWindow","width=461,height=250,resizable=no,scrollbars=no");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openDisclaimerWindow() {
	var url = "/hongkong/english/disclaimer.html"
	var hWnd = window.open(url,"popupWindow","width=700,height=500,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openSitemapWindow() {
	var url = "/hongkong/english/sitemap.html"
	var hWnd = window.open(url,"popupWindow","width=700,height=500,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openTaxTCWindow() {
	var url = "/hongkong/english/personal_banking/loans/t&c_tax.html"
	var hWnd = window.open(url,"popupWindow","width=700,height=500,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openPrivacyOrdinanceWindow() {
	var url = "/hongkong/english/privacyordinance.html"
	var hWnd = window.open(url,"popupWindow1","width=700,height=500,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openCountryListWindow() {
	var url = "/hongkong/english/personal_banking/insurance/country_list.html"
	var hWnd = window.open(url,"popupWindow","width=350,height=450,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openCashierWindow() {
	var url = "/hongkong/english/personal_banking/find_out_more/comm_cashierorder.html"
	var hWnd = window.open(url,"popupWindow","width=450,height=550,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openTravelerCheckWindow() {
	var url = "/hongkong/english/personal_banking/find_out_more/comm_travelercheck.html"
	var hWnd = window.open(url,"popupWindow","width=550,height=450,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openDemandWindow() {
	var url = "/hongkong/english/personal_banking/find_out_more/comm_demand.html"
	var hWnd = window.open(url,"popupWindow","width=550,height=450,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}

function openPartnerWindow() {
	var url = "/hongkong/english/personal_banking/loans/partner.html"
	var hWnd = window.open(url,"popupWindow","width=300,height=200,resizable=no,scrollbars=yes");
	if ((document.window != null) && (!hWnd.opener))
	hWnd.opener = document.window;
}


function openOBWindow()
{
  SigninOB();

}

function openWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	win.focus();
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function SigninOB() {
	if (BlockSignin == "Y") {		
		win = window.open("/hongkong/english/signin_block.html", "CCBAsiaOnlineBanking", "status,scrollbars,resizable,left=0,screenX=0,top=0,screenY=0,height=550,innerHeight=550,width=790,innerWidth=790,alwaysRaised");
	} else {
		win = window.open("https://online.asia.ccb.com/PersonalHKWeb/signin/chgLocale2En.do", "CCBAsiaOnlineBanking", "status,scrollbars,resizable,left=0,screenX=0,top=0,screenY=0,height=550,innerHeight=550,width=790,innerWidth=790,alwaysRaised");
  }
	win.focus();
}

function SigninCCOB() {	
	if (CC_BlockSignin == "Y") {		
		win = window.open("/hongkong/english/cc_signin_block.html", "CCBAsiaOnlineBanking", "status,scrollbars,resizable,left=0,screenX=0,top=0,screenY=0,height=550,innerHeight=550,width=790,innerWidth=790,alwaysRaised");
	} else {
		win = window.open("https://online.asia.ccb.com/CommercialHKWeb/signin/chgLocale2En.do", "CCBAsiaOnlineBanking", "status,scrollbars,resizable,left=0,screenX=0,top=0,screenY=0,height=550,innerHeight=550,width=790,innerWidth=790,alwaysRaised");	
  }	
  
  win.focus();
}






var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)   
		
		   
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	
	return null;
}


function goHome(name)
{
	url= "/index.html";
	//DeleteCookie(name);
	SetCookie('ccbhome', '0', exp,'/');
	window.location.href = url;
}


	
