﻿ function doEnter(btnid)
{
   try{
        var btn = document.getElementById(btnid);
      }catch(ex)
      {
      }
        if(window.Event)
        {
            window.captureEvents(Event.KEYPRESS)
        }
        document.onkeypress = keyPressed;
        function keyPressed(e)
        {
            var n;
            (window.Event) ? n=e.which : n=event.keyCode;
            if(n==13)
            {
                btn.click();
                return false;
            }
        }
}


 function forceChar(id)
        {
            var regExp=/^[A-Za-z0-9._-]/;
            var rg= /^[A-Za-z]/;
            var char1=id.value.substr((id.value.length-1),(id.value.length));
            if(rg.test(char1))
             {
               id.value=id.value.replace(/^\s+$/,"");
             }
            else
             {
                id.value=id.value.substr(0,id.value.length-1);
             }
            if(rg.test(id.value.charAt(0)))
            {
            }
            else
            {
                id.value=id.value.substr(0,id.value.length-1);
            }       
    }
    
function forceNumber(id)
{

    var regExp=/^[0-9]/;
    var char1=id.value.substr((id.value.length-1),(id.value.length));
   
    if(regExp.test(char1))
    {
        id.value=id.value.replace(/^\s+$/,"");
       
    }
    else
    {
        id.value=id.value.substr(0,id.value.length-1);
       
    }
}


 
    function disable(id)
    {
       var a = "ctl00_ContentPlaceHolder1_PopCalendar2_Control";
       document.getElementById(a).disabled="false";
    }
    var oldgridSelectedColor;

function setMouseOverColor(element)
{
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor="#DBAE31";
    element.style.cursor='hand';
    element.style.textDecoration='underline';
}

function setMouseOutColor(element)
{
    element.style.backgroundColor=oldgridSelectedColor;
    element.style.textDecoration='none';
}  
        
        
function AjaxForInsertValueJS(CurrencyName,Type,CurrencyAmt,Qty)
{
    //alert(CurrencyName+","+Type+","+CurrencyAmt+","+Qty);return false;
    $.ajax({
     type: "GET",
            url: "saveusertrade.aspx",
            data: "Currencyname="+urlencode(CurrencyName)+"&Type="+Type+"&Amt="+CurrencyAmt+"&Qty="+Qty,
            beforeSend:function(){
            },
            success: function(msg)
            {
               var av = new String();
               av=msg;
              if(av.indexOf("true")>=0)
               {
                   if(msg!="")
                   {
                   var a = new Date();
                   
                   var day_name=new Array(7);
                       day_name[0]= "Sun";
                       day_name[1]= "Mon";
                       day_name[2]= "Tue";
                       day_name[3]= "Wed";
                       day_name[4]= "Thu";
                       day_name[5]= "Fri";
                       day_name[6]= "Sat";
                       
                   var month_name = new Array(12);
                       month_name[0]  = "Jan";
                       month_name[1]  = "Feb";
                       month_name[2]  = "Mar";
                       month_name[3]  = "Apr";
                       month_name[4]  = "May";
                       month_name[5]  = "Jun";
                       month_name[6]  = "Jul";
                       month_name[7]  = "Aug";
                       month_name[8]  = "Sep";
                       month_name[9]  = "Oct";
                       month_name[10] = "Nov";
                       month_name[11] = "Dec";
                   
                      alert("Trade Confirmation\n\nOn "+day_name[a.getDay()]+" "+a.getDate()+"-"+ month_name[a.getMonth()]+"-"+a.getFullYear()+" at "+a.getHours()+":"+a.getMinutes()+":"+a.getSeconds()+"\nYou "+Type+" "+Qty+"k "+CurrencyName+" @"+CurrencyAmt);
                      document.location = "default4.aspx";
                   }
               }
               else if(av.indexOf("false")>=0)
               {
                    alert("Buy request failed. Please try again.");
               }
            }
            });
        }
