// JavaScript Document
/* Domain */
var defhost = document.URL;
var defhost = defhost.substr(defhost.lastIndexOf('//')+2,defhost.length);
var defhost = defhost.substr(0,defhost.indexOf('/'));
//document.write(defhost);

/* Language */
var lang = 'jp';

/* Words */
var words = new Array();

words.push(Array('wholesale-banking','Wholesale Banking'));

words.push(Array('client-relationships','Client Relationships'));
words.push(Array('corporate-clients','Corporate Clients'));
words.push(Array('financial-institutions','Financial Institutions'));

words.push(Array('financial-markets','Financial Markets'));
words.push(Array('project-export-finance','Project Export Finance'));

words.push(Array('transaction-banking','Transaction Banking'));
words.push(Array('cash-management','Cash Management'));
words.push(Array('trade-services','Trade Services'));
words.push(Array('securities-services','Securities Services'));

words.push(Array('about-us','About-Us'));
words.push(Array('access','Access'));
words.push(Array('global-network','Global Network'));
words.push(Array('ceo-message','CEO Message'));
words.push(Array('history','History'));
words.push(Array('principles-values','Principles and Values'));

words.push(Array('japan-careers','Japan Careers'));
words.push(Array('graduates','Graduates'));

words.push(Array('media-centre','Media Centre'));
words.push(Array('seeing-is-believing','Seeing is Believing'));
words.push(Array('financial-results','Financial Results'));
words.push(Array('press-releases','Press Releases'));
words.push(Array('photos','Photos'));
words.push(Array('reports','Reports'));

words.push(Array('legal-notices','Legal Notices'));
words.push(Array('sitemap','Site Map'));
words.push(Array('search','Search Results'));

words.push(Array('antisocial-force','Antisocial Forces Policy'));
words.push(Array('conflict-of-interest','Conflict of Interest Management Policy'));
words.push(Array('privacy-policy','Privacy Policy'));
words.push(Array('disclosure-statement','Disclosure Statement'));
words.push(Array('investor-status-expiration','Investor Status Expiration Policy'));
words.push(Array('solicitation-policy','Solicitation Policy'));
words.push(Array('terms-conditions','Terms & Conditions'));

/* URL domain */
var ud = new String();
ud = document.URL;
var ud = ud.substr(ud.lastIndexOf('http://')+7,ud.length);
//document.write('<p><strong>The URL is: </strong>'+ud+'</p>');
var ua = new Array();
ua = ud.split('/');
//document.write('<p><strong>The URL array is: </strong>'+ua+'</p><br />');
ua.splice(1,ua.length);
//document.write('<p><strong>The URL array after splice is: </strong>'+ua+'</p>');
//document.write('<p><strong>The URL array modified as: </strong>'+ua+' and total <strong>'+ua.length+'</strong> array item inside.</p>');
//ua[0] = 'www.standardchartered.com.hk';

/* URL path */
var up = new String();
up = document.location.pathname;
up = up.substr(up.lastIndexOf('Country_site_buildpack_B-localview')+34,up.length); // added by Amin for local view
//document.write('<p><strong>URL path = </strong>'+up+'</p>');

/* Array link */
var al = new Array();
//added 2 split options for local view (IE "\")
if (up.substr(0, 1) == "\\")
	al = up.split('\\');
else
	al = up.split('/');
//al.splice(0,1);
al.splice(al.length-2,2);
al[0] = ua[0];
//document.write('<p><strong>Array of link = </strong>'+al+'<br /><strong>Total array(s): </strong>'+al.length+'</p>');

/* Array */
var ap = new Array();
//added 2 split options for local view (IE "\")
if (up.substr(0, 1) == "\\")
	ap = up.split('\\');
else
	ap = up.split('/');
//ap.splice(0,1);
ap.splice(ap.length-2,2);
ap[0] = 'Home';
//document.write('<p><strong>Array of path = </strong>'+ap+'<br /><strong>Total array(s): </strong>'+ap.length+'</p>');

var ta = new Number(ap.length);

/* Value converstion */
//document.write('<p><strong>Converted array(s) as below: </strong><br />');
for (i=0; i<ta; i++) {
	var tmpvalue = ap[i];
	for (j=0; j<words.length;j++) {
		if (tmpvalue == words[j][0]) {
			ap[i] = words[j][1];
			//document.write(tmpvalue+' &gt; '+ap[i]+'<br />');
		}
	}
}
//document.write('</p><p>');

/* Store array */
var defuse = 0;
var sa = new Array();
for (k=0; k<=ta-1; k++) {
	var tmppath = ap[k];
	var tmplink = 'http://';
	for (m=0; m<=k; m++) {
		if (al[m] == 'personal-banking') {
			if (defuse) {
				tmplink += al[m];
				tmplink += '/';
			} else {
				defuse = true;
			}
		} else {
			tmplink += al[m];
			tmplink += '/';
		}
	}
	//document.write('<strong>ID '+k+': </strong> '+tmppath+' : '+tmplink+'<br />');
	sa.push(Array(tmppath,tmplink));
}
//document.write('</p>');

var counted = false;

/* Special case(s) */
// Repeat the statement block for each case(s)
for (n=0; n<ta-1; n++) {
	var chkstr = sa[n][0];
	var chklink = sa[n][1];
	// Insert specific condition(s) here
	if (chkstr == 'Personal Loans' && chklink.indexOf('/personal-loans/personal-loans/')) {
		if (counted) {
			sa.splice(n,1);
		} else {
			counted = true;
		}
	}
}

/* Trace updated array */
/*document.write('<p>');
for (s=0; s<sa.length; s++) {
	document.write('<strong>'+sa[s][0]+'</strong> : '+sa[s][1]+'<br />');
}
document.write('</p>');
*/



