// JavaScript Document
function iniciarBuscador(FORM,keyWs){	
	var auxW = keyWs.value;	
	auxW=EliminarPalabrasInutiles(auxW);
	while(auxW.indexOf(" ")>=0){
		auxW = auxW.replace(" ","+");}				
	document.getElementById(FORM).action+= "&keywords=" + escape(auxW);
	document.getElementById(FORM).submit();
}
function autoSubmit(e,form){
	var key = window.event ? e.keyCode : e.which;
	if(parseInt(key)==13){
		document.getElementById(form).submit();	
	}
}
//funcion en javascript para quitar preposiciones y articulos para el buscador interno
function EliminarPalabrasInutiles(keywords)
{
	var cadena;	
	var tbprepo = new Array("en "," en "," de "," un "," una "," unas "," unos "," para "," a "," ante "," bajo "," con "," contra "," desde "," durante ", " entre "," hacia "," hasta "," mediante "," para "," por "," según "," segun "," sin "," sobre "," tras ");
	var tbarticulos= new Array(" el "," la "," lo "," las "," los "," este "," estas "," esta "," estos "," este "," del ","Una ","Uno ","Según ","El ","La ","Al ","Las "," y ");
	var tbprepo_ing = new Array(" about "," after "," at "," behind "," beneath "," between "," by "," except "," from "," into "," near "," off "," over "," through "," till "," until "," under "," upon "," without "," above "," among "," before "," below "," beside "," but "," down "," for "," in "," like "," of "," on "," since "," throughout "," to "," up "," with ");
	for(i=0;i<tbprepo.length;i++){
			keywords=keywords.replace(tbprepo[i]," ");
	}
	for(i=0;i<tbarticulos.length;i++){
			keywords=keywords.replace(tbarticulos[i]," ");
	}
	for(i=0;i<tbprepo_ing.length;i++){
			keywords=keywords.replace(tbprepo_ing[i]," ");
	}
	return keywords;
}

//----------------------------------------------------> IDIOMAS
function changeIdioma(prefijo){
	 var pagina=window.location.toString();
	 var url;	
	 var sw=0;
	 if(pagina.lastIndexOf('En') != -1 )
	 {	
		url=pagina.replace('En','Es');		
		sw=1;
	 }
	 if(pagina.lastIndexOf('Es') != -1)
	 {
		 url=pagina.replace('Es','En');		
		 sw=1;
	}	
	if (sw==0)
	{
			url=window.location;
	}
	document.getElementById("fchangeidioma").value = prefijo;
	document.getElementById("frmIdioma").action = url;
	document.getElementById("frmIdioma").submit();
}
//----------------------------------------------------> VAR GLOBALES
var txtNews = "", txtNews2 = "";

