<!--
// JavaScript Document
// Libreria de Ajax para lengujes de Script en el Servidor
// Preparado por: Ricardo Ll. Haynes M.
// email: rhaynes03@gmail.com

//Funcion para validar los datos de un formulario
function validar(formulario,capamsg,capa,url,metodo){		
		var listelement = "";
		var objForm = "";
		var count = 0;
		var param;
		var resultado;
		for(i=0; i < document.getElementById(formulario).length; i++){
			objForm = document.getElementById(formulario).elements[i].name;
			if (objForm.substring(0,4) == 'txtv'){			   
			   if (document.getElementById(formulario).elements[i].value == ''){	   			
				count++;
			   }else if(document.getElementById(formulario).elements[i].value == 0){
				count++;
			   }
			}
		}		
		if (count > 0){
		  /* document.getElementById(capa).innerHTML = "";
		   document.getElementById(capa).innerHTML = "Complete los datos";
		   document.getElementById(capamsg).style.visibility = 'visible';	
		   MoverCapa(capamsg);
		   fadeMSG(capamsg,2);*/
		   alert("Complete los datos");
		}else{	
			  //Verificado los datos con Ajax
			  param = GenParametro(formulario);
			  resultado = Ajax_Request(url,param,metodo,capamsg,capa);
		}	
}
function fadeMSG(capa,a){
	if (document.all){
			document.getElementById(capa).style.filter = "alpha(opacity:"+a+")";
		}else{
			document.getElementById(capa).style.MozOpacity = (a/100);
		}
		a = a + 2;
		if (a <= 100){
			setTimeout("fadeMSG('"+capa+"',"+a+")",0);
		}
}
function MoverCapa(capa){
		var sizex = 220;
		var sizey = 193;
		var winx = screen.width;
		var winy = screen.height;
		
		posx = (winx/2) - (sizex/2);
		posy = (winy/2) - (sizey/2);
		
		posx = parseInt(posx);
		posy = parseInt(posy)-50;

		document.getElementById(capa).style.top = posy+'px';
		document.getElementById(capa).style.left = posx+'px';
		document.getElementById(capa).style.visibility = 'visible';
}
	
function OcultarCapa(capa,a){			
		if (document.all){
			document.getElementById(capa).style.filter = "alpha(opacity:"+a+")";
		}else{
			document.getElementById(capa).style.MozOpacity = (a/100);
		}
		a = a - 2;
		if (a >= 0){
			setTimeout("OcultarCapa('"+capa+"',"+a+")",0);
		}else{
			document.getElementById(capa).style.visibility = 'hidden';
		}
}

function GenParametro(formulario){
	var listelement = "";
	var objForm = "";
	var count = 0;
	var param;
	for(i=0; i < document.getElementById(formulario).length; i++){
		objForm = document.getElementById(formulario).elements[i].name;	
		switch(document.getElementById(formulario).elements[i].type){
			case "text":
			if (i >= 1){			   
				param = param+"&"+objForm+"="+document.getElementById(formulario).elements[i].value;		   			}else{
				param =  objForm+"="+document.getElementById(formulario).elements[i].value;
			}
			break;
			case "select-one":
			if (i >= 1){			   
				param = param+"&"+objForm+"="+document.getElementById(formulario).elements[i].value;		   			}else{
				param =  objForm+"="+document.getElementById(formulario).elements[i].value;
			}
			case "hidden":
			if (i >= 1){			   
				param = param+"&"+objForm+"="+document.getElementById(formulario).elements[i].value;		   			}else{
				param =  objForm+"="+document.getElementById(formulario).elements[i].value;
			}
			break;
			case "textarea":
			if (i >= 1){			   
				param = param+"&"+objForm+"="+document.getElementById(formulario).elements[i].value;		   			}else{
				param =  objForm+"="+document.getElementById(formulario).elements[i].value;
			}
			break;
			case "password":
			if (i >= 1){			   
				param = param+"&"+objForm+"="+document.getElementById(formulario).elements[i].value;		   			}else{
				param =  objForm+"="+document.getElementById(formulario).elements[i].value;
			}
			break;
			case "checkbox":
			if (i >= 1){
				if(document.getElementById(formulario).elements[i].checked == true){
					param = param+"&"+objForm+"="+1;
				}else{
					param = param+"&"+objForm+"="+0;
				}
			}else{
				if(document.getElementById(formulario).elements[i].checked == true){
					param =  objForm+"="+1;
				}else{
					param =  objForm+"="+1;
				}
			}
			break;
		}
	}
	return param;
}
function fadeOn(capa,a){
	if (document.all){
			document.getElementById(capa).style.filter = "alpha(opacity:"+a+")";
		}else{
			document.getElementById(capa).style.MozOpacity = (a/100);
		}
		if (a <= 100){
			a = a + 2;
			setTimeout("fadeOn('"+capa+"',"+a+")",0);
		}else{ 
			fadeOff(capa,a);
		}
}
function fadeOff(capa,a){
	if (document.all){
			document.getElementById(capa).style.filter = "alpha(opacity:"+a+")";
		}else{
			document.getElementById(capa).style.MozOpacity = (a/100);
		}
		if (a >= 0){
			a = a - 2;
			setTimeout("fadeOff('"+capa+"',"+a+")",0);
		}else{
			document.getElementById(capa).style.visibility = 'hidden';			
		}
}

