// JavaScript Document
var imgDir="../img/default.htm";
var mN;var dN;var dFN;var fx=-1;var fy=-1;var sA=1;var sT=0;
var ixm;var axm;var nDS;var scM;var cO=0;
var CMO,CYO,mSd,ySd,dSd,omSd,oySd,odSd,mC,yC,v1,t1,cTP,Ft;
var bpl=false;var ie=document.all;var dom=document.getElementById;var ns4=document.layers;
var today=new Date();var dW=today.getDate();var mW=today.getMonth();var yW=today.getFullYear();
var ccn=false;var sMd=false;var mnD=new Date();var o1d=new Date();var o2=new Date();
var bw=false;var thisForm=document.forms[0];
var noches=0;


function hE(eID,oD) {
if(ie) {
for(i=0;i<document.all.tags(eID).length;i++) 
{o=document.all.tags(eID)[i];if(!o||!o.offsetParent) {continue;}
oL=o.offsetLeft;oT=o.offsetTop;oP=o.offsetParent;
while(oP.tagName.toUpperCase()!="BODY") {
oL+=oP.offsetLeft;oT+=oP.offsetTop;oP=oP.offsetParent;} 
oH=o.offsetHeight;oW=o.offsetWidth;
if((oD.offsetLeft+oD.offsetWidth)<=oL);
else if((oD.offsetTop+oD.offsetHeight)<=oT); 
else if(oD.offsetTop>=(oT+oH)); 
else if(oD.offsetLeft>=(oL+oW)); 
else {o.style.visibility="hidden";}}}}

function gj(o) {
if (document.getElementById) {return document.getElementById(o);}
else if (document.all) {return document.all[o];}
else if (document.layers) {return document.layers[o];}}

function wE(eID) {
if(ie){for(i=0;i<document.all.tags(eID).length;i++){ 
o=document.all.tags(eID)[i]; 
if(!o || !o.offsetParent) {continue;}
o.style.visibility="";}}}

function SDM() {v1=setInterval("dM()",80)}
function SIM() {v1=setInterval("iM()",80)}
function iM() {if (isM()) {mSd++;if (mSd>11){mSd=0;ySd++;}bC();}else alert(axm);}
function dM() {if (isMi()) {mSd--;if (mSd<0){mSd=11;ySd--;}bC();}else alert(ixm);}
function isMi() {x=new Date((mSd+1)+"../01/default.htm"+ySd);return (mnD<x);} 
function isM() {x=new Date((mSd+1)+"../01/default.htm"+ySd);m=new Date((mnD.getMonth()+1)+"../01/default.htm"+(mnD.getFullYear()+2));return (x<m);}
function bC () {
var m1;var s1=new Date (ySd,mSd,1);var e1=new Date(ySd,mSd+1,1);
e1=new Date(e1-(24*60*60*1000));m2=e1.getDate();d1=0;d2=s1.getDay()-sA;
if (d2<0) {d2=6;}
s="<table border=0 class='body-style'><tr>";
for (i=0; i<7; i++) {s+="<td width='27' class='title-name-day' align='right'>"+dN[i]+"</td>";}
s+="</tr><tr>";
for (var i=1;i<=d2;i++ ) {s+="<td>&nbsp;</td>";}
for (d1=1;d1<=m2;d1++) {
d2++;s+="<td align=right>";var sS="normal-day-style";var p=true;
if ((d1==dW)&&(mSd==mW)&&(ySd==yW)) {sS="current-day-style";}
else if (d2%7==(sA*-1)+1) {sS="end-of-weekday-style";}
if ((d1==odSd)&&(mSd==omSd)&&(ySd==oySd)) {sS+=" selected-day-style";}
sD=new Date((mSd+1)+"/"+d1+"/"+ySd);
if (mnD>sD) {sS+=" not-selected-day-style";p=false;}
if (sD>o2) {sS+=" not-selected-day-style";p=false;}
h="";var g=/\"/g;h=h.replace(g,"&quot;");
m1="onmousemove='window.status=\""+scM.replace("[date]",CD1(d1,mSd,ySd))+"\"' onmouseout='window.status=\"\"' ";
if (p) s+="<a class='"+sS+"' "+m1+" title=\""+h+"\" href='javascript:dSd="+d1+";cC();'>&nbsp;"+d1+"&nbsp;</a>";
else s+="<a class='"+sS+"' "+m1+" title=\""+nDS+"\" >&nbsp;"+d1+"&nbsp;</a>";
s+="";if ((d2+sA)%7==sA) {s+="</tr><tr>";}}
gj("content").innerHTML=s;
//gj("spanMonth").innerHTML="&nbsp;"+mN[mSd]+"&nbsp;";
//gj("spanYear").innerHTML="&nbsp;"+ySd+"&nbsp;";
gj("spanCentro").innerHTML="&nbsp;"+mN[mSd]+"&nbsp;"+"&nbsp;"+ySd+"&nbsp;";
}
function sTD(d3) {
fC="/";aF=Ft.split(fC);aD=d3.split(fC);Tk=0;
for (i=0;i<3;i++) {
if ((aF[i]=="d") || (aF[i]=="dd")) {dSd=parseInt(aD[i], 10);Tk++;}
else if ((aF[i]=="m")||(aF[i]=="mm")) {mSd=parseInt(aD[i],10);Tk++;} 
else if (aF[i]=="yyyy") {ySd=parseInt(aD[i],10);Tk++;}}
if ((Tk!=3)||isNaN(dSd)||isNaN(mSd)||isNaN(ySd)) 
return (NaN);return(new Date(mSd+"/"+dSd+"/"+ySd));} 

