var ppimgNW;
var isIE = (navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);

function goLanguage(tg)
{
		window.top.location.assign("GoTo.aspx?ilang=" + tg.options[tg.selectedIndex].value);
}

function adjustHeight(contentId)
{
	if (document.getElementById(contentId))
	{
		var divContent=document.getElementById(contentId);		
		divContent.Height=window.screen.availHeight;		
	}	
}

function showHideContent(contentId)
{
	if (document.getElementById(contentId))
	{
		var divContent=document.getElementById(contentId);
		if (divContent.style.display=="none")
		{
			divContent.style.display="";			
			event.srcElement.src="images/minus.gif";
		}
		else
		{
			divContent.style.display="none";
			event.srcElement.src="images/plus.gif";
		}
	}
}

function showImage(imgid)
{
	showWindow('ViewImageHtml.aspx?url=ViewImage.aspx?ArticleLargeId=' + imgid, false, false, true, false, false, false, true, true, 550, 550, 0, 0);
	return false;
}
function showImageViewSize(img,width,height)
{	
	
	//height = height + 10
	showWindow('ViewImageHtml.aspx?url=ViewImage.aspx?img=' + img + '&width=' + width + '&height=' + height, false, false, true, false, false, false, true, true, parseInt(width)+20,parseInt(height)+20,0 ,0 );
	return false;
}
function showFAX(faxName)
{
	//alert(intModuleId);
	showWindow('../../ViewImageHtml.aspx?url=ViewImage.aspx?faxnameLarge=' + faxName , false, false, true, false, false, false, true, true, 800, 600, 0, 0);
	return false;
}
function showProductImage(imgid)
{
	showWindow('ViewImageHtml.aspx?url=ViewImage.aspx?ttproductthumbid=' + imgid, false, false, true, false, false, false, true, true, 550, 550, 0, 0);
	return false;
}

function showMKProductImage(imgid,name,id,detail)
{
	showWindow('MKViewHTMLImage.aspx?url=ViewImage.aspx?mkproductthumbid=' + imgid + '&name='+ name + '&id='+ id + '&descript=' + detail, false, false, true, false, false, false, true, true, 518, 514, 0, 0);
	return false;
}

function showpnjProductImage(imgid)
{
	showWindow('ViewImageHtml.aspx?url=ViewImage.aspx?mkproductthumbid=' + imgid, false, false, true, false, false, false, true, true, 550, 550, 0, 0);
	return false;
}

function showCategoryImage(imgid)
{
	showWindow('ViewImageHtml.aspx?url=ViewImage.aspx?categoryLargeId=' + imgid, false, false, true, false, false, false, true, true, 550, 550, 0, 0);
	return false;
}

function showEquipment(url)
{
	showWindow('ViewImageHtml.aspx?url='+url, false, false, true, false, false, false, true, true, 550, 550, 0, 0);
	return false;
}


function showWindow(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vWidth, vHeight, vTop, vLeft)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;
	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');
	if (vCentered)
	{
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}
	else
	{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}
	open(sLink, '_blank', winDef);
	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

document.onmouseover = fover;
document.onmouseout = fout;
document.onmousedown = fdown;
document.onmouseup = fup;
document.onclick = fclick;
var f_folderover="#0000FF";
var f_folderout="#000000";

var b_over = "#31659C";//"#4E7DC1";
//"#C1D2EE";
//var fontweight_over = "white"
var b_out = "#639ACE";
//"#D4D0C8";
var b_click = "#00BFBF";
//"#C1D2EE";
var f_over = "#F7AE10";
//"#000000";
//#963455 c
var f_out = "#FFFFFF";
//"#000000";
var f_click = "#000000";
var t_over = "1 solid #0a246a";
var t_out = "1 solid #D4D0C8";

