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");
}

function change_video(val) {
	var val_arr = val.split("|");
        var so = new SWFObject('js/jw_player/player.swf','playerID','210','170','9');
		    so.addParam('allowfullscreen','true');
		    so.addParam('allowscriptaccess','always');
                    so.addParam('autostart','true');
                    so.addVariable('stretching','fill');
		    //so.addVariable('skin','glow.zip');
		    so.addVariable('file', val_arr[0]);
                    so.addVariable('image', val_arr[1]); 

		    so.write('mediaplayer');
}

function change(node) {
    var video = document.getElementById("video_container");
    var o_param = video.getElementsByTagName('PARAM')[0];
var src = node.value;
o_param.setAttribute('value',src);


      if (typeof window.event == 'undefined') {

          var embd = video.getElementsByTagName('embed')[0];

          embd.setAttribute('src', src);

      }

   var n_video = video.cloneNode(true);



     video.parentNode.replaceChild(n_video, video);
} 
// + ------------------- +
// |      CONTACT        |
// + ------------------- +
function contact_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() {
        var contact_name = document.getElementById("contact_name").value;
        var email = document.getElementById("email").value;
        var catalog = document.getElementById("catalog").value;
        var content = document.getElementById("content").value;
        var captcha = document.getElementById("captcha").value;
                if(trim(contact_name) == "" || trim(content) == "" || trim(email) == "" || trim(catalog) == "" || trim(catalog) == "0" || trim(captcha) == "") {
                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',  'submit_contact.php');
                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                http.onreadystatechange = contact_handleResponse;
                                http.send('contact_name='+contact_name+'&email='+email+'&catalog='+catalog+'&content='+content+'&captcha='+captcha+'&sid='+Math.random());
                           }
                         }
                     }
}

function reset_contact() {
        if (confirm("Bạn có muốn xoá hết để làm lại?")) {
                document.getElementById("contact_name").value ='';
                document.getElementById("email").value ='';
                document.getElementById("catalog").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 contact_name = document.getElementById("contact_name").value;
        var email = document.getElementById("email").value;
        var catalog = document.getElementById("catalog").value;
        var content = document.getElementById("content").value;
        var captcha = document.getElementById("captcha").value;
                if(trim(contact_name) == "" || trim(content) == "" || trim(email) == "" || trim(catalog) == "" || trim(catalog) == "0" || trim(captcha) == "") {
                alert("please submit all fields!");
                 } else {
                        if (echeck(email)) {
                        if (confirm("Do you want to continue?")) {
                                http.open('POST',  'submit_contact.php');
                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                http.onreadystatechange = contact_en_handleResponse;
                                http.send('contact_name='+contact_name+'&email='+email+'&catalog='+catalog+'&content='+content+'&captcha='+captcha+'&sid='+Math.random());
                           }
                         }
                     }
}

function reset_contact_en() {
        if (confirm("Do you want to clear all fields?")) {
                document.getElementById("contact_name").value ='';
                document.getElementById("email").value ='';
                document.getElementById("catalog").value ='';
                document.getElementById("content").value ='';
        }
}
// + ------------------- +
// |     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
        }

// + ------------------- +
// |      CAREER         |
// + ------------------- +
function career_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 = 'career.php';
                        }
                }
        }
        catch(e){}
        finally{}
}

function submit_career() {
        var name = document.getElementById("name").value;
        var dob = document.getElementById("dob").value;
        var nationality = document.getElementById("nationality").value;
        var gender = document.getElementById("gender").value;
        var marital = document.getElementById("marital").value;
        var address = document.getElementById("address").value;
        var phone = document.getElementById("phone").value;
        var fax = document.getElementById("fax").value;
        var mobile = document.getElementById("mobile").value;
        var email = document.getElementById("email").value;
        var career = document.getElementById("career").value;
       // var cv = document.getElementById("cv").value;
        var captcha = document.getElementById("captcha").value;
                /*if(trim(name) == "" || trim(dob) == "" || trim(gender) == "" || trim(marital) == "" || trim(phone) == "" || trim(mobile) == "" || trim(address) == "" || trim(email) == "" || trim(career) == "" || trim(career) == "0" || trim(captcha) == "") {*/
               if(trim(name) == "" ) {
				   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',  'submit_career.php');
                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                http.onreadystatechange = career_handleResponse;
                                http.send('name='+name+'&dob='+dob+'&nationality='+nationality+'&gender='+gender+'&marital='+marital+'&address='+address+'&phone='+phone+'&fax='+fax+'&mobile='+mobile+'&email='+email+'&career='+career+'&captcha='+captcha+'&sid='+Math.random());
							   }
                         }
                     }
}

