function popup_window(url,w,h)
{
	//alert("hihi");
	var width=w;
	var height=h;
	var from_top=350;
	var from_left=500;
	var toolbar='no';
	var location='no';
	var directories='no';
	var status='no';
	var menubar='no';
	var scrollbars='yes';
	var resizable='yes';
	var atts='width='+width+',height='+height+',top='+ from_top+',screenY=';
	atts+= from_top+',left='+from_left+',screenX='+from_left+ ',toolbar='+toolbar;
	atts+=',location='+location+',directories='+directories+',status='+status;
	atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;
	window.open(url,'win_name',atts);
}

/*
  * Kiem tra du lieu nhap vao co phai la ngay hop le khong
  * Tham so truyen vao se la(year, month, day)
  * Neu ham tra ve la True -> Ngay hop le,nguoc lai
  *                   False -> Ngay ko hop le
  */
function fncCheckValidDate(yyyy, mm, dd) {

	yyyy = parseInt(yyyy, 10);
	mm = parseInt(mm, 10);
	dd = parseInt(dd, 10);
	if ((yyyy < 1900) || (yyyy > 9999)) /*note-xanhbiec - kiem tra gioi han nam*/
	{
		return false;
	}
	else if ((mm < 1) || (mm > 12)) /*note-xanhbiec - kiem tra gioi han thang*/
	{
		return false;
	}
	else if ((dd < 1) || (dd > 31)) /*note-xanhbiec - kiem tra gioi han ngay*/
	{
		return false;
	}
	else if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd == 31)) /*xanhbiec - kiem tra lien he giua thang va ngay*/
	{
		return false;
	}
	else if (mm == 2) /*note-xanhbiec - kiem tra nam nhuan*/
	{
		var isleap = (yyyy % 4 == 0 && (yyyy % 100 != 0 || yyyy % 400 == 0));
		if (dd > 29 || (dd == 29 && !isleap))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}
/**********************************************************************************
Description: chi dinh text cho phep nhap vao
Parameter: e: Truyen su kiem phai sinh vao cho ham..o day la su kien keypress
	validchars: la dang chuoi...
	chi co cac tu trong chuoi nay moi duoc phep nhap vao textbox chi dinh
**********************************************************************************/
function fncKeyRestrict(e, validchars)
{
	var key='', keychar='';
	key = fncGetKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}
/**********************************************************************************
Description: nhan ve keycode
Note: ham ho tro cho ham keyRestrict
**********************************************************************************/
function fncGetKeyCode(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}
/*[HUYNH THI HONG NGUYEN]*/

/***************VO CHI HOANG*****************************
Description: Ham su dung show dialog voi cac tham so nhan vao cho ca IE va FX
Parameter:
*/
function ShowPopup(_url,width,heigh) {
    var url = _url;
    if (window.showModalDialog) {
        var ieFeatures = "dialogHeight:"+heigh+"px;"
                       + "dialogWidth:"+width+"px;"
                       + "edge:sunken;"
                       + "help:no;"
                       + "scroll:no;"
                       + "resizable:no;"
                       + "status:no;"
                       + "unadorned:no;";
        showModalDialog(url, window, ieFeatures);
    } else {
        var windowName = "sampleDialog"
        var mozillaFeatures = "width="+width+","
                            + "height="+heigh+","
                            + "toolbar=no,"
                            + "location=no,"
                            + "directories=no,"
                            + "status=no,"
                            + "menubar=no,"
                            + "scrollbars=no,"
                            + "resizable=no,"
                            + "modal=yes";
        window.open(url, windowName, mozillaFeatures);
    }
    return false;

}
	/**
	*
	*  UTF-8 data encode / decode
	*  http://www.webtoolkit.info/
	*
	**/
	var Utf8 = {
	// public method for url encoding
		encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
/* Ham cat khoang trang, tham so la mot chuoi ky tu*/
function Trim(str) {
    return str.replace(/^\s*|\s*$/, "");
}

/*--------------------------------------------------------------
 [Summary]
	Name        isEmail
	Description Ham kiem tra du lieu nhap la email
 [Value]
	Param		strEmail     string
	Param		control      object
	Param		StrMessage   string
	Return		true
	Return		false
 [Note]
	Gan tren su kien OnKeyPress
------------------------------------------------------------------------*/
function isEmail(strEmail)
{
	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=strEmail.match(emailPat)
	if (matchArray==null) 	{

		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null)
	{
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				return false;
			}
		}
		return true;
	}
	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null)
	{
		return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 )//|| domArr[domArr.length-1].length>4)
	{
		return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2)
	{
		return false;
	}

	return true;
}
/*
//Nguyeng Thanh Tri khong chay tren firefox
function IsNumber(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789";

	if (Expression.length < 1)	return false;

	for (var i = 0; i < Expression.length; i++)
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)		return false;
	}
	return true;
}
*/

