// deteccion del navegador 
ns4 = (document.layers) ? true:false;
ie4 = (document.all) ? true:false;
//
function noenter() {
  return !((window.event) && (''+window.event.keyCode== '13')); 
}
function recomposicion(){
	var tam=window.innerWidth;
	if ((tam) && (tam!='')){
		tam=parseInt(tam)-145;
		tam=parseInt(tam)-221;
	}else{
		var tam=document.all.tabposicion.clientWidth;
		if ((tam) && (tam!='')){
			tam=parseInt(tam)-125;
			tam=parseInt(tam)-221;
		}
	}
	var img=450;
	if (tam>img){
		if (document.all){
			document.all.divcomposicion.style.left=tam;
		}else if (document.getElementById){
			document.getElementById("divcomposicion").style.left=tam;
		}else{
			document.divcomposicion.style.left=tam;
		}
	}
	if (document.all){
		document.all.divcomposicion.style.visibility="visible";
	}else if (document.getElementById){
		document.getElementById("divcomposicion").style.visibility="visible";
	}else{
		document.divcomposicion.style.visibility="visible";
	}

}
function isEmailAddress(theElement)
{
var s = theElement;
var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
   if (filter.test(s))
      return true;
   else
     alert("Introduzca una direccion de correo valida");
//theElement.focus();
return false;
}
// abrir ventana nueva
function abrir_v (pag,tam_x,tam_y,vent,scroll,resize,menu,tool,status) {
 var pos_x, pos_y;
 scroll = (scroll==null) ? false : scroll;
 scroll = (scroll) ? "yes" : "no";
 resize = (resize==null) ? false : resize;
 resize = (resize) ? "yes" : "no";
 menu = (menu==null) ? false : menu;
 menu = (menu) ? "yes" : "no";
 tool = (tool==null) ? false : tool;
 tool = (tool) ? "yes" : "no";
 status = (status==null) ? false : status;
 status = (status) ? "yes" : "no";
 tam_x = (tam_x==null) ? 640 : tam_x;
 tam_y = (tam_y==null) ? 300 : tam_y;
 if (ns4 || ie4) {
 	var alto=window.screen.height;
 	var ancho=window.screen.width;
	pos_x = (ancho-tam_x)/2;
	pos_y = (alto-tam_y)/2-20;
 } else {
 	pos_x = 0;
 	pos_y = 0;
 }
 return(window.open(pag, vent, "toolbar="+tool+",directories=no,menubar="+menu+",scrollbars="+scroll+",location=no,status="+status+",resizable="+resize+",width="+tam_x+",height="+tam_y+",left="+pos_x+",top="+pos_y));
}

function abrir (pag) {
 vent = abrir_v(pag,null,null,"vent","true","true","true","true","true");
}

function abrir (pagina){
  location.href=pagina;
}

// abrir chromeless
function abrir_ventana (u,W,H,X,Y,n) {
	var cD  ='../img/ventana/iCerrar.gif'
	var cU  ='../img/ventana/iCerrar.gif'
	var cO  ='../img/ventana/iCerrar_on.gif'
	var cL  =''
	var tH  ='../img/ventana/cabecera.gif'
	var tW  =''
	var wB  ='#000000'
	var wBs ='#FC9048'
	var wBG ='#FC9048'
	var wBGs='#FF6600'
	var wNS ='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0'
	var fSO ='scrolling=no noresize'
	return chromeless(u,n,W,H,X,Y,cD,cU,cO,cL,tH,tW,wB,wBs,wBG,wBGs,wNS,fSO)
//chromeless(u,n,W,H,X,Y,cD,cU,cO,cL,tH,tW,wB,wBs,wBG,wBGs,wNS,fSO)
//return false;
}

