// ROLLOVER CODE - START
if (document.images) {
var imageCache = new Array();
var allCacheCalls = 0;
var tempImage = new Image();
}
function swapImage(names) {
if (document.images) {
imageList = names.split(",");
for (i = 0 ; i < imageList.length ; i++) {
imagePair = imageList[i].split("=");
if (imagePair.length == 2) {
if (document.images[imagePair[0]]) {
document.images[imagePair[0]].src = imagePair[1];
}
}
}
}
}
function cache(name) {
if (document.images) {
var current = imageCache.length;
imageCache[current] = new Image();
imageCache[current].src = name;
}
}
function pageLoaded() {
if (document.images) {
cache("images/headnav_cardover.gif");                                   // top nav
cache("images/headnav_readyover.gif");
cache("images/headnav_investmentover.gif");
cache("images/headnav_loansover.gif");
cache("images/headnav_insuranceover.gif");       
cache("images/headnav_financialover.gif");
allCacheCalls = 1;
}
}
function pageLoaded1() {
if (document.images) {
cache("images/headnav_myhomeover.gif");                                 // top nav
cache("images/headnav_accdetailsover.gif");
cache("images/headnav_payanyoneover.gif");
cache("images/headnav_investingover.gif");
cache("images/headnav_managecreditover.gif");            
cache("images/headnav_servicesover.gif");
allCacheCalls = 1;
}
}
// ROLLOVER CODE - END
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@_.)]/;

function setBeginEnd(which,from,to) {
        arPopups[which] = new Array();
        arPopups[which][0] = from;
        arPopups[which][1] = to;
}
if (ver4) {
          arPopups = new Array()

/*
        <area shape="rect" coords="6,0,58,22" href="#"> 
        <area shape="rect" coords="62,0,152,22" href="#"> 
        <area shape="rect" coords="158,0,247,22" href="#"> 
        <area shape="rect" coords="252,0,353,22" href="#"> 
        <area shape="rect" coords="358,0,513,22" href="#"> 
        <area shape="rect" coords="518,0,634,22" href="#"> 
*/


// ENG PRE
          setBeginEnd("1_1",0,0);
          setBeginEnd("1_2",6,57);
          setBeginEnd("1_3",60,152);
          setBeginEnd("1_4",152,247);
          setBeginEnd("1_5",248,354);
          setBeginEnd("1_6",355,515);
          setBeginEnd("1_7",516,636);

//ENG POST 


                  setBeginEnd("2_1",0,0);
          setBeginEnd("2_2",1,75);
          setBeginEnd("2_3",76,170);
          setBeginEnd("2_4",169,265);
          setBeginEnd("2_5",267,371);
          setBeginEnd("2_6",373,531);
          setBeginEnd("2_7",532,652);

/*
        <area shape="rect" coords="17,1,72,23" href="#">
        <area shape="rect" coords="77,1,144,25" href="#">
        <area shape="rect" coords="149,1,221,24" href="#">
        <area shape="rect" coords="226,0,315,23" href="#">
        <area shape="rect" coords="320,0,474,23" href="#">
        <area shape="rect" coords="479,0,588,23" href="#">
*/
// TH PRE 
          setBeginEnd("3_1",0,0);
          setBeginEnd("3_2",13,72);
          setBeginEnd("3_3",74,144);
          setBeginEnd("3_4",144,221);
          setBeginEnd("3_5",219,312);
          setBeginEnd("3_6",314,474);
          setBeginEnd("3_7",470,588);

// TH POSt
          setBeginEnd("4_1",0,0);
          setBeginEnd("4_2",5,74);
          setBeginEnd("4_3",75,145);
          setBeginEnd("4_4",147,222);
          setBeginEnd("4_5",222,316);
          setBeginEnd("4_6",316,475);
          setBeginEnd("4_7",475,610);
}
clTop = 1;
clBot = 23;

function mapOver(which,on) {
//      alert('which --- ' + 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 }
//      alert('which --- ' + which + ' ** ');
        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: 37px; left: 155; width: 641; }' +
'#elMenuOver { position: absolute; visibility: hidden; top: 37px; left: 155; width: 641; }' +
'#elMenuOn { position: absolute; visibility: hidden; top: 47px; 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="/SGCBZ/APPS/portal/loadPage.do?path="+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 = "/SGCBZ/APPS/portal/loadPage.do?"+prodAttr+ "&path="+path;
return ;
}
else if (target == "1")
{
parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=no" + "," +"status=no" +"," +"toolbar=yes" + "," + "menubar=yes" + "," + "scrollbars=yes" + "," + "resizable=yes";
window.open(url,'', parm);
return ;
}
else if (target == "2")
{
var parm = "left=95" + "," + "width=" + width +"," + "height=" + height + "," + "scrollbars=yes" + "," + "resizable=yes";
if(isWebServerFile || isExternalSite) {
window.open(url,'', parm);
return ;
}
url="/SGCBZ/APPS/portal/loadPopup.do?path="+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 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 the user presses the yes button
        {
                if (target == "1") // pop up with browser controls
                {

                        parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=no" + "," +"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 + "," + "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;
        }
}
