var now   = new Date();

var firstyear=now.getYear()-50;  //años anteriores
var lastyear=now.getYear()+15;  //posteriores
var colour="#cccccc";//Greyed out days.
var coltoday="#FF0000";//todays colour.
var hoy= now.getDay();
var Forma;
var pWin;
var parm;
var miVent;
// onclick para dias
//-------------------------------------------------------------
function setParent(){
    pWin = top.window.opener;
}

function NuevaVentana(pasa){
var paso
var Numero = parseInt(pasa,10);
if (Numero > 5 )
//if (pasa > "5" || pasa=="10" || pasa=="11" || pasa=="12" || pasa=="13" || pasa=="14" || pasa=="15" || pasa=="16" || pasa=="17" || pasa=="18" || pasa=="19" || pasa=="20" || pasa=="21" || pasa=="22" || pasa=="23" || pasa=="24" || pasa=="25" || pasa=="26" || pasa=="27" || pasa=="28")
{
     paso = "calendario.jsp?parametro="+pasa
}else{ paso = "../calendario.jsp?parametro="+pasa }

	if (miVent==null || miVent.closed){
		miVent = window.open(paso,'mywindow','width=210,height=230,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');
        	miVent.creator = window;
	}else {
  	     miVent.close();
  	}
}

function cargafecha()
{
 Forma = document.forma1;
 Forma.semana.value=hoy;
}

