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");

}



// + ------------------- +

// |     CHECK EMAIL     |

// + ------------------- +



function echeck(str) {



                var at="@"

                var dot="."

                var lat=str.indexOf(at)

                var lstr=str.length

                var ldot=str.indexOf(dot)

                if (str.indexOf(at)==-1){

                   alert("Địa chỉ E-mail không chính xác")

                   return false

                }



                if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

                        alert("Địa chỉ E-mail không chính xác")

                   return false

                }



                if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

                    alert("Địa chỉ E-mail không chính xác")

                    return false

                }



                 if (str.indexOf(at,(lat+1))!=-1){

                    alert("Địa chỉ E-mail không chính xác")

                    return false

                 }



                 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

                    alert("Địa chỉ E-mail không chính xác")

                    return false

                 }



                 if (str.indexOf(dot,(lat+2))==-1){

                    alert("Địa chỉ E-mail không chính xác")

                    return false

                 }



                 if (str.indexOf(" ")!=-1){

                    alert("Địa chỉ E-mail không chính xác")

                    return false

                 }



                 return true



        }



// + ------------------- +

// |     POOL SUBMIT     |

// + ------------------- +

function submit_vote(id) {

        var tt_opt = document.getElementsByName(id).length;

        var opt = document.getElementsByName(id);

        var c= "";

        for(var i = 0; i < tt_opt; i++) {

                if(opt[i].checked) {

                        var c = opt[i].value;

                }

        }

        if (trim(c) == "") {

        alert ("Vui lòng chọn câu trả lời trước khi bình chọn!");

        } else {

                        http.open('POST',  'source/submit_vote.php');

                        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                        http.onreadystatechange = voted_handleResponse;

                        http.send('pool_id='+id+'&opt_id='+c+'&sid='+Math.random());

        }



}



