var idimage='';
var idvideo='';
function rssMaker(tag,page)
{

	sURL="http://www.d2videos.com/tags/make_tag_rss.php?"+
	"tag="+tag+
	"&page="+page;

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=xmlhttpChange
		xmlhttp.open("GET",sURL,true)
		xmlhttp.send(null)
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange=xmlhttpChange
			xmlhttp.open("GET",sURL,true)
			xmlhttp.send(null)
		}
	}
}

function xmlhttpChange()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			// ...some code here...
		}
		else
		{
			alert("Problem retrieving XML data")
		}
	}
}


function ShowHideConsole(id)
{
	el = document.getElementById(id);
	var display = el.style.display ? '' : 'none';
	el.style.display = display;
}

function Validate()
{

}

function resetRate(video_id)
{
	el = document.getElementById('img1'+video_id);
	el.style.display='none';
	el = document.getElementById('img2'+video_id);
	el.style.display='none';
	el = document.getElementById('img3'+video_id);
	el.style.display='none';
	el = document.getElementById('img4'+video_id);
	el.style.display='none';
	el = document.getElementById('img5'+video_id);
	el.style.display='none';

}
function showRate(score,video_id)
{

	if (score>0)
	{
		el = document.getElementById('img1'+video_id);
		el.style.display='';
	}

	if (score>1)
	{
		el = document.getElementById('img2'+video_id);
		el.style.display='';
	}

	if (score>2)
	{
		el = document.getElementById('img3'+video_id);
		el.style.display='';
	}

	if (score>3)
	{
		el = document.getElementById('img4'+video_id);
		el.style.display='';
	}

	if (score>4)
	{
		el = document.getElementById('img5'+video_id);
		el.style.display='';
	}

}

function loadtags(video_id)
{

	sURL="http://www.d2videos.com/admin/XMLHTTPfunc.php?function=loadtags"+
	"&Video_ID="+video_id;

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()

	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

	}


	if (xmlhttp)
	{
		xmlhttp.open("POST",sURL,true)
		xmlhttp.onreadystatechange=xmlhttpChangelvideo
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader('Content-Type','text/html; charset=utf-8');
		xmlhttp.send(null)
	}
	/*
	xmlhttp.open("POST", sURL, false);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader('Content-Type','text/html; charset=utf-8');
	xmlhttp.send(null);
	*/
	
}

function xmlhttpChangelvideo()
{
	// if xmlhttp shows "loaded"
	var loader = "<img src='http://www.d2videos.com/images/ajax-loader.gif'>";
	//document.getElementById(idimage).innerHTML=loader;
	
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{

			var RE = /<success>/;
			
			if(xmlhttp.responseText.match(RE)) {
				tags=xmlhttp.responseText.replace('<success>','');
				document.getElementById('tags'+idvideo).innerHTML=tags;
			}
			else {alert(xmlhttp.responseText);}
		}
		else
		{
			//alert("Problem retrieving XML data")
		}
	}
	else
	{
		//document.getElementById(idimage).innerHTML=loader;
	}
}


function addtag(id,video_id)
{
	var nothing='';
	idimage=id;
	idvideo=video_id;
	el = document.getElementById('addtag'+video_id).value;
	sURL="http://www.d2videos.com/admin/XMLHTTPfunc.php?function=add_tag"+
	"&Tag="+el+
	"&Video_ID="+video_id;

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()

	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

	}

	if (xmlhttp)
	{
		xmlhttp.open("POST",sURL,true)
		xmlhttp.onreadystatechange=xmlhttpChanget
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader('Content-Type','text/html; charset=utf-8');
		xmlhttp.send(null)
	}
}


function xmlhttpChanget()
{
	var nothing='';
	// if xmlhttp shows "loaded"
	var loader = "<img src='http://www.d2videos.com/images/ajax-loader.gif'>";
	document.getElementById(idimage).innerHTML=loader;
	
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{

			var RE = /<success>/;
			if(xmlhttp.responseText.match(RE)) {
				loadtags(idvideo);
				document.getElementById(idimage).innerHTML=nothing;
				ShowHideConsole('tagit'+idvideo);
				document.getElementById('addtag'+idvideo).value='';
			}
			else {alert(xmlhttp.responseText);}
			
		}
		else
		{
			//alert("Problem retrieving XML data")
		}
	}
	else
	{
		
	}
}



function banvideo(video_id)
{
	var nothing='';
	sURL="http://www.d2videos.com/admin/XMLHTTPfunc.php?function=ban_video"+
	"&Video_ID="+video_id;
	if (window.XMLHttpRequest)
	{
		var xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	xmlhttp.open("POST", sURL, false);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader('Content-Type','text/html; charset=utf-8');
	xmlhttp.send(null);
	var RE = /<success>/;
	if(xmlhttp.responseText.match(RE)) {
		alert('Video was banned!');
		//loadtags(video_id);
		//document.getElementById('addtag'+video_id).value='';
	}
	else {alert(xmlhttp.responseText);}

}

function rateFilm(score,video_id,rate_this)
{

	var sURL="http://www.d2videos.com/admin/XMLHTTPfunc.php?function=set_rate_video"+
	"&rate="+score+
	"&Video_ID="+video_id;
	var rank = '';

	if (window.XMLHttpRequest)
	{
		var xmlhttp=new XMLHttpRequest()

	}
	// code for IE
	else if (window.ActiveXObject)
	{
		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

	}


	xmlhttp.open("GET", sURL, false);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.setRequestHeader('Content-Type','text/html; charset=utf-8');


	xmlhttp.send(null);

	var RE = /<success>/;
	if(xmlhttp.responseText.match(RE)) {
		resetRate(video_id);
		rank=xmlhttp.responseText.replace('<success>','');
		showRate(rank,video_id);
		el = document.getElementById(rate_this);
		el.style.display='none';
		//alert(rank); /*window.location.reload();*/}
	}
	else { alert(xmlhttp.responseText);}
}


function addVideoView(video)
{

	sURL="http://www.d2videos.com/admin/XMLHTTPfunc.php?function=add_Video_View"+
	"&video="+video;

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=xmlhttpChange
		xmlhttp.open("GET",sURL,true)
		xmlhttp.send(null)
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange=xmlhttpChange
			xmlhttp.open("GET",sURL,true)
			xmlhttp.send(null)
		}
	}
}
