var jlib = {};


jlib.addStyleSheet = function (href, media) {
	if (!href) {
		return;
	}
	href = ' href="' + href + '"';
	media = (media) ? ' media="' + media + '"' : '';
	document.writeln('<link rel="stylesheet" type="text/css"' + media + href + '>');
};


jlib._findLang = function (str, findFirst) {
	var matches;
	if (str == null) {
		return '';
	}
	matches = str.toString().replace(/^\/+|\/+$/g, '').split('/');
	return (findFirst) ? matches[0] : matches[matches.length - 1];
};


jlib.switchLangInit = function (root) {
	var _findLang, href, dir, els, a, i;
	if (!root) {
		return;
	}
	_findLang = jlib._findLang;
	href = location.href.toString();
	dir = '/' + _findLang(location.pathname, true) + '/';
	els = root.getElementsByTagName('a');
	for (i = els.length - 1; i >= 0; i--) {
		a = els[i];
		if (a.rel.indexOf('switch_lang') > -1) {
			a.href = href.replace(dir, '/' + _findLang(a.href, false) + '/');
		}
	}
};


jlib._imageButtonClick = function () {
	var form = this.form;
	var result;
	if (form) {
		switch (this.type) {
		case 'submit':
			if (form.onsubmit) {
				result = form.onsubmit();
  		}
			if (result !== false) {
				form.submit();
			}
			break;
		case 'reset':
			form.reset();
			break;
		}
	}
	return false;
};


jlib.imageButtonInit = function (root) {
	var _imageButtonClick, els, input, type, a, img, i;
	if (!root) {
		return;
	}
	_imageButtonClick = jlib._imageButtonClick;
	els = root.getElementsByTagName('input');
	for (i = els.length - 1; i >= 0; i--) {
		input = els[i];
		type = input.type.toLowerCase();
		if ((type == 'submit' || type == 'reset') && input.src) {
			a = document.createElement('a');
			a.href = '#';
			a.form = input.form;
			a.type = type;
			a.className = 'button';
			a.onclick = _imageButtonClick;
			img = document.createElement('img');
			img.src = input.src;
			img.alt = input.value;
			img.className = input.className;
			a.appendChild(img);
			a.input = input;
			input.style.position = 'absolute';
			input.style.left = '-5000px';
			input.style.top = '-5000px';
			input.parentNode.insertBefore(a, input);
		}
	}
};


jlib.imageButtonUninit = function (root) {
	var els, a, input, i;
	if (!root) {
		return;
	}
	els = root.getElementsByTagName('a');
	for (i = els.length - 1; i >= 0; i--) {
		a = els[i];
		if (a.input) {
			input = a.input;
			input.parentNode.removeChild(a);
			a.onclick = null;
			a.form = null;
			a.input = null;
			input.style.position = '';
			input.style.left = '';
			input.style.top = '';
		}
	}
};


jlib._createSelectMenuOption = function (el) {
	var option, nodes, i;
	if (!el) {
		return null;
	}
	option = document.createElement('option');
	if (typeof el == 'string') {
		option.appendChild(document.createTextNode(el));
	} else {
		option.href = el.href;
		option.isNewWindow = (el.rel.indexOf('external') > -1);
		if (el.rel.indexOf('show') > -1) {
			i = el.href.indexOf('#');
			if (i > -1) {
				option.showEl = document.getElementById(el.href.substring(i + 1));
			}
		}
		nodes = el.childNodes;
		for (i = 0; i < nodes.length; i++) {
			option.appendChild(nodes[i].cloneNode(false));
		}
	}
	return option;
};


