﻿//Thùc hiÖn bëi Haso Design - haso@hcm.vnn.vn
function openChild(file,window) 
	{
	   	childWindow=open(file,window,'resizable=yes,width=500,height=350,scrollbars=yes');
	   	if (childWindow.opener == null) childWindow.opener = self;
	}

function ToolbarRed() {
	oSrcEl = window.event.srcElement;
	if (oSrcEl.tagName == "IMG") {
		oSrcEl.src = oSrcEl.src.substring(0,(oSrcEl.src.indexOf(".gif"))) + "_.gif";
		window.event.cancelBubble = true;
	}
}
function ToolbarWhite() {
	oSrcEl = window.event.srcElement
	if (oSrcEl.tagName == "IMG") {
		oSrcEl.src = oSrcEl.src.substring(0,(oSrcEl.src.indexOf("_.gif"))) + ".gif";
		window.event.cancelBubble = true;
	}
}

//----------------------------------------------------

function ZoomIn(dir,image,name) {
 
 stats="toolbar=no,location=no,scrollbars=no,directories=no,status=no,menubar=no,width=430,height=410,top=100,left=100,resizable=yes";
 popUpWin = window.open('','popWin',stats);

 zhtm= '<HTML><HEAD><TITLE>Zoom In Images: ' + name+ '</TITLE>';
 zhtm += '<SCRIPT language=javascript src="../pages/pso.js"></SCRIPT></head>';
 zhtm += '<body>';
 zhtm += '<p align="center">';
if (name.length !=0 || name.length !=1) zhtm += '<FONT face=Arial color=#008080 size=4>'+ name+'</FONT><br><br>';
 zhtm += '<a href="javascript:window.close();" ><IMG SRC="../images/' + dir + '/' + image + 'i.gif" border=0></a>';
 zhtm += '</P><P ALIGN="right"><font face="arial" color="#000000" size="1">© 2004 by <a href="mailto:webmaster@binhthuan.gov.vn?subject=Chao cac ban !">PSO Net</a></font></p>';
 zhtm += '</BODY></HTML>';
 window.popUpWin.document.write(zhtm);
 window.popUpWin.document.close();
}
//----------------------------------------------------
function ViewI(dir,image,name,align) {
if (align== '') jalign='justify';
if (align== 'c') jalign='center';
if (align== 'l') jalign='left';
if (align== 'r') jalign='right';
if (dir=='t') jdir='tinhdoan';
if (dir=='k') jdir='khac';
if (dir=='m') jdir='picture';
if (dir=='n') jdir='pictures';

 zhtm= '<table cellPadding="5" width="1" align="'+jalign+'"><tr><td align="middle">';
 zhtm += "<a href=\"javascript:ZoomIn('" + jdir + "','" + image + "','" + name + "')\">";
 zhtm += '<img src="../images/' + jdir + '/' + image + '.gif" border=0 alt="'+ name +'"></a></td></tr>';
 zhtm += '<tr><td align="middle"><a class=note>'+ name+'</a></td></tr></table>';
document.write(zhtm);
}
//----------------------------------------------------
function ViewA(dir,image,name,img,align) {
if (align== '') jalign='justify';
if (align== 'c') jalign='center';
if (align== 'l') jalign='left';
if (align== 'r') jalign='right';
if (img== '') jimg='.gif';
if (img!='') jimg='.jpg';
if (dir=='c') jdir='cacgiai';
if (dir=='o') jdir='other';
if (dir=='m') jdir='picture';
if (dir=='n') jdir='pictures';
if (dir=='t') jdir='tinhdoan';
if (dir=='k') jdir='ketqua';

 zhtm= '<table cellPadding="5" width="1" align="'+jalign+'"><tr><td align="middle">';
 zhtm += '<img src="../images/' + jdir +'/' + image +jimg + '" border=0 alt="'+ name +'"></td></tr>';
 zhtm += '<tr><td align="middle"><a class=note>'+ name+'</a></td></tr></table>';
document.write(zhtm);
}
//----------------------------------------------------
function OnClick(fform){
	var errorMsg = "";
	if(fform.Name.value =="")
	{
		errorMsg += "\nLoi ban mac phai do la: Ban chua nhap Ten dang nhap";
		fform.Name.focus();
	}
if(fform.Name.value =="")
	{
		errorMsg += "\nLoi ban mac phai do la: Ban chua mat khau truy cap";
		fform.Password.focus();
	}
	if (errorMsg != ""){
		msg = "------------------------------------------------------------------\n";
		msg += "Da co mot vai loi xay ra trong qua trinh BAN dang nhap.\n";
		msg += "Ban vui long kiem tra lai ! \n";
		msg += "-----------------------------------------------------------------\n\n";
		errorMsg += alert(msg + errorMsg + "\n\n");
		return (false);
	}
	return (true);
//document.fform.submit();
}
//----------------------------------------------------
function CheckForm()
{
with (document.email_regist_form )
	{if (email.value=="")
		{	alert("Bạn chưa nhập địa chỉ E-mail!\n Please input your E-mail!");
			email.focus();
			return false;
		}
		else
		{if(email.value.indexOf("@")<0||email.value.indexOf(".")<0)
			{
				alert("Bạn chưa nhập đúng địa chỉ email!\n VD: thaimex@hcm.vnn.vn");
				email.focus();
				return false;
			}
		}
	}
}
//----------------------------------------------------
message = "  Chao mung cac ban vieng tham WebSite: DANG KY KINH DOANH  !^" +
"  Trang tin chinh thuc DANG KY KINH DOANH cua So Ke hoach va dau tu tinh Binh Thuan!^" +
               "^"
  scrollSpeed = 25
  lineDelay   = 1500
  txt         = ""

