var scW=screen.width/2;
var scH=screen.height/2;
function OpenWindow(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,menubar=no,statusbar=no,location=no,scrollbars=yes, resizable=no,top=0,width=640, height=480, left=0");
}
function OpenWinTrans(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,menubar=no,statusbar=no,location=no,scrollbars=no, resizable=no,top=0,width=640, height=200, left=0");
}
function pageChange(){
	jmpPage.submit();
}
function gallChange(){
	jmpGall.submit();
}
function OpenGall(file,w,h){
	OpenWin=this.open(file,"NewWindow","location=no,scrollbars=no,top=0,left=0,resizable=no,width=" +w +",height=" +h +"");
}
function openUrl(ur)
{
	window.location=ur;
}
function ovClass(id){
	id.className="tr_linkover";
}
function ouClass(id){
	id.className="tr_link";
}
function editorAction()
{
	frm_action.message.value = document.all.tags('div')['message'].innerHTML;
	frm_action.i_hdn.value="send";
	frm_action.submit();
}
function changeflag(si_id,si_read)
{
	frm_action.i_hdn.value="chgflag";
	frm_action.sread.value=si_read;
	frm_action.chgflag.value=si_id;
	frm_action.submit();
}
function replyto()
{
	
	frm_action.i_hdn.value="re";
	frm_action.submit();
}
function forwardto()
{
	frm_action.i_hdn.value="fw";
	frm_action.submit();
}
function forwardto1()
{
	frm_action.i_hdn.value="fw1";
	frm_action.submit();
}
function setValue(page)
{
	jmpPage.page.value=page;
	jmpPage.submit();
}
function changeImage(id,urlimg)
{
		id.src=urlimg;
}
function restoreImage(id)
{
	if (id.src=="images/congvandi_ov.gif"){
		id.src="images/congvandi.gif";
	}
	if (id.src=="images/congvantoi_ov.gif"){
		id.src="images/congvantoi.gif";
	}
}
function changepass()
{
	frm_action.i_hdn.value="cp";
	frm_action.submit();
}
function submitinfo()
{
	frm_action.i_hdn.value="subinfo";
	frm_action.submit();
}
function chglangEn()
{
	window.location="lang.asp?lang=2";
}
function chglangVN()
{
	window.location="lang.asp?lang=1";
}
function showdial()
{
	NewWindow=window.open('confirmdel.asp','NewWindow','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=300,height=120,dependet=yes,modal=no,left='+l+',top='+t);
}
function destroy(windowref)
{
	if(windowRef && !windowRef.closed)
		windowRef.close();
}
function submithidden()
{
	frm_login.getvl.value="loginfullpers";
	frm_login.submit();
}

//=====================================================================================================================

var mSelectedDay;
var mSelectedMonth
var mSelectedYear;

var mHighlightedDay = 0;
var mCurrentMonth;
var mCurrentYear;

var mOnHideFunction;

function setSelectedDates(dateString)
{
  var currentSelectedDate = new Date(dateString);

  if (isNaN(currentSelectedDate))
  {
    currentSelectedDate = new Date();
  }

  mSelectedDay = currentSelectedDate.getDate();
  mSelectedMonth = currentSelectedDate.getMonth();
  mSelectedYear = currentSelectedDate.getFullYear();

  mCurrentMonth = mSelectedMonth;
  mCurrentYear = mSelectedYear;
}

