// ASP Web Database Interface Builder (http://www.awdib.com)
// © Handy Productions, 2002 - All Rights Reserved
// You may use all/part of this script in your own, non-competing
// projects on the condition that you leave this message in tact.

function enterField(f1)
{
   f1.style.background='FEFDE0';   
}

function exitField(f1)
{
   f1.style.background='FFFFFF'
}

function ValidateKey(f1,f2,f3,f4,f5) 
{   
   var key=window.event.keyCode;
   if (f3=='a')
   {
     var allowed='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ :;,.?!£$%^&*()_+-*{}@~<>&"\'';
   }
   else if (f3=='n')
   {
     var allowed='0123456789.-';
   }
   else if (f3=='i')
   {
     var allowed='0123456789-';
   }
   else if (f3=='s')
   {
     var allowed=f4;
   }
   if (f3!='')
   {
      if (key!=13)
      {
         if (allowed.indexOf(String.fromCharCode(key))==-1) 
         {
            key=0;  
         }
      }
   }

   if (f3=='n'||f3=='i')
   {    
      if (key==46)
      {
         if (f1.value.indexOf('.')>-1)
         {
            key=0;
         }
      }
   }

   
   if (f5=='u')
   {
      var newkey=String.fromCharCode(key).toUpperCase();
      key=newkey.charCodeAt(0);
   }
   else if (f5=='l')
   {
      var newkey=String.fromCharCode(key).toLowerCase();
      key=newkey.charCodeAt(0);
   }

   window.event.keyCode=key;
}


function ValidateField(f1,f2) 
{   
   if (document.frmMain.currentError.value!='') 
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;  
      }
   }

   if (f1.value.length<f2)
   {
      alert('This field must be at least '+f2+' characters long');
      document.frmMain.currentError.value=f1.name;      
      f1.focus();
      f1.select();      
      return false;
   }
   else
   {
      exitField(f1);
      document.frmMain.currentError.value='';
      return true;
   }
}

