$( function () { //find comment form //on submit button click validate fields //then do an ajax submit var itemIdField = $("input[name='itemId']", "#commentsSubmitForm"); var replyToId = $("input[name='replyToId']", "#commentsSubmitForm"); var nameField = $("input[name='name']", "#commentsSubmitForm"); var emailField = $("input[name='email']", "#commentsSubmitForm"); var websiteField = $("input[name='website']", "#commentsSubmitForm"); var commentsField = $("textarea[name='comments']", "#commentsSubmitForm"); var similarField = $("input[name='similar']", "#commentsSubmitForm"); var uploadLink = $("#uplFanArtLnk"); uploadLink.click( function () { $("#addFanArtDlg").remove(); var dlgHtml = $( "
" ); $("body").append(dlgHtml); //$("#addFanArtDlg p").append( //"" //); $("#addFanArtDlg").dialog( { modal: true, width: 600, buttons: { OK: function () { $("#fanArtImg").show(); $(this).dialog("close"); }, Cancel: function () { $(this).dialog("close"); } } }); } ); nameField .focus(function () { $(this).val($(this).val().replace("Name(required)", "")); }) .blur(function () { if ($(this).val() == "") { $(this).val("Name(required)"); } }); emailField .focus(function () { $(this).val($(this).val().replace("Email(required)", "")); }) .blur(function () { if ($(this).val() == "") { $(this).val("Email(required)"); } }); websiteField .focus(function () { $(this).val($(this).val().replace("Website(optional)", "")); }) .blur(function () { if ($(this).val() == "") { $(this).val("Website(optional)"); } }); $(".commentSubmitButton", "#commentsSubmitForm").click( function () { if (nameField.val() == "Name(required)") { nameField.val(""); }; if (emailField.val() == "Email(required)") { emailField.val(""); }; if (websiteField.val() == "Website(optional)") { websiteField.val(""); }; var emailNotifyField = $("#emailNotify:checked", "#commentsSubmitForm"); if (!nameIsValid(nameField.val())) { nameField.addClass("commentFieldInvalid").focus(); } else { nameField.removeClass("commentFieldInvalid"); if (!emailIsValid(emailField.val())) { emailField.addClass("commentFieldInvalid").focus(); } else { emailField.removeClass("commentFieldInvalid"); if (!websiteIsValid(websiteField.val())) { websiteField.addClass("commentFieldInvalid").focus(); } else { websiteField.removeClass("commentFieldInvalid"); //alert("validare completa"); var saveCommentsURL = document.location.toString(); var tutResObj = { cmd: "addComment", replyToId: replyToId.val(), name: nameField.val(), email: emailField.val(), website: websiteField.val(), comment: stripHTML(commentsField.val()), emailNotify: emailNotifyField.length, similar: similarField.val() }; if (saveCommentsURL.indexOf("/resources/") >= 0) { saveCommentsURL = saveCommentsURL.replace(".aspx", "").replace("/resources/", "/resources/default.aspx?page="); tutResObj.resourceId = itemIdField.val(); } if (saveCommentsURL.indexOf("/design-news/") >= 0) { if (saveCommentsURL.indexOf("default.aspx?page") >= 0) { } else { saveCommentsURL = saveCommentsURL.replace(".aspx", "").replace("/design-news/", "/design-news/default.aspx?page="); } tutResObj.designNewsId = itemIdField.val(); } else { tutResObj.tutorialId = itemIdField.val(); } $.get( saveCommentsURL, tutResObj, function (data) { var lastGravatar = $(".commentsGravatar").last(); var lastComment = $(".comment").last(); var newGravatar; var newComment; if (lastGravatar.length > 0) { newGravatar = lastGravatar.clone(); newComment = lastComment.clone(); } else { noPreviousComments = true; lastComment = $(".commentsArea h3"); newGravatar = $("