function validar(f)
	{
		var True=1;
		var False=0;

		return validarForm(f);
	}	
function contarcarinp(formcampo,formrestantes,cuantos)
{	
n = formcampo.value.length;
t = cuantos; 
    {
   
    formrestantes.value = (t-n);
    }
}


function busqueda_onkeypress() 
{
	if(document.all)
	{
		if (event.keyCode == 13) 
			// Hemos pulsado la tecla enter,hacemos validación del formulario			
			envio_datos('document.fAlta');
	}
	else{
		return false;}
}
function validarForm(f)
	{
		var i,a,b,c,ss,s,expe,msg,valor,cadena,obl,fn,vector;
		vector=new Array();
		for(i=0;i<f.elements.length;i++){
			if (f.elements[i].alt){
				if (f.elements[i].alt !=""){
					cadena=f.elements[i].alt;								
					vector=cadena.split("$$$");					
				        expe=vector[0];
				        msg=vector[1];
				        obl=vector[2];			        	       				         
				    if (vector[3]!="")
				        fn=vector[3];					        							        
				        else
				        fn="";				       		       
					b=(f.elements[i].value).length;
					if (obl==0 && b<=0) continue;
					 if (b==0){
						c=(expe).replace("$$$","1");
					}
					else{
						c=(expe).replace("$$$",b);
					}
					a =new RegExp("%"+c+"%","i");									
					valor=f.elements[i].value;	
										
					valor="%"+valor+"%";
					if (obl==1 && b<=0){
						msg="El campo "+f.elements[i].name+" es obligatorio."
						alerta(msg,f.elements[i]);	
						return false;
					}
					if (!a.test(valor)){
						alerta(msg,f.elements[i]);	
						return false;
					}
					s=f.elements[i].value;
					if (fn && fn!="" && s!=""){ 						
						if (!eval(fn+"('"+f.elements[i].value+"')")){						
						 alerta(msg,f.elements[i]);	
						 return false;
						}
					}	
				}
				
				f.elements[i].style.backgroundColor = '#FFFFFF';//
			}
		}
		return true
	}
function alerta(mensaje,elemento)
	{
		alert(mensaje);
		//document.getElementById("mS").innerHTML=document.getElementById("mS").innerHTML+'> '+mensaje+'<br/>';
		elemento.style.backgroundColor = '#FFFFCF';
		elemento.focus();
		//elemento.select();
	}
/* function envio_datos(f)
{
			if(validar(eval(f))){
				var formulario;
				var datos='';
				formulario=eval(f);
					for(i=0;i<formulario.elements.length;i++){
					document.getElementById("mS").innerHTML=document.getElementById("mS").innerHTML+'> '+formulario.elements[i].name+'-'+formulario.elements[i].value+'<br/>'; 
					datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].value);
					}
				//document.getElementById("mS").innerHTML=document.getElementById("mS").innerHTML+'> '+datos+'<br/>';
				enviar(formulario.elements['dirHTML'].value,datos);
				}
		
}*/

function envio_datos(f,operacion,funcion)
{
			
			if(validar(eval(f))){
				var formulario;
				var datos='';
				formulario=eval(f);				
				formulario.elements['oper'].value=operacion;
				for(i=0;i<formulario.elements.length;i++){
				var sw=0;
				//document.getElementById("mS").innerHTML=document.getElementById("mS").innerHTML+'> '+formulario.elements[i].value+'<br/>';
					if((formulario.elements[i].type=='checkbox' || formulario.elements[i].type=='radio'  && formulario.elements[i].checked==false) || formulario.elements[i].type=='select-multiple' ){
						var sw=1;
						if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){				
							datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].value);				
						}
					}
					
					if(formulario.elements[i].type=='select-multiple' ){
						var sw=1;
						if(formulario.elements[i].type=='select-multiple'){	//comprobamos otra vez para insertar los select-multiple				
							var k;
							for (k=0; k<formulario.elements[i].options.length; k++) {
								if (formulario.elements[i].options[k].selected) {
									datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].options[k].value);									
								}
							}				
						}
					}
					
					//if(formulario.elements[i].name=='archivos'){alert(formulario.elements[i].value+'-'+formulario.elements[i].name+'-'+formulario.elements[i].type+'-'+formulario.elements[i].checked);}
					if(sw==0){
							datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].value);
					}
					//alert(encodeURIComponent(formulario.elements[i].value));					
				}		
				//enviar(formulario.elements['dirHTML'].value,datos,funcion);
				 document.fAlta.submit();
				return true;
			}
			else{
				return false;
			}
} 

