﻿// Brand Page Search Validation
function validatePartNumberSearch()
{
    var partNumberTextBox = document.getElementById("PartNumber");
    
    trimSpaces(partNumberTextBox);
    
    if(partNumberTextBox.value == null || partNumberTextBox.value == "")
    {
        var errorMessage = "The following errors occured while trying to process your search: \n\nPart Number was entered incorrectly.";
        alert(errorMessage);
    }
    else
    {
        var brandPageIDTextBox = document.getElementById("BrandPageID");
        var newLocation = "/Brands/SearchResults.aspx?BrandPageID=" + brandPageIDTextBox.value + "&PartNumber=" + partNumberTextBox.value;
	    window.location = wwwRootSearch + newLocation;
    }
}

function trimSpaces(formField)
{
	formField.value = formField.value.replace(/\s/g, "");
}

// Flags fields with yellow background and red border
function flagFormField(formField)
{
	formField.style["border"] = "1px solid red";
	formField.style["background"] = "#FFFCCB";
}

// Clears alert style from form fields
function resetFormField(formField)
{
	if( formField.type != "checkbox" )
	{
		formField.style["border"] = "1px solid #ccc";
		formField.style["background"] = "#fff";
	}
}

function partNumberSearchOnKeyDown(e)
{
    //handle the enter key on the email registration textbox
    var key;

    if(window.event)
    {
         key = window.event.keyCode;    //IE
    }
    else
    {
         key = e.which;                 //firefox
    }
    
    if (key == 13)
    {
        validatePartNumberSearch();
    }
    return true;

}
