function isEmail(Email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(Email);
}
function isPassword(pw){
	var filter  = /^([a-zA-Z0-9])+$/;
	return filter.test(pw);
}
function isNumber(myStr){ 
	var filter = /^[0-9\.]+$/;
	return filter.test(myStr);
}
function validDay(day,month,year)
{
	switch(month)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:			
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			if(day==31)return false;
			break;
		case 2:
			if(year%4==0)
				if(day>29)return false;
			else if(day>28)return false;
			break;		
	}
	return true;
}
function isDay(date)
{
	var arr=new Array();
	var arr=date.split("/");
	date=new Date();
	var curday=date.getDate();
	var curmonth=date.getMonth();
	var curyear=date.getYear();
	if(arr.length==1)return false;
	var day=arr[0];
	var month=arr[1];
	var year=arr[2];
	if(day>31 || day<0) return false;
	if(month>12 || month<0) return false;
	if(year<curyear)return false;
	else 
		if(year==curyear)
		{
			if(month<curmonth)return false;
			if(month==curmonth)
				if(day<curday) return false;
		}
	return validDay(day,month,year);
}
//
function isChecked(formName, chkName){
	var i
	i=0;
	if (document.forms[formName][chkName].value == null) {
		while (i< document.forms[formName][chkName].length){
			if (document.forms[formName][chkName][i].checked) return true;
			i++;
		}	
	}
	else {
		if (document.forms[formName][chkName].checked) return true;
	}
	return false;
}
//
function UnicodeSet(iStr)
{
	for (i=0, oStr=''; i < iStr.length; i++)
	{
		switch ((j=iStr.charCodeAt(i)))
		{
		case 34:
			oStr=oStr.concat('&quot;');
			break;
		case 38:
			oStr=oStr.concat('&amp;');
			break;
		case 39:
			oStr = oStr.concat('&#39;');
			break;
		case 60:
			oStr = oStr.concat('&lt;');
			break;
		case 62:
			oStr = oStr.concat('&gt;');
			break;
		default:
			if (j < 32 || j > 127 || j==34 || j==39)
			{
				oStr=oStr.concat('&#').concat(j).concat(';');
			}
			else
			{
				oStr=oStr.concat(iStr.charAt(i)); 
			}
			break;
		}
	}
	
	return oStr;
}
function UnicodeGet(iStr)
{
	for (i=0, oStr=''; i < iStr.length; )
	{
		if (iStr.charCodeAt(i)==38)
		{
			if (iStr.charCodeAt(i + 1)==35)
			{
				p=iStr.indexOf(';', i  + 2);
				if (p!=-1)
				{
					if (p - i <= 7)
					{
						if (isFinite(iStr.substr(i + 2, p - i - 2)))
						{
							oStr = oStr.concat(String.fromCharCode(iStr.substr(i + 2, p - i - 2)));
							i = p + 1;
							continue;
						}
					}
				}
			}
			else
			{
				p=iStr.indexOf(';', i  + 1);
				if (p!=-1)
				{
					switch (iStr.substr(i + 1, p - i - 1))
					{
					case 'amp':
						oStr = oStr.concat('&');
						i = p + 1;
						break;
					case 'quot':
						oStr = oStr.concat('"');
						i = p + 1;
						break;
					case 'lt':
						oStr = oStr.concat('<');
						i = p + 1;
						break;
					case 'gt':
						oStr = oStr.concat('>');
						i = p + 1;
						break;
					}
				}
			}
		}
	
	
		oStr=oStr.concat(iStr.charAt(i));
		i++;
	}
	
	return oStr;
}

function xoadau(keyword)
{
	var len = keyword.length;
	var str = '', c;
	for(i=0; i < len; i++)
	{
		c = keyword.charCodeAt(i);
		// alert(c);
		

		if(( c>= 192 && c <= 195) || ( c>= 224 && c <= 227) || c==258 || c==259 || ( c>= 461 && c <= 7863))
		{
			str+='a';
		}else
			if(c==272 || c==273 )
			{
				str+='d';
			}else
				if((c>=200 && c<=202) || (c>=232 && c<=234) || ( c>= 7864 && c <= 7879))
				{
					str+='e';
				}else
					if(c==204 || c==205 ||c==236 || c==237 ||c==296 || c==297 || ( c>= 7880 && c <= 7883))
					{
						str+='i';
					}else
						if(c==217 || c==218 || c==249 || c==250 || c==360 || c==361 || c==431 || c==432 || ( c>= 7908 && c <= 7921))
						{
							str+='u';
						}else
							if((c>=210 && c<=213) || (c>=242 && c<=245) || c==416 || c==417 || ( c>= 7884 && c <= 7907))
							{
								str+='o';
							} else
								if(c==221 || c==253 || (c>= 7922 && c <= 7929))
								{
									str+='y';
								} else
									str+= keyword.charAt(i);
		// alert(c);
		//alert(keyword.charAt(i));
	}
	//alert(str);
	return str;
}
//
function isValidFileFolder(ffName){
	// Invalid character : \ / : * " < > |	
	if (ffName.indexOf('\\') >= 0) return false;
	if (ffName.indexOf('/') >= 0) return false;
	if (ffName.indexOf(':') >= 0) return false;
	if (ffName.indexOf('*') >= 0) return false;
	if (ffName.indexOf('"') >= 0) return false;
	if (ffName.indexOf('<') >= 0) return false;
	if (ffName.indexOf('>') >= 0) return false;
	if (ffName.indexOf('|') >= 0) return false;
	return true;
}
function popupWindow(wLink, wName, wWidth, wHeight)
{
    var wLeft = (window.screen.width - wWidth)/2;
    var wTop = (window.screen.height - wHeight)/2;
    var wPopup = window.open(wLink,wName,'location=0,status=1,scrollbars=1,width='+wWidth+',height='+wHeight+',top='+wTop+',left='+wLeft);
    wPopup.focus();
}

function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
  return ((c >= "0") && (c <= "9"))
}
// Add Item to ListBox or ComboBox
function addItem(objBox, itemText, itemValue) {
    var objItem = new Option(itemText, itemValue);
    var itemsCount = objBox.options.length;
    objBox.options[itemsCount] = objItem;
}
// Delete Item from ListBox or ComboBox
function deleteItem(objBox, itemIndexDelete) {
    if (objBox.options.length!=0) { objBox.options[itemIndexDelete]=null }
}