function envio_datos_busqueda(f,operacion,funcion)
{
			
				var formulario;
				var datos='';
				formulario=eval(f);				
				formulario.elements['oper'].value=operacion;
				for(i=0;i<formulario.elements.length;i++){
				var sw=0;
					if((formulario.elements[i].type=='checkbox' || formulario.elements[i].type=='radio'  && formulario.elements[i].checked==false) || formulario.elements[i].type=='select-multiple' ){
						var sw=1;
						if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){				
							datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].value);				
						}
					}
					
					if(formulario.elements[i].type=='select-multiple' ){
						var sw=1;
						if(formulario.elements[i].type=='select-multiple'){	//comprobamos otra vez para insertar los select-multiple				
							var k;
							for (k=0; k<formulario.elements[i].options.length; k++) {
								if (formulario.elements[i].options[k].selected) {
									datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].options[k].value);									
								}
							}				
						}
					}
					
					if(sw==0){
							datos=datos+'&'+formulario.elements[i].name+'='+encodeURIComponent(formulario.elements[i].value);
					}
				}	
				
				enviar_busqueda(formulario.elements['dirHTML'].value,datos,funcion);
				return true;			
} 

function actualizarPag(locJ,locId, varJ,operacion) {

var locV=new Array();
var varV=new Array();
locV=locJ.split("|");
varV=varJ.split("|");

	for(i=0;i<locV.length;i++){
		switch (operacion) {
			case 'eli':
				document.getElementById(locV[i]+locId).innerHTML='--';
				document.getElementById(locV[i]+locId).style.backgroundColor="#FCFF00";
			break
			
			case 'mod':
					if (document.getElementById(varV[i]).value!="borrarchk"){
					switch (document.getElementById(varV[i]).type) {
						case 'select-multiple':
							var k;var temp='';
							for (k=0; k<document.getElementById(varV[i]).options.length; k++) {
								if (document.getElementById(varV[i]).options[k].selected) {
									desglosarvalores=document.getElementById(varV[i]).options[k].value.split("$");
									//temp=temp+document.getElementById(varV[i]).options[k].value+',';								
									temp=temp+desglosarvalores[1]+'<br>';								
								}
							}
							temp=temp.substring(0,temp.length-1);
							if (temp.length==0)
							temp='&nbsp;';
							document.getElementById(locV[i]+locId).innerHTML=temp;
							document.getElementById(locV[i]+locId).style.backgroundColor="#FCFF00";
							break
						/*case 'radio':	
							alert(getCheckedValue(document.forms['fAlta'].elements[varV[i]]));
							break*/
						default:
						document.getElementById(locV[i]+locId).innerHTML='&nbsp;'+document.getElementById(varV[i]).value;
						document.getElementById(locV[i]+locId).style.backgroundColor="#FCFF00";
					}
				}
			break
			case 'fondo':
				document.getElementById(locV[i]+locId).style.backgroundColor="#FCFF00";
			break
		}
	}
	if(operacion=='eli'){
	document.getElementById("mSuggest").style.left=-1000;// movemos la capa  a una zona invisible
	document.getElementById("mSuggest").style.top=-1000;// movemos la capa a una zona invisible
	}
}
function actualizarPagImg(locJ,locId,varJ,operacion,nameform) {
var locV=new Array();
var varV=new Array();
locV=locJ.split("|");
varV=varJ.split("|");
	for(i=0;i<locV.length;i++){
		if(operacion=='eli')
		{
			auxfila=locV[i]+locId;
			document.getElementById(auxfila).innerHTML='--';
			document.getElementById(auxfila).style.backgroundColor="#FCFF00";
		}
		if(operacion=='mod')
		{
			auxfila=locV[i]+locId;
			if (document.getElementById(varV[i]).value!="borrarchk"){
			switch (document.getElementById(varV[i]).type) {
				case "checkbox": 
					if(document.getElementById(varV[i]).checked==true)
						document.getElementById(auxfila).innerHTML='<img src="entorno/si.gif">';
					else
						document.getElementById(auxfila).innerHTML='<img src="entorno/no.gif">';
				break
				case "radio": 
					//var temp=getCheckedValue(document.forms['fAlta'].elements[varV[i]])
					document.getElementById(auxfila).innerHTML=getCheckedValue(document.forms[nameform].elements[varV[i]]);
				break
				case "select-multiple": 
					var k;var temp='';
						for (k=0; k<document.getElementById(varV[i]).options.length; k++) {
							if (document.getElementById(varV[i]).options[k].selected) {
								temp=temp+document.getElementById(varV[i]).options[k].value+',';								
							}
						}
						temp=temp.substring(0,temp.length-1);
						if (temp.length==0)
						temp='&nbsp;'
						document.getElementById(auxfila).innerHTML=temp;
				break
				default:
					document.getElementById(auxfila).innerHTML=document.getElementById(varV[i]).value;
					if(document.getElementById(varV[i]).value.length==0){document.getElementById(auxfila).innerHTML='&nbsp;';}			
			}
			document.getElementById(auxfila).style.backgroundColor="#FCFF00";
			}
		} 		
	}
	if(operacion=='eli'){
	document.getElementById("mSuggest").style.left=-1000;// movemos la capa  a una zona invisible
	document.getElementById("mSuggest").style.top=-1000;// movemos la capa a una zona invisible
	}
}
function actualizarPagMultiple(locJ,operacion,prefijocampo,varJ) {
var locV=new Array();
var varV=new Array();
locV=locJ.split(",");
varV=varJ.split("|");
	for(i=0;i<locV.length;i++){
		var campo=prefijocampo+locV[i];
		if(document.getElementById(campo)){	
			if(operacion=='eli')
			{
				for(k=0;k<varV.length;k++){
					document.getElementById(varV[k]+locV[i]).innerHTML="--";
					//document.getElementById(varV[k]+locV[i]).style.backgroundColor="#FCFF00";
				}
			}
			/*if(operacion=='mod')
			{
				document.getElementById('Web'+locV[i]).innerHTML='<a href="_" onclick="javascript:dH1(\'Web.Mod.cfm?idnoticia='+locV[i]+'&option=eli\');return false;">[Supr]</a>';
				document.getElementById('Web'+locV[i]).style.backgroundColor="#FCFF00";
			}*/
		}
	}
}
function actualizarPagCorreo(locJ,operacion) {
var locV=new Array();
var varV=new Array();
locV=locJ.split(",");
	for(i=0;i<locV.length;i++){
		if(document.getElementById('Correo'+locV[i])){	
			if(operacion=='eli')
			{
				document.getElementById('a'+locV[i]).innerHTML='--';
				document.getElementById('a'+locV[i]).style.backgroundColor="#FCFF00";
				document.getElementById('b'+locV[i]).innerHTML='--';
				document.getElementById('b'+locV[i]).style.backgroundColor="#FCFF00";
				document.getElementById('c'+locV[i]).innerHTML='--';
				document.getElementById('c'+locV[i]).style.backgroundColor="#FCFF00";
				document.getElementById('Correo'+locV[i]).innerHTML='--';
				document.getElementById('Correo'+locV[i]).style.backgroundColor="#FCFF00";
			}
			
		}
	}
}
function actualizarPagConte(locJ,operacion) {
var locV=new Array();
var varV=new Array();
locV=locJ.split(",");
	for(i=0;i<locV.length;i++){
		if(document.getElementById('chk'+locV[i])){	
			if(operacion=='eli')
			{
				document.getElementById('chk'+locV[i]).style.backgroundColor="#FCFF00";
			}
			if(operacion=='mod')
			{
				document.getElementById('chk'+locV[i]).style.backgroundColor="#FCFF00";
			}
		}
	}
}
function actualizarVent(locJ,varJ,operacion,capa) {
var locV=new Array();
var varV=new Array();
locV=locJ.split("|");
varV=varJ.split("|");
	for(i=0;i<locV.length;i++){

		if(operacion=='eli')
		{
			document.getElementById(locV[i]).innerHTML='';
			document.getElementById(locV[i]).style.backgroundColor="#FCFF00";
		}
	}
}
function envioArchivos(direccion)
{
if(document.getElementById("archivos"))
				{	
					var archivosTemp='';
					
					for(i=0;i<document.fAlta.elements.length;i++){
						if(document.fAlta.elements[i].name=='archivos' && document.fAlta.elements[i].type=='checkbox' && document.fAlta.elements[i].checked==true){
							archivosTemp=archivosTemp+document.fAlta.elements[i].value+',';
						}
					}
					
				dHmArchivo(direccion+'?1=1&archivos='+archivosTemp);
				
					if(document.getElementById("oper").value=='alta')
					{
						document.getElementById('images').innerHTML='';
					}
				return false;
					}				
} 
function Enviolisform(f,ruta,parametros,evento){
	var formulario=eval(f);
	var datos='';
	for(i=0;i<formulario.elements.length;i++){				
		if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){
					datos=datos+formulario.elements[i].value+',';
		}
	}
	if (datos !=''){
	dHmVisor(ruta+'?id='+datos+'&loc='+parametros,evento);
	}else{
	alert('Debe seleccionar algun elemento de la lista');	
	}
}

