function buildCal(m, y, cM, cH, cDW, cD, brdr){
	mesPedido=m;
	anioPedido=y;
	var mn=['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
	
	var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
	//oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st
	
	// Conversion a fecha castellana
	oD.od=oD.getDay(); //DD replaced line to fix date bug when current day is 31st
	if (oD.od==0) oD.od=7;
	
	var todaydate=new Date() //DD added
	var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
	//var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? 30 : 0 //DD added
	dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
	var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
	t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
	//for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
	for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"LMXJVSD".substr(s,1)+'</td>';
	t+='</tr><tr align="center">';
	weekDay=0;

	//12062007 Jonathan Parche para los viernes
	viernes=false;
	if (todaydate.getDay()==5) viernes=true;

	ultimoDia=getLastDayInMonth(todaydate);
	diaHoy=todaydate.getDate();
	mesActual=todaydate.getMonth()+1;
	anioActual=todaydate.getFullYear();
	pintames=false;	
	hoy=false;
	masdos=0;
	margen=2;

	for(i=1;i<=42;i++){
		weekDay=weekDay+1;
		//alert((weekDay)%7+'  -  '+weekDay);
		if((weekDay)%7==1) weekDay=1;
		
		var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
		fullDate = x+'/'+m+'/'+y;
		if (x==scanfortoday) {
			x='<span id="today">'+x+'</span>' //DD added
			hoy=true;
		}

		//Controlamos el cambio de mes
		//Ultimo dia de mes - 1 dia del mes siguiente deshabilitado
		if (ultimoDia==diaHoy && viernes==false && x==1 && (mesActual==mesPedido-1 || (anioPedido>anioActual && mesPedido==1))) {
			hoy=true;
			masdos++;
		}
		//Ultimo dia de mes, viernes - 2 dias del mes siguiente deshabilitados
		if (ultimoDia==diaHoy && viernes && x==1 && (mesActual==mesPedido-1 || (anioPedido>anioActual && mesPedido==1))) {
			hoy=true;
			masdos++;
		}
		//Penultimo dia de mes, viernes - 1 dia del mes siguiente deshabilitado
		if (ultimoDia-1==diaHoy && viernes && x==1 && (mesActual==mesPedido-1 || (anioPedido>anioActual && mesPedido==1))) {
			hoy=true;
			masdos++;
			masdos++;
		}
		//Cualquier otro dia del mes - habilitados todos los dias
		if ((ultimoDia-1>diaHoy && mesActual==mesPedido-1) || (anioPedido>anioActual && mesPedido>1)) pintames=true;

		if (hoy) masdos++;	

		if (viernes) margen=3;
		
		if (masdos>margen || mesPedido>mesActual+1 || pintames)  {
			t+='<td class="'+cD+'"><a href="#" onClick="javascript:addSrcToDestList(\''+fullDate+'\',\''+weekDay+'\')" class="linkNone">'+x+'</a></td>';
		}
	//Fin modificacion

		else {
			t+='<td class="'+cD+'">'+x+'</td>';
		}
		if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
	}
	return t+='</tr></table></div>';
}
function addSrcToDestList(src,weekDay) {
destList = window.document.getElementById('cmbdias');
var len = destList.length;
if (src != "") {
var found = false;
for(var count = 0; count < len; count++) {
	if (destList.options[count] != null) {
		if (src == destList.options[count].text) {
			found = true;
			break;
        }
     }
}
if (found != true) {
destList.options[len] = new Option(src,weekDay+':'+src,1,1); 
len++;
         }
      }   
}

//Jonathan 14062007 - Funcion para sacar el ultimo dia del mes
function getLastDayInMonth(dt){ 
var lastDay = new Date(dt.getFullYear(), dt.getMonth()+1, 0); 
return lastDay.getDate(); 
}

/*ORIGINAL SIN MODIFICAR*/
/*function buildCal(m, y, cM, cH, cDW, cD, brdr){
	var mn=['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
	
	var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
	//oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st
	
	// Conversion a fecha castellana
	oD.od=oD.getDay(); //DD replaced line to fix date bug when current day is 31st
	if (oD.od==0) oD.od=7;
	
	var todaydate=new Date() //DD added
	var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
	
	dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
	var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
	t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
	//for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
	for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"LMXJVSD".substr(s,1)+'</td>';
	t+='</tr><tr align="center">';
	weekDay=0;
	for(i=1;i<=42;i++){
		weekDay=weekDay+1;
		//alert((weekDay)%7+'  -  '+weekDay);
		if((weekDay)%7==1) weekDay=1;
		
		var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
		fullDate = x+'/'+m+'/'+y;
		if (x==scanfortoday) {
			x='<span id="today">'+x+'</span>' //DD added
		}
		t+='<td class="'+cD+'"><a href="#" onClick="javascript:addSrcToDestList(\''+fullDate+'\',\''+weekDay+'\')" class="linkNone">'+x+'</a></td>';
		if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
	}
	return t+='</tr></table></div>';
}
function addSrcToDestList(src,weekDay) {
destList = window.document.getElementById('cmbdias');
var len = destList.length;
if (src != "") {
var found = false;
for(var count = 0; count < len; count++) {
	if (destList.options[count] != null) {
		if (src == destList.options[count].text) {
			found = true;
			break;
        }
     }
}
if (found != true) {
destList.options[len] = new Option(src,weekDay+':'+src,1,1); 
len++;
         }
      }   
}*/

