﻿function getVariationCode()
{
	var url = window.top.location.href;

	
	url=url.replace("://","");
	var removehost = url.substring(0, url.indexOf("/")+1);
	url=url.replace(removehost, "");
	url=url.substring(0, url.indexOf("/"));
	return url;
}

function VariationRedirect(redirectTo)
{
  window.location = "/" + getVariationCode() + redirectTo;
}


//Pop out new small security form
function securityPopUp(url) {
		//original using asp	var curUrl = "/_layouts/CorporateWebsite/popupconfirmation.asp?url=" + url;
		var curUrl = "/Style%20Library/CorporateWebsite/html/interceptpage.html?url=" + escape(url);
		window.open(curUrl ,'','width=400,height=280,scrollbars=no,resizable=no,top=100,left=200');
	}
	
	
function PopUpContent(str){
newwin=window.open('','printwin','left=100,top=100,width=830,height=650,scrollbars=yes,resizable=yes');
newwin.document.write('<HTML>\n<HEAD><meta name="WebPartPageExpansion" content="full" /><meta name="WebPartPageExpansion" content="full" /><meta name="WebPartPageExpansion" content="full" /><meta name="WebPartPageExpansion" content="full" /><meta name="WebPartPageExpansion" content="full" />\n');
newwin.document.write('<TITLE>Print Page</TITLE>\n');
newwin.document.write('<link href="/style library/CorporateWebsite/css/Content.css" rel="stylesheet" />\n');
newwin.document.write('<link href="/style library/CorporateWebsite/css/corporatewebsite.css" rel="stylesheet" />\n');
newwin.document.write('<style>.noprintout{display:none;}INPUT {border : 0px solid; background : #FFFFFF; font-size : 11px; border : 1px solid; border-color: #969696;} </style>\n');
newwin.document.write('<scr'+ 'ipt>\n');
newwin.document.write('function chkstate(){\n');
newwin.document.write('if(document.readyState=="complete"){\n');
newwin.document.write('window.close()\n');
newwin.document.write('}\n');
newwin.document.write('else{\n');
newwin.document.write('setTimeout("chkstate()",2000)\n');
newwin.document.write('}\n');
newwin.document.write('}\n');
newwin.document.write('function print_win(){\n');
newwin.document.write('window.print();\n');
newwin.document.write('}\n');
newwin.document.write('<\/script>\n');
newwin.document.write('<style>\n');
newwin.document.write('.fx-MainContents{padding:13px;padding-top:5px;}\n');
newwin.document.write('<\/style>\n');
newwin.document.write('</HEAD>\n');
newwin.document.write('<BODY><table  cellpadding="0"cellspacing="0" border="0" width="768px"><tr><td>\n');
newwin.document.write(str);
newwin.document.write('</td></tr>');
newwin.document.write('<tr><td align="center"><input onclick="window.print()" type="button" value="Print This Page"/></td></tr>');
newwin.document.write('</table></BODY>\n');
newwin.document.write('</HTML>\n');
newwin.document.close();

}
	
function printContent(id){
str=document.getElementById(id).innerHTML;
PopUpContent(str);
}

function printFAQsContent(id){
	var divs = document.getElementById(id).getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++) {
			divs[i].style.display ="block";
	}
	str=document.getElementById(id).innerHTML;
	r = /(\<SCRIPT (.*)\>([\s\S.]*)\<\/SCRIPT\>)/;
	str=str.replace(r,"");
	r = /(\<script (.*)\>([\s\S.]*)\<\/script\>)/;
	str=str.replace(r,"");
	PopUpContent(str);
	  __doPostBack();
}
	
	
//Change Layout page navigation logo
function changeImg() 
		{
		if (document.getElementById("NavigationLogo")!=null)
		{
			var strURL = document.URL.toLowerCase();
			if (strURL.indexOf("/InvestmentBanking/".toLowerCase()) != -1)
			{
				// Logo for pages under "Investment Banking" site
				document.getElementById("NavigationLogo").src = '/Style Library/CorporateWebsite/images/logo/icon_small_investment_logo.gif';
			}
			else if (strURL.indexOf("/FundManagement/InstitutionalInvestor/".toLowerCase()) != -1)
			{
				// Logo for pages under "Funds Management" >> "Institutional Investor" site
				document.getElementById("NavigationLogo").src = '/Style Library/CorporateWebsite/images/logo/icon_small_fminstituitional.gif';
			}
			else if ( (strURL.indexOf("/FundManagement/".toLowerCase()) != -1) || (strURL.indexOf("UnitTrustPrices.aspx".toLowerCase()) != -1) )
			{
				// Logo for pages under "Funds Management"  ||  "Funds Management" >> "Individual Investor"  ||  "UnitTrustPrices.aspx" site
				document.getElementById("NavigationLogo").src = '/Style Library/CorporateWebsite/images/logo/icon_small_fmindividual.gif';
			}
			else if ( (strURL.indexOf("/Islamic/".toLowerCase()) != -1) || (strURL.indexOf("Islamic.aspx".toLowerCase()) != -1) )
			{
				// Logo for pages under "Islamic" site
				document.getElementById("NavigationLogo").src = '/Style Library/CorporateWebsite/images/logo/icon_small_islamic_logo.gif';
			}
			else
			{
				document.getElementById("NavigationLogo").src = '/Style Library/CorporateWebsite/images/logo/icon_small_retail_logo.gif';
			}
		}
    	}
    	
  
function SetWelcomeHidden() 
{
 
	var isExist=false; 		
	var elem;
	var elems = document.getElementsByTagName("*");
	var dd="";
	for ( var cls, i = 0; ( elem = elems[i] ); i++ )
	{
	  if ( elem.className == "edit-mode-panel" )
		{
			isExist=true;
			break;
		}
	}
	if (isExist==false)
	{
		document.write("<style>.welcome{display:none;}</style>" ); 
	}
}

/*Search*/
function checkvalue(obj)
	{
		tmp_str = obj.value
		
		if (tmp_str == "Enter Keyword(s)")
		{
			obj.value = ''
		}
	}
	
	function checkblur(obj)
	{
		if (obj.value == "")
		{
			obj.value = "Enter Keyword(s)"
		}
	}
function SearchResult()
{
	if (document.getElementById('SearchKeywordResult').value.length <= 3)        	
	{
		alert("You must enter more than 3 characters");
		return false;
	} 
	
	var iChars = "*|,\":<>[]{}`\';()@&$#%";
	for (var i = 0; i < document.getElementById('SearchKeywordResult').value.length; i++) 
	{
		if (iChars.indexOf(document.getElementById('SearchKeywordResult').value.charAt(i)) != -1)
		{
			alert ("Please enter keyword(s).\nOnly alphabet or number is allowed.\nPlease try again.");
			return false;
		}
	 }

	var search_keyword = document.getElementById('SearchKeywordResult').value;
	var redirectTo="/Pages/Result.aspx?k=" + encode(search_keyword) + "&s=CorporateWebsite_" + getVariationCode();
	VariationRedirect(redirectTo);

}

function EnterSearchResult(e) 
{     
	if (e.keyCode == 13) 
	{         
		SearchResult();        
	    return false;     
	} 
} 

function encode(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	return escape(result);
}
 
function decode(str) {
//	var result = "";
 
 	var result = str.replace(/\+/g, " ");
	
	return unescape(result);
}


