function loadAjax()
{
var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }

   if (!request)
     alert("Error initializing XMLHttpRequest!");
	 
	 return request;

}

function editAjax(comment, commentId)
{
	// show lightbox effect hide flashvideo and give the textbox
	document.getElementById('lightBox').style.display = 'block';
	document.getElementById('flashVideo').style.display = 'none';
	document.getElementById('blankPlayer').style.display = 'block';
	document.getElementById('commentEdit').style.display = 'block';
	document.getElementById('commenteditBox').innerHTML = '<span>Edit Comment</span><br /><form class="form_input_admin" method="post"><span style="font-size: 13px; color: #eee;">Comment :</span><textarea id="commentInput" style="height: 75px; width: 96.5%;"></textarea><input type="button" name="submit" value="Submit" onclick="submitEditedComment(' + commentId + ');" /> <input type="button" name="submit" value="Cancel" onclick="hideEdit();" /></form>';
	document.getElementById('commentInput').value = comment;
}

function hideEdit()
{
	// show lightbox effect hide flashvideo and give the textbox
	document.getElementById('lightBox').style.display = 'none';
	document.getElementById('flashVideo').style.display = 'block';
	document.getElementById('blankPlayer').style.display = 'none';
	document.getElementById('commentEdit').style.display = 'none';
}

function deleteComment(commentId)
{
	if (window.confirm('Are you sure you want to delete this comment \n This cannot be undone'))
	{
		var ajax = loadAjax();
		
		ajax.open('GET', '/admin/videos/delete?commentId=' + commentId);
		ajax.send(null);
		
		ajax.onreadystatechange = function()
		{
			if (ajax.readyState == 4)
			{
				document.getElementById('comment'+commentId).style.display = 'none';
				
			}
			else
			{
				document.getElementById('comment'+commentId).innerHTML = '<center><br /><img src="/images/ajax-loader.gif" /></center>';
			}
		}
	}
}

function submitEditedComment(commentId)
{
	var ajax = loadAjax();
	
	var comment = document.getElementById('commentInput').value;
	
	ajax.open('GET', '/admin/videos/submit?comment='+comment+'&commentId='+commentId);
	ajax.send(null);
	
	hideEdit();

	ajax.onreadystatechange = function()
	{
		if (ajax.readyState == 4)
		{
			document.getElementById('commentText'+commentId).innerHTML = comment;
			
		}
		else
		{
			document.getElementById('commentText'+commentId).innerHTML = '<center><br /><img src="/images/ajax-loader.gif" /></center>';
		}
	}
}

function loadContent(status, div)
{
	var number = 0;
	
	if (status != 4)
	{
		var engine = window.setInterval(
									function ()
									{
										if(number != 100)
										{
											number++;
											document.getElementById(div).innerHTML = '<center><br /><img src="/images/ajax-loader.gif" /> <br />'+number+'% done</center>';
										}
										else
										{
											number = 0;
											window.clearInterval(engine);
										}
									},

									// SET THE FADE TIME
									// 0 - Infiniti Lower the Number Faster it Renders
									225);
	}
}

/*
 * This will load a external page into the requested div
 */
function loadPage(page, div, content)
{
	var ajax = loadAjax();
	
	var atr = document.getElementById(content).value;
	
	page = page + atr;
	
	//alert(page);
	
	ajax.open('GET', page);
	
	ajax.send(null);
	
	var number = 0;
	
	ajax.onreadystatechange = function()
							  {
							      if (ajax.readyState == 4  )
								  {
									  window.clearInterval(engine);
									  document.getElementById(div).innerHTML = ajax.responseText;
								  }
							  }
	
	var engine = window.setInterval(
									function ()
									{
										if(number != 100)
										{
											number++;
											document.getElementById(div).innerHTML = '<center><br /><img src="/images/ajax-loader.gif" /> <br /><strong>'+number+'% Loaded</strong></center>';
										}
										else
										{
											number = 0;
											window.clearInterval(engine);
										}
									},

									// SET THE FADE TIME
									// 0 - Infiniti Lower the Number Faster it Renders
									85);
}