//----------------------------------------------------------------WEB FORM
function verDetalleMicrosite(idEtiqueta){	
	var id = document.getElementById(idEtiqueta).value;
	if(id != "")
		window.open("accesorios.asp?ac=1&id=" + id,"","width=500,height=450,scrollbars=0");
	else
		alert("Seleccione un microsite.");
}
function verListaCatSub(){
	window.open("accesorios.asp?ac=2","","width=500,height=450,scrollbars=0")
}
function abrirAccesorios(id){
	window.open("http://www.eventplannerspain.com/accesorios.asp?ac=" + id,"","width=500,height=450,scrollbars=0")
}
//----------------------------------------------------> COLUMNA
function submitNews(){
	var obMail = document.getElementById("fmailnewsletter");
	if(obMail.value != ""){
		if(validarMail(obMail)){
			document.getElementById("frmNews").submit();}
	}
}
function politica(){
	window.open("politica.asp#tratamientoDatos","","width=450,height=500,scrollbars=1")
}
function goBuscador(){
	alert("Buscar");	
}
function goLogin(frm){
	var arrIdes = new Array("fuser","fpass");
	var arrTxt = new Array("el nombre de usuario","la contraseña");
	if(validar(arrIdes,arrTxt,'')){
		document.getElementById(frm).submit();	
	}
}
function txtFocus(input,tieneFoco){
	if(txtNews == "")
		txtNews = input.value;
	if(tieneFoco){
		input.value = "";	
	}else{
		if(input.value == ""){
			input.value = txtNews;	
		}
	}	
}
function txtFocus2(input,tieneFoco){
	if(txtNews2 == "")
		txtNews2 = input.value;
	if(tieneFoco){
		if(input.value == txtNews2)
			input.value = "";	
	}else{
		if(input.value == ""){
			input.value = txtNews2;	
		}
	}	
}
function modifyDatosNews(){
	window.location = "addNews.asp?idForm=1&idioma=Es";
}
function validarModSus(){
	var aux = document.getElementById("femailold");	
	var sw = true;
	if(!validarMail(aux) || aux.value == "")
		sw = false;
	aux = document.getElementById("femailnew");	
	if(!validarMail(aux) || aux.value == "")
		sw = false;
	return sw;
}
//----------------------------------------------------->CONTROLES GENERALES
function control_numerico(){	
	if ((event.keyCode<"48")||(event.keyCode>"57")){
			return false;}
		else{
			return true;}
}
function validar(aErr,aErrT,valEmail){
	var sw = true;	
	var msj = mensajeValidar + ":\n";
	if(valEmail){
		if(!validarMail(document.getElementById(valEmail)))
			sw = false;	
		}
	for(i=0;i<aErr.length;i++){
		if(document.getElementById(aErr[i]).value == ""){
			sw = false;
			msj+= "     · " + aErrT[i] + ".\n";
			document.getElementById(aErr[i]).style.background = "#F1FDC1";
	}else{
		document.getElementById(aErr[i]).style.background = "#D8D0C8";			
	}}
	
	if(msj != mensajeValidar + ":\n")
		alert(msj);

	return sw;
}



function validar2(aErr,aErrT,valEmail,idForm){
	var sw = true;
	var msj = mensajeValidar + ":\n";
	if(valEmail){
		if(!validarMail(document.getElementById(valEmail)))
			sw = false;	
		}
	for(i=0;i<aErr.length;i++){
		if(document.getElementById(aErr[i]).value == ""){
			sw = false;
			msj+= "     · " + aErrT[i] + ".\n";
			document.getElementById(aErr[i]).style.background = "#F1FDC1";			
	}else{
		document.getElementById(aErr[i]).style.background = "#D8D0C8";			
	}}
	if(msj != mensajeValidar + ":\n")
		alert(msj);
	if(sw)
		document.getElementById(idForm).submit();
}
function validarMail(mail){
	if (mail.value.indexOf("@") < 0 && mail.value.length > 0) {
		alert ('El valor del e-mail no se corresponde con un patrón válido');		
		return false;}
	else 
		return true;	
}



function getIdiomaCliente(){
	//CET
	var sw = true;
	if (navigator.userAgent.indexOf("Opera")!=-1) (language=navigator.language) 
	
	else{ 
		if (navigator.appName == "Netscape") (language=navigator.language) 
		
		else 
			language=navigator.browserLanguage }; 

	if (language){
		language=language.substring(0,2)
		} 
	else{
		language="zz"} 
	switch (language) { 
//		case "en" : window.location="Pagina_en_ingles.html"; break; 
		case "es" : sw = false; break; 
//		case "ca" : window.location="Pagina_en_catalan.html"; break; 
//		case "zz" : window.location="Pagina_en_catalan.html"; break; 
		default : window.location="Pagina_en_catalan.html" } 
	if(sw)
		document.write("CET");
}
//----------------------------------------------------------------LISTADOS EMPRESAS
function selTodos(n, ob){
	try{
	for(i=0;i<n+1;i++){
		document.getElementById("fprov" + i).checked = ob.checked;}
	}catch(e){}
}

function selTodosjj(ini, n, ob){
	try{
	for(i=ini;i<n+1;i++){
		document.getElementById("fprov" + i).checked = ob.checked;}
	}catch(e){}
}

