//Javascript name: My Date Time Picker
//Date created: 16-Nov-2003 23:19
//Scripter: TengYong Ng
//Website: http://www.rainforestnet.com
//Copyright (c) 2003 TengYong Ng
//FileName: DateTimePicker.js
//Version: 0.8
//Contact: contact@rainforestnet.com
// Note: Permission given to use this script in ANY kind of applications if
//       header lines are left unchanged.

//Global variables
var winCal;
var dtToday=new Date();
var Cal;
var docCal;
var MonthName=["January", "February", "March", "April", "May", "June","July",
	"August", "September", "October", "November", "December"];
var WeekDayName=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var exDateTime;//Existing Date and Time

//Configurable parameters
var cnTop="200";//top coordinate of calendar window.
var cnLeft="500";//left coordinate of calendar window
var WindowTitle ="DateTime Picker";//Date Time Picker title.
var WeekChar=2;//number of character for week day. if 2 then Mo,Tu,We. if 3 then Mon,Tue,Wed.
var CellWidth=20;//Width of day cell.
var DateSeparator="/";//Date Separator, you can change it to "/" if you want.
var TimeMode=24;//default TimeMode value. 12 or 24

var ShowLongMonth=true;//Show long month name in Calendar header. example: "January".
var ShowMonthYear=true;//Show Month and Year in Calendar header.
var MonthYearColor="#cc0033";//Font Color of Month and Year in Calendar header.
var WeekHeadColor="#0099CC";//Background Color in Week header.
var SundayColor="#6699FF";//Background color of Sunday.
var SaturdayColor="#CCCCFF";//Background color of Saturday.
var WeekDayColor="white";//Background color of weekdays.
var FontColor="blue";//color of font in Calendar day cell.
var TodayColor="#FFFF33";//Background color of today.
var SelDateColor="#FFFF99";//Backgrond color of selected date in textbox.
var HolDateColor="#99FF99";//Backgrond color of selected date in textbox.
var YrSelColor="#cc0033";//color of font of Year selector.
var ThemeBg="";//Background image of Calendar window.
//end Configurable parameters
//end Global variable

function IsHoliday( iMonth, iDay) {
	if ((iMonth == 0) & (iDay == 1) ) { return true; };
	if( (iMonth==2) & ( (iDay==21) || (iDay==25) || (iDay==28) ) )	{ return true; };
	if( (iMonth==3) & ((iDay==27) || (iDay==12) || (iDay==27)) )	{ return true; };
	if( (iMonth==4) & ((iDay==1) ||(iDay==2)) )	{ return true; };
	if( (iMonth==5) & (iDay==16)  )	{ return true; };
	if( (iMonth==7) & (iDay==9)  )	{ return true; };
	if( (iMonth==8) & (iDay==24)  )	{ return true; };
	if( (iMonth==11) & ((iDay==16) || (iDay==25) || (iDay==26)) )	{ return true; };
}


function NewCal(pCtrl,pFormat,pShowTime,pTimeMode)
{
	Cal=new Calendar(dtToday);
	if ((pShowTime!=null) && (pShowTime))
	{
		Cal.ShowTime=true;
		if ((pTimeMode!=null) &&((pTimeMode=='12')||(pTimeMode=='24')))
		{
			TimeMode=pTimeMode;
		}
	}
	if (pCtrl!=null)
		Cal.Ctrl=pCtrl;
	if (pFormat!=null)
		Cal.Format=pFormat.toUpperCase();

	exDateTime=document.getElementById(pCtrl).value;
	if (exDateTime!="")//Parse Date String
	{
		var Sp1;//Index of Date Separator 1
		var Sp2;//Index of Date Separator 2
		var tSp1;//Index of Time Separator 1
		var tSp1;//Index of Time Separator 2
		var strMonth;
		var strDate;
		var strYear;
		var intMonth;
		var YearPattern;
		var strHour;
		var strMinute;
		var strSecond;
		//parse month
		Sp1=exDateTime.indexOf(DateSeparator,0)
		Sp2=exDateTime.indexOf(DateSeparator,(parseInt(Sp1)+1));

		if ((Cal.Format.toUpperCase()=="DDMMYYYY") || (Cal.Format.toUpperCase()=="DDMMMYYYY"))
		{
			strMonth=exDateTime.substring(Sp1+1,Sp2);
			strDate=exDateTime.substring(0,Sp1);
		}
		else if ((Cal.Format.toUpperCase()=="MMDDYYYY") || (Cal.Format.toUpperCase()=="MMMDDYYYY"))
		{
			strMonth=exDateTime.substring(0,Sp1);
			strDate=exDateTime.substring(Sp1+1,Sp2);
		}
		if (isNaN(strMonth))
			intMonth=Cal.GetMonthIndex(strMonth);
		else
			intMonth=parseInt(strMonth,10)-1;
		if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12))
			Cal.Month=intMonth;
		//end parse month
		//parse Date
		if ((parseInt(strDate,10)<=Cal.GetMonDays()) && (parseInt(strDate,10)>=1))
			Cal.Date=strDate;
		//end parse Date
		//parse year
		strYear=exDateTime.substring(Sp2+1,Sp2+5);
		YearPattern=/^\d{4}$/;
		if (YearPattern.test(strYear))
			Cal.Year=parseInt(strYear,10);
		//end parse year
		//parse time
		if (Cal.ShowTime==true)
		{
			tSp1=exDateTime.indexOf(":",0)
			tSp2=exDateTime.indexOf(":",(parseInt(tSp1)+1));
			strHour=exDateTime.substring(tSp1,(tSp1)-2);
			Cal.SetHour(strHour);
			strMinute=exDateTime.substring(tSp1+1,tSp2);
			Cal.SetMinute(strMinute);
			strSecond=exDateTime.substring(tSp2+1,tSp2+3);
			Cal.SetSecond(strSecond);
		}
	}
	winCal=window.open("","DateTimePicker","toolbar=0,status=0,menubar=0,fullscreen=no,width=195,height=245,resizable=0,top="+cnTop+",left="+cnLeft);
	docCal=winCal.document;
	RenderCal();
}

function RenderCal()
{
	var vCalHeader;
	var vCalData;
	var vCalTime;
	var i;
	var j;
	var SelectStr;
	var vDayCount=0;
	var vFirstDay;

	docCal.open();
	docCal.writeln("<html><head><title>"+WindowTitle+"</title>");
	docCal.writeln("<script>var winMain=window.opener;</script>");
	docCal.writeln("</head><body background='"+ThemeBg+"' link="+FontColor+" vlink="+FontColor+"><form name='Calendar'>");

	vCalHeader="<table border=1 cellpadding=1 cellspacing=1 width='100%' align=\"center\" valign=\"top\">\n";
	//Month Selector
	vCalHeader+="<tr>\n<td colspan='7'><table border=0 width='100%' cellpadding=0 cellspacing=0><tr><td align='left'>\n";
	vCalHeader+="<select name=\"MonthSelector\" onChange=\"javascript:winMain.Cal.SwitchMth(this.selectedIndex);winMain.RenderCal();\">\n";
	for (i=0;i<12;i++)
	{
		if (i==Cal.Month)
			SelectStr="Selected";
		else
			SelectStr="";
		vCalHeader+="<option "+SelectStr+" value >"+MonthName[i]+"\n";
	}
	vCalHeader+="</select></td>";
	//Year selector
	//Old code
	//vCalHeader+="\n<td align='right'><a href=\"javascript:winMain.Cal.DecYear();winMain.RenderCal()\"><b><font color=\""+YrSelColor+"\"><</font></b></a><font face=\"Verdana\" color=\""+YrSelColor+"\" size=2><b> "+Cal.Year+" </b></font><a href=\"javascript:winMain.Cal.IncYear();winMain.RenderCal()\"><b><font color=\""+YrSelColor+"\">></font></b></a></td></tr></table></td>\n";

	//New code
	//vCalHeader+="\n<td align='right'><font face=\"Verdana\" color=\""+YrSelColor+"\" size=2><b> "+Cal.Year+" </b></font></td></tr></table></td>\n";
	vCalHeader+="\n<td align='right'><select name=\"YearSelector\" onChange=\"javascript:winMain.Cal.SetYear(this.selectedIndex + 1940);winMain.RenderCal();\">\n";
	for (i=1940;i<=dtToday.getFullYear()+5;i++)
	{
		if (i==Cal.Year)
			SelectStr="Selected";
		else
			SelectStr="";

		vCalHeader+="<option " + SelectStr +  " value='" + i + "' >"+i+"\n";

	}
	//vCalHeader+="<option  value='" + Cal.Year + "' >"+Cal.Year+"\n";
	vCalHeader+="</select></td></tr></table></td>\n";

	//End New code
	vCalHeader+="</tr>";
	//Calendar header shows Month and Year
	if (ShowMonthYear)
		vCalHeader+="<tr><td colspan='7'><font face='Verdana' size='2' align='center' color='"+MonthYearColor+"'><b>"+Cal.GetMonthName(ShowLongMonth)+" "+Cal.Year+"</b></font></td></tr>\n";
	//Week day header
	vCalHeader+="<tr bgcolor="+WeekHeadColor+">";
	for (i=0;i<7;i++)
	{
		vCalHeader+="<td align='center'><font face='Verdana' size='2'>"+WeekDayName[i].substr(0,WeekChar)+"</font></td>";
	}
	vCalHeader+="</tr>";
	docCal.write(vCalHeader);

	//Calendar detail
	CalDate=new Date(Cal.Year,Cal.Month);
	CalDate.setDate(1);
	vFirstDay=CalDate.getDay();
	vCalData="<tr>";
	for (i=0;i<vFirstDay;i++)
	{
		vCalData=vCalData+GenCell();
		vDayCount=vDayCount+1;
	}
	for (j=1;j<=Cal.GetMonDays();j++)
	{
		var strCell;
		vDayCount=vDayCount+1;
		if ((j==dtToday.getDate())&&(Cal.Month==dtToday.getMonth())&&(Cal.Year==dtToday.getFullYear()))
			strCell=GenCell(j,true,TodayColor);//Highlight today's date
		else
		{
			if (j==Cal.Date)
			{
				strCell=GenCell(j,true,SelDateColor);
			}
			else
			{
				if (IsHoliday(Cal.Month, j)) {
					strCell=GenCell(j,null,HolDateColor);
				} else {

					if (vDayCount%7==0)
						strCell=GenCell(j,false,SaturdayColor);
					else if ((vDayCount+6)%7==0)
						strCell=GenCell(j,false,SundayColor);
					else
						strCell=GenCell(j,null,WeekDayColor);
				}

			}
		}
		vCalData=vCalData+strCell;

		if((vDayCount%7==0)&&(j<Cal.GetMonDays()))
		{
			vCalData=vCalData+"</tr>\n<tr>";
		}
	}
	docCal.writeln(vCalData);
	//Time picker
	if (Cal.ShowTime)
	{
		var showHour;
		showHour=Cal.getShowHour();
		vCalTime="<tr>\n<td colspan='7' align='center'>";
		vCalTime+="<input type='text' name='hour' maxlength=2 size=1 style=\"WIDTH: 22px\" value="+showHour+" onchange=\"javascript:winMain.Cal.SetHour(this.value)\">";
		vCalTime+=" : ";
		vCalTime+="<input type='text' name='minute' maxlength=2 size=1 style=\"WIDTH: 22px\" value="+Cal.Minutes+" onchange=\"javascript:winMain.Cal.SetMinute(this.value)\">";
		vCalTime+=" : ";
		vCalTime+="<input type='text' name='second' maxlength=2 size=1 style=\"WIDTH: 22px\" value="+Cal.Seconds+" onchange=\"javascript:winMain.Cal.SetSecond(this.value)\">";
		if (TimeMode==12)
		{
			var SelectAm =(parseInt(Cal.Hours,10)<12)? "Selected":"";
			var SelectPm =(parseInt(Cal.Hours,10)>=12)? "Selected":"";

			vCalTime+="<select name=\"ampm\" onchange=\"javascript:winMain.Cal.SetAmPm(this.options[this.selectedIndex].value);\">";
			vCalTime+="<option "+SelectAm+" value=\"AM\">AM</option>";
			vCalTime+="<option "+SelectPm+" value=\"PM\">PM<option>";
			vCalTime+="</select>";
		}
		vCalTime+="\n</td>\n</tr>";
		docCal.write(vCalTime);
	}
	//end time picker
	docCal.writeln("\n</table>");
	docCal.writeln("</form></body></html>");
	docCal.close();
}

