document.onclick = function(){
	    try{
		    CancelCal();
	    }
	    catch(e){}
    }
    
function UpdDt(date1, date2_id)
{   
    var f = DE(date1.id);
    var t = DE(date2_id);

    if(null!=f&&null!=t&&null!=GetInputDate(f.value)&&(null==GetInputDate(t.value)||GetInputDate(f.value)>GetInputDate(t.value))){t.value=f.value;}    
}

function UpdDt2(date1, date2_id)
{   
    var f = DE(date1.id);
    var t = DE(date2_id);

    if(null!=f&&null!=t&&null!=GetInputDate(f.value)&&(null==GetInputDate(t.value)||GetInputDate(f.value)<GetInputDate(t.value))){t.value=f.value;}    
}

function SC(date1, date2_id, NumberDayStart)
{
    if (DE('Cal2MFrame') == null)	{	return;	}
    var id = date1.id;
    
    //Number of days after the current date, dates are active for selection .0 days by default
    var StartDayDiff = 0;
    if (NumberDayStart!=null)
        StartDayDiff = NumberDayStart;

    var CalDateStart = new Date();
   
   
    CalDateStart.setDate(CalDateStart.getDate()+ StartDayDiff);
    CalS = CalDateStart.getMonth()+1 + '/'+ CalDateStart.getDate() +'/' + CalDateStart.getFullYear();
    CalDateStart.setDate(CalDateStart.getDate()+ 183); // prev 329
	CalE = CalDateStart.getMonth()+1 + '/'+ CalDateStart.getDate() +'/' + CalDateStart.getFullYear();
	
    if (date2_id==null)
    {
        date1.select();
        ShowCalendar(date1,date1,null,CalS,CalE);    
    }
	if (date2_id!=null) { date1.select();ShowCalendar(date1,date1,DE(date2_id),CalS,CalE); }
}

function checkFutureDate(date1)
{
	var CalDateStart = new Date();
	var CalDateNow = new Date();
	    CalDateStart.setDate(CalDateStart.getDate()+ 183); // prev 329

	if(GetInputDate(date1.value) != null && GetInputDate(date1.value) > CalDateStart)
	{
		alert("You can only enter dates within the next 6 months.");
		date1.value = "dd/mm/yyyy";
		date1.select();
		
	}
	else if(GetInputDate(date1.value) != null && GetInputDate(date1.value) < CalDateNow)
	{
		alert("You can not enter dates in the past.");
		date1.value = "dd/mm/yyyy";
		date1.select();
	}
}

function DE(el){return document.getElementById(el);}

function SH(id,s){var e = DE(id);if(s){e.style.display = 'block';}else{e.style.display = 'none';}}

var aS = new Array();
function SB(){this.Concat = Concat;this.GetValue = GetValue;this.Reset = Reset;}
function Concat(StringToConcat){this.aS[this.aS.length] = StringToConcat;}
function GetValue(){return this.aS.join('');}
function Reset(){this.aS = null;this.aS = new Array();}
   
function ecsf(){document.ec.submit();}
function ece(e){var k;if(e.keyCode){k=e.keyCode;}if(e.which){k=e.which;}if(k=='13'){e.cancelBubble=true;ecsf();}}

function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}

var CalS = '';
var CalE = '';

var arrMN = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July','August', 'September', 'October', 'November', 'December');
var nextFocus = null;
var arrSH = new Array(10);
var sb = new SB();
var sb1 = new SB();
var arrE = [];

function SH1(id,s){var e = DE(id);if(s){e.style.display = 'block';}else{e.style.display = 'none';}}
function GetDowStart() {return 1;}function GetDateFmt() {return "ddmmyy";}function GetDateSep() {return "/";}
function ShowCalendar(eP,eD,eDP,dmin,dmax)
{
	SCal(eP,eD,eDP,dmin,dmax);
}

var zz, zv, d, fTSR;
d = new Date();
fTSR=0;
zv = d.getTime();
zz = "&zz="+zv;

var gBF=false;
function GoTo(u){window.top.location = u + zz;}
function Go(u){window.top.location = u;} 
function BF(){gBF=true;}

function getObj(objID)
	{
	if (document.getElementById) {return document.getElementById(objID);}
	else if (document.all) {return document.all[objID];}
	else if (document.layers) {return document.layers[objID];}
	}

function DoNothing() {return false;}var cF=null;var cW=null;var g_tid=0;var g_cP,g_eD,g_eDP,g_dmin,g_dmax;
var nextFocus;var g_fNoCal=false;
function getEventObj(e){if(!e)e=window.event;return e;}
function stopBubble(e){e=getEventObj(e);e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();}
function CB(){stopBubble(event);}

function SCal(cP,eD,eDP,dmin,dmax){
 clearTimeout(g_tid);
 if(g_fNoCal){g_fNoCal=false;return;}
	if(g_calShown && eD==g_eD){return;}
	g_calShown = true;
	g_calCB = null;
 g_cP=cP;
 g_eD=eD;
 g_eDP=eDP;
 g_dmin=dmin;
 g_dmax=dmax;
 WaitCal();}