// Nguyen thanh Tri

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


/**********************************************************************************
Description: Kiem tra ngay nhap vao co hop le hay khong
Parameter: yyyy,mm,dd
**********************************************************************************/
function isValidDate(Expression)
{
		if(!getIsDate(Expression)) return false;
		//var elem = Expression.split(/[\-/]/);
		//var elem = Expression.split('-');
		var elem = Expression.split('/');

		if(isNaN(elem[0])) return false;
		if(isNaN(elem[1])) return false;
		if(isNaN(elem[2])) return false;

		dd = elem[0];
		mm = elem[1];
		yyyy = elem[2];

		if(yyyy.length < 4 || mm.length < 2 || dd.length < 2)
		{
			return false;
		}
		if(isNaN(yyyy) || isNaN(mm) || isNaN(dd))
		{
			return false;
		}
		if(yyyy == "" || mm == "" || dd == "")
		{
			return false;
		}
		yyyy = parseInt(yyyy, 10);
		mm = parseInt(mm, 10);
		dd = parseInt(dd, 10);
		if ((yyyy < 1900) || (yyyy > 2099)) /*note-xanhbiec - kiem tra gioi han nam*/
		{
			return false;
		}
		else if ((mm < 1) || (mm > 12)) /*note-xanhbiec - kiem tra gioi han thang*/
		{
			return false;
		}
		else if ((dd < 1) || (dd > 31)) /*note-xanhbiec - kiem tra gioi han ngay*/
		{
			return false;
		}

		else if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd == 31)) /*xanhbiec - kiem tra lien he giua thang va ngay*/
		{
			return false;
		}
		else if (mm == 2) /*note-xanhbiec - kiem tra nam nhuan*/
		{
			var isleap = (yyyy % 4 == 0 && (yyyy % 100 != 0 || yyyy % 400 == 0));
			if (dd > 29 || (dd == 29 && !isleap))
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		else
		{
			return true;
		}


}

function getIsDate(Expression)
{
	Expression = Expression.toLowerCase();
	//RefString = "0123456789-/";
	//RefString = "0123456789-";
	RefString = "0123456789/";

	if (Expression.length < 1)	return false;

	for (var i = 0; i < Expression.length; i++)
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)		return false;
	}
	return true;
}
/*Ham dung de xu ly su kien nhan phim enter khi go du lieu vao textbox txt_key_search*/
function txt_key_search_onkeypress(e)
{

	key = fncGetKeyCode(e);
	if(key == 13){
		btn_search_click();
	} else {
		return false;
	}
}
/*VO CHI HOANG*/
/*Show popups */
function fncShowDialog(p_strUrl, p_intHeight, p_intWidth, p_blnScrollBar, p_blnResizable)
{
		var objArguments = window;		//Get arguments on dialog with window.dialogArguments
		var strScrollBar;
		var strResizable;
		var strFeatures = "";

		if (p_blnScrollBar) {
			strScrollBar = "yes";
		} else {
			strScrollBar = "no";
		}

		if (p_blnResizable) {
			strResizable = "yes";
		} else {
			strResizable = "no";
		}

		strFeatures += "dialogHeight: " + p_intHeight + "px; ";
		strFeatures += "dialogWidth: " + p_intWidth + "px; ";
		strFeatures += "center: Yes; ";
		strFeatures += "scroll: " + strScrollBar + "; ";
		strFeatures += "resizable: " + strResizable + "; ";
		strFeatures += "status: No; ";
		strFeatures += "help: No;";

		return window.showModalDialog(p_strUrl, objArguments, strFeatures);
}
/**
HAI NAM
onkeydown =13//enter
**/
function EventEnter(event,a)
{
	var k=(event.which)?event.which : event.keyCode;
	if(k==13)
	{
		if(a==2)
			xajax_UserLogin(xajax.getFormValues('frm'));
		else
			document.frm.txtpass.focus();
	}
}
/**
HAI NAM
onkeydown function dateformat dung de chuyen 20010101 -> 2001-01-01
**/
function dateformat(controlName,event)
{
	var str=document.getElementById(controlName).value;
	var k=(event.which)?event.which : event.keyCode;
	if(k!=8)
		if(str.length==4)
		{
			for(var i=1 ;i<=4 ; i++)
				{
					document.getElementById(controlName).value=str+"-";
				}
		}
		else if(str.length==7)
		{
			for(var i=1 ;i<=6 ; i++)
				{
					document.getElementById(controlName).value=str+"-";
				}
		}

}
/**
HAI NAM
onkeypress function IsOnlyNumber(event,str) chi co phep nhap so
//str ='' chi nhap so
//str ='.' chi nhap so + "  .  "
**/
function IsOnlyNumber(event)
{
	var k=(event.which)?event.which : event.keyCode;
	if(k==null||k==8)
	return true;
	return (k < 48 || k > 57) ? false : true;
}