function GenCell(pValue,pHighLight,pColor)//Generate table cell with value
{
	var PValue;
	var PCellStr;
	var vColor;
	var vHLstr1;//HighLight string
	var vHlstr2;
	var vTimeStr;

	if (pValue==null)
		PValue="";
	else
		PValue=pValue;

	if (pColor!=null)
		vColor="bgcolor=\""+pColor+"\"";
	else
		vColor="";
	if ((pHighLight!=null)&&(pHighLight))
		{vHLstr1="color='red'><b>";vHLstr2="</b>";}
	else
		{vHLstr1=">";vHLstr2="";}

	if (Cal.ShowTime)
	{
		vTimeStr="winMain.document.getElementById('"+Cal.Ctrl+"').value+=' '+"+"winMain.Cal.getShowHour()"+"+':'+"+"winMain.Cal.Minutes"+"+':'+"+"winMain.Cal.Seconds";
		if (TimeMode==12)
			vTimeStr+="+' '+winMain.Cal.AMorPM";
	}
	else
		vTimeStr="";
	PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='2'"+vHLstr1+"<a href=\"javascript:winMain.document.getElementById('"+Cal.Ctrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr+";window.close();\">"+PValue+"</a>"+vHLstr2+"</font></td>";
	return PCellStr;
}

function Calendar(pDate,pCtrl)
{
	//Properties
	this.Date=pDate.getDate();//selected date
	this.Month=pDate.getMonth();//selected month number
	this.Year=pDate.getFullYear();//selected year in 4 digits
	this.Hours=pDate.getHours();

	if (pDate.getMinutes()<10)
		this.Minutes="0"+pDate.getMinutes();
	else
		this.Minutes=pDate.getMinutes();

	if (pDate.getSeconds()<10)
		this.Seconds="0"+pDate.getSeconds();
	else
		this.Seconds=pDate.getSeconds();

	this.MyWindow=winCal;
	this.Ctrl=pCtrl;
	this.Format="ddMMyyyy";
	this.Separator=DateSeparator;
	this.ShowTime=false;
	if (pDate.getHours()<12)
		this.AMorPM="AM";
	else
		this.AMorPM="PM";
}

function GetMonthIndex(shortMonthName)
{
	for (i=0;i<12;i++)
	{
		if (MonthName[i].substring(0,3).toUpperCase()==shortMonthName.toUpperCase())
		{	return i;}
	}
}
Calendar.prototype.GetMonthIndex=GetMonthIndex;

function IncYear()
{	Cal.Year++;}
Calendar.prototype.IncYear=IncYear;

function DecYear()
{	Cal.Year--;}
Calendar.prototype.DecYear=DecYear;

function SetYear(intYr)
{	Cal.Year = intYr;}
Calendar.prototype.SetYear=SetYear;


function SwitchMth(intMth)
{	Cal.Month=intMth;}
Calendar.prototype.SwitchMth=SwitchMth;

function SetHour(intHour)
{
	var MaxHour;
	var MinHour;
	if (TimeMode==24)
	{	MaxHour=23;MinHour=0}
	else if (TimeMode==12)
	{	MaxHour=12;MinHour=1}
	else
		alert("TimeMode can only be 12 or 24");
	var HourExp=new RegExp("^\\d\\d$");
	if (HourExp.test(intHour) && (parseInt(intHour,10)<=MaxHour) && (parseInt(intHour,10)>=MinHour))
	{
		if ((TimeMode==12) && (Cal.AMorPM=="PM"))
		{
			if (parseInt(intHour,10)==12)
				Cal.Hours=12;
			else
				Cal.Hours=parseInt(intHour,10)+12;
		}
		else if ((TimeMode==12) && (Cal.AMorPM=="AM"))
		{
			if (intHour==12)
				intHour-=12;
			Cal.Hours=parseInt(intHour,10);
		}
		else if (TimeMode==24)
			Cal.Hours=parseInt(intHour,10);
	}
}
Calendar.prototype.SetHour=SetHour;

function SetMinute(intMin)
{
	var MinExp=new RegExp("^\\d\\d$");
	if (MinExp.test(intMin) && (intMin<60))
		Cal.Minutes=intMin;
}
Calendar.prototype.SetMinute=SetMinute;

function SetSecond(intSec)
{
	var SecExp=new RegExp("^\\d\\d$");
	if (SecExp.test(intSec) && (intSec<60))
		Cal.Seconds=intSec;
}
Calendar.prototype.SetSecond=SetSecond;

function SetAmPm(pvalue)
{
	this.AMorPM=pvalue;
	if (pvalue=="PM")
	{
		this.Hours=(parseInt(this.Hours,10))+12;
		if (this.Hours==24)
			this.Hours=12;
	}
	else if (pvalue=="AM")
		this.Hours-=12;
}
Calendar.prototype.SetAmPm=SetAmPm;

function getShowHour()
{
	var finalHour;
    if (TimeMode==12)
    {
    	if (parseInt(this.Hours,10)==0)
		{
			this.AMorPM="AM";
			finalHour=parseInt(this.Hours,10)+12;
		}
		else if (parseInt(this.Hours,10)==12)
		{
			this.AMorPM="PM";
			finalHour=12;
		}
		else if (this.Hours>12)
		{
			this.AMorPM="PM";
			if ((this.Hours-12)<10)
				finalHour="0"+((parseInt(this.Hours,10))-12);
			else
				finalHour=parseInt(this.Hours,10)-12;
		}
		else
		{
			this.AMorPM="AM";
			if (this.Hours<10)
				finalHour="0"+parseInt(this.Hours,10);
			else
				finalHour=this.Hours;
		}
	}
	else if (TimeMode==24)
	{
		if (this.Hours<10)
			finalHour="0"+parseInt(this.Hours,10);
		else
			finalHour=this.Hours;
	}
	return finalHour;
}
Calendar.prototype.getShowHour=getShowHour;

function GetMonthName(IsLong)
{
	var Month=MonthName[this.Month];
	if (IsLong)
		return Month;
	else
		return Month.substr(0,3);
}
Calendar.prototype.GetMonthName=GetMonthName;

function GetMonDays()//Get number of days in a month
{
	var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (this.IsLeapYear())
	{
		DaysInMonth[1]=29;
	}
	return DaysInMonth[this.Month];
}
Calendar.prototype.GetMonDays=GetMonDays;

