



function getPageObject(n)
{
	var p,i,x,d;
	d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=getPageObject(n,d.layers[i].document);
	if(!x && document.getElementById)
		x=document.getElementById(n);	
	return x;
}
function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera 
  this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera   
  this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
  this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
	this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
  this.ie = (this.ie4 || this.ie5 || this.ie6)
	this.mac=(this.agent.indexOf("mac")>-1)
	this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ns4=(!this.dom && document.layers)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
  this.usedom= this.ns6//Use dom creation
  this.reuse = this.ie||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
	return this
}
var bw=new lib_bwcheck()

function HashMap(){
	this.a = new Array();
	this.b = new Array();
	this.size = 0;
	this.put = put;
	this.get = get;
	this.keys = this.a;
	this.values = this.b;
	this.remove = remove;
	this.removeAll = removeAll;	
}
function removeAll(){
	with(this){
		a = new Array();
		b = new Array();
		size = this.a.length
		keys = this.a
		values = this.b
	}	
}

function remove(x){
	n = this.size;
	for(i=0;i<n;i++){
		if(x == this.a[i])
			break;
	}
	if(i == n)
		return;
	tKeys = new Array();
	tValues = new Array();
	count = 0
	for(j=0;j<n;j++){		
		if(j!= i){
			tKeys[count] = this.a[j]
			tValues[count] = this.b[j]
			count++;
		}
	}	
	this.a = tKeys
	this.b = tValues
	this.size = this.a.length
}

function get(x){
	n = this.size;
	for(i=0;i<n;i++){
		if(x == this.a[i])
			return this.b[i];
	}
	return null;
}
function put(x,y){
	n = this.size;
	for(i=0;i<n;i++){
		if(x == this.a[i]){
			this.b[i] = y;
			return;
		}
	}
	this.a[this.a.length] = x
	this.b[this.b.length] = y
	this.size = this.a.length;
}

var closedDates = new HashMap( );

function daysAfter(baseDate,days)
{
var bDate= new Date(baseDate);
var bTime;
bTime=bDate.getTime();
bTime+=86400000*days;
bDate.setTime(bTime);
return (bDate.getDate()+"/"+(bDate.getMonth()+1)+"/"+bDate.getYear());
	
}

function valClosedDates(depDate,days)
{
	var band=true;
	for (i=1;i<=days;i++)
	{
		if (closedDates.get(date+"/"+month+"/"+year)!=null)
			band=false;
		//alert(daysAfter(depDate,i));
	}
	return band;
}


function writeLayer(layerID,txt){
if(document.getElementById){
document.getElementById(layerID).innerHTML=txt;
}else if(document.all){
document.all[layerID].innerHTML=txt;
}else if(document.layers){
with(document.layers[layerID].document){
open();
write(txt);
close();
}
}
}

/* PopUp Calendar v2.1
© PCI, Inc.,2000 Freeware
webmaster@personal-connections.com
+1 (925) 955 1624
Permission granted for unlimited use so far
as the copyright notice above remains intact. 
Modified by Emeterio Fabian
*/
/* Settings. Please read readme.html file for instructions*/
function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} 

sDateTextSize = "10px";
sDateTextWeight = "normal";

ppcDF = "d/m/Y";
ppcMN = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
ppcWN = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
ppcWE = new Array ("Su","Mo","Tu","We","Th","Fr","Sa");

