$(document).ready(function() {
	var location = new String(document.location);
	location = location.replace('http://', '');
	var index = location.indexOf('');
	location = location.substring(0, index);
	
    var options = { 
    	url:			location + 'subscribe.php',
        target:        '#subscribe_result',
        beforeSubmit:  showRequestGoogle,
        success:       showResponseGoogle
    }; 
 
    $('#form_subscribe').ajaxForm(options); 
}); 
	
function showRequestGoogle(formData, jqForm, options) {
	if (jqForm.context.is_user.value == "0" && jqForm.context.email.value == "") {
		alert('Please input a email');
		return false;
	}
	
	if (jqForm.context.is_user.value == "0") {
		var email = jqForm.context.email;
	    var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i');
	    if (!reg.test(email.value)) {
	        //email.style.backgroundColor="red";
	        alert('Please input a correct email');
	        email.focus();
	        return false;
	    }
	}
	    
	jqForm.context.Subscribe.disabled = true;
    return true;
} 

function showResponseGoogle(responseText, statusText, xhr, $form) {
	$form.context.Subscribe.disabled = false;
} 