function fecha(){

fecha = new Date();
dia = fecha.getDate();
dia_semana = fecha.getDay();
mes = fecha.getMonth();
ano = fecha.getFullYear();

nombre_dias = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
nombre_meses = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");

document.write(nombre_dias[dia_semana] + " " + dia + " de " + nombre_meses[mes] + ", " + ano);

}

function validarFRM(formulario,capamsg,capa){		
		var listelement = "";
		var objForm = "";
		var count = 0;
		var param;
		var resultado;
		for(i=0; i < document.getElementById(formulario).length; i++){
			objForm = document.getElementById(formulario).elements[i].name;
			if (objForm.substring(0,4) == 'txtv'){			   
			   if (document.getElementById(formulario).elements[i].value == ''){	   			
				count++;
			   }else if(document.getElementById(formulario).elements[i].value == 0){
				count++;
			   }
			}
		}		
		if (count > 0){
		   /*document.getElementById(capa).innerHTML = "";
		   document.getElementById(capa).innerHTML = "Complete los datos";
		   document.getElementById(capamsg).style.visibility = 'visible';	
		   MoverCapa(capamsg);
		   fadeMSG(capamsg,2);*/		   
		}else{	
			  document.getElementById(formulario).submit();
		}	
}

function darkpage(){
	var darkDIV;
	var alto = document.body.offsetHeight;
	var ancho = document.body.offsetWidth;
	if (screen.availHeight > document.body.offsetHeight){
		alto = screen.availHeight;
	}

	darkDIV = document.createElement('DIV');
	darkDIV.id = 'divDark';
	darkDIV.className = 'lyDark_fondo';
	darkDIV.style.zIndex = 10000;
	darkDIV.style.visibility = 'visible';
	
	darkDIV.style.height  = alto+'px';
	darkDIV.style.width = ancho+'px';
	document.body.appendChild(darkDIV);	
}

function DelReg(url,param,metodo){
	var sw = false;
	var posX = 0;
	var posY = 0;
	Ajax_Request(url,param,metodo,'','');
	if (sw){
		if (document.all){
		if(document.documentElement.scrollTop < screen.availHeight ){
			posY = Math.ceil(screen.availHeight/2)-95;
		}else{
			if (document.documentElement.scrollTop > minTop){
				posY = minTop;
			}else{
				if (document.documentElement.scrollTop > screen.availHeight){
					posY = document.documentElement.scrollTop-95;
				}
			}
		}
	}else{
		if(window.pageYOffset < screen.availHeight ){
			posY = Math.ceil(screen.availHeight/2)-95;
		}else{
			if (window.pageYOffset > minTop){
				posY = minTop;
			}else{
				if (window.pageYOffset > screen.availHeight){
					posY = window.pageYOffset-95;
				}
			}
		}
	}
	if (document.body.offsetWidth > 220){		
		posX = Math.ceil(document.body.offsetWidth/2)-110;
	}else{
		if(document.body.offsetWidth < 110){	
			window.resizeBy(screen.width,screen.height);
			window.moveTo(0,0);
			posX = Math.ceil(document.body.offsetWidth/2)-110;
		}
	}
	document.getElementById('msgboxfoco').innerHTML = "";
	document.getElementById('msgboxfoco').innerHTML = "Registro Eliminado";
	document.getElementById('lyFOCO').style.top = posY;
	document.getElementById('lyFOCO').style.left = posX;
	document.getElementById('lyFOCO').style.visibility = 'visible';					   	
	fadeOn('lyFOCO',2);
	}// fin del sw
	closedel('divDark','divDel');
}
function viewImg(filepath,ancho,alto,leyenda,inicia,maximg){
	showImagen(filepath,ancho,alto,leyenda,inicia,maximg);
}