function Enviolisformwindow(f,ruta,parametros,nombrewin){
	var formulario=eval(f);
	var datos='';
	for(i=0;i<formulario.elements.length;i++){				
		if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){
					datos=datos+formulario.elements[i].value+',';
		}
	}
	if (datos !=''){
	URL = ruta+'?id='+datos+parametros;
	eval("window.open(URL, nombrewin, 'width=745,height=450,menubar=yes,status=no,scrollbars=yes,resizable=no,top=10,left=50');");	
	}else{
	alert('Debe seleccionar algun elemento de la lista');	
	}
}

function Envioliswindow(f,ruta,parametros,nombrewin){
	var formulario=eval(f);
	var datos='';
	for(i=0;i<formulario.elements.length;i++){				
		if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){
					datos=datos+formulario.elements[i].value+',';
		}
	}
	URL = ruta+'?id='+datos+parametros;
	eval("window.open(URL, nombrewin, 'width=745,height=450,menubar=yes,status=no,scrollbars=yes,resizable=no,top=10,left=50');");	
	
}

function Enviolisprincipal(f,ruta,parametros){
	var formulario=eval(f);
	var datos='';	
	
	for(i=0;i<formulario.elements.length;i++){				
		if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){
					datos=datos+formulario.elements[i].value+',';
		}
	}
	if (datos !=''){
	dHPPrincipal(ruta+'?id='+datos+'&loc='+parametros);
	}else{
	alert('Debe seleccionar algun elemento de la lista');	
	}
}

