 
  /*--------------[Web Ticker Control Summary]---------------------------------------------------------------------------------*
     * Control  Name : Web Ticker
     * Creation Date : 11/7/2009
     * Created By    : Swathi
     * How to Use    : Add a DIV tag where you want the Ticker to appear and call the Script Function:ajax_ticker
                         with text file to be read passed as parameter. To change the Scroll direction set TICKER_RIGTHTOLEFT 
                         to true or false.To Increase the Speed of the Ticker Set TICKER_SPEED.To set the Style use TICKER_STYLE
                         To Pause the Tricker set TICKER_PAUSED to false.
     *                  
     * ------------------------------------------------------------------------------------------------------------------------* */
    

var strp = new Array();
var str=new Array();
var str2=new Array();
var str3=new Array();
var messages=new Array();
TICKER_CONTENT="";
TICKER_RIGHTTOLEFT = false;
TICKER_SPEED = 1;
TICKER_PAUSED = false;
var currentmessage1=0;
var currentmessage2=0;
div1=document.createElement("DIV");
div2=document.createElement("DIV");

// -------------------------------------------------------------------
// Main Ajax Ticker Object function
// -------------------------------------------------------------------

function ajax_ticker()//xmlfile)
{
    //this.xmlfile=xmlfile //Variable pointing to the local ticker txt file
    this.ajaxobj=createAjaxObj()
    this.getXMLfile()
}
// -------------------------------------------------------------------
//Function to start the ticker
//ticker_start();
// -------------------------------------------------------------------

function ticker_start() {

	var tickerSupported = false;
	TICKER_WIDTH = document.getElementById("TICKER").style.width;
	var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";

	// Firefox // IE //Opera //Safari
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1||navigator.userAgent.indexOf("MSIE")!=-1 ) {
	            document.getElementById("TICKER").appendChild(div1);
                document.getElementById("TICKER").appendChild(div2);
			tickerSupported = true;
	}

	if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else {
		
		document.getElementById("TICKER").style.display="block";
            div1.innerHTML=TICKER_CONTENT;
            div2.innerHTML=TICKER_CONTENT;
            div1.style.whiteSpace="nowrap";
            div1.style.position="absolute";
            div2.style.whiteSpace="nowrap";
            div2.style.position="absolute";
            div1.style.left=0;
            div2.style.left=div2.offsetWidth +'px';
		//-----------revives the last viewed message.------------------//
		currentmessage1=revivelastmsg1();
        currentmessage2=revivelastmsg2();
        if((!isNaN(currentmessage1))&&currentmessage1!=""&&currentmessage1!=null)
        {
                 div1.style.left=currentmessage1+'px';
        }
         if((!isNaN(currentmessage2))&&currentmessage2!=""&&currentmessage2!=null)
        {
                 div2.style.left=currentmessage2+'px';
        }
		TICKER_tick();
		
	}
}
function TICKER_tick()
 {

var d=(TICKER_RIGHTTOLEFT) ? 1 : -1;
  
 if(!TICKER_PAUSED)
{
     //1
      div1.style.left = parseInt(div1.style.left) + d * TICKER_SPEED+ 'px';
     //2
      div2.style.left = parseInt(div2.style.left) + d * TICKER_SPEED + 'px';
}
//1
    if(d * parseInt(div1.style.left) >= div1.offsetWidth )
        div1.style.left= parseInt(div2.style.left) - d * div2.offsetWidth + 'px';
  //2 
  if(d * parseInt(div2.style.left) >= div2.offsetWidth)
        div2.style.left = parseInt(div1.style.left) - d * div2.offsetWidth + 'px';

   

    window.setTimeout("TICKER_tick()",30);
}

//-----------------------------------------------------------------------//
//Function to create Ajaxobj(windows httprequest object or activeX object)
//-----------------------------------------------------------------------//
function createAjaxObj()
{
    var httprequest=false
    if (window.XMLHttpRequest)
    { // if Mozilla, Safari etc
        httprequest=new XMLHttpRequest()
        if (httprequest.overrideMimeType)
        httprequest.overrideMimeType('text/xml')
    }
    else if (window.ActiveXObject){ // if IE
    try {
        httprequest=new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e){
    try{
        httprequest=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e){}
    }
    }
    return httprequest
}
// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Gets contents of xml file and parse it using JavaScript DOM methods 
// -------------------------------------------------------------------

ajax_ticker.prototype.initialize=function()
{ 

    var laststr="",style1="",style2="";
    var xmldata="";
    if (this.ajaxobj.readyState == 4)
    { //if request of file completed
    if (this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1)
    { //if request was successful
       
    xmldata=this.ajaxobj.responseText;
    var count=0;
    strp=xmldata.split('\n');
//    for(var i=0;i<strp.length;i++)
//    {
//        str[i]=strp[0].split('</br>');
//    }
    str=strp[0].split('<br/>');
     for(var i=0;i<str.length;i++)
     {
        str3[i]=str[i].split('%');
     }
    for(var j=0;j<str3.length;j++)
    {
        if(str3[j].length>1)
        {
       
            str2[count]=str3[j][0].split('\t');
            count+=1
        }
        
    }
    for(var k=0;k<str2.length;k++)
    {
            if(str2[k].length>=3)
            {
           
            laststr= str2[k][2];
                if(laststr.length>1)
                {
                if(laststr.substring(0,1)=='-')
                {style1="<sub style='color: #FF0000;  font-family: Arial;'>";style2="</sub>";}
                else
                {style1="<sup style='color: #257E02; font-family: Arial;'>";style2="</sup>";}
                }
             
     
            messages="<font style='font-family: Arial; font-size: 13px; color:#000000;'>"+messages+"&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;"+str2[k][0]+"&nbsp; &nbsp;&nbsp; &nbsp;"+"<font color='#0066FF'>"+str2[k][1]+"</font>"+"&nbsp; &nbsp;"+style1+str2[k][2]+"%"+style2+"</font>";
            }
    }
 
TICKER_CONTENT=messages;
ticker_start();

}
}
}



// -------------------------------------------------------------------
// getXMLfile()- Use Ajax to fetch xml file (txt)
// -------------------------------------------------------------------

ajax_ticker.prototype.getXMLfile=function(){
    if (this.ajaxobj){
        var instanceOfTicker=this
        var url="../webpages/proxy.aspx"; //this.xmlfile+"?bustcache="+new Date().getTime()
        this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
        this.ajaxobj.open('GET', url, true)
        this.ajaxobj.send(null)
    }
}

//---------------------------------------------------------------------//
//get the last message viewed stored in cookie
//---------------------------------------------------------------------//
function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = ""
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
    if (offset != -1) {
        offset += search.length
        end = document.cookie.indexOf(";", offset)
    if (end == -1)
        end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
}
//-----------------------------------------------------------------------//
//Save last message viewed in cookie
//-----------------------------------------------------------------------//
function savelastmsg(){

 currentmessage1=div1.style.left;
 currentmessage2=div2.style.left;
document.cookie="lastmsgnum1="+currentmessage1
document.cookie="lastmsgnum2="+currentmessage2

}


//-----------------------------------------------------------------------//
//store last message viewed in current message
//-----------------------------------------------------------------------//
function revivelastmsg1(){
currentmessage1=parseInt(get_cookie("lastmsgnum1"));

return currentmessage1;
}
function revivelastmsg2(){
currentmessage2=parseInt(get_cookie("lastmsgnum2"));

return currentmessage2;
}
//------------------------------------------------------------------------//
//on unload save the position
//-------------------------------------------------------------------------//
window.onunload=savelastmsg;