
$(document).ready( function()
{
    $('input[name="zip"]').keypress( function()
    {
        if($(this).val() != '' && $('.zip_options').css('display') == 'none')
        {
            $('.zip_options').css('display', 'block');
        }
    });
    
    f_bustype_select(document.search2009.bustype.value);
});

function submitform()
{
	var s = document.search2009.state.value;
	var z = document.search2009.zip.value;
    
	if (isCanadian(s))
    {
		document.search2009.zip.value='';
    }
	else if(document.search2009.zip.value!="")
    {
        document.search2009.state.value = "";
        document.search2009.city.value = "";
    }
    
	document.search2009.submit();
}

function isCanadian(s)
{
	var Can_states='AB,BC,MB,NB,NL,NT,NS,ON,PE,QC,SK,YT';
    return ((s=='')||(Can_states.indexOf(s) == -1)) ? (false) : (true);
}

function f_form_submit()
{
	var s = document.search2009.state.value;
	var z = document.search2009.zip.value;
    
	if (isCanadian(s))
    {
		document.search2009.zip.value='';
    }
	else if(document.search2009.zip.value!="")
    {
        document.search2009.state.value=""
        document.search2009.city.value=""
    }
}

function f_bustype_select(v)
{
    if((v!="4") && (v!="5"))
    {
        document.search2009.state.options[0].text=" - No state selected - ";
    }
    else
    {
        document.search2009.state.options[0].text="Entire US and Canada";
        f_state_change();
    }
}

function f_state_change()
{
    if(document.search2009.state.value=="")
    {
        if( (GetSelectedbustype()=="4") || (GetSelectedbustype()=="5") )
        {
            document.search2009.city.options.length=1;
            document.search2009.city.options[0] = new Option(' -- N/A -- ','');
        } 
    }
}

function GetSelectedbustype()
{
  return document.search2009.bustype.value;
}