function CancelCal(){clearTimeout(g_tid);if(!cF)cF=getObj('Cal2MFrame');cF.style.visibility="hidden";g_calShown=false;}
function WaitCal()
{ 
 if(!cW)cW=frames['Cal2MFrame'];

 if(null==cW||null==cW.g_fCL||false==cW.g_fCL){
	g_tid=setTimeout("WaitCal()", 200);
	}
 else{
 if(!cF)cF=getObj('Cal2MFrame');
	cF.style.visibility="hidden";
	setTimeout("DoCal()",1);
	}
}
function DoCal(){PosCal(g_cP);
if(!cW)cW=frames['Cal2MFrame'];
cW.DoCal(g_eD,g_eDP,g_dmin,g_dmax);}

function getScrollTop()
{
	if(document.documentElement.scrollTop) return document.documentElement.scrollTop;
	if(document.body.scrollTop) return document.body.scrollTop;
	if(window.pageYOffset) return window.pageYOffset;
	return 0;
}

function getWinHeight()
{
	if(window.innerHeight) return window.innerHeight;
	if(document.documentElement.clientHeight) return document.documentElement.clientHeight;
	if(document.body.clientHeight) return document.body.clientHeight;
	return 0;
}

function PosCal(cP)
{
	var dB=document.body;var eL=0;var eT=0;
    if(!cF)cF=getObj('Cal2MFrame');
	for(var p=cP;p&&p.tagName!='BODY';p=p.offsetParent)
	{
	eL+=p.offsetLeft;
	eT+=p.offsetTop;
	}
	var eH=cP.offsetHeight;var dH=parseInt(cF.style.height);var sT=getScrollTop();
	if(eT-dH>=sT&&eT+eH+dH>getWinHeight()+sT)eT-=dH;else eT+=eH;
	//cF.style.left=eL+'px';cF.style.top=eT+'px';
}

function SetNextFocus(e){nextFocus=e;if(nextFocus)nextFocus.onfocus=CancelCal;}
function SetPrevFocus(e){if(e)e.onfocus=CancelCal;}
function FGoNextFocus(){if(nextFocus){nextFocus.focus();return true;}return false;}
function CalSetFocus(e){if(e){g_fNoCal=true;e.focus();setTimeout("EndCalFocus()", 200);}}
function EndCalFocus(){g_fNoCal=false;}

function CalDateSet(eInp,d,m,y,giveFocus)
{
	var ds=GetDateSep();
	var fmt=GetDateFmt();

	if(fmt=="mmddyy")eInp.value=m+ds+d+ds+y;
	else if(fmt=="ddmmyy")eInp.value=d+ds+m+ds+y;
	else eInp.value=y+ds+m+ds+d;
	if(!giveFocus)
	CalSetFocus(eInp);
}

var g_calShown = false;
function SetCalShown(fcshown){g_calShown=fcshown;}
var g_calCB;
function CalendarCallback(){if(g_calCB)g_calCB();}
function SetCalendarCallback(cb){g_calCB=cb;}

function GetInputDate(t)
{
	if (!t) return null;
	if(!t.length) return null;
	t=t.replace(/\s+/g,"");
	if(t.match(/[^-|\d|\.|\/]/)) return null;
	var rgt=t.split(/-|\.|\//);
	for(var i=0;i<rgt.length;i++) rgt[i]=parseInt(rgt[i],10);
	if(!rgt[1]) return null;
	var m,d,y;
	var fmt=GetDateFmt();
	if(fmt=="yymmdd")
	{
	if(!rgt[2]) return null;
	m=rgt[1];d=rgt[2];y=rgt[0];
	}
	else
	{
	if(fmt=="mmddyy"){m=rgt[0];d=rgt[1];}
	else{m=rgt[1];d=rgt[0];}//fmt=="ddmmyy"
	if(rgt[2])y=rgt[2];
	else y=DefYr(m-1,d);
	}
	m-=1;if(y<100)y+=2000;
	if(y<1601||y>4500||m<0||m>11||d<1||d>GetMonthCount(m,y))return null;
	return new Date(y,m,d);
}

var rM=new Array(12);rM[0]=rM[2]=rM[4]=rM[6]=rM[7]=rM[9]=rM[11]=31;rM[3]=rM[5]=rM[8]=rM[10]=30;rM[1]=28;
function GetMonthCount(m,y){var c=rM[m];if((1==m)&&IsLY(y))c++;return c;}
function IsLY(y){if(0==y%4&&((y%100!=0)||(y%400==0)))return true;else return false;}
function DefYr(m,d){var dt=new Date();var yC=(dt.getYear()<1000)?1900+dt.getYear():dt.getYear();if(m<dt.getMonth()||(m==dt.getMonth()&&d<dt.getDate()))yC++;return yC;}

