// JavaScript Document

function fullscreen(form,target) {
	full = window.open('', target, 'top=0,left=0,width='+(screen.availWidth)+',height ='+(screen.availHeight)+',fullscreen=yes,toolbar=0 ,location=0,directories=0,status=0,menubar=0,resizable=0,scrolling=1,scrollbars=1');
	formsubmit(form);
}


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 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 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 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 putaction(id,action){
	document.getElementById(id).action=action;
}
function putleft(id,left){
	document.getElementById(id).style.left=left;
}
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 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 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();
			}