﻿/// <reference path="jquery-1.3.2.min.js" />

//************************************************************************************
//NEWUSERREGISTRATION PAGE BEGINS
//************************************************************************************

//validates the email provided by user
function CustValidateEmail(source, args) {
    args.IsValid = ValidateEmail(jQuery.trim(args.Value));
}
function ValidateEmail(email) {
    emailRe = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
	if(emailRe.test(email))
	{
	    return true;
	}
	else
	{
	    return false;
	}                  
}

//************************************************************************************
//NEWUSERREGISTRATION PAGE ENDS
//************************************************************************************

//*******************************/
//* Default Portal Page Scripts */
//*******************************/
var DefaultSearchText = 'Enter keyword and click GO...';
var SujectListCache;
var SearchValue = "";
var SearchValueCache = "";
var hrefRedir;
var ctrlPrefix = "ctl00_Main_";
var btnClickSet = false;
var BlackList = jQuery.makeArray(new Array("about ", "after ", "am ", "and ", "any ", "ask ", "at ", "be  ", "because ", "between ", "but ", "can ", "city of bellevue ", "cob ", "complaint ", "concern ", "could ", "curious ", "did ", "didn't ", "few ", "find a ", "find ", "for ", "from ", "get ", "give ", "had ", "has ", "have ", "how ", "i ", "if ", " in ", " is ", "information ", "inquiry ", "issue ", " it ", "less ", "many ", "may ", "me ", "more ", "my ", "need a ", "need ", "of ", "often ", "one ", "or ", "other ", "our ", "please ", "problem ", "question ", "report ", "request ", "should ", "some ", "that ", "the ", "this ", "there ", "these ", "they ", "those ", "to ", "us ", "want a ", "want ", "was ", "with ", "we ", "were ", "would ", "what ", "when ", "where ", "which ", "who ", "why ", "wonder ", "you ", "your "));
function GetMeSomeSubjects(evt) {
    var cEvent = evt || window.event;
    var ctrl = cEvent.target || cEvent.srcElement;
    if (cEvent.keyCode == 13) {            
        GetSubmitAction();
    }
    SearchValue = $(ctrl).val().toLowerCase().replace(DefaultSearchText.toLowerCase(), '');    
    
    $('#' + ctrlPrefix + 'hidSubject').val('');
    $(BlackList).each(function() {
        SearchValue = SearchValue.toLowerCase().replace(this, '');
    });
    if (SearchValue.length > 2 || SearchValueCache != "") {
        if (SujectListCache == null ||
                $(SujectListCache).is(':empty') ||
                    (
                        (SearchValue.length > SearchValueCache.length &&
                            SearchValue.substr(0, SearchValueCache.length) != SearchValueCache) ||
                         (SearchValue.length < SearchValueCache.length &&
                            SearchValueCache.substr(0, SearchValue.length) != SearchValue) ||
                         (SearchValue.length == SearchValueCache.length &&
                            SearchValue != SearchValueCache)
                    )
            ) {
            $.post(location.pathname.substr(0, location.pathname.indexOf("/", 1)) + '/TopicList.asmx/QueryTopics', { queryText: SearchValue }, function(data) {
                if (document.implementation && document.implementation.createDocument) {
                    var parser = new DOMParser();
                    objDocument = parser.parseFromString(data, "text/xml");
                } else if (typeof ActiveXObject != 'undefined') {
                    var progIDs = ['Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.3.0'];
                    for (var i = 0; i < progIDs.length; i++) {
                        try {
                            objDocument = new ActiveXObject(progIDs[i]);
                            i = progIDs.length;
                        }
                        catch (ex) {
                        }
                    }
                    try {
                        objDocument.async = "false";
                        objDocument.loadXML(data);
                    }
                    catch (e) {
                    }
                }
                SujectListCache = objDocument;
                ProcessSubjectList();
            }, 'text');
        } else {
            ProcessSubjectList();
        }
        if (SearchValue != "") {
            SearchValueCache = SearchValue;
        }
    } 
    if (SearchValue == "") {
        $('#ddlSubjectList').hide('fast');
    }                       
}
function ProcessSubjectList() {
    var ii = 0;
    $('#ddlSubjectList').empty();
    $('subjectTree', SujectListCache).find('subject').each(function() {
        if (ii >= 10) {
            return;
        }
        if ($(this).attr('title').toLowerCase().indexOf(SearchValue) > -1) {
            var firstFound = $(this).attr('title').toLowerCase().indexOf(SearchValue);
            var foundText = $(this).attr('title').substring(firstFound, firstFound + SearchValue.length);
            var titleVal = $(this).attr('title').replace(foundText, "<strong>" + foundText + "</strong>");
            if ($('#ddlSubjectList').html().indexOf('>' + titleVal + '<') == -1) {
                $('#ddlSubjectList').append('<li><a href="javascript:void(0)" onfocus="highlightMe(this);" onclick="SelectMe(this, \'' + $(this).attr('subjectextid') + '\');">' + titleVal + '</a></li>');
                ii++;
            }
        }
    });
    if ($('#ddlSubjectList > li').length == 0) {
        $('#ddlSubjectList').hide();
    } else {
        $('#ddlSubjectList').show();
    }
    $('#ddlSubjectList > li > a').keydown(chkListKey);	
}
function SelectMe(ctrl, extid) {
    var regE = /\<[\/]?strong\>/ig;
    $('#' + ctrlPrefix + 'txtFindSubject').val(ctrl.innerHTML.replace('&amp;', '&').replace(regE, ''));
    $('#' + ctrlPrefix + 'hidSubject').val(extid);    
    $('#ddlSubjectList').hide('fast');
    $('#' + ctrlPrefix + 'btnSubmit').click();
}
function GetSubmitAction() {
    $('#ddlSubjectList').hide('fast');
    $('#' + ctrlPrefix + 'txtFindSubject').val($('#' + ctrlPrefix + 'txtFindSubject').val().toLowerCase().replace(DefaultSearchText.toLowerCase(), '')); 
    if ($('#' + ctrlPrefix + 'txtFindSubject').val() == "") {
        $("#TextDisplay").html('<a href="javascript:void(0);" onclick="$(\'#TextDisplay\').slideUp(\'fast\')" id="TextDisplayClose">X</a><strong>You must enter/select keywords relating to your request before continuing.</strong><div class="clearFloat"></div>').slideDown('fast');
        return;
    } else {
        SearchValue = $('#' + ctrlPrefix + 'txtFindSubject').val();
    }    
    if ($('#' + ctrlPrefix + 'hidSubject').val() == "" && $('#' + ctrlPrefix + 'txtFindSubject').val() != "") {        
        $('subjectTree', SujectListCache).find('subject').each(function() {
            if (jQuery.trim($(this).attr('title')).toLowerCase().replace(/\s{2,}/g, ' ') == jQuery.trim(SearchValue).toLowerCase().replace(/\s{2,}/g, ' ')) {
                $('#' + ctrlPrefix + 'hidSubject').val($(this).attr('subjectextid'));                
            }
        });
    }
    var ServicePath = '../TopicList.asmx/GetSubjectAction';

    if (window.opener && $(window.opener.document).find('#citzn_queuedepartmentid_ledit')) {
        ServicePath = 'TopicList.asmx/GetSubjectAction';
    }

    $.post(ServicePath, { subjectExtId: $('#' + ctrlPrefix + 'hidSubject').val() }, function(data) {
        if (document.implementation && document.implementation.createDocument) {
            var parser = new DOMParser();
            objDocument = parser.parseFromString(data, "text/xml");
        } else if (typeof ActiveXObject != 'undefined') {
            var progIDs = ['Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.3.0'];
            for (var i = 0; i < progIDs.length; i++) {
                try {
                    objDocument = new ActiveXObject(progIDs[i]);
                    i = progIDs.length;
                }
                catch (ex) {
                }
            }
            try {
                objDocument.async = "false";
                objDocument.loadXML(data);
            }
            catch (e) {
            }
        }
        var ii = 0;
        var subjectID = $('subjectData', objDocument).find('subject:first').attr('subjectid');
        var departmentId = $('subjectData', objDocument).find('subject:first').attr('departmentid');
        var newLocation = '../Portal_Pages/CustomerInfo.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
        var formAction = $('subjectData', objDocument).find('subject:first').attr('action');
        var actionId = $('subjectData', objDocument).find('subject:first').attr('actionId');
        if (formAction == "Display Text") {
            var text = $('subjectData', objDocument).find('subject:first').attr('text');
            $("#TextDisplay").html('<a href="javascript:void(0);" onclick="$(\'#TextDisplay\').slideUp(\'fast\')" id="TextDisplayClose">X</a><strong>' + text + '</strong><div class="clearFloat"></div>').slideDown('fast');
        } else if (formAction == "Redirect to Url") {
            var url = $('subjectData', objDocument).find('subject:first').attr('url');
            var text = $('subjectData', objDocument).find('subject:first').attr('text');
            $("#TextDisplay").html('<a href="javascript:void(0);" onclick="$(\'#TextDisplay\').slideUp(\'fast\'); clearTimeout(hrefRedir);" id="TextDisplayClose">X</a>Based on your selected subject, you will be automatically redirected in 10 seconds to a web page or site that should be able to assist you. ' + text + ' If you are not automatically redirected, <a href="' + url + '">click to visit manually</a>.  To cancel and stay on this site, <a href="javascript:void(0)" onclick="$(\'#TextDisplay\').slideUp(\'fast\'); clearTimeout(hrefRedir);">click to cancel</a> and try your search again.').slideDown('fast');
            hrefRedir = setTimeout(function() { location.href = url; }, 10000);
        } else if (formAction && actionId) {
            if (window.opener && $(window.opener.document).find('#citzn_queuedepartmentid_ledit')) {
                var subjectText = $('subjectData', objDocument).find('subject:first').attr('subjecttext');
                var departmentText = $('subjectData', objDocument).find('subject:first').attr('departmenttext');
                $(window.opener.document).find('#citzn_selectedsubject').val($('#txtFindSubject').val());
                $(window.opener.document).find('#subjectid_ledit').val(subjectText).click().focus().blur();
                $(window.opener.document).find('#citzn_departmentid_ledit').val(departmentText).click().focus().blur();
                window.close();
            } else {
                switch (parseInt(actionId)) {
                    case 10:
                        newLocation = '../Portal_Pages/Location.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 11:
                        newLocation = '../Portal_Pages/LocationNR.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 4:
                        newLocation = '../Portal_Pages/PublicRecordsCityCodes.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 2:
                        newLocation = '../Portal_Pages/CustomerInfo.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 8:
                        newLocation = '../Portal_Pages/CustomerLocation.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 9:
                        newLocation = '../Portal_Pages/CustomerLocationNR.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 12:
                        newLocation = '../Portal_Pages/LocationByMap.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                    case 13:
                        newLocation = '../Portal_Pages/LocationByAddress.aspx?SubjectId=' + subjectID + '&DepartmentId=' + departmentId + '&SubjectText=' + $('#' + ctrlPrefix + 'txtFindSubject').val();
                        break;
                }
                location.href = newLocation;
            }
        } else {
            location.href = newLocation;
        }
    }, 'text');
}
function searchReset(ctrl) {
    if (ctrl.value == '') {
        ctrl.value = DefaultSearchText;     
        $('#ddlSubjectList').hide('slow');      
        $(ctrl).css({color: '#CCCCCC', fontStyle: 'italic'});
    }	        
}
function txtClear(ctrl) {
    if ($(ctrl).val() == DefaultSearchText) {
        $(ctrl).val('');
        $(ctrl).css({ color: '#000000', fontStyle: 'normal' });
    }
}
function chkTextKey(evt) {    
    if ($('#' + ctrlPrefix + 'txtFindSubject').val().indexOf(DefaultSearchText) > -1) txtClear($('#' + ctrlPrefix + 'txtFindSubject'));        
    var charCode = (window.event) ? event.keyCode : evt.keyCode;
    if (charCode == 40) {
        $('#ddlSubjectList > li:first > a').focus();
    } else if (charCode == 13) {
        GetSubmitAction();
        return false;
    }
}
function chkListKey(evt) {
    var cEvent = (window.event) ? event : evt;	
    var element = cEvent.target || cEvent.srcElement;
    if (cEvent.keyCode == 40) {
        $(element).parent().next().children('a:first').focus();
    } else if (cEvent.keyCode == 38) {
        if ($(element).parent().text() != $('#ddlSubjectList > li:first').text()) {	
            $(element).parent().prev().children('a:first').focus();
        } else {
            $('#' + ctrlPrefix + 'txtFindSubject').focus();
        }
    }
}
function highlightMe(ctrl) {
    $('#ddlSubjectList > li > a').css({background: 'none', color: '#15466a'});
    $(ctrl).css({background: '#fafafa', color: '#ff0000'});
}