function message(cell)
{
var cadena = new String(cellday[cell]);
// alert(cadena+","+cadena.length);
var dia = cadena.substring(0,2);
var mes = cadena.substring(2,4);
var anio = cadena.substring(4,8);

var fecha = new Date();

fecha.setFullYear(anio);
fecha.setMonth(mes);
fecha.setDate(dia);

var df = new DateFormat("EEEE");	// long name of the day of week
var dayOfWeek = df.format(fecha);
// objetos de Registro
if (parm == "1"){
	pWin.document.form1.inicio1.value=dia  // regresa a la forma anterior los datos
	pWin.document.form1.inicio2.value=mes
	pWin.document.form1.inicio3.value=anio
}
if (parm == "2"){
	pWin.document.form1.fin1.value=dia  // regresa a la forma anterior los datos
	pWin.document.form1.fin2.value=mes
	pWin.document.form1.fin3.value=anio
}
if (parm == "3"){
	pWin.document.form1.fe1.value=dia  // regresa a la forma anterior los datos
	pWin.document.form1.fe2.value=mes
	pWin.document.form1.fe3.value=anio
}
if (parm == "4"){
	pWin.document.form1.const1.value=dia  // regresa a la forma anterior los datos
	pWin.document.form1.const2.value=mes
	pWin.document.form1.const3.value=anio
}
if (parm == "5"){
	pWin.document.form1.insRPP1.value=dia  // regresa a la forma anterior los datos
	pWin.document.form1.insRPP2.value=mes
	pWin.document.form1.insRPP3.value=anio
}
//objetos de Cedula de Presentación
if (parm == "6"){
	pWin.document.presenta.fechaEsc1.value=dia  // regresa a la forma anterior los datos cedeula de presentacion
	pWin.document.presenta.fechaEsc2.value=mes
	pWin.document.presenta.fechaEsc3.value=anio
}
if (parm == "7"){
	pWin.document.presenta.fechaInicio1.value=dia  // regresa a la forma anterior los datos cedeula de presentacion
	pWin.document.presenta.fechaInicio2.value=mes
	pWin.document.presenta.fechaInicio3.value=anio
}
if (parm == "8"){
	pWin.document.zonas.docAreasFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.docAreasFechaMes.value=mes
	pWin.document.zonas.docAreasFechaAno.value=anio
}
if (parm == "9"){
	pWin.document.zonas.dictamenAreasFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.dictamenAreasFechaMes.value=mes
	pWin.document.zonas.dictamenAreasFechaAno.value=anio
}
if (parm == "10"){
	pWin.document.zonas.rsDocOficialFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.rsDocOficialFechaMes.value=mes
	pWin.document.zonas.rsDocOficialFechaAno.value=anio
}
if (parm == "11"){
	pWin.document.zonas.rsDictamenFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.rsDictamenFechaMes.value=mes
	pWin.document.zonas.rsDictamenFechaAno.value=anio
}
if (parm == "12"){
	pWin.document.zonas.docZonasFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.docZonasFechaMes.value=mes
	pWin.document.zonas.docZonasFechaAno.value=anio
}
if (parm == "13"){
	pWin.document.zonas.dictamenZonasFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.dictamenZonasFechaMes.value=mes
	pWin.document.zonas.dictamenZonasFechaAno.value=anio
}
if (parm == "14"){
	pWin.document.forma.fechaEstudio1.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.forma.fechaEstudio2.value=mes
	pWin.document.forma.fechaEstudio3.value=anio
}
if (parm == "15"){
	pWin.document.carga.dia5.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes5.value=mes
	pWin.document.carga.ano5.value=anio
}
if (parm == "16"){
	pWin.document.carga.vdia5.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes5.value=mes
	pWin.document.carga.vano5.value=anio
}
if (parm == "17"){
	pWin.document.carga.dia6.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes6.value=mes
	pWin.document.carga.ano6.value=anio
}
if (parm == "18"){
	pWin.document.carga.vdia6.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes6.value=mes
	pWin.document.carga.vano6.value=anio
}
if (parm == "19"){
	pWin.document.carga.dia4.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes4.value=mes
	pWin.document.carga.ano4.value=anio
}
if (parm == "20"){
	pWin.document.carga.vdia4.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes4.value=mes
	pWin.document.carga.vano4.value=anio
}
if (parm == "21"){
	pWin.document.carga.dia7.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes7.value=mes
	pWin.document.carga.ano7.value=anio
}
if (parm == "22"){
	pWin.document.carga.vdia7.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes7.value=mes
	pWin.document.carga.vano7.value=anio
}
if (parm == "23"){
	pWin.document.carga.dia1.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes1.value=mes
	pWin.document.carga.ano1.value=anio
}
if (parm == "24"){
	pWin.document.carga.vdia1.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes1.value=mes
	pWin.document.carga.vano1.value=anio
}
if (parm == "25"){
	pWin.document.carga.dia2.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes2.value=mes
	pWin.document.carga.ano2.value=anio
}
if (parm == "26"){
	pWin.document.carga.vdia2.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes2.value=mes
	pWin.document.carga.vano2.value=anio
}
if (parm == "27"){
	pWin.document.carga.dia3.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.mes3.value=mes
	pWin.document.carga.ano3.value=anio
}
if (parm == "28"){
	pWin.document.carga.vdia3.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.carga.vmes3.value=mes
	pWin.document.carga.vano3.value=anio
}
if (parm == "30"){
	pWin.document.zonas.docImpactoFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.docImpactoFechaMes.value=mes
	pWin.document.zonas.docImpactoFechaAno.value=anio
}
if (parm == "31"){
	pWin.document.zonas.dictamenImpactoFechaDia.value=dia  // regresa a la forma anterior los datos zonas en cedeula de presentacion
	pWin.document.zonas.dictamenImpactoFechaMes.value=mes
	pWin.document.zonas.dictamenImpactoFechaAno.value=anio
}
if (parm == "32"){
	pWin.document.urbano.pavFecha1.value=dia  // regresa a la forma anterior los datos urbano fecha pavimento en diseñourbano
	pWin.document.urbano.pavFecha2.value=mes
	pWin.document.urbano.pavFecha3.value=anio
}
if (parm == "33"){
	pWin.document.presenta.fechaReg1.value=dia  // regresa a la forma anterior los datos urbano fecha pavimento en diseñourbano
	pWin.document.presenta.fechaReg2.value=mes
	pWin.document.presenta.fechaReg3.value=anio
}
if (parm == "34"){
	pWin.document.carga.dia8.value=dia  // regresa a la forma anterior los datos urbano fecha pavimento en diseñourbano
	pWin.document.carga.mes8.value=mes
	pWin.document.carga.ano8.value=anio
}
if (parm == "35"){
	pWin.document.carga.vdia8.value=dia  // regresa a la forma anterior los datos urbano fecha pavimento en diseñourbano
	pWin.document.carga.vmes8.value=mes
	pWin.document.carga.vano8.value=anio
}

window.close();


// alert(dia+"/"+mes+"/"+anio);

}

