// JScript File
//21/08/2007
//Cac ham thong dung co ban duoc dung lai nhieu lan
//this is to select or unselect the datagrid check boxes 

function DGSelectOrUnselectAll(grdid,obj,objlist){ 

    //this function decides whether to check or uncheck all
     if(obj.checked) 

    DGSelectAll(grdid,objlist) 

    else 

    DGUnselectAll(grdid,objlist)    
 } 

//---------- 
function DGSelectAll(grdid,objid){ 

    //.this function is to check all the items

    var chkbox; 

    var i=2; 


    chkbox=document.getElementById(grdid + 

    '_ctl0' + i + '_' + objid); 


    while(chkbox!=null){ 

        chkbox.checked=true; 

        i=i+1; 

        chkbox=document.getElementById(grdid + 

        '_ctl0' + i + '_' + objid); 

    } 


}//-------------- 


function DGUnselectAll(grdid,objid){ 

    //.this function is to uncheckcheck all the items

    var chkbox; 

    var i=2; 


    chkbox=document.getElementById(grdid + 

    '_ctl0' + i + '_' + objid); 


    while(chkbox!=null){ 

        chkbox.checked=false; 

        i=i+1; 

        chkbox=document.getElementById(grdid + 

        '_ctl0' + i + '_' + objid); 

    } 

}

//-------------------------------------------------------

function GetParam(pName, pDef)
	{
		var	str=location.href;
		var	pos=str.indexOf('?'.concat(pName).concat('='));

		if (pos==-1)
		{
			pos=str.indexOf('&'.concat(pName).concat('='));
			if (pos==-1) return pDef;
		}
		
		str=str.substring(pos + pName.length + 2);
		pos=str.indexOf('&');

		if (pos==-1)
		{
			pos=str.length;
		}	

		if (pos > 0)
		{
			str=str.substring(0, pos);
		}

		return str;
}


	
	// ---- Cac ham tao menu trai
	function additemmnu(mnusite,mnuid,mnuname,sLink,mnulevel,mnustyle)
			{
				var strLink =sLink;
				var stemp="";
				
					var sMenuOff = 'MenuOffWindow';
				var sMenuHover = 'MenuHoverWindow';
				stemp += '<tr><td nowrap><div class=' + sMenuOff + ' onmouseover=\"this.className=\'' + sMenuHover ;
				stemp += '\'\" onmouseout=\"this.className=\'' + sMenuOff + '\'\" onclick=\"location.href=\'' ;
				stemp += strLink +'\'\"><div style=\"padding-top:7px;\">'; 
				stemp += mnuname + '</div></div></td></tr>';
				
				
				return stemp;
			};
			
			function hienmnu(position,msg,mnusite)
			{
				var subID = 'menucon';
				if (position.offsetLeft && position.offsetTop)
				{
					var x = position.offsetLeft + 190 + 'px'   ;
					var y = position.offsetTop - 2 + 'px';
					//alert(y);
					var content='';
					var submenu = new Array();
					submenu = msg.split("^");
					//alert(msg);
					if (msg.length > 4 )
					{
						var i=0;
						content = '<table cellspacing=\'0\' cellpadding=\'0\' width=\'120px\' class=\'hienMenu\'>';    
						content += '<tr><td style=\"padding-left:1px; padding-right:1px; border:solid 1px #ffffff;\"><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">';
						while (i<submenu.length)
						{
							var itemmnu = new Array();
							itemmnu = submenu[i].split("*");
							content += additemmnu(mnusite,itemmnu[0],itemmnu[1],itemmnu[2],itemmnu[3],itemmnu[4]);
							
							
							i = i+ 1;
						}
						content += '</table></td></tr>';
						content += '</table>';
						
						//alert(content);
						
						if (document.getElementById(subID) && (i > 0))
						{
							var sub = document.getElementById(subID);
							if (sub.style)
							{
								sub.style.visibility = 'visible';
								sub.style.left = x  ;
								sub.style.top = y ;
								sub.innerHTML = content ;
							}
						}
					}
					
				}
			};
			function anmnu()
			{
				
				if (document.getElementById('menucon'))
				{
					var sub = document.getElementById('menucon');
					sub.style.visibility = 'hidden';
					
				}
			};
			//----end menu----
			// Popup
			function popUp(theURL,width, height)
            {
	            if (width == null) width = 300;
	            if (height == null) height = screen.height;
	            if (width > screen.width) width=screen.width;
	            if (height > screen.height) height = screen.height;
	            
	            if ( height  >= screen.height) { 
		            
		            popUpWin = window.open(theURL,'_blank','toolbar=no,width='+ width+',height='+ height+ ',directories=no,status=no,scrollbars=1,resizable=yes, menubar=no');
	            }
	            else
	            {
		            popUpWin = window.open(theURL,'_blank','toolbar=no,width='+ width+',height='+ height+ ',directories=no,status=no,scrollbars=0,resizable=yes, menubar=no');
	            }
	            popUpWin.moveTo(50,50);

	        }
	        // Fix width height Images
	        function scaleImg(what, mw, mh) {
	            var saveWidth = 0;
	            var saveHeight = 0;
	            var maxWidth = mw;
	            var maxHeight = mh;
	            var ratio = 1;
	            what = document.getElementById(what);
	            if (what.width > maxWidth || what.height > maxHeight) {
	                if ((maxHeight / what.height) <= (maxWidth / what.width)) {
	                    saveWidth = what.width;
	                    saveHeight = what.height;
	                    ratio = what.width / what.height;
	                    what.height = maxHeight;
	                    what.width = maxHeight * ratio;
	                    what.style.cursor = "pointer";
	                }
	                else {
	                    saveWidth = what.width;
	                    saveHeight = what.height;
	                    ratio = what.height / what.width;
	                    what.height = maxWidth * ratio;
	                    what.width = maxWidth;
	                    what.style.cursor = "pointer";
	                }
	            }
	            else if (saveWidth > maxWidth || saveHeight > maxHeight) {
	                what.width = saveWidth;
	                what.height = saveHeight;
	                what.style.cursor = "pointer";
	            }
	        }
	        // End Fix width height Images