function showImagen(filepath,ancho,alto,leyenda,inicia,maximg){
	var tabla = "";
	var posH = Math.ceil(alto/2);
	var posW = Math.ceil(ancho/2);
	var posX;
	var posY;
	var imgDIV;
	var minTop;
	iniSlide();
	tabla  = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
    tabla += "<tr>";
    tabla +="<td><div align=\"center\"><img name=\"imgSlideShow\" src=\""+filepath+"\" width=\""+ancho+"\" height=\""+alto+"\" class=\"borde_galeria\" id=\"imgSlideShow\"/></div></td>";
	tabla +="</tr>";
    tabla += "<tr>";
    tabla += "<td bgcolor=\"#000066\"><table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">\n";
    tabla += "<tr>";
    tabla += "<td colspan=\"2\" bgcolor=\"#FFFFFF\" height=\"15\" class=\"txtAsK\"><div align=\"left\" id=\"txtleyenda\">&nbsp;"+leyenda+"</div></td>";
    tabla += "</tr>";
    tabla += "<tr>";
	tabla += "<td width=\"97%\">\n";
	tabla += "<table width=\"100\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
    tabla += "<tr>\n";
    tabla += "<td><div align=\"center\">\n";
	tabla += "<img src=\"img/jpg/rew.jpg\" width=\"16\" height=\"16\" style=\"cursor: pointer; cursor: hand;\" onClick=\"PreviewSlide()\"></div>\n";
	tabla += "</td>\n";
    tabla += "<td><div align=\"center\">\n";
	tabla += "<img src=\"img/jpg/play.jpg\" width=\"16\" height=\"16\" style=\"cursor: pointer; cursor: hand;\" onClick=\"StartSW();StartSlide("+inicia+","+maximg+");\"></div>\n";
	tabla += "</td>\n";
    tabla += "<td><div align=\"center\">\n";
	tabla += "<img src=\"img/jpg/stop.jpg\" width=\"16\" height=\"16\" style=\"cursor: pointer; cursor: hand;\" onClick=\"StopSlide();\"></div>\n";
	tabla += "</td>\n";
    tabla += "<td><div align=\"center\">\n";
	tabla += "<img src=\"img/jpg/fwd.jpg\" width=\"16\" height=\"16\" style=\"cursor: pointer; cursor: hand;\" onClick=\"NextSlide("+maximg+")\"></div>\n";
	tabla += "</td>\n";
    tabla += "<td><input name=\"Slideposicion\" type=\"hidden\" id=\"Slideposicion\"\n";
	tabla += "value=\""+inicia+"\" /></td>\n";
    tabla += "</tr>\n";		
    tabla += "</table>\n";
	tabla += "</td>\n";
    tabla += "<td><div align=\"right\"><img src=\"img/jpg/exit.jpg\" width=\"16\" height=\"16\" style=\"cursor: pointer; cursor: hand;\" onClick=\"cerrarView('divimg','divDark');StopSlide();\"/></div></td>";
    tabla += "</tr>";
    tabla += "</table></td>";
    tabla += "</tr>";
	tabla += "</table>";
		
	imgDIV = document.createElement('DIV');
	imgDIV.id = 'divimg';
	imgDIV.className = 'lyImg';
	imgDIV.style.zIndex = 15000;	
	imgDIV.innerHTML = tabla;
	
	var posH = Math.ceil((400+110)/2);
	var posW = Math.ceil((380+100)/2);
	minTop = Math.abs((document.body.clientHeight - screen.availHeight));
	if (document.all){
		if(document.documentElement.scrollTop < screen.availHeight  && document.documentElement.scrollTop < minTop){
			if((document.documentElement.scrollTop+50) < minTop){
				posY = (document.documentElement.scrollTop+175);
			}else{
				posY = Math.ceil(screen.availHeight/2)-(posH+100);
			}
		}else{
			if (document.documentElement.scrollTop > minTop){
				if ((document.documentElement.scrollTop-minTop) > 200){
					posY = document.documentElement.scrollTop+175;					
				}else{
					posY = document.documentElement.scrollTop+100;
				}
			}else{
				if (document.documentElement.scrollTop > screen.availHeight){
					posY = document.documentElement.scrollTop-(posH+50);
					
				}
			}
		}
	}else{
		if(window.pageYOffset < screen.availHeight && window.pageYOffset < minTop){
			if((window.pageYOffset+50) < minTop){
				if ((window.pageYOffset-minTop) > 200){
					posY = window.pageYOffset+175;					
				}else{
					posY = window.pageYOffset+175;
				}
			}else{
				posY = Math.ceil(screen.availHeight/2)-(posH+175);
			}
		}else{
			if (window.pageYOffset > minTop){
				posY = minTop+posH-50;
			}else{
					if (window.pageYOffset > screen.availHeight){
					posY = window.pageYOffset-posH;
				}
			}
		}
	}
	if (document.body.offsetWidth > ancho){		
		posX = Math.ceil(document.body.offsetWidth/2)-posW;
	}else{
		if(document.body.offsetWidth < posW){	
			window.resizeBy(screen.width,screen.height);
			window.moveTo(0,0);
			posX = Math.ceil(document.body.offsetWidth/2)-posW;
		}
	}
	darkpage();
	imgDIV.style.top = posY+'px';
	imgDIV.style.left = posX+'px';	
	imgDIV.style.width = 380+'px';
	imgDIV.style.height = 400+'px';
	imgDIV.style.visibility = 'visible';
	document.body.appendChild(imgDIV);
}

function cerrarView(capa,capaDark){
	try{			
	document.getElementById(capaDark).style.visibility = 'hidden';
	document.getElementById(capa).style.visibility = 'hidden';
	document.body.removeChild(document.getElementById(capaDark));			
	document.body.removeChild(document.getElementById(capa));
	}catch(e){
	}
}
-->