﻿var map = null;

  $(document).ready(function(){
    $("#contactusform").validate();
  
    
    $("#contactsub").bind("click", function(){
          $("#contactusform").validate().form();
         if($("#contactusform").valid())
         {
             $.post(BaseURL + "/corporate/contactus", { firstname: $('#firstname').attr('value'),
                                            email: $('#email').attr('value'),
                                            phone: $('#phone').attr('value'),
                                            street1: $('#street1').attr('value'),
                                            comments: $('#comments').attr('value'),
                                            contact: $('#contact').attr('value'),
                                            type: $('#type').attr('value'),
                                            city: $('#city').attr('value'),
                                            state: $('#state').attr('value'),
                                            zip: $('#zip').attr('value') }, function(xml) {
                                            
               // format and output result
               if(xml.toString().indexOf('true') > -1)
               {
                     $("#purpleblock").animate({ height: '125px'}, 'slow');
                     $("#contactform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                     $('#results').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
                     if ($.browser.msie) 
                         this.style.removeAttribute('filter'); 
                      });  
                      
                      setTimeout('cancelall()', 5000);
               }
               else
               {
                    $("#purpleblock").animate({ height: '100px'}, 'slow');
                    $("#contactform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
                     if ($.browser.msie) 
                         this.style.removeAttribute('filter'); 
                      });  
                      
                      setTimeout('expandcontactform()', 4000);
                      
                      
               }
               
             });
         }
    });
    
     
  });


function expandcontactform() {

    $('html, body').animate({ scrollTop: 0 }, 400); 
     $("#purpleblock").animate({ height: '380px'}, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     
    $('#resultserror').animate({ height: 'hide', opacity: 'hide' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

     $('#contactform').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

}

function cancelall()
 {
     $("#cancel").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#purpleblock").animate({ height: '35px'}, 'slow');
     $("#contactform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#results").hide();
     $("#resultserror").hide();

     $("#welllink").show('slow'); //animate({ height: 'show', opacity: 'show' }, 'slow');

}
