// JavaScript Document

/* Method 1st
------------------------------------------------------------------------------------*/
function contact(){	
    var name    = $('#contact_name').val();
    var email   = $('#contact_email').val();
    var subject   = $('#contact_subject').val();
    var message = $('#contact_text').val();
    var to = $('#to').val();

    if(name == ''){
        alert('Nhập họ và tên');
        return false;
    }
    if(email == ''){
    	alert('Nhập email');
        return false;
    }else if(!is_email(email)){
    	alert('Email không đúng định dạng');
        return false;
    }
    if(subject == ''){
        alert('Nhập chủ đề');
        return false;
    }
    if(message == ''){
    	alert('Nhập nội dung email');
    	return false;
    }
    
    jQuery.ajax({
        type: "POST",
        url: "module/ajax/contact-mail.php",
        cache:false,
        data: ({                                
        	name: name,
            email: email,
            to: to,
            subject: subject,
            message: message
          }),     
        beforeSend:function(){
        	jQuery("#loading").html('<img width="20px" src="loading.gif" />');
        },   
        success:function(b){
        	jQuery("#result").html(b);  
        	jQuery('#loading').hide();                
        }
    });
    return false;
}
function is_email(str) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var check = reg.test(str);
	return check;
}
