var randomNumber;
randomNumber=Math.floor(Math.random()*12321);
function showpic(imgID,imgWidthFix,imgHeightFix,orSize,isresizewidth) {
if (imgID == null) return;
var imgPic = document.getElementById('img_'+imgID);
getImgSizePhoto(imgPic,imgWidthFix,imgHeightFix,orSize,isresizewidth);
}
function getImgSizePhoto(ImgID,imgWidthFix,imgHeightFix,orSize,isresizewidth)
{
   var newImg = new Image();
   newImg.src =ImgID.src;
   var height = newImg.height;
   var width = newImg.width;
   var imgHeight, imgWidth;
   
   if (orSize != null)
   {
		imgWidth=imgWidthFix;
		imgHeight=imgHeightFix;
   }
   else
   {   
		
		if(isresizewidth=='yes')
		{
			//fix chieu rong
			imgWidth=imgWidthFix;
			imgHeight  = Math.round(height / (width/imgWidth));	
		}		
		else
		{
			if (width < imgWidthFix && height < imgHeightFix)
			{
				imgWidth=width;
				imgHeight=height;
			}
			else if (width > height)
			{
				imgHeight = imgWidthFix;
				imgWidth  = Math.round(height / (width/imgWidth));	
			}
			else
			{
				//fix chieu cao			
				imgHeight = imgHeightFix;
				imgWidth  = Math.round(width / (height/imgHeight));	
			}			
		}		
		
   }
   
   ImgID.width=imgWidth;
   ImgID.height=imgHeight;
}


//showpic photo
function showpicphoto(src,id,imgWidthFix,imgHeightFix,orSize) 
{
try
{
	if (src == '') return;
	var imgID ="img_" + id;
	getImgSize(src,imgID,imgWidthFix,imgHeightFix,orSize);
}
catch(e)
{
	return;
	//alert(src + '\r\r' + e.message + '\r\r' + imgPic);
}

}
function getImgSize(imgSrc, ImgID,imgWidthFix,imgHeightFix,orSize)
{
try
{
   var newImg = new Image();
   newImg.src = imgSrc;
   var height = newImg.height;
   var width = newImg.width;
   var imgHeight, imgWidth
   
   if (width < imgWidthFix && height < imgHeightFix)
	{
		imgWidth=width;
		imgHeight=height;
	}
	else if(width > height)
	{
		imgWidth = imgWidthFix;
		imgHeight  = Math.round(height / (width/imgWidth));	
	}
	else
	{
		//fix chieu cao			
		imgHeight = imgHeightFix;
		imgWidth  = Math.round(width / (height/imgHeight));	
	}		
   if (orSize != null)
   {
	document.getElementById(ImgID).style.width=imgWidthFix;
	document.getElementById(ImgID).style.height=imgHeightFix;
   }
   else
   {
   document.getElementById(ImgID).style.width=imgWidth;
   document.getElementById(ImgID).style.height=imgHeight;
   }
}
catch(e)
{
	//alert(e.name );
	document.getElementById(ImgID).style.width=imgWidthFix;
	document.getElementById(ImgID).style.height=imgHeightFix;
	//alert(imgSrc + '\r\r' + e.message + '\r\r' + width+ '\r\r' + height);
}
 
}
//Vietdq
function InputSearch(btnSearch){
	if (event.keyCode == 13)
	{
		
		document.getElementById(btnSearch).click();
		alert(btnSearch);
		return false;
	}else {
		return true;
	}
}
function SelectAllCheckboxes(spanChk){
	
	// Added as ASPX uses SPAN for checkbox 
	var xState=spanChk.checked;
	var theBox=spanChk;
	
		elm=theBox.form.elements;
		for(i=0;i<elm.length;i++)
		if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
			{
			//elm[i].click();
			if(elm[i].checked!=xState)
			elm[i].click();
			//elm[i].checked=xState;
			}
	}
	
function openwinGTSP(url) 
			{
				var width  = 700;
				var height = 500;
				var left   = (screen.width  - width)/2;
				var top    = (screen.height - height)/2;
				var params = 'width='+width+', height='+height;
				params += ', top='+top+', left='+left;
				params += ', directories=no';
				params += ', location=no';
				params += ', menubar=no';
				params += ', resizable=yes';
				params += ', scrollbars=no';
				params += ', status=no';
				params += ', toolbar=yes';
				newwin=window.open(<%=Global.GetAppPath(Request)%> + 'Thongbao_GTSP.aspx','View', params);
				//if (window.focus) {newwin.focus()}
				//return false;
				
				window.location = url;
			}		