function sendFeedback(){
	var name = document.getElementById('feedback_name');
	var msg = document.getElementById('feedback_msg');
	if (name.value == ""){
		name.focus();
		alert('Please enter your name/nickname');
		return;
	}
	if (msg.value == ""){
		msg.focus();
		alert('You have not entered a message');
		return;
	}
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			name.value = "";
			msg.value = "";
			msg.value = xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","ajax/feedback.php?name="+name.value+"&msg="+msg.value,true);
	name.value = "";
	msg.value = "Sending...";
	xmlhttp.send();
}

function sendPoll(ans,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var container = document.getElementById('poll_container');
	var shadeDiv = document.createElement('div');
	var animationDiv =  document.createElement('div');
	shadeDiv.setAttribute('id','poll_shade');
	animationDiv.setAttribute('id','poll_animation');
	container.appendChild(shadeDiv);
	container.appendChild(animationDiv);
	xmlhttp.open("GET","ajax/poll.php?id="+id+"&ans="+ans,true);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && ( xmlhttp.status==200 ||  xmlhttp.status==304 )){
			container.innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.send();
}

function saveBlog(){
	var xhr = new getXhr();
	var error = '';
	var url = 'ajax/saveblog.php';
	var mode = document.getElementById('blog_mode').value;
	if(mode != 'edit'){ return true; }
	var id = document.getElementById('blog_id').value;
	var title = document.getElementById('blog_title').value;
	if(title == ''){
		error += 'Required Field Empty: Title\n';
	};
	var category = document.getElementById('blog_category').value;
	var content = nicEditors.findEditor('blog_textarea').getContent();
	if(error != ''){
		var msg = 'Error:\n\n'+error;
		alert(msg);
		return false;
	}
	var params = 'xhr=1&check_submit=1&form[mode]='+mode+'&form[id]='+id+'&form[category]='+category+'&form[title]='+title+'&form[story]='+content;
	xhr.open("POST",url,true);
	
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.setRequestHeader("Content-length", params.length);
	xhr.setRequestHeader("Connection", "close");
	
	xhr.onreadystatechange=function(){
		if (xhr.readyState==4 && ( xhr.status==200 ||  xhr.status==304 )){
			//alert(xhr.responseText);
			if(xhr.responseText == "Saved!"){
				show('successbox');
			} else {
				alert(xhr.responseText);
			}
		}
	}
	
	xhr.send(params);
	return false;
}

function getXhr(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		return XMLHttpRequest();
	} else {// code for IE6, IE5
		return ActiveXObject("Microsoft.XMLHTTP");
	}
}
