function openNewWin(url,winName,winProp,lid,ipath){
        if(url.substring(0,4) !='http'){
        var result = url.indexOf(".do");
        if(result !=-1){
         url=trim(url);
                 var context=url.substring(0,6);
                 if (context != '/HKGCB')
                 {
                        url= "/HKGCB" + url ;
                 }
        }
        }
 newWin = window.open(url,winName,winProp);
 newWin.focus();
}

function Loadpage(path, tabId, target, external, height, width) {
        var arr=new Array();
        arr=tabId.split(" ");
        
        if( arr.length != 1 ){
                tabId=arr[0].charAt(0).toLowerCase()+arr[0].substring(1,arr[0].length)+arr[1].charAt(0).toLowerCase()+arr[1].substring(1,arr[1].length)
        }else{
                tabId=tabId.charAt(0).toLowerCase()+tabId.substring(1,tabId.length);
        }       
        if ( (!path) || (trim(path) == "") ) {
                return alert ("path cannot be empty or null");
        }

tabId=escape(tabId);
if( tabId=="%u500B%u4EBA%u9280%u884C%u670D%u52D9"){
tabId="personalbanking";
}
if( tabId=="%u5B58%u6B3E"){
tabId="deposits";}
if( tabId=="%u6295%u8CC7"){
tabId="investments";
}
if( tabId=="%u4FE1%u7528%u5361"){
tabId="creditcards";
}
if( tabId=="%u4FDD%u96AA"){
tabId="insurance";
}
if( tabId=="%u8CB8%u6B3E"){
tabId="loans";
}


        var queryStringIndex = path.indexOf("?");
        var normalizedPath = (queryStringIndex > 0)?path.substring(0, queryStringIndex):path;
        normalizedPath = normalizedPath.toLowerCase();

        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 (target == "1" || target == "2") 
        {
                
                var param =     "left=95,top=11,location=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height+",status=yes";
                if(target == "2") 
                {
                        param += ",toolbar=yes,menubar=yes";
                }
                                if(!isWebServerFile & !isExternalSite) 
                {
                        path="/APPS/portal/loadPopup.do?path="+path;
                }
                

                window.open(path, "_blank", param);
        }
        else if (target == "3" || target == "4" || target == "5") 
        {
                var fullPath;

                var param =     "left=95,top=11,location=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height+",status=yes";

                if(target == "4") 
                {
                        param += ",toolbar=yes,menubar=yes";
                }
                
                if(!isWebServerFile) 
                {
                        fullPath="https://" + window.document.domain + "/APPS/portal/loadPopup.do?path="+path;
                }
                
                if(isExternalSite)
                {
                        fullPath = path ;
                }

                if (target == "3")
                        top.location.href = fullPath;
                else 
                        window.open(fullPath, "_blank", param);
                        
        }
        else 
        {
                if(!isWebServerFile && !isExternalSite) {                        
                        path = "/HKGCB/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
                }
                else if (isExternalSite)
                {       
                }
                top.location.href = path;
        }
}

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 LoadNewPage(path, productId, target, external, height, width, protocol, statusBar){
if(path.substring(0,4) !='http'){
        var result = path.indexOf(".do");
        if(result !=-1){
         path=trim(path);
                 var context=path.substring(0,6);
                 if (context != '/HKGCB')
                 {
                        path= "/HKGCB" + path;
                 }
        }
        }
                if ((path == "" ) || (productId == ""))
                {
                        return alert ( "path and product id cannot be empty");
                }
                var prod_cat_Id = trim(productId);
                prod_cat_Id = prod_cat_Id.replace(/&/g,"");
                
                var pattern1 = "?WOW_PROD_CAT=";
                var pattern2 = "&WOW_PROD_CAT=";
                var qryStrFlag;
                var realProdID;
                if(path.indexOf(pattern1) >0) {
                        qryStrFlag = 'NEW';
                } else if (path.indexOf(pattern2) >0) {
                        qryStrFlag = 'ADDED';
                }
        
                if(qryStrFlag == "NEW") {
                        queryStr = path.substring(path.indexOf(pattern1));
                        prodCat = queryStr.substring(pattern1.length);
                        prod_cat_Id = trim(prodCat);
                        realProdID =   trim(prodCat);
                        prod_cat_Id = prod_cat_Id.replace(/&/g,"");
                        path = path.replace(queryStr,"");
                } else if (qryStrFlag == "ADDED") {
                        queryStr = path.substring(path.indexOf(pattern2));
                        prodCat = queryStr.substring(pattern2.length);
                        prod_cat_Id = trim(prodCat);
                        prod_cat_Id = prod_cat_Id.replace(/&/g,"");
                        path = path.replace(queryStr,"");
                }
                
                var win_height  = height ;
                var win_width   = width;
                var isWebServerFile = false;
                var isJspFile = false;
                var islightPage = false;
                var isExternalSite = false;
                
                if ((win_height == "") || (win_height== "null"))
                {
                        height = "534";
                }
                if ((win_width == "") || (win_width =="null"))
                {
                        width = "650";
                }
                if ((external == "N") || (external == "")|| (external == "null"))
                {
                        if (prod_cat_Id == "null" || prod_cat_Id == "CitibankOnlinePromotions")
                        {
                                prod_cat_Id="Home_gl";
                        }
                        
                        if(path.indexOf("/global_docs/") >= 0) {
                                isWebServerFile = true;
                                if((protocol == "0")){
                                        url = "http://" + top.location.hostname + trim(path);
                                }else if((protocol == "1")){
                                        url = "https://" + top.location.hostname + trim(path);
                                }else{
                                        url = trim(path);
                                }
                        }
                            
                        var checkext=parseLink(path);
                        if(checkext != -1)
                        {       isJspFile = true;
                                if((protocol == "0")){
                                        url = "http://" + top.location.hostname + trim(path);
                                }else if(protocol == "1"){
                                        url = "https://" + top.location.hostname + trim(path);
                                }else if((protocol == "") || (protocol == "null")){
                                        url = path;
                                }
                        }
                        
                        if((path.indexOf("http://") >= 0 || path.indexOf("https://") >= 0)) {
                                isExternalSite = true; 
                                url = path;
                        }
                        
                        if(!isWebServerFile&&!isJspFile&&!isExternalSite){
                                islightPage = true;
                                var prodAttr = "productID=" + prod_cat_Id ;
                                if((target == "1")||(target == "2")){
                                        
                                        url = "/APPS/portal/loadPage.do?path="+path;
                                }else if((protocol == "0")){
                                        
                                        url = "http://" + top.location.hostname +"/APPS/portal/loadPage.do?tabId="+prod_cat_Id+ "&path="+path;
                                }else if(protocol == "1"){
                                        
                                        url = "https://" + top.location.hostname +"/APPS/portal/loadPage.do?tabId="+prod_cat_Id+ "&path="+path;
                                }else if((protocol == "") || (protocol == "null")){
                                        
                                        url = "/APPS/portal/loadPage.do?tabId="+prod_cat_Id+"&path="+path;
                                        
                                }
                        }
                        
                        
                        if ((target == "") || (target == "0") || (target == "null"))
                        {
                                top.location.href = url;
                                return ;
                        }
                        else if (target == "1")
                        {
                                var status;
                                if((statusBar == "0")||(statusBar == "")||(statusBar == "null")){
                                        status = "no";
                                }else if(statusBar == "1"){
                                        status = "yes";
                                }
                                parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=" + status +"," +"toolbar=yes" + "," + "menubar=yes" + "," + "scrollbars=yes" + "," + "resizable=yes";
                                window.open(url,'NewWinDow', parm);
                                return ;
                        }
                        else if (target == "2")
                        {
                                var status;
                                if((statusBar == "0")||(statusBar == "")||(statusBar == "null")){
                                        status = "no";
                                }else if(statusBar == "1"){
                                        status = "yes";
                                }
                                var parm = "left=95" + "," + "width=" + width +"," + "height=" + height + "," +"location=yes" + ","+ "scrollbars=yes" + "," + "resizable=yes" + "," + "status=" + status;
                                window.open(url,'NewWinDow', parm);
                                return;
                        }
                }
                else if (external == "Y")
                {
                        confirnbox(path,target, height, width);
                }
        }
        
        
function confirnbox(path,target, height, width)
{
var name = confirm("You are now leaving Citibank website and entering an third party site. \n All information you provide will be subject to confidentiality and security terms of the applicable third party site. \n Citibank, N.A. does not take any responsibility for information you provide at such third party site. \n would you like to continue?")
if (name == true) 
{
if (target == "1")
{
parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=no" +"," +"toolbar=yes" + "," + "menubar=yes" + "," + "scrollbars=yes" + "," + "resizable=yes";
window.open(path,'NewWinDow', parm);
return ;
}
else if(target == "2")
{
var parm = "left=95" + "," + "width=" + width +"," + "height=" + height + "," +"location=yes" + ","+ "scrollbars=yes" + "," + "resizable=yes";
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;
}
function parseLink(path)
{
var strpath=path.indexOf('.do');
return strpath;
}
function getTab()
{
var QryString = top.location.search.substr( 1 ).split( "&" );
var prodName="";
for ( x = 0; x < QryString.length; x++ ) {
        qrystr = QryString[x].split( "=" );

        if ( qrystr[0] == "productID" ){prodName=qrystr[1]; break ;}
}
var prodList = null;


}

