// JavaScript Document
function getcontent(){
	document.getElementById("new").value="";
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
		var inner=ajaxRequest.responseText;
		var parsed = inner.split('|');   
		document.getElementById("page").value=parsed[0];
		document.getElementById("category").value=parsed[2];
		document.getElementById("label").value=parsed[3];
		if(parsed[4]==1) {document.getElementById("shown").checked = true} else {document.getElementById("shown").checked=false;}
		
		var oEditor = FCKeditorAPI.GetInstance('contentbox');
		oEditor.SetHTML(parsed[1]);
		var theimg = document.getElementById("statusimg")
		theimg.src="../images/live.png"
		}
	}
	
	ajaxRequest.open("GET", "../scripts/getvalues.php?page="+document.getElementById('thepage').value+"&time="+new Date().getTime(), true);
	ajaxRequest.send(null); 
}

function update_draft_status() {
	document.getElementById("status").innerHTML="";
		
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
		var inner=ajaxRequest.responseText;
		if(inner) {
		document.getElementById("status").innerHTML=inner;
		}}
	}
	
	ajaxRequest.open("GET", "../scripts/check_draft.php?page="+document.getElementById('thepage').value+"&time="+new Date().getTime(), true);
	ajaxRequest.send(null); 
	
}

function edit_draft(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
		var inner=ajaxRequest.responseText;
		var parsed = inner.split('|');   
		
		
		document.getElementById("category").value=parsed[2];
		document.getElementById("label").value=parsed[3];
		var oEditor = FCKeditorAPI.GetInstance('contentbox');
		oEditor.SetHTML(parsed[1]);
		var theimg = document.getElementById("statusimg")
		theimg.src="../images/draft.png"
		document.getElementById("shown").checked = false;
		}
	}
	
	ajaxRequest.open("GET", "../scripts/getvalues.php?page="+document.getElementById('thepage').value+"_draft&time="+new Date().getTime(), true);
	ajaxRequest.send(null); 
}

function delete_draft(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
		var inner=ajaxRequest.responseText;
		
		document.getElementById("status").innerHTML="";
		alert(inner);
		getcontent();
		}
	}
	
	ajaxRequest.open("GET", "../scripts/deletedraft.php?page="+document.getElementById('thepage').value+"&time="+new Date().getTime(), true);
	ajaxRequest.send(null); 
	
}