﻿// JScript File
function SetFrameWidth(curframe,lrwidth)
{
  var cw=document.body.clientWidth;//body width
  var framewidth=cw-parseInt(lrwidth);
  framewidth=(framewidth<742)?742:framewidth;
  document.getElementById(curframe).style.width=framewidth+"px";
  document.getElementById('tdFrame').style.width=framewidth+"px";
  
  //var scrwidth=window.screen.width;
  //document.getElementById(curframe).style.width=(scrwidth-250)+"px";
  //document.getElementById('tdFrame').style.width=(scrwidth-250)+"px";
  
  

}

function getInnerHeight(iframe)
{
    var d=iframe.contentWindow ?
    iframe.contentWindow.document :
    iframe.contentDocument;
    var h=0;
    if(d){
    if(d.documentElement && d.compatMode &&
    d.compatMode=="CSS1Compat")
    h=d.documentElement.scrollHeight;
    else if(d.body)
    h=d.body.scrollHeight;
    if(h) h+=getInsets(d);
    }

    document.getElementById('imgDiv').style.display='none';
    document.getElementById('mainFrame').style.visibility='visible';
    document.getElementById('tablemaster').focus();
     var frameheight="632px";
    if(h>632) frameheight=h+"px";
    return frameheight;
    
    //return (h||850)+"px"; //300 is a default value
}
function getInsets(d)
{
    if(d.body.currentStyle)
    with (d.body.currentStyle)
    return (parseInt(marginTop)||0) +
    (parseInt(marginBottom)||0) +
    (parseInt(paddingTop)||0) +
    (parseInt(paddingBottom)||0);
    if(d.defaultView && d.defaultView.getComputedStyle)
    with (d.defaultView)
    return parseInt(getComputedStyle(d.body,"").
    getPropertyValue("margin-top"))+
    parseInt(getComputedStyle(d.body,"").
    getPropertyValue("margin-bottom"))+
    parseInt(getComputedStyle(d.body,"").
    getPropertyValue("padding-top"))+
    parseInt(getComputedStyle(d.body,"").
    getPropertyValue("padding-bottom"));
    return 0;
}

 function setPage(url)
{
    document.body.scrollTop =0;
    var ifrme = document.getElementById('mainFrame');
    ifrme.src=url;
    ifrme.style.visibility='hidden';
    document.getElementById('imgDiv').style.display='block';
    
   
}

function subscribe(txtbox,flag)
{
    var emailBox = document.getElementById('txtEmail');
    var emailTxt = emailBox.value;
    if(emailTxt == "")
    {
        alert("Enter a valid Email Address");
    }
    else
    {
        var ind = emailTxt.lastIndexOf(".");
        if(((emailTxt.lastIndexOf("."))-(emailTxt.lastIndexOf("@"))<=1) || (emailTxt.indexOf(".")<=0) || (emailTxt.indexOf("@")<=0) || (emailTxt.substring(ind+1,ind+2)==""))
        {
            alert("Enter a valid Email Address in 'abc@xyz.com' format");
            emailBox.value = "";
            document.getElementById(txtbox).focus();
        }
        else
        {
            var redirectURL = "message.aspx?youremail="+emailTxt+"&subscribe="+flag;
            emailBox.value = "";
          
            setPage(redirectURL)
        }
    }
}

// Menu Area
 
    
function ShowSubMenu(submenu)
{
 var spancurrlist=document.getElementsByTagName('span');
  var count=spancurrlist.length;
  for(var i=0;i<count;i++)
  {  
      try
      {
        if(spancurrlist[i].id.indexOf('SpanMenu')!=-1)
                   spancurrlist[i].style.display="none";
      }
      catch(err)
      {         
      }
    }
    document.getElementById(submenu).style.display="block";

}
var cTD;
var oldmenu;
function ShowAsActive(curTD,submenu,menuname)
{
   if (menuname=="Home") menuname="&nbsp;&nbsp;Home&nbsp;&nbsp;";
   if(submenu != "")  ShowSubMenu(submenu);     
   var curmenu="<table border='0' cellspacing='0' cellpadding='0'><td><img align='top' src='images/menubuttonleft.jpg' width='16' height='41' /></td>";
   curmenu+="<td  background='images/menubuttonBG.jpg' align='center' >"+menuname+"</td>";
   curmenu+="<td width='17'><img align='top' src='images/menubuttonright.jpg' width='16' height='41' /></td></tr></table>";
   
    if(!cTD)
    {
          cTD = document.getElementById('tdMenuHome');  
          oldmenu="<table border='0' cellspacing='0' cellpadding='0'><tr><td style='padding-left:16px;padding-right:16px;'>&nbsp;&nbsp;Home&nbsp;&nbsp;</td></tr></table>";        
    }
    if(cTD)
    {
                    
           var thisTD=document.getElementById(curTD);  
           if(cTD.id !=thisTD.id)
           {
             cTD.innerHTML=oldmenu;
           }
           cTD = thisTD;
           
           oldmenu="<table border='0' cellspacing='0' cellpadding='0'><tr><td style='padding-left:16px;padding-right:16px;'>"+menuname+"</td></tr></table>";
     }   
   
  document.getElementById(curTD).innerHTML=curmenu;
  document.getElementById(curTD).style.paddingTop="0px";
}
    
