﻿// JScript File

function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


   
// Code for future Ticker Starts
var req = new Array();
var flag= new Boolean();
var lastPos=null;
var currentPos="";
var bIsLighWindowActive=new Boolean();
flag=true;


function sMOver(event,obj)
{
obj.style.cursor="pointer";
currentPos=obj.id;
event=window.event?window.event:event;
//document.getElementById('FutureMarquee').stop();
var notes = document.getElementById("divMOver")
var nX=new Number();
var nY=new Number();

if(notes != null)

{
    var nScrollLeft=new Number();
    var nScrollTop=new Number();

    nScrollLeft=f_scrollLeft();
    nScrollTop=f_scrollTop();
    
 nX=event.clientX;
  nY=event.clientY; 
  
  nY=nY+nScrollTop;
  nX=nX+nScrollLeft;
  var nWinWidth=f_clientWidth();
  var nPopupWidth=notes.clientWidth;    
  nWinWidth=nWinWidth+nScrollLeft;
                        
  if((nPopupWidth+nX)>nWinWidth)
  {
  nX=nX-((nPopupWidth+nX)-nWinWidth);
  }
notes.style.top = nY+5+"px";
notes.style.left = nX+"px";
notes.style.visibility = "visible";
if(obj.id!=lastPos)
{
document.getElementById("tdName").innerHTML="Loading&nbsp;&nbsp;<img src='images/loading.gif' />";
document.getElementById("tdOpenPrice").innerHTML="";
document.getElementById("tdHighPrice").innerHTML="";
document.getElementById("tdLowPrice").innerHTML="";
document.getElementById("tdPCP").innerHTML="";
document.getElementById("tdLifeHigh").innerHTML="";
document.getElementById("tdLifeLow").innerHTML="";

req.push(obj.id);
if(flag==true)
{
flag=false;
var res = Home.GetMOverDetails(req.pop(),sMOver_callback);
}
}
}
}

function sMOver_callback(res)
{
var ss=res.value;
if(ss != "" && ss !=null)
{
if(ss[0]==currentPos)
{
var notes = document.getElementById("divMOver");

document.getElementById("tdName").innerHTML="<span style='margin-left:2px' class='txtwhite'>"+ss[1]+"-"+ss[8]+"</span>";
document.getElementById("tdOpenPrice").innerHTML="<span class='toolrates'>" + ss[2] + "</span>";
document.getElementById("tdHighPrice").innerHTML="<span class='toolrates'>" + ss[3] + "</span>";
document.getElementById("tdLowPrice").innerHTML="<span class='toolrates'>" + ss[4] + "</span>";
document.getElementById("tdPCP").innerHTML="<span class='toolrates'>" + ss[5] + "</span>";
document.getElementById("tdLifeHigh").innerHTML="<span class='toolrates'>" + ss[6] + "</span>";
document.getElementById("tdLifeLow").innerHTML="<span class='toolrates'>" + ss[7] + "</span>";
}
}
else
{
document.getElementById("tdName").innerHTML="Loading&nbsp;&nbsp;<img src='Images/loading.gif' />";
document.getElementById("tdOpenPrice").innerHTML="No-Data";
document.getElementById("tdHighPrice").innerHTML="No-Data";
document.getElementById("tdLowPrice").innerHTML="No-Data";
document.getElementById("tdPCP").innerHTML="No-Data";
document.getElementById("tdLifeHigh").innerHTML="No-Data";
document.getElementById("tdLifeLow").innerHTML="No-Data";
}
flag=true;
lastPos=currentPos;
}

function sMOut()
{
var notes = document.getElementById("divMOver");
notes.style.visibility = "hidden";
//document.getElementById('FutureMarquee').start();
flag=true;
}

function LeftFutureClick()
{
var FutureMarquee=document.getElementById("FutureMarquee");
if(FutureMarquee!=null)
    {
        FutureMarquee.setAttribute("behavior","scroll");		
	 	FutureMarquee.setAttribute("direction","left");
    }
}
function RightFutureClick()
{
var FutureMarquee=document.getElementById("FutureMarquee");
if(FutureMarquee!=null)
    {
        FutureMarquee.setAttribute("behavior","scroll");		
	 	FutureMarquee.setAttribute("direction","right");
    }
}

