var loaded = 0;

function load()
{
  if (loaded === 0)
  {
    loaded = 1;
    var Srch1;
    var Srch;
    var ThisParam;
    var field;
    var val;
    Srch1 = location.search;
    Srch = Srch1.replace("?","");
    if (Srch.length >0)
    {
        while (Srch.indexOf("_") != -1)
            {
            Srch = Srch.replace("_", " ");
            }
        while(Srch.length >0)
        {
            if (Srch.indexOf("&") > 0)
            {
                ThisLen = Srch.indexOf("&");
            }
            else
            {
                ThisLen = Srch.length;
            }
            ThisParam = Srch.slice(0,ThisLen);
            StrMid = ThisParam.indexOf("=");
            field = ThisParam.slice(0,StrMid);
            val = ThisParam.replace(field + "=","");
            Srch = Srch.replace(ThisParam,"");

            if (field === "thumbs" || field ===  "new" || field ===  "used")
            {
                document.getElementById('SearchFrame').contentDocument.getElementById(field).checked=true;
            }
            else if (field === "mfr")
            {
                var selObj = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('mfr');
                while (val.length > 0)
                {
                    lenThisMfr = val.indexOf(",");
                    if (lenThisMfr >0)
                    {
                        ThisMfr = val.slice(0,lenThisMfr);
                        val = val.replace(ThisMfr + ",","");
                    }
                    else
                    {
                        ThisMfr = val;
                        val = 0;
                    }
                    var i;
                    for (i=0; i<selObj.options.length; i++)
                    {
                        if (selObj.options[i].value === ThisMfr)
                        {
                            document.getElementById('SearchFrame').contentDocument.getElementById('mfr').options[i].selected=true;
                            i = selObj.options.length;
                        }
                    }
                }
            }
            else
            {
                document.getElementById('SearchFrame').contentDocument.getElementById(field).value=val;
            }
            if (Srch.length != 0)
            {
                Srch = Srch.replace("&","");
            }
        }
        document.getElementById('SearchFrame').contentDocument.getElementById('SearchForm').submit();
    }
  }
}

function SubmitSearch()
{
    var url = parent.window.location.protocol + "//" + parent.window.location.host + parent.window.location.pathname;
    var srch = "";

    var selectedArray = new Array();
    var selObj = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('mfr');
    var i;
    var count = 0;
    for (i=0; i<selObj.options.length; i++)
        {
        if (selObj.options[i].selected)
            {
            selectedArray[count] = selObj.options[i].value;
            count++;
            }
        }
    if (selectedArray.length >0)
        {
        srch = srch + "mfr=" + selectedArray + "&";
        }

    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('pns').value
    if (pn1.length > 0)
      {
      srch = srch + "pns=" + pn1 + "&";
      }
    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('pni').value
    if (pn1.length > 0)
      {
      srch = srch + "pni=" + pn1 + "&";
      }
    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('pne').value
    if (pn1.length > 0)
      {
      srch = srch + "pne=" + pn1 + "&";
      }
    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('txt1').value
    if (pn1.length > 0)
      {
      srch = srch + "txt1=" + pn1 + "&";
      }
    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('txt2').value
    if (pn1.length > 0)
      {
      srch = srch + "txt2=" + pn1 + "&";
      }
    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('txt3').value
    if (pn1.length > 0)
      {
      srch = srch + "txt3=" + pn1 + "&";
      }
    pn1 = parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('txt4').value
    if (pn1.length > 0)
      {
      srch = srch + "txt4=" + pn1 + "&";
      }
    if (parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('new').checked)
      {
      srch = srch + "new=true" + "&";
      }
    if (parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('used').checked)
      {
      srch = srch + "used=true" + "&";
      }
    if (parent.window.document.getElementById('SearchFrame').contentDocument.getElementById('thumbs').checked)
      {
      srch = srch + "thumbs=true";
      }
    if (srch.length > 0)
        {
            while (srch.indexOf(" ") != -1)
                {
                srch = srch.replace(" ", "_");
                }
        url = url + "?" + srch;
        if (parent.window.location.href != url)
            {
            loaded = 0;
            parent.window.location.assign(url);
            }
        else
            {
            loaded = 1;
            parent.window.location.assign(url);
            }
        }
    else
        {
        loaded = 1;
        parent.window.location.assign(url);
        }
    return false;
}


function resizeIframe()
{
    var height = document.documentElement.clientHeight;
    height -= document.getElementById('content').offsetTop;
    height -= 10;
    document.getElementById('content').style.height = height +"px";
}

// put the desired page into the content frame
var tashost="http://" + location.hostname + "/";

function loadpage(pageURL)
{
  if (pageURL == "home")
    {
    parent.window.location = tashost;
    }
    else
    {
    parent.window.location = tashost + pageURL;
    }
}
