//will alert the user of errors in input. var initialMessage="You are missing the following required information:\n\n"; var problemStr = initialMessage; var problemCount=0;//keep track of the number of problems //captcha handling var ci = new Image();//captcha var cv; //used later function callit(){ //load via ajax var dd=new Date(); $.get("amver_scripts/c.asp?"+dd.getTime()+Math.floor(Math.random()*16)+"", function(data){ cv=data; });//end ajax success } $(document).ready(function() { //captcha image load handling $(ci).load( function(){//on image load //callit(); //to make sure the image gets loaded properly into the image tag $("#captchaimg").attr("src",ci.src); }//end load function ); //unhide captchas $("#hideCaptcha").removeClass("hidden"); $("input[name='newCaptcha']").click(function(){ var dd=new Date(); ci.src = "amver_scripts/captcha.asp?"+dd.getTime()+Math.floor(Math.random()*16)+""; setTimeout(callit,1000); }).click();//trigger an update //change border colors //required field indication $(".jsrequired:not([type='checkbox'],.jsgroup)").css("border","1px solid #999").bind("blur", function(e) { if($(this).val() == "") { $(this).css("border","1px solid red"); } else { $(this).css("border","1px solid #339933"); } }); //checkbox label mouseover $("#SARQ input[type='checkbox']").next().bind("mouseover",function(){ $(this).css("cursor","pointer"); }); //checkbox label clicking $("#SARQ input[type='checkbox']").next().toggle(function(){ var thebox=$(this).prev(); //turn on thebox.attr("checked",true); $(this).css("color","#338833"); }, function(){ //turn off var thebox=$(this).prev(); thebox.attr("checked",false); $(this).css("color","black"); } ); //checkbox interception of clicking $("#SARQ input[type='checkbox']").click(function(){ return $(this).next().click(); }); //trigger indication of required fields $(".jsrequired").trigger('blur'); //bind validation to form $("#SARQ").submit(function(){return validate();}); //handle resetting $("#SARQ input[name='reset']").click(function(){ //fix refresh glitch where first click doesnt do anything $("#SARQ input[type='checkbox']").each(function(){ if($(this).attr("checked") == true) { //call the label's toggle function $(this).next().click(); } }); });//end reset //fix refresh glitch where first click doesnt do anything $("#SARQ input[type='checkbox']").each(function(){ if($(this).attr("checked") == true) { //call the label's toggle function $(this).next().click(); } }); });//end document ready ready //form submit handler function validate() { //load via ajax var dd=new Date(); $.get("amver_scripts/c.asp?"+dd.getTime()+Math.floor(Math.random()*16)+"", function(data){ cv=data; });//end ajax success if($("input[name='captcha']").val()=="" || md5($("input[name='captcha']").val())!=cv){ //alert("session captcha value: " + cv+"\n md5'd: "+md5(cv)+"\ninput: "+$("input[name='captcha']").val()+"\nmd5'd: "+md5($("input[name='captcha']").val())); problemStr +="CAPTCHA Value did not match text in the image"+"\n"; problemCount++; } //check text-entry and radio blocks $(".jsrequired:not([type='checkbox'],.jsgroup)").each(function(i) { if($(this).val() == "") { problemStr +=jQuery.trim($(this).parent().filter("label").text())+"\n"; problemCount++; } }); //check checkbox groups $("input[type='hidden']").each( function(){ if($(this).hasClass("jsrequired") && $(this).hasClass("jsgroup")) //find required groups { //find the actual check boxes, loop through and see if atleast one is checked. //if not, add an error var good=false; $("input."+$(this).attr("name")+":not([type='radio'])").each( function(){ //this is performed on each checkbox of each group if($(this).attr("checked")) { good=true; }//endif });//end function if(!good){ problemCount++; problemStr +=jQuery.trim($(this).attr("id"))+"\n"; } //Sets cookie for emailing a thank you email //Sets the date of the cookie to expire in one day var expire=new Date(); var myDays = ["Sun", "Mon", "Tues", "Wed", "Thrus", "Fri", "Sat"] var myMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"] var month = expire.getMonth(); var day = expire.getDay()+1; var year = expire.getFullYear(); var dateString = myDays[day] + ", " + (expire.getDate()+1) + " " + myMonths[month] + " " + year + " " + expire.getHours() + ":" + expire.getMinutes() + ":" + expire.getSeconds(); email = document.SARQ.Email.value; name = document.SARQ.Name.value; document.cookie = "amversarqemail="+email+"; expires="+dateString+"UTC; path=/" document.cookie = "amversarqname="+name+"; expires="+dateString+"UTC; path=/" }//end if }//end function ); //verify all required fields are filled in if(problemCount>0) { alert(problemStr); problemStr=initialMessage; problemCount=0; return false; } return true; }