<!--

function resize() {
	if ( typeof( self.sizeToContent ) == 'function' ) {
	
        self.sizeToContent();

			return;
    
	}
	if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined' ) {
		var newWidth  = document.getElementById('querywindowcontainer').offsetWidth;
		var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
		self.resizeTo( newWidth + 45, newHeight + 75 );

	}
}
function popUpImage(theURL,width, height)
{
	width = width-0+17;
	height=height;
	if (width > screen.width) width=screen.width;
	if (height > screen.height) height=screen.height-60;
	popUpWin = window.open(theURL,'ViewFullImage',"toolbar=no,width="+ width+",height="+ height+ ",directories=no,status=no,scrollbars=yes,resizable=yes, menubar=no");
	popUpWin.moveTo(200,10);
	if (!popUpWin.opener) popUpWin.opener = self;
	with (popUpWin.document) {
		write('<HTML><HEAD><TITLE>View Full Image</TITLE>');
		write('</head>');
		write('<BODY bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
		write('<IMG SRC="' + theURL + '" alt="Click on image to close window" onclick="window.close()">');
		write('</BODY></HTML>');
		close();
	}
}
function popUpContent(url, x, y) {
	if (!x){x=800;}
	if (!y){y=600;}
	if (x>400 && y>300){
		var popUpWin = window.open(url,'','height='+y+',width='+x+', location=no, scrollbars=yes, menubars=no,toolbars=no,resizable=yes');
	}else{
		var popUpWin = window.open(url,'','height='+y+',width='+x+', location=no, scrollbars=no, menubars=no,toolbars=no,resizable=yes');
	}
	if (!popUpWin.opener) 
	popUpWin.opener = self;
}
function confSlideShow(sURL, id){
	var popUpWin = window.showModalDialog(sURL, id, "dialogWidth:220px;dialogHeight:150px;status:no;help:no");
}
function Close(){
	window.close();
}
function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   }
function btnBack(){
	history.go(-1);

}
function deleteConfirm(str) {
  if (confirm(str)){	
    return true;
  }	
  else{
    return false;
  }	
}
function GoBack(){
	history.go(-1);
}
function SubmitForm(formname){
	document.formname.submit();

}
function Print()
{
	printMain.window.focus();
	printMain.window.print();
}


function Close()
{
	window.close();
}


function BacktoList(url){
	window.location=url;
}
function SelectAll(){
	fiel = document.frmCheckAll.elements['id[]'];
			if(fiel.length){
				for (i = 0; i < fiel.length; i++)
					fiel[i].checked = true ;
			}else{
					fiel.checked = true;
			}
}

function UnSelectAll(){
	fiel = document.frmCheckAll.elements['id[]'];
			if(fiel.length){
				for (i = 0; i < fiel.length; i++)
					fiel[i].checked = false ;
			}else{
					fiel.checked = false;
			}
}


function CheckDelete(){
	notok=true;
	fiel = document.frmCheckAll.elements['id[]'];
			if(fiel.checked==true){
				notok=false;
			}
			for (i = 0; i < fiel.length; i++)
				if(fiel[i].checked == true){
					notok=false;
				}
		  if(notok ){
					alert(" Hay chon ban ghi can xoa ! ");
		  }else{
			 if (confirm("Ban co chac chan muon xoa khong? ")){	
				document.frmCheckAll.submit();
			  }else{
				return false;
			  }
		  }
}






function maskMoney_New(fldVal,namaform,fldName)
{
    var awal,akhir,tmp,tengah,fl;
    keyCount = fldVal.length;
    keyCount++;

	switch (keyCount)
        {
        case 4: 
        namaform.elements[fldName].value = insertkoma(fldVal) ;
        break;
        case 6:
        awal = fldVal.substr(0,1);
        akhir = fldVal.substr(2,4);
        namaform.elements[fldName].value = awal+insertkoma(akhir);
        break;
        case 7:
        	 awal = fldVal.substr(0,2);
        akhir = fldVal.substr(3,4);
        namaform.elements[fldName].value = awal+insertkoma(akhir);
        break;
        
        	case 8:
        	 awal = fldVal.substr(0,3);
        akhir = fldVal.substr(4,4);
        tmp = awal + insertkoma(akhir);
        		awal = tmp.substr(0,4);
        akhir = tmp.substr(4,4);
        namaform.elements[fldName].value = insertkoma(awal)+ akhir;
        break;
        case 10:
        	 awal = fldVal.substr(0,5);
        akhir = fldVal.substr(6,4);
        tmp = awal + insertkoma(akhir);
        		 awal = tmp.substr(0,1);
        		 tengah = tmp.substr(2,4);
        akhir = tmp.substr(6,4);
        namaform.elements[fldName].value = awal+insertkoma(tengah)+ akhir;
        break;
        case 11:
        	 awal = fldVal.substr(0,6);
        akhir = fldVal.substr(7,4);
        tmp = awal + insertkoma(akhir);
        
        		 awal = tmp.substr(0,2);
        		 tengah = tmp.substr(3,4);
        akhir = tmp.substr(7,4);
        namaform.elements[fldName].value = awal+insertkoma(tengah)+ akhir;
        break;
        case 12:
        	 awal = fldVal.substr(0,7);
        akhir = fldVal.substr(8,4);
        tmp = awal + insertkoma(akhir);
        
        		 awal = tmp.substr(0,3);
        		 tengah = tmp.substr(4,4);
        akhir = tmp.substr(8,4);
        tmp = insertkoma(awal) + insertkoma(tengah) + akhir;
        		 
        namaform.elements[fldName].value = tmp;
        break;
		case 14:
        	 awal = fldVal.substr(0,9);
        akhir = fldVal.substr(10,4);
        tmp = awal + insertkoma(akhir);                               
        
        		 awal = tmp.substr(0,5);
        	     tengah = tmp.substr(6,4);
           akhir = tmp.substr(10,4);
		   tmp= awal + insertkoma(tengah) + akhir;
           awal = tmp.substr(0,1);
		   tengah = tmp.substr(2,4);
		   akhir = tmp.substr(6,8);
           tmp = awal + insertkoma(tengah) + akhir;	 
        namaform.elements[fldName].value = tmp;
        break;
		case 15:
        	 awal = fldVal.substr(0,10);
        akhir = fldVal.substr(11,4);
        tmp = awal + insertkoma(akhir);                
        		 awal = tmp.substr(0,6);
        	     tengah = tmp.substr(7,4);
           akhir = tmp.substr(11,4);
		   tmp= awal + insertkoma(tengah) + akhir;
           awal = tmp.substr(0,2);
		   tengah = tmp.substr(3,4);
		   akhir = tmp.substr(7,8);
          
        	tmp = awal + insertkoma(tengah) + akhir;

        namaform.elements[fldName].value = tmp;
        break;

    } 

}

	function insertkoma(angka)
    {
    	var depan,belakang,hasil;
    	depan= angka.substr(0,1);
    	belakang= angka.substr(1,3);
    	hasil = depan+'.'+belakang;
    	return hasil;

}
function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   }

