
function abreVentana(pagina, ancho, alto, oculta, nombre) {
  var arriba;
  var izquierda;
  
  if (nombre == undefined) {
  	nombre = "";
  }
  
  if (oculta) {
    arriba = screen.availHeight + 20;
    izquierda = screen.availWidth + 20;
    ancho=1;
    alto=1;
//    document.body.style.cursor = "wait";
//    parent.frames.oculto.document.location = pagina;
//    return;
  } else {
//    arriba = window.screenTop + (document.body.clientHeight/2) - (alto/2);
//    izquierda = window.screenLeft + (document.body.clientWidth/2) - (ancho/2);
    arriba = (screen.availHeight/2) - (alto/2) - 30;
    izquierda = window.screenLeft + (document.body.clientWidth/2) - (ancho/2);
    if ((arriba + alto) > screen.availHeight) arriba = screen.availHeight - alto - 30;
    if ((izquierda + ancho) > screen.availWidth) izquierda = screen.availWidth - ancho - 30;
    if (arriba < 0) arriba = 0;
    if (izquierda < 0) izquierda = 0;
  }

  var propiedades = "directories=0,resizable=1,location=0,status=1,scrollbars=1,toolbar=0,menubar=0,width="+ancho+",height="+alto+",top="+arriba+",left="+izquierda;
  window.open(pagina, nombre, propiedades);
}

function setViewMode(development) {
	var frm = document.forms.frm_cms_canal;
	frm.formulario.value = "viewMode";
	frm.development.value = development;
	frm.target = "_self";
	frm.action = "";
	frm.submit();
}

function editar(idDatatype, idContenido) {
	abreVentana("/blanco.html", 550, 600, false, "editor_window");
	var frm = document.forms.frm_cms_canal;
	frm.target = "editor_window";
	frm.OBJECT.value = idContenido;
	frm.NEW.value = "FALSE";
	frm.DATATYPE.value = idDatatype;
	frm.action = "cms/component/editor/v1/editor.jsp";
	frm.submit();
}


function refresh() {
	var frm = document.forms.frm_cms_canal;
	frm.target = "_self";
	frm.OBJECT.value = "";
	frm.NEW.value = "FALSE";
	frm.DATATYPE.value = "";
	frm.formulario.value = "";
	frm.action = "";
	frm.submit();
}

function newContent(idDatatype) {
	abreVentana("blanco.html", 550, 600, false, "editor_window");
	var frm = document.forms.frm_cms_canal;
	frm.target = "editor_window";
	frm.OBJECT.value = "";
	frm.DATATYPE.value = idDatatype;
	frm.NEW.value = "TRUE";
	frm.action = "cms/component/editor/v1/editor.jsp";
	frm.submit();
}

function eliminar_old(idDatatype, idContenido) {
	var frm = document.forms.frm_cms_canal;
	frm.target = "_self";
	frm.formulario.value = "eliminarContenido";
	frm.OBJECT.value = idContenido;
	frm.NEW.value = "FALSE";
	frm.DATATYPE.value = idDatatype;
	frm.accion.value = "eliminar";
	frm.action = "";
	frm.submit();
}
function eliminar(idDatatypeSrc, idContenido) {
	var idDatatype = idDatatypeSrc;
	
	if ("PIEZA" == idDatatype.substring(0, 5)) {
		idDatatype = "PIEZA";
	} else if ("MODULO" == idDatatype.substring(0, 6)) {
		idDatatype = "MODULO";
	} else if ("NOTICIA" == idDatatype.substring(0, 7)) {
		idDatatype = "NOTICIA";
	}
	
	$.getJSON("cms/ajax/json_eliminarContenido.jsp", 
		{
			DATATYPE: idDatatype,
			OBJECT: idContenido
		},
		function (result) {
			if (result.mensaje.length > 0) {
				jAlert("Error:" + result.mensaje, "Línea Directa Asistencia");
			}
			
			if (result.exito) {
				var div1 = $("#div_" + idDatatype + "_" + idContenido);
				div1.remove();
			}
		}
	);
}

function mover_old(idDatatype, idContenido, direction, orderFilterColumn) {
	var frm = document.forms.frm_cms_canal;
	frm.target = "_self";
	frm.formulario.value = "moverContenido";
	frm.OBJECT.value = idContenido;
	frm.NEW.value = "FALSE";
	frm.DATATYPE.value = idDatatype;
	frm.direccion.value = direction;
	frm.accion.value = "mover";
	frm.value1.value = orderFilterColumn;
	frm.action = "#"+idDatatype;
	frm.submit();
}

function mover(idDatatypeSrc, idContenido, direction, orderFilterColumn) {
	
	var idDatatype = idDatatypeSrc;
	
	if ("PIEZA" == idDatatype.substring(0, 5)) {
		idDatatype = "PIEZA";
	} else if ("MODULO" == idDatatype.substring(0, 6)) {
		idDatatype = "MODULO";
	} else if ("NOTICIA" == idDatatype.substring(0, 7)) {
		idDatatype = "NOTICIA";
	}
	
	$.getJSON("cms/ajax/json_moverContenido.jsp", 
			{
				DATATYPE: idDatatype,
				OBJECT: idContenido,
				direccion: direction,
				value1: orderFilterColumn
			},
			function (result) {
				if (result.mensaje.length > 0) {
					jAlert("Error: " + result.mensaje, "Línea Directa Asistencia");
				}
				
				if (result.exito) {
					var div1 = $("#div_" + idDatatype + "_" + result.id1);
					var div2 = $("#div_" + idDatatype + "_" + result.id2);
					div1.remove();
					if (direction == "up") {
						div1.insertBefore(div2);
					} else {
						div1.insertAfter(div2);
					}
				}
			}
		);
}

function setDevelopmentContenido_old(idDatatype, idContenido, development) {
	var frm = document.forms.frm_cms_canal;
	frm.target = "_self";
	frm.formulario.value = "setDevelopmentContenido";
	frm.OBJECT.value = idContenido;
	frm.NEW.value = "FALSE";
	frm.DATATYPE.value = idDatatype;
	frm.direccion.value = development;
	frm.accion.value = "setDevelopmentContenido";
	frm.action = "";
	frm.action = "#"+idDatatype;
	frm.submit();
}

function setDevelopmentContenido(idDatatype, idContenido, development) {
	$.getJSON("cms/ajax/json_setDevelopmentContenido.jsp", 
		{
			DATATYPE: idDatatype,
			OBJECT: idContenido,
			direccion: development
		},
		function (result) {
			if (result.mensaje.length > 0) {
				jAlert("Error:" + result.mensaje, "Línea Directa Asistencia");
			}
			
			if (result.exito) {
				$("#tdDevelopmentContent_" + idDatatype + "_" + idContenido + (!development? "_on": "_off")).hide();
				$("#tdDevelopmentContent_" + idDatatype + "_" + idContenido + (development? "_on": "_off")).show();
			}
		}
	);
}

function setValues(value1, value2, value3, value4) {
	var frm = document.forms.frm_cms_canal;
	frm.value1.value = value1;
	frm.value2.value = value2;
	frm.value3.value = value3;
	frm.value4.value = value4;
}
