﻿//Global variable for storing symbols in grid when clicking the action buttons
var symbol = null;
var isTradePage = false; //For not calling "HideSymbolLookupOnOuterMouseClick" function for normal pages.

function IsTradePage(status) {//Called  from SymbolLookup.js
    isTradePage = status; //setting as false wen hide symbol lookup.
}
var decimalStatus = false;
function keyRestrict(e, vtype) {
    var key = '', keychar = '';
    key = getKeyCode(e);
    if (key == null) return true;
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    if ((key == 190) || (key == 110))
        keychar = ".";
    var validchars;
    if (vtype == 'N')
        validchars = '1234567890-';
    else if (vtype == 'n')
        validchars = '1234567890';
    else if (vtype == 'A')
        validchars = 'abcdefghijklmnopqrstuvwxyz ';
    else if (vtype == 'B')
        validchars = '1234567890-.()';
    else if (vtype == 'f') {
        validchars = '1234567890.';
        decimalStatus = false;
        if (e.srcElement.value.indexOf('.') != -1)
            decimalStatus = true;
        if ((keychar == '.') && (decimalStatus == true))
            return false;
    } else if (vtype == 'Y') {//For Year
        validchars = '1234567890';
        if (validchars.indexOf(keychar) != -1)
            return true;
        if (key == null || key == 0 || key == 8 || key == 9 || key == 13 || key == 27)
            return true;
        return false;
    }
    if (validchars.indexOf(keychar) != -1)
        return true;
    if (key == null || key == 0 || key == 8 || key == 9 || key == 13 || key == 27 || key == 46)
        return true;
    return false;
}
function getKeyCode(e) {
    if (window.event)
        return window.event.keyCode;
    else if (e)
        return e.which;
    else
        return null;
}
function setCheckToSelectedText(rbl, text) {
    if (text == '')
        return;
    for (x = 0; x < rbl.length; x++) {
        if (rbl[x].type == "radio")
            if (rbl[x].value == text)
            break;
    }
    rbl[x].checked = true;
}
function trim(str) {
    str = str.replace(/^\s+|\s+$/g, '');
    return str;
}
// Using in Stock.aspx & Option.aspx
function getSelectedItem(id, divL, divS) {
    var options = document.getElementById(id).getElementsByTagName('input');
    for (x = 0; x < options.length; ++x) {
        if (options[x].type == "radio" && options[x].checked) {
            switch (options[x].value) {
                case "2":
                    document.getElementById(divL).style.display = "block";
                    document.getElementById(divS).style.display = "none";
                    break;
                case "3":
                    document.getElementById(divL).style.display = "none";
                    document.getElementById(divS).style.display = "block";
                    break;
                case "4":
                    document.getElementById(divL).style.display = "block";
                    document.getElementById(divS).style.display = "block";
                    break;
                default:
                    document.getElementById(divL).style.display = "none";
                    document.getElementById(divS).style.display = "none";
                    break;
            }
            break;
        }
    }
}
// Using in Stock.aspx OCO
function getSelectedOCOItem(id, divL, divS) {
    var item = document.getElementById(divL).className;
    document.getElementById(divS).style.marginTop = "0px";
    var options = document.getElementById(id).getElementsByTagName('input');
    for (x = 0; x < options.length; ++x) {
        if (options[x].type == "radio" && options[x].checked) {
            switch (options[x].value) {
                case "2":
                    document.getElementById(divL).style.display = "block";
                    document.getElementById(divS).style.display = "none";
                    break;
                case "3":
                    document.getElementById(divL).style.display = "none";
                    document.getElementById(divS).style.display = "block";
                    if (item == '')
                        document.getElementById(divS).style.marginTop = "20px";
                    break;
                case "4":
                    document.getElementById(divL).style.display = "block";
                    document.getElementById(divS).style.display = "block";
                    break;
                default:
                    document.getElementById(divL).style.display = "none";
                    document.getElementById(divS).style.display = "none";
                    break;
            }
            break;
        }
    }
}
//Setting the dropdownlist selected text to specified one
function setIndexToSelectedText(drl, text) {
    text = trim(text);
    text = text.replace(/\&amp;/g, '&');
    for (i = 0; i < drl.length; i++) {
        if (drl.options[i].text == text)
            break;
    }
    drl.selectedIndex = i;
}
//Setting the dropdownlist selected value to specified one
function setIndexToSelectedvalue(drl, text) {
    text = trim(text);
    text = text.replace(/\&amp;/g, '&');
    for (i = 0; i < drl.length; i++) {
        if (drl.options[i].text == text)
            break;
    }
    drl.selectedIndex = i;
}
// Validates date input in three textboxes - day,month and year
function checkDate(monthInputId, dateInputId, yearInputId) {
    var myDayStr = document.getElementById(dateInputId).value;
    var myMonthStr = document.getElementById(monthInputId).value;
    var myYearStr = document.getElementById(yearInputId).value;
    var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;
    var myDate = new Date();
    myDate.setFullYear(myYearStr, parseInt(myMonthStr) - 1, myDayStr);

    if (myDate.getMonth() != parseInt(myMonthStr) - 1) {
        alert('Please enter a valid date');
        document.getElementById(monthInputId).focus();
        return false;
    }
    return true;
}
// Used to validate year input in a 3-input date field     
function IsValidYear(yearVal) {
    if (yearVal < 1900 || yearVal > 2035) {
        return false;
    } else {
        return true;
    }
}
//Set text in label compatible for IE n Firefox
function SetLabelText(elem, text) {
    if (document.all)
        elem.innerText = text;
    else
        elem.textContent = text;
}
function CurrencyFormatted(amount) {
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}
function getSelectedItemStock(id, divL, divS) {

    var options = document.getElementById(id).getElementsByTagName('input');
    for (x = 0; x < options.length; ++x) {
        if (options[x].type == "radio" && options[x].checked) {
            switch (options[x].value) {
                case "2":
                    document.getElementById(divL).style.display = "block";
                    document.getElementById(divS).style.display = "none";
                    break;
                case "3":
                    document.getElementById(divL).style.display = "none";
                    document.getElementById(divS).style.display = "block";
                    document.getElementById(divS).style.paddingTop = "20px";
                    document.getElementById(divS).style.marginTop = "0px";
                    break;
                case "4":
                    document.getElementById(divL).style.display = "block";
                    document.getElementById(divS).style.display = "block";
                    document.getElementById(divS).style.paddingTop = "0px";
                    document.getElementById(divS).style.marginTop = "-4px";
                    break;
                default:
                    document.getElementById(divL).style.display = "none";
                    document.getElementById(divS).style.display = "none";
                    break;
            }
            break;
        }
    }
}
function uncheckAll(field) {
    var chkBoxCount = field.getElementsByTagName("input");
    for (i = 0; i < chkBoxCount.length; i++)
        chkBoxCount[i].checked = false;
}

/*_____________________________________ LinkPacket Popup _________________________________________*/
var menuwidth = '165px';  //default menu width
var disappearDelay = 500;  //menu disappear speed onMouseout (in milliseconds)
var hidemenu_onclick = "yes"; //hide menu when user clicks within menu?
var gridSymbol = null; //for storing the symbol in grid.
var accountId = 0; //stores the accountId for GlobalOrderStatus(Admin)
var accountNumber = null;
var underlyingSymbol = null;
var orderAction = null;
var __limitPrice = null;
var quantity = null;
var assetType = null;
var pageType = "T";
var pageId = null;
var orderId = null;
var multilegParamsInfo = '';
var isMultiLeg = false;

/*_____________________ LinkPacket for Combined positions_____________________*/
var isCombinedPosition = false;

var ie4 = document.all;
var ns6 = document.getElementById && !document.all;

if (ie4 || ns6)
    document.write('<div id="dropmenudiv" style="visibility:hidden;width:' + menuwidth + 'background-color:#f0f0f0;" onMouseover="ClearHideMenu()" onMouseout="dynamichide(event)"></div>');