function EdicionVacas(f,quien){
				var formulario=eval(f);
				var datos='';
				for(i=0;i<document.fLisC.elements.length;i++){
				
				if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){
				
					datos=datos+formulario.elements[i].value+',';
				
				}
				
				}
				dH1('Vacaciones.Eli.cfm?id='+datos+'&q='+quien);
				
				
}
function EdicionCorreo(f,email){
				var formulario=eval(f);
				var datos='';
				var datos1='';
				vector=new Array();
				for(i=0;i<document.fWeb.elements.length;i++){
				
				if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){
											
					vector=formulario.elements[i].value.split("||");					
				        datos=datos+vector[0]+',';
				        datos1=datos1+vector[1]+',';
					//datos=datos+formulario.elements[i].value+',';
				
				}
				
				}
				//alert('Correo.Mod.cfm?uidCorreo='+datos+'&uidCorreoF'+datos1);
				dH1('Correo.Mod.cfm?idCorreo='+datos+'&idCorreoF='+datos1+'&email='+email);
				
				
}

function asignarC(f,donde,option){
				var formulario=eval(f);
				var datos='';
				for(i=0;i<document.fasignar.elements.length;i++){				
					if(formulario.elements[i].type=='checkbox' && formulario.elements[i].checked==true){				
						datos=datos+formulario.elements[i].value+',';				
					}				
				}
				dH1('Contenidos.2Mod.cfm?id='+datos+'&donde='+donde+'&oper='+option);
}