jlib._selectMenuChange = function () {
	var option = this.options[this.selectedIndex];
	if (!option.href) {
		return;
	}
	if (!option.showEl) {
		if (option.isNewWindow) {
			window.open(option.href, '', '');
		} else {
			location.href = option.href;
		}
	} else {
    if (option.showEl.id == 'brokerLogin') {
      var consultantLogin = document.getElementById('consultantLogin');
      if(consultantLogin.className.indexOf('hide') == -1) consultantLogin.className = 'hide';
      resetLoginBox('broker');
      option.showEl.className = '';
    }
    else if (option.showEl.id == 'consultantLogin') {
      var brokerLogin = document.getElementById('brokerLogin');
      if(brokerLogin.className.indexOf('hide') == -1) brokerLogin.className = 'hide';
      resetLoginBox('consultant');
      option.showEl.className = '';
    } else {
      option.showEl.className = '';    
    } 
	}
	if (this.blur) {
		this.blur();
	}
	this.selectedIndex = 0;
};


jlib.selectMenuInit = function (root) {
	var _createSelectMenuOption, select, els, i;
	if (!root) {
		return;
	}
	_createSelectMenuOption = jlib._createSelectMenuOption;
	select = document.createElement('select');
	select.id = root.id;
	select.className = root.className;
	select.onchange = jlib._selectMenuChange;
	if (root.title) {
		select.appendChild(_createSelectMenuOption(root.title));
	}
	els = root.getElementsByTagName('a');
	for (i = 0; i < els.length; i++) {
		select.appendChild(_createSelectMenuOption(els[i]));
	}
	select.root = root;
	root.parentNode.replaceChild(select, root);
};

jlib.selectMenuUninit = function (select) {
	var els, i;
	if (!select) {
		return;
	}
	els = select.options;
	for (i = els.length - 1; i >= 0; i--) {
		els[i].showEl = null;
	}
	select.parentNode.replaceChild(select.root, select);
	select.onchange = null;
	select.root = null;
};


jlib._rolloverHandler = function (e) {
	var target;
	if (!e) {
		e = window.event;
	}
	target = e.target || e.srcElement;
	if (!target || !target.offSrc || !target.onSrc) {
		return;
	}
	target.src = (e.type == 'mouseover') ? target.onSrc : target.offSrc;
};

jlib.rolloverInit = function (root) {
	var _rolloverHandler, els, img, src, preload, i;
	if (!root) {
		return;
	}
	_rolloverHandler = jlib._rolloverHandler;
	els = root.getElementsByTagName('img');
	for (i = els.length - 1; i >= 0; i--) {
		img = els[i];
		src = img.src;
		if (img.className.indexOf('rollover') > -1 && src.indexOf('_off.') > -1) {
			img.offSrc = src;
			img.onSrc = src.replace('_off.', '_on.');
			preload = document.createElement('img');
			preload.src = img.onSrc;
			img.preload = preload;
		}
	}
	root.onmouseover = _rolloverHandler;
	root.onmouseout = _rolloverHandler;
};


jlib.rolloverUninit = function (root) {
	var els, img, i;
	if (!root) {
		return;
	}
	els = root.getElementsByTagName('img');
	for (i = els.length - 1; i >= 0; i--) {
		img = els[i];
		if (img.preload) {
			img.src = img.offSrc;
			img.preload = null;
		}
	}
	root.onmouseover = null;
	root.onmouseout = null;
};

/* for image rollover for input type of submit */
jlib.imageButtonRolloverInit = function (root) {
	var _rolloverHandler, inputs, input, src, preload, i;
	if (!root) {
		return;
	}
	_rolloverHandler = jlib._rolloverHandler;
	inputs = root.getElementsByTagName('input');
	for (i = inputs.length - 1; i >= 0; i--) {
		input = inputs[i];
		src = input.src;
		if (input.className.indexOf('rollover') > -1 && src.indexOf('_off.') > -1) {
			input.offSrc = src;
			input.onSrc = src.replace('_off.', '_on.');
			input.onmouseover = _rolloverHandler;
			input.onmouseout = _rolloverHandler;
		}
	}
};

jlib.imageButtonRolloverUninit = function (root) {
	var inputs, input, i;
	if (!root) {
		return;
	}
	inputs = root.getElementsByTagName('input');
	for (i = inputs.length - 1; i >= 0; i--) {
		input = inputs[i];
  	input.onmouseover = null;
  	input.onmouseout = null;
	}
};


