			$(document).ready(function () {
		var lurlws="sbd_kline.php";
    // Tabs
    // $('#tabsprod').tabs();
		// $("#tabsprod").tabs("option", "selected", 0);
    // $('#tabsprof').tabs();
		// $("#tabsprof").tabs("option", "selected", 0);
    // $('#tabsregl').tabs();
		// $("#tabsregl").tabs("option", "selected", 0);
    //buttons
    $("button", ".boton").button();

		$('#divofertas').show();
		$('#divempleo').hide();
		var noti=jQuery.url.param("new");
		if (noti!=undefined){
			//cargar_noticia(noti);
			$('#divnews').hide();
			$('#divnoticia').show();
		}
		else {
			$('#divnews').show();
			$('#divnoticia').hide();
		}
    //Overlay de LOPD
    $('#over_lopd').overlay({ closeOnClick: false, left:150, top:0 });
    //Overlay de Politica de privacidad
    $('#over_nlpp').overlay({ closeOnClick: false, left:150, top:0 });
    //Overlay de Error
    $('#over_error').overlay({ closeOnClick: false });

		var submenu=jQuery.url.param("submenu");
		if (submenu!=undefined){
			$('#div_submenu').tab({tselected: parseInt(submenu)});
			$('#div_submenuregl').tab({tselected: parseInt(submenu)});
			$('#div_submenuprod').tab({tselected: parseInt(submenu)});
			$('#div_submenuemp').tab({tselected: parseInt(submenu)});
			$('#div_submenuserv').tab({tselected: parseInt(submenu)});
			// $("#tabsprod").tabs("option", "selected", parseInt(submenu));
			// $("#tabsprof").tabs("option", "selected", parseInt(submenu));
			// $("#tabsregl").tabs("option", "selected", parseInt(submenu));
		}
		else {
			$('#div_submenu').tab({tselected: 0});
			$('#div_submenuemp').tab({tselected: 0});
			$('#div_submenuregl').tab({tselected: 0});
			$('#div_submenuprod').tab({tselected: 0});
			$('#div_submenuserv').tab({tselected: 0});
			// $("#tabsprod").tabs("option", "selected", 0);
			// $("#tabsprof").tabs("option", "selected", 0);
			// $("#tabsregl").tabs("option", "selected", 0);
		}

		rellena_provincias();
		rellena_productos_check();
		rellena_tiposnegocio();
		rellena_tiposnegocio2();
		rellena_puestostrabajo();
		rellena_tipoconstruccion();
		rellena_productos_cmb();

		var prod=jQuery.url.param("id_producto");
		if (prod!=undefined){
			$("#cmbproducto").selectOptions(prod);
		}
		var constr=jQuery.url.param("id_constr");
		if (constr!=undefined){
			$("#cmbtipocontruc").selectOptions(constr);
		}
				
		// $('#imgdet').hover(function(){
			// $(this).attr("src", "./images/flecha_iz.png");
		// });
		// $('#imgdet').mouseover(function(){
			// $(this).attr("src", "./images/flecha_iz2.png");
		// });
		// $('#imgdel').hover(function(){
			// $(this).attr("src", "./images/flecha_der.png");
		// });
		// $('#imgdel').mouseover(function(){
			// $(this).attr("src", "./images/flecha_der2.png");
		// });
		
	// $('#btndelante').click(function(){	
			// var pictWidth = $('#fotos-kline-prod').find("img").width();
			// var curr = parseInt($('div#stripTransmitter0 a.current').text());
			// var cnt = -(pictWidth * (curr));
			// var last = $('div#stripTransmitter0 a').size();
			// //curr= curr - 1;
			// if (curr < last) {
				// $('div#stripTransmitter0 a')[curr - 1].classList.remove("current");
				// $('div#stripTransmitter0 a')[curr].classList.add("current");
				// $('div#fotos-kline-prod').find("ul").animate({ left: cnt}, 800, "easeInSine");
			// }
		// });
		
	// $('#btndetras').click(function(){	
			// var pictWidth = $('#fotos-kline-prod').find("img").width();
			// var curr = parseInt($('div#stripTransmitter0 a.current').text());
			// var cnt = -(pictWidth * (curr - 2));
			// var last = $('div#stripTransmitter0 a').size();
			// //curr= curr - 1;
			// if (curr > 1) {
				// $('div#stripTransmitter0 a')[curr - 1].classList.remove("current");
				// $('div#stripTransmitter0 a')[curr - 2].classList.add("current");
				// $('div#fotos-kline-prod').find("ul").animate({ left: cnt}, 800, "easeInSine");
			// }
		// });
		
	// $('#btndelantehome').click(function(){	
			// var pictWidth = $('#fotos-kline-home').find("img").width();
			// var curr = parseInt($('div#stripTransmitter0 a.current').text());
			// var cnt = -(pictWidth * (curr));
			// var last = $('div#stripTransmitter0 a').size();
			// //curr= curr - 1;
			// if (curr < last) {
				// /*$('div#stripTransmitter0 a')[curr - 1].removeClass("current");
				// $('div#stripTransmitter0 a')[curr].addClass("current");*/
				// $('div#fotos-kline-home').find("ul").animate({ left: cnt}, 800, "easeInSine");
			// }
		// });
		
		// $('#btndetrashome').click(function(){	
			// var pictWidth = $('#fotos-kline-home').find("img").width();
			// var curr = parseInt($('div#stripTransmitter0 a.current').text());
			// var cnt = -(pictWidth * (curr - 2));
			// var last = $('div#stripTransmitter0 a').size();
			// //curr= curr - 1;
			// if (curr > 1) {
				// /*$('div#stripTransmitter0 a')[curr - 1].classList.remove("current");
				// $('div#stripTransmitter0 a')[curr - 2].classList.add("current");*/
				// $('div#fotos-kline-home').find("ul").animate({ left: cnt}, 800, "easeInSine");
			// }
		// });
		
		
	// function home_galeria(accion){
			// var ui = (!settings.uiBefore) ? jQuery(this).next().find("a.current") : jQuery(this).prev().find("a.current");
			// var bTotal = parseFloat(jQuery(this).css('borderLeftWidth').replace("px", "")) +  parseFloat(jQuery(this).css('borderRightWidth').replace("px", ""));
			// var dOs = jQuery(this).offset();
			// if(accion="ant") {
				// var uiprev = ui.parent().prev().find("a");	
				// (jQuery(uiprev).length != 0)? uiprev.trigger("click") : ui.parent().parent().find("a:last").trigger("click");							
			// } 
			// else {
				// var uinext = ui.parent().next().find("a");
			  // (jQuery(uinext).length != 0)? uinext.trigger("click") : ui.parent().parent().find("a:first").trigger("click");
			// }
		// };
		
	
		
	// $('#btndelantegal').click(function(){	
		// home_galeria("sig");

	// // var pictWidth = $('#fotos-kline-gal').find("img").width();
			// // var curr = parseInt($('div#stripTransmitter0 a.current').text());
			// // var cnt = -(pictWidth * (curr));
			// // var last = $('div#stripTransmitter0 a').size();
			// // //curr= curr - 1;
			// // if (curr < last) {
				// // $('div#stripTransmitter0 a')[curr - 1].classList.remove("current");
				// // $('div#stripTransmitter0 a')[curr].classList.add("current");
				// // $('div#fotos-kline-gal').find("ul").animate({ left: cnt}, 800, "easeInSine");
			// // }
		// });
		
		// $('#btndetrasgal').click(function(){	
		// home_galeria("ant");
		
			// // var pictWidth = $('#fotos-kline-gal').find("img").width();
			// // var curr = parseInt($('div#stripTransmitter0 a.current').text());
			// // var cnt = -(pictWidth * (curr - 2));
			// // var last = $('div#stripTransmitter0 a').size();
			// // //curr= curr - 1;
			// // if (curr > 1) {
				// // $('div#stripTransmitter0 a')[curr - 1].classList.remove("current");
				// // $('div#stripTransmitter0 a')[curr - 2].classList.add("current");
				// // $('div#fotos-kline-gal').find("ul").animate({ left: cnt}, 800, "easeInSine");
			// // }
		// });
	
		$(window).bind("load", function() {
			$("div#fotos-kline-prod").slideView({
			easeFunc: "easeInSine",
			easeTime: 800,
			uiBefore: false,
			ttOpacity:0.5,
			toolTip:false
			});
			$('#fotos-kline-prod a:not(.del):not(.det)').lightBox();
			
			$("div#fotos-kline-gal").slideView({
			easeFunc: "easeInSine",
			easeTime: 800,
			uiBefore: false,
			ttOpacity:0.5,
			toolTip:false
			});
			$('#fotos-kline-gal a:not(.del):not(.det)').lightBox();
			
		  $("div#fotos-kline-home").slideView({
		  easeFunc: "easeInSine",
		  easeTime: 800,
		  uiBefore: false,
		  ttOpacity:0.5,
		  toolTip:false
		  });
			$('#fotos-kline-home a:not(.del):not(.det)').lightBox();
			
			$(".lightb.render a").lightBox();
			$(".lightb.seccion a").lightBox();
			$(".lightb.manilla a").lightBox();
			$(".lightb.categ a").lightBox();
			$(".lightb.empresa a").lightBox();
		});

    function urlencode(texto) {
        var safechars = "0123456789" + // numeric
    "abcdefghijklmnopqrstuvwxyz" + // alphabetic
    "abcdefghijklmnopqrstuvwxyz" +
    "-_.!~*'()"; // rfc2396 mark characters
        var hex = "0123456789abcdef";
        var encoded = "";
        if (texto != null) {
            var plaintext = texto;
            for (var i = 0; i < plaintext.length; i++) {
                var ch = plaintext.charat(i);
                if (ch == " ") {
                    encoded += "+"; // x-www-urlencoded, rather than %20
                } else {
                    if (safechars.indexof(ch) != -1) {
                        encoded += ch;
                    } else {
                        var charcode = ch.charcodeat(0);
                        if (charcode > 255) {
                            encoded += "+";
                        }
                        else {
                            encoded += "%";
                            encoded += hex.charat((charcode >> 4) & 0xf);
                            encoded += hex.charat(charcode & 0xf);
                        }
                    }
                }
            } // for
        }
        return encoded;
    };

    function alert_error(error) {
        $("#errId").text(error);
        $("#over_error").overlay().load();
    }

		// Rellenamos las provincias
	 function rellena_provincias(){
			var peticion = "fn=getprovincias";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar las Provincias.');
				},
				success: function(xml){
					$("#cmbProvincia").removeOption(/./);
					$("#cmbProvincia").addOption(-1, '---');
					$(xml).find('row').each(function(){
							var frm_id = $(this).find('id').text();
							var frm_valor = $(this).find('nombre').text();
							$("#cmbProvincia").addOption(frm_id, frm_valor);
						});
						$("#cmbProvincia").selectOptions('-1');
				}//Cierra funcion
			});//Cierra Ajax
	 };

		// Rellenamos los tipos de negocio
	 function rellena_tiposnegocio(){
			var peticion = "fn=gettiposnegocio";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar los Tipos de Negocio.');
				},
				success: function(xml){
					var htm = "";
					var numtipos = 0;
					$(xml).find('row').each(function(){
							htm = htm + "<input type='checkbox' id='tipneg" + $(this).find('id').text() + "' name='tipneg" + $(this).find('id').text() + "' value='" + $(this).find('nombre').text() + "'> <font size='2'> " + $(this).find('nombre').text() +"</font> <br />"
							numtipos +=1;
						});
					$("#div_tiponegocio").html(htm);
					$("#numneg").val(numtipos);
				}//Cierra funcion
			});//Cierra Ajax
	 };
	 
		// Rellenamos los tipos de negocio sin arquitecto, constructor y decorador
	 function rellena_tiposnegocio2(){
			var peticion = "fn=gettiposnegocio2";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar los Tipos de Negocio sin arquitecto, constructor y decorador.');
				},
				success: function(xml){
					var htm = "";
					var numtipos = 0;
					$(xml).find('row').each(function(){
							htm = htm + "<input type='checkbox' id='tipneg" + $(this).find('id').text() + "' name='tipneg" + $(this).find('id').text() + "' value='" + $(this).find('nombre').text() + "'> <font size='2'> " + $(this).find('nombre').text() +"</font> <br />"
							numtipos +=1;
						});
					$("#div_tiponegocio2").html(htm);
					$("#numneg2").val(numtipos);
				}//Cierra funcion
			});//Cierra Ajax
	 };

		// Rellenamos las productos
	 function rellena_productos_check(){
			var peticion = "fn=getcategorias";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar los Productos en los checks.');
				},
				success: function(xml){
					var htm = "";
					var numcategorias = 0;
					$(xml).find('row').each(function(){
							htm = htm + "<input type='checkbox' id='categoria" + $(this).find('id').text() + "' name='categoria" + $(this).find('id').text() + "' value='" + $(this).find('titulo').text() + "'><font size='2'> " + $(this).find('titulo').text() +"</font> <br />"
							numcategorias +=1;
						});
					$("#div_productos").html(htm);
					$("#numcat").val(numcategorias);
				}//Cierra funcion
			});//Cierra Ajax
	 };

		// Rellenamos los productos en el combo
	 function rellena_productos_cmb(){
			var peticion = "fn=getproductos";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar los Productos en el combo.');
				},
				success: function(xml){
					$("#cmbproducto").removeOption(/./);
					$("#cmbproducto").addOption(-1, '---');
					$(xml).find('row').each(function(){
							var frm_id = $(this).find('id').text();
							var frm_valor = $(this).find('titulo').text();
							$("#cmbproducto").addOption(frm_id, frm_valor);
						});
						$("#cmbproducto").selectOptions('-1');
				}//Cierra funcion
			});//Cierra Ajax
	 };

		// Rellenamos los puestos de trabajo
	 function rellena_puestostrabajo(){
			var peticion = "fn=getpuestostrabajo";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar los Puestos de Trabajo.');
				},
				success: function(xml){
					var htm = "";
					var numtipos = 0;
					$(xml).find('row').each(function(){
							htm = htm + "<input type='checkbox' id='puestrab" + $(this).find('id').text() + "' name='puestrab" + $(this).find('id').text() + "' value='" + $(this).find('nombre').text() + "'> <font size='2'> " + $(this).find('nombre').text() +"</font> <br />"
							numtipos +=1;
						});
					$("#div_puestoTrabajo").html(htm);
					$("#numpuestrab").val(numtipos);
				}//Cierra funcion
			});//Cierra Ajax
	 };

		// Rellenamos los productos en el combo
	 function rellena_tipoconstruccion(){
			var peticion = "fn=gettipoconstruccion";
			$.ajax({
				type: "GET",
				url: lurlws,
				data: peticion,
				async:false,
				cache:false,
				dataType: "xml",
				error: function(xml){
					alert_error('Error al cargar los tipos de construcción.');
				},
				success: function(xml){
					$("#cmbtipocontruc").removeOption(/./);
					$("#cmbtipocontruc").addOption(-1, '---');
					$(xml).find('row').each(function(){
							var frm_id = $(this).find('id').text();
							var frm_valor = $(this).find('titulo').text();
							$("#cmbtipocontruc").addOption(frm_id, frm_valor);
						});
						$("#cmbtipocontruc").selectOptions('-1');
				}//Cierra funcion
			});//Cierra Ajax
	 };

		//var ts=$('#cmbTipusServei').val();
	$(":input[@name='rbRazon']").change(function(){
		switch ($(this).val())
		{
			case '1':
				$('#txtNomEmpresa').attr('disabled', false);
			break;
			case '2':
				$('#txtNomEmpresa').attr('disabled', true);
			break;
		}
	});

	$('#cmbProvincia').change(function(){
		$("#Provincia").val($('#cmbProvincia option:selected').text());
	});

	$('#btnEnviarmail').click(function(){
		if (!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test($("#txtEmail").val()))) {
			alert_error('El e-mail es incorrecto.');
			return false;
		}
		
		if (!$("#chkLOPDLeido").attr("checked"))
		{
			alert_error('Debe aceptar la política de privacidad para enviar sus datos.');
			return false;
		}
		$('#frmenviomail').submit();
  });

	$('a[id^=lnkempleo]').click(function () {
		var peticion = "fn=getoferta&id=" + this.id.replace('lnkempleo', '');
		$.ajax({
			type: "GET",
			url: lurlws,
			data: peticion,
			async:false,
			cache:false,
			dataType: "xml",
			error: function(xml){
				var htm = "";
				alert_error('Error al mostrar la oferta de empleo.');
				$('#divempleo').html(htm);
			},
			success: function(xml){
				var htm = "";
					$(xml).find('row').each(function(){
						$('#txtFecha').html($(this).find('fecha').text() );
						$('#txtTitulo').html($(this).find('titulo').text() );
						htm = $(this).find('descripcion').text();
						htm = htm.replace(/#i#/ig, "<");
						htm = htm.replace(/#f#/ig, ">");
						$('#txtDescripcion').html(htm);
							//htm = htm + "<p>Fecha:<br />" + $(this).find('fecha').text() + "</p><p>Titulo:<br />" + $(this).find('titulo').text() + "</p><p>Descripción:<br />" + $(this).find('descripcion').text() + "</p>" +" <br />"
						});
						//htm = htm + '<button class="boton" id="btnvolverOfertas">Volver</button>';
				$('#divofertas').hide();
				//$('#divempleo').html(htm);
				$('#divempleo').show();
			}//Cierra funcion
		});//Cierra Ajax
	});

	/*$('a[name^=lnknew]').click(function () {
		cargar_noticia(this.id.replace('lnknew', ''));
	});

	function cargar_noticia(id){
		var peticion = "fn=getnoticia&id=" + id;
		$.ajax({
			type: "GET",
			url: lurlws,
			data: peticion,
			async:false,
			cache:false,
			dataType: "xml",
			error: function(xml){
				var htm = "";
				alert_error('Error al mostrar la noticia.');
				$('#divnoticia').html(htm);
			},
			success: function(xml){
				var htm = "";
					$(xml).find('row').each(function(){
						$('#txtFecha').html($(this).find('fecha').text() );
						$('#txtTitulo').html($(this).find('titulo').text() );
						htm = $(this).find('descripcion').text();
						alert(htm);
						alert($(this).find('descripcion').val());
						$('#txtDescripcion').html(htm);
						});
				$('#divnews').hide();
				$('#divnoticia').show();
			}//Cierra funcion
		});//Cierra Ajax
	}*/

	$('#btntipoconst').click(function () {
		window.location= "galeria.php?id_constr=" + $("#cmbtipocontruc").val();
	});
	
	// $('#btntipoconst').click(function () {
		// var peticion = "fn=getgaleriaconst&id_constr=" + $("#cmbtipocontruc").val();
		// $("#cont-fotos-kline-gal").html("");
		// var htm = "";
		// $.ajax({
			// type: "GET",
			// url: lurlws,
			// data: peticion,
			// async:false,
			// cache:false,
			// dataType: "xml",
			// error: function(xml){
				// alert_error('Error al mostrar la galeria por contruccion.');
				// $('#cont-fotos-kline-gal').html(htm);
			// },
			// success: function(xml){
				// htm = '<div id="fotos-kline-gal" class="svw"><ul>';
					// $(xml).find('row').each(function(){
						// htm = htm + '<li><a href = "' + $(this).find('ref').text() + '" title = "' + $(this).find('titulo').text() + '"><img src = "' + $(this).find('ref').text() + '" width="280px" alt="" /></a></li>';
					// });
					// htm= htm + "</ul></div>";
				// $("#cont-fotos-kline-gal").html(htm);
					// $("#fotos-kline-gal").slideView({
					// uiBefore: false,
					// easeFunc: "easeInSine",
					// easeTime: 400
					// });
					// $('#fotos-kline-gal a').lightBox();
			// }//Cierra funcion
		// });//Cierra Ajax
	// });

	$('#btnproducto').click(function () {
		window.location= "galeria.php?id_producto=" + $("#cmbproducto").val();
	});
	
	// $('#btnproducto').click(function () {
		// var peticion = "fn=getgaleriaprod&id_prod=" + $("#cmbproducto").val();
		// $('#div_detalle_producto_2').html("");
		// $.ajax({
			// type: "GET",
			// url: lurlws,
			// data: peticion,
			// async:false,
			// cache:false,
			// dataType: "xml",
			// error: function(xml){
				// var htm = "";
				// alert_error('Error al mostrar la galeria por producto.');
				// $('#fotos-kline-gal').html(htm);
			// },
			// success: function(xml){
				// var htm = '<div style ="float:left;margin: 20px 0px 0px 10px;"><div id="fotos-kline-gal" class="svw"><ul>';
					// $(xml).find('row').each(function(){
						// htm = htm + '<li><a href="' + $(this).find('ref').text() + '" title="' + $(this).find('titulo').text() + '"><img src="./' + $(this).find('ref').text() + '" width="280px" alt="" /></a></li>';
					// });
					// htm= htm + "</ul></div></div>";
				// $('#div_detalle_producto_2').html(htm);
					// $("div#fotos-kline-gal").slideView({
					// uiBefore: false,
					// easeFunc: "easeInSine",
					// easeTime: 800
					// })
					// $('#fotos-kline-gal a').lightBox();
			// }//Cierra funcion
		// });//Cierra Ajax
	// });

	$('#lnkLOPD').click(function () {
			$("#over_lopd").overlay().load();
	});
	$('#lnknlpp').click(function () {
			$("#over_nlpp").overlay().load();
	});
	$('#btnvolverOfertas').click(function () {
				$('#divofertas').show();
				$('#divempleo').hide();
	});
	$('#btnvolvernoticias').click(function () {
				$('#divnews').show();
				$('#divnoticia').hide();
	});
	$('#btnLOPD').click(function () {
			$("#over_lopd").overlay().close();
	});
	$('#btnError').click(function () {
			$("#over_error").overlay().close();
	});
	$('#btnnlpp').click(function () {
			$("#over_nlpp").overlay().close();
	});
	$('#cont').click(function () {
			$("#subcontactar").show();
	});
});
