if(location.hostname=='www.uob.com.hk')location.replace('http://www.uob.com.hk');

/*
*	General Javascript functions
*/

function getWindowName()
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 64;
	var windowname = '';
	for (var i=0; i<string_length; i++)
	{
		var rnum = Math.floor(Math.random() * chars.length);
		windowname += chars.substring(rnum,rnum+1);
	}
	return windowname;
}

function openNewWindow(url)
{
	window.open(url,getWindowName());
}

// Sets the day / night / holiday classes
var DayNightHols = {
	init: function () {
		if (!window.$holiday) $holiday = false;			// Set holiday externally or in this section
		if ($holiday) $('body').addClass ('holiday');	//Actual holiday theme to be applied via CSS

		var hour = new Date().getHours();
		if (hour < 5 || hour >= 17) $('body').addClass ('night');
	}
}

// Fixes IE 'Click to activate' requirement
var FlashFix = {
	init: function () {
		if (jQuery.browser.msie)
			$('#main-content object').not($('#UOB-assist object'))
				.each (function() { this.outerHTML = this.outerHTML; });
	}
}

/*
*	Javascript Include - handles misc content-related functions
*	Works around problems with using jQuery, due to excessive use of document.write in current content
*/
var JSI = {
	/* Tag injector - used to write HTML during runtime, synchronously */
	inject: function (tag, attrs, content) {
		document.write ('<' + tag);
		if (attrs) for (attr in attrs) { document.write (' ' + attr + '="' + attrs[attr] + '"'); }
		document.write ('>');
		if (content) document.write (content);
		document.write ('</' + tag + '>');
	},
	/* Load XML synchronously & works around lack of mis-set HTTP headers */
	loadXML: function (url) {
		var xmlDoc = null;
		try
		{
			if (window.ActiveXObject)
			{
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async = false;
				xmlDoc.load(url);
			}
			else if (window.XMLHttpRequest)
			{
				var req = new XMLHttpRequest();
				req.open("GET", url, false);
				req.send(null);
				xmlDoc = (window.DOMParser)? (new DOMParser()).parseFromString(req.responseText, 'text/xml'): req.responseXML;
			}
			else
			{
				xmlDoc = document.implementation.createDocument("", "", null);
				xmlDoc.async = false;
				xmlDoc.load (url);
			}
		}
		catch (e) { /* Do nothing */ }
		return xmlDoc;
	}
}

