﻿/**** Created by: T.Brooks (3/17/2008) *****/
/*********************************************
***    Start: Jquery Code                  ***
Jquery Code: Show Hide Tabs for Calendar Search Component
Jquery Code: Mini calendar functionality for Calendar Search Component
**********************************************/

$(document).ready(function() {
    // Show & Hide EasySearch Form
    $('#EasyTab').addClass('cal_tabSelectedBasic').click(function(){
        $('#CalEasySearchForm').show();
        $('#CalAdvanceSearchForm').hide();
        $(this).removeClass('cal_tabNotSelectedBasic');
        $(this).addClass('cal_tabSelectedBasic');
        $('#AdvancedTab').removeClass('cal_tabSelectedAdvanced');
        $('#AdvancedTab').addClass('cal_tabNotSelectedAdvanced'); 
    });

    $('#AdvancedTab').click(function(){
        $('#CalAdvanceSearchForm').show();
        $('#CalEasySearchForm').hide();
        $(this).removeClass('cal_tabNotSelectedAdvanced');
        $(this).addClass('cal_tabSelectedAdvanced');
        $('#EasyTab').removeClass('cal_tabSelectedBasic');
        $('#EasyTab').addClass('cal_tabNotSelectedBasic');
    });

    $('#CalAdvanceSearchForm').hide();

    // Show & Hide current event div ("pages")
    $('#previousEventLink').click(function(){

        $('#events'+(intCurrentDiv - 1)).show();
        $('#events'+intCurrentDiv).hide();
        $(this).removeClass('cal_showButton');
        $(this).addClass('cal_hideButton');        
        $('#events'+intCurrentDiv).removeClass('cal_hideDiv');
        $('#events'+intCurrentDiv).addClass('cal_showDiv');        
        $('#nextEventLink').removeClass('cal_showButton');
        $('#nextEventLink').addClass('cal_showButton');

        intCurrentDiv--;
    
        // Check if we are at the last div, returns true if we are
        var isLast = checkLastDiv(intCurrentDiv, intTotalNumberOfDivs);
        var calculatedDivCheck = checkCurrentDiv(intCurrentDiv, intTotalNumberOfDivs);    
        // If we are not on the last div show the "next" link
        if(!isLast)
        {
            $('#nextEventLink').removeClass('cal_hideButton');
            $('#nextEventLink').addClass('cal_showButton');
        }
        
        if(calculatedDivCheck < 0 && intCurrentDiv != 0)
        {
            $(this).removeClass('cal_hideButton');
            $(this).addClass('cal_showButton');        
            $('#cal_linkPipe').removeClass('cal_hideButton');
            $('#cal_linkPipe').addClass('cal_showButton');
        }
        
        if(intCurrentDiv == 0)
        {
            $('#cal_linkPipe').removeClass('cal_showButton');
            $('#cal_linkPipe').addClass('cal_hideButton');
        }
    });//end $('#previousEventLink').click(function()
    
    /*Start: Helper functions for the current events list components*/
    // -> Returns true if we are on the last div
    function checkLastDiv(currDiv, totalDivs)
    {
        if( ((currDiv + 1) % totalDivs) == 0)
            return true;
        
        return false;
    }

    // Returns negative one if we are on any other div other than the last div
    function checkCurrentDiv(currDiv, totalDivs)
    {
        if( ((currDiv + 1) - totalDivs) < 0)
            return -1;
         
        return 0;
    }
    /*End: Helper functions for the current events list components*/

    $('#nextEventLink').click(function(){

        $('#events'+(intCurrentDiv + 1)).show();
        $('#events'+intCurrentDiv).hide();
        //$(this).removeClass('cal_hideButton');
        $(this).addClass('cal_showButton');
        $('#events'+intCurrentDiv).removeClass('cal_showDiv');
        $('#events'+intCurrentDiv).addClass('cal_hideDiv');        
        $('#previousEventLink').removeClass('cal_hideButton');
        $('#previousEventLink').addClass('cal_showButton');
        
        intCurrentDiv++;
        
        // Check if we are at the last div, returns true if we are
        var isLast = checkLastDiv(intCurrentDiv, intTotalNumberOfDivs);
        var calculatedDivCheck = checkCurrentDiv(intCurrentDiv, intTotalNumberOfDivs);
    
        // If we are on the last div do not show the "next" link
        if(isLast)
        {
            $(this).addClass('cal_hideButton');            
            $('#cal_linkPipe').removeClass('cal_showButton');
            $('#cal_linkPipe').addClass('cal_hideButton');
        }
        
        if (calculatedDivCheck < 0 && intCurrentDiv != 0)
        {
            $('#cal_linkPipe').removeClass('cal_hideButton');
            $('#cal_linkPipe').addClass('cal_showButton');
        }
        
        if(intCurrentDiv == 0)
        {
            $('#cal_linkPipe').removeClass('cal_showButton');
            $('#cal_linkPipe').addClass('cal_hideButton');
        }
    });//end $('#nextEventLink').click(function()
});//end $(document).ready(function()
/*********************************************
***    End: Jquery Code                    ***
**********************************************/


