﻿// JScript File
 //Global XMLHTTP Request object
    var XmlHttp;
    var XmlHttpExch;
    var FeedExchData;
    var FeedData;
    var FeedDataTemp;
    var bFlag = false;
    var bXHRCreated = false;
    
    //Creating and setting the instance of appropriate XMLHTTP Request object to a "XmlHttp" variable  
    function CreateXMLHttp()
    { 
        try
        {
            XMLHttp = new XMLHttpRequest();
        }
        catch (e)
        { 
            try
            {
                XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e)
            {
                try
                { 
                    XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) 
                { 
                    return false;
                } 
            }
        }
    }

    function HandleResponse()
    {
        if(XMLHttp.readyState == 4)
        {
            if(XMLHttp.status == 200)
            {			
                //var theValue = document.getElementById("stateName");
                //theValue.value = XMLHttp.responseText;
                FeedDataTemp = XMLHttp.responseText;
                
                if(FeedDataTemp.indexOf("@@@") > -1 )
                {
                    FeedDataTemp = FeedDataTemp.substring(FeedDataTemp.indexOf("@@@") + 3);
                   
                    if(FeedDataTemp.indexOf("@@@") > -1 )
                    {
                        FeedDataTemp = FeedDataTemp.substring(0,FeedDataTemp.indexOf("@@@"));
                        //alert(FeedDataTemp);
                    }
                }
                FeedData = FeedDataTemp;
                
                //Ticker();
                //alert(FeedData);
            }
            else
            {              
                //alert("Unable to get the data from the server. Readystate: " + 
                //XMLHttp.readyState + " Status: " + XMLHttp.status);
            }
        } 
         //alert("Unable to get the data from the server. Readystate: " + 
                //XMLHttp.readyState + " Status: " + XMLHttp.status);
    }

    function SpeedUp() 
    {
        if( marqueespeed < 9 )
        {
            marqueespeed = marqueespeed + 1;
            copyspeed=marqueespeed;
            pausespeed=(pauseit==0)? copyspeed: 0;
            //alert( marqueespeed );
        }
    }
    
    function SpeedDown() 
    {
      if( marqueespeed > 2  )
      {
            marqueespeed = marqueespeed - 1;
            copyspeed=marqueespeed;
            pausespeed=(pauseit==0)? copyspeed: 0;
            //alert( marqueespeed );
      }
    }
    
    function ajaxGetValue() 
    {
        var now = new Date(); 
    
        //FeedData = "<Span class='StockNormal'>Connecting to Feed Server</span>"
        // The main code to execute
        //var clientValue = document.getElementById("stateAbbreviation");
        //var requestUrl = "Webform2.aspx?val=" + clientValue.value;
        //var requestUrl = "testWebservice.asmx/HelloWorld"; // calling function with out parameters
        //var requestUrl = "FeedService.asmx/GetFeed"; // calling function with parameters
        //var requestUrl = "FeedService.asmx/GetFeed"; // calling function with parameters
        //var requestUrl = "FeedService.asmx/GetFeed?time="+now.getTime(); // calling function with parameters
        var requestUrl = "Feeds.asmx/GetFeed"; // calling function with parameters

        //if( bXHRCreated == false)
        //{
            CreateXMLHttp();
        //    bXHRCreated = true;
        //}
	
	    // If browser supports XMLHTTPRequest object	
        if(XMLHttp)
        {
            	
	        // Create the SOAP Envelope
            //	        var strEnvelope = "<soap:Envelope xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xsd=\"'http://www.w3.org/2001/XMLSchema\'" +	
            //	            " soap=\'http://schemas.xmlsoap.org/soap/envelope/\'>" +	
            //	            "  <soap:Body>  <" + "Helloworld2" + " xmlns=\'http://tempuri.org/'> </" + "Helloworld2" + ">" +	
            //	            "  </soap:Body></soap:Envelope>";
    
        
            //Setting the event handler for the response
            XMLHttp.onreadystatechange = HandleResponse;
            
            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            //XMLHttp.open("GET", requestUrl, true); // webpage
            XMLHttp.open("POST", requestUrl, true); // webservice
            //Sends the request to server
            XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 
            //XMLHttp.send(null);
            var sendData = "&d="+now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds();
            XMLHttp.send(sendData)
            //XMLHttp.send(strEnvelope);
            //Ticker();
            if( bFlag == false )
            {
                populate()
                //Ticker();
                //alert("ticker started");
            }
            //var nCount = 0;
            //while( nCount  < 1000 )
            //{
//                if( bFlag == true )
//                {
//                    bFlag = false;
                    //nCount++;
                    
                //}
//            }
            //alert("N");
            //timer = setTimeout("ajaxGetValue()",3000); // commented on 21 Oct 2008 
            timer = setTimeout("ajaxGetValue()",4500); 
            //alert("Y");
        }
        //else
        //    alert("N");
    }