//var oldwindow;
function showTickers()
{
    var thisDiv = document.getElementById("tickersDiv");
    thisDiv.style.display = "none";
    var mid = document.getElementById("Market").value;
    if(oldwindow)
        oldwindow.close();
    oldwindow = window.open("tickers.aspx?mid="+ mid, "","resizable=0,scrollbars=1,top=0,left=300,width=700,height=1000");
}

function showTickerInfo()
{
    var thisDiv = document.getElementById("tickersDiv");
    thisDiv.style.display = "none";
    var mid = document.getElementById("Market").value;
    var sid = document.getElementById("txtSecurityName").value;
    if(sid == "")
    {
        alert("Enter a Ticker!");
    }
    else
    {
        if(oldwindow)
            oldwindow.close();
        oldwindow = window.open("tickerinfo.aspx?mid=" + mid + "&sid=" + sid, "","resizable=0,scrollbars=1,top=0,left=300,width=700,height=600");
    }
}
   function test()
    {
        window.open("etrade.html","","resizable=0,scrollbars=1,top=0,left=300,width=800,height=850");
    }


// End of Menu Area




function checkPhoneNo(evt)
{   
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if(charCode==40 || charCode==41 || charCode==43 || charCode==45 || charCode==32) return true;
    if (charCode > 31 && (charCode < 48 || charCode > 57) )
    {
        alert("Form the Phone/Mobile/Fax Number using 0-9 + - ( ) Space"); 
        return false;
    }
}

function checkIntegers(evt)
{   
    var charCode = (evt.which) ? evt.which : event.keyCode;
    //alert(charCode);
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    { 
        alert("Numbers  0-9 Only");
        return false;
    }
}

var oldwindow;
function showPopUp(url,width,height)
{
    var clwidth=window.parent.document.documentElement.clientWidth;
    var left=clwidth-width;//clwidth-width(popup)
    var settings="width="+width+",height="+height+",left="+left+" ,top=0,toolbar=0,status=0,scrollbars=yes, resizable=no";
    if(oldwindow) oldwindow.close();                      
    oldwindow=window.open(url,"",settings); 
               
}

function showTicker(url,width,height)
{
var clwidth=window.parent.document.documentElement.clientWidth;
var left=(clwidth-width) / 2;//clwidth-width(popup)
var settings="width="+width+",height="+height+",left="+left+" ,top=300,toolbar=0,status=0,scrollbars=yes, resizable=no";
if(oldwindow) oldwindow.close();
oldwindow=window.open(url,"",settings);

}

function closeChild()
{ 
   if(oldwindow)oldwindow.close();                
             
}

function showTickerList()
{
    var thisDiv = document.getElementById("tickersDiv");
    thisDiv.style.display = "block";
    var tickerStr =event.srcElement.value;
    var marketStr = document.getElementById("Market").value;
    var req;
    if (window.XMLHttpRequest)
        req = new XMLHttpRequest();
    else if (window.ActiveXObject)
        req = new ActiveXObject("Microsoft.XMLHTTP");
    var url = "getnames.aspx?tk=" + tickerStr + "&mk=" + marketStr;
    req.open('GET',url, false); 
    req.send(null);
    var result="";
    if(req.status == 200)
        result = req.responseText;
    thisDiv.innerHTML = result;
}

function setTVal(val)
{
    document.getElementById("txtSecurityName").value = val;
    var thisDiv = document.getElementById("tickersDiv");
    thisDiv.style.display = "none";
}

function showHideTables(disp1, disp2)
{
    document.getElementById("forexTable").style.display = disp1;
    document.getElementById("converterTable").style.display = disp2;
}

function showLoading()
{

    document.getElementById("currResultDiv").style.display = "block";
    document.getElementById("currResultDiv").innerHTML =  "<font face='verdana' size='1'>Calculating...</font>"; //"<img src='images/spinner.gif'>";
   
}

function getCurrencyValue(ddl1, ddl2)
{   
    var txt = document.getElementById("txtCurrencyValue");
    if(txt.value == "")
        alert("Enter the Value to convert");
    else
    {
        var req;
        var fc = document.getElementById(ddl1);
        var tc = document.getElementById(ddl2);
        if (window.XMLHttpRequest)
            req = new XMLHttpRequest();
        else if (window.ActiveXObject)
            req = new ActiveXObject("Microsoft.XMLHTTP");
        var url = "getcurrency.aspx?cv=" + txt.value + "&fc=" + fc.value + "&tc=" + tc.value;
       
        req.open('GET',url, false); 
        req.send(null);
        var result="";
        if(req.status == 200)
            result = req.responseText;
        
        document.getElementById("currResultDiv").innerHTML = txt.value + " " + fc.value + " = " + result + " " + tc.value;
        

    }
}

function validateNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if(charCode==40 || charCode==41 || charCode==43 || charCode==45 || charCode==32) return true;
    if (charCode > 31 && (charCode < 48 || charCode > 57) )
    {
        return false;
    }
}