///////////////////////////////////
//    ESTRUCTURA DEL FORM        // 
///////////////////////////////////

function botones(tipo)
{
	if(tipo=="proyecto")
		var modif = {type:"button", name:"baseline", value:"Baseline", offsetLeft:20, offsetTop:10};
	else
		var modif = {type:"button", name:tipo+"modificar", value:"Modificar", offsetLeft:20, offsetTop:10};
	
	var botones = {type:"block", width: 800, list:[
					{type:"button", name:tipo+"agregar", value:"Agregar", offsetLeft:440, offsetTop:10},
					{type:"newcolumn"},
					modif,
					{type:"newcolumn"},
					{type:"button", name:tipo+"eliminar", value:"Eliminar", offsetLeft:20, offsetTop:10}
				  ]};
	return botones;
}

function strucForm(){
	var struc = [
		{type:"settings", inputWidth:150, labelWidth:200},
		{type:"fieldset", name:"frbuscar", width:880, list:[
			{type:"label", label:"Reporte de Programas", labelWidth:500},
			{type:"combo", name:"agenciab", label:"Departamento:", inputWidth:300},
			{type:"combo", name:"entidadb", label:"Entidad:", inputWidth:300},
			{type:"combo", name:"codigob", label:"C&oacute;digo del Programa:", inputWidth:300},
			{type:"block", width: 800, list:[
					{type:"button", name:"reportar", value:"Reportar", offsetLeft:160, offsetTop:10},
					{type:"newcolumn"},
					{type:"button", name:"nueva", value:"Crear Nuevo", offsetLeft:20, offsetTop:10},
					{type:"newcolumn"},
					{type:"button", name:"eliminar", value:"Eliminar", offsetLeft:20, offsetTop:10}
			]}
		]},
		{type:"fieldset", name:"frinversion", width:880, list:[
			{type:"label", label:"Formulario Cabecera de Programas TIC", labelWidth:500},
			{type:"fieldset", name:"general", label:"Datos Generales", width:840, list:[
				{type:"input", name:"codigo", label:"C&oacute;digo del Programa:", inputWidth:200, required:true, maxLength:30},
				{type:"calendar", name:"fechaalta", label:"Fecha de Alta:", required:true, readonly:true},
				{type:"combo", name:"agencia", label:"Departamento:", inputWidth:300, required:true},
				{type:"combo", name:"entidad", label:"Entidad:", inputWidth:300, required:true},
				{type:"combo", name:"tipo", label:"Tipo:", inputWidth:300, required:true},
				{type:"combo", name:"funcion", label:"Categor&iacute;a Funcional:", inputWidth:300, required:true},
				{type:"input", name:"nombre", label:"Nombre del Programa:", inputWidth:300, required:true},
				{type:"input", name:"descripcion", label:"Descripci&oacute;n del Programa:", inputWidth:300, rows:3},
				{type:"input", name:"responsablenombre", label:"Nombre del Responsable:", inputWidth:300},
				{type:"combo", name:"estado", label:"Estado:", inputWidth:200, required:true},
				{type:"block", width: 800, list:[
					{type:"button", name:"guardar", value:"Guardar Cambios", offsetLeft:200, offsetTop:20},
						{type:"newcolumn"},
						{type:"button", name:"cancelar", value:"Regresar", offsetLeft:20, offsetTop:20}
				]}
			]},
			{type:"fieldset", name:"frpresupuestos", label:"Presupuesto Asignado", width:840, list:[
				{type: "container", name: "presupuestosgrid", label: "", inputWidth:800, inputHeight:100},
				botones("presupuesto")
			]},
			{type:"fieldset", name:"frcontrataciones", label:"Contrataciones", width:840, list:[
				{type: "container", name: "contratosgrid", label: "", inputWidth:800, inputHeight:250},
				botones("contratacion")
			]},
			{type:"fieldset", name:"frproyectos", label:"Proyectos", width:840, list:[
    			{type: "container", name: "proyectosgrid", label: "", inputWidth:800, inputHeight:250},
				botones("proyecto")
			]}
		]},
		{type:"hidden", name:"fecha"}, 
		{type:"hidden", name:"anio"},
		{type:"hidden", name:"act_tipo"},
		{type:"hidden", name:"act_id"}
	];
	return struc;
}

