// JavaScript Document

//Funcion para la rotacion de imagenes
function imgRotate()
{
	var url = "http://public.cwpanama.net/~conperu/";
	var imgs = new Array("images/layout/conperu_lay1_04.jpg", "images/layout/conperu_lay1_04.jpg", "images/layout/conperu_lay2_04.jpg", "images/layout/conperu_lay3_04.jpg", "images/layout/conperu_lay4_04.jpg", "images/layout/conperu_lay5_04.jpg", "images/layout/conperu_lay6_04.jpg", "images/layout/conperu_lay7_04.jpg", "images/layout/conperu_lay8_04.jpg");
	var current = Math.round(Math.random()*imgs.length);
	
	if(current>8 || current<0)
	{
		current=0;	
	}
	
	document.write('<img src="' + url + imgs[current] + '" width="175" height="103">');
}

//Funcion para establecer los horarios de atencion
function scheduler(option)
{
	var today = new Date();
	var result = "";
	
	switch(option)
	{
		case "year":
			result = today.getFullYear();
		break;
		
		case "satSched":
			var satSched = new Array();
			var monthList = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
			var freeDays = new Array("1,9", "0", "0", "0", "1", "0", "0", "0", "0", "0", "2,3,4,5,10,28", "8,24,25,31");
			
			var isSat = false;
			var curMonth = 0;
			var curFreeSet = "";
			
			for(ml=0;ml<monthList.length;ml++)
			{
				satSched[ml] = new Array(ml, monthList[ml], 1, 0, freeDays[ml]);
			}
			
			for(i=0;i<monthList.length;i++)
			{
				today.setDate(1);
				today.setMonth(i);
				curMonth = today.getMonth();
				curFreeSet = freeDays[i].split(",");
				
				//Encontrando el primer sabado de cada mes
				while(isSat==false)
				{
					if(today.getDay()==6)
					{
						//alert(curFreeSet.length);
						//Checking if is not an freeday
						for(fs=0;fs<curFreeSet.length;fs++)
						{
							//alert("Comparing: " + curFreeSet[fs] + "==" + today.getDate());
							
							if(curFreeSet[fs]==today.getDate())
							{
								satSched[i][2] = today.getDate();					
								isSat = true;
								break;
							}
							else
							{
								satSched[i][3] = 1;			
								satSched[i][2] = today.getDate();					
								isSat = true;
								//alert(today);
								//break;
							}
						}
					}
					else
					{
						if(today.getMonth()==curMonth)
						{
							today.setDate(today.getDate() + 1);
							isSat = false;
						}
						else
						{
							isSat = true;
						}
					}
				}
				
				isSat = false;
				curFreeSet = new Array();
			}
		//Construyendo el string para enviar la data del calendario
		var htmlCode = "";
		htmlCode = htmlCode + '<ul type="disc" style="text-transform:uppercase;">';
		
		for(hct=0;hct<satSched.length;hct++)
		{
			if(satSched[hct][3]==1)
			{
				htmlCode = htmlCode + '<li class="text">' + satSched[hct][1] + ' ' + satSched[hct][2] + '</li>';
			}
		}
		
		htmlCode = htmlCode + '</ul>';
		
		result = htmlCode;
		break;
	}
	
	return result;
}
