/*
$(document).ready(function(e) {
	$("#register_form").validate({
		 rules: {
			email: {
		 		required: true,
				email: true,
				remote: {
					url: BASEURL+"login/checkemail",
					type: "post",
					data: {
						email : function() {
							return $("#email").val();	
						}
					}
				}
		 	},
			password: {
				required: true,
				minlength: 5,			
			},
			confirm_password: {
				required: true,
				minlength: 5,
				equalTo: "#password"	
			},
			gender: {
				required : true,	
			},
			terms: {
				required : true,	
			}
		 },
		 messages: {
		 	email: {
				remote: "This email address is already in our database"
			}
		 }
	});
*/
/*	
	$("#register_form_big").validate({
		 rules: {	
			email: {
		 		required: true,
				email: true,
				remote: {
					url: BASEURL+"login/checkemail",
					type: "post",
					data: {
						email : function() {
							return $("#email").val();	
						}
					}
				}
		 	}
		 }
		 
	});

});
*/



function validate_registrate() {

	var valid = true;
	$(".exclamation_label").css("visibility", "hidden");
	
	if($("#firstname").val() == '') {
		$("#firstname_label").css("visibility", "visible");
		valid = false;
	}
	
	if($("#lastname").val() == '') {
		$("#lastname_label").css("visibility", "visible");
		valid = false;
	}
	
	var email = $("#email").val();
	if(!valid_email(email)) {
		$("#email_label").attr("title", "Please enter a valid email address");
		$("#email_label").tooltip();
		$("#email_label").css("visibility", "visible");
		valid = false;
	}
	
	$.ajax({
        url: BASEURL + "login/checkemail",
        type: "post",
        data: {
            email: function(){
                return $("#email").val();
            }
        },
		dataType: 'json',
		success: function(msg){
	    	var good_email = msg.status;
			if(good_email == 10) {
				$("#email_label").css("visibility", "visible");
				$("#email_label").attr("title", "This email already exists in our database");
				$("#email_label").tooltip();
				valid = false;
			} else {
				
			}
	   }
    });
	
	var password = $("#password").val();
	if(password.length < 5) {
		$("#password_label").css("visibility", "visible");
		valid = false;
	}
	
	var confirm_password = $("#confirm_password").val();
	if(confirm_password != password) {
		$("#confirm_password_label").css("visibility", "visible");
		valid = false;
	}
	
	var var_name = $('#terms').attr('checked')?1:0;
	if(var_name == 0){
		$("#terms_label").css("visibility", "visible");
		valid = false;
	}
	
	return valid;	
}

$(document).ready(function(e) {
	
	$("#firstname_label").tooltip();
	$("#lastname_label").tooltip();
	$("#email_label").tooltip();
	$("#password_label").tooltip();
	$("#confirm_password_label").tooltip();
	$("#terms_label").tooltip();
	
	$('#terms_of_service').click(function() {
	
        //$('#terms_of_service_dialog').load(BASEURL+'login/terms_of_service');
		
        $.get(BASEURL+'login/terms_of_service', function(data){            
			$('#terms_of_service_dialog').html(data);
        });

        $('#terms_of_service_dialog').dialog({
            width: 560,
            height: 457,
            draggable: false,
            position: ['center', 110],
            show: 'blind',
			hide: 'blind',
			modal: true,
			'zIndex':5001,
            buttons: {
                'Close': function() {
                    $(this).dialog('close');
                }
            }
        });
        $('#terms_of_service_dialog').dialog('open');
    });
});