function fclick()
{
	if (document.all)
	{
	var tg = event.srcElement;
		if (tg.xpbutton != null)
		{
			if (tg.url != null) {window.location = tg.url};
			//showModelessWaitingPage();
		}
	}

}
function fup()
{
	
	if (document.all)
	{
	var tg = event.srcElement;
		if (tg.xpbutton != null)
		{
			tg.style.background = b_over;
			tg.style.color = f_over;
			tg.style.border = "1 solid #0057AE";
			tg.hideFocus=true;
			
		}
	}

}
function fdown()
{
	if (document.all)
	{
	var tg = event.srcElement;
		if (tg.xpbutton != null)
		{
			tg.style.background = b_click;
			tg.style.color = f_click;
			tg.style.border ="1 solid #0057AE";
			tg.hideFocus=true;
		}
	}
}
function fover()
{
	if (document.all)
	{
	var tg = event.srcElement;
		if (tg.xpbutton != null)
		{
			tg.style.background = b_over;
			tg.style.color = f_over;
			tg.style.border = "1 solid black";
			tg.hideFocus=true;
		}
		if (tg.xptextbox != null)
		{
			tg.style.border = t_over;
			tg.onfocus = ffocus;
		}
		if (tg.cmsfolder != null)
		{
			tg.style.color = f_folderover;
			tg.hideFocus=true;			
		}
		if(tg.xptoolbar!=null)
		{
			tg.style.border = "2 solid #FFFFFF";
		}
	}
}

function fout()
{
	if (document.all)
	{
	var tg = event.srcElement;
		if (tg.xpbutton != null)
		{
			tg.style.background = b_out;
			tg.style.color = f_out;
			tg.style.border = "1 solid #0057AE";			
			tg.hideFocus=true;
		}
		if (tg.xptextbox != null)
		{
			if (document.activeElement != tg)	tg.style.border = t_out;
		}
		if (tg.cmsfolder != null)
		{
			tg.style.color = f_folderout;
			tg.hideFocus=true;			
		}
		if(tg.xptoolbar!=null)
		{
			tg.style.border = "0";
		}
	}
}
function ffocus()	
{
	if (document.all)
	{
	var tg = event.srcElement;

		if (tg.xptextbox != null)
		{
			tg.style.border = t_over;
			tg.onblur = flfocus;
		}
	}
}
function flfocus()
{
	if (document.all)
	{
	var tg = event.srcElement;
		if (tg.xptextbox != null)
		{
			tg.style.border = t_out;
		}
	}
}
function showWaitingPage()
{
   var width = 150;
   var height = 150;
   var left = (screen.availWidth - width)/2;
   var top = (screen.availHeight - height)/2;
   var features = 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + top;
   window.open('wait.htm', null, features);
}

function showModelessWaitingPage()
{
   var features = 'dialogWidth:150px; dialogHeight:150px; center:yes; status:no; help:no';
   window.showModelessDialog('wait.htm', null, features);
   return true;
}
function popupImage(src, note, title, css, border) {
  if (border==null) border = 0;
  if (note==null) note = '';
  if (ppimgNW != null) ppimgNW.close();

  ppimgNW = window.open('','POPUPIMAGE','width=1,height=1');
  var doc = ppimgNW.document;
  doc.write('<html>');
  doc.write('<head>');

  if (title!=null) doc.write('<title>'+ title +'</title>');
  doc.write('<style> body {'+css+'} #ppImgText{'+ css +'} #ppImg{cursor:hand}</style></head>');
  doc.write('<body leftmargin="0" topmargin="' + border + '">');
  doc.write('<div align="center">');
  doc.write('<img src="' + src + '" id="ppImg" onclick="self.close();" title="Close">');
  doc.write('</div>');
  doc.write('<div style="height:1; width:' + border + '; font-size:4pt;">');
  doc.write('</div>');
  doc.write('<div id="ppImgText" align="center">');
  doc.write(note);
  doc.write('</div>');
  doc.write('</body>');
  doc.write('</html>');

  doc.write('<' + 'script>');
  doc.write('var resized = false;');
  doc.write('function doResize() {');
  doc.write('  var imgW = ppImg.width, imgH = ppImg.height;');     
  doc.write('  window.resizeTo(imgW + 8 +' + border*2 +', imgH + ppImgText.offsetHeight + 26 + '+ border*2 +');');
  doc.write('  setTimeout("doResize()",1000);');

  doc.write('}');
  doc.write('doResize(); ');
  doc.write('</' + 'script>');

}