// Codigo del Calendario
//--------------------------------------------------------------------------------------------

var day   = now.getDate();
var month = now.getMonth();
var year  = now.getYear();
if (year < 2000)
year = year + 1900;
var daycell=new Array();
var cellday=new Array();
var n;

// Create Calender
//-----------------


function calendar(parametro)
{
var calobj, caption
parm = parametro;
caption=' I N F O N A V I T';

calobj='<table border="1" cellspacing="0" cellpadding="0" class="calborder">';
calobj+='<tr><td>';
calobj+='<table border="0" cellspacing="0" cellpadding="0" class="calender">'
calobj+='<tr><td colspan="5" class="calcaption">'+caption+'</td></tr>';
calobj+='<tr><td colspan="3">';
calobj+='<select name="calmonth" onChange="updatecalendar()" class="caldropdowns">';
calobj+='<option>Enero<option>Febrero<option>Marzo<option>Abril<option>Mayo';
calobj+='<option>Junio<option>Julio<option>Agosto<option>Septiembre<option>Octubre';
calobj+='<option>Noviembre<option>Diciembre</select>';
calobj+='</td><td colspan="2" align="right">';
calobj+='<select name="calyear" onChange="updatecalendar()" class="caldropdowns">';

for (n=firstyear;n<lastyear;n++)
{
  if (n==year)
  {
     calobj+='<option selected value="'+n+'">'+n+'</option>';
  }
  else
  {
    calobj+='<option value="'+n+'">'+n+'</option>';
  }
}
calobj+='</select>';
calobj+='</td></tr>';
calobj+='<tr><td colspan="5" class="calinsideborder">';
calobj+='<table cellspacing="0" class="calinsidesettings" border="1">';
calobj+='<tr align="center">';
calobj+='<td class="caldays">D</td>';
calobj+='<td class="caldays">L</td>';
calobj+='<td class="caldays">M</td>';
calobj+='<td class="caldays">M</td>';
calobj+='<td class="caldays">J</td>';
calobj+='<td class="caldays">V</td>';
calobj+='<td class="caldays">S</td>';
calobj+='</tr>';

var calcell,calrow
for (calcell=0;calcell<6;calcell++)
{
calobj+='<tr><td class="calwknd" id=cal'+(calcell*7)+' onclick=message('+(calcell*7)+');></td>';
calobj+='<td class="calwkdy" id=cal'+(calcell*7+1)+' onclick=message('+(calcell*7+1)+');></td>';
calobj+='<td class="calwkdy" id=cal'+(calcell*7+2)+' onclick=message('+(calcell*7+2)+');></td>';
calobj+='<td class="calwkdy" id=cal'+(calcell*7+3)+' onclick=message('+(calcell*7+3)+');></td>';
calobj+='<td class="calwkdy" id=cal'+(calcell*7+4)+' onclick=message('+(calcell*7+4)+');></td>';
calobj+='<td class="calwkdy" id=cal'+(calcell*7+5)+' onclick=message('+(calcell*7+5)+');></td>';
calobj+='<td class="calwknd" id=cal'+(calcell*7+6)+' onclick=message('+(calcell*7+6)+');></td></tr>';
}
calobj+='</table>';
calobj+='</td></tr>';
calobj+='<tr align="center">';
calobj+='<td>';
calobj+='<input type="button" name="backyear" value="&lt;&lt;" class="calbutts" onclick=gobackyear();updatecalendar()>';
calobj+='</td>';
calobj+='<td>';
calobj+='<input type="button" name="backmonth" value="&lt;" class="calbutts" onclick=gobackmonth();updatecalendar()>';
calobj+='</td>';
calobj+='<td>';
calobj+='<input type="button" name="TODAY" value="HOY" class="calbutts" onclick=caltoday()>';
calobj+='</td>';
calobj+='<td>';
calobj+='<input type="button" name="onmonth" value="&gt;" class="calbutts" onclick=goonmonth();updatecalendar()>';
calobj+='</td>';
calobj+='<td>';
calobj+='<input type="button" name="onyear" value="&gt;&gt;" class="calbutts" onclick=goonyear();updatecalendar()>';
calobj+='</td>';
calobj+='</tr>';
calobj+='</table>';
calobj+='</td>';
calobj+='</tr>';
calobj+='</table>';

document.write(calobj)

daycell[0]=cal0;
daycell[1]=cal1;
daycell[2]=cal2;
daycell[3]=cal3;
daycell[4]=cal4;
daycell[5]=cal5;
daycell[6]=cal6;
daycell[7]=cal7;
daycell[8]=cal8;
daycell[9]=cal9;
daycell[10]=cal10;
daycell[11]=cal11;
daycell[12]=cal12;
daycell[13]=cal13;
daycell[14]=cal14;
daycell[15]=cal15;
daycell[16]=cal16;
daycell[17]=cal17;
daycell[18]=cal18;
daycell[19]=cal19;
daycell[20]=cal20;
daycell[21]=cal21;
daycell[22]=cal22;
daycell[23]=cal23;
daycell[24]=cal24;
daycell[25]=cal25;
daycell[26]=cal26;
daycell[27]=cal27;
daycell[28]=cal28;
daycell[29]=cal29;
daycell[30]=cal30;
daycell[31]=cal31;
daycell[32]=cal32;
daycell[33]=cal33;
daycell[34]=cal34;
daycell[35]=cal35;
daycell[36]=cal36;
daycell[37]=cal37;
daycell[38]=cal38;
daycell[39]=cal39;
daycell[40]=cal40;
daycell[41]=cal41;

caltoday()
updatecalendar()
}

