function xmlhttpPost(strURL, getString) {
  var xmlHttpReq = false;
  var self = this;
  // Mozilla/Safari
  if (window.XMLHttpRequest) {
      self.xmlHttpReq = new XMLHttpRequest();
  }
  // IE
  else if (window.ActiveXObject) {
      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }
  self.xmlHttpReq.open('POST', strURL, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.send(getString);
}
   
function flash_movie_display(fixture_id, race_id, division, div_id, type)
{
 if (type == "result") {
	  var so = new SWFObject("player.swf", "movieplayer", "360", "270", "7", "#EEF6EF");
  } else if (type == "horse_det") {
  	  var so = new SWFObject("player.swf", "movieplayer", "360", "270", "7", "#FFFFFF");
  } else if (type == "special") {
  	  var so = new SWFObject("player.swf", "movieplayer", "540", "360", "7", "#FFFFFF");
  }
  //so.addVariable("MM_ComponentVersion", "1");
  /*
  so.addVariable("serverName", "secure.hostireland.com");
  so.addVariable("appName", "media.p2p.ie/" + fixture_id);
  if (division == ""){
	  so.addVariable("streamName", race_id);
  }
  else {
	  so.addVariable("streamName", race_id + "_" + division);
  }
  */
  //so.addVariable("serverName", "media.p2p.ie");
  //so.addVariable("serverName", "p2p-media.p2p.ie");
  //so.addVariable("appName", "vod");
  //so.addVariable("appName", "cfx/st");
  //so.addVariable("isLive", "false");
  //so.addVariable("bufferTime", "0");
  //so.addVariable("skinName", "Clear_Skin_3");
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addVariable('provider','rtmp');
  so.addVariable('streamer','rtmp://media.p2p.ie/vod');
  
  if (division == ""){
   //so.addVariable("streamName", "media.p2p.ie/streams/" + fixture_id + "/" + race_id);
   so.addVariable('file','media.p2p.ie/streams/' + fixture_id + '/' + race_id + '.flv');
    //so.addVariable("streamName", fixture_id + "/" + race_id);
  }
  else {
   //so.addVariable("streamName", "media.p2p.ie/streams/" + fixture_id + "/" + race_id + "_" + division);
   so.addVariable('file','media.p2p.ie/streams/' + fixture_id + '/' + race_id + '_' + division + '.flv');
    //so.addVariable("streamName", fixture_id + "/" + race_id + "_" + division);
  }
  //so.addVariable("autoPlay", "true");
  //so.addVariable("autoRewind", "false");
  //so.useExpressInstall('expressinstall.swf');
  so.addVariable('autostart', 'true');
  so.addVariable('plugins','adttext');
  so.addVariable('adttext.config', 'http://www.p2p.ie/advert.xml');
  so.write(div_id);
  if (type == "result") {
	 // change_video_link("video_link"+division, "hide", fixture_id, race_id, division, div_id, type);
  	/*
	  var left_content = document.getElementById('vid_content_left'+division);
	  var right_content = document.getElementById('vid_content_right'+division);
	  var vid_div = document.getElementById(div_id);
	  vid_div.style.width = "50%";
	  left_content.style.display = "inline";
	  left_content.style.width = "25%";
	  right_content.style.display = "inline";
	  right_content.style.width = "25%";
	  */
  } else {
  	 // change_video_link("video_link_"+race_id +"_"+division, "hide", fixture_id, race_id, division, div_id, type);
  }
  /*
  var member_id = document.member_id.member_id.value;
  getString = 't='+type+'&r='+race_id+'&d='+division+'&m='+member_id;
  strURL = 'track_vid_view.asp';
  xmlhttpPost(strURL, getString);
  */

}

function flash_movie_display_short(fixture_id, race_id, division, div_id, type, gs)
{
	flash_movie_display(fixture_id, race_id, division, div_id, type);
	setTimeout("flash_movie_hide('"+fixture_id+"', '"+race_id+"', '"+division+"', '"+div_id+"', '"+type+"', 'not', '"+gs+"')", 5000);
	var autoClose = (type == "result" ? false : true);
	setTimeout( "restoreScreen(" + autoClose + ")", 5100);
}

function restoreScreen (autoClose)
{
	var autoClose = (autoClose) ? autoClose : false;
	if ( autoClose && document.getElementById("vidmessage") != null )
	{
		removeMessageArea ( "vidmessage", null );
	}
	alert('Sorry, you must be a member to view the whole video."\nTo login or register use the form at the top of the screen.')	
}
function flash_movie_hide(fixture_id, race_id, division, div_id, type, logged_in, gs)
{
	var vid_div = document.getElementById(div_id);
	if (type == "result") {
		if (logged_in == "not") {
			if ( vid_div != null )
			{
				vid_div.innerHTML = "";
			}
			/*
			document.getElementById(div_id).innerHTML = "<a style=\"color: #FF9900;\" href=\"members_login.asp?msg=not+logged+in&rp=results.asp&gs=key="+race_id+"\">Click here to log in</a>";
			*/
		} else {
			vid_div.innerHTML = "(viewed)";
		}
		/*
		var left_content = document.getElementById('vid_content_left'+division);
	    var right_content = document.getElementById('vid_content_right'+division);
	    left_content.style.display = "none";
		left_content.style.width = "0px";
	    right_content.style.display = "none";
		right_content.style.width = "0px";
		vid_div.style.width = "100%";
		*/
		change_video_link("video_link"+division, "show", fixture_id, race_id, division, div_id, type, logged_in);
	} else if (type == "horse_det") {
		document.getElementById(div_id).innerHTML = ""; 
		/*
		if (logged_in == "not") {
			document.getElementById(div_id).innerHTML = "<a style=\"color: #FF9900;\" href=\"members_login.asp?msg=not+logged+in&rp=horse_det.asp&gs="+gs+"\">Click here to log in</a>";
		} else {
			document.getElementById(div_id).innerHTML = "(viewed)";
		}
		change_video_link("video_link_"+race_id+"_"+division, "show", fixture_id, race_id, division, div_id, type, logged_in, gs);
		*/
	}
}

function change_video_link(name, status, fixture_id, race_id, division, div_id, type, logged_in, gs)
{
	/*
	if (type == "result") {
		if (status == "hide"){
			document.getElementById(name).innerHTML = "Hide the Video";
			document.getElementById(name).onclick = function() {flash_movie_hide(fixture_id, race_id, division, div_id, type)};
		}
		if (status == "show"){
			if (logged_in == "not") {
				document.getElementById(name).innerHTML = "View Race Finish";
				document.getElementById(name).onclick = function() {flash_movie_display_short(fixture_id, race_id, division, div_id, type, logged_in, gs)};
			} else {
				document.getElementById(name).innerHTML = "View Race Finish";
				document.getElementById(name).onclick = function() {flash_movie_display(fixture_id, race_id, division, div_id, type)};
			}
		}
	} else {
		if (status == "hide"){
			document.getElementById(name).innerHTML = "HIDE";
			document.getElementById(name).onclick = function() {flash_movie_hide(fixture_id, race_id, division, div_id, type)};
		}
		if (status == "show"){
			if (logged_in == "not") {
				document.getElementById(name).innerHTML = "<img border=\"0\" src=\"images/video_guy.jpg\">";
				document.getElementById(name).onclick = function() {flash_movie_display_short(fixture_id, race_id, division, div_id, type, logged_in)};
			} else {
				document.getElementById(name).innerHTML = "<img border=\"0\" src=\"/images/video_guy.jpg\">";
				document.getElementById(name).onclick = function() {flash_movie_display(fixture_id, race_id, division, div_id, type)};
			}
		}
	}
	*/
}



