function closefck(parametro1)
{
	alert('se cierra');
}

function valida_buscador(value_query,errmsg)
{
   if(value_query.length < 3)
   {alerta(errmsg);return false;}
   else
   {return true;}
}

/*
------------------------------------------------------------------------------
 Dado el valor numerico del parametro parNumero, 
 le da formato a dos decimales fijos con coma y lo retorna en formato string
 Nota. Esta funcion tambien existen en eBD: avanzado-librerias-utils-formato_precio
------------------------------------------------------------------------------
*/

function formato_dosdecimales(parNumero)
{
	var varNumber=Math.round(parNumero*100)/100;
	varNumber=varNumber.toFixed(2);
	var varString=varNumber.toString();
	varString= varString.replace('.',',');
	return varString;
}
//------------------------------------------------------- -----------------------

function capaVisible(sino,contenedor,formname)
{
	var poner_capa = '';
	var mascara = 'mask'; //Mascara normal
	
	if(sino=='si')
	{
		var propri='hidden';
		var bloque='block';
		var contpropri ='visible';
	}
	else
	{
		var propri='visible';
		var bloque='none';
		//Cuando ocultar mascara
		if (contenedor == 'contenedor_alertas' && (document.getElementById('contenedor') != null && document.getElementById('contenedor').style.visibility == 'visible') || (document.getElementById('contenedor_mails') != null && document.getElementById('contenedor_mails').style.visibility == 'visible'))
		{
			bloque = 'block';
		}
		var contpropri ='hidden';
	}
	
	numform=document.forms.length;
	for(k=0;k<numform;k++)
	{
		formpage=document.forms[k];
		tamano1=formpage.length;
			 
		for(l=0;l<tamano1;l++)
		{
			if (formpage.elements[l].type=='select-one' || formpage.elements[l].type=='select-multiple')
			{
				if (contenedor == 'contenedor_alertas')
				{
					if((document.getElementById('contenedor') != null && document.getElementById('contenedor').style.visibility == 'visible') || (document.getElementById('contenedor_mails') != null && document.getElementById('contenedor_mails').style.visibility == 'visible'))
					{
						formpage.elements[l].style.visibility = 'hidden';
					}
					else
						formpage.elements[l].style.visibility=propri;
				}
				else
				{
					formpage.elements[l].style.visibility=propri;
				}
			}
		}
		if (formname != null)
		{
			if (formpage.name == formname)
			{
				for(l=0;l<tamano1;l++)
				{
					if (formpage.elements[l].type=='select-one' || formpage.elements[l].type=='select-multiple')
					{
						formpage.elements[l].style.visibility='visible';
						formpage.elements[l].style.display='block';
					}
				}
			}
		}
	}
	
//	maskara.resizeTo(dd.getWndW() + dd.getScrollX(), dd.getWndH()+ dd.getScrollY());
	//Segun el contendor que sea se abre una mascara u otra. Contenedor_alertas --> mask_alertas. Contenedor --> mask
	if (contenedor == 'contenedor_alertas')
	{
		/* Pruebas dos capas*/
		if (sino == 'si')
		{
			if(dd.elements['contenedor'] != null)
			{
				dd.elements['contenedor'].setDraggable(false); 
				dd.elements['contenedor'].setOpacity(0.9);
				dd.elements[mascara].maximizeZ();
				dd.elements[contenedor].maximizeZ();
			}
			if(dd.elements['contenedor_mails'] != null)
			{
				dd.elements['contenedor_mails'].setDraggable(false); 
				dd.elements['contenedor_mails'].setOpacity(0.9);
				dd.elements[mascara].maximizeZ();
				dd.elements[contenedor].maximizeZ();
			}
		}
		else
		{
			if(dd.elements['contenedor'] != null)
			{
				dd.elements['contenedor'].setDraggable(true); 
				dd.elements['contenedor'].setOpacity(1);
				dd.elements['contenedor'].maximizeZ();
			}
			if(dd.elements['contenedor_mails'] != null)
			{
				dd.elements['contenedor_mails'].setDraggable(true); 
				dd.elements['contenedor_mails'].setOpacity(1);
				dd.elements['contenedor_mails'].maximizeZ();
			}
			if(dd.elements['contenedor_carrito2'] != null && dd.elements['contenedor_carrito'] != null)
			{
				if(dd.elements['contenedor_carrito2'].text != null && dd.elements['contenedor_carrito2'].text != '')
				{
					dd.elements['contenedor_carrito2'].setDraggable(true); 
					dd.elements['contenedor_carrito2'].setOpacity(1);
					dd.elements['contenedor_carrito2'].maximizeZ();
					poner_capa = 'contenedor_carrito2';
				}
				else
				{
					if(dd.elements['contenedor_carrito'].text != null && dd.elements['contenedor_carrito'].text != '')
					{
						dd.elements['contenedor_carrito'].setDraggable(true); 
						dd.elements['contenedor_carrito'].setOpacity(1);
						dd.elements['contenedor_carrito'].maximizeZ();
						poner_capa = 'contenedor_carrito';
					}
				}
			}
		}
	}

if (contenedor == 'contenedor_carrito2')
	{
		if (sino == 'si')
		{
			if(dd.elements['contenedor'].text != null)
			{
				dd.elements['contenedor'].setDraggable(false); 
				dd.elements['contenedor'].setOpacity(0.9);
				dd.elements[mascara].maximizeZ();
				dd.elements[contenedor].maximizeZ();
			}

			if(dd.elements['contenedor_carrito'].text != null && dd.elements['contenedor_carrito'].text != '')
			{
				dd.elements['contenedor_carrito'].setDraggable(false); 
				dd.elements['contenedor_carrito'].setOpacity(0.9);
				dd.elements[mascara].maximizeZ();
				dd.elements[contenedor].maximizeZ();
			}
		}
		else
		{
			if(dd.elements['contenedor_carrito'].text != null && dd.elements['contenedor_carrito'].text != '')
			{
				dd.elements['contenedor_carrito'].setDraggable(true); 
				dd.elements['contenedor_carrito'].setOpacity(1);
				dd.elements['contenedor_carrito'].maximizeZ();
				poner_capa = 'contenedor_carrito';
			}
		}
	}

	
	document.getElementById(mascara).style.width=(document.body.scrollWidth) +"px";

//	if (navigator.appName.indexOf("Microsoft")!=-1) {
	if (document.body.clientHeight > document.body.scrollHeight)
	{
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			document.getElementById(mascara).style.height=document.body.clientHeight+"px";
		}
		else
		{
			document.getElementById(mascara).style.height=document.body.clientHeight+"px";
			document.getElementByTagName('body').style.height='inherit';
			
		}
	}
	else 
	{
		document.getElementById(mascara).style.height=(document.body.scrollHeight) +"px";
	}
	