/**************************************************
START: Calendar Search Component functionality Code
***************************************************/
// Global variables: Calendar Search Component functionality 
var isUpdated = false;
var calfilterID = 0;

// Variable to store running count of the number of category buttons we have at any given time
var intTotalNumberofButtons = 0;

function updateAdvancedSearchForm()
{
    // Calendar filter ID from modal window
    calfilterID = document.calsearch_categories_form.calfilterIdFromModal.value;
     
    if(document.getElementById('CalSearch_isUpdated').value == "true")
         document.getElementById("CalSearchButtonHolder").innerHTML = "<div><div id=\"div_0\" class=\"cal_categoryButton\">All Categories</div></div>";

    if(document.calsearch_categories_form.ShowNationalEvents.checked)
        document.getElementById('CalSearch_ShowNationalEvents').value = "true";
    
    if(document.getElementById("IncludeAnyCategories").checked)
        document.getElementById('CalSearch_DisplayLogic').value = "any";
    else
        document.getElementById('CalSearch_DisplayLogic').value = "all";
        
    if(document.getElementById("AllCategories").checked)
    {
        document.getElementById("div_0").style.display = "block"; // 0 - default value for "All Categories"
        document.getElementById('CalSearch_Categories').value = 0;
        document.getElementById('CalSearch_Organization').value = 0; 
        document.getElementById('CalSearch_UserGroups').value = 0;
        document.getElementById('CalSearch_Interest').value = 0;
        document.getElementById('CalSearch_isUpdated').value = "false";
    }  
    else
    {
        if(document.calsearch_categories_form.CalFilter_AllCategoriesSelected.value == "true")
        {
            // If all checkboxes are checked (all categories are selected) we will check display
            // the All Categories button and set all the hidden fields to 0            
            document.getElementById("div_0").style.display = "block"; // 0 - default value for "All Categories"
            document.getElementById('CalSearch_Categories').value = 0;
            document.getElementById('CalSearch_Organization').value = 0; 
            document.getElementById('CalSearch_UserGroups').value = 0;
            document.getElementById('CalSearch_Interest').value = 0;
            document.getElementById('CalSearch_isUpdated').value = "false";
        }
        else
        {   
            // Build category buttons
            buildCategoryButtons(calfilterID,document.calsearch_categories_form.filtercategories,"cat_");
            buildCategoryButtons(calfilterID,document.calsearch_categories_form.filterinterests,"ints_");
            buildCategoryButtons(calfilterID,document.calsearch_categories_form.filterorgs,"orgs_");
            buildCategoryButtons(calfilterID,document.calsearch_categories_form.filterusergroups,"usergroup_");
        }
    }
}

function createAdvSearchCategoryButtons(catId, catName)
{
    // Start running count of number of buttons created
    intTotalNumberofButtons++;    
    document.getElementById("CalSearchButtonHolder").innerHTML += "<div id=\"div_"+catId+"\"><div id=\"catButtonId_"+catId+"\" class=\"cal_categoryButton\">"+catName+"</div><img id=\"remove_"+catId+"\" onclick=\"removeAdvSearchCategoryButtons("+catId+");\" src=\"/images_main/newCalendar/delete.gif\" /></div>";
}

