// JavaScript Document

/*function fullscreen(form,target) {
	full = window.open('', target, 'top=0,left=0,width=100%,height=100%,fullscreen=yes,toolbar=0 ,location=0,directories=0,status=0,menubar=0,resizable=0,scrolling=1,scrollbars=1');
	formsubmit(form);
}*/

function fullscreen(form,target){ 
	ancho=screen.availWidth;
	alto=screen.availHeight;
	if (navigator.appName=='Netscape'){
		window.open('', target, 'top=0,left=0,width='+ancho+',height='+alto+',fullscreen=yes,toolbar=0 ,location=0,directories=0,status=0,menubar=0,resizable=0,scrolling=1,scrollbars=1');
		//pag_home1.moveTo(0,0);
		//pag_home1.resizeTo(ancho,alto);
	}
	if (navigator.appName=='Microsoft Internet Explorer'){
		window.open('',target,'width='+ ancho +',height='+ alto +',fullscreen=yes,toolbar=0 ,location=0,directories=0,status=0,menubar=0,resizable=0,scrolling=1,scrollbars=1');
		//pag_home1.moveTo(0,0);
	}
	formsubmit(form);
}

function fullwin(){ 
	ancho=screen.availWidth;
	alto=screen.availHeight;
	if (navigator.appName=='Netscape'){
		var pag_home1=window.open('pagina.html','window2','wid th='+ancho+',height='+alto+',top=0,left=0','toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no,resizable=no');
		pag_home1.moveTo(0,0);
		pag_home1.resizeTo(ancho,alto);
	}
	if (navigator.appName=='Microsoft Internet Explorer'){
		window.open('pagina.html','window2','width='+ ancho +',height='+ alto +',left=0,top=0,fullscreen=yes,scrollbars=yes');
	}
}

function chequeoNif(dni){
	function is9digit(dni){
		if(dni.length==9)
			return true;
		else
			alert('El número de digitos admitidos es de 9 (8 numeros y una letra). El NIF debe ir seguido sin guiones ni caracteres de separación.');
		return false;
	}
	function is8digit(dni){
		if (!/^\d{8}$/.test(dni)){
		alert('Compruebe que los primeros 8 dígitos son numéricos.');
		return false;
		}
		else
		  return true;
	}
	if(is9digit(dni)){
		if(is8digit(dni.substr(0,8))){
			var letras ='TRWAGMYFPDXBNJZSQVHLCKE';
			var pos=sumar(dni.substr(0,8)%23,1);
			letra1=dni.substr(8,9);
			letra2=letras.substr((pos-1),1);
			letra1=mayusculas(letra1);
			if(letra1==letra2)
				return true;
			else{
				alert('LETRA INCORRECTA. LA LETRA DE SU NIF ES:'+letra2);
			}
			
		}
	}
	else
		return false;
		
	
}

function error(id,msg){
	alert(msg);
	document.getElementById(id).focus();
}
function formulario(formulario,msg){
	form=document.forms[formulario];
		if(confirm(msg))
			form.submit();
}

function esNumero(numero){
	if (!/^([0-9])*$/.test(numero))
		return false;
	else
		return true;
}
function  is_numeric(tuNumero){
	if(isNaN(tuNumero))
		return false;
	else
		return true;
}
function sizeScreen(op){
		switch(op){
				case 'width':
					return screen.width;
				break;
				case 'height':
					return screen.height;
		}
		
}

function restar(op1,op2){
	var o1=parseInt(op1);
	var o2=parseInt(op2);
	return o1-o2;
}
function sumar(op1,op2){
	var o1=parseInt(op1);
	var o2=parseInt(op2);
	return o1+o2;
}
function redondeo(numero){
	var original=parseFloat(numero);
	var result=Math.round(original*100)/100 ;
	return result;
}

function intro(evento) { 
	//para IE 
	if (window.event){ 
		if (window.event.keyCode==13){ 
		return true;
		} 
	} 
	else{ 
		//Firefox y otros navegadores 
		if (evento){ 
			if(evento.which==13){ 
				//Haga algo...(cambie focus) 
				return true;
			} 
		} 
	} 
	return false;
} 


function isimgextension(idfile){
				var ext='/\.(gif|jpg|png)$/';
				function negativo() {
					alert("El fichero seleccionado no es válido...");					
				}
				function ok() {
					alert("El fichero seleccionado es correcto...");					
				}

				(/\.(gif|jpg|png)$/i.test(getvalue(idfile))) ? ok() : negativo();
}