function generateCalendar(month, year, calendarDivID)
{
  var headingHTML = "<table class='monthHeadingTable' border='0'>";
  headingHTML += "<tr><td class='changeMonthTD' align=center>";
  headingHTML += "<img src='images/prev.gif' title='Show Previous Month' ";
  headingHTML += "onclick='goPreviousMonth(\"";
  headingHTML += calendarDivID + "\")'></td>";
  headingHTML += "<td class='monthHeadingTD'>";
  headingHTML += getMonthName(month) + " " + year + "</td>";
  headingHTML += "<td class='changeMonthTD' align=center>";
  headingHTML += "<img src='images/next.gif' title='Show Next Month' ";
  headingHTML += "onclick='goNextMonth(\"";
  headingHTML += calendarDivID + "\")'></td></tr></table>";
  var tableInnerHTML = "";
  tableInnerHTML = "<tr class='dayHeadTR'><TD class='dayHeadTD'>S</td>";
  tableInnerHTML += "<td class='dayHeadTD'>M</td>";
  tableInnerHTML += "<td class='dayHeadTD'>T</td>"
  tableInnerHTML += "<td class='dayHeadTD'>W</td>";
  tableInnerHTML += "<td class='dayHeadTD'>T</td>";
  tableInnerHTML += "<td class='dayHeadTD'>F</td>";
  tableInnerHTML += "<td class='dayHeadTD'>S</td>";
  tableInnerHTML += "</tr>"
  var elementIndex = 1;
  var iCellCounter;
  var iStartDayOfMonth = getStartDayOfMonthNumber(month,year);
  var iLastDayOfMonth = getDaysInAMonth(month,year);
  var tableRows = 6;
  for (weekIndex = 1; weekIndex <= tableRows; weekIndex++)
  {
    tableInnerHTML = tableInnerHTML + "<tr>";
    var dayCounter;

    for (dayCounter = 1; dayCounter <= 7; dayCounter++)
    {
      if (elementIndex <= iStartDayOfMonth 
          || 
          elementIndex > (iLastDayOfMonth + iStartDayOfMonth) )
      {
        tableInnerHTML += "<td class='emptyTD' id='dayTD"; 
        tableInnerHTML += elementIndex;
        tableInnerHTML += "'>&nbsp</td>";
      }
      else
      {
		var fulldate=new Date();
		if ((elementIndex - iStartDayOfMonth)==fulldate.getDate() && month==fulldate.getMonth() && year==fulldate.getFullYear()){
			tableInnerHTML += "<td class='curdayTD' ";
		}
		else
		{
			tableInnerHTML += "<td class='dayTD' ";
		}
        tableInnerHTML += " onclick='updateSelectedDate("; 
        tableInnerHTML += (elementIndex - iStartDayOfMonth); 
        tableInnerHTML += "," + month + ","; 
        tableInnerHTML += year + "); ";
        tableInnerHTML += " hideCalendar(\"" + calendarDivID; 
        tableInnerHTML += "\"); "; 
        tableInnerHTML += "'id='dayTD" + elementIndex +"'>"; 
        tableInnerHTML += (elementIndex - iStartDayOfMonth ); 
        tableInnerHTML += "</td>";
      }

      elementIndex++;
    }
    tableInnerHTML = tableInnerHTML + "</tr>";
  }
  var calendarDivObject = getTagById(calendarDivID)
  calendarDivObject.innerHTML = headingHTML + 
    "<table style='calendarTable' cellspacing='0'><tbody>" + 
    tableInnerHTML + 
    "</tbody></table>" + 
    "<span class='cancelHyperlink'><a href='javaScript: " + 
    "cancelCalendarNoSubmit(\"" + 
    calendarDivID + "\")' >Cancel</a></span>";
  if (mCurrentMonth == mSelectedMonth && mCurrentYear == mSelectedYear)
  {
    highlightDay(mSelectedDay, mSelectedMonth, mSelectedYear);
  }
  
  
}

function getTagById(tagId)
{
  var selectedTag;

  if (document.all)
  {
    selectedTag = document.all.item(tagId);
  }
  else 
  {
    selectedTag = document.getElementById(tagId);
  }

  return selectedTag;
}

function getStartDayOfMonthNumber(month,year)
{
  var newDate = new Date();
  newDate.setMonth(month)
  newDate.setFullYear(year);
  newDate.setDate(1);

  return newDate.getDay();
}

function getDaysInAMonth(month, year)
{
  var nowDate;
  month = parseInt(month)
  year = parseInt(year)

  var monthDays = new Array(31,29,31,30,31,30,31,31,30,31,30,31)

  // If Feb then need to check for leap years
  if (month == 1)
  {
    nowDate = new Date();
    nowDate.setMonth(1);
    nowDate.setYear(year);
    nowDate.setDate(29);

    if (nowDate.getMonth() == 2)
      monthDays[1] = 28;
  }

  return monthDays[month];
}

function getMonthName(month)
{
  var months = new 
    Array("Jan","Feb","Mar","Apr","May","Jun",
          "Jul","Aug","Sep","Oct","Nov","Dec");
  return months[month];
}

function highlightDay(day, month, year)
{
  // highlight selected cell
  var idOfCellToHighlight = day + getStartDayOfMonthNumber(month,year);
  idOfCellToHighlight = "dayTD" + idOfCellToHighlight;
  getTagById(idOfCellToHighlight).style.backgroundColor = 'lightgrey';
}

function updateSelectedDate(day,month,year)
{
  mSelectedDay = day;
  mSelectedMonth = month;
  mSelectedYear = year;
}

function goPreviousMonth(calendarDivID)
{
  mCurrentMonth--;
  if (mCurrentMonth < 0)
  {
    mCurrentMonth = 11;
    mCurrentYear--;
  }

  generateCalendar(mCurrentMonth, mCurrentYear,calendarDivID);
}

function goNextMonth(calendarDivID)
{
  mCurrentMonth++;
  if (mCurrentMonth > 11)
  {
    mCurrentMonth = 0;
    mCurrentYear++;
  }

  generateCalendar(mCurrentMonth, mCurrentYear,calendarDivID);
}

function cancelCalendar(calendarDivID)
{
  getTagById(calendarDivID).style.left = "-1200px";
  getTagById(calendarDivID).style.top = "-1000px";
}

function cancelCalendarNoSubmit(calendarDivID)
{
  getTagById(calendarDivID).style.left = "-1200px";
  getTagById(calendarDivID).style.top = "-1000px";
}

function hideCalendar(calendarDivID)
{
  cancelCalendar(calendarDivID);

  mOnHideFunction(mSelectedDay, getMonthName(mSelectedMonth), mSelectedYear);
}

function showCalendar(xPos, yPos, calendarDivID, onHideFunction)
{
  getTagById(calendarDivID).style.left = xPos;
  getTagById(calendarDivID).style.top = yPos;
  mOnHideFunction = onHideFunction;
}

//====================================================================================
function printpreview(page)
{
	frm_action.i_hdn.value="print";
	window.open(page,"print","width=400,height=400,menubar=no,statusbar=no,scrollbars=yes, resizable=yes,")
}