function removeAdvSearchCategoryButtons(catId,objCategoryFormField)
{
    // Bit to aid in identifing where the updateCategoryHiddenFields() 
    // and writeCategoriesIdToHiddenFields() functions are being called from (see comments in these functions)
    // 1 - called from buildCategoryButtons(), 2 - called from removeAdvSearchCategoryButtons()
    var intFromRemoveFunctionBit = 2;
    var strCatToRemoveId = "catButtonId_"+catId;
    var strCatDivToRemove = "div_"+catId;
    var strCatId = strCatDivToRemove.substring(4);   
    // "Remove" button from component
    document.getElementById(strCatDivToRemove).style.display = "none";    
    // Decrement running count of number of buttons created
    intTotalNumberofButtons--;    
    // Update hidden category form field to reflect removed categoryId;
    updateCategoryHiddenFields(catId,objCategoryFormField,intFromRemoveFunctionBit);
}

function writeCategoriesIdToHiddenFields(strCommaListofCatIds,objCategoryFormField,intFromRemoveFunctionBit)
{
    isUpdated = document.getElementById('CalSearch_isUpdated').value;          
    // Add comma seperated list of categoryIds to CalSearch_Categories hidden advance cal search form field
    // Note: Added substr() function to remove the trailing comma at the end of the list    
    if(intFromRemoveFunctionBit != 2)
    {
        if(document.calsearch_categories_form.filtercategories == objCategoryFormField)
            document.getElementById('CalSearch_Categories').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
        
        if(document.calsearch_categories_form.filterinterests == objCategoryFormField)
            document.getElementById('CalSearch_Interest').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
        
        if(document.calsearch_categories_form.filterorgs == objCategoryFormField)
            document.getElementById('CalSearch_Organization').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
        
        if(document.calsearch_categories_form.filterusergroups == objCategoryFormField)
            document.getElementById('CalSearch_UserGroups').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
    }
    else
    {
        // If we are in this function because it was called in the chain of execution 
        // that started from the removeAdvSearchCategoryButtons() function being called
        // we need to check the name of the form field for our category form with as a string        
        if("document.calsearch_categories_form.filtercategories" == objCategoryFormField)
            document.getElementById('CalSearch_Categories').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
        
        if("document.calsearch_categories_form.filterinterests" == objCategoryFormField)
            document.getElementById('CalSearch_Interest').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
        
        if("document.calsearch_categories_form.filterorgs" == objCategoryFormField)
            document.getElementById('CalSearch_Organization').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
        
        if("document.calsearch_categories_form.filterusergroups" == objCategoryFormField)
            document.getElementById('CalSearch_UserGroups').value = strCommaListofCatIds.substr(0,strCommaListofCatIds.length - 1);    
    }
    
    // If the user has removed all the category buttons in the component and we are in "update" mode
    // for the component's buttons
    // Set the values for all hidden fields to 0, and display the button (div) that says "All Categories"
    if(intTotalNumberofButtons == 0 && (isUpdated == "true"))
    {   
        // list of buttons returns to original state (update all hidden fields) 
        document.getElementById("div_0").style.display = "block"; // 0 - default value for "All Categories"
        document.getElementById('CalSearch_Categories').value = 0;
        document.getElementById('CalSearch_Organization').value = 0; 
        document.getElementById('CalSearch_UserGroups').value = 0;
        document.getElementById('CalSearch_Interest').value = 0;
        document.getElementById('CalSearch_isUpdated').value = "false";
    }     
}