function AjaxForInsertValue(CurrencyName,Type,CurrencyAmt,Qty)
{
    alert(CurrencyName+","+Type+","+CurrencyAmt+","+Qty);return false;
    $.ajax({
     type: "GET",
            url: "saveusertrade.aspx",
            data: "Currencyname="+urlencode(CurrencyName)+"&Type="+Type+"&Amt="+CurrencyAmt+"&Qty="+Qty,
            beforeSend:function(){
          
            //$("div#tradeconf").show();
            //$("div#tradeconfirmation").html("<img src='images/loader_wait.gif'/>");
            },
            success: function(msg)
            {
               var av = new String();
               av=msg;
              if(av.indexOf("Hello")>=0)
               {
                   if(msg!="")
                   {
                   var a = new Date();
                   
                   var day_name=new Array(7);
                       day_name[0]= "Sun";
                       day_name[1]= "Mon";
                       day_name[2]= "Tue";
                       day_name[3]= "Wed";
                       day_name[4]= "Thu";
                       day_name[5]= "Fri";
                       day_name[6]= "Sat";
                       
                   var month_name = new Array(12);
                       month_name[0]  = "Jan";
                       month_name[1]  = "Feb";
                       month_name[2]  = "Mar";
                       month_name[3]  = "Apr";
                       month_name[4]  = "May";
                       month_name[5]  = "Jun";
                       month_name[6]  = "Jul";
                       month_name[7]  = "Aug";
                       month_name[8]  = "Sep";
                       month_name[9]  = "Oct";
                       month_name[10] = "Nov";
                       month_name[11] = "Dec";
                   //$("div#tradeconf").show();
                   //$("div#tradeconfirmation").html("<table><tr><td style='font-size:14; color:#DBAE31'>Trade Confirmation</td></tr><tr><td>&nbsp;</td></tr><tr><td>On "+day_name[a.getDay()]+" "+a.getDate()+"-"+month_name[a.getMonth()]+"-"+a.getFullYear()+" at "+a.getHours()+":"+a.getMinutes()+":"+a.getSeconds()+"</td></tr><tr><td>You "+Type+" "+Qty+"k "+CurrencyName+" @"+CurrencyAmt+"</td></tr></table>");
                      alert("Trade Confirmation\n\nOn "+day_name[a.getDay()]+" "+a.getDate()+"-"+ month_name[a.getMonth()]+"-"+a.getFullYear()+" at "+a.getHours()+":"+a.getMinutes()+":"+a.getSeconds()+"\nYou "+Type+" "+Qty+"k "+CurrencyName+" @"+CurrencyAmt);
                   }
               }
               else if(av.indexOf("You have no sufficient money")>=0)
               {
                    $("div#tradeconf").hide();
                   alert("Sorry, Insufficient balance");
               }
               else
               {
                    $("div#tradeconf").hide();
                    alert("You can not trade today");                
               }
              
            }
            });
        }
        
        function popup(TicketNumber,MoveOrLimit,Amount,CurrencyName,BuyorSell,BuySellAmt,Profit,bscheck)
        {
            if(document.getElementById("div2").style.display == "block")
            {
                alert("Please first Exit the Buy/Sell window");
                return false;
            }
            else
            {
                document.getElementById("bv").style.display = "block";
//            try
//            {
//                document.getElementById("message").innerHTML="";
//            }
//            catch(e)
//            {
//            
//            }
            
            
            //saturdayD
          //  document.getElementById("ifram").src="newpopup.aspx?Ticket="+TicketNumber+"&MoveLimit="+MoveOrLimit+"&Amount="+Amount+"&CurName="+CurrencyName+"&BuySell="+BuyorSell+"&BuySellAmt="+BuySellAmt;
                document.getElementById("ifram").src="newpopup.aspx?Ticket="+TicketNumber+"&MoveLimit="+MoveOrLimit+"&Amount="+Amount+"&CurName="+CurrencyName+"&BuySell="+BuyorSell+"&BuySellAmt="+BuySellAmt+"&Profit="+Profit+"&bscheck="+bscheck;
                document.getElementById("ifram").style.height= "130px";
            }
        }
        
        function popupForLimitStopinAdim(TicketNumber,MoveOrLimit,Amount,CurrencyName,BuyorSell,BuySellAmt, Userid)
        {
            //alert(Amount);
            document.getElementById("bv").style.display = "block";
            try
            {
            document.getElementById("message").innerHTML="";
            }
            catch(e)
            {
            
            }
            document.getElementById("ifram").src="newpopup.aspx?Ticket="+TicketNumber+"&MoveLimit="+MoveOrLimit+"&Amount="+Amount+"&CurName="+CurrencyName+"&BuySell="+BuyorSell+"&BuySellAmt="+BuySellAmt+"&userid="+Userid;
        }
        
        function deleteTrade(id,qty,pl,closeBuySellAmt,ClosedStatus,rollover,commission)
        {
            $.ajax(
            {
                type:"GET",
                url:"DeleteTrade.aspx",
                data:"TicketId="+id+"&Qty="+qty+"&pl="+pl+"&closeBuySellAmt="+closeBuySellAmt+"&ClosedStatus="+ClosedStatus+"&rollover="+rollover+"&commission="+commission,
                beforeSend:function(){
               
            $("div#closeTradeConfirmation").show();
            $("div#CloseTrade").html("<img src='images/loader_wait.gif'/>");
            },
                success:function (msg)
                {
                   if(msg=="never")
                   {
                    $("div#closeTradeConfirmation").hide();
                    alert("you can not trade today due to market closed");
                   }
                   else
                   {
                   $("div#closeTradeConfirmation").show();
                   $("div#CloseTrade").html("<table><tr><td style='font-size:14; color:#DBAE31'>Trade Closed confirmation</td></tr><tr><td>&nbsp;</td></tr><tr><td>Your trade closed @ "+closeBuySellAmt+"</td></tr></table>");
                   }
                   // alert("Position closed successfully");
                }
            }
            )
        }
        
        function closeTrade(id,qty,pl,closeBuySellAmt,ClosedStatus,rollover,sts,commission,feedchkcount)
        {
            if(parseInt(feedchkcount)<60)
            {
                if(sts=="True")
                {
                     alert('Your account has been suspended.');
                }
                else
                {            
                document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_ID").value=id;
                document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_Qty").value=qty;
                document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_PL").value=pl;
                document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closeBuySellAmt").value=closeBuySellAmt;
                document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closedStatus").value=ClosedStatus;
                document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_rollover").value=rollover;
                document.getElementById("ctl00_ContentPlaceHolder1_hdnCommission").value=commission;
                document.getElementById("divTradeCloseAlert").style.display="block";
                }
                //var a = confirm("Are you sure? You want to close position");
                //if(a)
               // {
                          //  deleteTrade(id,qty,pl,closeBuySellAmt,ClosedStatus,rollover);
                //}
                //else
                //return false;
            }
            else
            {
                alert('Trading closed');
            }
                
        }
        
      function urlencode(str) 
        {
            str = escape(str);
            str = str.replace('+', '%2B');
            str = str.replace('%20', '+');
            str = str.replace('*', '%2A');
            str = str.replace('/', '%2F');
            str = str.replace('@', '%40');
            return str;
        }

        function urldecode(str) 
        {
            str = str.replace('+', ' ');
            str = unescape(str);
            return str;
        }
        
    function BuyCurr()
    {
        try
        {
            flagTransWindow = 0;
            var objusm= document.getElementById("ctl00_ContentPlaceHolder1_DataList1_ctl00_lblUsbalMargin");
            var usm= parseFloat(objusm.innerHTML);
            var a = document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value;
            var __Currenci = document.getElementById("drpCurrency");
            for(j=0;j<__Currenci.length;j++)
            {
                if(__Currenci[j].selected==true)
                {
                    a = __Currenci[j].value;
                }
            }
                
            a = replaceOriCurrencyName(a);
           
            var currencyValue = document.getElementById("aa").innerHTML;
            
            var Quantity = document.getElementById("ctl00_ContentPlaceHolder1_Amount");
            var Qty
            for(k=0;k<Quantity.length;k++)
            {
                if(Quantity[k].selected==true)
                    Qty=Quantity[k].value;
            }
                
            //document.getElementById("divSellBtn123").style.display='none';
            var q = Qty * 5;
            q = q + ((q * 20) /100);
            if(usm < q)
            {
                alert("Insufficient margin");
                return false;
            }
              
            if( currencyValue != "")
            {
                AjaxForInsertValue(a,"Buy",currencyValue,Qty);
                document.getElementById("div2").style.display ='none';
            }  
            else
            {
                alert('Please, Try Again ');       
            }
        }
        catch(ex)
        {
        }
        
    }
        
        function BuyCurrJS(){
            try{
                //alert("BuyCurrJS");
                objBuySellWindow = document.getElementById("divBuySellWindow");
                objBuySellWindow.style.display = "none";
                
                var useablemargin = parseFloat(arrGlobalPageVars["useablemargin"]);
                var objBuyCurrency = document.getElementById("Commod");
                var strBuyCurrencyName = replaceOriCurrencyName(objBuyCurrency.innerHTML);
                var objCurrencyValue = document.getElementById("divJSBSRate");
                var currencyValue = objCurrencyValue.innerHTML;
                var Quantity = document.getElementById("Amount");
                var Qty;
                for(k=0;k<Quantity.length;k++){
                    if(Quantity[k].selected==true)
                        Qty=Quantity[k].value;
                }
                
                var q = Qty * 5;
                q = q + ((q * 20) /100);
                if(useablemargin < q){
                    alert("Insufficient margin");
                    return false;
                }
                AjaxForInsertValueJS(strBuyCurrencyName,"Buy",currencyValue,Qty);
            }
            catch(err){
                alert("Error - BuyCurrJS : " + err.description);
            }
            return false;
        }
        
        function SellCurrJS(){
            try{
                //alert("SellCurrJS");return false;
                objBuySellWindow = document.getElementById("divBuySellWindow");
                objBuySellWindow.style.display = "none";
                
                var useablemargin = parseFloat(arrGlobalPageVars["useablemargin"]);
                var objBuyCurrency = document.getElementById("Commod");
                var strBuyCurrencyName = replaceOriCurrencyName(objBuyCurrency.innerHTML);
                var objCurrencyValue = document.getElementById("divJSBSRate");
                var currencyValue = objCurrencyValue.innerHTML;
                var Quantity = document.getElementById("Amount");
                var Qty;
                for(k=0;k<Quantity.length;k++){
                    if(Quantity[k].selected==true)
                        Qty=Quantity[k].value;
                }
                //alert(Qty);return false;
                
                var q = Qty * 5;
                q = q + ((q * 20) /100);
                if(useablemargin < q){
                    alert("Insufficient margin");
                    return false;
                }
                //alert(strBuyCurrencyName+","+currencyValue+","+Qty);return false;
                AjaxForInsertValueJS(strBuyCurrencyName,"Sell",currencyValue,Qty);
            }
            catch(err){
                alert("Error - SellCurrJS : " + err.description);
            }
            return false;
        }
        
        
    function SellCurr(usm)
    {
        try
        {
            flagTransWindow = 0;
            var objusm= document.getElementById("ctl00_ContentPlaceHolder1_DataList1_ctl00_lblUsbalMargin");
            var usm= parseFloat(objusm.innerHTML);
            var a = document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value;
            var __Currenci = document.getElementById("drpCurrency");
            for(j=0;j<__Currenci.length;j++)
            {
                if(__Currenci[j].selected==true)
                {
                    a = __Currenci[j].value;
                }
            }
                
            a = replaceOriCurrencyName(a);
           
            var currencyValue = document.getElementById("aa").innerHTML;
            
            var Quantity = document.getElementById("ctl00_ContentPlaceHolder1_Amount");
            var Qty
            for(k=0;k<Quantity.length;k++)
            {
                if(Quantity[k].selected==true)
                    Qty=Quantity[k].value;
            }
                
            var q = Qty * 5;
            q = q + ((q * 20) /100);
            if(usm < q)
            {
                alert("Insufficient margin");
                return false;
            }
              
            if( currencyValue != "")
            {
                AjaxForInsertValue(a,"Sell",currencyValue,Qty);
                document.getElementById("div2").style.display ='none';
            }  
            else
            {
                alert('Please, Try Again ');       
            }
        }
        catch(ex)
        {
        }
        
    }
    var flagTransWindow = 0;
    var flgRefresh = 0;
        
    function abcd(id,type,sts,feedchkcount)
    {
   // document.getElementById("myvalue").innerHTML=rate;    
        try
        {
            if(document.getElementById("bv").style.display == "block")
            {
                alert("Please first close the Limit/Stop window");
                return false;
            }
            if(flagTransWindow)
            {
                alert("Please first Exit the Buy/Sell window to select another currency");
                return false;
            }
            else
            {
                flagTransWindow= 1;
            }
            
            if (document.getElementById("div2").style.display == "none")
            { 
                if(parseInt(feedchkcount)<60)
                {
                    if(sts=="true")
                    {
                        alert('Your account has been suspended.');
                    }
                    else
                    {  
                        document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value=id;              
                        var a = id;
                        a = replaceCurrencyName(a);
                        var Array_currency =document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value;
                        var currency = Array_currency.split(',');
                        var drpcurrency = document.getElementById("drpCurrency");
                      
                        var newName = replaceCurrencyName(id);
                        document.getElementById("ctl00_ContentPlaceHolder1_lblcurrency").innerHTML =newName;
                        for(i=0;i<currency.length;i++)
                        {
                            var newName = replaceCurrencyName(currency[i]);
                            // alert(newName);  
                            drpcurrency.options[i] = new Option(newName, newName);
                        }
                        selectDrpValue(a);
//                        if(type=="sell")
//                            document.getElementById("sell").checked=true;
//                        else
//                            document.getElementById("buy").checked=true;
            
                            flgRefresh++;  
                            sendRequest(id,1,"aa",type, flgRefresh);
                            //setTimeout("ShowWindow()", 2000);
                            document.getElementById("div2").style.display="Block";
                            document.getElementById("divSellBtn123").style.display="none";
                            document.getElementById("divSellBtn321").style.display="none";    
                           
                     } 
                 }
                 else
                 {
                    alert('Trading closed');
                 }                  
            }
            else
            {
               alert("Please first Exit the Buy/Sell window to select another currency");
            }
        }
        catch(e)
        {
        }
            
}   
    
    var objSetPriceTimeOut;
    function closeJSWindow(id)
    {
        if(objSetPriceTimeOut != null){
            clearTimeout(objSetPriceTimeOut);
        }
        objElement = document.getElementById(id);
        objElement.style.display ="none";
    }
    function funSetPrice(strCurrencyVal){
        objBuySellWindow = document.getElementById("divBuySellWindow");
        if(objBuySellWindow.style.display == "block"){
            document.getElementById("divJSBSRate").innerHTML = document.getElementById(strCurrencyVal).innerHTML;
            if(objSetPriceTimeOut != null){
                clearTimeout(objSetPriceTimeOut);
            }
            objSetPriceTimeOut = setTimeout("funSetPrice('"+strCurrencyVal+"')",3000);
        }
        else{
            if(objSetPriceTimeOut != null){
                clearTimeout(objSetPriceTimeOut);
            }
        }
    }
    function funLimitStopWindow(id,type,sts,feedchkcount)
    {
        alert(id+","+type+","+sts+","+feedchkcount);
        return false;
        objLimitStopWindow = document.getElementById("divBuySellWindow");
        if(objLimitStopWindow.style.display == "block"){
            alert("Limit/Stop window already Open");
            return false;
        }
        try{
            strCurrency = "GridView1_ctl" + id + "_lbl";
            objCurrency = document.getElementById(strCurrency);
            if(objCurrency != null){
                strCurrencyF = objCurrency.innerHTML;
            }
        }catch(err){
            alert(",Error - funLimitStopWindow : "+err.description);
        }
        strLimitStopWindowContent = '';
        strLimitStopWindowContent += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="heading_td2"><table style="background-color: #2F3130" width="100%" cellpadding="0" cellspacing="0"><tr><td class="heading_td2">Buy/Sell</td><td class="heading_td2" align="right" style="padding-right: 5px"><div id="divhidebuysell" style="float: right; padding-right: 5px"><a href="#" onclick="javascript:hidediv(\'divbuysell\',\'divshowbuysell\',\'divhidebuysell\');return false;"><img border="0" src="images/minus.gif" /></a></div><div id="divshowbuysell" style="display: none; float: right; padding-right: 5px">';
        strLimitStopWindowContent += '<a href="#" onclick="javascript:showdiv(\'divbuysell\',\'divshowbuysell\',\'divhidebuysell\');return false;"><img border="0" src="images/plus.gif" /></a></div></td></tr></table></td></tr><tr><td><div id="divbuysell"><table style="background-color: #2F3130" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="135px" valign="top" align="center"><input type="hidden" name="hdnCurrency" /><input type="hidden" name="HiddenField2" />';
        strLimitStopWindowContent += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="25px" class="style1"><b>Currency: </b></td><td id="Commod">' + strCurrencyF;
        strLimitStopWindowContent += '</td></tr><tr><td colspan="2"></td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td height="28px" class="style1"><b>Rate: </b></td><td><div id="divJSBSRate1"></div></td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td valign="middle" height="35px" class="style1"><b>Amt.(k): </b></td><td style="padding-right: 15px;">';
        strLimitStopWindowContent += '<select name="Amount" id="Amount">';
        switch(parseInt(arrGlobalPageVars["AccountType"])){
            case 1:
                accType = 100;
                break;
            case 2:
                accType = 10;
                break;
            case 3:
                accType = 1;
                break;
        }
        for(loopVal = 1; loopVal <= 10; loopVal++){
        strLimitStopWindowContent += '<option value="' + (loopVal*accType) + '">' + (loopVal*accType) + '</option>';
        }
        strLimitStopWindowContent += '</select>';
        strLimitStopWindowContent += '</td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td height="28px" class="style1" style="padding-top: 8px;">';
        if(type == "Buy"){
            strLimitStopWindowContent += '<div id="divSellBtn123" style="display: block;"><a id="b" onclick="return BuyCurrJS();" href="#"><img alt="Buy" src="images/buy.gif" border="0" /></a></div>';
        }
        else{
            strLimitStopWindowContent += '<div id="divSellBtn321" style="display: block;"><a id="s" onclick="return SellCurrJS();" href="#"><img alt="Sell" src="images/sell.gif" border="0" /></a></div>';
        }
        strLimitStopWindowContent += '</td><td style="padding-top: 8px;"><a href="#" onclick="javascript:closeJSWindow(\'divBuySellWindow\');return false;"><img src="images/exit.gif" border="0" /></a></td></tr></table></td></tr></table></div></td></tr></table></td></tr></table>';
        strLimitStopWindowContent.innerHTML = strLimitStopWindowContent;
        strLimitStopWindowContent.style.display ="block";
        alert("set values" + strCurrency+type);
        return false; 
        funSetPrice(strCurrency+type);
        return false; 
    }
    function funBuySellWindow(id,type,sts,feedchkcount)
    {
        //alert(id+","+type+","+sts+","+feedchkcount);
        objBuySellWindow = document.getElementById("divBuySellWindow");
        if(objBuySellWindow.style.display == "block"){
            alert("Buy/Sell window already Open");
            return false;
        }
        try{
            strCurrency = "GridView1_ctl" + id + "_lbl";
            objCurrency = document.getElementById(strCurrency);
            if(objCurrency != null){
                strCurrencyF = objCurrency.innerHTML;
            }
        }catch(e){
            alert(strCurrency+",Error : "+e.description);
        }
        strBuySellWindowContent = '';
        strBuySellWindowContent += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="heading_td2"><table style="background-color: #2F3130" width="100%" cellpadding="0" cellspacing="0"><tr><td class="heading_td2">Buy/Sell</td><td class="heading_td2" align="right" style="padding-right: 5px"><div id="divhidebuysell" style="float: right; padding-right: 5px"><a href="#" onclick="javascript:hidediv(\'divbuysell\',\'divshowbuysell\',\'divhidebuysell\');return false;"><img border="0" src="images/minus.gif" /></a></div><div id="divshowbuysell" style="display: none; float: right; padding-right: 5px">';
        strBuySellWindowContent += '<a href="#" onclick="javascript:showdiv(\'divbuysell\',\'divshowbuysell\',\'divhidebuysell\');return false;"><img border="0" src="images/plus.gif" /></a></div></td></tr></table></td></tr><tr><td><div id="divbuysell"><table style="background-color: #2F3130" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="135px" valign="top" align="center"><input type="hidden" name="hdnCurrency" /><input type="hidden" name="HiddenField2" />';
        strBuySellWindowContent += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="25px" class="style1"><b>Currency: </b></td><td id="Commod">' + strCurrencyF;
        strBuySellWindowContent += '</td></tr><tr><td colspan="2"></td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td height="28px" class="style1"><b>Rate: </b></td><td><div id="divJSBSRate"></div></td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td valign="middle" height="35px" class="style1"><b>Amt.(k): </b></td><td style="padding-right: 15px;">';
        strBuySellWindowContent += '<select name="Amount" id="Amount">';
        switch(parseInt(arrGlobalPageVars["AccountType"])){
            case 1:
                accType = 100;
                break;
            case 2:
                accType = 10;
                break;
            case 3:
                accType = 1;
                break;
        }
        
        for(loopVal = 1; loopVal <= 10; loopVal++){
        strBuySellWindowContent += '<option value="' + (loopVal*accType) + '">' + (loopVal*accType) + '</option>';
        }
        strBuySellWindowContent += '</select>';
        strBuySellWindowContent += '</td></tr><tr><td colspan="2" height="1px" style="background-color: #888787"></td></tr><tr><td height="28px" class="style1" style="padding-top: 8px;">';
        if(type == "Buy"){
            strBuySellWindowContent += '<div id="divSellBtn123" style="display: block;"><a id="b" onclick="return BuyCurrJS();" href="#"><img alt="Buy" src="images/buy.gif" border="0" /></a></div>';
        }
        else{
            strBuySellWindowContent += '<div id="divSellBtn321" style="display: block;"><a id="s" onclick="return SellCurrJS();" href="#"><img alt="Sell" src="images/sell.gif" border="0" /></a></div>';
        }
        strBuySellWindowContent += '</td><td style="padding-top: 8px;"><a href="#" onclick="javascript:closeJSWindow(\'divBuySellWindow\');return false;"><img src="images/exit.gif" border="0" /></a></td></tr></table></td></tr></table></div></td></tr></table></td></tr></table>';
        /*                                                       
            <asp:DropDownList CssClass="drpTradeamt" ID="Amount" runat="server"></asp:DropDownList>
        */
        objBuySellWindow.innerHTML = strBuySellWindowContent;
        objBuySellWindow.style.display ="block";
        //alert(strCurrency+type);
        funSetPrice(strCurrency+type);
        return false; 
        
        try
        {
            if(document.getElementById("bv").style.display == "block")
            {
                alert("Please first close the Limit/Stop window");
                return false;
            }
            if(flagTransWindow)
            {
                alert("Please first Exit the Buy/Sell window to select another currency");
                return false;
            }
            else
            {
                flagTransWindow= 1;
            }
            
            if (document.getElementById("div2").style.display == "none")
            { 
                if(parseInt(feedchkcount)<60)
                {
                    if(sts=="true")
                    {
                        alert('Your account has been suspended.');
                    }
                    else
                    {  
                        document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value=id;              
                        var a = id;
                        a = replaceCurrencyName(a);
                        var Array_currency =document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value;
                        var currency = Array_currency.split(',');
                        var drpcurrency = document.getElementById("drpCurrency");
                      
                        var newName = replaceCurrencyName(id);
                        document.getElementById("ctl00_ContentPlaceHolder1_lblcurrency").innerHTML =newName;
                        for(i=0;i<currency.length;i++)
                        {
                            var newName = replaceCurrencyName(currency[i]);
                            // alert(newName);  
                            drpcurrency.options[i] = new Option(newName, newName);
                        }
                        selectDrpValue(a);
//                        if(type=="sell")
//                            document.getElementById("sell").checked=true;
//                        else
//                            document.getElementById("buy").checked=true;
            
                            flgRefresh++;  
                            sendRequest(id,1,"aa",type, flgRefresh);
                            //setTimeout("ShowWindow()", 2000);
                            document.getElementById("div2").style.display="Block";
                            document.getElementById("divSellBtn123").style.display="none";
                            document.getElementById("divSellBtn321").style.display="none";    
                           
                     } 
                 }
                 else
                 {
                    alert('Trading closed');
                 }                  
            }
            else
            {
               alert("Please first Exit the Buy/Sell window to select another currency");
            }
        }
        catch(e)
        {
        }
            
} 

    function ShowWindow()
    {
        document.getElementById("div2").style.display="Block";
    }
        
        
         function abcd1(id,type,sts,feedchkcount,value)
            {
      
          alert(value); 
          if(parseInt(feedchkcount)<60)
          {
                if(sts=="true")
                {
                    alert('Your account has been suspended.');
                }
                else
                {  
                  document.getElementById("hdnCurrency").value=id;              
                  
                  var a = id;
                  a = replaceCurrencyName(a);
               //   alert(a);
                  var Array_currency =document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value;
                  var currency = Array_currency.split(',');
                  var drpcurrency = document.getElementById("drpCurrency");
                  
                   var newName = replaceCurrencyName(id);
                   document.getElementById("ctl00_ContentPlaceHolder1_lblcurrency").innerHTML =newName;
                  for(i=0;i<currency.length;i++)
                   {
                        var newName = replaceCurrencyName(currency[i]);
                       // alert(newName);  
                        drpcurrency.options[i] = new Option(newName, newName);
                   }
                  selectDrpValue(a);
                  
                  if(type=="sell")
                     document.getElementById("sell").checked=true;
                  else
                    document.getElementById("buy").checked=true;
                    document.getElementById("div2").style.display="Block";
                    document.getElementById("divSellBtn123").style.display="none";  
                    requestme(id)
                    sendRequest(id,1,"aa",type, flgRefresh);
                    
                } 
             }
             else
             {
                alert('Trading closed');
             }                  
                
        }         
        
         function requestme(id)
        {
            id = replaceOriCurrencyName(id);
            document.getElementById("aa").innerHTML="";
            document.getElementById("divSellBtn123").style.display="none";
            if(document.getElementById("sell").checked)
            {
                 sendRequest(id,1,"aa","Sell", flgRefresh);
            }
            else
            {
                 sendRequest(id,1,"aa","Buy", flgRefresh);
            }
           
            adjustwaitdiv();
            setTimeout("divwaitclose();", 10000);
              document.getElementById("ctl00_ContentPlaceHolder1_lblcurrency").style.visibility=true;   
            
        }
        
        
          
        function requestOnSelect(id)
        {
            id = replaceOriCurrencyName(id);
            document.getElementById("aa").innerHTML="";
            document.getElementById("divSellBtn123").style.display="none";
            if(document.getElementById("sell").checked)
            {
                 sendRequest(id,1,"aa","Sell", flgRefresh);
            }
            else
            {
                 sendRequest(id,1,"aa","Buy", flgRefresh);
            }
           
            adjustwaitdiv();
            setTimeout("divwaitclose();", 10000);
        }
        
        function replaceCurrencyName(CurrencyName)
        {
           var curName;
           switch(CurrencyName)
           {
                case "EURODOLLAR":
                    curName="EUR/USD";
                    break;
                case "AUDUSD":
                    curName="AUD/USD";
                    break;
                case "JAPANESEYEN":
                        curName="USD/JPY";
                        break;
                case "POUNDSTERLING":
                        curName="GBP/USD";
                        break;
                case "CANADIANDOLLAR":
                        curName="USD/CAD";
                        break;
                case "SWISSFRANC":
                        curName="USD/CHF";
                        break;
                case "EUR/INR":
                        curName="EUR/INR";
                        break;  
                case "GBP/INR":
                        curName="GBP/INR";
                        break;
                case "USD/INR":
                        curName="USD/INR";
                        break;      
                default:
                    break;
           }     
            return curName;       
        }
        
        
        function replaceOriCurrencyName(CurrencyName)
        {
           var curName;
           switch(CurrencyName)
           {
                case "EUR/USD":
                    curName="EURODOLLAR";
                    break;
                case "AUD/USD":
                    curName="AUDUSD"
                    break;
                case "USD/JPY":
                        curName="JAPANESEYEN";
                        break;
                case "GBP/USD":
                        curName="POUNDSTERLING";
                        break;
                case "USD/CAD":
                        curName="CANADIANDOLLAR";
                        break;
                case "USD/CHF":
                        curName="SWISSFRANC";
                        break;
                case "EUR/INR":
                        curName="EUR/INR";
                        break;  
                case "GBP/INR":
                        curName="GBP/INR";
                        break;
                case "USD/INR":
                        curName="USD/INR";
                        break;  
                default:
                    break;
           }     
            return curName;       
        }
        
        
        
        function selectDrpValue(drpValue)
        {
            var __Currency = document.getElementById("drpCurrency");
            for(j=0;j<__Currency.length;j++)
            {
                if(drpValue==__Currency[j].value)
                {
                    __Currency[j].selected=true;
                }
            }
        }
        
        function hidedivclose()
        {
            document.getElementById("bv").style.display="none";
        }
        
        function selectRadbtn(id)
        {
            var a = document.getElementById("drpCurrency");
            var curname;
            for(i=0;i<a.length;i++)
            {
                if(a[i].selected==true)
                    curname=a[i].value;
            }
            curname=replaceOriCurrencyName(curname);
            
            sendRequest(curname,1,"aa",id, flgRefresh);
        }
        
        function xyz(id)
        {
                document.getElementById("txtBuy").value="";
                document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value=id;
                document.getElementById("commod1").innerHTML=id;
                document.getElementById("div2").style.display="none";
                document.getElementById("bb").innerHTML="";
                sendRequest(id,1,"bb", flgRefresh);
        }
        
        function close(id)
        {
            flagTransWindow=0;
            document.getElementById(id).style.display ="none";
        }
        
        function sellValue()
        {
            var a = document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value;
            var __Currenci = document.getElementById("drpCurrency");
            for(j=0;j<__Currenci.length;j++)
            {
                if(__Currenci[j].selected==true)
                {
                    a = __Currenci[j].value;
                }
            }
            
            a = replaceOriCurrencyName(a);
            
            var type;
            if(document.getElementById("sell").checked)
            type="Sell";
            else
            type="Buy";
            var currencyValue = document.getElementById("aa").innerHTML;
            
            var Quantity = document.getElementById("ctl00_ContentPlaceHolder1_Amount");
            var Qty
            for(k=0;k<Quantity.length;k++)
            {
                if(Quantity[k].selected==true)
                    Qty=Quantity[k].value;
            }
            
            document.getElementById("divSellBtn123").style.display='none';
          
          if( currencyValue != "")
          {
         
            AjaxForInsertValue(a,type,currencyValue,Qty);
              document.getElementById("div2").style.display ='none';
          }  
          else
          {
          alert('Please, Try Again ');       
             }
              
              
                           
            
//            close('div2');
        }
        
        function BuyValue()
        {
            var a = document.getElementById("Commod1").innerHTML;
            var b = document.getElementById("bb").innerHTML;
            var c =document.getElementById("txtBuy").value;
            alert(c);
        }
        function checkPrice(id)
        {
           var val=document.getElementById(id.id).value;
           
            var a = /^([1-9]{0,4})+$/;
            if(a.test(val))
            {
            return true;
            }
            else
            {
                document.getElementById(id.id).value="";
                alert("Quantity must be a number");
                return false;
            }
        }
        
        function hidediv(id, plusid, minusid)
        {
            document.getElementById(id).style.display='none';
            document.getElementById(minusid).style.display='none';
            document.getElementById(plusid).style.display='block';
        }
        
        function showdiv(id, plusid, minusid)
        {
            document.getElementById(id).style.display='block';
            document.getElementById(minusid).style.display='block';
            document.getElementById(plusid).style.display='none';
        }
        
        function displayNews()
        {
            startSearchRequest('rss.aspx','news');
        }
    
        function geturl(id)
            {
                window.open(id,"aa","Width=600 height=450 scrollbars=yes resizable=yes");
            }
            
            
            function checkValidationOfreport()
    {
       var chksince = document.getElementById("ctl00_ContentPlaceHolder1_chkSince");
       var chknow = document.getElementById("ctl00_ContentPlaceHolder1_chkNow");
       var fromdate= document.getElementById("ctl00_ContentPlaceHolder1_txtfromdate").value;
       var todate = document.getElementById("ctl00_ContentPlaceHolder1_txttodate").value;
       
       
        if(chksince.checked==false && fromdate=="")
        {
            alert("Please enter from date");
            return false;
        }
        if(chknow.checked==false && todate=="")
       {
        alert("Please enter to date");
        return false;
       }
       
       
    }
    
    function hideHeader()
        {
            document.getElementById("divHeader").style.display="none";
            document.getElementById("divhidHeader").style.display="none";
            document.getElementById("divshowHeader").style.display="block";
        }
        
        function showHeader()
        {
            document.getElementById("divHeader").style.display="block";
            document.getElementById("divhidHeader").style.display="block";
            document.getElementById("divshowHeader").style.display="none";
        }
        
        function OpenCurrencyInfo_Popup(CurrencyName, BuyOrSell)
        {
            window.open("placeorder.aspx","placeorder","width=350 height=250 scrollbars=yes resizable=yes");    
        }
        
        
        
        
        function EnbdisValue(chkid, txtid)
        {
            if(document.getElementById(chkid).checked)
            {
                
                document.getElementById(txtid).disabled=false;
                if(chkid=="chkLimit")
                {    
                    if(document.getElementById("buy").checked)    
                    {
                        document.getElementById("divlimitvalue").innerHTML = "> "+document.getElementById("txtRate").value;
                        document.getElementById(txtid).value = parseFloat(document.getElementById("txtRate").value)+parseFloat("0.0002");   
                    }
                    else
                    {
                        document.getElementById("divlimitvalue").innerHTML = "< "+document.getElementById("txtRate").value;
                        document.getElementById(txtid).value = parseFloat(document.getElementById("txtRate").value)-parseFloat("0.0002");   
                    }
                }
                else
                {
                   
                    if(document.getElementById("buy").checked)
                    {
                        document.getElementById("divstopvalue").innerHTML = "< "+document.getElementById("txtRate").value;
                        document.getElementById(txtid).value = parseFloat(document.getElementById("txtRate").value)-parseFloat("0.0002");   
                    }
                    else
                    {
                        document.getElementById("divstopvalue").innerHTML = "> "+document.getElementById("txtRate").value;
                        document.getElementById(txtid).value = parseFloat(document.getElementById("txtRate").value)+parseFloat("0.0002");   
                    }
                }
            }
            else
            {
                document.getElementById(txtid).disabled=true;
                document.getElementById(txtid).value = "";
            }
        }
        
        function Placeorders(id,type)
        {
              document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value=id;
              var a = id;
              a = replaceCurrencyName(a);
              var Array_currency =document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value;
              var currency = Array_currency.split(',');
              var drpcurrency = document.getElementById("drpCurrency");
              for(i=0;i<currency.length;i++)
               {
                    var newName = replaceCurrencyName(currency[i]);
                    drpcurrency.options[i] = new Option(newName, newName);
               }
              selectDrpValue(a);
              if(type=="sell")
                 document.getElementById("sell").checked=true;
              else
                document.getElementById("buy").checked=true;
                document.getElementById("div2").style.display="Block";
                //document.getElementById("aa").innerHTML="";
                sendRequest1(id,1,"aa",type, flgRefresh);
        }
        
        function selectRadbtnBuyorSell(id)
        {
            var a = document.getElementById("drpCurrency");
            var curname;
            for(i=0;i<a.length;i++)
            {
                if(a[i].selected==true)
                    curname=a[i].value;
            }
            curname=replaceOriCurrencyName(curname);
            
            sendRequest(curname,1,"aa",id, flgRefresh);
        }
        
        function requestOnSelectCurrency(id)
        {
            
            id = replaceOriCurrencyName(id);
            
            if(document.getElementById("sell").checked)
            {
                 sendRequest(id,1,"txtRate","Sell", flgRefresh);
              //   document.getElementById("divSellBtn123").style.display='block';
            }
            else
            {
                 sendRequest(id,1,"aa","Buy", flgRefresh);
                // document.getElementById("divSellBtn123").style.display='block';
            }
        }
        
        function saveorder()
        {
          var currencyValue = document.getElementById("txtRate").value;
          if(isNaN(currencyValue)|| currencyValue=="")
          {
                document.getElementById("txtRate").focus();
                alert("Enter a value");
                return false;
          }
          else
          {
              var a = document.getElementById("ctl00_ContentPlaceHolder1_hdnCurrency").value;
              var __Currenci = document.getElementById("drpCurrency");
                for(j=0;j<__Currenci.length;j++)
                {
                    if(__Currenci[j].selected==true)
                    {
                        a = __Currenci[j].value;
                    }
                }
                a = replaceOriCurrencyName(a);
                var type;
                if(document.getElementById("sell").checked)
                type="Sell";
                else
                type="Buy";
            
                var Quantity = document.getElementById("ctl00_ContentPlaceHolder1_Amount");
                var movenumber;
                var limit;
                
                if(document.getElementById("chkStop").checked)
                {
                    movenumber=parseFloat(document.getElementById("txtStop").value);
                    if(document.getElementById("sell").checked)
                        {
                            if(movenumber<currencyValue)
                                {
                                    alert("Stop should be > "+currencyValue);
                                    return false;
                                }                            
                        }
                        else
                        {
                            if(movenumber>currencyValue)
                                {
                                    alert("Stop should be < "+currencyValue);
                                    return false;
                                }
                        }
                }
                else
                    movenumber="0.00";
            
                if(document.getElementById("chkLimit").checked)
                {
                    limit=parseFloat(document.getElementById("txtLimit").value);
                    if(document.getElementById("sell").checked)
                    {
                        if(limit>currencyValue)
                        {
                            alert("Limit should be < "+currencyValue);
                            return false;
                        }
                    }
                    else
                    {
                        if(limit<currencyValue)
                            {
                                alert("Limit should be > "+currencyValue);
                                return false;
                            }
                    }
                }
                else
                    limit="0.00";
                
                
                var Qty;
                for(k=0;k<Quantity.length;k++)
                {
                    if(Quantity[k].selected==true)
                        Qty=Quantity[k].value;
                }
                AjaxForInsertOrderValue(a,type,currencyValue,Qty,movenumber,limit);   
            }
        }
        
        function AjaxForInsertOrderValue(CurrencyName,Type,CurrencyAmt,Qty,Movenumber,Limits)
        {
            $.ajax({
            type: "GET",
            url: "saveoutstandingorders.aspx",
            data: "Currencyname="+urlencode(CurrencyName)+"&Type="+Type+"&Amt="+CurrencyAmt+"&Qty="+Qty+"&moveto="+Movenumber+"&limit="+Limits,
            success: function(msg)
            {
               if(msg=="Saved Successfully")
               {
                    var a = new Date();
                   
                   var day_name=new Array(7);
                    day_name[0]= "Sun";
                    day_name[1]= "Mon";
                    day_name[2]= "Tue";
                    day_name[3]= "Wed";
                    day_name[4]= "Thu";
                    day_name[5]= "Fri";
                    day_name[6]= "Sat";
                   
                   var month_name = new Array(12);
                   month_name[0]  = "Jan";
                   month_name[1]  = "Feb";
                   month_name[2]  = "Mar";
                   month_name[3]  = "Apr";
                   month_name[4]  = "May";
                   month_name[5]  = "Jun";
                   month_name[6]  = "Jul";
                   month_name[7]  = "Aug";
                   month_name[8]  = "Sep";
                   month_name[9]  = "Oct";
                   month_name[10] = "Nov";
                   month_name[11] = "Dec";
                   
                   alert("Order Placed\n\nOn "+day_name[a.getDay()]+" "+a.getDate()+"-"+ month_name[a.getMonth()]+"-"+a.getFullYear()+" at "+a.getHours()+":"+a.getMinutes()+":"+a.getSeconds()+"\nYou placed order to "+Type+" "+Qty+"k "+CurrencyName+" @"+CurrencyAmt);
               
               
               }
               
               //alert(msg);
               document.getElementById("txtRate").value="";
                document.getElementById("chkStop").checked=false ;
                 document.getElementById("txtStop").value="";
                  document.getElementById("chkLimit").checked=false;
                   document.getElementById("txtLimit").value="";
            }
            });
        }
        
        function checkStoporLimit()
        {
            if(document.getElementById("chkLimit").checked)
            {
                document.getElementById("txtLimit").disabled=false;
                document.getElementById("txtLimit").value = parseFloat(document.getElementById("txtrate").value)+parseFloat("0.0002");   
                document.getElementById("divlimitvalue").innerHTML = "> "+document.getElementById("txtrate").value;
           }
             if(document.getElementById("chkStop").checked)
           {
                document.getElementById("txtStop").disabled=false;
                document.getElementById("txtStop").value = parseFloat(document.getElementById("txtrate").value)-parseFloat("0.0002");   
                document.getElementById("divstopvalue").innerHTML = "< "+document.getElementById("txtrate").value;
           }
        }

        function checkPasswordComplexity(asPassword) 
        {
        var arPasswordSymbols = new Array();
        arPasswordSymbols[0] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        arPasswordSymbols[1] = 'abcdefghijklmnopqrstuvwxyz';
        arPasswordSymbols[2] = '0123456789';
        var bResult = true;
         var aa = new String();
         aa = asPassword;
         aa = aa.replace(/^\s+|\s+$/g, '') ;
    if (aa.length < 8) 
    {
         alert("Should be atleast One Uppercase, Lowercase and numeric without spaces");
         document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').value="";
         document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').focus();
        bResult = false;
    } 
    else 
    {
        var arHasSymbol = new Array();
        for (var i = 0; i < asPassword.length; i++)
        {
            var sChar = asPassword.charAt(i);
            for (var j = 0; j < arPasswordSymbols.length; j++) {
                var sSymbols = arPasswordSymbols[j];
              
                if (sSymbols.indexOf(sChar) != -1 && sChar !="") 
                {
                    arHasSymbol[j] = true;
                }
            }
        }
        for (var i = 0; i < arPasswordSymbols.length; i++) 
        {
            if (!arHasSymbol[i]) 
            {
                bResult = false;
                alert("Should be atleast One Uppercase, Lowercase and numeric");
                document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').value="";
                document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').focus();
                break;
            }
        }
    }

    return bResult;
}

        function confirmpwd()
        {
            if(document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').value=="")
            {
                document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').value="";
                document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').focus();
                return false;
            }
            else
            {
                var confpwd = document.getElementById('ctl00_ContentPlaceHolder1_txtverpwd').value;
                var pwd =  document.getElementById('ctl00_ContentPlaceHolder1_txtnewpwd').value;
                if(confpwd != pwd)
                   {
                    alert("Password should be matched");
                    document.getElementById('ctl00_ContentPlaceHolder1_txtverpwd').value="";
                    document.getElementById('ctl00_ContentPlaceHolder1_txtverpwd').focus();
                    return false;
                    }
            }
        }   
        
        
function DisplayFormValues()
{
    var str = '';
    var elem = document.getElementById("aspnetForm").elements;
    for(var i = 0; i < elem.length; i++)
    {
        if(elem[i].type=="text")
            document.getElementById(elem[i].id).style.borderColor="green";
    } 
}

function printabledata()
{
//document.getElementById("divHeader").style.display="none";
document.getElementById("divhidHeader").style.display="none";
//document.getElementById("divshowHeader").style.display="none";
//document.getElementById("ctl00_ContentPlaceHolder1_panel1").style.display="none";
document.getElementById("printversion").style.display="none";
document.getElementById("print").style.display="block";
}
 
 function showPrint()
 {
//document.getElementById("divHeader").style.display="block";
document.getElementById("divhidHeader").style.display="block";
//document.getElementById("divshowHeader").style.display="block";
//document.getElementById("ctl00_ContentPlaceHolder1_panel1").style.display="block";
document.getElementById("printversion").style.display="block";
document.getElementById("print").style.display="none";
 }
 
 function changeColor()
 {
    document.getElementById('idStyle').href="http://192.168.25.72/tradenew/css/orange/style.css";
    var mmspobj=document.getElementById('iframeDefault2');
    if (mmspobj.tagName=='IFRAME')
    {
        window.frames['iframeDefault2'].document.getElementById('default2Body').style.backgroundColor="Yellow";
    }
 }
 
 function hidePositions(Activeid, Deactiveid1, Deactiveid2)
 {
    document.getElementById(Activeid).style.display="block";
    document.getElementById(Deactiveid1).style.display="none";
    document.getElementById(Deactiveid2).style.display="none";
    if(Activeid=="divclosedPos")
    {
        document.getElementById("div22").style.display="none";
        document.getElementById("div222").style.display="block";
        document.getElementById("div11").style.display="block";
        document.getElementById("div111").style.display="none"; 
        document.getElementById(Activeid).innerHTML = "<iframe width='100%' src='Userclosedpositions.aspx'></iframe>";
    }
    else
    {
   
        document.getElementById("div22").style.display="block";
        document.getElementById("div222").style.display="none";  
        document.getElementById("div11").style.display="none";
        document.getElementById("div111").style.display="block";  
    }
    
 }
 
 function checkStopLimitOnSellBuyPlaceOrder()
 {
          if(document.getElementById("chkLimit").checked)
              {
                 document.getElementById("txtLimit").disabled=false;
                 if(document.getElementById("buy").checked)    
                   {
                        document.getElementById("divlimitvalue").innerHTML = "> "+document.getElementById("txtRate").value;
                        document.getElementById("txtLimit").value = parseFloat(document.getElementById("txtRate").value)+parseFloat("0.0002");   
                    }
                    else
                    {
                        document.getElementById("divlimitvalue").innerHTML = "< "+document.getElementById("txtRate").value;
                        document.getElementById("txtLimit").value = parseFloat(document.getElementById("txtRate").value)-parseFloat("0.0002");   
                    }
              }
              if(document.getElementById("chkStop").checked)
                {
                    if(document.getElementById("buy").checked)
                    {
                        document.getElementById("divstopvalue").innerHTML = "< "+document.getElementById("txtRate").value;
                        document.getElementById("txtStop").value = parseFloat(document.getElementById("txtRate").value)-parseFloat("0.0002");   
                    }
                    else
                    {
                        document.getElementById("divstopvalue").innerHTML = "> "+document.getElementById("txtRate").value;
                        document.getElementById("txtStop").value = parseFloat(document.getElementById("txtRate").value)+parseFloat("0.0002");   
                    }
                }
 }
 
 function closeOpentrades(status)
 {
    if(status==1)
    {
         document.getElementById("divTradeCloseAlert").style.display="none";
         var trade__id =  document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_ID").value;
         var trade__qty =   document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_Qty").value;
         var trade__pl =   document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_PL").value;
         var trade__buysellamt =  document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closeBuySellAmt").value;
         var trade__closestatus =  document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closedStatus").value;
         var trade__rollover = "-"+ document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_rollover").value;
         var commission=document.getElementById("ctl00_ContentPlaceHolder1_hdnCommission").value;
        deleteTrade(trade__id,trade__qty,trade__pl,trade__buysellamt,trade__closestatus,trade__rollover,commission);
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_ID").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_Qty").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_PL").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closeBuySellAmt").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closedStatus").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_rollover").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnCommission").value="";
    }
    else
    {
        document.getElementById("divTradeCloseAlert").style.display="none";
    }
 }
 
 function CheckAllDataGridCheckBoxes(aspCheckBoxID,checkVal,rows,gridname)
 {
    try
     {
      rows = rows + 2;
      for(i = 0; i < document.forms[0].elements.length; i++)
      {
       elm = document.forms[0].elements[i].type
       if (elm == "checkbox")
       {
        for(j=2;j<rows;j++)
        {
            var a;
            if(j<10)
            {
             a = "ctl00_ContentPlaceHolder1_"+gridname+"_ctl0"+j+"_chk";
            }
            else
            {
                a = "ctl00_ContentPlaceHolder1_"+gridname+"_ctl"+j+"_chk";
            }
            document.getElementById(a).checked=checkVal;
            
        }
       }
      }
      }
      catch(ex)
      {
      }
 }
 