// Set today
//-----------

function caltoday()
{
day   = now.getDate();
calmonth.selectedIndex=now.getMonth();
calyear.value=now.getYear();
updatecalendar()
}

// Refresh Cells and Dates
//-------------------------

function updatecalendar()
{
month = calmonth.selectedIndex
year  = calyear.value

var firstOfMonth = new Date (year, month, 1);
var startingPos = firstOfMonth.getDay();
var curday=1
var days=monthdays(month,year)
var prevdays=monthdays(month-1,year)
var str

for (n=0;n<42;n++)
{
  if (startingPos==n)
  {
	if (month==now.getMonth()&year==now.getYear()&curday==now.getDate())
	{
	str=curday
    daycell[n].innerHTML="<font color='"+coltoday+"'>"+str.toString()+"</font>"
	}
	else
	{
	daycell[n].innerHTML=curday
	}
	setday(n,month,year,curday);
    startingPos++
    curday++
  }
  else
  {
  	  if (startingPos==66)
	  {
	  setday(n,month+1,year,curday);
	  str=curday
 	  curday++
	  }
	  else
	  {
	  setday(n,month-1,year,prevdays-startingPos+n+1);
      str=prevdays-startingPos+n+1
	  }
      daycell[n].innerHTML="<font color='"+colour+"'>"+str.toString()+"</font>"
  }

  if (curday>days){
  curday=1
  startingPos=66
  }
}
}

// Set day variables
//-------------------

