// JavaScript Document 1.2

var _viewpage = "cad_visualizar.php";
var _viewflash = "cad_flashplayer.php"
var _newnode = "cad_eslabon.php"
var _savechain = "cad_admin_nuevacadena.php";
var _editchain = "cad_admin_editar_vistaprevia.php";
var _editroot = "cad_admin_editar_actprincipales.php"
var _editnode = "cad_admin_editar_actsecundarias.php";
var _newempresa = "cad_empresa.php";
var _moderaeslabon = "cad_admin_moderareslabones.php"
var _moderaempresa= "cad_admin_moderarempresas.php"
var _adminempresa = "cad_admin_mantempresas.php";
var _editempresa = "cad_admin_editar_empresas.php";
var _empresadetalle = "cad_admin_empresas_detalle.php";
var _searchchain = "cad_buscar.php";
var _eliminarcadena = "cad_admin_cadenas.php";
var _adminframework = "lis_cadena_admin";
var _clientframework = "201";
var _updatechain = "cad_admin_editar_cadenas.php";
var _productos = "productos.php";
var _editarcadenaexportacion = "cad_admin_editar_cadenas.php";

SearchExportChain = function()
{
	document.getElementById("cad_page").value = _searchchain;
	document.getElementById("cad_action").value = "search";
	document.getElementById("cad_param_01").value = document.getElementById("txtBuscar").value;
	document.getElementById("formulario").submit();
}

FSCommand_NewNode = function(chain, id, position)
{
	document.getElementById("cad_page").value = _newnode;
	document.getElementById("cad_param_01").value = chain;
	document.getElementById("cad_param_02").value = id;
	document.getElementById("formulario").submit();
}

FSCommand_NewEnterprise = function(chain, id, type)
{
	document.getElementById("cad_page").value = _newempresa;
	document.getElementById("cad_param_01").value = chain;
	document.getElementById("cad_param_02").value = id;
	document.getElementById("formulario").submit();
}

FSCommand_CheckFlashPlayer = function(isValid)
{
	if(isValid)
	{
		var id = document.getElementById("cad_tempchain").value;
		ViewExportChain(id);
	}
	else
	{
		GetUrl("cad_noflash.html");
	}
}

ViewFlashPlayer = function(_id)
{
	document.getElementById("cad_page").value = _viewflash;
	document.getElementById("cad_param_01").value = _id;
	document.getElementById("formulario").submit();
}

ViewExportChain = function(_id)
{
	document.getElementById("cad_page").value = _viewpage;
	document.getElementById("cad_param_01").value = _id;
	document.getElementById("formulario").submit();
}

SelectExportChain = function(_id,_obj)
{
	var count = document.getElementById("cad_count").value;
	document.getElementById("cad_param_01").value = _id;
	
	for(n = 0; n < count; n++)
	{
		document.getElementById("cad_" + n).style.backgroundColor = '#FAFAFA';
	}
	
	document.getElementById(_obj).style.backgroundColor = '#AED36A';
}

SaveExportChain = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarControlXValorIncorrecto("cad_titulo",""))
	{
		ShowMessage("Ingrese el titulo para la cadena.", "alert")
		document.getElementById("cad_titulo").focus();
		return;
	}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _savechain;
	document.getElementById("cad_action").value = "save";
	document.getElementById("formulario").submit();
}

EditExportChain = function(id)
{
	document.getElementById("cad_param_01").value = id;
	document.getElementById("cad_page").value = _editchain;
	document.getElementById("cad_action").value = "edit";
	document.getElementById("formulario").submit();
}
UpdateExportChain = function(idcadena)
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarControlXValorIncorrecto("cad_titulo",""))
	{
		ShowMessage("Ingrese el titulo para la cadena.", "alert")
		document.getElementById("cad_titulo").focus();
		return;
	}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _updatechain;
	document.getElementById("cad_action").value = "save";
	document.getElementById("cad_param_01").value = idcadena;
	document.getElementById("formulario").submit();
}

DeleteExportChain = function(id)
{	
	if(ShowMessage("Esta seguro de eliminar la cadena seleccionada.?", "confirm"))
	{
		document.getElementById("cad_param_01").value = id;
		document.getElementById("cad_page").value = _eliminarcadena;
		document.getElementById("cad_action").value = "delete";
		document.getElementById("formulario").submit();
	}
}