function  onefunction()
{
    var chk="";
    chk=showErrorwhenNotChecked()
    
    if(chk==true)
        {
     return disp_confirm();
     
        }
        else
        return false;
}
function disp_confirm()
{
   var r=confirm('Are you sure, you want to delete these record');
   
 if(r==false)
  {
  return false;
  }
 
}
function showErrorwhenNotChecked()
{
    var ch="true";
    for(var i=0; i < document.forms[0].elements.length; i++)
        {
            var elmnt = document.forms[0].elements[i].type;
            if(elmnt=="checkbox")
            {
                if(document.getElementById(document.forms[0].elements[i].id).checked==true)
                {
                  ch="false";
                }
            }
        }
        if(ch=="true")
        {
        alert("Please select at least one record");
        return false;
        }
        else
        {
        return true;
        }
}


function  CheckFunction()
{
    var chk="";
    chk=showErrorwhenNotChecked()
    
    if(chk==true)
        {
          return Check_Confirm();
        }
        else
        return false;
}
function adjustwaitdiv()
{
    try
    {
        var left=$("#drpCurrency").offset().left;
         var top=$("#drpCurrency").offset().top;
        var d=document.getElementById("divdrpwait");
        $("div#divdrpwait").css("left",left-150);
         $("div#divdrpwait").css("top",top+90);
        d.style.display="block";
    }
    catch(ex)
    {
    }
}
function divwaitclose()
{
    document.getElementById("divdrpwait").style.display="none";
}
function doEnter(btnid)
{
   try{
        var btn = document.getElementById(btnid);
      }catch(ex)
      {
      }
        if(window.Event)
        {
            window.captureEvents(Event.KEYPRESS)
        }
        document.onkeypress = keyPressed;
        function keyPressed(e)
        {
            var n;
            (window.Event) ? n=e.which : n=event.keyCode;
            if(n==13)
            {
                btn.click();
                return false;
            }
        }
}