//    function Ticker()
//    { 
     //window.status = FeedData; 
//     var clientValue = document.getElementById("stockTicker");
//     if( FeedData == null )
//     {
//        FeedData = "";        
//     }
//     else
//        FeedData = FeedData.substring(1, FeedData.length) + FeedData.substring(0,1); 
//    
//     clientValue.value = FeedData ;  
//     bFlag = true;
//     //alert(FeedData);
//     timer = setTimeout("Ticker()", 600); 
//    } 
//////////////00000000000000000000000000000000000000
/*
Cross browser Marquee script- © Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and Terms Of Use, visit http://www.dynamicdrive.com
Credit MUST stay intact
*/

//Specify the marquee's width (in pixels)
//var marqueewidth="643px"
var marqueewidth="690px"
//var marqueewidth="1500px"
//Specify the marquee's height
var marqueeheight="24px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed= 3
//2
//configure background color:
var marqueebgcolor="#000000"
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1

//Specify the marquee's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

//var marqueecontent='<nobr><span class="StockUp">+ 23</span> <span class="StockDown">- 45.6 </span> <span class="StockNormal">9.7</span></nobr>'
//var marqueecontent='<nobr><span class="StockUp">1ABCDEFGHIJKLMNOPQRSTUVWXYZ-2ABCDEFGHIJKLMNOPQRSTUVWXYZ-3ABCDEFGHIJKLMNOPQRSTUVWXYZ</SPAN></nobr>'
var marqueecontent="<nobr><Span class='StockNormal'>Connecting to Feed Server</span></nobr>"

////NO NEED TO EDIT BELOW THIS LINE////////////
marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
if (iedom)    
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-48000px">'+marqueecontent+'</span>')
    //document.write('<span id="temp" style="position:absolute;top:100px;left:100px">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee
var direction = "left"

function scrollmarquee()
{
if( direction == "right" )
{
    if (iedom)
    {
        if( actualwidth < 712 )
            actualwidth = 712
        //if (parseInt(cross_marquee.style.left)< (actualwidth + 8) )
        if (parseInt(cross_marquee.style.left) < 712 )
        {
            //copyspeed=marqueespeed
            cross_marquee.style.left=parseInt(cross_marquee.style.left)+copyspeed+"px"
        }       
        else
        {
            //alert( "1: " + FeedData )
            if( ( FeedData != null ) && ( FeedData != "" ) )
            {
                FeedData = FeedData.replace(/&lt;/g,"<")            
                FeedData = FeedData.replace(/&gt;/g,">")
            }
         
	        //marqueecontent='<nobr><span class="StockUp">+ 555</span> <span class="StockDown">- 444 </span> <span class="StockNormal">888</span></nobr>';
	        if( FeedData == null )
	            FeedData = "<Span class='StockNormal'>..Connecting to Feed Server</span>"
	        marqueecontent='<nobr>' + FeedData + '</nobr>'
	        if (iedom)
	            document.getElementById("temp").innerHTML = marqueecontent
        	//alert(marqueecontent)
	        if (iedom)
	        {
                cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
                cross_marquee.style.left="0px"                
                cross_marquee.innerHTML=marqueecontent
                actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
            }
            else if (document.layers)
            {
                ns_marquee=document.ns_marquee.document.ns_marquee2
                ns_marquee.left=0
                ns_marquee.document.write(marqueecontent)
                ns_marquee.document.close()
                actualwidth=ns_marquee.document.width
            }
	        //document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
	        //cross_marquee.style.left=parseInt(marqueewidth)+8+"px"	        
	        //cross_marquee.style.left=parseInt(actualwidth)*(-1)+8+"px"             
	        
	        //cross_marquee.style.left="0px"	        
	        cross_marquee.style.left=parseInt(actualwidth)*(-1)+8+"px" 
        } 
    }
    else if (document.layers)
    {
        if (ns_marquee.left<(actualwidth*(1)-8))
            ns_marquee.left+=copyspeed
        else
            ns_marquee.left=parseInt(marqueewidth)-8
    }
   }
   else
   {
    if (iedom)
    {
        if (parseInt(cross_marquee.style.left)>(actualwidth*(-1) -100)) // -100 on 12 may 2008
        {
            //copyspeed=marqueespeed
            cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
        }
        else
        {
            //alert( "1: " + FeedData )
            if( ( FeedData != null ) && ( FeedData != "" ) )
            {
                FeedData = FeedData.replace(/&lt;/g,"<")            
                FeedData = FeedData.replace(/&gt;/g,">")
            }
         
	        //marqueecontent='<nobr><span class="StockUp">+ 555</span> <span class="StockDown">- 444 </span> <span class="StockNormal">888</span></nobr>';
	        
	        marqueecontent='<nobr>' + FeedData + '</nobr>'
	        if (iedom)
	            document.getElementById("temp").innerHTML = marqueecontent
        	//alert(marqueecontent)
	        if (iedom)
	        {
                cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
                cross_marquee.style.left=parseInt(marqueewidth)+8+"px"                
                cross_marquee.innerHTML=marqueecontent
                actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
            }
            else if (document.layers)
            {
                ns_marquee=document.ns_marquee.document.ns_marquee2
                ns_marquee.left=parseInt(marqueewidth)+8
                ns_marquee.document.write(marqueecontent)
                ns_marquee.document.close()
                actualwidth=ns_marquee.document.width
            }
	        //document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
	        cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"      
        }
    }
    else if (document.layers)
    {
        if (ns_marquee.left>(actualwidth*(-1)+8))
            ns_marquee.left-=copyspeed
        else
            ns_marquee.left=parseInt(marqueewidth)+8
    }
   }
}