//	document.getElementById('mask').style.height=(document.body.scrollHeight) +"px";
	if (bloque == 'block')
	{
		dd.elements[mascara].show();
	}
	else
	{
		dd.elements[mascara].hide();
	}
	//	document.getElementById(mascara).style.display=bloque;
	if (poner_capa != '')
	{
		//alert(poner_capa);
		capaVisible('si',poner_capa);
	}
}

function coordenadas_centro(widthdialogo,heightdialogo)
{
/* A partir del ancho y alto del dialogo devuelve las coordeandas para centrarlo dependiendo de la resolucion de la pantalla */

    var widthcenter = dd.getWndW()/2 + dd.getScrollX() - widthdialogo/2;
    if(widthcenter<dd.getScrollX()){widthcenter=dd.getScrollX();}

    var heightcenter = dd.getWndH()/2 + dd.getScrollY() - heightdialogo/2;
    if(heightcenter<dd.getScrollY()){heightcenter=dd.getScrollY();}

    var coordenadas = new Object();

    widthcenter = Math.round(widthcenter);
    heightcenter = Math.round(heightcenter);
    coordenadas['x'] = widthcenter;
    coordenadas['y'] = heightcenter;

    return coordenadas;
}

function abrir_dialogo(div,target,width,height,focus_name,formname)
{
/* Funcion que a partir de un identificador muestra una capa  
	div --> identificador origen
	target --> contenedor destino
	width, height --> medidas del cuadro de dialogo
	focus_name -->  nombre del campo del formulario que tendra el foco
	forname --> formulario del cadro de dialogo en el que si se veran los desplegables
*/
	//vaciamos el contenedor antes de abrirlo
	cerrar_dialogo(target);

	var obj=document.getElementById(div);
	var objtarget=document.getElementById(target);
	
	if(objtarget != null && obj != null)
	{
		if(width != null)
		{
			width=width;
			//objtarget.style.width = width;
		}else
		{
			width = obj.offsetWidth;
		}
		//objtarget.style.width = width;
		if(height != null)
		{
			height=height;
		}
		else
		{
			height=obj.offsetHeight;
		}
//		objtarget.style.height = height;
//		objtarget.innerHTML = obj.innerHTML;
		//dd.elements.contenedor.moveTo(width,height);	
		var aux = new String(obj.innerHTML);
		aux = aux.replace(/_original/gi,"");
		dd.elements[target].write(aux);
		dd.elements[target].defz = 100;

		dd.elements[target].resizeTo(width,height);
		var coord = coordenadas_centro(width,height);	
		dd.elements[target].moveTo(coord.x,coord.y);
		dd.elements[target].maximizeZ();
		//objtarget.style.display='block';
		//alert("target --> "+target);
	/*	if (target == 'contenedor_alertas')
		{
		//alert("entra en hechar para adelante");
			//document.getElementById('mask').style.zIndex = 9000;
			dd.elements['contenedor'].setZ();
			dd.elements[target].maximizeZ();
		}
	*/
		dd.elements[target].show();
		if (focus_name != null)
		{
			var f = document.getElementById(focus_name);
			if (f != null)
			{ 
				f.focus();
			}
		}
	}
	capaVisible('si',target,formname);
	
}