function updateCategoryHiddenFields(intCategoryidToBeRemoved,objCategoryFormField,intFromRemoveFunctionBit)
{
    var strOldListOfCategoryIds = new Array();
    var strNewListofCategories = "";
    
    if(intFromRemoveFunctionBit != 2)
    {
        if(document.calsearch_categories_form.filtercategories == objCategoryFormField)
            strOldListOfCategoryIds = document.getElementById('CalSearch_Categories').value.split(",");
        
        if(document.calsearch_categories_form.filterinterests == objCategoryFormField)
           strOldListOfCategoryIds = document.getElementById('CalSearch_Interest').value.split(",");
        
        if(document.calsearch_categories_form.filterorgs == objCategoryFormField)
            strOldListOfCategoryIds = document.getElementById('CalSearch_Organization').value.split(",");
        
        if(document.calsearch_categories_form.filterusergroups == objCategoryFormField)
            strOldListOfCategoryIds = document.getElementById('CalSearch_UserGroups').value.split(",");    
    }
    else
    {
        // If we are in this function because it was called from the removeAdvSearchCategoryButtons()
        // we need to check the name of the form field for our category form with as a string
        if("document.calsearch_categories_form.filtercategories" == objCategoryFormField)
            strOldListOfCategoryIds = document.getElementById('CalSearch_Categories').value.split(",");
        
        if("document.calsearch_categories_form.filterinterests" == objCategoryFormField)
           strOldListOfCategoryIds = document.getElementById('CalSearch_Interest').value.split(",");
        
        if("document.calsearch_categories_form.filterorgs" == objCategoryFormField)
            strOldListOfCategoryIds = document.getElementById('CalSearch_Organization').value.split(",");
        
        if("document.calsearch_categories_form.filterusergroups" == objCategoryFormField)
            strOldListOfCategoryIds = document.getElementById('CalSearch_UserGroups').value.split(",");    
    }
    
    // Make our comma seperated list into an arrary
    for(var x = 0; x < strOldListOfCategoryIds.length; x++)
    {
        if(strOldListOfCategoryIds[x] != intCategoryidToBeRemoved.toString())
            strNewListofCategories += strOldListOfCategoryIds[x] + ",";
    }

    // Update our category advance cal search hidden fields
    writeCategoriesIdToHiddenFields(strNewListofCategories,objCategoryFormField,intFromRemoveFunctionBit);
}

function updateLinkToGetCatModal()
{
    var strCategoryIDsToModals = "";
    var strInterestIDsToModals = "";
    var strUserGroupIDsToModals = "";
    var strOrgsIDsToModals = "";
    var strDisplayLogic = "";
    
    if(document.getElementById('CalSearch_Categories').value != 0)
        strCategoryIDsToModals = document.getElementById('CalSearch_Categories').value;
    
    if(document.getElementById('CalSearch_Interest').value != 0)
        strInterestIDsToModals = document.getElementById('CalSearch_Interest').value;
     
    if(document.getElementById('CalSearch_UserGroups').value != 0)
        strUserGroupIDsToModals = document.getElementById('CalSearch_UserGroups').value;
     
    if(document.getElementById('CalSearch_Organization').value != 0)
        strOrgsIDsToModals = document.getElementById('CalSearch_Organization').value;
    
    if(document.getElementById('CalSearch_DisplayLogic').value != "")
        strDisplayLogic = document.getElementById('CalSearch_DisplayLogic').value;
    
    // If ...CalSearch_isUpdated.value (hidden field to keep track if we are simply updating
    // the category list) is "true" then we need to update the link 
    if(document.getElementById('CalSearch_isUpdated').value == "true")
    {
        // Update href for link that opens category modal window: Adding variable to query string
        document.getElementById("CalSearchAdv_SelectCatLink").href = "/calendar/FilteredCalCategoriesModal.aspx?height=425&width=590&modal=true&calfilter="+calfilterID+"&isUpdate=true&currentcatIds=" + strCategoryIDsToModals +"&currentInterestIds="+strInterestIDsToModals+"&currentUserGroupIds="+strUserGroupIDsToModals+"&currentOrgsIds="+strOrgsIDsToModals+"&selectcatsradio=true&strDisplayLogic=" + strDisplayLogic;                
    }
}

function buildCategoryButtons(calfilterID,objCategoryFormField,strIdMarker)
{
   var strCategoryName = "";
   var intCategoryId = "";
   var strListOfCatIds = "";
   var strUpdatedListofCatIds = "";   
   // Bit to aid in identifing where the updateCategoryHiddenFields() 
   // and writeCategoriesIdToHiddenFields() functions are being called from (see comments in these functions)
   // 1 - called from buildCategoryButtons(), 2 - called from removeAdvSearchCategoryButtons()
   var intFromRemoveFunctionBit = 1;   
    for (var i = 0; i < objCategoryFormField.length; i++) 
   {
       if(objCategoryFormField[i].checked) 
       {
          strCategoryName = document.getElementById(strIdMarker+objCategoryFormField[i].value).value;
          intCategoryId = objCategoryFormField[i].value;          
          // Generate Category Buttons
          createAdvSearchCategoryButtons(intCategoryId, strCategoryName);                   
          // Construct comma seperated list of categoryIds
          strListOfCatIds += intCategoryId + ",";           
       }

        if(objCategoryFormField.length != 0)
        {
            // If we have categories in our list, do not display the "All Categories" button
            document.getElementById("div_0").style.display = "none";
            
            // Updated CalSearch_isUpdated hidden form field: to track if this is an updated category list, 
            // setting this field to "true" (it is string on purpose) 
            // lets us know that we now have categories selected for searching
            document.getElementById('CalSearch_isUpdated').value = "true"; 
         }
         
       // Pass comma seperated list of categoryIds to function that adds this to
       // CalSearch hidden form fields
       if(i == (objCategoryFormField.length - 1))         
            writeCategoriesIdToHiddenFields(strListOfCatIds,objCategoryFormField,intFromRemoveFunctionBit);
   }
}

