
function loadpage()
{
	address = '' + window.location + '';
	split_x_page=address.split("#x_page=");
	if(split_x_page[1])
	{
		fix_backAjax('?x_page='+split_x_page[1],'center_site_view');
	}
}

function center_site_view(){
	if(http_request.readyState==4){
		if(http_request.status == 200){
			document.getElementById('center_site').innerHTML = http_request.responseText;
		}else{
			alert("Nguồn bị lỗi không thể truy cập!");
			history.back();
		}
	}else{
		//document.getElementById('center_site').innerHTML = "Loading...";
	}
}

function show_answer(id_group,answer){
	for (var i=0;i<15;i++){
		if(answer == i){
			if(document.getElementById(id_group+answer).style.display =="block"){
			document.getElementById(id_group+answer).style.display="none";
			}else{
			document.getElementById(id_group+answer).style.display="block";
			}
		}else{
		document.getElementById(id_group+i).style.display="none";
		}	
	}
}

function isEmail(s)
{   
  if (s=="") return false;
  if(s.indexOf(" ")>0) return false;
  if(s.indexOf("@")==-1) return false;
  var i = 1;
  var sLength = s.length;
  if (s.indexOf(".")==-1) return false;
  if (s.indexOf("..")!=-1) return false;
  if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
  if (s.lastIndexOf(".")==s.length-1) return false;
  var str="abcdefghikjlmnopqrstuvwxyz-@._0123456789"; 
  for(var j=0;j<s.length;j++)	{if(str.indexOf(s.charAt(j))==-1) return false;}
	return true;
}
function emailCheck(emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}
if (user.match(userPat)==null) {
//alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
//alert("This address is missing a hostname!");
return false;
}
return true;
}
 
function isVld(s,Vld)
  {  
    var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (Vld.indexOf(c) == -1) return false;
    }
    return true;
  }
 
function bgcolor(obj,state) {
	if (state=="over") {
		obj.style.backgroundColor ='F8FFF4';
		obj.style.cursor='default';
	}
	else {
		obj.style.backgroundColor ='ECFFFF';
	}
}
	
function do_login(){
	p_action = encodeURIComponent(document.login_form.action.value); 
	p_txttendangnhap = encodeURIComponent(document.login_form.txttendangnhap.value); 
	p_txtmatkhau = encodeURIComponent(document.login_form.txtmatkhau.value); 
	p_Submit = encodeURIComponent(document.login_form.Submit.value); 
	
	post_data = "action="+p_action+"&txttendangnhap="+p_txttendangnhap+"&txtmatkhau="+p_txtmatkhau+"&Submit="+p_Submit
	actionFile='default.asp?x_page=32';
	ajax_send(post_data, actionFile, 'exe_js');
}

function exe_js(){
	if(http_request.readyState==4){
		if(http_request.status == 200){
			eval(http_request.responseText);
		}else{
			alert("Nguồn bị lỗi không thể truy cập!");
			history.back();
		}
	}
}

function lienhe2email(){
	p_doituong = encodeURIComponent(document.lienhe2email.doituong.value); 
	p_name = encodeURIComponent(document.lienhe2email.name.value); 
	p_email = encodeURIComponent(document.lienhe2email.email.value); 
	p_phone = encodeURIComponent(document.lienhe2email.phone.value); 
	p_subject = encodeURIComponent(document.lienhe2email.subject.value); 
	p_message = encodeURIComponent(document.lienhe2email.message.value); 

	post_data = "subject="+p_subject+"&phone="+p_phone+"&email="+p_email+"&name="+p_name+"&doituong="+p_doituong+"&message="+p_message;
	actionFile='?x_page=3&que_action=vbs_lienhe2email';
	ajax_send(post_data, actionFile, 'hidePopWinfalse');
}

function hidePopWinfalse(){
	alert('Chúng tôi đã nhận được liên hệ từ quý vị.\nThông tin sẽ được xử lý trong thời gian sớm nhất.\nPhản hồi sẽ có trong mục câu hỏi thường gặp!');
	self.parent.hidePopWin(false);
}

function TimKH(){
	var TimKH = document.TimKH;
	txtTDV = encodeURIComponent(TimKH.txtTDV.value); 
	txtTTP = encodeURIComponent(TimKH.txtTTP.value); 
	txtHQ = encodeURIComponent(TimKH.txtHQ.value);
	post_data = "TDV="+txtTDV+"&TTP="+txtTTP+"&HQ="+txtHQ;
	actionFile='?x_page=khachhang&action=TimKH';
	ajax_send(post_data, actionFile, 'center_site_view');
}

function showHideDiv(id) {
	if (document.getElementById(id).style.display == 'block') {
		displayElement(id, "none");
	} else if (document.getElementById("Buttons1_" + rte).style.display == 'none'){
		displayElement(id, "block");
	}
}

function displayElement(element, value) {
	try {
		document.getElementById(element).style.display = value;
	}
	catch (e) {
	}
}