/*
*	Semi-legacy support - Selects specified tab and (optional) bullet
*	Expects id's in the form of #tab{n} and #tab{n}-bullet{m}
*/
var TabContent = {
	find: function (anchor) {
		var cur = false;
		var tmp = {anchor: false, id: false};
		var match = false;

		// Search in tabs & li's
		$('#js-tabs .tab-content').each (function (t) {
			$(this).find('li.expandable').each(function (b) {
				tmp.id = $(this).find('#'+anchor);
				tmp.anchor = (tmp.id.length)? tmp.id: $(this).find('a[name='+anchor+']');
				if (
					tmp.anchor.length
					&& this.id
					&& (match = this.id.match(/tab(\d+)-bullet(\d+)/))
				) cur = {tab: match[1], bullet: match[2], anchor: tmp.anchor};
			});
		});

		// Search outside tabs
		if (!cur)
		{
			tmp.id = $('#'+anchor);
			tmp.anchor = tmp.id.length? tmp.id: $('a[name='+anchor+']');
			if (tmp.anchor.length) cur = {tab: false, bullet: false, anchor: tmp.anchor};
		}

		return cur;
	},
	select: function (tab, bullet, anchor) {
		if (tab) JSTab.group[tab-1].click();
		if (bullet) JSListMenu.select('tab'+tab+'-bullet'+bullet);
		anchor = anchor || '#tab'+tab+'-bullet'+bullet;
		TabContent.focus (anchor);
	},
	parseUrl: function () {
		if (location.hash)
		{
			var match = false;
			var anchor = location.hash.match(/#?(.*)$/)[1];
			if (match = anchor.match(/tab(\d+)/)) init_tab = match[1];
			if (match = anchor.match(/bullet(\d+)/)) init_bullet = match[1];
			if (!init_tab && !init_bullet && (match = TabContent.find(anchor))) { init_tab = match.tab; init_bullet = match.bullet; }
			anchor = (match && match.anchor)? match.anchor: '#'+anchor;
			setTimeout (function () { TabContent.focus (anchor); }, 1000);
		}
	},
	initLinks: function (links) {
		$(links).each (function () {
			var match = false; var ctab = 0; var cbullet = 0; var hash = '';
			var cur = {tab: false, bullet: false, anchor: false};
			if (match = this.href.match(/([^#]*#(.+))/))
			{
				hash = match[2];
				cur.anchor = '#'+hash;
				if (match = hash.match(/tab(\d+)/)) { cur.tab = match[1]; }
				if (match = hash.match(/bullet(\d+)/)) { cur.bullet = match[1]; }
				if (!cur.tab && !cur.bullet) cur = TabContent.find(hash);
				if (cur) $(this).click (function () { TabContent.select(cur.tab, cur.bullet, cur.anchor); return false; });
			}
		});
	},
	focus: function (anchor) {
		$(document).scrollTopSmooth ((
			$(anchor).offset() || 
			$('#js-tabs-control').offset() || 
			$('#js-tabs').offset() ||
			$('body').offset()
		).top - 20);
	}
}

jQuery.fn.scrollTopSmooth = function (target, self, prev) {
	self = self || this;
	var cur = self.scrollTop();
	var delta = 50; var interval = 20;
	if (Math.abs(target - cur) <= delta || (prev && prev==cur))
	{
		self.scrollTop (target);
	}
	else
	{
		self.scrollTop (cur + delta*((target > cur)? 1: -1));
		setTimeout (function () { jQuery.fn.scrollTopSmooth(target, self, cur) }, interval);
	}
}

/***************************
	LEGACY FUNCTIONS
****************************/

// Switch pages based on menu choice - 2nd level landing pages
function GoProd (s)
{
	var d = s.options[s.selectedIndex].value;
	window.top.location.href = d;
	s.selectedIndex = 0;
}

// centerTab - Deposit
function Show(obj_ID)
{
	HideAll();
    document.getElementById(obj_ID).style.display="block";
	document.getElementById('img'+obj_ID).src = "images/common/icon/close.gif";
}
function Hide(obj_ID)
{
 document.getElementById(obj_ID).style.display="none";
}
function HideAll()
{
    // Grab all elements that have tagname input
    var divArr = document.getElementsByTagName("div");

    // Loop through those elements and alert to user
    for (var i = 0; i < divArr.length; i++)
    {
        if ('divBenefit,divRateFees,divRequirementt,divContactForm'.indexOf(divArr[i].id) < 0)
        {
            if (divArr[i].style.display == "block")
            {
                divArr[i].style.display = "none"
                document.getElementById('img'+divArr[i].id).src = "images/common/icon/icon_collapse.gif";
            }
            else if (divArr[i].style.visibility == "visible")
            {
                divArr[i].style.visibility = "hidden"
            }
        }
    }
}
// end centerTab - Deposit
//********************************************************************************************//

//function show_UOB_Locator(locator_service)
//{
	//var locator_url = "";

	//locator_url = atm_search_link + 'uob/popup_result.cgi?preselect=' + locator_service;
	//window.open(locator_url,'UOBLocator','toolbar=no,directories=no,resizable=yes,status=yes,menubar=yes,location=no,scrollbars=yes,width=620,height=500,maximize=yes,minimize=yes');

	//var address=atm_search_link + "uob/popup_result.cgi?preselect="+locator_service+"&keepThis=true&TB_iframe=true&height=540&width=590";
	//tb_show("ATM Locator", address, false);
//}

function show_UOB_Locator(locator_service)
{
	//var address="http://www3.uobgroup.com/locator/uob_search.html?preselect="+locator_service;
	//alert(address);
	//tb_show("ATM Locator", address, false);
	var address=atm_search_link+"?preselect="+locator_service+"&keepThis=true&TB_iframe=true&height=540&width=590";
	tb_show("ATM Locator", address, false);
}

function show_UOB_Locator_iacct(lh,locator_service)
{
	var s=s_gi('uobcomprd');
	s.tl(lh,'o','i-Account Promotion : Branch Locator');

	//var address="http://www3.uobgroup.com/locator/uob_search.html?preselect="+locator_service;
	//alert(address);
	//tb_show("ATM Locator", address, false);
	var address=atm_search_link+"?preselect="+locator_service+"&keepThis=true&TB_iframe=true&height=540&width=590";
	tb_show("ATM Locator", address, false);
}

function print_this_page(url)
{
	window.print();
}

function bookmark_this_page(url, title)
{
	if (document.all)// ie
		window.external.AddFavorite(url, title);
	else if (window.sidebar) // firefox
	    window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
}


function openpibpopup()
{
	window.open('/assets/demo/UOBPersonalInternetBanking/index.html','Bodyframe','toolbar=no,directories=no,scrollbars=no,resizable=no, menubar=no,location=no,width=1024,height=768,maximize=no,minimize=no');
}


//********************************************************************************************//
// Font size style switcher

function setActiveStyleSheet(title) {
  var i, a, main;

  var curStyle = getActiveStyleSheet();

  if(curStyle == null){
	 if(title == "large"){
	 	title = "font2";
	 }
	 else{
		title = "font1";
	 }
  }
  else{
  if(title == "large"){
	if(curStyle == "font3"){
		title = "font3";
	}
	else if(curStyle == "font2"){
		title = "font3";
	}
	else if(curStyle == "font1"){
		title = "font2";
	}
  }
  else if(title == "small"){
	  if(curStyle == "font3"){
		  title = "font2";
	  }
	  else if(curStyle == "font2"){
		  title = "font1";
	  }
	  else if(curStyle == "font1"){
			title = "font1";
	  }
  }
  }

  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		a.disabled = true;
      if(a.getAttribute("title") == title){
		  a.disabled = false;
	  }
	  else{
		  a.disabled = true;
	  }
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/*
window.onload = function(e) {
  var cookie = readCookie("styleside");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("styleside", title, 365);
}

var cookie = readCookie("styleside");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);*/

// end Font size style switcher
//********************************************************************************************//

