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 Loadpage(path, productId, target, external,height,width)
{
	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';
	}
	//alert(path);
	if(qryStrFlag == "NEW") {
		//alert(path.indexOf(pattern1));
		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,"");
		//alert(queryStr);
	} else if (qryStrFlag == "ADDED") {
		//alert(path.indexOf(pattern2));
		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,"");
		//alert(queryStr);
	}
	


	var beanId		= "iptlightmodule1" ;
	var viewId		= "MY_PORTAL_VIEW";
	var url			= "";
	var brandmap	= "BrdImgMapBankSel"; 
	var menuId		= "LeftNavBanking"; 
	var win_height	= height ;
	var win_width	= width;
	var pageId		= "cngcb_template1"; 
	var isWebServerFile = 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("http://") >= 0 || path.indexOf("https://") >= 0) {
			isExternalSite = true;
			url = path;
		} else if(path.indexOf("/global_docs/") >= 0) {
			isWebServerFile = true;
			url = trim(path);
		} else {
			url="/portal/generic_hkgcb.jsp?stringID=iptlightmodule1&footerCID=noFooter&viewID=MY_PORTAL_VIEW&path=/hkgcb/english/"+path;
			//url = "/portal/index.jsp?path=/sggcb/english/"+path;
		}		
		
		var checkext=parseLink(path);
		if(checkext != -1)
		{
			url = path;
		}
		

		if ((target == "") || (target == "0") || (target == "null")) 
		{
			if(isWebServerFile || isExternalSite) {
				top.CENTER.WORK.location.href = url;
				return;
			}
			var prodAttr = "productID=" + prod_cat_Id ;
			top.CENTER.WORK.location.href = "/portal/generic_hkgcb.jsp?"+prodAttr+ "&stringID=iptlightmodule1&footerCID=noFooter&viewID=MY_PORTAL_VIEW&path=/hkgcb/english/"+path;
			return ;
		}
		else 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(url,'NewWinDow', parm);
			return ;
		}
		else if (target == "2") 
		{
			var parm = "left=95" + "," + "width=" + width +"," + "height=" + height + "," +"location=yes" + "," + "scrollbars=yes" + "," + "resizable=yes";
			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 Citribank, 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('.jsp');
	return strpath;
	
}

function getTab(){//alert("get TAB)");
//alert ("Querystring : "+top.CENTER.WORK.location.search);

var QryString = top.CENTER.WORK.location.search.substr( 1 ).split( "&" );
var prodName="";
for ( x = 0; x < QryString.length; x++ ) {
	//alert ("QryString" + QryString[x]);
	qrystr = QryString[x].split( "=" );
	//alert ("qrystr" + qrystr);

	if ( qrystr[0] == "productID" ){prodName=qrystr[1]; break ;}
}

//var prodList = 'null|1|home|2|PersonalBanking|3|Deposits|4|Investments|5|CreditCards|6|DinersClub|7|Insurance|8|Loans|9';

var prodList = top.CENTER.BRAND.prodList.products.value;
//alert("Prodlisting : " +prodList );
var prodArray = prodList.split('|');
//alert (prodName);
var prodID=0;


	for ( x = 0; x < prodArray.length; x++ ) {
		if( prodArray[x] == prodName ){
			prodID=prodArray[x+1];
			break;
		 }
	} 
	//alert ("ProdID is :"+prodID )
	if(prodID != null && prodID !="")
		top.CENTER.BRAND.mapOn(prodID);


}