function setTimer(check)
{
//1 min=60000
var Ajaxtimer = 1;//
Ajaxtimer = Ajaxtimer * 60000;
window.setTimeout(AppendData,Ajaxtimer);
}

function AppendData()
{
    if(bIsLighWindowActive==false)
    {
        var res = Home.GetFutureTickerData();
        if(res!=null && typeof res!='undefined' && res.value!=null &&res.value!="")
                document.getElementById("mLblFutureTicker").innerHTML = res.value;
        else
                document.getElementById("mLblFutureTicker").innerHTML ="Currently No Data is Available";
      }
    setTimer();
}

//Code for future ticker end
  

  
//for Spot Ticker Script Code Start
var req = new Array();
var flag= new Boolean();
var lastPos=null;
var currentPos="";
flag=true;


function LeftSpotClick()
{
    var SpotMarquee=document.getElementById("SpotMarquee");
    if(SpotMarquee!=null)
    {
        SpotMarquee.setAttribute("behavior","scroll");		
	 	SpotMarquee.setAttribute("direction","left");
    }
}
function RightSpotClick()
{
    var SpotMarquee=document.getElementById("SpotMarquee");
    if(SpotMarquee!=null)
    {
        SpotMarquee.setAttribute("behavior","scroll");		
	 	SpotMarquee.setAttribute("direction","right");
    }
  
}

function setSpotTimer(check)
{
        //1 min=60000
        var SpotAjaxRefreshTime = 5;
        SpotAjaxRefreshTime = SpotAjaxRefreshTime * 60000;
        window.setTimeout(AppendSpotData,SpotAjaxRefreshTime);
}

function AppendSpotData()
{
    if(bIsLighWindowActive==false)
    {
        var res = Home.GetSpotTickerData();
        if(res!=null && typeof res!='undefined' && res.value!=null &&res.value!="")
            document.getElementById("mLblSpotTicker").innerHTML = res.value;
        else
            document.getElementById("mLblSpotTicker").innerHTML ="Currently No Data is Available";
     }
setSpotTimer();
}
//Spot Ticker code End
   
    var sIndicesTimerId="mRefreshMarketData";
    
    function InitializeRequest(sender, args)
    {
   try{
      var oReqManager=Sys.WebForms.PageRequestManager.getInstance()
      var oPB_elementId= args.get_postBackElement();
      
        if (oReqManager!=null && oReqManager.get_isInAsyncPostBack()==false && oPB_elementId.id==sIndicesTimerId &&
          typeof  bIsLighWindowActive !='undefined' && bIsLighWindowActive==true)
        {
            args.set_cancel(true);
        }
        }catch(e){}
    }

  
function openWin( windowURL, windowName, windowFeatures ) {
return window.open( windowURL, windowName, windowFeatures ) ;
}
   
function gosearch()
{
if(trim(document.getElementById("txtSearch").value)!= "") //document.getElementById("txtSearch").style.color != 'gray')//
{
var str;
str=document.getElementById("txtSearch").value.replace("+","@(p)@").replace("&","@(a)@").replace("#","@(h)@");
window.open('Sitepages/SearchResult.aspx?searchText='+str,"_top");
}
else
{
alert('Please enter search text!');
document.getElementById("txtSearch").value = "";
document.getElementById("txtSearch").focus();
return false;
}
}

function setText()
{

if(trim(document.getElementById("txtSearch").value) == "")
{
document.getElementById("txtSearch").value = "search";
}
}

function trim(objTxtValue)
{
txtValue = new String();
txtValue1 = new String();
var i = 0;

txtValue = objTxtValue;

if (txtValue.length == 0) {
return txtValue;
} else {
while (((txtValue.lastIndexOf(' ') + 1) == txtValue.length) && (txtValue.lastIndexOf(' ') != 0)) {
txtValue1 = (txtValue.slice(0,txtValue.lastIndexOf(' ')));
txtValue = txtValue1;
}
while (txtValue.indexOf(' ') == 0) {
txtValue1 = (txtValue.slice(1,txtValue.length));
txtValue = txtValue1;
}
return txtValue;
}
}
  
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
var MCX_INDICES={
                    "FUTURE"    :"1",
                    "RAINFALL"  :"2"
                }
                
var sActiveIndices=MCX_INDICES.FUTURE;

