// JavaScript Document
navHover = function() {
	var lis = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  if (vis.display==''||vis.display=='block') 
    vis.display = 'none';
  else
    vis.display = 'block';
}

function coolToggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
      
  if (vis.display==''||vis.display=='block')
     setToMove(elem, 0, -200, false);
  else
     {  
     vis.display = 'block';
     setToMove(elem, -200, 0, true);
     }
  
}

var top;
var currentTop;
var searchBoxToMove;
var down = true;

function setToMove(elem, from, to, goDown)
{
 searchBoxToMove = elem; 
 currentTop = from; 
 top = to; 
 down = goDown; 
 searchBoxToMove.style.top = currentTop + 'px';
 searchBoxToMove.parentNode.style.display = 'block';      
 move();
}

function move()
{
 if (down)
    currentTop += 5;
 else
    currentTop -= 5;
 
 searchBoxToMove.style.top = currentTop + 'px';
 
 if (down)
    {
    if (currentTop < top)
       setTimeout('move();', 10);
    }
 else
    {
    if (currentTop > top)
       setTimeout('move();', 10);
    else
       searchBoxToMove.style.display = 'none';
    }
}

function showHideLayer( layerToShow, layerToHide )
{
  var elemToShow, elemToHide;
  if( document.getElementById ) {// this is the way the standards work
    elemToShow = document.getElementById( layerToShow );
    elemToHide = document.getElementById( layerToHide );
  }
  else if( document.all ) {// this is the way old msie versions work
      elemToShow = document.all[layerToShow];
	  elemToHide = document.all[layerToHide];
  }
  else if( document.layers ) {// this is the way nn4 works
    elemToShow = document.layers[layerToShow];
    elemToHide = document.layers[layerToHide];
  }
  elemToShow.style.display = 'block';
  elemToHide.style.display = 'none';
}

function layerPrice(){
  var elem, vis, i, whichLayer;
	var argv = layerPrice.arguments;
	var argc = argv.length;
	for (i = 0; i < argc; i++){
	 whichLayer = argv[i];
  if( document.getElementById ) // this is the way the standards work
   elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
   elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
   elem = document.layers[whichLayer];
  vis = elem.style;
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	}
	scroll(0,0);
}

function chart(tablaId, clsNam, wrapGrh)
{
var tableDatos, cellList, numCell, bar, sizeBar, numBar, newBar, newCont;
var topHeight, leftInit, total, divGraph, cnt;

topHeight = 300;
leftInit = 15;
total = 0;
cnt = 0;
	
if( document.getElementById )
tableDatos = document.getElementById( tablaId );
else if( document.all )
tableDatos = document.all[tablaId];
else if( document.layers )
tableDatos = document.layers[tablaId];

if( document.getElementById )
divGraph = document.getElementById( wrapGrh );
else  if( document.all )
divGraph = document.all[wrapGrh];
else if( document.layers )
divGraph = document.layers[wrapGrh];
cellList = tableDatos.getElementsByTagName('td');
numCell = cellList.length;
bar = new Array();
var ulGraph = document.createElement("ul");

for(var i = 0; i < numCell; i++)
{
  if(cellList[i].className == clsNam)
     { 
      sizeBar = bar[bar.length] = cellList[i].childNodes[0].nodeValue; 
			total = total + parseInt(sizeBar);
     }
}
for(var i = 0; i < numCell; i++)
{
  if(cellList[i].className == clsNam)
     { 
			cnt ++;
      sizeBar = bar[bar.length] = cellList[i].childNodes[0].nodeValue; 
      numBar = bar.length;
			newBar = document.createElement("li");
      newBar.className = "bar";
			newSpan = document.createElement("span");      
      newCont = document.createTextNode (sizeBar);
      newBar.appendChild(newSpan);
			newSpan.appendChild(newCont);
      newBar.style.left = leftInit + "px";
      leftInit += 65;
      newBar.style.height = Math.round(topHeight * (parseInt(sizeBar) / total)) + "px";
      ulGraph.appendChild(newBar);
      }
}
wGraph = cnt * 68;
divGraph.style.width = wGraph + "px";
divGraph.appendChild(ulGraph);
}

function toggleKitLayers( layerToShow )
{
  var elemToShow, elemKit1, elemKit2, elemKit3;
  if( document.getElementById ) {// this is the way the standards work
    elemToShow = document.getElementById( layerToShow );
	elemKit1 = document.getElementById( 'kit1' );
	elemKit2 = document.getElementById( 'kit2' );
	elemKit3 = document.getElementById( 'kit3' );
  }
  else if( document.all ) {// this is the way old msie versions work
    elemToShow = document.all[layerToShow];
	  elemKit1 = document.all['kit1'];
	  elemKit2 = document.all['kit2'];
	  elemKit3 = document.all['kit3'];
  }
  else if( document.layers ) {// this is the way nn4 works
    elemToShow = document.layers[layerToShow];
    elemKit1 = document.layers['kit1'];
    elemKit2 = document.layers['kit2'];
    elemKit3 = document.layers['kit3'];
  }
  elemKit1.style.display = 'none';
  elemKit2.style.display = 'none';
  elemKit3.style.display = 'none';
  elemToShow.style.display = 'block';
}
function addProdFstSt (anyDiv){
var elem, idProd, rowNum, rowNumTxt, crtCont, fldNum, fldCnt, lblPrd, lblPrdTxt, lblCnt, lblCntTxt;
if( document.getElementById )
  elem = document.getElementById(anyDiv);
else if(document.all)
  elem = document.all[anyDiv];
else if(document.layers)
  elem = document.layers[anyDiv];
	//Contamos el numero de inputs
	idProd= elem.getElementsByTagName("input").length / 2 + 1;
	//creamos el div donde agregamos el producto
	crtCont = document.createElement("div");
	elem.appendChild(crtCont);
	crtCont.className = "prod_added";
	//creamos el número del campo agregado
	rowNum = document.createElement("span");
	crtCont.appendChild(rowNum);
	rowNum.className = "row_num_fst";
	rowNumTxt = document.createTextNode(idProd);
	rowNum.appendChild(rowNumTxt);
	//creamos la etiqueta del primer elemento
	lblPrd = document.createElement("label");
	crtCont.appendChild(lblPrd);
	lblPrd.className = "row_lbl_fst";
	lblPrdTxt = document.createTextNode(" Producto ");
	lblPrd.appendChild(lblPrdTxt);
	//Creamos el siguiente input de la lista
	fldNum = document.createElement("input");
	crtCont.appendChild(fldNum);
	fldNum.type = "text";
	fldNum.maxlength = "50";
	fldNum.size = "25";
	fldNum.name = "prducto" + idProd;
	//creamos la etiqueta de la cantidad
	lblCnt = document.createElement("label");
	crtCont.appendChild(lblCnt);
	lblCnt.className = "row_lbl_fst";
	lblCntTxt = document.createTextNode(" Cantidad ");
	lblCnt.appendChild(lblCntTxt);
	//creamos el campo de cantidad
	fldCnt = document.createElement("input");
	crtCont.appendChild(fldCnt);
	fldCnt.type = "text";
	fldCnt.maxlength = "5";
	fldCnt.size = "10";
	fldCnt.name = "Cantidad";
}
var delay = 1;
var currentDiv, divToExpand;
var minHeight = 0;
var totalHeight = 451;

function acordionDiv()
{   
	if (divToExpand.offsetHeight < totalHeight)
		{
		divToExpand.style.height = (divToExpand.offsetHeight + 15) + 'px';
		currentDiv.style.height = (currentDiv.offsetHeight - 15) + 'px';
  	    setTimeout("acordionDiv();", delay);
	  }
	else
	  currentDiv = divToExpand;
		
}
function actvieAccordion(evt)
{
  var eventTarget;
  if (evt.target){
	eventTarget = evt.target;
  }else{
	eventTarget = evt.srcElement;
	}	
  divToExpand = document.getElementById('carro_' + eventTarget.name)
	acordionDiv();
}

function setCurrentDiv()
{
 var divIni = document.getElementById('carro_123');
 divIni.style.height = totalHeight + "px";
 currentDiv = divIni;
}
/*
var delay = 1, addedPixels = 10;
var adjExpPixels = 0, adjCurrPixels = 0;
var currentDiv, divToExpand;
var hcounter = 0, maxHeight = 0;
var currentHeight = 0, expandHeight = 0;
var prefix = 'orden_';

function acordionDiv()
{  
 	if (hcounter < maxHeight)
		{
		if (divToExpand.offsetHeight < expandHeight)
		    divToExpand.style.height = (expandHeight - divToExpand.offsetHeight > adjExpPixels)?(divToExpand.offsetHeight + addedPixels) + 'px':(divToExpand.offsetHeight + adjExpPixels) + 'px';	
		if (currentDiv != undefined)	
		{
		if (currentDiv.offsetHeight > 0)
		    currentDiv.style.height = (currentDiv.offsetHeight > adjCurrPixels)?(currentDiv.offsetHeight - addedPixels) + 'px':(currentDiv.offsetHeight - adjCurrPixels) + 'px';
		}
		hcounter += addedPixels;
  	    setTimeout("acordionDiv();", delay);
	  }	  
	else
	  {
	  currentDiv = divToExpand;
	  currentHeight = expandHeight;
	  adjCurrPixels = adjExpPixels;
	  }
		
}
function activeAccordion(evt)
{
  var eventTarget;  
  if (evt.target)
	{
	eventTarget = evt.target;
	}
  else
  	{
  	eventTarget = evt.srcElement;
  	}
  	
  if (eventTarget.tagName != 'A')
      eventTarget = eventTarget.parentNode;
      
  divToExpand = document.getElementById(prefix + eventTarget.name);
  if (divToExpand.className == "accordionHide")
    {   
    divToExpand.className = "accordionShow";
    }

  for (var i=0; i < divToExpand.childNodes.length; i++)
      if (divToExpand.childNodes[i].tagName == 'TABLE')
          expandHeight = divToExpand.childNodes[i].offsetHeight;
          
  adjExpPixels = expandHeight%addedPixels;
  maxHeight = Math.max(expandHeight, currentHeight);
  hcounter = 0;
  
  acordionDiv();	
}*/

var delay = 1;
var currentDiv, divToExpand;
var minHeight = 0;
var totalHeight = 451;

function acordionDiv()
{   
	if (divToExpand.offsetHeight < totalHeight)
		{
		divToExpand.style.height = (divToExpand.offsetHeight + 15) + 'px';
		currentDiv.style.height = (currentDiv.offsetHeight - 15) + 'px';
  	    setTimeout("acordionDiv();", delay);
	  }
	else
	  currentDiv = divToExpand;
		
}
function actvieAccordion(evt)
{
  var eventTarget;
  if (evt.target){
	eventTarget = evt.target;
  }else{
	eventTarget = evt.srcElement;
	}	
  divToExpand = document.getElementById('carro_' + eventTarget.name)
	acordionDiv();
}

function setCurrentDiv()
{
 var divIni = document.getElementById('carro_1');
 divIni.style.height = totalHeight + "px";
 currentDiv = divIni;
}