/**********************funciones de pagina***********************************/
function compruebavalida(){
	sform=document.formvalida;
	if (sform.accion.value=='valida')
	{
		if (sform.user.value==''){
			alert('No se ha introducido el usuario.');
			return false;
		}
		else if (sform.clave.value==''){
			alert('No se ha introducido la clave.');
			return false;
		}
		else{
			return true;
		}
	}else if (sform.accion.value=='olvido')
	{
		if (sform.user.value==''){
			alert('No se ha introducido el usuario.');
			return false;
		}
		else{
			return true;
		}
	}

}
function comprobarcampo(ncampo){
	if (document.getElementById(ncampo).value==''){
		alert('El campo debe estar relleno');
	}
	else{
		document.formaccion.submit();
	}
}
function cambiarAcc(acc){
	document.formaccion.action=acc;
	document.formaccion.submit();
}
function cambiarFormu(acc){
	document.formu.action=acc;
	document.formu.submit();
}
function rellenarCampo(ncampo,valor){
	document.getElementById(ncampo).value=valor;
}
function rellenarCampo(ncampo,valor){
	document.getElementById(ncampo).value=valor;
}
function irA(acc,ncampo,valor,act){
	if (acc=='borrar'){
		if (confirm('¿Esta seguro de querer eliminar el registro?')==false){
			return;
		}
	}
	document.formu.accion.value=acc;
	if ((ncampo)&&(ncampo!=null)&&(ncampo!='')){document.formu.campoid.value=valor;}
	if ((act)&&(act!=null)&&(act!='')){document.formu.action=act;}
	document.formu.submit();
}
function irAVal(acc,ncampo,valor,act){
	if (acc=='borrar'){
		if (confirm('¿Esta seguro de querer eliminar el registro?')==false){
			return;
		}
	}
	document.formvalida.accion.value=acc;
	if ((ncampo)&&(ncampo!=null)&&(ncampo!='')){document.formvalida.campoid.value=valor;}
	if ((act)&&(act!=null)&&(act!='')){document.formvalida.action=act;}
	document.formvalida.submit();
}

function modiftarget(sttarget){
	document.formu.target=sttarget;
}

function longitud(val, len)
{
	if(val.length > len)
	{
		alert("Error. El campo sobrepasa de " + len + " caracteres");
		return false;
	}
	return true;
}

function longitudexacta(val, len)
{
	if(val.length < len){
		alert("Error. El campo debe de contener " + len + " caracteres");
		return false;
	}
	return true;
}

/**************Comprueba que el string que le pasamos son todo numeros****************/

function sondecimales(val, enteros, decimales)
{
  var test1=',0123456789';
  var test2=',0123456789';
  var c, ndec=0, nent=0;
  var decimal=false;
  var numero=true;
  var partedecimal=false;
  
  while(val.indexOf(" ")!=-1)
  {
	val=val.substring(1,val.length);
  }


  for(var i=0;i < val.length;i++)
  {
	c=test2.indexOf(val.charAt(i));
	if(c<0)
		numero=false;
	else
	if(c==0)
		partedecimal=true;
	else
	{
		if(partedecimal==true)
			ndec++;
		else
			nent++
	}
  }

  if (numero==false || ndec>decimales || (enteros!=null && nent>enteros) )
  {
	if (enteros!=null){
		alert("Error. Introduzca un Número de "+enteros + " enteros y " + decimales + " decimales");
	}
	else{
		alert("Error. Introduzca un Número con "+ decimales + " decimales como maximo");
	}
    return false;
  }
  return true;
}
function soncantidades(val)
{
  var test1=',0123456789';
  var test2=',0123456789';
  var c;
  var decimal=false;
  var numero=true;
  while(val.indexOf(" ")!=-1){
		val=val.substring(1,val.length);
  }
  for(var i=0;i < val.length;i++)
    {
	c=test2.indexOf(val.charAt(i));
	if (c<0){
		numero=false;
		}
	}
  if (numero==false)
    {
	alert("Error. Introduzca un Número.");
    return false;
	}
  return true;
}

function sonnumeros(val)
{
  var test1='0123456789';
  var test2='0123456789';
  var c;
  var decimal=false;
  var numero=true;
  while(val.indexOf(" ")!=-1){
		val=val.substring(1,val.length);
  }
  for(var i=0;i < val.length;i++)
    {
	c=test2.indexOf(val.charAt(i));
	if (c<0){
		numero=false;
		}
	}
  if (numero==false)
    {
	alert("Error. Introduzca un Número.");
    return false;
	}
  return true;
}

/**************Busca el elemento que indiquemos****************/

function Buscarelemento(elem,cadena)
{
if (cadena!=''){
	if (cadena.indexOf(elem)!=-1)
		{cadena=cadena.substring(cadena.indexOf(elem)+1,cadena.length);
		if (cadena.indexOf(elem)!=-1)
			{alert('El texto escrito no es un E-mail.Introduzca el dato correctamente.')
			return false;}
		else
			{return true;}
		}		
	else
		{alert('El texto escrito no es un E-mail.Introduzca el dato correctamente.')
		return false;}
	}
return true;
}