function istextextension(idfile){
				var ext='/\.(gif|jpg|png)$/';
				function negativo() {
					alert("El fichero seleccionado no es válido...");					
				}
				function ok() {
					alert("El fichero seleccionado es correcto...");					
				}

				(/\.(txt|csv)$/i.test(getvalue(idfile))) ? ok() : negativo();
}


function putsrc(id,ruta){
	document.getElementById(id).src=ruta;
}
function putclassName(id,name){
	document.getElementById(id).className=name;
}
function putnameclass(este,name){
	este.className=name;
}
function getclassName(id){
	return document.getElementById(id).className;
}
function getsrc(id){
	return document.getElementById(id).src;
}
function putsrcclass(clase,ruta){
	array=document.getElementsByTagName('img');
	for(i=0;i<array.length;i++){
		if(array[i].className.length && array[i].className==clase)
			array[i].src=ruta;
	}
}
function getname(id){
	return document.getElementById(id).name;
}

function putname(id,nombre){
	document.getElementById(id).name=nombre;
}

function getaction(id){
	return document.getElementById(id).action;
}

function getaction(id){
	return document.getElementById(id).action;
}
function gettarget(id){
	return document.getElementById(id).target;
}
function getchecked(id){
	return document.getElementById(id).checked;
}
function putchecked(id,valor){
	document.getElementById(id).checked=valor;
}
function putallchecked(nombreclase,contenedor,valor){
	array=document.getElementsByTagName(contenedor);
	for(i=0;i<array.length;i++){
		if(array[i].className.length && array[i].className==nombreclase){
			array[i].checked=valor;
		}
	}
}
function getallcheckedvalue(nombreclase,contenedor){
	array=document.getElementsByTagName(contenedor);
	valores='';
	for(i=0;i<array.length;i++){
		if(array[i].className.length && array[i].className==nombreclase){
			if(array[i].checked){
				valores=valores+array[i].value+',';
			}
		}
	}
	valores=valores.substr(0,(valores.length)-1);
	return valores;
}
function puttype(id,valor){
	document.getElementById(id).type=valor;
}
function getdisabled(id){
	return document.getElementById(id).disabled;
}
function putdisabled(id,valor){
	document.getElementById(id).disabled=valor;
}
function putaction(id,action){
	document.getElementById(id).action=action;
}
function putleft(id,left){
	document.getElementById(id).style.left=left;
}
function putright(id,right){
	document.getElementById(id).style.right=right;
}
function puttop(id,top){
	document.getElementById(id).style.top=top;
}
function puttarget(id,target){
	document.getElementById(id).target=target;
}

function formsubmit(id){
	document.getElementById(id).submit();
}
function putbackgroundcolor(id,color){
	document.getElementById(id).style.backgroundColor=color;
}
function putfocus(id){
	document.getElementById(id).focus();
}

function putvalue(id,valor){
		document.getElementById(id).value=valor;
}
function getvalue(id){
	return document.getElementById(id).value;
}

function putinnerHTML(id,valor){
		document.getElementById(id).innerHTML=valor;
}

function putdisabled(id,valor){
	document.getElementById(id).disabled=valor;
}
function putwidth(id,valor){
	document.getElementById(id).style.width=valor;
}

function sh(id){
	var ventana=document.getElementById(id);
	var visible=(ventana.style.display=='block')?true:false;
	if(visible==true)
		ventana.style.display='none';
	else
		ventana.style.display='block';
	return visible;
}

function block(id){
		document.getElementById(id).style.display='block';
}

function blocknone(id){
	if(document.getElementById(id).style.display=='block')
		document.getElementById(id).style.display='none';
	else
		document.getElementById(id).style.display='block';
}
function table(id){
		document.getElementById(id).style.display='table';
}
function none(id){
		document.getElementById(id).style.display='none';
}

function noneClass(label,name){
	array=document.getElementsByTagName(label,name);
	for(i=0;i<array.length;i++){
		if(array[i].className.length && array[i].className==name)
			array[i].style.display='none';
	}
}

function visible(id){
	var ventana=document.getElementById(id);
	var visible=(ventana.style.display=='block')?true:false;
	return visible;
}
function concatenar(parametro1,parametro2){
	cadena=parametro1+parametro2;
	return cadena;
}
function in_array(array,valor){
	for(i=0;i<array.length;i++){
		if(array[i]==valor)
			return true;
	}
	return false;
}
function minusculas(texto){
	return texto.toLowerCase( );
}
function mayusculas(texto){
	return texto.toUpperCase( );
}
function concatenarconseparador(parametro1,parametro2,separador){
		var valores='';
		valores=parametro1+separador+parametro2;
		return valores;
}
function vacio(id){	
	var vacio=document.getElementById(id);
	var cadena=trim(vacio.value);
	var v=(!cadena.length)?true:false;
	return v;
}
function cadenaVacia(cadena){
	cadena=trim(cadena);
	var v=(!cadena.length)?true:false;
	return v;
}
function trim(cadena){
// USO: Devuelve un string como el parámetro cadena pero quitando los espacios en blanco de los bordes.
	var retorno=cadena.replace(/^\s+/g,'');
	retorno=retorno.replace(/\s+$/g,'');
	return retorno;
}