function init(sLM,sRM) {
if (!ns4) {cO=(dom)?gj("clnd").style:ie?document.all.clnd:document.clnd;
h0();CMO=(dom)?gj("selectMonth").style:ie?document.all.selectMonth:document.selectMonth;
CYO=(dom)?gj("SY").style:ie?document.all.SY:document.SY;mC=false;yC=false;
s="<div id='spanLeft' class='title-style' onclick='javascript:dM()' onmouseout='clearInterval(v1);'>&laquo;</div>";
//s+="<span id='spanMonth' class='title-style'></span>&nbsp;";
//s+="<span id='spanYear' class='title-style'></span>&nbsp;";
s+="<div id='spanCentro' class='title-style'></div>";
s+="<div id='spanRight' class='title-style' onclick='iM()' onmousedown='clearTimeout(t1);t1=setTimeout(\"SIM()\",500)' onmouseup='clearTimeout(t1);clearInterval(v1)'>&raquo;</div>";
gj("caption").innerHTML=s;bpl=true;}

}

function cC() {
	h0();
	cTP.value=CD1(dSd,mSd,ySd);
	if (sMd) {
		dP=new Date((mSd+1)+"/"+dSd+"/"+ySd);
		//gj("chkday_in").innerHTML=dFN[(dP.getDay()-sA==-1)?6:(dP.getDay()-sA)]+"&nbsp;"+dSd+"&nbsp;"+mN[mSd]+"&nbsp;"+ySd;
		//ponFecha();
		return;
	}
	if (ccn) {
		dP=new Date((mSd+1)+"/"+dSd+"/"+ySd);
		noches=(-Math.floor((o1d.getTime()-dP.getTime()+10800000)/(1000*60*60*24)));
		//gj("chkday_out").innerHTML=dFN[(dP.getDay()-sA==-1)?6:(dP.getDay()-sA)]+"&nbsp;"+dSd+"&nbsp;"+mN[mSd]+"&nbsp;"+ySd;
	}else{
	dP=new Date((mSd+1)+"/"+dSd+"/"+ySd);
		//gj("chkday_in").innerHTML=dFN[(dP.getDay()-sA==-1)?6:(dP.getDay()-sA)]+"&nbsp;"+dSd+"&nbsp;"+mN[mSd]+"&nbsp;"+ySd;
		t=dP.getTime()+(86400000*parseInt(noches))+10800000;
		dP=new Date(t);
		thisForm.ffin.value=CD1(dP.getDate(),dP.getMonth(),dP.getFullYear());
	//gj("chkday_out").innerHTML=dFN[(dP.getDay()-sA==-1)?6:(dP.getDay()-sA)]+"&nbsp;"+dP.getDate()+"&nbsp;"+mN[dP.getMonth()]+"&nbsp;"+dP.getFullYear();
	}
	ponFecha();
}

function h0() {
	cO.visibility="hidden";
	if (CMO != null){CMO.visibility="hidden"}
	if (CYO != null){CYO.visibility="hidden"}
	wE('SELECT');wE('APPLET');
}

function p0(num) {return(num<10)?'0'+num:num;}

function CD1(d,m,y) {
var s=Ft;s=s.replace ("dd","<e>");s=s.replace ("d","<d>");
s=s.replace ("<e>",p0(d));s=s.replace ("<d>",d);s=s.replace ("mmm","<o>");
s=s.replace ("mm","<n>");s=s.replace ("m","<m>");s=s.replace ("<m>",m+1);
s=s.replace ("<n>",p0(m+1));s=s.replace ("<o>",mN[m]);return s.replace ("yyyy",y);
}


