﻿var xmlHttp;

function showUser(str,url)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
  document.getElementById("response").innerHTML=xmlHttp.responseText;
  }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  //Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function warning(Str){alert(Str);}
function validate_require(field){
with(field){
if(value==null||value=="" ){alert("Thông tin này không được bỏ trống");return false;}
else {
return true;
}
}
}

function check_name(value,str_length){
    if(value.length<str_length){return false;}
    else{
        var partent=value.match(/[a-zA-Z_0-9]*/).toString();
       
        if(partent.length<value.length){return false;}
        else return true;
    }
    return true;
    
}
 function check_mail(value){
    apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if(apos<1 || dotpos-apos<2){return false;}else {return true;}
 }
function validate_email(field){
with(field){
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if(apos<1 || dotpos-apos<2){alert("Email Không đúng!");return false;}
else{
return true;
}
}
}
 
function validate_number(field){
with(field){
if(isNaN(value)||value==""||value==null){alert("Phải nhập số"); return false;}
else {return true;}
}
}

/* checkAllBox */


function checkAllBox(form_id,check){
var els=document.getElementById(form_id).elements;
for(var i=0;i<els.length;i++){
if(els[i].type=='checkbox'){
if(check=='1'){
els[i].checked=true;
}else{els[i].checked=false;}
}


}
}

/* getValue */
function getValueId(elementId){
    return document.getElementById(elementId).value;
}
/*End of get Value /*

/* validate image field */
function validate_image(field){
 with(field){
    var str=field.value;
    if( (str.match(/.png$/gi)==null)&&(str.match(/.jpg$/gi)==null)&&(str.match(/.gif$/gi)==null)&&(str.match(/.bmp/gi)==null) &&(str.match(/.jpeg$/gi)==null)){
        alert("image không đúng định dạng!");return false;
    }else return true;
 }   
 }
 function disable_element(element){
    document.getElementById(element).disabled=true;
 }


function ajax(id,value,El)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
url='ajax.php?'+id+'='+value;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
  document.getElementById(El).innerHTML=xmlHttp.responseText;
  }
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function ajax_adv(get_url,El){
  xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
url='ajax.php?'+url;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState!=4 || xmlHttp.readyState!="complete"){
    document.getElementById(El).innerHTML='<div style="text-align:center"><img src="libs/loading.gif"/></div>';      
    }
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
  document.getElementById(El).innerHTML=xmlHttp.responseText;
  }else{document.getElementById(El).innerHTML='ERROR!';  }
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function InputFocus(value_x,element){
    element.value='';
}
function InputBlur(value_x,element){
    if(element.value==''){element.value=value_x;}
}  
function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}

