$(function(){$('.signup-link').click(function(e){e.preventDefault();$.get("/ws/signup",function(data){$(data).modal({close:false,position:["5%",],overlayId:'contact-overlay',containerId:'contact-container',onOpen:signup.open,onShow:signup.show,onClose:signup.close});});});var img=['cancel.png','form_bottom.gif','form_top.gif','loading.gif','send.png'];$(img).each(function(){var i=new Image();i.src='/img/contact/'+this;});});function readBDay(){$('#linkedDates').val($('#selectMonth').val()+'/'+
$('#selectDay').val()+'/'+$('#selectYear').val());return{};}
function updateBDay(date){$('#selectMonth').val(date.substring(0,2));$('#selectDay').val(date.substring(3,5));$('#selectYear').val(date.substring(6,10));}
function checkBDay(){var daysInMonth=32-new Date($('#selectYear').val(),$('#selectMonth').val()-1,32).getDate();$('#selectDay option').attr('disabled','');$('#selectDay option:gt('+(daysInMonth-1)+')').attr('disabled','disabled');if($('#selectDay').val()>daysInMonth){$('#selectDay').val(daysInMonth);}}
var h2;var signup={message:null,open:function(dialog){if($.browser.mozilla){$('#contact-container .contact-button').css({'padding-bottom':'2px'});}
if($.browser.safari){$('#contact-container .contact-input').css({'font-size':'.9em'});}
h2=300;var title=$('#contact-container .contact-title').html();$('#contact-container .contact-title').html('Loading...');dialog.overlay.fadeIn(200,function(){dialog.container.fadeIn(200,function(){dialog.data.fadeIn(200,function(){$('#contact-container .contact-content').animate({height:h2},function(){$('#contact-container .contact-title').html(title);$('#contact-container form#form1').fadeIn(200,function(){$('#contact-container :text')[0].focus();if($.browser.msie&&$.browser.version<7){$('#contact-container .contact-button').each(function(){if($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)){var src=RegExp.$1;$(this).css({backgroundImage:'none',filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+src+'", sizingMethod="crop")'});}});}});});});});});},show:function(dialog){$('#contact-container #captcha_image').hover(function(){$(this).attr('title','Click to regenerate image');$(this).css({cursor:'pointer'});},function(){$(this).css({cursor:'default'});});$('#contact-container #captcha_image').click(function(){$(this).attr('src',"/ws/signup/captcha/?"+Math.random()*1000);});$("#linkedDates").datepicker({minDate:new Date(1920,1-1,1),maxDate:new Date(),yearRange:'-88:+90',beforeShow:readBDay,onSelect:updateBDay,showOn:"both",buttonImage:"/img/calendar.png",buttonImageOnly:true,changeMonth:true,changeYear:true,nextText:''});$("#selectMonth, #selectYear").change(checkBDay);$('#contact-container #submit-form1').click(function(e){e.preventDefault();formValidate1();});$('#contact-container #form-back').click(function(e){e.preventDefault();form.init({fout:2,fin:1,height:h2,title:'Create a New Account'});});$('#contact-container #submit-form2').click(function(e){e.preventDefault();formValidate2();});$('#contact-container :text').focus(function(){$(this).select();});},goInvalid:function(){if($('#contact-container .contact-message:visible').length>0){var msg=$('#contact-container .contact-message div');msg.fadeOut(200,function(){msg.empty();signup.showError();msg.fadeIn(200);});}
else{$('#contact-container .contact-message').animate({height:'50px'},signup.showError);}},close:function(dialog){$('#contact-container .contact-message').fadeOut();$('#contact-container .contact-title').html('Goodbye...');$('#contact-container form').fadeOut(200);$('#contact-container .contact-content').animate({height:100},function(){dialog.data.fadeOut(200,function(){dialog.container.fadeOut(200,function(){dialog.overlay.fadeOut(200,function(){$("#contact-container #captcha_image").removeAttr('src');$.modal.close();});});});});},error:function(xhr){alert('An unexpected error occurred while processing your query. Please try again.');},validate:function(part){signup.message='';part=(part===undefined?1:part)
if(part==1){if(!$('#contact-container #contact-fname').val()||!$('#contact-container #contact-lname').val()){signup.message+='Name is required. ';}else if($('#contact-container #contact-lname').val().length<2){signup.message+='Please supply your lastname. ';}
var $has_pword=($('#contact-container #contact-pword1').val().length>0?true:false);var pw1=$('#contact-container #contact-pword1').val();var pw2=$('#contact-container #contact-pword2').val();if(!pw1||!pw2||pw1.length<8){signup.message+='Password and Confirm Password is required & min. of 8 characters.';}
if($has_pword){if(pw1!=pw2){signup.message+='Passwords do not match.';}}
var email=$('#contact-container #contact-email').val();if(!email){signup.message+='Email is required. ';}
else{if(!signup.validateEmail(email)){signup.message+='Email is invalid. ';}}}else if(part==2){if(!$('#contact-container #contact-captcha').val()){signup.message+='Plase type the letters as shown in the image. ';}
if($('#terms1:checked').val()===undefined||$('#terms2:checked').val()===undefined){signup.message+='You need to accept all our terms before signing up!';}}
if(signup.message.length>0){return false;}
else{return true;}},validateEmail:function(email){var at=email.lastIndexOf("@");if(at<1||(at+1)===email.length)
return false;if(/(\.{2,})/.test(email))
return false;var local=email.substring(0,at);var domain=email.substring(at+1);if(local.length<1||local.length>64||domain.length<4||domain.length>255)
return false;if(/(^\.|\.$)/.test(local)||/(^\.|\.$)/.test(domain))
return false;if(!/^"(.+)"$/.test(local)){if(!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
return false;}
if(!/^[-a-zA-Z0-9\.]*$/.test(domain)||domain.indexOf(".")===-1)
return false;return true;},showError:function(){$('#contact-container .contact-message').html($('<div class="contact-error">').append(signup.message)).fadeIn(200);}};var form={init:function(opt){$('#contact-container .contact-message').fadeOut(function(){$('#contact-container .contact-message').removeClass('contact-error').empty();});$(('#contact-container form#form'+opt.fout)).fadeOut(function(){$('#contact-container .contact-title').html(opt.title);$('#contact-container .contact-content').animate({height:opt.height},function(){$(('#contact-container form#form'+opt.fin)).fadeIn(200,function(){$('#contact-container form:visible :text')[0].focus();});});});}};var formValidate1=function(){if(signup.validate()){form.init({fout:1,fin:2,height:h2+150,title:'Personal Profile'});}else{signup.goInvalid();}};var formValidate2=function(){if(signup.validate(2)){$('#contact-container .contact-message').fadeOut(function(){$('#contact-container .contact-message').removeClass('contact-error').empty();});$('#contact-container .contact-title').html('Submitting...');$('#contact-container form#form2').fadeOut(200);$('#contact-container .contact-content').animate({height:'100px'},function(){$('#contact-container .contact-loading').fadeIn(200,function(){$.ajax({url:'/ws/signup/process',data:$('#contact-container form').serialize(),type:'post',cache:false,dataType:'json',success:function(data){var msg='';if(true!==data.success){var errs='';for(var x=0;x<data.errors.length;x++){msg+="+ "+String(data.errors[x])+"<br />";}
signup.message=msg;signup.goInvalid();if(data.critical!==true){$('#contact-container .contact-loading').fadeOut(200,function(){$('#contact-container .contact-content').animate({height:h2+150},function(){$('#contact-container .contact-title').html('Send us a Message:');$('#contact-container form#form2').fadeIn(200);});});}else{$('#contact-container .contact-title').html('Unexpected server error!');$('#contact-container .contact-loading').fadeOut(200);}}else{$('#contact-container .contact-loading').fadeOut(200,function(){$('#contact-container .contact-title').html(("Thank you!"));$('#contact-container .contact-message').html(data.msg).fadeIn(200);});}},error:signup.error});});});}else{signup.goInvalid();}};