function GetPosOffset(what, offsettype) {
    var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
    var parentEl = what.offsetParent;
    while (parentEl != null) {
        totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;
}
function Showhide(obj, e, visible, hidden, menuwidth) {
    if (ie4 || ns6)
        dropmenuobj.style.left = dropmenuobj.style.top = "-500px";
    if (menuwidth != "") {
        dropmenuobj.widthobj = dropmenuobj.style;
        dropmenuobj.widthobj.width = menuwidth;
    }
    if (e.type == "click" && obj.visibility == hidden || e.type == "mouseover")
        obj.visibility = visible;
    else if (e.type == "click")
        obj.visibility = hidden;
}
function iecompattest() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}
function clearbrowseredge(obj, whichedge) {
    var edgeoffset = 0;
    if (whichedge == "rightedge") {
        var windowedge = ie4 && !window.opera ? iecompattest().scrollLeft + iecompattest().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15;
        dropmenuobj.contentmeasure = dropmenuobj.offsetWidth;
        if (windowedge - dropmenuobj.x < dropmenuobj.contentmeasure)
            edgeoffset = dropmenuobj.contentmeasure - (obj.offsetWidth - 10);
        else edgeoffset = -20;
    } else {
        var topedge = ie4 && !window.opera ? iecompattest().scrollTop : window.pageYOffset;
        var windowedge = ie4 && !window.opera ? iecompattest().scrollTop + iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18;
        dropmenuobj.contentmeasure = dropmenuobj.offsetHeight;
        if (windowedge - dropmenuobj.y < dropmenuobj.contentmeasure) { //move up?
            edgeoffset = dropmenuobj.contentmeasure + obj.offsetHeight - 10;
            if ((dropmenuobj.y - topedge) < dropmenuobj.contentmeasure) //up no good either?
                edgeoffset = dropmenuobj.y + obj.offsetHeight - topedge;
        }
    }
    return edgeoffset;
}
function PopulateMenu(what, imgPathOffSet) {
    var topDiv = "<table cellpadding='0' cellspacing='0'><tr><td ><img src='" + imgPathOffSet + "media/images/tl.gif'/></td><td class='roundcont'></td><td ><img src='" + imgPathOffSet + "media/images/tr.gif'/></td></tr><tr><td style='background-color:#f0f0f0;width:2px'></td><td style='background-color:#f0f0f0'>";
    var bottomDiv = "</td><td style='background-color:#f0f0f0;width:2px'></td></tr><tr><td><img src='" + imgPathOffSet + "media/images/bl.gif'/></td><td class='roundcont'></td><td ><img src='" + imgPathOffSet + "media/images/br.gif'/></td></tr></table>";
    if (ie4 || ns6) {
        dropmenuobj.innerHTML = topDiv + what.join("") + bottomDiv;
    }
}
function DropDownMenu(obj, e, menucontents, menuwidth) {
    if (window.event) event.cancelBubble = true;
    else if (e.stopPropagation) e.stopPropagation();
    ClearHideMenu();
    dropmenuobj = document.getElementById ? document.getElementById("dropmenudiv") : dropmenudiv;
    PopulateMenu(menucontents, '../');

    if (ie4 || ns6) {
        Showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
        dropmenuobj.x = GetPosOffset(obj, "left");
        dropmenuobj.y = GetPosOffset(obj, "top");
        dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + "px";
        dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px";
    }
    return clickreturnvalue();
}
function clickreturnvalue() {
    if (ie4 || ns6) return false;
    else return true;
}
function contains_ns6(a, b) {
    while (b.parentNode)
        if ((b = b.parentNode) == a)
        return true;
    return false;
}
function dynamichide(e) {
    if (ie4 && !dropmenuobj.contains(e.toElement))
        delayhidemenu();
    else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))
        delayhidemenu();
}
function hidemenu(e) {
    if (isTradePage) {
        HideSymbolLookupOnOuterMouseClick();
    }
    if (typeof dropmenuobj != "undefined") {
        if (ie4 || ns6)
            dropmenuobj.style.visibility = "hidden";
    }
}
function sethidemenu() {
    if (ie4 || ns6)
        delayhide = setTimeout("hidemenu()", 2000);
}
function delayhidemenu() {
    if (ie4 || ns6)
        delayhide = setTimeout("hidemenu()", disappearDelay);
}
function ClearHideMenu() {
    if (typeof delayhide != "undefined")
        clearTimeout(delayhide);
}
if (hidemenu_onclick == "yes") {
    document.onclick = hidemenu;
}