function selTodos2(n, ob){
	try{
		for(i=0;i<n;i++){
			document.getElementById("floc" + i).checked = ob.checked;}
	}catch(e){
		
	}
}
function selTodos3(m, ob){
	document.getElementById("ftodas").checked = ob.checked;	
	for(i=1;i<20;i++){
		document.getElementById("ftodas" + i).checked = ob.checked;}
	selTodosjj(1, 8, ob)
	selTodosjj(10, 57, ob)
}

//------------------------------------------->
function cmbEnviarA(origen,destino,maximo){
	var desde = document.getElementById(origen);
	var hasta = document.getElementById(destino);
	var frase = new String();
	if(hasta.options.length < maximo){
		if(desde.selectedIndex >= 0){
			hasta.options[hasta.options.length] = new Option(desde.options[desde.selectedIndex].innerHTML,desde.options[desde.selectedIndex].value);
			
			frase=desde.options[desde.selectedIndex].title; 

			frase2=desde.options[desde.selectedIndex].value;
			
			if (frase2.length>0) { 
			   if ((frase2==1)||(frase2==105)||(frase2==2)||(frase2==13)||(frase2==3)||(frase2==4)||(frase2==5)||(frase2==10)||(frase2==6)
                  ||(frase2==7)||(frase2==8)||(frase2==9)||(frase2==114)||(frase2==11)||(frase2==12)||(frase2==14))
			      frase2="optg1"; 
			   if ((frase2==37)||(frase2==29)||(frase2==30)||(frase2==31)||(frase2==33)||(frase2==34)
                  ||(frase2==35)||(frase2==36)||(frase2==38)||(frase2==39)||(frase2==40)||(frase2==41))
			      frase2="optg5";
			   if ((frase2==16)||(frase2==17)||(frase2==42)||(frase2==104)||(frase2==19)||(frase2==21)||(frase2==23)
                  ||(frase2==22)||(frase2==18)||(frase2==20))
			      frase2="optg2";
			   if ((frase2==47)||(frase2==112)||(frase2==48)||(frase2==49)||(frase2==50)||(frase2==51)||(frase2==52)
                  ||(frase2==53))
			      frase2="optg7";
			   if ((frase2==25)||(frase2==26)||(frase2==27)||(frase2==28))
			      frase2="optg3";
			   if ((frase2==89)||(frase2==90)||(frase2==91)||(frase2==92)||(frase2==93)||(frase2==95)||(frase2==96))
			      frase2="optg12";
			   if ((frase2==83)||(frase2==84)||(frase2==85)||(frase2==86)||(frase2==87)||(frase2==88))
			      frase2="optg11";			  
			   if ((frase2==61)||(frase2==62)||(frase2==63)||(frase2==64)||(frase2==65)||(frase2==66)
			      ||(frase2==67)||(frase2==68)||(frase2==69)||(frase2==70))
			      frase2="optg9";			  
			   if ((frase2==97)||(frase2==98)||(frase2==99)||(frase2==100)||(frase2==101)||(frase2==102)
			      ||(frase2==103))
			      frase2="optg13";			  
			   if ((frase2==54)||(frase2==55)||(frase2==56)||(frase2==57)||(frase2==113)||(frase2==58)||(frase2==59)
			      ||(frase2==60))
			      frase2="optg8";			  
			   if ((frase2==71)||(frase2==72)||(frase2==73)||(frase2==74)||(frase2==75)||(frase2==76)
			      ||(frase2==77)||(frase2==78)||(frase2==79)||(frase2==80)||(frase2==81))
			      frase2="optg10";			  
			   if ((frase2==43)||(frase2==44)||(frase2==45)||(frase2==46))
			      frase2="optg6";
			}
			
			
			if (frase.indexOf("optg") < 0 && frase.length > 0) {
			   hasta.options[hasta.options.length-1].title = desde.options[desde.selectedIndex].title+"*"+frase2;
			}
		    else {
			   hasta.options[hasta.options.length-1].title = desde.options[desde.selectedIndex].title;
			}
   
			   
			desde.options[desde.selectedIndex] = null;}
	}else{
		alert("Según el tipo de Minisite elegido seleccionar más elementos!");		
	}
}
function cmbDevolverA(origen){
	var desde = document.getElementById(origen);
	var idOptg = desde.options[desde.selectedIndex].title;
	idOptg = idOptg.substring(idOptg.indexOf("*")+1);
	identificador = "optg"+idOptg.substring(idOptg.indexOf("*")+5);
	titulo = desde.options[desde.selectedIndex].title;
	desde.options[desde.selectedIndex].title = titulo.substring(0,titulo.indexOf("*"));
	//desde.options[desde.selectedIndex].label= identificador;
	document.getElementById(idOptg).appendChild(desde.options[desde.selectedIndex]);
}
function cmbDevolverA2(origen, destino){
	var hasta = document.getElementById(destino);
	hasta.options[hasta.options.length] = new Option(origen.options[origen.selectedIndex].innerHTML,origen.options[origen.selectedIndex].value);
	origen.options[origen.selectedIndex] = null;	
}

