/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function comment() {
// Optional: Show a waiting message in the layer with ID ajax_response
//document.getElementById('login_response').innerHTML = "Loading..."
	$("#msgbox").removeClass().addClass('messagebox').text('Please wait ....').fadeIn(2000);


// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var comment = encodeURI(document.getElementById('comment').value);
var fkmember = encodeURI(document.getElementById('fkmember').value);
var fkpost = encodeURI(document.getElementById('fkpost').value);
//nocache = Math.random();


//http.open('get', 'comment.asp?comment='+comment);
http.open('get', '../comment.asp?comment='+comment+'&fkmember='+fkmember+'&fkpost='+fkpost);


http.onreadystatechange = loginReply;


http.send(null);


}










function loginReply() {
if(http.readyState == 4){
var response = http.responseText;


if(response == 0){
//document.getElementById('login_response').innerHTML = 'Login failed! Verify user and password';

$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Username Not Correct .....').addClass('messageboxerror').fadeTo(900,1);
			});
} 
else if (response == 1){
//document.getElementById('login_response').innerHTML = '<font color="#FF0000"><b>Login failed! Verify  password</b></font>';

$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Please Login Before Comment .....').addClass('messageboxerror').fadeTo(900,1,
			 function()
			  { 
			  	 //redirect to secure page
				 document.location='http://blog.siamsport.co.th/';
			  });
			});

}
else {
$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Comment Sucess !!').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='index.asp';
			  });
			  
			});
}
//document.getElementById('login_show').innerHTML = ""
//document.getElementById('login_response').innerHTML = response;

}
}