jlib._labelHandler = function () {
	var field = this.field;
	var action;
	switch (field.nodeName) {
		case 'INPUT':
			switch (field.type) {
				case 'text':
				case 'password':
					action = 'focus';
					break;

				case 'checkbox':
				case 'radio':
					action = 'click';
					break;
			}
			break;

		case 'SELECT':
		case 'TEXTAREA':
			action = 'focus';
			break;
	}
//	if (action && field[action]) {
	if (action && field[action] && !field.disabled) {
		field[action]();
		return false;
	}
	return true;
};


jlib.labelInit = function (root) {
	var _labelHandler, els, label, field, i;
	if (!root) {
		return;
	}
	_labelHandler = jlib._labelHandler;
	els = root.getElementsByTagName('label');
	for (i = els.length - 1; i >= 0; i--) {
		label = els[i];
		if (label.htmlFor) {
			field = document.getElementById(label.htmlFor);
			if (field) {
				label.style.cursor = 'default';
				label.field = field;
				label.onclick = _labelHandler;
			}
		}
	}
};


jlib.labelUninit = function (root) {
	var els, label, i;
	if (!root) {
		return;
	}
	els = root.getElementsByTagName('label');
	for (i = els.length - 1; i >= 0; i--) {
		label = els[i];
		if (label.field) {
			label.field = null;
			label.onclick = null;
		}
	}
};


jlib._largeListHandler = function (e) {
	var target, undef, href, parent, grandparent, greatgrandparent;
	if (!e) {
		e = window.event;
	}
	target = e.target || e.srcElement;
	if (!target) {
		return undef;
	}
	if (target.nodeType != 1 || target.nodeName != 'A') {
		return undef;
	}
	parent = target.parentNode;
	if (typeof target.isToggler == 'undefined') {
		href = target.href;
		grandparent = parent.parentNode;
		greatgrandparent = grandparent.parentNode;
		target.isToggler = (href.charAt(href.length - 1) == '#' &&
			parent.nodeName == 'LI' &&
			grandparent.nodeName == 'UL' && grandparent.className.indexOf('arrow') > -1 &&
			(grandparent.className.indexOf('largelist') || greatgrandparent.nodeName == 'DIV'));
	}
	if (!target.isToggler) {
		return undef;
	}
	if (typeof target.isOpen == 'undefined') {
		parent.offClassName = parent.className.replace('selected', '');
		parent.onClassName = ((parent.offClassName) ? parent.offClassName + ' ' : '') + 'selected';
		target.isOpen = (parent.className.indexOf('selected') > -1);
	}
	parent.className = (target.isOpen) ? parent.offClassName : parent.onClassName;
	target.isOpen = !target.isOpen;
	if (target.blur) {
		target.blur();
	}
	return false;
};


jlib.largeListInit = function (root) {
	var _largeListHandler, els, i;
	if (!root) {
		return;
	}
	_largeListHandler = jlib._largeListHandler;
	els = root.getElementsByTagName('ul');
	for (i = els.length - 1; i >= 0; i--) {
		if (els[i].className.indexOf('largelist') > -1) {
			els[i].onclick = _largeListHandler;
		}
	}
};


jlib.largeListUninit = function (root) {
	var els, i;
	if (!root) {
		return;
	}
	els = root.getElementsByTagName('ul');
	for (i = els.length - 1; i >= 0; i--) {
		if (els[i].className.indexOf('largelist') > -1) {
			els[i].onclick = null;
		}
	}
};


jlib._tabsHandler = function (e) {
	var target, undef, parent, tab;
	if (!e) {
		e = window.event;
	}
	target = e.target || e.srcElement;
	if (!target || target.nodeType != 1 || target.nodeName != 'A' || !target.tab) {
		return undef;
	}
	if (this.open) {
		parent = this.open.parentNode;
		tab = this.open.tab;
		parent.className = parent.offClassName;
		tab.className = tab.offClassName;
	}
	parent = target.parentNode;
	tab = target.tab;
	parent.className = parent.onClassName;
	tab.className = tab.onClassName;
	this.open = target;
	if (target.blur) {
		target.blur();
	}
	return false;
};