function setleftscroll()
{
direction = "left"
//cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"     
}

function setrightscroll()
{
direction = "right"
//cross_marquee.style.left="0px" 
//parseInt(cross_marquee.style.left)-copyspeed+"px"
 
}


function scrollmarqueeleft()
{
    if (iedom)
    {
        if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
        {
            //copyspeed=marqueespeed
            cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
        }
        else
        {
            //alert( "1: " + FeedData )
            if( ( FeedData != null ) && ( FeedData != "" ) )
            {
                FeedData = FeedData.replace(/&lt;/g,"<")            
                FeedData = FeedData.replace(/&gt;/g,">")
            }
         
	        //marqueecontent='<nobr><span class="StockUp">+ 555</span> <span class="StockDown">- 444 </span> <span class="StockNormal">888</span></nobr>';
	        
	        marqueecontent='<nobr>' + FeedData + '</nobr>'
	        if (iedom)
	            document.getElementById("temp").innerHTML = marqueecontent
        	//alert(marqueecontent)
	        if (iedom)
	        {
                cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
                cross_marquee.style.left=parseInt(marqueewidth)+8+"px"                
                cross_marquee.innerHTML=marqueecontent
                actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
            }
            else if (document.layers)
            {
                ns_marquee=document.ns_marquee.document.ns_marquee2
                ns_marquee.left=parseInt(marqueewidth)+8
                ns_marquee.document.write(marqueecontent)
                ns_marquee.document.close()
                actualwidth=ns_marquee.document.width
            }
	        //document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
	        cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"      
        }
    }
    else if (document.layers)
    {
        if (ns_marquee.left>(actualwidth*(-1)+8))
            ns_marquee.left-=copyspeed
        else
            ns_marquee.left=parseInt(marqueewidth)+8
    }
}

function populate()
{
    bFlag = true;   // flag to use in ajaxgetvalue
    if (iedom)
    {
        cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
        cross_marquee.style.left=parseInt(marqueewidth)+8+"px"        
        cross_marquee.innerHTML=marqueecontent
        actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
    }
    else if (document.layers)
    {
        ns_marquee=document.ns_marquee.document.ns_marquee2
        ns_marquee.left=parseInt(marqueewidth)+8        
        ns_marquee.document.write(marqueecontent)
        ns_marquee.document.close()
        actualwidth=ns_marquee.document.width
    }
    
    //cross_marquee.style.left = "0px"  /// for scroll right
    if( direction == "right" )    
        cross_marquee.style.left="0px"
//    else
//        cross_marquee.style.left=parseInt(actualwidth)*(-1)+8+"px"
     //alert("1");
    lefttime=setInterval("scrollmarquee()",40)
   
}