﻿// JScript File

function SFinderCheckZip()
{
   document.SFinderInputForm.advanced.value = 0;
   SFinderRunCheck(); 
}

function SFinderRunCheck()
{
    var zip;
    var province;
    var provCheck = 0;
    
    try
    {
        zip = document.SFinderInputForm["txtZip"].value;
    }
    catch(e)
    {
        zip = "";
        
        try
        {
            province = document.SFinderInputForm.province.options[document.SFinderInputForm.province.selectedIndex].value;            
            if (province.length > 0)
            {
                provCheck = 1;
            }   
        }
        catch(e)
        {
            provCheck = 0; 
        }        
    }
    if (sfinderDisplayZip)
    {
    		stringEmpty = "";
        if (SFinderValidateZip(zip) || provCheck == 1 || strCmp(zip, stringEmpty) == 0)
        {
            document.SFinderInputForm.submit();   
        }
        else
        {
            alert(sfinderZipMessage);
        }
    }
    else
    {
        document.SFinderInputForm.submit(); 
    }
}

function SFinderValidateZip(zip)
{
    if (zip.length == 0 || zip.length > 12)
        return false;
    
    if (sfinderZipExpress.test(zip))
        return true;
    else
        return false;
}

function SFinderAdvancedSearch()
{
    document.SFinderInputForm.advanced.value = 1;
    SFinderRunCheck();
}

//function for forcing form submission
function SFinderCheckEnter(e)
{
    var characterCode
    if(e && e.which)
    {
        e = e
        characterCode = e.which
    }
    else
    {
        e = event
        characterCode = e.keyCode
    }	 
    if(characterCode == 13)
    {
        SFinderCheckZip();
        return false
    }
    return true	
}

function strCmp(str1, str2)
{
		if ( str1 < str2 ) {
        return -1;
    }
    else if ( str1 > str2 ) {
        return 1;
    }
    else {
        return 0;
    }
}