SaveExportNode = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarControlXValorIncorrecto("cad_txtnode", ""))
		{
				ShowMessage("Ingrese un nombre para el eslabón", "alert");
				document.getElementById("cad_txtnode").focus();
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _newnode;
	document.getElementById("cad_action").value = "save";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selraiz").value;
	document.getElementById("cad_param_03").value = document.getElementById("cad_orientacion").value;
	
	document.getElementById("formulario").submit();
}

ListRootNodes = function(_id)
{
	document.getElementById("cad_page").value = _newnode;
	document.getElementById("cad_param_01").value = _id;
	document.getElementById("formulario").submit();
}

ListRootInfo = function(_id)
{
	document.getElementById("cad_page").value = _editroot;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = _id;
	
	document.getElementById("formulario").submit();
}

NewRootInfo = function()
{
	document.getElementById("txtDescripcion").value = "";
	document.getElementById("txtOrden").value = "";
	document.getElementById("btnUpdate").style.visibility = '';
	document.getElementById("btnUpdate").style.display = 'none';
	document.getElementById("btnDelete").style.visibility = '';
	document.getElementById("btnDelete").style.display = 'none';
	document.getElementById("btnSave").style.visibility = 'visible';
	document.getElementById("btnSave").style.display = '';
	document.getElementById("btnCancel").style.visibility = 'visible';
	document.getElementById("btnCancel").style.display = '';
	
	document.getElementById("cad_selroot").selectedIndex = -1;
	
}
NewRootInfoCancel = function()
{
	document.getElementById("btnSave").style.visibility = '';
	document.getElementById("btnSave").style.display = 'none';
	document.getElementById("btnCancel").style.visibility = '';
	document.getElementById("btnCancel").style.display = 'none';
	document.getElementById("btnUpdate").style.visibility = 'visible';
	document.getElementById("btnUpdate").style.display = '';
	document.getElementById("btnDelete").style.visibility = 'visible';
	document.getElementById("btnDelete").style.display = '';
	document.getElementById("cad_selroot").selectedIndex = -1;
	document.getElementById("txtDescripcion").value = "";
	document.getElementById("txtOrden").value = "";	
}


