// JavaScript Document
<!--

String.prototype.Trim = function(){return this.replace(/\s+$|^\s+/g,"");}
String.prototype.LTrim = function(){return this.replace(/^\s+/,"");}
String.prototype.RTrim = function(){return this.replace(/\s+$/,"");}

//var objeto=ie4? document.all.popmenu : ns6? document.getElementById('popmenu') : ns4? document.popmenu : ''
//var objeto==ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function detectarNavegador(){
var version=navigator.appName;
	return version;
}
function mayusculas(objeto){
objeto.value=objeto.value.toUpperCase();
objeto.value=objeto.value.Trim();
}
function ChangeUrl(formulaire)
	{
	if (formulaire.ListeUrl.selectedIndex != 0)
		{
		location.href = formulaire.ListeUrl.options[formulaire.ListeUrl.selectedIndex].value;
	 	}
	else 
		{
		alert('Tienes que elegir un destino.');
		}
}
function ratonSobre(grupo, etiqueta){
    var etiquetas = document.getElementById(grupo).getElementsByTagName(etiqueta);
      for (var i = 0; i < etiquetas.length; i++) {
         etiquetas[i].onmouseover = function() {
            this.className += ' ie';
         }
         etiquetas[i].onmouseout = function() {
            this.className = this.className.replace('ie', '');
         }
      }
}
function asignarEventos(selec){//evento para cada celda del menu, la celda lleva como id el nombre de la pagina 
var i,obj="links", paginas,grupo=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	paginas=grupo.getElementsByTagName('td');
	for(i=0;i<paginas.length;i++){		
		if(selec==i){paginas[i].style.background="url(../imagenes/b_boton_s_corto.png) no-repeat right";paginas[i].style.cursor="default";paginas[i].style.color="#fff";}
		else paginas[i].onclick=function(){location.href=this.id+".php";}
	}	
}
function aHilatura(opcion){
	var url,opciones= new Array('','hlakshmi','hnewtex','hsmith','hinspiron','tomsic');
	if(opcion==0){
		opcion=1;
		url='../productos/'+opciones[opcion]+'.html';
		var ventana_destino=document.getElementById('Parte3');	ventana_destino.src=url;	
	} else location.href=opciones[opcion];
	/*window.open(opciones[opcion],'Parte3');*/
}
function aHilaturaEventos(){
	var oficina,i,oficinas=document.getElementById('links').getElementsByTagName('td');
	for(i=0;i<oficinas.length;i++){
		if(i==0)oficinas[i].onclick=function(){aHilatura(1);}
		if(i==1)oficinas[i].onclick=function(){aHilatura(2);}
		if(i==2)oficinas[i].onclick=function(){aHilatura(3);}
		if(i==3)oficinas[i].onclick=function(){aHilatura(4);}
		if(i==4)oficinas[i].onclick=function(){aHilatura(5);}
	}
	oficina=document.getElementById('oficina');
	oficina.style.background="url(../imagenes/b_boton_s_corto.png) no-repeat right";
	oficina.style.cursor="default";oficina.style.color="#fff";	
}
function aTejido(opcion){
	var url,opciones= new Array('','tprobity','treynold','texim','tmotofrenos','tforraje','totros');
	if(opcion==0){
		opcion=1;
		url='../productos/'+opciones[opcion]+'.html';
		var ventana_destino=document.getElementById('Parte3');	ventana_destino.src=url;	
	} else location.href=opciones[opcion];
	/*window.open(opciones[opcion],'Parte3');*/
}
function aTejidoEventos(){
	var oficina,i,oficinas=document.getElementById('links').getElementsByTagName('td');
	for(i=0;i<oficinas.length;i++){
		if(i==0)oficinas[i].onclick=function(){aTejido(1);}
		if(i==1)oficinas[i].onclick=function(){aTejido(2);}
		if(i==2)oficinas[i].onclick=function(){aTejido(3);}
		if(i==3)oficinas[i].onclick=function(){aTejido(4);}
		if(i==4)oficinas[i].onclick=function(){aTejido(5);}
		if(i==5)oficinas[i].onclick=function(){aTejido(6);}
		if(i==6)oficinas[i].onclick=function(){aTejido(7);}
	}
	oficina=document.getElementById('oficina');
	oficina.style.background="url(../imagenes/b_boton_s_corto.png) no-repeat right";
	oficina.style.cursor="default";oficina.style.color="#fff";
	
}
function atejidoEventoImg(){
	var obj="contenedor_tablas";
	var contenedor=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	var imgs=contenedor.getElementsByTagName('img');	
	for(i=0;i<imgs.length;i++){
		imgs[i].onclick=function(){if(togle('div_pop'))abrirImg(this,this.src);
		}
	}	
}
function abrirImg(posxy,src) {
	
	var obj="div_pop";
	var capa=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	obj="div_img";
	var img=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	capa.style.top=getDimension(posxy).y;
	capa.style.left=getDimension(posxy).x;
	img.src=src;	
}

