/* - global.js - */
// http://queue.acm.org/portal_javascripts/global.js?original=1
var jq=jQuery.noConflict();jq(document).ready(function(){jq("#q,#add_email,#addtag").inputSetter();jq(".narrowresults button").hide();jq(".narrowresults select").change(function(){jq(this).parents("form").submit()});jq("#user-print a").bind("click",ACMQ.printPage);jq("#user-send a").bind("click",ACMQ.showSender);jq("#user-share a").bind("click",ACMQ.showSharer);jq("#form-emailsignup").validate(ACMQ.signup);jq("#form-comment").validate(ACMQ.comment);jq("#form-feedback").validate(ACMQ.feedback);jq(".charactersremaining").charactersRemaining()});jq(document).keydown( function(e){if(e.which==27){ACMQ.clearUserActions()}});jQuery.validator.setDefaults({errorElement:"strong",errorPlacement: function(error,element){if(element.prev("label").length!=0){element.prev("label").after(error)} else{element.prev("img").before(error)}}});jQuery.validator.addMethod("notEqualTo", function(value,element,param){return jq(element).val()!=jq(element).prev("label").text()},"error");var ACMQ={signup:{rules:{add_email:{required:true,email:true,notEqualTo:true}},messages:{email:"Please enter a valid email address"}},comment:{rules:{comment_name:{required:true},comment_email:{required:true,email:true},comment_content:{required:true},comment_captcha:{required:true}},messages:{comment_name:"Please enter your name",comment_email:"Please enter a valid email address",comment_content:"Please enter a comment",comment_captcha:"Field must match the graphic"},submitHandler: function(){jq.ajax({type:"GET",url:"#",success: function(msg){}})}},feedback:{rules:{feedback_name:{required:true},feedback_email:{required:true,email:true},feedback_content:{required:true},feedback_captcha:{required:true}},messages:{feedback_name:"Please enter your name",feedback_email:"Please enter a valid email address",feedback_content:"Please enter your feedback",feedback_captcha:"Field must match the graphic"},submitHandler: function(){jq.ajax({type:"GET",url:"#",success: function(msg){}})}},printPage: function(e){ACMQ.clearUserActions();window.print();e.preventDefault()},showSender: function(e){var $this=jq(this);jq("#share").hide();jq("#user-share a").removeClass("on");ACMQ.clearValidation();if(ACMQ.send){jq("#sendtocolleague").toggle()} else{jq.ajax({type:"GET",url:$this.attr("href"),success: function(msg){var msgclipped=msg.split("<div>");$this.parent().prepend('<div class="dropdown" id="sendtocolleague"><div>'+msgclipped[1]+'</div>').find("a[name='documentContent']").hide();jq("#sendtocolleague .formControls").append('<div class="buttons"><button class="cancel" type="button" value="Cancel"><span>Cancel</span></button></div>');jq(".captchaImage img:eq(1),#sendtocolleague #captcha-audio-embed").remove();jq("#sendtocolleague form").validate({rules:{"your-name":{required:true,notEqualTo:true},replyto:{required:true,email:true,notEqualTo:true},"your-friends-name":{required:true,notEqualTo:true},"your-friends-e-mail-address":{required:true,email:true,notEqualTo:true},verification:"required"},messages:{"your-name":"Please enter your name",replyto:"Please enter a valid email address","your-friends-name":"Please enter your friend's name","your-friends-e-mail-address":"Please enter a valid email address",verification:"Field must match the graphic"},errorPlacement: function(error,element){element.before(error)},submitHandler: function(){jq.ajax({type:"POST",url:jq("#formid-send-to-a-colleague form:first").attr("action"),success: function(msg){jq("#sendtocolleague").html('<h4>Success!</h4><div class="buttons"><button type="button"><span>OK</span></button></div>');jq("#sendtocolleague button").bind("click",ACMQ.clearUserActions);ACMQ.send=false}})}});jq("#sendtocolleague input, #sendtocolleague textarea").hide().not("#verification, input.context, input[type='hidden']").inputSetter().end().show();jq("#sendtocolleague button.cancel").click(function(e){ACMQ.clearUserActions();e.preventDefault()});ACMQ.send=true},error: function(msg){return}})}
$this.toggleClass("on");e.preventDefault()},showSharer: function(e){var $this=jq(this);jq("#sendtocolleague").hide();jq("#user-send a").removeClass("on");ACMQ.clearValidation();if(ACMQ.share){jq("#share").toggle()} else{jq.ajax({type:"GET",url:$this.attr("href"),success: function(msg){$this.parent().append(msg);ACMQ.share=true},error: function(msg){return}})}
$this.toggleClass("on");e.preventDefault()},clearUserActions: function(){jq(".dropdown").hide();jq("#useractions a").removeClass("on");ACMQ.clearValidation()},clearValidation: function(){jq("#sendtocolleague input, #sendtocolleague textarea").not("#verification, input.context, input[type='hidden']").inputSetter().removeClass("error");jq("#sendtocolleague strong.error").remove()}};jQuery.fn.inputSetter=function(){return this.each(function(){var $input=jq(this);var $label=jq("label[for='"+$input.attr("id")+"']");var labeltext=$label.text();$label.hide();$input.val(labeltext);$input.focus(function(){if(this.value==labeltext){this.value=""}}).blur(function(){if(!this.value.length){this.value=labeltext}})})};jQuery.fn.charactersRemaining=function(){if(this.length===0){return(this)}
function cr($obj){var counter={$target:jq("#"+$obj.attr('for')),$span:$obj.find("span:first"),maxvalue:$obj.children('span:first').text(),remaining:null,init: function(){counter.remaining=counter.maxvalue-counter.$target.val().length;counter.$span.text(counter.remaining);counter.$target.bind("keyup keydown",counter.tally)},tally: function(){if(counter.$target.val().length>counter.maxvalue){counter.$target.val(counter.$target.val().substring(0,counter.maxvalue))}
counter.$span.text(counter.maxvalue-counter.$target.val().length)}};counter.init($obj)};return this.each(function(){new cr(jQuery(this))})};