function voted_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (response) {

                                alert(response);

                        }

                        else {

                                alert ("Đã nhận ý kiến của bạn! Cảm ơn!");

                                window.location.href = 'index.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



// + ---------------------- +

// |     POOL SUBMIT EN     |

// + ---------------------- +

function submit_vote_en(id) {

        var tt_opt = document.getElementsByName(id).length;

        var opt = document.getElementsByName(id);

        var c= "";

        for(var i = 0; i < tt_opt; i++) {

                if(opt[i].checked) {

                        var c = opt[i].value;

                }

        }

        if (trim(c) == "") {

        alert ("Please select your choice before submit!");

        } else {

                        http.open('POST',  'source/submit_vote.php');

                        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                        http.onreadystatechange = voted_en_handleResponse;

                        http.send('pool_id='+id+'&opt_id='+c+'&sid='+Math.random());

        }



}



function voted_en_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (response) {

                                alert(response);

                        }

                        else {

                                alert ("Thanks for submit your choice!");

                                window.location.href = 'index.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



// + ------------------- +

// |     FIND SCIENCE    |

// + ------------------- +

function sci_find(cat_id) {

        var level = document.getElementById("level").value;

        var year = document.getElementById("year").value;

        window.location.href = 'science.php?act=cat&id='+cat_id+'&level='+level+'&year='+year;

}



// + ---------------------- +

// |     FIND SCIENCE EN    |

// + ---------------------- +

function sci_find_en(cat_id) {

        var level = document.getElementById("level").value;

        var year = document.getElementById("year").value;

        window.location.href = 'science.php?act=cat&id='+cat_id+'&level='+level+'&year='+year;

}



// + ------------------- +

// |     SERVICE RESET   |

// + ------------------- +

function reset_service() {

        if (confirm("Bạn muốn xoá hết để làm lại?")) {

                document.getElementById("company").value ='';

                document.getElementById("present").value ='';

                document.getElementById("address").value ='';

                document.getElementById("phone").value ='';

                document.getElementById("fax").value ='';

                document.getElementById("email").value ='';

                document.getElementById("date").value ='';

                document.getElementById("content").value ='';

        }

}



// + ------------------- +

// |     SERVICE REG     |

// + ------------------- +

function submit_service() {

        var company = document.getElementById("company").value;

        var present = document.getElementById("present").value;

        var address = document.getElementById("address").value;

        var phone = document.getElementById("phone").value;

        var fax = document.getElementById("fax").value;

        var email = document.getElementById("email").value;

        var date = document.getElementById("date").value;

        var organization = document.getElementById("organization").value;

        var content = document.getElementById("content").value;

                if(trim(present) == "" || trim(email) == "" || trim(phone) == "" || trim(date) == "") {

                alert("Vui lòng nhập đầy đủ các vùng in đậm");

                } else {

                        if (confirm("Bạn có chắc những thông tin trên đã chính xác?")) {

                                http.open('POST',  'source/service_register.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = submit_service_handleResponse;

                                http.send('company='+company+'&present='+present+'&address='+address+'&phone='+phone+'&fax='+fax+'&email='+email+'&date='+date+'&organization='+organization+'&content='+content+'&sid='+Math.random());

                        }

                }

}



function submit_service_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (!response) {

                                alert ("Cảm ơn bạn đã đăng kí! Chúng tôi sẽ gọi điện để xác nhận lại.");

                                window.location.href = 'index.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



// + ---------------------- +

// |     SERVICE RESET EN   |

// + ---------------------- +

function reset_service_en() {

        if (confirm("Do you want to clear all fields?")) {

                document.getElementById("company").value ='';

                document.getElementById("present").value ='';

                document.getElementById("address").value ='';

                document.getElementById("phone").value ='';

                document.getElementById("fax").value ='';

                document.getElementById("email").value ='';

                document.getElementById("date").value ='';

                document.getElementById("content").value ='';

        }

}



// + ---------------------- +

// |     SERVICE REG EN     |

// + ---------------------- +

function submit_service_en() {

        var company = document.getElementById("company").value;

        var present = document.getElementById("present").value;

        var address = document.getElementById("address").value;

        var phone = document.getElementById("phone").value;

        var fax = document.getElementById("fax").value;

        var email = document.getElementById("email").value;

        var date = document.getElementById("date").value;

        var organization = document.getElementById("organization").value;

        var content = document.getElementById("content").value;

                if(trim(present) == "" || trim(email) == "" || trim(phone) == "" || trim(date) == "") {

                alert("Please submit all bold fields");

                } else {

                        if (confirm("Do you want to continue?")) {

                                http.open('POST',  'source/service_register.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = submit_service_en_handleResponse;

                                http.send('company='+company+'&present='+present+'&address='+address+'&phone='+phone+'&fax='+fax+'&email='+email+'&date='+date+'&organization='+organization+'&content='+content+'&sid='+Math.random());

                        }

                }

}



function submit_service_en_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (!response) {

                                alert ("Thanks for register! We'll confirm by phone.");

                                window.location.href = 'index.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



// + ------------------- +

// |      HEALTH FIND    |

// + ------------------- +

function health_find() {

        var cat = document.getElementById("cat").value;

        window.location.href = 'health.php?act=cat&id='+cat;

}



// + ------------------- +

// |       CONTACT       |

// + ------------------- +



function contact_vn_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (response) {

                                alert(response);

                        }

                        else {

                                alert ("Cảm ơn! Chúng tôi sẽ liên lạc sớm nhất có thể!");

                                window.location.href = 'contact.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



function submit_contact_vn() {

        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 (echeck(email)) {

                        if (confirm("Bạn có chắc những thông tin trên là đúng?")) {

                                http.open('POST',  'source/submit_contact.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = contact_vn_handleResponse;

                                http.send('name='+name+'&email='+email+'&phone='+phone+'&title='+title+'&content='+content+'&sid='+Math.random());

                           }

                         }

                     }



}



function reset_contact_vn() {

        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 ='';

        }

}



// + ------------------- +

// |       CONTACT EN    |

// + ------------------- +



function contact_en_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (response) {

                                alert(response);

                        }

                        else {

                                alert ("Thank you! We'll reply as soon as possible!");

                                window.location.href = 'contact.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



function submit_contact_en() {

        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("Please submit all fields marked with star!");

                 } else {

                        if (echeck(email)) {

                        if (confirm("Do you want to continue?")) {

                                http.open('POST',  'source/submit_contact.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = contact_en_handleResponse;

                                http.send('name='+name+'&email='+email+'&phone='+phone+'&title='+title+'&content='+content+'&sid='+Math.random());

                           }

                         }

                     }



}



function reset_contact_en() {

        if (confirm("Do you want to clear all fields")) {

                document.getElementById("name").value ='';

                document.getElementById("email").value ='';

                document.getElementById("phone").value ='';

                document.getElementById("title").value ='';

                document.getElementById("content").value ='';

        }

}



// + ------------------- +

// |      SEARCH VN      |

// + ------------------- +

function do_search() {

                var kw = document.getElementById("kw").value;

                var type = document.getElementById("type").value;

                if(trim(kw) == "" || trim(kw) == "Nhập từ khoá cần tìm") {

                        alert("Vui lòng nhập từ khoá cần tìm");

                } else {

                        window.location.href = 'search.php?cat='+type+'&kw='+kw;

                }

                return false; 

}



// + ------------------- +

// |      SEARCH EN      |

// + ------------------- +

function do_search_en() {

                var kw = document.getElementById("kw").value;

                var type = document.getElementById("type").value;

                if(trim(kw) == "" || trim(kw) == "Enter your keyword here") {

                        alert("Please enter a keyword");

                } else {

                        window.location.href = 'search.php?cat='+type+'&kw='+kw;

                }

                return false;

}



// + ------------------- +

// |       QUESTION      |

// + ------------------- +



function question_vn_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (response) {

                                alert(response);

                        }

                        else {

                                alert ("Cảm ơn! Chúng tôi sẽ liên lạc sớm nhất có thể!");

                                window.location.href = 'index.php';

                        }

                }

        }

        catch(e){}

        finally{}

}

function submit_comment_vn() {
		
		var video_id = document.getElementById("video_id").value;
		
        var name = document.getElementById("name").value;

        var email = document.getElementById("email").value;

        var content = document.getElementById("content").value;


                if(trim(name) == "" || trim(content) == "" || trim(email) == "") {

                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',  'source/submit_comment.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = comment_vn_handleResponse;

                                http.send('name='+name+'&email='+email+'&content='+content+'&video_id='+video_id);

                           }

                     }



}

function reset_comment_vn() {

        if (confirm("Bạn có muốn xoá hết để làm lại?")) {

                document.getElementById("name").value ='';

                document.getElementById("email").value ='';

                document.getElementById("content").value ='';

        }

}


function submit_question_vn() {

        var name = document.getElementById("name").value;

        var address = document.getElementById("address").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(address) == "" || trim(content) == "" || 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',  'source/submit_question.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = question_vn_handleResponse;

                                http.send('name='+name+'&address='+address+'&email='+email+'&phone='+phone+'&title='+title+'&content='+content+'&sid='+Math.random());

                           }

                     }



}



function reset_question_vn() {

        if (confirm("Bạn có muốn xoá hết để làm lại?")) {

                document.getElementById("name").value ='';

                document.getElementById("address").value ='';

                document.getElementById("email").value ='';

                document.getElementById("phone").value ='';

                document.getElementById("title").value ='';

                document.getElementById("content").value ='';

        }

}



// + ---------------------- +

// |       QUESTION EN      |

// + ---------------------- +



function question_en_handleResponse() {

        try {

                if((http.readyState == 4)&&(http.status == 200)){

                        var response = http.responseText;

                        if (response) {

                                alert(response);

                        }

                        else {

                                alert ("Thank you! We'll reply as soon as possible");

                                window.location.href = 'index.php';

                        }

                }

        }

        catch(e){}

        finally{}

}



function submit_question_en() {

        var name = document.getElementById("name").value;

        var address = document.getElementById("address").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(address) == "" || trim(content) == "" || trim(title) == "") {

                alert("Please submit all fields which mark with star!");

                 } else {

                        if (confirm("Do you want to continue?")) {

                                http.open('POST',  'source/submit_question.php');

                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                                http.onreadystatechange = question_en_handleResponse;

                                http.send('name='+name+'&address='+address+'&email='+email+'&phone='+phone+'&title='+title+'&content='+content+'&sid='+Math.random());

                           }

                     }



}



function reset_question_en() {

        if (confirm("Do you want to clear all fields?")) {

                document.getElementById("name").value ='';

                document.getElementById("address").value ='';

                document.getElementById("email").value ='';

                document.getElementById("phone").value ='';

                document.getElementById("title").value ='';

                document.getElementById("content").value ='';

        }

}