//function closeAlltrades(status)
// {
//    if(status==1)
//    {
//       CallServer("y",""); 
//       document.getElementById("divCloseAllTrades").style.display="none";
//    }
//    else
//    {
//        
//        document.getElementById("divCloseAllTrades").style.display="none";
//    }
// }
 
 function displayResult(value)
 {
    alert(value);
 }
 
 
 function closeAllTrade()
 {
    document.getElementById("divCloseAllTrades").style.display="block";
 }
 
 function closeAlltrades(status)
 {
    if(status==1)
    {
    return true;
    }
    else
    {
    document.getElementById("divCloseAllTrades").style.display="none";
    return false;
    }
 }

 function hideAdminPositions(Activeid, Deactiveid1, Deactiveid2)
 {
    document.getElementById(Activeid).style.display="block";
    document.getElementById(Deactiveid1).style.display="none";
    document.getElementById(Deactiveid2).style.display="none";
    if(Activeid=="divclosedPos")
    {
        document.getElementById(Activeid).innerHTML = "<iframe width='100%' src='Allclosedpositions.aspx' height='300px'></iframe>";
    }
    else
    {
    }
 }
 
 function closeTradefromAdmin(id,qty,pl,closeBuySellAmt,ClosedStatus,rollover,UserID,commission)
  {
              
    document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_ID").value=id;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_Qty").value=qty;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_PL").value=pl;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closeBuySellAmt").value=closeBuySellAmt;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closedStatus").value=ClosedStatus;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_rollover").value="-"+rollover;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnUserID").value = UserID;
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCommission").value= commission;
    document.getElementById("divTradeCloseAlert").style.display="block";
       
  }
  
  function closeOpentradesfromAdmin(status)
 {
    if(status==1)
    {
         
         document.getElementById("divTradeCloseAlert").style.display="none";
         var trade__id =  document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_ID").value;
         var trade__qty =   document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_Qty").value;
         var trade__pl =   document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_PL").value;
         var trade__buysellamt =  document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closeBuySellAmt").value;
         var trade__closestatus =  document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closedStatus").value;
         var trade__rollover =   document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_rollover").value;
         var userid = document.getElementById("ctl00_ContentPlaceHolder1_hdnUserID").value;
         var commission=document.getElementById("ctl00_ContentPlaceHolder1_hdnCommission").value;
        deleteTradefromAdmin(trade__id,trade__qty,trade__pl,trade__buysellamt,trade__closestatus,trade__rollover,userid,commission);
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_ID").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_Qty").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_PL").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closeBuySellAmt").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_closedStatus").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnTradeclose_rollover").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_hdnCommission").value="";
    }
    else
    {
        document.getElementById("divTradeCloseAlert").style.display="none";
    }
 }
 
 function deleteTradefromAdmin(id,qty,pl,closeBuySellAmt,ClosedStatus,rollover,Userid,commission)
    {
        alert(commission);
        $.ajax(
        {
            type:"GET",
            url:"DeleteTrade.aspx",
            data:"TicketId="+id+"&Qty="+qty+"&pl="+pl+"&closeBuySellAmt="+closeBuySellAmt+"&ClosedStatus="+ClosedStatus+"&rollover="+rollover+"&userid="+Userid+"&commission="+commission,
            beforeSend:function(){
           
        $("div#closeTradeConfirmation").show();
        $("div#CloseTrade").html("<img src='../images/loader_wait.gif'/>");
        },
            success:function (msg)
            {
               $("div#closeTradeConfirmation").show();
               $("div#CloseTrade").html("<table><tr><td style='font-size:14; color:#DBAE31'>Trade Closed confirmation</td></tr><tr><td>&nbsp;</td></tr><tr><td>Your trade closed @ "+closeBuySellAmt+"</td></tr></table>");
               // alert("Position closed successfully");
            }
        }
        )
    }
    
    
    function deleteTradeFromAdminUserDetail(id,qty,pl,closeBuySellAmt,ClosedStatus,rollover,commission)
        {
            $.ajax(
            {
                type:"GET",
                url:"DeleteTrade.aspx",
                data:"TicketId="+id+"&Qty="+qty+"&pl="+pl+"&closeBuySellAmt="+closeBuySellAmt+"&ClosedStatus="+ClosedStatus+"&rollover="+rollover+"&commission="+commission,

                success:function (msg)
                {
                    alert("Position closed successfully");
                    location.href=msg;
                }
            }
            )
        }
        
        
        
        function forceChar(id)
{
    var regExp=/^[A-Za-z0-9._-]/;
    var rg= /^[A-Za-z]/;
    var char1=id.value.substr((id.value.length-1),(id.value.length));
    if(rg.test(char1))
     {
       id.value=id.value.replace(/^\s+$/,"");
     }
    else
     {
        id.value=id.value.substr(0,id.value.length-1);
     }
    if(rg.test(id.value.charAt(0)))
    {
    }
    else
    {
        id.value=id.value.substr(0,id.value.length-1);
    }       
}


 function forceZip(id)
{
    var regExp=/^[A-Za-z0-9._-]/;
    var rg= /^[0-9]/;
    var char1=id.value.substr((id.value.length-1),(id.value.length));
    if(rg.test(char1))
     {
       id.value=id.value.replace(/^\s+$/,"");
     }
    else
     {
        id.value=id.value.substr(0,id.value.length-1);
     }
    if(rg.test(id.value.charAt(0)))
    {
    }
    else
    {
        id.value=id.value.substr(0,id.value.length-1);
    }       
}

function forceregularexlicense(id)
{
    var regExp=/^[A-Za-z0-9.@#$%&*?~-]/;
    var rg= /^[A-Za-z0-9@#$%&*?~-]/;
    var char1=id.value.substr((id.value.length-1),(id.value.length));
    if(regExp.test(char1))
     {
       id.value=id.value.replace(/^\s+$/,"");
     }
    else
     {
        id.value=id.value.substr(0,id.value.length-1);
     }
    if(rg.test(id.value.charAt(0)))
    {
    }
    else
    {
        id.value=id.value.substr(0,id.value.length-1);
    }       
}
