function find(txt, arr)
{
	for (z=0;z<arr.length;z++)
	{
		if (arr[z].toUpperCase()==txt.toUpperCase())
		{
			return z;
		}
	}
}

function buildHeader(path, txt)
{
	txt = txt.toLowerCase();
	var ret = "";
	var source = new Array("a", "á", "b", "c", "d", "e", "é", "f", "g", "h", "i", "í", "j", "k", "l", "m", "n", "ñ", "o", "ó", "p", 
	"q", "r", "s", "t", "u", "ú", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "@", ",",  "$", ":", "!", 
	"+", "-", "(", ")",  "&", "#", "/", ".", " ", "\"", "¡");
	var dest = new Array( "a", "aconacento", "b", "c", "d", "e", "econacento", "f", "g", "h", "i", "iconacento", "j", "k", "l", "m", "n", 
	"�", "o", "oconacento", "p", "q", "r", "s", "t", "u", "uconacento", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", 
	"8", "9", "arroba", "coma",   "dolar", "dosPuntos", "exclamacion", "mas", "menos", "parentesisAbriendo", "parentesisCerrando", "as", 
	"numeral", "slash", "punto", "espacio", "comillas", "abreexclamacion");
	for (i=0; i < txt.length; i++)
	{
		ret += '<img src="' + path + dest[find(txt.substring(i, i+1), source)] + '.gif" class="headerLetters" />\n';
	}
	
	return ret;
}

function showHowTo()
{
	document.getElementById('productInfoDisplay').style.display = 'none';
	document.getElementById('productBudgetInfo').style.display = 'none';
	document.getElementById('productHowToInfo').style.display = 'block';
}

function showBudget()
{
	document.getElementById('productInfoDisplay').style.display = 'none';
	document.getElementById('productHowToInfo').style.display = 'none';
	document.getElementById('productBudgetInfo').style.display = 'block';
}

function hideHowTo()
{
	document.getElementById('productInfoDisplay').style.display = 'block';
	document.getElementById('productHowToInfo').style.display = 'none';
}

function hideBudget()
{
	document.getElementById('productInfoDisplay').style.display = 'block';
	document.getElementById('productBudgetInfo').style.display = 'none';
}

function verify(dir)
{
	if (document.getElementById('name').value=='')
	{
		alert('Debe colocar su nombre');	
	} 
	else if (document.getElementById('email').value=='')
	{
		alert('Debe colocar su email');	
	} 
	else if (document.getElementById('phone').value=='')
	{
		alert('Debe colocar su telefono');	
	} 
	else if (document.getElementById('company').value=='')
	{
		alert('Debe colocar el nombre de su compania');	
	} 
	else 	
	{
		document.getElementById('mailLink').disabled = true;
		document.getElementById('loadingBar').style.display = 'block';
		sendMail(dir, document.getElementById('name').value, document.getElementById('email').value, document.getElementById('phone').value, document.getElementById('company').value, document.getElementById('productName').value, document.getElementById('productURL').value);
	}
}


function sendMail(dir, a_name, a_email, a_phone, a_company, a_pName, a_pURL)
{
	try
    {
	$.post(dir + "/budget.php", { name: a_name, email: a_email, phone: a_phone, company: a_company, productName: a_pName, productURL: a_pURL },
  function(data){
	document.getElementById('loadingBar').style.display = 'none';
	document.getElementById('loadingBar').style.textAlign = 'right';
    alert(data);
	document.getElementById('mailLink').disabled = false;
	document.getElementById('name').value='';
	document.getElementById('email').value='';
	document.getElementById('phone').value='';
	document.getElementById('company').value='';
  });
  }
  catch (e)
  {
  alert(e);
  }

}

var sub_actual='';
$(document).ready(function()
{
    $('.desplegar_sub').click(function(e)
    {
        e.preventDefault();

        if (sub_actual!='')
        {
            $('#sub_' + sub_actual).slideUp();
            sub_actual='';
        }

        if ($('#sub_' + $(this).attr('href')).css('display')=='none')
        {
            $('#sub_' + $(this).attr('href')).slideDown();
            sub_actual=$(this).attr('href');
        }
        else
            $('#sub_' + $(this).attr('href')).slideUp();
        return false;
    });
	
	$('.subcategoria').bind('mouseenter',function(){
		var src=$(this).attr('src');
		$(this).attr('src', src.replace('N.', 'B.'));
	}).bind('mouseleave', function(){
		var src=$(this).attr('src');
		$(this).attr('src', src.replace('B.', 'N.'));
	});
	
	// aires
	$('#aires_descargas').click(function()
	{
		$('#aires_botones2').slideToggle('fast', function()
		{
			var img=$('#aires_descargas').children('img:first');
			if (img.attr('src')==sd+'/images/aires_descargas_flip.gif')
				img.attr('src', sd+'/images/aires_descargas.gif');
			else
				img.attr('src', sd+'/images/aires_descargas_flip.gif');
		});

		return false;
	});	
	
	$('#aires_ficha').click(function()
	{
		if ($('#aires_texto_descripcion').css('display')!='none')
			$('#aires_texto_descripcion').slideUp(400,function(){$('#aires_texto_ficha').slideDown(400, 'easeOutBounce')});
		else
			$('#aires_texto_ficha').slideUp(400,function(){$('#aires_texto_descripcion').slideDown(400, 'easeOutBounce')});
			
		return false;
	});
	
	$('#aires_galeria').click(function()
	{
		if ($('a[rel=galeria]').size()>0)
			$('a[rel=galeria]:first').click();
	});
		
	$('.volante').click();
	
});