function setday(cell,month,year,day)
{
month++
if (month==13){month=1;year++}
if (month==0){month=12;year--}

var strmon;
var stryear;
var strday;

strmon=month.toString();
if (strmon.length==1){strmon="0"+strmon}
strday=day.toString();
if (strday.length==1){strday="0"+strday}
stryear=year.toString();

cellday[cell]=strday+strmon+stryear
}

// Check days in month
//---------------------

function monthdays(month,year)  {
var days;
if (month==0 || month==2 || month==4 || month==6 || month==7 || month==9 || month==11 || month==-1 || month==12)  days=31;
else if (month==3 || month==5 || month==8 || month==10) days=30;
else if (month==1)  {
if (leapyear(year)) { days=29; }
else { days=28; }
}
return (days);
}

// Check for leap year
//---------------------

function leapyear (Year) {
if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
return (true);
} else { return (false); }
}

// Forward one month
//-------------------

function goonmonth()
{
  month = calmonth.selectedIndex
  month++
  if (month==12)
  {
    month=0;
    goonyear()
  }
  calmonth.selectedIndex=month
}

// Forward one year
//------------------

function goonyear()
{
  year  = calyear.value
  year++
  if (year==lastyear){year=firstyear}
  calyear.value=year
}

// Back one month
//----------------

function gobackmonth()
{
  month = calmonth.selectedIndex
  month--
  if (month==-1)
  {
    month=11;
    gobackyear()
  }
  calmonth.selectedIndex=month
}

// Back one year
//---------------

function gobackyear()
{
  year  = calyear.value
  year--
  if (year<firstyear){year=lastyear-1}
  calyear.value=year
}

////////

function DateFormat()
{
	var argv = DateFormat.arguments;
	var argc = argv.length;

	if(argc == 0)
	{
		this.pattern = "";
		this.locale = Locale.availableLocales[Locale.DEFAULT];
	}
	else if(typeof argv[0] == "string")
	{
		this.pattern = argv[0];
		this.locale = (argc >= 2) ? argv[2] : Locale.availableLocales[Locale.DEFAULT];
	}
	else
	{
		this.locale = argc >= 3 && argv[2] ? argv[2] : Locale.availableLocales[Locale.DEFAULT];
		this.setStyle(argv[0], argc > 1 ? argv[1] : DateFormat.NONE);
	}
}

// methods ********************************************************************

function /*string*/ _DateFormat_format(/*Date*/ date)
{
	//sanity check
	if(!date)
		return "";
	if(typeof date == "string")
		date = new Date(date);

	var s = "";
	var pos = 0;
	while(pos < this.pattern.length)
	{
		var c = this.pattern.charAt(pos);
		var length;
		var symbol = DateFormat.SYMBOLS[c];

		if(symbol)
		{
			length = this._consume(pos, c);
			s += symbol.format(date, length, this.locale);
		}
		else if(c == "'")
		{
			if(pos >= this.pattern.length - 1)	// last char
			{
				length = 1;
				s += c;
			}
			else if(this.pattern.charAt(pos + 1) != "'")	// delim, not escape
			{
				var eos = this.pattern.indexOf("'", ++pos);
				if(eos == -1) eos = this.pattern.length;	// don't be anal
				length = (eos - pos) + 1;
				s += this.pattern.substring(pos, eos);
			}
			else	// escape
			{
				length = 2;
				s += c;
			}
		}
		else	// treat any other char as literal
		{
			length = 1;
			s += c;
		}

		pos += length;
	} // while

	return s;
}

function _DateFormat_setStyle(/*number*/ dateStyle, /*number*/ timeStyle)
{
	dateStyle = parseInt(dateStyle);
	timeStyle = parseInt(timeStyle);

	this.pattern = this.locale.datePattern[dateStyle];
	if(this.pattern && timeStyle)
		this.pattern += " ";
	this.pattern += this.locale.timePattern[timeStyle];
}