function set_opacity(div, value) {
	div.style.opacity = value;
	div.style.MozOpacity = value;
	div.style.KhtmlOpacity = value;
	div.style.filter = 'alpha(opacity=' + value*100 + ')';
	div.style.zoom=1;//necesario para Explorer
}
var num_pasos=(document.getElementById&&!document.all)?50:15;//  mozilla : iexplorer  // menor mas rapido
var transicion=function(inicio,fin,segundos){
    var _this=this;
    this.test=0;
    if(_this.intervalo)clearInterval(_this.intervalo);
    if(this.val && Math.abs(fin-_this.val)<0.01)return;
    this.val=!this.val?inicio<1?inicio+.0001:inicio:this.val;
    set_opacity(this, this.val);
    this.pasos=(fin-inicio)/num_pasos;
    this.pausa=segundos;
    this.intervalo=setInterval(
    function(){
        if(_this.test>99 || Math.abs(fin-_this.val)<0.01){
          clearInterval(_this.intervalo);
        }
        _this.test++;
        //document.getElementById("log").innerHTML=_this.test;
        _this.val=_this.val+_this.pasos;
        if(_this.val<=.01) 
            _this.style.display='none';
        else
            _this.style.display='block';
        set_opacity(_this, _this.val);
    },this.pausa);
}
getDimension = function(element) {
	var x, y, w, h,sx,sy;
	sx=0;sy=0;
	if((navigator.userAgent.toLowerCase().indexOf('safari/') > -1) || (navigator.userAgent.toLowerCase().indexOf('chrome/') > -1)){sx=.5;sy=.5;}
	var coords = { x: 0, y: 0, w: element.offsetWidth, h:	element.offsetHeight };
	while (element) {
		coords.x += element.offsetLeft+sx;		
		coords.y += element.offsetTop+sy;		
		element = element.offsetParent;
	}	
	return coords;
}
function ajustarPosicion(ancho,alto,obj){
	if(obj.id==null)obj=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	var ancho_ventana = parseInt(document.all?document.body.clientWidth:window.innerWidth-16);
	var alto_ventana = parseInt(document.all?document.body.clientHeight:window.innerHeight-16);
	var posx=parseInt(obj.style.left);
	var posy=parseInt(obj.style.top);
	var ancho=parseInt(obj.style.width);
	var alto=parseInt(obj.style.height);	
	if((posx+ancho) > ancho_ventana)obj.style.left=ancho_ventana - ancho;
	if((posy+alto) > alto_ventana)obj.style.top=alto_ventana - alto;
}
function winPop(ancho,alto,url,posxy,obj,o){
   elementoMove(posxy,obj,o);   
	var padre=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	ajustarPosicion(ancho,alto,padre)
   if(padre.hasChildNodes())padre.removeChild(padre.childNodes.item(0));
   padre.innerHTML="<iframe id='ventana_pop' name='ventana_pop' AllowTransparency></iframe>";
	var ventana = document.getElementById('ventana_pop');
    ventana.src=url;
    ventana.setAttribute("width",ancho);
    ventana.setAttribute("height",alto);	
    ventana.style.borderWidth=0;	
}
function elementoMove(posxy,obj,o){//o = orientacion derecha(d abajo(a))
	if(posxy.id==null)posxy=ie4? document.all(posxy) : ns6? document.getElementById(posxy) : ns4? document.posxy : '';
	if(obj.id==null)obj=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	myposxy=posxy;
	var an=(o=='d')?getDimension(posxy).w:0;
	var al=(o=='a')?getDimension(posxy).h:0;    
    obj.style.top=getDimension(posxy).y+al;
    obj.style.left=getDimension(posxy).x+an;
}
function togle(obj){	
	var el=ie4? document.all(obj) : ns6? document.getElementById(obj) : ns4? document.obj : '';
	if(el.style.display!='none'){	
    transicion.call(el,1,0,1); 
	return false;
   } else {
   		transicion.call(el,0,1,1); 
   		return true;    	
	}
}
//Termina funciones Nitta
//-->