//<---------------------------------------------
function validarPaso3(idInput,idForm){
	var ob = document.getElementById(idInput);
	if(ob.options.length == 0){
		alert("Debe seleccionar una subcategoria por lo menos!!");	
		return false;
	}else{
		for(j=0;j<ob.options.length;j++)
			ob.options[j].selected = true;
		document.getElementById(idForm).submit();
	}
}
function validarPaso4(){
	var user, pass, recPass, msj, sw;
	sw = true;
	user = document.getElementById("fusuarioMinisite");
	pass = document.getElementById("fpasswordMinisite");
	recPass = document.getElementById("fpasswordMinisite2");
	msj = "Faltan por rellenar los siguientes campos: \n";
	if(user.value == ""){
		msj+= " · El nombre de usuario!\n";		
		sw = false;
	}
	if(pass.value == ""){
		msj+= " · La contraseña!\n";		
		sw = false;
	}
	if(recPass.value == ""){
		msj+= " · Repita la contraseña!\n";		
		sw = false;
	}	
	if(!sw){
		alert(msj);
	}
	if(pass.value != recPass.value){
		recPass.value = "";
		sw = false;
		alert("Ha repetido mal la contraseña!")
	}
	return sw;		
}
function validarAdminSite(idInput1,idInput2,idForm){
	var ob = document.getElementById(idInput1);
	var ob2 = document.getElementById(idInput2);
	if(ob.options.length == 0){
		alert("Debe seleccionar una subcategoria por lo menos!!");	
		return false;
	}else{
		for(j=0;j<ob2.options.length;j++)
			ob2.options[j].selected = true;
		for(j=0;j<ob.options.length;j++)
			ob.options[j].selected = true;
		document.getElementById(idForm).submit();
	}
}
function goURL(url){
	window.location = url;	
}
function salirAdmin(){
	window.location = "exitAdmin.asp";	
}
//////////////////--------------------------->
function expandirSelect1(o){
	o.style.position = "absolute";
	o.style.width = "";
}
function comprimirSelect1(o){
	o.style.position = "relative";
	o.style.width = "138px";
	
}
//-----------------------------------------------------------------------------CONTADORES DE PALABRAS
var charAcontar = new Array(" ");
var swWordCounter = true;
function SingleCounter(obj,maxWords,display,e){
	var aux, cont = 0, sw;	
	aux = obj.value;													
	if(aux != ""){
		aux+= " ";
		sw = false;
		for(k=0;k<charAcontar.length;k++){
			while(aux.indexOf(charAcontar[k])>=0){										
				aux = aux.substring(aux.indexOf(charAcontar[k])+1);										
				cont++;
				sw = true;
			}
		}
	if(!sw)
		cont++;
	}
	document.getElementById(display).innerHTML = cont;
	if(cont > parseInt(maxWords)){
		try{
			var key = window.event ? e.keyCode : e.which;		
			if((parseInt(key)>=97 && parseInt(key)<=122) || (parseInt(key)>=65 && parseInt(key)<=90) || (parseInt(key)>=48 && parseInt(key)<=57)){
				if(swWordCounter)										
					alert("Ha superado el límite máximo de " + maxWords + " palabras!!");
				return false;
			}else{
				if(parseInt(key) == null || parseInt(key) == 8 || parseInt(key) == 0)
					return true;
				else{
					if(swWordCounter)										
						alert("Ha superado el límite máximo de " + maxWords + " palabras!!");
					return false;
					}
			}
		}catch(er){}
		
	}else{
		return true;
	}		
}