function ProcessTheAction(Obj, lnkId) {
    if(pageId == "QR-OC" && quantity < 1){
        quantity = 1;
    }
    var absPath = '../LinkPacketRedirect.aspx?Symbol=';
    if (pageType == 'M') {
        absPath = '../' + absPath;
    }
    window.location = absPath + gridSymbol + "&type=" + assetType + "&underlyingSymbol=" + underlyingSymbol + "&linkId=" + lnkId + "&Qty=" + quantity + "&AccID=" + accountId + "&AccNo=" + accountNumber + "&pageId=" + pageId + "&id=" + orderId + multilegParamsInfo + "&OA=" + orderAction + "&ordPT=" + __limitPrice + "&isMultiLeg=" + isMultiLeg + "&isCombinedPosition=" + isCombinedPosition;
   
}
function CreateMenuContent(obj, evnt, grdType) {
    window.onresize = function() { hidemenu('resize'); }
    var menu = GetLinkPacketItems(grdType, obj);
    DropDownMenu(obj, evnt, menu, '150px');
}
function CreateActionPopupinManagement(obj, ev, grdType) {//grdType-> P = Position in B&P, W = WorkingOrder, S = SavedOrder & PA - PositionAnalyzer
    var menu = GetLinkPacketItems(grdType, obj);
    if (ev != null) {
        window.onresize = function() { hidemenu(ev); }
    }
    pageType = "M"; //indicates pages in mangement folder.For Stock & OPT it is "T";
    CreateDropDownMenuInManagent(obj, ev, menu, '150px');
}
function CreateMenuContentForQR(obj, evnt, pgId, symbolHolder) {
    pageId = pgId;
    var menu = GetLinkPacketItemsForQR(pageId, symbolHolder);
    window.onresize = function() { hidemenu(evnt); }
    DropDownMenu(obj, evnt, menu, '150px');
}
function CreateDropDownMenuInManagent(obj, e, menucontents, menuwidth) {
    if (window.event) event.cancelBubble = true;
    else if (e.stopPropagation) e.stopPropagation();
    ClearHideMenu();
    dropmenuobj = document.getElementById ? document.getElementById("dropmenudiv") : dropmenudiv;
    PopulateMenu(menucontents, '../../');
    if (ie4 || ns6) {
        Showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
        dropmenuobj.x = GetPosOffset(obj, "left");
        dropmenuobj.y = GetPosOffset(obj, "top");
        dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + "px";
        dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px";
    }
    return clickreturnvalue();
}
function GenerateMultilegQueryString(gridType, rowObj) {
    if (gridType == "SP" || gridType == "OP" || gridType == "SL" || gridType == "MP") { // SP: Stock Page Position, OP: Option Page Position, SL -SymbolLookupPage
        return;
    }  
    var description = "";
    if (gridType == 'W' || gridType == 'OS') {
        description = rowObj.cells[4].innerHTML;
    } else if (gridType == 'P') { // Positions table
        multilegParamsInfo = "&leg1Symbol=" + rowObj.cells[5].innerHTML + "&leg1Qty=" + rowObj.cells[6].innerHTML + "&origination=OpenPosition";
        return;
    } else if (gridType == 'URG') {
        multilegParamsInfo = "&leg1Symbol=" + rowObj.cells[0].innerHTML + "&leg1Qty=" + rowObj.cells[2].innerHTML + "&origination=OpenPosition";
        return;
    } else if (gridType == 'GOS') {
        description = rowObj.cells[5].innerHTML;
    }
    else if (gridType == 'PA') {
        if (ns6){
            description = rowObj.cells[3].textContent;
        }
        else{
            description = rowObj.cells[3].innerText;
        }
        isMultiLeg = IsMultiLegOrder(description);
        return;
    }
    else {
        description = rowObj.cells[15].getElementsByTagName('input')[1].value;
    }
    var isMultilegOrder = ((description.indexOf(':') > 0 || description.indexOf('/') > 0) && description.split('/').length > 1) ? true : false;
    if (isMultilegOrder && gridType != 'OS') {
        var legInfo = "";
        var numOflegs = description.split('/').length;
        var isLimitPrice = IsLimitOrder(rowObj);
        var limitPrice = (isLimitPrice) ? GetLimitOrderPrice(rowObj) : "";
        var grid = rowObj.parentNode.parentNode;
        var detailsGridObj = grid.rows[rowObj.rowIndex + 1].cells[1].getElementsByTagName('TABLE')[0];
        for (var i = 1; i <= 4; i++) {
            var row = (detailsGridObj.rows[i] != null) ? detailsGridObj.rows[i] : null;
            if (row != null) {
                limitPrice = (isLimitPrice) ? limitPrice : GetValidSpreadPrice(row);
                legInfo += "&leg" + i + "Symbol=" + row.cells[0].innerHTML + "&leg" + i + "Qty=" + row.cells[2].innerHTML + "&leg" + i + "Price=" + limitPrice;
            } else {
                legInfo += "&leg" + i + "Symbol=&leg" + i + "Qty=&leg" + i + "Price=";
            }
        }
        multilegParamsInfo = legInfo + "&OrderSecurityType=MLEG";
    } else if (isMultilegOrder && gridType == 'OS') {
        var priceType = (IsLimitOrder(rowObj)) ? "LIMIT" : "MARKET";
        var orginalOrdId = rowObj.cells[15].getElementsByTagName('input')[0].value;
        var orderId = ExtractOrderId(orginalOrdId);
        if (IsSavedOrder(orginalOrdId)) {
            multilegParamsInfo = "&priceType=" + priceType + "&OrderType=SAVED" + "&pid=" + 'OS';
        } else {
            multilegParamsInfo = "&priceType=" + priceType + "&OrderType=WORKING" + "&pid=" + 'OS';
        }
        multilegParamsInfo += "&OrderSecurityType=MLEG";
    }
    else {
        var price = "";
        var priceType = (IsLimitOrder(rowObj)) ? "LIMIT" : "MARKET";
        var orderAction = trim(rowObj.cells[5].innerHTML);
        if (IsMarketHour() && orderAction == "Buy" && priceType != "LIMIT") {
            price = trim(rowObj.cells[11].innerHTML);
        } else if (IsMarketHour() && orderAction == "Sell" && priceType != "LIMIT") {
            price = trim(rowObj.cells[10].innerHTML);
        } else if (priceType == "LIMIT") {
            price = GetLimitOrderPrice(rowObj);
        }
        multilegParamsInfo = "&leg1Symbol=" + rowObj.cells[3].innerHTML + "&leg1Qty=" + rowObj.cells[6].innerHTML + "&leg1Price=" + price;
    }
}
function GetValidSpreadPrice(rowObj) {
    var price = "";
    var orderAction = trim(rowObj.cells[1].innerHTML);
    if (IsMarketHour() && orderAction == "Buy") {
        price = trim(rowObj.cells[7].innerHTML);
    } else if (IsMarketHour() && orderAction == "Sell") {
        price = trim(rowObj.cells[6].innerHTML);
    }
    return price;
}
function IsLimitOrder(rowObj) {
    return (rowObj.cells[7].innerHTML.toString().indexOf("$") > 0) ? true : false;
}
function GetLimitOrderPrice(rowObj) {
    var priceText = rowObj.cells[7].innerHTML.toString();
    priceText = priceText.split('$');
    return trim(priceText[1]);
}
function GetLinkPacketItems(sourceGrid, lnkBtnObj) {    
    var rowObj = lnkBtnObj.parentNode.parentNode;
    GenerateMultilegQueryString(sourceGrid, rowObj);
    if (sourceGrid == 'W' || sourceGrid == 'S' || sourceGrid == 'OS') {
        SetParametersForLinkPackets(rowObj, 3, 16, 17, 6, sourceGrid);
    }
    switch (sourceGrid) {
        case 'S':
            pageId = "SO";
            break;
        case 'OS':
            var category;
            if (ns6)
                category = parseInt(rowObj.cells[18].textContent, 10); //indicating working order or not
            else
                category = parseInt(rowObj.cells[18].innerText, 10);
            pageId = (category == 15) ? 'SO' : 'WO'; //indicating saved stock order
            break;
        case 'P':
            pageId = 'BP';
            SetParametersForLinkPackets(rowObj, 5, 0, 1, 6, 'P');
            if (ns6) {
                orderId = rowObj.cells[2].textContent;
            }
            else {
                orderId = rowObj.cells[2].innerText;
            }
            break;
        case 'SP': //For Stock Page Positions In XXXX 
            if (ns6) {
                gridSymbol = rowObj.cells[0].textContent;
            }
            else {
                gridSymbol = rowObj.cells[0].innerText;
            }
            assetType = 'E';
            break;
        case 'OP': //For Option Page Positions In XXXX 
            pageId = 'OP';
            if (ns6) {
                gridSymbol = rowObj.cells[0].textContent;
                quantity = rowObj.cells[1].textContent;
            }
            else {
                gridSymbol = rowObj.cells[0].innerText;
                quantity = rowObj.cells[1].innerText;
            }
            assetType = (IsUnderlyingSymbol(gridSymbol)) ? "E" : "O";
            underlyingSymbol = document.getElementById("ctl00_ContentPlaceHolder1_txtUnderlying").value;
            break;
        case 'MP': //For MutualFund Page Positions In XXXX
            if (ns6) {
                gridSymbol = rowObj.cells[0].textContent;
            }
            else {
                gridSymbol = rowObj.cells[0].innerText;
            }
            assetType = 'F';
            break;
        case 'SL': //Symbol Lookup page.
            if (ns6)
                gridSymbol = rowObj.cells[0].textContent;
            else
                gridSymbol = rowObj.cells[0].innerText;
            gridSymbol = trim(gridSymbol);
            assetType = 'E';
            if (gridSymbol.substring(0, 1) == ':')
                assetType = 'F'
            else if (gridSymbol.substring(0, 1) == '$')
                assetType = 'I';
            break;
        case 'GOS': //Global Order Status Grid -> Admin
            var category;
            SetParametersForLinkPackets(rowObj, 4, 19, 20, 7, 'GOS');
            if (ns6) {
                category = rowObj.cells[21].textContent; //indicating working order or not
                orderAction = (trim(rowObj.cells[6].textContent).toUpperCase() == "BUY") ? 1 : 2;
                orderId = ExtractOrderId(rowObj.cells[16].getElementsByTagName('input')[0].value);
                accountId = rowObj.cells[18].textContent;
                accountNumber = rowObj.cells[17].textContent;
            }
            else {
                category = rowObj.cells[21].innerText;
                orderAction = (trim(rowObj.cells[6].innerText).toUpperCase() == "BUY") ? 1 : 2;
                orderId = ExtractOrderId(rowObj.cells[16].getElementsByTagName('input')[0].value);
                accountId = rowObj.cells[18].innerText;
                accountNumber = rowObj.cells[17].innerText;
            }
            pageId = (category == 15) ? 'SO' : 'WO';
            break;
        case 'URG': //In H&S Unrealized gain fnctn call.
            pageId = 'BP';
            SetParametersForLinkPackets(rowObj, 0, 11, 12, 2, 'URG');
            break;
        case 'PA': //For Position Analyzer Positions In XXXX        
            isCombinedPosition = IsCombinedPosition(rowObj);
            if(isCombinedPosition){
                SetCombinedParametersForLinkPackets(rowObj, symbol_Index, assetType_Index, underlying_Index, netQauantity_Index, description_Index, bid_Index, ask_Index, multiplier_Index);
            }else{
                SetParametersForLinkPackets(rowObj, symbol_Index, assetType_Index, underlying_Index, netQauantity_Index, 'PA');
            }
            if (ns6) {
                orderId = trim(rowObj.cells[orderId_Index].textContent);
            }
            else {
                orderId = trim(rowObj.cells[orderId_Index].innerText);
            }
            break;
    }
    return GetActionLinkPacketLinks(sourceGrid, rowObj);

}
function SetCombinedParametersForLinkPackets(rowObj, symbColIndex, assetColIndex, underLyingIndex, qtyColIndex, descColIndex, bidColIndex, askColIndex, multiplierColIndex){
    var numberOfLegs = parseFloat(rowObj.cells[numberOfLegs_Index].innerHTML);
    var rowIndex = rowObj.rowIndex;
    var node = null;
    isMultiLeg = true;
    
    if (ns6) {
            gridSymbol = trim(rowObj.cells[parseInt(symbColIndex, 10)].textContent);
            assetType = trim(rowObj.cells[parseInt(assetColIndex, 10)].textContent);
            underlyingSymbol = trim(rowObj.cells[parseInt(underLyingIndex, 10)].textContent);
     }else{   
            gridSymbol = trim(rowObj.cells[parseInt(symbColIndex, 10)].innerText);
            assetType = trim(rowObj.cells[parseInt(assetColIndex, 10)].innerText);
            underlyingSymbol = trim(rowObj.cells[parseInt(underLyingIndex, 10)].innerText);
     }
            
    multilegParamsInfo = "&numberOfLegs=" + numberOfLegs;
    var legSymbol;
    var legDescription;
    var legQuantity;
    var legMultiplier;
    var legPrice;
    var totalPrice = 0;
    var totalQuantity = 1;
    for(var legCount = 1; legCount <= numberOfLegs; legCount++){
        node = rowObj.parentNode.rows[rowIndex + legCount];
        
        if (ns6) {
            legSymbol = $.trim(node.cells[parseInt(symbColIndex, 10)].textContent);
            legDescription = $.trim(node.cells[parseInt(descColIndex, 10)].textContent);
            legQuantity = $.trim(node.cells[parseInt(qtyColIndex, 10)].textContent);
            legMultiplier = parseFloat($.trim(node.cells[parseInt(multiplierColIndex, 10)].textContent));
            legPrice = (parseFloat(legQuantity) > 0) ? $.trim(node.cells[parseInt(askColIndex, 10)].textContent) : $.trim(node.cells[parseInt(bidColIndex, 10)].textContent);
            totalPrice = totalPrice + (parseFloat(legQuantity) * legMultiplier * legPrice);
        } else {
            legSymbol = $.trim(node.cells[parseInt(symbColIndex, 10)].innerText);
            legDescription = $.trim(node.cells[parseInt(descColIndex, 10)].innerText);
            legQuantity = $.trim(node.cells[parseInt(qtyColIndex, 10)].innerText);
            legMultiplier = parseFloat($.trim(node.cells[parseInt(multiplierColIndex, 10)].innerText));
            legPrice = (parseFloat(legQuantity) > 0) ? $.trim(node.cells[parseInt(askColIndex, 10)].innerText) : $.trim(node.cells[parseInt(bidColIndex, 10)].innerText);
            totalPrice = totalPrice + (parseFloat(legQuantity) * legMultiplier * legPrice);
        }
        if(legCount == 1){
            totalQuantity = parseFloat(legQuantity) * legMultiplier;
            }
        switch(legCount){
            case 1:
                multilegParamsInfo += "&leg1Symbol=" + legSymbol + "&leg1Qty=" + legQuantity + "&leg1Description=" + legDescription;
                break;
            case 2:
               multilegParamsInfo += "&leg2Symbol=" + legSymbol + "&leg2Qty=" + legQuantity + "&leg2Description=" + legDescription;
                break;
            case 3:
                multilegParamsInfo += "&leg3Symbol=" + legSymbol + "&leg3Qty=" + legQuantity + "&leg3Description=" + legDescription;
                break;
            case 4:
                multilegParamsInfo += "&leg4Symbol=" + legSymbol + "&leg4Qty=" + legQuantity + "&leg4Description=" + legDescription;
                break;
            default:
                break;         
        }    
    }
    __limitPrice = Math.abs(totalPrice/totalQuantity).toFixed(2);
    multilegParamsInfo += "&LimitPrice=" + __limitPrice;
}
function GetLinkPacketItemsForQR(pageId, symbolHolder) {
    var linkItems = new Array();
    var style = new Array();
    for (var i = 0; i < 6; i++) {
        style[i] = 'block';
    }
    if (pageId == 'QR-OC') {
        assetType = 'O';
        var rowObj = symbolHolder.parentNode.parentNode; //for Option Chain page symbolHolder Means the action button itself.
        underlyingSymbol = document.getElementById('ctl00_ContentPlaceHolder1_txtSymbol').value;
        underlyingSymbol = trim(underlyingSymbol.replace('.', ''));
        SetOptionChainParamsInfo(rowObj);
        style[1] = 'none';
        style[4] = 'none';
        gridSymbol = rowObj.cells[1].innerHTML;
    }
    else {
        //Hiding ClosePos, Analyzer
        style[1] = 'none';
        style[2] = 'none';
        if (pageId == 'A-CH') //Hiding Charts link in chart page.
            style[5] = 'none';
        else if (pageId == 'A-MF')//Hiding TBr for MF
            style[3] = 'none';
        if (pageId != 'A-CH')//Hiding Detailed Quote for other Analyze pages
            style[4] = 'none';
        gridSymbol = document.getElementById(symbolHolder).innerHTML;
        var ch = gridSymbol.charAt(0);
        if (ch == '$')
            assetType = 'I';
        else if (ch == ':')
            assetType = 'F';
        else if (!IsUnderlyingSymbol(gridSymbol))
            assetType = 'O';
        else
            assetType = 'E';
    }
    if (assetType == 'I' || assetType == 'F') {
        style[0] = 'none'; //hiding Trade Link for MF and Index Symbols.
    }
    linkItems[0] = "<a style='cursor:pointer;display:" + style[0] + "' onclick='ProcessTheAction(this,1);'>Trade</a>";
    linkItems[1] = "<a style='cursor:pointer;display:" + style[1] + "' onclick='ProcessTheAction(this,2);'>Close Position</a>";
    linkItems[2] = "<a style='cursor:pointer;display:" + style[2] + "' onclick='ProcessTheAction(this,3);'>Analyzer</a>";
    linkItems[3] = "<a style='cursor:pointer;display:" + style[3] + "' onclick='ProcessTheAction(this,4);'>TradeBuilder</a>";
    linkItems[4] = "<a style='cursor:pointer;display:" + style[4] + "' onclick='ProcessTheAction(this,5);'>Detailed Quote</a>";
    linkItems[5] = "<a style='cursor:pointer;display:" + style[5] + "' onclick='ProcessTheAction(this,6);'>Chart</a>";
    linkItems[6] = "<a style='cursor:pointer;display:" + style[6] + "' onclick='ProcessTheAction(this,7);'>Positions</a>";
    return linkItems;
}
function IsWorkingOrder(stat) {
    if (stat == 1 || stat == 2 || stat == 6 || stat == 7 || stat == 11 || stat == 14 || stat == 16 || stat == 18)
        return true;
    else
        return false;
}
function ExtractOrderId(orderId) {
    orderId = orderId.toUpperCase();
    if ((orderId.charAt(0) == "O" || orderId.charAt(0) == "F") && orderId.charAt(1) == "S") {
        orderId = orderId.substring(2, orderId.length);
    }
    else if (orderId.charAt(0) == "O" || orderId.charAt(0) == "S" || orderId.charAt(1) == "F") {
        orderId = orderId.substring(1, orderId.length);
    }
    return orderId;
}
function IsSavedOrder(orderId) {
    return (orderId.toString().charAt(0).toUpperCase() == "O" && orderId.toString().charAt(1).toUpperCase() == "S") ? true : false;
}
function show_confirm() {
    var r = confirm("Do You Want to Delete?");
    if (r == true) {
        return true;
    }
    else {
        return false;
    }
}
function IsUnderlyingSymbol(symbolText) {
    symbolText = symbolText.replace(/^\s+|\s+$/g, '');
    for (var i = 0; i < symbolText.length; i++) {
        var ch = symbolText.charAt(i);
        if (ch == ' ') {
            return false;
        }
    }
    return true;
}
function IsMarketHour() {
    var isMarketHour = document.getElementById("ctl00_ContentPlaceHolder1_hfIsMarketHour").value;
    return (isMarketHour == true || isMarketHour.toLowerCase() == "true") ? true : false;
}
function SetOptionChainParamsInfo(rowObj) {
    var strategy = GetStartegyType();
    var symbolIndex = (GetOptionChainSection() == "L") ? 1 : 7;
    var lastPriceIndex = (GetOptionChainSection() == "L") ? 4 : 10;
    switch (parseInt(strategy, 10)) {
        case 1: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML) + "&leg1Qty=1&leg2Symbol=&leg2Qty=&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break;   // Single
        case 2: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Vertical
        case 3: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Calendar
        case 5: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Straddle
        case 6: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Strangle
        case 7: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=2&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[2]) + "&leg3Qty=1&leg4Symbol=&leg4Qty="; break; // Butterfly
        case 8: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[2]) + "&leg3Qty=1&leg4Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[3]) + "&leg4Qty=1"; break; // Condor
        case 9: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[2]) + "&leg3Qty=1&leg4Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[3]) + "&leg4Qty=1"; break; // Iron Butterfly
        case 10: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[2]) + "&leg3Qty=1&leg4Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[3]) + "&leg4Qty=1"; break; // Iron Condor
        case 11: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[2]) + "&leg3Qty=1&leg4Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[3]) + "&leg4Qty=1"; break; // Box
        case 13: multilegParamsInfo = "&leg1Symbol=" + underlyingSymbol + "&leg1Qty=100&leg2Symbol=" + rowObj.cells[symbolIndex].innerHTML + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Covered Call
        case 14: multilegParamsInfo = "&leg1Symbol=" + underlyingSymbol + "&leg1Qty=100&leg2Symbol=" + rowObj.cells[symbolIndex].innerHTML + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Married Put
        case 15: multilegParamsInfo = "&leg1Symbol=" + underlyingSymbol + "&leg1Qty=100&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg2Qty=1&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg3Qty=1&leg4Symbol=&leg4Qty="; break;  // Conversion
        case 16: multilegParamsInfo = "&leg1Symbol=" + underlyingSymbol + "&leg1Qty=100&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg2Qty=1&leg3Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg3Qty=1&leg4Symbol=&leg4Qty="; break; // Collar
        case 17: multilegParamsInfo = "&leg1Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[0]) + "&leg1Qty=1&leg2Symbol=" + ExtractSymbol(rowObj.cells[symbolIndex].innerHTML.split('/')[1]) + "&leg2Qty=1&leg3Symbol=&leg3Qty=&leg4Symbol=&leg4Qty="; break; // Synthetic Combo
    }
    multilegParamsInfo += "&origination=AnalyzeOptionChain&StratId=" + strategy + "&LimitPrice=" + rowObj.cells[lastPriceIndex].innerHTML;
}
function ExtractSymbol(symbolText) {
    return trim(symbolText.replace('.', ''));
}
function GetActionLinkPacketLinks(sourceGrid, rowObj) {
    var links = new Array();
    var style = new Array();
    for (var i = 0; i < 6; i++) {
        style[i] = 'block';
    } 
    style[6] = 'none'; //Not Showing Positions link from normal pages.
    style[1] = 'none';
    if (assetType == 'E')
        style[2] = 'none';
    else if (assetType == 'F') {
        style[2] = 'none';
        style[3] = 'none';
    }
    else if (assetType == 'B') {
        style[0] = 'none';
        style[1] = 'none';
    }
    switch (sourceGrid) {
        case 'W':
            style[0] = 'none';
            break;
        case 'S':
            //ddd
            break;
        case 'OS':
            if (IsWorkingOrder(parseInt(rowObj.cells[18].textContent, 10)))
                style[0] = 'none';
            break;
        case 'P':case 'URG':
            if (assetType != 'B') {
                style[1] = 'block';
            }
            break;
        case 'SP':
            for (var k = 0; k < 3; k++) {
                style[k] = 'none';
            }
            style[6] = 'block';
            break;
        case 'MP':
            for (var k = 0; k < 3; k++) {
                style[k] = 'none';
            }
            style[6] = 'block';
            break;
        case 'SL': 
            style[6] = 'block';
            if (assetType == 'I') {
                style[0] = 'none'; //Hiding Trade link
                style[3] = 'none';
            }
            break;
        case 'GOS':
            if (IsWorkingOrder(parseInt(rowObj.cells[21].innerHTML, 10)))
                style[0] = 'none';
            style[1] = 'none';
            break;
        case 'PA':
            pageId = "PA";
            style[1] = "block";
            if (IsCombinedPosition(rowObj)) {
                style[0] = "block";
                style[1] = "block";
                style[2] = "none";
                links[7] = "<a style='cursor:pointer;' onclick='UnlinkStrategies(0," + rowObj.rowIndex + ");'>Break Apart</a>";
            }
            if(IsMultiLegOrder(trim(GetRowDescription(rowObj.cells[3])))){
                //style[0] = "none";
                //style[1] = "none";
                style[2] = "none";
                if(document.getElementById('ctl00_ContentPlaceHolder1_hfOptApprovalLevel').value=="6")
                    links[7] = "<a style='cursor:pointer;' onclick='UnlinkStrategies(0," + rowObj.rowIndex + ");'>Break Apart</a>";
            }
    }
    links[0] = "<a style='cursor:pointer;display:" + style[0] + "' onclick='ProcessTheAction(this,1);'>Trade</a>";
    links[1] = "<a style='cursor:pointer;display:" + style[1] + "' onclick='ProcessTheAction(this,2);'>Close Position</a>";
    links[2] = "<a style='cursor:pointer;display:" + style[2] + "' onclick='ProcessTheAction(this,3);'>Analyzer</a>";
    links[3] = "<a style='cursor:pointer;display:" + style[3] + "' onclick='ProcessTheAction(this,4);'>TradeBuilder</a>";
    links[4] = "<a style='cursor:pointer;display:" + style[4] + "' onclick='ProcessTheAction(this,5);'>Detailed Quote</a>";
    links[5] = "<a style='cursor:pointer;display:" + style[5] + "' onclick='ProcessTheAction(this,6);'>Chart</a>";
    links[6] = "<a style='cursor:pointer;display:" + style[6] + "' onclick='ProcessTheAction(this,7);'>Positions</a>";
    return links;
}
function GetRowDescription(cellObj){
    return (cellObj.getElementsByTagName("DIV").length > 0) ? cellObj.getElementsByTagName("DIV")[0].innerHTML : cellObj.innerHTML;
}
// Takes the Symbol, Qty, AssetType  etc from Grid columns and assign it to global variables
function SetParametersForLinkPackets(rowObj, symbColIndex, assetColIndex, underLyingIndex, qtyColIndex, source) {    
    if (ns6) {
        gridSymbol = trim(rowObj.cells[parseInt(symbColIndex, 10)].textContent);
        assetType = trim(rowObj.cells[parseInt(assetColIndex, 10)].textContent);
        underlyingSymbol = trim(rowObj.cells[parseInt(underLyingIndex, 10)].textContent);
        quantity = trim(rowObj.cells[parseInt(qtyColIndex, 10)].textContent);
        if (source == 'S' || source == 'OS') {
            orderAction = (trim(rowObj.cells[5].textContent).toUpperCase() == "BUY") ? 1 : 2;
            __limitPrice = trim(rowObj.cells[7].textContent);
            orderId = ExtractOrderId(rowObj.cells[15].getElementsByTagName('input')[0].value);            
        }
    }
    else {
        gridSymbol = trim(rowObj.cells[parseInt(symbColIndex, 10)].innerText);
        assetType = trim(rowObj.cells[parseInt(assetColIndex, 10)].innerText);
        underlyingSymbol = trim(rowObj.cells[parseInt(underLyingIndex, 10)].innerText);
        quantity = trim(rowObj.cells[parseInt(qtyColIndex, 10)].innerText);
        if (source == 'S' || source == 'OS') {
            orderAction = (trim(rowObj.cells[5].innerText).toUpperCase() == "BUY") ? 1 : 2;
            __limitPrice = trim(rowObj.cells[7].innerText);
            orderId = ExtractOrderId(rowObj.cells[15].getElementsByTagName('input')[0].value);            
        }
    }
}

