function checkValidZip(events)
{var unicodes=events.charCode?events.charCode:events.keyCode;if((unicodes>47&&unicodes<58)||(unicodes==8)||(unicodes==32)||(unicodes==37)||(unicodes==39))
return true;else
return false;}
function checkValidPhone(events)
{var unicodes=events.charCode?events.charCode:events.keyCode;if((unicodes>47&&unicodes<58)||(unicodes==8)||(unicodes==9)||(unicodes==32)||(unicodes==37)||(unicodes==39)||(unicodes==40)||(unicodes==41)||(unicodes==43)||(unicodes==45)||(unicodes==46))
return true;else
return false;}
function getCity(text,li)
{var id=li.id;document.getElementsByName('city_hidden').value=id;alert(id)}
function updateStates(countryId)
{var options='';new Ajax.Request('/states/getStateListXML',{method:'post',postBody:'countryId='+countryId,onComplete:function(states){noOfStates=states.responseXML.getElementsByTagName('id').length;$('states').options.length=noOfStates;for(i=0;i<noOfStates;i++)
{if(states.responseXML.getElementsByTagName('id')[i])
{stateId=states.responseXML.getElementsByTagName('id')[i].firstChild.data;}
else
{stateId='';}
if(states.responseXML.getElementsByTagName('name')[i])
{stateName=states.responseXML.getElementsByTagName('name')[i].firstChild.data;}
else
{stateName='';}
$('states').options[i].value=stateId;$('states').options[i].text=stateName;}}});}
function addCustomer()
{custType=$('customerType').value;new Ajax.Request('/customers/addCustomer',{method:'post',parameters:$("addCustomerForm").serialize(),onComplete:function(customer){xmlResponse=customer.responseXML;if(xmlResponse.getElementsByTagName('result')[0])
{customerId=parseInt(xmlResponse.getElementsByTagName('result')[0].firstChild.data);if(customerId&&customerId>0)
{Dialog.cancelCallback();enableScrolling();getCustomerAddress(custType,customerId)}}
else
{if(xmlResponse.getElementsByTagName('customerName')[0])
{$('customerNameError').innerHTML=xmlResponse.getElementsByTagName('customerName')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('address1')[0])
{$('address1Error').innerHTML=xmlResponse.getElementsByTagName('address1')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('address2')[0])
{$('address2Error').innerHTML=xmlResponse.getElementsByTagName('address2')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('countries')[0])
{$('countriesError').innerHTML=xmlResponse.getElementsByTagName('countries')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('states')[0])
{$('statesError').innerHTML=xmlResponse.getElementsByTagName('states')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('city')[0])
{$('cityError').innerHTML=xmlResponse.getElementsByTagName('city')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('zip')[0])
{$('zipError').innerHTML=xmlResponse.getElementsByTagName('zip')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('phone')[0])
{$('phoneError').innerHTML=xmlResponse.getElementsByTagName('phone')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('monday1')[0].firstChild.data!='')
{$('timeErrMsg').innerHTML=xmlResponse.getElementsByTagName('monday1')[0].firstChild.data;$('timeErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('monday2')[0].firstChild.data!='')
{$('timeErrMsg').innerHTML=xmlResponse.getElementsByTagName('monday2')[0].firstChild.data;$('timeErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('monday')[0].firstChild.data!='')
{$('timeErrMsg').innerHTML=xmlResponse.getElementsByTagName('monday')[0].firstChild.data;$('timeErrMsg').style.display="block";}
else
{$('timeErrMsg').style.display="none";}
if(xmlResponse.getElementsByTagName('tuesday1')[0].firstChild.data!='')
{$('timeTuesdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('tuesday1')[0].firstChild.data;$('timeTuesdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('tuesday2')[0].firstChild.data!='')
{$('timeTuesdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('tuesday2')[0].firstChild.data;$('timeTuesdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('tuesday')[0].firstChild.data!='')
{$('timeTuesdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('tuesday')[0].firstChild.data;$('timeTuesdayErrMsg').style.display="block";}
else
{$('timeTuesdayErrMsg').style.display="none";}
if(xmlResponse.getElementsByTagName('wednesday1')[0].firstChild.data!='')
{$('timeWednesdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('wednesday1')[0].firstChild.data;$('timeWednesdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('wednesday2')[0].firstChild.data!='')
{$('timeWednesdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('wednesday2')[0].firstChild.data;$('timeWednesdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('wednesday')[0].firstChild.data!='')
{$('timeWednesdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('wednesday')[0].firstChild.data;$('timeWednesdayErrMsg').style.display="block";}
else
{$('timeWednesdayErrMsg').style.display="none";}
if(xmlResponse.getElementsByTagName('thursday1')[0].firstChild.data!='')
{$('timeThursdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('thursday1')[0].firstChild.data;$('timeThursdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('thursday2')[0].firstChild.data!='')
{$('timeThursdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('thursday2')[0].firstChild.data;$('timeThursdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('thusday')[0].firstChild.data!='')
{$('timeThursdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('thusday')[0].firstChild.data;$('timeThursdayErrMsg').style.display="block";}
else
{$('timeThursdayErrMsg').style.display="none";}
if(xmlResponse.getElementsByTagName('friday1')[0].firstChild.data!='')
{$('timeFridayErrMsg').innerHTML=xmlResponse.getElementsByTagName('friday1')[0].firstChild.data;$('timeFridayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('friday2')[0].firstChild.data!='')
{$('timeFridayErrMsg').innerHTML=xmlResponse.getElementsByTagName('friday2')[0].firstChild.data;$('timeFridayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('friday')[0].firstChild.data!='')
{$('timeFridayErrMsg').innerHTML=xmlResponse.getElementsByTagName('friday')[0].firstChild.data;$('timeFridayErrMsg').style.display="block";}
else
{$('timeFridayErrMsg').style.display="none";}
if(xmlResponse.getElementsByTagName('saturday1')[0].firstChild.data!='')
{$('timeSaturdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('saturday1')[0].firstChild.data;$('timeSaturdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('saturday2')[0].firstChild.data!='')
{$('timeSaturdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('saturday2')[0].firstChild.data;$('timeSaturdayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('saterday')[0].firstChild.data!='')
{$('timeSaturdayErrMsg').innerHTML=xmlResponse.getElementsByTagName('saterday')[0].firstChild.data;$('timeSaturdayErrMsg').style.display="block";}
else
{$('timeSaturdayErrMsg').style.display="none";}
if(xmlResponse.getElementsByTagName('sunday1')[0].firstChild.data!='')
{$('timeSundayErrMsg').innerHTML=xmlResponse.getElementsByTagName('sunday1')[0].firstChild.data;$('timeSundayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('sunday2')[0].firstChild.data!='')
{$('timeSundayErrMsg').innerHTML=xmlResponse.getElementsByTagName('sunday2')[0].firstChild.data;$('timeSundayErrMsg').style.display="block";}
else if(xmlResponse.getElementsByTagName('sunday')[0].firstChild.data!='')
{$('timeSundayErrMsg').innerHTML=xmlResponse.getElementsByTagName('sunday')[0].firstChild.data;$('timeSundayErrMsg').style.display="block";}
else
{$('timeSundayErrMsg').style.display="none";}
$('divTop').style.display="none";$('divBottom').style.display="none";}}});}
function updateCustomer()
{custType=$('customerType').value;customerId=$('hidden_customerId').value;new Ajax.Request('/customers/updateCustomer',{method:'post',parameters:$('addCustomerForm').serialize(),onComplete:function(customer){xmlResponse=customer.responseXML;if(xmlResponse.getElementsByTagName('result')[0])
{result=parseInt(xmlResponse.getElementsByTagName('result')[0].firstChild.data);if(result==1)
{Dialog.cancelCallback();enableScrolling();getCustomerAddress(custType,customerId)}}
else
{if(xmlResponse.getElementsByTagName('customerName')[0])
{$('customerNameError').innerHTML=xmlResponse.getElementsByTagName('customerName')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('address1')[0])
{$('address1Error').innerHTML=xmlResponse.getElementsByTagName('address1')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('address2')[0])
{$('address2Error').innerHTML=xmlResponse.getElementsByTagName('address2')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('countries')[0])
{$('countriesError').innerHTML=xmlResponse.getElementsByTagName('countries')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('states')[0])
{$('statesError').innerHTML=xmlResponse.getElementsByTagName('states')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('city')[0])
{$('cityError').innerHTML=xmlResponse.getElementsByTagName('city')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('zip')[0])
{$('zipError').innerHTML=xmlResponse.getElementsByTagName('zip')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('phone')[0])
{$('phoneError').innerHTML=xmlResponse.getElementsByTagName('phone')[0].firstChild.data;}
if(xmlResponse.getElementsByTagName('monday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('monday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('monday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('monday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('monday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('monday')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('tuesday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('tuesday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('tuesday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('tuesday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('tuesday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('tuesday')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('wednesday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('wednesday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('wednesday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('wednesday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('wednesday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('wednesday')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('thursday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('thursday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('thursday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('thursday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('thusday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('thusday')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('friday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('friday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('friday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('friday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('friday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('friday')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('saturday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('saturday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('saturday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('saturday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('saterday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('saterday')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('sunday1')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('sunday1')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('sunday2')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('sunday2')[0].firstChild.data;}
else if(xmlResponse.getElementsByTagName('sunday')[0].firstChild.data!='')
{$('loadingTimeErrMsg').innerHTML=xmlResponse.getElementsByTagName('sunday')[0].firstChild.data;}
else
{$('loadingTimeErrMsg').innerHTML='';}
$('divTop').style.display="none";$('divBottom').style.display="none";}}});}
function check_time(orig_str)
{var _reg=new RegExp(/^([0-9]|[0-1][0-9]|2[0-3]):[0-5][0-9]$/);return _reg.test(orig_str);}
function copyTime()
{check_time($('loadingMonday1').value)
if(!check_time($('loadingMonday1').value)||!check_time($('loadingMonday2').value))
{$('timeErrMsg').innerHTML='Enter a valid time';return;}
else
{$('timeErrMsg').innerHTML='';$('loadingTuesday1').value=$('loadingMonday1').value;$('loadingTuesday2').value=$('loadingMonday2').value;$('loadingWednesday1').value=$('loadingMonday1').value;$('loadingWednesday2').value=$('loadingMonday2').value;$('loadingThursday1').value=$('loadingMonday1').value;$('loadingThursday2').value=$('loadingMonday2').value;$('loadingFriday1').value=$('loadingMonday1').value;$('loadingFriday2').value=$('loadingMonday2').value;}}
function displayCustomerData(customerType)
{if(customerType==1)
{customerId=$('originCustomerId').value;$('hidden_customerId').value=customerId;$('customerName').value=$('originCustomers').value;$('address1').value=$('originAddressOne').value;$('address2').value=$('originAddressTwo').value;var originCountryCode=$('originCountry').value;new Ajax.Request('/countries/getCountryId',{method:'post',postBody:'countryCode='+originCountryCode,onComplete:function(countryId)
{$('countries').value=parseInt(countryId.responseText);}});originStateCode=$('originState').value;new Ajax.Request('/states/getStateId',{method:'post',postBody:'stateCode='+originStateCode,onComplete:function(stateId)
{$('states').value=parseInt(stateId.responseText);}});$('city').value=$('originCity').value;$('zip').value=$('originZip').value;$('phone').value=$('originPhoneNumber').value;$('appointmentRequired').checked=$('appointmentRequiredOrigin').checked;}
else if(customerType==2)
{customerId=$('destinationCustomerId').value;$('hidden_customerId').value=customerId;$('customerName').value=$('destinationCustomers').value;$('address1').value=$('destinationAddressOne').value;$('address2').value=$('destinationAddressTwo').value;destCountryCode=$('destinationCountry').value;new Ajax.Request('/countries/getCountryId',{method:'post',postBody:'countryCode='+destCountryCode,onComplete:function(countryId)
{$('countries').value=parseInt(countryId.responseText);}});destStateCode=$('destinationState').value;new Ajax.Request('/states/getStateId',{method:'post',postBody:'stateCode='+destStateCode,onComplete:function(stateId)
{$('states').value=parseInt(stateId.responseText);}});$('city').value=$('destinationCity').value;$('zip').value=$('destinationZip').value;$('phone').value=$('destinationPhoneNumber').value;$('appointmentRequired').checked=$('appointmentRequiredDest').checked;}
new Ajax.Request('/customers/getLoadingHours',{method:'post',postBody:'custId='+customerId,onComplete:function(ladingHours)
{loadingHourDetails=new Array();loadingHourDetails=ladingHours.responseText.split(",");$('loadingMonday1').value=loadingHourDetails[0];$('loadingMonday2').value=loadingHourDetails[1];$('loadingTuesday1').value=loadingHourDetails[2];$('loadingTuesday2').value=loadingHourDetails[3];$('loadingWednesday1').value=loadingHourDetails[4];$('loadingWednesday2').value=loadingHourDetails[5];$('loadingThursday1').value=loadingHourDetails[6];$('loadingThursday2').value=loadingHourDetails[7];$('loadingFriday1').value=loadingHourDetails[8];$('loadingFriday2').value=loadingHourDetails[9];$('loadingSaturday1').value=loadingHourDetails[10];$('loadingSaturday2').value=loadingHourDetails[11];$('loadingSunday1').value=loadingHourDetails[12];$('loadingSunday2').value=loadingHourDetails[13];}});}
function searchCustomer()
{var custname=$('customerName').value;var stateId=$('states').value;var stateCode='';if(stateId!='')
{new Ajax.Request('/states/getStateCode',{asynchronous:false,method:'post',postBody:'stateId='+stateId,onComplete:function(statecode)
{stateCode=statecode.responseText;}})}
var passval=$('city').value+' '+stateCode+' '+$('zip').value;var url='http://yellowpages.superpages.com/listings.jsp?C=&N='+custname+'&STYPE=S&CID=&scale=&lng=&lat=&L='+passval+'&search=Find+It';window.open(url);}
function getCustonerDetailsToEdit(custId)
{var custId=(custId==null)?$('hidden_customerId').value:custId;var selectedCompanyName;var selectedAddress1;var selectedAddress2;var selectedCity;var selectedState;var selectedCountry;var selectedZip;var selectedPhone;var appointment;var from='link';var address=new Ajax.Request('/customers/getSelectedCustometrDetails',{asynchronous:false,method:'post',postBody:'selectedId='+custId+'&from='+from,onComplete:function(CustomerDetails){if(CustomerDetails.responseXML.getElementsByTagName('companyName')[0].firstChild!=null)
{selectedCompanyName=CustomerDetails.responseXML.getElementsByTagName('companyName')[0].firstChild.data;}
else
{selectedCompanyName='';}
if(CustomerDetails.responseXML.getElementsByTagName('address1')[0].firstChild!=null)
{selectedAddress1=CustomerDetails.responseXML.getElementsByTagName('address1')[0].firstChild.data;}
else
{selectedAddress1='';}
if(CustomerDetails.responseXML.getElementsByTagName('address2')[0].firstChild!=null)
{selectedAddress2=CustomerDetails.responseXML.getElementsByTagName('address2')[0].firstChild.data;}
else
{selectedAddress2='';}
if(CustomerDetails.responseXML.getElementsByTagName('city')[0].firstChild!=null)
{selectedCity=CustomerDetails.responseXML.getElementsByTagName('city')[0].firstChild.data;}
else
{selectedCity='';}
if(CustomerDetails.responseXML.getElementsByTagName('state')[0].firstChild!=null)
{selectedState=CustomerDetails.responseXML.getElementsByTagName('state')[0].firstChild.data;}
else
{selectedState='';}
if(CustomerDetails.responseXML.getElementsByTagName('country')[0].firstChild!=null)
{selectedCountry=CustomerDetails.responseXML.getElementsByTagName('country')[0].firstChild.data;}
else
{selectedCountry='';}
if(CustomerDetails.responseXML.getElementsByTagName('zip')[0].firstChild!=null)
{selectedZip=CustomerDetails.responseXML.getElementsByTagName('zip')[0].firstChild.data;}
else
{selectedZip='';}
if(CustomerDetails.responseXML.getElementsByTagName('phone')[0].firstChild!=null)
{selectedPhone=CustomerDetails.responseXML.getElementsByTagName('phone')[0].firstChild.data;}
else
{selectedPhone='';}
if(CustomerDetails.responseXML.getElementsByTagName('appointment')[0].firstChild!=null)
{appointment=CustomerDetails.responseXML.getElementsByTagName('appointment')[0].firstChild.data;}
else
{appointment='';}}})
$('hidden_customerId').value=custId;$('customerName').value=selectedCompanyName
$('address1').value=selectedAddress1;$('address2').value=selectedAddress2;$('countries').value=selectedCountry;$('states').value=selectedState;$('city').value=selectedCity;$('zip').value=selectedZip;$('phone').value=selectedPhone;if(appointment=='Yes')
{$('appointmentRequired').checked=true;}
else
{$('appointmentRequired').checked=false;}
$('captionDiv').innerHTML="Edit Customer";new Ajax.Request('/customers/getLoadingHours',{method:'post',postBody:'custId='+custId,onComplete:function(ladingHours)
{loadingHourDetails=new Array();loadingHourDetails=ladingHours.responseText.split(",");$('loadingMonday1').value=loadingHourDetails[0];$('loadingMonday2').value=loadingHourDetails[1];$('loadingTuesday1').value=loadingHourDetails[2];$('loadingTuesday2').value=loadingHourDetails[3];$('loadingWednesday1').value=loadingHourDetails[4];$('loadingWednesday2').value=loadingHourDetails[5];$('loadingThursday1').value=loadingHourDetails[6];$('loadingThursday2').value=loadingHourDetails[7];$('loadingFriday1').value=loadingHourDetails[8];$('loadingFriday2').value=loadingHourDetails[9];$('loadingSaturday1').value=loadingHourDetails[10];$('loadingSaturday2').value=loadingHourDetails[11];$('loadingSunday1').value=loadingHourDetails[12];$('loadingSunday2').value=loadingHourDetails[13];}});$('addDiv').style.display='none';$('updateDiv').style.display='inline';$('addCustomerForm').action='/customers/updateCustomer';}
