var http = createRequestObject();

function createRequestObject() {
        var xmlhttp;
        try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
        catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
        catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
        xmlhttp=new XMLHttpRequest();
  }
        return  xmlhttp;
}

function trim(a) {
        return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

// + ------------------- +
// |       CONTACT       |
// + ------------------- +

function submit_contact() {
        var name = document.getElementById("name").value;
        var email = document.getElementById("email").value;
        var phone = document.getElementById("phone").value;
        var content = document.getElementById("content").value;
        var title = document.getElementById("title").value;

                if(trim(name) == "" || trim(content) == "" || trim(phone) == "" || trim(email) == "" || trim(title) == "") {
                alert("Vui lòng nhập đầy đủ thông tin ở những vùng đánh dấu sao!");
                 } else {
                        if (confirm("Bạn có chắc những thông tin trên là đúng?")) {
                                http.open('POST',  'submit_contact.php');
                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                http.onreadystatechange = contact_handleResponse;
                                http.send('name='+name+'&email='+email+'&phone='+phone+'&title='+title+'&content='+content+'&sid='+Math.random());
                           }

                     }

}

function reset_contact() {
        if (confirm("Bạn có muốn xoá hết để làm lại?")) {
                document.getElementById("name").value ='';
                document.getElementById("email").value ='';
                document.getElementById("phone").value ='';
                document.getElementById("title").value ='';
                document.getElementById("content").value ='';
        }
}

function search() {
        var kw = document.getElementById("kw").value;
        if (trim(kw) == "") {
        alert ("Vui lòng nhập chuỗi kí tự cần tìm");
        return false;
        } else {
        window.location.href = 'search.php?act=result&kw='+kw;
        return false;
        }
}