/*____________________________________Link Packet popup ends____________________________________________________________  */

/*_______________________For multiLeg spread Bid/Ask calculation_______________________________*/
function IsMultiLegOrder(description) {
    var isMultilegOrder = ((description.indexOf(':') > 0 || description.indexOf('/') > 0) && description.split('/').length > 1) ? true : false;
    return isMultilegOrder;
}
function CalculateMultiLegSpreadBidAsk(strategyType, putOrCall, legSymbolsBid, legSymbolsAsk,underLyingBidAsk) {
    var spreadBidAsk = new Array();//0th postn stores Bid,1st postn stores Ask

    switch (strategyType) {
        case 'Vertical':
            if (putOrCall == 'PUT') {//Leg1Ask - leg2Bid = ASK  -- bcoz the Leg1 and Leg2 insertion are reversed.
                                     //Leg1Bid - Leg2Ask = BID --new Eqtns
                spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]); 
                spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]); 
            }
            else {
                spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]);
                spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]);
            }
            break;
        case 'Calendar'://Leg1Bid - Leg2Ask = BID //Leg1Ask - leg2Bid = ASK
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]);
            break;
        case 'Straddle': case 'Strangle':
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) + parseFloat(legSymbolsBid[1]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) + parseFloat(legSymbolsAsk[1]);
            break;
        case 'Butterfly':
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - (2 * parseFloat(legSymbolsAsk[1])) + parseFloat(legSymbolsBid[2]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - (2 * parseFloat(legSymbolsBid[1])) + parseFloat(legSymbolsAsk[2]);
            break;
        case 'Condor':
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]) - parseFloat(legSymbolsAsk[2]) + parseFloat(legSymbolsBid[3]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]) - parseFloat(legSymbolsBid[2]) + parseFloat(legSymbolsAsk[3]);
            break;
        case 'Iron Butterfly': //Leg1Bid - Leg2Ask + Leg4Bid - Leg3Ask = BID , Leg2Ask - Leg1Bid + Leg3Ask - Leg4Bid = ASK
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]) + parseFloat(legSymbolsBid[3]) - parseFloat(legSymbolsAsk[2]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[1]) - parseFloat(legSymbolsBid[0]) + parseFloat(legSymbolsAsk[2]) - parseFloat(legSymbolsBid[3]);
            break;
        case 'Iron Condor': //Leg2Bid - Leg1Ask + Leg3Bid - Leg4Ask = BID, Leg2Ask - Leg1Bid + Leg3Ask - Leg4Bid = ASK -- In DB Leg1 & Leg2 are interchanged, so change the Eqn also.
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]) + parseFloat(legSymbolsBid[2]) - parseFloat(legSymbolsAsk[3]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]) + parseFloat(legSymbolsAsk[2]) - parseFloat(legSymbolsBid[3]);
            break; 
        case 'Box':
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]) - (parseFloat(legSymbolsAsk[2]) - parseFloat(legSymbolsBid[3]));
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]) - (parseFloat(legSymbolsBid[2]) - parseFloat(legSymbolsAsk[3]));
            break;
        case 'Covered Call':
            spreadBidAsk[0] = parseFloat(underLyingBidAsk[0]) - parseFloat(legSymbolsAsk[1]);//Now inserts the Option symbol in Leg2 and underlying in Leg1
            spreadBidAsk[1] = parseFloat(underLyingBidAsk[1]) - parseFloat(legSymbolsBid[1]); //underlyingAsk - LegSymbolBid
            break;
        case 'Married Put':
            spreadBidAsk[0] = parseFloat(underLyingBidAsk[0]) + parseFloat(legSymbolsBid[1]);//Now inserts the Option symbol in Leg2 and underlying in Leg1
            spreadBidAsk[1] = parseFloat(underLyingBidAsk[1]) + parseFloat(legSymbolsAsk[1]);
            break;
        case 'Conversion': case 'Collar':
            spreadBidAsk[0] = parseFloat(underLyingBidAsk[0]) - parseFloat(legSymbolsAsk[1]) + parseFloat(legSymbolsBid[2]);//Now inserts the Option symbols in Leg 1&2 and underlying in Leg1
            spreadBidAsk[1] = parseFloat(underLyingBidAsk[1]) - parseFloat(legSymbolsBid[1]) + parseFloat(legSymbolsAsk[2]);
            break;       
        case 'Synthetic Combo':
            spreadBidAsk[0] = parseFloat(legSymbolsBid[0]) - parseFloat(legSymbolsAsk[1]);
            spreadBidAsk[1] = parseFloat(legSymbolsAsk[0]) - parseFloat(legSymbolsBid[1]);
            break;
        case 'Create My Own':
            break;
    }
    return spreadBidAsk;
}
function GetNumberOfLegSymbols(strategyType) {
    var noOfLeg = 0;
    switch (strategyType) {
        case 'Vertical': case 'Calendar': case 'Straddle': case 'Strangle':
        case 'Covered Call': case 'Married Put': case 'Synthetic Combo':
            noOfLeg = 2;
            break;
        case 'Butterfly': case 'Conversion': case 'Collar':
            noOfLeg = 3;
            break;
        case 'Condor': case 'Iron Butterfly': case 'Iron Condor': case 'Box':
            noOfLeg = 4;
            break;
        case 'Create My Own':
            break;
    }
    return noOfLeg;
}
function GetStrategyNameFromDescription(descr) {
    var strategy = descr.split(':');
    return strategy[0];
}
function IsPutOrCall(descr) {
    if (descr.indexOf('CALL') > 1) {
        return 'CALL';
    }
    else
        return "PUT";
}
//same function body is used in master pages,TakeATour.ascx,Public\ShowLearnContent.aspx.. So if change the content,do it in these pages also.
function IsConfirm() {
    var linkPrivacy = document.getElementById('ctl00_lnkPrivacyPolicy').href;
    return confirm('You are now leaving TradingBlock.com. The third party website you have chosen to enter \nhas no affiliation with TradingBlock. We do not endorse or warrant the content, services or \nproducts offered on this website. TradingBlock is not responsible for the privacy practices \non selected website and we recommend that you review the website’s privacy and securities \nstatement thoroughly. TradingBlock provides access to this website for educational and \ninformational purposes only. Use of this site and its services and products is at your own risk, \nand without guarantee or warranty of any kind from TradingBlock.\n\nTo view TradingBlock’s privacy policy, please go to the website URL \n'+linkPrivacy+'.\n\n                              Do you wish to continue to the selected site?');
}
function CurrencyConverter(strValue) {
    var newValue = strValue.toFixed(2);
    var objRegExp = new RegExp('-?[0-9]+\.[0-9]{2}$');
    if (objRegExp.test(newValue)) {
        objRegExp.compile('^-');
        newValue = AddCommas(newValue);
        if (objRegExp.test(newValue)) {
            newValue = '($' + newValue.replace(objRegExp, '') + ')';
        }
        else { newValue = '$' + newValue.replace(objRegExp, ''); }
    }
    else {
        newValue = '$' + newValue;
    }
    objRegExp = null;
    return newValue;
}
function AddCommas(str) {
    var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');  
    while (objRegExp.test(str)) {
        str = str.replace(objRegExp, '$1,$2');
    }objRegExp = null;
    return str;
}