function CHKverifyIMG(campoform){
	if (campoform.checked==true){
			campoform.value='<img src="entorno/si.gif">';
	}
	else{
		campoform.value='<img src="entorno/no.gif">';
	}
}

function chkselect(linea,id){
	if (linea.checked==true){
		document.getElementById(id).style.backgroundColor="#FCFF00";		
	}
	else{
		document.getElementById(id).style.backgroundColor="#EEEEEE";		
	}
}

function chkselectcolor(linea,id,color){
	if (linea.checked==true){
		document.getElementById(id).style.backgroundColor="#FCFF00";	
	}
	else{
		document.getElementById(id).style.backgroundColor="#"+color;		
	}
}

function over(objtr){
	if (IE){
		if (objtr.style.backgroundColor.toUpperCase()!="#FCFF00")
			objtr.style.backgroundColor="#FFD0B0";
	}
	else{
		if (objtr.style.backgroundColor.toUpperCase()!="RGB(252, 255, 0)")
			objtr.style.backgroundColor="#FFD0B0";
	}
}
function out(objtr){		
	if (IE){
		if (objtr.style.backgroundColor.toUpperCase()!="#FCFF00")
			objtr.style.backgroundColor="#EEEEEE";
	}
	else{	//alert(objtr.style.backgroundColor.toUpperCase());		
		if (objtr.style.backgroundColor.toUpperCase()!="RGB(252, 255, 0)")
			objtr.style.backgroundColor="#EEEEEE";
	}
}	

function outps(objtr,color){/*objtr.style.backgroundColor="#"+color;*/
	if (IE){
		if (document.getElementById(objtr).style.backgroundColor.toUpperCase()!="#FCFF00")
			document.getElementById(objtr).style.backgroundColor="#"+color;
	}
	else{
		if (document.getElementById(objtr).style.backgroundColor.toUpperCase()!="RGB(252, 255, 0)")
			document.getElementById(objtr).style.backgroundColor="#"+color;
	}
}
function overps(objtr){
	if (IE){
		if (document.getElementById(objtr).style.backgroundColor.toUpperCase()!="#FCFF00")
			document.getElementById(objtr).style.backgroundColor="#FFD0B0";
	}
	else{
		if (document.getElementById(objtr).style.backgroundColor.toUpperCase()!="RGB(252, 255, 0)")
			document.getElementById(objtr).style.backgroundColor="#FFD0B0";
	}
}

function pruebaordenar(){
	  Sortable.create("caja1",{dropOnEmpty:true,containment:["caja1","caja2"],constraint:false,onChange:function(){$('caja1_debug').innerHTML = Sortable.serialize('caja1') }});
	  Sortable.create("caja2",{dropOnEmpty:true,handle:'handle',containment:["caja1","caja2"],constraint:false,onChange:function(){$('caja2_debug').innerHTML = Sortable.serialize('caja2') }});				 
}