function caracteresRaros(cadena){
	for(i=0;i<cadena.length;i++)
		if(cadena.charCodeAt(i)>=192 && cadena.charCodeAt(i)<=255)
			return true;
	return false;
}

function safeName(cadena){
	if(cadenaVacia(cadena))
		return false;
	else
		for(i=0;i<cadena.length;i++){
			if((cadena.charCodeAt(i)>40 && cadena.charCodeAt(i)<91)||(cadena.charCodeAt(i)>96 && cadena.charCodeAt(i)<123));
			else
				return false;			
		}
	return true;
}
function getSplit(cadena,separador){
		elementos=cadena.split(separador);
		return elementos;
}

function sinEspacios(cadena){
		elementos=cadena.split(' ');
		if(elementos.length>1)
			return false;
		else
			return true;
}

function buscarCaracter(cadena,caracter){
	for(i=0;i<cadena.length;i++){
		if(cadena.substr(i,1)==caracter)
			return true;
	}
	return false;
}
function reemplazar(cadena,origen,cambio){
	nueva=cadena.replace(origen,cambio);
	return nueva;
}
function ruta(id,ruta){
		document.getElementById(id).src=ruta;
}

//funciones de select
function putSelect(id,texto,valor){
    var sel=document.getElementById(id);
	sel[sel.length]= new Option(texto,valor);
}
function getTextSelect(id){
		var sel=document.getElementById(id);
            // Obtenemos que posición del SELECT está seleccionada
        var indiceSeleccionado = sel.selectedIndex;
            // Si hemos seleccionado una opción válida ...
            //if (indiceSeleccionado != 0)           
                // Obtenemos el valor seleccionado
        return sel.options[indiceSeleccionado].text;

}

function getAllTextSelect(id){
		var sel=document.getElementById(id);
		var valores='';
		for (i=0; opt=sel.options[i];i++){
			valores=valores+opt.text+',';
		}
		valores=valores.substr(0,(valores.length)-1);
		return valores;
}

function getalltextselectarray(id,caracter){
	var sel=document.getElementById(id);
	var valores='';
	for(i=0; opt=sel.options[i];i++){
		valores=valores+opt.text+caracter;
	}
	valores=valores.substr(0,(valores.length)-(caracter.length));
	return valores;		
}

function TextExistSelect(id,value){
		var sel=document.getElementById(id);
		for (i=0; opt=sel.options[i];i++){
			if(opt.text==value)
				return true;
		}
		return false;
}

function selectedIni(id){
		var sel=document.getElementById(id);
		sel.selectedIndex=0;
}
function selected(id){
		var sel=document.getElementById(id);
		if(sel.selectedIndex>=0)
			return true;
		else
			return false;
}

function indexSelect(id){
	var sel=document.getElementById(id);
	return sel.selectedIndex; 
}
function getAllValueSelect(id){
		var sel=document.getElementById(id);
		var valores='';
		for (i=0; opt=sel.options[i];i++){
			valores=valores+opt.value+',';
		}
		valores=valores.substr(0,(valores.length)-1);
		return valores;

}
function deleteValueSelect(id,valor){
		var sel=document.getElementById(id);
		for (i=0; opt=sel.options[i];i++){
			if(opt.value==valor)
				sel.options[i]=null;
		}
}
function deleteAllValueSelect(id){
	var sel=document.getElementById(id);
	sel.options.length=0;		
}
function countSelect(id){
	 return document.getElementById(id).length;
}
function moveItemSelect(id,opcion){
	if(!selected(id))
			alert('Debe seleccionar un elemento de la lista.');
	else{
		posicion=indexSelect(id);
		var sel=document.getElementById(id);
		var total=countSelect(id);
		switch(opcion){
			case 1://subir
			if(posicion>0){
				switch1=sel.options[posicion-1].text;
				switch2=sel.options[posicion-1].value;
				sel.options[posicion-1].text=sel.options[posicion].text;
				sel.options[posicion-1].value=sel.options[posicion].value;
				sel.options[posicion].text=switch1;
				sel.options[posicion].value=switch2;
				sel.selectedIndex=posicion-1;
			}
			break;
			case 2://bajar
			if(posicion<total){
				switch1=sel.options[posicion+1].text;
				switch2=sel.options[posicion+1].value;
				sel.options[posicion+1].text=sel.options[posicion].text;
				sel.options[posicion+1].value=sel.options[posicion].value;
				sel.options[posicion].text=switch1;
				sel.options[posicion].value=switch2;
				sel.selectedIndex=posicion+1;
			}					
			break;
		}
	}
}
function valueExistSelect(id,value){
		var sel=document.getElementById(id);
		for (i=0; opt=sel.options[i];i++){
			if(opt.value==value)
				return true;
		}
		return false;
}
function putValueSelected(id,value){
		var sel=document.getElementById(id);
		for (i=0; opt=sel.options[i];i++){
			if(opt.value==value){
				opt.selected=true;
				break;
			}
		}
}
function getValueSelect(id){
		var sel=document.getElementById(id);
		return sel.value;
}
function delSelect(id){
		var sel=document.getElementById(id);
		if (sel.selectedIndex >= 0) {
			sel.options[sel.selectedIndex]=null;
			sel.selectedIndex=0;
		}
}