function cerrar_dialogo(div)
{
/* Funcion que a partir de un identificador oculta una capa  */

	if(dd.elements[div])
	{
		dd.elements[div].hide();
		dd.elements[div].write('');
	}
	else
	{
		var obj=document.getElementById(div);
		if(obj != null)
		{
			obj.innerHTML='';
			obj.style.display='none';
		}
	}
	capaVisible('no',div);
}

function alerta(sms,titulo)
{
	document.getElementById('contenido_alerta_original').innerHTML= sms;
	
	if (titulo != null)
		document.getElementById('titulo_aviso').innerHTML = titulo;
	var alto = document.getElementById('aviso').offsetHeight;
	var ancho = document.getElementById('aviso').offsetWidth;
	cerrar_dialogo('contenedor_alertas');
	abrir_dialogo('aviso','contenedor_alertas',ancho,alto,null);
	document.getElementById('contenedor_alertas').focus();
}

function confirma(title,sms,funcion,cancelar)
{
	var botones = '';
	if (title != null)
		document.getElementById('contenido_confirma_title_original').innerHTML= title;
	
	document.getElementById('contenido_confirma_original').innerHTML= sms;
	if (funcion != null)
	{
		botones+='<div class="boton" id="boton_original" onClick="cerrar_dialogo(\'contenedor_alertas\');'+funcion+'" onMouseOver="this.className=\'boton_hover\';" onMouseOut="this.className=\'boton\';"><span>Aceptar</span></div>';
	}
	
	if (cancelar == null)
	{
		document.getElementById('boton_cancelar_original').style.display = 'none';
		document.getElementById('cruz_original').style.visibility = 'hidden';
	}
	document.getElementById('contenido_confirma_botones_original').innerHTML= botones;
	var alto = document.getElementById('confirma').offsetHeight+20;
	var ancho = document.getElementById('confirma').offsetWidth;
	abrir_dialogo('confirma','contenedor_alertas',ancho,alto,null);
}

/* ----- v 2.0 de la funcion de confirma    EN DESARROLLO -----*/
function confirma2(title,sms)
{
	var botones = '';
	document.getElementById('contenido_confirma2_title_original').innerHTML= title;
	document.getElementById('contenido_confirma2_original').innerHTML= sms;
	botones+='<div class="boton" id="boton_confirma22_original" onClick="cerrar_dialogo(\'contenedor_alertas\');return true;" onMouseOver="this.className=\'boton_hover\';" onMouseOut="this.className=\'boton\';"><span>Aceptar</span></div>';
	document.getElementById('contenido_confirma2_botones_original').innerHTML= botones;
	var alto = document.getElementById('confirma2').offsetHeight+20;
	var ancho = document.getElementById('confirma2').offsetWidth;
	abrir_dialogo('confirma2','contenedor_alertas',ancho,alto,null);
}

/* ***** Funciones que se utilizan para pasar valores de una lista (select) a otra. Por ejemplo: opcion de compartir carpetas con los contactos ******** */
function ClearList(OptionList, TitleName) 
{
	OptionList.length = 0;
}
	
