
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 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 doSelFun(valor) {

	switch (valor) {
		case 'null':
			document.getElementById('mail_q').disabled=true;
			document.getElementById('telf_q').disabled=true;
			document.getElementById('mail_q').value='';
			document.getElementById('telf_q').value='';
		break;

		case 'telf':
			document.getElementById('mail_q').disabled=true;
			document.getElementById('telf_q').disabled=false;
			document.getElementById('mail_q').value='';
			document.getElementById('telf_q').value='';
		break;

		case 'mail':
			document.getElementById('mail_q').disabled=false;
			document.getElementById('telf_q').disabled=true;
			document.getElementById('mail_q').value='';
			document.getElementById('telf_q').value='';
		break;

		case 'ambos':
			document.getElementById('mail_q').disabled=false;
			document.getElementById('telf_q').disabled=false;
			document.getElementById('mail_q').value='';
			document.getElementById('telf_q').value='';
		break;
	}
}

function form_registro(sw, ref, sel) {
	var altura_contenido = document.getElementById("body").offsetHeight;
	document.getElementById('capa_desactivado').style.height = altura_contenido+"px";

	if (sel==0) {
        
        document.getElementById('capa_desactivado').style.display='block';        
        document.getElementById('reg_form_dist').style.display='none';
        document.getElementById('reg_form_user').style.display='none';
        document.getElementById('reg_form').style.display='none';
        document.getElementById('ref').value = ref;
        document.getElementById('form_reg_sel').style.display='block';
        
    } else {
        if (sw == 1) {
            document.getElementById('form_reg_sel').style.display='none';
            document.getElementById('capa_desactivado').style.display='block';
            document.getElementById('reg_form_dist').style.display='none';
            document.getElementById('reg_form_user').style.display='none';
            document.getElementById('reg_form').style.display='block';
            document.getElementById('ref').value = ref;
        } else if (sw == 2) {
            document.getElementById('form_reg_sel').style.display='none';
            document.getElementById('capa_desactivado').style.display='block';
            document.getElementById('reg_form_dist').style.display='none';
            document.getElementById('reg_form').style.display='none';
            document.getElementById('reg_form_user').style.display='block';
            document.getElementById('ref').value = ref;
        } else if (sw == 3) {
            document.getElementById('form_reg_sel').style.display='none';
            document.getElementById('capa_desactivado').style.display='block';
            document.getElementById('reg_form_user').style.display='none';
            document.getElementById('reg_form').style.display='none';
            document.getElementById('reg_form_dist').style.display='block';
            document.getElementById('ref').value = ref;
        } else {
            document.getElementById('form_reg_sel').style.display='none';
            document.getElementById('reg_form').style.display='none';
            document.getElementById('capa_desactivado').style.display='none';
            document.getElementById('capa_desactivado').style.zIndex='300';
            document.getElementById('reg_form_user').style.display='none';
            document.getElementById('reg_form_dist').style.display='none';
        }
    }
}

function sendFormCat(modo) {

	switch (modo) {
		case 1:
			var name = document.getElementById('name_q').value;
			var dir = document.getElementById('dir_q').value;
			var cp = document.getElementById('cp_q').value;
			var pais = document.getElementById('pais_q').value;
			var pob = document.getElementById('pob_q').value;
			var nif = document.getElementById('ni').value;
			var telf = document.getElementById('telf_q').value;
			var mail = document.getElementById('mail_q').value;
			var region = document.getElementById('region_q').value;
            var forma_pago = document.getElementById('forma_pago_sel').value;
            var mensajes = 'Comprueba los siguientes datos: \n\n';

			//document.getElementById('capa_desactivado').style.zIndex='11';

			var correcto = true;

			if (name.length <= 3) {
				correcto = false;
				mensajes += '  - Debe indicar un nombre para poder realizar la factura.\n';
			}

			if (cp.length <= 4) {
				correcto=false;
				mensajes += '  - Debe indicar un código postal correcto.\n';
			}

			if (telf.length <= 5) {
				correcto=false;
				mensajes += '  - Debe indicar un telefono para que el repartidor pueda contactarle.\n';
			}

			/*if (mail.length <= 5 && (metodo == 'mail' || metodo == 'ambos')) {
				correcto=false;
				alert('Debe indicar una direccion de correo valida para que le pueda llegar el pedido.');
			}*/

			if (nif.length <= 8) {
				correcto=false;
				mensajes += '  - Debe indicar un NIF/CIF/NIE valido para poder realizar la factura.\n';
			}

			if (dir.length <= 5) {
				correcto=false;
				mensajes += '  - Debe indicar una direccion valida para que le pueda llegar el pedido.\n';
			}

			if (pob.length <= 3) {
				correcto=false;
				mensajes += '  - Debe indicar una poblacion valida para que le pueda llegar el pedido.\n';
			}

			if (correcto)
                getAjax('gestion/include/ajax.php', 'opcion=41&modo=fastbuy&forma_pago='+forma_pago+'&nif='+nif+'&nombre='+name+'&direccion='+dir+'&cp='+cp+'&pais='+pais+'&ciudad='+pob+'&telefono='+telf+'&mail='+mail+'&region='+region, 'ajax_resp_1', 'ajax_loading_1');
            else
                alert(mensajes);
                
		break;

		case 2:
			var name = document.getElementById('name').value;
			var dir = document.getElementById('dir').value;
			var cp = document.getElementById('cp').value;
			var pais = document.getElementById('pais').value;
			var pob = document.getElementById('pob').value;
			var nif = document.getElementById('ni').value;
			var telf = document.getElementById('telf').value;
			var mail = document.getElementById('mail').value;
			var user = document.getElementById('user').value;
			var pass = document.getElementById('pass').value;

			//document.getElementById('capa_desactivado').style.zIndex='11';
			getAjax('gestion/include/ajax.php', 'opcion=41&modo=registro&login='+user+'&passwd='+pass+'&nif='+nif+'&nombre='+name+'&direccion='+dir+'&cp='+cp+'&pais='+pais+'&ciudad='+pob+'&telefono='+telf+'&mail='+mail, 'ajax_resp_1', 'ajax_loading_1');
		break;
	}
}

