
	var username_error = true;
	var student_name_error = true;
	var parent_name_error = true;
	var parent_email_error = true;
	var mobile_prefix_error = true;
	var mobile_error = true;
	var school_name_error = true;
	var std_id_error = true;
	var password_error = true;
	var address_error = true;
	var district_error = true;
	var state_error = true;
	var taluka_error = true;
	var city_error = true;
	var pin_code_error = true;


	function username_check()
	{
		var username = $('#username').val();
		if (username.length == '') 
		{
			$('#username_check').show();
			$('#username_check').html('The username field is required');
			username_error = false;
		}
		else
		{
			$.ajax({
	            url: base_url+'home/check_username_available', // point to server-side controller method
	            data: {username:username},
	            type: 'post',
	            dataType:'json',
	            success: function (response) {

	                if(response == 0)
                    {
                       	$('#username_check').show();
                        $('#username_check').html('<span style="color:green;">Available</span>');
                        username_error = true;
                    }
                    else
                    {
                       	$('#username_check').show();
                        $('#username_check').html('This username is already exist.');
                        username_error = false;
                    }
	            },
	            
	        });
		}
	}


	function student_name_check()
	{
		var student_name = $('#student_name').val();
		if (student_name.length == '') 
		{
			$('#student_name_check').show();
			$('#student_name_check').html('The student name field is required');
			student_name_error = false;
		}
		else
		{
			$('#student_name_check').hide();
			student_name_error = true;
		}
	}


	function parent_name_check()
	{
		var parent_name = $('#parent_name').val();
		if (parent_name.length == '') 
		{
			$('#parent_name_check').show();
			$('#parent_name_check').html('The parent name field is required');
			parent_name_error = false;
		}
		else
		{
			$('#parent_name_check').hide();
			parent_name_error = true;
		}
	}

	function parent_email_check()
	{
		var mailformat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var parent_email = $('#parent_email').val();
        if (parent_email.length == '') 
        {
            $('#parent_email_check').show();
            $('#parent_email_check').html('The email field is required');
            parent_email_error = false;
        }
        else
        {
            if(mailformat.test(parent_email) == false)
	        {
	            $('#parent_email_check').show();
	            $('#parent_email_check').html('Please Enter Valid Email Format.');
	            parent_email_error = false;
	        }
	        else
	        {
	            $.ajax({
	                url: base_url+'home/check_email_available', // point to server-side controller method
	                data: {parent_email:parent_email},
	                type: 'post',
	                dataType:'json',
	                success: function (response) {

	                    if(response == 0)
	                    {
	                        $('#parent_email_check').show();
	                        $('#parent_email_check').html('<span style="color:green;">Available</span>');
	                        parent_email_error = true;
	                    }
	                    else
	                    {
	                        $('#parent_email_check').show();
	                        $('#parent_email_check').html('This Email is already exist.');
	                        parent_email_error = false;
	                    }
	                },
	                
	            }); 
	        } 
        }          

	}


	function mobile_prefix_check()
	{
		var mobile_prefix = $('#mobile_prefix').val();
		if (mobile_prefix.length == '') 
		{
			$('#mobile_prefix_check').show();
			$('#mobile_prefix_check').html('The mobile prefix field is required');
			mobile_prefix_error = false;
		}
		else
		{
			$('#mobile_prefix_check').hide();
			mobile_prefix_error = true;
		}
	}


	function mobile_check()
	{
		var mobile = $('#mobile').val();
		if (mobile.length == '') 
		{
			$('#mobile_check').show();
			$('#mobile_check').html('The mobile field is required');
			mobile_error = false;
		}
		else
		{
			$.ajax({
	            url: base_url+'home/check_mobile_available', // point to server-side controller method
	            data: {mobile:mobile},
	            type: 'post',
	            dataType:'json',
	            success: function (response) {
	                
	                if(response == 0)
                    {
                        $('#mobile_check').show();
                        $('#mobile_check').html('<span style="color:green;">Available</span>');
                        mobile_error = true;
                    }
                    else
                    {
                        $('#mobile_check').show();
                        $('#mobile_check').html('This mobile no is already exist.');
                        mobile_error = false;
                    }
	            },
	            
	        });
		}
	}


	function school_name_check()
	{
		var school_name = $('#school_name').val();
		if (school_name.length == '') 
		{
			$('#school_name_check').show();
			$('#school_name_check').html('The school name field is required');
			school_name_error = false;
		}
		else
		{
			$('#school_name_check').hide();
			school_name_error = true;
		}
	}

	function std_id_check()
	{
		var std_id = $('#std_id').val();
		if (std_id.length == '') 
		{
			$('#std_id_check').show();
			$('#std_id_check').html('The standard field is required');
			std_id_error = false;
		}
		else
		{
			$('#std_id_check').hide();
			std_id_error = true;
		}
	}

	function password_check()
	{
		var password = $('#password').val();
		if (password.length == '') 
		{
			$('#password_check').show();
			$('#password_check').html('The password field is required');
			password_error = false;	
		}
		else
		{
			$('#password_check').hide();
			password_error = true;	
		}
	}

	function address_check()
	{
		var address = $('#address').val();
		if (address.length == '') 
		{
			$('#address_check').show();
			$('#address_check').html('The address field is required');
			address_error = false;
		}
		else
		{
			$('#address_check').hide();
			address_error = true;
		}
	}

	function district_check()
	{
		var district = $('#district').val();
		if (district.length == '') 
		{
			$('#district_check').show();
			$('#district_check').html('The district field is required');
			district_error = false;
		}
		else
		{
			$('#district_check').hide();
			district_error = true;
		}
	}

	function state_check()
	{
		var state = $('#state').val();
		if (state.length == '') 
		{
			$('#state_check').show();
			$('#state_check').html('The state field is required');
			state_error = false;
		}
		else
		{
			$('#state_check').hide();
			state_error = true;
		}
	}

	function taluka_check()
	{
		var taluka = $('#taluka').val();
		if (taluka.length == '') 
		{
			$('#taluka_check').show();
			$('#taluka_check').html('The taluka field is required');
			taluka_error = false;		}
		else
		{
			$('#taluka_check').hide();
			taluka_error = true;		
		}
	}


	function city_check()
	{
		var city = $('#city').val();
		if (city.length == '') 
		{
			$('#city_check').show();
			$('#city_check').html('The city field is required');
			city_error = false;
		}
		else
		{
			$('#city_check').hide();
			city_error = true;
		}
	}
	
	function pin_code_check()
	{
		var pin_code = $('#pin_code').val();
		if (pin_code.length == '') 
		{
			$('#pin_code_check').show();
			$('#pin_code_check').html('The pin code field is required');
			pin_code_error = false;
		}
		else
		{
			$('#pin_code_check').hide();
			pin_code_error = true;
		}
	}

