﻿// JScript File

function isTelNo(str) {
	var pattern = "0123456789-() ";
	if (str.length > 0) {
		if (str.length < 5) {
			return false;
		} else {
			for (var a=0; a<pattern.length; a++) {
				if (pattern.indexOf(str.charAt(a),0) == -1) return false;
			}
		}
	}
	return true;
}
 function isMoney(str) {
	var pattern = "0123456789.";	
	for (var a=0; a<pattern.length; a++) 
		if (pattern.indexOf(str.charAt(a),0) == -1) return false;	
	return true;
}
function isNumber(str) {
	var pattern = "0123456789";	
	for (var a=0; a<pattern.length; a++) 
		if (pattern.indexOf(str.charAt(a),0) == -1) return false;	
	return true;
}
function isMobile(str) {
	var pattern = "0123456789-() ";
	if (str.length > 0) {
		if (str.length <10) {
			return false;
		} else {
			for (var a=0; a<pattern.length; a++) {
				if (pattern.indexOf(str.charAt(a),0) == -1) return false;
			}
		}
	}
	return true;
}
function isEmailAddr(email) {
	var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789@~";
	var theStr = new String(email)
	var index = theStr.indexOf("@");

	for (var a=0; a<pattern.length; a++) {
		if (pattern.indexOf(email.charAt(a),0) == -1) return false;
	}
	if (theStr.indexOf(" ",0) != -1) return false;
	if (index > 0) {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)) return true;
	}
	return false;
}

