﻿
	function stopStartPostLoading(obj){
	    
	    //alert(postInterval);
	    if (postInterval){
	        isRunning=false;
	        clearInterval(postInterval);
	        postInterval=null;
	        if(obj){
	            obj.innerHTML = "Play"
	            obj.style.backgroundImage="url(images/icons/play.gif)";
	        }
	    }
	    else {
	        isRunning=true;
	        postInterval = setInterval("loadXMLDoc('getposts','tdShouts')", 3000);
	        if(obj){
	            obj.innerHTML = "Pause"
	            obj.style.backgroundImage="url(images/icons/pause.gif)";
	        }
	    }
	    
	}
	
	function postMessage(){
	/*
	    if (stock != ""){
	        var postedStock = document.forms["frmPostShout"]["txtStockShouted"].value;
	        if (postedStock.toLowerCase() != stock.toLowerCase()){
	            if (!confirm("You are posting about " + postedStock + " while you are on the " + stock + " shout board, are you sure you want to do that?\nYou won't see your message unless you go to the homepage.")){
	                return false;
	            }
	        }
	    }
	*/
	    if (document.forms["frmPostShout"]["txtComment"].value != ""){
	        document.getElementById("tblPostingTable").style.display="none";
	        document.getElementById("divPostAlert").style.display = "";
		    document.getElementById("divPostAlert").innerHTML = "<img src='images/ajax-loader.gif'> Posting Message...";
	        loadXMLDoc('postmessage','postmessage');
	    }
	    //else{
	    //    alert("Enter the stock symbol you are shouting.");
	    //    document.forms["frmPostShout"]["txtComment"].focus();
	    //}
	}
	
	function reShowInterface(){
	    document.getElementById("divPostAlert").innerHTML = "";
	    document.getElementById("divPostAlert").style.display = "none";
        document.getElementById("tblPostingTable").style.display="";
		document.forms["frmPostShout"]["txtComment"].focus();
	}
	
	var xmlhttp = new Array;
	var showInterface=false;
	function loadXMLDoc(query, divObj){
	    //alert("QUERY CALLED: " + query + " " + divObj);
	
		xmlhttp[divObj] = null
		
		// code for Mozilla, etc.
		try {
			xmlhttp[divObj]=new XMLHttpRequest()
		} catch (e) {
			// code for IE
			try {
				xmlhttp[divObj]=new ActiveXObject("MSXML2.XMLHTTP.4.0")
			} catch (e) {
				xmlhttp[divObj]=new ActiveXObject("Microsoft.XMLHTTP")
			}
		}
		
		if (xmlhttp[divObj]!=null){
		        if (divObj != "postmessage"){
				    objWindow = document.getElementById(divObj);
				}
				
				xmlhttp[divObj].onreadystatechange=function(){
						if (xmlhttp[divObj].readyState==4){
							if (xmlhttp[divObj].status==200){
								//alert("CHECK TYPE:" + divObj)
		                        if (divObj != "postmessage"){
	                                var stockChartIsOpen=false;
                                    try {
                                        if(document.getElementById("divMiniQuote").style.display==""){
                                            stockChartIsOpen=true;
                                        }
                                    }catch(er){
                                    
                                    }
		                            if (xmlhttp[divObj].responseText == "nothing new"){
		                                //
	                                }
	                                else{
	                                    if (!stockChartIsOpen){
	                                        document.getElementById(divObj).innerHTML = (xmlhttp[divObj].responseText);
	                                       
	                                        SoundNewMessage(xmlhttp[divObj].responseText)
	                                    }
		                            }
		                            try{
	                                    if (!stockChartIsOpen){
		                                    document.getElementById("divUpdateTime").innerHTML = "updated: " + (new Date()).toString();
		                                }
								    }catch(er){}
		                            /*
		                            if(showInterface){
		                                //alert(divObj + " : " + showInterface);
								    }*/
								}
								else{
								    if (xmlhttp[divObj].responseText == "login user"){
								        window.location.href="Login.aspx?msg=Please+log+into+StockShouter+to+post."
								    }
								    else{
								        //message posted, reload messages...
								        //-----------------------------------------
								        //document.forms["frmPostShout"]["txtStockShouted"].value = stock.toUpperCase();
								        document.forms["frmPostShout"]["txtComment"].value = "";
								        if (stock != "") {
								           //document.forms["frmPostShout"]["txtComment"].value =  "$" + stock.toUpperCase();
								        }
								        
								        var newHTML = xmlhttp[divObj].responseText;
								        if (newHTML != "nothing new"){
								            document.getElementById("tdShouts").innerHTML = newHTML; 
	                                        soundManager.play('select');   
								        }
								        
								        //setTimeout('reShowInterface()',2000);
								        reShowInterface();
								    }
								}
							}else {
							    if (divObj != "postmessage"){
								    document.getElementById(divObj).innerHTML = "<img src='images/ajax-loader.gif' /> Loading Page, Please Wait...";
								}
							}
						}
						else{
						   // alert(xmlhttp[divObj].status);
						}
					}
					/*
				if (divObj == "postmessage"){
				    showInterface=false;
				    clearInterval(postInterval);
				}*/
				
				var cm = "";
				var sm = "";
				try {
				    //sm = document.forms["frmPostShout"]["txtStockShouted"].value;
				    cm = document.forms["frmPostShout"]["txtComment"].value
				    if (stock != ""){
				        cm = "$" + (stock).toUpperCase() + ": " + cm;
				    }
				}
				catch(er){
				
				}
				
				xmlhttp[divObj].open("GET","_shoutLookup.aspx?trader="+theTrader+"&stock="+stock+"&type=" + query + "&cm=" + encodeURIComponent(cm) + "&sm=" + encodeURIComponent(sm) + "&nc=" + (new Date()),true)
				
				xmlhttp[divObj].send(null);
				
		} else {
			alert("Your browser does not support XMLHTTP.")
		}
	}
        
        function SoundNewMessage(html){
            var rArray = html.split(";;*;;");
            if (rArray[1] != maxMessageID){
                soundManager.play('select');
            }
        }



        function Set_Cookie(name, value, expires, path, domain, secure){
            // set time, it's in milliseconds
            var today = new Date();
            today.setTime( today.getTime() );

            /*
            if the expires variable is set, make the correct
            expires time, the current script below will set
            it for x number of days, to make it for hours,
            delete * 24, for minutes, delete * 60 * 24
            */
            if ( expires ){
                expires = expires * 1000 * 60 * 60 * 24;
            }
            var expires_date = new Date( today.getTime() + (expires) );

            document.cookie = name + "=" +escape( value ) +
            ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
            ( ( path ) ? ";path=" + path : "" ) +
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ( ( secure ) ? ";secure" : "" );
        }