/**************funcion para comprobar que el string que se pasa es una fecha****************/
function compruebafecha(f) {
if (f.length == 10){
	var test="0123456789";
	var i;
	for (i=0;i<2;i++)
		{
		if (test.indexOf(f.charAt(i))<0){
			alert(f.substring(0,2)+" dia no valido");
			return false;}
		}
	for (i=3;i<5;i++)
		{
		if (test.indexOf(f.charAt(i))<0){
			alert(f.substring(3,5)+" mes no valido");
			return false;}
		}
	for (i=6;i<10;i++)
		{
		if (test.indexOf(f.charAt(i))<0){
			alert(f.substring(6,10)+" año no valido");
			return false;}
		}
 if  (isBetween(parseInt(f.substring(0,2),10),1,31)==false) {
	alert(f.substring(0,3)+" dia no valido");
    return false;
 }
 if (isBetween(parseInt(f.substring(3,5),10),1,12)==false) {
	alert(f.substring(3,5)+" mes no valido");
    return false;
 }
 if ( f.substring(5,6)!="/") {
		alert(f.substring(5,6)+" separador no valido");
    return false;
 }
  if ( f.substring(2,3)!="/") {
		alert(f.substring(2,3)+" separador no valido");
    return false;
 }
 if ( parseInt(f.substring(6,10),10)==false ) {
	alert(f.substring(6,10)+" año no valido");
    return false;
 }
 if ( (parseInt(f.substring(0,3),10)==31) && ((parseInt(f.substring(3,5),10)==11)||(parseInt(f.substring(3,5),10)==4)||(parseInt(f.substring(3,5),10)==6)||(parseInt(f.substring(3,5),10)==9))) {
	alert(f+" fecha incorrecta");
    return false;
 }
 if ( parseInt(f.substring(3,5),10)==2 && (parseInt(f.substring(0,3),10)>29)) {
	alert(f+" fecha incorrecta");
    return false;
 }
//bisiestos
 if (( parseInt(f.substring(3,5),10)==2) && (parseInt(f.substring(0,3),10)==29)) {
	if ((parseInt(f.substring(8,10))==0) && (parseInt(f.substring(6,8)) % 4!=0))	{
   	  alert("No es bisiesto");
      return false;
	}
	if ((parseInt(f.substring(8,10),10)!=0) && (parseInt(f.substring(8,10),10) % 4 != 0))	{
   	  alert("No es bisiesto");
      return false;
	}
 }
}
else
{
	if (f.length > 0)
	{
		alert(f+" fecha incorrecta. El formato debe ser dd/mm/aaaa");
		return false;
	}
}
return true;
}
function ultimodiames(f){
	mes=parseInt(f.substring(3,5),10);
	if (mes==2) {
		if ((parseInt(f.substring(8,10))==0) && (parseInt(f.substring(6,8)) % 4!=0))	{
	   	  return '28';
		}
		if ((parseInt(f.substring(8,10),10)!=0) && (parseInt(f.substring(8,10),10) % 4 != 0))	{
	   	  return '28';
		}
		return '29';
	}
	if ((mes==1)||(mes==3)||(mes==5)||(mes==7)||(mes==8)||(mes==10)||(mes==12)) {
		return '31';

	}
	if ((mes==2)||(mes==4)||(mes==6)||(mes==9)||(mes==11)) {
		return '30';
	}
}
/**************funcion para comprobar que el string que se pasa es una fecha****************/