//ventanas


//window.close()
function windowclose(){
	self.close();
}
//close()

//extensiones
// JavaScript Document
function extension_imagen(archivo){
	var extension=archivo.substr(archivo.lastIndexOf("."));
	var ext=(extension.toLowerCase()!='.jpg' && extension.toLowerCase()!='.jpeg' && extension.toLowerCase()!='.png' && extension.toLowerCase()!='.bmp' && extension.toLowerCase()!='.gif')?false:true;
	return ext;
}

function extension_flash(archivo){
	var extension=archivo.substr(archivo.lastIndexOf("."));
	var ext=(extension.toLowerCase()!='.swf')?false:true;
	return ext;
}



//
		
		
		/*function ini(){
				document.forms.formu.actualizar = actuar;
				window.frames.ver.location.href = 'modulos/archivo/previsor.php';
				document.forms.formu.actualizar(0, 0, 0);
		}
		function actuar(peso, anchura, altura)	{
				this.peso.value = peso;
				this.ancho.value = anchura;
				this.alto.value = altura;
		}*/
		function validar(f)	{
				enviar = /\.(gif|jpg|png)$/i.test(f.archivo.value);
				if (!enviar)	alert("seleccione imagen");
				return enviar;
			}

			function limpiar(idfile){
				f = document.getElementById(idfile);
				nuevoFile = document.createElement('input');			
				nuevoFile.id = f.id;
				nuevoFile.type = 'file';
				nuevoFile.name = idfile;
				nuevoFile.value = '';
				nuevoFile.onchange = f.onchange;
				nodoPadre = f.parentNode;
				nodoSiguiente = f.nextSibling;
				nodoPadre.removeChild(f);
				(nodoSiguiente == null) ? nodoPadre.appendChild(nuevoFile):
					nodoPadre.insertBefore(nuevoFile, nodoSiguiente);
			}

			function checkfile(idfile,idform,ruta){
				function no_prever() {
					alert("El fichero seleccionado no es válido...");
					limpiar(idfile);
				}
				function prever() {
					var campos = new Array("maxpeso", "maxalto", "maxancho");
					for (i = 0, total = campos.length; i < total; i ++)
						putdisabled([campos[i]],false);
					actionActual = getaction(idform);
					targetActual = gettarget(idform);
					putaction(idform,ruta);
					puttarget(idform,'ver');
					formsubmit(idform);
					for (i = 0, total = campos.length; i < total; i ++)
						putdisabled([campos[i]],true);
					putaction(idform,actionActual);
					puttarget(idform,targetActual);					
				}

				(/\.(gif|jpg|png)$/i.test(getvalue(idfile))) ? prever() : no_prever();
			}

			function datosImagen(peso, ancho, alto, error, idfile)	{				
				function mostrar_error()	{
					enviar = false;					
					mensaje = "Ha habido un error (error nş " + error + "):";
					if (error % 2 == 1) // tipo incorrecto
						mensaje += "\nel fichero no es válido";
					error = parseInt(error / 2);
					if (error % 2 == 1) // excede en peso
						mensaje += "\nLímite de peso superado (" + peso + ").";
					error = parseInt(error / 2);
					if (error % 2 == 1) // excede en anchura
						mensaje += "\nla imagen excede en anchura (" + ancho + ").";
					error = parseInt(error / 2);
					if (error % 2 == 1) // excede en altura
						mensaje += "\nla imagen excede en altura (" + alto + ").";
					error = parseInt(error / 2);
					alert (mensaje);
					limpiar(idfile);
				}
				if (error == 0)
					//document.forms.formu.actualizar(peso, ancho, alto);
					;
				else
					mostrar_error();
			}