function mover(inicio,fin)
{
/* Mueve de un select a otro los valores seleccionados. Para los botones > y < */

	var temp1 = new Array();
	var temp2 = new Array();
	var tempa = new Array();
	var tempb = new Array();
	var tempc = new Array(); //Clase de la opcion
	var tempd = new Array(); //Clase de la opcion
	var current1 = 0;
	var current2 = 0;
	var y=0;
	var attribute;
	
	attribute1 = inicio; //select inicio
	attribute2 = fin; //select final

	//llenarlo de los viejos valores
	for (var i = 0; i < attribute2.length; i++)
	{  
		y=current1++
		temp1[y] = attribute2.options[i].value;
		tempa[y] = attribute2.options[i].text;
		tempc[y] = attribute2.options[i].className;
	}

	//asigna nuevos valores al array
	for (var i = 0; i < attribute1.length; i++)
	{   
		if ( attribute1.options[i].selected )
		{  
			y=current1++
			temp1[y] = attribute1.options[i].value;
			tempa[y] = attribute1.options[i].text;
			tempc[y] = attribute1.options[i].className;
		}
		else
		{  
			y=current2++
			temp2[y] = attribute1.options[i].value; 
			tempb[y] = attribute1.options[i].text;
			tempd[y] = attribute1.options[i].className;
		}
	}

	//genera nuevas opciones 
	for (var i = 0; i < temp1.length; i++)
	{  
		attribute2.options[i] = new Option();
		attribute2.options[i].value = temp1[i];
		attribute2.options[i].text =  tempa[i];
		attribute2.options[i].className =  tempc[i];
	}

	//generar nuevas opciones
	ClearList(attribute1,attribute1);
	if (temp2.length>0)
	{	
		for (var i = 0; i < temp2.length; i++)
		{   
			attribute1.options[i] = new Option();
			attribute1.options[i].value = temp2[i];
			attribute1.options[i].text =  tempb[i];
			attribute1.options[i].className =  tempd[i];
		}
	}
}

function mover_todos (inicio,fin)
{
/* Mueve de la caja a todos los valores. Para las opciones de >> y << */

	var temp1 = new Array();
	var temp2 = new Array();
	var tempa = new Array();
	var tempb = new Array();
	var tempc = new Array();
	var current1 = 0;
	var current2 = 0;
	var y=0;
	var attribute;
	
	attribute1 = inicio; //select inicio
	attribute2 = fin; //select final

	//llenarlo de los viejos valores
	for (var i = 0; i < attribute2.length; i++)
	{  
		y=current1++
		temp1[y] = attribute2.options[i].value;
		tempa[y] = attribute2.options[i].text;
		tempc[y] = attribute2.options[i].className;
	}
	//asigna nuevos valores al array
	for (var i = 0; i < attribute1.length; i++)
	{   
			y=current1++
			temp1[y] = attribute1.options[i].value;
			tempa[y] = attribute1.options[i].text;
			tempc[y] = attribute1.options[i].className;
	}

	//genera nuevas opciones 
	for (var i = 0; i < temp1.length; i++)
	{  
		attribute2.options[i] = new Option();
		attribute2.options[i].value = temp1[i];
		attribute2.options[i].text =  tempa[i];
		attribute2.options[i].className = tempc[i];
	}
	//generar nuevas opciones
	ClearList(attribute1,attribute1);
	if (temp2.length>0)
	{	
		for (var i = 0; i < temp2.length; i++)
		{   
			attribute1.options[i] = new Option();
			attribute1.options[i].value = temp2[i];
			attribute1.options[i].text =  tempb[i];
			attribute1.options[i].className = tempd[i];
		}
	}
}

function des_habilitar_radio(radio,jefe,esclavo)
{
/* Si el radio button jefe esta checked el esclavo tambien pero si el jefe se "descheckea" el esclavo tb se descheckea y se inabilita. 
Parametros entrada: 
	radio --> objeto que se selecciona. Radio button
	jefe --> el valor del radio que hace que el checkbox secundario cambie
	esclavo --> checkbox que que cambia
Utilizado en el upload (publica, permitir utilizar foto)
*/
	if (radio.value == jefe)
	{
		esclavo.checked = true;
		esclavo.disabled = false;	
	}
	else
	{
		esclavo.checked = false;
		esclavo.disabled = true;
	}
}

function des_habilitar_checkbox(jefe,esclavo)
{
/* Si el checkbox jefe esta checked el esclavo tambien pero si el jefe se "descheckea" el esclavo tb se descheckea y se inabilita. 
*/
	if (!jefe.checked) 
	{
		esclavo.checked = false;
		esclavo.disabled = true;
	}
	if (jefe.checked)
	{
		esclavo.checked = true;
		esclavo.disabled = false;
	}
}

