
function getObjc(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 checkClickc(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (getObjc('fcc'))
		if (!isChildc(CSE,getObjc('fcc')))
			getObjc('fcc').style.display='none';
}

function isChildc(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function Leftc(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Topc(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//document.write('.line {border-top-width: 1px;border-top-style: solid;border-top-color: 727272;}');	
document.write('<table id="fcc" border="0" style="width:170px;height:170px;position:absolute;border-collapse:collapse;background-image:url(/sitogioco/Immagini/Servizi/quadri_grey.jpg);background-repeat:no-repeat;display:none" cellpadding=2 class="claendarBorderGray">');
document.write('<tr><td style="cursor:pointer" onclick="csubmc()"><img src="/sitogioco/Immagini/Servizi/arrowleftmonth.gif"></td><td style="cursor:pointer" onclick="csubyc()"><img src="/sitogioco/Immagini/Servizi/arrowleftyear.gif"></td><td colspan="3" id="mnsc" align="center" style="font:bold 11px Verdana"></td><td align="right" style="cursor:pointer" onclick="caddyc()"><img src="/sitogioco/Immagini/Servizi/arrowrightyear.gif"></td><td align="right" style="cursor:pointer" onclick="caddmc()"><img src="/sitogioco/Immagini/Servizi/arrowrightmonth.gif"></td></tr>');
document.write('<tr><td class="lineTestCalendar" align=center style="font:12px Verdana"><strong>D</strong></td><td class="lineTestCalendar" align=center style="font:12px Verdana"><strong>L</strong></td><td class="lineTestCalendar" align=center style="font:12px Verdana"><strong>M</strong></td><td  class="lineTestCalendar" align=center style="font:12px Verdana"><strong>M</strong></td><td class="lineTestCalendar" align=center style="font:12px Verdana"><strong>G</strong></td><td class="lineTestCalendar" align=center style="font:12px Verdana"><strong>V</strong></td><td class="lineTestCalendar" align=center style="font:12px Verdana"><strong>S</strong></td></tr>');
for(var kk=1;kk<=6;kk++) {
	document.write('<tr>');
	for(var tt=1;tt<=7;tt++) {
		num=7 * (kk-1) - (-tt);
		document.write('<td id="c' + num + '" style="width:18px;height:18px">&nbsp;</td>');
	}
	document.write('</tr>');
}
document.write('<tr><td colspan="7" class="calendarLinkChiudi"><a onclick="chiudicalendarc();" style="cursor:pointer">Chiudi</a></td></tr>');
document.write('</table>');

document.all?document.attachEvent('onclick',checkClickc):document.addEventListener('click',checkClickc,false);


// Calendar script
var nowc = new Date;
var sccmc=nowc.getMonth();
var sccyxc=nowc.getFullYear();
var ccmc=nowc.getMonth();
var ccyxc=nowc.getFullYear();

//ccyxc=parseInt(ccyxc-18);//SETTO a MENO 18
//sccyxc=parseInt(sccyxc-18);//SETTO a MENO 18


var updobjc;
function lcsg(ielem) {
	updobjc=ielem;
	getObjc('fcc').style.left=Leftc(ielem)  + 'px'; 
	getObjc('fcc').style.top=Topc(ielem)+ielem.offsetHeight  + 'px';
	getObjc('fcc').style.display='';
	
	//In primo luogo verifico se la data è valida
	curdt=ielem.value;
	curdtarr=curdt.split('/');
	isdt=true;
	for(var k=0;k<curdtarr.length;k++) {
		if (isNaN(curdtarr[k]))
			isdt=false;
	}
	if (isdt&(curdtarr.length==3)) {
		ccmc=curdtarr[1]-1;
		ccyxc=curdtarr[2];
		prepcalendarc(curdtarr[0],curdtarr[1]-1,curdtarr[2]);
		
	}
	chiudialtricalendaric();
}

function evtTgtc(e)
{
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; //Safari bug
	return el;
}
function EvtObjc(e){if(!e)e=window.event;return e;}
function cs_overc(e) {
	evtTgtc(EvtObjc(e)).style.background='#7bc143'; //FFCC66
}
function cs_outc(e) {
	evtTgtc(EvtObjc(e)).style.background='transparent';//C4D3EA
}
function cs_clickc(e) {
	updobjc.value=calvalarrc[evtTgtc(EvtObjc(e)).id.substring(1,evtTgtc(EvtObjc(e)).id.length)];
	getObjc('fcc').style.display='none';
	
}

var mnc=new Array('Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic');
var mnnc=new Array('31','28','31','30','31','30','31','31','30','31','30','31');
var mnlc=new Array('31','29','31','30','31','30','31','31','30','31','30','31');
var calvalarrc=new Array(42);

function f_cpsc(obj) {
	obj.style.background='transparent'; //#ffffff sfondo tabella  C4D3EA
	obj.style.font='10px Verdana'; //Arial
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.textDecoration='none';
	//obj.style.border='1px solid #ffffff'; //bordi delle celle 6487AE
	obj.style.cursor='pointer';
}

function f_cppsc(obj) {
	//alert('barrato grigio');
	//obj.style.background='#ffffff'; //sfondo tabella  C4D3EA
	obj.style.font='10px Verdana'; //Arial
	obj.style.color='#ABABAB'; //giorni disabilitati
	obj.style.textAlign='center';
	obj.style.textDecoration='line-through';
	//obj.style.border='1px solid #ffffff'; // bordi delle celle 6487AE
	obj.style.cursor='default';
}

function f_hdsc(obj) {
	obj.style.backgroundColor ='#FFF799'; //background
	obj.style.font='bold 10px Verdana'; //Arial
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.border='1px solid #ffffff'; // bordi delle celle  6487AE
	obj.style.cursor='pointer';
}

// Giorno selezionato
function prepcalendarc(hd,cm,cy) {

	nowc=new Date();
	sd=nowc.getDate();
	td=new Date();
	td.setDate(1);
	td.setFullYear(cy);
	td.setMonth(cm);
	cd=td.getDay();
	getObjc('mnsc').innerHTML=mnc[cm]+ ' ' + cy;
	marr=((cy%4)==0)?mnlc:mnnc;
	for(var d=1;d<=42;d++) {
		f_cpsc(getObjc('c'+parseInt(d)));
		if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) {
			dip=((d-cd > sd)&&(cm==sccmc))&&(cy==sccyxc); // SCOMMENTATO 1 OTTOBRE &&(cy==sccyxc)
			htd=((hd!='')&&(d-cd==hd));
			if (dip)
				f_cppsc(getObjc('c'+parseInt(d)));
			else if (htd)
				f_hdsc(getObjc('c'+parseInt(d)));
			else
				f_cpsc(getObjc('c'+parseInt(d)));

			getObjc('c'+parseInt(d)).onmouseover=(dip)?null:cs_overc;
			getObjc('c'+parseInt(d)).onmouseout=(dip)?null:cs_outc;
			getObjc('c'+parseInt(d)).onclick=(dip)?null:cs_clickc;
			
			getObjc('c'+parseInt(d)).innerHTML=d-cd;	

			var giorno = (d-cd);
            var mese   = (cm-(-1));

            if (giorno <= 9){ 
				giorno = '0' + giorno;}           
			if (mese <= 9){ 
				mese = '0' + mese;} 
				
			calvalarrc[d]=''+(giorno)+'/'+(mese)+'/'+cy;
		}else{
			getObjc('c'+d).innerHTML='&nbsp;';
			getObjc('c'+parseInt(d)).onmouseover=null;
			getObjc('c'+parseInt(d)).onmouseout=null;
			getObjc('c'+parseInt(d)).style.cursor='default';
			}
	}
}

prepcalendarc('',ccmc,ccyxc);


function caddmc() {//Scorre di mese in mese DESTRA	
	marr=((ccyxc%4)==0)?mnlc:mnnc;
	ccmc+=1;


	if (ccmc>=12) {
		ccmc=0;
		ccyxc++;
	}
	cdayfc(); //cdayfc(); blocca il ritorno indietro
	prepcalendarc('',ccmc,ccyxc);
}

function caddyc() { //SCORRO  ANNI VERSO DESTRA 
	
	if ((ccyxc==sccyxc)&&(ccmc<=sccmc)){ //||(ccmc<sccmc)
		return;
	}else{
		(ccyxc++);
		prepcalendarc('',ccmc,ccyxc);
	}
} 

function csubmc() {  //Scorrimento di MESE in mese SINISTRA 

	marr=((ccyxc%4)==0)?mnlc:mnnc;
	ccmc-=1;
	
	if (ccmc < 0) {
		//ccmc=11;
		if(ccyxc==1900){ //((ccyx==1901)|(ccyx==1900))
			if(ccmc<=0){
				ccmc=0;
				return;
			}else{
				ccmc=11;
			}
		}else{
		
			ccmc=11;
			ccyxc=(ccyxc-1);
		}
	}

		prepcalendarc('',ccmc,ccyxc);	
		
} 


function csubyc() { //SCORRIMENTO ANNI VERSO SINISTRA
	if (ccyxc < 1901){
		return;
	}else {
		prepcalendarc('',ccmc,ccyxc=parseInt(ccyxc-1));
	}
}

function cdayfc() {

if ((ccyxc<sccyxc)|((ccyxc==sccyxc)&&(ccmc<=sccmc))){
	return;
}else {
	ccyxc=sccyxc;
	ccmc=sccmc;
	cfd=scfd;
	}
}

function chiudicalendarc() {
//getObjs('fcs').style.display='none';
//getObjs('fc').style.display='none';
getObjs('fcc').style.display='none';
}

function chiudialtricalendaric() {
getObjs('fcs').style.display='none';
getObjs('fc').style.display='none';
//getObjs('fcc').style.display='none';

}
