$('document').ready(function () {
// Set Searched Word in input field
if (decodeURIComponent(getUrlVars()["searchedtext"]).toString() != "undefined") {
$('.simpleSearchTxt input').val(decodeURIComponent(getUrlVars()["searchedtext"]));
$('#AsearchedWordTxt').val(decodeURIComponent(getUrlVars()["searchedtext"]));
}
else {
$('.simpleSearchTxt input').val("كلمة البحث");
}
var date = new Date();
var todyDay = date.getDate();
var todyMonth = date.getMonth() + 1;
var todyYear = date.getFullYear();
var dayNumber = daysInMonth(todyMonth, todyYear);
if (todyDay < 10) {
todyDay = "0" + todyDay;
}
if (todyMonth < 10) {
todyMonth = "0" + todyMonth;
}
SectionsDropDownList();
setDays(dayNumber, "");
setYears(todyYear);
$('#FromYear').change(function () {
var year = $('#FromYear option:selected').val()
var month = $('#FromMonth option:selected').val();
if (month == 0) {
month = todyMonth;
}
var dayNumber = daysInMonth(month, year);
setDays(dayNumber, "From");
});
$('#FromMonth').change(function () {
var year = $('#FromYear option:selected').val()
var month = $('#FromMonth option:selected').val();
if (year == 0) {
year = todyYear;
}
var dayNumber = daysInMonth(month, year);
setDays(dayNumber, "From");
});
$('#TOYear').change(function () {
var year = $('#TOYear option:selected').val()
var month = $('#TOMonth option:selected').val();
if (month == 0) {
month = todyMonth;
}
var dayNumber = daysInMonth(month, year);
setDays(dayNumber, "To");
});
$('#TOMonth').change(function () {
var year = $('#TOYear option:selected').val()
var month = $('#TOMonth option:selected').val();
if (year == 0) {
year = todyYear;
}
var dayNumber = daysInMonth(month, year);
setDays(dayNumber, "To");
});
$('.ApublishDateFrom select').change(function () {
var selectedValue = "";
$('.ApublishDateFrom select').each(function () {
selectedValue += $('option:selected', this).val();
});
if (selectedValue == "16122013") {
$('#FromRest').addClass('restedBtnDisbel');
}
else {
$('#FromRest').removeClass('restedBtnDisbel');
}
});
$('.ApublishDateTo select').change(function () {
var selectedValue = "";
$('.ApublishDateTo select').each(function () {
selectedValue += $('option:selected', this).val();
});
var comparedate = todyDay + "" + todyMonth + "" + todyYear;
if (selectedValue == comparedate) {
$('#TORest').addClass('restedBtnDisbel');
}
else {
$('#TORest').removeClass('restedBtnDisbel');
}
});
$('.restedBtn').click(function () {
var attId = $(this).attr('id');
if (!$(this).hasClass('restedBtnDisbel')) {
switch (attId) {
case "FromRest":
$('#FromYear option[value=2013]').prop('selected', 'selected');
$('#FromDay option[value=16]').prop('selected', 'selected');
$('#FromMonth option[value=12]').prop('selected', 'selected');
$('#FromRest').addClass('restedBtnDisbel');
break;
case "TORest":
$('#TOYear option[value=' + todyYear + ']').prop('selected', 'selected');
$('#TODay option[value=' + todyDay + ']').prop('selected', 'selected');
$('#TOMonth option[value=' + todyMonth + ']').prop('selected', 'selected');
$('#TORest').addClass('restedBtnDisbel');
break;
}
}
});
$('#FromYear option[value=2013]').prop('selected', 'selected');
$('#FromDay option[value=16]').prop('selected', 'selected');
$('#FromMonth option[value=12]').prop('selected', 'selected');
$('#TODay option[value=' + todyDay + ']').prop('selected', 'selected');
$('#TOMonth option[value=' + todyMonth + ']').prop('selected', 'selected');
$('#TOYear option[value=' + todyYear + ']').prop('selected', 'selected');
advanceSearch();
updatedControls();
$('.advSearchArrowMob,.advancedTitle').click(function () {
if ($('.advSearchArrowMob').css('display') == "block") {
if ($('.searchControles').css('display') == "none") {
$('.searchControles').fadeIn();
$(this).css('background-position', 'left bottom');
}
else if ($('.searchControles').css('display') == "block") {
$('.searchControles').fadeOut();
$(this).css('background-position', 'left top');
}
}
});
});
function daysInMonth(month, year) {
var dd = new Date(year, month, 0);
return dd.getDate();
}
function setDays(dayNumber, parendId) {
if (parendId == "") {
for (var i = 1; i <= dayNumber; i++) {
if (i < 10) {
$('.daySelect').append('');
}
else {
$('.daySelect').append('');
}
}
}
else if (parendId == "From") {
var oldValue = $('#FromDay option:selected').val();
$('#FromDay').html("");
for (var i = 1; i <= dayNumber; i++) {
if (i < 10) {
$('#FromDay').append('');
$("#FromDay option[value='0" + oldValue + "']").prop('selected', 'selected');
}
else {
$('#FromDay').append('');
$("#FromDay option[value='" + oldValue + "']").prop('selected', 'selected');
}
}
}
else if (parendId == "To") {
var oldValue = $('#TODay option:selected').val();
$('#TODay').html("");
for (var i = 1; i <= dayNumber; i++) {
if (i < 10) {
$('#TODay').append('');
$("#TODay option[value='0" + oldValue + "']").prop('selected', 'selected');
}
else {
$('#TODay').append('');
$("#TODay option[value='" + oldValue + "']").prop('selected', 'selected');
}
}
}
}
function setYears(CurrentYear) {
for (var i = "2013"; i <= CurrentYear; i++) {
$('.yearSelect').append('');
}
}
function SectionsDropDownList() {
var URL = "/services/GetDataSourceSectionsSearch/cc7dbaa4-7308-41ff-9a05-6d5c281c504c";
$.ajax({
type: "Get",
cache: false,
url: URL,
success: function (data) {
if (data != null) {
var MainSection = jQuery.parseJSON(data);
for (var i = 0; i < MainSection.length; i++) {
$('.AmainSection').append('');
}
}
$('.AmainSection').change(function () {
var optionValue = $('option:selected', this).attr('id');
if (optionValue != "allSite") {
DrawSubSection(optionValue);
}
else {
$('.ASubSection').hide();
}
});
var MainSectionId = decodeURIComponent(getUrlVars()["ChecksectionId"]);
if (MainSectionId != undefined) {
$(".AmainSection option[value='" + MainSectionId + "']").prop('selected', 'selected');
var newsection = $(".AmainSection option[value='" + MainSectionId + "']").attr('id');
DrawSubSection(newsection);
}
} // Success End
});
}
function DrawSubSection(sectionId) {
var sectionId = $.trim(sectionId);
if (sectionId != "" && sectionId != 0 && sectionId != undefined) {
var URL = "/services/GetDataSourceSectionsSearch/" + sectionId;
$.ajax({
type: "Get",
cache: false,
url: URL,
success: function (data) {
if (data != null) {
var SubSection = jQuery.parseJSON(data);
if (SubSection.length > 0) {
$('.ASubSection').html('');
$('.ASubSection').append('');
for (var i = 0; i < SubSection.length; i++) {
if (SubSection[i].SectionId!= "80EFB28B-E00F-43C6-97CA-80380013AD8D") {
$('.ASubSection').append('');
} }
$('.ASubSection').show();
}
else {
$('.ASubSection').hide();
}
}
var SubSectionId = decodeURIComponent(getUrlVars()["sectionId"]);
if (SubSectionId != undefined) {
if (SubSection.length > 0) {
$('.ASubSection').show();
$(".ASubSection option[value='" + SubSectionId + "']").prop('selected', 'selected');
}
}
} // Success End
});
}
}
function advanceSearch() {
$('.AdvancedSearchBtn').click(function () {
var text = $('#AsearchedWordTxt').val();
var anywordString = text.toString();
var wordSpace = anywordString.toLowerCase().replace(/[_...#;,--"<>%""*]/g, '');
var anywordnoSpace = wordSpace.replace(/\s+/g, " "); //words without extra spaces
var SearchTxt = $.trim(anywordnoSpace); //الكلمة المدخلة
var SearchWordSpecialChars = parametersChecking(SearchTxt, ';##,##--##<##>##%##"##""##*');
if (SearchTxt != "") {
var MainSectionId = $('.AmainSection option:selected').val();
var SubSectionId = $('.ASubSection option:selected').val();
var dateFrom = $('#FromYear option:selected').val() + "-" + $('#FromMonth option:selected').val() + "-" + $('#FromDay option:selected').val();
var dateTo = $('#TOYear option:selected').val() + "-" + $('#TOMonth option:selected').val() + "-" + $('#TODay option:selected').val();
var Fromnewdate = Date.parse(dateFrom);
var Tonewdate = Date.parse(dateTo);
qString = "/search?searchedtext=" + SearchTxt + "&pagenumber=1";
if (SubSectionId != "0" && SubSectionId != undefined) {
qString = "/search?searchedtext=" + SearchTxt + "&pagenumber=1§ionId=" + SubSectionId + "&ChecksectionId=" + MainSectionId;
}
else if (MainSectionId != "0") {
qString = "/search?searchedtext=" + SearchTxt + "&pagenumber=1§ionId=" + MainSectionId + "&ChecksectionId=" + MainSectionId;
}
else {
qString = "/search?searchedtext=" + SearchTxt + "&pagenumber=1";
}
if (dateFrom != "2013-12-16") {
qString += "&dateFrom=" + dateFrom;
}
var date = new Date();
var todyDay = date.getDate();
var todyMonth = date.getMonth() + 1;
var todyYear = date.getFullYear();
if (todyDay < 10) {
todyDay = "0" + todyDay;
}
if (todyMonth < 10) {
todyMonth = "0" + todyMonth;
}
var comparedate = todyYear + "-" + todyMonth + "-" + todyDay;
if (dateTo != comparedate) {
qString += "&dateTo=" + dateTo;
}
if (Tonewdate < Fromnewdate) {
$('.timeValidationError').fadeIn();
}
else {
$('.timeValidationError').fadeOut('fast');
document.location.href = qString;
}
}
else {
$('#AsearchedWordTxt').css('border-color', 'red');
}
});
}
function updatedControls() {
if (decodeURIComponent(getUrlVars()["dateFrom"]) != undefined) {
var dateFrom = decodeURIComponent(getUrlVars()["dateFrom"]).toString().split('-');
$("#FromYear option[value='" + dateFrom[0] + "']").prop('selected', 'selected');
$("#FromMonth option[value='" + dateFrom[1] + "']").prop('selected', 'selected');
$("#FromDay option[value='" + dateFrom[2] + "']").prop('selected', 'selected');
var selectedValue = "";
$('.ApublishDateFrom select').each(function () {
selectedValue += $('option:selected', this).val();
});
if (selectedValue == "16122013") {
$('#FromRest').addClass('restedBtnDisbel');
}
else {
$('#FromRest').removeClass('restedBtnDisbel');
}
}
if (decodeURIComponent(getUrlVars()["dateTo"]) != undefined) {
var dateTo = decodeURIComponent(getUrlVars()["dateTo"]).toString().split('-');
$("#TOYear option[value='" + dateTo[0] + "']").prop('selected', 'selected');
$("#TOMonth option[value='" + dateTo[1] + "']").prop('selected', 'selected');
$("#TODay option[value='" + dateTo[2] + "']").prop('selected', 'selected');
var selectedValue = "";
$('.ApublishDateTo select').each(function () {
selectedValue += $('option:selected', this).val();
});
var date = new Date();
var todyDay = date.getDate();
var todyMonth = date.getMonth() + 1;
var todyYear = date.getFullYear();
if (todyDay < 10) {
todyDay = "0" + todyDay;
}
if (todyMonth < 10) {
todyMonth = "0" + todyMonth;
}
var comparedate = todyDay + "" + todyMonth + "" + todyYear;
if (selectedValue == comparedate) {
$('#TORest').addClass('restedBtnDisbel');
}
else {
$('#TORest').removeClass('restedBtnDisbel');
}
}
}