var COLOR_LISTA = "#F4FDCF";
var COLOR_LISTA_SIN = "";
function cambiarIdioma(idioma) {
	document.getElementById('idioma').value = idioma;
	document.formulario_idioma.submit();	
}
function mostrarDivIdiomas(div_idioma, altura) {
	if (document.getElementById(div_idioma)) {
		document.getElementById('div_formulario').style.height = (parseInt(document.getElementById('div_formulario').style.height.replace('px','')) + altura)+'px';
		document.getElementById(div_idioma).style.display = "";
		document.getElementById('lab_'+div_idioma).style.display = "none";
	}
}
function cargarBusqueda(idPatalla, enlace, idMenu, nomMenu, codBuscar) {
	if (document.getElementById('b_enlace')) {
		document.getElementById('b_enlace').value= enlace;
	}
	if (document.getElementById('cod_menu_cargado')) {
		document.getElementById('cod_menu_cargado').value= idMenu;
	}
	if (document.getElementById('nom_menu_cargado')) {
		document.getElementById('nom_menu_cargado').value= nomMenu;
	}
	if (document.getElementById('codBuscar')) {
		document.getElementById('codBuscar').value= codBuscar;
	}	
	document.getElementById('formulario').action= 'index.php?p='+idPatalla;
	document.formulario.submit();
}
function clearInput(valor, control){
	var valorActual = document.getElementById(control).value;
	if (valor == valorActual){
		document.getElementById(control).value= '';
		document.getElementById(control).style.color = '';
	}
}
function clearInput2(valor, control){
	var valorActual = document.getElementById(control).value;
	if (valorActual == ''){
		document.getElementById(control).value = valor;
		document.getElementById(control).style.color = "#C1C1C1";
	}
}
function cargar_buscar() {
	alert('en pruebas...');
}
function cargarMenu(cod_menu_cargado, nom_menu_cargado) {
	document.getElementById('cod_menu_cargado').value = cod_menu_cargado;
	document.getElementById('nom_menu_cargado').value = nom_menu_cargado;
	document.getElementById('formulario').action = 'index.php';
	if (document.getElementById('accion')) { document.getElementById('accion').value = ''; }
	if (document.getElementById('buscar') && document.getElementById('b_buscar')) { document.getElementById('b_buscar').value = document.getElementById('buscar').value; }
	document.formulario.submit();
}
function cargarBoton(control, imagen) {
	control.background=imagen;
}
function quitarBoton(control, imagen) {
	control.background=imagen;
}
function cambiaColor(control) {
	control.bgColor = COLOR_LISTA;
}
function devuelveColor(control) {
	control.bgColor = COLOR_LISTA_SIN;
}
function borrarSeleccionados(cadena1, cadena2) {
	if (document.getElementById("para_borrar").value == "") {
		alert(cadena1);
		return false;
	}	
	if (!confirm(cadena2)) {
		return false;
	}
	document.getElementById("accion").value = "BORRAR";
	document.formulario.submit();
}
function cargarParaBorrar(control) {
	if (document.getElementById(control.id).checked) {
		document.getElementById("para_borrar").value = document.getElementById("para_borrar").value + control.id + ",";
	}
	if (!document.getElementById(control.id).checked) {
		document.getElementById("para_borrar").value = document.getElementById("para_borrar").value.replace(control.id + ",", "");
	}
}
function replaceAll_X(cadena, valor, valor_nuevo) {
	 while(cadena.indexOf(valor) >= 0) {
	 	cadena = cadena.replace(valor, valor_nuevo); 
	} 
	return cadena; 
}
function aleatorio(inferior,superior){
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.round(aleat)
    return parseInt(inferior) + aleat
} 
function centrarCapa() {
	if (document.layers){
		ancho_navegador = window.innerWidth;
	} else {
		ancho_navegador = document.body.clientWidth;
	}
	ancho = (ancho_navegador-document.getElementById('div_formulario').style.width.replace('px',''))/2;
	document.getElementById('div_formulario').style.left= ancho + 'px';
	document.getElementById('div_formulario').style.top='100px';
}
function cambioFichero1(sValor, sValor2) {
	sValor2.value = sValor.value.replace('C:\\fakepath\\','');
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
var N = document.getElementById && !document.all;
//N = (document.all) ? 0 : 1;
var ob;
var formu;
function MD(e) {
	var N = document.getElementById && !document.all;
	if (N) {
		ob = document.getElementById('div_formulario').style;
		Y=e.clientY-parseInt(ob.top);
		X=e.clientX-parseInt(ob.left); 
		return false;
	}
	else {
		if (formu == "datos") {
			ob = div_formulario.style;
		}
		else {
			if (formu == "filtro") {
				ob = div_formulario_filtro.style;
			}
			else {
				if (formu == "columnas") {
					ob = formularioColumnas.style;
				}
				else {
					ob = formularioMailing.style;
				}
			}
		}	
		X=event.offsetX;
		Y=event.offsetY;
	}
}

function MM(e) {
	var N = document.getElementById && !document.all;
	if (ob) {
		if (N) {
			ob.top=(e.clientY-Y)+"px";
			ob.left=(e.clientX-X)+"px"; 
		}
		else {
			ob.pixelLeft = event.clientX-X + document.body.scrollLeft-10;
			ob.pixelTop = event.clientY-Y + document.body.scrollTop-10;
			return false;
		}
	}
}

function MU() {
	ob = null;
}

if (N) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
function mover1(control) {
	if (control == "datos") {
		N = document.div_formulario;
	}
	else {
		if (control == "filtro") {
			N = document.div_formulario_filtro;
		}
		else {
			if (control == "columnas") {
				N = document.formularioColumnas;
			}
			else {
				N = document.formularioMailing;
			}
		}
	}
	//alert(control);
	formu = control;
	document.onmousedown = MD;
	document.onmousemove = MM;
	document.onmouseup = MU;
}
function mover2() {
	document.onmousedown = "";
	document.onmousemove = "";
	document.onmouseup = "";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
function OpenNewWindow(Destination,WindowName,Width,Height,Position,Scrollbars,Resizable,Left,Top)	{
/*	var features = "resizable:"+Resizable+";scroll:"+Scrollbars+";status:no;center:yes;help:no;dialogWidth:"+Width+"px;dialogHeight:"+Height+"px;";
	window.showModalDialog(Destination, window, features);
*/
//   Position where the window will open
//   --------------------
//   |   TL   TC   TR   |
//   |   ML   MC   MR   |
//   |   BL   BC   BR   |
//   --------------------
	DefaultPosition = 'MC';
	DefaultWidth = 200;
	DefaultHeight = 150;
	DefaultMargin = 10;
	
	if (!Position)
		{ Position = DefaultPosition; }

	if (!Height)
		{ Height = DefaultHeight; }

	if (!Width)
		{ Width = DefaultWidth; }

	if (!Scrollbars && !Resizable)
		{
		Scrollbars = 'no';
		Resizable = 'no';
		}

	if (!Left && !Top)
		{
		Left = DefaultMargin;
		Top = DefaultMargin;
		}

	if (Position == 'TC')
		{ Left = (screen.width - Width) / 2; }
	else if (Position == 'TR')
		{ Left = screen.width - Width - (Left * 2); }
	else if (Position == 'ML')
		{ Top = (screen.height - Height) / 2; }
	else if (Position == 'MC')
		{
		Left = (screen.width - Width) / 2;
		Top = (screen.height - Height) / 2;
		}
	else if (Position == 'MR')
		{
		Left = screen.width - Width - (Left * 2);
		Top = (screen.height - Height) / 2;
		}
	else if (Position == 'BL')
		{ Top = screen.height - (Height + (Top * 2) + 45); }
	else if (Position == 'BC')
		{
		Left = (screen.width - Width) / 2;
		Top = screen.height - (Height + (Top * 2) + 45);
		}
	else if (Position == 'BR')
		{
		Left = screen.width - Width - (Left * 2);
		Top = screen.height - (Height + (Top * 2) + 45);
		}

 	WindowName = window.open(Destination,WindowName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + Scrollbars + ",resizable=" + Resizable + ",copyhistory=yes,top=" + Top + ",left=" + Left + ",width=" + Width + ",height=" + Height+",dialog=yes,modal=yes")
	WindowName.focus();

/*	if (ErrorOpeningPopups && !Window)
		{ alert(ErrorOpeningPopups); }
*/
}