var b_selected ="#CCCCCC";
var b_unselected="#FFFFFF";
var RECYCLE="-1";

function f_chooseFolder(tg)
{	
	try
	{
		unselect(document.getElementById(SELECTED_CATEGORY).value);
	}catch(e){}
	//update current id into parent form
	document.getElementById(SELECTED_CATEGORY).value = tg.id;
	//select new item
	var parentId= tg.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
	parentId = parentId.slice(2,10);
	select(tg.id,parentId);
}
function f_expandclick(tg)
{
	var targetgroup = document.getElementById("cg"+tg.id.substring(3));	
	
	toggle(targetgroup);		
	if (tg.src.indexOf("minus.gif")>0)
		tg.src="ecms/images/plus.gif"
	else
		tg.src="ecms/images/minus.gif";
}

function toggle(tgsrc)
{
	if(tgsrc.style.display=="none") 
		tgsrc.style.display=""; 
	else 
		tgsrc.style.display="none";								
}
function expand(tg)
{	
	if (tg!=null)
	{
		
		var img01 = document.getElementById("img"+tg.id.substring(2));
		if (img01!=null) img01.src="ecms/images/minus.gif";
		
		tg.style.display="";
		if (tg.className!=null)
		{	
			expand(document.getElementById("cg"+tg.className));		
		}		
	}	 	
}

function unselect(nodeid)
{
	var citem = document.getElementById(nodeid);
	if (citem)
	{
		citem.style.background=b_unselected;	
		citem.style.border = "1 solid #F1F1F1";				
	}												
}
function select(nodeid,parentId)
{
	var citem = document.getElementById(nodeid);
	if (citem)
	{
		citem.style.background=b_selected;		
		citem.style.border = "1 solid #13646A";			
	}						
}
function findselected()
{	
	var sCurrentID = document.getElementById(SELECTED_CATEGORY).value;
	
	var tg;
	tg = document.getElementById("cg"+document.getElementById(SELECTED_CATEGORY).value);
	
	if (tg!=null) 
	{
		expand(tg);		
		f_chooseFolder(document.getElementById(document.getElementById(SELECTED_CATEGORY).value));											
	}	
}

      function kiemdoben()
		{
		//alert(imgtrangsuc.src);
		var imgkiemdoben = new Image();
		imgkiemdoben.src="/TanTien/Portals/publics/hethongquanly/may-kiemdoben.jpg";
		document.imgdynamic.src=	imgkiemdoben.src;	
		}
		function phantichmau()
		{
		//alert(imggas.src);
		var imgphantichmau = new Image();
		imgphantichmau.src="/TanTien/Portals/publics/hethongquanly/may-phantichmau.jpg";
		document.imgdynamic.src=	imgphantichmau.src;	
		}
		function hanthinghiem()
		{
		//alert(imgother.src);
		var imghanthinghiem = new Image();
		imghanthinghiem.src="/TanTien/Portals/publics/hethongquanly/may-hanthinghiem.jpg";
		document.imgdynamic.src=	imghanthinghiem.src;	
		}

        function instron()
		{
		//alert(imgtrangsuc.src);
		var imgkiemdoben = new Image();
		imgkiemdoben.src="/TanTien/Portals/publics/hethongquanly/instron.jpg";
		document.imgdynamic.src=	imgkiemdoben.src;	
		}
		function gretagcolor()
		{
		//alert(imggas.src);
		var imgphantichmau = new Image();
		imgphantichmau.src="/TanTien/Portals/publics/hethongquanly/gretagcolor.jpg";
		document.imgdynamic.src=	imgphantichmau.src;	
		}
		function heatgraden()
		{
		//alert(imgother.src);
		var imghanthinghiem = new Image();
		imghanthinghiem.src="/TanTien/Portals/publics/hethongquanly/heatgraden.jpg";
		document.imgdynamic.src=	imghanthinghiem.src;	
	}