/**
HAI NAM
onkeypress function IsOnlyNumber(event,str) chi co phep nhap so
//str ='' chi nhap so
//str ='.' chi nhap so + "  .  "
**/
function IsOnlyFloat(event)
{
	var k=(event.which)?event.which : event.keyCode;
	if(k==null || k==8 || k == 46){
	return true;}
	return (k < 48 || k > 57) ? false : true;
}



function printpreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}

/**
 * BUI THI KIM XUAN
 * 2008/07/23
 * Check email
**/
function checkEmail(n,v){
var a=0;
var p=0;
for(var i=1;i<v.length;i++){
if(!v.charAt(i))
   return false;
else if(v.charAt(i)=='@')
       { a++;
          if(v.charAt(i+1)=='')
           {
             return false;
           }
       }
else if(v.charAt(i)=='.')
       { p++;
         if(v.charAt(i+1)==''||v.charAt(i+1)=='@'||v.charAt(i-1)=='@')
         {
           return false;
         }
       }
}

if(a==1&&p){
   return true;
}else {
   return false;
}
}


/**
 * Pham Duc Tien
 * 2008/07/23
 * Check Date
 * Check a date string is yyyy/mm/dd format or not.
 * If dateStr is yyyy/mm/dd format then return true.
 * Else return fasle.
**/
	function isDate(dateStr) {

		var datePat = /^(\d{4})(\/)(\d{2,2})(\/)(\d{2,2})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
			return false;
		}
		year = matchArray[1];
		month = matchArray[3];
		day = matchArray[5];
		if (month < 1 || month > 12) { // check month range
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
			return false;
			}
		}
		return true;
	}

	//onkeypress="InputNumberOne(this,event)"
	//Nhap number only
	function InputNumberOne(txt,e)
    {
         obj = document.all ? window.event : e;
        touch = document.all ? obj.keyCode : obj.which;
        var txtValue = txt.value;
        var ch = String.fromCharCode(touch)
        if(String(parseInt(txtValue + ch)) == "NaN" || (touch < 48 || touch > 57) )
        {
            if(document.all)
            {
                obj.returnValue = false;
            }
            else
            {
                obj.preventDefault();
            }
        }
    }

	function IsNumber(Expression)
	{
		Expression = Expression.toLowerCase();
		RefString = "0123456789.";

		if (Expression.length < 1)	return true;//Doan nay Tien sua. Trong truong hop
		//khong bat buoc phai nhap du lieu vao control can kiem tra

		for (var i = 0; i < Expression.length; i++)
		{
			var ch = Expression.substr(i, 1);
			var a = RefString.indexOf(ch, 0);
			if (a == -1)		return false;
		}
		return true;
	}

	function IsNumberFloat(Expression)
	{
		Expression = Expression.toLowerCase();
		RefString = "0123456789.";
		//if (Expression.length < 1)	return true;//Doan nay Tien sua. Trong truong hop
		//khong bat buoc phai nhap du lieu vao control can kiem tra

		for (var i = 0; i < Expression.length; i++)
		{
			var ch = Expression.substr(i, 1);
			var a = RefString.indexOf(ch, 0);
			if (a == -1)
			return false;
		}
		return true;
	}

	//Chi duoc nhap ky tu number, chay tren ca firefox
	//onkeypress="return isNumberKey(event)"
	function isNumberKey(evt)
	{
		var charCode = (evt.which) ? evt.which : event.keyCode
		if(charCode != 46)//44 Cho phep hien thi dau , 46 neu la dau .
		{
			if (charCode > 31 && (charCode < 48 || charCode > 57))
				return false;
		}
		return true;
	}