﻿
function checkForDouble1(selectBox) {
    var otherSelected;
    otherSelected = 0;

    if (selectBox.selectedIndex != 0) {
        if (window.document.forms[0].industrial1.selectedIndex != 0) {
            otherSelected++;
        }
        if (window.document.forms[0].service1.selectedIndex != 0) {
            otherSelected++;
        }
        if (window.document.forms[0].motive1.selectedIndex != 0) {
            otherSelected++;
        }
        if (window.document.forms[0].construction1.selectedIndex != 0) {
            otherSelected++;
        }
    }
    if (otherSelected > 1) {
        alert("You can only choose one job type.");
        window.document.forms[0].motive1.selectedIndex = 0;
        window.document.forms[0].industrial1.selectedIndex = 0;
        window.document.forms[0].service1.selectedIndex = 0;
        window.document.forms[0].construction1.selectedIndex = 0;
    }
}


function checkForDouble(selectBox) {
    var otherSelected;
    otherSelected = 0;

    if (selectBox.selectedIndex != 0) {
        if (window.document.forms[0].industrial.selectedIndex != 0) {
            otherSelected++;
        }
        if (window.document.forms[0].service.selectedIndex != 0) {
            otherSelected++;
        }
        if (window.document.forms[0].motive.selectedIndex != 0) {
            otherSelected++;
        }
        if (window.document.forms[0].construction.selectedIndex != 0) {
            otherSelected++;
        }
    }
    if (otherSelected > 1) {
        alert("You can only choose one job type");
        window.document.forms[0].motive.selectedIndex = 0;
        window.document.forms[0].industrial.selectedIndex = 0;
        window.document.forms[0].service.selectedIndex = 0;
        window.document.forms[0].construction.selectedIndex = 0;
    }
}

$(document).ready(function () {
    // endable label clicking to check off checkbox
    $('.applicantEdit .checkboxesForRegions label').each(function () {
        var checkbox = $(this).siblings('input[type="checkbox"]');
        $(this).attr('for', checkbox.attr('id'));
    });

    $('input[watermark]').each(function () {
        var watermark = $(this).attr('watermark');
        $(this).watermark(watermark);
    });

    $('#siteSearchForm').submit(function () {
        var searchStr = $('#search-box').val();
        if (searchStr) {
            var url = 'http://yboss.yahooapis.com/ysearch/limitedweb';
            

            var params = [];
            params.push('format=xml');
            params.push('sites=' + $('#search-button').attr('siteurl'));
            params.push('q=' + searchStr);
            
            params = params.join('&');

            $('#siteSearchUrl').val(url + '?' + params);
            $('#searchText').val(searchStr);
            return true;
        }
        else {
            $('#search-box').focus();
            return false;
        }
    });

    $('#searchedText').each(function () {
        $('#search-box').val($(this).val());
    });

    $('#PageSearchLink').live('click', function () {
        var searchText = $('#searchedText').val()
        var searchUrl = $(this).siblings('#searchUrl').val();
        var params = [];
        params.push('format=xml');
        params.push('sites=' + $('#search-button').attr('siteurl'));
        params.push('q=' + searchText);
        
        params = params.join('&');

        searchUrl = (searchUrl + '&' + params);
        $.ajax({
            url: '/Resources/SiteSearch',
            type: 'GET',
            data: { searchtext: searchText, siteSearchUrl: searchUrl },
            success: function (content) {
                $('#serpContentDiv').html($(content).find('#serpContentDiv').html());
            }
        });
    });
});