function ValidateNumber(f1,f2,f3,f4)
{
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value=='')
   {
      alert('This value must be specified.');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }


   if ((f3!=0||f4!=0))
   {
      if (f1.value<f3)
      {
         alert('Minimum value allowed is: '+f3);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
      else if (f1.value>f4)
      {
         alert('This value must be less than or equal to '+f4);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
   }

   var decimalpos=f1.value.indexOf('.');
   var fieldlen=f1.value.length;
   if (decimalpos>0)
   {
      if ((f2+1)<(fieldlen-decimalpos))
      {
        alert('Only '+f2+' decimal places allowed!');
        document.frmMain.currentError.value=f1.name;
        f1.focus();
        f1.select();
        return false;
      }
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}

function ValidateSearchNumber(f1,f2,f3,f4) 
{
   if (f1.value=='')
   {
      exitField(f1);  
      return true;
   }
   else
   {
      return ValidateNumber(f1,f2,f3,f4);
   }

}


function ValidateDateTime(f1,f2,f3)
{
   if ((f3==0) & (f1.value.length==0))
   {
     exitField(f1);
     return true;
   }
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value.length<12)
   {
      alert('Please enter date/time in format');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }

   if (f2==1)
   {
      var dd=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==0)
   {
      var mm=f1.value.substring(0,2);
      var dd=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==2)
   {
      var yy=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var dd=f1.value.substring(4,8);
   }

   if (dd>31)
   {
      alert('Day value must not be larger than 31!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>12)
   {
      alert('Month must not be larger than 12!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (dd==30)
   {
      if (mm==4||mm==6||mm==9||mm==11)
      {
         alert('There is no 30th in Month '+mm);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
   }
   if (mm==2)
   {
      if (dd>29)
      {
         alert('There are not '+dd+' days in February!');
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
      if (dd==29)
      {
         if (yy%4!=0)
         {
            alert('There are not 29 days in February of that year!');
            document.frmMain.currentError.value=f1.name;
            f1.focus();
            f1.select();
            return false;
         }
      }
   }

   var hh=f1.value.substring(8,10);
   var mm=f1.value.substring(10,12);
   if (hh>23)
   {
      alert('Hours can not be larger than 23!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>59)
   {
      alert('[M13]!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}




function ValidateDate(f1,f2,f3)
{
   if ((f3==0) & (f1.value.length==0))
   {
     exitField(f1);
     return true;
   }
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value.length<8)
   {
      alert('Please enter date/time in format');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }

   if (f2==1)
   {
      var dd=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==0)
   {
      var mm=f1.value.substring(0,2);
      var dd=f1.value.substring(2,4);
      var yy=f1.value.substring(4,8);
   }
   else if (f2==2)
   {
      var yy=f1.value.substring(0,2);
      var mm=f1.value.substring(2,4);
      var dd=f1.value.substring(4,8);
   }

   if (dd>31)
   {
      alert('Day value must not be larger than 31!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>12)
   {
      alert('Month must not be larger than 12!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (dd==30)
   {
      if (mm==4||mm==6||mm==9||mm==11)
      {
         alert('There is no 30th in Month '+mm);
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
   }
   if (mm==2)
   {
      if (dd>29)
      {
         alert('There are not '+dd+' days in February!');
         document.frmMain.currentError.value=f1.name;
         f1.focus();
         f1.select();
         return false;
      }
      if (dd==29)
      {
         if (yy%4!=0)
         {
            alert('There are not 29 days in February of that year!!');
            document.frmMain.currentError.value=f1.name;
            f1.focus();
            f1.select();
            return false;
         }
      }
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}

function ValidateTime(f1,f2,f3)
{
   if ((f3==0) & (f1.value.length==0))
   {
     exitField(f1);
     return true;
   }
   if (document.frmMain.currentError.value!='')
   {
      if (document.frmMain.currentError.value!=f1.name)
      {
         exitField(f1);
         return true;
      }
   }

   if (f1.value.length<4)
   {
      alert('Please enter time in format HHMM');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }

   var hh=f1.value.substring(0,2);
   var mm=f1.value.substring(2,4);
   if (hh>23)
   {
      alert('Hours can not be larger than 23!');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   if (mm>59)
   {
      alert('Minutes can not be larger than 59');
      document.frmMain.currentError.value=f1.name;
      f1.focus();
      f1.select();
      return false;
   }
   exitField(f1);
   document.frmMain.currentError.value='';
   return true;
}

function processClick(f1,f2,f3,f4)
{
   if (f1.checked)
   {
     f2.value=f3;
   }
   else
   {
     f2.value=f4;
   }
   return true;
}

function processRange(f1,f2)
{
   if (f1.value=='3')
   {
      f2.className='fieldSettings'
   }
   else
   {
      f2.className='fieldSettingsHidden'
   }
   return true;
}

function lineOn(f1) 
{
  f1.className="lineOn"
}

function lineOff(f1) 
{
  f1.className="lineOff"
}

function highlightRow(f1) 
{
  if (eval(frmRow.selRow.value)==f1)
  {
     return false;
  }
  f1.className="gridHighlight"
}

function revertRow(f1) 
{  
  if (eval(frmRow.selRow.value)==f1)
  {
     return false;
  }
  if (f1.id.charAt(0)=='A')
  {
     f1.className="gridRowA"
  }
  else
  {
     f1.className="gridRowB"
  }
}

function revertRowNC(f1) 
{  
  if (f1.id.charAt(0)=='A')
  {
     f1.className="gridRowA";
  }
  else
  {
     f1.className="gridRowB";
  }
}

function selectRow(f1)
{
   if (frmRow.selRow.value!='')
   {
      revertRowNC(eval(frmRow.selRow.value));
   }

   frmRow.selRow.value=f1.id; 

   f1.className="gridSelected";
   if (btnEdit)
   {
      btnEdit.className="buttonColor";
   }
   btnDelete.className="buttonColor";
}

function showRow()
{
   if (document.all("frmRow"))
   {    
   
      if (frmRow.selRow.value=='')
      {
         return false;
      }
      if (eval(frmRow.selRow.value))
      {
         selectRow(eval(frmRow.selRow.value));
      }
   }
}

function editDeleteRecord(F1)
{
   if (F1=='a')
   {
      frmMain.mode.value='add';
      frmMain.submit();  
      return true;
   } 

   if (frmRow.selRow.value=='')
   {
      alert('Please select record!');
      return false;
   }
   
   frmMain.f105where.value=eval('frm'+frmRow.selRow.value).f105where.value;
   
   if (F1=='e')
   {
      frmMain.mode.value='edit';
      frmMain.submit();
      return true;
   }
   else
   {
      var result
      result = confirm("Are you sure that you wish to delete this record?");
      if (result) 
      {
         frmMain.mode.value='delete';
         frmMain.submit();
         return true;
      }
   }
   return true;
}

function showOutline(f1)
{
   f1.className="menubuttonGreyRaised"
}

function removeOutline(f1)
{
   f1.className="menubuttonGrey"
}

function doStatus(f1)
{
   window.status=f1;
}

function checkCombo(f1,f2)
{
   if (f1.value=='') 
   {
      f2.value=0;
      return false;
   }
   if (f2.value==0)
   {
      f2.value=1
   }
}
 
var alertVar = 0;

function nothing(){}

function verifyInput_allNumbers( theInput ){

	
	if (alertVar == 1){
		alert("verifyInput_allNumbers begin");
	}
	
	var str = "0123456789";
	var n = theInput.length;
	var itMatches = 0;

	for (var i=0;i<n;i++){
		itMatches = 0;
		for (var j=0;j<str.length;j++){
			if ( theInput.charAt(i) == str.charAt(j) ){
				itMatches=1;
			}
		}
		if (itMatches==0){
			i=n;
		}
	}

	if ( itMatches == 0 ) {
		return false;
	}
	else{
		return true;
	}

}

function parseInput( theInput , dFormat ){

	if (alertVar == 1){
		alert("parseInput begin");
	}
	
	i11 = theInput.substring(0,2)*1;
	i22 = (theInput.substring(2,4)*1);

	if (dFormat==2||dFormat==4){
		iiDay=i22;
		iiMonth=i11-1;
	}
	else{
		iiDay=i11;
		iiMonth=i22-1;
	}


	iiYear = theInput.substring(4,8)*1;
	if (theInput.length==12){
		iiHour = theInput.substring(8,10)*1;
		iiMinute = theInput.substring(10,12)*1;
		sTodayIs = "Now";
	}
	else{
		sTodayIs = "Today";
	}

	
	if (alertVar == 1){
		alert("iiDay: ."+iiDay+".");
		alert("iiMonth: ."+iiMonth+".");
		alert("iiYear: ."+iiYear+".");
		alert("iiHour: ."+iiHour+".");
		alert("iiMinute: ."+iiMinute+".");
	}	

	if ( verifyInput_DateTime( iiDay, iiMonth, iiYear, iiHour, iiMinute )==0 ){
		setTimeNow();
	}

	if (alertVar == 1){
		alert("parseInput end");
	}
}


function verifyInput_DateTime( iiDay, iiMonth, iiYear, iiHour, iiMinute ){

	if (alertVar == 1){
		alert("verifyInput_DateTime begin");
	}
	returnBoolean = 0;

	iVal = parseInt(iiMonth);
	var num = ++iVal;

	if (alertVar == 1){
		alert("bakżlan " + num);
	}

	switch ( num ){

		case  1:
		case  3:
		case  5:
		case  7:
		case  8:
		case 10:
		case 12:

			if (iiDay<=31){
				returnBoolean = 1;
			}
			break;
			
		case  4:
		case  6:
		case  9:
		case 11:

			if (iiDay<=30){
				returnBoolean = 1;
			}
			break;

		case  2:
			if (isLeapYear(iiYear)){
				if (iiDay<=29){
					returnBoolean = 1;
				}
			}
			else{
				if (iiDay<=28){
					returnBoolean = 1;
				}
			}
			break;
	}
	

	if (iiHour!=""){
		if (iiHour>23||iiMinute>59){
			returnBoolean = 0;
		}
	}

	if (alertVar == 1){
		alert("verifyInput_DateTime : " +returnBoolean);
	}
	return returnBoolean;

}


function setTimeNow(){

	if (alertVar == 1){
		alert("setTimeNow begin");
	}
	d = new Date();
	iiDay = d.getDate();
	iiMonth = d.getMonth();
	iiYear = d.getYear();
	iiHour = d.getHours();
	iiMinute = d.getMinutes();


	if (alertVar == 1){
		alert("iiDay: ."+iiDay+".");
		alert("iiMonth: ."+iiMonth+".");
		alert("iiYear: ."+iiYear+".");
		alert("iiHour: ."+iiHour+".");
		alert("iiMinute: ."+iiMinute+".");
	
		alert("setTimeNow end");
	}
}


function onafterload_c( iiDay, iiMonth, iiYear, iiHour, iiMinute ){

	if (alertVar == 1){
		alert("onafterload_c begin");
	}			
	iSelDay = iiDay;
	iMonth = iiMonth;
	iYear = iiYear;
	iHour = iiHour;
	iMinute = iiMinute;

	clearAllDays();
	setCurrentDate(iYear, iMonth, iSelDay, iHour, iMinute);

	if (alertVar == 1){
		alert("onafterload_c end");
	}
}


function onafterload(iNextMonthDayPressed){
   setCurrentDate(iYear, iMonth, iNextMonthDayPressed, iHour, iMinute);
}



function controlAndOpen_calendar(theObj,dFormat){
	if ( document.getElementById('calendar').style.visibility == 'hidden' ){
		showCalendar(theObj,'txtDate',dFormat);
	}
	else{
		hideCalendar();
	}
}
function controlAndOpen_DropDown(num){

	if (num==0){
		if (isOpen_DropDownMonth == 1){
			popDownYear(0);
			popUpMonth();
		}
		else{
			popDownMonth(0);
		}
	}
	else{
		if (isOpen_DropDownYear == 1){
			popDownMonth(1);
			popUpYear();
		}
		else{
			popDownYear(1);
		}
	}
	
}

function isLeapYear(y) 
{
	return (y%4!=0) ? false : (y%100!=0) ? true : (y%400!=0) ? false : true;
}

function addDay(iDay)
{
	if(iMaxY==6)
		{iMaxY = 0; iMaxX++;}
	else
		iMaxY ++;
	document.getElementById("cell_" + iMaxX + "_" + iMaxY).innerHTML = String(iDay);
	document.getElementById("cell_" + iMaxX + "_" + iMaxY).onclick = function(){tdclick(this)};
}

function makeDaySelected(iDay)
{
	for(var x=0; x<=5; x++)
		for(var y=0; y<=6; y++)
		{
			if(document.getElementById("cell_" + x + "_" + y).style.color=="")
				if(document.getElementById("cell_" + x + "_" + y).innerHTML==String(iDay))
					document.getElementById("cell_" + x + "_" + y).style.backgroundColor = "#FFAAFF";
		}
}

function getDaysNumberForMonth(iMonth, iYear)
{

	switch (iMonth+1)
	{
		case  1:
		case  3:
		case  5:
		case  7:
		case  8:
		case 10:
		case 12:
			return(31);
			break;
		case  4:
		case  6:
		case  9:
		case 11:
			return(30);
			break;
		case  2:
			if (isLeapYear(iYear)) 
				return(29)
			else
				return(28);
			break;
	}
}

function checkToday()
{
	if((todayDate.getUTCFullYear() == iYear)&&
		(todayDate.getUTCMonth()+1 == monthName[iMonth]))
	{
		for(var x=0; x<=5; x++)
			for(var y=0; y<=6; y++)
				if((document.getElementById("cell_" + x + "_" + y).innerHTML == String(todayDate.getUTCDate()))&&(document.getElementById("cell_" + x + "_" + y).style.color != "gray"))
				{
					document.getElementById("cell_" + x + "_" + y).innerHTML += "<img src='./images/select.gif'>";
					break;
				}
	}
}

function gotoToday()
{
	d = new Date();
	d.setUTCMonth(todayDate.getUTCMonth());
	d.setUTCFullYear(todayDate.getUTCFullYear());
	iSelDay = d.getUTCDate();
	iMonth = d.getUTCMonth();
	iYear = d.getUTCFullYear();

	iHour = d.getHours();
	iMinute = d.getMinutes();

	clearAllDays();
	onafterload(todayDate.getUTCDate());

}

function fnShowPic(obj, mode)
{
	if (mode == 1)
		document.getElementById(obj).style.filter=''
	else
		document.getElementById(obj).style.filter='gray(), alpha(opacity=50)';
}

function setCurrentDate(iYear, iMonth, iDay, iHour, iMinute)
{
	var s;
	var iLastDayOfMonth;
	var tempDateObj = new Date();
		
	document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[iMonth] + "&nbsp;<IMG id='changeMonth' style='filter: gray(), alpha(opacity=50);' SRC='./images/dropcal.gif' BORDER=0 onmouseover='fnShowPic(\"changeMonth\",1)' onmouseout='fnShowPic(\"changeMonth\",0)'>";
	
	document.getElementById("spanYear").innerHTML = 								"&nbsp;<IMG id='changeYear' style='filter: gray(), alpha(opacity=50);' SRC='./images/dropcal2.gif' BORDER=0 onmouseover='fnShowPic(\"changeYear\",1)' onmouseout='fnShowPic(\"changeYear\",0)'>" + "&nbsp;" + iYear;

	crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth;
	crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear;
	

    tempDateObj.setUTCFullYear(iYear, iMonth, 1);

	iLastDayOfMonth = getDaysNumberForMonth(iMonth, iYear);
	document.getElementById("txtToday").innerHTML = "<img src=\"./images/select.gif\"><b><FONT size=1>" + sTodayIs + "</FONT></b>";
	document.getElementById("txtToday").onclick = function(){gotoToday()};

	
	var iDisabledDayBefore = 0;
	var iPrevMonth;

	var iPrevYear = iYear;
	var iDaysInPrevMonth;
	if(tempDateObj.getUTCDay()>0)
		for(var x=0; x<tempDateObj.getUTCDay(); x++)
		{
			iDisabledDayBefore++;
		}
	switch (iMonth)
	{
		case 0:
			iPrevMonth = 11;
			iPrevYear--;
			break;
		default:
			iPrevMonth = iMonth-1;
			break;
	}
	iDaysInPrevMonth = getDaysNumberForMonth(iPrevMonth, iPrevYear);
	var arrTemp = new Array();
	
	if(tempDateObj.getUTCDay()>0)
	{
		for(var i=iDaysInPrevMonth-iDisabledDayBefore+1; i<=iDaysInPrevMonth;i++)
		{
			arrTemp[arrTemp.length] = i;
		}
		for(var x=0; x<tempDateObj.getUTCDay(); x++)
		{
			document.getElementById("cell_0_" + x).innerHTML = arrTemp[x];
			document.getElementById("cell_0_" + x).onclick = function(){changeDate(2, this)};
			document.getElementById("cell_0_" + x).style.color = "gray";
			iMaxY++;
		}
	}
	else
	{
		for(var i=iDaysInPrevMonth-6; i<=iDaysInPrevMonth;i++)
		{
			arrTemp[arrTemp.length] = i;
		}		
		for(var x=0; x<=6; x++)
		{
			document.getElementById("cell_0_" + x).innerHTML = arrTemp[x];
			document.getElementById("cell_0_" + x).onclick = function(){changeDate(2, this)};
			document.getElementById("cell_0_" + x).style.color = "gray";
		}
		
		iMaxX++;
		iMaxY = 0;
	}

	document.getElementById("cell_" + iMaxX + "_" + iMaxY).innerHTML = "1";
	document.getElementById("cell_" + iMaxX + "_" + iMaxY).onclick = function(){tdclick(this)};

	for(var iCurrentDay = 2; iCurrentDay <= iLastDayOfMonth; iCurrentDay++)
		addDay(iCurrentDay)
		makeDaySelected(iDay);

	var iNextDays = 1;
	for(var i=iMaxY+1; i<=6; i++)
	{
		document.getElementById("cell_" + iMaxX + "_" + i).innerHTML = iNextDays;
		document.getElementById("cell_" + iMaxX + "_" + i).onclick = function(){changeDate(3, this)};
		document.getElementById("cell_" + iMaxX + "_" + i).style.color = "gray";
		iNextDays++;
	}
	if(iMaxX<5)
	{
		iMaxX++;
		iMaxY=0;
		for(var i=iMaxY; i<=6; i++)
		{
			document.getElementById("cell_" + iMaxX + "_" + i).innerHTML = iNextDays;
			document.getElementById("cell_" + iMaxX + "_" + i).onclick = function(){changeDate(3, this)};
			document.getElementById("cell_" + iMaxX + "_" + i).style.color = "gray";
			iNextDays++;
		}
	}
	bIsLoaded = true;


	if (sTodayIs.indexOf("Now")!=-1){

		if(iHour<10){
			self.document.frmCalendar.txt_hh.value="0"+iHour;
		}
		else{
			self.document.frmCalendar.txt_hh.value=iHour;
		}

		if(iMinute<10){
			self.document.frmCalendar.txt_mm.value="0"+iMinute;
		}
		else{
			self.document.frmCalendar.txt_mm.value=iMinute;
		}

		self.document.frmCalendar.txt_hh.focus();
	}
	else{
		self.document.frmCalendar.txt_hh.value="";
		self.document.frmCalendar.txt_mm.value="";
	}

	checkToday();
}


function changeDate(mode, obj)
{
	var iNextMonthDayPressed = null;
	if(bIsLoaded)
	{
		switch (mode)
		{
			case 0:
				d.setUTCMonth(obj);
				break;
			case 1:
				d.setUTCFullYear(obj);
				break;
			case 2:
				if(obj != null) iNextMonthDayPressed = obj.innerHTML;
				switch (d.getUTCMonth())
				{
					case 0:
						d.setUTCMonth(11);
						d.setUTCFullYear(d.getUTCFullYear()-1);
						break;
					default:
						d.setUTCMonth(d.getUTCMonth()-1);
						break;
				}
				break;
			case 3:
				if(obj != null) iNextMonthDayPressed = obj.innerHTML;
				switch (d.getUTCMonth())
				{
					case 11:
						d.setUTCMonth(0);
						d.setUTCFullYear(d.getUTCFullYear()+1);
						break;
					default:
						d.setUTCMonth((d.getUTCMonth()+1));
						break;
				}
				break;
		}
		iMonth = d.getUTCMonth();
		iYear = d.getUTCFullYear();
		clearAllDays();
		iSelDay = iNextMonthDayPressed;
		onafterload(iNextMonthDayPressed);
	}
}

function clearAllDays()
{
	setAllCellsNoColor();
	for(var x=0; x<=5; x++)
		for(var y=0; y<=6; y++)
		{
			document.getElementById("cell_" + x + "_" + y).innerHTML = "";
			document.getElementById("cell_" + x + "_" + y).onclick = "";
			document.getElementById("cell_" + x + "_" + y).style.color = "";
			document.getElementById("cell_" + x + "_" + y).background = "";
		}
	iMaxX = 0;
	iMaxY = 0;
}

function setAllCellsNoColor()
{
	for(var x=0; x<=5; x++)
		for(var y=0; y<=6; y++)
		{
			document.getElementById("cell_" + x + "_" + y).style.backgroundColor = "";
		}
}

function tdclick(obj)
{
	setAllCellsNoColor()
	if(obj.innerHTML!="") 
	{
		obj.style.backgroundColor = "#FFAAFF";
		iSelDay = obj.innerHTML;
	}
	fnRetVal();hideCalendar();
}

function fnRetVal()
{
	var retval = "";
	var sSeparator, hourSeparator, separatorBoth;
	var data = document.frmCalendar;
	sSeparator = "";
	hourSeparator = "";
	separatorBoth = "";
	if(iSelDay==null) iSelDay=0;
	var sMonth = String(iMonth+1);
	var sSelDay = iSelDay;
	if(String(iMonth+1).length==1) sMonth = "0" + sMonth;
	if(String(sSelDay).length==1) sSelDay = "0" + sSelDay;
	var sHH = document.getElementById("txt_hh").value+"";
	var sMM = document.getElementById("txt_mm").value+"";

	if ( !(sHH.indexOf(" ")!=-1 || sHH.indexOf("  ")!=-1 || sMM.indexOf(" ")!=-1 || sMM.indexOf("  ")!=-1) ){
		if(sHH.length==1){
			sHH="0"+sHH;
		}
	
		if(sMM.length==1){
			sMM="0"+sMM;
		}
	}
	else{
		sHH="";
		sMM="";
	}
		
	switch (lngFormat)
	{
		case 1: 	
			if(iSelDay!=0) 
				retval += sSelDay + sSeparator + sMonth + sSeparator + iYear;
			else
				retval = -1;	
			break;
		case 2: 	
			if(iSelDay!=0) 
				retval += sMonth + sSeparator + sSelDay + sSeparator + iYear;
			else
				retval = -1;	
			break;
		case 3: 	
			if(iSelDay!=0) 
				retval += sSelDay + sSeparator + sMonth + sSeparator + iYear + separatorBoth + sHH + hourSeparator + sMM;
			else
				retval = -1;	
			break;
		case 4: 	
			if(iSelDay!=0) 
				retval += sMonth + sSeparator + sSelDay + sSeparator + iYear  + separatorBoth + sHH + hourSeparator + sMM;
			else
				retval = -1;	
			break;
	}
	if(retval!=-1) {document.getElementById(objRetName).value = retval;}
}

function hideElement( elmID, overDiv )
{
	if(ie)
	{
		for( i = 0; i < document.all.tags(elmID).length; i++ )
		{
			obj = document.all.tags(elmID)[i];
			if( !obj || !obj.offsetParent )	continue;
			objLeft = obj.offsetLeft;
			objTop = obj.offsetTop;
			objParent = obj.offsetParent;
            while( objParent.tagName.toUpperCase() != "BODY" )
			{
				objLeft += objParent.offsetLeft;
				objTop  += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}
            objHeight = obj.offsetHeight;
			objWidth = obj.offsetWidth;
            if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
			else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
			else if( overDiv.offsetTop >= ( objTop + objHeight ));
			else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
			else
			{
				if(obj.id!="selMonth"&&obj.id!="selYear") obj.style.visibility = "hidden";
			}
		}
	}
}

function swapImage(srcImg, destImg)
{
	if (ie)	{ document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
}

function showElement( elmID )
{
	if(ie)
	{
		for( i = 0; i < document.all.tags(elmID).length; i++ )
		{
			obj = document.all.tags( elmID )[i];
            if( !obj || !obj.offsetParent ) continue;
		    obj.style.visibility = "";
		}
	}
}

function showCalendar(obj, RetName, dFormat)
{
	isOpen_calendar = -isOpen_calendar;
	var leftpos = 0;
	var toppos = 0;
	aTag = new Object(obj);
	lngFormat = dFormat;
	objRetName = RetName;
	
	if (dFormat==3||dFormat==4) document.getElementById("div_time").style.display = "block";
		
	var crossobj = document.getElementById("calendar").style;
	
	do 
	{
		aTag = aTag.offsetParent;
		leftpos += aTag.offsetLeft;
		toppos += aTag.offsetTop;
	} 
	while(aTag.tagName!="BODY");

	crossobj.left =	fixedX==-1 ? obj.offsetLeft + leftpos :	fixedX;
	crossobj.top = fixedY==-1 ? obj.offsetTop + toppos + obj.offsetHeight +2 : fixedY;
	crossobj.visibility=(dom||ie)? "visible" : "show";
	hideElement( 'SELECT', document.getElementById("calendar") );
	hideElement( 'APPLET', document.getElementById("calendar") );

	var theInput = obj.value;

	if (alertVar == 1){
		alert("theInput: ." + theInput + ".");
	}

	if (theInput!=""){

		if (alertVar == 1){
			alert("length: ." + theInput.length + ".");
		}
		
		if ( (theInput.length==8||theInput.length==12) && verifyInput_allNumbers( theInput ) ){
			if (alertVar == 1){
				alert("correct");
			}
			parseInput( theInput, dFormat );
		}
		else{
			if (alertVar == 1){
				alert("incorrect");
			}
			setTimeNow();
		}

		onafterload_c( iiDay, iiMonth, iiYear, iiHour, iiMinute );
	}
	else{
		sTodayIs = "Today";
		if (alertVar == 1){
			alert("empty theInput: ." + theInput + ".");
		}
	}
	


}

function hideCalendar()	
{
	isOpen_calendar = -isOpen_calendar;
    showElement( 'SELECT' );
	showElement( 'APPLET' );
	crossMonthObj.visibility = "hidden";
	crossYearObj.visibility = "hidden";
	document.getElementById("calendar").style.visibility = "hidden";

}

function constructMonth() 
{
	popDownYear(0);
	document.onselectstart=new Function ("return false")

	if (!monthConstructed) 
	{
		sHTML =	""
		for	(i=0; i<12;	i++) 
		{
			sName =	monthName[i];
			if (i==iMonth){
				sName =	"<B>" +	sName +	"</B>"
			}
			sHTML += "<tr><td id='m" + i + "' style='cursor:default' onmouseout='this.style.backgroundColor=\"\";this.style.color=\"black\"' onclick='monthConstructed=false;monthSelected=" + i + ";popDownMonth(0);event.cancelBubble=true;changeDate(0, " + i + ");'>&nbsp;" + sName + "&nbsp;</td></tr>"
		}
		document.getElementById("selectMonth").innerHTML = "<table style='font-family:verdana; font-size:9px; border-width:1; border-style:solid; border-color:#000080;' bgcolor='#FFFFFF' cellspacing=0 onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownMonth(1)\",100)' " + sHTML + "</table>"
		monthConstructed=true
	}
	
}

function popUpMonth() 
{
	isOpen_DropDownMonth=-1;
	var crossobj1 = document.getElementById("spanMonth");
	
	constructMonth()
	crossMonthObj.visibility = (dom||ie)? "visible" : "show";
	crossMonthObj.left = parseInt(crossobj1.offsetWidth);
	crossMonthObj.top =	 parseInt(crossobj1.offsetHeight);

	hideElement( 'SELECT', document.getElementById("selectMonth") );
	hideElement( 'APPLET', document.getElementById("selectMonth") );			
	fnShowPic("changeMonth",1);
}

function popDownMonth(fromWhere)	
{

	if (fromWhere==1){
		document.onselectstart=new Function ("return false");
	}
	else{
		document.onselectstart=new Function ("return true");
	}

	isOpen_DropDownMonth=1;
	crossMonthObj.visibility = "hidden";
	fnShowPic("changeMonth",0);
}

function incYear() 
{
	for	(i=0; i<7; i++)
	{
		newYear	= (i+nStartingYear)+1
		if (newYear==iYear)
			txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" 
		else
			txtYear = "&nbsp;" + newYear + "&nbsp;";
		document.getElementById("y"+i).innerHTML = txtYear;
	}
	nStartingYear ++;
	bShow=true
}

function incYear10() 
{
	for	(i=0; i<7; i++)
	{
		newYear	= (i+nStartingYear)+10;
		if (newYear==iYear)
			txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" 
		else
			txtYear = "&nbsp;" + newYear + "&nbsp;";
		document.getElementById("y"+i).innerHTML = txtYear;
	}
	nStartingYear = nStartingYear + 10;
	bShow=true
}

function decYear() 
{
	for	(i=0; i<7; i++)
	{
		newYear	= (i+nStartingYear)-1;
		if (newYear==iYear)
			txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" 
		else
			txtYear = "&nbsp;" + newYear + "&nbsp;" 
		document.getElementById("y"+i).innerHTML = txtYear;
	}
	nStartingYear --;
	bShow=true
}

function decYear10() 
{
	for	(i=0; i<7; i++)
	{
		newYear	= (i+nStartingYear)-5;
		if (newYear==iYear)
			txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" 
		else
			txtYear = "&nbsp;" + newYear + "&nbsp;" 
		
		document.getElementById("y"+i).innerHTML = txtYear;
	}
	nStartingYear = nStartingYear - 5;
	bShow=true
}

function selectYear(nYear) 
{
	yearSelected = parseInt(nYear+nStartingYear);
	yearConstructed = false;
	popDownYear(1);
	changeDate(1,yearSelected);
}

function popDownYear(fromWhere) 
{

	if (fromWhere==0){
		document.onselectstart=new Function ("return false");
	}
	else{
		document.onselectstart=new Function ("return true");
	}

	isOpen_DropDownYear=1;	
	crossYearObj.visibility= "hidden";
}

function constructYear() 
{
	popDownMonth(1);
	sHTML =	"";
	if (!yearConstructed) 
	{
		sHTML =	"<tr><td align='center' style='cursor:default' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-1</td>" +
		"<td align='center' style='cursor:default' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear10()\",1)' onmouseup='clearInterval(intervalID1)'>-10</td></tr>"

		j =	0;
		nStartingYear = iYear-3;
		for	(i=(iYear-3); i<=(iYear+3); i++) 
		{
			sName =	i;
			if (i==iYear)
			{
				sName =	"<B>" +	sName +	"</B>";
			}

			sHTML += "<tr><td colspan=2 id='y" + j + "' style='cursor:default' onmouseout='this.style.backgroundColor=\"\";this.style.color=\"black\"' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>";
			j ++;
		}

		sHTML += "<tr><td align='center' style='cursor:default' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+1</td>" +
			"<td align='center' style='cursor:default' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear10()\",1)'	onmouseup='clearInterval(intervalID2)'>+10</td></tr>"

		document.getElementById("selectYear").innerHTML	= "<table style='font-family:verdana; font-size:9px; border-width:1; border-style:solid; border-color:#000080;' bgcolor='#FFFFFF' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear(1)\",100)' cellspacing=0>" + sHTML + "</table>"

		yearConstructed	= true;
	}
}

function popUpYear() 
{
	isOpen_DropDownYear=-1;
	var crossobj2 = document.getElementById("spanYear");
	var leftOffset;
	constructYear();
	crossYearObj.visibility	= (dom||ie)? "visible" : "show";
	leftOffset = parseInt(crossobj2.offsetWidth) + document.getElementById("spanYear").offsetLeft;
	if (ie)
	{
		leftOffset += 6;
	}
	crossYearObj.left = parseInt(crossobj2.offsetWidth) +	65;
	crossYearObj.top = parseInt(crossobj2.offsetHeight);
}


var isOpen_calendar = 1;
var isOpen_DropDownMonth = 1;
var isOpen_DropDownYear = 1;

var iiDay = "";
var iiMonth = "";
var iiYear = "";
var iiHour = "";
var iiMinute = "";

var fixedX = -1			
var fixedY = -1			
var imgDir = "images"			
var monthConstructed = false;
var yearConstructed = false;

var yearSelected;
var crossMonthObj, crossYearObj;
var intervalID1,timeoutID2,intervalID2,timeoutID1;
var nStartingYear;

var iMinYear = 1900;
var iMaxYear = 2100;
var iMaxX = 0;
var iMaxY = 0;
var bIsLoaded = false;
var iSelDay = 0;

var lngFormat = 1;
var objRetName;

var d = new Date();
var iMonth = d.getMonth();
var iYear = d.getFullYear();
var iHour = d.getHours();
var iMinute = d.getMinutes();
var todayDate = new Date();
var sTodayIs = "Today";

var ie=document.all;
var dom=document.getElementById;

var monthName =	new Array("January","February","March","April","May","June","July","August","September","October","November","December")

document.write(""+

	"<div onclick='bShow=true' id='calendar' style='z-index:+999;position:absolute;visibility:hidden;'>"+

	"<FORM name=\"frmCalendar\" method=\"post\">" +
	"<TABLE width=180 cellSpacing=0 cellPadding=0 border=0 style='BORDER-RIGHT: #a0a0a0 1px solid; BORDER-TOP: #a0a0a0 1px solid; FONT-SIZE: 11px; BORDER-LEFT: #a0a0a0 1px solid; BORDER-BOTTOM: #a0a0a0 1px solid; FONT-FAMILY: arial' align=center valign=middle bgColor=white>" +
	"<TR>"+
		"<TD align=left class=\"buttons\" onclick=\"changeDate(2, null);\" onmouseover=\"document.getElementById('arL').style.filter='';\" onmouseout=\"document.getElementById('arL').style.filter='gray(), alpha(opacity=50)';\">&nbsp;&nbsp;<img id='arL' style=\"filter: 'gray(), alpha(opacity=50)'\" src='./images/left.gif'></TD>"+
	    "<TD width=150><span id='spanMonth' style='cursor:pointer' onmouseover='fnShowPic(\"changeMonth\",1);window.status=\"Click to select a month.\"' onmouseout='fnShowPic(\"changeMonth\",0);window.status=\"\"' onclick='controlAndOpen_DropDown(0)'></span>&nbsp;<div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div></TD>"+
		"<TD nowrap><span id='spanYear' style='cursor:pointer' onmouseover='fnShowPic(\"changeYear\",1);window.status=\"Click to select a year.\"' onmouseout='fnShowPic(\"changeYear\",0);window.status=\"\"' onclick='controlAndOpen_DropDown(1)'></span><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>&nbsp;</TD>"+
		"<TD nowrap class=\"buttons\" onclick=\"changeDate(3, null);\" onmouseover=\"document.getElementById('arR').style.filter='';\" onmouseout=\"document.getElementById('arR').style.filter='gray(), alpha(opacity=50)';\"><img id='arR' style=\"filter: 'gray(), alpha(opacity=50)'\" src='./images/right.gif'>&nbsp;</TD>"+
	"</TR>"+
	"<TR>"+
		"<TD colspan=4>"+
		"<TABLE style=\"WIDTH: 100%\" cellSpacing=0 cellPadding=0 width=\"100%\" align=center border=0>"+
		"<TR>"+
			"<TD class=\"WEEKEND\">SU</TD>"+
			"<TD class=\"DAYOFWEEK\">MO</TD>"+
			"<TD class=\"DAYOFWEEK\">TU</TD>"+
			"<TD class=\"DAYOFWEEK\">WE</TD>"+
			"<TD class=\"DAYOFWEEK\">TH</TD>"+
			"<TD class=\"DAYOFWEEK\">FR</TD>"+
			"<TD class=\"WEEKEND\">SA</TD>"+
		"</TR>"+
		"<TR>"+
			"<TD colspan=7><HR></TD>"+
		"</TR>");

for(var a = 0; a <=5; a++)
{
	document.write(""+

		"<TR id=\"cell_" + String(a) + "\">");

	for(var b = 0; b<=6; b++)
	{
		document.write(""+

			"<TD id=\"cell_" + String(a) + "_" + String(b) + "\" class=\"ALLDAYS\" onmouseover=\"this.className='ALLDAYSUP'\" onmouseout=\"this.className='ALLDAYS'\" onclick=\"tdclick(this)\"></TD>");

	}
	document.write(""+

		"</TR>");

}    

document.write(""+

		"</TABLE>"+
		"</TD>"+
	"</TR>"+
	"</TABLE>"+
	"<TABLE width=180 cellSpacing=0 cellPadding=0 border=0 style='BORDER-RIGHT: #a0a0a0 1px solid; BORDER-TOP: #a0a0a0 1px solid; FONT-SIZE: 11px; BORDER-LEFT: #a0a0a0 1px solid; BORDER-BOTTOM: #a0a0a0 1px solid; FONT-FAMILY: arial' align=center valign=middle bgColor=white>" +
	"<TR>"+
		"<TD colspan=2><div id=\"txtToday\" style='cursor:default'></div><div id='div_time' style='display:none'>HH<input type='text' class='hhmm' id='txt_hh' size='1' maxlength='2' onkeyup='if(isNaN(this.value)||this.value>23||this.value<0) this.value=\"\"' onchange='if(isNaN(this.value)||this.value>23||this.value<0) this.value=\"\"'>MM<input type='text' class='hhmm' id='txt_mm' size='1' maxlength='2' onkeyup='if(isNaN(this.value)||this.value>59||this.value<0) this.value=\"\"' onchange='if(isNaN(this.value)||this.value>59||this.value<0)  this.value=\"\"'></div></TD>"+
                "<TD class=\"ALLDAYS\"></TD>"+		
                "<TD class=\"ALLDAYS\"><span onclick=\"hideCalendar();\" id='img_2'>cancel</span></TD>"+	"</TR>"+
	"</TABLE>"+

	"</FORM>"+

	"</DIV>");

onafterload(null);
 
 

