function showNamesModal() { displayOverlay(); $("#suggest_a_name_modal").css('display','block'); } function hideNamesModal() { hideOverlay(); $("#suggest_a_name_modal").css('display','none'); } function activateOrigin(id) { var div ="#flag"+id; $(".flag_active").removeClass("flag_active").addClass("flag_inactive"); $(div).removeClass("flag_inactive").addClass("flag_active"); } function validateSuggestNameForm() { var error = 0; var name = $("#suggest_input_name").val(); if (name=='') { $("#suggest_name_error").css('display','block'); error = 1; } else { $("#suggest_name_error").css('display','none'); } var request = $.ajax({ url: "/ajax/suggest_a_name.php", type: "POST", async: false, data: {action: 'validate_name', name : name}, dataType: "html" }); request.done(function(msg) { if (msg=='found') { $("#suggest_name_error2").css('display','block'); error = 1; } else { $("#suggest_name_error2").css('display','none'); } }); // validate if name already exists var gender = ''; if ($("#suggest_form_gender_male").hasClass('gender_active')) { gender = 'male'; } if ($("#suggest_form_gender_female").hasClass('gender_active')) { gender = 'female'; } if ($("#suggest_form_gender_unisex").hasClass('gender_active')) { gender = 'unisex'; } if (gender == '') { $("#suggest_gender_error").css('display','block'); error = 1; } else { $("#suggest_gender_error ").css('display','none'); } var origin = ''; if ($("#flag1").hasClass('flag_active')) { origin = 'english'; } if ($("#flag2").hasClass('flag_active')) { origin = 'french'; } if ($("#flag3").hasClass('flag_active')) { origin = 'japanese'; } if ($("#flag4").hasClass('flag_active')) { origin = 'chinese'; } if ($("#flag5").hasClass('flag_active')) { origin = 'italian'; } if ($("#flag6").hasClass('flag_active')) { origin = 'german'; } if ($("#flag7").hasClass('flag_active')) { origin = 'spanish'; } if (origin=='') { $("#suggest_origin_error").css('display','block'); error = 1; } else { $("#suggest_origin_error").css('display','none'); } if (error == 0) { $("#suggest_a_name_submit_button").removeAttr('onclick').html('SUBMISSION IN PROGRESS... PLEASE WAIT.'); var request = $.ajax({ url: "/ajax/suggest_a_name.php", type: "POST", data: { action: 'insert_name', name : name, origin: origin, gender: gender}, dataType: "html" }); request.done(function(msg) { if (msg=='added') { $("#suggest_a_name_submit_button").css('display','none'); $("#suggest_a_name_form_table").css('display','none'); $("#suggest_a_name_form_container").append('
Thank you for submitting your dog name!

It will appear on this page within 24 hours, after it has been moderated.
Suggest another name
'); //setTimeout('hideNamesModal()', 5000); } if (msg=='confirmed') { $("#suggest_a_name_submit_button").css('display','none'); $("#suggest_a_name_form_table").css('display','none'); $("#suggest_a_name_form_container").append('
Thank you for submitting your dog name!

Suggest another name
'); //setTimeout('hideNamesModal()', 5000); } }); } } function showForm() { $("#confirm_msg").remove(); $(".flag_active").removeClass("flag_active").addClass("flag_inactive"); $(".gender_active").removeClass("gender_active").addClass("gender_inactive"); $("#suggest_a_name_submit_button").css('display','block'); $("#suggest_a_name_form_table").css('display','block'); $("#suggest_a_name_submit_button").attr('onclick', 'validateSuggestNameForm()').html('SUBMIT NAME'); $("#suggest_input_name").val(''); $("#suggest_another_name").remove(); } function activateGender(gender) { $(".gender_active").removeClass("gender_active").addClass("gender_inactive"); var div = "#suggest_form_gender_"+gender; $(div).removeClass('gender_inactive').addClass('gender_active'); } /* --------------------------------------------------------------------------------------- */ function loadPagination() { var start = $("#start").val(); var selected_alpha = $(".names_alpha_btn_active").attr('id'); if (typeof selected_alpha != 'undefined') { var alpha = selected_alpha.replace("names_filter_alpha_",""); } else { var alpha = ''; } var order_by = $("#order_by").val(); var female_switch = ''; if ($("#names_filter_gender_female").hasClass('names_gender_female_active')) { female_switch = 'on'; } else { female_switch = 'off'; } var male_switch = ''; if ($("#names_filter_gender_male").hasClass('names_gender_male_active')) { male_switch = 'on'; } else { male_switch = 'off'; } if ((male_switch=='on') && (female_switch=='on')) { gender = ''; } if ((male_switch=='on') && (female_switch=='off')) { gender = 'male'; } if ((male_switch=='off') && (female_switch=='on')) { gender = 'female'; } if ((male_switch=='off') && (female_switch=='off')) { gender = 'unisex'; } var flags = ''; if ($("#flag_1").hasClass('names_flag_1')) { flags = flags+"1,"; } if ($("#flag_2").hasClass('names_flag_2')) { flags = flags+"2,"; } if ($("#flag_3").hasClass('names_flag_3')) { flags = flags+"3,"; } if ($("#flag_4").hasClass('names_flag_4')) { flags = flags+"4,"; } if ($("#flag_5").hasClass('names_flag_5')) { flags = flags+"5,"; } if ($("#flag_6").hasClass('names_flag_6')) { flags = flags+"6,"; } if ($("#flag_7").hasClass('names_flag_7')) { flags = flags+"7,"; } window.location='/dog_names?start='+start+"&alpha="+alpha+"&order_by="+order_by+"&gender="+gender+"&flag="+flags; } /* --------------------------------------------------------------------------------------- */ function updatePosition() { pinMenuToTop(); var scrolltop = $("body").scrollTop(); if (scrolltop==0) { scrolltop = $("html").scrollTop(); } if (scrolltop > 1000) { $("#back_to_top").css('display','block'); } else { $("#back_to_top").css('display','none'); } var updating = $("#updating").val(); var stop_loadmore = $("#stop_loadmore").val(); if ((updating=='0') && (stop_loadmore=='0')) { var screen_height = $("#container_test").height() + 255; $("#screen_height").val(screen_height); var offset_top = $("body").scrollTop(); if (offset_top==0) { offset_top = $("html").scrollTop(); } $("#position").val(offset_top); var percentage = (parseInt(offset_top) / parseInt(screen_height)) * 100; percentage = Math.floor(percentage); //console.log(percentage); if (percentage>40) { $("#updating").val("1"); loadMoreNames(); } } } /* --------------------------------------------------------------------------------------- */ function loadMoreNames() { displayLoader(); var selected_alpha = $(".names_alpha_btn_active").attr('id'); if (typeof selected_alpha != 'undefined') { var alpha = selected_alpha.replace("names_filter_alpha_",""); } else { var alpha = ''; } var female_switch = ''; if ($("#names_filter_gender_female").hasClass('names_gender_female_active')) { female_switch = 'on'; } else { female_switch = 'off'; } var male_switch = ''; if ($("#names_filter_gender_male").hasClass('names_gender_male_active')) { male_switch = 'on'; } else { male_switch = 'off'; } var start = $("#start").val(); var order_by = $("#order_by").val(); var flags = ''; if ($("#flag_1").hasClass('names_flag_1')) { flags = flags+"1,"; } if ($("#flag_2").hasClass('names_flag_2')) { flags = flags+"2,"; } if ($("#flag_3").hasClass('names_flag_3')) { flags = flags+"3,"; } if ($("#flag_4").hasClass('names_flag_4')) { flags = flags+"4,"; } if ($("#flag_5").hasClass('names_flag_5')) { flags = flags+"5,"; } if ($("#flag_6").hasClass('names_flag_6')) { flags = flags+"6,"; } if ($("#flag_7").hasClass('names_flag_7')) { flags = flags+"7,"; } //alert('alpha: '+alpha+' | male_switch: '+male_switch+' | female_switch: '+female_switch+' | start: '+start+' | flags: '+flags); var request = $.ajax({ url: "/ajax/names_load_more.php", type: "POST", data: { alpha: alpha, male_switch: male_switch, female_switch: female_switch, start: start, flags: flags, order_by: order_by, show_table_header: '0' }, dataType: "html" }); request.done(function(msg) { hideLoader(); $("#names_container").append(msg); $("#updating").val("0"); }); } /* --------------------------------------------------------------------------------------- */ function updateFilters(type,id) { $(".pagination_button").css("display","none"); displayOverlay(); if (type=='alpha') { var div = "#names_filter_alpha_"+id; if ($(div).hasClass('names_alpha_btn')) { $(".names_alpha_btn_active").removeClass('names_alpha_btn_active').addClass('names_alpha_btn');; $(div).removeClass('names_alpha_btn').addClass('names_alpha_btn_active'); } else { $(div).removeClass('names_alpha_btn_active').addClass('names_alpha_btn'); } } if (type=='gender') { var div = "#names_filter_gender_"+id; if (id=='male') { if ($(div).hasClass('names_gender_male_active')) { $(div).removeClass('names_gender_male_active').addClass('names_gender_male') } else { $(div).removeClass('names_gender_male').addClass('names_gender_male_active') } } if (id=='female') { if ($(div).hasClass('names_gender_female_active')) { $(div).removeClass('names_gender_female_active').addClass('names_gender_female') } else { $(div).removeClass('names_gender_female').addClass('names_gender_female_active') } } } if (type=='flag') { var div = "#flag_"+id; var class_active = "names_flag_"+id; var class_inactive = "names_flag_"+id+"_inactive"; if ($(div).hasClass(class_active)) { $(div).removeClass(class_active).addClass(class_inactive); } else { $(div).removeClass(class_inactive).addClass(class_active); } } var selected_alpha = $(".names_alpha_btn_active").attr('id'); if (typeof selected_alpha != 'undefined') { var alpha = selected_alpha.replace("names_filter_alpha_",""); } else { var alpha = ''; } var female_switch = ''; if ($("#names_filter_gender_female").hasClass('names_gender_female_active')) { female_switch = 'on'; } else { female_switch = 'off'; } var male_switch = ''; if ($("#names_filter_gender_male").hasClass('names_gender_male_active')) { male_switch = 'on'; } else { male_switch = 'off'; } var start = 0; var flags = ''; if ($("#flag_1").hasClass('names_flag_1')) { flags = flags+"1,"; } if ($("#flag_2").hasClass('names_flag_2')) { flags = flags+"2,"; } if ($("#flag_3").hasClass('names_flag_3')) { flags = flags+"3,"; } if ($("#flag_4").hasClass('names_flag_4')) { flags = flags+"4,"; } if ($("#flag_5").hasClass('names_flag_5')) { flags = flags+"5,"; } if ($("#flag_6").hasClass('names_flag_6')) { flags = flags+"6,"; } if ($("#flag_7").hasClass('names_flag_7')) { flags = flags+"7,"; } // alert('alpha: '+alpha+' | male_switch: '+male_switch+' | female_switch: '+female_switch+' | start: '+start+' | flags: '+flags); var order_by = $("#order_by").val(); var request = $.ajax({ url: "/ajax/names_load_more.php", type: "POST", data: { alpha: alpha, male_switch: male_switch, female_switch: female_switch, start: start, flags: flags, order_by: order_by, show_table_header: '1' }, dataType: "html" }); request.done(function(msg) { hideOverlay(); $("#names_container").html(msg); }); } /* --------------------------------------------------------------------------------------- */ function showTooltip(text,id,distFromLeft,distFromTop) { var position = $("#"+id).position(); var posLeft = Math.floor(position.left) + parseInt(distFromLeft); var posTop = Math.floor(position.top) + parseInt(distFromTop); $("#tooltip_text").html(text); $("#tooltip").css('display','block').css('top',posTop+"px").css('left',posLeft+"px"); } /* --------------------------------------------------------------------------------------- */ function hideTooltip() { $("#tooltip_text").html(''); $("#tooltip").css('display','none'); } /* --------------------------------------------------------------------------------------- */ function like_dislike(type,id) { var request = $.ajax({ url: "/ajax/names_like_dislike.php", type: "POST", data: {type : type, id: id}, dataType: "html" }); request.done(function(msg) { var data = msg.split(':'); var div_like = "#nb_likes_"+id; var div_dislike = "#nb_dislikes_"+id; $(div_like).html(data[0]); $(div_dislike).html(data[1]); if (type=='like') { var btn_like = "#btn_like_"+id; var btn_dislike = "#btn_dislike_"+id; if ($(btn_like).attr('src')=='images/names_like_off.png') { $(btn_like).attr('src','images/names_like_on.png'); $(btn_dislike).attr('src','images/names_dislike_off.png'); } else if ($(btn_like).attr('src')=='images/names_like_on.png') { $(btn_like).attr('src','images/names_like_off.png'); $(btn_dislike).attr('src','images/names_dislike_off.png'); } } if (type=='dislike') { var btn_like = "#btn_like_"+id; var btn_dislike = "#btn_dislike_"+id; if ($(btn_dislike).attr('src')=='images/names_dislike_off.png') { $(btn_dislike).attr('src','images/names_dislike_on.png'); $(btn_like).attr('src','images/names_like_off.png'); } else if ($(btn_dislike).attr('src')=='images/names_dislike_on.png') { $(btn_dislike).attr('src','images/names_dislike_off.png'); $(btn_like).attr('src','images/names_like_off.png'); } } }); } /* --------------------------------------------------------------------------------------- */ function changeFilter(filter) { displayOverlay(); $(".pagination_button").remove(); var selected_alpha = $(".names_alpha_btn_active").attr('id'); if (typeof selected_alpha != 'undefined') { var alpha = selected_alpha.replace("names_filter_alpha_",""); } else { var alpha = ''; } var female_switch = ''; if ($("#names_filter_gender_female").hasClass('names_gender_female_active')) { female_switch = 'on'; } else { female_switch = 'off'; } var male_switch = ''; if ($("#names_filter_gender_male").hasClass('names_gender_male_active')) { male_switch = 'on'; } else { male_switch = 'off'; } var start = 0; $("#order_by").val(filter); var flags = ''; if ($("#flag_1").hasClass('names_flag_1')) { flags = flags+"1,"; } if ($("#flag_2").hasClass('names_flag_2')) { flags = flags+"2,"; } if ($("#flag_3").hasClass('names_flag_3')) { flags = flags+"3,"; } if ($("#flag_4").hasClass('names_flag_4')) { flags = flags+"4,"; } if ($("#flag_5").hasClass('names_flag_5')) { flags = flags+"5,"; } if ($("#flag_6").hasClass('names_flag_6')) { flags = flags+"6,"; } if ($("#flag_7").hasClass('names_flag_7')) { flags = flags+"7,"; } // alert('alpha: '+alpha+' | male_switch: '+male_switch+' | female_switch: '+female_switch+' | start: '+start+' | flags: '+flags); var request = $.ajax({ url: "/ajax/names_load_more.php", type: "POST", data: { alpha: alpha, male_switch: male_switch, female_switch: female_switch, start: start, flags: flags, order_by: filter, show_table_header: '1' }, dataType: "html" }); request.done(function(msg) { $("#names_container").html(msg); hideOverlay(); }); } /* --------------------------------------------------------------------------------------- */ function jumpToTop() { $('html, body').animate({ scrollTop: 0 }, 500); $("#back_to_top").css('display','none'); }