function onMakeChange(formName, inputName, makeSelect)
{
    if (makeSelect.options[makeSelect.selectedIndex].value == '-1')
    {
        // other is selected
        document.forms[formName][inputName].value = '';
        document.forms[formName][inputName].disabled  = false;
    }
    else {
        // its not other
        document.forms[formName][inputName].value = makeSelect.options[makeSelect.selectedIndex].text;
        document.forms[formName][inputName].disabled  = true;

    }
}
function unhide(name)
{
    //document.getElementById(name).style.visibility="visible";
    //document.getElementById(name).style.display="block";

    document.getElementById(name).style.display = 'block';
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function parsePriceXML(xmlData, vendor, motor_id, logo)
{
    // Retarded fix required to make it parse XML in IE
    if (jQuery.browser.msie)
    {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.loadXML(xmlData);
        xmlData = xmlDoc;
    }

    var error = $("error",xmlData).text();
    var msg = "Error: [" + error + "]\n";

    var price = $("price",xmlData).text();
    msg = msg+"Price: [" + price + "]\n";

    var url = $("url",xmlData).text();
    msg = msg+"URL: [" + url + "]\n";

    if (price != "" && url != "")
    {
        // got a price and a link so show them
        var ajaxOnClick = "$.ajax({ url: '/advertise/buyBoxClick/" + vendor + "/" + motor_id + "\',"
        ajaxOnClick += " success: function(msg){ window.location = '" + url +"'; } ";
        ajaxOnClick += "}); return false;";

        html = "<tr>";
        // add the logo
        if (logo != '') {
            html+= "<td align='center'><a href='" + url + "' onClick=\"" + ajaxOnClick + "\" ><img src='" + logo + "' alt='" + vendor + "' /></a></td>";
        }
        else {
            html+= "<td>&nbsp;</td>";
        }
        
        // add the vendors name
        html+= "<td><a href='" + url + "' onClick=\"" + ajaxOnClick + "\" >" + vendor + "</a></td>";

        // add the price
        html+= "<td><a href='" + url + "' onClick=\"" + ajaxOnClick + "\" >$" + CurrencyFormatted(price) + "</a></td>";

        // close the table row
        html+= "</tr>";

        // add the new row to the table and remove the hide class
        // so that the table will show up
        $("#priceList").append(html).removeClass("hide");
    }
}

