	
	String.prototype.replaceAll=function(s1, s2) {
		return this.split(s1).join(s2);
	}
	
	// Función de validación de adjuntos
	function adjuntoValida(valor) {
		valor = valor.toLowerCase();
		valor = valor.replaceAll(" ", "");
		valor = valor.replaceAll("á", "a");
		valor = valor.replaceAll("é", "e");
		valor = valor.replaceAll("í", "i");
		valor = valor.replaceAll("ó", "o");
		valor = valor.replaceAll("ú", "u");		

		return new RegExp(/\w+\.*[doc|pdf|jpg|mp3|mov|swf|rtf|DOC|PDF|JPG|MP3|MOV|SWF|RTF]$/).test(valor);
	}
	

	function emailValido(valor) {
		var EmailOk = true;
		var AtSym = valor.indexOf('@');
		var Period = valor.lastIndexOf('.');
		var Space = valor.indexOf(' ');
		var Length = valor.length - 1;
		if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1)) {  
			  EmailOk = false;
		}
		return EmailOk;
	}

	function validar() {
		
		var urlExp= /(ht|f)tp(s?):\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
		var emailExp1 = '/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/';

		var emailExp = new RegExp(emailExp1,"i");
		//var urlExp = new RegExp(urlExp1,"i");
		
		var frm = window.document.inscripcion;

		var miurl = document.location.href;
		var idioma = miurl.indexOf('/en/') > 0 ? 'ingl' : 'cast';
		
		if (frm.artista.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca el artista');
			else 
				window.alert('Please, insert the artist');
			frm.artista.focus();
			return;
		}
		
		if (frm.direccion.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca la direccion');
			else
				window.alert('Please, insert the address');
			frm.direccion.focus();
			return;
		}
		
		/*
		if (frm.cp.value == '') {
			window.alert('Por favor, introduzca el código postal');
			frm.cp.focus();
			return;
		}
		*/
		
		if (frm.ciudad.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca la ciudad');
			else
				window.alert('Please, insert the city');
			frm.ciudad.focus();
			return;
		}
		
		if (frm.telefono.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca el telefono');
			else
				window.alert('Please, insert the phone number');
			
			frm.telefono.focus();
			return;
		}
		
		if (frm.email.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca el email');
			else
				window.alert('Please, insert the e-mail address');
			
			frm.email.focus();
			return;
		}
		
		/*
		if (!emailExp.test(frm.email.value)) {
			window.alert('El email introducido no es válido');
			frm.email.focus();
			return;	
		}
		*/

		if(!emailValido(frm.email.value)) {
			if(idioma == 'cast')
				window.alert('El email introducido no es valido');
			else
				window.alert('The e-mail is not valid');
			
			frm.email.focus();
			return;	
		}
		
		if (frm.titulo.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca el titulo');
			else
				window.alert('Please, insert the title');
			
			frm.titulo.focus();
			return;
		}
		
		if (frm.descripcion.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca la descripcion');
			else
				window.alert('Please, insert the description');
			
			frm.descripcion.focus();
			return;
		}

		if (frm.urlpropuesta.value != '' && frm.urlpropuesta.value != 'http://' && !urlExp.test(frm.urlpropuesta.value)) {
			if(idioma == 'cast')
				window.alert('La url de la propuesta ampliada no es valida');
			else
				window.alert('The expanded proposal URL is not valid');
			
			frm.urlpropuesta.focus();
			return;	
		}

		/*
		if(frm.documentopropuesto.value != '' && !adjuntoValida(frm.documentopropuesto.value)) {
			if(idioma == 'cast')
				window.alert('El documento adjunto a la url de la propuesta ampliada no es válido. Por favor, revise el formato');
			else
				window.alert('The document attached to the expanded proposal URL is not valid. Please, review the format');
			
			frm.documentopropuesto.focus();
			return;	
		}
		*/

		if (frm.cv.value == '') {
			if(idioma == 'cast')
				window.alert('Por favor, introduzca el cv');
			else
				window.alert('Please, insert the CV');
			
			frm.cv.focus();
			return;
		}

		if(!adjuntoValida(frm.cv.value)) {
			if(idioma == 'cast')
				window.alert('El cv adjunto no es valido. Por favor, revise el formato');
			else
				window.alert('The attached CV is not valid. Please, review the format');
			
			frm.cv.focus();
			return;	
		}
	
		frm.nombrepais.value = frm.pais.options[frm.pais.selectedIndex].text;

		frm.action = idioma == 'cast' ? '/arte-web-confirmar.php?lang=cast' : '/en/arte-web-confirmar.php?lang=en';
		frm.submit();
		
	}


