﻿var ppimgNW;
var isIE = (navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);
function goLanguage(tg){
	if(window.document.all)
	{
		var af=window.document.getElementById("actionForm");
		af.action="GoTo.aspx";
		af.ilang.value=tg.options[tg.selectedIndex].value;
		af.submit(); 			
	}
	else
		window.top.location.assign("GoTo.aspx?ilang=" + tg.options[tg.selectedIndex].value); 
 }
 function goLanguageLink(tg){
	if(window.document.all)
	{
		var af=window.document.getElementById("actionForm");
		af.action="GoTo.aspx";
		af.ilang.value=tg;
		af.submit(); 			
	}
	else
		window.top.location.assign("GoTo.aspx?ilang=" + tg); 
 }
function ec(str){if(encodeURIComponent)return encodeURIComponent(str); if(escape)return escape(str) }
function createRequest(){var C=null;try{C=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{C=new ActiveXObject("Microsoft.XMLHTTP")}catch(sc){C=null}}if(!C&&typeof XMLHttpRequest!="undefined"){C=new XMLHttpRequest()}return C}
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= event.srcElement.src.replace("plus","minus");
		}
		else
		{
			divContent.style.display="none";
			event.srcElement.src= event.srcElement.src.replace("minus","plus");			
		}
	}
}

function showImage(url)
{
	showDialog('ImageView.htm?' + url.substr(url.indexOf('?') + 1), 150, 150);
}

function showDialog(url, width, height)
{
	return showWindow(url, false, true, false, false, false, false, true, true, width, height, 0, 0);
}
function showService(sname)
{
	return showWindow('Services/' + sname + '.htm' , false, true, true, false, false, false, true, true, 150, 150, 0, 0);	
}

function showLCMSImage(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, parentmode)
{
	//alert(intModuleId);
	showWindow('../../ViewImageHtml.aspx?url=ViewImage.aspx?faxnameLarge=' + faxName + '&parentmode=' + parentmode, 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, 550, 550, 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;
	}
}
function showSlide(imglink)
{
	showWindow(imglink.href, false, false, false, false, false, false, true, true, 700, 560, 0, 0);
	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 writeToday()
{
	var mydate=new Date();
	
	var year = mydate.getYear();
	year = (year < 1000) ? year + 1900 : year;
	var month = mydate.getMonth() + 1;
	month =	(month < 10) ? "0" + month : month;
	var day = mydate.getDate();
	day = (day < 10) ? "0" + day : day;
	var dayofweek = mydate.getDay();
	var hour = mydate.getHours()
	hour =  (hour < 10) ? "0" + hour :hour;	
	var minute=mydate.getMinutes()
	minute =  (minute < 10) ? "0" + minute : minute;
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayofweek]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+" (GMT+7)")
}
function writeTime(s)
{
	var mydate=new Date(s)
	
	var year = mydate.getYear();
	year = (year < 1000) ? year + 1900 : year;
	var month = mydate.getMonth() + 1;
	month =	(month < 10) ? "0" + month : month;
	var day = mydate.getDate();
	day = (day < 10) ? "0" + day : day;
	var dayofweek = mydate.getDay();
	var hour = mydate.getHours()
	hour =  (hour < 10) ? "0" + hour :hour;	
	var minute=mydate.getMinutes()
	minute =  (minute < 10) ? "0" + minute : minute;
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayofweek]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+" (GMT+7)")
}

function getTodayString(s)
{
	document.write('<span class="LargeTime2">');
	writeToday(s);
	document.write('</span>')
}

function getTimeString(s)
{
	document.write('<span class="LargeTime2">');
	writeTime(s);
	document.write('</span>')
}
//bhbao them vao 2006-04-13
function bhbaoStartTime()
{
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var D = today.getDate();
var M = today.getMonth() + 1;
var Y = today.getFullYear();
var period = "";

//weekdays
var weekday = new Array(7);
weekday[0] = "Chủ nhật";
weekday[1] = "Thứ hai";
weekday[2] = "Thứ ba";
weekday[3] = "Thứ tư";
weekday[4] = "Thứ năm";
weekday[5] = "Thứ sáu";
weekday[6] = "Thứ bảy";

period = bhbaoGetPeriod(h);
h = bhbaoCheckHour(h);
m = bhbaoCheckTime(m);
s = bhbaoCheckTime(s);


document.getElementById('spanWebTimer').innerHTML = "&nbsp;" + weekday[today.getDay()] + ", " + D +"/"+M+"/"+Y+" " + h+":"+m+":"+s + " " + period;
t = setTimeout('bhbaoStartTime()',1000);
}

function bhbaoCheckTime(i)
{
if (i<10) 
  {
  	i="0" + i;
  }
  return i;
}
function bhbaoCheckHour(i)
{
	if (i>12)
		{
			i = i - 12;
		}
	return i;
}
function bhbaoGetPeriod(i)
{
	if (i>12)
		return "CH";
	else return "SA";
}