//-----------------------------------------Home
function toggleSection(itemId) {
	var	arrowId	= itemId.replace("SectionPanel", "ArrowImage");
	var	arrow, item;
	if (document.all) {
		item = document.all[itemId];
		arrow =document.all[arrowId];
		}
		if (!document.all && document.getElementById) {
			item = document.getElementById(itemId);
			arrow =	document.getElementById(arrowId);
			}
				
			if (item.style.display == closedDisplay) {
				arrow.src =arrowDown.src;
				item.style.display = openDisplay;
			}
			else {
				arrow.src =arrowRight.src;	
				item.style.display = closedDisplay;		
			}
		}

//-----------------------------------------
function saveState(menuId) {
	var cookieInfo = "";
	for (i = 0;	i <	sectionCount; i++) {
		var item;
		 var itemId = menuClientId.replace(menuId + "_Menu",menuId + "_MenuSections__ctl" + i + "_SectionPanel");
		
		if (document.all) {
			item = document.all[itemId];
			}
			if (!document.all && document.getElementById) {
				item = document.getElementById(itemId);
			}
			if (item.style.display == openDisplay)
				cookieInfo = cookieInfo	+ "|" +	i;		
		}
		setCookie("menuState",cookieInfo, getExpirationDate(1));
		}
//-----------------------------------------
function getState(menuId) {
	var sections = new Array();
	sections = getCookie("menuState").split("|");
	for (i = 1;	i < sections.length; i++) {
		var itemId = menuClientId.replace(menuId + "_Menu",menuId + "_MenuSections__ctl" + sections[i] + "_SectionPanel");
		expandit(itemId);
		}
	}	

//-----------------------------------------
function getCookie(cookieName) {
	var cookie;
	cookie = "" + document.cookie;
	var start = cookie.indexOf(cookieName);
	if (cookie == "" ||	start == -1) 
		return "";
	var end = cookie.indexOf(';',start);
	if (end == -1)
		end = cookie.length;
	return unescape(cookie.substring(start+cookieName.length + 1,end));
}

//-----------------------------------------
function setCookie(cookieName, value, expires) {
	cookieInfo = cookieName + "=" +	escape(value) +	";path=/"
	document.cookie	= cookieInfo;  
	return document.cookie;
}

//-----------------------------------------
function getExpirationDate(days){
	today =	new Date();
	today.setTime(Date.parse(today) + (days * 60 * 60 * 24 * 100));
	return	today.toUTCString();
	}


//---------------------------------------
function init()
{
	frmCalenda.frmDate1.disabled = true;
	frmCalenda.frmDate2.disabled = true;
}

//---------------------------------------
function openpage(pageurl, pagewidth, pageheight)                                     
{                                       
	var attr;                                       
	attr="width="+pagewidth+",height="+pageheight+",scrollbars=yes,left=0,top=0,status=auto,toolbar=auto,title=yes,resizable=no"
	window.open(pageurl,"_blank",attr);
}                                       

//---------------------------------------Calenda
function ShowCalenda(elTarget){
  if (showModalDialog)
  {
    var sRtn;
    sRtn = showModalDialog("Calenda.asp","","dialogWidth=191pt;dialogHeight=160pt;status=no;scroll=no");
    if (sRtn!="")
      elTarget.value = sRtn;
  }
}  

//---------------------------------------
function Kiemtra()
{
	if (Kiemtrangay(frmCalenda.frmDate1)!=0)
	{
		alert("Ngay bat dau tu = " + frmCalenda.frmDate1.value + " khong hop le, vui long xem lai. \n \n Can nhap theo dinh dang (dd/mm/yyyy)");
		frmCalenda.frmDate1.focus();
		return;
	}
	if (Kiemtrangay(frmCalenda.frmDate2)!=0)
	{
		alert("Ngay den = " + frmCalenda.frmDate2.value + " khong hop le, vui long xem lai. \n \n Can nhap theo dinh dang (dd/mm/yyyy)");
		frmCalenda.frmDate2.focus();
		return;
	}

	mDate1 = new Date(formatNgay(frmCalenda.frmDate1.value));
	mDate2 = new Date(formatNgay(frmCalenda.frmDate2.value));
	if (mDate1 > mDate2)
	{
		alert("Ngay bat dau tu = " + frmCalenda.frmDate1.value + " \n khong the lon hon \n ngay den = " + frmCalenda.frmDate2.value );
		frmCalenda.frmDate1.focus();
		return;
	}
	frmCalenda.submit();
}

//---------------------------------------
function Kiemtrangay(obj)
{
	var mretval = 0
	if (obj.value.length!=0)
	{
		if (isValidDate(obj.value)!=0)
		{		
			mretval = 2
			return;
		}
		dtest = new Date(formatNgay(obj.value));
	}
	return mretval
}