function isURL(str) {
	var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789/~:";
	if (str.length > 0) {
		if (str.length < 5 ) {
			return false;
		} else {
			if (str.lastIndexOf(".") == -1) { 											// khong tim thay dau cham
				return false;
			} else {
				if (str.lastIndexOf(".") == (str.length - 1)) return false;				// dau cham nam o cuoi cung
//				if (!isAlpha(str.charCodeAt(str.lastIndexOf(".") + 1))) return false;	// sau dau cham khong phai ki tu Alphabet
			}
			for (var c=0; c<pattern.length; c++) {
				if (pattern.indexOf(str.charAt(c),0) == -1) return false;				// ki tu khong hop le
			}
		}
	}
	return true;
}
//KIEM TRA NGAY THANG
function isLeafYear(intYear) { 										/*Ham kiem tra nam nhuan*/
	var bleReturn = false;

	intYear += 2000;
	if (((intYear % 4) == 0) && !((intYear % 100) == 0)) bleReturn = true;
	else bleReturn = ((intYear % 400) == 0);
	return bleReturn;
}
function isValidDate(d, m, y) { 									/*Ham kiem tra ngay hop le*/
	var bleReturn = false;

	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
		bleReturn = (d >= 1 && d <= 31);
	} else if (m == 4 || m == 6 || m == 9 || m == 11) {
		bleReturn = (d >= 1 && d <= 30);
	} else if (m == 2) {
		if (isLeafYear(y)) bleReturn = (d >= 1 && d <= 29);
		else bleReturn = (d >= 1 && d <= 28);
	}
	return bleReturn;
}
function isDate(strDate) {
	var arrDate;
	var type=1;// type = 2: mm/dd/yyyy ---- type = 1: dd/mm/yyyy
	separate="/";//dau cach giua ngay thang nam
	arrDate = strDate.split(separate);
	//alert(arrDate);
	if (arrDate.length != 3) return false;
	else
		for (var i=0; i<arrDate.length; i++) {
			if (isNaN(arrDate[i])) return false;
		}
		if (type == 1) return isValidDate(parseInt(arrDate[0],10), parseInt(arrDate[1],10), parseInt(arrDate[2],10));
		else if (type == 2) return isValidDate(parseInt(arrDate[1],10), parseInt(arrDate[0],10), parseInt(arrDate[2],10));
}
function openWindow(filename,winname,width,height) {
	var features, top, left;

	left = (window.screen.width - width) / 2;
	top = (window.screen.height - height) / 2;
	features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
	void(window.open(filename,winname,features));
}
function selectList(sel,val)
{
	for(i=0;i<sel.options.length;i++)
		if(sel.options[i].value==val) 
		{
			sel.options[i].selected=true;
			break;
		}
}	
function radCheck(rad,val)
{
	for(i=0;i<rad.length;i++)
	{
		if(rad[i].value==val)
		{
			rad[i].checked=true;
			break;
		}
	}
}
function showAlertDiv(obj,title,width,height)
{
    var bzAlertShow=dhtmlmodal.open('Alert', 'div', obj, title, 'width='+width.toString()+'px,height='+height.toString()+'px,left=220px,top=100px,resize=0,scrolling=0');
    return bzAlertShow;
}
function addInput(idContainer,idDIV,type,name,id)
{
	div=document.createElement("div");
	div.setAttribute("id",idDIV);
	div.innerHTML="<input style=\"width:260px;\" type=\""+type+"\" name=\""+name+"\" value=\"\" id=\""+id+"\"/>";
	document.getElementById(idContainer).appendChild(div);
}
function searchCombo(oCBO,val)
{
    for(i=0;i<oCBO.options.length;i++)
        if(oCBO.options[i].text.toLowerCase().indexOf(val.toString().toLowerCase())!=-1)
        {
            oCBO.options[i].selected=true;
            break;
        }
}
function strReplace(val)
{
    str = val.toString();    
    //str = str.replace("."," .");
    //str = str.replace("?"," ?");
    //---------------------------------a^
    str = str.replace("ấ", "a");
    str = str.replace("ầ", "a");
    str = str.replace("ẩ", "a");
    str = str.replace("ẫ", "a");
    str = str.replace("ậ", "a");
    //---------------------------------A^
    str = str.replace("Ấ", "A");
    str = str.replace("Ầ", "A");
    str = str.replace("Ẩ", "A");
    str = str.replace("Ẫ", "A");
    str = str.replace("Ậ", "A");
    //---------------------------------a(
    str = str.replace("ắ", "a");
    str = str.replace("ằ", "a");
    str = str.replace("ẳ", "a");
    str = str.replace("ẵ", "a");
    str = str.replace("ặ", "a");
    //---------------------------------A(
    str = str.replace("Ắ", "A");
    str = str.replace("Ằ", "A");
    str = str.replace("Ẳ", "A");
    str = str.replace("Ẵ", "A");
    str = str.replace("Ặ", "A");
    //---------------------------------a
    str = str.replace("á", "a");
    str = str.replace("à", "a");
    str = str.replace("ả", "a");
    str = str.replace("ã", "a");
    str = str.replace("ạ", "a");
    str = str.replace("â", "a");
    str = str.replace("ă", "a");
    //---------------------------------A
    str = str.replace("Á", "A");
    str = str.replace("À", "A");
    str = str.replace("Ả", "A");
    str = str.replace("Ã", "A");
    str = str.replace("Ạ", "A");
    str = str.replace("Â", "A");
    str = str.replace("Ă", "A");
    //---------------------------------e^
    str = str.replace("ế", "e");
    str = str.replace("ề", "e");
    str = str.replace("ể", "e");
    str = str.replace("ễ", "e");
    str = str.replace("ệ", "e");
    //---------------------------------E^
    str = str.replace("Ế", "E");
    str = str.replace("Ề", "E");
    str = str.replace("Ể", "E");
    str = str.replace("Ễ", "E");
    str = str.replace("Ệ", "E");
    //---------------------------------e
    str = str.replace("é", "e");
    str = str.replace("è", "e");
    str = str.replace("ẻ", "e");
    str = str.replace("ẽ", "e");
    str = str.replace("ẹ", "e");
    str = str.replace("ê", "e");
    //---------------------------------E
    str = str.replace("É", "E");
    str = str.replace("È", "E");
    str = str.replace("Ẻ", "E");
    str = str.replace("Ẽ", "E");
    str = str.replace("Ẹ", "E");
    str = str.replace("Ê", "E");
    //---------------------------------i
    str = str.replace("í", "i");
    str = str.replace("ì", "i");
    str = str.replace("ỉ", "i");
    str = str.replace("ĩ", "i");
    str = str.replace("ị", "i");
    //---------------------------------I
    str = str.replace("Í", "I");
    str = str.replace("Ì", "I");
    str = str.replace("Ỉ", "I");
    str = str.replace("Ĩ", "I");
    str = str.replace("Ị", "I");
    //---------------------------------o^
    str = str.replace("ố", "o");
    str = str.replace("ồ", "o");
    str = str.replace("ổ", "o");
    str = str.replace("ỗ", "o");
    str = str.replace("ộ", "o");
    //---------------------------------O^
    str = str.replace("Ố", "O");
    str = str.replace("Ồ", "O");
    str = str.replace("Ổ", "O");
    str = str.replace("Ô", "O");
    str = str.replace("Ộ", "O");
    //---------------------------------o*
    str = str.replace("ớ", "o");
    str = str.replace("ờ", "o");
    str = str.replace("ở", "o");
    str = str.replace("ỡ", "o");
    str = str.replace("ợ", "o");
    //---------------------------------O*
    str = str.replace("Ớ", "O");
    str = str.replace("Ờ", "O");
    str = str.replace("Ở", "O");
    str = str.replace("Ỡ", "O");
    str = str.replace("Ợ", "O");
    //---------------------------------u*
    str = str.replace("ứ", "u");
    str = str.replace("ừ", "u");
    str = str.replace("ử", "u");
    str = str.replace("ữ", "u");
    str = str.replace("ự", "u");
    //---------------------------------U*
    str = str.replace("Ứ", "U");
    str = str.replace("Ừ", "U");
    str = str.replace("Ử", "U");
    str = str.replace("Ữ", "U");
    str = str.replace("Ự", "U");
    //---------------------------------y
    str = str.replace("ý", "y");
    str = str.replace("ỳ", "y");
    str = str.replace("ỷ", "y");
    str = str.replace("ỹ", "y");
    str = str.replace("ỵ", "y");
    //---------------------------------Y
    str = str.replace("Ý", "Y");
    str = str.replace("Ỳ", "Y");
    str = str.replace("Ỷ", "Y");
    str = str.replace("Ỹ", "Y");
    str = str.replace("Ỵ", "Y");
    //#---------------------------------DD
    str = str.replace("Đ", "D");
    str = str.replace("Đ", "D");
    str = str.replace("đ", "d");
    //---------------------------------o
    str = str.replace("ó", "o");
    str = str.replace("ò", "o");
    str = str.replace("ỏ", "o");
    str = str.replace("õ", "o");
    str = str.replace("ọ", "o");
    str = str.replace("ô", "o");
    str = str.replace("ơ", "o");
    //---------------------------------O
    str = str.replace("Ó", "O");
    str = str.replace("Ò", "O");
    str = str.replace("Ỏ", "O");
    str = str.replace("Õ", "O");
    str = str.replace("Ọ", "O");
    str = str.replace("Ô", "O");
    str = str.replace("Ơ", "O");
    //---------------------------------u
    str = str.replace("ú", "u");
    str = str.replace("ù", "u");
    str = str.replace("ủ", "u");
    str = str.replace("ũ", "u");
    str = str.replace("ụ", "u");
    str = str.replace("ư", "u");
    //#---------------------------------U
    str = str.replace("Ú", "U");
    str = str.replace("Ù", "U");
    str = str.replace("Ủ", "U");
    str = str.replace("Ũ", "U");
    str = str.replace("Ụ", "U");
    str = str.replace("Ư", "U");
    //#---------------------------------
    return str;
    
}


//function addInputFile()
//{
//	if(num_file>=10)
//		alert("{File_Error}");
//	else
//	{
//		num_file++;
//		div=document.createElement("div");
//		div.setAttribute("id","div"+num_file.toString());
//		div.innerHTML="<input style=\"width:260px;\" type=\"file\" name=\"txtFile[]\" value=\"\" id=\"file"+num_file.toString()+"\"/>";
//		document.getElementById("file").appendChild(div);
//		
//	}
//}