function IsLeapYear()
{
	if ((this.Year%4)==0)
	{
		if ((this.Year%100==0) && (this.Year%400)!=0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
Calendar.prototype.IsLeapYear=IsLeapYear;

function FormatDate(pDate)
{
	var lsDay;
	var lsMth;

	lsDay = pDate;
	lsMth = this.Month+1;

	if (lsDay < 10) {lsDay = '0' + lsDay;}
	if (lsMth < 10) {lsMth = '0' + lsMth;}


	if (this.Format.toUpperCase()=="DDMMYYYY")
		return (lsDay+DateSeparator+lsMth+DateSeparator+this.Year);
	else if (this.Format.toUpperCase()=="DDMMMYYYY")
		return (pDate+DateSeparator+this.GetMonthName(false)+DateSeparator+this.Year);
	else if (this.Format.toUpperCase()=="MMDDYYYY")
		return ((this.Month+1)+DateSeparator+pDate+DateSeparator+this.Year);
	else if (this.Format.toUpperCase()=="MMMDDYYYY")
		return (this.GetMonthName(false)+DateSeparator+pDate+DateSeparator+this.Year);


//	if (this.Format.toUpperCase()=="DDMMYYYY")
//		return (pDate+DateSeparator+(this.Month+1)+DateSeparator+this.Year);
//	else if (this.Format.toUpperCase()=="DDMMMYYYY")
//		return (pDate+DateSeparator+this.GetMonthName(false)+DateSeparator+this.Year);
//	else if (this.Format.toUpperCase()=="MMDDYYYY")
//		return ((this.Month+1)+DateSeparator+pDate+DateSeparator+this.Year);
//	else if (this.Format.toUpperCase()=="MMMDDYYYY")
//		return (this.GetMonthName(false)+DateSeparator+pDate+DateSeparator+this.Year);
}
Calendar.prototype.FormatDate=FormatDate;



//End of datetimepicker

/*
=====================================================================================================================

//*/


function nextIndexOf(str,sub, num) {
var total;
var pos;
var llLoop;
lsStr = "";
	pos = 0;
	lsStr = str;
	total = 0;
	for (llLoop=0;llLoop<=num;llLoop++) {
//		alert (llLoop + " " + lsStr );
		total +=  pos = lsStr.indexOf(sub);
//		total++;
		lsStr = lsStr.substr(pos + 1, lsStr.length - pos);
	}
	return total + llLoop - 1;
}



function setMnthly() {
var perYear;

	calcNon();
	calcPAYE();
//	alert( "emp|emp: 3: " + nextIndexOf("emp|emp","|",0) );
//	alert( "12|1001|: 2: " + nextIndexOf("12|1001|","|",0) );
//	alert( "12|1001|: 7: " + nextIndexOf("12|1001|","|",1) );

//	alert( "12|1001|00|: 10: " + nextIndexOf("12|1001|00|","|",2) );

//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;
	if (document.getElementById('iP13').value == '') {
//		document.getElementById('iPMnthCTC').value = Math.round((document.getElementById('iPAnnCTC').value / perYear)) / 100;

		document.getElementById('iPMnthCTC').value = (document.getElementById('iPAnnCTC').value / perYear) / 100;
	} else {
//		document.getElementById('iPMnthCTC').value = Math.round(( (document.getElementById('iPAnnCTC').value -document.getElementById('iP13').value) / perYear)) / 100;

		document.getElementById('iPMnthCTC').value = ( (document.getElementById('iPAnnCTC').value -document.getElementById('iP13').value) / perYear) / 100;
	}
/*
	document.getElementById('iPMnthTravel').value = Math.round((document.getElementById('iPAnnTravel').value / perYear)) / 100;
	document.getElementById('iPMnthPC').value = Math.round((document.getElementById('iPAnnPC').value / perYear)) / 100;
	document.getElementById('iPMnthCell').value = Math.round((document.getElementById('iPAnnCell').value / perYear)) / 100;

	document.getElementById('iPMnthOther').value = Math.round((document.getElementById('iPAnnOther').value / perYear)) / 100;
	document.getElementById('iPMnthMed').value = Math.round((document.getElementById('iPAnnMed').value / perYear)) / 100;
//	document.getElementById('iPMnthSave').value = Math.round((document.getElementById('iPAnnSave').value / perYear)) / 100;
	document.getElementById('iPMnthFund').value = Math.round((document.getElementById('iPAnnFund').value / perYear)) / 100;

	document.getElementById('iPMnthOwnFund').value = Math.round((document.getElementById('iPAnnOwnFund').value / perYear)) / 100;
	document.getElementById('iPMnthEmpMed').value = Math.round((document.getElementById('iPAnnEmpMed').value / perYear)) / 100;
	document.getElementById('iPMnthOwnMed').value = Math.round((document.getElementById('iPAnnOwnMed').value / perYear)) / 100;

//	document.getElementById('iPMnthNett').value = Math.round((document.getElementById('iPAnnNett').value / perYear)) / 100;
//*/

	document.getElementById('iPMnthTravel').value = ((document.getElementById('iPAnnTravel').value / perYear)) / 100;
	document.getElementById('iPMnthTvl').value = ((document.getElementById('iPAnnTvl').value / perYear)) / 100;
	document.getElementById('iPMnthCash').value = ((document.getElementById('iPAnnCash').value / perYear)) / 100;
	document.getElementById('iPMnthPC').value = ((document.getElementById('iPAnnPC').value / perYear)) / 100;
	document.getElementById('iPMnthCell').value = ((document.getElementById('iPAnnCell').value / perYear)) / 100;
	document.getElementById('iPMnthOther').value = ((document.getElementById('iPAnnOther').value / perYear)) / 100;
	document.getElementById('iPMnthMed').value = ((document.getElementById('iPAnnMed').value / perYear)) / 100;
//	document.getElementById('iPMnthSave').value = ((document.getElementById('iPAnnSave').value / perYear)) / 100;
	document.getElementById('iPMnthFund').value = ((document.getElementById('iPAnnFund').value / perYear)) / 100;

	document.getElementById('iPMnthOwnFund').value = ((document.getElementById('iPAnnOwnFund').value / perYear)) / 100;
	document.getElementById('iPMnthEmpMed').value = ((document.getElementById('iPAnnEmpMed').value / perYear)) / 100;
	document.getElementById('iPMnthOwnMed').value = ((document.getElementById('iPAnnOwnMed').value / perYear)) / 100;

//	document.getElementById('iPMnthNett').value = ((document.getElementById('iPAnnNett').value / perYear)) / 100;




}

function setAnnual() {
var perYear;

//	if (document.getElementById('perYear').checked) {perYear = 13} else {perYear = 12};
	perYear = 12;


	calcNon();
	calcPAYE();


	document.getElementById('iPAnnCTC').value = (document.getElementById('iPMnthCTC').value ) * perYear;
/*	document.getElementById('iPAnnTravel').value = Math.round((document.getElementById('iPMnthTravel').value )) * perYear;
	document.getElementById('iPAnnPC').value = Math.round((document.getElementById('iPMnthPC').value )) * perYear;
	document.getElementById('iPAnnCell').value = Math.round((document.getElementById('iPMnthCell').value )) * perYear;
	document.getElementById('iPAnnMed').value = Math.round((document.getElementById('iPMnthMed').value )) * perYear;
//	document.getElementById('iPAnnSave').value = Math.round((document.getElementById('iPMnthSave').value )) * perYear;
	document.getElementById('iPAnnFund').value = Math.round((document.getElementById('iPMnthFund').value )) * perYear;
	document.getElementById('iPAnnEmpMed').value = Math.round((document.getElementById('iPMnthEmpMed').value )) * perYear;
	document.getElementById('iPAnnOwnMed').value = Math.round((document.getElementById('iPMnthOwnMed').value )) * perYear;

//*/
	document.getElementById('iPAnnTravel').value = ((document.getElementById('iPMnthTravel').value )) * perYear;
	document.getElementById('iPAnnPC').value = ((document.getElementById('iPMnthPC').value )) * perYear;
	document.getElementById('iPAnnCell').value = ((document.getElementById('iPMnthCell').value )) * perYear;

	document.getElementById('iPAnnOther').value = ((document.getElementById('iPMnthOther').value * perYear)) ;


	document.getElementById('iPAnnOther').value = ((document.getElementById('iPMnthOther').value )) * perYear;
	document.getElementById('iPAnnMed').value = ((document.getElementById('iPMnthMed').value )) * perYear;
//document.getElementById('iPAnnSave').value = ((document.getElementById('iPMnthSave').value )) * perYear;
//	document.getElementById('iPAnnFund').value = ((document.getElementById('iPMnthFund').value )) * perYear;
	document.getElementById('iPAnnEmpMed').value = ((document.getElementById('iPMnthEmpMed').value )) * perYear;
	document.getElementById('iPAnnOwnMed').value = ((document.getElementById('iPMnthOwnMed').value )) * perYear;

	calcNon();
//*/


}
function calcNon() {
var perYear;

//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;

	document.getElementById('iPAnnNon').value = (1 * document.getElementById('iPAnnTravel').value) +
									(1 * document.getElementById('iPAnnPC').value) +
									(1 * document.getElementById('iPAnnCell').value) +
									(1 * document.getElementById('iPAnnMed').value) +
									(1 * document.getElementById('iPAnnOther').value);// +
//									(1 * document.getElementById('iPAnnSave').value);
	document.getElementById('iPMnthNon').value = Math.round( (document.getElementById('iPAnnNon').value / perYear) ) / 100;
	calcPen();
}

function calcPen() {
var perYear;
//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;

	if ( document.getElementById('iPAnnCTC').value < 106032 ) {
		document.getElementById('iPAnnUIF').value = document.getElementById('iPAnnCTC').value * 0.01;
	} else {
		document.getElementById('iPAnnUIF').value = 106032 * 0.01;
	};
	document.getElementById('iPMnthUIF').value = document.getElementById('iPAnnUIF').value /12;


//								document.getElementById('iPAnnFund').value -
//								document.getElementById('iPAnnEmpMed').value -
//								document.getElementById('iPAnnNon').value ;


	str = document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text;
	document.getElementById('iPAnn').value = document.getElementById('iPAnnCTC').value -
								document.getElementById('iPAnnEmpMed').value -
								document.getElementById('iPAnnNon').value ;


	document.getElementById('iPMnth').value = Math.round( (document.getElementById('iPAnn').value / perYear) ) / 100;
	calcTaxable();
}

function calcPAYE() {
var perYear;
//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;
//	document.getElementById('iPPAYE').value = document.getElementById('iPMnth').value;

}

function calcTaxable() {
var perYear;
//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;
	/*document.getElementById('iPTaxable').value = (document.getElementById('iPMnthCTC').value * 1)-
									(document.getElementById('iPMnthTravel').value * 0.5) -
									(document.getElementById('iPMnthEmpMed').value * 1) -
									(document.getElementById('iPMnthFund').value * 1);
//*/
	//alert(document.getElementById('iPMnthOwnFund').value);

	document.getElementById('iPTaxable').value = (document.getElementById('iPMnthCash').value * 1) +
									(document.getElementById('iPMnthTravel').value * 0.5) -
									(document.getElementById('iPMnthOwnFund').value * 1);
//Loading allowances
document.getElementById('iPTaxable').value = (document.getElementById('iPTaxable').value * 1)+
								(document.getElementById('iPMnthPC').value * 1) +
								(document.getElementById('iPMnthCell').value * 1) +
								(document.getElementById('iPMnthMed').value * 1) +
								(document.getElementById('iPMnthOther').value * 1);

}


function calcFunds() {
var perYear;
var Emp;
var Empee;
var pos;
var nextPos;
var Prov;
var str = "";
var rfi;
var thirteen;

var str;
	str = document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].value;
	pos = str.indexOf("|");
	nextPos = nextIndexOf(str, "|", 1);
	Emp = str.substr(pos + 1, nextPos - pos - 1);

//	if (Emp != str.substr(pos + 1, str.length)) { alert("Problems: " + Emp + " | "  + str.substr(pos + 1, str.length) ); };
	Empee = str.substr(0,pos);

//	Emp = str.substr(pos + 1, str.length);
	Prov = str.substr(nextPos + 1, str.length);





//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;

	str = document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text;
	if ( str.substring(0,4) != 'MEGA') {
		document.getElementById('iPAnn').value = document.getElementById('iPAnnCash').value
		document.getElementById('iPMnth').value = document.getElementById('iPMnthCash').value
	}

	document.getElementById('iPAnnFund').value = Emp * document.getElementById('iPAnn').value / 100;
	document.getElementById('iPAnnOwnFund').value = Empee * document.getElementById('iPAnn').value / 100;

//	document.getElementById('iPAnnFund').value = document.getElementById('iPAnn').value / (1 + (Emp / 100)) ;
//	document.getElementById('iPAnnOwnFund').value = document.getElementById('iPAnn').value / (1 + (Empee / 100));
	setMnthly();
//	alert( "Emp: " + Emp);
//	alert( "Empee: " + Empee);

	document.getElementById('empFperc').value = Emp;
	document.getElementById('empeeFperc').value = Empee;

								document.getElementById('iPAnnEmpMed').value;



	document.getElementById('iPAnnCash').value = document.getElementById('iPAnn').value / (1 + (Emp / 100)) ;



	document.getElementById('iPMnthCash').value = document.getElementById('iPMnth').value -
									document.getElementById('iPMnthFund').value -
									document.getElementById('iPMnthEmpMed').value;

	document.getElementById('iPMnthCash').value = ((document.getElementById('iPAnnCash').value / perYear)) / 100;


	document.getElementById('empFPerc').readonly = true;
	document.getElementById('empeeFPerc').readonly = true;
	iElSVisible( iElGet('iPePerc'), 0);
	iElSVisible( iElGet('iPeePerc'), 0);

	//if (document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text == 'MEGA') {
	str = document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text;
	if ( str.substring(0,4) == 'MEGA') {
		document.getElementById('iP13').value = 0;
		iElSVisible( document.getElementById('iPGuarantee'), 0);
		iElSVisible( document.getElementById('iPR13calc'), 1);
		//document.getElementById('iPAnnFund').value =  document.getElementById('iPAnnCash').value * (Emp / 100) / 13 * 12;
		//document.getElementById('iPMnthFund').value =  document.getElementById('iPMnthCash').value * (Emp / 100) * 12 / 13;

		rfi = document.getElementById('iPAnn').value / 13;
		thirteen = rfi  / ( 1 + (Emp / 100) );
		document.getElementById('iPMnthCash').value = thirteen;
		document.getElementById('iP13calc').value = thirteen;
		thirteen =
		Prov = thirteen + (thirteen / 12);
//		document.getElementById('iPMnth').value = Prov * (Emp / 100);
//		document.getElementById('iPAnn').value = Prov * (Emp / 100) * 12;
		document.getElementById('iPMnthFund').value = Prov * (Emp / 100);
		document.getElementById('iPAnnFund').value = Prov * (Emp / 100) * 12;


	} else {
//		document.getElementById('iPAnn').value = document.getElementById('iPAnnCash').value
//		document.getElementById('iPMnth').value = document.getElementById('iPMnthCash').value


		iElSVisible( document.getElementById('iPGuarantee'), 1);
		iElSVisible( document.getElementById('iPR13calc'), 0);

		if (document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text == 'Umbrella Plus Provident') {
			alert('Your Employer Contribution can vary from 5% to 20%');
			document.getElementById('empFPerc').readonly = false;

			iElSVisible( iElGet('iPePerc'), 1);
		}

		str = document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text;
		if (str.substring(0,11) == 'New Holland') {
		//if (document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text == 'New Holland') {
			alert('Your Employee Contribution can vary from 5% to 7.5%');
			document.getElementById('empeeFPerc').readonly = false;

			//iElSVisible( iElGet('iPeePerc'), 1);
		}


		if (document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text == 'Aster Marinus Group Provident Fund') {
			alert('Your Employee Contribution can vary from 2.5% to 12.5%');
			document.getElementById('empeeFPerc').readonly = false;
			iElSVisible( iElGet('iPeePerc'), 1);
		}

		document.getElementById('iPAnnFund').value =  document.getElementById('iPAnnCash').value * (Emp / 100);
		document.getElementById('iPMnthFund').value =  document.getElementById('iPMnthCash').value * (Emp / 100);
	}

}

function calcNett(tax) {
var perYear;
//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 0.12;

/*	document.getElementById('iPNett').value = document.getElementById('iPAnnCTC').value -
//									document.getElementById('iPAnnFund').value -
									document.getElementById('iPAnnMed').value -
									document.getElementById('iPAnnOwnFund').value -
									document.getElementById('iPAnnOwnMed').value;
//*/


document.getElementById('iPNett').value = (document.getElementById('iPAnnCTC').value * 1) -
									(document.getElementById('iPAnnFund').value * 1)  -
									(document.getElementById('iPAnnEmpMed').value * 1) -
									(document.getElementById('iPAnnOwnFund').value * 1 )-
									(document.getElementById('iPAnnOwnMed').value * 1) -
									(document.getElementById('iPAnnUIF').value * 1) -
									(tax * 1);
/*alert( document.getElementById('iPNett').value + "|" + (document.getElementById('iPAnnCTC').value * 1) + "|" +
									(document.getElementById('iPAnnFund').value * 1)  + "|" +
									(document.getElementById('iPAnnMed').value * 1) + "|" +
									(document.getElementById('iPAnnOwnFund').value * 1 ) + "|" +
									(document.getElementById('iPAnnOwnMed').value * 1) + "|" +
									(document.getElementById('iPAnnUIF').value * 1) + "|" +
									(tax * 1) );
//*/
//document.getElementById('iPNett').value = document.getElementById('iPNett').value
//alert (document.getElementById('iPNett').value );
//	document.getElementById('iPMnthNett').value = Math.round((document.getElementById('iPNett').value / perYear)) / 100;


	str = document.getElementById('iPFund').options[document.getElementById('iPFund').selectedIndex].text;
	if ( str.substring(0,4) != 'MEGA') {
		document.getElementById('iPMnthNett').value = ((document.getElementById('iPNett').value / perYear)) / 100;
	} else {
		document.getElementById('iPMnthNett').value = ((((document.getElementById('iPNett').value * 1) - (document.getElementById('iP13calc').value * 1)) / perYear)) / 100;
	}


}


function calcTax() {
var llLoop;
var tax;
var base;
var taxable;
var perc;
var pos;
var str = "";
var perYear;
var lastTaxable;
//	if (document.getElementById('perYear').checked) {perYear = 0.13} else {perYear = 0.12};
	perYear = 12;

	llLoop = 1;
	taxable = 0;
//	alert ( llLoop + "|" + document.getElementById('iPTaxRecs').value + "   " + document.getElementById('iPTaxable').value +"|" + taxable );

	base = 0;
	while ( ((llLoop*1) <= (document.getElementById('iPTaxRecs').value)*1) && (((document.getElementById('iPTaxable').value)*1) * (perYear*1) > (taxable*1)) ) {
//	alert ( llLoop + "|" + document.getElementById('iPTaxRecs').value + "   " + (document.getElementById('iPTaxable').value * perYear) +"|" + taxable );

		str = document.getElementById('iPBase').value;
		pos = nextIndexOf(str, "|", llLoop - 1);
		base = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1);

		str = document.getElementById('iPTax').value;
		pos = nextIndexOf(str, "|", llLoop - 1);
		lastTaxable = taxable;
		taxable = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1 );

		str = document.getElementById('iPPerc').value;
		pos = nextIndexOf(str, "|", llLoop - 1);
		perc = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1 );
//		alert( taxable );
		llLoop++;
	}