//-----------------------------------------------------------------
function verDetalleNoticia(idNoticia){
	document.getElementById("fidNoticia").value = idNoticia;
	document.getElementById("FormBuscador").action = "noticias_eventos.asp?id=" + idNoticia;
	document.getElementById("FormBuscador").submit();
}
function paginar(nPage, form){
	document.getElementById("p").value = nPage;
	/*document.getElementById(form).submit();  */	
	document.FormBuscador.submit();
}
function paginacionProveedores(total,pag,val,ancla,categoria)
{
	/*document.FormBuscador.action="empresas.asp?idcat=" + categoria;*/
	document.FormBuscador.action="";
/*	document.FormBuscador.action="empresas.asp#" + ancla;*/
	document.FormBuscador.tot.value=total;
	document.FormBuscador.page.value=pag;
	document.FormBuscador.hdnvalores.value=val;
	document.FormBuscador.submit();
}
function paginacionLugares(total,pag,val,ancla)
{
	document.FormBuscador.action="buscalugares.asp?idcat=1#" + ancla;
	document.FormBuscador.tot.value=total;
	document.FormBuscador.page.value=pag;
	document.FormBuscador.hdnvalores.value=val;
	document.FormBuscador.submit();
}
function paginacionAgencias(total,pag,val,ancla)
{
	document.FormBuscador.action="";
	/*document.FormBuscador.action="buscaAgencias.asp?idcat=2#" + ancla;*/
	document.FormBuscador.tot.value=total;
	document.FormBuscador.page.value=pag;
	document.FormBuscador.hdnvalores.value=val;
	document.FormBuscador.submit();
}
function paginarAncla(nPage,form,ancla){
	document.getElementById(form).action="buscador2.asp#" + ancla;
	document.getElementById("p").value = nPage;
	document.getElementById(form).submit();	
}
function Rellenar(total,pag,val,ancla){	
	document.FormBuscador.action="buscador2.asp#" + ancla;
	document.FormBuscador.tot.value=total;
	document.FormBuscador.page.value=pag;
	document.FormBuscador.hdnvalores.value=val;
	document.FormBuscador.submit();
}
function Rellenarprov(total,pag,val,ancla){	
	document.FormBuscador.action="buscador-provincia.asp#" + ancla;
	document.FormBuscador.tot.value=total;
	document.FormBuscador.page.value=pag;
	document.FormBuscador.hdnvalores.value=val;
	document.FormBuscador.submit();
}
function eliminarImagenCliente(idimagen,m_link){
	if(confirm("¿Confirma que desea eliminar esta imagen?")){
		window.open("eliminarImagenCliente.asp?idImgCte="+idimagen);
	}
}
function eliminarLogoCliente(idcliente){
	if(confirm("¿Confirma que desea eliminar el logo?")){
		window.open("eliminarImagenCliente.asp?idCteLogo="+idcliente);
	}
}
function mensajeImagenEliminada(mensaje){
	alert(mensaje);
}
var valueRadio = "";
function deseleccionarRadio(radio){
	if(radio.checked && radio.value == valueRadio){
		radio.checked = false;		
		valueRadio = "";
	}else{
		if(valueRadio != radio.value){
			valueRadio = radio.value;
		}	
	}
}