// private methods ************************************************************

// returns number of same chars as c in this.pattern starting with pos
function _DateFormat_consume(pos, c)
{
	var i = pos;
	while(++i < this.pattern.length)
		if(this.pattern.charAt(i) != c)
			break;
	return i - pos;
}

// pads a number with leading zeros so that it has at least l digits
function _DateFormat_formatNumber(n, l, locale)
{
	var s = "";
	var digits = (new String(n)).length;
	var zeros = Math.max(0, l - digits);
	for(var i = 0; i < zeros; i++)
		s += "0";
	return s + n;
}

function _DateFormat_formatEra(year, l, locale)
{
	var era = year < 0 ? DateFormat.BC : DateFormat.AD;
	return locale.era[era];
}

function _DateFormat_formatMonth(month, l, locale)
{
	if(l < 3)
		return DateFormat._formatNumber(month + 1, l, locale);
	else
	{
		var months = l == 3 ? locale.shortMonths : locale.longMonths;
		return months[month];
	}
}

function _DateFormat_formatWeekday(weekday, l, locale)
{
	var weekdays = l < 4 ? locale.shortWeekdays : locale.longWeekdays;
	return weekdays[weekday];
}

function _DateFormat_formatAMPM(hour, l, locale)
{
	var ampm = hour <= 12 && hour > 0 ? DateFormat.AM : DateFormat.PM;
	return locale.amPm[ampm];
}

function _DateFormat_formatTimezone(offset, l, locale)
{
	// todo localized Timezone names
	var diff = Math.abs(offset);
	var hours = DateFormat._formatNumber(parseInt(diff / 60), 2);
	var minutes = DateFormat._formatNumber(diff % 60, 2);
	return "GMT" + (offset > 0 ? "-" : "+") + hours + ":" + minutes;
}

function _DateFormat_formatMillis(date, l, locale)
{
	var date2 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
	return DateFormat._formatNumber(date.getTime() - date2.getTime(), l, locale);
}

function _DateFormat_formatYear(date, l, locale)
{
	var y = l > 2 ? date.getFullYear() : date.getYear();
	return DateFormat._formatNumber(y, l, locale);
}

DateFormat.NONE = 0;
DateFormat.SHORT = 1;
DateFormat.MEDIUM = 2;
DateFormat.LONG = 3;
DateFormat.FULL = 4;
DateFormat.NSTYLES = 5;

DateFormat.BC = 0;
DateFormat.AD = 1;

DateFormat.AM = 0;
DateFormat.PM = 1;

DateFormat._formatNumber = _DateFormat_formatNumber;
DateFormat._formatEra = _DateFormat_formatEra;
DateFormat._formatMonth = _DateFormat_formatMonth;
DateFormat._formatWeekday = _DateFormat_formatWeekday;
DateFormat._formatAmPm = _DateFormat_formatAMPM;
DateFormat._formatTimzone = _DateFormat_formatTimezone;
DateFormat._formatMillis = _DateFormat_formatMillis;
DateFormat._formatYear = _DateFormat_formatYear;

