/**
 * @author Lyov
 * @site 	 http://naghashyan.com
 * @email  levon@naghashyan.com	
 * @year   2009-2010
 **/
var videoId = 0;

function makeRequest(url, _callbackFunc, params) {
/**
 * @sending ajax request
 * parmas
 * url
 * callbackFunction
**/	
	var httpRequest;

	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}
	
	if (!httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	httpRequest.onreadystatechange = function() { _callbackFunc(httpRequest); };
	if(params){
		url += "?"+params;	
	}

	httpRequest.open('GET', url, true);
	httpRequest.send(null);

}

function changeGif(id, videoId, dir){

	var path = stream_static_path+"/data/";
	document.getElementById(id+videoId).src = path+dir+"thumb/"+videoId+".gif";
}
function changeJpg(id, videoId, dir){
	var path = stream_static_path+"/data/";
	document.getElementById(id+videoId).src = path+dir+"thumb/"+videoId+"_190_145.jpg";
}
function confirmAction(id, cmd) {
	videoId = id;
	this.cmd = cmd;
	if(cmd == "delete"){
		if(confirm("Do you really want delete video?")){  	
	    	window.location = static_path+"/go/admin/do_deletevideo/"+videoId;
	    }
	}
	if(cmd == "featured"){
		
		if(confirm("Do you really want featured video?")){  	
	    	window.location = static_path+"/go/admin/do_setfeatured/"+videoId;
	    }
	}
	if(cmd == "disable"){
 	
	   var reasonWindow = window.open(static_path+'/go/admin/reasons/1','_blank','width=250,height=100');

	}
	if(cmd == "censored"){
		var reasonWindow = window.open(static_path+'/go/admin/reasons/1','_blank','width=250,height=100');

	}
    
	
 }
function doConfirmation(reasonId){

	if(this.cmd == "censored"){
		window.location = static_path+"/go/admin/do_setcensored/"+this.videoId+"/"+reasonId;
	}
	if(this.cmd == "disable"){
		window.location = static_path+"/go/admin/do_setdisable/"+this.videoId+"/"+reasonId;
	}
}


function fbCheck(fbStatusUpdateCheck){
	
	if(!fbStatusUpdateCheck){
		
		window.open ('http://www.facebook.com/authorize.php?api_key=46fc3f4ac5945f7ae95a9dd29adddc91&v=1.0&ext_perm=status_update');
		document.getElementById("allowed").style.display = "block";
	  document.getElementById("allow").value = "Try Again";
	 return false;
	}else{
		 params = 0;
		 makeRequest('fblogin/do_check_status/', evalStatusCheck, params);
	}
		
	
	
}
function evalStatusCheck(httpRequest) {
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			eval('var data = ' + httpRequest.responseText);	

	        if (data.status_check == 1) {
	        	location.reload(true);
	        }else{
	        	var errElem = document.getElementById("allow_err");
	        	errElem.style.display = "block";	
	        }
		}
	}
}