
var agt=navigator.userAgent.toLowerCase();
var is_safari = (agt.indexOf("safari")!=-1);
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_DOM   = (document.getElementById) ? true : false;
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_ie = (agt.indexOf("msie") != -1);
var is_ie4up  = (is_ie  && (is_major >= 4));
var ver4 = (is_ie4up || is_nav4up) ? 1 : 0;


var appsValidPattern = /[^(0-9a-zA-Z@_.)]/;

/* Added By Christine*/
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=0,width=650,height=600,left = 400,top = 180');");
}
/* END Added By Christine*/

function setBeginEnd(which,from,to) {
	arPopups[which] = new Array();
	arPopups[which][0] = from;
	arPopups[which][1] = to;
}
if (ver4) {
		arPopups = new Array()	  

		//for pre login
		setBeginEnd("1_1",0,0);
    setBeginEnd("1_2",54,94);
    setBeginEnd("1_3",144,204);
    setBeginEnd("1_4",234,314);
    setBeginEnd("1_5",340,406);
    setBeginEnd("1_6",452,498);
    setBeginEnd("1_7",545,605);


		//for post login
		/*
		setBeginEnd("2_1",0,0);
		setBeginEnd("2_2",22,88);
		setBeginEnd("2_3",93,157);
		setBeginEnd("2_4",163,251);
		setBeginEnd("2_5",254,319);
		setBeginEnd("2_6",320,372);
		setBeginEnd("2_7",375,453);
		*/
		
		// for post login new images
		setBeginEnd("2_1",0,0);
		setBeginEnd("2_2",45,105);
		setBeginEnd("2_3",144,204);
		setBeginEnd("2_4",234,314);
		setBeginEnd("2_5",340,406);
		setBeginEnd("2_6",452,498);
		setBeginEnd("2_7",545,605);

}
clTop = 0;
clBot = 24;

function mapOver(which,on) {
	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 mapOn(which) {
	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";
}

if(is_safari){
document.write('' +
'<STYLE TYPE="text/css">' +
'#elMenuUp { position: absolute; top: 59px; left: 155; width: 641; }' +
'#elMenuOver { position: absolute; visibility: hidden; top: 59px; left: 155; width: 641; }' +
'#elMenuOn { position: absolute; visibility: hidden; top: 59px; left: 155; width: 641; }' +
'</style>');
}
else{
document.write('' +
'<STYLE TYPE="text/css">' +
'#elMenuUp { position: absolute; top: 60px; left: 155; width: 641; }' +
'#elMenuOver { position: absolute; visibility: hidden; top: 60px; left: 155; width: 641; }' +
'#elMenuOn { position: absolute; visibility: hidden; top: 60px; left: 155; width: 641; }' +
'</style>');
}
function Createlink(obj)
{
	if ( (obj == "") || (obj == "null") ){return alert ('Feature not implemented');}
	top.location.href = obj;
}


/**
 * This JSP is created by  . It has two functions which are used by IPTLightModule's dynamic link.
 * It is cloned from sgipb's loadPopup_new.js, with the modification on default value of tabNo based on the language and user type.
 *
 *
 * 1)  Functions = Createlink(obj)
 *
 *	   params
 *	   obj :- This would contain the comma seperated values to be passed to loadPopup function.
 *			  This function is called when there is a dropdown containing a list of landing pages. on cliking the go button
 *			  adjecent to the dropdown, this function will be called, which would intern parse the parameters and pass it to
 *			  loadPopup function.
 *
 * 2)  Functions = loadPopup(path, productId, target, external,height,width)
 *			    confirnbox(path)
 *
 *		 params
 *
 *		  path :- path of the landing page. This is a mandatory input
 *		  productId :- This is mandatorr. Product id will be used to get the meniId and the brandmap
 *		  target :- This is where the target page will open, it could be
 *					A) same work area (default if no value is passed, or value 0 is passed, or null passed)
 *					B) Pop up with browser controls (value 1 is passed)
 *					C) pop up without browser controls (value 2 is passed)
 *
 *		external :- Y if external site
 *					N if not external (default, if no value is passed or null passed)
 *		height	:- Height of the window, in case of popup. This is optional field, pass null if dont require to pass 				height.
 *		width	:- width of the window, in case of popup. This is optional field, pass null if dont require to pass height
 *
 */

function getTabNumb ( prodID) {
	//alert (prodID);
	var defProdIDVals = "null|home|CreditCards|Savings&Investments|Loans|Insurance";
	var myTabNoArray = defProdIDVals.split('|');
	for (i=0;i < myTabNoArray.length; i++ )	{
			if (myTabNoArray[i] == prodID){
				//alert ( "tab number=" + myTabNoArray[i] );
				return myTabNoArray[i+1];
			}
	}
	return 1 ;
}

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,"");