function reset_career() {
        if (confirm("Bạn có muốn xoá hết để làm lại?")) {
                document.getElementById("name").value ='';
                document.getElementById("email").value ='';
                document.getElementById("gender").value ='';
                document.getElementById("marital").value ='';
                document.getElementById("dob").value ='';
             //   document.getElementById("cv").value ='';
                document.getElementById("phone").value ='';
                document.getElementById("mobile").value ='';
                document.getElementById("career").value ='';
                document.getElementById("captcha").value ='';
        }
}
// + ------------------------- +
// |         NEW CAPTCHA       |
// + ------------------------- +
function refreshimg() {

        http.open('POST',  'new_captcha.php');
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.onreadystatechange = refreshimg_handleResponse;
        http.send('null');
}

function refreshimg_handleResponse()
{
        if((http.readyState == 4)&&(http.status == 200)){
                var response = http.responseText;
                document.getElementById('captchaimage').innerHTML = response;
        }
}

// + ------------------- +
// |      CAREER         |
// + ------------------- +
function subscribe_en_handleResponse() {
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                alert(response);
                        }
                        else {
                                alert ("Subscribe success!");
                                window.location.href = 'subscribe.php';
                        }
                }
        }
        catch(e){}
        finally{}
}

function submit_subscribe_en() {
        var title = document.getElementById("title_vn").value;
        var lname = document.getElementById("lname").value;
        var fname = document.getElementById("fname").value;
        var company = document.getElementById("company").value;
        var job = document.getElementById("job").value;
        var country = document.getElementById("country").value;
        var city = document.getElementById("city").value;
        var address = document.getElementById("address").value;
        var phone = document.getElementById("phone").value;
        var email = document.getElementById("email").value;
        var fund = document.getElementById("fund").value;
        var captcha = document.getElementById("captcha").value;
                if(trim(lname) == "" || trim(fname) == "" || trim(address) == "" || trim(fund) == "" || trim(phone) == "" || trim(email) == "" || trim(captcha) == "") {
                alert("Please submit all required fields above!");
                 } else {
                        if (echeck(email)) {
                        if (confirm("Do you sure all fields correct?")) {
                                http.open('POST',  'submit_subscribe.php');
                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                http.onreadystatechange = subscribe_en_handleResponse;
                                http.send('title='+title+'&lname='+lname+'&fname='+fname+'&company='+company+'&job='+job+'&country='+country+'&city='+city+'&address='+address+'&phone='+phone+'&email='+email+'&fund='+fund+'&captcha='+captcha+'&sid='+Math.random());
							   }
                         }
                     }
}

function reset_subscribe_en() {
        if (confirm("Are you sure to clear all fields?")) {
                document.getElementById("title_vn").value ='';
                document.getElementById("lname").value ='';
                document.getElementById("fname").value ='';
                document.getElementById("company").value ='';
                document.getElementById("email").value ='';
                document.getElementById("city").value ='';
                document.getElementById("country").value ='';
                document.getElementById("job").value ='';
                document.getElementById("phone").value ='';
                document.getElementById("fund").value ='';
                document.getElementById("career").value ='';
                document.getElementById("captcha").value ='';
        }
}

// + ------------------- +
// |      CAREER         |
// + ------------------- +
function subscribe_handleResponse() {
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                alert(response);
                        }
                        else {
                                alert ("Đăng ký thành công!");
                                window.location.href = 'subscribe.php';
                        }
                }
        }
        catch(e){}
        finally{}
}