//	tax = document.getElementById('iPTaxable').value - base - (perc * (document.getElementById('iPTaxable').value - base) / 100);

	document.getElementById('iPAnnTaxable').value = document.getElementById('iPTaxable').value * perYear ;
	tax = (base * 1) + (perc * ((document.getElementById('iPAnnTaxable').value * 1) - (lastTaxable * 1) ) / 100);
	tax = tax - 6300;
  	//alert ("Tax: " + tax);
	alert (taxable + " " + base + " " + perc + " tax: " + tax + "|" + document.getElementById('iPAnnTaxable').value);

	calcNett(tax );
}

function calcAll() {
	iElSVisible( iElGet( 'iPCalcs'), 1);
	iElSVisible( iElGet( 'iPVals'), 1);
	calcNon();
	calcPen();
	calcFunds();
	calcTax();
//	alert("New Code");
	calcNon();
	calcPen();
	calcFunds();
	calcTax();
	calcNon();
	calcPen();
	calcFunds();
	calcTax();

}


function calcVehicle() {
var llLoop;
var value;
var fixed;
var fuel;
var maint;
var pos;
var str = "";
var perYear;
var travel;
var fixedkm;
var bizkm;
	perYear = 0.12;

	llLoop = 1;
	value = 0;


	while ( ((llLoop*1) < (document.getElementById('iPVehicleRecs').value*1)) && (((document.getElementById('iPval').value*1)) > (value*1)) ) {

		str = document.getElementById('iPValue').value;

		pos = nextIndexOf(str, "|", llLoop - 1);

		value = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1);
//		alert( value );
		str = document.getElementById('iPFixed').value;
		pos = nextIndexOf(str, "|", llLoop - 1);
		fixed = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1 );

		str = document.getElementById('iPFuel').value;
		pos = nextIndexOf(str, "|", llLoop - 1);
		fuel = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1 );

		str = document.getElementById('iPMaint').value;
		pos = nextIndexOf(str, "|", llLoop - 1);
		maint = str.substr(pos + 1, nextIndexOf(str, "|", llLoop ) - pos - 1 );

//		alert( llLoop + " < " + document.getElementById('iPVehicleRecs').value+  "| " + value + " < " + document.getElementById('iPval').value  );

		llLoop++;
	}
//	alert(fuel +"|" + maint + "|" + value);
	if (document.getElementById('iPLog').checked) {
		fixedkm = fixed / document.getElementById('iPkm').value;


		travel = document.getElementById('iPbizkm').value *
				((fixedkm*1) + (fuel*1) + (maint*1));
		document.getElementById('iPAnnTravel').value = travel;
//		alert (fixed + ' '+ fixedkm);
//		alert ((fixedkm*1) + (fuel*1) + (maint*1));
	} else {
		if (document.getElementById('iPkm').value >= 32000) {
			fixedkm = fixed / 32000;
		} else {
			fixedkm = fixed / document.getElementById('iPkm').value;
		};
		if (document.getElementById('iPkm').value >= 32000) {
			bizkm = 16000;
		} else {
			bizkm = document.getElementById('iPkm').value - 16000;
		};
		if (bizkm > 0) {
			travel = bizkm *
				((fixedkm*1) + (fuel*1) + (maint*1));
			document.getElementById('iPAnnTravel').value = travel;
		} else {
			document.getElementById('iPAnnTravel').value = 0;
		}

	}
	document.getElementById('iPAnnTvl').value = document.getElementById('iPAnnTravel').value;



	setMnthly();
//	alert (fixed + " " + fixedkm + " " + fuel + " " + maint);
//	tax = document.getElementById('iPTaxable').value - base - (perc * (document.getElementById('iPTaxable').value - base) / 100);

//	tax = (base * 1) + (perc * (document.getElementById('iPTaxable').value - base) / 100);
//	document.getElementById('iPAnnTaxable').value = document.getElementById('iPTaxable').value * perYear * 100;
//	alert (tax);
//	calcNett(tax);
}


function printPage() {
 var lobjEl ;
	iElSVisible( iElGet('step1'),0);
	iElSVisible( iElGet('step2'),0);
	iElSVisible( iElGet('step3'),0);
	iElSVisible( iElGet('step4'),0);
	iElSVisible( iElGet('step5'),0);
	iElSVisible( iElGet('results'),0);

	iElSVisible( iElGet('iPnxt1'),0);
	iElSVisible( iElGet('iPnxt2'),0);
	iElSVisible( iElGet('iPnxt3'),0);
	iElSVisible( iElGet('iPnxt4'),0);

	iElSVisible( iElGet('btnCalc'),0);
	iElSVisible( iElGet('btnTvl'),0);
	iElSVisible( iElGet('btnPrint'),0);
	iElSVisible( iElGet('Tax_disc'),0);

	iElSVisible( iElGet('signature'),1);


//new
	iElSVisible( iElGet('ipI.O2000.C78'),0);
	iElSVisible( iElGet('ipI.S1'),0);
	iElSVisible( iElGet('ipI.S2'),0);
	iElSVisible( iElGet('ipI.S176'),0);
	iElSVisible( iElGet('ipI.S202'),0);

	window.print();

	iElSVisible( iElGet('step1'),1);
	iElSVisible( iElGet('step2'),1);
	iElSVisible( iElGet('step3'),1);
	iElSVisible( iElGet('step4'),1);
	iElSVisible( iElGet('step5'),1);
	iElSVisible( iElGet('results'),1);
	iElSVisible( iElGet('btnCalc'),1);
	iElSVisible( iElGet('btnTvl'),1);
	iElSVisible( iElGet('btnPrint'),1);
	iElSVisible( iElGet('ipI.O2000.C78'),1);
	iElSVisible( iElGet('ipI.S1'),1);
	iElSVisible( iElGet('ipI.S2'),1);
	iElSVisible( iElGet('ipI.S176'),1);
	iElSVisible( iElGet('ipI.S202'),1);


	iElSVisible( iElGet('Tax_disc'),1);

	iElSVisible( iElGet('signature'),0);


//*/
//'	iElget(  ).style.border = "none";
//	document.getElementByName('Allowances').border = 'none';

}

function setTvl() {
	if (iElGet('iPtvlOver').checked) {
		iElSVisible(iElGet('iPAnnTravel'),1);
		iElSVisible(iElGet('iPMnthTravel'),1);
	} else {
		iElSVisible(iElGet('iPAnnTravel'),0);
		iElSVisible(iElGet('iPMnthTravel'),0);
	}

}

function clearAll() {
	document.getElementById('iPMnthTravel').value = 0;
	document.getElementById('iPMnthTvl').value = 0;
	document.getElementById('iPMnthCash').value = 0;
	document.getElementById('iPMnthPC').value = 0;
	document.getElementById('iPMnthCell').value = 0;
	document.getElementById('iPMnthOther').value = 0;
	document.getElementById('iPMnthMed').value = 0;
//	document.getElementById('iPMnthSave').value = 0;
	document.getElementById('iPMnthFund').value = 0;

	document.getElementById('iPMnthOwnFund').value = 0;
	document.getElementById('iPMnthEmpMed').value = 0;
	document.getElementById('iPMnthOwnMed').value = 0;

	document.getElementById('iPMnthUIF').value = 0;
	document.getElementById('iPMnthNett').value = 0;



	document.getElementById('iPAnnTravel').value = 0;
	document.getElementById('iPAnnPC').value = 0;
	document.getElementById('iPAnnCell').value = 0;
	document.getElementById('iPAnnOther').value = 0;
	document.getElementById('iPAnnOther').value = 0;
	document.getElementById('iPAnnMed').value = 0;
//	document.getElementById('iPAnnSave').value = 0;
	document.getElementById('iPAnnFund').value = 0;
	document.getElementById('iPAnnEmpMed').value = 0;
	document.getElementById('iPAnnOwnMed').value = 0;
	document.getElementById('iPAnnUIF').value = 0;

}



    /* Credit Card Checker - (c)oded '05 shaman, www.nox.org.uk                                                   *
     * Function to check for valid credit card numbers using the LUHN algorithm.                                  *
     * This code is based on the wikicode pseudocode at: http://en.wikipedia.org/wiki/Luhn_algorithm              *
     * You can see a working example of this script here: http://www.nox.org.uk/code/examples/creditcardcheck.php *
     * Do what you want with this code, but please give credit where possible.                                    */

    function validatecc(x) {
      var ccnumber=x.value.replace(/\D/g, '');
      var cclength=ccnumber.length;
      var parity=cclength % 2;
      var sum=0;
      for (i=0; i < cclength; i++) {
        var ccdigit=ccnumber.charAt(i);
        if (i % 2 == parity) ccdigit=ccdigit * 2;
        if (ccdigit > 9) ccdigit=ccdigit - 9;
        sum = sum + parseInt(ccdigit);
      }
      var valid=(sum % 10 == 0);
      if (valid) alert("Valid"); else alert("Not Valid");
    }


    function checkLUHN(elID) {
    	if (validatecc(document.getElementById(elID).value) ) {
    		return true;
    	} else {
		alert( "Card is not a valid number!");
    		return false;
    	}


    }