DateFormat.SYMBOLS = new Object();
DateFormat.SYMBOLS["G"] = new _DFSymbol(DateFormat._formatEra, "date.getFullYear()");
DateFormat.SYMBOLS["y"] = new _DFSymbol(DateFormat._formatYear, "date");
DateFormat.SYMBOLS["M"] = new _DFSymbol(DateFormat._formatMonth, "date.getMonth()");
DateFormat.SYMBOLS["d"] = new _DFSymbol(DateFormat._formatNumber, "date.getDate()");
DateFormat.SYMBOLS["h"] = new _DFSymbol(DateFormat._formatNumber, "date.getHours() > 12 ? date.getHours() - 12 : (date.getHours() > 0 ? date.getHours() : 12)");
DateFormat.SYMBOLS["H"] = new _DFSymbol(DateFormat._formatNumber, "date.getHours()");
DateFormat.SYMBOLS["m"] = new _DFSymbol(DateFormat._formatNumber, "date.getMinutes()");
DateFormat.SYMBOLS["s"] = new _DFSymbol(DateFormat._formatNumber, "date.getSeconds()");
DateFormat.SYMBOLS["S"] = new _DFSymbol(DateFormat._formatMillis, "date");
DateFormat.SYMBOLS["E"] = new _DFSymbol(DateFormat._formatWeekday, "date.getDay()");
DateFormat.SYMBOLS["D"] = new _DFSymbol();
DateFormat.SYMBOLS["F"] = new _DFSymbol();
DateFormat.SYMBOLS["w"] = new _DFSymbol();
DateFormat.SYMBOLS["W"] = new _DFSymbol();
DateFormat.SYMBOLS["a"] = new _DFSymbol(DateFormat._formatAmPm, "date.getHours()");
DateFormat.SYMBOLS["k"] = new _DFSymbol(DateFormat._formatNumber, "date.getHours() + 1");
DateFormat.SYMBOLS["K"] = new _DFSymbol(DateFormat._formatNumber, "date.getHours() > 11 ? date.getHours() - 12 : date.getHours()");
DateFormat.SYMBOLS["z"] = new _DFSymbol(DateFormat._formatTimezone, "date.getTimezoneOffset()");

DateFormat.prototype.format = _DateFormat_format;
DateFormat.prototype.setStyle = _DateFormat_setStyle;
DateFormat.prototype._consume = _DateFormat_consume;

// _DFSymbol ***********************************************************

// helper object
function _DFSymbol(func, value)
{
	this.func = func;
	this.value = value;
}

function _DFSymbol_format(date, l, locale)
{
	return this.func ? this.func(eval(this.value), l, locale) : "";
}

_DFSymbol.prototype.format = _DFSymbol_format;

// Locale *******************************************************************

function Locale(/*string*/ name, /*opt Locale or string*/ parent)
{
	this.name = name;
	Locale.availableLocales[this.name] = this;
	this.shortWeekdays = new Array("", "", "", "", "", "", "");
	this.longWeekdays = new Array("", "", "", "", "", "", "");
	this.shortMonths = new Array("", "", "", "", "", "", "", "", "", "", "", "");
	this.longMonths = new Array("", "", "", "", "", "", "", "", "", "", "", "");
	this.era = new Array("", "");
	this.amPm = new Array("", "");
	this.datePattern = new Array("", "", "", "", "");
	this.timePattern = new Array("", "", "", "", "");

	if(parent)
	{
		if(typeof parent == "string")
			parent = Locale.availableLocales[parent];
		copy(parent.shortWeekdays, this.shortWeekdays);
		copy(parent.longWeekdays, this.longWeekdays);
		copy(parent.shortMonths, this.shortMonths);
		copy(parent.longMonths, this.longMonths);
		copy(parent.era, this.era);
		copy(parent.amPm, this.amPm);
		copy(parent.datePattern, this.datePattern);
		copy(parent.timePattern, this.timePattern);
	}
}

function _Locale_toString()
{
	return this.name;
}

Locale.prototype.toString = _Locale_toString;
Locale.availableLocales = new Object();

// helper functions ***********************************************************

// shallow copy
function /*Object*/ copy(/*object*/ src, /*opt object*/ dst)
{
	if(!dst) dst = new Object();
	for(var prop in src)
		dst[prop] = src[prop];
	return dst;
}

// Locale definitions *********************************************************

var tmp;
Locale.DEFAULT = "en";

tmp = new Locale("en");
tmp.shortWeekdays = new Array("Su", "Mo", "Tu", "We", "Fr", "Sa");
tmp.longWeekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Friday", "Saturday");
tmp.shortMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
tmp.longMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
tmp.era = new Array("BC", "AD");
tmp.amPm = new Array("AM", "PM");
tmp.datePattern = new Array("", "M/d/yy", "MMM d, yyyy", "MMMM d, yyyy", "EEEE, MMMM d, yyyy");
tmp.timePattern = new Array("", "h:mm a", "h:mm:ss a", "h:mm:ss a z", "h:mm:ss a z");