//---------------------------------------
function isValidDate(strDate)
{
  var retval = 0
  var aDDMMCCYY
  var dtest
  // Kiem tra dung format
  if (/^(\d\d?-\d\d?-\d{4})|(\d\d?\/\d\d?\/\d{4})|(\d{8})$/.test(strDate))
  {
    if (/\//.test(strDate))
    {
      aDDMMCCYY = strDate.split("/");
    }
    else
    if (/-/.test(strDate))
    {
      aDDMMCCYY = strDate.split("-");
    }
    else
    {
      aDDMMCCYY = Array(strDate.substr(0,2), strDate.substr(2,2), strDate.substr(4,4))
    }    
	dtest = new Date(aDDMMCCYY[1] + "/" + aDDMMCCYY[0] + "/" + aDDMMCCYY[2]);      
    if (dtest.getDate() != aDDMMCCYY[0] || dtest.getMonth() +1 != aDDMMCCYY[1] || dtest.getFullYear() != aDDMMCCYY[2])
    {
      retval = 2
    }
  }
  else
  {
	retval = 1
  }
  return retval
}

//---------------------------------------
function formatNgay(strNgay)
{
	var s="";
	var arr;
	n=strNgay.indexOf("/")
	if (n!=-1)
	{
		arr=strNgay.split("/")
		s=arr[1] + "/" + arr[0] + "/" + arr[2]
	}
	else
	{
		n=strNgay.indexOf("-")
		if (n!=-1)
		{
			arr=strNgay.split("-")
			s=arr[1] + "-" + arr[0] + "-" + arr[2]
		}	
	}
	return (s);
}


//---------------------------------------
function newCalendar() {
	today = new getToday();
	var parseYear = parseInt(document.all.year
	[document.all.year.selectedIndex].text);
	var newCal = new Date(parseYear,
	document.all.month.selectedIndex, 1);
	var day = -1;
	var startDay = newCal.getDay();
	var daily = 0;
	if ((today.year == newCal.getFullYear()) &&
	(today.month == newCal.getMonth()))
	day = today.day;
	var tableCal = document.all.calendar.tBodies.dayList;
	var intDaysInMonth =
	getDays(newCal.getMonth(), newCal.getFullYear());
	for (var intWeek = 0; intWeek < tableCal.rows.length;
		intWeek++)
		for (var intDay = 0;
			intDay < tableCal.rows[intWeek].cells.length;
			intDay++) {
			var cell = tableCal.rows[intWeek].cells[intDay];
		if ((intDay == startDay) && (0 == daily))
		daily = 1;
		cell.className = (day == daily) ? "today" : "allday";
		if ((daily > 0) && (daily <= intDaysInMonth))
			cell.innerText = daily++;
		else
               cell.innerText = "";
               }
         }

//---------------------------------------
function getDate() {
	var sDate;
	if ("TD" == event.srcElement.tagName)
	if ("" != event.srcElement.innerText)
//	sDate = event.srcElement.innerText + "/" + document.all.month.value + "/" + document.all.year.value;
	sDate = event.srcElement.innerText + "/" + document.all.month.value + "/" + document.all.year.value;
	document.all.ret.value = sDate;
 	window.close();
}

//----------------------------------------------------
function ZoomIn(image,name) {
 
 stats="toolbar=no,location=no,scrollbars=no,directories=no,status=no,menubar=no,width=430,height=410,top=100,left=100,resizable=yes";
 popUpWin = window.open('','popWin',stats);

 zhtm= '<HTML><HEAD><TITLE>' + name+ '</TITLE>';
 zhtm += '</head>';
 zhtm += '<body>';
 zhtm += '<p align="center">';
if (name.length !=0 || name.length !=1) zhtm += '<FONT face=Arial color=#008080 size=4>'+ name+'</FONT><br><br>';
 zhtm += '<a href="javascript:window.close();" ><IMG SRC="../images/' + image + 'm.jpg" border=0></a>';
 zhtm += '</P><P ALIGN="right"><font face="arial" color="#000000" size="1">© 2004 by <a href="mailto:webmaster@binhthuan.gov.vn?subject=Chao cac ban !">PSO Net</a></font></p>';
 zhtm += '</BODY></HTML>';
 window.popUpWin.document.write(zhtm);
 window.popUpWin.document.close();
}

//----------------------------------------------------
function ViewI(image,name,align) {
if (align== '') jalign='justify';
if (align== 'c') jalign='center';
if (align== 'l') jalign='left';
if (align== 'r') jalign='right';

 zhtm= '<table cellPadding="5" width="1" align="'+jalign+'"><tr><td align="middle">';
 zhtm += "<a href=\"javascript:ZoomIn('" + image + "','" + name + "')\">";
 zhtm += '<img src="../images/' + image + '.jpg" border=0 alt="'+ name +'"></a></td></tr>';
 zhtm += '<tr><td align="middle"><a class=rollovernav>'+ name+'</a></td></tr></table>';
document.write(zhtm);
}

//---------------------------------------
function thu_ngay(dk) {
  today = new Date(); 
  weekday = today.getDay();
  if (dk == 2)  {
  if (weekday == 6) document.write('Saturday');
  if (weekday == 0) document.write('Sunday');
  if (weekday == 1) document.write('Monday');
  if (weekday == 2) document.write('Tuesday');
  if (weekday == 3) document.write('Wednesday');
  if (weekday == 4) document.write('Thursday');
  if (weekday == 5) document.write('Friday');
  }
  else  {
  if (weekday == 6) document.write('Thứ bảy');
  if (weekday == 0) document.write('Chủ nhật');
  if (weekday == 1) document.write('Thứ hai');
  if (weekday == 2) document.write('Thứ ba');
  if (weekday == 3) document.write('Thứ tư');
  if (weekday == 4) document.write('Thứ năm');
  if (weekday == 5) document.write('Thứ sáu');
  }
  document.write(' - ' + today.getDate());
  month = today.getMonth()+1;
  document.write('/'+ month);
  year=today.getYear();
  if (year <= 1999) 
  document.write ('/',1900+year);
  else document.write ('/',year);
}
