var _w;
function calendario(theField1){
		//verFecha(theField1);
		//defino variables para mostrar la nueva ventana
		var valor = eval("document.getElementById('"+theField1+"').value");
		var altoventana = 257;
		var anchoventana = 174;
		var y = (window.screen.height - altoventana)/2;
		var x = (window.screen.width - anchoventana)/2 ;
		//y ahora reviso que si la variable _w no se ha definido
		//o si es que existe y esta cerrada, abra una nueva ventana
		// esto verifica que la ventana este abierta
		if((_w && _w.closed) || _w == undefined) {
			_w = window.open('about:blank','Calendario','directories=no,height='+altoventana+',location=no,menubar=no,left='+x+',top='+y+',resizable=no,scrollbars=no, status=no,toolbar=no,width='+anchoventana); 
			_w.document.open();
			_w.document.write('<html><head><title>Calendario</title></head>\n');
			//escribo el html con la funcion FSCommand de flash para
			//recuperar el dato de fecha y cerrar esta misma ventana
			_w.document.write('<'+'script>\n');
			_w.document.write('var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;\n');
			_w.document.write('function calendario_DoFScommand(comando, args){ \n');
			_w.document.write('var calendarioObj = InternetExplorer ? calendario : document.calendario;');
			//le tuve que agregar este chequeo del parametro comando
			//porque sino me lo disparaba erraticamente y me pasaba
			//el valor false como resultado al campo de referencia
			//que se habia cargado en el root y que se habia tomado
			//desde la referencia del embed
			_w.document.write('		 if(comando=="comando"){\n');
			_w.document.write('		 window.opener.document.getElementById("'+theField1+'").value = args;\n');
			_w.document.write('		  window.close();\n');
			_w.document.write('}\n');
			_w.document.write('}\n');
			_w.document.write('<'+'/script>\n');
			_w.document.write('<'+'SCRIPT LANGUAGE=VBScript\> \n');
			_w.document.write('on error resume next \n');
			_w.document.write('Sub calendario_FSCommand(ByVal command, ByVal args)\n');
			_w.document.write('  call calendario_DoFSCommand(command, args)\n');
			_w.document.write('end sub\n');
			_w.document.write('<'+'/SCRIPT\> \n');
			_w.document.write('<body bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>');
			//reviso si he de pasar el parametro de fecha al flash
			//si es que el parametro existe, el flash se encarga
			//de asignarle el dia de hoy al calendario si es
			//que no se cargo ningun dato
			_w.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"      codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ID="calendario" WIDTH="174" HEIGHT="257" ALIGN=""> <PARAM NAME=movie VALUE="/Backoffice/Includes/Calendario.swf?fmanda='+valor+'"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=autohigh>\n');			
			_w.document.write(' <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="/Backoffice/Includes/Calendario.swf?fmanda='+valor+'" menu=false quality=autohigh bgcolor=#FFFFFF  WIDTH="174" HEIGHT="257" swLiveConnect=true ID="calendario" NAME="calendario" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
			_w.document.write('</body></html>');
			_w.document.close();
		}else {
			//si la ventana existe, no la creo de nuevo,
			//pero abro nuevamente el documento, lo limpio y
			//le vuelvo a cargar los valores, reescribo el 
			//htm, y luego lo pogo en foco
			_w.document.open();
			_w.document.clear();
			_w.moveTo(x,y);
			_w.document.write('<html><head><title>Calendario</title></head>\n');
			_w.document.write('<'+'script>\n');
			_w.document.write('var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;\n');
			_w.document.write('function calendario_DoFScommand(comando, args){ \n');
			_w.document.write('var calendarioObj = InternetExplorer ? calendario : document.calendario;');
			_w.document.write('		 if(comando=="comando"){\n');
			_w.document.write('		 window.opener.document.getElementById("'+theField1+'").value = args;\n');
			_w.document.write('		  window.close();\n');
			_w.document.write('}\n');
			_w.document.write('}\n');
			_w.document.write('<'+'/script>\n');
			_w.document.write('<'+'SCRIPT LANGUAGE=VBScript\> \n');
			_w.document.write('on error resume next \n');
			_w.document.write('Sub calendario_FSCommand(ByVal command, ByVal args)\n');
			_w.document.write('  call calendario_DoFSCommand(command, args)\n');
			_w.document.write('end sub\n');
			_w.document.write('<'+'/SCRIPT\> \n');
			_w.document.write('<body bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>');
			_w.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"       codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ID="calendario" WIDTH="174" HEIGHT="257" ALIGN=""> <PARAM NAME=movie VALUE="/Backoffice/Includes/Calendario.swf?fmanda='+valor+'"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=autohigh>\n');	
			_w.document.write(' <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="/Backoffice/Includes/Calendario.swf?fmanda='+valor+'" menu=false quality=autohigh bgcolor=#FFFFFF  WIDTH="174" HEIGHT="257" swLiveConnect=true ID="calendario" NAME="calendario" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
			_w.document.write('</body></html>');
			_w.document.close();
			_w.focus();
		}
	}
function verFecha(theField){
	var maxdia;
	var dParb = new Array();
	maxdia = 31;

	 // chequea para saber en base a que caracter se dividio la fecha
	dParb = theField.value.split('.');
	if (dParb.length<2){
			dParb = theField.value.split('/');
					if (dParb.length<2){
						dParb = theField.value.split('-');
					}
	}
	dPar= dParb;
	errore = "";
 //reviso que los valores sean numericos
	for (x in dPar){
		if (isNaN(dPar[x]))	errore=errore+LEN20+"\n";
	}
	if(errore==""){
	// chequea que haya menos de cuatro valores
		if(dPar.length>3){
			errore= errore+(LEN20);
			theField.select();
			theField.focus();
		}
		//recupero las variables de aņo y mes para simplificar 
		//codigo
		aDate = new Date();
		aMonth = aDate.getMonth() + 1;
		aYear = aDate.getFullYear();
		// si tengo un solo valor, o sea dia
		//le asigno el mes actual como mes
		//a no ser que el dia supere al maximo dia
		//del mes actual
		if(dPar.length<2||dPar[1]==""){
				dPar[1]=aMonth;
				dPar[2]=aYear;
		}
		if(dPar[1]>12){
			dPar[1]=12;
		}
		// se ingresaron dos valores
		if(dPar.length<3||dPar[2]==""){
				dPar[2]=aYear;
		}

		if(dPar[2] > 99){
			dPard= dPar[2].toString();
			dPar[2] = (dPard.substring(dPard.length-2,dPard.length));
		}
		// ahora creo un objeto de fecha con los valores
		cDate = new Date(dPar[2], dPar[1]-1, dPar[0]);
		// me fijo que la fecha sea valida
		if(cDate.getMonth()!=dPar[1]-1 || cDate.getDate()!=dPar[0]){
			errore= errore +(LEN20);
			theField.select();
			theField.focus();
		}
		// le devuelvo el valor formateado al campo
		// que me dispara el evento
		//chequeo para cada parte con un if statement de 
		//?*: por si es menor de 10 y hay que agregarle 
		//el 0
	}
	if(errore==""){
		//si estoy por dejar la aplicacion
		//y tengo el calendario abierto
		//lo cierro
		if(_w && !(_w==undefined)){
			_w.close();
		}
		theField.value = ((dPar[0]<10)?"0"+dPar[0]*1:dPar[0])+"/"+((dPar[1]<10)?"0"+dPar[1]*1:dPar[1])+"/"+((dPar[2]<10)?"0"+dPar[2]*1:dPar[2]);
		return true;
	}else{
		alert(errore);
		return false;
	}
}

//funcion que compara fechas
function compararFechas (valor1, valor2) {
   var dia1,dia2;
   var mes1,mes2;
   var anio1,anio2;
   var separador;
   
   //reviso cual es el separador usado en la fecha
	if (0,valor1.indexOf("-")<0){
		if (0,valor1.indexOf("/")<0){
			if (0,valor1.indexOf(".")>=0){
				separador = ".";
			}else{
				return 0;
			}
		}else{
			separador = "/";
	}
	}else{
		separador = "-";
	}


   //recupero el mes, dia y anio
   dia1 = valor1.substring (0, valor1.indexOf (separador));
   mes1 = valor1.substring (valor1.indexOf (separador)+1, valor1.lastIndexOf (separador));
   anio1 = valor1.substring (valor1.lastIndexOf (separador)+1, valor1.length);

   dia2 = valor2.substring (0, valor2.indexOf (separador));
   mes2 = valor2.substring (valor2.indexOf (separador)+1, valor2.lastIndexOf (separador));
   anio2 = valor2.substring (valor2.lastIndexOf (separador)+1, valor2.length);

   if (anio1 > anio2) return 1;
   if (anio1 < anio2) return -1;
   if (mes1 > mes2) return 1;
   if (mes1 < mes2) return -1;
   if (dia1 > dia2) return 1;
   if (dia1 < dia2) return -1;
   return 0;
} 


function datenow(format)
{
	var F = new Date();
	var dia = F.getDate().toString();
	if (dia.length == 1)
		dia = '0' +  dia;	
	var mes = (F.getMonth() + 1).toString();
	if (mes.length == 1)
		mes = '0' + mes;
	
	var Hora = F.getHours();
	var Minutos = F.getMinutes();
	var Segundos = F.getSeconds();	
	
	switch(format){
		case 0:
			var F_str = dia + "/" + mes + "/" + F.getFullYear().toString().substr(2,2);
			break;
		case 1:
			var F_str = dia + "/" + mes + "/" + F.getFullYear().toString().substr(2,2) + " " + Hora + ":" + Minutos + ":" + Segundos;
			break;
	}
	
	return F_str;
}

