$(function(){
		//save the data from customer tab
		$("button[name='__submit']").live('click', function(){			
			A25Core.__validate('.contact_form', 'contact-us/json-validate', function(resp){
                               if (resp.success){
                                        
					A25Core.iframeAjax('.contact_form', 'contact-us/ajax-send-email',{}, function(resp){
                                            if (resp.success){
//                                                $('#dialog').html('Email with the address : ' + resp.email + ' has been send');
                                                $('#firstname').val('');
                                                $('#address').val('');
                                                $('#state').val('');
                                                $('#email').val('');
                                                $('#lastname').val('');
                                                $('#city').val('');
                                                $('#zip').val('');
                                                $('#comments').val('');
                                                $('#phone').val('');
                                                $('#security_code').val('');                                             
                                                $('#dialog').dialog({
                                                    autoOpen: false,
                                                    width: 600,
                                                    model:true,
                                                    buttons: {
                                                            "Ok": function() {                                                                
                                                                $(this).dialog("close");
                                                            }
                                                    }
                                                });
                                                $('#dialog').dialog('open');
//											alert("Email has been sent");
                                            }
                                        });
				} else {
					$('.security #theimage').html('<img src="captcha/CaptchaSecurityImages.php?width=100&height=40&characters=6&'+ Math.random() * 3 +'" alt="CaptchaSecurityImages" />');
					$('#security_code').val('');
                    $.each(resp.errors,function(k,value){
                        $("input[name='" +k +"']").parent().parent().find('em').html(value);
                        $("select[name='"+ k + "']").parent().parent().find('em').html(value);                                        
                    });
                }
			});
			return false;
		});
		
		
		/**/
		$("button[name='__submitemail1']").live('click', function(){	
			   
			A25Core.__validate('.email_form', 'property-search/json-validate-email', function(resp){
				
                 if (resp.success){                                        
					A25Core.iframeAjax('.email_form', 'property-search/requestinformation',{}, function(resp){
                                            if (resp.success){
                                                $('input[name=firstname]').val('');
                                                $('input[name=phone]').val('');
                                                $('input[name=email]').val('');
                                                $('input[name=lastname]').val('');
                                                $('textarea[name=comments]').val('');
                                                
//												alert("Message Sent");
                                                $('#dialog').dialog({
                                                    autoOpen: false,
                                                    width: 600,
                                                    model:true,
                                                    buttons: {
                                                            "Ok": function() {                                                                
                                                                $(this).dialog("close");
                                                            }
                                                    }
                                                });
                                                $('#dialog').dialog('open');
                                                
												$('#fancybox-close').trigger('click');
												$('#fancybox-overlay').trigger('click');
	                                            }
                                        });
				} else {
                                    $.each(resp.errors,function(k,value){
                                        $("input[name='" +k +"']").parent().parent().find('em').html(value);
                                        $("select[name='"+ k + "']").parent().parent().find('em').html(value);                                        
                                    });
                                }
			});
			return false;
		});
		
		$("button[name='__submitemaill2']").live('click', function(){	
			   
			A25Core.__validate('.email_form', 'property-search/json-validate-email', function(resp){
			
                 if (resp.success){                                        
					A25Core.iframeAjax('.email_form', 'property-search/showing',{}, function(resp){
                                            if (resp.success){
                                                $('input[name=firstname]').val('');
												$('input[name=phone]').val('');
												$('input[name=email]').val('');
												$('input[name=lastname]').val('');
												$('textarea[name=comments]').val('');                                              
                                              
//												alert("Message Sent");
												$('#dialog').dialog({
                                                    autoOpen: false,
                                                    width: 600,
                                                    model:true,
                                                    buttons: {
                                                            "Ok": function() {                                                                
                                                                $(this).dialog("close");
                                                            }
                                                    }
                                                });
                                                $('#dialog').dialog('open');
												
												$('#fancybox-close').trigger('click');
												$('#fancybox-overlay').trigger('click');
	                                            }
                                        });
				} else {
                                    $.each(resp.errors,function(k,value){
                                        $("input[name='" +k +"']").parent().parent().find('em').html(value);
                                        $("select[name='"+ k + "']").parent().parent().find('em').html(value);                                        
                                    });
                                }
			});
			return false;
		});
});