ppcER = new Array ( "Required DHTML functions are not supported in this browser.",
"Target form field is not assigned or not accessible.",
"Sorry, the chosen date is not acceptable. Please read instructions on the page.",
"Unknown error occured while executing this script.");
ppcArrow = new Array ("blue","green");
ppcColors = new Array ("#006666","#FFFFFF");
//ppcColors = new Array ("#000033","#CCCC00");
ppcTextColors = new Array ("#FFFFFF","#006666");
/* Do not edit below this line unless you are sure what are you doing! */
sCurDate = "";
sCurDateText = "";
var ppcIE=(navigator.appName == "Microsoft Internet Explorer");
var ppcNN=(bw.ns4 || bw.ns6);
var ppcSV=null; 
var ppcUC = false;
var ppcArrowInx = 0;
var ppcTipo;
var ppcTT="<table border=\"1\" width=\"130\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" bordercolorlight=\"#000000\" bordercolordark=\"#000000\">\n";
var ppcCD=ppcTT;
//var ppcFT="<font face=\"Verdana, Arial, Helvetica, sans-serif\" font-size=\""+ sDateTextSize +"\" FONT-WEIGHT:\"" + sDateTextWeight + "\" color=\"#000000\">";
var MyppcFT="<font style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px\" ";
var ppcFC=true;
var ppcINI=null;
var ppcFIN=null;
var ppcMesLimite;
var ppcTI=false;var ppcRL=null;var ppcXC=null;var ppcYC=null;
var ppcML= [31,28,31,30,31,30,31,31,30,31,30,31];
var ppcNow=new Date();
var ppcPtr=new Date();
var hoy = new Date(); 
var fin = new Date(); 
var x= 0, y = 0;
var ppcDias = 0;
function restoreLayers(e) {
if (ppcNN) {
with (window.document) {
open("text/html");
write("<html><head><title>Restoring the layer structure...</title></head>");
write("<body bgcolor=\"#EBF5EB\" onLoad=\"history.go(-1)\">");
write("</body></html>");
close();}}}
function gotoXYCal(x,y) 
{
if (ppcIE) {
var obj = getPageObject('PopUpCalendar');
obj.style.left = x;
obj.style.top = y;
}
else if (bw.ns6) {
var obj = document.getElementById('PopUpCalendar');
obj.left = x;
obj.top = y;
} 
else if (bw.ns4) {
var obj = document.layers['PopUpCalendar'];
obj.left = x;
obj.top = y;
}
} 
// no se use directamente FAFA
function getCalendar(target, color,rules,bAntes, px, py ) {
var iMonth, iDay;
var strDateArray;
ppcSV = target;
ppcRL = rules; 
ppcArrowInx = color;
ppcTipo = (bAntes== null)? 0:bAntes ;
ppcAnte = (bAntes == 1)? true:false;

//alert('jorgiro esta borracho...'+closedDates.get("uno"));


x =px; y = py;
hoy=new Date();
if (ppcFIN ==null){
if (hoy.getMonth() != 0) {
if (hoy.getDate() != 1)
fin.setFullYear(getFullYear(hoy)+1,hoy.getMonth()-1, hoy.getDate()-1);
else
fin.setFullYear(getFullYear(hoy)+1,hoy.getMonth()-2, ppcML[hoy.getMonth()-2]);
}
else fin.setFullYear(getFullYear(hoy),11, hoy.getDate()-1 );
}else {
strDateArray = ppcFIN.split('/');
if (ppcDF.charAt(0) == 'd') {// d/m/y ?
iDay = parseInt(strDateArray[0],10);
iMonth = parseInt(strDateArray[1],10) -1;
}else{ // m/d/y
iMonth = parseInt(strDateArray[0],10) -1;
iDay = parseInt(strDateArray[1],10);
}
fin.setFullYear(parseInt(strDateArray[2],10),iMonth , iDay);
}


if (ppcINI!=null)
{
strDateArray = ppcINI.split('/');
if (ppcDF.charAt(0) == 'd') {// d/m/y ?
iDay = parseInt(strDateArray[0],10);
iMonth = parseInt(strDateArray[1],10) -1;
}else{ // m/d/y
iMonth = parseInt(strDateArray[0],10) -1;
iDay = parseInt(strDateArray[1],10);
}
hoy.setFullYear(parseInt(strDateArray[2],10),iMonth , iDay);
if (ppcDias != 0){
fin = AddDays(hoy, ppcDias);
}
}
if ((x != null) && (y != null) ) {
gotoXYCal(x,y);
}

if (ppcSV.value == ""){
if (ppcINI==null) setTimeout("setCalendar(null, null, null)",15);
else setTimeout("setCalendar("+parseInt(strDateArray[2],10)+","+iMonth+", "+iDay+")",25);
}else{
strDateArray = ppcSV.value.split('/');
if (ppcDF.charAt(0) == 'd') {// d/m/y ?
iDay = parseInt(strDateArray[0],10);
iMonth = parseInt(strDateArray[1],10) -1;
}else{ // m/d/y
iMonth = parseInt(strDateArray[0],10) -1;
iDay = parseInt(strDateArray[1],10);
}
setTimeout("setCalendar("+parseInt(strDateArray[2],10)+","+iMonth+", "+iDay+")",25);
}
if ((ppcSV != null)&&(ppcSV)) {
if (ppcIE) {
var obj = getPageObject('PopUpCalendar');
obj.style.visibility = 'visible';}
else if (bw.ns6) {
var obj = document.getElementById('PopUpCalendar');
obj.style.visibility = 'visible';
} else if (bw.ns4) {
var obj = document.layers['PopUpCalendar'];
obj.visibility = 'show';
}
else {showError(ppcER[0]);}}
else {showError(ppcER[1]);}}
//----------usar estos
function getCalendarForFIN(target, fechaFIN, color,rules,bAntes, px, py ) 
{
ppcINI = null;
ppcFIN = fechaFIN;
ppcDias = 0;
getCalendar(target, color,rules,bAntes, px, py );
}
function getCalendarForINI(target, fechaINI, color,rules,bAntes, px, py ) 
{
ppcINI = fechaINI;
ppcFIN = null;
ppcDias = 0;
getCalendar(target, color,rules,bAntes, px, py );
}
function getCalendarForINI_FIN(target, fechaINI, dias, color,rules,bAntes, px, py ) 
{
ppcINI = fechaINI;
ppcFIN = null;
ppcDias = dias;
getCalendar(target, color,rules,bAntes, px, py );
}
function getCalendarForINI(target, fechaINI, color,rules,bAntes, px, py ) 
{
ppcINI = fechaINI;
ppcFIN = null;
ppcDias = 0;
getCalendar(target, color,rules,bAntes, px, py );
}
function getCalendarFor(target, color,rules,bAntes, px, py )
{
ppcINI = null;
ppcFIN = null;
getCalendar(target, color,rules,bAntes, px, py );
}