function scrollText(pos) {
    if (message.charAt(pos) != '^') {
      txt    = txt + message.charAt(pos)
      status = txt
      pauze  = scrollSpeed
    }
    else {
      pauze = lineDelay
      txt   = ""
      if (pos == message.length-1) pos = -1
    }
    pos++
    setTimeout("scrollText('"+pos+"')",pauze)
  }
   //-->
//scrollText(0)
//====================================
var pattern="";
// Khoi tao form
// Kiem tra tung o nhap
function init()
{
	//theform.hoten.disabled = true;
	//theform.cmnd.disabled = true;
	//theform.txtDNTN.disabled = true;

	if (theform.tong_von.value=="") 
		theform.tong_von.value = 0;
}
//================================================
function  convert(control)
{
	control.value = control.value.toLowerCase( );
}
//================================================
// Truoc khi dong form
function uninit()
{
	theform.hoten.disabled = false;
	theform.cmnd.disabled = false;
}

//================================================
function Ktra()
{
	var strErrMsg="";
	if ((theform.Type.value=="12")||(theform.Type.value=="22"))
	{
		strLoai="h&#7897; chi&#7871;u"
		strDC="&#273;&#7883;a ch&#7881; th&#432;&#7901;ng trú"
	}
	else
	{
		strLoai="cmnd"
		strDC="N&#417;i &#273;&#259;ng ký h&#7897; kh&#7849;u th&#432;&#7901;ng trú"
		if (theform.dtoc.value.length==0)
			strErrMsg = strErrMsg + "<u>Dân t&#7897;c</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
	}	
	
	if (theform.nsinh.value.length==0) 
		strErrMsg = strErrMsg + "<u>Ngày sinh</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
	
	if (theform.cmnd_ngay.value.length==0) 
		strErrMsg = strErrMsg + "<u>Ngày c&#7845;p " + strLoai + "</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
	else
		if (isValidDate(theform.cmnd_ngay.value)!=0)
			strErrMsg = strErrMsg + "<u>Ngày c&#7845;p " + strLoai + "</u> : Ngày " + theform.txtNgayCap.value + " không h&#7907;p l&#7879;.<br>";
		else
		{
			dtest = new Date(formatNgay(theform.cmnd_ngay.value));
			y1=parseInt(theform.txtNam.value);
			y2=dtest.getFullYear()
			m1=parseInt(theform.txtThang.value);
			m2=dtest.getMonth()
			d1=parseInt(theform.txtNgay.value);
			d2=dtest.getDate()
			if (y1 < y2)
				strErrMsg = strErrMsg + "<u>Ngày c&#7845;p " + strLoai + "</u> : Không th&#7875; l&#7899;n h&#417;n ngày hi&#7879;n hành.<br>";
			if (y1 == y2)
			{
				if (m1 < m2)
					strErrMsg = strErrMsg + "<u>Ngày c&#7845;p " + strLoai + "</u> : Không th&#7875; l&#7899;n h&#417;n ngày hi&#7879;n hành.<br>";
				if (m1 == m2)
					if (d1 < d2)
						strErrMsg = strErrMsg + "<u>Ngày c&#7845;p " + strLoai + "</u> : Không th&#7875; l&#7899;n h&#417;n ngày hi&#7879;n hành.<br>";
			}			
		}
	
	dtest1 = new Date(formatNgay(theform.cmnd_ngay.value));
	dtest2 = new Date(formatNgay(theform.nsinh.value));
	y1=dtest1.getFullYear()
	y2=dtest2.getFullYear()
	m1=dtest1.getMonth()
	m2=dtest2.getMonth()
	d1=dtest1.getDate()
	d2=dtest2.getDate()
	if (y1 < y2)
		strErrMsg = strErrMsg + "Ngày c&#7845;p " + strLoai + " không th&#7875; l&#7899;n h&#417;n ngày sinh.<br>";
	if (y1 == y2)
	{
		if (m1 < m2)
			strErrMsg = strErrMsg + "Ngày c&#7845;p " + strLoai + " không th&#7875; l&#7899;n h&#417;n ngày sinh.<br>";
		if (m1 == m2)
			if (d1 < d2)
				strErrMsg = strErrMsg + "Ngày c&#7845;p " + strLoai + " không th&#7875; l&#7899;n h&#417;n ngày sinh.<br>";
	}
		
if (theform.so_ct.value=="KHAC")
if (trim(theform.so_ct.value)=="")
		{
			strErrMsg = strErrMsg + "<u>Loại chứng thực</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
		}
	if (theform.noicap_ct.value.length==0)
		strErrMsg = strErrMsg + "<u>N&#417;i c&#7845;p " + strLoai + "</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
		
	if (theform.noi_dkhk.value.length==0) 
		strErrMsg = strErrMsg + "<u>" + strDC + "</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
		
	if (theform.noi_htai.value.length==0) 
		strErrMsg = strErrMsg + "<u>Ch&#7895; &#7903; hi&#7879;n t&#7841;i</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
		
	if (theform.ten_ct.value.length==0) 
		strErrMsg = strErrMsg + "<u>Tên doanh nghi&#7879;p</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
  			
	if (theform.dchi_ct.value.length==0) 
		strErrMsg = strErrMsg + "<u>&#272;&#7883;a ch&#7881; doanh nghi&#7879;p</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
		
	if (theform.nkd.value.length==0) 
		strErrMsg = strErrMsg + "<u>Ngành ngh&#7873; kinh doanh</u> : B&#7855;t bu&#7897;c ph&#7843;i nh&#7853;p.<br>";
		
	strTongVon=repl(theform.tong_von.value)	
	strTongVDL=repl(theform.vdle.value)	
	//VonPhapDinh =repl(theform.vphapdinh.value)
	//if (VonPhapDinh!=0) 
	//if ( VonPhapDinh>parseInt(repl(theform.vphapdinh.value))  )
	//		strErrMsg = strErrMsg + "<u>Vốn pháp định phải nhỏ hơn hoặc bằng tổng vốn</u><br>";

	if (isNaN(parseInt(strTongVon)))
		strErrMsg = strErrMsg + "<u>T&#7893;ng v&#7889;n kinh doanh</u> : Ph&#7843;i là s&#7889;.<br>";
	else
		if ((strTongVon.indexOf("e") != -1)||(strTongVon.length > 15))
			strErrMsg = strErrMsg + "<u>T&#7893;ng v&#7889;n kinh doanh</u> : Giá tr&#7883; quá l&#7899;n.<br>";			
		

	if ((parseInt(repl(theform.tong_von.value)) ==  0 ))
		strErrMsg=strErrMsg + "T&#7893;ng v&#7889;n &#273;&#259;ng ký kinh doanh không có giá tr&#7883;. Xin nh&#7853;p l&#7841;i!<BR>";
	
	return strErrMsg;
}
//================================================
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
//================================================
// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
//================================================
// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