function iIsDtBefore( psEl1, psEl2, psLabel1, psLabel2 )
{

 var lobjEl1 = iElGet( psEl1 ); ;
 var lobjEl2 = iElGet( psEl2 ); ;
 var dt1=new Date();
 var dt2=new Date();
//---------------------------------------------------
		var Sp1;//Index of Date Separator 1
		var Sp2;//Index of Date Separator 2

		var strMonth;
		var strDate;
		var strYear;


		Sp1=lobjEl1.value.indexOf('/',0)

		Sp2=lobjEl1.value.indexOf('/',(parseInt(Sp1)+1));
		//alert(Sp1 + "  " + Sp2);
		strMonth=lobjEl1.value.substring(Sp1+1,Sp2);
		//alert(parseInt(strMonth,10)-1 + "month" );
		strDate=lobjEl1.value.substring(0,Sp1);
		//alert(parseInt(strDate) + "day");
		strYear=lobjEl1.value.substring(Sp2+1,Sp2+5);
		//dt1.setFullYear( parseInt(strYear), parseInt(strMonth)-1, parseInt(strDate))
		dt1.setFullYear( parseInt(strYear) );
		dt1.setMonth( (parseInt(strMonth)-1) );
		dt1.setDate( parseInt(strDate))

		Sp1=lobjEl2.value.indexOf('/',0)
		Sp2=lobjEl2.value.indexOf('/',(parseInt(Sp1)+1));
		strMonth=lobjEl2.value.substring(Sp1+1,Sp2);
		strDate=lobjEl2.value.substring(0,Sp1);
		strYear=lobjEl2.value.substring(Sp2+1,Sp2+5);
		//dt1.setFullYear( parseInt(strYear), parseInt(strMonth)-1, parseInt(strDate))
		dt2.setFullYear( parseInt(strYear) );
		dt2.setMonth( (parseInt(strMonth)-1) );
		dt2.setDate( parseInt(strDate))

//---------------------------------------------------
	//alert( "dt1: " + dt1.getFullYear()  + "  /  " + dt1.getMonth() + "  /   " + dt1.getDate());
	//alert( "dt2: " + dt2.getFullYear()  + "  /  " + dt2.getMonth() + "  /   " + dt2.getDate());


	if ( dt1.getFullYear() > dt2.getFullYear() ) {
	  window.alert( psLabel1+' must be before '+psLabel2 );
	  lobjEl1.focus();
	  return( false );
	}
	if ( (dt1.getMonth() > dt2.getMonth())  && (dt1.getYear() == dt2.getYear()) )  {
	  window.alert( psLabel1+' must be before '+psLabel2 );
	  lobjEl1.focus();
	  return( false );
	}

	if ( (dt1.getDate() > dt2.getDate()) && (dt1.getMonth() == dt2.getMonth())  && (dt1.getYear() == dt2.getYear()) )  {
	  window.alert( psLabel1+' must be before '+psLabel2 );
	  lobjEl1.focus();
	  return( false );

	} ;

// if ( dt1.getDate() > dt2.getDate() )
//{
//  window.alert( psLabel1+' must be before '+psLabel2 );
//  lobjEl1.focus();
//  return( false );
// };

 return( true );
}


//function iIsMaxLength( psElName, piMaxLength, psLabel )
//{
// var lobjEl = iElGet( psElName ); ;
//
// if ( lobjEl.value.length > piMaxLength )
// {
//  window.alert( psLabel+' must be at least '+piMaxLength+'  characters' );
//  lobjEl.focus();
//  return( false );
// };
//
// return( true );
//}


//config

// Config.js, Version 1.0, 2004/03
// Copyright (C) 2004 by Hans Bauer, Schillerstr. 30, D-73072 Donzdorf
//                       http://www.h-bauer.de
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation.
//
function config(name, tree, title, tooltip) {                                   //>config
 this.name     = name;          this.tree       = tree;                         //
 this.title    = title;         this.titelTTip  = tooltip;                      //
 this.lines    = true;          this.linesTxt   = 'Show Lines';                 //
                                this.linesTTip  = 'Lines indicate hierarchy';   //
 this.icons    = true;          this.iconsTxt   = 'Show Icons';                 //
                                this.iconsTTip  = 'Icons indicate node status'; //
 this.cookies  = false;         this.cookiesTxt = 'Save Cookies';               //
                                this.cookiesTTip= 'Stores tree configuration';  //
 this.expireTxt= 'days';        this.expireTTip = 'Cookie expiration period';   //
 this.level    = -1;
 this.levelTxt = 'Open Level';  this.levelTTip  = 'Open tree up to this level'; //
 this.helpTxt  = 'Help';        this.helpTTip   = 'Items show tooltips';        //
 this.helpAlert= 'Tooltips are shown on mouse-over'; }                          //
                                                                                // ------------- TextOf ... ------------
config.prototype.textOfLines = function(text, tooltip) {                        //>TextOfLines
 this.linesTxt = text;         this.linesTTip = tooltip; }                      //

config.prototype.textOfIcons = function(text, tooltip) {                        //>TextOfIcons
 this.iconsTxt = text;         this.iconsTTip = tooltip; }                      //

config.prototype.textOfCookies = function(text, tooltip) {                      //>TextOfCookies
 this.cookiesTxt = text;         this.cookiesTTip = tooltip; }                  //

config.prototype.textOfExpire = function(text, tooltip) {                       //>TextOfExpire
 this.expireTxt = text;         this.expireTTip = tooltip; }                    //

config.prototype.textOfLevel = function(text, tooltip) {                        //>TextOfLevel
 this.levelTxt = text;         this.levelTTip = tooltip; }                      //

config.prototype.textOfHelp = function(text, tooltip, alert) {                  //>TextOfHelp
 this.helpTxt = text;   this.helpTTip = tooltip;   this.helpAlert = alert; }    //
                                                                                // ---------- Build Html-Code ----------
config.prototype.toString = function() {                                        //>ToString


 var str  = '<form><div class="Config">';                                       // Encapsulate class 'Config' in a form
 var icon = (this.tree.showIcons) ? 'ii/config.gif' : 'ii/minicon.gif';       // Decide icon = config- or minIcon.gif
 str += '<a href="javascript: ' + this.name + '.toggle()">'                     // Config-icon:
     +  '<img id="' + this.name + 'ConfigGif"'                                  //   Write Html-string for the image
     +  ' src="' + icon + '" alt="" /></a>';                                    //   and a reference to this -> toggle
 str += '<a href="javascript: ' + this.name + '.toggle()"'                      // Config-text
     +  ' id="' + this.name + 'ConfigTxt" class="ConfigText"'                   //   Write Html-string for the text
     +  ' title="' + this.titelTTip + '">'                                      //   in class 'Text' with tooltip
     +  this.title + '</a>';                                                    //   and a reference to this -> toggle
//alert( this.name + 'SubTree"'
 str += '<div id="' + this.name + 'SubTree"'                                    // SubTree-block (default is invisible:
     +  ' class="SubTree" style="display:none">';                               //   to show or hide the SubTree
 str += '<img src="gif/empty.gif" alt="" />'                                    // Show Lines:
     +  '<input type="checkbox" name="Lines" value="Lines"'                     //   Checkbox: Name & value is 'Lines'
     +  ' id="' + this.name + 'LinesCheck"'                                     //     ID for checkbox
     +  ' onClick="javascript: ' + this.name + '.changeLines()">'               //     OnClick -> java.changeLines
     +  '<a id="' + this.name + 'LinesTxt" class="Text"'                        //   Text: Define ID and class
     +  ' title="'  + this.linesTTip  + '">' +  this.linesTxt + '</a><br>';     //     Write tooltip and text
 str += '<img src="gif/empty.gif" alt="" />'                                    // Show Icons:
     +  '<input type="checkbox" name="Icons" value="Icons"'                     //   Checkbox: Name & value is 'Icons'
     +  ' id="' + this.name + 'IconsCheck"'                                     //     ID for checkbox
     +  ' onClick="javascript: ' + this.name + '.changeIcons()">'               //     OnClick -> java.changeIcons
     +  '<a id="' + this.name + 'IconsTxt" class="Text"'                        //   Text: Define ID and class
     +  ' title="'  + this.iconsTTip  + '">' +  this.iconsTxt + '</a><br>';     //     Write tooltip and text
 str += '<img src="gif/empty.gif" alt="" />'                                    // Use Cookies:
     +  '<input type="checkbox" name="Cookies" value="Cookies"'                 //   Checkbox: Name & value is 'Cookies'
     +  ' id="' + this.name + 'CookiesCheck"'                                   //     ID for checkbox
     +  ' onClick="javascript: ' + this.name + '.changeCookies()">'             //     OnClick -> java.changeCookies
     +  '<a id="' + this.name + 'CookiesTxt" class="Text"'                      //   Text: Define ID and class
     +  ' title="'  + this.cookiesTTip  + '">' +  this.cookiesTxt + '</a><br>'; //     Write tooltip and text
 str += '<img src="gif/empty.gif" alt="" /><img src="gif/empty.gif" alt="" />'  // Expire period of cookies
     +  '&nbsp;<select name="Expire" size="1"'                                  //   Select options 'Expire'
     +  ' id="' + this.name + 'ExpireList"'                                     //     ID for options
     +  ' onClick="' + this.name + '.changeExpire()">';                         //   OnClick -> call this.changeExpire
 for (i=0; i<7; i++) str += '<option>' + Math.pow(2,i) + '</option>';           //   Loop: include options 1, 2, 4,...
 str += '</select>'                                                             //   Close 'Expire'-select
     +  '<a id="' + this.name + 'ExpireTxt" class="Text"'                       //   Text: Define ID and class
     +  ' title="'  + this.expireTTip  + '">' +  this.expireTxt + '</a><br>';   //     Write tooltip and text
 str += '<img src="gif/empty.gif" alt="" />';                                   // Open Level:
 str += '<select name="Level" size="1"'                                         //   Select options 'Level
     +  ' id="' + this.name + 'LevelList"'                                      //     ID for options
     +  ' onClick="' + this.name + '.clickLevel()">'                            //   OnClick  -> call this.clickLevel
     +  '<option>-</option>';                                                   //   Option '-'
 str += '</select>'                                                             //   End of 'select'
     +  '<a id="' + this.name + 'LevelTxt" class="Text"'                        //   Text: Define ID and class
     +  ' title="'  + this.levelTTip  + '">' +  this.levelTxt + '</a><br>';     //     Write tooltip and text
 str += '<img src="gif/empty.gif" alt="" />'                                    // Help:
     + '<a href="javascript: ' + this.name + '.help()">'                        //   Icon:
     +  '<img id="' + this.name + 'HelpGif"'                                    //     Write Html-string for the image
     +  ' src="gif/help.gif" alt="" /></a>';                                    //     and a reference to this -> toggle
 str += '<a href="javascript: ' + this.name + '.help()"'                        //   Text
     +  ' id="' + this.name + 'HelpTxt" class="Text"'                           //   Write Html-string for the text
     +  ' title="' + this.helpTTip + '">'                                       //   in class 'Text' with tooltip
     +  this.helpTxt + '</a>';                                                  //   and a reference to this -> help
 str += '<hr></div></div></form>';                                              // Close SubTree, class 'Config', form
 return str; }                                                                  // Return Html-string