function CalendarSearchComponentEasy()
{
    window.location = "/calendar/index.aspx?id=" + document.getElementById('CalendarSearchId').value + "&CalSearchKeywordsBasic=" + document.getElementById("CalSearchKeywordsBasic").value + "&calendar_search=Search";
}

function CalendarSearchComponentAdvanced()
{
    var query = "/calendar/index.aspx?id=" + document.getElementById('CalendarSearchId').value;
    query += "&CalSearchKeywordsAdvanced=" + document.getElementById("CalSearchKeywordsAdvanced").value;
    query += "&dateRadioList=" + document.getElementById('dateRadioList').checked;    
    query += "&CalSearchDateDropDown=" + document.getElementById('CalSearchDateDropDown').value;
    query += "&CalSearchStartDate=" + document.getElementById('CalSearchStartDate').value;
    query += "&CalSearchEndDate=" + document.getElementById('CalSearchEndDate').value;
    query += "&CalSearchTimeFrom=" + document.getElementById('CalSearchTimeFrom').value;
    query += "&CalSearchTimeFromAMPM=" + document.getElementById('CalSearchTimeFromAMPM').value;
    query += "&CalSearchTimeTo=" + document.getElementById('CalSearchTimeTo').value;
    query += "&CalSearchTimeToAMPM=" + document.getElementById('CalSearchTimeToAMPM').value;
    query += "&CalSearchCompDaysOfWeekSu=" + document.getElementById('CalSearchCompDaysOfWeekSu').checked;
    query += "&CalSearchCompDaysOfWeekM=" + document.getElementById('CalSearchCompDaysOfWeekM').checked;
    query += "&CalSearchCompDaysOfWeekTu=" + document.getElementById('CalSearchCompDaysOfWeekTu').checked;
    query += "&CalSearchCompDaysOfWeekW=" + document.getElementById('CalSearchCompDaysOfWeekW').checked;
    query += "&CalSearchCompDaysOfWeekTh=" + document.getElementById('CalSearchCompDaysOfWeekTh').checked;
    query += "&CalSearchCompDaysOfWeekF=" + document.getElementById('CalSearchCompDaysOfWeekF').checked;
    query += "&CalSearchCompDaysOfWeekSa=" + document.getElementById('CalSearchCompDaysOfWeekSa').checked;
    query += "&CalSearch_Categories=" + document.getElementById('CalSearch_Categories').value;
    query += "&CalSearch_Organization=" + document.getElementById('CalSearch_Organization').value;
    query += "&CalSearch_UserGroups=" + document.getElementById('CalSearch_UserGroups').value;
    query += "&CalSearch_Interest=" + document.getElementById('CalSearch_Interest').value;
    query += "&CalSearch_isUpdate=" + document.getElementById('CalSearch_isUpdate').value; 
    query += "&CalSearch_ShowNationalEvents=" + document.getElementById('CalSearch_ShowNationalEvents').value;
    query += "&CalSearch_DisplayLogic=" + document.getElementById('CalSearch_DisplayLogic').value;
    query += "&CalSearchLocation=" + document.getElementById('CalSearchLocation').value + "&adv_calendar_search=Search";
    setTimeout("doSearch('" + query + "')", 25);
}
function doSearch(query)
{
    window.location = query;
}
/************************************************
END: Calendar Search Component functionality Code
*************************************************/