function LTrim(iStr)
{
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr=iStr.substr(1);
	}
	return iStr;
}

function RTrim(iStr)
{
	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr=iStr.substr(0, iStr.length - 1);
	}
	return iStr;
}

function Trim(iStr)
{
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr=iStr.substr(1);
	}

	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr=iStr.substr(0, iStr.length - 1);
	}

	return iStr;
}

function CheckEmailAddress(Email)
{
	Email = Trim(Email);

	while (Email != '')
	{
		c = Email.charAt(0);	
		if (c==' ' || c=='<' || c==39 || c==':' || c=='.')
		{
			Email = Email.substr(1);
		}
		else
		{
			break;
		}
	}

	i = Email.indexOf('>');
	if (i==-1)
	{
		while (Email != '')
		{
			c = Email.charAt(Email.length - 1);
			if (c==' ' || c==39 || c=='.')
			{
				Email = Email.substr(0, Email.length - 1);
			}
			else
			{
				break;
			}
		}
	}
	else
	{
		Email = Email.substr(0, i);
	}

	if (Email.length > 96)
		return '';

	i = Email.lastIndexOf('@');
	j = Email.lastIndexOf('.');
	if (i < j)
		i = j;

	switch (Email.length - i - 1)
	{
	case 2:
		break;
	case 3:
		switch (Email.substr(i))
		{
		case '.com':
		case '.net':
		case '.org':
		case '.edu':
		case '.mil':
		case '.gov':
		case '.biz':
		case '.pro':
		case '.int':
			break;
		default:
			return '';
		}
		break;
	default:
		switch (Email.substr(i))
		{
		case '.name':
		case '.info':
			break;
		default:
			return '';
		}
		break;
	}

	Email = Email.toLowerCase();

	if (Email == '')
		return '';

	if (Email.indexOf(' ') != -1)
		return '';

	if (Email.indexOf('..') != -1)
		return '';

	if (Email.indexOf('.@') != -1)
		return '';

	if (Email.indexOf('@.') != -1)
		return '';

	if (Email.indexOf(':') != -1)
		return '';

	for (i=0; i < Email.length; i++)
	{
		c = Email.charAt(i);

		if (c >= '0' && c <= '9')
			continue;
		
		if (c >= 'a' && c <= 'z')
			continue;
		
		if ('`~!#$%^&*-_+=?/\\|@.'.indexOf(c) != -1)
			continue;

		return '';
	}

	if ((i=Email.indexOf('@'))==-1)
		return '';

	if (Email.substr(i + 1).indexOf('@')!=-1)
		return '';

	if (Email.charAt(0)=='.' || Email.charAt(Email.length - 1)=='.')
		return '';

	return Email;
}
//-->
	var current_row=null;
	function Datmau(tr, color, bgcolor){
		if(current_row!=null){
			current_row.style.background = '#EDEADE';
			current_row.style.color = '#3300CC';
			current_row.style.fontStyle = 'italic';
		}
		tr.style.background = bgcolor;
		tr.style.color = color;
		tr.style.fontStyle = 'italic';
		current_row=tr;

	}

				function CheckBoxSelected(theId,theForm){
						fid = document.Form4.elements['const_checks[]'];
						fid[theId].checked = true ;
						document.getElementById(theId).style.background='#84C1DF';
				}
				function SelectRow(box,theId){
					if(document.getElementById) {
						var cell = document.getElementById(theId);
						if(box.checked) {
							cell.style.backgroundColor='#84C1DF';
						}
						else {
							cell.style.backgroundColor='#FBFCFE';
						}
					}
					
				}
//-->
function addRow(tableID) 
{ 
var tbody = document.getElementById(tableID).getElementsByTagName("tbody")[0]; 
var row = document.createElement("TR"); 
var cell1 = document.createElement("TD"); 
var inp1 =  document.createElement("INPUT"); 
inp1.setAttribute("type","text"); 
inp1.setAttribute("name","eng[]"); 

cell1.appendChild(inp1); 

row.appendChild(cell1); 

tbody.appendChild(row); 
//alert(row.innerHTML); 
} 