var aparam = ",toolbar=yes,menubar=yes";

function LoadpageImp(path, tabId, target, external, height, width){
  var curbizId = "/MYGCB";
 
	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;
	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 (external == "Y")
	{
		confirnbox(path,target, height, width);
	}
	//Added to open the Bahasa link in the same window
	else if (external == "B")
	{
	
	toBahasaLink(path,target, height, width);
	
	}else if (target == "1" || target == "2" || target == "4") 
	{
		var param =	"left=95,top=11,scrollbars=yes,location=yes,status=yes,resizable=yes,width="+width+",height="+height;
		if(target == "2" || target == "4") {
			param += aparam;
		}		
		if(!isWebServerFile && !isExternalSite) {
			path=curbizId+"/APPS/portal/loadPopup.do?path="+path;
		}			
		window.open(path, "_blank", param);
	}else {
		if(!isWebServerFile && !isExternalSite) {
			path = curbizId+"/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
		}
		top.location.href = path;
	}	
		
}

function Loadpage(path, tabId, target, external, height, width) {
  aparam = ",toolbar=yes,menubar=yes";
  LoadpageImp(path, tabId, target, external, height, width);
}
function Loadpage1(path, tabId, target, external, height, width) {
  aparam = ",toolbar=yes,menubar=yes";
  LoadpageImp(path, tabId, target, external, height, width);
}

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 LoadNewPage(path, productId, target, external, height, width, protocol, statusBar){
                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 the Citibank Malaysia website and entering a third party website. \n Any information you may provide on the third party website shall be subject to the confidentiality and security terms of such website and not the privacy policies of Citibank Malaysia, and Citibank Malaysia shall not bear any responsibility for any unauthorised disclosure or breach of confidentiality in relation to such information provided. \n Furthermore any link to a third party website contained herein does not constitute an endorsement by Citibank Malaysia of such third party, their website or their products and/or services, and Citibank Malaysia also makes no warranties as to the content of such website.\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;

}

function mapOn(which) {
	if (typeof(arPopups) != 'undefined'){
		if (arPopups[which] == null) { return }
		if (!ver4) { return }
		if (is_DOM){var el = document.getElementById("elMenuOn"); whichEl = el.style;}
		else if (is_ie4up){	whichEl = document.all.elMenuOn.style;}
		else{whichEl = document.elMenuOn;}
	
		clLeft = arPopups[which][0];
		clRight = arPopups[which][1];
	
		if (is_nav4) {whichEl.clip.left = clLeft; whichEl.clip.right = clRight;}
		else {whichEl.clip = "rect(" + clTop + " " + clRight + " " + clBot + " " + clLeft + ")";}
		whichEl.visibility = "visible";
	}
}
function mapOver(which,on) {
 	if (typeof(arPopups) != 'undefined'){	
		if (arPopups[which] == null) { return }
		if (!ver4) { return }
	
		if (is_DOM){var el = document.getElementById("elMenuOver");	whichEl = el.style;}
		else if (is_ie4up){whichEl = document.all.elMenuOver.style;}
		else{whichEl = document.elMenuOver;}
	
		if (!on){whichEl.visibility = "hidden";	return;}
		clLeft = arPopups[which][0];
		clRight = arPopups[which][1];
		if (is_nav4) {whichEl.clip.left = clLeft; whichEl.clip.right = clRight;}
		else {whichEl.clip = "rect(" + clTop + " " + clRight + " " + clBot + " " + clLeft + ")";}
		whichEl.visibility = "visible";
	}
}

//Function Added to open the Bahasa link in the same window
function toBahasaLink(path,target, height, width)
{
	if (target == "6") 
		window.location=path;
	else 
		return ;

}
