// JavaScript Document
var MOZ = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'); 
var IE = (typeof window.ActiveXObject != 'undefined'); 
var http_request=false;
var target;

function expand_div(obj)
{
	obj.rows = 15;
}

function reduce_div(obj)
{
	obj.rows = 5;
}


function send_contact_email (tg, code) {	
	var contact_fullname = document.getElementById("contact_fullname").value;
	var contact_address = document.getElementById("contact_address").value;
	var contact_phone = document.getElementById("contact_phone").value;
	var contact_email = document.getElementById("contact_email").value;
	var contact_content = document.getElementById("contact_content").value;
	var contact_security_code = document.getElementById("contact_security_code").value;	

	if ((typeof contact_fullname == "undefined") ||(contact_fullname=="")){
		alert("Họ và tên");
		document.getElementById("contact_fullname").focus();
		return;	
	}

	if ((typeof contact_email == "undefined") ||(contact_email=="")){
		alert("Email");
		document.getElementById("contact_email").focus();
		return;	
	}
	if ((typeof contact_content == "undefined") ||(contact_content=="")){
		alert("Thông tin");
		document.getElementById("contact_content").focus();
		return;	
	}
	
	if ((typeof contact_security_code == "undefined") ||(contact_security_code=="")){
		alert("Mã bảo mật");
		document.getElementById("contact_security_code").focus();
		return;	
	}
	if (contact_security_code!=code){
		alert("Mã bảo mật không chính xác");
		return;	
	}
	
	
	var url="contact_send_email.php";		
	var parameters = "contact_fullname=" + contact_fullname + "&contact_address=" + contact_address + "&contact_phone=" + contact_phone + "&contact_email=" + contact_email + "&contact_content=" + contact_content;

        if (MOZ) { // Mozilla
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        }else if (IE) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

         if (!http_request) 
		 {
	         alert('Sorry. Cannot create XMLHTTP instance so we can not add data ');
		     return false;
		 }
      
	  target=tg;
      http_request.onreadystatechange = showResult;
	  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);
	  document.getElementById("status").style.display = "block";
	  document.getElementById("right_data_1").style.display = "none";
	  document.getElementById("right_data").style.display = "block";
}

function showResult()
   // target name of div who get the result
   {
      if (http_request.readyState == 4) {
		  document.getElementById("status").style.display = "none";
         if (http_request.status == 200) {
            result = http_request.responseText;
			//document.getElementById("status").innerHTML = "";			
            document.getElementById(target).innerHTML = result;            
         } else {
            document.getElementById(target).innerHTML ="<font color='red'><b>There was a problem with the connection</b></font>";
         }
      }
}