function des_habilitar_checkbox_value(jefe,esclavo,value)
{
/* Si el checkbox jefe esta checked el esclavo tambien pero si el jefe se "descheckea" el esclavo tb se descheckea y se inabilita. 
Utilizado en el en los mantenimientos donde el checkbox no tiene la propiedad checked sino el value='S' o value='N'
*/

//alert('jefe=' + jefe.value + ' esclavo=' + esclavo.value);
	if (jefe.value=='N') 
	{
		esclavo.value = 'N';
		esclavo.disabled = true;
	}
	if (jefe.value=='S')
	{
		esclavo.value = 'S';
		esclavo.disabled = false;
	}
//alert('jefe=' + jefe.value + ' esclavo=' + esclavo.value);
}

function abrir_ventana(url,nombre,alto,ancho,resize,scroll,menu,toolbar)
{
/* Abre una ventana secundaria centrada en la pantalla del usuario 
	url --> direccion de la ventana secundaria
	nombre --> nombre que le damos
	demas --> caracteristicas que tendra la pantalla nueva
*/
	var altura_popup=alto; 
	var H = (screen.height - alto) / 2; 
	var anchura_popup=ancho; 
	var L = (screen.width - ancho) / 2; 
	pop_up = window.open(url,nombre,"height="+altura_popup+",width="+anchura_popup+",top="+H+",left="+L+",scrollbars="+scroll+",resizable="+resize+",menubar="+menu+",toolbar="+toolbar); 
}

function cerrar_ventana()
{
/* Cierra la ventana del explorador. Para que funcione en el firefox la ventana que se quiere cerrar se ha tenido que abrir con el window.open()*/
	window.close();
}

function cancelar_envio()
{
/* Para la ejecucion de la pagina, el envio de informacion... */
	var navegador= navigator.appName;
	
	if (navegador.indexOf("Netscape") > -1) 
	{
		window.stop(); 
	}
	if (navegador.indexOf("Explorer") > -1) 
	{
		document.execCommand("Stop"); 
	}
}

function dividir(txt,num) 
{
/* Divide un texto de manera coherente en el numero que nosotros le decimos. 
    Si el texto no se puede dividir pone puntos suspensivos
	txt --> texto
	num --> numero de carateres que tendra como maximo 
	devuelve el texto cortado (cad)
*/	
	txt = txt.toString(); 
	palabras = txt.split(' ');
	cad = '';
	i=0;
	while (i < palabras.length) 
	{
	    tot=0;
		if (palabras[i].length > num) 
		{
	    
		  cad += palabras[i].substring(0,num-4)+' ...'; //Si no puede cortarlo le pone puntos suspensivos
	      i++
	    }
	    else while (true) 
		{
	      if (tot + palabras[i].length + ((tot>0) ? 1 : 0) <= num) 
		  {
	        cad += ' '+palabras[i];
	        tot += palabras[i].length + ((tot>0) ? 1 : 0);
	        i++; 
	        if (i > palabras.length-1) break;
	      }
	      else 
		  {
	        cad+='<br>';
	        break;
	      }
	    } // end else while
	} // end while
  return cad;
}

function cambiar_clase (id,clase)
{
/* Cambia la clase de un elemento a partir de su identificador*/
	document.getElementById(id).className = clase;
}

function activar_opcion (id,clase1,total,clase2)
{
/* Cambia la clase de un elemento a partir de su identificador
	Los identificadores de las opciones seran OPCION+numeros por tal de poder hacer el recorrido por cada uno de ellas
	id --> identificador de la opcion que se "activa" o cambia de clase
	clase1 --> clase de la opcion activa
	total --> total de opciones
	clase2 --> classe del resto de las opciones
*/
	for (var i=1;i<=total;i++)
	{
		if (document.getElementById('opcion'+i).id == id)
		{
			document.getElementById('opcion'+i).className = clase1;
		}
		else
		{
			document.getElementById('opcion'+i).className = clase2;
		}
	}
}

function comprobar_dispo_alias(alias)
{
/* Comprueba la disponibilidad el alias
	cliente --> si es 1 indica que se mira desde mi cuenta (el cliente puede guardar el alias que tenia hasta ahora)
		 si es 0 viene de registro, el alias no tiene que existir desde ningun sitio
*/
	var url = '/bdd.comp_alias';
	var params = new Object();
	params['alias'] = encodeURIComponent(alias);
	ajaxCaller.postForPlainText(url,params,tratar_webservicecd);
}