config.prototype.toggle = function() {                                          //>Toggle config tree
 subTree = document.getElementById(this.name + 'SubTree');                      // Get element: SubTree
 status  = subTree.style.display;                                               // Status of the SubTree (open/close)
 subTree.style.display = (status=='none') ? 'block' : 'none';                   // Toggle SubTree-status
 if (subTree.style.display=='block') this.updateOnOpen(); }                     // UpdateOnOpen this using tree.values

config.prototype.updateOnOpen = function() {                                    //>Update config-tree on opening
 var check;                                                                     // Initialize 'check'
 check = document.getElementById(this.name + 'LinesCheck');                     // Lines checkbox
 check.checked = (this.tree.showLines)  ? true : false;                         //   Get setting from 'tree'
 check = document.getElementById(this.name + 'IconsCheck');                     // Icons checkbox
 check.checked = (this.tree.showIcons)  ? true : false;                         //   Get setting from 'tree'
 check = document.getElementById(this.name + 'CookiesCheck');                   // Cookies checkbox
 check.checked = (this.tree.useCookies) ? true : false;                         //   Get setting from 'tree'
 this.updateExpireList();                                                       // Update Expire-list
 this.fillLevelList(); }                                                        // Fill Level-list

config.prototype.updateExpireList = function() {                                //>UpdateExpireList
 for (i=0; i<7; i++) if (Math.pow(2,i)==this.tree.expire) break;                // Loop to find the tree's expire
 var list = document.getElementById(this.name + 'ExpireList');                  // Expire list
 list.selectedIndex = i; }                                                      // Select appropriate option

config.prototype.fillLevelList = function() {                                   //>FillLevelList
 var list = document.getElementById(this.name + 'LevelList');                   // Level list
 if (list.length>1) return;                                                     // List already filled -> nothing
 for (i=0; i<=this.tree.maxIndent; i++) {                                       // Loop levels up to maxIndent of tree
   var item = new Option(i,i,false,false);                                      //   Options 0, 1,... maxIndent-1
   list.options[list.length] = item; } }                                        //   Append next indent-number

config.prototype.changeLines = function() {                                     //>ChangeLines (Checkbox Show Lines)
 var check = document.getElementById(this.name + 'LinesCheck');                 // Lines checkbox
 this.tree.lines(check.checked); }                                              // Transfer setting to 'tree'

config.prototype.changeIcons = function() {                                     //>ChangeIcons (Checkbox Show Icons)
 var icon  = document.getElementById(this.name + 'ConfigGif');                  // Main icon of config-tree:
 var check = document.getElementById(this.name + 'IconsCheck');                 // Icons checkbos
 icon.src  = (check.checked) ? 'ii/config.gif' : 'ii/minIcon.gif';            // Show or hide main icon of this
 this.tree.icons(check.checked); }                                              // Show or hide the icons of the tree

config.prototype.changeCookies = function() {                                   //>ChangeCookies (Checkbox Use Cookies)
 var check = document.getElementById(this.name + 'CookiesCheck');               // Cookies checkbox
 this.tree.cookies(check.checked); }                                            // Transfer setting to 'tree'

config.prototype.changeExpire = function() {                                    //>ChangeExpire (Listbox expire)
 var list = document.getElementById(this.name + 'ExpireList');                  // ExpireList, IE fakes 'list.value'
 this.tree.expiration(Math.pow(2,list.selectedIndex)); }                        // Transfer selected option to 'tree'

config.prototype.clickLevel = function() {                                      //>ClickLevel
 var list = document.getElementById(this.name + 'LevelList');                   // Level list
 if (this.level==list.selectedIndex-1) this.level = -1;                         // Invalidate level on opening options
 else { this.level = list.selectedIndex - 1;                                    // Else: Get selected level and
        if (this.level>=0) this.tree.level(this.level); } }                     //       apply selected level in tree

config.prototype.help = function() { alert(this.helpAlert); }                   //>Help message on click





//loaded
// default.js, Version 1.0, 2004/03
// Copyright (C) 2004 by Hans Bauer, Schillerstr. 30, D-73072 Donzdorf
//                       http://www.h-bauer.de
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation.
//
function loaded(document) {                                                     //>Loaded a document
 if (0==parent.frames.length) return;                                           // Only if frames (menu) are shown
 var path  = document.location.pathname;                                        // Path of the document
 var frame = parent.location.pathname;                                          // Path of 'index.html'
 var index = frame.indexOf("index.html");                                       // Start-position of 'index.html'
 if (index==-1) index = frame.length;                                           // If frame=='/' (not '/index.html')
 var rel   = path.slice(index);                                                 // Relative path of loaded document
 if (parent.menu.tree) parent.menu.tree.selectPath(rel); }                      // Select appropriate node in menu




//New tree code

// TreeMenu.js, Version 1.0, 2004/03
// Copyright (C) 2004 by Hans Bauer, Schillerstr. 30, D-73072 Donzdorf
//                       http://www.h-bauer.de
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation.
//
function Node(id,indent,text,target,url,tooltip,iconOpen,iconClose,isOpen) {    //>Node (Folder or Item)
 this.id        = id;                 this.indent    = indent;                  // Initialize variables
 this.text      = text;               this.target    = target;                  //     ..        ..
 this.url       = url;                this.tooltip   = tooltip;                 //     ..        ..
 this.iconOpen  = iconOpen;           this.iconClose = iconClose;               //     ..        ..
 this.parent    = null;               this.childs    = [];                      //     ..        ..
 this.isOpen    = isOpen;   }                                                   //     ..        ..

function treemenu(name, showLines, showIcons, useCookies) {                     //>treemenu

 this.name      = name;               this.showLines = showLines;               // Initialize variables
 this.showIcons = showIcons;          this.useCookies= useCookies;              //     ..        ..
 this.nodes     = [];                 this.root      = new Node(-1,-1,'root');  //     ..        ..
 this.selected  = -1;                 this.maxIndent = 0;                       //     ..        ..
 this.expire    = 1;                  this.openNodes = '';                      //     ..        ..
 this.classDepth= 2;                                                            // ClassDepth for text-format-> css-file
 this.readCookies();                                                            // Read cookies if available
 if (!navigator.cookieEnabled) this.useCookies = false;                         // Respect the browsers cookie setting
 this.defaults = {                                                              // Default images/icons
   iconRoot  : 'ii/root.gif',        iconItem  : 'ii/item.gif',               //    ..        ..
   iconOpen  : 'ii/open.gif',        iconClose : 'ii/close.gif',              //    ..        ..
   passLine  : 'ii/passline.gif',    empty     : 'ii/empty.gif',              //    ..        ..
   tieLine   : 'ii/tieline.gif',     tiePlus   : 'ii/tieplus.gif',            //    ..        ..
   endLine   : 'ii/endline.gif',     endPlus   : 'ii/endplus.gif',            //    ..        ..
   rectPlus  : 'ii/rectplus.gif',    tieMinus  : 'ii/tieminus.gif',           //    ..        ..
   rectMinus : 'ii/rectminus.gif',   endMinus  : 'ii/endminus.gif',           //    ..        ..
   minIcon   : 'ii/minicon.gif'  } }                                           //
                                                                                // ----------- Build up menu -----------
treemenu.prototype.put = function(open, label, target, url,                     //>Put a node to the treemenu
                                  tooltip, iconOpen, iconClose) {               //     that is initially to be loaded
 if (this.selected==-1) this.selected = this.nodes.length;                      // Set 'selected' if not cookie-defined
 this.add(open, label, target, url, tooltip, iconOpen, iconClose); }            // Add a node to the treemenu

treemenu.prototype.add = function(open, label, target, url,                     //>Add a node to the treemenu
                                  tooltip, iconOpen, iconClose) {               //
 var indent = 0;                                                                // Indent: initialize
 while (label.charAt(indent)==' ') indent++;                                    //   Indent by leading spaces
 if (this.maxIndent<indent) this.maxIndent = indent;                            //   Adjust 'maxIndent'
 var id     = this.nodes.length;                                                // ID of the new node
 var isOpen = (open==0) ? false : true;                                         // IsOpen from given value '0' or '1'
 if (this.openNodes && id<this.openNodes.length)                                // On given 'OpenNodes'
     isOpen = (this.openNodes.charAt(id)=='1') ? true : false;                  // -> Status depending on cookie
 var node   = new Node(id, indent, label.substr(indent),                        // New node: ID corresponds with number
                       target, url, tooltip, iconOpen, iconClose, isOpen);      //   Text without leading spaces
 this.nodes[this.nodes.length] = node;                                          //   Append node to the nodes-array
 for (i=this.nodes.length-1; i>=0; i--)                                         // Parent node:
   if (this.nodes[i].indent < indent) { node.parent = this.nodes[i];   break; } //   Loop back to find parent by indent
 if (!node.parent) node.parent = this.root;                                     //   Root-node is parent if none found
 if (node.parent.indent<node.indent-1)                                          //   Invalid indent
     alert('Indent of "' + node.text + '" must be <' + (node.parent.indent+2)); //   -> alert-message
 node.parent.childs[node.parent.childs.length] = node; }                        //   New node is child of the parent

                                                                                // ---------- Build Html-code ----------
treemenu.prototype.toString = function() {                                      //>ToString used by document.write(...)


 var str = '<div class="TreeMenu">';                                            // Encapsulate class 'TreeMenu'
 var lastIndent = 0;                                                            // Initialize lastIndent
 for (id=0; id<this.nodes.length; id++) {                                       // Loop: Nodes
   var node = this.nodes[id]                                                    //   Current node
   if (lastIndent < node.indent) lastIndent = node.indent;                      //   Update lastIndent to max
   while (lastIndent>node.indent) { str += '</div>';   lastIndent--; }          //   Close previous </div>-Subtrees
   str += this.writeNode(node);                                                 //   Write node
   if (0<node.childs.length) {                                                  //   Parent -> SubTree of childs
     str += '<div id="' + this.name + 'SubTree_' + id                           //   -> Write <div..-block to display
         +  '" style="display:'                                                 //            or to hide the SubTree
         +  ((node.isOpen) ? 'block' : 'none') + '">'; } }                      //            according to isOpen-value
 for (i=lastIndent; i>0; i--) str += '</div>';                                  // Close remaining SubTrees
// str += this.writeCreatedWithTreeMenu();                                        // Write CreatedWithTreeMenu
 str += '</div>';                                                               // Close class 'TreeMenu'
 this.setCookies(this.expire);                                                  // Set Cookies
 this.loadSelected();                                                           // LoadSelected on already filled frames
// alert(str);                                                                  // Discomment to see Html-Code
 return str;  }                                                                 // Return HTML-String

                                                                                // -------------- Write ----------------
treemenu.prototype.writeNode = function(node) {                                 //>WriteNode
 if (node.target=='hide') return '';                                            // Only node with no hidden target
 var str = '<div>'                                                              // Open <div>-block for the node
         + this.writeIndenting(node)  + this.writeTieUpIcon(node)               // Write Indenting, tieUpIcon
         + this.writeNodeSymbol(node) + this.writeNodeText(node) + '</div>';    //       Symbol, Text, close 'TreeNode'
 return str; }                                                                  // Return cumulated Html-String

treemenu.prototype.writeIndenting = function(node) {                            //>WriteIndenting
 if (node.indent < 2) return '';                                                // Only if node-indent >= 2
 var str      = '';                                                             // Initialize str
 var icons    = [];                                                             //            icons[]
 var ancestor = node.parent;                                                    // Start at ancestor = node.parent
 for (i=node.indent-2; i>=0; i--, ancestor=ancestor.parent) {                   // Loop ancestors from right to left
      icons[i] = (this.isLastChild(ancestor) ? 'empty' : 'passLine');  }        //   Last child -> empty, else passLine
 for (i=0; i<=node.indent-2; i++) {                                             // Loop from left to right:
      var icon = this.defaults.empty;                                           //   Default icon = empty
      if (this.showLines && icons[i]!='empty') icon = this.defaults.passLine;   //   or passLine to be shown
      str += '<img name="' + icons[i] + '" src="' + icon + '" alt="" />'; }     //   Html-string for the icon
 return str;  }                                                                 // Return html-string

