﻿
function checkPhone1(){if(!checkAndFormat($('#phone1'))){return[[$('#phone1').get(0),"Please enter a 10-digit primary phone number."]];}
return true;}
function checkPhone2(){var p2=$('#phone2');if(p2.val()!=''){if(!checkAndFormat(p2)){return[[p2.get(0),"Please enter a 10-digit alternate phone number (or leave blank)."]];}}
return true;}
function checkAndFormat(phone){var strPhone=phone.val().replace(/\D/g,'');if(strPhone.length!=10){return false;}
phone.val("("+strPhone.substr(0,3)+") "+strPhone.substr(3,3)+"-"+strPhone.substr(6));return true;}
$(document).ready(function(){$('#noscript').hide();if(!GBrowserIsCompatible()){$('#nogmaps').show();return;}
$('#step1').show();$(document).unload(GUnload);var map=null;var routes=new Routes();var openMap=function(){var map=new GMap2(document.getElementById("map"));map.addControl(new GSmallMapControl());map.setCenter(new GLatLng(29.97924,-90.12485000000001),11);map.enableContinuousZoom();map.enableDoubleClickZoom();$.each(routes,function(i,val){val.route=i.replace(/\D/g,'');map.addOverlay(val);var label=new ELabel(val.getBounds().getCenter(),val.route,"maplabel",new GSize(-6,10));map.addOverlay(label);});return map;};var getStartDate=function(){var val=$('#firstPickup').val();try{return Date.parse(val).addHours(12);}catch(err){return Date.parse("01-01-2001");}};var createContact=function(){return{Company:$('#company').val(),Title:$('#title').val(),FirstName:$('#firstName').val(),LastName:$('#lastName').val(),Suffix:$('#suffix').val(),Phone1:$('#phone1').val(),Phone1Ext:$('#phone1ext').val(),Phone2:$('#phone2').val(),Phone2Ext:$('#phone2ext').val(),Email:$('#email1').val(),Password:$('#password').val(),EmailAddress2:$('#email2').val(),StreetNumber:$('#streetNumber').val(),StreetAddress1:$('#streetAddress').val(),StreetAddress2:$('#apt').val(),City:$('#city').val(),State:$('#state').val(),PostalCode:$('#zip').val(),NAssoc:$('#association').val(),RouteNotes:$('#specialInstructions').val(),RouteId:$('#route').val(),FirstCollectionDate:getStartDate(),__type:"PhoenixRecycling.Billing.Contact"};}
var processGeocode=function(resp){if(!resp||(resp.Status.code!=G_GEO_SUCCESS)){alert("We could not locate the address you entered. Please make sure that you have entered your address completely and without errors.");$('#step2').hide();$('#step1').show();return;}
if(resp.Placemark.length>1){alert("We could not unambiguously resolve the address you entered. Please make sure that you have entered your address completely and without errors.");$('#step2').hide();$('#step1').show();return;}
var place=resp.Placemark[0];try{var localityName=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;if((localityName)&&(localityName!=$('#city').val())){$('#city').val(localityName);}}catch(x){}
try{var postalCode=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;if((postalCode)&&(postalCode!=$('#zip').val())){$('#zip').val(postalCode);}}catch(x){}
var center=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);var marker=new GMarker(center);map.addOverlay(marker);map.setCenter(center,14);var hits=new Array();$.each(routes,function(i,val){if(val.getBounds().containsLatLng(center)){hits.push(val);}});var hit=null;$.each(hits,function(i,val){if(val.containsLatLng(center)){hit=val;}});if(!hit){var contact=createContact();$.jmsajax({type:"POST",url:"crm/SignUp.asmx",method:"AddProspect",dataType:"msjson",data:{c:contact},success:function(data){$('#custInfo').html("<b>"+contact.FirstName+" "+contact.LastName+"</b><br/>"
+contact.StreetNumber+" "+contact.StreetAddress1+"<br/>"
+contact.City+", "+contact.State+" "+contact.PostalCode);marker.openInfoWindowHtml($('#custInfo').html());$('#routeNotOK').show();},error:function(XMLHttpRequest,textStatus,errorThrown){$('#test').html(textStatus);}});return;}
var loadCalendar=function(calendarUrl,routeId){var service=new
google.gdata.calendar.CalendarService('phoenix-sign-up');var query=new google.gdata.calendar.CalendarEventQuery(calendarUrl);query.setOrderBy('starttime');query.setSortOrder('ascending');query.setMinimumStartTime(new google.gdata.DateTime(Date.today().add(2).days(),true));query.setSingleEvents(true);query.setMaxResults(3);query.setFullTextQuery('Route '+routeId);service.getEventsFeed(query,function(feedRoot){var sel=$('#firstPickup');sel.html('');$.each(feedRoot.feed.getEntries(),function(i,entry){var times=entry.getTimes();if(times.length>0){var startDate=times[0].getStartTime().getDate();sel.append("<option value='"+startDate.toString('MM-dd-yyyy')+"'>"+startDate.toString('M/d/yyyy (dddd)')+"</option>");}});},function(e){alert(e.toString());});};loadCalendar('http://www.google.com/calendar/feeds/phoenixrecyclingnola.com_2se7jk0oruoj689l8334bkovb4%40group.calendar.google.com/public/full',hit.route);$('#route').val(hit.route);$('.rt').html(hit.route);var cust=createContact();$('#custInfo').html("<b>"+cust.FirstName+" "+cust.LastName+"</b><br/>"
+cust.StreetNumber+" "+cust.StreetAddress1+"<br/>"
+cust.City+", "+cust.State+" "+cust.PostalCode);$('#routeOK').show();marker.openInfoWindowHtml($('#custInfo').html());};$(document.forms[0]).RSV({onCompleteHandler:function(){$('#step1').hide();$('#step2').show();map=openMap();var addr=$('#streetNumber').val()+" "+$('#streetAddress').val()+", "+$('#city').val()+", "+$('#state').val()+" "+$('#zip').val();var geocoder=new GClientGeocoder();geocoder.getLocations(addr,processGeocode);return false;},errorFieldClass:"error",rules:["required,firstName,Please enter your first name.","required,lastName,Please enter your last name.","required,email1,Please enter your email address.","valid_email,email1,Please enter a valid email address.","valid_email,email2,Please enter a valid alternate email address (or leave blank).","required,phone1,Please enter your primary phone number","function,checkPhone1","digits_only,phone1ext,Please enter only numbers for your primary extension.","function,checkPhone2","digits_only,phone2ext,Please enter only numbers for your alternate extension.","required,streetNumber,Please enter your pick-up street number.","required,streetAddress,Please enter your pick-up street name.","required,city,Please enter the city for your pick-up address.","required,zip,Please enter your five-digit zip code.","digits_only,zip,Please enter your five-digit zip code."]});$('.back2step1').click(function(){$('#step2').hide();$('#signupErrorMessage').html('');$('.signupError').hide();$('#routeOK').hide();$('#routeNotOK').hide();$('#route').val('43');$('.rt,#custInfo').html('');$('#firstPickup').html('');$('#step1').show();});$('#agree').click(function(evt){evt.preventDefault();var contact=createContact();$.jmsajax({type:"POST",url:"crm/SignUp.asmx",method:"AddCustomer",dataType:"msjson",data:{c:contact},success:function(data){if(data.success){$('.dt').html(getStartDate().toString('dddd, MMMM dd'));$('.step').hide();$('#signupErrorMessage').html('');$('.signupError').hide();$('#step3').show();}else{$('#signupErrorMessage').html(data.message);$('.signupError').show();}},error:function(XMLHttpRequest,textStatus,errorThrown){$('#error').show();}});});});