function AjaxSubmit(mUrl, mParametters)
{
	// Validate Ajax enable with browsers
	var xmlHttp;	    
	try{  
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch(e){
	  	// Internet Explorer
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch(e){
	    try{
	      	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch(e){
	      	alert("Hay dung Internet Explorer 5.5 tro len hoac Firefox 1.5 tro len.");
	      	return false; 
	      }
	    }
	}
	xmlHttp.onreadystatechange = function()
	{
	 	document.getElementById('vieAdditional').style.display='block';
	   	if(xmlHttp.readyState==4){
			document.getElementById('vieAdditional').style.display='none';
			alert(xmlHttp.responseText);
	    }
	}
	xmlHttp.open("POST", mUrl, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	xmlHttp.setRequestHeader("Content-Length", mParametters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(mParametters);	
}

function AjaxDisplayInfo(mUrl, mParametters, mDivTag)
{
	// Validate Ajax enable with browsers
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch(e){
	  	// Internet Explorer
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch(e){
	    try{
	      	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch(e){
	      	alert("Hay dung Internet Explorer 5.5 tro len hoac Firefox 1.5 tro len.");
	      	return false;
	      }
	    }
	}
	xmlHttp.onreadystatechange = function()
	{
		document.getElementById('vieAdditional').style.display='block';
	   	if(xmlHttp.readyState==4){
			document.getElementById('vieAdditional').style.display='none';
			document.getElementById(mDivTag).innerHTML = xmlHttp.responseText;
	    }
	}	
	xmlHttp.open('GET', mUrl + "?" + mParametters, true);
    xmlHttp.send(null);
}
		
function AjaxSubmitRedirect(mUrl, mParametters, mUrlRedirect)
{
	// Validate Ajax enable with browsers
	var xmlHttp;	    
	try{  
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch(e){
	  	// Internet Explorer
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch(e){
	    try{
	      	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch(e){
	      	alert("Hay dung Internet Explorer 5.5 tro len hoac Firefox 1.5 tro len.");
	      	return false; 
	      }
	    }
	}
	xmlHttp.onreadystatechange = function()
	{
	 	document.getElementById('vieAdditional').style.display='block';
	   	if(xmlHttp.readyState==4){
			document.getElementById('vieAdditional').style.display='none';
			if(xmlHttp.responseText != ""){
				alert(xmlHttp.responseText);
			}else{
				if(mUrlRedirect != "") window.location = mUrlRedirect;
			}			
	    }
	}
	xmlHttp.open("POST", mUrl, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	xmlHttp.setRequestHeader("Content-Length", mParametters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(mParametters);	
}

function Thongbao(MessageText)
{
	alert(MessageText);
}
			
function OpenDialogEx(mUrl, vWidth, vHeight)
{
	winDef = 'menubar=no,status=yes,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=no,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	win2Open = open(mUrl, '_blank', winDef);	
	return;
}

function OpenDialogEx1(mUrl, vWidth, vHeight)
{
	winDef = 'menubar=no,status=yes,resizable=no,scrollbars=yes,toolbar=no,location=no,fullscreen=no,titlebar=no,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	win2Open = open(mUrl, '_blank', winDef);	
	return;
}

//Ap dung cho viec check dia chi Email
function isCharsInBag(s, bag)
{
  var i;
  for (i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

//Check email
function CheckEmail(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("Địa chỉ E-mail không hợp lệ. Bạn hãy nhập lại!");
    return false;
  }
var user=matchArray[1];
var domain=matchArray[2];
  for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
      alert("Tên người dùng của địa chỉ e-mail chứa ký tự không hợp lệ!");
      return false;
    }
  }
  for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
      alert("Tên miền của địa chỉ e-mail chứa ký tự không hợp lệ!");
      return false;
    }
  }
  if (user.match(userPat)==null) {
    alert("Tên người dùng của địa chỉ email không hợp lệ!");
    return false;
  }

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("Tên miền của địa chỉ e-mail không hợp lệ!");
      return false;
    }
  }
  if (checkTLD && domArr[domArr.length-1].length!=2 &&
     domArr[domArr.length-1].search(knownDomsPat)==-1) {
    alert("Địa chỉ e-mail phải kết thúc với tên miền đã biết hoặc với hai ký tự của tên nước!");
    return false;
  }
  if (len<2) {
    alert("Địa chỉ e-mail không có tên miền!");
    return false;
  }
  return true;
}

// Mo hop thoai quan ly tai nguyen tep (file)		
function FileManagerOpen(vWidth, vHeight)
{
	window.SetUrl=function(value){
		alert(value);
		return;
	}	
	var winDef = 'status=yes,resizable=no,scrollbars=yes,toolbar=no,location=no,fullscreen=no,titlebar=no,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);	
	var filemanager='../aspnet_client/FCKEditor/editor/filemanager/browser/default/browser.html?Connector=connectors/aspx/connector.aspx';
	window.open(filemanager,'filemanager', winDef);
}

// Thuc hien submit mot action theo Ajax voi method la POST	
function RunAjaxAction(mUrl, mParameters)
{
	var f = document.all("Form1");
	var xmlHttp;	    
	try{
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch(e){
	    try{
	      	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch(e){
	      	alert("Your browser does not support AJAX!");
	      	return false; 
	      }
	    }
	}
	xmlHttp.onreadystatechange = function()
	{
	   	document.getElementById('vieAdditional').style.display='';
		if(xmlHttp.readyState==4){
			if(xmlHttp.responseText !=''){ 
				alert(xmlHttp.responseText);
			}
			window.location.reload(true);
	    }
		document.getElementById('vieAdditional').style.display='none';
	}
	xmlHttp.open("POST", mUrl, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", mParameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(mParameters);
}

// Thuc hien load du lieu ra the DIV
function LoadInfo2Div(mUrl, mParameters, mDivInfo)
{
	var f = document.all("Form1");
	var xmlHttp;	    
	try{
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch(e){
	    try{
	      	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch(e){
	      	alert("Your browser does not support AJAX!");
	      	return false; 
	      }
	    }
	}
	xmlHttp.onreadystatechange = function()
	{
		document.getElementById(mDivInfo).innerHTML = "<table width='100%'><tr><td align='center'><br><br><img src='../images/ajax-loader.gif' /> &#272;&#7907;i trong gi&#226;y l&#225;t...</td></tr></table>";
		if(xmlHttp.readyState==4){
			if(xmlHttp.responseText !=''){				
				document.getElementById(mDivInfo).innerHTML = xmlHttp.responseText;
			}
	    }
	}
	xmlHttp.open("POST", mUrl, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-Length", mParameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(mParameters);
}

function KeyDownHandler(btn){
	// process only the Enter key
	if (event.keyCode == 13){
		// cancel the default submit
		event.returnValue	=	false;
		event.cancel 		= 	true;
		// submit the form by programmatically clicking the specified button
		btn.click();
	}
}
		
function SearhVanban_Full()
{
	var f = document.all("Form1");	
	if(f.txtKeyword_Full.value == "")
	{
		alert("Nhap tu khoa can tim kiem.");
		return;
	}
	window.location.href = "/vbqppl/admin/?mod=vanban&action=search&keyword=" + encodeURIComponent(f.txtKeyword_Full.value);
}