jlib.tabsInit = function (root) {
	var els, a, href, tab, parent, cn, firstA, i;
	if (!root) {
		return;
	}
	els = root.getElementsByTagName('a');
	for (i = els.length - 1; i >= 0; i--) {
		a = els[i];
		href = a.href;
		tab = document.getElementById(href.substring(href.indexOf('#') + 1));
		if (tab) {
			parent = a.parentNode;
			cn = parent.className;
			parent.offClassName = cn;
			parent.onClassName = ((cn) ? cn + ' ' : '') + 'selected';
			cn = tab.className;
			tab.offClassName = cn;
			tab.onClassName = ((cn) ? cn + ' ' : '') + 'show';
			a.tab = tab;
			firstA = a;
		}
	}
	if (firstA) {
		parent.className = parent.onClassName;
		tab.className = tab.onClassName;
		root.open = firstA;
	}
	root.onclick = jlib._tabsHandler;
};


jlib.tabsUninit = function (root) {
	var els, a, i;
	if (!root) {
		return;
	}
	els = root.getElementsByTagName('a');
	for (i = els.length - 1; i >= 0; i--) {
		a = els[i];
		if (a.tab) {
			a.tab = null;
		}
	}
	root.open = null;
	root.onclick = null;
};


jlib.fundTableInit = function (root) {
  
  var a, imgHide, imgShow , urlSplit;

  if(!root) {
    return;
  }
  
  urlSplit = location.href.substring(7).split('/');
  
  a = document.createElement('a');
  a.href = location.href;
  a.className = "button";
  a.id = "fundTableButton";

  imgHide = document.createElement('img');
  imgHide.src = (urlSplit[1] == 'en')? "/images/en/buttons/hide_table_off.gif" : "/images/tc/buttons/hide_table_off.gif";
  imgHide.alt = (urlSplit[1] == 'en')? "Hide Table" : "隱藏列表";
  imgHide.className = "rollover";
  imgHide.id = "hideFundTableImage";

  imgShow = document.createElement('img');
  imgShow.src = (urlSplit[1] == 'en')? "/images/en/buttons/show_table_off.gif" : "/images/tc/buttons/show_table_off.gif";
  imgShow.alt = (urlSplit[1] == 'en')? "Show Table" : "顯示列表";
  imgShow.className = "rollover";
  imgShow.id = "showFundTableImage";

  // be default, the table is hiding
  imgHide.style.display = "none";

  a.appendChild(imgHide);
  a.appendChild(imgShow);

  root.insertBefore(a, root.firstChild);
}


jlib.externalLinkInit = function (root) {

  var anchors = root.getElementsByTagName('a');

  if(anchors.length < 1) return;

  for(var i = 0; i < anchors.length; i++) {
    // not every anchor has rel, so better check if it has rel first
    if(anchors[i].rel && anchors[i].rel.indexOf('external') > -1 && anchors[i].id.indexOf('consultantLoginButton') == -1) {
      anchors[i].onclick = function() {
        window.open(this.href,'','');
        return false;   
      }
    }
  }
}


jlib.externalLinkUninit = function (root) {

  var anchors = root.getElementsByTagName('a');

  if(anchors.length < 1) return;

  for(var i = 0; i < anchors[i].length; i++) {
    if(anchors[i] && anchors[i].rel.indexOf('external') > -1) {
      anchors[i].onclick = null;
    }
  }
}


function validateDate() {
  var errMsgObj, errObj, day, month, year, fundListTable;

  errObj = document.getElementById('errorMsg');    
  errMsgObj = document.getElementById('warnmsg');    

  day = document.getElementById('day');
  month = document.getElementById('month');
  year = document.getElementById('year');
    
  day = day.options[day.selectedIndex].value;
  month = month.options[month.selectedIndex].value;
  year = year.options[year.selectedIndex].value;

  if(!isValidDate(day,month,year)) {
    var strUrl=window.location.href+ '';
    errMsgObj.innerHTML = (strUrl.indexOf("/tc/") != -1)? displayDate(day,month,year) + "是一個無效的日期" : displayDate(day,month,year) + " is an invalid date.";
    errObj.className = '';
    return false;
  } else {
    errMsgObj.innerHTML = '';
    errObj.className = 'hide';
    return true; 
  }
}