/* Primera version (NO SE USA)
function comprobar_dispo(alias,text1,text2,origen)
{
	var url = '/bdd.comp_alias';
	var params = new Object();
	params['alias'] = alias;
	params['text1'] = text1;
	params['text2'] = text2;
	params['origen'] = origen;
	ajaxCaller.postForPlainText(url,params,tratar_webservicecd);
}
*/
//function comprobar_dispo2(document.f.alias.value)

function tratar_webservicecd(json)
{
	var all = eval('('+json+')');
	if (all.alias != null)
	{
		document.getElementById('disponible').innerHTML = all.texto;
		//Para hacer la validacion del formulario 0 alias disponible, 1 alias no disponible, 2 alias del propio usuario
		document.getElementById('hidden_disponible').value= all.alias;
		if (all.alias == 0)
			document.getElementById('disponible').style.color = 'green';
		if (all.alias == 1)
			document.getElementById('disponible').style.color = 'red';
		if (all.alias == 2)
			document.getElementById('disponible').style.color = 'blue';
	}
}

function redirigir_dobleclick(urlcarpeta)
{
	location.href = urlcarpeta;
}

function enviar_mail_amigo(para,correo_para,texto)
{
/* Envia por correo un mail a un amigo
*/
	var url = '/mails.enviar_mail_amigo';
	var params = new Object();
	params['nombre_contacto'] = encodeURIComponent(para);
	params['correo_contacto'] = encodeURIComponent(correo_para);
	params['texto_mail'] = encodeURIComponent(texto);
	ajaxCaller.postForPlainText(url,params,tratar_webservice_funciones);
}


function tratar_webservice_funciones(json)
{
/* Funci? que segn la informaci? que tenga el json llama a una opci? u otra. Hace de filtro.
	json --> lo devuelve la funci? hecha con eBDML y se lo pasa cuando llama con la url del webServices
 */
 	var all = eval('('+json+')');

	//Mensaje de confirmacion cuando un la operacion ha tenido exito
	if (all.confirmacion != null)
	{
		alerta(all.confirmacion);
	}
	//Cuando ha ocurrido algn error inesperado
	if(all.error != null)
	{
		alerta(all.error);
	}
}

function openclose(id,idimg)
{
	if (document.getElementById(id).style.display == 'block')
	{
		document.getElementById(id).style.display = 'none';
		if(idimg != null)
			document.getElementById(idimg).className = 'flecha_desplegable';
	}
	else
	{
		document.getElementById(id).style.display = 'block';
		if(idimg != null)
			document.getElementById(idimg).className = 'flecha_plegable';
	}
}

function estilo_titular(id, class1, class2)
{
	if(document.getElementById(id).innerHTML == '')
		document.getElementById(id).className = class2;
	else
		document.getElementById(id).className = class1;
}

function titulo(txt) 
{
	document.title = 'dichis ' + txt;
}

function capLocks(e)
{
	kc=e.keyCode?e.keyCode:e.which;
	sk=e.shiftKey?e.shiftKey:((kc==16)?true:false);
	if(((kc>=65&&kc<=90)&&!sk)||((kc>=97&&kc<=122)&&sk))
		return true;
	else 
		return false;
}

function es_enter(myfield,e)
{
/* Funcion que devuelve false si la tecla apretada no es enter y true en caso contrario.
	parametros de entrada: 
		myfield -->  objeto sobre el que se le aplica la funcion
		e --> evento
	ejemplo de la llamada:
		onKeyPress="if (es_enter(this,event)) validaproyecto();"
*/
	var keycode;
	if (window.event) //IE
		keycode = window.event.keyCode;
	else 
	{
		if (e) 
			keycode = e.which; // Netscape/Firefox/Opera 
		else 
			return false;
	}
	if (keycode == 13)
	{
		return true;
	}
	else
		return false;
}


function es_escape(myfield,e)
{
/* Funcion que devuelve false si la tecla apretada no es escape y true en caso contrario.
	parametros de entrada: 
		myfield -->  objeto sobre el que se le aplica la funcion
		e --> evento
	ejemplo de la llamada:
		onKeyPress="if (es_escape(this,event)) validaproyecto();"
*/
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else 
	{
		if (e) 
			keycode = e.which;
		else 
			return false;
	}
	if (keycode == 27)
	{
		return true;
	}
	else
		return false;
}

