var addthis_config = {ui_click: true}

function confirmar_url(url,texto)
{
	if (confirm (texto)) {self.location=url;}
}

function url_self()
{
	var text;
	
	text=location.href;
	var array_text=text.split("?");
    return array_text[0];
}

function openZoom(url,w,h)
{
var w = 800;
var h = 800;
  var str="height="+h+",width="+w+", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no";
  window.open(url,"_blank",str);
}


function desplegables(id, nivel1, nivel2, nivel3, nivel4, nivel5) {
	
	if (id != 'null') location.href="index.php?opcion=33&id_cat="+id+"&nivel1="+nivel1+"&nivel2="+nivel2+"&nivel3="+nivel3+"&nivel4="+nivel4+"&nivel5="+nivel5;
}

function renombrar_galeria(id, galeria, nombre) {
	getAjax('modules/fotografos/gal_fotos_ajax.php', 'opcion=cname&galeria='+galeria+'&nombre='+nombre, id, 'load_'+id);
}

function renombrar_cat_grid(id, cat, nombre) {
	getAjax('modules/grid/grid_ajax.php', 'opcion=cname&cat='+cat+'&nombre='+nombre, id, 'load_'+id);
}

function cambiar_comentario_foto(id, foto, comentario) {
	getAjax('modules/fotografos/gal_fotos_ajax.php', 'opcion=ccom&id='+foto+'&comentario='+comentario, id, 'load_'+id);
}

function borrar_foto(id, foto, galeria, nodo) {
	if(confirm('Seguro que quieres borrar esta foto ?')) getAjax('modules/fotografos/gal_fotos_ajax.php', 'opcion=cdel&id='+foto+'&galeria='+galeria+'&nodo='+nodo, id, 'load_'+id);
}

function leerCookie(nombre) {
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
   return a; 
}


function conseguirContenidoJSON(url) {

     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         }
       }
     }
	
     req.onreadystatechange = respuestaContenidoJSON;
     req.open("GET",url,true);
     req.send(null);
}

function respuestaContenidoJSON() {

   if(req.readyState == 4) {
   	  if(req.status == 200) {
		
        var respuesta_json = req.responseText;
    	var _respuestaContenido = eval("("+respuesta_json+")");
		var selectTallas = document.getElementById('s_talla_id');
		
		for (j in selectTallas.options)
			selectTallas.options[j] = null;
		
        selectTallas.options[selectTallas.options.length] = new Option('Talla', '0');
        
		for (i in _respuestaContenido)
			selectTallas.options[selectTallas.options.length] = new Option(_respuestaContenido[i], i);			

		selectTallas.value = 'null';
		selectTallas.disabled = false;		
      }
   }
}

function insertTallas(fabricante) {
		
		//alert(fabricante);
		
	  conseguirContenidoJSON('gestion/include/ajax.php?&op=insertTallas&fabricante='+fabricante);
}

function enviar_mail() {
	
	var dest_nombre = document.getElementById('m_des_name').value;
	var dest_dir = document.getElementById('m_des_dir').value;
	var rem_dir = document.getElementById('m_rem_dir').value;
	var rem_nombre = document.getElementById('m_rem_name').value;
	var asunto = document.getElementById('m_asunto').value;
	
	if (dest_nombre.length < 1 || dest_dir.length < 1 || rem_nombre.length < 1 || rem_dir.length < 1 || asunto.length < 1) {
		alert('No se deje ningun campo por rellenar')
	} else {
		document.getElementById('formulario_mail_plantilla').submit();
	}
	
}


function resetVentanaFlotante() {
		document.getElementById('ventanaFlotante').style.display = 'none';
        document.getElementById('capa_desactivado').style.display = 'none';
}


function ventanaFlotante() {

        var ancho = 500;
	
		// Ancho
		document.getElementById('ventanaFlotante').style.width = ancho+'px';
		document.getElementById('ventanaFlotante').style.marginLeft = '-'+(ancho/2)+'px';
		document.getElementById('ventanaFlotanteMain').style.width = (ancho-22)+'px';
		document.getElementById('ventanaFlotanteTitulo').style.width = (ancho-22)+'px';
		document.getElementById('ventanaFlotanteTop').style.width = (ancho-20)+'px';
		document.getElementById('ventanaFlotanteBot').style.width = (ancho-20)+'px';
	
        document.getElementById('capa_desactivado').style.display = 'block';
		document.getElementById('ventanaFlotante').style.display = 'block';
	
}