treemenu.prototype.writeTieUpIcon = function(node)  {                           //>WriteTieUpIcon
 if (node.indent < 1) return '';                                                // Only for indents > 1
 var icon = this.getTieUpIcon(node);                                            // GetTieUpIcon
 var str  = '';                                                                 // Initialize str
 if (0==node.childs.length)                                                     // No childs -> Return only TieUpIcon
      str = '<img id="' + this.name + 'TieUp_' + node.id                        //   Write tieUpIcon with
          + '" src="' + icon + '" alt="" />';                                   //   name & source
 else str = '<a href="javascript: ' + this.name + '.toggle(' + node.id + ')">'  // Parent node:
          +  '<img id="' + this.name + 'TieUp_' + node.id                       //   Write tieUpIcon with
          +  '" src="' + icon + '" alt="" /></a>';                              //   name, source & javascript:toggle
 return str; }                                                                  // Html-code for the TieUpIcon

treemenu.prototype.getTieUpIcon = function(node) {                              //>GetTieUpIcon
 if (0 == node.childs.length) {                                                 // No childs:
   if      (!this.showLines)        return this.defaults.empty;                 //   Don't show Lines   -> empty
   else if (this.isLastChild(node)) return this.defaults.endLine;               //   Else if last child -> endLine
   else                             return this.defaults.tieLine;  }            //   Else if fore child -> tieLine
 else if (node.isOpen) {                                                        // Open parent:
   if      (!this.showLines)        return this.defaults.rectMinus;             //   Don't show Lines   -> rectMinus
   else if (this.isLastChild(node)) return this.defaults.endMinus;              //   Else if last child -> endMinus
   else                             return this.defaults.tieMinus; }            //   Else if fore child -> tieMinus
 else {                                                                         // Closed parent:
   if      (!this.showLines)        return this.defaults.rectPlus;              //   Don't show Lines   -> rectPlus
   else if (this.isLastChild(node)) return this.defaults.endPlus;               //   Else if last child -> endPlus
   else                             return this.defaults.tiePlus;  } }          //   Else if fore child -> tiePlus

treemenu.prototype.writeNodeSymbol = function(node) {                           //>WriteNodeSymbol
 var icon = this.getNodeSymbol(node) ;                                          // GetNodeSymbol
 if (0==node.childs.length) {                                                   // No childs:
   var str = '';                                                                //   Reference to the nodes url
   if (node.url) {    str += '<a href="' + node.url + '"';                      //     if a url is given and load
     if (node.target) str += ' target="' + node.target + '")';                  //     the url into the target frame.
                      str += '">'; }                                            //     Close leading <a..>-tag
   str += '<img id="' + this.name + 'Symbol_' + node.id                         //   Write the Html-code for the
       +  '" src="'   + icon + '" alt="" />';                                   //     image of the node-symbol
   if (node.url) str += '</a>';                                                 //   Close trailing </a>-tag if any
   return str; }                                                                //   Return Html-string for symbol
 return   '<a href="javascript: ' + this.name + '.toggle(' + node.id + ')">'    // Parent:
          + '<img id="' + this.name + 'Symbol_' + node.id                       //   Write Html-string for the image
          + '" src="' + icon + '" alt="" /></a>'; }                             //   and a reference to java -> toggle

treemenu.prototype.getNodeSymbol = function(node) {                             //>GetNodeSymbol
 if (!this.showIcons)  return this.defaults.minIcon;                            // No Symbols-> 'minIcon' (for IE)
 if (0==node.childs.length) {                                                   // No childs:
   if (node.iconOpen)  return node.iconOpen;                                    //   Use nodes  'iconOpen'
   else                return this.defaults.iconItem;  }                        //   or default 'iconItem'
 else if (node.isOpen) {                                                        // Open parent:
   if (node.iconOpen)  return node.iconOpen;                                    //   Use nodes  'iconOpen'
   else                return this.defaults.iconOpen;  }                        //   or default 'iconOpen'
 else {                                                                         // Closed parent:
   if (node.iconClose) return node.iconClose;                                   //   Use nodes  'iconClose'
   else                return this.defaults.iconClose; } }                      //   or default 'iconClose'

treemenu.prototype.writeNodeText = function(node) {                             //>WriteNodeText
 var cls = this.getNodeTextClass(node, this.selected);                          // Get NodeTextClass
 var str = '<a id="' + this.name + 'Node_' + node.id + '" class="' + cls + '"'; // Add '<a id=...' and 'class=...'
 if (node.url) str += ' href="' + node.url + '"';                               // HRef-link to node.url
 else          str += ' href="javascript: '+this.name+'.toggle('+node.id+')"';  //     or to java.toggle
 if (node.url && node.target)  str += ' target="' + node.target   + '"';        // Target ="node.target"
 if (node.tooltip)             str += ' title="'  + node.tooltip  + '"';        // Title  ="node.tooltip"
 str += ' onclick="javascript: ' + this.name + '.pick(' + node.id + ')"';       // OnClick="javascript.pick"
 str += '>' + node.text + ((node.url) ? '</a>' : '</a>') ;                      // Node text, close 'a>'
 return str; }                                                                  // Return HTML-string

treemenu.prototype.getNodeTextClass = function(node, selectID) {                //>GetNodeTextClass for TreeMenu.css
 var cls = (node.id==selectID) ? 'Selected' : 'Node';                           // Class 'Selected', 'Node'
 if (!node.url) cls = 'Item';                                                   //    or 'Item' (without url)
 return cls + '_' + Math.min(node.indent, this.classDepth); }                   // Append '_indent' or '_classDepth'

treemenu.prototype.writeCreatedWithTreeMenu = function() {                      //>WriteCreatedWithTreeMenu
 var path = '',    target ='';                                                  // Path to the freeware 'treemenu'
 var elem = document.getElementById('treepath');                                // Path defined in document
 if (elem) { target = 'main';      path = elem.title;               }           //   ->   Use defined path
 else      { target = '_parent';   path = 'http://www.h-bauer.de';  }           //   Else use 'http://h-bauer.de'
 var str = '<br>Created with <a class="CreatedBy" target="' + target +'"'       // Please don't alter this code to
         + ' href="' + path + '">TreeMenu</a>';                                 // give your visitors the ability to
 return str; }                                                                  // also access this utility. THANKS!

                                                                                // --------------- Load ----------------
treemenu.prototype.loadSelected = function() { this.loadNode(this.selected); }  //>LoadSelected

treemenu.prototype.loadNode = function(id) {                                    //>LoadNode by ID into it's target frame
 if (id<0) return;                                                              // Only nodes with id>=0
 if (this.nodes[id].target=='hide') return;                                     // Only nodes with no hidden target
 for (var i=0; i<parent.frames.length; i++) {                                   // Loop: Frames in frameset
   if (parent.frames[i].name==this.nodes[id].target) {                          //   Target-frame of the selected node
     parent.frames[i].location.href = this.nodes[id].url;                       //   -> Reference to the node to load
     break; } } }                                                               //      Break the loop and return

                                                                                // ----------- Pick / Select -----------
treemenu.prototype.pick = function(id) {                                        //>Pick a node by id
 var node = this.nodes[id];                                                     // Picked node
 if (node.url) {                                                                // Nodes with URL (->no href to toggle)
   if      (node.indent==0       && this.showIcons==false) this.toggle(id);     // -> Toggle top node without icon
   else if (node.childs.length>0 && node.isOpen==false)    this.toggle(id); }   //    Else: open closed parent node
 this.select(id); }                                                             // Select node by ID & unselect previous
// document.location.reload(); }

treemenu.prototype.select = function(id) {                                      //>Select a node by a given ID
 if (!this.nodes[id].url) return;                                               // Only for a node with url:
 if (this.selected >= 0) {                                                      // Deselect selected Html-node:
   node = document.getElementById(this.name + 'Node_' + this.selected);         //   Get selected Html-node by id
   name = this.getNodeTextClass(this.nodes[this.selected],-1);                  //   ClassName for unselected
   if (node && name) node.className = name;                                     //   Unselect previous selected node
   this.selected  = -1;  }                                                      //   Invalidate this.selected
 node = document.getElementById(this.name + 'Node_' + id);                      // Select Html-node:
 name = this.getNodeTextClass(this.nodes[id], id);                              //   ClassName for selected
 if (node && name) node.className = name;                                       //     Selected previous unselected node
 this.selected  = id;                                                           //     Set this.selected value to id
 this.openAncestors(id);                                                        //     Open the nodes ancestors
 this.setCookies(this.expire); }                                                //     Set cookies

treemenu.prototype.openAncestors = function(id) {                               //>OpenAncestors of the node with id
 if (id<0) return;                                                              // Only valid nodes with ID>=0
 var ancestor = this.nodes[id].parent;                                          // Ancestor is parent node;
 while(ancestor.indent>=0) {                                                    // Loop: Ancestors
   if (!ancestor.isOpen) { ancestor.isOpen=true;  this.updateNode(ancestor); }  //   Open and update ancestor
   ancestor = ancestor.parent;   } }                                            //   Parent of ancestor  }

treemenu.prototype.selectPath = function(path) {                                //>SelectPath  (for page registration)
 path = this.pathWithSlash(path);                                               // Ensure path with slash '/'
 if (this.selected>=0) {                                                        // A node ist already selected:
   var url = this.pathWithSlash(this.nodes[this.selected].url);                 //   URL of the selected node
   if (url==path) return;  }                                                    //   URL already selected -> return
 for (id=0; id<this.nodes.length; id++) {                                       // Loop to search node:
   var url = this.pathWithSlash(this.nodes[id].url);                            //   Node path with slash '/'
   if (url && url==path) { this.select(id);    break; } } }                     //   Equal path -> select node by id

treemenu.prototype.pathWithSlash = function(path) {                             //>PathWithSlash
 var parts = path.split("\\");                                                  // Split path at '\' into string-array
 var str   = parts[0];                                                          // Write first part to 'str'
 for (i=1; i<parts.length; i++) str = str + '/' + parts[i];                     // Add next parts divided by '/'
 return str; }                                                                  // Return path with '/' instead of '\'

                                                                                // ---------- Toggle / Update ----------
treemenu.prototype.toggle = function(id) {                                      //>Toggle a node by id
 if (this.nodes[id].childs.length==0) return;                                   // Only for parent nodes
 this.nodes[id].isOpen = !this.nodes[id].isOpen;                                // Toggle node-status (open or close)
 this.updateNode(this.nodes[id]);                                               // Update the node
 this.setCookies(this.expire); }                                                // Set cookies

treemenu.prototype.updateNode = function(node) {                                //>UpdateNode
 subTree = document.getElementById(this.name + 'SubTree_' + node.id);           // Get Html-element: SubTree
 tieUp   = document.getElementById(this.name + 'TieUp_'   + node.id);           //                   TieUpIcon
 symbol  = document.getElementById(this.name + 'Symbol_'  + node.id);           //                   NodeSymbol
 if (subTree) subTree.style.display = (node.isOpen) ? 'block' : 'none';         // Update Html-elem. SubTree
 if (tieUp)   tieUp.src   = this.getTieUpIcon(node);                            //                   TieUpIcon
 if (symbol)  symbol.src  = this.getNodeSymbol(node); }                         //                   NodeSymbol

                                                                                // ----------- IsLastChild -------------
