// JavaScript Document
$(document).ready(function(){
	$("#imagess a").mouseover(function(){
		var title = "aplication/webroot/imgs/catalogo/"+ $(this).attr("title");
		var len = title.length;
		var text = title.substr(0,33);
		var newtitle = text + title.substr(39,len);
		$("#imgp").hide();
		$("#imgp").attr("src",title).fadeIn('slow'); 
		$("#imgp").attr("alt",title); 
		$("#grande").attr("href",newtitle); 
	
	});	 		
	
	$('#menus li').each(function(index){ 
		$(this).click(function(){			                
			$("#subcat"+index).toggle("fast"); 			   
		}); 	  
	});	
	
	
		
	
		marquee();
		$("#sub_container").mouseout(function(){
			marquee();
		});
	
});
var vcar = 270;
var vcar2 = 270;
var t;
	function marquee(){
		vcar =  parseInt(vcar - 1);
		if (vcar == -vcar2){
			vcar = vcar2;
		} 
		$("#sub_container").css("top",vcar);
		t = window.setTimeout("marquee()",20);
		$("#sub_container").mouseover(function(){
			window.clearTimeout(t);
		});
	}
	
function busqueda(url,texto){
	
	document.fbuscar.action = url+'&q=' + texto.value;
	document.fbuscar.submit();
}

function checkTheKey(keyCode){
	if(event.keyCode==13){	
		valida();
		return true ;
	}
	return false ;
}
function validnum(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la línea de patron que se necesite y borrar el resto 
    //patron =/[A-Za-z]/; // Solo acepta letras 
    patron = /\d/; // Solo acepta números
    //patron = /\w/; // Acepta números y letras 
    //patron = /\D/; // No acepta números 
    // patron = /[\d.-]/; numeros el punto y el signo -
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
	// uso  onKeyPress="return validnum(event)"
}


function ver_compromiso(){
  $('#nosotros').hide('slow');
  $('#compromiso').show('slow');
}
function ver_nosotros(){
  $('#compromiso').hide('slow');
  $('#nosotros').show('slow');
}

/*$(document).ready( function(){						   
	$('#menu li').each(function(index){ 
		$(this).click(function(){			                
			$("#subcat"+index).toggle("fast"); 			   
		}); 	  
	});					   

	$("#imagenes a").click( function(){
		var title = $(this).attr("title");
		$("#imgp").hide();
		$("#imgp").attr("src",title).fadeIn('slow'); 
	});	 	
});*/


function validar(){
	if(document.f1.nombre.value==""){
		alert("ERROR: Por favor ingrese su Nombre");
		document.f1.nombre.focus();
		return false;
	}else if(document.f1.email.value==""){
		alert("ERROR: Por favor ingrese su Email");
		document.f1.email.focus();
		return false;
	}else if(document.f1.telefono.value==""){
		alert("ERROR: Por favor ingrese su Telefono");
		document.f1.telefono.focus();
		return false;
	}else if(document.f1.mensaje.value==""){
		alert("ERROR: Por favor dejenos su comentario");
		document.f1.mensaje.focus();
		return false;
	}else{
		document.f1.action="enviar.php";
		document.f1.submit();
		
	}
	
}

function estado_paginador(k){
	
	$("#p"+k).css({background: "#E4E4E4",color: "#701005"});
}


function resultado(div){
		ran = Math.ceil(Math.random());
		v=0;
		n=0;
		for(x = 1; x <= 17 ;x++ ){
			radio = document.frmtest.elements['n'+x];

		if(radio[0].checked == true && radio[0].value == 1){
				v++;	
			}
		}
		for(i = 1; i <= 17 ;i++ ){
			radio2 = document.frmtest.elements['n'+i];
			if(radio2[1].checked == true && radio2[1].value == 0){
				n++;	
			}
		}
		
		
		$('#' + div).empty();
		$('#' + div).hide();
		
		if (v == 0 && n == 0 ){
			$('#' + div).fadeIn('slow').html('<br><br><br><center> <br><br><span style="color:#B13838"> Por favor conteste las preguntas...</span> </center>');
		}
		else{
			
		$('#' + div).ajaxStart(function(){
		$('#' + div).html('<br><br><br><center><img src="aplication/webroot/imgs/icons/ajax-loader.gif"><br><br><span style="color:#B13838"> Cargando Resultados...</span> </center>');		
		}).fadeIn('slow').load("resultado.php?si="+v); 
		
		
		}							
			
	}
	
function ponerimagen(index){
	if (index == 1){ $("#m1").attr('src','aplication/webroot/imgs/g_home.jpg') }
	if (index == 2){ $("#m2").attr('src','aplication/webroot/imgs/g_nosotros.jpg')  }
	if (index == 3){ $("#m3").attr('src','aplication/webroot/imgs/g_noticias.jpg')  }
	if (index == 4){ $("#m4").attr('src','aplication/webroot/imgs/g_capacitacion.jpg')  }
	if (index == 5){ $("#m5").attr('src','aplication/webroot/imgs/g_catalogo.jpg')  }
	if (index == 6){ $("#m6").attr('src','aplication/webroot/imgs/g_contacto.jpg')  }
			
}

function sacarimagen(index){
	if (index == 1){ $("#m1").attr('src','aplication/webroot/imgs/home.jpg') }
	if (index == 2){ $("#m2").attr('src','aplication/webroot/imgs/nosotros.jpg')  }
	if (index == 3){ $("#m3").attr('src','aplication/webroot/imgs/t_noticias.jpg')  }
	if (index == 4){ $("#m4").attr('src','aplication/webroot/imgs/capacitacion.jpg')  }
	if (index == 5){ $("#m5").attr('src','aplication/webroot/imgs/catal.jpg')  }
	if (index == 6){ $("#m6").attr('src','aplication/webroot/imgs/contant.jpg')  }
}

function PNG_loader() { 
   for(var i=0; i<document.images.length; i++) { 
      var img = document.images[i]; 
      var imgName = img.src.toUpperCase(); 
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG") { 
         var imgID = (img.id) ? "id='" + img.id + "' " : ""; 
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""; 
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; 
         var imgStyle = "display:inline-block;" + img.style.cssText; 
         if (img.align == "left") imgStyle += "float:left;"; 
         if (img.align == "right") imgStyle += "float:right;"; 
         if (img.parentElement.href) imgStyle += "cursor:hand;"; 
         var strNewHTML = "<span " + imgID + imgClass + imgTitle 
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"; 
         img.outerHTML = strNewHTML; 
         i--; 
      } 
   } 
} 
window.attachEvent("onload", PNG_loader);