SaveRootInfo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	
	if(ValidarControlXValorIncorrecto("txtDescripcion", ""))
		{
				ShowMessage("Ingrese una descripcion para la actividad principal", "alert");
				document.getElementById("txtDescripcion").focus();
				return;
		}
	if(!ShowMessage("Desea agregar esta actividad principal","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editroot;
	document.getElementById("cad_action").value = "save";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("formulario").submit();
}

UpdateRootInfo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selroot",-1))
		{
				ShowMessage("Seleccione una actividad principal", "alert");
				document.getElementById("cad_selroot").focus();
				return;
		}
	
	if(ValidarControlXValorIncorrecto("txtDescripcion", ""))
		{
				ShowMessage("Ingrese una descripcion para la actividad principal", "alert");
				document.getElementById("txtDescripcion").focus();
				return;
		}
	if(!ShowMessage("Desea actualizar la actividad principal seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editroot;
	document.getElementById("cad_action").value = "update";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("formulario").submit();
}

DeleteRootInfo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selroot",-1))
		{
				ShowMessage("Seleccione una actividad principal", "alert");
				document.getElementById("cad_selroot").focus();
				return;
		}
	if(!ShowMessage("Desea eliminar la actividad principal seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editroot;
	document.getElementById("cad_action").value = "delete";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("formulario").submit();
}

ListNodes = function(_id)
{
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = _id;
	/*if(document.getElementById("hidaction").value == "new")
		{
			document.getElementById("cad_action").value = "new";
		}*/
	document.getElementById("formulario").submit();
}

ListNodeInfo = function(_id)
{
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("cad_param_03").value = _id;
	document.getElementById("formulario").submit();
}
ListOrientationActSecundaria = function(_id)
{
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("cad_param_03").value = document.getElementById("cad_selnodo").value;
	document.getElementById("cad_param_04").value = document.getElementById("cad_orientacion").value;
	/*if(document.getElementById("hidaction").value == "new")
		{
			document.getElementById("cad_action").value = "new";
			
		}*/
	document.getElementById("formulario").submit();
}
NewNodeInfo = function()
{
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_action").value = "new";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("formulario").submit();
}

SaveNodeInfo = function()
{
	///////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selroot",-1) || ValidarListaXIndiceIncorrecto("cad_selroot",0))
		{
				ShowMessage("Seleccione una actividad principal", "alert");
				document.getElementById("cad_selroot").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtDescripcion", ""))
		{
				ShowMessage("Ingrese una descripcion para la actividad secundaria", "alert");
				document.getElementById("txtDescripcion").focus();
				return;
		}
	if(!ShowMessage("Desea agregar esta actividad secundaria","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_action").value = "save";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("formulario").submit();
}

UpdateNodeInfo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selroot",-1) || ValidarListaXIndiceIncorrecto("cad_selroot",0))
		{
				ShowMessage("Seleccione una actividad principal", "alert");
				document.getElementById("cad_selroot").focus();
				return;
		}
	if(ValidarListaXIndiceIncorrecto("cad_selnodo",-1))
	{
			ShowMessage("Seleccione una actividad secundaria", "alert");
			document.getElementById("cad_selnodo").focus();
			return;
	}
	if(ValidarControlXValorIncorrecto("txtDescripcion", ""))
		{
				ShowMessage("Ingrese una descripcion para la actividad secundaria", "alert");
				document.getElementById("txtDescripcion").focus();
				return;
		}
	if(!ShowMessage("Desea actualizar la actividad secundaria seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_action").value = "update";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("formulario").submit();
}

DeleteNodeInfo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selroot",-1) || ValidarListaXIndiceIncorrecto("cad_selroot",0))
		{
				ShowMessage("Seleccione una actividad principal", "alert");
				document.getElementById("cad_selroot").focus();
				return;
		}
	if(ValidarListaXIndiceIncorrecto("cad_selnodo",-1))
	{
			ShowMessage("Seleccione una actividad secundaria", "alert");
			document.getElementById("cad_selnodo").focus();
			return;
	}
	if(!ShowMessage("Desea eliminar la actividad secundaria seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editnode;
	document.getElementById("cad_action").value = "delete";
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("formulario").submit();
}

ListRootNodeInfo = function(_id)
{ 
	document.getElementById("cad_page").value = _newnode;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_03").value = document.getElementById("cad_orientacion").value;
	document.getElementById("cad_param_02").value = _id;

	document.getElementById("formulario").submit();
}

GetUrl = function(_url, _params)
{
	document.getElementById("cad_page").value = _url;
	
	//Asignando Parametros
	if(_params != undefined)
	{	
		for(n = 0; n < _params.length; n++)
		{
			document.getElementById("cad_param_0" + (n + 1)).value = _params[n];
		}
	}
	document.getElementById("formulario").submit();
}

GetRemoteUrl = function(_url)
{
	document.getElementById("ver_opt").value = _clientframework;
	document.getElementById("hdfOpcion").value = _url;
	document.formulario.nom_seccion.value='201';  // Rhonald ;puse esta linea de codigo pues habia una pequeña falla al subtitular la seccion mostrada, creo que no afecta a nada si pongo algun valor al control nom_seccion
	document.getElementById("formulario").submit();

}

ListEmpresaRootNodes = function(_id)
{
	document.getElementById("cad_page").value = _newempresa;
	document.getElementById("cad_param_01").value = _id;
	document.getElementById("formulario").submit();
}
ListEmpresaRootNodeInfo = function(_id)
{
	document.getElementById("cad_page").value = _newempresa;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = _id;
	document.getElementById("formulario").submit();
}
SaveEmpresa = function()
{
	////////////////////////////////////////////////////
	// Validacion  
	 if(ValidarControlXValorIncorrecto("txtempresa",""))
	 	{
				ShowMessage("Ingrese el nombre de la empresa", "alert");
				document.getElementById("txtempresa").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtcontacto",""))
	 	{
				ShowMessage("Ingrese el nombre del contacto", "alert");
				document.getElementById("txtcontacto").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtdireccion",""))
	 	{
				ShowMessage("Ingrese la dirección de la empresa", "alert");
				document.getElementById("txtdireccion").focus();
				return;
		}
	if(ValidarListaXIndiceIncorrecto("cad_selregion",-1) || ValidarListaXIndiceIncorrecto("cad_selregion",0))
		{
				ShowMessage("Seleccione una región", "alert");
				document.getElementById("cad_selregion").focus();
				return;
		} 
	////////////////////////////////////////////////////
	if(!ShowMessage("Desea guardar los datos de la empresa","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	
	document.getElementById("cad_page").value = _newempresa;
	document.getElementById("cad_action").value = "save";
	document.getElementById("formulario").submit();
}
ListOrientation = function(_id)
{
	document.getElementById("cad_page").value = _newnode;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selroot").value;
	document.getElementById("cad_param_03").value = _id;
	document.getElementById("formulario").submit();
}
ListOrientationEslabon = function(_id)
{
	document.getElementById("cad_page").value = _newnode;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_selraiz").value;
	document.getElementById("cad_param_03").value = _id;
	document.getElementById("formulario").submit();
}

ListDetalleNodo = function(_id)
{
	
	document.getElementById("cad_page").value = _moderaeslabon;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selnodo").value.split(",")[0];
	document.getElementById("cad_param_02").value = document.getElementById("cad_selnodo").value.split(",")[1];
	document.getElementById("cad_param_03").value = document.getElementById("cad_selnodo").value.split(",")[2];
	document.getElementById("formulario").submit();
}
SaveModeradorEslabon = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selnodo",-1))
		{
				ShowMessage("Seleccione una actividad secundaria", "alert");
				document.getElementById("cad_selnodo").focus();
				return;
		}
	////////////////////////////////////////////////////
	if(!ShowMessage("Desea aprobar la actividad secundaria seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	document.getElementById("cad_page").value = _moderaeslabon;
	document.getElementById("cad_action").value = "save";
	document.getElementById("formulario").submit();
}

DeleteModeradorEslabon = function()
{
	if(ValidarListaXIndiceIncorrecto("cad_selnodo",-1))
		{
				ShowMessage("Seleccione una actividad secundaria", "alert");
				document.getElementById("cad_selnodo").focus();
				return;
		}
	if(!ShowMessage("Desea eliminar la actividad secundaria seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	document.getElementById("cad_page").value = _moderaeslabon;
	document.getElementById("cad_action").value = "delete";
	document.getElementById("formulario").submit();
}

ListDetalleEmpresa = function(_id)
{
	document.getElementById("cad_page").value = _moderaempresa;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selempresas").value;
	document.getElementById("formulario").submit();
}
SaveModeradorEmpresa = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selempresas",-1))
		{
				ShowMessage("Seleccione una empresa propuesta", "alert");
				document.getElementById("cad_selempresas").focus();
				return;
		}
	////////////////////////////////////////////////////
	if(!ShowMessage("Desea aprobar la empresa seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	document.getElementById("cad_page").value = _moderaempresa;
	document.getElementById("cad_action").value = "save";
	document.getElementById("formulario").submit();
}

DeleteModeradorEmpresa = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selempresas",-1))
		{
				ShowMessage("Seleccione una empresa propuesta", "alert");
				document.getElementById("cad_selempresas").focus();
				return;
		}
	if(!ShowMessage("Desea eliminar la empresa seleccionada","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	////////////////////////////////////////////////////
	
	document.getElementById("cad_page").value = _moderaempresa;
	document.getElementById("cad_action").value = "delete";
	document.getElementById("formulario").submit();
}
ListAdminDetalleEmpresa = function(_id)
{
	document.getElementById("cad_page").value = _adminempresa;
	document.getElementById("cad_param_01").value = document.getElementById("cad_selempresas").value;
	document.getElementById("formulario").submit();
}

SaveAdminEmpresa = function()
{
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selempresas",-1))
		{
				ShowMessage("Seleccione una empresa", "alert");
				document.getElementById("cad_selempresas").focus();
				return;
		}

	 if(ValidarControlXValorIncorrecto("txtEmpresa",""))
	 	{
				ShowMessage("Ingrese el nombre de la empresa", "alert");
				document.getElementById("txtEmpresa").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtContacto",""))
	 	{
				ShowMessage("Ingrese el nombre del contacto", "alert");
				document.getElementById("txtContacto").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtDireccion",""))
	 	{
				ShowMessage("Ingrese la dirección de la empresa", "alert");
				document.getElementById("txtDireccion").focus();
				return;
		}
	if(ValidarListaXIndiceIncorrecto("cad_selregion",-1))
		{
				ShowMessage("Seleccione una región", "alert");
				document.getElementById("cad_selregion").focus();
				return;
		}

	////////////////////////////////////////////////////
	if(!ShowMessage("Desea actualizar los datos de la empresa","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _adminempresa;
	document.getElementById("cad_action").value = "save";
	document.getElementById("formulario").submit();
}

DeleteAdminEmpresa = function()
{
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selempresas",-1))
		{
				ShowMessage("Seleccione una empresa", "alert");
				document.getElementById("cad_selcadena").focus();
				return;
		}
	 
	////////////////////////////////////////////////////
	if(!ShowMessage("Desea eliminar los datos de la empresa","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _adminempresa;
	document.getElementById("cad_action").value = "delete";
	document.getElementById("formulario").submit();
}
InsertAdminEmpresa = function()
{
	// Validacion

	 if(ValidarControlXValorIncorrecto("txtEmpresa",""))
	 	{
				ShowMessage("Ingrese el nombre de la empresa", "alert");
				document.getElementById("txtEmpresa").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtContacto",""))
	 	{
				ShowMessage("Ingrese el nombre del contacto", "alert");
				document.getElementById("txtContacto").focus();
				return;
		}
	if(ValidarControlXValorIncorrecto("txtDireccion",""))
	 	{
				ShowMessage("Ingrese la dirección de la empresa", "alert");
				document.getElementById("txtDireccion").focus();
				return;
		}
	if(ValidarListaXIndiceIncorrecto("cad_selregion",-1))
		{
				ShowMessage("Seleccione una región", "alert");
				document.getElementById("cad_selregion").focus();
				return;
		}

	////////////////////////////////////////////////////
	if(!ShowMessage("Desea agregar los datos de la empresa","confirm"))
		{
				ShowMessage("Operacion Cancelada","alert");
				return;
		}
	
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _adminempresa;
	document.getElementById("cad_action").value = "new";
	document.getElementById("formulario").submit();
}
NewAdminEmpresa = function()
{
	document.getElementById("cad_selempresas").selectedIndex = -1;
	document.getElementById("txtEmpresa").value = "";
	document.getElementById("txtTelefono").value = "";
	document.getElementById("txtContacto").value = "";
	document.getElementById("txtEmail").value = "";
	document.getElementById("txtDireccion").value = "";
	document.getElementById("txtWeb").value = "";
	document.getElementById("txtProducto").value = "";
	document.getElementById("cad_param_01").value = "";
	
	document.getElementById("btnSave").style.visibility = 'visible';
	document.getElementById("btnSave").style.display = '';
	document.getElementById("btnCancel").style.visibility = 'visible';
	document.getElementById("btnCancel").style.display = '';
	
	document.getElementById("btnUpdate").style.visibility = '';
	document.getElementById("btnUpdate").style.display = 'none';
	document.getElementById("btnDelete").style.visibility = '';
	document.getElementById("btnDelete").style.display = 'none';
	
	
}

CancelNewAdminEmpresa = function()
{
	document.getElementById("cad_selempresas").selectedIndex = -1;
	document.getElementById("txtEmpresa").value = "";
	document.getElementById("txtTelefono").value = "";
	document.getElementById("txtContacto").value = "";
	document.getElementById("txtEmail").value = "";
	document.getElementById("txtDireccion").value = "";
	document.getElementById("txtWeb").value = "";
	document.getElementById("txtProducto").value = "";
	document.getElementById("cad_param_01").value = "";
	
	document.getElementById("btnSave").style.visibility = '';
	document.getElementById("btnSave").style.display = 'none';
	document.getElementById("btnCancel").style.visibility = '';
	document.getElementById("btnCancel").style.display = 'none';
	
	document.getElementById("btnUpdate").style.visibility = 'visible';
	document.getElementById("btnUpdate").style.display = '';
	document.getElementById("btnDelete").style.visibility = 'visible';
	document.getElementById("btnDelete").style.display = '';
}

ListActividadesAdminEditarEmpresas = function(_id, _param1)
{
	document.getElementById("cad_page").value = _editempresa;
	document.getElementById("cad_param_01").value = _param1;
	document.getElementById("cad_param_02").value = _id;
	document.getElementById("formulario").submit();
}

VerDetalleEmpresas = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selnodo",-1))
		{
				ShowMessage("Seleccione una Actividad", "alert");
				document.getElementById("cad_selnodo").focus();
				return;
		}
	////////////////////////////////////////////////////
	GetUrl(_empresadetalle,new Array(document.getElementById("cad_selcadena").value,document.getElementById("cad_seltipo").value,document.getElementById("cad_selnodo").value));
}

SaveEmpresaNodo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_seldisponibles",-1))
		{
				ShowMessage("Seleccione la empresa a agregar", "alert");
				document.getElementById("cad_seldisponibles").focus();
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_tipo").value;
	document.getElementById("cad_param_03").value = document.getElementById("cad_nodo").value;
	document.getElementById("cad_page").value = _empresadetalle;
	document.getElementById("cad_action").value = "save";
	document.getElementById("formulario").submit();
}
DeleteEmpresaNodo = function()
{
	////////////////////////////////////////////////////
	// Validacion
	if(ValidarListaXIndiceIncorrecto("cad_selasignadas",-1))
		{
				ShowMessage("Seleccione la empresa a quitar", "alert");
				document.getElementById("cad_selasignadas").focus();
				return;
		}
	////////////////////////////////////////////////////
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_param_02").value = document.getElementById("cad_tipo").value;
	document.getElementById("cad_param_03").value = document.getElementById("cad_nodo").value;
	document.getElementById("cad_page").value = _empresadetalle;
	document.getElementById("cad_action").value = "delete";
	document.getElementById("formulario").submit();
}
CancelarEmpresaNodo = function()
{
	document.getElementById("cad_param_01").value = document.getElementById("cad_selcadena").value;
	document.getElementById("cad_page").value = _editempresa;
	document.getElementById("formulario").submit();
}
ShowMessage = function(_msg, _type)
{
	switch(_type)
	{
		case "alert":
			return alert("Cadenas de Exportación \n" + _msg);
			break;
		case "confirm":
			return confirm("Cadenas de Exportación \n" + _msg);
			break;
		case "prompt":
			return prompt("Cadenas de Exportación \n" + _msg);
			break;
	}
}
ValidarListaXIndiceIncorrecto = function(_id, _error)
{
		return (document.getElementById(_id).selectedIndex == _error);
}
ValidarControlXValorIncorrecto = function(_id, _error, _notrim)
{
		if(_notrim)
			{
				return (document.getElementById(_id).value == _error);
			}
		else
			{
				return (Trim(document.getElementById(_id).value) == _error);
			}
}

Trim = function(value) 
{
		if(value == null)
			{
					return '';
			}
		while(value.charAt(0) == ' ')
			{
					value = value.substring(1, value.length);
			}
		return value;
}

VerifyActionButtons = function(value, test)
{
	if(!value == test)
	{
		DisplayUpdateButtons();
		DisplayDeleteButtons();
	}
}

DisplaySaveButtons = function()
{
	document.getElementById("btnNew").style.visibility = 'hidden';
	document.getElementById("btnNew").style.display = 'none';
	document.getElementById("btnSave").style.visibility = 'visible';
	document.getElementById("btnSave").style.display = '';
	document.getElementById("btnCancel").style.visibility = 'visible';
	document.getElementById("btnCancel").style.display = '';
}

DisplayNewButtons = function()
{
	document.getElementById("btnNew").style.visibility = 'visible';
	document.getElementById("btnNew").style.display = '';
	document.getElementById("btnSave").style.visibility = 'hidden';
	document.getElementById("btnSave").style.display = 'none';
	document.getElementById("btnUpdate").style.visibility = 'hidden';
	document.getElementById("btnUpdate").style.display = 'none';
	document.getElementById("btnDelete").style.visibility = 'hidden';
	document.getElementById("btnDelete").style.display = 'none';
}

DisplayUpdateButtons = function()
{
	document.getElementById("btnNew").style.visibility = 'hidden';
	document.getElementById("btnNew").style.display = 'none';
	document.getElementById("btnUpdate").style.visibility = 'visible';
	document.getElementById("btnUpdate").style.display = '';
	document.getElementById("btnCancel").style.visibility = 'visible';
	document.getElementById("btnCancel").style.display = '';
}

DisplayDeleteButtons = function()
{
	document.getElementById("btnNew").style.visibility = 'hidden';
	document.getElementById("btnNew").style.display = 'none';
	document.getElementById("btnDelete").style.visibility = 'visible';
	document.getElementById("btnDelete").style.display = '';
	document.getElementById("btnCancel").style.visibility = 'visible';
	document.getElementById("btnCancel").style.display = '';
}

DisplayButton = function(id)
{
	document.getElementById(id).style.visibility = 'visible';
	document.getElementById(id).style.display = '';
}
HideButton = function(id)
{
	document.getElementById(id).style.visibility = 'hidden';
	document.getElementById(id).style.display = 'none';
}

MoveNextPage = function()
{
	var pagInicio;
	var pagFin;
	pagInicio = parseInt(document.getElementById("pagInicio").value);
	pagFin = parseInt(document.getElementById("pagFin").value);
	document.getElementById("pagInicio").value = pagInicio + 30;
	document.getElementById("pagFin").value = pagFin + 30;
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _eliminarcadena;
	document.getElementById("cad_action").value = "";
	document.getElementById("formulario").submit();
}
MovePreviousPage = function()
{
	var pagInicio;
	var pagFin;
	pagInicio = parseInt(document.getElementById("pagInicio").value);
	pagFin = parseInt(document.getElementById("pagFin").value);
	document.getElementById("pagInicio").value = pagInicio - 30;
	document.getElementById("pagFin").value = pagFin - 30;
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _eliminarcadena;
	document.getElementById("cad_action").value = "";
	document.getElementById("formulario").submit();
}
MoveNextPageProducts = function(paginado)
{
	var pagInicio;
	var pagFin;
	pagInicio = parseInt(document.getElementById("pagInicio").value);
	pagFin = parseInt(document.getElementById("pagFin").value);
	document.getElementById("pagInicio").value = pagInicio + paginado;
	document.getElementById("pagFin").value = pagFin + paginado;
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _productos;
	document.getElementById("cad_action").value = "";
	document.getElementById("formulario").submit();
}
MovePreviousPageProducts = function(paginado)
{
	var pagInicio;
	var pagFin;
	pagInicio = parseInt(document.getElementById("pagInicioProducto").value);
	pagFin = parseInt(document.getElementById("pagFinProducto").value);
	document.getElementById("pagInicioProducto").value = pagInicio - paginado;
	document.getElementById("pagFinProducto").value = pagFin - paginado;
	////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _productos;
	document.getElementById("cad_action").value = "";
	document.getElementById("formulario").submit();
}

EditarCadenaExportacion = function(idcadena)
{
		////////////////////////////////////////////////////
	document.getElementById("cad_page").value = _editarcadenaexportacion;
	document.getElementById("cad_action").value = "";
	document.getElementById("cad_param_01").value = idcadena;
	document.getElementById("formulario").submit();
}

SetPage = function(_currentpage, _totalpage, _action, _page)
{
	if(_action == "next")
	{
		if(_currentpage < _totalpage)
		{
			document.getElementById("hdfPage").value = (_currentpage + 1);
			document.getElementById("cad_page").value = _page;
			document.getElementById("cad_action").value = "";
			document.getElementById("formulario").submit();
		}
	}
	else
	{
		if(_currentpage > 1)
		{
			document.getElementById("hdfPage").value = (_currentpage - 1);
			document.getElementById("cad_page").value = _page;
			document.getElementById("cad_action").value = "";
			document.getElementById("formulario").submit();
		}
	}
	
}

