//AJAX
///nhap du lieu
function LSH(url,id, parameters) {
	loadstatustext = '<center>Loading...<br></center>';
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function()
   {
      // document.getElementById('loading').innerHTML = 'loading...';
	   el = document.getElementById(id);
       el.innerHTML = loadstatustext;
       if (http_request.readyState == 4) {
       //alert(http_request.responseText);
       result = http_request.responseText;
      // document.getElementById('loading').innerHTML = '';
       document.getElementById(id).innerHTML = result;
       }
    }

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);
return true;
}
////////
function ajaxPost(pagepost,fields,idview){
var srchStr="_LSH_";
var offset = 0;
var dau=0;
poststr="DATA=";
var i=0;
offset = fields.indexOf(srchStr, offset);

  while(offset!=-1){
    var subcon=fields.substring(dau,offset);
//    alert(subcon);
    poststr+= encodeURIComponent(document.getElementById(subcon).value)+"L_S_H";
    dau=offset+5;
    offset=dau;
    offset = fields.indexOf(srchStr, offset);
    i=1;
  }

  offset = fields.lastIndexOf(srchStr);
  if(i==1)  subcon=fields.slice(offset+5);
  else subcon=fields;
  //alert(subcon);
  poststr+= encodeURIComponent(document.getElementById(subcon).value);
LSH(pagepost,idview,poststr);
}
//end nhap du lieu
////truyen lien ket

function ajaxLoad(url,id)
{
	loadstatustext = '<center>Loading...<br><img src=images/loading.gif></center>';
   if (document.getElementById) {
       var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
       }
       if (x){
            x.onreadystatechange = function()
            {
                   el = document.getElementById(id);
                   el.innerHTML = loadstatustext;
             if (x.readyState == 4 && x.status == 200){
                   el.innerHTML = x.responseText;
               }
             }
           x.open("GET", url, true);
           x.send(null);
           }
}

//	var url = window.location.href;
//	if(url.indexOf('#')!=-1) c_url = url.split('#');
//	id = c_url?c_url[1]:'#';
	//ajaxLoad('noidung.php?id='+id,'hienthi');
//======end truyen lien ket
//end AJAX
function postlienhe(){
	ajaxPost('user/dblienhe.php','congty_LSH_nguoilienhe_LSH_diachi_LSH_dienthoai_LSH_email_LSH_noidung','hienthi');
}
function SendLienHe()
{

if(CheckText2("nguoilienhe","Ban hay nhap vao ten Nguoi lien he","","frm_contact"))
{
        frm_contact.elements["nguoilienhe"].focus();
        return false;
}
if(CheckEmail2("email","Ban hay nhap vao dia chi Email","frm_contact"))
{
        frm_contact.elements["email"].focus();
        return false;
}
   
}
function postsendmail(){
	ajaxPost('sendmail.php','emailnhan','hienthi');
}
function checkemailnhan()
{
if(CheckEmail2("emailnhan","Email nguoi nhan khhong dung","frm_sendmailsm"))
{
        frm_sendmailsm.elements["emailnhan"].focus();
        return false;
}
       // frm_contact.submit();
}

function CheckText(Name,Msg,Style)
{
        var str;
        if(frm.elements[Name].value==Style)
        {
                window.alert(Msg);
                return true;
        }
    return false;
}
function CheckText2(Name,Msg,Style,Form)
{
        var obj=eval(Form)
        var str;
        if(obj.elements[Name].value==Style)
        {
                window.alert(Msg);
                return true;
        }
    return false;
}

function CheckEmail(mName,Msg,Value)
{
        var str=frm.elements[mName].value;
        if(cEmail(str)==false) //Khong hop le
        {
                alert(Msg);
                return true;
        }
        return false;
}
function CheckEmail2(mName,Msg,Form)
{
        var obj=eval(Form)
        var str=obj.elements[mName].value;
        if(cEmail(str)==false) //Khong hop le
        {
                alert(Msg);
                return true;
        }
        return false;
}
function cEmail(stringIn)
{
        if (stringIn.indexOf("@") < 1){
                return false;
        }else{
                st = stringIn.substr(stringIn.indexOf("@"));
                if(st.indexOf(".") == -1 || st.indexOf(".")==1){
                        return false;
                }else{
                        if(!NormalChar(stringIn)){
                                return false;
                        }else{
                                return true;
                        }
                }
        }
}
function NormalChar(stringIn)
{
         retval = false
         var i;
     for (i=0;i<=stringIn.length-1;i++) {
              //cho phep nhung ky tu tu A->Z, a->z, 0->9,va cac ky tu @,_
              if (((stringIn.charCodeAt(i) >= 48)&&(stringIn.charCodeAt(i) <= 57)) || ((stringIn.charCodeAt(i) >= 64)&&(stringIn.charCodeAt(i) <= 90)) || ((stringIn.charCodeAt(i) >= 97)&&(stringIn.charCodeAt(i) <= 122)) ||(stringIn.charCodeAt(i)==95) ||(stringIn.charCodeAt(i)==46) ||(stringIn.charCodeAt(i)==45)) {
                retval = true;
                }else{
                                retval = false;
                                break;
         }
     }
         return retval;
}