function checksendmail()
{
	var a = document;
	if(a.getElementById('txt_mail_name').value == "")
	{
		alert("Bạn chưa nhập tên");
		return false;		
	}
	if(a.getElementById('txt_email').value == "")
	{
		alert("Bạn chưa nhập email");
		return false;
	}
	else
	{
		if(!emailvalid(a.getElementById('txt_email').value))
		{
			alert("Email không hợp lệ");
			return false;
		}
	}
	if(a.getElementById('txt_mail_content').value == "")
	{
		alert("Bạn chưa nhập nội dung");
		return false;
	}
	return true;
}
function checksendcomment()
{
	var a =  document;
	if(a.getElementById('txt_comment_name').value == "")
	{
		alert("Bạn chưa nhập tên");
		return false;		
	}
	if(a.getElementById('txt_comment_mail').value == "")
	{
		alert("Bạn chưa nhập email");
		return false;
	}
	else
	{
		if(!emailvalid(a.getElementById('txt_comment_mail').value))
		{
			alert("Email không hợp lệ");
			return false;
		}
	}
	if(a.getElementById('txt_comment_content').value == "")
	{
		alert("Bạn chưa nhập nội dung");
		return false;
	}
	return true;
}
function emailvalid(str){
    var myRegExp = /[a-z0-9-.]{1,30}@[a-z0-9-]{1,65}.(com|net|org|info|biz|([a-z]{2,3}.[a-z]{2}))/ ;
    return myRegExp.test(str)
}
function submitmail(url_post_mail)
{
	if(checksendmail())
	{
		var poststr = "txt_mail_name=" + encodeURI( document.getElementById("txt_mail_name").value ) +
					  "&txt_mail_content=" + encodeURI( document.getElementById("txt_mail_content").value ) +	
                      "&txt_email=" + encodeURI( document.getElementById("txt_email").value );
      	makePOSTRequest(url_post_mail, poststr);

	}	
}
function submitcomment(url_post_comment)
{
	if(checksendcomment())
	{
		var poststr = "txt_comment_name=" + encodeURI( document.getElementById("txt_comment_name").value ) +
					  "&txt_comment_mail=" + encodeURI( document.getElementById("txt_comment_mail").value ) +
                      "&txt_comment_content=" + encodeURI( document.getElementById("txt_comment_content").value );
      	makePOSTRequest(url_post_comment, poststr);

	}	
}
var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
     	// set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) 
  {
     if (http_request.status == 200) 
        alert('Cảm ơn bạn đã gửi yêu cầu.');            
     else 
        alert('Không thể gửi yêu cầu tới dịch vụ.');
     
  }
}
