// Incluimos las librerias de efectos
document.write("<"+"script type='text/javascript' src='/javascript/scriptaculous/prototype.js'><"+"/script>")
document.write("<"+"script type='text/javascript' src='/javascript/scriptaculous/scriptaculous.js'><"+"/script>")
// Constructor ajax
function nuevoAjax(){
        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;
}
// Inserta el contenido del archivo php
function loadContent(toload,label,param,action,type_select,code_filter){
		if (toload.indexOf('@') != -1) {
			load = toload.split('@');
			if (load[0] != "SUBFAB") {
				var content = document.getElementById(load[0]);
				var label_content = document.getElementById("label_"+load[0])
				var label = label_content.innerHTML;
			}
			else {
			var content = document.getElementById(toload);
			var label_content = document.getElementById("label_" + toload);
			}
		}
		else {
			var content = document.getElementById(toload);
			if(toload!="submit")
				var label_content = document.getElementById("label_" + toload);
		}
		if(toload!="submit")
			label_content.innerHTML=label;
        var ajax=nuevoAjax();
	var ts = Number(new Date());
        ajax.open("GET", "/external/ylos_search/search.test.php?load="+toload+"&param="+param+"&action="+action+"&type_select="+type_select+"&code_filter="+code_filter+"&ts="+ts,true);
        ajax.onreadystatechange=function() {
		//if (ajax.readyState==1) {content.innerHTML = "<span class='loading'>Cargando...</span>";}
		if (ajax.readyState==4) {content.innerHTML = ajax.responseText;}
		}
        ajax.send(null);
}
function search()
{
new Ajax.Request('/external/ylos_search/search.test.php?load=url',
  {
    method:'get',
    onSuccess: function(transport){
      response = transport.responseText || "Búsqueda no procesada";
	  buildSearchUrl('',response)
    },
    onFailure: function(){ alert('No se pudo procesar la búsqueda') }
  }); 
}
function buildSearchUrl(id_form,domain) {
var id_form = (id_form) ? (id_form) : ('search');
var free = (typeof document.forms[id_form].free != 'undefined') ? ((document.forms[id_form].free.value).replace(" ","+")) :("");
var price1 = (typeof document.forms[id_form].Precio1 != 'undefined') ? (document.forms[id_form].Precio1.value) :("");
var price2 = (typeof document.forms[id_form].Precio2 != 'undefined') ? (document.forms[id_form].Precio2.value) :("");
var i = 1;
var var_libre='';
var fab = '';
if ((document.forms[id_form].Familia.value).indexOf('@') != -1) {
	family_at = (document.forms[id_form].Familia.value).split('@');
	fam = family_at[1];
}
else var fam = (typeof document.forms[id_form].Familia != 'undefined') ? (document.forms[id_form].Familia.value) : ("");
if (typeof document.forms[id_form].Seccion !='undefined')  {
	fab_at = (document.forms["search"].Seccion.parentNode.id).split('@'); //span id='SUBFAB@XXXX'
	fab = fab_at[1];
	}
else var fab = (typeof document.forms[id_form].Fabricante!='undefined') ? (document.forms[id_form].Fabricante.value) :("-1");
while (i <= 10) {
	if (document.getElementById("CampoLibre"+i) != null) 
	{
		varbd = i-1;
		var_libre_selected = document.getElementById('CampoLibre' + i).options.selectedIndex;
		if( document.getElementById('CampoLibre' + i).options[var_libre_selected].text != "Seleccione")
			var_libre = "&CampoLibre=" + varbd + "&ValorCampoLibre=" + document.getElementById('CampoLibre' + i).options[var_libre_selected].text;
	}
	i++;
}
var section = (typeof document.forms[id_form].Seccion!='undefined') ? (document.forms[id_form].Seccion.value) :("-1");
var subfam = (typeof document.forms[id_form].Subfamilia!='undefined') ? (document.forms[id_form].Subfamilia.value) : ("-1");

var direccion="http://"+domain+"/index.html?msgOrigen=10&OrdenarPor=FechaDesc&Descripcion="+free+"&Subfamilia="+subfam+"&Familia="+fam;
direccion+="&Precio1="+price1+"&Precio2="+price2+"&Fabricante="+fab+"&Seccion="+section+var_libre;
location.href=direccion;
}