tmp = new Locale("en_GB", "en");
tmp.datePattern = new Array("", "dd/MM/yy", "dd-MMM-yyyy", "dd MMMM yyyy", "dd MMMM yyyy");
tmp.timePattern = new Array("", "HH:mm", "HH:mm:ss", "HH:mm:ss z", "HH:mm:ss o''cloc'k' z");

tmp = new Locale("de");
tmp.shortWeekdays = new Array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
tmp.longWeekdays = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
tmp.shortMonths = new Array("Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez");
tmp.longMonths = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
tmp.era = new Array("v. Chr.", "n. Chr.");
tmp.datePattern = new Array("", "dd.MM.yy", "dd.MM.yyyy", "dd. MMMM yyyy", "d. MMMM yyyy");
tmp.timePattern = new Array("", "HH:mm", "HH:mm:ss", "HH:mm:ss z", "HH:mm:ss U'h'r z");

tmp = new Locale("de_AT", "de");
tmp.shortMonths = new Array("J&auml;n", "Feb", "M&auml;r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez");
tmp.longMonths = new Array("J&auml;nner", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");

tmp = new Locale("fr");
tmp.shortWeekdays = new Array("dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam.");
tmp.longWeekdays = new Array("dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi");
tmp.shortMonths = new Array("janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.");
tmp.longMonths = new Array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");
tmp.era = new Array("BC", "ap. J.-C.");
tmp.datePattern = new Array("", "dd/MM/yy", "d MMM yy", "d MMMM yyyy", "EEEE d MMMM yyyy");
tmp.timePattern = new Array("", "HH:mm", "HH:mm:ss", "HH:mm:ss z", "HH 'h' mm z");

tmp = new Locale("it");
tmp.shortWeekdays = new Array("dom", "lun", "mar", "mer", "gio", "ven", "sab");
tmp.longWeekdays = new Array("domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato");
tmp.shortMonths = new Array("gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "set", "ott", "nov", "dic");
tmp.longMonths = new Array("gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre");
tmp.era = new Array("BC", "dopo Cristo");
tmp.datePattern = new Array("", "dd/MM/yy", "d-MMM-yy", "d MMMM yyyy", "EEEE d MMMM yyyy");
tmp.timePattern = new Array("", "H.mm", "H.mm.ss", "HH.mm.ss z", "HH.mm.ss z");

tmp = new Locale("es");
tmp.shortWeekdays = new Array("dom", "lun", "mar", "mié", "jue", "vie", "sáb");
tmp.longWeekdays = new Array("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado");
tmp.shortMonths = new Array("ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic");
tmp.longMonths = new Array("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
tmp.era = new Array("BC", "AD");
tmp.datePattern = new Array("", "d/MM/yy", "d-MMM-yy", "d 'de' MMMM 'de' yyyy", "EEEE d 'de' MMMM 'de' yyyy");
tmp.timePattern = new Array("", "H:mm", "H:mm:ss", "HH:mm:ss z", "HH'H'mm'' z");

tmp = new Locale("pt");
tmp.shortWeekdays = new Array("Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb");
tmp.longWeekdays = new Array("Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado");
tmp.shortMonths = new Array("Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez");
tmp.longMonths = new Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
tmp.era = new Array("BC", "AD");
tmp.datePattern = new Array("", "dd-MM-yy", "d/MMM/yy", "d 'de' MMMM 'de' yyyy", "EEEE, d 'de' MMMM 'de' yyyy");
tmp.timePattern = new Array("", "H:mm", "H:mm:ss",  "HH:mm:ss z", "HH'H'mm'm' z");

