/*****FUNCIONES SUBMENU LATERAL*****/
function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
function ChangeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 
function getURL(url) { 
	window.location=url;
} 

/**COMPROBACIONES DE CAMPOS DE FORMULARIOS**/
function ComprobarEmail(texto)
{
	var mailres = true;             
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
    var arroba = texto.indexOf("@",0); 

    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 

    var punto = texto.lastIndexOf("."); 
                 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
     mailres = true; 
    else 
     mailres = false;    
	 
    return mailres; 
}

function ComprobarTelefono(valor){ 
    //expresion regular para telefonos
    //permite campos vacios y guiones
    var tlfono = /^[0-9]{2,3}-? ?[0-9]{6,7}$/

    //comprueba campo tlfono de formu
    //usa el metodo test de expresion regular
    if(!tlfono.test(valor)) {
       return false    //no submit
    }

    return true         
} 

/******CAMBIAR IMAGEN Y COMENTARIO***********/
function cambiarImagen(ruta,comentario)
{
	document.getElementById('comentarios').innerHTML=comentario;
	document.images['imgGrande'].src="imagenes/"+ruta;
}
function obtener_ancho()
{
if (navigator.userAgent.indexOf("MSIE") > 0)
{
return(document.body.clientWidth);
}
else
{
return window.outerWidth;
}
}
function obtener_alto()
{
if (navigator.userAgent.indexOf("MSIE") > 0)
{
return(document.body.clientHeight);
} 
else
{
return(window.outerHeight);
}
}

/******ABRIR VENTANA NUEVA CENTRADA*******/
function openw(ventana,foto,nombre,ancho,alto,x,y,modtam,scrl,rec)
{
  var X = obtener_ancho() / 2;
  var Y = obtener_alto() / 2;

  x=(window.screenTop + (Y - (alto/2))); 
  y=(window.screenLeft + (X - (ancho/2)));

  ventana=window.open(foto,nombre,"toolbar=no,alwaysRaised=yes,dependent=yes,tilebar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrl+",resizable="+modtam+",copyhistory=no,width="+ancho+",height="+alto+",screenx="+x+",screeny="+y+",top="+x+",left="+y);
  ventana.focus();
}

function parseaParametro(param) {
    //NOTA: Esta funcion no es del todo correcta: Caso de parametros: art, nomart. Si
    //buscas art y el segundo parametro es nomart, devuelve nomart (maaal)
	var url=window.location.href;
	var posalmohada = url.lastIndexOf('#');
	if(posalmohada!=-1) url=url.substr(0,posalmohada);
	var aux=url.lastIndexOf(param+"=");
	if(aux==-1) { return aux; }
	else {
		var valor=url.substr(aux+param.length+1, url.length)+"&";
		valor=valor.substr(0, valor.indexOf("&"));
		return valor;
	}
}

function parseaParametroURL(url,param) {
    //NOTA: Esta funcion no es del todo correcta: Caso de parametros: art, nomart. Si
    //buscas art y el segundo parametro es nomart, devuelve nomart (maaal)
	var aux=url.lastIndexOf(param+"=");
	if(aux==-1) { return aux; }
	else {
		var valor=url.substr(aux+param.length+1, url.length)+"&";
		valor=valor.substr(0, valor.indexOf("&"));
		return valor;
	}
}

function convertirDecimal(valor){
  var poscoma=valor.indexOf(",");
  if(poscoma!=-1){
      return (valor.substr(0,poscoma)+"."+valor.substr(poscoma+1));
  }
  else return valor;
}

function maxDecimal(num,valor){
    pos=valor.indexOf(".");
    valor=parseFloat(valor)+"";
    dec=valor.substr(pos+1);
    if(pos!=-1) {
      if(dec=="" || dec=="0") {return false;}
      if(dec.length>num) return false;
      else return true;
    } else return true;
}

function introtab(e,myForm,next){
 if(!e) e = window.event;
 codtecla = (document.all)?e.keyCode:e.which;
 if(codtecla == 13)
   if(!eval("myForm."+next+".readOnly;")) eval("myForm."+next+".focus();"); //Pasa al siguiente si está vacio
}

function Trim( str ) {
var resultStr = "";
resultStr = TrimLeft(str);
resultStr = TrimRight(resultStr);
return resultStr;
}

function TrimLeft( str ) {
var resultStr = "";
var i = len = 0;
if (str+"" == "undefined" || str == null) 
return "";
str += "";

if (str.length == 0) 
resultStr = "";
else { 
len = str.length;
while ((i <= len) && (str.charAt(i) == " "))
i++;
resultStr = str.substring(i, len);
}
return resultStr;
}

function TrimRight( str ) {
var resultStr = "";
var i = 0;
if (str+"" == "undefined" || str == null) 
return "";
str += "";
if (str.length == 0) 
resultStr = "";
else {
i = str.length - 1;
while ((i >= 0) && (str.charAt(i) == " "))
i--;
resultStr = str.substring(0, i + 1);
}

return resultStr; 
}

function bloqueaBorrado(e){	
  if(!e) e = window.event;
  codtecla = (document.all)?e.keyCode:e.which;
  if(document.activeElement==null) return true;
  else {
    if(document.activeElement.type!="text" || document.activeElement.readOnly)
      if(codtecla==8) return false;      
  }
}