function MailingList()
{
    var totCheckBoxes = $get('totCheckBoxes').value;
    var Checked = '';
    for ( var i = 0; i < totCheckBoxes; i++ ) 
    {
        if ( $get('iChk' + i).checked )
            Checked += '&iChk' + i + '=' + $get('iChk' + i).value;
    } 
    if(EmailValidate($get('Email').value))   
        window.location = 'mailing_list.html?Email=' + $get('Email').value + '&totCheckBoxes=' + totCheckBoxes + Checked;
    else
        alert('Invalid Email Address');
} 
function EmailValidate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      //alert('Invalid Email Address');
      return false;
   }
   return true;
}

function JobSearch(){window.location='career_search_job_result.html?keyword=' + $get('keyword').value + '&searchType=' + $get('searchType').value;} 
function ProdSearch(){window.location = 'product_search_results.html?txtSearch=' + $get('txtSearch').value + '&selSearch=' + $get('selSearch').value + '&category=' + $get('category').value;}
function SpeakerSearch(){window.location = 'speakers_search_results.html?bread=0&keyword=' + $get('keyword').value + '&topics=' + $get('topics').value + '&fee=' + $get('fee').value;}
function NWP2(){window.location = 'nwp_results.html?name=' + $get('name').value + '&community=' + $get('community').value;}
function GAEventSearch2(){window.location = 'ga_events_results.html?bread=0&keyword=' + $get('keyword').value + '&topic=' + $get('topic').value + '&day=' + $get('day').value;}
function GAEventSearch1(){window.location = 'ga_speakers_results.html?bread=0&keyword=' + $get('keyword').value + '&topic=' + $get('topic').value;}
function ZipSearch2()
{
	// Validation added for case 63086
	var zip = $get('zipcode').value;

	if(zip.search(/^([0-9]{5}|[A-Za-z0-9]{6})$/) < 0)
	{
		alert('Please enter a valid 5-digit U.S. zip code, or 6-character Canadian \npostal code to find the closest North American Jewish Federation.');
		return;
	}
	else
		window.location = 'ir_zipsearch.html?zipcode=' + zip;
}

function frmStudySearch2(){window.location = 'jdbstudy_search_results.html?bread=0&formID=' + $get('formID').value + '&keyword=' + $get('keyword').value + '&locations=' + $get('locations1').value + '&comStudy=' + $get('comStudy2').value;}
function CandleSearch2(){window.location = 'candle_search_results.html?zipcode=' + $get('zipcode').value;}
function frmAJDSearch2(){window.location = 'adultjewishlearning_results.html?keywords=' + $get('keywords').value + '&structure=' + $get('structure').value + '&population=' + $get('population').value + '&venue=' + $get('venue').value + '&fundedby=' + $get('fundedby').value + '&cost=' + $get('cost').value;}
function SchoolSearch2(){window.location = 'bjela_school_results.html?keywords=' + $get('keywords').value + '&schoolType=' + $get('schoolType').value + '&ideology=' + $get('ideology').value + '&region=' + $get('region').value + '&zipCode=' + $get('zipCode').value;}
function WashConfSearch2(){window.location = 'washconf_speakers_search_results.html?bread=0&keywords=' + $get('keywords').value + '&topics=' + $get('topics').value;}
function frmYldSearch2(){window.location = 'yld_search_results.html?bread=0&genderSearch=' + $get('genderSearch').value + '&txtSearch=' + $get('txtSearch').value;}