function isValidDate(day,month,year) {
  var dayNum, monthNum, yearNum, date;
  
  monthNum = parseInt(month, 10);
  dayNum = parseInt(day, 10);
  yearNum = parseInt(year);
  date = new Date(year, monthNum - 1, day);
  
  return (dayNum == date.getDate());
}


var enMonths = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];


function displayDate(day,month,year) {
  var strDate, strUrl;

  strDate = '';
  strUrl=window.location.href+ '';  

  if(parseInt(month, 10) < 10) month = month.substring(1);
  if(parseInt(day, 10) < 10) day = day.substring(1);

  if(strUrl.indexOf("/tc/") > -1) {
    strDate = strDate + year + "年 " + month + "月 " + day + "日";     
  } else {
    month = enMonths[parseInt(month)-1];
    strDate = strDate + month + " " + day + ", " + year;
  }
  return strDate;  
}


function resetLoginBox(root) {
  document.getElementById(root + 'Username').value = '';
  document.getElementById(root + 'UsernameLabel').className = '';
  if(root == 'broker') {
    document.getElementById('password').value = '';
    document.getElementById('brokerPasswordLabel').className = '';    
  }
  document.getElementById(root + 'WarnMsg').innerHTML = '';
  document.getElementById(root + 'ErrMsg').className = 'hide';
}


function validateLoginBoxInput(root, href) {

  var username, password, usernameLabel, passwordLabel, errorMsgObj, errorMsg;
  
  username = document.getElementById(root + 'Username');
  usernameLabel = document.getElementById(root + 'UsernameLabel'); 
  errorMsgObj = document.getElementById(root + 'ErrMsg');
  errorMsg = document.getElementById(root + 'WarnMsg');

  if(root == 'broker') {
    password = document.getElementById('password');
    passwordLabel = document.getElementById('brokerPasswordLabel');
  }
  
  if(root == 'consultant') {
    password = document.getElementById('consultantpassword');
    passwordLabel = document.getElementById('consultantPasswordLabel');
  }

  usernameLabel.className = '';
  if(passwordLabel) passwordLabel.className = '';
  errorMsg.innerHTML = '';
  errorMsgObj.className = 'hide';
  
  var allFilled = true;

  if(username.value == '') {
    usernameLabel.className = 'mandatory';  
    allFilled = false;
  }

  if (password && password.value == '') {
    passwordLabel.className = 'mandatory';
    allFilled = false;
  }
    
  if(allFilled) {
    if(root == 'broker'){
      return true;
    } 
    else if ( root == 'consultant')
    {
	    var strUrl=window.location.href+ '';
	    if(strUrl.indexOf("/tc/")!=-1)
		{
	   		document.getElementById('consultantbutton').focus();
	   		return true;
   		}	
	   	else
	   	{
	   		document.getElementById('consultantbutton').focus(); 
			return true;
    	}
	}    
    else {
      window.open(href + username.value + '.nsf','');
      return false;
    }    
  } else {
    var strUrl=window.location.href+ '';
    if(strUrl.indexOf("/tc/")!=-1) {
      errorMsg.innerHTML = "下列橙色顯示的各欄需要更正。";
    } else {
      errorMsg.innerHTML = "The field(s) shown in orange below require correction.";        
    }
    errorMsgObj.className = '';                                    
    return false;
  }

}

function passthru(id,v){
  var e = document.getElementById(id);
  if(e){
    e.disabled = false;
    e.value=v;
    e.disabled=true;
  }
}

function popup(path){
  var popupTop = (screen.height - 600) / 2;
  var popupLeft = (screen.width - 800) / 2;
  window.open(path, "win", "toolbar = no, location = no, directories = no, status = no, menubar = no, scrollbars = yes, resizeable = no, width = 840, height = 630, top = " + popupTop + ", left = " + popupLeft);
}

