﻿function Createlink(obj) {
	var myArray = obj.split(',');
	var size = myArray.length;
	if ( (obj == "") || (obj == "null") || (size < 6) )
	{
		return alert ("insufficient parameter");
	}
	var path		=	myArray[0];
	var productId	=	myArray[1];
	var target		=	myArray[2];
	var external	=	myArray[3];
	var height		=	myArray[4];
	var width		=	myArray[5];

	Loadpage(path, productId, target, external,height,width);
}

function openNewWin(url,winName,winProp,lid,ipath){
 newWin = window.open(url,winName,winProp);
 newWin.focus();
}

function Loadpage(path, tabId, target, external, height, width) {
	var arr=new Array("home","CreditCards","Mortgages","Deposits","Loans","Investments","Insurance","SuperRetire");

	if ( (!path) || (trim(path) == "") ) {
		return alert ("path cannot be empty or null");
	}

	var queryStringIndex = path.indexOf("?");
	var normalizedPath = (queryStringIndex > 0)?path.substring(0, queryStringIndex):path;

	var isWebServerFile = false;
	var isExternalSite = false;
	height = ( (height == "") || (height == "null") || (!height) )?"534" :height;
	width =  ( (width  == "") || (width  == "null") || (!width)  )?"650" :width;
	tabId =  ( (tabId == "" ) || (tabId == "null" ) || (!tabId)  )?"home":tabId

	if(normalizedPath.indexOf("http://") >= 0 || normalizedPath.indexOf("https://") >= 0) {
		isExternalSite = true;
	}else if(normalizedPath.indexOf("/global_docs/") == 0 || normalizedPath.indexOf("/portal/") == 0) {
		isWebServerFile = true;
	}
	if(external == "Y" || external == "y"){
    	isExternalSite = true;
    }
	
	var isAppLink = false;
	var isAppLoadPage = false;
	if(path.indexOf(".do") >= 0) {
		isAppLink = true;
	}	
//	if(arr.toString().indexOf(tabId) != -1){
//        isAppLoadPage = false;	        
//    }    
    
    if (isExternalSite) {
    	confirnbox(path,target, height, width,external );
    }
    else if (target == "0" || target == "null" || target == ""){
        if(!isWebServerFile && !isAppLink) {
        	if(isAppLoadPage)
                path = "/CNGCB/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path;
            else
                path = "/CNGCB/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
    	}
    	else if(isAppLink){
    		path = "/CNGCB/"+path;
    	}
    	top.location.href = path;
    }
	else if (target == "1") {		
		var param =	"left=95,top=11,location=yes,status=no,toolbar=no,menubar=no,scrollbars=yes,"+"width="+width+","+"height="+height;
		if(!isWebServerFile && !isAppLink) {
        	if(isAppLoadPage)
                path = "/CNGCB/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path;
            else
                path = "/CNGCB/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
    	}
    	else if(isAppLink){
    		path = "/CNGCB/"+path;
    	}  	
		window.open(path, "NewWinDow", param);
	}
	else if (target == "2") {
		var param = "left=95,location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,"+ "width="+width+","+"height="+height;
		if(!isWebServerFile && !isAppLink) {
			path = "/CNGCB/APPS/portal/loadPopup.do?tabId="+tabId+ "&path="+path;
    	}
    	else if(isAppLink){
    		path = "/CNGCB/"+path;
    	} 	
		window.open(path, "NewWinDow", param);			
	}
	else if (target == "3") {		
		if(!isWebServerFile && !isAppLink) {
        	if(isAppLoadPage)
                path = "/CNGCB/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path;
            else
                path = "/CNGCB/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
    	}
    	else if(isAppLink){
    		path = "/CNGCB/"+path;
    	}
		linkParentAndCloseSelf(path);
	}
}
function confirnbox(path,target, height, width,external)
{
 if(external == "N" || external == "n"){
 window.location=path;   
}
else {
var name = confirm("您即将离开花旗银行（中国）有限公司网站，进入第三方网站。\n你在此提供的所有信息将受制于该第三方网站的保密和安全条款，不在花旗银行（中国）有限公司控制范围之内。\n您同意继续吗？\n\nYou are now leaving the website of Citibank (China) Co., Ltd. and entering a third party site.\nAll information you provide there will be subject to confidentiality and security terms of the applicable third party site which are beyond control of Citibank (China) Co., Ltd..\nWould you like to continue?")
if (name == true) 
{
if (target == "1")
{
parm = "left=95,top=11,location=yes,status=no,toolbar=no,menubar=no,scrollbars=yes,"+"width="+width+","+"height="+height;
window.open(path,'NewWinDow', parm);
return ;
}
else if(target == "2")
{
var parm = "left=95,location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,"+ "width="+width+","+"height="+height;
window.open(path,'NewWinDow', parm);
return;
}
else
{
window.location=path;
}
}
else
{
return ;
}
}
}
function trim(inputString) {
var newInputString = replace(inputString,'%20',' ');  
if (typeof newInputString != "string") { return newInputString; }
var retValue = newInputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { 
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { 
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) { 
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); 
}
return retValue; 
}
function replace(string,text,by) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) 
return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}