function switchMonth(param) {
var tmp = param.split("|");
setCalendar(tmp[0],tmp[1]);}
function moveMonth(dir) {
var tmp,dptrYear,dptrMonth;
tmp = sCurDate.split("|");
dptrYear = tmp[0];
dptrMonth = tmp[1];
if (dir == 'back' ){
if (ppcTipo == 0){
if ( (dptrMonth == hoy.getMonth()) && (dptrYear == getFullYear(hoy)) ) {return;}
}

dptrMonth--;
if (dptrMonth < 0) {
dptrYear--; 
dptrMonth = 11;
}

}
else {
if (ppcTipo == 0){
if ( (dptrMonth == fin.getMonth()) && (dptrYear == getFullYear(fin)) ) {return;}
}
if (ppcTipo == 1){
if ( (dptrMonth == hoy.getMonth()) && (dptrYear == getFullYear(hoy)) ) {return;}
}
dptrMonth++;
if (11 < dptrMonth) {
dptrYear++; 
dptrMonth = 0;
}

}
setTimeout("setCalendar("+dptrYear+","+dptrMonth+", 1)",15);
}
function selectDate(param) {
var arr = param.split("|");
var year = arr[0];
var month = arr[1];
var date = arr[2];
var ptr = parseInt(date);
ppcPtr.setDate(ptr);
if ((ppcSV != null)&&(ppcSV)) {
ppcSV.value = dateFormat(year,month,date); 
if ( ppcRL != null ) { //FAFA
var iDay, iMonth;
var arrRL = ppcRL.value.split("/");
if (ppcDF.charAt(0) == 'd') {// d/m/y ?
iDay = parseInt(arrRL[0],10);
iMonth = parseInt(arrRL[1],10) -1;
}else{ // m/d/y
iMonth = parseInt(arrRL[0],10) -1;
iDay = parseInt(arrRL[1],10);
}

if ( (parseInt(arrRL[2],10) != year ) ||
(iMonth < month ) ||
(iMonth == month ) && (iDay < date ) ) 
{ ppcRL.value = ppcSV.value}
} 
ppcNow.setFullYear(year, month, date);
ppcPtr.setFullYear(year, month, 1);
setTimeout("updateContent()",5);
document.getElementById('PopUpCalendar').style.visibility="hidden";
try
   {
mostrar('c1');
mostrar('c2');
mostrar('c3');
mostrar('c4'); 
   }
catch(e)
   {
	
   }

}
else {
showError(ppcER[1]);
PopUpCalendar.style.visibility="hidden"; 
}}
function setCalendar(year,month,day) {
if (year == null) {year = getFullYear(ppcNow);}
if (month == null) {month = ppcNow.getMonth();}
if (month == 1) {ppcML[1] = (isLeap(year)) ? 29 : 28;}
if (day == null ) {day = 1;}else{ppcNow.setFullYear(year, month, day); }

setSelectList(year,month);
ppcPtr.setFullYear(year, month, 1);

updateContent();}
function updateContent() {
generateContent();
writeLayer('monthDays',ppcCD);
/*
if (ppcIE) {getPageObject('monthDays').innerHTML = ppcCD;}
else if(bw.ns6){ document.getElementById('monthDays').innerHTML = ppcCD; }
else if (bw.ns4) {
with (document.layers['PopUpCalendar'].document.layers['monthDays'].document) {
open("text/html");
write("<html>\n<head>\n<title>DynDoc</title>\n</head>\n<body bgcolor=\"#EBF5EB\">\n");
write(ppcCD);
write("</body>\n</html>");
close();
}
}
else {showError(ppcER[0]);}
*/
ppcCD = ppcTT;}
function generateContent() {
var year = getFullYear(ppcPtr);
var month = ppcPtr.getMonth();
var date = 1;
var day = ppcPtr.getDay();
var len = ppcML[month];
var bgr,cnt,tmp = "";
var j,i = 0;
var FT = MyppcFT +"color=\"#009966\"> ";
ppcCD +="<table width=\"130\" bgcolor=\"#EBF5EB\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"7\"><table border=\"0\" width=\"130\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";

ppcCD +="<tr bgcolor=\"#EBF5EB\">";

ppcCD +="<td><a href=\"javascript:moveMonth('back');\"><<</a></td>";

ppcCD +="<td bgcolor=\"" + ppcColors[ppcArrowInx] + "\" width=\"100\" align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\""+ 
ppcTextColors[ppcArrowInx] + "\">"+sCurDateText+"</font></td>";
ppcCD +="<td onclick=\"moveMonth('forward');\"><a href=\"javascript:moveMonth('forward');\">>></a></td></tr>";
// ppcCD +="<tr><td colspan=\"3\" height=\"2\" bgcolor=\"#006699\"></td></tr>";
ppcCD +="</table></td></tr>";
for (j = 0; j < 7; ++j) {
tmp += "<td align='center' bgcolor='#006699'><font face='arial' size='1' color='white'>\n" + ppcWE[j]+"</font></td>";
} 
// ppcCD += "<TR align='center' bgcolor='#006699'>\n" + tmp + "</tr>\n";
ppcCD += "<TR  align='center' bgcolor=\"#EBF5EB\">\n" + tmp + "</tr>\n";
tmp = "";

for (j = 0; j < 7; ++j) {
if (date > len) {break;}
for (i = 0; i < 7; ++i) {
if (((j == 0)&&(i < day))||(date > len)) {tmp += makeCell(year,month,0);}
else {tmp += makeCell(year,month,date);++date;}}
ppcCD += "<tr class='overviewtxt'>\n" + tmp + "</tr>\n";tmp = "";}
ppcCD += "</table>\n"; 
}