function RemoveRepeatedSymbols(gridSymbols) {
    var symbols = new Array();
    start: for (var i = 0, n = gridSymbols.length; i < n; i++) {
        for (var x = 0, y = symbols.length; x < y; x++)
            if (symbols[x] == gridSymbols[i]) continue start;
            symbols[symbols.length] = gridSymbols[i];
    }
    return symbols;
}
function FindTheIndexOfElementFromArray(contentArray, searchItem) {
    for (var i = 0; i < contentArray.length; i++) {
        if (contentArray[i].Symbol == searchItem) {
            return i;
        }
    }
    return -1;
}
function QuoteRequestInfo(ddlObj) {
    this.UserId = (ddlObj!=null)? ddlObj.options[ddlObj.selectedIndex].value : -1;
    this.AccountNumber = (ddlObj!=null)? ddlObj.options[ddlObj.selectedIndex].text : '';
    this.Token = document.getElementById('ctl00_hfToken').value;
    this.Requester = document.location.host;
    this.SymbolList = new Array();
}
function IsCombinedPosition(rowObj) {
    var isCombined = false;
    if (ns6)
        isCombined = trim(rowObj.cells[3].textContent).indexOf('Combined') != -1 ? true : false;
    else
        isCombined = trim(rowObj.cells[3].innerText).indexOf('Combined') != -1 ? true : false;
    return isCombined;
}
//Region Modal pop up for virtual trade
function loadjscssfile(filename, filetype) {
    if (filetype == "js") { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css") { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}
function ModalPopUp() {
    this.GetHTML = function() {
        throw new Error("GetHTML method is not implemented");
    }
    this.PostData = function() {
        throw new Error("PostData method is not implemented");
    }
}
var __modalPopUp;
TradingLevel.prototype = new ModalPopUp();
VirtualMoney.prototype = new ModalPopUp();
InviteFriends.prototype = new ModalPopUp();
function ModalPopUpProvider(popUpName) {
    var modalPopUp = null;
    if (popUpName == "TradingLevel") {
        modalPopUp = new TradingLevel();
    }
    else if (popUpName == "InviteFriends") {
        modalPopUp = new InviteFriends();
    }
    else if (popUpName == "VirtualMoney") {
        modalPopUp = new VirtualMoney();
    }
    else if(popUpName == "RejectedOrder") {
        modalPopUp = new RejectedOrder();
    }
    else if(popUpName == "ShowSSN") {
        modalPopUp = new ShowSSN();
    }
    return modalPopUp;
}
function ShowPopUp(popUpName) {
    __modalPopUp = ModalPopUpProvider(popUpName);
    var html = __modalPopUp.GetHTML();
    $(document).ready(function() {
        $.modal(html, { overlayClose: true });
    });
    if(popUpName == "InviteFriends" && !(navigator.appVersion.indexOf("MSIE 7.")==-1)){
        var element = document.getElementById('simplemodal-container');	
        element.style.left = "";
	        element.setAttribute("className", "InviteFriends-simplemodal-container");
        }
}
function PostPopUpData(popUpName) {
    if (validate(popUpName)) {
        __modalPopUp = ModalPopUpProvider(popUpName);
        __modalPopUp.PostData();
        __modalPopUp = null;
    }
}
function validate(popUpName) {
    var result = false;
    switch (popUpName) {
        case "TradingLevel":
            result=validateTradingLevel();
            break;
        case "VirtualMoney":
            result=validateVirtualMoney();
            break;
        case "InviteFriends":
            result=validateInviteFriends();
            break;
        default:
            break;
    }
    return result;
}
function validateTradingLevel() {
    if (document.getElementById('chkCash').checked == false && document.getElementById('chkOption').checked == false && document.getElementById('chkMargin').checked == false) {
        document.getElementById('spnTradingLevel').style.display = 'none';
        document.getElementById('spnTradingType').style.display = 'block';
        document.getElementById('spnTradingType').innerHTML = "You have to select atleast one trading type.";
        return false;
    }
    else {
        document.getElementById('spnTradingType').style.display = 'none';
    }
    if (document.getElementById('chkLevel_0').checked == false && document.getElementById('chkLevel_1').checked == false && document.getElementById('chkLevel_2').checked == false && document.getElementById('chkLevel_3').checked == false && document.getElementById('chkLevel_4').checked == false && document.getElementById('chkLevel_5').checked == false && document.getElementById('chkLevel_6').checked == false) {
        document.getElementById('spnTradingType').style.display = 'none';
        document.getElementById('spnTradingLevel').style.display = 'block';
        document.getElementById('spnTradingLevel').innerHTML = "You have to select atleast one option approval level";
        return false;
    }
    else {
        document.getElementById('spnTradingLevel').style.display = 'none';
    }
    return true;
}
function validateVirtualMoney() {
    if (document.getElementById('txtVirtualMoney').value == '') {
        document.getElementById('spnVirtualMoney').style.display = 'block';
        document.getElementById('spnVirtualMoney').innerHTML = "Please enter money.";
        document.getElementById('txtVirtualMoney').focus();
        return false;
    }
    else if (document.getElementById('txtVirtualMoney').value != '') {
        if (isNaN(document.getElementById('txtVirtualMoney').value)) {
            document.getElementById('spnVirtualMoney').style.display = 'block';
            document.getElementById('spnVirtualMoney').innerHTML = "Monay format is not valid.";
            document.getElementById('txtVirtualMoney').focus();
            return false;
        }
    }
    else {
        document.getElementById('spnVirtualMoney').style.display = 'none';
    }
    return true;
}
function validateInviteFriends() {
    var validity = true;
    if (document.getElementById('txtInviteFriend1').value == '' && document.getElementById('txtInviteFriend2').value == '' && document.getElementById('txtInviteFriend3').value == '' && document.getElementById('txtInviteFriend4').value == '' && document.getElementById('txtInviteFriend5').value == '' && document.getElementById('txtInviteFriend6').value == '' && document.getElementById('txtInviteFriend7').value == '' && document.getElementById('txtInviteFriend8').value == '' && document.getElementById('txtInviteFriend9').value == '' && document.getElementById('txtInviteFriend10').value == '') {
        document.getElementById('spnInviteFriend').style.visibility = 'visible';
         document.getElementById('spnInviteFriend').className = "InviteFriendsValidator";
        document.getElementById('spnInviteFriend').innerHTML="You have to invite at least one friend.";
        document.getElementById('txtInviteFriend1').focus();
        return false;
    }

    var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    for (var i = 1; i <= 10; i++) {
        if (document.getElementById('txtInviteFriend' + i).value != '') {
            if (reg.test(document.getElementById('txtInviteFriend' + i).value) == false) {
                document.getElementById('spnInviteFriend').style.display = 'none';
                document.getElementById('spnInviteFriend' + i).style.visibility = "visible";
                document.getElementById('spnInviteFriend' + i).className = "InviteFriendsValidator";
                document.getElementById('spnInviteFriend' + i).innerHTML = "Invalid email address.";
                document.getElementById('txtInviteFriend' + i).focus();
                validity = false;
            }
            else if (document.getElementById('txtInviteFriend' + i).value.length > 100) {
                document.getElementById('spnInviteFriend').style.display = 'none';
                document.getElementById('spnInviteFriend' + i).style.visibility = "visible";
                document.getElementById('spnInviteFriend' + i).className = "InviteFriendsValidator";
                document.getElementById('spnInviteFriend' + i).innerHTML = "Email cannot exceed 100 characters.";
                document.getElementById('txtInviteFriend' + i).focus();
                validity = false;
            }
            else {
                document.getElementById('spnInviteFriend' + i).style.visibility = 'hidden';
                validity = true;
            }
        }
    }
    return validity;
}
function InitAjaxRequest(obj, popUpName) {
    if (!JSON) {
        loadjscssfile("json2.js", "js");
    }
    if (!(popUpName == '' && popUpName == null && popUpName == 'undefined')) {
        $.ajax({
            type: "POST",
            url: GetHandlerPath('ModalPopUp'),
            data: { data: JSON.stringify(obj), popUp: popUpName },
            dataType: "json",
            responseType: "json",
            success: function(msg) {
                if (msg != null) {
                    if (msg['ErrorCode'] == 1) {
                        $.modal.impl.close()
                    }
                    else {
                        if (msg['ErrorCode'] == "ErrTradingLevel1") {
                            document.getElementById('spnTradingLevel').style.display = 'none';
                            document.getElementById('spnTradingType').style.display = 'block';
                            document.getElementById('spnTradingType').innerHTML = msg['ErrorDescription'];
                        }
                        else if (msg['ErrorCode'] == "ErrTradingLevel2") {
                            document.getElementById('spnTradingType').style.display = 'none';
                            document.getElementById('spnTradingLevel').style.display = 'block';
                            document.getElementById('spnTradingLevel').innerHTML = msg['ErrorDescription'];
                        }
                        else if (msg['ErrorCode'] == "ErrInviteFriends") {
                            document.getElementById('spnInviteFriend').style.visibility = "visible";
                            document.getElementById('spnInviteFriend').innerHTML = msg['ErrorDescription'];
                            document.getElementById('txtInviteFriend1').focus();
                        }
                        else if (msg['ResponseData'] == 101) {
                            var errors = msg['ErrorCode'].substring(1);
                            var errorList = errors.split(",");
                            var errorDescription = msg['ErrorDescription'].substring(1);
                            var errorDescriptionList = errorDescription.split(",");
                            for (var i = 0; i < 10; i++) {
                                if (errorList[i] == 'ErrInviteFriends' + i) {
                                    document.getElementById('spnInviteFriend').style.display = 'none';
                                    if (errorDescriptionList[i] != "") {
                                        document.getElementById('spnInviteFriend' + (i + 1)).style.visibility = 'visible';
                                        document.getElementById('spnInviteFriend' + (i + 1)).className = "InviteFriendsValidator";
                                    } else {
                                        document.getElementById('spnInviteFriend' + (i + 1)).className = "";
                                    }
                                    document.getElementById('spnInviteFriend' + (i + 1)).innerHTML = errorDescriptionList[i];
                                    document.getElementById('txtInviteFriend' + (i + 1)).focus();
                                }
                            }
                        }
                        else if (msg['ErrorCode'] == "ErrVirtualMoney2") {
                        document.getElementById('spnVirtualMoney').style.display = 'block';
                        document.getElementById('spnVirtualMoney').innerHTML = msg['ErrorDescription'];
                        document.getElementById('txtVirtualMoney').focus();
                        }
                        else {
                            alert(msg['ErrorDescription']);
                        }
                    }
                }
            }
        });
    }
}
var approvalLevel;
function TradingLevel() {
    var id;
    approvalLevel = { "Level_0": "No Option Trading", "Level_1": "Covered Writing", "Level_2": "Buying Options", "Level_3": "Spreading Options", "Level_4": "Selling Naked Equity Puts", "Level_5": "Selling Naked Equity Calls", "Level_6": "Selling Naked Index Calls and Puts" };
    var htmlArray = new Array();
    htmlArray.push('<div id="popUpHeader">Trading Level</div><div id="optionApprovalLevel"><div id="popUpContent">');
    htmlArray.push('<span id="spnTradingType" class="validator" style="display:none"></span>');
    htmlArray.push('<div class="subHeader">Trading Type</div>');
    htmlArray.push('<div class="modalPopUpContent">');
    htmlArray.push('<div class="floatLeft"><input type="checkbox" name="tradingType" id="chkCash"  value="1"/></div>');
    htmlArray.push('<div>Cash</div>');
    htmlArray.push('<div class="floatLeft"><input type="checkbox" name="tradingType" id="chkOption" value="2"/></div>');
    htmlArray.push('<div>Option</div>');
    htmlArray.push('<div class="floatLeft"><input type="checkbox" name="tradingType" id="chkMargin"  value="3"/></div>');
    htmlArray.push('<div>Margin</div>');
    htmlArray.push('</div>');
    htmlArray.push('<span id="spnTradingLevel" class="validator" style="display:none"></span>');
    htmlArray.push('<div class="subHeader">Option Approval Level</div>');
    htmlArray.push('<div class="modalPopUpContent">');
    var lastApprovalLevel;
    for (var j in approvalLevel) {
        id = j.split("_");
        htmlArray.push('<div class="floatLeft"><input type="checkbox" name="OptionApproval" id="chk' + j + '" value=' + id[1] + ' onclick="javascript:SetCheckboxStatus(' + id[1] + ');" /></div>');
        htmlArray.push('<div>(' + id[1] + ') ' + approvalLevel[j] + '</div>');
    }
    htmlArray.push('<div class="paddingTop floatRight"><a class="cancelButton" align="right" href="' + "javascript:ClosePopUp();" + '"></a></div><div class="paddingTop floatRight submitCancelBtnSeperator"></div><div class="paddingTop floatRight"><a class="submitButton" align="center" href="' + "javascript:PostPopUpData('TradingLevel');" + '"></a></div>');
    htmlArray.push('</div></div></div>');
    var htmlString = htmlArray.join('');
    this.GetHTML = function() {
        return htmlString;
    };

   if (!JSON) {
     loadjscssfile("json2.js", "js");
   }
   $.ajax({
            type: "POST",
            url: GetHandlerPath('ModalPopUp'),
            data: { popUp: "LoadOptionApproval" },
            dataType: "json",
            responseType: "json",
            success: function(msg) {
             if (msg != null) {
                    if (msg['ErrorCode'] == 1) {
                                    if (msg['ResponseLoadTradeLevel']['AccountType'] != "" || msg['ResponseLoadTradeLevel']['AccountType']!= null || msg['ResponseLoadTradeLevel']['AccountType'][0] != "undefined")
                                    {
                                    if(include(msg['ResponseLoadTradeLevel']['AccountType'],1)){
                                    document.getElementById('chkCash').checked=true;
                                    }
                                    if (include(msg['ResponseLoadTradeLevel']['AccountType'],2))
                                    {
                                    document.getElementById('chkOption').checked=true;
                                    } if (include(msg['ResponseLoadTradeLevel']['AccountType'],3))
                                    {
                                    document.getElementById('chkMargin').checked=true;
                                    }
                                }
                                if(msg['ResponseLoadTradeLevel']['ApprovalLevel']==0){
                                document.getElementById('chkLevel_0').checked=true;
                                for (var j in approvalLevel) {
                                   if (j != "Level_0") {
                                     document.getElementById('chk' + j + '').disabled = true;
                                    }
                                  }
                                }
                                else{
                                  for(var i=1;i<=msg['ResponseLoadTradeLevel']['ApprovalLevel'];i++)
                                  {
                                    document.getElementById('chkLevel_'+ i).checked=true;
                                  }
                                }
                              }
                           }
                        }
                     });

    this.PostData = function() {
        var accountType = new Array();
        if (document.getElementById('chkCash').checked) {
            accountType.push(1);
        }
        if (document.getElementById('chkOption').checked) {
            accountType.push(2);
        }
        if (document.getElementById('chkMargin').checked) {
            accountType.push(3);
        }
        for (var j in approvalLevel) {
            id = j.split("_");
            if (document.getElementById('chk' + j + '').checked && document.getElementById('chk' + j + '').disabled==false) {
                lastApprovalLevel = id[1];
            }
        }
        var tradingLevelInfo = new Object();
        tradingLevelInfo.AccountType = accountType;
        if(typeof(lastApprovalLevel) != "undefined" && typeof(lastApprovalLevel)!="unknown" && lastApprovalLevel){
          tradingLevelInfo.ApprovalLevel = lastApprovalLevel;
        }
        else{
          tradingLevelInfo.ApprovalLevel = -1;
        }
        InitAjaxRequest(tradingLevelInfo, 'TradingLevel');
    }
}
function include(arr, obj) {
    for(var i=0; i<arr.length; i++) {
        if (arr[i] == obj) return true;
    }
}
function ClosePopUp()
{
  $.modal.impl.close();
}
function VirtualMoney() {
    var htmlString;
    var htmlArray = new Array();
    htmlArray.push('<div id="popUpHeader">Virtual Money</div><div id="virtualMoney"><div id="popUpContent">');
    htmlArray.push('<span id="spnVirtualMoney" class="validator" style="display:none"></span>');
    htmlArray.push('<div class="subHeader"></div>');
    htmlArray.push('<div class="modalPopUpVirtualMoneyContent">');
    htmlArray.push('<div class="floatLeft"><div class="floatLeft paddingRight">Money</div>');
    htmlArray.push('<div class="floatLeft"><input type="text" name="txtVirtualMoney"  id="txtVirtualMoney" /></div></div>');
    htmlArray.push('<div class="floatLeft clearPosition"><input type="checkbox" name="OptionApproval" id="chkClearPosition" />');
    htmlArray.push('Clear position</div>');
    htmlArray.push('<div class="paddingTop floatRight"><a class="cancelButton" align="right" href="' + "javascript:ClosePopUp();" + '"></a></div><div class="paddingTop floatRight submitCancelBtnSeperator"></div><div class="paddingTop floatRight"><a class="submitButton" align="center" href="' + "javascript:PostPopUpData('VirtualMoney');" + '"></a></div>');
    htmlArray.push('</div></div></div>');
    htmlString = htmlArray.join('');
    this.GetHTML = function() {
        return htmlString;
    };
    this.PostData = function() {
        var clearPosition;
        if (document.getElementById('chkClearPosition').checked) {
            clearPosition = true;
        }
        else {
            clearPosition = false;
        }
        var virtualMoneyInfo = new Object();
        virtualMoneyInfo.Money = document.getElementById('txtVirtualMoney').value;
        virtualMoneyInfo.ClearPosition = clearPosition;
        InitAjaxRequest(virtualMoneyInfo, 'VirtualMoney');
    }
}
function InviteFriends() {
     var htmlString;
     var htmlArray = new Array();
     htmlArray.push('<div class="inviteFriendsMainDv">');
     htmlArray.push('<div id="popUpHeader">Invite Friends</div>');
     htmlArray.push('<div id="inviteFriends">');
     htmlArray.push('<div id="popUpContent">');
     htmlArray.push('<div class="subHeader">Friends Emails</div>');
     htmlArray.push('<div class="modalPopUpContent">');
     htmlArray.push('<span id="spnInviteFriend" class="InviteFriendsSpan" style="visibility:hidden"></span>');
     htmlArray.push('<div class="dvFullFloatLeft">');
     htmlArray.push('<div class="dvHalfFloatLeft">');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend1" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv">');
     htmlArray.push('<span class="emailLabels">Email 1 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend1" id="txtInviteFriend1" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend2" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv">');
     htmlArray.push('<span class="emailLabels">Email 2 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend2" id="txtInviteFriend2" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend3" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv">');
     htmlArray.push('<span class="emailLabels">Email 3 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend3" id="txtInviteFriend3" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend4" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv">');
     htmlArray.push('<span class="emailLabels">Email 4 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend4" id="txtInviteFriend4" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend5" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv">');
     htmlArray.push('<span class="emailLabels">Email 5 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend5" id="txtInviteFriend5" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvHalfFloatLeft">');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend6" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv" align="center">');
     htmlArray.push('<span class="emailLabels">Email 6 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend6" id="txtInviteFriend6" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend7" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv" align="center">');
     htmlArray.push('<span class="emailLabels">Email 7 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend7" id="txtInviteFriend7" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend8" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv" align="center">');
     htmlArray.push('<span class="emailLabels">Email 8 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend8" id="txtInviteFriend8" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend9" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv" align="center">');
     htmlArray.push('<span class="emailLabels">Email 9 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend9" id="txtInviteFriend9" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvValidator"><span id="spnInviteFriend10" class="InviteFriendsSpan" style="visible: hidden"></span></div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div class="inviteFriendsLabelDv" align="left">');
     htmlArray.push('<span class="emailLabels">Email 10 :</span></div>');
     htmlArray.push('<div class="inviteFriendsTextBoxDv">');
     htmlArray.push('<input type="text" name="txtInviteFriend10" id="txtInviteFriend10" /></div>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="dvFullFloatLeft paddingTop">');
     htmlArray.push('<div style="float: left; width: 15%">Message :</div>');
     htmlArray.push('<div style="float: left; width: 85%;">');
     htmlArray.push('<textarea name="txtInviteFriend11" id="txtInviteFriend11" cols="38" rows="5"></textarea>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('<div class="floatRight paddingTop inviteFriendSubmitPaddingRight">');
     htmlArray.push('<div class="floatLeft paddingRight">');
     htmlArray.push('<a class="submitButton" href="' + "javascript:PostPopUpData('InviteFriends');" + '"></a>');
     htmlArray.push('</div>');
     htmlArray.push('<div style="float:Left">');
     htmlArray.push('<a class="cancelButton" href="' + "javascript:ClosePopUp();" + '"></a>');
     htmlArray.push('</div>');                 
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlArray.push('</div>');
     htmlString = htmlArray.join('');
     this.GetHTML = function() {
        return htmlString;
     };
     this.PostData = function() {
        var friendsList = new Array();
        for (var i = 1; i <= 10; i++) {
            //if (document.getElementById('txtInviteFriend' + i + '').value != '') {
                friendsList.push(document.getElementById('txtInviteFriend' + i + '').value);
            //}
        }
        var inviteFriendsInfo = new Object();
        inviteFriendsInfo.FriendList = friendsList;
        if (document.getElementById('txtInviteFriend11').value != '') {
            inviteFriendsInfo.Message = document.getElementById('txtInviteFriend11').value;
        }
        else {
            inviteFriendsInfo.Message = '';
        }
        InitAjaxRequest(inviteFriendsInfo, 'InviteFriends');
    }
}
function SetCheckboxStatus(ind) {
    if (document.getElementById('chkLevel_0').checked) {
        for (var j in approvalLevel) {
            if (j != "Level_0") {
                document.getElementById('chk' + j + '').disabled = true;
            }
        }
    }
    else {
        for (var j in approvalLevel) {
            document.getElementById('chk' + j + '').disabled = false;
        }

        if (!document.getElementsByName('OptionApproval')[ind].checked) {
            for (var i = ind; i <= 6; i++) {
                document.getElementsByName('OptionApproval')[i].checked = false;
            }
        }
        else {
            for (var i = 1; i <= ind; i++) {
                document.getElementsByName('OptionApproval')[i].checked = true;
            }
        }
    }
}
function ShowSSN(){
     var htmlString = document.getElementById('ctl00_ContentPlaceHolder1_hfSsnDetails').value;
    this.GetHTML = function() {
        return htmlString;
    };
}
function RejectedOrder() {
    var htmlString = document.getElementById('ctl00_ContentPlaceHolder1_hfRejectedOrderDetails').value;
    this.GetHTML = function() {
        return htmlString;
    };
    this.PostData = function() {
        var orderInfo = new Object();
        var rejOrderDetails = document.getElementById('hfRejectedOrderTypeOrderId').value.split('&');
        orderInfo.OrderID = rejOrderDetails[1];
        orderInfo.AssetType = rejOrderDetails[0];
        InitAjaxRequest(orderInfo, 'RejectedOrder');
    }
}
function UpdateAcknowledgedStatus(){
    __modalPopUp = ModalPopUpProvider('RejectedOrder');
    __modalPopUp.PostData();
    __modalPopUp = null;
}
function GetHandlerPath(handlerName) {
    var handlerUrl = window.location.href;
    handlerUrl = ((handlerUrl||'')+'').match(/^https:\/\/[^/]+/);
    if(handlerUrl[0].indexOf('localhost') > 0)
        handlerUrl = handlerUrl + "/Wbtp2008";
    handlerUrl = handlerUrl + "/Handlers/" + handlerName + "Handler.ashx?t=" + Math.random();
    return handlerUrl;
}
//end region
//Enums for FeedService methods calling from JS
__QuoteMethods = {"QuotesWithDesc":"RQD","QuotesWithOutDesc":"RQ","CheckIsValidSymbol":"CVS"};
function GetSSN(){
 $.ajax({
        type: "GET",
        url: "AccountApproval.aspx?t=" + Math.random(),
        data: { PopUp: "SSN" },
        success: function (msg) {
            if (msg != null) {
               document.getElementById('ctl00_ContentPlaceHolder1_hfSsnDetails').value = msg;
               ShowPopUp("ShowSSN");
            }
        }
     });
}