var brokerLogin, brokerClose, brokerLoginForm, brokerErrMsg, brokerWarnMsg;
var consultantLogin, consultantClose, consultantLoginForm, consultantLoginButton, consultantLoginInput, consultantErrMsg, consultantWarnMsg;

var existing, nonexisting, policyrow;

var fundTableButton, hideFundTableImage, showFundTableImage, lines;

var disclaimerPopup, developmentGuide;

var homePopup;

var step2, ftp;

var link_detail, link_enrollment, link_prize, link_requirement;
var detail, enrollment, prize, requirement;

window.onload = function () {
	var body = document.getElementsByTagName('body')[0];

	jlib.switchLangInit(document.getElementById('alsonav'));
	jlib.imageButtonInit(body);
	jlib.selectMenuInit(document.getElementById('login'));
	jlib.selectMenuInit(document.getElementById('homesites'));
  
  jlib.fundTableInit(document.getElementById('fundTable'));

  lines = document.getElementById('lines');
  // by default, we hide the table
  if(lines) {
    lines.className = "lines hide";
  }
  fundTableButton = document.getElementById('fundTableButton');
  hideFundTableImage = document.getElementById('hideFundTableImage');
  showFundTableImage = document.getElementById('showFundTableImage');

  if(fundTableButton){
    fundTableButton.onclick = function () {
      // hiding
      if(lines.className.indexOf('hide') != -1) {
        lines.className = "lines";
        showFundTableImage.style.display = "none";
        hideFundTableImage.style.display = "block";
      } else {
        lines.className = "lines hide";
        hideFundTableImage.style.display = "none";
        showFundTableImage.style.display = "block";
      }    
      return false;
    }
  }

	jlib.rolloverInit(body);
	jlib.labelInit(body);
	jlib.largeListInit(body);
	jlib.tabsInit(document.getElementById('tabs'));

  var copy = document.getElementById('copy');
  jlib.imageButtonRolloverInit(copy);


  brokerLoginForm = document.getElementById('brokerLoginForm');
  if(brokerLoginForm) {    
    brokerLoginForm.onsubmit = function () {
      return validateLoginBoxInput('broker', '');
    }
  }
  
	brokerLogin = document.getElementById('brokerLogin');
	brokerClose = document.getElementById('brokerClose');
	if (brokerLogin && brokerClose) {
/*
		brokerClose.parentNode.onclick = function () {
			brokerLogin.className = 'hide';
			return false;
		};
*/
    brokerClose.onclick = function () 
    {
			brokerLogin.className = 'hide';
			return false;
    }

	}

	consultantLoginForm = document.getElementById('consultantLoginForm');
  	if(consultantLoginForm) {    
    consultantLoginForm.onsubmit = function () {
       return validateLoginBoxInput('consultant', '');
    }
 	}		

	consultantLoginInput = document.getElementById('consultantUsername');
	consultantLoginButton = document.getElementById('consultantpassword');
	
	if(consultantLoginInput) {
    consultantLoginInput.onkeypress = function (event) {
	    var characterCode;
	    	characterCode = window.event.keyCode;  	
		if(characterCode == 13 )	return validateLoginBoxInput('consultant', ''); 
		}        
	}	
	if(consultantLoginButton) {
    consultantLoginButton.onkeypress = function (event) {
		 var characterCode;
	    	characterCode = window.event.keyCode;  	
		if(characterCode == 13 )	return validateLoginBoxInput('consultant', ''); 
		}        
	}	

	consultantLogin = document.getElementById('consultantLogin');
  	consultantClose = document.getElementById('consultantClose');

	if (consultantLogin && consultantClose) 
  	{
    consultantClose.onclick = function () 
    {
			consultantLogin.className = 'hide';
			return false;
    }
	}
	
/*
	consultantLoginButton = document.getElementById('consultantLoginButton');

	if(consultantLoginButton) {
    consultantLoginButton.onclick = function () {
      return validateLoginBoxInput('consultant', this.href);            
    }
  }

  consultantLoginInput = document.getElementById('consultantUsername');
  if(consultantLoginInput) {
    consultantLoginInput.onkeypress = function (event) {
      var characterCode;
      if(event && event.which) {
        characterCode = event.which;
      } else {
        characterCode = window.event.keyCode;
      }
      if(characterCode == 13 && consultantLoginButton) return validateLoginBoxInput('consultant', consultantLoginButton.href);    
    }  
  }
*/

	existing = document.getElementById('existing');
	nonexisting = document.getElementById('nonexisting');
	policyrow = document.getElementById('policyrow');
	if (existing && nonexisting && policyrow) {
		existing.onclick = nonexisting.onclick = function () {
			policyrow.className = (existing.checked) ? 'show' : '';
		};
		existing.onclick();
	}

  jlib.externalLinkInit(document.getElementById('container'));

  disclaimerPopup = document.getElementById('disclaimerPopup');	
  if(disclaimerPopup) {
    var popupTop = (screen.height - 600) / 2;
    var popupLeft = (screen.width - 600) / 2;
    var popupRiskTop = (screen.height - 600) / 2;
    var popupRiskLeft = (screen.width - 1000) / 2;
    var strUrl=window.location.href+ '';
    var query;
    if(strUrl.indexOf("/life/")!= -1 || strUrl.indexOf("/education/")!= -1 || strUrl.indexOf("/health/")!= -1 || strUrl.indexOf("/retirement/")!= -1) {
      query = "1";
    }
    if(strUrl.indexOf("/fund-prices/")!= -1 || strUrl.indexOf("/investment/")!= -1 || strUrl.indexOf("/downloads/")!= -1) {
      query = "2";
    }
    if(strUrl.indexOf("/tc/")!=-1) {
	    if(strUrl.indexOf("/life/")!= -1 || strUrl.indexOf("/education/")!= -1 || strUrl.indexOf("/health/")!= -1 || strUrl.indexOf("/retirement/")!= -1) {
			window.open("/tc/disclaimer/popup.aspx?src=" + query, "popupWindow", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 800, height = 600, top = " + popupRiskTop + ", left = " + popupRiskLeft);
		}
		if(strUrl.indexOf("/fund-prices/")!= -1 || strUrl.indexOf("/investment/")!= -1 || strUrl.indexOf("/downloads/")!= -1) {			    
      		window.open("/tc/disclaimer/popup.aspx?src=" + query, "popupWindow", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 800, height = 600, top = " + popupRiskTop + ", left = " + popupRiskLeft);
      		window.open("/tc/disclaimer/disclosure.aspx?src=" + query, "popupWindow2", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 800, height = 600, top = " + popupTop + ", left = " + popupLeft);
  		}	
    } else {
      	if(strUrl.indexOf("/life/")!= -1 || strUrl.indexOf("/education/")!= -1 || strUrl.indexOf("/health/")!= -1 || strUrl.indexOf("/retirement/")!= -1) {
			window.open("/en/disclaimer/popup.aspx?src=" + query, "popupWindow", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 800, height = 600, top = " + popupRiskTop + ", left = " + popupRiskLeft);
		}
		if(strUrl.indexOf("/fund-prices/")!= -1 || strUrl.indexOf("/investment/")!= -1 || strUrl.indexOf("/downloads/")!= -1) {			    
      		window.open("/en/disclaimer/popup.aspx?src=" + query, "popupWindow", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 800, height = 600, top = " + popupRiskTop + ", left = " + popupRiskLeft);
      		window.open("/en/disclaimer/disclosure.aspx?src=" + query, "popupWindow2", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 800, height = 600, top = " + popupTop + ", left = " + popupLeft);
  		}	    
    }
  }
  
  homePopup = document.getElementById('homePopup');	
  if(homePopup) {
    var popupTop = (screen.height - 600) / 2;
    var popupLeft = (screen.width - 800) / 2;
    var strUrl=window.location.href+ '';
   
    if(strUrl.indexOf("/tc/")!=-1) {
      window.open("/tc/popup.aspx", "popupWindow", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 750, height = 500, top = " + popupTop + ", left = " + popupLeft);
    } else {
      window.open("/en/popup.aspx", "popupWindow", "toolbar = no, location = no, directories = no, scrollbars = yes, width = 750, height = 500, top = " + popupTop + ", left = " + popupLeft);    
    }
  }
  

  developmentGuide = document.getElementById('developmentGuide');
  if(developmentGuide) {
    developmentGuide.onclick = function() {
      popup(this.href);
      return false;
    };
  }
  
  var main = document.getElementById('main');
  jlib.imageButtonRolloverInit(main);

  step2 = document.getElementById('step2');
  if(step2) {
    ftp = new ftpModule();
  }
  
  if(document.getElementById('links')) {
    link_detail = document.getElementById('link_detail'); 
    link_enrollment = document.getElementById('link_enrollment'); 
    link_prize = document.getElementById('link_prize'); 
    link_requirement = document.getElementById('link_requirement'); 
  
    detail = document.getElementById('detail');
    enrollment = document.getElementById('enrollment');
    prize = document.getElementById('prize');
    requirement = document.getElementById('requirement');
  
    if(detail && enrollment && prize && requirement && link_detail && link_enrollment && link_prize && link_requirement) {
      
      var strUrl=window.location.href+ '';
      if(strUrl.indexOf("?en") != -1) {
        detail.style.display = 'none';
        enrollment.style.display = 'block';
        prize.style.display = 'none';
        requirement.style.display = 'none';      
      } else if (strUrl.indexOf("?pr") != -1 ) {
        detail.style.display = 'none';
        enrollment.style.display = 'none';
        prize.style.display = 'block';
        requirement.style.display = 'none';              
      } else if (strUrl.indexOf("?re") != -1 ) {
        detail.style.display = 'none';
        enrollment.style.display = 'none';
        prize.style.display = 'none';
        requirement.style.display = 'block';                    
      } else {
        detail.style.display = 'block';
        enrollment.style.display = 'none';
        prize.style.display = 'none';
        requirement.style.display = 'none';      
      }
            
      link_detail.onclick = function() {
        detail.style.display = 'block';  
        enrollment.style.display = 'none';
        prize.style.display = 'none';
        requirement.style.display = 'none';
        return false;
      }

      link_enrollment.onclick = function() {
        detail.style.display = 'none';  
        enrollment.style.display = 'block';
        prize.style.display = 'none';
        requirement.style.display = 'none';
        return false;
      }

      link_prize.onclick = function() {
        detail.style.display = 'none';  
        enrollment.style.display = 'none';
        prize.style.display = 'block';
        requirement.style.display = 'none';
        return false;
      }

      link_requirement.onclick = function() {
        detail.style.display = 'none';  
        enrollment.style.display = 'none';
        prize.style.display = 'none';
        requirement.style.display = 'block';
        return false;
      }
    
    }  
  }
  
};

window.onunload = function () {
	var body = document.getElementsByTagName('body')[0];

	if (brokerClose) {
//		brokerClose.parentNode.onclick = null;
		brokerClose.onclick = null;
	}

  if (consultantClose)
  {
    consultantClose.onclick = null;
  }

  if (consultantLoginButton) 
  {
    consultantLoginButton.onclick = null;  
  }

	if (existing && nonexisting && policyrow) {
		existing.onclick = null;
		nonexisting.onclick = null;
	}

  if (fundTableButton) {
    fundTableButton.onclick = null;
  }

	jlib.tabsUninit(document.getElementById('tabs'));
	jlib.largeListUninit(body);
	jlib.labelUninit(body);
	jlib.rolloverUninit(body);
	jlib.selectMenuUninit(document.getElementById('login'));
	jlib.selectMenuUninit(document.getElementById('homesites'));
	jlib.imageButtonUninit(body);

  var copy = document.getElementById('copy');
  jlib.imageButtonRolloverUninit(copy);

  jlib.externalLinkUninit(document.getElementById('container'));

  var main = document.getElementById('main');
  jlib.imageButtonRolloverUninit(main);

  if(step2) {
    ftp = null;
  }

};
