/**
 * @author PacMan / Bob
 */

var xmlhttp_editfile;
var file_active = null;

function editFile_AJAX(id){
	xmlhttp_editfile = null;
	
	if(file_active != null){
		cancelFile_AJAX(file_active);
	}
	file_active = id;
	
	if (window.XMLHttpRequest){// code for all new browsers
		xmlhttp_editfile = new XMLHttpRequest();
	}else if (window.ActiveXObject){// code for IE5 and IE6
		xmlhttp_editfile = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp_editfile!=null){
		url = "js/AJAX/file_edit.php?id="+id;
		xmlhttp_editfile.onreadystatechange=state_Change_editFile;
		xmlhttp_editfile.open("GET",url,true);
		xmlhttp_editfile.send(null);
		return false;
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change_editFile(){
	if(xmlhttp_editfile.readyState==4){// 4 = "loaded"
		if(xmlhttp_editfile.status==200){// 200 = "OK"
			eval(xmlhttp_editfile.responseText)
		}else{
			alert("Problem retrieving XML data:" + xmlhttp_editfile.statusText);
		}
	}
}

var xmlhttp_cancelfile;

function cancelFile_AJAX(id){
	xmlhttp_cancelfile = null;	
	if (window.XMLHttpRequest){// code for all new browsers
		xmlhttp_cancelfile = new XMLHttpRequest();
	}else if (window.ActiveXObject){// code for IE5 and IE6
		xmlhttp_cancelfile = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp_cancelfile!=null){
		url = "js/AJAX/file_cancel.php?id="+id;
		xmlhttp_cancelfile.onreadystatechange=state_Change_cancelFile;
		xmlhttp_cancelfile.open("GET",url,true);
		xmlhttp_cancelfile.send(null);
		return false;
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change_cancelFile(){
	if(xmlhttp_cancelfile.readyState==4){// 4 = "loaded"
		if(xmlhttp_cancelfile.status==200){// 200 = "OK"
			eval(xmlhttp_cancelfile.responseText)
		}else{
			alert("Problem retrieving XML data:" + xmlhttp_cancelfile.statusText);
		}
	}
}


var xmlhttp_updatefile;

function updateFile_AJAX(id){
	xmlhttp_updatefile = null;	
	if (window.XMLHttpRequest){// code for all new browsers
		xmlhttp_updatefile = new XMLHttpRequest();
	}else if (window.ActiveXObject){// code for IE5 and IE6
		xmlhttp_updatefile = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp_updatefile!=null){
		name = document.getElementById('UFile_name').value;
		desc = document.getElementById('UFile_desc').value;
		
		url = "js/AJAX/file_update.php?id="+id+"&name="+name+"&desc="+desc;
		xmlhttp_updatefile.onreadystatechange=state_Change_updateFile;
		xmlhttp_updatefile.open("GET",url,true);
		xmlhttp_updatefile.send(null);
		return false;
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change_updateFile(){
	if(xmlhttp_updatefile.readyState==4){// 4 = "loaded"
		if(xmlhttp_updatefile.status==200){// 200 = "OK"
			eval(xmlhttp_updatefile.responseText)
		}else{
			alert("Problem retrieving XML data:" + xmlhttp_updatefile.statusText);
		}
	}
}