function compruebafechahora(f) 
{
	if (f.length == 19)
	{
		var test="0123456789";
		var i;
		for (i=6;i<10;i++)
		{
			if (test.indexOf(f.charAt(i))<0)
			{
				alert(f.substring(6,10)+" año no valido");
				return false;
			}
		}

		for (i=0;i<2;i++)
		{
			if (test.indexOf(f.charAt(i))<0)
			{
				alert(f.substring(0,2)+" día no valido");
				return false;
			}
		}

		for (i=3;i<5;i++)
		{
			if (test.indexOf(f.charAt(i))<0)
			{
				alert(f.substring(3,5)+" mes no valido");
				return false;
			}
		}

		for (i=11;i<13;i++)
		{
			if (test.indexOf(f.charAt(i))<0)
			{
				alert(f.substring(11,13)+" hora no valida");
				return false;
			}
		}

		for (i=14;i<16;i++)
		{
			if (test.indexOf(f.charAt(i))<0)
			{
				alert(f.substring(14,16)+" minutos no validos");
				return false;
			}
		}

		for (i=17;i<19;i++)
		{
			if (test.indexOf(f.charAt(i))<0)
			{
				alert(f.substring(17,19)+" segundos no valido");
				return false;
			}
		}


		if  (isBetween(parseInt(f.substring(0,3),10),1,31)==false) 
		{
			alert(f.substring(0,3)+" dia no valido");
		    return false;
		}
	 
		if (isBetween(parseInt(f.substring(3,5),10),1,12)==false) 
		{
			alert(f.substring(3,5)+" mes no valido");
		    return false;
		 }
		 
		 if (isBetween(parseInt(f.substring(11,13),10),0,24)==false) 
		 {
			alert(f.substring(11,13)+" hora no valida");
		    return false;
		 }
		 
		if (isBetween(parseInt(f.substring(14,16),10),0,59)==false) 
		{
			alert(f.substring(14,16)+" minutos no validos");
		    return false;
		 }
		 
		if (isBetween(parseInt(f.substring(17,19),10),0,59)==false) 
		{
			alert(f.substring(17,19)+" segundos no validos");
		    return false;
		 }
		 
		if ( parseInt(f.substring(6,10),10)==false ) 
		{
			alert(f.substring(6,10)+" año no valido");
		    return false;
		 }
		 
		if ( (parseInt(f.substring(0,3),10)==31) && ((parseInt(f.substring(3,5),10)==11)||(parseInt(f.substring(3,5),10)==4)||(parseInt(f.substring(3,5),10)==6)||(parseInt(f.substring(3,5),10)==9))) 
		{
			alert(f+" fecha incorrecta");
		    return false;
		 }
		 
		if ( parseInt(f.substring(3,5),10)==2 && (parseInt(f.substring(0,3),10)>29)) 
		{
			alert(f+" fecha incorrecta");
		    return false;
		}


		// BISIESTOS
		if (( parseInt(f.substring(3,5),10)==2) && (parseInt(f.substring(0,3),10)==29)) 
		{
			if ((parseInt(f.substring(8,10))==0) && (parseInt(f.substring(6,8)) % 4!=0))
			{
				alert("No es bisiesto");
			    return false;
			}

			if ((parseInt(f.substring(8,10),10)!=0) && (parseInt(f.substring(8,10),10) % 4 != 0))	
			{
			   	  alert("No es bisiesto");
			      return false;
			}
		}

		// ASEGURAR FORMATO 'dd/mm/aaaa hh:mi:ss'
		if(f.charAt(2)!='/' || f.charAt(5)!='/' || f.charAt(13)!=':' || f.charAt(16)!=':')
		{
			alert(f+" fecha incorrecta. El formato debe ser dd/mm/aaaa hh:mi:ss");
			return false;
		}

	}
	else
	{
		if (f.length > 0)
		{
			alert(f+" fecha incorrecta. El formato debe ser dd/mm/aaaa hh:mi:ss");
			return false;
		}
	}
}


function isBetween(val,limit1,limit2) {
var max=(limit1 > limit2) ? limit1 : limit2 ;
var min=(limit1 < limit2) ? limit1 : limit2 ;
if (val == max || val == min)
  {return true;}
if (val > min && val < max)
  {return true;}
return false;
}

function recorrer(){
	var ncampo="";
	var valor=0;
	for (i=0; i<document.all.length;i++){
		if (document.all(i).name){
			ncampo=document.all(i).name;
			if (document.getElementById(ncampo).isTextEdit){
				if (document.getElementById(ncampo).value!=""){
					valor++;}
			}
			if (document.getElementById(ncampo).getAttribute("type")=="select-one"){
				if (document.getElementById(ncampo).value!=""){
					valor++;}
			}
		}
	}
	if (valor>1){
		document.formaccion.submit();
	}
	else{
		alert('Rellene al menos un campo');
	}
}
function enviaFrmOpcion(opcion){
	document.formu.opcion.value=opcion;
	document.formu.submit();
}
//Objeto oNumero
function oNumero(numero)
{
	//Propiedades 
	this.valor = numero || 0
	this.dec = -1;
	//Métodos 
	this.formato = numFormat;
	this.ponValor = ponValor;
	//Definición de los métodos 
	function ponValor(cad)
	{
	if (cad =='-' || cad=='+') return
	if (cad.length ==0) return
	if (cad.indexOf(',') >=0)
		this.valor = parseFloat(cad);
	else 
		this.valor = parseInt(cad);
} 
function numFormat(dec, miles)
{
	var num = this.valor, signo=3, expr;
	var cad = ""+this.valor;
	var ceros = "", pos, pdec, i;
	for (i=0; i < dec; i++)
	ceros += '0';
	pos = cad.indexOf('.')
	if (pos < 0)
		cad = cad+","+ceros;
	else
		{
		pdec = cad.length - pos -1;
		if (pdec <= dec)
			{
			for (i=0; i< (dec-pdec); i++)
				cad += '0';
			}
		else
			{
			num = num*Math.pow(10, dec);
			num = Math.round(num);
			num = num/Math.pow(10, dec);
			cad = new String(num);
			}
		}
	pos = cad.indexOf(',')
	if (pos < 0) pos = cad.lentgh
	if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
		   signo = 4;
	if (miles && pos > signo)
		do{
			expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
			cad.match(expr)
			cad=cad.replace(expr, RegExp.$1+'.'+RegExp.$2)
			}
	while (cad.indexOf('.') > signo)
		if (dec<0) cad = cad.replace(/\./,'')
			return cad;
	}
}//Fin del objeto oNumero:
