//ajax
function valorar()
{ 
	var xmlhttp=false; 
	try 
	{ 
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function valor(variable,nombrecapa,ad)
{
  var capa=document.getElementById(nombrecapa);
	var ajax=valorar();
	capa.innerHTML="<img src='http://img.tendalia.com/ajax.gif' width=12 height=12>";
	ajax.open("POST", "http://control.tendalia.com/js/valor.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("d="+variable+"&ad="+ad);
	
	
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4)
		{
		capa.innerHTML=ajax.responseText;
			
		}
	}
	var capa2=document.getElementById('contador');
	var ajax2=valorar();
	ajax2.open("POST", "http://control.tendalia.com/js/valor2.php", true);
	ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax2.send("d="+variable);
	ajax2.onreadystatechange=function()
	{
		if (ajax2.readyState==4)
		{
		capa2.innerHTML=ajax2.responseText;
			
		}
	}
}

// calculadora 
function valorc(variable,tipo)
{
  var capa=document.getElementById('div'+tipo);
	var ajax=valorar();
	capa.innerHTML="<img src='http://img.tendalia.com/ajax.gif' width=12 height=12>";
	ajax.open("POST", "http://control.tendalia.com/js/valorc.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("d="+variable+"&tipo="+tipo);

	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4)
		{
		capa.innerHTML=ajax.responseText;
			
		}
	}
}


//Contador de caracteres.----------------------------
function getObject(obj) {
  var theObj;
  if(document.all) {
  if(typeof obj=="string") {
          return document.all(obj);
  } else {
          return obj.style;
  }
  }
  if(document.getElementById) {
  if(typeof obj=="string") {
          return document.getElementById(obj);
  } else {
          return obj.style;
  }
  }
  return null;
}
function Contar(entrada,salida,texto,caracteres) {
 
          var entradaObj=getObject(entrada);
          var salidaObj=getObject(salida);
          var longitud=caracteres - entradaObj.value.length;
 
if(longitud <= 0) {
          longitud=0;
          texto='<span class="disable"> '+texto+' </span>';
          entradaObj.value=entradaObj.value.substr(0,caracteres);
  }
          salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
  }


function entrar(){
if (entrar.q.value != ''){
document.entrar.action='http://www.tendalia.com/?sec=search&q='+buscador.q.value;
document.entrar.submit();
}
}

function capa(elemento){			
var menu1 = document.getElementById(elemento);
if(menu1.style.display == "none"){
menu1.style.display = "block";
document.getElementById("flecha"+elemento).src="http://img.tendalia.com/flechaupa.gif"; 
}else{
menu1.style.display = "none";
document.getElementById("flecha"+elemento).src="http://img.tendalia.com/flechadowna.gif"; 
}
}

function capabuscar(){			
var menu1 = document.getElementById('b');
var menu2 = document.getElementById('c');
if(menu1.style.display == "none"){
menu1.style.display = "block";
menu2.style.display = "none";
}else{
menu1.style.display = "none";
}
}

function cambia(){
var indice = document.cambiar.idtienda.selectedIndex;
var valor = document.cambiar.idtienda.options[indice].value; 
document.cambiar.action='http://control.tendalia.com';
document.cambiar.submit();
}