function makeCell(year,month,date) {
var param = "\'"+year+"|"+month+"|"+date+"\'";
var ppcFT = MyppcFT;
var ColorNO = "color=\"#000000\"> ";
var ColorSI = "color=\"#0000FF\"> ";  
var color; 
var conLiga;

if (ppcTipo!=2)
{
conLiga = false;
if ( ("\'"+year+"."+((month<=9)?('0'+month):month)+"\'") >= ("\'"+getFullYear(hoy)+"."+ ((hoy.getMonth()<=9)?('0'+hoy.getMonth()):hoy.getMonth())+"\'" ) )
{
if ((year == getFullYear(hoy) )&& ( month == hoy.getMonth()) && ( date < hoy.getDate()) )
{ conLiga = false}
else if ( (month == fin.getMonth()) && (year == getFullYear(fin)) ) // limita a once meses
{ conLiga = (date <= fin.getDate());
}else{ conLiga = (ppcAnte && ( date == hoy.getDate()))?false: true } 
} 
if(ppcAnte){ conLiga = !conLiga}
color = conLiga ? ColorSI:ColorNO;

}else {conLiga = true; color = ColorSI;}

//Codigo Para fechas cerradas********************

if (closedDates.get(date+"/"+(month+1)+"/"+year)!=null)
{
	conLiga=false;
	color=ColorNO;
}
//Termina Codigo Para fechas cerradas********************

ppcFT = ppcFT+color;
var td1 = "<td bgcolor='#EBF5EB' align='center' valign='middle' ";
var td2 = (ppcIE || bw.ns6) ? "</font></span></td>\n" : "</font></a></td>\n";
var evt = "onMouseUp=\"this.style.backgroundColor=\'#C0C0C0\';selectDate("+param+")\" ";
var ext = "<span Style=\"cursor: hand; cursor:pointer;\">";
var lck = "<span Style=\"cursor: default\">";
var lnk = "<a href=\"javascript:selectDate("+param+")\" onMouseOver=\"window.status=\' \';return true;\">";
//var cellValue = (date != 0) ? date+""+month+""+year+"" : "&nbsp;";
var cellValue = (date != 0) ? date+"" : "&nbsp;";
if ((ppcNow.getDate() == date)&&(ppcNow.getMonth() == month)&&(getFullYear(ppcNow) == year)) {
cellValue = "<b>"+cellValue+"</b>";}

var cellCode = "";

if ( (date == 0) || !conLiga) {
if (ppcIE || bw.ns6) {cellCode = td1+"Style=\"cursor: default\">"+lck+ppcFT+cellValue+td2;}
else {cellCode = td1+">"+ppcFT+cellValue+"</font></td>\n";}}
else {
if (ppcIE || bw.ns6) {cellCode = td1+evt+"Style=\"cursor: hand\">"+ext+ppcFT+cellValue+td2;}
else {
if (date < 10) {cellValue = "&nbsp;" + cellValue + "&nbsp;";}
cellCode = td1+">"+lnk+ppcFT+cellValue+td2;}}
return cellCode;}
function setSelectList(year,month) {
var i = 0;
var obj = null;
sCurDate = year + "|" + month;
sCurDateText = ppcMN[month] + " " + year;
} 
function showError(message) { window.alert("[ PopUp Calendar ]\n\n" + message);}
function isLeap(year) {
if ((year%400==0)||((year%4==0)&&(year%100!=0))) {return true;}
else {return false;}
}
function getFullYear(obj) {
if (ppcNN) {return obj.getYear() + 1900;}
else {return obj.getYear();}}
function isEvenOrOdd(date) {
if (date - 21 > 0) {return "e";}
else if (date - 14 > 0) {return "o";}
else if (date - 7 > 0) {return "e";}
else {return "o";}}
function dateFormat(year,month,date) {
if (ppcDF == null) {ppcDF = "m/d/Y";}
var day = ppcPtr.getDay();
var crt = "";
var str = "";
var chars = ppcDF.length;
for (var i = 0; i < chars; ++i) {
crt = ppcDF.charAt(i);
switch (crt) {
case "M": str += ppcMN[month]; break;
case "m": str += (month < 9) ? ("0"+(++month)) : ++month; break;
case "Y": str += year; break;
case "y": str += year.substring(2); break;
case "d": str += ((ppcDF.indexOf("m")!=-1)&&(date< 10)) ? ("0"+date) : date; break;
case "W": str += ppcWN[day]; break;
default: str += crt;}}
return unescape(str);}
function AddDays(fecha, dias)
{
var year = getFullYear(fecha);
var month = fecha.getMonth();
var date = fecha.getDate();
var diasMes;
if (month == 1) {ppcML[1] = (isLeap(year)) ? 29 : 28;}
date += dias;
diasMes = ppcML[month];

if (date > diasMes){
if (month == 11) {
month = 0;
year += 1;
}
else month += 1;
date -= diasMes;
}
return new Date(year,month, date);
}
function getDay(someDate)
{
var temp=someDate.split("/");
if (ppcDF.charAt(0) == 'd')
return parseInt(temp[0],10);
else
return parseInt(temp[1],10);
}
function getMonth(someDate)
{
var temp=someDate.split("/");
if (ppcDF.charAt(0) == 'd')
return parseInt(temp[1],10);
else
return parseInt(temp[0],10);
}
function getYear(someDate)
{
var temp=someDate.split("/");
return parseInt(temp[2],10);
}
function MyStrToDate(someDate)
{
var day,month,year
var temp=someDate.split("/");
if (ppcDF.charAt(0) == 'd'){
day=parseInt(temp[0],10);
month=parseInt(temp[1],10)-1;
year=parseInt(temp[2],10);
}
else{
month=parseInt(temp[0],10)-1;
day=parseInt(temp[1],10);
year=parseInt(temp[2],10);
}
return Date.UTC(year, month, day); 
}	

