var base_url = 'http://54.218.78.31:50/portal/';


	
		
   

$(document).ready(function()
{

	$(window).on('load', function()  {
        // Animate loader off screen
       $("#loader-wrapper").fadeOut(2000);
        $("#body").fadeIn(2000);
    });

	var height=$( window ).height();
	$(".loginOuter").css('height',height);
	
	if($(window).height()<800){
		$('.footer').addClass("footermobile");
	}else{
		$('.footer').removeClass("footermobile");
	}
	
	$(window).resize(function(){
			
			if($(window).height()<800){
				$('.footer').addClass("footermobile");
			}else{
				$('.footer').removeClass("footermobile");
			}
    });
	
	
	if($(window).height()<800){
		$('.footer').addClass("lg-foot");
	}else{
		$('.footer').removeClass("lg-foot");
	}
	
	$(window).resize(function(){
			
			if($(window).height()<800){
				$('.footer').addClass("footermobile");
			}else{
				$('.footer').removeClass("footermobile");
			}
    });


/* change password */
	
	$('#change_password').submit(function(e)
	{
		e.preventDefault();
		//alert();
		$.ajax({
				url: base_url+'index.php/portal/change_password',
				type: 'post',
				data: $('#change_password').serialize(),
				success: function(response)
				{
					alert(response);
				}

			});

	});


	$('#login_portal').submit(function(e)
	{
		e.preventDefault();
		$.ajax(
			{
				url: base_url+'index.php/portal/login_check',
				type: 'post',
				data: $('#login_portal').serialize(),
				success: function(response)
				{
					if( response == 'done' )
					{
						$('#error_div').html('<div class="alert alert-success"><strong>Login Success!</strong> Please Wait.</div>');
						setTimeout(function(){
							window.location.href = base_url+'index.php/portal/account';
						}, 1000)
					}
					else
					{
						$('#error_div').html('<div class="alert alert-danger">'+response+'</div>');
					}
				}
			});
	});


	$('#send_value_id').click(function(){
		$('#elect_reading_submit').trigger('submit');
	});

	$('#elect_reading_submit').validate({
		rules: 
		{
			elec_reading:
			{
				required: true,
				number: true,
				maxlength: 5
			}
		},
		submitHandler: function(form)
		{
			$.ajax({
				url: base_url+'/index.php/portal/send_elec_reading',
				type: 'post',
				dataType: 'json',	
				data: $('#elect_reading_submit').serialize(),
				success:function(response)
				{
					console.log(response.Message);
					if( response.Message == 'SUCCESS' )
					{
						$('#meterHeading').html('<b><span style="color:green">Meter Reading Updated</span></b>');
						setTimeout(function()
						{
								window.location.href='';
						},1000)
					}
					else
					{
						$('#meterHeading').html(response);
					}
				}
			});
		}
	});


	$('#send_value_id_gas').click(function(){
		$('#gas_reading_submit').trigger('submit');
	});

	$('#gas_reading_submit').validate({
		rules: 
		{
			gas_reading:
			{
				required: true,
				number: true,
				maxlength: 5
			}
		},
		submitHandler: function(form)
		{
			$.ajax({
				url: base_url+'/index.php/portal/send_gas_reading',
				type: 'post',
				dataType: 'json',
				data: $('#gas_reading_submit').serialize(),
				success:function(response)
				{
					console.log(response.Message);
					if( response.Message == 'SUCCESS' )
					{
						$('#meterHeading').html('<b><span style="color:green">Meter Reading Updated</span></b>');
						setTimeout(function()
						{
								window.location.href='';
						},1000)
					}
					else
					{
						$('#meterHeading').html(response);
					}
				}
			});
		}
	});





});
/* end document ready */