/// Change done by
	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);
	}

/// Change End


	var url			= "";

	var win_height	= height ;
	var win_width	= width;

	var isWebServerFile = false;
	var isExternalSite = false;

	if ((win_height == "") || (win_height== "null"))
	{
		height = "534";
	}

	if ((win_width == "") || (win_width =="null"))
	{
		width = "650";
	}

	/* Add by  , 2004-06-09, change for TW forms showing status bar
	 * if the path include stringID=cititwmigrateform1, then set the tagert to 3
	 * target = 3 is not a standard value, it is used only internally
	 * target = 3 will make the popup windows have status bar only
	 *
	 * add footerCID parameter to change the footer sytle (the popup window footer)
	 */

if ((external == "N") || (external == "")|| (external == "null"))
	{
		/* comment by  , "null" will mapping to "home" in database
		if (prod_cat_Id == "null")
		{
			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 if(path.indexOf("/portal/") >= 0) {
			isWebServerFile = true;
			url = trim(path);
		}else {
			url="/APPS/portal/loadPage.do?htmlPageName="+path;;
		}

		if ((target == "") || (target == "0") || (target == "null"))
{
if(isWebServerFile || isExternalSite) {
top.location.href = url;
return;
}
var prodAttr = "tabNo=" + getTabNumb(prod_cat_Id);
//top.location.href = "/portal/citiwm_home_center.jsp?"+prodAttr+ "&path=/mygcb/english/"+path+"&frameset=myCenterFrameset&frameval1=wowWorkID&framevar1=myWorkID";
top.location.href = "/APPS/portal/loadPage.do?"+prodAttr+ "&htmlPageName="+path;
return ;
}
else if (target == "1")
{
parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=no" +"," +"toolbar=no" + "," + "menubar=yes" + "," + "scrollbars=yes" + "," + "resizable=yes";
window.open(url,'', parm);
return ;
}
else if (target == "2")
{
var parm = "left=95" + "," + "width=" + width +"," + "height=" + height + "," +"location=yes" + ","  + "scrollbars=yes" + "," + "resizable=yes";
if(isWebServerFile || isExternalSite) {
window.open(url,'', parm);
return ;
}
url="/APPS/portal/loadPopup.do?htmlPageName="+path;
window.open(url,'', 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 Singapore Limited website and entering a Citibank Affiliate website.\n All the information you provide will be subject to confidentiality and security terms of the applicable website.\n Would you like to continue?")
	if (name == true) // if the user presses the yes button
	{
		if (target == "1") // pop up with browser controls
		{

			parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=no" +"," +"toolbar=no" + "," + "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) {

   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.

   // This function is called to replace the %20 char to spaces.
   // On some of the solaris boxex space is treated as %20.
	var newInputString = replace(inputString,'%20',' ');

   if (typeof newInputString != "string") { return newInputString; }
   var retValue = newInputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string

      retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function replace(string,text,by) {
// Replaces text with by in string
    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;
}

// functions for trimming string values
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function


//added for qf pattern validation
function appsValidateExpression(expr){
	if( appsValidPattern.test(expr) ){
		return false;
	}else{
		return true;
	}
}