function IRSearch2()
{
    var loc = "/IR/Search.aspx";
    var queryString = "", searchType = "";
    
    if ($get("KeywordBox") && $get("KeywordBox").value != "")
        searchType = "KeywordBox";
    else if ($get("ctl00_ContentPlaceHolder1_KeywordBox") && $get("ctl00_ContentPlaceHolder1_KeywordBox").value != "")
        searchType = "ctl00_ContentPlaceHolder1_KeywordBox";
    if (searchType != "")
        queryString += "?keywords=" + $get(searchType).value;        
    searchType = "";
    if ($get("ZipCodeBox") && $get("ZipCodeBox").value != "")
        searchType = "ZipCodeBox";
    else if ($get("ctl00_ContentPlaceHolder1_ZipCodeBox") && $get("ctl00_ContentPlaceHolder1_ZipCodeBox").value != "")
        searchType = "ctl00_ContentPlaceHolder1_ZipCodeBox";
    if (searchType != "")
    {
        queryString += (queryString != "" ? "&" : "?");
        queryString += "zipCode=" + $get(searchType).value;
    }    
    searchType = "";
    if ($get("CategoryList") && $get("CategoryList").value != 0)
        searchType = "CategoryList";
    else if ($get("ctl00_ContentPlaceHolder1_CategoryList") && $get("ctl00_ContentPlaceHolder1_CategoryList").value != 0)
        searchType = "ctl00_ContentPlaceHolder1_CategoryList";
    if (searchType != "")
    {
        queryString += (queryString != "" ? "&" : "?");
        queryString += "category=" + $get(searchType).value;
    }    
    searchType = "";
    if ($get("SubCategoryList") && $get("SubCategoryList").value != 0)
        searchType = "SubCategoryList";
    else if ($get("ctl00_ContentPlaceHolder1_SubCategoryList") && $get("ctl00_ContentPlaceHolder1_SubCategoryList").value != 0)
        searchType = "ctl00_ContentPlaceHolder1_SubCategoryList";
    if (searchType != "")
    {
        queryString += (queryString != "" ? "&" : "?");
        queryString += "subcategory=" + $get(searchType).value;
    }    
    searchType = "";
    if ($get("RegionList") && $get("RegionList").value != 0)
        searchType = "RegionList";
    else if ($get("ctl00_ContentPlaceHolder1_RegionList") && $get("ctl00_ContentPlaceHolder1_RegionList").value != 0)
        searchType = "ctl00_ContentPlaceHolder1_RegionList";
    if (searchType != "")
    {
        queryString += (queryString != "" ? "&" : "?");
        queryString += "region=" + $get(searchType).value;
    }
    window.location = loc + queryString;
}

function VolunteerSearch()
{
    var theForm = document.forms['aspnetForm'];
    if (!theForm)
        theForm = document.aspnetForm;
    
//    if(theForm.__VIEWSTATE)
//        alert('theForm.__VIEWSTATE');
//    if(theForm.__VIEWSTATE.name)
//        alert('theForm.__VIEWSTATE.name');
        
    //alert(theForm.action);
    
    theForm.action = '/IR/VolunteerSearch.aspx';
    theForm.__VIEWSTATE.name = 'NOVIEWSTATE';
    theForm.submit();
    
    //alert(theForm.action);
    
//    function __doPostBack(eventTarget, eventArgument) {
//        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
//            theForm.__EVENTTARGET.value = eventTarget;
//            theForm.__EVENTARGUMENT.value = eventArgument;
//            theForm.submit();
//        }
//    }


//    alert(document.forms[0].action);
//    document.forms[0].action = '/IR/VolunteerSearch.aspx';
//    document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';

    //alert("Need to implement search yet.");
}

function SynSearch2(){window.location = 'synagogue_search_results.html?zipcode=' + $get('zipcode').value + '&city=' + $get('city').value + '&state=' + $get('state').value + '&radius=' + $get('radius').value;}
function OMPProgramSearch2(){window.location = '/OMP/search_results.html?ctid=' + $get('ctid').value + '&keyword=' + $get('keyword').value + '&category=' + $get('category').value;}
function OMPSituationalSearch2(){window.location = '/OMP/search_results.html?ctid=' + $get('ctid').value + '&keyword=' + $get('keyword').value;}
function StaffSearch2(){window.location = 'staff_search_results.html?txtSearch=' + $get('txtSearch').value + '&selDivision=' + $get('selDivision').value + '&selDepartment=' + $get('selDepartment').value + '&selRegion=' + $get('selRegion').value;}
function MissionSearch(){window.location = 'travel_missionfinder.html?selDestination=' + $get('selDestination').value + '&dateradio=' + $get('dateradio').value + '&iDuration=' + $get('iDuration').value + '&startDate=' + $get('startDate').value + '&endDate=' + $get('endDate').value;}
function JewishFinder(){window.location = 'ir_region.html?id=' + $get('id').value;}
function pollSubmit(val)
{
    var componentid = val;
    //$get("pollId").value;
    var answer = 0;
    for ( i = 1; i <= 8; i++ )
    {        
        if ( $get('poll_' + componentid + "_" + i).checked )
        {
            answer = $get('poll_' + componentid + "_" + i).value;
            break;
        }
    }
    window.location = ("poll_submit.ashx?id=" + componentid + "&poll_" + componentid + "=" + answer + "&referrer=" + location.href);
}

