function validateNarrowTruck1()
{
    var returnVal = 1;

    returnVal &= CheckDropDown("Used");
    returnVal &= CheckDropDown("LiftCapacity");
    returnVal &= CheckDropDown("LiftHeight");

    return !!returnVal;
}

function validateNarrowTruck2()
{
    var returnVal = 1;

    returnVal &= CheckText("Name");
    returnVal &= CheckText("Company");
    returnVal &= CheckText("Address");
    returnVal &= CheckText("City");
    returnVal &= CheckText("Zip");
    returnVal &= CheckText("Email");
    
    if ($("#Region")[0].value == "Mexico")
    {
        returnVal &=- CheckText("Phone");
    }
    else
    {
        returnVal &= CheckPhone("AreaCode", "PhonePrefix", "PhoneLine", "PhoneError");
    }

    return !!returnVal;
}

function validateRental1()
{
    var returnVal = 1;

    returnVal &= CheckDropDown("WhenNeeded");
    returnVal &= CheckDropDown("TimeFrame");
    returnVal &= CheckDropDown("FuelType");

    return !!returnVal;
}

function validateParts1()
{
    var returnVal = 1;
    returnVal &= CheckDropDown("Manufacturer");
    
    return !!returnVal;
}

function validateParts()
{
    var returnVal = 1;

    returnVal &= CheckText("Name");
    returnVal &= CheckText("Company");
    returnVal &= CheckText("City");
    returnVal &= CheckText("Zip");
    returnVal &= CheckText("Email");
    
    if ($("#Region")[0].value == "Mexico")
    {
        returnVal &=- CheckText("Phone");
    }
    else
    {
        returnVal &= CheckPhone("AreaCode", "PhonePrefix", "PhoneLine", "PhoneError");
    }

    return !!returnVal;
}

function validateCertification()
{
    var returnVal = 1;

    returnVal &= CheckText("Name");
    returnVal &= CheckText("Company");
    returnVal &= CheckText("Address");
    returnVal &= CheckText("City");
    returnVal &= CheckText("Zip");
    returnVal &= CheckText("Email");
    
    if ($("#Region")[0].value == "Mexico")
    {
        returnVal &=- CheckText("Phone");
    }
    else
    {
        returnVal &= CheckPhone("AreaCode", "PhonePrefix", "PhoneLine", "PhoneError");
    }
    
    return !!returnVal;
}

function validateBF1()
{
    var returnVal = 1;
    returnVal &= CheckDropDown("type");
    returnVal &= CheckText("Make");
    returnVal &= CheckDropDown("Year");
    
    return !!returnVal;
}

function validateBMFform2()
{
    try
    {
        var returnVal = 1;
        returnVal &= CheckRatio("EngineType");
        returnVal &= CheckRatio("MastType");
        returnVal &= CheckRatio("SideShift");
        returnVal &= CheckRatio("LiftHeight");
        returnVal &= CheckDropDown("capacity");
        returnVal &= CheckRatio("Condition");
        
        return !!returnVal;
    }
    catch (err)
    {
        return true;
    }
}

function validateBFform3()
{
    try
    {
        var returnVal = 1;
        returnVal &= CheckText("Name");
        returnVal &= CheckText("Company");
        returnVal &= CheckText("Address");
        returnVal &= CheckText("City");
        returnVal &= CheckText("Zip");
        returnVal &= CheckPhone("AreaCode", "PhonePrefix", "PhoneLine", "PhoneError");
        returnVal &= CheckText("Email");
        
        return !!returnVal;
    }
    catch (err)
    {
        alert(err);
        return false;
    }
}

function CheckText(id)
{
    if ($("#" + id)[0].value.length == 0)
    {
        $("#" + id + "Error")[0].style.visibility = "visible";
        return 0;
    }
    else
    {
        $("#" + id + "Error")[0].style.visibility = "hidden";
        return 1;
    }
}

function CheckDropDown(id)
{
    if ($("#" + id)[0].selectedIndex == 0)
    {
        $("#" + id + "Error")[0].style.visibility = "visible";
        return 0;
    }
    else
    {
        $("#" + id + "Error")[0].style.visibility = "hidden";
        return 1;
    }
}

function CheckRatio(id)
{
    if ($("input[name='" + id + "']:checked").val() == undefined)
    {
        $("#" + id + "Error")[0].style.visibility = "visible";
        $("#" + id + "Error")[0].style.display = "inline";
        return 0;
    }
    else
    {
        $("#" + id + "Error")[0].style.visibility = "hidden";
        $("#" + id + "Error")[0].style.display = "none";
        return 1;
    }
} 

function CheckPhone(areaCodeId, prefixId, lineId, errorId)
{
    if ($("#" + areaCodeId)[0].value.length == 0 ||
        $("#" + prefixId)[0].value.length == 0 ||
        $("#" + lineId)[0].value.length == 0)
    {
        $("#" + errorId)[0].style.visibility = "visible";
        return 0;
    }
    else
    {
        $("#" + errorId)[0].style.visibility = "hidden";
        return 1;
    }
}
