/* VARIABLES GLOBALES */
var nav4 = window.Event ? true : false;
var imgAltActual=-1;
opcMenuElegido = 3;

/* FUNCIONES VARIAS */
function colorFondoAcordeon(src,clrOver,opc) {
	if(opcMenuElegido!=opc)
		src.style.backgroundColor = clrOver;
}
function menuElegido(menu){
	opcMenuElegido=menu;
}
function colorFondoMenu(src,clrOver){
	src.style.backgroundColor = clrOver;
}
function colorFondo(src,clrOver){
	src.bgColor = clrOver;
}
function colorBorde(src,clrOver){
	src.style.borderColor = clrOver;
}
function establecerAncla(ancla){
	if(navigator.appName.indexOf("Explorer")!=-1){ 
		var hash = ancla; 
		hash = hash.replace(/^.*#/, '');
		jQuery.historyLoad(hash);
	}
}
function mostrarOcultarCapa(capa,opc){
	if(document.getElementById(capa)){ document.getElementById(capa).style.display=opc; }
}
function mostrarOcultarDosCapas(capa1,capa2,opc1,opc2){
	if(document.getElementById(capa1)){ document.getElementById(capa1).style.display=opc1; }
	if(document.getElementById(capa2)){ document.getElementById(capa2).style.visibility=opc2; }
}
/* PARA LAS COMPARACIONES DE LOS PRODUCTOS 
----------------------------------------------------------------------------------------------------- */
// Funcion para saber cuantos CHK se han marcado
function fncTotalChkMarcados(form){
	var tot=0;
	for(a=0;a<form.elements.length;a++){ 
		if(form[a].type=="checkbox"){ 
			if((form[a].checked)){
				tot++;
			}
		} 
	}
	if(tot>3){ alert('Usted solo puede marcar 3 productos como maximo.'); return 4; }
	return tot;
}
function fncCompararProductos(form){
	var tot = fncTotalChkMarcados(form);
	if(tot<=3 && tot>1){
		var params="";
		for(a=0;a<form.elements.length;a++){ 
			if(form[a].type=="checkbox"){ 
				if((form[a].checked)){
					params+=form[a].value+",";
				}
			} 
		}
		
		abrirPopup('comparar', 'productos_comparar.php?id='+params, '800', '610');	
	}else{
		if(tot==0 || tot==1) alert("Aviso!!\n\nDebe de marcar al menos dos productos");
	}
}
function fncLimpiarChk(form){
	for(a=0;a<form.elements.length;a++){ 
		if(form[a].type=="checkbox"){ 
			form[a].checked=0;
		} 
	}
}
function marcarChk(chk){
	if(document.getElementById(chk).checked){
		document.getElementById(chk).checked=0;
	}else{
		document.getElementById(chk).checked=1;
	}
}
// --------------------------------------------------------------------------------------------------
function marcarImgAlterna(id,estilo_1,estilo_2){
	for(i=0; i<=4; i++){
		obj = "id_img_alt_"+i;
		if(document.getElementById(obj)){
			if(id==i){ cambiarEstiloImg(obj,estilo_1); }
			else{ cambiarEstiloImg(obj,estilo_2); }
		}
	}
	imgAltActual = id;
}

function cambiarEstiloImgAlt(id,obj,estilo){
	if(imgAltActual!=id){
		document.getElementById(obj).className = estilo;
	}
}

function cambiarEstiloImg(obj,estilo){
	document.getElementById(obj).className = estilo;
}

// Funcion para enviar pagina por URL por medio de una celda "TD"
function oClick(url){
	document.location.href = url;
}

// Funcion para convertir a mayusculas
function soloMayusculas(obj){
	obj.value = obj.value.toUpperCase();	
}

// Funcion para aceptar solo numeros
function soloNumeroCompatible(evt){
	if(navigator.appName.indexOf("Explorer")!=-1){ // Si se trata del Explorer
		var key=window.event.keyCode;
		if (key < 48 || key > 57){ window.event.keyCode=0; }
	}else{ // Cualquier otro navegador
		var key = nav4 ? evt.which : evt.keyCode;	//46
		return (key <= 13 || (key >= 48 && key <= 57));
	}
}

/*-------- OTRAS FUNCIONES --------*/
// Para crear popups
function abrirPopup(id, url, ancho, alto) {
	var h = (screen.width);
    var v = (screen.height);  
    var left=(h/2)-(ancho/2);
	var top=(v/2)-(alto/2);
	eval("page" + id + " = window.open(url, '"+id+"', 'width="+ancho+"px,height="+alto+"px,left="+left+",top="+top+",toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1');");
	eval("page" + id + ".focus()");
}

// Validar el cierre de sesion
function validarCerrarSesion(){
	var ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if(confirm("Realmente desea cerrar su sesion? ")){
		ht[0].style.filter = "";
		cerrarSesion();
	}else{
		ht[0].style.filter = "";
	}
	return false;
}

// Funcion para limpiar los espacios en blanco
function ltrim(s) { return s.replace(/^\s+/, ""); }  
function rtrim(s) { return s.replace(/\s+$/, ""); }  
function trim(s)  { return rtrim(ltrim(s)); }