﻿$(document).ready(function() { var txtKeywords = $("div#search input[type='text']"); var ddlCategories = $("div#search select[name='cid']"); var ddlAuthors = $("div#search select[name='ra_id']"); $("div#search form").submit(function() { try { var keywords = $.trim(txtKeywords.val()); if (keywords.length == 0) { var regex = new RegExp('[ -]+', 'g'); var categoryID = ddlCategories.val(); var authorID = ddlAuthors.val(); if (!isNaN(categoryID) && !isNaN(authorID)) { var category = encodeURI($.trim(ddlCategories.children('option:selected').text()).replace(regex, '-')); var authorOptionValue = ddlAuthors.children('option:selected').text(); var authorArray = authorOptionValue.split(','); var authorName = authorOptionValue; if (authorArray.length == 2) { authorName = $.trim(authorArray[1]) + ' ' + $.trim(authorArray[0]); } var author = encodeURI($.trim(authorName).replace(regex, '-')); var href = location.protocol + '//' + location.hostname + '/'; if ((categoryID > 0 ? 1 : 0) ^ (authorID > 0 ? 1 : 0)) { if (categoryID > 0) { href += 'articles/category/' + category + '/' + categoryID; } else { href += 'articles/author/' + author + '/' + authorID; } location.href = href; return false; } } } } catch (err) { return true; } return true; }); });