function formPresupuestos(lyt)
{
	var struc = [
		{type:"settings", inputWidth:100, labelWidth:150, offsetLeft:30},
		{type:"label", label:"Presupuesto Asignado", labelWidth:200},
		{type:"input", name:"anio", label:"A&ntilde;o:", required:true},
		{type:"input", name:"anterior", label:"Ejercicio Anterior:"},
		{type:"input", name:"actual", label:"Ejercicio Actual:"},
		{type:"input", name:"siguiente", label:"Ejercicio Siguiente:"},
		{type:"hidden", name:"programa"},
		{type:"hidden", name:"op", value:"presup"},
		{type:"hidden", name:"id"},
		{type:"hidden", name:"act_tipo", value:"1"},
		{type:"block", width: 330, list:[
			{type:"button", name:"presupuestoguardar", value:"Guardar", offsetLeft:30, offsetTop:20},
			{type:"newcolumn"},
			{type:"button", name:"presupuestocancelar", value:"Cancelar", offsetLeft:20, offsetTop:20}
		]}
	];
	var form = lyt.attachForm(struc);
	return form;
}

function formContratos(lyt)
{
	var struc = [
		{type:"settings", inputWidth:100, labelWidth:150, offsetLeft:30},
		{type:"label", label:"Contrato Adjudicado", labelWidth:200},
		{type:"input", name:"numero", label:"Contrato:", required:true},
		{type:"input", name:"empresa", label:"Empresa(s) Adjudicataria(s):", inputWidth:150, rows:2, required:true},
		{type:"input", name:"importe", label:"Importe:", required:true},
		{type:"calendar", name:"iniprev", label:"Inicio Previsto:", readonly:true, required:true},
		{type:"input", name:"inireal", label:"Inicio Real:", readonly:true, className:"fondogris"},
		{type:"calendar", name:"finprev", label:"Fin Previsto:", readonly:true, required:true},
		{type:"input", name:"finreal", label:"Fin Real:", readonly:true, className:"fondogris"},
		{type:"hidden", name:"programa"},
		{type:"hidden", name:"op", value:"contrat"},
		{type:"hidden", name:"id"},
		{type:"hidden", name:"act_tipo", value:"1"},
		{type:"block", width: 330, list:[
			{type:"button", name:"contratoguardar", value:"Guardar", offsetLeft:30, offsetTop:20},
			{type:"newcolumn"},
			{type:"button", name:"contratocancelar", value:"Cancelar", offsetLeft:20, offsetTop:20}
		]}
	];
	var form = lyt.attachForm(struc);
	return form;
}

function formProyectos(lyt)
{
	var struc = [
		{type:"settings", inputWidth:100, labelWidth:100, offsetLeft:30},
		{type:"label", label:"Avance de Proyectos", labelWidth:200},
		{type:"input", name:"nombre", label:"Nombre:", inputWidth:200, rows:2, required:true},
		{type:"input", name:"costo", label:"Costo:", readonly:true, className:"fondogris"},
		{type:"calendar", name:"inicio", label:"Inicio Previsto:", readonly:true, required:true},
		{type:"calendar", name:"final", label:"Final Previsto:", readonly:true, required:true},
		{type:"input", name:"inicio_ro", label:"Inicio Previsto:", readonly:true, className:"fondogris"},
		{type:"input", name:"final_ro", label:"Final Previsto:", readonly:true, className:"fondogris"},
		{type:"input", name:"cambios", label:"Cambios:", readonly:true, className:"fondogris"},
		{type:"container", name:"gdbaseline", label:"Baseline:", inputWidth:300, inputHeight:200},
		{type:"hidden", name:"baseline"},
		{type:"hidden", name:"programa"},
		{type:"hidden", name:"op", value:"proy"},
		{type:"hidden", name:"id"},
		{type:"hidden", name:"act_tipo", value:"1"},
		{type:"block", width: 330, list:[
			{type:"button", name:"proyectoguardar", value:"Guardar", offsetLeft:30, offsetTop:20},
			{type:"newcolumn"},
			{type:"button", name:"proyectocancelar", value:"Cancelar", offsetLeft:20, offsetTop:20}
		]}
	];
	var form = lyt.attachForm(struc);
	with(form)
	{
		attachEvent("onChange", function (id, value){
			switch(id)
			{
				case "inicio":
				case "final":
					gdBaseline.clearAll();
					var ini = getItemValue("inicio");
					var fin = getItemValue("final");
					if(ini && fin)
					{
						m = ini.getMonth();
						y = ini.getFullYear();
						m_diff = fin.getMonth() - ini.getMonth() + (12 * (fin.getFullYear() - ini.getFullYear()));
						for(var i=0; i<=m_diff; i++)
						{
							gdBaseline.addRow(gdBaseline.uid(),[nomMeses[m] + ' ' + y,,]);
							m += 1;
							if(m > 11)
							{
								m = 0;
								y++;
							}
						}
					}
					gdBaseline.setSizes();
					break;
			}
		});
	}
	return form;
}