function getprovincias(idpais, selectprovincias, funcion)
{
	var url = '/general.getProvincias';
	var params = new Object();
	params['idpais'] = idpais;
	params['selectprovincias'] = selectprovincias;
	if (funcion != null) params['funcion'] = funcion;
	ajaxCaller.postForPlainText(url,params,tratar_wsprovincias);
}

function tratar_wsprovincias(json)
{
	var all = eval('('+json+')');
	if(all[0] != 0)
	{
		var provincias = eval(all[0].selectprovincias);
		borrar_todos(provincias);
		for (h=0; h<=all.length-1; h++)
		{
			insert_element(provincias, all[h].IDPROVINCIA, all[h].DESCRIPCION); 
		}
		if (all[0].funcion != null)
			if (all[0].funcion != '')
				var funcion = eval(all[0].funcion);
	}
	else
	{
		var provincias = eval(all[1]);
		borrar_todos(provincias);
	}
}

function insert_element(destino,value,text)
{
 elem = new Option(text, value, false, true);
 elem.selected=false;
 destino.options[destino.length]=elem;
}

function borrar_todos(campo)
{
 var n=campo.length;
 for(var i=1;i<n;i++){
  campo.remove(1);
 }
}

function getciudades(idprovincia, selectciudades)
{
	var url = '/general.getCiudades';
	var params = new Object();
	params['idprovincia'] = idprovincia;
	params['selectciudades'] = selectciudades;
	ajaxCaller.postForPlainText(url,params,tratar_wsciudades);
}

function tratar_wsciudades(json)
{
	var all = eval('('+json+')');
	if(all[0] != 0)
	{
		var ciudades = eval(all[0].selectciudades);
		borrar_todos(ciudades);
		for (h=0; h<=all.length-1; h++)
		{
			insert_element(ciudades, all[h].IDCIUDAD, all[h].DESCRIPCION); 
		}
	}
	else
	{
		var ciudades = eval(all[1]);
		borrar_todos(ciudades);
	}
}

function rotar_imagen(idfoto,grados)
{
	var url="/general.rotar";
	var params = new Object();
	params['idfoto']=idfoto;
	if(idfoto == '0'){params['idfoto']=objmanager.getSelected();}
	params['grados']=grados;
	ajaxCaller.postForPlainText(url, params, tratar_rotar);
}
				
function tratar_rotar(path)
{
	location.reload();
}
function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength);
}

function abrir_slideshow(origen, id)
{
	//Origen 1-> desde carpetas
	//Origen 2-> desde fotos
	//Origen 3 -> desde guardar compartidas
	
	document.getElementById('slideshow').style.display='block';
	capaVisible('si','contenedor');
//var random = Math.random() * 8000;
	var compartir = 1; //Poder compartir
	var tipo;
//var so = new SWFObject("/imgfiles/Flash/dichis_slide_queue.swf?id="+random, "banner", "773", "701", "8", "#000000");
//so.addParam("quality", "high");
	//so.addParam("wmode", "transparent");
//so.addParam("allowFullScreen", "true");
//so.addParam("allowScriptAccess", "sameDomain");
	//so.addVariable("variable1", "value1");
//so.useExpressInstall('/imgfiles/Flash/expressinstall.swf');
	if (origen==1)
	{

		var ids = objmanager.getSelected();
		//var id = new Array();
		//id = idcarpetas.split(",");
		//so.addVariable("idcarpeta", id[0]);
		tipo = 'c';
//so.addVariable("idcarpeta", 'c'+idcarpetas);
	}
	if (origen==2)
	{
		if (objmanager.getSelect_all() == true || objmanager.getSelected() == '')
		{
			var ids = objmanager.getTodos_ids();
		}
		else
		{
			var ids = objmanager.getSelected();
		}
		tipo = 'f';
//so.addVariable("idcarpeta", 'f'+ids);
	}
	if (origen==3) 
	{
		if (objmanager.getSelect_all() == true || objmanager.getSelected() == '')
		{
			var ids = objmanager.getTodos_ids();
		}
		else
		{
			var ids = objmanager.getSelected();
		}
		tipo = 'g';
//so.addVariable("idcarpeta", 'f'+ids);
		compartir = 0;
	}
	
	logged = 0;
	if (id != null)
		if (id > 0)
			logged = 1;
//so.addVariable("login", logged);
	//1 permite compartir 0 no
//so.addVariable("compartir", compartir); //Si se permite o no al usuario la opcion de compartir fotos des del slide show
	
	var url='/slideshow/ws_slideshow.guardar_parametros_url';
	var params = new Object();
	params['tipo']=tipo;
	params['ids']=ids;
	params['compartir']=compartir;
	params['logged']=logged;
	ajaxCaller.postForPlainText(url,params,tratar_slideshow);
//so.write("slideshow");  //Quitar
}

