
//obtiene los parametros de la url
function getParameter(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  	var regexS = "[\\?&]"+name+"=([^&#]*)";
  	var regex = new RegExp( regexS );
  	var results = regex.exec( window.location.href );
  	if( results == null )
		return "";
  	else
    	return results[1];
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
}


function votar1(idComponente)
{
	var indice = window.document.forms["form"+idComponente].pVoto.selectedIndex;
	var voto	= window.document.forms["form"+idComponente].pVoto[indice].value;
	if(voto==-1)
	{
		alert("Debe seleccionar un valor del voto");
		return false;
	}
	else
	{
		fAbrirVentana('','ventana_votar','scrollbars=no,resizable=yes,width=1000,height=500');
		
		window.document.forms["form"+idComponente].action = "/servicios/galeriasMultimedia/votacion.jsp";
		window.document.forms["form"+idComponente].target = "ventana_votar";
   	window.document.forms["form"+idComponente].submit();
	}
}   

function descargarOriginal(idComponente)
{
	window.document.forms["form"+idComponente].action = "/servicios/galeriasMultimedia/original.jsp";
	window.document.forms["form"+idComponente].target = "_blank";
	window.document.forms["form"+idComponente].submit();
}

function fAbrirVentana(theURL,winName,features) 
{
	window.open(theURL,winName,features);
}

function EmailAntiSpam(titulo, contenido)
{
	locationString = "mailto:?subject="+portal+": "+titulo;
	locationString += "&body="+contenido;
	locationString += "<br/><br/>"+url;
	location = locationString;		
}

function compruebaTexto(idioma)
{
   var texto = document.formComent.pTexto.value;
 			
 	if (texto.length == 0)
 	{
 		if (idioma=='es')
			alert ("Debe escribir algo en la casilla de texto");
		else if (idioma=='ca') 		
			alert ("Ha d'escriure una mica en la casella de text");
			else if (idioma=='de')
				alert ("Bitte füllen Sie das Textfeld aus");
				
		document.formComent.pTexto.focus();
		return false;
 	}
  		return true;
}	

function compruebaNombre(idioma)
{
   var nombre = document.formComent.pNombreUsuario.value;
 			
 	if (nombre.length == 0)
 	{
 		if (idioma=='es')
			alert ("Debe indicar un nombre obligatoriamente");
		else if (idioma=='ca')
			alert ("Ha d'indicar un nom obligatòriament");
			else if (idioma=='de')
				alert ("Sie müssen einen Namen angeben");			
			
			
		document.formComent.pNombreUsuario.focus();
		return false;
 	}
  		return true;
}			
	
function enviar(idioma)
{	

	if(compruebaTexto(idioma) && compruebaTamTexto(document.formComent.pTexto, 4000, idioma))
	{
		if(compruebaNombre(idioma))
		{
				fAbrirVentana('','ventana_coment','scrollbars=no,resizable=yes,width=600,height=100');
				document.formComent.action = "/servicios/galeriasMultimedia/almacenar_comentario.jsp?idGaleria="+idGaleria+"&idComponente="+idComponente+"&idioma="+idioma+"&pFechaGaleria="+fechaGaleria;				
				document.formComent.submit();	
				
				//Borramos todos los campos del comentario añadido
				document.formComent.pTexto.value = "";
				document.formComent.pNombreUsuario.value = "";
			}
		}
}
	

function compruebaTamTexto(objTexto, tamMax, idioma)
{
	var texto="";
	var error="";
	
	if(objTexto!=null)
	{
		texto=objTexto.value;
		
		if(texto.length>tamMax)
		{
			error="El tam. máximo permitido es de "+tamMax+" caracteres.";
		}
	}

	if(error!="")
	{
		alert(error);
		return false;
	}

	return true;				
}

function getElementsByClassName(clsName) {
   var i, matches=new Array();
   var els=document.getElementsByTagName("div");

   for(i=0; i<els.length; i++) {
      if(els.item(i).className==clsName) {
         matches.push(els.item(i));
      }
   }
   return matches;
}