function OnRainFall_Click(obj)
{  

    var objTblRainFall=document.getElementById("tbl_RainfallTable");
    var objTbl_FutureIndices=document.getElementById("tbl_FutureIndicesTable");
    var objIndicesLabel=document.getElementById("lbl_IndicesLabel");
    var objSelectedIndex=document.getElementById("mHdnSelectedIndex");
   var objImgIndices=document.getElementById("img_MCXIndices");
   
   if(objTblRainFall!=null)objTblRainFall.style.display="none";
   if(objTbl_FutureIndices!=null) objTbl_FutureIndices.style.display="none";
     
    if(MCX_INDICES.FUTURE==sActiveIndices && objTblRainFall!=null && objTbl_FutureIndices!=null)
    {
        objTblRainFall.style.display="block";
         sActiveIndices=MCX_INDICES.RAINFALL;
         objSelectedIndex.value="2";
        objIndicesLabel.innerHTML="Rainfall";
        if(objImgIndices!=null) objImgIndices.src="images/Futureindex.gif"
       
    }
    else  if(MCX_INDICES.RAINFALL==sActiveIndices && objTblRainFall!=null && objTbl_FutureIndices!=null)
    {
         objTbl_FutureIndices.style.display="block";
        sActiveIndices=MCX_INDICES.FUTURE;
         objIndicesLabel.innerHTML="Futures";
             if(objImgIndices!=null) objImgIndices.src="images/rainindex.gif"
             objSelectedIndex.value="1";
    }
}
function SetActiveIndices(nActiveIndices)
{
try{

   var objTblRainFall=document.getElementById("tbl_RainfallTable");
    var objTbl_FutureIndices=document.getElementById("tbl_FutureIndicesTable");
    var objIndicesLabel=document.getElementById("lbl_IndicesLabel");
    var objSelectedIndex=document.getElementById("mHdnSelectedIndex");
   var objImgIndices=document.getElementById("img_MCXIndices");
   
     nActiveIndices=sActiveIndices
    if(nActiveIndices=="1"  && objTblRainFall!=null && objTbl_FutureIndices!=null)
    {
        objTbl_FutureIndices.style.display="block";
        objTblRainFall.style.display="none";
        sActiveIndices=MCX_INDICES.FUTURE;
       objIndicesLabel.innerHTML="Futures";
             if(objImgIndices!=null) objImgIndices.src="images/rainindex.gif"
             objSelectedIndex.value="1";
    }
    else  if(nActiveIndices=="2" && objTblRainFall!=null && objTbl_FutureIndices!=null)
    {
    objTblRainFall.style.display="block";
    objTbl_FutureIndices.style.display="none";
        objIndicesLabel.innerHTML="Rainfall";
           sActiveIndices=MCX_INDICES.RAINFALL;
        if(objImgIndices!=null) objImgIndices.src="images/Futureindex.gif"
        objSelectedIndex.value="2";
    }
        

}catch(e){}
}
   
        function OpenNesData(URL,WIDTH,HEIGHT)
        {   
             window.open(URL,null,"scrollbars=yes,width="+ WIDTH +",height="+ HEIGHT +",status=no,toolbar=no,menubar=no,location=no,fullscreen=no");
        }
        
        function rss(intPType)
        {
            switch(intPType)
                {
                    case "0":
                        window.open('Sitepages/RssLink.htm','','left=100,top=100,right=0,width=830,height=560,scrollbars=1,resizable=yes'); 
                        break;
                  
                }
        }
   
function openMCXChartMini() 
	{	
	  windowPopup = window.open('http://mcxactmini.mcxindia.com/MCXOnlineCommodities.aspx',null,'fullscreen=no,toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=no,scrollbars=yes,left=0,top=0,width='+(screen.availWidth-10)+',height='+(screen.availHeight-50));windowPopup.focus();	
	} 

function openMCXChart() 
	{
	windowPopup = window.open('https://mcxact.mcxindia.com/LoginPage.aspx',null,'fullscreen=no,toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=no,scrollbars=yes,left=0,top=0,width='+(screen.availWidth-10)+',height='+(screen.availHeight-50));windowPopup.focus();
	} 

function clickButton()
{

    if(navigator.appName.indexOf("Netscape")>(-1))
    {
        if (event.keyCode == 13)
        {
            gosearch();
            return false;
        }
    }
    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
    {
        if (event.keyCode == 13)
        {
            gosearch();
            return false;
        }
    }

}
   
 