function tratar_slideshow(json)
{
	var all = eval('('+json+')');
	
	var random = Math.random() * 8000;
	var so = new SWFObject("/imgfiles/Flash/dichis_slide_queue.swf?id="+random, "banner", "773", "701", "8", "#000000");
	so.addParam("quality", "high");
	so.addParam("allowFullScreen", "true");
	so.addParam("allowScriptAccess", "sameDomain");
	so.useExpressInstall('/imgfiles/Flash/expressinstall.swf');
	so.addVariable("login", all.logged);
	//1 permite compartir 0 no
	so.addVariable("compartir", all.compartir); //Si se permite o no al usuario la opcion de compartir fotos des del slide show
	so.addVariable("idcarpeta",all.tipo+all.id_parametros);
	so.write("slideshow");
}

function cerrar_slideshow()
{
	cerrar_dialogo('contenedor');
	document.getElementById('slideshow').innerHTML='&nbsp;';
	document.getElementById('slideshow').style.display='none';
}

function revelar(origen,id,id_pack,idproductocesta,error,destino)
{
/* Susana. (17-1-2008) */

	var ids;

	try{ 
		if (objmanager)
		{
			if (objmanager.getSelect_all())
			{
				var ids = objmanager.getTodos_ids();
			}
			else
			{
				var ids = objmanager.getSelected();
			}
		}
	}catch(e){
		var ids = id;
	}
	
	//alert ("origen --> "+origen+"\nids --> "+ids+"\nerror --> "+error);
	if (origen != '')
	{
		var url = '/carrito.revelar';
		var params = new Object();
		params['ids'] = ids;
		params['origen'] = origen;
		params['destino'] = destino;
		if(idproductocesta)params['idproductocesta'] = idproductocesta;
		if(id_pack)params['idpack'] = id_pack;
		ajaxCaller.postForPlainText(url,params,tratar_revelar);
		//cerrar_dialogo('contenedor');
	}
	else
	{
		alerta(error);
	}
}

function tratar_revelar(json)
{
	var all = eval('('+json+')');
	
	if (all.error != null)
	{
		alerta(all.error);
	}
	else
	{
		if (all.href != null)
			location.href=all.href;
		if (all.div != null)
		{
			document.getElementById('packs').innerHTML=all.div;
			abrir_dialogo('elegir_pack','contenedor_alertas',500,null,null);
		}
	}
		
}

function open_projectv2(idproyecto, url)
{
	if(url)
		window_projectv2(idproyecto, url)
	else
	{
		var url = '/mis_creaciones.abrirproyecto';
		var params = new Object();
		params['idproyecto'] = idproyecto;
		ajaxCaller.postForPlainText(url,params,tratar_open_projectv2);
	}
}

function tratar_open_projectv2(json)
{
	var all = eval('('+json+')');
	if (all.errormsg)
		alerta(all.errormsg);
	else
	{
		if (all.abrir && all.version==1)
			window.location=all.url;
		if (all.abrir && all.version==2)
			window_projectv2(all.idproyecto, all.url)
	}
}

function window_projectv2(idproyecto, url)
{
	pname="project_"+idproyecto;
	var width = screen.width < 1024 ? 1024 : screen.width;
	var height = screen.height < 768 ? 768 : screen.height;
	settings="toolbar=no,location=no,directories=no,"+
		 "status=yes,menubar=no,scrollbars=no,"+
		 "resizable=no,location=yes,top=0,left=0";
	if (navigator.appName == "Microsoft Internet Explorer"){
		settings += ",width=" + (width-10) + ",height=" + (height-30);
	}
	else {
		settings += ",width=" + (width-5) + ",height=" + (height-30);
	}
	var f_open=pname+'=window.open(url, pname, settings);';
	eval(f_open);
	setTimeout("isProjectOpened("+idproyecto+")",1500);
	//window.open(url, pname, settings);
}

function isProjectOpened(id)
{
	if(eval('project_'+id) == null)
		abrir_dialogo('popup_blocked','contenedor_alertas',null,null,null);
		//alerta(popupmsg);
}