function submitSearch(evt) {
    var cEvent = (window.event) ? event : evt;
    if ((cEvent.keyCode == 13 || cEvent.keyCode == 0) && $('#q').val() != "") {
        document.forms[0].method = "GET";
        $('#__VIEWSTATE').val('');
        $('#__EVENTVALIDATION').val('');
        document.forms[0].action = "http://search.bellevuewa.gov/search?q=" + escape($('#q').val()) + "&site=default_collection&client=default_frontend&output=xml_no_dtd&proxystylesheet=default_frontend";
        document.forms[0].submit();
    }
}

$(document).ready(function() {
    if ($('#' + ctrlPrefix + 'txtFindSubject').length == 0) {
        ctrlPrefix = "";
    }
    if (window.parent && $(window.parent.document).find('#IFRAME_SubjectSearch_d').length > 0) {
        $(window.parent.document).find('#IFRAME_SubjectSearch_d').parent().css('display', 'none');
        if ($(window.parent.document).find('#LookupButton').length == 0) {
            var inputSubject = $(window.parent.document).find('#citzn_selectedsubject_d').html();
            $(window.parent.document).find('#citzn_selectedsubject_d').html('<a href="javascript:void(0);" onclick="window.open(\'/portal/CRMSubjectSearch.htm\', \'PortalSearch\', \'width=600,height=500,resizable=1\'); return false;">' + inputSubject + '</a>');
            $(window.parent.document).find('#citzn_selectedsubject').css('width', $(window.parent.document).find('#citzn_selectedsubject').width() - 21 + 'px');
            $(window.parent.document).find('#citzn_selectedsubject').before('<a href="javascript:void(0);" onclick="window.open(\'/portal/CRMSubjectSearch.htm\', \'PortalSearch\', \'width=600,height=500,resizable=1\'); return false;"><img src="/_imgs/btn_off_lookup.gif" id="LookupButton" align="right" alt="Subject Lookup" style="border-left: #6699cc 1px solid;" /></a>');
            $.post(location.pathname.substr(0, location.pathname.indexOf("/", 1)) + '/TopicList.asmx/QueryTopics', { queryText: 'precache' });
            $.post(location.pathname.substr(0, location.pathname.indexOf("/", 1)) + '/TopicList.asmx/GetSubjectAction', { subjectExtId: "9cf3c91f-f988-dd11-ae53-005056b4198d" });
        }
    }   
    if (document.cookie) {
        if ($("#ctl00_lnkMyProfile").is(":visible") && $.cookie('MyProfileView') == null) {
            $("#ctl00_lnkMyProfile").after('<div id="ProfileHelper" style="text-align: center; position: absolute; top: 132px; right: 220px;"><span style="font-size: 24px; font-weight: bolder; color: #cccccc;">^</span><br /><div style="margin-top: -15px; border: 1px solid #cccccc; padding: 3px 5px; background: #ffffcc;"><a href="' + $("#ctl00_lnkMyProfile").attr("href") + '" style="color: #000000; text-decoration: none;">' + $("#ctl00_lnkMyProfile").attr('title') + '</a></div></div>').slideDown('slow', function() {
                setTimeout(function() { $('#ProfileHelper').slideUp('normal'); }, 3000);
            });
            $.cookie('MyProfileView', 'true', { path: '/', expires: 30, secure: false });
        } else if ($("#ctl00_lnkMyRequests").is(":visible") && $.cookie('MyRequestsView') == null) {
            $("#ctl00_lnkMyRequests").after('<div id="RequestsHelper" style="text-align: right; position: absolute; top: 132px; right: 100px;"><span style="font-size: 24px; font-weight: bolder; color: #cccccc; padding-right: 10px;">^</span><br /><div style="margin-top: -15px; border: 1px solid #cccccc; padding: 3px 5px; background: #ffffcc;"><a href="' + $("#ctl00_lnkMyRequests").attr("href") + '" style="color: #000000; text-decoration: none;">' + $("#ctl00_lnkMyRequests").attr('title') + '</a></div></div>').slideDown('slow', function() {
                setTimeout(function() { $('#RequestsHelper').slideUp('normal'); }, 3000);
            });
            $.cookie('MyRequestsView', 'true', { path: '/', expires: 30, secure: false });
        }
    }
    $('#' + ctrlPrefix + 'txtFindSubject').keydown(chkTextKey);
    $('#' + ctrlPrefix + 'txtFindSubject').val(DefaultSearchText);
    $('#' + ctrlPrefix + 'txtFindSubject').focus();
});
//*************************************/
//* End - Default Portal Page Scripts */
//*************************************/