function submit_subscribe() {
        var title = document.getElementById("title_vn").value;
        var lname = document.getElementById("lname").value;
        var fname = document.getElementById("fname").value;
        var company = document.getElementById("company").value;
        var job = document.getElementById("job").value;
        var country = document.getElementById("country").value;
        var city = document.getElementById("city").value;
        var address = document.getElementById("address").value;
        var phone = document.getElementById("phone").value;
        var email = document.getElementById("email").value;
        var fund = document.getElementById("fund").value;
        var captcha = document.getElementById("captcha").value;
                if(trim(lname) == "" || trim(fname) == "" || trim(address) == "" || trim(fund) == "" || trim(phone) == "" || trim(email) == "" || trim(captcha) == "") {
                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',  'submit_subscribe.php');
                                http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                http.onreadystatechange = subscribe_handleResponse;
                                http.send('title='+title+'&lname='+lname+'&fname='+fname+'&company='+company+'&job='+job+'&country='+country+'&city='+city+'&address='+address+'&phone='+phone+'&email='+email+'&fund='+fund+'&captcha='+captcha+'&sid='+Math.random());
							   }
                         }
                     }
}

function reset_subscribe() {
        if (confirm("Bạn có muốn xoá hết để làm lại?")) {
                document.getElementById("title_vn").value ='';
                document.getElementById("lname").value ='';
                document.getElementById("fname").value ='';
                document.getElementById("company").value ='';
                document.getElementById("email").value ='';
                document.getElementById("city").value ='';
                document.getElementById("country").value ='';
                document.getElementById("job").value ='';
                document.getElementById("phone").value ='';
                document.getElementById("fund").value ='';
                document.getElementById("career").value ='';
                document.getElementById("captcha").value ='';
        }
}
// + ------------------- +
// |      LOAD FAQ       |
// + ------------------- +
function load_faq(id) {
        http.open('POST',  'source/nq_change_faq.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = load_faq_handleResponse;
	http.send('id='+id+'&sid='+Math.random());
}

function load_faq_handleResponse() {
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                document.getElementById("faq_block").innerHTML = response;
                                document.getElementById("faq_block").style.display = "block";
                        }
                }
        }
        catch(e){}
        finally{}
}
var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.accordion=function(){
	function slider(n){this.n=n; this.a=[]}
	slider.prototype.init=function(t,e,m,o,k){
		var a=T$(t), i=s=0, n=a.childNodes, l=n.length; this.s=k||0; this.m=m||0;
		for(i;i<l;i++){
			var v=n[i];
			if(v.nodeType!=3){
				this.a[s]={}; this.a[s].h=h=T$$(e,v)[0]; this.a[s].c=c=T$$('div',v)[0]; h.onclick=new Function(this.n+'.pr(0,'+s+')');
				if(o==s){h.className=this.s; c.style.height='auto'; c.d=1}else{c.style.height=0; c.d=-1} s++
			}
		}
		this.l=s
	};
	slider.prototype.pr=function(f,d){
		for(var i=0;i<this.l;i++){
			var h=this.a[i].h, c=this.a[i].c, k=c.style.height; k=k=='auto'?1:parseInt(k); clearInterval(c.t);
			if((k!=1&&c.d==-1)&&(f==1||i==d)){
				c.style.height=''; c.m=c.offsetHeight; c.style.height=k+'px'; c.d=1; h.className=this.s; su(c,1)
			}else if(k>0&&(f==-1||this.m||i==d)){
				c.d=-1; h.className=''; su(c,-1)
			}
		}
	};
	function su(c){c.t=setInterval(function(){sl(c)},20)};
	function sl(c){
		var h=c.offsetHeight, d=c.d==1?c.m-h:h; c.style.height=h+(Math.ceil(d/5)*c.d)+'px';
		c.style.opacity=h/c.m; c.style.filter='alpha(opacity='+h*100/c.m+')';
		if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'} clearInterval(c.t)}
	};
	return{slider:slider}
}();

