function GetGL(i,t){return '<label for="' + i +'" style="cursor:default;">' + t + '</label>';}

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';}}

function HCal(e){
	var c = DE('CalFrame');
	if (c!=null){CancelCal();}}

document.onclick = HCal;


function SH1(id,s){var e = DE(id);if(s){e.style.display = 'block';}else{e.style.display = 'none';}}


function GetDowStart() {return 0;}function GetDateFmt() {return "ddmmyy";}function GetDateSep() {return "-";}
function ShowCalendar(eP,eD,eDP,dmin,dmax)
{
	SCal(eP,eD,eDP,dmin,dmax);
}

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 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('CalFrame');cF.style.visibility="hidden";g_calShown=false;}
function WaitCal()
{ 
 if(!cW)cW=frames['CalFrame'];

 if(null==cW||null==cW.g_fCL||false==cW.g_fCL){
	g_tid=setTimeout("WaitCal()", 200);
	}
 else{
 if(!cF)cF=getObj('CalFrame');
	cF.style.visibility="hidden";
	setTimeout("DoCal()",1);
	}
}
function DoCal(){PosCal(g_cP);
if(!cW)cW=frames['CalFrame'];
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('CalFrame');
	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;}

var nN = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function Mes(m){return nN[m];}

function CalDateSet(eInp,d,m,y,giveFocus)
{
	var ds=GetDateSep();
	var fmt=GetDateFmt();
	m=nN[m-1];
	if (d < 10) {d = "0" + d;}
	eInp.value=d+ds+m+ds+y;
	if(!giveFocus)
	CalSetFocus(eInp);
	CancelCal();
}

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.length) return null;
	t=t.replace(/\s+/g,"");
	var rgt=t.split(/-/);
	var m,d,y;
	m=rgt[1];d=rgt[0];y=rgt[2];

/////////////////////////////////////////////////////////////////////
			month=0;
			for (var i=0; i<nN.length; i++) {
				var month_name=nN[i];
				if (m==month_name) {
				month=i+1;
				if (month>12) { month -= 12; }
				break;
				}
				}
			if ((month < 1)||(month>12)){month=0;}
	m=month;
	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==rN.getMonth()&&d<dt.getDate()))yC++;return yC;}

function UpdDt(e)
{    
    switch(e.id)
    {
        case "play_date_from":
            var f = DE('play_date_from');
            var t = DE('play_date_to');
            break;
        default:
            var f = null;
            var t = null;
            break;
    }
    if(null!=f&&null!=t&&null!=GetInputDate(f.value)&&(null==GetInputDate(t.value)||GetInputDate(f.value)>GetInputDate(t.value))){t.value=f.value;}    
}
