//var reqSession=GetXmlHttpObject();
var checkSession = false;

function showSession(url) {

	url = url + "?rand=" + Math.floor(Math.random()*1001);
	if(checkSession == false) {
		reqSession = GetXmlHttpObject();
		if (reqSession == null) {
			checkSession = false;
	  		return;
	  	}

	  	checkSession = true;

		reqSession.onreadystatechange = function () {

			stateChangedSession(reqSession);
			try {
				if (reqSession.readyState == 4) {
					reqSession.abort();
					reqSession = null;
				}
			}
			catch(ex) {

			}
		};

		reqSession.open("GET",url,true);
		reqSession.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
		reqSession.setRequestHeader("Cache-Control", "no-cache");
		reqSession.send(null);
	}
}


function stateChangedSession(reqSession){
	if (reqSession.readyState==4){
  		var result = reqSession.responseText;
  		try {
	  		var arrIndex = result.split("#");
			var arrValues = arrIndex[1].split(";");
			window.document.getElementById("session_status").innerHTML = arrStatus[parseFloat(arrValues[0])];
			window.document.getElementById("session_date").innerHTML = arrValues[1];
			window.document.getElementById("session_current").innerHTML = arrValues[2];
			/*
			 * B.M.W - Currently, VTG wants to trade from 8:00AM - 7:00AM
			 */
			/*
			window.document.getElementById("session_from_to").innerHTML = arrValues[3];
			if(arrValues[3]!=""){
				window.document.getElementById("session_period").style.display="";
				window.document.getElementById("session_period").style.visibility="";
			}else{
				window.document.getElementById("session_period").style.display="none";
				window.document.getElementById("session_period").style.visibility="hidden";
			}
			*/

			window.document.getElementById("session_from").innerHTML = arrValues[3];
			window.document.getElementById("session_to").innerHTML = arrValues[4];

			arrValues = null;
			arrIndex = null;
		}catch(e) {
		}
		result = null;
		checkSession = false;
  	}
}

var hh, mm, ss, time, dtSession;
function getSessionTime(){
	dtSession  = new Date();
	hh = dtSession.getHours();
	mm = dtSession.getMinutes();
	ss = dtSession.getSeconds();
	dtSession = null;
	time = hh;
	if(hh<10){
		time = "0" + time;
	}
	if(mm<10){
		time += ":0" + mm;
	}else{
		time += ":" + mm;
	}
	if(ss<10){
		time += ":0" + ss;
	}else{
		time += ":" + ss;
	}
	if(hh>=12){
		time += " PM";
	}else{
		time += " AM";
	}

	window.document.getElementById("session_time").innerHTML = time;
}