//funtions for Community Directory search form
function LoadSubCategories(categories)
{
    if (categories.value);
        Ujc.Public.ComponentService.GetSubCategories(categories.value, GetSubCategories_OnSuccess, OnWebmethodFailed, categories.value);
}
function GetSubCategories_OnSuccess(result, catId)
{
    var subcatlist = $get('SubCategoryList');
    if (!subcatlist)
        subcatlist = $get('ctl00_ContentPlaceHolder1_SubCategoryList');
    
    if (subcatlist)
    {
        var len = subcatlist.options.length;
        for (var i = 1; i < len; i++)
        {
            subcatlist.options[1] = null;
        }
        if (Number(catId) > 0)
        {
            for (var i = 0; i < result.length; i++)
            {
                var subcat = result[i];            
                subcatlist.options[i+1] = new Option ( subcat.Name, subcat.Id );
            }
        }
    }
}
function OnWebmethodFailed(error) 
{    
    alert('OnWebmethodFailed(): ' + error.get_message());
    
//    if ( error.get_message().indexOf('DELETE statement conflicted with TABLE REFERENCE constraint') > -1 )
//    {
//        var alertManager = new AlertManager('../modal/');
//        var yesno = alertManager.Alert('Alert', 'All content (pages, components, assets) assigned to this section now have no section assigned.<br> All Subsections must be manually removed before the section can be completely removed.  <br>All flash content must have their section manually re-assigned before this section can be completely removed.', 'Ok',155,360);
//        
////        alert('You must first delete all content associated with this section before deleting this section.');
//    }
//    else if ( error.get_message().indexOf('FK_SubSections_FederationSection') > -1 )
//    {        
//        var alertManager = new AlertManager('../modal/');
//        var yesno = alertManager.Alert('Alert', 'All content (pages, components, assets) assigned to this section now have no section assigned.<br>  All Subsections must be manually removed before the section can be completely removed.  <br>All flash content must have their section manually re-assigned before this section can be completely removed.', 'Ok',155,360);
//    }
//    else
//    {
//        alert('OnWebmethodFailed(): ' + error.get_message());
//    }
}

/***********************************************************************/
/*********************For IR Search Component **************************/
/***********************************************************************/
function switchDiv(type)
{
    if(type=='adv')
    {
        document.getElementById("SearchAdv").style.display='none';
        document.getElementById("advSearch").style.display='';
        document.getElementById("SearchBac").style.display='';
        document.getElementById("IRHorizontalRow").style.display='';
    }
    else
    {
        document.getElementById("SearchAdv").style.display='';
        document.getElementById("advSearch").style.display='none';
        document.getElementById("SearchBac").style.display='none';
        document.getElementById("IRHorizontalRow").style.display='none';
    }
}

function CatTabSwitch(type)
{ 
   
    if ( type == 'nat' )
    {
        document.getElementById("LocalIRSearchCategories").style.display='none';
        document.getElementById("NationalIRSearchCategories").style.display='';
        document.getElementById("LocalCatTab").className = "TabSelectOff";
        document.getElementById("NatCatTab").className = "TabSelectOn";
    }
    else
    {
        document.getElementById("LocalIRSearchCategories").style.display='';
        document.getElementById("NationalIRSearchCategories").style.display='none';
        document.getElementById("LocalCatTab").className = "TabSelectOn";
        document.getElementById("NatCatTab").className = "TabSelectOff";
    }
}

function RegionTabSwitch(type)
{	        
    if ( type == 'nat' )
    {
        document.getElementById("LocalIRSearchRegions").style.display = 'none';
        document.getElementById("NatIRSearchRegions").style.display='';
        document.getElementById("LocalRegionTab").className = 'TabSelectOff';
        document.getElementById("NatRegionTab").className='TabSelectOn';
    }
    else
    {
        document.getElementById("LocalIRSearchRegions").style.display = '';
        document.getElementById("NatIRSearchRegions").style.display='none';
        document.getElementById("LocalRegionTab").className = 'TabSelectOn';
        document.getElementById("NatRegionTab").className='TabSelectOff';
    }
}