//================================================
function FormatTenDN()
{
	//theform.ten_ct.value=FormatStr(theform.ten_ct.value)
}
//================================================
function repl(str)
{
	var strResult="";
	for(i=0;i<str.length;i++)
		if (str.charAt(i)!=pattern)
			strResult=strResult + str.charAt(i)
	return strResult;
}
//================================================
function repl1(str)
{
	var strResult="";
	for(i=0;i<str.length;i++)
		if ((str.charAt(i)!="$")&&(str.charAt(i)!=","))
			strResult=strResult + str.charAt(i)
	return strResult;
}
//================================================
function FormatStr(strTen)
{
	strKQ=strTen
	nViTri = strKQ.indexOf(" ");
	if (nViTri != -1)
	{
		strSub = strKQ.substring(0,nViTri)
		strKQ = strKQ.substring(nViTri)
		nViTri = strKQ.indexOf(" ")
		while (nViTri != -1)
		{
			strTam = strKQ.substring(0,nViTri)
			strSub = strSub + " " + strTam
			strKQ = strKQ.substring(nViTri)
			nViTri = strKQ.indexOf(" ")
		}
		strSub = strSub + " " + strKQ
	}
	else
		strSub = strKQ
	return (strSub)
	
}
//================================================
// Kiem tra cac yeu cau
// trong form "Dang ky Kinh doanh"
function KtraDKKD()
{
	theform.txtLan.value=""
	strErrMsg=Ktra();
	
	if (strErrMsg!="")
	{
		event.returnValue=false;
		
		frmMsg.txtMsg.value=strErrMsg;
		frmMsg.submit();
	}
	else uninit();
	return;
}
//================================================
function KtraSoLoai()
{
	strErrMsg=Ktra();

	if (strErrMsg!="")
	{
		event.returnValue=false;
		frmMsg.txtMsg.value=strErrMsg;
		frmMsg.submit();
	}
	else uninit();
	return;
}
//================================================
// Kiem tra ngay hop le.
// returns 0 : hop le
// returns 1 : sai format (dd/mm/ccyy, dd-mm-ccyy, ddmmccyy, d/m/ccyy , d-m-ccyy )
// returns 2 : khong hop le (i.e. 30/02/1999)
function isValidDate(strDate)
{
  var retval = 0
  var aDDMMCCYY
  var dtest
  // Kiem tra dung format
  if (/^(\d\d?-\d\d?-\d{4})|(\d\d?\/\d\d?\/\d{4})|(\d{8})$/.test(strDate))
  {
    if (/\//.test(strDate))
    {
      aDDMMCCYY = strDate.split("/");
    }
    else
    if (/-/.test(strDate))
    {
      aDDMMCCYY = strDate.split("-");
    }
    else
    {
      aDDMMCCYY = Array(strDate.substr(0,2), strDate.substr(2,2), strDate.substr(4,4))
    }    
	dtest = new Date(aDDMMCCYY[1] + "/" + aDDMMCCYY[0] + "/" + aDDMMCCYY[2]);      
    if (dtest.getDate() != aDDMMCCYY[0] || dtest.getMonth() +1 != aDDMMCCYY[1] || dtest.getFullYear() != aDDMMCCYY[2])
    {
      retval = 2
    }
  }
  else
  {
	retval = 1
  }
  return retval
}
//================================================
function KtraNgaySinh(obj)
{	
	strLoai="cmnd"
	dtest = new Date(formatNgay(obj.value));
	dNgaySinh = new Date(formatNgay(theform.nsinh.value));
	y1=parseInt(theform.txtNam.value);
	y2=dtest.getFullYear()

		if (obj.value.length==4 )
		{
			num = repl1(obj.value.toString());
		if (isNaN(num)) 
		{
			alert("Nam sinh " + obj.value + " khong hop le!");
			obj.value="";
			obj.focus();
			return;

		}
		else
		{
			if (y1- obj.value < 18)
			{
				alert("Ban chua du tuoi de dang ky thanh lap doanh nghiep ! (18 tuoi)");
				obj.value="";
				obj.focus();
				return;
			}
		
		}

		}


	if (obj.value.length!=0 && obj.value.length!=4 )
	{
		if (isValidDate(obj.value)!=0)
		{		
			alert("Ngay " + obj.value + " khong hop le!");
			obj.value="";
			obj.focus();
			return;
		}
		
		dtest = new Date(formatNgay(obj.value));
		dNgaySinh = new Date(formatNgay(theform.nsinh.value));
		y1=parseInt(theform.txtNam.value);
		y2=dtest.getFullYear()
		m1=parseInt(theform.txtThang.value);
		m2=dtest.getMonth()
		d1=parseInt(theform.txtNgay.value);
		d2=dtest.getDate()
		if (y1 < y2)
		{
			alert("Ngay sinh " + strLoai + " khong duoc lon hon ngay hien hanh");
			obj.value="";
			obj.focus();
			return;
		}	
		if (y1 == y2)
		{
			if (m1 < m2)
			{
				alert("Ngay sinh " + strLoai + " khong duoc lon hon ngay hien hanh");
				obj.value="";
				obj.focus();
				return;

			}	
			if (m1 == m2)
				if (d1 < d2)
				{
					alert("Ngay sinh " + strLoai + " khong duoc lon hon ngay hien hanh");
					obj.value="";
					obj.focus();
					return;

				}
		}
		

		if (y1-y2 < 18)
		
		{
			alert("Ban chua du tuoi de dang ky thanh lap doanh nghiep ! (18 tuoi)");
			obj.value="";
			obj.focus();
			return;
		}
		if (dtest.getFullYear()-dNgaySinh.getFullYear()<0)
		{
			alert("Ban chua du tuoi de dang ky thanh lap doanh nghiep ! (18 tuoi)");
			obj.value="";
			obj.focus();
			return;
		}
	}
	
	if (y1-y2 == 18 && strLoai=="cmnd")
	{
		if (m1 < m2 +1)
		{
			alert("Ban chua du tuoi de dang ky thanh lap doanh nghiep ! (18 tuoi)");
			obj.value="";
			obj.focus();
			return;
		}
		if (m1 == m2 +1 && d1 < d2 )
		{
			alert("Ban chua du tuoi de dang ky thanh lap doanh nghiep ! (18 tuoi)");
			obj.value="";
			obj.focus();
			return;
		}
		
	}

}
//================================================
function KtraNgaySinhKieuVarchar(obj)
{
	if (obj.value.length!=0 && obj.value.length!=4)
	{
		if (isValidDate(obj.value)!=0)
		{		
			alert("Ngµy " + obj.value + " kh«ng hîp lÖ!");
			obj.value=""
			obj.focus();
			return;
		}
		dtest = new Date(formatNgay(obj.value));
		y = parseInt(theform.txtNam.value);
		if (y - dtest.getFullYear() < 18)
		{
			alert("Ng­êi d­íi 18 tuæi ch­a ®ñ ®iÒu kiÖn ®¨ng ký thµnh lËp doanh nghiÖp.");
			obj.value=""
			obj.focus();
		}	
	}
}
//================================================
function KtraDT(obj)
{
	if (obj.value.length!=0)
	{
		if ((obj.value.length!=0 && obj.value.length>15) || isNaN(obj.value))
		{	
			alert("Nhap lai so dien thoai");
			obj.value="";
			obj.focus();
		}
	}
}
//================================================
// kiem tra o nhap ngay cap cmnd hop le
function KtraNgayCap(obj)
{	
	strLoai="cmnd"
	if (obj.value.length!=0)
	{
		if (isValidDate(obj.value)!=0)
		{		
			alert("Ngay " + obj.value + " khong hop le!");
			obj.value="";
			obj.focus();
			return;
		}
		
		dtest = new Date(formatNgay(obj.value));
		dNgaySinh = new Date(formatNgay(theform.cmnd_ngay.value));
		y1=parseInt(theform.txtNam.value);
		y2=dtest.getFullYear()
		m1=parseInt(theform.txtThang.value);
		m2=dtest.getMonth()
		d1=parseInt(theform.txtNgay.value);
		d2=dtest.getDate()
		if (y1 < y2)
		{
			alert("Ngay cap " + strLoai + " khong duoc lon hon ngay hien hanh");
			obj.value="";
			obj.focus();
			return;
		}	
		if (y1 == y2)
		{
			if (m1 < m2+1)
			{
				alert("Ngay cap " + strLoai + " khong duoc lon hon ngay hien hanh");
				obj.value="";
				obj.focus();
				return;

			}	
			if (m1 == m2+1)
				if (d1 < d2)
				{
					alert("Ngay cap " + strLoai + " khong duoc lon hon ngay hien hanh");
					obj.value="";
					obj.focus();
					return;

				}
		}
		
		
		
		if (y1-y2 > 15)
		
		{
			alert("Khong duoc su dung giay cmnd da duoc cap tren 15 nam");
			obj.value="";
			obj.focus();
			return;
		}
		if (dtest.getFullYear()-dNgaySinh.getFullYear()<0)
		{
			alert("Nam cap " + strLoai + " khong duoc nho hon nam sinh");
			obj.value="";
			obj.focus();
			return;
		}
	}
	
	if (y1-y2 == 15)
	{
		if (m1 > m2 +1)
		{
			alert("Khong duoc su dung giay cmnd da duoc cap tren 15 nam");
			obj.value="";
			obj.focus();
			return;
		}
		if (m1 == m2 +1 && d1 > d2 )
		{
			alert("Khong duoc su dung giay cmnd da duoc cap tren 15 nam");
			obj.value="";
			obj.focus();
			return;
		}
		
	}

}
//================================================
function KtraNgay(obj)
{	
	if (obj.value.length!=0)
	{
		if (isValidDate(obj.value)!=0)
		{		
			alert("Ngay khong hop le!");
			obj.value="";
			obj.focus();
			return;
		}
		
		dtest = new Date(formatNgay(obj.value));
		y1=parseInt(theform.txtNam.value);
		y2=dtest.getFullYear()
		m1=parseInt(theform.txtThang.value);
		m2=dtest.getMonth()
		d1=parseInt(theform.txtNgay.value);
		d2=dtest.getDate()
		if (y1 < y2)
		{
			alert("Ngay cap khong duoc lon hon ngay hien hanh");
			obj.value="";
			obj.focus();
			return;
		}	
		if (y1 == y2)
		{
			if (m1 < m2+1)
			{
				alert("Ngay cap khong duoc lon hon ngay hien hanh");
				obj.value="";
				obj.focus();
				return;

			}	
			if (m1 == m2+1)
				if (d1 < d2)
				{
					alert("Ngay cap khong duoc lon hon ngay hien hanh");
					obj.value="";
					obj.focus();
					return;

				}
		}}

}
//================================================

function formatNgay(strNgay)
{
	var s="";
	var arr;
	n=strNgay.indexOf("/")
	if (n!=-1)
	{
		arr=strNgay.split("/")
		s=arr[1] + "/" + arr[0] + "/" + arr[2]
	}
	else
	{
		n=strNgay.indexOf("-")
		if (n!=-1)
		{
			arr=strNgay.split("-")
			s=arr[1] + "-" + arr[0] + "-" + arr[2]
		}	
	}
	return (s);
}
//================================================
// Ham chuyen kieu du lieu so sang dang de doc hon
function formatCurrency(num) 
{
	num = repl1(num.toString());
	if (isNaN(num)) 
		num = "0"
	else
		if (parseInt(num)<0)
			num = "0"
	//cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	//if (cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
	//return (num + '.' + cents);

	return (num);
}
//==========================================
function TinhSoCoPhan(num) 
{
if (theform.txtMenhGia.value !=0 )
{
//  var a= parseFloat(repl1(theform.txtMenhGia.value))
	var a = repl1(theform.mgia.value)*1
	theform.tong_cp.value	=(repl1(theform.tong_von.value)*1)/a;		
//	theform.txtSoCoPhan.value	=20/10;

}
else
	theform.txtSoCoPhan.value=0;

}
//=======================================
// RETURN: true  -> tim dung tu khoa
//			 false -> khong tim thay
function TimTuKhoa(strNganh,strTuKhoa)
{	
	var i,j;
	aQuote = new Array(' ',',','.',';');
	i = strNganh.indexOf(strTuKhoa);
	if ( i>=0 )  // tim thay
	{
		if (i-1 >= 0)
		{
			boolNotFound = true;
			for (j=0; j<aQuote.length; j++)
				if (strNganh.charAt(i-1) == aQuote[j])
					boolNotFound = false;
			if (boolNotFound) return false;
		}
		i = i + strTuKhoa.length;
		if (i < strNganh.length)
		{
			boolNotFound = true;
			for (j=0; j<aQuote.length; j++)
				if (strNganh.charAt(i) == aQuote[j])
					boolNotFound = false;
			if (boolNotFound) return false;
		}
		return true;
	}
	return false;
}
//================================================
function StrToUpper(Str)
{
	var i;
	strLower = "©¨ª®«¬­";
	strUpper = "¢¡£§¤¥¦";
	strReturn = "";
	for (i=0; i<Str.length; i++)
	{
		if ((Str.charAt(i)>='a') && (Str.charAt(i)<='z'))
			chr = Str.charAt(i).toString().toUpperCase();
		else
		{
			idx = strLower.indexOf(Str.charAt(i).toString());
			chr = ((idx >= 0)?strUpper.charAt(idx):Str.charAt(i));
		}
		strReturn = strReturn + chr;
	}
	return strReturn;
}
//================================================
function formatCurrency1(num) 
{
	num = repl1(num.toString());
	if (isNaN(num)) 
		num = "0"
	else
		if (parseInt(num)<0)
			num = "0"
	//cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	//if (cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
	//return (num + '.' + cents);
		return (num);
}
//================================================
function SetFocus01() 
{
theform.Txtsocophangiu01.focus();
return;
}
//================================================
function SetFocus02() 
{
theform.Txtsocophangiu02.focus();
return;
}
//================================================
function SetFocus03() 
{
theform.Txtsocophangiu03.focus();
return;
}
//================================================
function SetFocus04() 
{
theform.Txtsocophangiu04.focus();
return;
}
//================================================

function KtraCoPhan01giu() 
{
var  cophan1 = repl1(theform.Txtsocophan01.value)*1;
var cophangiu= repl1(theform.Txtsocophangiu01.value)*1;
if (theform.Txtsocophan01.value!="0")
{
if (theform.Txtsocophangiu01.value=="0" && theform.Txtsocophan01.value!="0" )
{
alert("So luong co phan pho thong dang ky mua phai bang toi thieu 20% so luong co phan pho thong")
theform.Txtsocophangiu01.value="0";
theform.Txtsocophangiu01.focus();
return;
}

if (cophan1 <cophangiu )
{
alert("Co phan co dong dang ky mua phai nho hon so luong co phan pho thong ")
theform.Txtsocophangiu01.value="0";
theform.Txtsocophangiu01.focus();
return;
}
else

if ((cophangiu/cophan1)*100 >=20   )
{

return;
}
else
{
alert("So luong co phan pho thong dang ky mua phai bang toi thieu 20% so luong co phan pho thong ")
theform.Txtsocophangiu01.value="0";
theform.Txtsocophangiu01.focus();
return;
}
}
else
{
theform.Txtsocophangiu01.value="0";
return;
}
}
//================================================
function KtraCoPhan02giu() 
{
var  cophan1 = repl1(theform.Txtsocophan02.value)*1;
var cophangiu= repl1(theform.Txtsocophangiu02.value)*1;

if (cophan1 <cophangiu )
{
alert("Co phan co dong dang ky mua phai nho hon so luong co phan")
theform.Txtsocophangiu02.value="0";
theform.Txtsocophangiu02.focus();
return;
}
else
{
return;
}
}
//================================================
function KtraCoPhan03giu() 
{
var  cophan1 = repl1(theform.Txtsocophan03.value)*1;
var cophangiu= repl1(theform.Txtsocophangiu03.value)*1;

if (cophan1 <cophangiu )
{
alert("Co phan co dong dang ky mua phai nho hon so luong co phan")
theform.Txtsocophangiu03.value="0";
theform.Txtsocophangiu03.focus();
return;
}
else
{

return;
}
}
//================================================
function KtraCoPhan04giu() 
{
var  cophan1 = repl1(theform.Txtsocophan04.value)*1;
var cophangiu= repl1(theform.Txtsocophangiu04.value)*1;

if (cophan1 <cophangiu )
{
alert("Co phan co dong dang ky mua phai nho hon so luong co phan")
theform.Txtsocophangiu04.value="0";
theform.Txtsocophangiu04.focus();
return;
}
else
{

return;
}
}

//================================================
function KtraCoPhan(obj) 
{
var  cophan1 = repl1(theform.Txtsocophan01.value)*1;
var cophan2= repl1(theform.Txtsocophan02.value)*1;
var cophan3= repl1(theform.Txtsocophan03.value)*1;
var cophan4= repl1(theform.Txtsocophan04.value)*1;
var Tongcophan= repl1(theform.txtSoCoPhan.value)*1;
 if (cophan1 =="0" &&( cophan2 !="0" || cophan3 !="0"|| cophan4 !="0")) 
 {
alert("So luong co phan pho thong phai lon hon 0")
obj.value="0";
theform.Txtsocophan02.value="0";
theform.Txtsocophan03.value="0";
theform.Txtsocophan04.value="0";
theform.Txtsocophangiu01.value="0";
theform.Txtsocophangiu02.value="0";
theform.Txtsocophangiu03.value="0";
theform.Txtsocophangiu04.value="0";
return;
 }

if (cophan1 +cophan2+cophan3+cophan4 > Tongcophan )
{
alert("So luong co phan khong the lon hon tong so co phan")
obj.value="0";
obj.focus();
return;
}
}
//================================================
function repl(str)
{
	var strResult="";
	for(i=0;i<str.length;i++)
		if (str.charAt(i)!=pattern)
			strResult=strResult + str.charAt(i)
	return strResult;
}
//================================================
function repl1(str)
{
	var strResult="";
	for(i=0;i<str.length;i++)
		if ((str.charAt(i)!="$")&&(str.charAt(i)!=","))
			strResult=strResult + str.charAt(i)
	return strResult;
}
//================================================
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
//================================================
// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
//================================================
// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
//================================================
function TimKiem()     
{
	theform.TxtReload.value="TimKiem";
	theform.submit();
}
//================================================
function reload()     
{
	theform.TxtReload.value="reload";
	theform.submit();
}
//================================================
//function ChonSubmit()     
//{
//	theform.TxtReload.value="ChonNganh";
//	theform.submit();
//}
//================================================
function XoaSubmit()     
{
	theform.TxtReload.value="XoaNganh";
	theform.submit();
}
//================================================
function Answer(loaidn)     
{
	if (trim(theform.gtinh.value)=="") 
	{
		alert("Chon gioi tinh cua dai dien phap luat");
		theform.gtinh.focus();
		return false;
	}
	if (trim(theform.nsinh.value)=="") 
	{
		alert("Nhap ngay sinh cua dai dien phap luat");
		theform.nsinh.focus();
		return false;
	}
	if (trim(theform.dtoc.value)=="")
	{
		alert("Nhap dan toc cua dai dien phap luat");
		theform.dtoc.focus();
		return false;
	}

	if (trim(theform.qtich.value)=="")
	{
		alert("Chon quoc tich cua dai dien phap luat");
		theform.qtich.focus();
		return false;
	}
	if (trim(theform.cmnd_ngay.value)=="") 
	{
		alert("Nhap ngay cap cmnd cua dai dien phap luat");
		theform.cmnd_ngay.focus();
		return false;
	}
	if (trim(theform.cmnd_ncap.value)=="") 
	{
		alert("Nhap noi cap cmnd cua dai dien phap luat");
		theform.cmnd_ncap.focus();
		return false;
	}

	if (trim(theform.so_ct.value)=="" && trim(theform.ngaycap_ct.value)!="" && trim(theform.noicap_ct.value)!="") 
	{
		alert("Kiem tra giay to chung thuc cua dai dien phap luat");
		theform.ngaycap_ct.focus();
		return false;
	}
	if (trim(theform.noi_dkhk.value)=="")
	{
		alert("Nhap ho khau thuong tru cua dai dien phap luat");
		theform.noi_dkhk.focus();
		return false;
	}
	if (trim(theform.noi_dkhk.value)!="" && theform.ftinh_hk.value=="" && theform.fhuyen_hk.value=="" && theform.fxa_hk.value=="" ) 
	{
		alert("Chon Tinh/Huyen/Xa thuong tru cua dai dien phap luat");
		theform.ftinh_hk.focus();
		return false;
	}
	if (trim(theform.noi_htai.value)=="") 
		{
			alert("Nhap noi o cua dai dien phap luat");
			theform.noi_htai.focus();
			return false;
		}
	if (trim(theform.noi_htai.value)!="" && theform.ftinh_ht.value=="" && theform.fhuyen_ht.value=="" && theform.fxa_ht.value=="" ) 
	{
		alert("Chon Tinh/Huyen/Xa noi o cua dai dien phap luat");
		theform.ftinh_ht.focus();
		return false;
	}

	if (trim(theform.ten_ct.value)=="") 
		{
			alert("Hay nhap Ten doanh nghiep");
			theform.ten_ct.focus();
			return false;
		}
	if (trim(theform.dchi_ct.value)=="") 
		{
			alert("Nhap dia chi doanh nghiep");
			theform.dchi_ct.focus();
			return false;
		}
	if (trim(theform.dchi_ct.value)!="" && theform.ftinh_ct.value=="" && theform.fhuyen_ct.value=="" && theform.fxa_ct.value=="" ) 
	{
		alert("Chon Tinh/Huyen/Xa dia chi doanh nghiep");
		theform.ftinh_ct.focus();
		return false;
	}

	if (trim(theform.nkd.value)=="") 
		{
			alert("Nhap/chon nganh nghe kinh doanh cua doanh nghiep");
			theform.nkd.focus();
			return false;
		}
	if (theform.nkd.value.indexOf("-")<0) 
		{
			alert("Nganh nghe kinh doanh khong dung\nPhai co dang: 'ma so - ten nganh', neu nhieu nganh dung dau ';' \nde ngan cach cac nganh nghe");
			theform.nkd.focus();
			return false;
		}
	strTongVon=repl(theform.tong_von.value)	
	
	if (isNaN(parseInt(strTongVon)))
	{
		alert("Nhap tong so von doanh nghiep");
			theform.tong_von.focus();
			return false;
	}
	else
		if ((strTongVon.indexOf("e") != -1)||(strTongVon.length > 15))
			{
			alert("Nhap tong von qua nho doanh nghiep");
			theform.tong_von.focus();
			return false;
			
			}		
		
	//VonPhapDinh = (theform.vphapdinh.value.length>0 ? parseInt(repl(theform.vphapdinh.value)) : 0)

	//if ((VonPhapDinh!=0) && (VonPhapDinh>parseInt(repl(theform.tong_von.value)))  )
	//	{
	//		alert("Von phap dinh phai nho hon tong von");
	//		theform.vphapdinh.focus();
	//		return false;
	//	}	


	if ((parseInt(repl(theform.tong_von.value)) ==  0 ))
		{
			alert("Nhap tong von");
			theform.tong_von.focus();
			return false;
		}	
	if (loaidn!=1 && parseInt(repl(theform.vdle.value)) ==  0)
		{
			alert("Nhap von dieu le");
			theform.vdle.focus();
			return false;
		}	
 	if (loaidn==3)
 	{
 		if (parseInt(repl(theform.tong_cp.value))==0) 
		{
			alert("Nhap so co phan cua cong ty ");
			theform.tong_cp.focus();
			return false;
		}
 		if (parseInt(repl(theform.mgia.value))==0) 
		{
			alert("Nhap menh gia co phan cua cong ty ");
			theform.mgia.focus();
			return false;
		}
 		//if (parseInt(repl(theform.vdle.value))!=parseInt(repl(theform.mgia.value))*parseInt(repl(theform.tong_cp.value))) 
		//{
		//	alert("Kiem tra lai: Vondieule <> menh gia * so co phan " );
		//	theform.mgia.focus();
		//	return false;
		//}
 		if (parseInt(repl(theform.cpcd_pt.value))==0) 
		{
			alert("Nhap so co phan pho thong co dong sang lap mua");
			theform.cpcd_pt.focus();
			return false;
		}
 		//if (parseInt(repl(theform.cpcd_ud.value))==0) 
		//{
		//	alert("Nhap so co phan pho thong co dong sang lap mua");
		//	theform.cpcd_ud.focus();
		//	return false;
		//}
 		//if (repl(theform.tong_cp.value)*1 != repl(theform.cpcd_pt.value)*1+repl(theform.cpcd_ud.value)*1+repl(theform.cpcb_pt.value)*1+repl(theform.cpcb_ud.value)*1) 
		//{
		//	alert("Kiem tra lai: Tong co phan  <> CPPT co dong mua + CPUD co dong mua+CPPT chao ban + CPUD chao ban");
		//	theform.cpcb_ud.focus();
		//	return false;
		//}
 	}
 	
 	if (loaidn==4)
 	{
	 	if (theform.hthuc_shuu.value==1)
	 		{
		 	if (trim(theform.nsinh_cn.value)=="") 
			{
				alert("Nhap ngay sinh cua ca nhan");
				theform.nsinh_cn.focus();
				return false;
			}
			if (trim(theform.dtoc_cn.value)=="")
			{
				alert("Nhap dan toc cua ca nhan");
				theform.dtoc_cn.focus();
				return false;
			}
		
			if (trim(theform.soct_cn.value)=="") 
			{
				alert("Nhap ngay cap cmnd cua  ca nhan");
				theform.soct_cn.focus();
				return false;
			}
			if (trim(theform.ngayct_cn.value)=="") 
			{
				alert("Nhap noi cap cmnd cua ca nhan");
				theform.ngayct_cn.focus();
				return false;
			}
		
			if (trim(theform.hktt.value)=="")
			{
				alert("Nhap ho khau thuong tru cua  ca nhan");
				theform.hktt.focus();
				return false;
			}
			if (trim(theform.hktt.value)!="" && theform.matinh_hk.value=="" && theform.mahuyen_hk.value=="" && theform.maxa_hk.value=="" ) 
			{
				alert("Chon Tinh/Huyen/Xa thuong tru cua ca nhan");
				theform.matinh_hk.focus();
				return false;
			}
			if (trim(theform.noht.value)=="") 
				{
					alert("Nhap noi o cua ca nhan");
					theform.noht.focus();
					return false;
				}
			if (trim(theform.noht.value)!="" && theform.matinh_ht.value=="" && theform.mahuyen_ht.value=="" && theform.maxa_ht.value=="" ) 
			{
				alert("Chon Tinh/Huyen/Xa noi o cua ca nhan");
				theform.matinh_ht.focus();
				return false;
			}
			}
		else
			{
			if (trim(theform.sodk.value)=="") 
			{
				alert("Nhap so GCNDKKD/QD cua chu so huu");
				theform.sodk.focus();
				return false;
			}
			if (trim(theform.noi_sodk.value)=="") 
			{
				alert("Nhap noi cap GCNDKKD/QD cua chu so huu");
				theform.noi_sodk.focus();
				return false;
			}
			if (trim(theform.ncap_sodk.value)=="") 
			{
				alert("Nhap ngay cap GCNDKKD/QD cua chu so huu");
				theform.ncap_sodk.focus();
				return false;
			}
			if (trim(theform.dchi_truso.value)=="") 
				{
					alert("Nhap dia chi tru so chu so huu");
					theform.dchi_truso.focus();
					return false;
				}
			if (trim(theform.dchi_truso.value)!="" && theform.ftinh_truso.value=="" && theform.fhuyen_truso.value=="" && theform.fxa_truso.value=="" ) 
			{
				alert("Chon Tinh/Huyen/Xa dia chi tru so chu so huu");
				theform.ftinh_truso.focus();
				return false;
			}
			if (trim(theform.mo_hinh.value)=="") 
			{
				alert("Chon mo hinh to chuc cua chu so huu");
				theform.mo_hinh.focus();
				return false;
			}
		}
	}
	
	if (loaidn!=1 && theform.dieule.value=="")
	{
		alert("Vui long chon dieu le cong ty kem theo");
		theform.dieule.focus();
		return false;
	}	
	if (loaidn==4 &&  theform.hthuc_shuu.value==2 ){
	if (theform.dsthanhvien.value=="" && theform.mo_hinh.value=="1")
	{
		alert("Vui long chon danh sach thanh vien/co dong cong ty kem theo");
		theform.dsthanhvien.focus();
		return false;
	}}
	//theform.TxtReload.value="KiemTraNganhVon";
	theform.action='luu.asp';//?id='+ getParameterValues("id")
    theform.submit();
}
