// JavaScript Document
var globalstadiumid;
var globallastid;

function savecomment()
{	
	text=document.formcomments.text.value;
	stadiumid=document.formcomments.stadiumid.value;
	name=document.formcomments.name.value;
	globalstadiumid=stadiumid;
	
	//Create a boolean variable to check for a valid MS instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	
    xmlhttp.onreadystatechange=function()
	{
      	if(xmlhttp.readyState==4)
        {
			globallastid=xmlhttp.responseText;
		 
			document.formcomments.text.value="";
			document.formcomments.name.value="";
			
			// Get date, month and year
			today=new Date();
			day=today.getDate().toString();
			jsmonth=today.getMonth();
			jsyear=today.getFullYear().toString();
			// Convert Month to 12 unit measure
			month=(jsmonth + 1).toString();
			// Output month in two digits
			if (month.length != 2) {
			month="0" + month  }
			// Output year in two digits
			year=jsyear;
			// Output day in two digits
			if (day.length != 2) {
			day="0" + day  }
			// Output date in YYMMDD format
			todayDate=(year +"-"+ month +"-"+ day);

			if (name!="")
			{
				datename="By "+name+" on "+ftn_convertdatetoslash(todayDate);
			}
			else
			{
				datename="On "+ftn_convertdatetoslash(todayDate);
			}
	
			livedel ="<a href='#footer' onclick='delcomment()'>Delete This Comment</a>";	
					
			document.getElementById("livecomment").innerHTML="<a name='newcomment' id='newcomment'></a><blockquote>"+ text +"<br/> "+datename+"<br/>"+livedel+"</blockquote>";
				
				
			document.getElementById("addcommentform").innerHTML="<p><a href='#newcomment'>Thank you, your comment has been added above.</a></p>";
				
        	}
      	};
	  	xmlhttp.open("GET","../../ajax/stadiumcomments-addnew.php?text="+escape(text)+"&name="+name+"&stadiumid="+stadiumid,true);
	 	xmlhttp.send(null);	
}

function delcomment()
{	
	document.getElementById("livecomment").innerHTML="";
	document.getElementById("addcommentform").innerHTML="<div id='addcommentform'><p>Your old comment has been deleted. You can add another one if you wish.</p><form name='formcomments' id='formcomments' method='Post'><table border='0'><tr><td align='right'><p>Comments : </p></td><td colspan='2'><textarea name='text' cols='40' rows='5'></textarea></td></tr><tr><td align='right'><p>Your Name (optional) : </p></td><td><input type='text' name='name' size='30'/></td><td align ='left'><input name='stadiumid' type='hidden' value='"+ globalstadiumid +"'/><input type='button' name='Submit' value='Save' onclick='savecomment()'/></td></tr></table></form></div>";

	
	//Create a boolean variable to check for a valid MS instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	xmlhttp.onreadystatechange=function()
    {
      	if(xmlhttp.readyState==4)
        {
			document.formcomments.text.value="";
			document.formcomments.name.value="";	
        }
   	};
	xmlhttp.open("GET","../../ajax/stadiumcomments-deletenew.php?id="+globallastid,true);
	xmlhttp.send(null);	
}

function seeallcomments()
{
	document.getElementById("previouscomments").innerHTML="<img alt='Loading' src='images/loading.gif' />";
	page=document.formcomments.page.value;
	
	//Create a boolean variable to check for a valid MS instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	xmlhttp.onreadystatechange=function()
    {
      	if(xmlhttp.readyState==4)
        {
			document.getElementById("previouscomments").innerHTML=xmlhttp.responseText;;
        }
   	};
	xmlhttp.open("GET","../../ajax/stadiumcomments-seeall.php?stadiumdbtoinc="+globalstadiumid,true);
	xmlhttp.send(null);		
}