function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if( browser == "Microsoft Internet Explorer" ){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = createRequestObject();
var lock = 0;

function clickAnswer( theAnswer ) {
	var pageRef = window.location.pathname;
	if( theAnswer == 'yes' ){
		document.fb_form.comment_yes.value = document.fb_form.DefaultComment.value;
	} else {
		document.fb_form.comment_no.value = document.fb_form.DefaultComment.value;
	}
	document.getElementById('feedback').style.display = 'none';
	document.getElementById('feedback_' + theAnswer ).style.display = 'block';
	http.open('GET', '/feedback.php?ref=' + pageRef + '&answer=' + theAnswer, false);
	http.send(null);
}

function commentFocus( theField ) {
	if( theField.value == theField.form.DefaultComment.value ) {
		theField.style.color = '#000';
		theField.value = '';
	}
}

function commentBlur( theField ) {
	if( theField.value == '' ) {
		theField.style.color = '#888';
		theField.value = theField.form.DefaultComment.value;
	}
}

function commentKeyup( theField ) {
	if( theField.value != '' ) {
		theField.form.elements['btn_' + theField.name].disabled = false;
	} else {
		theField.form.elements['btn_' + theField.name].disabled = true;
	}
}

function sendComment( theAnswer ) {
	var pageRef = window.location.pathname;
	var f = document.fb_form;
	var comment = document.fb_form.elements['comment_' + theAnswer].value;
	document.getElementById('feedback_' + theAnswer ).style.display = 'none';
	document.getElementById('feedback_thanks').style.display = 'block';
	theData = 'ref=' + encodeURI(pageRef) + '&answer=' + theAnswer + '&comment=' + encodeURI(comment);
	http.open('POST', '/feedback.php', false);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.send( theData );
}

function selectReason() {
	var pageRef = window.location.pathname;
	var f = document.fb_form;
	var theAnswer = f.reason[ f.reason.selectedIndex ].value;
	if( theAnswer != '' ){
		document.getElementById('feedback_no2').style.display = 'none';
		document.getElementById('feedback_no3').style.display = 'block';
		http.open('GET', '/feedback.php?ref=' + pageRef + '&answer=' + theAnswer, false);
		http.send(null);
	} else if( f.comment_no.value == f.DefaultComment.value ){
		f.btn_comment_no.disabled = true;
	}
}