function popUpCalendar(extForm, ctl, ctl2, ctlx, ft6, mNe, dNe, dFNe,xd3,isOut,dmx,nsx,mrx,arx,s8) { 
	var l7=0;var t7=0;mN=mNe;dN=dNe;dFN=dFNe;nDS=nsx;scM=dmx;ccn=isOut;axm=arx;ixm=mrx;sMd=s8;thisForm=extForm;
	if (bpl) {
		if (cO.visibility=="hidden") {
			cTP=ctl2;Ft=ft6;f8="/";
			aF=Ft.split(f8);
			if (aF.length<3) {
					f8="";}
			Tk=0;
		if (f8!="") {aD=ctl2.value.split(f8);m3=xd3.split(f8);if (!s8) oid=ctlx.value.split(f8);
		for (i=0;i<3;i++) {
if ((aF[i]=="d")||(aF[i]=="dd")){dSd=parseInt(aD[i],10);dx=parseInt(m3[i],10);if (!s8) ois=parseInt(oid[i],10);Tk++;}
else if ((aF[i]=="m")||(aF[i]=="mm")) {mSd=parseInt(aD[i],10)-1;mx=parseInt(m3[i],10);if (!s8) mos=parseInt(oid[i],10);Tk++;}
else if (aF[i]=="yyyy") {ySd=parseInt(aD[i],10);yx=parseInt(m3[i],10);if (!s8) yos=parseInt(oid[i],10);Tk++;}}}

if ((Tk!=3)||isNaN(dSd)||isNaN(mSd)||isNaN(ySd)) {
	dSd=today.getDate();
	mSd=today.getMonth();
	ySd=today.getFullYear();
	}
mnD=new Date(mx+"/"+dx+"/"+yx);
if (!s8) o1d=new Date(mos+"/"+ois+"/"+yos);
if (ccn) o2=new Date((mos)+"/"+(ois+30)+"/"+yos);
else o2=new Date((mx+1)+"/"+dx+"/"+(yx+2));

odSd=dSd;
omSd=mSd;
oySd=ySd;
aTag=ctl;
//alert(ctl.offsetTop);
//do {aTag=aTag.offsetParent;l7+=aTag.offsetLeft;t7+=aTag.offsetTop;
//	alert(l7);
//	} 
//while (aTag.tagName!="body");
//alert("DD");
//cO.left=fx==-1?ctl.offsetLeft+l7:fx;
//cO.top=fy==-1?ctl.offsetTop+t7+ctl.offsetHeight+2-115:fy;
bC(1,mSd,ySd);
cO.visibility=(dom||ie)?"visible":"show";
//hE('SELECT',gj("clnd"));
hE('APPLET',gj("clnd"));
bw=true;
}
}
else {init();popUpCalendar(thisForm, ctl, ctl2, ctlx, ft6, mN,dNe,dFNe,xd3,isOut,dmx,nsx,mrx,arx,s8);}
}

if (!ie)
	document.onclick=hidecal2();

function hidecal2() {
	if (!bw) {
		h0();
		}
	bw=false;
}
function ponFecha(){
	if (HayObjeto('fini')){
		ponNoches();
	}
}

function HayObjeto(este){
    //Comprobar si un objeto existe
	d=document;
	for (i=0;i<d.forms.length;i++){
		for (y=0;y<d.forms[i].length;y++){
			x=d.forms[i][y].name;
			if (x==este)
    	        return true;
		}
	}
    return false;
}
function ponNoches() {
	//Restar las fechas para saber dias introducidos
	fi=document.fb.fini.value;
	ff=document.fb.ffin.value;
	ano=ff.substring(6,10);
	mes=ff.substring(3,5)-1;
	dia=ff.substring(0,2);
	da1=new Date(fi.substring(6,10),fi.substring(3,5)-1,fi.substring(0,2));
	if (da1<frelease){
		dia=frelease.getDate();
		dia=dia.toString();
		if (dia.length==1)
			dia="0"+dia;
		elmes=frelease.getMonth()+1;
		mes=elmes.toString();
		if (mes.length==1)
			mes="0"+mes;
		/*alert("Release: "+dia+"/"+mes+"/"+frelease.getFullYear());
		document.fb.fini.value=dia+"/"+mes+"/"+frelease.getFullYear();
		document.fb.txtdias.value="***";*/
		return;
	}
    da2=new Date(ano,mes,dia);
  if (da1>=da2 )
    document.fb.txtdias.value="***";
  else
  	{
	//noches=parseInt((da2-da1)/86400000+1)-1;
	dife=da2.getTime() - da1.getTime()+10800000; //se aņade  10800000 pa evitar el error de marzo
	bnoches=parseInt(dife/ (1000 * 60 * 60 * 24));
	}
}

frelease=new Date();
hoyEd=new Date();
diaEd=hoyEd.getDate();
diaEd=diaEd.toString();
if (diaEd.length==1)
	diaEd="0"+diaEd;
mesEd=hoyEd.getMonth()+1;
mesEd=mesEd.toString();
if (mesEd.length==1)
	mesEd="0"+mesEd;
	
inicioEd = new Date(Date.UTC(hoyEd.getFullYear(),mesEd-1,diaEd,0,0,0));
		diaiEd=inicioEd.getDate();
		diaiEd=diaiEd.toString();
		if (diaiEd.length==1)
			diai="0"+diaiEd;
		mesiEd=inicioEd.getMonth()+1;
		mesiEd=mesiEd.toString();
		if (mesiEd.length==1)
			mesiEd="0"+mesiEd;

			
fhoy=diaiEd+"/"+mesiEd+"/"+inicioEd.getFullYear();