function view_news(id,cat_id) {
	$("#loader").show();
        http.open('POST',  'load_news_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_view_news_handleResponse(cat_id);};
	http.send('act=detail&id='+id+'&sid='+Math.random());
}

function return_news_cat(id) {
	$("#loader").show();
        http.open('POST',  'load_news_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_view_news_handleResponse(id);};
	http.send('act=cat&id='+id+'&sid='+Math.random());
}

function page_news(pg_id,cat_id) {
	$("#loader").show();
        http.open('POST',  'load_news_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_view_news_handleResponse(cat_id);};
	http.send('act=cat&id='+cat_id+'&pg='+pg_id+'&sid='+Math.random());
}

function reload_view_news_handleResponse(id) {
	$("#loader").hide();
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                document.getElementById("cat_"+id).innerHTML = response;
                        }
                }
        }
        catch(e){}
        finally{}
	}
function view_releases(id,cat_id) {
	$("#loader").show();
        http.open('POST',  'load_releases_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_view_releases_handleResponse(cat_id);};
	http.send('act=detail&id='+id+'&sid='+Math.random());
}

function return_releases_cat(id) {
	$("#loader").show();
        http.open('POST',  'load_releases_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_view_releases_handleResponse(id);};
	http.send('act=cat&id='+id+'&sid='+Math.random());
}

function page_releases(pg_id,cat_id) {
	$("#loader").show();
        http.open('POST',  'load_releases_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_releases_news_handleResponse(cat_id);};
	http.send('act=cat&id='+cat_id+'&pg='+pg_id+'&sid='+Math.random());
}

function reload_view_releases_handleResponse(id) {
	$("#loader").hide();
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                document.getElementById("cat_"+id).innerHTML = response;
                        }
                }
        }
        catch(e){}
        finally{}
	}
function page_releases(pg_id,cat_id) {
	$("#loader").show();
        http.open('POST',  'load_releases_detail.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {reload_view_releases_handleResponse(cat_id);};
	http.send('act=cat&id='+cat_id+'&pg='+pg_id+'&sid='+Math.random());
}

function reload_view_releases_handleResponse(id) {
	$("#loader").hide();
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                document.getElementById("cat_"+id).innerHTML = response;
                        }
                }
        }
        catch(e){}
        finally{}
	}
function load_department(id) {
        http.open('POST',  'source/nq_change_faq.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = load_department_handleResponse;
	http.send('id='+id+'&sid='+Math.random());
}

function load_department_handleResponse() {
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                document.getElementById("department_block").innerHTML = response;
                                document.getElementById("department_block").style.display = "block";
                        }
                }
        }
        catch(e){}
        finally{}
}
function do_search_faq() {

        var organization = document.getElementById("organization").value;
        var department = document.getElementById("department").value;

        if ((trim(department) == "" || trim(department) == "0") && (trim(organization) == "" || trim(organization) == "0")) {

        	window.location.href = 'faq.php';

        } else {
	
	        	window.location.href = 'faq.php?act=search&organization='+organization+'&department='+department;

}
}

function logout_user() {
	if (confirm("Bạn có muốn thoát khỏi hệ thống?")) {
                http.open('POST',  'source/mem_logout.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                http.onreadystatechange = login_user_handleResponse;
                http.send(); 
        }

}
function logout_user_en() {
	if (confirm("Are you sure, logout?")) {
                http.open('POST',  'source/mem_logout.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                http.onreadystatechange = login_user_handleResponse;
                http.send(); 
        }

}
function login_user() {
        var user = document.getElementById("username").value;
        var pass = document.getElementById("password").value;

        if ((trim(user) == "" || trim(pass) == "")) {
        	alert("Vui lòng nhập tài khoản & mật khẩu");
                return false;
        } else {
                http.open('POST',  'source/mem_login.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = login_user_handleResponse;
		http.send('user='+user+'&pass='+pass+'&sid='+Math.random());
                return false;
        }
        return false;
}

function login_user_handleResponse() {
        try {
                if((http.readyState == 4)&&(http.status == 200)){
                        var response = http.responseText;
                        if (response) {
                                alert(response);
                        } else {
                        	location.reload();
                        }
                }
        }
        catch(e){}
        finally{}
	}