treemenu.prototype.isLastChild = function(node) {                               //>IsLastChild (?)
 var parent = node.parent;                                                      // Parent of the node
 return ((node == parent.childs[parent.childs.length-1]) ? true : false); }     // Check for last child

                                                                                // --------- Level/Lines/Icons ---------
treemenu.prototype.level = function(level) {                                    //>Level to open/close menu
 for (id=0; id<this.nodes.length; id++) {                                       // Loop: nodes
   this.nodes[id].isOpen = (this.nodes[id].indent<level) ? true : false;        //   Open/close node depending on level
   this.updateNode(this.nodes[id]); }                                           //   Update the node
 this.setCookies(this.expire); }                                                // Set cookies

treemenu.prototype.lines = function(bool) {                                     //>Lines to be shown (?)
 if (this.showLines == bool) return;                                            // Nothing changed -> return
 this.showLines = bool;                                                         // Update 'showLines'
 var passLines = document.getElementsByName("passLine");                        // Get PassLines
 if (!passLines) return;                                                        // Existing passLines:
 for (i=0; i<passLines.length; i++) {                                           //  Loop: passLines
   passLines[i].src = (bool) ? this.defaults.passLine : this.defaults.empty; }  //   Update icon-source
 for (id=0; id<this.nodes.length; id++) {                                       // TieUpIcon for each node
   if (this.nodes[id].indent < 1) continue;                                     //   with indent >= 1
   var tieUp = document.getElementById(this.name + 'TieUp_' + id);              //   TieUpIcon of the node
   if (tieUp) tieUp.src = this.getTieUpIcon(this.nodes[id]);  }                 //   Update icon-source
 this.setCookies(this.expire); }                                                // Set cookies

treemenu.prototype.icons = function(bool) {                                     //>Icons to be shown (?)
 if (this.showIcons == bool) return;                                            // Nothing changed -> return
 this.showIcons = bool;                                                         // Set 'showIcons'-value
 for (id=0; id<this.nodes.length; id++) {                                       // Loop: nodes
   var icon  = this.getNodeSymbol(this.nodes[id]);                              //   Get node symbol
   var image = document.getElementById(this.name + 'Symbol_' + id)              //   Get Html-image by id
   if (image)  image.src = icon; }                                              //   Set image source to node symbol
 this.setCookies(this.expire); }                                                // Set cookies

                                                                                // -------------- Cookies --------------
treemenu.prototype.expiration = function(expire) {                              //>Expiration
 this.expire = expire;          this.setCookies(this.expire); }                 // Set/Save expiration period of cookies

treemenu.prototype.cookies = function(bool) {                                   //>Cookies to be used (?)
 if (bool) { this.useCookies = bool;  this.setCookies(this.expire);   }         // Use cookies -> Set cookies
 else      { this.setCookies(-1);     this.useCookies = bool;         } }       // No  cookies -> Clear existing cookies

treemenu.prototype.setCookies = function(expire) {                              //>SetCookies
 this.openNodes = '';                                                           // Initialize 'openNodes'-String
 for (i=0; i<this.nodes.length; i++)                                            // Loop: nodes
   this.openNodes += (this.nodes[i].isOpen) ? '1' : '0';                        //   Fill 'openNodes'-String
 this.setCookie("OpenNodes", this.openNodes, expire);                           // Set cookie 'OpenNodes'
 this.setCookie("ShowLines", this.showLines, expire);                           //            'ShowLines'
 this.setCookie("ShowIcons", this.showIcons, expire);                           //            'ShowIcons'
 this.setCookie("Selected",  this.selected,  expire);                           //            'Selected'
 this.setCookie("Expire"   , this.expire,    expire); }                         //            'Expire'

treemenu.prototype.readCookies = function() {                                   //>ReadCookies (as string!)
 var lines  = this.getCookie("ShowLines");                                      // Get Cookie:  'ShowLines'
 var icons  = this.getCookie("ShowIcons");                                      //              'ShowIcons'
 var select = this.getCookie("Selected");                                       //              'Selected'
 var open   = this.getCookie("OpenNodes");                                      //              'OpenNodes'
 var expire = this.getCookie("Expire");                                         //              'Expire'
 if (lines)   this.showLines = (lines=='true') ? true : false;                  // Set value of 'showLines'
 if (icons)   this.showIcons = (icons=='true') ? true : false;                  //              'showIcons'
 if (select)  this.selected  = select;                                          //              'selected'
 if (open)    this.openNodes = open;                                            //              'openNodes'
 if (expire)  this.expire    = expire;                                          //              'expire'
 if (lines || icons || select ||  open) this.useCookies = true;  }              // Cookies found -> useCookies is true

                                                                                // --------------- Cookie --------------
treemenu.prototype.setCookie = function(name, value, expire) {                  //>SetCookie by name and value
 if (!this.useCookies) return;                                                  // Only if cookies are to be used
 var exp = new Date();                                                          // Actual date
 var end = exp.getTime() + (expire * 24 * 60 * 60 * 1000);                      // In 'expire'-days (-1: -> invalidate)
 exp.setTime(end);                                                              // Expire time of cookes
 document.cookie =  name + '=' + value + '; expires=' + exp.toGMTString(); }    // Set cookie with expiration-date

treemenu.prototype.getCookie = function(name) {                                 //>GetCookie value (as string!)
 var cookies  = document.cookie;                                                // Cookies separated by ';'
 var posName  = cookies.indexOf(name + '=');                                    // Start position of 'name='
 if (posName == -1) return '';                                                  // Cookie not found -> Return ''
 var posValue = posName + name.length + 1;                                      // Start position of cookie-value
 var endValue = cookies.indexOf(';',posValue);                                  // End position of cookie value at ';'
 if (endValue !=-1) return cookies.substring(posValue, endValue);               // ';' -> Return substring as value
 return cookies.substring(posValue); }                                          // Else-> Return rest of line as value





function uCompanynameCheckContact(RElement)
	{	
		var companyElement;
		companyElement = RElement.replace('ContactName','Company');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(companyElement)) ) ) ) 
		 { 	
			alert('Company name is required.');
			iElGet(companyElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}

function uCompanynameCheckTelephone(RElement)
	{	
		var companyElement;
		companyElement = RElement.replace('Telephone','Company');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(companyElement)) ) ) ) 
		 { 	
			alert('Company name is required.');
			iElGet(companyElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}

function uCompanynameCheckFax(RElement)
	{	
		var companyElement;
		companyElement = RElement.replace('FaxNumber','Company');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(companyElement)) ) ) ) 
		 { 	
			alert('Company name is required.');
			iElGet(companyElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}

function uCompanynameCheckEmail(RElement)
	{	
		var companyElement;
		companyElement = RElement.replace('Email','Company');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(companyElement)) ) ) ) 
		 { 	
			alert('Company name is required.');
			iElGet(companyElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}
function uCompanynameCheckLength(RElement)
	{	
		var companyElement;
		companyElement = RElement.replace('RelationLength','Company');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(companyElement)) ) ) ) 
		 { 	
			alert('Company name is required.');
			iElGet(companyElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}

function uSurnameCheckFirstName(RElement)
	{	
		var SurnameElement;
		SurnameElement = RElement.replace('FirstNames','Surname');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(SurnameElement)) ) ) ) 
		 { 	
			alert('Surname is required.');
			iElGet(SurnameElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}

function uSurnameCheckIDNo(RElement)
	{	
		var SurnameElement;
		SurnameElement = RElement.replace('IdentityNo','Surname');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(SurnameElement)) ) ) ) 
		 { 	
			alert('Surname is required.');
			iElGet(SurnameElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}

function uSurnameCheckOwner(RElement)
	{	
		var SurnameElement;
		SurnameElement = RElement.replace('Ownership ','Surname');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(SurnameElement)) ) ) ) 
		 { 	
			alert('Surname is required.');
			iElGet(SurnameElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}


function uProductCheckName(RElement)
	{	
		var productElement;
		productElement = RElement.replace('Description ','Name');
		
		 if ( !(iIsNilStr( iElGVal( iElGet(RElement)) ) )   && (iIsNilStr( iElGVal( iElGet(productElement)) ) ) ) 
		 { 	
			alert('Product / Service name is required.');
			iElGet(productElement).focus();
			return false;
		 } else 
		 {
		 	return true;
		 }

}



// Date Validation Javascript
// copyright 30th October 2004, by Stephen Chapman
// http://javascript.about.com

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function valDateFmt(datefmt) 
{
	myOption = -1;
	for (i=0; i<datefmt.length; i++) {if (datefmt[i].checked) {myOption = i;}}

	if (myOption == -1) {alert("You must select a date format");return ' ';}
	return datefmt[myOption].value;
}

function valDateRng(daterng) 
{
	myOption = -1;
	for (i=0; i<daterng.length; i++) {if (daterng[i].checked) {myOption = i;}}
	if (myOption == -1) {alert("You must select a date range");return ' ';}
	return daterng[myOption].value;
}

function stripBlanks(fld) 
{
	var result = "";
	
	for (i=0; i<fld.length; i++) 
	{
		if (fld.charAt(i) != " " || c > 0) 
		{
			result += fld.charAt(i);
			if (fld.charAt(i) != " ") c = result.length;
		}
	}
	return result.substr(0,c);
}
	
var numb = '0123456789';

function isValid(parm,val) 
{
	if (parm == "") return true;
	for (i=0; i<parm.length; i++) {if (val.indexOf(parm.charAt(i),0) == -1) return false;}
	return true;
}

function isNum(parm) {return isValid(parm,numb);}

var shortmth = new Array(' ','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
var mth = new Array(' ','january','february','march','april','may','june','july','august','september','october','november','december');
var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function validateDate(fld,fmt,rng) {
var dd, mm, yy;var today = new Date;var t = new Date;fld = stripBlanks(fld);
if (fld == '') return false;var d1 = fld.split('\/');
if (d1.length != 3) d1 = fld.split(' ');
if (d1.length != 3) return false;
if (fmt == 'u' || fmt == 'U') {
  dd = d1[1]; mm = d1[0]; yy = d1[2];}
else if (fmt == 'j' || fmt == 'J') {
  dd = d1[2]; mm = d1[1]; yy = d1[0];}
else if (fmt == 'w' || fmt == 'W'){
  dd = d1[0]; mm = d1[1]; yy = d1[2];}
else return false;
var n = dd.lastIndexOf('st');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('nd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('rd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('th');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf(',');
if (n > -1) dd = dd.substr(0,n);
n = mm.lastIndexOf(',');
if (n > -1) mm = mm.substr(0,n);
if (!isNum(dd)) return false;
if (!isNum(yy)) return false;
if (!isNum(mm)) {
  var nn = mm.toLowerCase();
  for (var i=1; i < 13; i++) {
    if (nn == mth[i] ||
        nn == mth[i].substr(0,3)) {mm = i; i = 13;}
  }
}
if (!isNum(mm)) return false;
dd = parseFloat(dd); mm = parseFloat(mm); yy = parseFloat(yy);
if (yy < 100) yy += 2000;
if (yy < 1582 || yy > 4881) return false;
if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
if (mm < 1 || mm > 12) return false;
if (dd < 1 || dd > day[mm-1]) return false;
t.setDate(dd); t.setMonth(mm-1); t.setFullYear(yy);
if (rng == 'p' || rng == 'P') {
if (t > today) return false;
}
else if (rng == 'f' || rng == 'F') {
if (t < today) return false;
}
else if (rng != 'a' && rng != 'A') return false;
return true;
}


function iIsDate(psElName)
{

 var lobjEl = iElGet( psElName ); ; 

 if ( lobjEl.value.length > 0 ) 
 {

  if ( !validateDate(lobjEl.value,'w','a') ) 
  { 
   window.alert( 'Please enter a valid date' ); 
   lobjEl.focus(); 
   return( false);
  }; 
 }

 return( true ); 

}