// -------------------------------------------------------------------------------


	function validateForm() 
	{
		username_check();
		student_name_check();
		parent_name_check();
		parent_email_check();
		mobile_prefix_check();
		mobile_check();
		school_name_check();
		std_id_check();
		password_check();
		address_check();
		district_check();
		state_check();
		taluka_check();
		city_check();
		pin_code_check();

		if ((username_error == true) && (student_name_error == true) && (parent_name_error == true) && 
			(parent_email_error == true) && (mobile_prefix_error == true) && (mobile_error == true) && 
			(school_name_error == true) && (std_id_error == true) && (password_error == true) && 
			(address_error == true) && (district_error == true) && (state_error == true) && 
			(taluka_error == true) && (city_error == true) && (pin_code_error == true)) 
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
// -------------------------------------------------------------------------------



$(document).ready(function($) {

	$('#username_check').hide();
	$('#student_name_check').hide();
	$('#parent_name_check').hide();
	$('#parent_email_check').hide();
	$('#mobile_prefix_check').hide();
	$('#mobile_check').hide();
	$('#school_name_check').hide();
	$('#std_id_check').hide();
	$('#password_check').hide();
	$('#address_check').hide();
	$('#district_check').hide();
	$('#state_check').hide();
	$('#taluka_check').hide();
	$('#city_check').hide();
	$('#pin_code_check').hide();
// -------------------------------------------------------------------------------
	
	$("#username").keyup(function () {
		username_check();
    });

	$("#student_name").keyup(function () {
		student_name_check();
    });
	
	$("#parent_name").keyup(function () {
		parent_name_check();
    });
	
	$("#parent_email").keyup(function () {
		parent_email_check();
    });

	$("#mobile_prefix").change(function () {
		mobile_prefix_check();
    });

	
	$("#mobile").keypress(function (e) {
         //if the letter is not digit then display error and don't type anything
         if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            //display error message
            $('#mobile_check').show();
            $("#mobile_check").html("Digits Only").show().fadeOut("slow");
            return false;
        }
    });

	$("#mobile").keyup(function () {
		mobile_check();
    });

	$("#school_name").keyup(function () {
		school_name_check();
    });

	$("#std_id").change(function () {
		std_id_check();
    });

	$("#password").keyup(function () {
		password_check();
    });
	
	$("#address").keyup(function () {
		address_check();
    });

	$("#district").keyup(function () {
		district_check();
    });
	
	$("#state").keyup(function () {
		state_check();
    });
	
	$("#taluka").keyup(function () {
		taluka_check();
    });
	
	$("#city").keyup(function () {
		city_check();
    });
	
	$("#pin_code").keyup(function () {
		pin_code_check();
    });

});
// -------------------------------------------------------------------------------





